static void sync_menu_shell (GtkMenuShell *menu_shell, MenuRef carbon_menu, gboolean toplevel, gboolean debug) { GList *children; GList *l; MenuItemIndex carbon_index = 1; if (debug) g_printerr ("%s: syncing shell %p\n", G_STRFUNC, menu_shell); carbon_menu_connect (GTK_WIDGET (menu_shell), carbon_menu, toplevel); children = gtk_container_get_children (GTK_CONTAINER (menu_shell)); for (l = children; l; l = l->next) { GtkWidget *menu_item = l->data; CarbonMenuItem *carbon_item; if (GTK_IS_TEAROFF_MENU_ITEM (menu_item)) continue; if (toplevel && g_object_get_data (G_OBJECT (menu_item), "gtk-empty-menu-item")) continue; carbon_item = carbon_menu_item_get (menu_item); if (debug) g_printerr ("%s: carbon_item %d for menu_item %d (%s, %s)\n", G_STRFUNC, carbon_item ? carbon_item->index : -1, carbon_index, get_menu_label_text (menu_item, NULL), g_type_name (G_TYPE_FROM_INSTANCE (menu_item))); if (carbon_item && carbon_item->index != carbon_index) { if (debug) g_printerr ("%s: -> not matching, deleting\n", G_STRFUNC); DeleteMenuItem (carbon_item->menu, carbon_index); carbon_item = NULL; } if (!carbon_item) { GtkWidget *label = NULL; const gchar *label_text; CFStringRef cfstr = NULL; MenuItemAttributes attributes = 0; if (debug) g_printerr ("%s: -> creating new\n", G_STRFUNC); label_text = get_menu_label_text (menu_item, &label); if (label_text) cfstr = CFStringCreateWithCString (NULL, label_text, kCFStringEncodingUTF8); if (GTK_IS_SEPARATOR_MENU_ITEM (menu_item)) attributes |= kMenuItemAttrSeparator; if (!gtk_widget_is_sensitive (menu_item)) attributes |= kMenuItemAttrDisabled; if (!gtk_widget_get_visible (menu_item)) attributes |= kMenuItemAttrHidden; InsertMenuItemTextWithCFString (carbon_menu, cfstr, carbon_index - 1, attributes, 0); SetMenuItemProperty (carbon_menu, carbon_index, IGE_QUARTZ_MENU_CREATOR, IGE_QUARTZ_ITEM_WIDGET, sizeof (menu_item), &menu_item); if (cfstr) CFRelease (cfstr); carbon_item = carbon_menu_item_connect (menu_item, label, carbon_menu, carbon_index); if (GTK_IS_CHECK_MENU_ITEM (menu_item)) carbon_menu_item_update_active (carbon_item, menu_item); carbon_menu_item_update_accel_closure (carbon_item, menu_item); if (gtk_menu_item_get_submenu (GTK_MENU_ITEM (menu_item))) carbon_menu_item_update_submenu (carbon_item, menu_item); } carbon_index++; } g_list_free (children); }
static void sync_menu_shell (GtkMenuShell *menu_shell, MenuRef carbon_menu, gboolean toplevel) { GList *children; GList *l; MenuItemIndex carbon_index = 1; carbon_menu_connect (GTK_WIDGET (menu_shell), carbon_menu); children = gtk_container_get_children (GTK_CONTAINER (menu_shell)); UInt16 carbon_item_count = CountMenuItems(carbon_menu); for (l = children; l; l = l->next) { GtkWidget *menu_item = l->data; CarbonMenuItem *carbon_item; if (GTK_IS_TEAROFF_MENU_ITEM (menu_item)) continue; if (toplevel && g_object_get_data (G_OBJECT (menu_item), "gtk-empty-menu-item")) continue; GtkWidget *label = NULL; const gchar *label_text = NULL; label_text = get_menu_label_text (menu_item, &label); if (label_text && strcmp(label_text, "_SKIP_") == 0) { carbon_index++; continue; } else if (!label_text) label_text = ""; MenuItemAttributes attributes = 0; if (GTK_IS_SEPARATOR_MENU_ITEM (menu_item)) attributes |= kMenuItemAttrSeparator; if (!GTK_WIDGET_IS_SENSITIVE (menu_item)) attributes |= kMenuItemAttrDisabled; if (!GTK_WIDGET_VISIBLE (menu_item)) attributes |= kMenuItemAttrHidden; CFStringRef cfstr = CFStringCreateWithCString (NULL, label_text, kCFStringEncodingUTF8); if (carbon_index > carbon_item_count) AppendMenuItemTextWithCFString(carbon_menu, cfstr, attributes, 0, NULL); else if (!toplevel && (carbon_index > carbon_item_count)) InsertMenuItemTextWithCFString (carbon_menu, cfstr, carbon_index, attributes, 0); else SetMenuItemTextWithCFString(carbon_menu, carbon_index, cfstr); CFRelease (cfstr); MenuItemAttributes c_attributes = kMenuItemAttrSectionHeader | kMenuItemAttrAutoDisable; if (!(attributes & kMenuItemAttrDisabled)) c_attributes |= kMenuItemAttrDisabled; if (!(attributes & kMenuItemAttrSeparator)) c_attributes |= kMenuItemAttrSeparator; if (!(attributes & kMenuItemAttrHidden)) c_attributes |= kMenuItemAttrHidden; ChangeMenuItemAttributes(carbon_menu, carbon_index, attributes, c_attributes); SetMenuItemProperty (carbon_menu, carbon_index, GTK_QUARTZ_MENU_CREATOR, GTK_QUARTZ_ITEM_WIDGET, sizeof (menu_item), &menu_item); carbon_item = carbon_menu_item_connect (menu_item, label, carbon_menu, carbon_index); if (GTK_IS_CHECK_MENU_ITEM (menu_item)) carbon_menu_item_update_active (carbon_item, menu_item); carbon_menu_item_update_accel_closure (carbon_item, menu_item); if (gtk_menu_item_get_submenu (GTK_MENU_ITEM (menu_item))) carbon_menu_item_update_submenu (carbon_item, menu_item); carbon_index++; } while (carbon_index <= carbon_item_count) { DeleteMenuItem (carbon_menu, carbon_index); carbon_index++; } g_list_free (children); }