/* * Adds menu items to a context menu which is just about to appear! * Add commands to aid in editing a BonoboDockItem, with signals pointing to * other functions in this file. */ static void gb_bonobo_dock_item_create_popup_menu (GtkWidget * widget, GbWidgetCreateMenuData * data) { GtkWidget *menuitem; /* We can't add items next to floating items or items that have the BONOBO_DOCK_ITEM_BEH_EXCLUSIVE flag set. */ if (!BONOBO_DOCK_ITEM (widget)->is_floating && !(BONOBO_DOCK_ITEM (widget)->behavior & BONOBO_DOCK_ITEM_BEH_EXCLUSIVE)) { menuitem = gtk_menu_item_new_with_label (_("Add dock item before")); gtk_widget_show (menuitem); gtk_menu_append (GTK_MENU (data->menu), menuitem); gtk_signal_connect (GTK_OBJECT (menuitem), "activate", GTK_SIGNAL_FUNC (gb_bonobo_dock_item_add_item_before), widget); menuitem = gtk_menu_item_new_with_label (_("Add dock item after")); gtk_widget_show (menuitem); gtk_menu_append (GTK_MENU (data->menu), menuitem); gtk_signal_connect (GTK_OBJECT (menuitem), "activate", GTK_SIGNAL_FUNC (gb_bonobo_dock_item_add_item_after), widget); } }
static GtkWidget * dock_item_build (GladeXML *xml, GType widget_type, GladeWidgetInfo *info) { GtkWidget *w; w = glade_standard_build_widget (xml, widget_type, info); g_free(BONOBO_DOCK_ITEM (w)->name); BONOBO_DOCK_ITEM (w)->name = g_strdup (info->name); return w; }
static void dock_item_set_shadow_type (GladeXML *xml, GtkWidget *widget, const char *name, const char *value) { bonobo_dock_item_set_shadow_type ( BONOBO_DOCK_ITEM (widget), glade_enum_from_string (GTK_TYPE_SHADOW_TYPE, value)); }
/* SPECIAL CODE: "placement", "band", "position", "offset" and "behavior" are now packing properties, so we have this special function to save them, which is called directly in gb_widget_save(). */ void gb_bonobo_dock_item_save_packing_properties (GtkWidget *parent, GtkWidget *widget, GbWidgetGetArgData * data) { char *behavior; save_start_tag (data, "packing"); if (BONOBO_DOCK_ITEM (widget)->is_floating) { gb_widget_output_string (data, Placement, "BONOBO_DOCK_FLOATING"); } else { BonoboDockPlacement placement; gint band_num, position, offset, idx; if (gb_bonobo_dock_item_find_position (BONOBO_DOCK_ITEM (widget), &placement, &band_num, &position, &offset)) { idx = glade_util_int_array_index (GladePlacementValues, GladePlacementSize, placement); if (idx != -1) gb_widget_output_string (data, Placement, GladePlacementSymbols[idx]); gb_widget_output_int (data, BandNum, band_num); gb_widget_output_int (data, Position, position); gb_widget_output_int (data, Offset, offset); } else { g_warning ("Dock band not found"); } } behavior = glade_util_string_from_flags (BONOBO_TYPE_DOCK_ITEM_BEHAVIOR, BONOBO_DOCK_ITEM (widget)->behavior); save_string (data, Behavior, behavior); g_free (behavior); save_end_tag (data, "packing"); }
/* If the widgets properties are currently shown, we update them if necessary. */ static void gb_bonobo_dock_item_drag_end (GtkWidget *widget, gpointer user_data) { if (property_get_widget () == widget) { /* The orientation is only useful for floating items. */ property_set_sensitive (Orientation, BONOBO_DOCK_ITEM (widget)->is_floating); } }
static void gb_bonobo_dock_item_add_item (BonoboDockItem * existing_dock_item, gboolean after) { BonoboDock *dock; BonoboDockBand *dock_band; GtkWidget *dock_item, *placeholder; BonoboDockPlacement placement; gint band_num, position, offset; if (!gb_bonobo_dock_item_find_position (BONOBO_DOCK_ITEM (existing_dock_item), &placement, &band_num, &position, &offset)) { g_warning ("Dock band not found"); return; } dock_band = BONOBO_DOCK_BAND (GTK_WIDGET (existing_dock_item)->parent); dock = BONOBO_DOCK (GTK_WIDGET (dock_band)->parent); /* Create the new dock item. */ dock_item = gb_widget_new ("BonoboDockItem", NULL); placeholder = editor_new_placeholder (); gtk_container_add (GTK_CONTAINER (dock_item), placeholder); /* Now add it at the required position. */ if (after) position++; bonobo_dock_add_item (dock, BONOBO_DOCK_ITEM (dock_item), placement, band_num, position, 0, FALSE); gtk_widget_show (dock_item); /* Show the properties of the new dock item. */ gb_widget_show_properties (dock_item); }
static void dock_item_set_behavior (GladeXML *xml, GtkWidget *widget, const char *name, const char *value) { BonoboDockItem *dock_item = BONOBO_DOCK_ITEM (widget); gchar *old_name; old_name = dock_item->name; dock_item->name = NULL; bonobo_dock_item_construct (dock_item, old_name, glade_flags_from_string ( BONOBO_TYPE_DOCK_ITEM_BEHAVIOR, value)); g_free (old_name); }
/* * Gets the properties of the widget. This is used for both displaying the * properties in the property editor, and also for saving the properties. */ static void gb_bonobo_dock_item_get_properties (GtkWidget *widget, GbWidgetGetArgData * data) { gint i; if (BONOBO_DOCK_ITEM (widget)->is_floating) { /* Orientation is only relevant when floating. */ for (i = 0; i < GladeOrientationSize; i++) { if (GladeOrientationValues[i] == BONOBO_DOCK_ITEM (widget)->orientation) { gb_widget_output_choice (data, Orientation, i, GladeOrientationSymbols[i]); } } } if (data->action == GB_SHOWING) { gb_widget_output_bool (data, Locked, BONOBO_DOCK_ITEM (widget)->behavior & BONOBO_DOCK_ITEM_BEH_LOCKED); gb_widget_output_bool (data, Exclusive, BONOBO_DOCK_ITEM (widget)->behavior & BONOBO_DOCK_ITEM_BEH_EXCLUSIVE); gb_widget_output_bool (data, NeverFloating, BONOBO_DOCK_ITEM (widget)->behavior & BONOBO_DOCK_ITEM_BEH_NEVER_FLOATING); gb_widget_output_bool (data, NeverVertical, BONOBO_DOCK_ITEM (widget)->behavior & BONOBO_DOCK_ITEM_BEH_NEVER_VERTICAL); gb_widget_output_bool (data, NeverHorizontal, BONOBO_DOCK_ITEM (widget)->behavior & BONOBO_DOCK_ITEM_BEH_NEVER_HORIZONTAL); } for (i = 0; i < sizeof (GbShadowValues) / sizeof (GbShadowValues[0]); i++) { if (GbShadowValues[i] == BONOBO_DOCK_ITEM (widget)->shadow_type) gb_widget_output_choice (data, ShadowType, i, GbShadowSymbols[i]); } if (data->action == GB_SHOWING) { /* The orientation is only useful for floating items. */ property_set_sensitive (Orientation, BONOBO_DOCK_ITEM (widget)->is_floating); } }
static void add_dock_item (GladeXML *xml, GtkWidget *parent, GladeWidgetInfo *info, GladeChildInfo *childinfo) { BonoboDockPlacement placement; guint band, offset; int position; int i; GtkWidget *child; band = offset = position = 0; placement = BONOBO_DOCK_TOP; for (i = 0; i < childinfo->n_properties; i++) { const char *name = childinfo->properties[i].name; const char *value = childinfo->properties[i].value; if (!strcmp (name, "placement")) placement = glade_enum_from_string ( BONOBO_TYPE_DOCK_PLACEMENT, value); else if (!strcmp (name, "band")) band = UINT (value); else if (!strcmp (name, "position")) position = INT (value); else if (!strcmp (name, "offset")) offset = UINT (value); } child = glade_xml_build_widget (xml, childinfo->child); bonobo_dock_add_item (BONOBO_DOCK (parent), BONOBO_DOCK_ITEM (child), placement, band, position, offset, FALSE); }
/* Outputs source to add a child menu to a BonoboDock. */ static void gb_bonobo_dock_item_write_add_child_source (GtkWidget * parent, const gchar *parent_name, GtkWidget *child, GbWidgetWriteSourceData * data) { GnomeApp *app; /* If we're adding a dock item to a GnomeApp's dock, we use the special functions to add it here. */ if ((app = glade_gnome_is_app_dock_item (parent))) { /* Children of floating items are added as normal. */ if (BONOBO_DOCK_ITEM (parent)->is_floating) { source_add (data, " gtk_container_add (GTK_CONTAINER (%s), %s);\n", parent_name, data->wname); } else if (GTK_IS_MENU_BAR (child)) { source_add (data, " gnome_app_create_menus (GNOME_APP (%s), %s_uiinfo);\n", data->component_name, data->real_wname); /* Output the code to install the menu hints, if the GnomeApp has a status bar. This must be output after the code to create the GnomeAppBar is output, so we add it to the same buffer as the signal connections. */ if (app->statusbar) { source_add_to_buffer (data, GLADE_SIGNAL_CONNECTIONS, " gnome_app_install_menu_hints (GNOME_APP (%s), %s_uiinfo);\n", data->component_name, data->real_wname); } } else { BonoboDockPlacement placement; BonoboDockItemBehavior behavior; const gchar *placement_string; gint idx, band_num, position, offset; gchar *prefix, *prefix2; if (gb_bonobo_dock_item_find_position (BONOBO_DOCK_ITEM (parent), &placement, &band_num, &position, &offset)) { idx = glade_util_int_array_index (GladePlacementValues, GladePlacementSize, placement); if (idx == -1) { g_warning ("BonoboDock placement not found"); placement = 0; } placement_string = GladePlacementSymbols[idx]; if (GTK_IS_TOOLBAR (child)) { source_add (data, " gnome_app_add_toolbar (GNOME_APP (%s), GTK_TOOLBAR (%s), %s,\n", data->component_name, data->wname, source_make_string (data->wname, FALSE)); } else { source_add (data, " gnome_app_add_docked (GNOME_APP (%s), %s, %s,\n", data->component_name, data->wname, source_make_string (data->wname, FALSE)); } source_add (data, " "); behavior = BONOBO_DOCK_ITEM (parent)->behavior; prefix = ""; prefix2 = "\n | "; if (behavior == BONOBO_DOCK_ITEM_BEH_NORMAL) { source_add (data, "%sBONOBO_DOCK_ITEM_BEH_NORMAL", prefix); } else { if (behavior & BONOBO_DOCK_ITEM_BEH_EXCLUSIVE) { source_add (data, "%sBONOBO_DOCK_ITEM_BEH_EXCLUSIVE", prefix); prefix = prefix2; } if (behavior & BONOBO_DOCK_ITEM_BEH_NEVER_FLOATING) { source_add (data, "%sBONOBO_DOCK_ITEM_BEH_NEVER_FLOATING", prefix); prefix = prefix2; } if (behavior & BONOBO_DOCK_ITEM_BEH_NEVER_VERTICAL) { source_add (data, "%sBONOBO_DOCK_ITEM_BEH_NEVER_VERTICAL", prefix); prefix = prefix2; } if (behavior & BONOBO_DOCK_ITEM_BEH_NEVER_HORIZONTAL) { source_add (data, "%sBONOBO_DOCK_ITEM_BEH_NEVER_HORIZONTAL", prefix); prefix = prefix2; } if (behavior & BONOBO_DOCK_ITEM_BEH_LOCKED) { source_add (data, "%sBONOBO_DOCK_ITEM_BEH_LOCKED", prefix); prefix = prefix2; } } source_add (data, ",\n" " %s, %i, %i, %i);\n", placement_string, band_num, position, offset); } } } else { g_warning ("Skipping adding dock item to parent - unimplemented."); } }
/* * Writes the source code needed to create this widget. * You have to output everything necessary to create the widget here, though * there are some convenience functions to help. */ static void gb_bonobo_dock_item_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) { /* If we are in a GnomeApp's dock, we don't create the dock item here, or add it to the BonoboDock, since it is created automatically when the item is added to the GnomeApp. */ if (glade_gnome_is_app_dock_item (widget) && !BONOBO_DOCK_ITEM (widget)->is_floating) { return; } if (data->create_widget) { BonoboDockItemBehavior behavior; const gchar *prefix = "\n "; const gchar *prefix2 = "\n | "; behavior = BONOBO_DOCK_ITEM (widget)->behavior; source_add (data, " %s = bonobo_dock_item_new (%s,", data->wname, source_make_string (data->real_wname, FALSE)); if (behavior == 0) { source_add (data, "%sBONOBO_DOCK_ITEM_BEH_NORMAL);\n", prefix); } else { if (behavior & BONOBO_DOCK_ITEM_BEH_EXCLUSIVE) { source_add (data, "%sBONOBO_DOCK_ITEM_BEH_EXCLUSIVE", prefix); prefix = prefix2; } if (behavior & BONOBO_DOCK_ITEM_BEH_NEVER_FLOATING) { source_add (data, "%sBONOBO_DOCK_ITEM_BEH_NEVER_FLOATING", prefix); prefix = prefix2; } if (behavior & BONOBO_DOCK_ITEM_BEH_NEVER_VERTICAL) { source_add (data, "%sBONOBO_DOCK_ITEM_BEH_NEVER_VERTICAL", prefix); prefix = prefix2; } if (behavior & BONOBO_DOCK_ITEM_BEH_NEVER_HORIZONTAL) { source_add (data, "%sBONOBO_DOCK_ITEM_BEH_NEVER_HORIZONTAL", prefix); prefix = prefix2; } if (behavior & BONOBO_DOCK_ITEM_BEH_LOCKED) { source_add (data, "%sBONOBO_DOCK_ITEM_BEH_LOCKED", prefix); } source_add (data, ");\n"); } } gb_widget_write_standard_source (widget, data); }
/* * Sets the properties of the widget. This is used for both applying the * properties changed in the property editor, and also for loading. */ static void gb_bonobo_dock_item_set_properties (GtkWidget * widget, GbWidgetSetArgData * data) { gboolean locked, exclusive, never_floating, never_vertical, never_horizontal; gchar *shadow, *orientation; BonoboDockItemBehavior behavior; gint i; /* This is a bit of a hack, as some of the properties are now saved as packing properties instead of normal properties. */ if (data->action == GB_LOADING) { gchar *behavior_string; data->loading_type = GB_CHILD_PROPERTIES; behavior_string = load_string (data, Behavior); behavior = glade_util_flags_from_string (BONOBO_TYPE_DOCK_ITEM_BEHAVIOR, behavior_string); data->loading_type = GB_STANDARD_PROPERTIES; } else { behavior = BONOBO_DOCK_ITEM (widget)->behavior; locked = gb_widget_input_bool (data, Locked); if (data->apply) { if (locked) behavior |= BONOBO_DOCK_ITEM_BEH_LOCKED; else behavior &= ~BONOBO_DOCK_ITEM_BEH_LOCKED; /* This avoids any problems with redrawing the selection. */ if (data->action == GB_APPLYING) editor_clear_selection (NULL); gtk_widget_queue_resize (widget); } exclusive = gb_widget_input_bool (data, Exclusive); if (data->apply) { if (exclusive) behavior |= BONOBO_DOCK_ITEM_BEH_EXCLUSIVE; else behavior &= ~BONOBO_DOCK_ITEM_BEH_EXCLUSIVE; } never_floating = gb_widget_input_bool (data, NeverFloating); if (data->apply) { if (never_floating) behavior |= BONOBO_DOCK_ITEM_BEH_NEVER_FLOATING; else behavior &= ~BONOBO_DOCK_ITEM_BEH_NEVER_FLOATING; } never_vertical = gb_widget_input_bool (data, NeverVertical); if (data->apply) { if (never_vertical) behavior |= BONOBO_DOCK_ITEM_BEH_NEVER_VERTICAL; else behavior &= ~BONOBO_DOCK_ITEM_BEH_NEVER_VERTICAL; } never_horizontal = gb_widget_input_bool (data, NeverHorizontal); if (data->apply) { if (never_horizontal) behavior |= BONOBO_DOCK_ITEM_BEH_NEVER_HORIZONTAL; else behavior &= ~BONOBO_DOCK_ITEM_BEH_NEVER_HORIZONTAL; } } /* BonoboDockItem has no method for setting the behavior. */ BONOBO_DOCK_ITEM (widget)->behavior = behavior; shadow = gb_widget_input_choice (data, ShadowType); if (data->apply) { for (i = 0; i < sizeof (GbShadowValues) / sizeof (GbShadowValues[0]); i++) { if (!strcmp (shadow, GbShadowChoices[i]) || !strcmp (shadow, GbShadowSymbols[i])) { bonobo_dock_item_set_shadow_type (BONOBO_DOCK_ITEM (widget), GbShadowValues[i]); break; } } } orientation = gb_widget_input_choice (data, Orientation); if (data->apply) { for (i = 0; i < GladeOrientationSize; i++) { if (!strcmp (orientation, GladeOrientationChoices[i]) || !strcmp (orientation, GladeOrientationSymbols[i])) { bonobo_dock_item_set_orientation (BONOBO_DOCK_ITEM (widget), GladeOrientationValues[i]); /* This avoids any problems with redrawing the selection. */ if (data->action == GB_APPLYING) editor_clear_selection (NULL); /* FIXME: A test to see if changing orientation works. */ if (BONOBO_DOCK_ITEM (widget)->bin.child) gtk_widget_queue_resize (BONOBO_DOCK_ITEM (widget)->bin.child); break; } } } }