Implemented menu destruction on Windows.
This commit is contained in:
parent
b52aa4cfcb
commit
75b4d28569
|
@ -340,4 +340,5 @@ void freeMenubar(GtkWidget *mb)
|
|||
|
||||
i = 0;
|
||||
gtk_container_foreach(GTK_CONTAINER(mb), freeMenu, &i);
|
||||
// no need to worry about destroying any widgets; destruction of the window they're in will do it for us
|
||||
}
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
// 24 april 2015
|
||||
#include "uipriv_windows.h"
|
||||
|
||||
// TODO window destruction
|
||||
|
||||
// TODO turn this into struct menu **
|
||||
static struct menu *menus = NULL;
|
||||
static uintmax_t len = 0;
|
||||
static uintmax_t cap = 0;
|
||||
|
@ -12,6 +11,7 @@ static WORD curID = 100; // start somewhere safe
|
|||
struct menu {
|
||||
uiMenu m;
|
||||
WCHAR *name;
|
||||
// TODO turn into struct menuItem **
|
||||
struct menuItem *items;
|
||||
uintmax_t len;
|
||||
uintmax_t cap;
|
||||
|
@ -326,3 +326,39 @@ found:
|
|||
// then run the event
|
||||
(*(item->onClicked))(umi, w, item->onClickedData);
|
||||
}
|
||||
|
||||
static void freeMenu(struct menu *m, HMENU submenu)
|
||||
{
|
||||
uintmax_t i;
|
||||
struct menuItem *item;
|
||||
uintmax_t j;
|
||||
|
||||
for (i = 0; i < m->len; i++) {
|
||||
item = &m->items[i];
|
||||
for (j = 0; j < item->len; j++)
|
||||
if (item->hmenus[j] == submenu)
|
||||
break;
|
||||
if (j >= item->len)
|
||||
complain("submenu handle %p not found in freeMenu()", submenu);
|
||||
for (; j < item->len - 1; j++)
|
||||
item->hmenus[j] = item->hmenus[j + 1];
|
||||
item->hmenus[j] = NULL;
|
||||
item->len--;
|
||||
}
|
||||
}
|
||||
|
||||
void freeMenubar(HMENU menubar)
|
||||
{
|
||||
uintmax_t i;
|
||||
MENUITEMINFOW mi;
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
ZeroMemory(&mi, sizeof (MENUITEMINFOW));
|
||||
mi.cbSize = sizeof (MENUITEMINFOW);
|
||||
mi.fMask = MIIM_SUBMENU;
|
||||
if (GetMenuItemInfoW(menubar, i, TRUE, &mi) == 0)
|
||||
logLastError("error getting menu to delete item references from in freeMenubar()");
|
||||
freeMenu(&menus[i], mi.hSubMenu);
|
||||
}
|
||||
// no need to worry about destroying any menus; destruction of the window they're in will do it for us
|
||||
}
|
||||
|
|
|
@ -77,3 +77,4 @@ extern const char *initContainer(HICON, HCURSOR);
|
|||
extern HMENU makeMenubar(void);
|
||||
extern const uiMenuItem *menuIDToItem(UINT_PTR);
|
||||
extern void runMenuEvent(WORD, uiWindow *);
|
||||
extern void freeMenubar(HMENU);
|
||||
|
|
|
@ -86,7 +86,9 @@ static void windowDestroy(uiControl *c)
|
|||
// now destroy the bin
|
||||
// the bin has no parent, so we can just call uiControlDestroy()
|
||||
uiControlDestroy(uiControl(w->bin));
|
||||
// TODO menus
|
||||
// now free the menubar, if any
|
||||
if (w->menubar != NULL)
|
||||
freeMenubar(w->menubar);
|
||||
// now destroy ourselves
|
||||
if (DestroyWindow(w->hwnd) == 0)
|
||||
logLastError("error destroying uiWindow in windowDestroy()");
|
||||
|
|
Loading…
Reference in New Issue