Mercurial > dwindows
comparison gtk4/dw.c @ 2289:26a76f94f8d8
GTK4: Added action groups to the menus, because everything says we need
them... however it still isn't working... GTK_DEBUG=action
shows that the actions are created and then go missing...very confused.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Thu, 04 Feb 2021 09:33:19 +0000 |
parents | d0bb8f99ac45 |
children | 3c3f0023ae02 |
comparison
equal
deleted
inserted
replaced
2288:d0bb8f99ac45 | 2289:26a76f94f8d8 |
---|---|
2166 g_object_set_data(G_OBJECT(tmp), "_dw_id", GINT_TO_POINTER(id)); | 2166 g_object_set_data(G_OBJECT(tmp), "_dw_id", GINT_TO_POINTER(id)); |
2167 g_object_set_data(G_OBJECT(tmp), "_dw_pagearray", (gpointer)pagearray); | 2167 g_object_set_data(G_OBJECT(tmp), "_dw_pagearray", (gpointer)pagearray); |
2168 return tmp; | 2168 return tmp; |
2169 } | 2169 } |
2170 | 2170 |
2171 static int _dw_menugroup = 0; | |
2172 | |
2171 /* | 2173 /* |
2172 * Create a menu object to be popped up. | 2174 * Create a menu object to be popped up. |
2173 * Parameters: | 2175 * Parameters: |
2174 * id: An ID to be used for getting the resource from the | 2176 * id: An ID to be used for getting the resource from the |
2175 * resource file. | 2177 * resource file. |
2178 { | 2180 { |
2179 GMenu *menu = g_menu_new(); | 2181 GMenu *menu = g_menu_new(); |
2180 /* Create the initial section and add it to the menu */ | 2182 /* Create the initial section and add it to the menu */ |
2181 GMenu *section = g_menu_new(); | 2183 GMenu *section = g_menu_new(); |
2182 GMenuItem *item = g_menu_item_new_section(NULL, G_MENU_MODEL(section)); | 2184 GMenuItem *item = g_menu_item_new_section(NULL, G_MENU_MODEL(section)); |
2185 GSimpleActionGroup *group = g_simple_action_group_new(); | |
2186 HMENUI tmp = gtk_popover_menu_new_from_model_full(G_MENU_MODEL(menu), GTK_POPOVER_MENU_NESTED); | |
2187 char tempbuf[25] = {0}; | |
2188 | |
2183 g_menu_append_item(menu, item); | 2189 g_menu_append_item(menu, item); |
2184 HMENUI tmp = gtk_popover_menu_new_from_model_full(G_MENU_MODEL(menu), GTK_POPOVER_MENU_NESTED); | 2190 snprintf(tempbuf, 24, "menu%d", ++_dw_menugroup); |
2185 | 2191 gtk_widget_insert_action_group(GTK_WIDGET(tmp), tempbuf, G_ACTION_GROUP(group)); |
2192 | |
2193 g_object_set_data(G_OBJECT(tmp), "_dw_menugroup", GINT_TO_POINTER(_dw_menugroup)); | |
2194 g_object_set_data(G_OBJECT(tmp), "_dw_group", (gpointer)group); | |
2186 g_object_set_data(G_OBJECT(tmp), "_dw_id", GINT_TO_POINTER(id)); | 2195 g_object_set_data(G_OBJECT(tmp), "_dw_id", GINT_TO_POINTER(id)); |
2187 g_object_set_data(G_OBJECT(tmp), "_dw_section", (gpointer)section); | 2196 g_object_set_data(G_OBJECT(tmp), "_dw_section", (gpointer)section); |
2188 return tmp; | 2197 return tmp; |
2189 } | 2198 } |
2190 | 2199 |
2207 GtkWidget *oldmenu = GTK_WIDGET(g_object_get_data(G_OBJECT(location), "_dw_menubar")); | 2216 GtkWidget *oldmenu = GTK_WIDGET(g_object_get_data(G_OBJECT(location), "_dw_menubar")); |
2208 GMenu *menu = g_menu_new(); | 2217 GMenu *menu = g_menu_new(); |
2209 /* Create the initial section and add it to the menu */ | 2218 /* Create the initial section and add it to the menu */ |
2210 GMenu *section = g_menu_new(); | 2219 GMenu *section = g_menu_new(); |
2211 GMenuItem *item = g_menu_item_new_section(NULL, G_MENU_MODEL(section)); | 2220 GMenuItem *item = g_menu_item_new_section(NULL, G_MENU_MODEL(section)); |
2221 GSimpleActionGroup *group = g_simple_action_group_new(); | |
2222 char tempbuf[25] = {0}; | |
2223 | |
2212 g_menu_append_item(menu, item); | 2224 g_menu_append_item(menu, item); |
2213 | 2225 |
2214 if(oldmenu && GTK_IS_WIDGET(oldmenu)) | 2226 if(oldmenu && GTK_IS_WIDGET(oldmenu)) |
2215 gtk_grid_remove(GTK_GRID(box), tmp); | 2227 gtk_grid_remove(GTK_GRID(box), tmp); |
2216 | 2228 |
2217 /* Create a new menu bar */ | 2229 /* Create a new menu bar */ |
2218 tmp = gtk_popover_menu_bar_new_from_model(G_MENU_MODEL(menu)); | 2230 tmp = gtk_popover_menu_bar_new_from_model(G_MENU_MODEL(menu)); |
2231 snprintf(tempbuf, 24, "menu%d", ++_dw_menugroup); | |
2232 gtk_widget_insert_action_group(GTK_WIDGET(tmp), tempbuf, G_ACTION_GROUP(group)); | |
2219 gtk_widget_show(tmp); | 2233 gtk_widget_show(tmp); |
2234 | |
2220 /* Save pointers to each other */ | 2235 /* Save pointers to each other */ |
2221 g_object_set_data(G_OBJECT(location), "_dw_menubar", (gpointer)tmp); | 2236 g_object_set_data(G_OBJECT(location), "_dw_menubar", (gpointer)tmp); |
2222 g_object_set_data(G_OBJECT(tmp), "_dw_window", (gpointer)location); | 2237 g_object_set_data(G_OBJECT(tmp), "_dw_window", (gpointer)location); |
2238 g_object_set_data(G_OBJECT(tmp), "_dw_menugroup", GINT_TO_POINTER(_dw_menugroup)); | |
2239 g_object_set_data(G_OBJECT(tmp), "_dw_group", (gpointer)group); | |
2223 g_object_set_data(G_OBJECT(tmp), "_dw_section", (gpointer)section); | 2240 g_object_set_data(G_OBJECT(tmp), "_dw_section", (gpointer)section); |
2224 gtk_grid_attach(GTK_GRID(box), tmp, 0, 0, 1, 1); | 2241 gtk_grid_attach(GTK_GRID(box), tmp, 0, 0, 1, 1); |
2225 } | 2242 } |
2226 return tmp; | 2243 return tmp; |
2227 } | 2244 } |
2336 g_object_set_data(G_OBJECT(menu), "_dw_submenucount", GINT_TO_POINTER(submenucount)); | 2353 g_object_set_data(G_OBJECT(menu), "_dw_submenucount", GINT_TO_POINTER(submenucount)); |
2337 } | 2354 } |
2338 else | 2355 else |
2339 { | 2356 { |
2340 char numbuf[25] = {0}; | 2357 char numbuf[25] = {0}; |
2341 | 2358 GSimpleActionGroup *group = g_object_get_data(G_OBJECT(menu), "_dw_group"); |
2342 snprintf(tempbuf, 100, "menu.%llu-%lu", DW_POINTER_TO_ULONGLONG(menu), id); | 2359 int menugroup = DW_POINTER_TO_INT(g_object_get_data(G_OBJECT(menu), "_dw_menugroup")); |
2343 action = g_simple_action_new(tempbuf, NULL); | 2360 char *actionname; |
2344 g_object_ref(G_OBJECT(action)); | 2361 |
2362 snprintf(tempbuf, 100, "menu%d.action%lu", menugroup, id); | |
2363 actionname = strchr(tempbuf, '.'); | |
2364 action = g_simple_action_new(&actionname[1], NULL); | |
2365 g_action_map_add_action(G_ACTION_MAP(group), G_ACTION(action)); | |
2345 tmphandle=g_menu_item_new(temptitle, tempbuf); | 2366 tmphandle=g_menu_item_new(temptitle, tempbuf); |
2346 snprintf(numbuf, 24, "%lu", id); | 2367 snprintf(numbuf, 24, "%lu", id); |
2347 g_object_set_data(G_OBJECT(menu), numbuf, (gpointer)tmphandle); | 2368 g_object_set_data(G_OBJECT(menu), numbuf, (gpointer)tmphandle); |
2348 g_object_set_data(G_OBJECT(tmphandle), "_dw_action", (gpointer)action); | 2369 g_object_set_data(G_OBJECT(tmphandle), "_dw_action", (gpointer)action); |
2349 } | 2370 } |
9557 strcpy(signal->gname, "toggled"); | 9578 strcpy(signal->gname, "toggled"); |
9558 /* For menu items, get the G(Simple)Action and the signal is "activate" */ | 9579 /* For menu items, get the G(Simple)Action and the signal is "activate" */ |
9559 else if(G_IS_MENU_ITEM(object) && strcmp(signal->name, DW_SIGNAL_CLICKED) == 0) | 9580 else if(G_IS_MENU_ITEM(object) && strcmp(signal->name, DW_SIGNAL_CLICKED) == 0) |
9560 { | 9581 { |
9561 GSimpleAction *action = G_SIMPLE_ACTION(g_object_get_data(object, "_dw_action")); | 9582 GSimpleAction *action = G_SIMPLE_ACTION(g_object_get_data(object, "_dw_action")); |
9562 | 9583 |
9563 if(action) | 9584 if(action) |
9564 { | 9585 { |
9565 int cid, sigid = _dw_set_signal_handler(G_OBJECT(action), (HWND)object, sigfunc, data, (gpointer)_dw_menu_handler, discfunc); | 9586 int cid, sigid = _dw_set_signal_handler(G_OBJECT(action), (HWND)object, sigfunc, data, (gpointer)_dw_menu_handler, discfunc); |
9566 | 9587 |
9567 params[0] = DW_INT_TO_POINTER(sigid); | 9588 params[0] = DW_INT_TO_POINTER(sigid); |