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;
|
||||
}
|
||||
|
||||
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
|
||||
extern HMENU makeMenubar(void);
|
||||
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;
|
||||
RECT r;
|
||||
HWND contenthwnd;
|
||||
const uiMenuItem *item;
|
||||
|
||||
w = (struct window *) GetWindowLongPtrW(hwnd, GWLP_USERDATA);
|
||||
if (w == NULL) {
|
||||
|
@ -37,12 +36,8 @@ static LRESULT CALLBACK uiWindowWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPA
|
|||
break;
|
||||
if (HIWORD(wParam) != 0)
|
||||
break;
|
||||
/*TODO item = menuIDToItem(LOWORD(wParam));
|
||||
printf("%d", item->Type);
|
||||
if (item->Type == uiMenuItemTypeCommand)
|
||||
printf(" %s", item->Name);
|
||||
printf("\n");
|
||||
*/ return 0;
|
||||
runMenuEvent(LOWORD(wParam), uiWindow(w));
|
||||
return 0;
|
||||
case WM_WINDOWPOSCHANGED:
|
||||
if ((wp->flags & SWP_NOSIZE) != 0)
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue