set menu to window through a function

This commit is contained in:
Chris Young 2019-05-07 22:22:12 +01:00
parent 67af746324
commit 83c3831853
4 changed files with 38 additions and 7 deletions

View File

@ -363,6 +363,15 @@ struct Menu *ami_gui_get_menu(struct gui_window *gw)
return gw->shared->imenu; return gw->shared->imenu;
} }
void ami_gui2_set_menu(struct gui_window_2 *gwin, struct Menu *menu)
{
if(menu != NULL) {
gwin->imenu = menu;
} else {
ami_gui_menu_freemenus(gwin->imenu);
}
}
STRPTR ami_locale_langs(int *codeset) STRPTR ami_locale_langs(int *codeset)
{ {
struct Locale *locale; struct Locale *locale;

View File

@ -316,5 +316,10 @@ struct Window *ami_gui_get_window(struct gui_window *gw);
*/ */
struct Menu *ami_gui_get_menu(struct gui_window *gw); struct Menu *ami_gui_get_menu(struct gui_window *gw);
/**
* Set imenu to gui_window_2. A value of NULL will free the menu.
*/
void ami_gui2_set_menu(struct gui_window_2 *gwin, struct Menu *menu);
#endif #endif

View File

@ -1035,26 +1035,31 @@ struct Menu *ami_gui_menu_create(struct gui_window_2 *gwin)
if(LIB_IS_AT_LEAST((struct Library *)IntuitionBase, 54, 6)) { if(LIB_IS_AT_LEAST((struct Library *)IntuitionBase, 54, 6)) {
#ifdef __amigaos4__ #ifdef __amigaos4__
if(gui_menu != NULL) { if(gui_menu != NULL) {
gwin->imenu = gui_menu; ami_gui2_set_menu(gwin, gui_menu);
gui_menu_count++; gui_menu_count++;
return gwin->imenu; return gui_menu;
} }
ami_init_menulabs(gui_menu_data); ami_init_menulabs(gui_menu_data);
ami_menu_scan(gui_menu_data); ami_menu_scan(gui_menu_data);
ami_menu_arexx_scan(gui_menu_data); ami_menu_arexx_scan(gui_menu_data);
gwin->imenu = ami_menu_layout(gui_menu_data, AMI_MENU_AREXX_MAX); gui_menu = ami_menu_layout(gui_menu_data, AMI_MENU_AREXX_MAX);
gui_menu = gwin->imenu; ami_gui2_set_menu(gwin, gui_menu);
gui_menu_count++; gui_menu_count++;
return gui_menu;
#endif #endif
} else { } else {
struct Menu *temp_menu;
ami_init_menulabs(gwin->menu_data); ami_init_menulabs(gwin->menu_data);
ami_menu_scan(gwin->menu_data); ami_menu_scan(gwin->menu_data);
ami_menu_arexx_scan(gwin->menu_data); ami_menu_arexx_scan(gwin->menu_data);
gwin->imenu = ami_menu_layout(gwin->menu_data, AMI_MENU_AREXX_MAX); temp_menu = ami_menu_layout(gwin->menu_data, AMI_MENU_AREXX_MAX);
ami_gui2_set_menu(gwin, temp_menu);
return temp_menu;
} }
return gwin->imenu; return NULL; // shouldn't get this far
} }
static void ami_free_menulabs(struct ami_menu_data **md) static void ami_free_menulabs(struct ami_menu_data **md)
@ -1089,6 +1094,13 @@ static void ami_free_menulabs(struct ami_menu_data **md)
} }
} }
void ami_gui_menu_freemenus(struct Menu *menu)
{
if(menu != NULL) {
FreeMenus(menu);
}
}
void ami_gui_menu_free(struct gui_window_2 *gwin) void ami_gui_menu_free(struct gui_window_2 *gwin)
{ {
if(LIB_IS_AT_LEAST((struct Library *)IntuitionBase, 54, 6)) { if(LIB_IS_AT_LEAST((struct Library *)IntuitionBase, 54, 6)) {
@ -1106,7 +1118,7 @@ void ami_gui_menu_free(struct gui_window_2 *gwin)
#endif #endif
} else { } else {
ami_free_menulabs(gwin->menu_data); ami_free_menulabs(gwin->menu_data);
FreeMenus(gwin->imenu); ami_gui2_set_menu(gwin, NULL);
} }
} }

View File

@ -154,5 +154,10 @@ void ami_gui_menu_refresh_hotlist(void);
* \return true if NetSurf has been quit * \return true if NetSurf has been quit
*/ */
bool ami_gui_menu_quit_selected(void); bool ami_gui_menu_quit_selected(void);
/**
* Frees a menu. Only used on OS3 and old OS4.
*/
void ami_gui_menu_freemenus(struct Menu *menu);
#endif #endif