Skip to content

Commit c925b50

Browse files
committed
Fix the windows backend
1 parent 7b88b6e commit c925b50

File tree

3 files changed

+20
-15
lines changed

3 files changed

+20
-15
lines changed

examples/video/01-menubar/menubar.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ void CreateMenuBar()
4343
{
4444
SDL_MenuItem* menu = SDL_CreateMenuItem(bar, "File", SDL_MENU, MENU_BAR_LAST);
4545
new_window = SDL_CreateMenuItem(menu, "New Window", SDL_MENU_BUTTON, MENU_BAR_FILE_NEW_WINDOW);
46-
checkable = SDL_CreateMenuItem(menu, "Autosave Tabs on Close", SDL_MENU_CHECKABLE, MENU_BAR_FILE_DISABLE_NEW_WINDOW);
46+
checkable = SDL_CreateMenuItem(menu, "Enable New Window", SDL_MENU_CHECKABLE, MENU_BAR_FILE_DISABLE_NEW_WINDOW);
4747

4848
SDL_CheckMenuItem(checkable);
4949
}

src/video/SDL_video.c

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6093,21 +6093,26 @@ SDL_MenuItem *SDL_CreateMenuItemAt(SDL_MenuItem *menu_bar_as_item, size_t index,
60936093

60946094
// Get the last item in the list and insert our new item.
60956095
if (menu->child_list) {
6096-
SDL_MenuItem *current = menu->child_list;
6096+
if (index == 0) {
6097+
menu_item->common.next = menu->child_list;
6098+
menu->child_list->common.prev = menu_item;
6099+
menu->child_list = menu_item;
6100+
} else {
6101+
SDL_MenuItem *current = menu->child_list;
6102+
for (size_t i = 1; (i < index) && current; ++i) {
6103+
current = current->common.next;
6104+
}
60976105

6098-
for (size_t i = 1; (i < index) && current; ++i) {
6099-
current = current->common.next;
6100-
}
6106+
SDL_assert(current);
61016107

6102-
SDL_assert(current);
6108+
if (current->common.next) {
6109+
current->common.next->common.prev = menu_item;
6110+
menu_item->common.next = current->common.next;
6111+
}
61036112

6104-
if (current->common.next) {
6105-
current->common.next->common.prev = menu_item;
6106-
menu_item->common.next = current->common.next;
6113+
current->common.next = menu_item;
6114+
menu_item->common.prev = current;
61076115
}
6108-
6109-
current->common.next = menu_item;
6110-
menu_item->common.prev = current;
61116116
} else {
61126117
menu->child_list = menu_item;
61136118
}
@@ -6241,7 +6246,7 @@ bool SDL_DestroyMenuItem(SDL_MenuItem *menu_item)
62416246

62426247
if (menu_item->common.prev) {
62436248
menu_item->common.prev->common.next = menu_item->common.next;
6244-
menu_item->common.next->common.next = menu_item->common.prev;
6249+
menu_item->common.next->common.prev = menu_item->common.prev;
62456250

62466251
if (menu_item == menu_item->common.parent->menu_common.child_list) {
62476252
menu_item->common.parent->menu_common.child_list = menu_item->common.next;

src/video/windows/SDL_windowsvideo.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -945,7 +945,7 @@ static bool Win32_MenuItemEnabled(SDL_MenuItem *menu_item, bool *enabled)
945945
return WIN_SetError("Unable to get menu_item check state.");
946946
}
947947

948-
*enabled = !(flags & MF_DISABLED);
948+
*enabled = !(flags & MF_GRAYED);
949949

950950
return true;
951951
}
@@ -984,7 +984,7 @@ static bool Win32_DestroyMenuItem(SDL_MenuItem *menu_item)
984984
return WIN_SetError("Unable to remove menu item.");
985985
}
986986
} else {
987-
DeleteMenu((HMENU)platform_data->self_handle, i, MF_BYPOSITION);
987+
DeleteMenu((HMENU)platform_data->owner_handle, i, MF_BYPOSITION);
988988
}
989989

990990
SDL_free(menu_item->common.platform_data);

0 commit comments

Comments
 (0)