Hooked up menu events on Windows. We're done!
This commit is contained in:
parent
7a1634a387
commit
333d610b0e
|
@ -295,3 +295,34 @@ HMENU makeMenubar(void)
|
||||||
|
|
||||||
return menubar;
|
return menubar;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void runMenuEvent(WORD id, uiWindow *w)
|
||||||
|
{
|
||||||
|
struct menu *m;
|
||||||
|
struct menuItem *item;
|
||||||
|
uintmax_t i, j;
|
||||||
|
uiMenuItem *umi;
|
||||||
|
|
||||||
|
// TODO optimize this somehow?
|
||||||
|
for (i = 0; i < len; i++) {
|
||||||
|
m = &menus[i];
|
||||||
|
for (j = 0; j < m->len; j++) {
|
||||||
|
item = &(m->items[j]);
|
||||||
|
if (item->id == id)
|
||||||
|
goto found;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// no match
|
||||||
|
// TODO complain?
|
||||||
|
return;
|
||||||
|
|
||||||
|
found:
|
||||||
|
umi = uiMenuItem(item);
|
||||||
|
|
||||||
|
// first toggle checkboxes, if any
|
||||||
|
if (item->type == typeCheckbox)
|
||||||
|
uiMenuItemSetChecked(umi, !uiMenuItemChecked(umi));
|
||||||
|
|
||||||
|
// then run the event
|
||||||
|
(*(item->onClicked))(umi, w, item->onClickedData);
|
||||||
|
}
|
||||||
|
|
|
@ -76,3 +76,4 @@ extern const char *initOSContainer(HICON, HCURSOR);
|
||||||
// menu.c
|
// menu.c
|
||||||
extern HMENU makeMenubar(void);
|
extern HMENU makeMenubar(void);
|
||||||
extern const uiMenuItem *menuIDToItem(UINT_PTR);
|
extern const uiMenuItem *menuIDToItem(UINT_PTR);
|
||||||
|
extern void runMenuEvent(WORD, uiWindow *);
|
||||||
|
|
|
@ -21,7 +21,6 @@ static LRESULT CALLBACK uiWindowWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPA
|
||||||
WINDOWPOS *wp = (WINDOWPOS *) lParam;
|
WINDOWPOS *wp = (WINDOWPOS *) lParam;
|
||||||
RECT r;
|
RECT r;
|
||||||
HWND contenthwnd;
|
HWND contenthwnd;
|
||||||
const uiMenuItem *item;
|
|
||||||
|
|
||||||
w = (struct window *) GetWindowLongPtrW(hwnd, GWLP_USERDATA);
|
w = (struct window *) GetWindowLongPtrW(hwnd, GWLP_USERDATA);
|
||||||
if (w == NULL) {
|
if (w == NULL) {
|
||||||
|
@ -37,12 +36,8 @@ static LRESULT CALLBACK uiWindowWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPA
|
||||||
break;
|
break;
|
||||||
if (HIWORD(wParam) != 0)
|
if (HIWORD(wParam) != 0)
|
||||||
break;
|
break;
|
||||||
/*TODO item = menuIDToItem(LOWORD(wParam));
|
runMenuEvent(LOWORD(wParam), uiWindow(w));
|
||||||
printf("%d", item->Type);
|
return 0;
|
||||||
if (item->Type == uiMenuItemTypeCommand)
|
|
||||||
printf(" %s", item->Name);
|
|
||||||
printf("\n");
|
|
||||||
*/ return 0;
|
|
||||||
case WM_WINDOWPOSCHANGED:
|
case WM_WINDOWPOSCHANGED:
|
||||||
if ((wp->flags & SWP_NOSIZE) != 0)
|
if ((wp->flags & SWP_NOSIZE) != 0)
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue