Skip to content

Commit 3d39b39

Browse files
committed
Started appmenu work, not remotely ready.
1 parent bb07a98 commit 3d39b39

File tree

5 files changed

+38
-8
lines changed

5 files changed

+38
-8
lines changed

src/dynapi/SDL_dynapi.sym

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,6 +1265,7 @@ SDL3_0.0.0 {
12651265
SDL_SavePNG_IO;
12661266
SDL_SavePNG;
12671267
SDL_CreateMenuBar;
1268+
SDL_GetMenuBarAppMenu;
12681269
SDL_GetWindowMenuBar;
12691270
SDL_SetWindowMenuBar;
12701271
SDL_CreateMenuItemAt;

src/dynapi/SDL_dynapi_overrides.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,6 +1291,7 @@
12911291
#define SDL_SavePNG_IO SDL_SavePNG_IO_REAL
12921292
#define SDL_SavePNG SDL_SavePNG_REAL
12931293
#define SDL_CreateMenuBar SDL_CreateMenuBar_REAL
1294+
#define SDL_GetMenuBarAppMenu SDL_GetMenuBarAppMenu_REAL
12941295
#define SDL_GetWindowMenuBar SDL_GetWindowMenuBar_REAL
12951296
#define SDL_SetWindowMenuBar SDL_SetWindowMenuBar_REAL
12961297
#define SDL_CreateMenuItemAt SDL_CreateMenuItemAt_REAL

src/dynapi/SDL_dynapi_procs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,6 +1301,7 @@ SDL_DYNAPI_PROC(bool,SDL_SavePNG,(SDL_Surface *a,const char *b),(a,b),return)
13011301
SDL_DYNAPI_PROC(SDL_MenuItem*,SDL_CreateMenuBar,(SDL_Window *a),(a),return)
13021302
SDL_DYNAPI_PROC(SDL_MenuItem*,SDL_GetWindowMenuBar, (SDL_Window * a), (a),return)
13031303
SDL_DYNAPI_PROC(bool,SDL_SetWindowMenuBar,(SDL_Window *a, SDL_MenuItem *b),(a, b),return)
1304+
SDL_DYNAPI_PROC(SDL_MenuItem*,SDL_GetMenuBarAppMenu,(SDL_MenuItem *a),(a),return)
13041305
SDL_DYNAPI_PROC(SDL_MenuItem*,SDL_CreateMenuItemAt,(SDL_MenuItem *a,size_t b,const char *c,SDL_MenuItemType d, Uint16 e), (a,b,c,d,e), return)
13051306
SDL_DYNAPI_PROC(SDL_MenuItem*,SDL_CreateMenuItem,(SDL_MenuItem *a, const char *b, SDL_MenuItemType c, Uint16 d),(a,b,c,d), return)
13061307
SDL_DYNAPI_PROC(Sint64,SDL_GetMenuChildItems, (SDL_MenuItem *a),(a),return)

src/video/SDL_sysvideo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ typedef struct SDL_MenuBar
236236
{
237237
SDL_Menu_CommonData common;
238238
SDL_Window *window;
239+
SDL_MenuItem *app_menu;
239240
} SDL_MenuBar;
240241

241242
typedef struct SDL_SubMenu

src/video/SDL_video.c

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6162,18 +6162,37 @@ bool SDL_SetWindowMenuBar(SDL_Window* window, SDL_MenuItem* menu_bar)
61626162
CHECK_WINDOW_MAGIC(window, false);
61636163

61646164
if (!_this) {
6165-
return false;
6165+
return SDL_UninitializedVideo();
6166+
}
6167+
6168+
// Same Window/MenuBar combination, no need to do anything.
6169+
if (menu_bar->menu_bar.window == window) {
6170+
return true;
61666171
}
61676172

6168-
if (!menu_bar) {
6173+
// Passed NULL to the Window, user wants to retake ownership of the menubar.
6174+
if (!menu_bar && window->menu_bar) {
6175+
bool success = _this->SetWindowMenuBar(NULL);
6176+
6177+
SDL_SetObjectValid(window->menu_bar, SDL_OBJECT_TYPE_MENUBAR, true);
61696178
window->menu_bar = NULL;
6170-
return true;
6179+
6180+
return success;
61716181
}
61726182

61736183
if (menu_bar->common.type != SDL_MENUITEM_MENUBAR) {
61746184
SDL_SetError("Can't set menu Item that isn't a Menu onto a Window.");
61756185
return false;
61766186
}
6187+
6188+
if (menu_bar->menu_bar.window) {
6189+
bool success = _this->SetWindowMenuBar(NULL);
6190+
SDL_SetObjectValid(menu_bar->menu_bar.window->menu_bar, SDL_OBJECT_TYPE_MENUBAR, true);
6191+
window->menu_bar = NULL;
6192+
menu_bar->menu_bar.window->menu_bar
6193+
6194+
menu_bar->menu_bar.window = NULL;
6195+
}
61776196

61786197
SDL_MenuBar *menu_bar_real = (SDL_MenuBar*)menu_bar;
61796198
menu_bar_real->window = window;
@@ -6284,11 +6303,6 @@ Uint32 SDL_GetIndexInMenu(SDL_MenuItem *menu_item)
62846303
return i;
62856304
}
62866305

6287-
SDL_MenuItem *SDL_CreateMenuItemWithProperties(SDL_MenuItem *menu_bar_as_item, SDL_PropertiesID props)
6288-
{
6289-
return NULL;
6290-
}
6291-
62926306
SDL_MenuItem *SDL_CreateMenuItem(SDL_MenuItem *menu_bar_as_item, const char *label, SDL_MenuItemType type, Uint16 event_type)
62936307
{
62946308
CHECK_MENUITEM_MAGIC(menu_bar_as_item, NULL);
@@ -6301,6 +6315,18 @@ SDL_MenuItem *SDL_CreateMenuItem(SDL_MenuItem *menu_bar_as_item, const char *lab
63016315
return SDL_CreateMenuItemAt(menu_bar_as_item, menu->num_children, label, type, event_type);
63026316
}
63036317

6318+
6319+
SDL_MenuItem *SDL_GetMenuBarAppMenu(SDL_MenuBar *menu_bar)
6320+
{
6321+
CHECK_MENUITEM_MAGIC(menu_bar, NULL);
6322+
6323+
if (!menu_bar->app_menu) {
6324+
SDL_SetError("This platform doesn't support an Application menu.");
6325+
}
6326+
6327+
return menu_bar->app_menu;
6328+
}
6329+
63046330
Sint64 SDL_GetMenuChildItems(SDL_MenuItem *menu_as_item)
63056331
{
63066332
CHECK_MENUITEM_MAGIC(menu_as_item, -1);

0 commit comments

Comments
 (0)