Exemplo n.º 1
0
/**
 * gtk_menu_button_get_align_widget:
 * @menu_button: a #GtkMenuButton
 *
 * Returns the parent #GtkWidget to use to line up with menu.
 *
 * Returns: (transfer none): a #GtkWidget value or %NULL
 *
 * Since: 3.6
 */
GtkWidget *
gtk_menu_button_get_align_widget (GtkMenuButton *menu_button)
{
  g_return_val_if_fail (GTK_IS_MENU_BUTTON (menu_button), NULL);

  return menu_button->priv->align_widget;
}
Exemplo n.º 2
0
/**
 * gtk_menu_button_get_menu_model:
 * @menu_button: a #GtkMenuButton
 *
 * Returns the #GMenuModel used to generate the popup.
 *
 * Returns: (transfer none): a #GMenuModel or %NULL
 *
 * Since: 3.6
 */
GMenuModel *
gtk_menu_button_get_menu_model (GtkMenuButton *menu_button)
{
  g_return_val_if_fail (GTK_IS_MENU_BUTTON (menu_button), NULL);

  return menu_button->priv->model;
}
Exemplo n.º 3
0
/**
 * gtk_menu_button_get_popup:
 * @menu_button: a #GtkMenuButton
 *
 * Returns the #GtkMenu that pops out of the button.
 * If the button does not use a #GtkMenu, this function
 * returns %NULL.
 *
 * Returns: (transfer none): a #GtkMenu or %NULL
 *
 * Since: 3.6
 */
GtkMenu *
gtk_menu_button_get_popup (GtkMenuButton *menu_button)
{
  g_return_val_if_fail (GTK_IS_MENU_BUTTON (menu_button), NULL);

  return GTK_MENU (menu_button->priv->menu);
}
Exemplo n.º 4
0
/**
 * gtk_menu_button_get_use_popover:
 * @menu_button: a #GtkMenuButton
 *
 * Returns whether a #GtkPopover or a #GtkMenu will be constructed
 * from the menu model.
 *
 * Returns: %TRUE if using a #GtkPopover
 *
 * Since: 3.12
 */
gboolean
gtk_menu_button_get_use_popover (GtkMenuButton *menu_button)
{
  g_return_val_if_fail (GTK_IS_MENU_BUTTON (menu_button), FALSE);

  return menu_button->priv->use_popover;
}
Exemplo n.º 5
0
/**
 * gtk_menu_button_get_popover:
 * @menu_button: a #GtkMenuButton
 *
 * Returns the #GtkPopover that pops out of the button.
 * If the button is not using a #GtkPopover, this function
 * returns %NULL.
 *
 * Returns: (transfer none): a #GtkPopover or %NULL
 *
 * Since: 3.12
 */
GtkPopover *
gtk_menu_button_get_popover (GtkMenuButton *menu_button)
{
  g_return_val_if_fail (GTK_IS_MENU_BUTTON (menu_button), NULL);

  return GTK_POPOVER (menu_button->priv->popover);
}
Exemplo n.º 6
0
/**
 * gtk_menu_button_set_use_popover:
 * @menu_button: a #GtkMenuButton
 * @use_popover: %TRUE to construct a popover from the menu model
 *
 * Sets whether to construct a #GtkPopover instead of #GtkMenu
 * when gtk_menu_button_set_menu_model() is called. Note that
 * this property is only consulted when a new menu model is set.
 *
 * Since: 3.12
 */
void
gtk_menu_button_set_use_popover (GtkMenuButton *menu_button,
                                 gboolean       use_popover)
{
  GtkMenuButtonPrivate *priv;

  g_return_if_fail (GTK_IS_MENU_BUTTON (menu_button));

  priv = menu_button->priv;

  use_popover = use_popover != FALSE;

  if (priv->use_popover == use_popover)
    return;

  priv->use_popover = use_popover;

  g_object_freeze_notify (G_OBJECT (menu_button));

  if (priv->model)
    gtk_menu_button_set_menu_model (menu_button, priv->model);

  g_object_notify (G_OBJECT (menu_button), "use-popover");

  g_object_thaw_notify (G_OBJECT (menu_button));
}
Exemplo n.º 7
0
/**
 * gtk_menu_button_get_direction:
 * @menu_button: a #GtkMenuButton
 *
 * Returns the direction the popup will be pointing at when popped up.
 *
 * Returns: a #GtkArrowType value
 *
 * Since: 3.6
 */
GtkArrowType
gtk_menu_button_get_direction (GtkMenuButton *menu_button)
{
  g_return_val_if_fail (GTK_IS_MENU_BUTTON (menu_button), GTK_ARROW_DOWN);

  return menu_button->priv->arrow_type;
}
Exemplo n.º 8
0
/**
 * rb_button_bar_remove_accelerators:
 * @bar: a #RBButtonBar
 * @group: the #GtkAccelGroup to remove accelerators from
 *
 * Reverses the effects of @rb_button_bar_add_accelerators.
 */
void
rb_button_bar_remove_accelerators (RBButtonBar *bar, GtkAccelGroup *group)
{
	GList *c, *l;

	c = gtk_container_get_children (GTK_CONTAINER (bar));
	for (l = c; l != NULL; l = l->next) {
		GtkWidget *widget = l->data;
		const char *accel_text;
		guint accel_key;
		GdkModifierType accel_mods;

		accel_text = g_object_get_data (G_OBJECT (widget), "rb-accel");
		if (accel_text != NULL) {
			gtk_accelerator_parse (accel_text, &accel_key, &accel_mods);
			if (accel_key != 0) {
				gtk_widget_remove_accelerator (widget, group, accel_key, accel_mods);
			}
		}

		/* handle menus attached to menu buttons */
		if (GTK_IS_MENU_BUTTON (widget)) {
			RBApplication *app = RB_APPLICATION (g_application_get_default ());
			GMenuModel *model;

			model = g_object_get_data (G_OBJECT (widget), "rb-menu-model");
			if (model != NULL)
				rb_application_set_menu_accelerators (app, model, FALSE);
		}
	}
	g_list_free (c);
}
Exemplo n.º 9
0
/* This function is used in GtkMenuToolButton, the call back will
 * be called when GtkMenuToolButton would have emitted the “show-menu”
 * signal.
 */
void
_gtk_menu_button_set_popup_with_func (GtkMenuButton                 *menu_button,
                                      GtkWidget                     *menu,
                                      GtkMenuButtonShowMenuCallback  func,
                                      gpointer                       user_data)
{
  GtkMenuButtonPrivate *priv;

  g_return_if_fail (GTK_IS_MENU_BUTTON (menu_button));
  g_return_if_fail (GTK_IS_MENU (menu) || menu == NULL);

  priv = menu_button->priv;
  priv->func = func;
  priv->user_data = user_data;

  if (priv->menu == GTK_WIDGET (menu))
    return;

  if (priv->menu)
    {
      if (gtk_widget_get_visible (priv->menu))
        gtk_menu_shell_deactivate (GTK_MENU_SHELL (priv->menu));

      g_signal_handlers_disconnect_by_func (priv->menu,
                                            menu_deactivate_cb,
                                            menu_button);
      gtk_menu_detach (GTK_MENU (priv->menu));
    }

  priv->menu = menu;

  if (priv->menu)
    {
      gtk_menu_attach_to_widget (GTK_MENU (priv->menu), GTK_WIDGET (menu_button),
                                 menu_detacher);

      gtk_widget_set_visible (priv->menu, FALSE);

      g_signal_connect_swapped (priv->menu, "deactivate",
                                G_CALLBACK (menu_deactivate_cb), menu_button);
      gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (menu_button)), "menu-button");
    }

  update_sensitivity (menu_button);

  g_object_notify (G_OBJECT (menu_button), "popup");
  g_object_notify (G_OBJECT (menu_button), "menu-model");
}
Exemplo n.º 10
0
/**
 * gtk_menu_button_set_align_widget:
 * @menu_button: a #GtkMenuButton
 * @align_widget: (allow-none): a #GtkWidget
 *
 * Sets the #GtkWidget to use to line the menu with when popped up.
 * Note that the @align_widget must contain the #GtkMenuButton itself.
 *
 * Setting it to %NULL means that the menu will be aligned with the
 * button itself.
 *
 * Note that this property is only used with menus currently,
 * and not for popovers.
 *
 * Since: 3.6
 */
void
gtk_menu_button_set_align_widget (GtkMenuButton *menu_button,
                                  GtkWidget     *align_widget)
{
  GtkMenuButtonPrivate *priv;

  g_return_if_fail (GTK_IS_MENU_BUTTON (menu_button));
  g_return_if_fail (align_widget == NULL || gtk_widget_is_ancestor (GTK_WIDGET (menu_button), align_widget));

  priv = menu_button->priv;
  if (priv->align_widget == align_widget)
    return;

  set_align_widget_pointer (menu_button, align_widget);

  g_object_notify (G_OBJECT (menu_button), "align-widget");
}
Exemplo n.º 11
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));
}
Exemplo n.º 12
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));
}
Exemplo n.º 13
0
/**
 * gtk_menu_button_set_popup:
 * @menu_button: a #GtkMenuButton
 * @menu: (allow-none): a #GtkMenu
 *
 * Sets the #GtkMenu that will be popped up when the button is clicked,
 * or %NULL to disable the button. If #GtkMenuButton:menu-model or
 * #GtkMenuButton:popover are set, they will be set to %NULL.
 *
 * Since: 3.6
 */
void
gtk_menu_button_set_popup (GtkMenuButton *menu_button,
                           GtkWidget     *menu)
{
  GtkMenuButtonPrivate *priv = menu_button->priv;

  g_return_if_fail (GTK_IS_MENU_BUTTON (menu_button));
  g_return_if_fail (GTK_IS_MENU (menu) || menu == NULL);

  g_object_freeze_notify (G_OBJECT (menu_button));

  g_clear_object (&priv->model);

  _gtk_menu_button_set_popup_with_func (menu_button, menu, NULL, NULL);

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

  update_sensitivity (menu_button);

  g_object_thaw_notify (G_OBJECT (menu_button));
}
Exemplo n.º 14
0
/**
 * gtk_menu_button_set_direction:
 * @menu_button: a #GtkMenuButton
 * @direction: a #GtkArrowType
 *
 * Sets the direction in which the popup will be popped up, as
 * well as changing the arrow’s direction. The child will not
 * be changed to an arrow if it was customized.
 *
 * If the does not fit in the available space in the given direction,
 * GTK+ will its best to keep it inside the screen and fully visible.
 *
 * If you pass %GTK_ARROW_NONE for a @direction, the popup will behave
 * as if you passed %GTK_ARROW_DOWN (although you won’t see any arrows).
 *
 * Since: 3.6
 */
void
gtk_menu_button_set_direction (GtkMenuButton *menu_button,
                               GtkArrowType   direction)
{
  GtkMenuButtonPrivate *priv = menu_button->priv;
  GtkWidget *child;

  g_return_if_fail (GTK_IS_MENU_BUTTON (menu_button));

  if (priv->arrow_type == direction)
    return;

  priv->arrow_type = direction;
  g_object_notify (G_OBJECT (menu_button), "direction");

  /* Is it custom content? We don't change that */
  child = gtk_bin_get_child (GTK_BIN (menu_button));
  if (priv->arrow_widget != child)
    return;

  set_arrow_type (GTK_IMAGE (child), priv->arrow_type);
  update_popover_direction (menu_button);
}
Exemplo n.º 15
0
/**
 * totem_interface_create_header_button:
 * @header: The header widget to put the button in
 * @button: The button to use in the header
 * @icon_name: The icon name for the button image
 * @pack_type: A #GtkPackType to tell us where to include the button
 *
 * Put the given @icon_name into @button, and pack @button into @header
 * according to @pack_type.
 *
 * Return value: (transfer none): the button passed as input
 */
GtkWidget *
totem_interface_create_header_button (GtkWidget  *header,
				      GtkWidget  *button,
				      const char *icon_name,
				      GtkPackType pack_type)
{
	GtkWidget *image;
	GtkStyleContext *context;

	image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_MENU);
	gtk_button_set_image (GTK_BUTTON (button), image);
	context = gtk_widget_get_style_context (button);
	gtk_style_context_add_class (context, "image-button");
	g_object_set (G_OBJECT (button), "valign", GTK_ALIGN_CENTER, NULL);
	if (GTK_IS_MENU_BUTTON (button))
		      g_object_set (G_OBJECT (button), "use-popover", TRUE, NULL);

	if (pack_type == GTK_PACK_END)
		gtk_header_bar_pack_end (GTK_HEADER_BAR (header), button);
	else
		gtk_header_bar_pack_start (GTK_HEADER_BAR (header), button);

	return button;
}