void
xplayer_search_entry_add_source (XplayerSearchEntry *self,
			       const gchar      *id,
			       const gchar      *label,
			       int               priority)
{
	GtkWidget *item;

	g_return_if_fail (XPLAYER_IS_SEARCH_ENTRY (self));

	if (self->priv->menu == NULL) {
		self->priv->menu = gtk_menu_new ();
		gtk_menu_button_set_popup (GTK_MENU_BUTTON (self->priv->button),
					   self->priv->menu);
		gd_tagged_entry_add_tag (GD_TAGGED_ENTRY (self->priv->entry),
					 SOURCE_ID, label);
	}

	item = gtk_radio_menu_item_new_with_label (self->priv->group, label);
	self->priv->group = g_slist_prepend (self->priv->group, item);

	g_object_set_data_full (G_OBJECT (item), "id", g_strdup (id), g_free);
	g_object_set_data_full (G_OBJECT (item), "label", g_strdup (label), g_free);
	g_object_set_data (G_OBJECT (item), "priority", GINT_TO_POINTER (priority));

	g_signal_connect (item, "toggled",
			  G_CALLBACK (item_toggled), self);

	insert_item_sorted (self, priority, item);
}
示例#2
0
static void
gtk_menu_button_set_property (GObject      *object,
                              guint         property_id,
                              const GValue *value,
                              GParamSpec   *pspec)
{
  GtkMenuButton *self = GTK_MENU_BUTTON (object);

  switch (property_id)
    {
      case PROP_POPUP:
        gtk_menu_button_set_popup (self, g_value_get_object (value));
        break;
      case PROP_MENU_MODEL:
        gtk_menu_button_set_menu_model (self, g_value_get_object (value));
        break;
      case PROP_ALIGN_WIDGET:
        gtk_menu_button_set_align_widget (self, g_value_get_object (value));
        break;
      case PROP_DIRECTION:
        gtk_menu_button_set_direction (self, g_value_get_enum (value));
        break;
      case PROP_USE_POPOVER:
        gtk_menu_button_set_use_popover (self, g_value_get_boolean (value));
        break;
      case PROP_POPOVER:
        gtk_menu_button_set_popover (self, g_value_get_object (value));
        break;
      default:
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
    }
}
示例#3
0
/**
 * gtk_menu_button_set_menu_model:
 * @menu_button: a #GtkMenuButton
 * @menu_model: (allow-none): a #GMenuModel
 *
 * Sets the #GMenuModel from which the popup will be constructed,
 * or %NULL to disable the button.
 *
 * Depending on the value of #GtkMenuButton:use-popover, either a
 * #GtkMenu will be created with gtk_menu_new_from_model(), or a
 * #GtkPopover with gtk_popover_new_from_model(). In either case,
 * actions will be connected as documented for these functions.
 *
 * If #GtkMenuButton:popup or #GtkMenuButton:popover are already set,
 * their content will be lost and replaced by the newly created popup.
 *
 * Since: 3.6
 */
void
gtk_menu_button_set_menu_model (GtkMenuButton *menu_button,
                                GMenuModel    *menu_model)
{
  GtkMenuButtonPrivate *priv;

  g_return_if_fail (GTK_IS_MENU_BUTTON (menu_button));
  g_return_if_fail (G_IS_MENU_MODEL (menu_model) || menu_model == NULL);

  priv = menu_button->priv;

  g_object_freeze_notify (G_OBJECT (menu_button));

  if (menu_model)
    g_object_ref (menu_model);

  if (menu_model)
    {
      if (priv->use_popover)
        {
          GtkWidget *popover;

          popover = gtk_popover_new_from_model (GTK_WIDGET (menu_button), menu_model);
          gtk_menu_button_set_popover (menu_button, popover);
        }
      else
        {
          GtkWidget *menu;

          menu = gtk_menu_new_from_model (menu_model);
          gtk_widget_show_all (menu);
          gtk_menu_button_set_popup (menu_button, menu);
        }
    }
  else
    {
      gtk_menu_button_set_popup (menu_button, NULL);
      gtk_menu_button_set_popover (menu_button, NULL);
    }

  priv->model = menu_model;
  g_object_notify (G_OBJECT (menu_button), "menu-model");

  g_object_thaw_notify (G_OBJECT (menu_button));
}
示例#4
0
/**
 * gtk_menu_button_set_popover:
 * @menu_button: a #GtkMenuButton
 * @popover: (allow-none): a #GtkPopover
 *
 * Sets the #GtkPopover that will be popped up when the button is
 * clicked, or %NULL to disable the button. If #GtkMenuButton:menu-model
 * or #GtkMenuButton:popup are set, they will be set to %NULL.
 *
 * Since: 3.12
 */
void
gtk_menu_button_set_popover (GtkMenuButton *menu_button,
                             GtkWidget     *popover)
{
  GtkMenuButtonPrivate *priv = menu_button->priv;

  g_return_if_fail (GTK_IS_MENU_BUTTON (menu_button));
  g_return_if_fail (GTK_IS_POPOVER (popover) || popover == NULL);

  g_object_freeze_notify (G_OBJECT (menu_button));

  g_clear_object (&priv->model);

  if (priv->popover)
    {
      if (gtk_widget_get_visible (priv->popover))
        gtk_widget_hide (priv->popover);

      g_signal_handlers_disconnect_by_func (priv->popover,
                                            menu_deactivate_cb,
                                            menu_button);

      gtk_popover_set_relative_to (GTK_POPOVER (priv->popover), NULL);
    }

  priv->popover = popover;

  if (popover)
    {
      gtk_popover_set_relative_to (GTK_POPOVER (priv->popover), GTK_WIDGET (menu_button));
      g_signal_connect_swapped (priv->popover, "closed",
                                G_CALLBACK (menu_deactivate_cb), menu_button);
      update_popover_direction (menu_button);
      gtk_style_context_remove_class (gtk_widget_get_style_context (GTK_WIDGET (menu_button)), "menu-button");
    }

  if (popover && priv->menu)
    gtk_menu_button_set_popup (menu_button, NULL);

  update_sensitivity (menu_button);

  g_object_notify (G_OBJECT (menu_button), "popover");
  g_object_notify (G_OBJECT (menu_button), "menu-model");
  g_object_thaw_notify (G_OBJECT (menu_button));
}
void
xplayer_search_entry_remove_source (XplayerSearchEntry *self,
				  const gchar *id)
{
	guint num_items;

	g_return_if_fail (XPLAYER_IS_SEARCH_ENTRY (self));

	/* FIXME
	 * - implement
	 * - don't forget to remove tag
	 * - check if it's the currently selected source and notify of the change if so */

	num_items = 1;

	if (num_items == 0) {
		gtk_menu_button_set_popup (GTK_MENU_BUTTON (self->priv->button), NULL);
		g_clear_object (&self->priv->menu);
		gd_tagged_entry_remove_tag (GD_TAGGED_ENTRY (self->priv->entry), SOURCE_ID);
	}
}
void
headerbarui_update_menubutton()
{
    GtkWindow *mainwin;
    GtkWidget *menubar;
    static GtkMenu *menu;

    mainwin = GTK_WINDOW (gtkui_plugin->get_mainwin ());
    menubar = lookup_widget (GTK_WIDGET(mainwin), "menubar");

    menu = GTK_MENU (gtk_menu_new ());

    GList *l, *children;
    children = gtk_container_get_children(GTK_CONTAINER (menubar));
    for (l = children; l; l = l->next)
    {
        gtk_container_add(GTK_CONTAINER(menu), g_object_clone(l->data));
    }
    g_list_free(children);
    gtk_menu_button_set_popup(GTK_MENU_BUTTON (headerbar_menubtn), GTK_WIDGET(menu));
}
示例#7
0
文件: widgets.c 项目: GNOME/gtk
static WidgetInfo *
create_menu_button (void)
{
  GtkWidget *widget;
  GtkWidget *image;
  GtkWidget *menu;
  GtkWidget *vbox;

  widget = gtk_menu_button_new ();
  image = gtk_image_new ();
  gtk_image_set_from_icon_name (GTK_IMAGE (image), "emblem-system-symbolic");
  gtk_container_add (GTK_CONTAINER (widget), image);
  menu = gtk_menu_new ();
  gtk_menu_button_set_popup (GTK_MENU_BUTTON (widget), menu);

  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 3);
  gtk_container_add (GTK_CONTAINER (vbox), widget);
  gtk_widget_set_halign (widget, GTK_ALIGN_CENTER);
  gtk_widget_set_valign (widget, GTK_ALIGN_CENTER);

  gtk_container_add (GTK_CONTAINER (vbox), gtk_label_new ("Menu Button"));

  return new_widget_info ("menu-button", vbox, SMALL);
}
示例#8
0
int main (int argc, char **argv)
{
	GtkWidget *window;
	GtkWidget *button;
	GtkWidget *grid;
	GtkWidget *entry;
	GtkWidget *menu_widget;
	GtkAccelGroup *accel_group;
	guint i;
	GMenu *menu;

	gtk_init (&argc, &argv);

	window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
	gtk_window_resize (GTK_WINDOW (window), 400, 300);

	grid = gtk_grid_new ();
	gtk_container_add (GTK_CONTAINER (window), grid);

	accel_group = gtk_accel_group_new ();
	gtk_window_add_accel_group (GTK_WINDOW (window), accel_group);

	/* Button next to entry */
	entry = gtk_entry_new ();
	gtk_grid_attach (GTK_GRID (grid),
			 entry,
			 0, 0,
			 1, 1);
	button = gtk_menu_button_new ();
	gtk_grid_attach (GTK_GRID (grid),
			 button,
			 1, 0,
			 1, 1);

	/* Button with GtkMenu */
	menu_widget = gtk_menu_new ();
	for (i = 5; i > 0; i--) {
		GtkWidget *item;

		if (i == 3) {
			item = gtk_menu_item_new_with_mnemonic ("_Copy");
		} else {
			char *label;

			label = g_strdup_printf ("Item _%d", i);
			item = gtk_menu_item_new_with_mnemonic (label);
			g_free (label);
		}
		gtk_menu_item_set_use_underline (GTK_MENU_ITEM (item), TRUE);
		gtk_menu_attach (GTK_MENU (menu_widget),
				 item,
				 0, 1,
				 i - 1, i);
	}
	gtk_widget_show_all (menu_widget);

	button = gtk_menu_button_new ();
	gtk_menu_button_set_popup (GTK_MENU_BUTTON (button), menu_widget);
	gtk_grid_attach (GTK_GRID (grid),
			 button,
			 1, 1,
			 1, 1);
	gtk_widget_show (create_prop_editor (G_OBJECT (button), 0));

	/* Button with GMenuModel */
	menu = g_menu_new ();
	for (i = 5; i > 0; i--) {
		char *label;
                GMenuItem *item;
		label = g_strdup_printf ("Item _%d", i);
                item = g_menu_item_new (label, NULL);
                if (i == 3)
                  g_menu_item_set_attribute (item, "icon", "s", "preferences-desktop-locale-symbolic");
		g_menu_insert_item (menu, i - 1, item);
                g_object_unref (item);
		g_free (label);
	}
	button = gtk_menu_button_new ();
	gtk_menu_button_set_menu_model (GTK_MENU_BUTTON (button), G_MENU_MODEL (menu));
	gtk_grid_attach (GTK_GRID (grid),
			 button,
			 1, 2,
			 1, 1);

	gtk_widget_show_all (window);

	gtk_main ();

	return 0;
}
static void
gth_contact_sheet_theme_dialog_init (GthContactSheetThemeDialog *self)
{
	GtkWidget *content;

	self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GTH_TYPE_CONTACT_SHEET_THEME_DIALOG, GthContactSheetThemeDialogPrivate);
	self->priv->builder = _gtk_builder_new_from_file ("contact-sheet-theme-properties.ui", "contact_sheet");
	self->priv->theme = NULL;
	self->priv->all_themes = NULL;

	gtk_window_set_title (GTK_WINDOW (self), _("Theme Properties"));
	gtk_window_set_resizable (GTK_WINDOW (self), TRUE);
	gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (self))), 5);
	gtk_container_set_border_width (GTK_CONTAINER (self), 5);

	content = _gtk_builder_get_widget (self->priv->builder, "theme_properties");
	gtk_container_set_border_width (GTK_CONTAINER (content), 5);
	gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (self))), content, TRUE, TRUE, 0);

	/* "Copy from" button */

	self->priv->copy_from_button = gtk_menu_button_new ();
	gtk_container_add (GTK_CONTAINER (self->priv->copy_from_button), gtk_label_new_with_mnemonic (_("Copy _From")));
	gtk_widget_show_all (self->priv->copy_from_button);

	self->priv->copy_from_menu = gtk_menu_new ();
	gtk_menu_button_set_popup (GTK_MENU_BUTTON (self->priv->copy_from_button), self->priv->copy_from_menu);

	gtk_dialog_add_action_widget (GTK_DIALOG (self), self->priv->copy_from_button, 100);

	/* other buttons */

	gtk_dialog_add_button (GTK_DIALOG (self),
			       _GTK_LABEL_CANCEL,
			       GTK_RESPONSE_CANCEL);
	gtk_dialog_add_button (GTK_DIALOG (self),
			       _GTK_LABEL_SAVE,
			       GTK_RESPONSE_OK);
	gtk_dialog_set_default_response (GTK_DIALOG (self), GTK_RESPONSE_OK);

	g_signal_connect (GET_WIDGET ("preview_area"),
			  "draw",
			  G_CALLBACK (preview_area_draw_cb),
			  self);
	g_signal_connect_swapped (GET_WIDGET ("solid_color_radiobutton"),
			  	  "toggled",
			  	  G_CALLBACK (update_preview),
			  	  self);
	g_signal_connect_swapped (GET_WIDGET ("gradient_radiobutton"),
			  	  "toggled",
			  	  G_CALLBACK (update_preview),
			  	  self);
	g_signal_connect_swapped (GET_WIDGET ("h_gradient_checkbutton"),
			  	  "toggled",
			  	  G_CALLBACK (update_preview),
			  	  self);
	g_signal_connect_swapped (GET_WIDGET ("v_gradient_checkbutton"),
			  	  "toggled",
			  	  G_CALLBACK (update_preview),
			  	  self);
	g_signal_connect_swapped (GET_WIDGET ("solid_color_colorpicker"),
			  	  "color-set",
			  	  G_CALLBACK (update_preview),
			  	  self);
	g_signal_connect_swapped (GET_WIDGET ("h_gradient_1_colorpicker"),
			  	  "color-set",
			  	  G_CALLBACK (update_preview),
			  	  self);
	g_signal_connect_swapped (GET_WIDGET ("h_gradient_2_colorpicker"),
			  	  "color-set",
			  	  G_CALLBACK (update_preview),
			  	  self);
	g_signal_connect_swapped (GET_WIDGET ("v_gradient_1_colorpicker"),
			  	  "color-set",
			  	  G_CALLBACK (update_preview),
			  	  self);
	g_signal_connect_swapped (GET_WIDGET ("v_gradient_2_colorpicker"),
			  	  "color-set",
			  	  G_CALLBACK (update_preview),
			  	  self);
	g_signal_connect_swapped (GET_WIDGET ("frame_colorpicker"),
			  	  "color-set",
			  	  G_CALLBACK (update_preview),
			  	  self);
	g_signal_connect_swapped (GET_WIDGET ("header_colorpicker"),
			  	  "color-set",
			  	  G_CALLBACK (update_preview),
			  	  self);
	g_signal_connect_swapped (GET_WIDGET ("footer_colorpicker"),
			  	  "color-set",
			  	  G_CALLBACK (update_preview),
			  	  self);
	g_signal_connect_swapped (GET_WIDGET ("caption_colorpicker"),
			  	  "color-set",
			  	  G_CALLBACK (update_preview),
			  	  self);
	g_signal_connect_swapped (GET_WIDGET ("frame_style_combobox"),
			  	  "changed",
			  	  G_CALLBACK (update_preview),
			  	  self);
	g_signal_connect_swapped (GET_WIDGET ("header_fontpicker"),
			  	  "font-set",
			  	  G_CALLBACK (update_preview),
			  	  self);
	g_signal_connect_swapped (GET_WIDGET ("footer_fontpicker"),
			  	  "font-set",
			  	  G_CALLBACK (update_preview),
			  	  self);
	g_signal_connect_swapped (GET_WIDGET ("caption_fontpicker"),
			  	  "font-set",
			  	  G_CALLBACK (update_preview),
			  	  self);
	g_signal_connect (GET_WIDGET ("h_gradient_swap_button"),
			  "clicked",
			  G_CALLBACK (h_gradient_swap_button_clicked_cb),
			  self);
	g_signal_connect (GET_WIDGET ("v_gradient_swap_button"),
			  "clicked",
			  G_CALLBACK (v_gradient_swap_button_clicked_cb),
			  self);
}
示例#10
0
static void
nautilus_toolbar_constructed (GObject *obj)
{
	NautilusToolbar *self = NAUTILUS_TOOLBAR (obj);
	GtkWidget *toolbar;
	GtkWidget *button;
	GtkWidget *menu;
	GtkWidget *box;
	GtkWidget *separator;
	GtkUIManager *ui_manager;
	gboolean rtl;

	G_OBJECT_CLASS (nautilus_toolbar_parent_class)->constructed (obj);

	gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (self)),
				     "header-bar");

	self->priv->toolbar = toolbar = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
	g_object_set (toolbar, "margin", 8, NULL);
	gtk_container_add (GTK_CONTAINER (self), toolbar);

	rtl = gtk_widget_get_default_direction () == GTK_TEXT_DIR_RTL;

	ui_manager = nautilus_window_get_ui_manager (self->priv->window);

	gtk_style_context_set_junction_sides (gtk_widget_get_style_context (GTK_WIDGET (self)),
					      GTK_JUNCTION_BOTTOM);

	/* Back and Forward */
	box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);

	/* Back */
	button = toolbar_create_toolbutton (self, FALSE, FALSE, NAUTILUS_ACTION_BACK, NULL);
	gtk_widget_set_valign (button, GTK_ALIGN_CENTER);
	gtk_action_set_icon_name (gtk_activatable_get_related_action (GTK_ACTIVATABLE (button)),
				  rtl ? "go-previous-rtl-symbolic" : "go-previous-symbolic");
	navigation_button_setup_menu (self, button, NAUTILUS_NAVIGATION_DIRECTION_BACK);
	gtk_container_add (GTK_CONTAINER (box), button);

	/* Forward */
	button = toolbar_create_toolbutton (self, FALSE, FALSE, NAUTILUS_ACTION_FORWARD, NULL);
	gtk_widget_set_valign (button, GTK_ALIGN_CENTER);
	gtk_action_set_icon_name (gtk_activatable_get_related_action (GTK_ACTIVATABLE (button)),
				  rtl ? "go-next-rtl-symbolic" : "go-next-symbolic");
	navigation_button_setup_menu (self, button, NAUTILUS_NAVIGATION_DIRECTION_FORWARD);
	gtk_container_add (GTK_CONTAINER (box), button);

	gtk_style_context_add_class (gtk_widget_get_style_context (box),
				     GTK_STYLE_CLASS_RAISED);
	gtk_style_context_add_class (gtk_widget_get_style_context (box),
				     GTK_STYLE_CLASS_LINKED);

	gtk_box_pack_start (GTK_BOX (toolbar), box, FALSE, FALSE, 0);

	if (rtl) {
		gtk_widget_set_margin_left (box, 12);
	} else {
		gtk_widget_set_margin_right (box, 12);
	}

	/* regular path bar */
	box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);

	self->priv->path_bar = g_object_new (NAUTILUS_TYPE_PATH_BAR, NULL);
	gtk_box_pack_start (GTK_BOX (box), self->priv->path_bar, TRUE, TRUE, 0);

	/* entry-like location bar */
	self->priv->location_entry = nautilus_location_entry_new ();
	gtk_box_pack_start (GTK_BOX (box), self->priv->location_entry, TRUE, TRUE, 0);

	gtk_box_pack_start (GTK_BOX (toolbar), box, TRUE, TRUE, 0);

	/* search */
	button = toolbar_create_toolbutton (self, FALSE, TRUE, NAUTILUS_ACTION_SEARCH, NULL);
	gtk_widget_set_valign (button, GTK_ALIGN_CENTER);
	gtk_container_add (GTK_CONTAINER (toolbar), button);
	if (rtl) {
		gtk_widget_set_margin_right (button, 76);
	} else {
		gtk_widget_set_margin_left (button, 76);
	}

	/* View buttons */
	box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);

	button = toolbar_create_toolbutton (self, FALSE, TRUE, NAUTILUS_ACTION_VIEW_LIST, NULL);
	gtk_widget_set_valign (button, GTK_ALIGN_CENTER);
	gtk_container_add (GTK_CONTAINER (box), button);
	button = toolbar_create_toolbutton (self, FALSE, TRUE, NAUTILUS_ACTION_VIEW_GRID, NULL);
	gtk_widget_set_valign (button, GTK_ALIGN_CENTER);
	gtk_container_add (GTK_CONTAINER (box), button);
	button = toolbar_create_toolbutton (self, TRUE, FALSE, "go-down-symbolic", _("View options"));
	gtk_widget_set_valign (button, GTK_ALIGN_CENTER);
	gtk_container_add (GTK_CONTAINER (box), button);
	menu = gtk_ui_manager_get_widget (ui_manager, "/ViewMenu");
	gtk_menu_button_set_popup (GTK_MENU_BUTTON (button), menu);

	gtk_style_context_add_class (gtk_widget_get_style_context (box),
				     GTK_STYLE_CLASS_RAISED);
	gtk_style_context_add_class (gtk_widget_get_style_context (box),
				     GTK_STYLE_CLASS_LINKED);

	gtk_container_add (GTK_CONTAINER (toolbar), box);
	if (rtl) {
		gtk_widget_set_margin_right (box, 12);
	} else {
		gtk_widget_set_margin_left (box, 12);
	}

	/* Action Menu */
	button = toolbar_create_toolbutton (self, TRUE, FALSE, "emblem-system-symbolic", _("Location options"));
	gtk_widget_set_valign (button, GTK_ALIGN_CENTER);
	menu = gtk_ui_manager_get_widget (ui_manager, "/ActionMenu");
	gtk_widget_set_halign (menu, GTK_ALIGN_END);
	gtk_menu_button_set_popup (GTK_MENU_BUTTON (button), menu);
	gtk_actionable_set_action_name (GTK_ACTIONABLE (button), "win.gear-menu");
        g_signal_connect (menu, "key-press-event", G_CALLBACK (gear_menu_key_press), self);

	gtk_container_add (GTK_CONTAINER (toolbar), button);
	if (rtl) {
		gtk_widget_set_margin_right (button, 12);
	} else {
		gtk_widget_set_margin_left (button, 12);
	}

	/* Separator and Close */
	separator = gtk_separator_new (GTK_ORIENTATION_VERTICAL);
	gtk_container_add (GTK_CONTAINER (toolbar), separator);

	if (rtl) {
		gtk_widget_set_margin_right (separator, 8);
	} else {
		gtk_widget_set_margin_left (separator, 8);
	}

	button = gtk_button_new_from_icon_name ("window-close-symbolic",
						GTK_ICON_SIZE_MENU);
	gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE);
	g_signal_connect (button, "clicked",
			  G_CALLBACK (close_button_clicked), self);
	gtk_container_add (GTK_CONTAINER (toolbar), button);

	if (rtl) {
		gtk_widget_set_margin_right (button, 6);
	} else {
		gtk_widget_set_margin_left (button, 6);
	}

	g_signal_connect_swapped (nautilus_preferences,
				  "changed::" NAUTILUS_PREFERENCES_ALWAYS_USE_LOCATION_ENTRY,
				  G_CALLBACK (toolbar_update_appearance), self);

	gtk_widget_show_all (toolbar);
	toolbar_update_appearance (self);
}