}
static void
-up_clicked (GtkToolItem *item,
- gpointer user_data)
+up_clicked (GtkButton *item,
+ gpointer user_data)
{
GtkListStore *store;
gchar *dir_name;
}
static void
-home_clicked (GtkToolItem *item,
- gpointer user_data)
+home_clicked (GtkButton *item,
+ gpointer user_data)
{
GtkListStore *store;
</chapter>
<chapter id="MenusAndCombos">
- <title>Menus, Combo Box, Toolbar</title>
+ <title>Menus, Combo Box</title>
<xi:include href="xml/gtkcombobox.xml" />
<xi:include href="xml/gtkcomboboxtext.xml" />
- <xi:include href="xml/gtktoolshell.xml" />
- <xi:include href="xml/gtktoolbar.xml" />
- <xi:include href="xml/gtktoolitem.xml" />
- <xi:include href="xml/gtkseparatortoolitem.xml" />
- <xi:include href="xml/gtktoolbutton.xml" />
- <xi:include href="xml/gtkmenutoolbutton.xml" />
- <xi:include href="xml/gtktoggletoolbutton.xml" />
- <xi:include href="xml/gtkradiotoolbutton.xml" />
<xi:include href="xml/gtkpopover.xml" />
<xi:include href="xml/gtkpopovermenu.xml" />
<xi:include href="xml/gtkpopovermenubar.xml" />
GtkToggleButtonPrivate
</SECTION>
-<SECTION>
-<FILE>gtktoolshell</FILE>
-<TITLE>GtkToolShell</TITLE>
-GtkToolShell
-GtkToolShellIface
-gtk_tool_shell_get_ellipsize_mode
-gtk_tool_shell_get_orientation
-gtk_tool_shell_get_style
-gtk_tool_shell_get_text_alignment
-gtk_tool_shell_get_text_orientation
-gtk_tool_shell_rebuild_menu
-gtk_tool_shell_get_text_size_group
-
-<SUBSECTION Standard>
-GTK_IS_TOOL_SHELL
-GTK_TOOL_SHELL
-GTK_TOOL_SHELL_GET_IFACE
-GTK_TYPE_TOOL_SHELL
-
-<SUBSECTION Private>
-gtk_tool_shell_get_type
-</SECTION>
-
-<SECTION>
-<FILE>gtktoolbar</FILE>
-<TITLE>GtkToolbar</TITLE>
-GtkToolbar
-gtk_toolbar_new
-gtk_toolbar_insert
-gtk_toolbar_get_item_index
-gtk_toolbar_get_n_items
-gtk_toolbar_get_nth_item
-gtk_toolbar_get_drop_index
-gtk_toolbar_set_drop_highlight_item
-gtk_toolbar_set_show_arrow
-gtk_toolbar_get_show_arrow
-gtk_toolbar_get_style
-
-gtk_toolbar_set_style
-gtk_toolbar_unset_style
-
-<SUBSECTION Standard>
-GTK_TOOLBAR
-GTK_IS_TOOLBAR
-GTK_TYPE_TOOLBAR
-GTK_TOOLBAR_CLASS
-GTK_IS_TOOLBAR_CLASS
-GTK_TOOLBAR_GET_CLASS
-<SUBSECTION Private>
-gtk_toolbar_get_type
-GtkToolbarPrivate
-</SECTION>
-
-<SECTION>
-<FILE>gtktoolitem</FILE>
-<TITLE>GtkToolItem</TITLE>
-GtkToolItem
-GtkToolItemClass
-gtk_tool_item_new
-gtk_tool_item_set_homogeneous
-gtk_tool_item_get_homogeneous
-gtk_tool_item_set_expand
-gtk_tool_item_get_expand
-gtk_tool_item_set_tooltip_text
-gtk_tool_item_set_tooltip_markup
-gtk_tool_item_set_visible_horizontal
-gtk_tool_item_get_visible_horizontal
-gtk_tool_item_set_visible_vertical
-gtk_tool_item_get_visible_vertical
-gtk_tool_item_set_is_important
-gtk_tool_item_get_is_important
-gtk_tool_item_get_ellipsize_mode
-gtk_tool_item_get_orientation
-gtk_tool_item_get_toolbar_style
-gtk_tool_item_get_text_alignment
-gtk_tool_item_get_text_orientation
-gtk_tool_item_set_overflow_text
-gtk_tool_item_get_overflow_text
-gtk_tool_item_rebuild_menu
-gtk_tool_item_toolbar_reconfigured
-gtk_tool_item_get_text_size_group
-
-<SUBSECTION Standard>
-GTK_TYPE_TOOL_ITEM
-GTK_TOOL_ITEM
-GTK_TOOL_ITEM_CLASS
-GTK_IS_TOOL_ITEM
-GTK_IS_TOOL_ITEM_CLASS
-GTK_TOOL_ITEM_GET_CLASS
-
-<SUBSECTION Private>
-gtk_tool_item_get_type
-GtkToolItemPrivate
-</SECTION>
-
-<SECTION>
-<FILE>gtkseparatortoolitem</FILE>
-<TITLE>GtkSeparatorToolItem</TITLE>
-GtkSeparatorToolItem
-gtk_separator_tool_item_new
-gtk_separator_tool_item_set_draw
-gtk_separator_tool_item_get_draw
-
-<SUBSECTION Standard>
-GTK_TYPE_SEPARATOR_TOOL_ITEM
-GTK_SEPARATOR_TOOL_ITEM
-GTK_SEPARATOR_TOOL_ITEM_CLASS
-GTK_IS_SEPARATOR_TOOL_ITEM
-GTK_IS_SEPARATOR_TOOL_ITEM_CLASS
-GTK_SEPARATOR_TOOL_ITEM_GET_CLASS
-
-<SUBSECTION Private>
-gtk_separator_tool_item_get_type
-GtkSeparatorToolItemPrivate
-</SECTION>
-
-<SECTION>
-<FILE>gtktoolbutton</FILE>
-<TITLE>GtkToolButton</TITLE>
-GtkToolButton
-GtkToolButtonClass
-gtk_tool_button_new
-gtk_tool_button_set_label
-gtk_tool_button_get_label
-gtk_tool_button_set_use_underline
-gtk_tool_button_get_use_underline
-gtk_tool_button_set_icon_name
-gtk_tool_button_get_icon_name
-gtk_tool_button_set_icon_widget
-gtk_tool_button_get_icon_widget
-gtk_tool_button_set_label_widget
-gtk_tool_button_get_label_widget
-
-<SUBSECTION Standard>
-GTK_TYPE_TOOL_BUTTON
-GTK_TOOL_BUTTON
-GTK_TOOL_BUTTON_CLASS
-GTK_IS_TOOL_BUTTON
-GTK_IS_TOOL_BUTTON_CLASS
-GTK_TOOL_BUTTON_GET_CLASS
-
-<SUBSECTION Private>
-gtk_tool_button_get_type
-GtkToolButtonPrivate
-</SECTION>
-
-<SECTION>
-<FILE>gtkmenutoolbutton</FILE>
-<TITLE>GtkMenuToolButton</TITLE>
-GtkMenuToolButton
-gtk_menu_tool_button_new
-gtk_menu_tool_button_set_popover
-gtk_menu_tool_button_get_popover
-gtk_menu_tool_button_set_arrow_tooltip_text
-gtk_menu_tool_button_set_arrow_tooltip_markup
-
-<SUBSECTION Standard>
-GTK_TYPE_MENU_TOOL_BUTTON
-GTK_MENU_TOOL_BUTTON
-GTK_MENU_TOOL_BUTTON_CLASS
-GTK_IS_MENU_TOOL_BUTTON
-GTK_IS_MENU_TOOL_BUTTON_CLASS
-GTK_MENU_TOOL_BUTTON_GET_CLASS
-
-<SUBSECTION Private>
-gtk_menu_tool_button_get_type
-GtkMenuToolButtonPrivate
-</SECTION>
-
-<SECTION>
-<FILE>gtkradiotoolbutton</FILE>
-<TITLE>GtkRadioToolButton</TITLE>
-GtkRadioToolButton
-gtk_radio_tool_button_new
-gtk_radio_tool_button_new_from_widget
-gtk_radio_tool_button_get_group
-gtk_radio_tool_button_set_group
-
-<SUBSECTION Standard>
-GTK_TYPE_RADIO_TOOL_BUTTON
-GTK_RADIO_TOOL_BUTTON
-GTK_RADIO_TOOL_BUTTON_CLASS
-GTK_IS_RADIO_TOOL_BUTTON
-GTK_IS_RADIO_TOOL_BUTTON_CLASS
-GTK_RADIO_TOOL_BUTTON_GET_CLASS
-
-<SUBSECTION Private>
-gtk_radio_tool_button_get_type
-</SECTION>
-
-<SECTION>
-<FILE>gtktoggletoolbutton</FILE>
-<TITLE>GtkToggleToolButton</TITLE>
-GtkToggleToolButton
-GtkToggleToolButtonClass
-gtk_toggle_tool_button_new
-gtk_toggle_tool_button_set_active
-gtk_toggle_tool_button_get_active
-
-<SUBSECTION Standard>
-GTK_TYPE_TOGGLE_TOOL_BUTTON
-GTK_TOGGLE_TOOL_BUTTON
-GTK_TOGGLE_TOOL_BUTTON_CLASS
-GTK_IS_TOGGLE_TOOL_BUTTON
-GTK_IS_TOGGLE_TOOL_BUTTON_CLASS
-GTK_TOGGLE_TOOL_BUTTON_GET_CLASS
-
-<SUBSECTION Private>
-gtk_toggle_tool_button_get_type
-GtkToggleToolButtonPrivate
-</SECTION>
-
<SECTION>
<FILE>gtktooltip</FILE>
<TITLE>GtkTooltip</TITLE>
GtkSelectionMode
GtkShadowType
GtkStateFlags
-GtkToolbarStyle
GtkSortType
GtkIconSize
gtk_media_file_get_type
gtk_media_stream_get_type
gtk_menu_button_get_type
-gtk_menu_tool_button_get_type
gtk_message_dialog_get_type
gtk_mount_operation_get_type
gtk_native_get_type
@DISABLE_ON_W32@gtk_print_unix_dialog_get_type
gtk_progress_bar_get_type
gtk_radio_button_get_type
-gtk_radio_tool_button_get_type
gtk_range_get_type
gtk_recent_manager_get_type
gtk_revealer_get_type
gtk_search_entry_get_type
gtk_selection_model_get_type
gtk_separator_get_type
-gtk_separator_tool_item_get_type
gtk_settings_get_type
gtk_shortcut_label_get_type
gtk_shortcuts_window_get_type
gtk_text_tag_table_get_type
gtk_text_view_get_type
gtk_toggle_button_get_type
-gtk_toggle_tool_button_get_type
-gtk_toolbar_get_type
-gtk_tool_button_get_type
-gtk_tool_item_get_type
gtk_tree_drag_dest_get_type
gtk_tree_drag_source_get_type
gtk_tree_list_model_get_type
switching to menu models and actions.
</para>
<para>
- Since menus are gone, GtkMenuButton and GtkMenuToolButton also lost their
- ability to show menus, and need to be used with popovers in GTK 4.
+ Since menus are gone, GtkMenuButton also lost its ability to show menus,
+ and needs to be used with popovers in GTK 4.
</para>
</section>
<section>
- <title>GtkToolbar overflow handling has changed</title>
+ <title>GtkToolbar has been removed</title>
<para>
- The handling of overflow in toolbars has been simplified.
- Instead of creating a proxy menuitem and setting it with
- gtk_tool_item_set_proxy_menu_item(), you simply provide
- a label for the overflow menu with gtk_tool_item_set_overflow_text().
- GTK will figure out itself whether to create a check- or
- radioitem as proxy.
+ Toolbars were using outdated concepts such as requiring special toolitem
+ widgets.
+ </para>
+ <para>
+ Toolbars should be replaced by using a GtkBox with regular widgets instead.
</para>
</section>
<link linkend="GtkPaned">
<inlinegraphic fileref="panes.png" format="PNG"></inlinegraphic>
</link>
- <link linkend="GtkToolbar">
- <inlinegraphic fileref="toolbar.png" format="PNG"></inlinegraphic>
- </link>
<link linkend="GtkPlacesSidebar">
<inlinegraphic fileref="placessidebar.png" format="PNG"></inlinegraphic>
</link>
#include <string.h>
#include <gtk/gtk.h>
#include "gtkimageaccessible.h"
-#include "gtktoolbarprivate.h"
#include "gtkimageprivate.h"
#include "gtkintl.h"
{ "zoom-out", NC_("Stock label", "Zoom _Out") }
};
+/* GTK+ internal methods */
+static gchar *
+elide_underscores (const gchar *original)
+{
+ gchar *q, *result;
+ const gchar *p, *end;
+ gsize len;
+ gboolean last_underscore;
+
+ if (!original)
+ return NULL;
+
+ len = strlen (original);
+ q = result = g_malloc (len + 1);
+ last_underscore = FALSE;
+
+ end = original + len;
+ for (p = original; p < end; p++)
+ {
+ if (!last_underscore && *p == '_')
+ last_underscore = TRUE;
+ else
+ {
+ last_underscore = FALSE;
+ if (original + 2 <= p && p + 1 <= end &&
+ p[-2] == '(' && p[-1] == '_' && p[0] != '_' && p[1] == ')')
+ {
+ q--;
+ *q = '\0';
+ p++;
+ }
+ else
+ *q++ = *p;
+ }
+ }
+
+ if (last_underscore)
+ *q++ = '_';
+
+ *q = '\0';
+
+ return result;
+}
+
static gchar *
name_from_icon_name (const gchar *icon_name)
{
label = g_dpgettext2 (GETTEXT_PACKAGE, "Stock label", name_map[i].label);
g_free (name);
- return _gtk_toolbar_elide_underscores (label);
+ return elide_underscores (label);
}
}
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkListStore, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkLockButton, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkMenuButton, g_object_unref)
-G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkMenuToolButton, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkMessageDialog, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkMountOperation, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkNotebook, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkPrintSettings, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkProgressBar, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkRadioButton, g_object_unref)
-G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkRadioToolButton, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkRange, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkRecentManager, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkRevealer, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkSearchBar, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkSearchEntry, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkSeparator, g_object_unref)
-G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkSeparatorToolItem, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkSettings, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkStackSidebar, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkSizeGroup, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkTextTagTable, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkTextView, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkToggleButton, g_object_unref)
-G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkToggleToolButton, g_object_unref)
-G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkToolButton, g_object_unref)
-G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkToolItem, g_object_unref)
-G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkToolShell, g_object_unref)
-G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkToolbar, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkTooltip, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkTreeDragDest, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkTreeDragSource, g_object_unref)
#include <gtk/gtkmediafile.h>
#include <gtk/gtkmediastream.h>
#include <gtk/gtkmenubutton.h>
-#include <gtk/gtkmenutoolbutton.h>
#include <gtk/gtkmessagedialog.h>
#include <gtk/gtkmountoperation.h>
#include <gtk/gtknative.h>
#include <gtk/gtkprintsettings.h>
#include <gtk/gtkprogressbar.h>
#include <gtk/gtkradiobutton.h>
-#include <gtk/gtkradiotoolbutton.h>
#include <gtk/gtkrange.h>
#include <gtk/gtkrecentmanager.h>
#include <gtk/gtkrender.h>
#include <gtk/gtkselection.h>
#include <gtk/gtkselectionmodel.h>
#include <gtk/gtkseparator.h>
-#include <gtk/gtkseparatortoolitem.h>
#include <gtk/gtksettings.h>
#include <gtk/gtkshortcutlabel.h>
#include <gtk/gtkshortcutsgroup.h>
#include <gtk/gtktexttagtable.h>
#include <gtk/gtktextview.h>
#include <gtk/gtktogglebutton.h>
-#include <gtk/gtktoggletoolbutton.h>
-#include <gtk/gtktoolbar.h>
-#include <gtk/gtktoolbutton.h>
-#include <gtk/gtktoolitem.h>
-#include <gtk/gtktoolshell.h>
#include <gtk/gtktooltip.h>
#include <gtk/gtktestutils.h>
#include <gtk/gtktreednd.h>
* @GTK_ORIENTATION_VERTICAL: The element is in vertical orientation.
*
* Represents the orientation of widgets and other objects which can be switched
- * between horizontal and vertical orientation on the fly, like #GtkToolbar or
+ * between horizontal and vertical orientation on the fly, like #GtkBox or
* #GtkGesturePan.
*/
typedef enum
/* Widget states */
-/**
- * GtkToolbarStyle:
- * @GTK_TOOLBAR_ICONS: Buttons display only icons in the toolbar.
- * @GTK_TOOLBAR_TEXT: Buttons display only text labels in the toolbar.
- * @GTK_TOOLBAR_BOTH: Buttons display text and icons in the toolbar.
- * @GTK_TOOLBAR_BOTH_HORIZ: Buttons display icons and text alongside each
- * other, rather than vertically stacked
- *
- * Used to customize the appearance of a #GtkToolbar. Note that
- * setting the toolbar style overrides the user’s preferences
- * for the default toolbar style. Note that if the button has only
- * a label set and GTK_TOOLBAR_ICONS is used, the label will be
- * visible, and vice versa.
- */
-typedef enum
-{
- GTK_TOOLBAR_ICONS,
- GTK_TOOLBAR_TEXT,
- GTK_TOOLBAR_BOTH,
- GTK_TOOLBAR_BOTH_HORIZ
-} GtkToolbarStyle;
-
/**
* GtkWrapMode:
* @GTK_WRAP_NONE: do not wrap lines; just make the text area wider
+++ /dev/null
-/* GTK - The GIMP Toolkit
- *
- * Copyright (C) 2003 Ricardo Fernandez Pascual
- * Copyright (C) 2004 Paolo Borelli
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "config.h"
-
-#include "gtkmenutoolbutton.h"
-
-#include "gtktogglebutton.h"
-#include "gtkmenubutton.h"
-#include "gtkmenubuttonprivate.h"
-#include "gtkbox.h"
-#include "gtkpopover.h"
-#include "gtkmain.h"
-#include "gtksizerequest.h"
-#include "gtkbuildable.h"
-
-#include "gtkprivate.h"
-#include "gtkintl.h"
-
-
-/**
- * SECTION:gtkmenutoolbutton
- * @Short_description: A GtkToolItem containing a button with an additional dropdown menu
- * @Title: GtkMenuToolButton
- * @See_also: #GtkToolbar, #GtkToolButton
- *
- * A #GtkMenuToolButton is a #GtkToolItem that contains a button and
- * a small additional button with an arrow. When clicked, the arrow
- * button pops up a dropdown menu.
- *
- * Use gtk_menu_tool_button_new() to create a new
- * #GtkMenuToolButton.
- *
- * # GtkMenuToolButton as GtkBuildable
- *
- * The GtkMenuToolButton implementation of the GtkBuildable interface
- * supports adding a popover by specifying “popover” as the “type” attribute
- * of a <child> element.
- * ]|
- */
-
-typedef struct _GtkMenuToolButtonClass GtkMenuToolButtonClass;
-typedef struct _GtkMenuToolButtonPrivate GtkMenuToolButtonPrivate;
-
-struct _GtkMenuToolButton
-{
- GtkToolButton parent;
-
- GtkMenuToolButtonPrivate *priv;
-};
-
-struct _GtkMenuToolButtonClass
-{
- GtkToolButtonClass parent_class;
-
- void (*show_menu) (GtkMenuToolButton *button);
-};
-
-
-struct _GtkMenuToolButtonPrivate
-{
- GtkWidget *button;
- GtkWidget *arrow_button;
- GtkWidget *box;
-};
-
-static void gtk_menu_tool_button_buildable_interface_init (GtkBuildableIface *iface);
-static void gtk_menu_tool_button_buildable_add_child (GtkBuildable *buildable,
- GtkBuilder *builder,
- GObject *child,
- const gchar *type);
-
-enum
-{
- SHOW_MENU,
- LAST_SIGNAL
-};
-
-enum
-{
- PROP_0,
- PROP_POPOVER
-};
-
-static gint signals[LAST_SIGNAL];
-
-static GtkBuildableIface *parent_buildable_iface;
-
-G_DEFINE_TYPE_WITH_CODE (GtkMenuToolButton, gtk_menu_tool_button, GTK_TYPE_TOOL_BUTTON,
- G_ADD_PRIVATE (GtkMenuToolButton)
- G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
- gtk_menu_tool_button_buildable_interface_init))
-
-static void
-gtk_menu_tool_button_construct_contents (GtkMenuToolButton *button)
-{
- GtkMenuToolButtonPrivate *priv = button->priv;
- GtkWidget *box;
- GtkWidget *parent;
- GtkOrientation orientation;
-
- orientation = gtk_tool_item_get_orientation (GTK_TOOL_ITEM (button));
-
- if (orientation == GTK_ORIENTATION_HORIZONTAL)
- {
- box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
- gtk_menu_button_set_direction (GTK_MENU_BUTTON (priv->arrow_button), GTK_ARROW_DOWN);
- }
- else
- {
- GtkTextDirection direction;
- GtkArrowType type;
-
- box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
- direction = gtk_widget_get_direction (GTK_WIDGET (button));
- type = (direction == GTK_TEXT_DIR_LTR ? GTK_ARROW_RIGHT : GTK_ARROW_LEFT);
- gtk_menu_button_set_direction (GTK_MENU_BUTTON (priv->arrow_button), type);
- }
-
- parent = gtk_widget_get_parent (priv->button);
- if (priv->button && parent)
- {
- g_object_ref (priv->button);
- gtk_container_remove (GTK_CONTAINER (parent),
- priv->button);
- gtk_container_add (GTK_CONTAINER (box), priv->button);
- g_object_unref (priv->button);
- }
-
- parent = gtk_widget_get_parent (priv->arrow_button);
- if (priv->arrow_button && parent)
- {
- g_object_ref (priv->arrow_button);
- gtk_container_remove (GTK_CONTAINER (parent),
- priv->arrow_button);
- gtk_container_add (GTK_CONTAINER (box), priv->arrow_button);
- g_object_unref (priv->arrow_button);
- }
-
- if (priv->box)
- {
- gchar *tmp;
-
- /* Transfer a possible tooltip to the new box */
- g_object_get (priv->box, "tooltip-markup", &tmp, NULL);
-
- if (tmp)
- {
- g_object_set (box, "tooltip-markup", tmp, NULL);
- g_free (tmp);
- }
-
- /* Note: we are not destroying the button and the arrow_button
- * here because they were removed from their container above
- */
- gtk_widget_destroy (priv->box);
- }
-
- priv->box = box;
-
- gtk_container_add (GTK_CONTAINER (button), priv->box);
-
- gtk_widget_queue_resize (GTK_WIDGET (button));
-}
-
-static void
-gtk_menu_tool_button_toolbar_reconfigured (GtkToolItem *toolitem)
-{
- gtk_menu_tool_button_construct_contents (GTK_MENU_TOOL_BUTTON (toolitem));
-
- /* chain up */
- GTK_TOOL_ITEM_CLASS (gtk_menu_tool_button_parent_class)->toolbar_reconfigured (toolitem);
-}
-
-static void
-gtk_menu_tool_button_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- GtkMenuToolButton *button = GTK_MENU_TOOL_BUTTON (object);
-
- switch (prop_id)
- {
- case PROP_POPOVER:
- gtk_menu_tool_button_set_popover (button, g_value_get_object (value));
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static void
-gtk_menu_tool_button_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- GtkMenuToolButton *button = GTK_MENU_TOOL_BUTTON (object);
-
- switch (prop_id)
- {
- case PROP_POPOVER:
- g_value_set_object (value, gtk_menu_button_get_popover (GTK_MENU_BUTTON (button->priv->arrow_button)));
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static void
-gtk_menu_tool_button_class_init (GtkMenuToolButtonClass *klass)
-{
- GObjectClass *object_class;
- GtkToolItemClass *toolitem_class;
-
- object_class = (GObjectClass *)klass;
- toolitem_class = (GtkToolItemClass *)klass;
-
- object_class->set_property = gtk_menu_tool_button_set_property;
- object_class->get_property = gtk_menu_tool_button_get_property;
-
- toolitem_class->toolbar_reconfigured = gtk_menu_tool_button_toolbar_reconfigured;
-
- /**
- * GtkMenuToolButton::show-menu:
- * @button: the object on which the signal is emitted
- *
- * The ::show-menu signal is emitted before the menu is shown.
- *
- * It can be used to populate the menu on demand, using
- * gtk_menu_tool_button_set_menu().
-
- * Note that even if you populate the menu dynamically in this way,
- * you must set an empty menu on the #GtkMenuToolButton beforehand,
- * since the arrow is made insensitive if the menu is not set.
- */
- signals[SHOW_MENU] =
- g_signal_new (I_("show-menu"),
- G_OBJECT_CLASS_TYPE (klass),
- G_SIGNAL_RUN_FIRST,
- G_STRUCT_OFFSET (GtkMenuToolButtonClass, show_menu),
- NULL, NULL,
- NULL,
- G_TYPE_NONE, 0);
-
- g_object_class_install_property (object_class,
- PROP_POPOVER,
- g_param_spec_object ("popover",
- P_("Popover"),
- P_("The dropdown popover"),
- GTK_TYPE_POPOVER,
- GTK_PARAM_READWRITE));
-}
-
-static void
-gtk_menu_tool_button_init (GtkMenuToolButton *button)
-{
- GtkWidget *box;
- GtkWidget *arrow_button;
- GtkWidget *real_button;
-
- button->priv = gtk_menu_tool_button_get_instance_private (button);
-
- gtk_tool_item_set_homogeneous (GTK_TOOL_ITEM (button), FALSE);
-
- box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
-
- real_button = gtk_bin_get_child (GTK_BIN (button));
- g_object_ref (real_button);
- gtk_container_remove (GTK_CONTAINER (button), real_button);
- gtk_container_add (GTK_CONTAINER (box), real_button);
- g_object_unref (real_button);
-
- arrow_button = gtk_menu_button_new ();
- gtk_container_add (GTK_CONTAINER (box), arrow_button);
-
- gtk_container_add (GTK_CONTAINER (button), box);
- gtk_menu_button_set_align_widget (GTK_MENU_BUTTON (arrow_button),
- GTK_WIDGET (button));
-
- button->priv->button = real_button;
- button->priv->arrow_button = arrow_button;
- button->priv->box = box;
-}
-
-static void
-gtk_menu_tool_button_buildable_add_child (GtkBuildable *buildable,
- GtkBuilder *builder,
- GObject *child,
- const gchar *type)
-{
- if (type && strcmp (type, "popover") == 0)
- gtk_menu_tool_button_set_popover (GTK_MENU_TOOL_BUTTON (buildable),
- GTK_WIDGET (child));
- else
- parent_buildable_iface->add_child (buildable, builder, child, type);
-}
-
-static void
-gtk_menu_tool_button_buildable_interface_init (GtkBuildableIface *iface)
-{
- parent_buildable_iface = g_type_interface_peek_parent (iface);
- iface->add_child = gtk_menu_tool_button_buildable_add_child;
-}
-
-/**
- * gtk_menu_tool_button_new:
- * @icon_widget: (allow-none): a widget that will be used as icon widget, or %NULL
- * @label: (allow-none): a string that will be used as label, or %NULL
- *
- * Creates a new #GtkMenuToolButton using @icon_widget as icon and
- * @label as label.
- *
- * Returns: the new #GtkMenuToolButton
- **/
-GtkToolItem *
-gtk_menu_tool_button_new (GtkWidget *icon_widget,
- const gchar *label)
-{
- GtkMenuToolButton *button;
-
- button = g_object_new (GTK_TYPE_MENU_TOOL_BUTTON, NULL);
-
- if (label)
- gtk_tool_button_set_label (GTK_TOOL_BUTTON (button), label);
-
- if (icon_widget)
- gtk_tool_button_set_icon_widget (GTK_TOOL_BUTTON (button), icon_widget);
-
- return GTK_TOOL_ITEM (button);
-}
-
-static void
-_show_menu_emit (GtkMenuButton *menu_button,
- gpointer user_data)
-{
- GtkMenuToolButton *button = (GtkMenuToolButton *) user_data;
- g_signal_emit (button, signals[SHOW_MENU], 0);
-}
-
-void
-gtk_menu_tool_button_set_popover (GtkMenuToolButton *button,
- GtkWidget *popover)
-{
- GtkMenuToolButtonPrivate *priv;
-
- g_return_if_fail (GTK_IS_MENU_TOOL_BUTTON (button));
- g_return_if_fail (GTK_IS_POPOVER (popover) || popover == NULL);
-
- priv = button->priv;
-
- gtk_menu_button_set_popover (GTK_MENU_BUTTON (priv->arrow_button), popover);
- gtk_menu_button_set_create_popup_func (GTK_MENU_BUTTON (priv->arrow_button),
- _show_menu_emit, NULL, NULL);
-
- g_object_notify (G_OBJECT (button), "popover");
-}
-
-/**
- * gtk_menu_tool_button_get_popover:
- * @menu_button: a #GtkMenuToolButton
- *
- * Returns the #GtkPopover that pops out of the button.
- * If the button is not using a #GtkPopover, this function
- * returns %NULL.
- *
- * Returns: (nullable) (transfer none): a #GtkPopover or %NULL
- **/
-GtkWidget *
-gtk_menu_tool_button_get_popover (GtkMenuToolButton *button)
-{
- GtkPopover *ret;
-
- g_return_val_if_fail (GTK_IS_MENU_TOOL_BUTTON (button), NULL);
-
- ret = gtk_menu_button_get_popover (GTK_MENU_BUTTON (button->priv->arrow_button));
- if (!ret)
- return NULL;
-
- return GTK_WIDGET (ret);
-}
-
-/**
- * gtk_menu_tool_button_set_arrow_tooltip_text:
- * @button: a #GtkMenuToolButton
- * @text: text to be used as tooltip text for button’s arrow button
- *
- * Sets the tooltip text to be used as tooltip for the arrow button which
- * pops up the menu. See gtk_tool_item_set_tooltip_text() for setting a tooltip
- * on the whole #GtkMenuToolButton.
- **/
-void
-gtk_menu_tool_button_set_arrow_tooltip_text (GtkMenuToolButton *button,
- const gchar *text)
-{
- g_return_if_fail (GTK_IS_MENU_TOOL_BUTTON (button));
-
- gtk_widget_set_tooltip_text (button->priv->arrow_button, text);
-}
-
-/**
- * gtk_menu_tool_button_set_arrow_tooltip_markup:
- * @button: a #GtkMenuToolButton
- * @markup: markup text to be used as tooltip text for button’s arrow button
- *
- * Sets the tooltip markup text to be used as tooltip for the arrow button
- * which pops up the menu. See gtk_tool_item_set_tooltip_text() for setting
- * a tooltip on the whole #GtkMenuToolButton.
- **/
-void
-gtk_menu_tool_button_set_arrow_tooltip_markup (GtkMenuToolButton *button,
- const gchar *markup)
-{
- g_return_if_fail (GTK_IS_MENU_TOOL_BUTTON (button));
-
- gtk_widget_set_tooltip_markup (button->priv->arrow_button, markup);
-}
+++ /dev/null
-/* GTK - The GIMP Toolkit
- *
- * Copyright (C) 2003 Ricardo Fernandez Pascual
- * Copyright (C) 2004 Paolo Borelli
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef __GTK_MENU_TOOL_BUTTON_H__
-#define __GTK_MENU_TOOL_BUTTON_H__
-
-#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
-#error "Only <gtk/gtk.h> can be included directly."
-#endif
-
-#include <gtk/gtktoolbutton.h>
-
-G_BEGIN_DECLS
-
-#define GTK_TYPE_MENU_TOOL_BUTTON (gtk_menu_tool_button_get_type ())
-#define GTK_MENU_TOOL_BUTTON(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GTK_TYPE_MENU_TOOL_BUTTON, GtkMenuToolButton))
-#define GTK_IS_MENU_TOOL_BUTTON(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GTK_TYPE_MENU_TOOL_BUTTON))
-
-typedef struct _GtkMenuToolButton GtkMenuToolButton;
-
-GDK_AVAILABLE_IN_ALL
-GType gtk_menu_tool_button_get_type (void) G_GNUC_CONST;
-GDK_AVAILABLE_IN_ALL
-GtkToolItem *gtk_menu_tool_button_new (GtkWidget *icon_widget,
- const gchar *label);
-
-GDK_AVAILABLE_IN_ALL
-void gtk_menu_tool_button_set_popover (GtkMenuToolButton *button,
- GtkWidget *popover);
-GDK_AVAILABLE_IN_ALL
-GtkWidget *gtk_menu_tool_button_get_popover (GtkMenuToolButton *button);
-GDK_AVAILABLE_IN_ALL
-void gtk_menu_tool_button_set_arrow_tooltip_text (GtkMenuToolButton *button,
- const gchar *text);
-GDK_AVAILABLE_IN_ALL
-void gtk_menu_tool_button_set_arrow_tooltip_markup (GtkMenuToolButton *button,
- const gchar *markup);
-
-G_END_DECLS
-
-#endif /* __GTK_MENU_TOOL_BUTTON_H__ */
+++ /dev/null
-/* gtkradiotoolbutton.c
- *
- * Copyright (C) 2002 Anders Carlsson <andersca@gnome.og>
- * Copyright (C) 2002 James Henstridge <james@daa.com.au>
- * Copyright (C) 2003 Soeren Sandmann <sandmann@daimi.au.dk>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "config.h"
-#include "gtkradiotoolbutton.h"
-#include "gtkradiobutton.h"
-#include "gtkintl.h"
-#include "gtkprivate.h"
-
-
-/**
- * SECTION:gtkradiotoolbutton
- * @Short_description: A toolbar item that contains a radio button
- * @Title: GtkRadioToolButton
- * @See_also: #GtkToolbar, #GtkToolButton
- *
- * A #GtkRadioToolButton is a #GtkToolItem that contains a radio button,
- * that is, a button that is part of a group of toggle buttons where only
- * one button can be active at a time.
- *
- * Use gtk_radio_tool_button_new() to create a new GtkRadioToolButton. Use
- * gtk_radio_tool_button_new_from_widget() to create a new GtkRadioToolButton
- * that is part of the same group as an existing GtkRadioToolButton.
- *
- * # CSS nodes
- *
- * GtkRadioToolButton has a single CSS node with name toolbutton.
- */
-
-typedef struct _GtkRadioToolButtonClass GtkRadioToolButtonClass;
-
-struct _GtkRadioToolButton
-{
- GtkToggleToolButton parent;
-};
-
-struct _GtkRadioToolButtonClass
-{
- GtkToggleToolButtonClass parent_class;
-};
-
-
-enum {
- PROP_0,
- PROP_GROUP
-};
-
-static void gtk_radio_tool_button_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec);
-
-G_DEFINE_TYPE (GtkRadioToolButton, gtk_radio_tool_button, GTK_TYPE_TOGGLE_TOOL_BUTTON)
-
-static void
-gtk_radio_tool_button_class_init (GtkRadioToolButtonClass *klass)
-{
- GObjectClass *object_class;
- GtkToolButtonClass *toolbutton_class;
-
- object_class = (GObjectClass *)klass;
- toolbutton_class = (GtkToolButtonClass *)klass;
-
- object_class->set_property = gtk_radio_tool_button_set_property;
-
- toolbutton_class->button_type = GTK_TYPE_RADIO_BUTTON;
-
- /**
- * GtkRadioToolButton:group:
- *
- * Sets a new group for a radio tool button.
- */
- g_object_class_install_property (object_class,
- PROP_GROUP,
- g_param_spec_object ("group",
- P_("Group"),
- P_("The radio tool button whose group this button belongs to."),
- GTK_TYPE_RADIO_TOOL_BUTTON,
- GTK_PARAM_WRITABLE));
-
-}
-
-static void
-gtk_radio_tool_button_init (GtkRadioToolButton *button)
-{
- GtkToolButton *tool_button = GTK_TOOL_BUTTON (button);
- gtk_check_button_set_draw_indicator (GTK_CHECK_BUTTON (_gtk_tool_button_get_button (tool_button)), FALSE);
-}
-
-static void
-gtk_radio_tool_button_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- GtkRadioToolButton *button;
-
- button = GTK_RADIO_TOOL_BUTTON (object);
-
- switch (prop_id)
- {
- case PROP_GROUP:
- {
- GtkRadioToolButton *arg;
- GSList *slist = NULL;
- if (G_VALUE_HOLDS_OBJECT (value))
- {
- arg = GTK_RADIO_TOOL_BUTTON (g_value_get_object (value));
- if (arg)
- slist = gtk_radio_tool_button_get_group (arg);
- gtk_radio_tool_button_set_group (button, slist);
- }
- }
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-/**
- * gtk_radio_tool_button_new:
- * @group: (allow-none) (element-type GtkRadioButton): An
- * existing radio button group, or %NULL if you are creating a new group
- *
- * Creates a new #GtkRadioToolButton, adding it to @group.
- *
- * Returns: The new #GtkRadioToolButton
- **/
-GtkToolItem *
-gtk_radio_tool_button_new (GSList *group)
-{
- GtkRadioToolButton *button;
-
- button = g_object_new (GTK_TYPE_RADIO_TOOL_BUTTON,
- NULL);
-
- gtk_radio_tool_button_set_group (button, group);
-
- return GTK_TOOL_ITEM (button);
-}
-
-/**
- * gtk_radio_tool_button_new_from_widget: (constructor)
- * @group: (allow-none): An existing #GtkRadioToolButton, or %NULL
- *
- * Creates a new #GtkRadioToolButton adding it to the same group as @gruup
- *
- * Returns: (transfer none): The new #GtkRadioToolButton
- **/
-GtkToolItem *
-gtk_radio_tool_button_new_from_widget (GtkRadioToolButton *group)
-{
- GSList *list = NULL;
-
- g_return_val_if_fail (group == NULL || GTK_IS_RADIO_TOOL_BUTTON (group), NULL);
-
- if (group != NULL)
- list = gtk_radio_tool_button_get_group (GTK_RADIO_TOOL_BUTTON (group));
-
- return gtk_radio_tool_button_new (list);
-}
-
-static GtkRadioButton *
-get_radio_button (GtkRadioToolButton *button)
-{
- return GTK_RADIO_BUTTON (_gtk_tool_button_get_button (GTK_TOOL_BUTTON (button)));
-}
-
-/**
- * gtk_radio_tool_button_get_group:
- * @button: a #GtkRadioToolButton
- *
- * Returns the radio button group @button belongs to.
- *
- * Returns: (transfer none) (element-type GtkRadioButton): The group @button belongs to.
- */
-GSList *
-gtk_radio_tool_button_get_group (GtkRadioToolButton *button)
-{
- g_return_val_if_fail (GTK_IS_RADIO_TOOL_BUTTON (button), NULL);
-
- return gtk_radio_button_get_group (get_radio_button (button));
-}
-
-/**
- * gtk_radio_tool_button_set_group:
- * @button: a #GtkRadioToolButton
- * @group: (element-type GtkRadioButton) (allow-none): an existing radio button group, or %NULL
- *
- * Adds @button to @group, removing it from the group it belonged to before.
- **/
-void
-gtk_radio_tool_button_set_group (GtkRadioToolButton *button,
- GSList *group)
-{
- g_return_if_fail (GTK_IS_RADIO_TOOL_BUTTON (button));
-
- gtk_radio_button_set_group (get_radio_button (button), group);
-}
+++ /dev/null
-/* gtkradiotoolbutton.h
- *
- * Copyright (C) 2002 Anders Carlsson <andersca@gnome.org>
- * Copyright (C) 2002 James Henstridge <james@daa.com.au>
- * Copyright (C) 2003 Soeren Sandmann <sandmann@daimi.au.dk>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef __GTK_RADIO_TOOL_BUTTON_H__
-#define __GTK_RADIO_TOOL_BUTTON_H__
-
-#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
-#error "Only <gtk/gtk.h> can be included directly."
-#endif
-
-#include <gtk/gtktoggletoolbutton.h>
-
-G_BEGIN_DECLS
-
-#define GTK_TYPE_RADIO_TOOL_BUTTON (gtk_radio_tool_button_get_type ())
-#define GTK_RADIO_TOOL_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_RADIO_TOOL_BUTTON, GtkRadioToolButton))
-#define GTK_IS_RADIO_TOOL_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_RADIO_TOOL_BUTTON))
-
-typedef struct _GtkRadioToolButton GtkRadioToolButton;
-
-GDK_AVAILABLE_IN_ALL
-GType gtk_radio_tool_button_get_type (void) G_GNUC_CONST;
-
-GDK_AVAILABLE_IN_ALL
-GtkToolItem *gtk_radio_tool_button_new (GSList *group);
-GDK_AVAILABLE_IN_ALL
-GtkToolItem *gtk_radio_tool_button_new_from_widget (GtkRadioToolButton *group);
-GDK_AVAILABLE_IN_ALL
-GSList * gtk_radio_tool_button_get_group (GtkRadioToolButton *button);
-GDK_AVAILABLE_IN_ALL
-void gtk_radio_tool_button_set_group (GtkRadioToolButton *button,
- GSList *group);
-
-G_END_DECLS
-
-#endif /* __GTK_RADIO_TOOL_BUTTON_H__ */
+++ /dev/null
-/* gtkseparatortoolitem.c
- *
- * Copyright (C) 2002 Anders Carlsson <andersca@gnome.org>
- * Copyright (C) 2002 James Henstridge <james@daa.com.au>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "config.h"
-
-#include "gtkseparatortoolitem.h"
-
-#include "gtkintl.h"
-#include "gtkprivate.h"
-#include "gtkstylecontext.h"
-#include "gtktoolbarprivate.h"
-#include "gtkwidgetprivate.h"
-
-/**
- * SECTION:gtkseparatortoolitem
- * @Short_description: A toolbar item that separates groups of other
- * toolbar items
- * @Title: GtkSeparatorToolItem
- * @See_also: #GtkToolbar, #GtkRadioToolButton
- *
- * A #GtkSeparatorToolItem is a #GtkToolItem that separates groups of other
- * #GtkToolItems. Depending on the theme, a #GtkSeparatorToolItem will
- * often look like a vertical line on horizontally docked toolbars.
- *
- * If the #GtkToolbar child property “expand” is %TRUE and the property
- * #GtkSeparatorToolItem:draw is %FALSE, a #GtkSeparatorToolItem will act as
- * a “spring” that forces other items to the ends of the toolbar.
- *
- * Use gtk_separator_tool_item_new() to create a new #GtkSeparatorToolItem.
- *
- * # CSS nodes
- *
- * GtkSeparatorToolItem has a single CSS node with name separator.
- */
-
-typedef struct _GtkSeparatorToolItemClass GtkSeparatorToolItemClass;
-
-struct _GtkSeparatorToolItem
-{
- GtkToolItem parent_instance;
-};
-
-struct _GtkSeparatorToolItemClass
-{
- GtkToolItemClass parent_class;
-};
-
-#define MENU_ID "gtk-separator-tool-item-menu-id"
-
-enum {
- PROP_0,
- PROP_DRAW
-};
-
-static void gtk_separator_tool_item_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec);
-static void gtk_separator_tool_item_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec);
-static void gtk_separator_tool_item_add (GtkContainer *container,
- GtkWidget *child);
-
-G_DEFINE_TYPE (GtkSeparatorToolItem, gtk_separator_tool_item, GTK_TYPE_TOOL_ITEM)
-
-static void
-gtk_separator_tool_item_class_init (GtkSeparatorToolItemClass *class)
-{
- GObjectClass *object_class;
- GtkContainerClass *container_class;
- GtkWidgetClass *widget_class;
-
- object_class = (GObjectClass *)class;
- container_class = (GtkContainerClass *)class;
- widget_class = (GtkWidgetClass *)class;
-
- object_class->set_property = gtk_separator_tool_item_set_property;
- object_class->get_property = gtk_separator_tool_item_get_property;
-
- container_class->add = gtk_separator_tool_item_add;
-
- g_object_class_install_property (object_class,
- PROP_DRAW,
- g_param_spec_boolean ("draw",
- P_("Draw"),
- P_("Whether the separator is drawn, or just blank"),
- TRUE,
- GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
-
- gtk_widget_class_set_css_name (widget_class, I_("separator"));
-}
-
-static void
-gtk_separator_tool_item_init (GtkSeparatorToolItem *separator_item)
-{
-}
-
-static void
-gtk_separator_tool_item_add (GtkContainer *container,
- GtkWidget *child)
-{
- g_warning ("attempt to add a child to a GtkSeparatorToolItem");
-}
-
-static void
-gtk_separator_tool_item_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- GtkSeparatorToolItem *item = GTK_SEPARATOR_TOOL_ITEM (object);
-
- switch (prop_id)
- {
- case PROP_DRAW:
- gtk_separator_tool_item_set_draw (item, g_value_get_boolean (value));
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static void
-gtk_separator_tool_item_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- GtkSeparatorToolItem *item = GTK_SEPARATOR_TOOL_ITEM (object);
-
- switch (prop_id)
- {
- case PROP_DRAW:
- g_value_set_boolean (value, gtk_separator_tool_item_get_draw (item));
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-/**
- * gtk_separator_tool_item_new:
- *
- * Create a new #GtkSeparatorToolItem
- *
- * Returns: the new #GtkSeparatorToolItem
- */
-GtkToolItem *
-gtk_separator_tool_item_new (void)
-{
- GtkToolItem *self;
-
- self = g_object_new (GTK_TYPE_SEPARATOR_TOOL_ITEM,
- NULL);
-
- return self;
-}
-
-/**
- * gtk_separator_tool_item_get_draw:
- * @item: a #GtkSeparatorToolItem
- *
- * Returns whether @item is drawn as a line, or just blank.
- * See gtk_separator_tool_item_set_draw().
- *
- * Returns: %TRUE if @item is drawn as a line, or just blank.
- */
-gboolean
-gtk_separator_tool_item_get_draw (GtkSeparatorToolItem *item)
-{
- GtkStyleContext *context;
-
- g_return_val_if_fail (GTK_IS_SEPARATOR_TOOL_ITEM (item), FALSE);
-
- context = gtk_widget_get_style_context (GTK_WIDGET (item));
-
- return !gtk_style_context_has_class (context, "invisible");
-}
-
-/**
- * gtk_separator_tool_item_set_draw:
- * @item: a #GtkSeparatorToolItem
- * @draw: whether @item is drawn as a vertical line
- *
- * Whether @item is drawn as a vertical line, or just blank.
- * Setting this to %FALSE along with gtk_tool_item_set_expand() is useful
- * to create an item that forces following items to the end of the toolbar.
- */
-void
-gtk_separator_tool_item_set_draw (GtkSeparatorToolItem *item,
- gboolean draw)
-{
- g_return_if_fail (GTK_IS_SEPARATOR_TOOL_ITEM (item));
-
- draw = !!draw;
-
- if (draw == gtk_separator_tool_item_get_draw (item))
- return;
-
- if (draw)
- gtk_style_context_remove_class (gtk_widget_get_style_context (GTK_WIDGET (item)),
- "invisible");
- else
- gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (item)),
- "invisible");
-
- g_object_notify (G_OBJECT (item), "draw");
-}
+++ /dev/null
-/* gtktoggletoolbutton.h
- *
- * Copyright (C) 2002 Anders Carlsson <andersca@gnome.org>
- * Copyright (C) 2002 James Henstridge <james@daa.com.au>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef __GTK_SEPARATOR_TOOL_ITEM_H__
-#define __GTK_SEPARATOR_TOOL_ITEM_H__
-
-#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
-#error "Only <gtk/gtk.h> can be included directly."
-#endif
-
-#include <gtk/gtktoolitem.h>
-
-G_BEGIN_DECLS
-
-#define GTK_TYPE_SEPARATOR_TOOL_ITEM (gtk_separator_tool_item_get_type ())
-#define GTK_SEPARATOR_TOOL_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_SEPARATOR_TOOL_ITEM, GtkSeparatorToolItem))
-#define GTK_IS_SEPARATOR_TOOL_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_SEPARATOR_TOOL_ITEM))
-
-typedef struct _GtkSeparatorToolItem GtkSeparatorToolItem;
-
-GDK_AVAILABLE_IN_ALL
-GType gtk_separator_tool_item_get_type (void) G_GNUC_CONST;
-GDK_AVAILABLE_IN_ALL
-GtkToolItem *gtk_separator_tool_item_new (void);
-
-GDK_AVAILABLE_IN_ALL
-gboolean gtk_separator_tool_item_get_draw (GtkSeparatorToolItem *item);
-GDK_AVAILABLE_IN_ALL
-void gtk_separator_tool_item_set_draw (GtkSeparatorToolItem *item,
- gboolean draw);
-
-G_END_DECLS
-
-#endif /* __GTK_SEPARATOR_TOOL_ITEM_H__ */
#include "gtktexthandleprivate.h"
#include "gtkcssstylepropertyprivate.h"
#include "gtkpopover.h"
-#include "gtktoolbar.h"
#include "gtkmagnifierprivate.h"
#include "gtkemojichooser.h"
#include "gtkpango.h"
+++ /dev/null
- /* gtktoggletoolbutton.c
- *
- * Copyright (C) 2002 Anders Carlsson <andersca@gnome.org>
- * Copyright (C) 2002 James Henstridge <james@daa.com.au>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "config.h"
-#include "gtktoggletoolbutton.h"
-#include "gtklabel.h"
-#include "gtktogglebutton.h"
-#include "gtkintl.h"
-#include "gtkradiotoolbutton.h"
-#include "gtkprivate.h"
-
-
-/**
- * SECTION:gtktoggletoolbutton
- * @Short_description: A GtkToolItem containing a toggle button
- * @Title: GtkToggleToolButton
- * @See_also: #GtkToolbar, #GtkToolButton, #GtkSeparatorToolItem
- *
- * A #GtkToggleToolButton is a #GtkToolItem that contains a toggle
- * button.
- *
- * Use gtk_toggle_tool_button_new() to create a new GtkToggleToolButton.
- *
- * # CSS nodes
- *
- * GtkToggleToolButton has a single CSS node with name togglebutton.
- */
-
-
-#define MENU_ID "gtk-toggle-tool-button-menu-id"
-
-enum {
- TOGGLED,
- LAST_SIGNAL
-};
-
-enum {
- PROP_0,
- PROP_ACTIVE
-};
-
-
-struct _GtkToggleToolButtonPrivate
-{
- guint active : 1;
-};
-
-
-static void gtk_toggle_tool_button_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec);
-static void gtk_toggle_tool_button_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec);
-
-static void button_toggled (GtkWidget *widget,
- GtkToggleToolButton *button);
-
-
-static guint toggle_signals[LAST_SIGNAL] = { 0 };
-
-G_DEFINE_TYPE_WITH_CODE (GtkToggleToolButton, gtk_toggle_tool_button, GTK_TYPE_TOOL_BUTTON,
- G_ADD_PRIVATE (GtkToggleToolButton));
-
-static void
-gtk_toggle_tool_button_class_init (GtkToggleToolButtonClass *klass)
-{
- GObjectClass *object_class;
- GtkToolButtonClass *toolbutton_class;
-
- object_class = (GObjectClass *)klass;
- toolbutton_class = (GtkToolButtonClass *)klass;
-
- object_class->set_property = gtk_toggle_tool_button_set_property;
- object_class->get_property = gtk_toggle_tool_button_get_property;
-
- toolbutton_class->button_type = GTK_TYPE_TOGGLE_BUTTON;
-
- /**
- * GtkToggleToolButton:active:
- *
- * If the toggle tool button should be pressed in.
- */
- g_object_class_install_property (object_class,
- PROP_ACTIVE,
- g_param_spec_boolean ("active",
- P_("Active"),
- P_("If the toggle button should be pressed in"),
- FALSE,
- GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
-
-/**
- * GtkToggleToolButton::toggled:
- * @toggle_tool_button: the object that emitted the signal
- *
- * Emitted whenever the toggle tool button changes state.
- **/
- toggle_signals[TOGGLED] =
- g_signal_new (I_("toggled"),
- G_OBJECT_CLASS_TYPE (klass),
- G_SIGNAL_RUN_FIRST,
- G_STRUCT_OFFSET (GtkToggleToolButtonClass, toggled),
- NULL, NULL,
- NULL,
- G_TYPE_NONE, 0);
-}
-
-static void
-gtk_toggle_tool_button_init (GtkToggleToolButton *button)
-{
- GtkToolButton *tool_button = GTK_TOOL_BUTTON (button);
- GtkToggleButton *toggle_button = GTK_TOGGLE_BUTTON (_gtk_tool_button_get_button (tool_button));
-
- button->priv = gtk_toggle_tool_button_get_instance_private (button);
-
- /* If the real button is a radio button, it may have been
- * active at the time it was created.
- */
- button->priv->active = gtk_toggle_button_get_active (toggle_button);
-
- g_signal_connect_object (toggle_button,
- "toggled", G_CALLBACK (button_toggled), button, 0);
-}
-
-static void
-gtk_toggle_tool_button_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- GtkToggleToolButton *button = GTK_TOGGLE_TOOL_BUTTON (object);
-
- switch (prop_id)
- {
- case PROP_ACTIVE:
- gtk_toggle_tool_button_set_active (button,
- g_value_get_boolean (value));
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static void
-gtk_toggle_tool_button_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- GtkToggleToolButton *button = GTK_TOGGLE_TOOL_BUTTON (object);
-
- switch (prop_id)
- {
- case PROP_ACTIVE:
- g_value_set_boolean (value, gtk_toggle_tool_button_get_active (button));
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static void
-button_toggled (GtkWidget *widget,
- GtkToggleToolButton *toggle_tool_button)
-{
- gboolean toggle_active;
-
- toggle_active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget));
-
- if (toggle_tool_button->priv->active != toggle_active)
- {
- toggle_tool_button->priv->active = toggle_active;
-
- g_object_notify (G_OBJECT (toggle_tool_button), "active");
- g_signal_emit (toggle_tool_button, toggle_signals[TOGGLED], 0);
- }
-}
-
-/**
- * gtk_toggle_tool_button_new:
- *
- * Returns a new #GtkToggleToolButton
- *
- * Returns: a newly created #GtkToggleToolButton
- **/
-GtkToolItem *
-gtk_toggle_tool_button_new (void)
-{
- GtkToolButton *button;
-
- button = g_object_new (GTK_TYPE_TOGGLE_TOOL_BUTTON,
- NULL);
-
- return GTK_TOOL_ITEM (button);
-}
-
-/**
- * gtk_toggle_tool_button_set_active:
- * @button: a #GtkToggleToolButton
- * @is_active: whether @button should be active
- *
- * Sets the status of the toggle tool button. Set to %TRUE if you
- * want the GtkToggleButton to be “pressed in”, and %FALSE to raise it.
- * This action causes the toggled signal to be emitted.
- **/
-void
-gtk_toggle_tool_button_set_active (GtkToggleToolButton *button,
- gboolean is_active)
-{
- g_return_if_fail (GTK_IS_TOGGLE_TOOL_BUTTON (button));
-
- is_active = is_active != FALSE;
-
- if (button->priv->active != is_active)
- {
- g_signal_emit_by_name (_gtk_tool_button_get_button (GTK_TOOL_BUTTON (button)), "clicked");
- g_object_notify (G_OBJECT (button), "active");
- }
-}
-
-/**
- * gtk_toggle_tool_button_get_active:
- * @button: a #GtkToggleToolButton
- *
- * Queries a #GtkToggleToolButton and returns its current state.
- * Returns %TRUE if the toggle button is pressed in and %FALSE if it is raised.
- *
- * Returns: %TRUE if the toggle tool button is pressed in, %FALSE if not
- **/
-gboolean
-gtk_toggle_tool_button_get_active (GtkToggleToolButton *button)
-{
- g_return_val_if_fail (GTK_IS_TOGGLE_TOOL_BUTTON (button), FALSE);
-
- return button->priv->active;
-}
+++ /dev/null
-/* gtktoggletoolbutton.h
- *
- * Copyright (C) 2002 Anders Carlsson <andersca@gnome.org>
- * Copyright (C) 2002 James Henstridge <james@daa.com.au>
- * Copyright (C) 2003 Soeren Sandmann <sandmann@daimi.au.dk>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef __GTK_TOGGLE_TOOL_BUTTON_H__
-#define __GTK_TOGGLE_TOOL_BUTTON_H__
-
-#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
-#error "Only <gtk/gtk.h> can be included directly."
-#endif
-
-#include <gtk/gtktoolbutton.h>
-
-G_BEGIN_DECLS
-
-#define GTK_TYPE_TOGGLE_TOOL_BUTTON (gtk_toggle_tool_button_get_type ())
-#define GTK_TOGGLE_TOOL_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_TOGGLE_TOOL_BUTTON, GtkToggleToolButton))
-#define GTK_TOGGLE_TOOL_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_TOGGLE_TOOL_BUTTON, GtkToggleToolButtonClass))
-#define GTK_IS_TOGGLE_TOOL_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_TOGGLE_TOOL_BUTTON))
-#define GTK_IS_TOGGLE_TOOL_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_TOGGLE_TOOL_BUTTON))
-#define GTK_TOGGLE_TOOL_BUTTON_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GTK_TYPE_TOGGLE_TOOL_BUTTON, GtkToggleToolButtonClass))
-
-typedef struct _GtkToggleToolButton GtkToggleToolButton;
-typedef struct _GtkToggleToolButtonClass GtkToggleToolButtonClass;
-typedef struct _GtkToggleToolButtonPrivate GtkToggleToolButtonPrivate;
-
-struct _GtkToggleToolButton
-{
- GtkToolButton parent;
-
- /*< private >*/
- GtkToggleToolButtonPrivate *priv;
-};
-
-/**
- * GtkToggleToolButtonClass:
- * @parent_class: The parent class.
- * @toggled: Signal emitted whenever the toggle tool button changes state.
- */
-struct _GtkToggleToolButtonClass
-{
- GtkToolButtonClass parent_class;
-
- /*< public >*/
-
- /* signal */
- void (* toggled) (GtkToggleToolButton *button);
-
- /*< private >*/
-
- gpointer padding[8];
-};
-
-GDK_AVAILABLE_IN_ALL
-GType gtk_toggle_tool_button_get_type (void) G_GNUC_CONST;
-GDK_AVAILABLE_IN_ALL
-GtkToolItem *gtk_toggle_tool_button_new (void);
-
-GDK_AVAILABLE_IN_ALL
-void gtk_toggle_tool_button_set_active (GtkToggleToolButton *button,
- gboolean is_active);
-GDK_AVAILABLE_IN_ALL
-gboolean gtk_toggle_tool_button_get_active (GtkToggleToolButton *button);
-
-G_END_DECLS
-
-#endif /* __GTK_TOGGLE_TOOL_BUTTON_H__ */
+++ /dev/null
-/* GTK - The GIMP Toolkit
- * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
- * GtkToolbar copyright (C) Federico Mena
- *
- * Copyright (C) 2002 Anders Carlsson <andersca@gnome.org>
- * Copyright (C) 2002 James Henstridge <james@daa.com.au>
- * Copyright (C) 2003, 2004 Soeren Sandmann <sandmann@daimi.au.dk>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/*
- * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
- * file for a list of people on the GTK+ Team. See the ChangeLog
- * files for a list of changes. These files are distributed with
- * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
- */
-
-
-#include "config.h"
-
-#include <math.h>
-#include <string.h>
-
-#include "gtktoolbar.h"
-#include "gtktoolbarprivate.h"
-
-#include "gtkbindings.h"
-#include "gtkbox.h"
-#include "gtkcontainerprivate.h"
-#include "gtkcssnodeprivate.h"
-#include "gtkimage.h"
-#include "gtkintl.h"
-#include "gtklabel.h"
-#include "gtkmain.h"
-#include "gtkmarshalers.h"
-#include "gtkorientable.h"
-#include "gtkorientableprivate.h"
-#include "gtkprivate.h"
-#include "gtkpopovermenuprivate.h"
-#include "gtkmodelbuttonprivate.h"
-#include "gtkseparator.h"
-#include "gtkradiobutton.h"
-#include "gtkradiotoolbutton.h"
-#include "gtkseparatortoolitem.h"
-#include "gtktoolshell.h"
-#include "gtktypebuiltins.h"
-#include "gtkwidgetprivate.h"
-#include "gtkwindowprivate.h"
-#include "gtkgestureclick.h"
-#include "gtkbuttonprivate.h"
-#include "gtkmenubutton.h"
-
-
-/**
- * SECTION:gtktoolbar
- * @Short_description: Create bars of buttons and other widgets
- * @Title: GtkToolbar
- * @See_also: #GtkToolItem
- *
- * A toolbar is created with a call to gtk_toolbar_new().
- *
- * A toolbar can contain instances of a subclass of #GtkToolItem. To add
- * a #GtkToolItem to the a toolbar, use gtk_toolbar_insert(). To remove
- * an item from the toolbar use gtk_container_remove(). To add a button
- * to the toolbar, add an instance of #GtkToolButton.
- *
- * Toolbar items can be visually grouped by adding instances of
- * #GtkSeparatorToolItem to the toolbar. If the GtkToolItem property
- * “expand” is #TRUE and the property #GtkSeparatorToolItem:draw is set to
- * #FALSE, the effect is to force all following items to the end of the toolbar.
- *
- * By default, a toolbar can be shrunk, upon which it will add an arrow button
- * to show an overflow menu offering access to any #GtkToolItem child that has
- * a proxy menu item. To disable this and request enough size for all children,
- * call gtk_toolbar_set_show_arrow() to set #GtkToolbar:show-arrow to %FALSE.
- *
- * Creating a context menu for the toolbar can be done by connecting to
- * the #GtkToolbar::popup-context-menu signal.
- *
- * # CSS nodes
- *
- * GtkToolbar has a single CSS node with name toolbar.
- */
-
-
-typedef struct _ToolbarContent ToolbarContent;
-
-#define DEFAULT_TOOLBAR_STYLE GTK_TOOLBAR_BOTH_HORIZ
-#define DEFAULT_ANIMATION_STATE TRUE
-
-#define MAX_HOMOGENEOUS_N_CHARS 13 /* Items that are wider than this do not participate
- * in the homogeneous game. In units of
- * pango_font_get_estimated_char_width().
- */
-#define SLIDE_SPEED 600.0 /* How fast the items slide, in pixels per second */
-#define ACCEL_THRESHOLD 0.18 /* After how much time in seconds will items start speeding up */
-
-typedef struct _GtkToolbarPrivate GtkToolbarPrivate;
-typedef struct _GtkToolbarClass GtkToolbarClass;
-
-struct _GtkToolbar
-{
- GtkContainer container;
-
- GtkToolbarPrivate *priv;
-};
-
-struct _GtkToolbarClass
-{
- GtkContainerClass parent_class;
-
- void (* orientation_changed) (GtkToolbar *toolbar,
- GtkOrientation orientation);
- void (* style_changed) (GtkToolbar *toolbar,
- GtkToolbarStyle style);
- gboolean (* popup_context_menu) (GtkToolbar *toolbar,
- gint x,
- gint y,
- gint button_number);
-};
-
-struct _GtkToolbarPrivate
-{
- GtkWidget *menu;
- GtkWidget *menu_box;
- GtkSettings *settings;
-
- GtkToolbarStyle style;
-
- GtkToolItem *highlight_tool_item;
- GtkWidget *arrow_button;
-
- GtkAllocation prev_allocation;
-
- GList *content;
-
- GTimer *timer;
-
- gulong settings_connection;
-
- gint idle_id;
- gint button_maxw; /* maximum width of homogeneous children */
- gint button_maxh; /* maximum height of homogeneous children */
- gint max_homogeneous_pixels;
- gint num_children;
-
- GtkOrientation orientation;
-
- guint animation : 1;
- guint is_sliding : 1;
- guint need_rebuild : 1; /* whether the overflow menu should be regenerated */
- guint show_arrow : 1;
- guint style_set : 1;
-};
-
-/* Properties */
-enum {
- PROP_0,
- PROP_ORIENTATION,
- PROP_TOOLBAR_STYLE,
- PROP_SHOW_ARROW,
- PROP_TOOLTIPS,
-};
-
-/* Signals */
-enum {
- ORIENTATION_CHANGED,
- STYLE_CHANGED,
- POPUP_CONTEXT_MENU,
- FOCUS_HOME_OR_END,
- LAST_SIGNAL
-};
-
-typedef enum {
- NOT_ALLOCATED,
- NORMAL,
- HIDDEN,
- OVERFLOWN
-} ItemState;
-
-
-static void gtk_toolbar_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec);
-static void gtk_toolbar_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec);
-static void gtk_toolbar_snapshot (GtkWidget *widget,
- GtkSnapshot *snapshot);
-static void gtk_toolbar_size_allocate (GtkWidget *widget,
- int width,
- int height,
- int baseline);
-static void gtk_toolbar_css_changed (GtkWidget *widget,
- GtkCssStyleChange *change);
-static gboolean gtk_toolbar_focus (GtkWidget *widget,
- GtkDirectionType dir);
-static void gtk_toolbar_move_focus (GtkWidget *widget,
- GtkDirectionType dir);
-static void gtk_toolbar_root (GtkWidget *widget);
-static void gtk_toolbar_unroot (GtkWidget *widget);
-static void gtk_toolbar_finalize (GObject *object);
-static void gtk_toolbar_dispose (GObject *object);
-static void gtk_toolbar_add (GtkContainer *container,
- GtkWidget *widget);
-static void gtk_toolbar_remove (GtkContainer *container,
- GtkWidget *widget);
-static void gtk_toolbar_forall (GtkContainer *container,
- GtkCallback callback,
- gpointer callback_data);
-static GType gtk_toolbar_child_type (GtkContainer *container);
-
-static void gtk_toolbar_orientation_changed (GtkToolbar *toolbar,
- GtkOrientation orientation);
-static void gtk_toolbar_real_style_changed (GtkToolbar *toolbar,
- GtkToolbarStyle style);
-static gboolean gtk_toolbar_focus_home_or_end (GtkToolbar *toolbar,
- gboolean focus_home);
-static gboolean gtk_toolbar_popup_menu (GtkWidget *toolbar);
-static void gtk_toolbar_reconfigured (GtkToolbar *toolbar);
-
-static void gtk_toolbar_measure (GtkWidget *widget,
- GtkOrientation orientation,
- int for_size,
- int *minimum,
- int *natural,
- int *minimum_baseline,
- int *natural_baseline);
-static void gtk_toolbar_pressed_cb (GtkGestureClick *gesture,
- int n_press,
- double x,
- double y,
- gpointer user_data);
-
-
-/* methods on ToolbarContent 'class' */
-static ToolbarContent *toolbar_content_new_tool_item (GtkToolbar *toolbar,
- GtkToolItem *item,
- gboolean is_placeholder,
- gint pos);
-static void toolbar_content_remove (ToolbarContent *content,
- GtkToolbar *toolbar);
-static void toolbar_content_free (ToolbarContent *content);
-static void toolbar_content_snapshot (ToolbarContent *content,
- GtkContainer *container,
- GtkSnapshot *snapshot);
-static gboolean toolbar_content_visible (ToolbarContent *content,
- GtkToolbar *toolbar);
-static void toolbar_content_size_request (ToolbarContent *content,
- GtkToolbar *toolbar,
- GtkRequisition *requisition);
-static gboolean toolbar_content_is_homogeneous (ToolbarContent *content,
- GtkToolbar *toolbar);
-static gboolean toolbar_content_is_placeholder (ToolbarContent *content);
-static gboolean toolbar_content_disappearing (ToolbarContent *content);
-static ItemState toolbar_content_get_state (ToolbarContent *content);
-static gboolean toolbar_content_child_visible (ToolbarContent *content);
-static void toolbar_content_get_goal_allocation (ToolbarContent *content,
- GtkAllocation *allocation);
-static void toolbar_content_get_allocation (ToolbarContent *content,
- GtkAllocation *allocation);
-static void toolbar_content_set_start_allocation (ToolbarContent *content,
- GtkAllocation *new_start_allocation);
-static void toolbar_content_get_start_allocation (ToolbarContent *content,
- GtkAllocation *start_allocation);
-static gboolean toolbar_content_get_expand (ToolbarContent *content,
- GtkOrientation orientation);
-static void toolbar_content_set_goal_allocation (ToolbarContent *content,
- GtkAllocation *allocation);
-static void toolbar_content_set_child_visible (ToolbarContent *content,
- GtkToolbar *toolbar,
- gboolean visible);
-static void toolbar_content_size_allocate (ToolbarContent *content,
- GtkAllocation *allocation);
-static void toolbar_content_set_state (ToolbarContent *content,
- ItemState new_state);
-static GtkWidget * toolbar_content_get_widget (ToolbarContent *content);
-static void toolbar_content_set_disappearing (ToolbarContent *content,
- gboolean disappearing);
-static void toolbar_content_set_size_request (ToolbarContent *content,
- gint width,
- gint height);
-static void toolbar_content_toolbar_reconfigured (ToolbarContent *content,
- GtkToolbar *toolbar);
-static const char * toolbar_content_get_overflow_text (ToolbarContent *content);
-static GtkButtonRole toolbar_content_get_button_role (ToolbarContent *content);
-static gboolean toolbar_content_get_active (ToolbarContent *content);
-static gboolean toolbar_content_has_proxy_menu_item (ToolbarContent *content);
-static gboolean toolbar_content_is_separator (ToolbarContent *content);
-static void toolbar_content_set_expand (ToolbarContent *content,
- gboolean expand);
-
-static void toolbar_tool_shell_iface_init (GtkToolShellIface *iface);
-static GtkOrientation toolbar_get_orientation (GtkToolShell *shell);
-static GtkToolbarStyle toolbar_get_style (GtkToolShell *shell);
-static void toolbar_rebuild_menu (GtkToolShell *shell);
-static void create_popup_func (GtkMenuButton *button,
- gpointer data);
-
-
-G_DEFINE_TYPE_WITH_CODE (GtkToolbar, gtk_toolbar, GTK_TYPE_CONTAINER,
- G_ADD_PRIVATE (GtkToolbar)
- G_IMPLEMENT_INTERFACE (GTK_TYPE_TOOL_SHELL,
- toolbar_tool_shell_iface_init)
- G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE,
- NULL))
-
-static guint toolbar_signals[LAST_SIGNAL] = { 0 };
-
-
-static void
-add_arrow_bindings (GtkBindingSet *binding_set,
- guint keysym,
- GtkDirectionType dir)
-{
- guint keypad_keysym = keysym - GDK_KEY_Left + GDK_KEY_KP_Left;
-
- gtk_binding_entry_add_signal (binding_set, keysym, 0,
- "move-focus", 1,
- GTK_TYPE_DIRECTION_TYPE, dir);
- gtk_binding_entry_add_signal (binding_set, keypad_keysym, 0,
- "move-focus", 1,
- GTK_TYPE_DIRECTION_TYPE, dir);
-}
-
-static void
-add_ctrl_tab_bindings (GtkBindingSet *binding_set,
- GdkModifierType modifiers,
- GtkDirectionType direction)
-{
- gtk_binding_entry_add_signal (binding_set,
- GDK_KEY_Tab, GDK_CONTROL_MASK | modifiers,
- "move-focus", 1,
- GTK_TYPE_DIRECTION_TYPE, direction);
- gtk_binding_entry_add_signal (binding_set,
- GDK_KEY_KP_Tab, GDK_CONTROL_MASK | modifiers,
- "move-focus", 1,
- GTK_TYPE_DIRECTION_TYPE, direction);
-}
-
-static void
-gtk_toolbar_class_init (GtkToolbarClass *klass)
-{
- GObjectClass *gobject_class;
- GtkWidgetClass *widget_class;
- GtkContainerClass *container_class;
- GtkBindingSet *binding_set;
-
- gobject_class = (GObjectClass *)klass;
- widget_class = (GtkWidgetClass *)klass;
- container_class = (GtkContainerClass *)klass;
-
- gobject_class->set_property = gtk_toolbar_set_property;
- gobject_class->get_property = gtk_toolbar_get_property;
- gobject_class->finalize = gtk_toolbar_finalize;
- gobject_class->dispose = gtk_toolbar_dispose;
-
- widget_class->snapshot = gtk_toolbar_snapshot;
- widget_class->measure = gtk_toolbar_measure;
- widget_class->size_allocate = gtk_toolbar_size_allocate;
- widget_class->css_changed = gtk_toolbar_css_changed;
- widget_class->focus = gtk_toolbar_focus;
-
- gtk_widget_class_set_accessible_role (widget_class, ATK_ROLE_TOOL_BAR);
-
- /* need to override the base class function via override_class_handler,
- * because the signal slot is not available in GtkWidgetClass
- */
- g_signal_override_class_handler ("move-focus",
- GTK_TYPE_TOOLBAR,
- G_CALLBACK (gtk_toolbar_move_focus));
-
- widget_class->root = gtk_toolbar_root;
- widget_class->unroot = gtk_toolbar_unroot;
- widget_class->popup_menu = gtk_toolbar_popup_menu;
-
- container_class->add = gtk_toolbar_add;
- container_class->remove = gtk_toolbar_remove;
- container_class->forall = gtk_toolbar_forall;
- container_class->child_type = gtk_toolbar_child_type;
-
- klass->orientation_changed = gtk_toolbar_orientation_changed;
- klass->style_changed = gtk_toolbar_real_style_changed;
-
- /**
- * GtkToolbar::orientation-changed:
- * @toolbar: the object which emitted the signal
- * @orientation: the new #GtkOrientation of the toolbar
- *
- * Emitted when the orientation of the toolbar changes.
- */
- toolbar_signals[ORIENTATION_CHANGED] =
- g_signal_new (I_("orientation-changed"),
- G_OBJECT_CLASS_TYPE (klass),
- G_SIGNAL_RUN_FIRST,
- G_STRUCT_OFFSET (GtkToolbarClass, orientation_changed),
- NULL, NULL,
- NULL,
- G_TYPE_NONE, 1,
- GTK_TYPE_ORIENTATION);
- /**
- * GtkToolbar::style-changed:
- * @toolbar: The #GtkToolbar which emitted the signal
- * @style: the new #GtkToolbarStyle of the toolbar
- *
- * Emitted when the style of the toolbar changes.
- */
- toolbar_signals[STYLE_CHANGED] =
- g_signal_new (I_("style-changed"),
- G_OBJECT_CLASS_TYPE (klass),
- G_SIGNAL_RUN_FIRST,
- G_STRUCT_OFFSET (GtkToolbarClass, style_changed),
- NULL, NULL,
- NULL,
- G_TYPE_NONE, 1,
- GTK_TYPE_TOOLBAR_STYLE);
-
- /**
- * GtkToolbar::popup-context-menu:
- * @toolbar: the #GtkToolbar which emitted the signal
- * @x: the x coordinate of the point where the menu should appear
- * @y: the y coordinate of the point where the menu should appear
- * @button: the mouse button the user pressed, or -1
- *
- * Emitted when the user right-clicks the toolbar or uses the
- * keybinding to display a popup menu.
- *
- * Application developers should handle this signal if they want
- * to display a context menu on the toolbar. The context-menu should
- * appear at the coordinates given by @x and @y. The mouse button
- * number is given by the @button parameter. If the menu was popped
- * up using the keyboard, @button is -1.
- *
- * Returns: return %TRUE if the signal was handled, %FALSE if not
- */
- toolbar_signals[POPUP_CONTEXT_MENU] =
- g_signal_new (I_("popup-context-menu"),
- G_OBJECT_CLASS_TYPE (klass),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (GtkToolbarClass, popup_context_menu),
- _gtk_boolean_handled_accumulator, NULL,
- _gtk_marshal_BOOLEAN__INT_INT_INT,
- G_TYPE_BOOLEAN, 3,
- G_TYPE_INT, G_TYPE_INT,
- G_TYPE_INT);
-
- /**
- * GtkToolbar::focus-home-or-end:
- * @toolbar: the #GtkToolbar which emitted the signal
- * @focus_home: %TRUE if the first item should be focused
- *
- * A keybinding signal used internally by GTK+. This signal can't
- * be used in application code
- *
- * Returns: %TRUE if the signal was handled, %FALSE if not
- */
- toolbar_signals[FOCUS_HOME_OR_END] =
- g_signal_new_class_handler (I_("focus-home-or-end"),
- G_OBJECT_CLASS_TYPE (klass),
- G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
- G_CALLBACK (gtk_toolbar_focus_home_or_end),
- NULL, NULL,
- _gtk_marshal_BOOLEAN__BOOLEAN,
- G_TYPE_BOOLEAN, 1,
- G_TYPE_BOOLEAN);
-
- /* properties */
- g_object_class_override_property (gobject_class,
- PROP_ORIENTATION,
- "orientation");
-
- g_object_class_install_property (gobject_class,
- PROP_TOOLBAR_STYLE,
- g_param_spec_enum ("toolbar-style",
- P_("Toolbar Style"),
- P_("How to draw the toolbar"),
- GTK_TYPE_TOOLBAR_STYLE,
- DEFAULT_TOOLBAR_STYLE,
- GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
- g_object_class_install_property (gobject_class,
- PROP_SHOW_ARROW,
- g_param_spec_boolean ("show-arrow",
- P_("Show Arrow"),
- P_("If an arrow should be shown if the toolbar doesn’t fit"),
- TRUE,
- GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
-
- binding_set = gtk_binding_set_by_class (klass);
-
- add_arrow_bindings (binding_set, GDK_KEY_Left, GTK_DIR_LEFT);
- add_arrow_bindings (binding_set, GDK_KEY_Right, GTK_DIR_RIGHT);
- add_arrow_bindings (binding_set, GDK_KEY_Up, GTK_DIR_UP);
- add_arrow_bindings (binding_set, GDK_KEY_Down, GTK_DIR_DOWN);
-
- gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Home, 0,
- "focus-home-or-end", 1,
- G_TYPE_BOOLEAN, TRUE);
- gtk_binding_entry_add_signal (binding_set, GDK_KEY_Home, 0,
- "focus-home-or-end", 1,
- G_TYPE_BOOLEAN, TRUE);
- gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_End, 0,
- "focus-home-or-end", 1,
- G_TYPE_BOOLEAN, FALSE);
- gtk_binding_entry_add_signal (binding_set, GDK_KEY_End, 0,
- "focus-home-or-end", 1,
- G_TYPE_BOOLEAN, FALSE);
-
- add_ctrl_tab_bindings (binding_set, 0, GTK_DIR_TAB_FORWARD);
- add_ctrl_tab_bindings (binding_set, GDK_SHIFT_MASK, GTK_DIR_TAB_BACKWARD);
-
- gtk_widget_class_set_css_name (widget_class, I_("toolbar"));
-}
-
-static void
-toolbar_tool_shell_iface_init (GtkToolShellIface *iface)
-{
- iface->get_orientation = toolbar_get_orientation;
- iface->get_style = toolbar_get_style;
- iface->rebuild_menu = toolbar_rebuild_menu;
-}
-
-static void
-gtk_toolbar_init (GtkToolbar *toolbar)
-{
- GtkToolbarPrivate *priv;
- GtkWidget *widget;
- GtkGesture *gesture;
-
- widget = GTK_WIDGET (toolbar);
- toolbar->priv = gtk_toolbar_get_instance_private (toolbar);
- priv = toolbar->priv;
-
- gtk_widget_set_can_focus (widget, FALSE);
-
- priv->orientation = GTK_ORIENTATION_HORIZONTAL;
- priv->style = DEFAULT_TOOLBAR_STYLE;
- priv->animation = DEFAULT_ANIMATION_STATE;
-
- _gtk_orientable_set_style_classes (GTK_ORIENTABLE (toolbar));
-
- priv->arrow_button = gtk_menu_button_new ();
- gtk_menu_button_set_create_popup_func (GTK_MENU_BUTTON (priv->arrow_button), create_popup_func, toolbar, NULL);
-
- gtk_widget_set_focus_on_click (priv->arrow_button, FALSE);
-
- gtk_widget_set_parent (priv->arrow_button, widget);
-
- /* which child position a drop will occur at */
- priv->menu = NULL;
- priv->show_arrow = TRUE;
- priv->settings = NULL;
-
- priv->max_homogeneous_pixels = -1;
-
- priv->timer = g_timer_new ();
-
- gesture = gtk_gesture_click_new ();
- gtk_gesture_single_set_touch_only (GTK_GESTURE_SINGLE (gesture), FALSE);
- gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (gesture), 0);
- gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (gesture), GTK_PHASE_BUBBLE);
- g_signal_connect (gesture, "pressed", G_CALLBACK (gtk_toolbar_pressed_cb), toolbar);
- gtk_widget_add_controller (GTK_WIDGET (toolbar), GTK_EVENT_CONTROLLER (gesture));
-}
-
-static void
-gtk_toolbar_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- GtkToolbar *toolbar = GTK_TOOLBAR (object);
-
- switch (prop_id)
- {
- case PROP_ORIENTATION:
- g_signal_emit (toolbar, toolbar_signals[ORIENTATION_CHANGED], 0,
- g_value_get_enum (value));
- break;
- case PROP_TOOLBAR_STYLE:
- gtk_toolbar_set_style (toolbar, g_value_get_enum (value));
- break;
- case PROP_SHOW_ARROW:
- gtk_toolbar_set_show_arrow (toolbar, g_value_get_boolean (value));
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static void
-gtk_toolbar_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- GtkToolbar *toolbar = GTK_TOOLBAR (object);
- GtkToolbarPrivate *priv = toolbar->priv;
-
- switch (prop_id)
- {
- case PROP_ORIENTATION:
- g_value_set_enum (value, priv->orientation);
- break;
- case PROP_TOOLBAR_STYLE:
- g_value_set_enum (value, priv->style);
- break;
- case PROP_SHOW_ARROW:
- g_value_set_boolean (value, priv->show_arrow);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static void
-gtk_toolbar_snapshot (GtkWidget *widget,
- GtkSnapshot *snapshot)
-{
- GtkToolbar *toolbar = GTK_TOOLBAR (widget);
- GtkToolbarPrivate *priv = toolbar->priv;
- GList *list;
-
- for (list = priv->content; list != NULL; list = list->next)
- {
- ToolbarContent *content = list->data;
-
- toolbar_content_snapshot (content, GTK_CONTAINER (widget), snapshot);
- }
-
- gtk_widget_snapshot_child (widget, priv->arrow_button, snapshot);
-}
-
-static void
-gtk_toolbar_measure (GtkWidget *widget,
- GtkOrientation orientation,
- int for_size,
- int *minimum,
- int *natural,
- int *minimum_baseline,
- int *natural_baseline)
-{
- GtkToolbar *toolbar = GTK_TOOLBAR (widget);
- GtkToolbarPrivate *priv = toolbar->priv;
- GList *list;
- gint max_child_height;
- gint max_child_width;
- gint max_homogeneous_child_width;
- gint max_homogeneous_child_height;
- gint homogeneous_size;
- gint pack_front_size;
- GtkRequisition arrow_requisition, min_requisition, nat_requisition;
-
- max_homogeneous_child_width = 0;
- max_homogeneous_child_height = 0;
- max_child_width = 0;
- max_child_height = 0;
- for (list = priv->content; list != NULL; list = list->next)
- {
- GtkRequisition requisition;
- ToolbarContent *content = list->data;
-
- if (!toolbar_content_visible (content, toolbar))
- continue;
-
- toolbar_content_size_request (content, toolbar, &requisition);
-
- max_child_width = MAX (max_child_width, requisition.width);
- max_child_height = MAX (max_child_height, requisition.height);
-
- if (toolbar_content_is_homogeneous (content, toolbar))
- {
- max_homogeneous_child_width = MAX (max_homogeneous_child_width, requisition.width);
- max_homogeneous_child_height = MAX (max_homogeneous_child_height, requisition.height);
- }
- }
-
- if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
- homogeneous_size = max_homogeneous_child_width;
- else
- homogeneous_size = max_homogeneous_child_height;
-
- pack_front_size = 0;
- for (list = priv->content; list != NULL; list = list->next)
- {
- ToolbarContent *content = list->data;
- guint size;
-
- if (!toolbar_content_visible (content, toolbar))
- continue;
-
- if (toolbar_content_is_homogeneous (content, toolbar))
- {
- size = homogeneous_size;
- }
- else
- {
- GtkRequisition requisition;
-
- toolbar_content_size_request (content, toolbar, &requisition);
-
- if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
- size = requisition.width;
- else
- size = requisition.height;
- }
-
- pack_front_size += size;
- }
-
- arrow_requisition.height = 0;
- arrow_requisition.width = 0;
-
- if (priv->show_arrow)
- gtk_widget_get_preferred_size (priv->arrow_button, &arrow_requisition, NULL);
-
- if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
- {
- nat_requisition.width = pack_front_size;
- nat_requisition.height = MAX (max_child_height, arrow_requisition.height);
-
- min_requisition.width = priv->show_arrow ? arrow_requisition.width : nat_requisition.width;
- min_requisition.height = nat_requisition.height;
- }
- else
- {
- nat_requisition.width = MAX (max_child_width, arrow_requisition.width);
- nat_requisition.height = pack_front_size;
-
- min_requisition.width = nat_requisition.width;
- min_requisition.height = priv->show_arrow ? arrow_requisition.height : nat_requisition.height;
- }
-
- priv->button_maxw = max_homogeneous_child_width;
- priv->button_maxh = max_homogeneous_child_height;
-
- if (orientation == GTK_ORIENTATION_HORIZONTAL)
- {
- *minimum = min_requisition.width;
- *natural = nat_requisition.width;
- }
- else
- {
- *minimum = min_requisition.height;
- *natural = nat_requisition.height;
- }
-}
-
-static gint
-position (GtkToolbar *toolbar,
- gint from,
- gint to,
- gdouble elapsed)
-{
- GtkToolbarPrivate *priv = toolbar->priv;
- gint n_pixels;
-
- if (!priv->animation)
- return to;
-
- if (elapsed <= ACCEL_THRESHOLD)
- {
- n_pixels = SLIDE_SPEED * elapsed;
- }
- else
- {
- /* The formula is a second degree polynomial in
- * @elapsed that has the line SLIDE_SPEED * @elapsed
- * as tangent for @elapsed == ACCEL_THRESHOLD.
- * This makes @n_pixels a smooth function of elapsed time.
- */
- n_pixels = (SLIDE_SPEED / ACCEL_THRESHOLD) * elapsed * elapsed -
- SLIDE_SPEED * elapsed + SLIDE_SPEED * ACCEL_THRESHOLD;
- }
-
- if (to > from)
- return MIN (from + n_pixels, to);
- else
- return MAX (from - n_pixels, to);
-}
-
-static void
-compute_intermediate_allocation (GtkToolbar *toolbar,
- const GtkAllocation *start,
- const GtkAllocation *goal,
- GtkAllocation *intermediate)
-{
- GtkToolbarPrivate *priv = toolbar->priv;
- gdouble elapsed = g_timer_elapsed (priv->timer, NULL);
-
- intermediate->x = position (toolbar, start->x, goal->x, elapsed);
- intermediate->y = position (toolbar, start->y, goal->y, elapsed);
- intermediate->width = position (toolbar, start->x + start->width,
- goal->x + goal->width,
- elapsed) - intermediate->x;
- intermediate->height = position (toolbar, start->y + start->height,
- goal->y + goal->height,
- elapsed) - intermediate->y;
-}
-
-static void
-fixup_allocation_for_rtl (gint total_size,
- GtkAllocation *allocation)
-{
- allocation->x += (total_size - (2 * allocation->x + allocation->width));
-}
-
-static void
-fixup_allocation_for_vertical (GtkAllocation *allocation)
-{
- gint tmp;
-
- tmp = allocation->x;
- allocation->x = allocation->y;
- allocation->y = tmp;
-
- tmp = allocation->width;
- allocation->width = allocation->height;
- allocation->height = tmp;
-}
-
-static gint
-get_item_size (GtkToolbar *toolbar,
- ToolbarContent *content)
-{
- GtkToolbarPrivate *priv = toolbar->priv;
- GtkRequisition requisition;
-
- toolbar_content_size_request (content, toolbar, &requisition);
-
- if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
- {
- if (toolbar_content_is_homogeneous (content, toolbar))
- return priv->button_maxw;
- else
- return requisition.width;
- }
- else
- {
- if (toolbar_content_is_homogeneous (content, toolbar))
- return priv->button_maxh;
- else
- return requisition.height;
- }
-}
-
-static gboolean
-slide_idle_handler (gpointer data)
-{
- GtkToolbar *toolbar = GTK_TOOLBAR (data);
- GtkToolbarPrivate *priv = toolbar->priv;
- GList *list;
-
- for (list = priv->content; list != NULL; list = list->next)
- {
- ToolbarContent *content = list->data;
- ItemState state;
- GtkAllocation goal_allocation;
- GtkAllocation allocation;
- gboolean cont;
-
- state = toolbar_content_get_state (content);
- toolbar_content_get_goal_allocation (content, &goal_allocation);
- toolbar_content_get_allocation (content, &allocation);
-
- cont = FALSE;
-
- if (state == NOT_ALLOCATED)
- {
- /* an unallocated item means that size allocate has to
- * called at least once more
- */
- cont = TRUE;
- }
-
- /* An invisible item with a goal allocation of
- * 0 is already at its goal.
- */
- if ((state == NORMAL || state == OVERFLOWN) &&
- ((goal_allocation.width != 0 &&
- goal_allocation.height != 0) ||
- toolbar_content_child_visible (content)))
- {
- if ((goal_allocation.x != allocation.x ||
- goal_allocation.y != allocation.y ||
- goal_allocation.width != allocation.width ||
- goal_allocation.height != allocation.height))
- {
- /* An item is not in its right position yet. Note
- * that OVERFLOWN items do get an allocation in
- * gtk_toolbar_size_allocate(). This way you can see
- * them slide back in when you drag an item off the
- * toolbar.
- */
- cont = TRUE;
- }
- }
-
- if (toolbar_content_is_placeholder (content) &&
- toolbar_content_disappearing (content) &&
- toolbar_content_child_visible (content))
- {
- /* A disappearing placeholder is still visible.
- */
-
- cont = TRUE;
- }
-
- if (cont)
- {
- gtk_widget_queue_resize (GTK_WIDGET (toolbar));
-
- return TRUE;
- }
- }
-
- gtk_widget_queue_resize (GTK_WIDGET (toolbar));
-
- priv->is_sliding = FALSE;
- priv->idle_id = 0;
-
- return FALSE;
-}
-
-static gboolean
-rect_within (GtkAllocation *a1,
- GtkAllocation *a2)
-{
- return (a1->x >= a2->x &&
- a1->x + a1->width <= a2->x + a2->width &&
- a1->y >= a2->y &&
- a1->y + a1->height <= a2->y + a2->height);
-}
-
-static void
-gtk_toolbar_begin_sliding (GtkToolbar *toolbar)
-{
- GtkAllocation content_allocation;
- GtkWidget *widget = GTK_WIDGET (toolbar);
- GtkToolbarPrivate *priv = toolbar->priv;
- GList *list;
- gint cur_x;
- gint cur_y;
- gboolean rtl;
- gboolean vertical;
-
- /* Start the sliding. This function copies the allocation of every
- * item into content->start_allocation. For items that haven't
- * been allocated yet, we calculate their position and save that
- * in start_allocatino along with zero width and zero height.
- *
- * FIXME: It would be nice if we could share this code with
- * the equivalent in gtk_widget_size_allocate().
- */
- priv->is_sliding = TRUE;
-
- if (!priv->idle_id)
- {
- priv->idle_id = g_idle_add (slide_idle_handler, toolbar);
- g_source_set_name_by_id (priv->idle_id, "[gtk] slide_idle_handler");
- }
-
- content_allocation.x = 0;
- content_allocation.y = 0;
- content_allocation.width = gtk_widget_get_width (widget);
- content_allocation.height = gtk_widget_get_height (widget);
-
- rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
- vertical = (priv->orientation == GTK_ORIENTATION_VERTICAL);
-
- if (rtl)
- {
- cur_x = content_allocation.width;
- cur_y = content_allocation.height;
- }
- else
- {
- cur_x = 0;
- cur_y = 0;
- }
-
- for (list = priv->content; list != NULL; list = list->next)
- {
- ToolbarContent *content = list->data;
- GtkAllocation new_start_allocation;
- GtkAllocation item_allocation;
- ItemState state;
-
- state = toolbar_content_get_state (content);
- toolbar_content_get_allocation (content, &item_allocation);
-
- if ((state == NORMAL &&
- rect_within (&item_allocation, &content_allocation)) ||
- state == OVERFLOWN)
- {
- new_start_allocation = item_allocation;
- }
- else
- {
- new_start_allocation.x = cur_x;
- new_start_allocation.y = cur_y;
-
- if (vertical)
- {
- new_start_allocation.width = content_allocation.width;
- new_start_allocation.height = 0;
- }
- else
- {
- new_start_allocation.width = 0;
- new_start_allocation.height = content_allocation.height;
- }
- }
-
- if (vertical)
- cur_y = new_start_allocation.y + new_start_allocation.height;
- else if (rtl)
- cur_x = new_start_allocation.x;
- else
- cur_x = new_start_allocation.x + new_start_allocation.width;
-
- toolbar_content_set_start_allocation (content, &new_start_allocation);
- }
-
- /* This resize will run before the first idle handler. This
- * will make sure that items get the right goal allocation
- * so that the idle handler will not immediately return
- * FALSE
- */
- gtk_widget_queue_resize (GTK_WIDGET (toolbar));
- g_timer_reset (priv->timer);
-}
-
-static void
-gtk_toolbar_stop_sliding (GtkToolbar *toolbar)
-{
- GtkToolbarPrivate *priv = toolbar->priv;
-
- if (priv->is_sliding)
- {
- GList *list;
-
- priv->is_sliding = FALSE;
-
- if (priv->idle_id)
- {
- g_source_remove (priv->idle_id);
- priv->idle_id = 0;
- }
-
- list = priv->content;
- while (list)
- {
- ToolbarContent *content = list->data;
- list = list->next;
-
- if (toolbar_content_is_placeholder (content))
- {
- toolbar_content_remove (content, toolbar);
- toolbar_content_free (content);
- }
- }
-
- gtk_widget_queue_resize (GTK_WIDGET (toolbar));
- }
-}
-
-static void
-remove_item (GtkWidget *menu_item,
- gpointer data)
-{
- gtk_container_remove (GTK_CONTAINER (gtk_widget_get_parent (menu_item)),
- menu_item);
-}
-
-static void
-button_clicked (GtkWidget *button,
- GtkWidget *item)
-{
- gtk_popover_popdown (GTK_POPOVER (gtk_widget_get_ancestor (button, GTK_TYPE_POPOVER)));
- if (GTK_IS_TOOL_BUTTON (item))
- g_signal_emit_by_name (_gtk_tool_button_get_button (GTK_TOOL_BUTTON (item)), "clicked");
-}
-
-static void
-create_popup_func (GtkMenuButton *menu_button,
- gpointer data)
-{
- GtkToolbar *toolbar = data;
- GtkToolbarPrivate *priv = toolbar->priv;
- GList *list;
-
- if (!priv->menu)
- {
- priv->menu = gtk_popover_menu_new (priv->arrow_button);
- gtk_menu_button_set_popover (GTK_MENU_BUTTON (priv->arrow_button), priv->menu);
- priv->menu_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
- gtk_popover_menu_add_submenu (GTK_POPOVER_MENU (priv->menu), priv->menu_box, "main");
- }
-
- gtk_container_foreach (GTK_CONTAINER (priv->menu_box), remove_item, NULL);
-
- for (list = priv->content; list != NULL; list = list->next)
- {
- ToolbarContent *content = list->data;
-
- if (toolbar_content_get_state (content) == OVERFLOWN &&
- !toolbar_content_is_placeholder (content))
- {
- if (toolbar_content_is_separator (content))
- gtk_container_add (GTK_CONTAINER (priv->menu_box), gtk_separator_new (GTK_ORIENTATION_HORIZONTAL));
- else if (toolbar_content_has_proxy_menu_item (content))
- {
- const char *text = toolbar_content_get_overflow_text (content);
- GtkButtonRole role = toolbar_content_get_button_role (content);
- gboolean active = toolbar_content_get_active (content);
-
- GtkWidget *button, *widget;
-
- button = gtk_model_button_new ();
- g_object_set (button,
- "text", text,
- "role", role,
- "active", active,
- NULL);
- widget = toolbar_content_get_widget (content);
- g_signal_connect (button, "clicked", G_CALLBACK (button_clicked), widget);
- gtk_container_add (GTK_CONTAINER (priv->menu_box), button);
- }
- }
- }
-
- priv->need_rebuild = FALSE;
-}
-
-static void
-gtk_toolbar_size_allocate (GtkWidget *widget,
- int width,
- int height,
- int baseline)
-{
- GtkToolbar *toolbar = GTK_TOOLBAR (widget);
- GtkToolbarPrivate *priv = toolbar->priv;
- GtkAllocation arrow_allocation, item_area;
- GtkAllocation *allocations;
- ItemState *new_states;
- gint arrow_size;
- gint size, pos, short_size;
- GList *list;
- gint i;
- gboolean need_arrow;
- gint n_expand_items;
- gint available_size;
- gint n_items;
- gint needed_size;
- GtkRequisition arrow_requisition;
- gboolean overflowing;
-
- gtk_toolbar_stop_sliding (toolbar);
-
- gtk_widget_get_preferred_size (priv->arrow_button,
- &arrow_requisition, NULL);
-
- if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
- {
- available_size = size = width;
- short_size = height;
- arrow_size = arrow_requisition.width;
- }
- else
- {
- available_size = size = height;
- short_size = width;
- arrow_size = arrow_requisition.height;
- }
-
- n_items = g_list_length (priv->content);
- allocations = g_new0 (GtkAllocation, n_items);
- new_states = g_new0 (ItemState, n_items);
-
- needed_size = 0;
- need_arrow = FALSE;
- for (list = priv->content; list != NULL; list = list->next)
- {
- ToolbarContent *content = list->data;
-
- if (toolbar_content_visible (content, toolbar))
- {
- needed_size += get_item_size (toolbar, content);
-
- /* Do we need an arrow?
- *
- * Assume we don't, and see if any non-separator item
- * with a proxy menu item is then going to overflow.
- */
- if (needed_size > available_size &&
- !need_arrow &&
- priv->show_arrow &&
- toolbar_content_has_proxy_menu_item (content) &&
- !toolbar_content_is_separator (content))
- {
- need_arrow = TRUE;
- }
- }
- }
-
- if (need_arrow)
- size = available_size - arrow_size;
- else
- size = available_size;
-
- /* calculate widths and states of items */
- overflowing = FALSE;
- for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
- {
- ToolbarContent *content = list->data;
- gint item_size;
-
- if (!toolbar_content_visible (content, toolbar))
- {
- new_states[i] = HIDDEN;
- continue;
- }
-
- item_size = get_item_size (toolbar, content);
- if (item_size <= size && !overflowing)
- {
- size -= item_size;
- allocations[i].width = item_size;
- new_states[i] = NORMAL;
- }
- else
- {
- overflowing = TRUE;
- new_states[i] = OVERFLOWN;
- allocations[i].width = item_size;
- }
- }
-
- /* calculate width of arrow */
- if (need_arrow)
- {
- arrow_allocation.width = arrow_size;
- arrow_allocation.height = MAX (short_size, 1);
- }
-
- /* expand expandable items */
-
- /* We don't expand when there is an overflow menu,
- * because that leads to weird jumps when items get
- * moved to the overflow menu and the expanding
- * items suddenly get a lot of extra space
- */
- if (!overflowing)
- {
- n_expand_items = 0;
-
- for (i = 0, list = priv->content; list != NULL; list = list->next, ++i)
- {
- ToolbarContent *content = list->data;
-
- if (toolbar_content_get_expand (content, priv->orientation) && new_states[i] == NORMAL)
- n_expand_items++;
- }
-
- for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
- {
- ToolbarContent *content = list->data;
-
- if (toolbar_content_get_expand (content, priv->orientation) && new_states[i] == NORMAL)
- {
- gint extra = size / n_expand_items;
- if (size % n_expand_items != 0)
- extra++;
-
- allocations[i].width += extra;
- size -= extra;
- n_expand_items--;
- }
- }
-
- g_assert (n_expand_items == 0);
- }
-
- /* position items */
- pos = 0;
- for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
- {
- /* Both NORMAL and OVERFLOWN items get a position.
- * This ensures that sliding will work for OVERFLOWN items too.
- */
- if (new_states[i] == NORMAL || new_states[i] == OVERFLOWN)
- {
- allocations[i].x = pos;
- allocations[i].y = 0;
- allocations[i].height = short_size;
-
- pos += allocations[i].width;
- }
- }
-
- /* position arrow */
- if (need_arrow)
- {
- arrow_allocation.x = available_size - arrow_allocation.width;
- arrow_allocation.y = 0;
- }
-
- item_area.x = 0;
- item_area.y = 0;
- item_area.width = available_size - (need_arrow? arrow_size : 0);
- item_area.height = short_size;
-
- /* fix up allocations in the vertical or RTL cases */
- if (priv->orientation == GTK_ORIENTATION_VERTICAL)
- {
- for (i = 0; i < n_items; ++i)
- fixup_allocation_for_vertical (&(allocations[i]));
-
- if (need_arrow)
- fixup_allocation_for_vertical (&arrow_allocation);
-
- fixup_allocation_for_vertical (&item_area);
- }
- else if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_RTL)
- {
- for (i = 0; i < n_items; ++i)
- fixup_allocation_for_rtl (available_size, &(allocations[i]));
-
- if (need_arrow)
- fixup_allocation_for_rtl (available_size, &arrow_allocation);
-
- fixup_allocation_for_rtl (available_size, &item_area);
- }
-
- /* did anything change? */
- for (list = priv->content, i = 0; list != NULL; list = list->next, i++)
- {
- ToolbarContent *content = list->data;
-
- if (toolbar_content_get_state (content) == NORMAL &&
- new_states[i] != NORMAL)
- {
- /* an item disappeared and we didn't change size, so begin sliding */
- gtk_toolbar_begin_sliding (toolbar);
- }
- }
-
- /* finally allocate the items */
- if (priv->is_sliding)
- {
- for (list = priv->content, i = 0; list != NULL; list = list->next, i++)
- {
- ToolbarContent *content = list->data;
-
- toolbar_content_set_goal_allocation (content, &(allocations[i]));
- }
- }
-
- for (list = priv->content, i = 0; list != NULL; list = list->next, ++i)
- {
- ToolbarContent *content = list->data;
-
- if (new_states[i] == OVERFLOWN || new_states[i] == NORMAL)
- {
- GtkAllocation alloc;
- GtkAllocation start_allocation = { 0, };
- GtkAllocation goal_allocation;
-
- if (priv->is_sliding)
- {
- toolbar_content_get_start_allocation (content, &start_allocation);
- toolbar_content_get_goal_allocation (content, &goal_allocation);
-
- compute_intermediate_allocation (toolbar,
- &start_allocation,
- &goal_allocation,
- &alloc);
- }
- else
- {
- alloc = allocations[i];
- }
-
- if (alloc.width <= 0 || alloc.height <= 0)
- {
- toolbar_content_set_child_visible (content, toolbar, FALSE);
- }
- else
- {
- if (!rect_within (&alloc, &item_area))
- {
- toolbar_content_set_child_visible (content, toolbar, FALSE);
- toolbar_content_size_allocate (content, &alloc);
- }
- else
- {
- toolbar_content_set_child_visible (content, toolbar, TRUE);
- toolbar_content_size_allocate (content, &alloc);
- }
- }
- }
- else
- {
- toolbar_content_set_child_visible (content, toolbar, FALSE);
- }
-
- toolbar_content_set_state (content, new_states[i]);
- }
-
- if (priv->menu && priv->need_rebuild)
- create_popup_func (GTK_MENU_BUTTON (priv->arrow_button), toolbar);
-
- if (need_arrow)
- {
- gtk_widget_size_allocate (GTK_WIDGET (priv->arrow_button), &arrow_allocation, -1);
- gtk_widget_show (GTK_WIDGET (priv->arrow_button));
- }
- else
- {
- gtk_widget_hide (GTK_WIDGET (priv->arrow_button));
- }
-
- g_free (allocations);
- g_free (new_states);
-}
-
-static void
-gtk_toolbar_css_changed (GtkWidget *widget,
- GtkCssStyleChange *change)
-{
- GtkToolbar *toolbar = GTK_TOOLBAR (widget);
- GtkToolbarPrivate *priv = toolbar->priv;
-
- GTK_WIDGET_CLASS (gtk_toolbar_parent_class)->css_changed (widget, change);
-
- priv->max_homogeneous_pixels = -1;
-}
-
-static GList *
-gtk_toolbar_list_children_in_focus_order (GtkToolbar *toolbar,
- GtkDirectionType dir)
-{
- GtkToolbarPrivate *priv = toolbar->priv;
- GList *result = NULL;
- GList *list;
- gboolean rtl;
-
- /* generate list of children in reverse logical order */
-
- for (list = priv->content; list != NULL; list = list->next)
- {
- ToolbarContent *content = list->data;
- GtkWidget *widget;
-
- widget = toolbar_content_get_widget (content);
-
- if (widget)
- result = g_list_prepend (result, widget);
- }
-
- result = g_list_prepend (result, priv->arrow_button);
-
- rtl = (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_RTL);
-
- /* move in logical order when
- *
- * - dir is TAB_FORWARD
- *
- * - in RTL mode and moving left or up
- *
- * - in LTR mode and moving right or down
- */
- if (dir == GTK_DIR_TAB_FORWARD ||
- (rtl && (dir == GTK_DIR_UP || dir == GTK_DIR_LEFT)) ||
- (!rtl && (dir == GTK_DIR_DOWN || dir == GTK_DIR_RIGHT)))
- {
- result = g_list_reverse (result);
- }
-
- return result;
-}
-
-static gboolean
-gtk_toolbar_focus_home_or_end (GtkToolbar *toolbar,
- gboolean focus_home)
-{
- GList *children, *list;
- GtkDirectionType dir = focus_home? GTK_DIR_RIGHT : GTK_DIR_LEFT;
-
- children = gtk_toolbar_list_children_in_focus_order (toolbar, dir);
-
- if (gtk_widget_get_direction (GTK_WIDGET (toolbar)) == GTK_TEXT_DIR_RTL)
- {
- children = g_list_reverse (children);
-
- dir = (dir == GTK_DIR_RIGHT)? GTK_DIR_LEFT : GTK_DIR_RIGHT;
- }
-
- for (list = children; list != NULL; list = list->next)
- {
- GtkWidget *child = list->data;
-
- if (gtk_widget_get_focus_child (GTK_WIDGET (toolbar)) == child)
- break;
-
- if (gtk_widget_get_mapped (child) && gtk_widget_child_focus (child, dir))
- break;
- }
-
- g_list_free (children);
-
- return TRUE;
-}
-
-/* Keybinding handler. This function is called when the user presses
- * Ctrl TAB or an arrow key.
- */
-static void
-gtk_toolbar_move_focus (GtkWidget *widget,
- GtkDirectionType dir)
-{
- GtkToolbar *toolbar = GTK_TOOLBAR (widget);
- GtkWidget *focus_child;
- GList *list;
- gboolean try_focus = FALSE;
- GList *children;
-
- focus_child = gtk_widget_get_focus_child (widget);
-
- if (focus_child && gtk_widget_child_focus (focus_child, dir))
- return;
-
- children = gtk_toolbar_list_children_in_focus_order (toolbar, dir);
-
- for (list = children; list != NULL; list = list->next)
- {
- GtkWidget *child = list->data;
-
- if (try_focus && gtk_widget_get_mapped (child) && gtk_widget_child_focus (child, dir))
- break;
-
- if (child == focus_child)
- try_focus = TRUE;
- }
-
- g_list_free (children);
-}
-
-/* The focus handler for the toolbar. It called when the user presses
- * TAB or otherwise tries to focus the toolbar.
- */
-static gboolean
-gtk_toolbar_focus (GtkWidget *widget,
- GtkDirectionType dir)
-{
- GtkToolbar *toolbar = GTK_TOOLBAR (widget);
- GList *children, *list;
- gboolean result = FALSE;
-
- /* if focus is already somewhere inside the toolbar then return FALSE.
- * The only way focus can stay inside the toolbar is when the user presses
- * arrow keys or Ctrl TAB (both of which are handled by the
- * gtk_toolbar_move_focus() keybinding function.
- */
- if (gtk_widget_get_focus_child (widget))
- return FALSE;
-
- children = gtk_toolbar_list_children_in_focus_order (toolbar, dir);
-
- for (list = children; list != NULL; list = list->next)
- {
- GtkWidget *child = list->data;
-
- if (gtk_widget_get_mapped (child) && gtk_widget_child_focus (child, dir))
- {
- result = TRUE;
- break;
- }
- }
-
- g_list_free (children);
-
- return result;
-}
-
-static GtkSettings *
-toolbar_get_settings (GtkToolbar *toolbar)
-{
- return toolbar->priv->settings;
-}
-
-static void
-animation_change_notify (GtkToolbar *toolbar)
-{
- GtkToolbarPrivate *priv = toolbar->priv;
- GtkSettings *settings = toolbar_get_settings (toolbar);
- gboolean animation;
-
- if (settings)
- g_object_get (settings,
- "gtk-enable-animations", &animation,
- NULL);
- else
- animation = DEFAULT_ANIMATION_STATE;
-
- priv->animation = animation;
-}
-
-static void
-settings_change_notify (GtkSettings *settings,
- const GParamSpec *pspec,
- GtkToolbar *toolbar)
-{
- if (! strcmp (pspec->name, "gtk-enable-animations"))
- animation_change_notify (toolbar);
-}
-
-static void
-gtk_toolbar_root (GtkWidget *widget)
-{
- GtkToolbar *toolbar = GTK_TOOLBAR (widget);
- GtkToolbarPrivate *priv = toolbar->priv;
- GtkSettings *settings;
-
- GTK_WIDGET_CLASS (gtk_toolbar_parent_class)->root (widget);
-
- settings = gtk_widget_get_settings (GTK_WIDGET (toolbar));
-
- priv->settings_connection =
- g_signal_connect (settings, "notify",
- G_CALLBACK (settings_change_notify),
- toolbar);
-
- priv->settings = g_object_ref (settings);
-
- animation_change_notify (toolbar);
-}
-
-static void
-gtk_toolbar_unroot (GtkWidget *widget)
-{
- GtkToolbar *toolbar = GTK_TOOLBAR (widget);
- GtkToolbarPrivate *priv = toolbar->priv;
-
- if (priv->settings_connection)
- g_signal_handler_disconnect (priv->settings, priv->settings_connection);
- priv->settings_connection = 0;
- g_clear_object (&priv->settings);
-
- GTK_WIDGET_CLASS (gtk_toolbar_parent_class)->unroot (widget);
-}
-
-static int
-find_drop_index (GtkToolbar *toolbar,
- gint x,
- gint y)
-{
- GtkToolbarPrivate *priv = toolbar->priv;
- GList *interesting_content;
- GList *list;
- GtkOrientation orientation;
- GtkTextDirection direction;
- gint best_distance = G_MAXINT;
- gint distance;
- gint cursor;
- gint pos;
- ToolbarContent *best_content;
- GtkAllocation allocation;
-
- /* list items we care about wrt. drag and drop */
- interesting_content = NULL;
- for (list = priv->content; list != NULL; list = list->next)
- {
- ToolbarContent *content = list->data;
-
- if (toolbar_content_get_state (content) == NORMAL)
- interesting_content = g_list_prepend (interesting_content, content);
- }
- interesting_content = g_list_reverse (interesting_content);
-
- if (!interesting_content)
- return 0;
-
- orientation = priv->orientation;
- direction = gtk_widget_get_direction (GTK_WIDGET (toolbar));
-
- /* distance to first interesting item */
- best_content = interesting_content->data;
- toolbar_content_get_allocation (best_content, &allocation);
-
- if (orientation == GTK_ORIENTATION_HORIZONTAL)
- {
- cursor = x;
-
- if (direction == GTK_TEXT_DIR_LTR)
- pos = allocation.x;
- else
- pos = allocation.x + allocation.width;
- }
- else
- {
- cursor = y;
- pos = allocation.y;
- }
-
- best_content = NULL;
- best_distance = ABS (pos - cursor);
-
- /* distance to far end of each item */
- for (list = interesting_content; list != NULL; list = list->next)
- {
- ToolbarContent *content = list->data;
-
- toolbar_content_get_allocation (content, &allocation);
-
- if (orientation == GTK_ORIENTATION_HORIZONTAL)
- {
- if (direction == GTK_TEXT_DIR_LTR)
- pos = allocation.x + allocation.width;
- else
- pos = allocation.x;
- }
- else
- {
- pos = allocation.y + allocation.height;
- }
-
- distance = ABS (pos - cursor);
-
- if (distance < best_distance)
- {
- best_distance = distance;
- best_content = content;
- }
- }
-
- g_list_free (interesting_content);
-
- if (!best_content)
- return 0;
- else
- return g_list_index (priv->content, best_content) + 1;
-}
-
-static void
-reset_all_placeholders (GtkToolbar *toolbar)
-{
- GtkToolbarPrivate *priv = toolbar->priv;
- GList *list;
-
- for (list = priv->content; list != NULL; list = list->next)
- {
- ToolbarContent *content = list->data;
- if (toolbar_content_is_placeholder (content))
- toolbar_content_set_disappearing (content, TRUE);
- }
-}
-
-static gint
-physical_to_logical (GtkToolbar *toolbar,
- gint physical)
-{
- GtkToolbarPrivate *priv = toolbar->priv;
- GList *list;
- int logical;
-
- g_assert (physical >= 0);
-
- logical = 0;
- for (list = priv->content; list && physical > 0; list = list->next)
- {
- ToolbarContent *content = list->data;
-
- if (!toolbar_content_is_placeholder (content))
- logical++;
- physical--;
- }
-
- g_assert (physical == 0);
-
- return logical;
-}
-
-static gint
-logical_to_physical (GtkToolbar *toolbar,
- gint logical)
-{
- GtkToolbarPrivate *priv = toolbar->priv;
- GList *list;
- gint physical;
-
- g_assert (logical >= 0);
-
- physical = 0;
- for (list = priv->content; list; list = list->next)
- {
- ToolbarContent *content = list->data;
-
- if (!toolbar_content_is_placeholder (content))
- {
- if (logical == 0)
- break;
- logical--;
- }
-
- physical++;
- }
-
- g_assert (logical == 0);
-
- return physical;
-}
-
-/**
- * gtk_toolbar_set_drop_highlight_item:
- * @toolbar: a #GtkToolbar
- * @tool_item: (allow-none): a #GtkToolItem, or %NULL to turn of highlighting
- * @index_: a position on @toolbar
- *
- * Highlights @toolbar to give an idea of what it would look like
- * if @item was added to @toolbar at the position indicated by @index_.
- * If @item is %NULL, highlighting is turned off. In that case @index_
- * is ignored.
- *
- * The @tool_item passed to this function must not be part of any widget
- * hierarchy. When an item is set as drop highlight item it can not
- * added to any widget hierarchy or used as highlight item for another
- * toolbar.
- **/
-void
-gtk_toolbar_set_drop_highlight_item (GtkToolbar *toolbar,
- GtkToolItem *tool_item,
- gint index_)
-{
- ToolbarContent *content;
- GtkToolbarPrivate *priv;
- gint n_items;
- GtkRequisition requisition;
- GtkRequisition old_requisition;
- gboolean restart_sliding;
-
- g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
- g_return_if_fail (tool_item == NULL || GTK_IS_TOOL_ITEM (tool_item));
-
- priv = toolbar->priv;
-
- if (!tool_item)
- {
- if (priv->highlight_tool_item)
- {
- gtk_widget_unparent (GTK_WIDGET (priv->highlight_tool_item));
- g_object_unref (priv->highlight_tool_item);
- priv->highlight_tool_item = NULL;
- }
-
- reset_all_placeholders (toolbar);
- gtk_toolbar_begin_sliding (toolbar);
- return;
- }
-
- n_items = gtk_toolbar_get_n_items (toolbar);
- if (index_ < 0 || index_ > n_items)
- index_ = n_items;
-
- if (tool_item != priv->highlight_tool_item)
- {
- if (priv->highlight_tool_item)
- g_object_unref (priv->highlight_tool_item);
-
- g_object_ref_sink (tool_item);
-
- priv->highlight_tool_item = tool_item;
-
- gtk_widget_set_parent (GTK_WIDGET (priv->highlight_tool_item),
- GTK_WIDGET (toolbar));
- }
-
- index_ = logical_to_physical (toolbar, index_);
-
- content = g_list_nth_data (priv->content, index_);
-
- if (index_ > 0)
- {
- ToolbarContent *prev_content;
-
- prev_content = g_list_nth_data (priv->content, index_ - 1);
-
- if (prev_content && toolbar_content_is_placeholder (prev_content))
- content = prev_content;
- }
-
- if (!content || !toolbar_content_is_placeholder (content))
- {
- GtkWidget *placeholder;
-
- placeholder = GTK_WIDGET (gtk_separator_tool_item_new ());
-
- content = toolbar_content_new_tool_item (toolbar,
- GTK_TOOL_ITEM (placeholder),
- TRUE, index_);
- }
-
- g_assert (content);
- g_assert (toolbar_content_is_placeholder (content));
-
- gtk_widget_get_preferred_size (GTK_WIDGET (priv->highlight_tool_item),
- &requisition, NULL);
-
- toolbar_content_set_expand (content, gtk_tool_item_get_expand (tool_item));
-
- restart_sliding = FALSE;
- toolbar_content_size_request (content, toolbar, &old_requisition);
- if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
- {
- requisition.height = -1;
- if (requisition.width != old_requisition.width)
- restart_sliding = TRUE;
- }
- else
- {
- requisition.width = -1;
- if (requisition.height != old_requisition.height)
- restart_sliding = TRUE;
- }
-
- if (toolbar_content_disappearing (content))
- restart_sliding = TRUE;
-
- reset_all_placeholders (toolbar);
- toolbar_content_set_disappearing (content, FALSE);
-
- toolbar_content_set_size_request (content,
- requisition.width, requisition.height);
-
- if (restart_sliding)
- gtk_toolbar_begin_sliding (toolbar);
-}
-
-static void
-gtk_toolbar_add (GtkContainer *container,
- GtkWidget *widget)
-{
- GtkToolbar *toolbar = GTK_TOOLBAR (container);
-
- gtk_toolbar_insert (toolbar, GTK_TOOL_ITEM (widget), -1);
-}
-
-static void
-gtk_toolbar_remove (GtkContainer *container,
- GtkWidget *widget)
-{
- GtkToolbar *toolbar = GTK_TOOLBAR (container);
- GtkToolbarPrivate *priv = toolbar->priv;
- ToolbarContent *content_to_remove;
- GList *list;
-
- content_to_remove = NULL;
- for (list = priv->content; list != NULL; list = list->next)
- {
- ToolbarContent *content = list->data;
- GtkWidget *child;
-
- child = toolbar_content_get_widget (content);
- if (child && child == widget)
- {
- content_to_remove = content;
- break;
- }
- }
-
- g_return_if_fail (content_to_remove != NULL);
-
- toolbar_content_remove (content_to_remove, toolbar);
- toolbar_content_free (content_to_remove);
-}
-
-static void
-gtk_toolbar_forall (GtkContainer *container,
- GtkCallback callback,
- gpointer callback_data)
-{
- GtkToolbar *toolbar = GTK_TOOLBAR (container);
- GtkToolbarPrivate *priv = toolbar->priv;
- GList *list;
-
- g_return_if_fail (callback != NULL);
-
- list = priv->content;
- while (list)
- {
- ToolbarContent *content = list->data;
- GList *next = list->next;
-
- if (!toolbar_content_is_placeholder (content))
- {
- GtkWidget *child = toolbar_content_get_widget (content);
-
- if (child)
- callback (child, callback_data);
- }
-
- list = next;
- }
-}
-
-static GType
-gtk_toolbar_child_type (GtkContainer *container)
-{
- return GTK_TYPE_TOOL_ITEM;
-}
-
-static void
-gtk_toolbar_reconfigured (GtkToolbar *toolbar)
-{
- GtkToolbarPrivate *priv = toolbar->priv;
- GList *list;
-
- list = priv->content;
- while (list)
- {
- ToolbarContent *content = list->data;
- GList *next = list->next;
-
- toolbar_content_toolbar_reconfigured (content, toolbar);
-
- list = next;
- }
-}
-
-static void
-gtk_toolbar_orientation_changed (GtkToolbar *toolbar,
- GtkOrientation orientation)
-{
- GtkToolbarPrivate *priv = toolbar->priv;
-
- if (priv->orientation != orientation)
- {
- priv->orientation = orientation;
-
- if (orientation == GTK_ORIENTATION_HORIZONTAL)
- gtk_menu_button_set_direction (GTK_MENU_BUTTON (priv->arrow_button), GTK_ARROW_DOWN);
- else
- gtk_menu_button_set_direction (GTK_MENU_BUTTON (priv->arrow_button), GTK_ARROW_RIGHT);
-
- gtk_toolbar_reconfigured (toolbar);
-
- _gtk_orientable_set_style_classes (GTK_ORIENTABLE (toolbar));
- gtk_widget_queue_resize (GTK_WIDGET (toolbar));
- g_object_notify (G_OBJECT (toolbar), "orientation");
- }
-}
-
-static void
-gtk_toolbar_real_style_changed (GtkToolbar *toolbar,
- GtkToolbarStyle style)
-{
- GtkToolbarPrivate *priv = toolbar->priv;
-
- if (priv->style != style)
- {
- priv->style = style;
-
- gtk_toolbar_reconfigured (toolbar);
-
- gtk_widget_queue_resize (GTK_WIDGET (toolbar));
- g_object_notify (G_OBJECT (toolbar), "toolbar-style");
- }
-}
-
-static void
-gtk_toolbar_pressed_cb (GtkGestureClick *gesture,
- int n_press,
- double x,
- double y,
- gpointer user_data)
-{
- GtkToolbar *toolbar = user_data;
- GdkEventSequence *sequence = gtk_gesture_single_get_current_sequence (GTK_GESTURE_SINGLE (gesture));
- const GdkEvent *event = gtk_gesture_get_last_event (GTK_GESTURE (gesture), sequence);
- int button = gtk_gesture_single_get_current_button (GTK_GESTURE_SINGLE (gesture));
-
- if (gdk_event_triggers_context_menu (event))
- {
- gboolean return_value;
-
- g_signal_emit (toolbar, toolbar_signals[POPUP_CONTEXT_MENU], 0,
- (int)x, (int)y, button, &return_value);
-
- if (return_value)
- gtk_gesture_set_state (GTK_GESTURE (gesture), GTK_EVENT_SEQUENCE_CLAIMED);
- else
- gtk_gesture_set_state (GTK_GESTURE (gesture), GTK_EVENT_SEQUENCE_DENIED);
- }
-}
-
-static gboolean
-gtk_toolbar_popup_menu (GtkWidget *toolbar)
-{
- gboolean return_value;
- /* This function is the handler for the "popup menu" keybinding,
- * ie., it is called when the user presses Shift F10
- */
- g_signal_emit (toolbar, toolbar_signals[POPUP_CONTEXT_MENU], 0,
- -1, -1, -1, &return_value);
-
- return return_value;
-}
-
-/**
- * gtk_toolbar_new:
- *
- * Creates a new toolbar.
-
- * Returns: the newly-created toolbar.
- **/
-GtkWidget *
-gtk_toolbar_new (void)
-{
- GtkToolbar *toolbar;
-
- toolbar = g_object_new (GTK_TYPE_TOOLBAR, NULL);
-
- return GTK_WIDGET (toolbar);
-}
-
-/**
- * gtk_toolbar_insert:
- * @toolbar: a #GtkToolbar
- * @item: a #GtkToolItem
- * @pos: the position of the new item
- *
- * Insert a #GtkToolItem into the toolbar at position @pos. If @pos is
- * 0 the item is prepended to the start of the toolbar. If @pos is
- * negative, the item is appended to the end of the toolbar.
- **/
-void
-gtk_toolbar_insert (GtkToolbar *toolbar,
- GtkToolItem *item,
- gint pos)
-{
- g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
- g_return_if_fail (GTK_IS_TOOL_ITEM (item));
-
- pos = MIN (pos, (int)g_list_length (toolbar->priv->content));
-
- if (pos >= 0)
- pos = logical_to_physical (toolbar, pos);
-
- toolbar_content_new_tool_item (toolbar, item, FALSE, pos);
-}
-
-/**
- * gtk_toolbar_get_item_index:
- * @toolbar: a #GtkToolbar
- * @item: a #GtkToolItem that is a child of @toolbar
- *
- * Returns the position of @item on the toolbar, starting from 0.
- * It is an error if @item is not a child of the toolbar.
- *
- * Returns: the position of item on the toolbar.
- **/
-gint
-gtk_toolbar_get_item_index (GtkToolbar *toolbar,
- GtkToolItem *item)
-{
- GtkToolbarPrivate *priv;
- GList *list;
- int n;
-
- g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), -1);
- g_return_val_if_fail (GTK_IS_TOOL_ITEM (item), -1);
- g_return_val_if_fail (gtk_widget_get_parent (GTK_WIDGET (item)) == GTK_WIDGET (toolbar), -1);
-
- priv = toolbar->priv;
-
- n = 0;
- for (list = priv->content; list != NULL; list = list->next)
- {
- ToolbarContent *content = list->data;
- GtkWidget *widget;
-
- widget = toolbar_content_get_widget (content);
-
- if (item == GTK_TOOL_ITEM (widget))
- break;
-
- ++n;
- }
-
- return physical_to_logical (toolbar, n);
-}
-
-/**
- * gtk_toolbar_set_style:
- * @toolbar: a #GtkToolbar.
- * @style: the new style for @toolbar.
- *
- * Alters the view of @toolbar to display either icons only, text only, or both.
- **/
-void
-gtk_toolbar_set_style (GtkToolbar *toolbar,
- GtkToolbarStyle style)
-{
- GtkToolbarPrivate *priv;
-
- g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
-
- priv = toolbar->priv;
-
- priv->style_set = TRUE;
- g_signal_emit (toolbar, toolbar_signals[STYLE_CHANGED], 0, style);
-}
-
-/**
- * gtk_toolbar_get_style:
- * @toolbar: a #GtkToolbar
- *
- * Retrieves whether the toolbar has text, icons, or both . See
- * gtk_toolbar_set_style().
-
- * Returns: the current style of @toolbar
- **/
-GtkToolbarStyle
-gtk_toolbar_get_style (GtkToolbar *toolbar)
-{
- g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), DEFAULT_TOOLBAR_STYLE);
-
- return toolbar->priv->style;
-}
-
-/**
- * gtk_toolbar_unset_style:
- * @toolbar: a #GtkToolbar
- *
- * Unsets a toolbar style set with gtk_toolbar_set_style(), so that
- * user preferences will be used to determine the toolbar style.
- **/
-void
-gtk_toolbar_unset_style (GtkToolbar *toolbar)
-{
- GtkToolbarPrivate *priv;
- GtkToolbarStyle style;
-
- g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
-
- priv = toolbar->priv;
-
- if (priv->style_set)
- {
- style = DEFAULT_TOOLBAR_STYLE;
-
- if (style != priv->style)
- g_signal_emit (toolbar, toolbar_signals[STYLE_CHANGED], 0, style);
-
- priv->style_set = FALSE;
- }
-}
-
-/**
- * gtk_toolbar_get_n_items:
- * @toolbar: a #GtkToolbar
- *
- * Returns the number of items on the toolbar.
- *
- * Returns: the number of items on the toolbar
- **/
-gint
-gtk_toolbar_get_n_items (GtkToolbar *toolbar)
-{
- GtkToolbarPrivate *priv;
-
- g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), -1);
-
- priv = toolbar->priv;
-
- return physical_to_logical (toolbar, g_list_length (priv->content));
-}
-
-/**
- * gtk_toolbar_get_nth_item:
- * @toolbar: a #GtkToolbar
- * @n: A position on the toolbar
- *
- * Returns the @n'th item on @toolbar, or %NULL if the
- * toolbar does not contain an @n'th item.
- *
- * Returns: (nullable) (transfer none): The @n'th #GtkToolItem on @toolbar,
- * or %NULL if there isn’t an @n'th item.
- **/
-GtkToolItem *
-gtk_toolbar_get_nth_item (GtkToolbar *toolbar,
- gint n)
-{
- GtkToolbarPrivate *priv;
- ToolbarContent *content;
- gint n_items;
-
- g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), NULL);
-
- priv = toolbar->priv;
-
- n_items = gtk_toolbar_get_n_items (toolbar);
-
- if (n < 0 || n >= n_items)
- return NULL;
-
- content = g_list_nth_data (priv->content, logical_to_physical (toolbar, n));
-
- g_assert (content);
- g_assert (!toolbar_content_is_placeholder (content));
-
- return GTK_TOOL_ITEM (toolbar_content_get_widget (content));
-}
-
-/**
- * gtk_toolbar_set_show_arrow:
- * @toolbar: a #GtkToolbar
- * @show_arrow: Whether to show an overflow menu
- *
- * Sets whether to show an overflow menu when @toolbar isn’t allocated enough
- * size to show all of its items. If %TRUE, items which can’t fit in @toolbar,
- * and which have a proxy menu item set by gtk_tool_item_set_proxy_menu_item()
- * or #GtkToolItem::create-menu-proxy, will be available in an overflow menu,
- * which can be opened by an added arrow button. If %FALSE, @toolbar will
- * request enough size to fit all of its child items without any overflow.
- **/
-void
-gtk_toolbar_set_show_arrow (GtkToolbar *toolbar,
- gboolean show_arrow)
-{
- GtkToolbarPrivate *priv;
-
- g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
-
- priv = toolbar->priv;
-
- show_arrow = show_arrow != FALSE;
-
- if (priv->show_arrow != show_arrow)
- {
- priv->show_arrow = show_arrow;
-
- if (!priv->show_arrow)
- gtk_widget_hide (priv->arrow_button);
-
- gtk_widget_queue_resize (GTK_WIDGET (toolbar));
- g_object_notify (G_OBJECT (toolbar), "show-arrow");
- }
-}
-
-/**
- * gtk_toolbar_get_show_arrow:
- * @toolbar: a #GtkToolbar
- *
- * Returns whether the toolbar has an overflow menu.
- * See gtk_toolbar_set_show_arrow().
- *
- * Returns: %TRUE if the toolbar has an overflow menu.
- **/
-gboolean
-gtk_toolbar_get_show_arrow (GtkToolbar *toolbar)
-{
- g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), FALSE);
-
- return toolbar->priv->show_arrow;
-}
-
-/**
- * gtk_toolbar_get_drop_index:
- * @toolbar: a #GtkToolbar
- * @x: x coordinate of a point on the toolbar
- * @y: y coordinate of a point on the toolbar
- *
- * Returns the position corresponding to the indicated point on
- * @toolbar. This is useful when dragging items to the toolbar:
- * this function returns the position a new item should be
- * inserted.
- *
- * @x and @y are in @toolbar coordinates.
- *
- * Returns: The position corresponding to the point (@x, @y) on the toolbar.
- **/
-gint
-gtk_toolbar_get_drop_index (GtkToolbar *toolbar,
- gint x,
- gint y)
-{
- g_return_val_if_fail (GTK_IS_TOOLBAR (toolbar), -1);
-
- return physical_to_logical (toolbar, find_drop_index (toolbar, x, y));
-}
-
-static void
-gtk_toolbar_dispose (GObject *object)
-{
- GtkToolbar *toolbar = GTK_TOOLBAR (object);
- GtkToolbarPrivate *priv = toolbar->priv;
-
- g_clear_pointer (&priv->arrow_button, gtk_widget_unparent);
-
- if (priv->settings_connection > 0)
- {
- g_signal_handler_disconnect (priv->settings, priv->settings_connection);
- priv->settings_connection = 0;
- }
-
- g_clear_object (&priv->settings);
-
- G_OBJECT_CLASS (gtk_toolbar_parent_class)->dispose (object);
-}
-
-static void
-gtk_toolbar_finalize (GObject *object)
-{
- GtkToolbar *toolbar = GTK_TOOLBAR (object);
- GtkToolbarPrivate *priv = toolbar->priv;
-
- g_list_free_full (priv->content, (GDestroyNotify)toolbar_content_free);
-
- g_timer_destroy (priv->timer);
-
- if (priv->idle_id)
- g_source_remove (priv->idle_id);
-
- G_OBJECT_CLASS (gtk_toolbar_parent_class)->finalize (object);
-}
-
-/*
- * ToolbarContent methods
- */
-typedef enum {
- UNKNOWN,
- YES,
- NO
-} TriState;
-
-struct _ToolbarContent
-{
- ItemState state;
-
- GtkToolItem *item;
- GtkAllocation allocation;
- GtkAllocation start_allocation;
- GtkAllocation goal_allocation;
- guint is_placeholder : 1;
- guint disappearing : 1;
- guint has_menu : 2;
-};
-
-static ToolbarContent *
-toolbar_content_new_tool_item (GtkToolbar *toolbar,
- GtkToolItem *item,
- gboolean is_placeholder,
- gint pos)
-{
- GtkToolbarPrivate *priv = toolbar->priv;
- ToolbarContent *content, *previous;
-
- content = g_slice_new0 (ToolbarContent);
-
- content->state = NOT_ALLOCATED;
- content->item = item;
- content->is_placeholder = is_placeholder;
-
- previous = pos > 0 ? g_list_nth_data (priv->content, -1) : NULL;
- priv->content = g_list_insert (priv->content, content, pos);
-
- gtk_widget_insert_after (GTK_WIDGET (item), GTK_WIDGET (toolbar),
- previous ? GTK_WIDGET (previous->item) : NULL);
-
- if (!is_placeholder)
- {
- priv->num_children++;
-
- gtk_toolbar_stop_sliding (toolbar);
- }
-
- gtk_widget_queue_resize (GTK_WIDGET (toolbar));
- priv->need_rebuild = TRUE;
-
- return content;
-}
-
-static void
-toolbar_content_remove (ToolbarContent *content,
- GtkToolbar *toolbar)
-{
- GtkToolbarPrivate *priv = toolbar->priv;
-
- gtk_widget_unparent (GTK_WIDGET (content->item));
-
- priv->content = g_list_remove (priv->content, content);
-
- if (!toolbar_content_is_placeholder (content))
- priv->num_children--;
-
- gtk_widget_queue_resize (GTK_WIDGET (toolbar));
- priv->need_rebuild = TRUE;
-}
-
-static void
-toolbar_content_free (ToolbarContent *content)
-{
- g_slice_free (ToolbarContent, content);
-}
-
-static gint
-calculate_max_homogeneous_pixels (GtkWidget *widget)
-{
- PangoContext *context;
- PangoFontMetrics *metrics;
- gint char_width;
-
- context = gtk_widget_get_pango_context (widget);
-
- metrics = pango_context_get_metrics (context,
- pango_context_get_font_description (context),
- pango_context_get_language (context));
- char_width = pango_font_metrics_get_approximate_char_width (metrics);
- pango_font_metrics_unref (metrics);
-
- return PANGO_PIXELS (MAX_HOMOGENEOUS_N_CHARS * char_width);
-}
-
-static void
-toolbar_content_snapshot (ToolbarContent *content,
- GtkContainer *container,
- GtkSnapshot *snapshot)
-{
- GtkWidget *widget;
-
- if (content->is_placeholder)
- return;
-
- widget = GTK_WIDGET (content->item);
-
- if (widget)
- gtk_widget_snapshot_child (GTK_WIDGET (container), widget, snapshot);
-}
-
-static gboolean
-toolbar_content_visible (ToolbarContent *content,
- GtkToolbar *toolbar)
-{
- GtkToolbarPrivate *priv = toolbar->priv;
- GtkToolItem *item;
-
- item = content->item;
-
- if (!gtk_widget_get_visible (GTK_WIDGET (item)))
- return FALSE;
-
- if (priv->orientation == GTK_ORIENTATION_HORIZONTAL &&
- gtk_tool_item_get_visible_horizontal (item))
- return TRUE;
-
- if (priv->orientation == GTK_ORIENTATION_VERTICAL &&
- gtk_tool_item_get_visible_vertical (item))
- return TRUE;
-
- return FALSE;
-}
-
-static void
-toolbar_content_size_request (ToolbarContent *content,
- GtkToolbar *toolbar,
- GtkRequisition *requisition)
-{
- gtk_widget_get_preferred_size (GTK_WIDGET (content->item),
- requisition, NULL);
- if (content->is_placeholder &&
- content->disappearing)
- {
- requisition->width = 0;
- requisition->height = 0;
- }
-}
-
-static gboolean
-toolbar_content_is_homogeneous (ToolbarContent *content,
- GtkToolbar *toolbar)
-{
- GtkToolbarPrivate *priv = toolbar->priv;
- GtkRequisition requisition;
- gboolean result;
-
- if (priv->max_homogeneous_pixels < 0)
- {
- priv->max_homogeneous_pixels =
- calculate_max_homogeneous_pixels (GTK_WIDGET (toolbar));
- }
-
- toolbar_content_size_request (content, toolbar, &requisition);
-
- if (requisition.width > priv->max_homogeneous_pixels)
- return FALSE;
-
- result = gtk_tool_item_get_homogeneous (content->item) &&
- !GTK_IS_SEPARATOR_TOOL_ITEM (content->item);
-
- if (gtk_tool_item_get_is_important (content->item) &&
- priv->style == GTK_TOOLBAR_BOTH_HORIZ &&
- priv->orientation == GTK_ORIENTATION_HORIZONTAL)
- {
- result = FALSE;
- }
-
- return result;
-}
-
-static gboolean
-toolbar_content_is_placeholder (ToolbarContent *content)
-{
- if (content->is_placeholder)
- return TRUE;
-
- return FALSE;
-}
-
-static gboolean
-toolbar_content_disappearing (ToolbarContent *content)
-{
- if (content->disappearing)
- return TRUE;
-
- return FALSE;
-}
-
-static ItemState
-toolbar_content_get_state (ToolbarContent *content)
-{
- return content->state;
-}
-
-static gboolean
-toolbar_content_child_visible (ToolbarContent *content)
-{
- return gtk_widget_get_child_visible (GTK_WIDGET (content->item));
-}
-
-static void
-toolbar_content_get_goal_allocation (ToolbarContent *content,
- GtkAllocation *allocation)
-{
- *allocation = content->goal_allocation;
-}
-
-static void
-toolbar_content_get_allocation (ToolbarContent *content,
- GtkAllocation *allocation)
-{
- *allocation = content->allocation;
-}
-
-static void
-toolbar_content_set_start_allocation (ToolbarContent *content,
- GtkAllocation *allocation)
-{
- content->start_allocation = *allocation;
-}
-
-static gboolean
-toolbar_content_get_expand (ToolbarContent *content, GtkOrientation orientation)
-{
- if (!content->disappearing &&
- (gtk_tool_item_get_expand (content->item) || gtk_widget_compute_expand (GTK_WIDGET (content->item), orientation)))
- return TRUE;
-
- return FALSE;
-}
-
-static void
-toolbar_content_set_goal_allocation (ToolbarContent *content,
- GtkAllocation *allocation)
-{
- content->goal_allocation = *allocation;
-}
-
-static void
-toolbar_content_set_child_visible (ToolbarContent *content,
- GtkToolbar *toolbar,
- gboolean visible)
-{
- gtk_widget_set_child_visible (GTK_WIDGET (content->item),
- visible);
-}
-
-static void
-toolbar_content_get_start_allocation (ToolbarContent *content,
- GtkAllocation *start_allocation)
-{
- *start_allocation = content->start_allocation;
-}
-
-static void
-toolbar_content_size_allocate (ToolbarContent *content,
- GtkAllocation *allocation)
-{
- content->allocation = *allocation;
- gtk_widget_size_allocate (GTK_WIDGET (content->item), allocation, -1);
-}
-
-static void
-toolbar_content_set_state (ToolbarContent *content,
- ItemState state)
-{
- content->state = state;
-}
-
-static GtkWidget *
-toolbar_content_get_widget (ToolbarContent *content)
-{
- return GTK_WIDGET (content->item);
-}
-
-
-static void
-toolbar_content_set_disappearing (ToolbarContent *content,
- gboolean disappearing)
-{
- content->disappearing = disappearing;
-}
-
-static void
-toolbar_content_set_size_request (ToolbarContent *content,
- gint width,
- gint height)
-{
- gtk_widget_set_size_request (GTK_WIDGET (content->item),
- width, height);
-}
-
-static void
-toolbar_content_toolbar_reconfigured (ToolbarContent *content,
- GtkToolbar *toolbar)
-{
- gtk_tool_item_toolbar_reconfigured (content->item);
-}
-
-static const char *
-toolbar_content_get_overflow_text (ToolbarContent *content)
-{
- return gtk_tool_item_get_overflow_text (content->item);
-}
-
-static gboolean
-toolbar_content_has_proxy_menu_item (ToolbarContent *content)
-{
- const char *text;
-
- if (content->has_menu == YES)
- return TRUE;
- else if (content->has_menu == NO)
- return FALSE;
-
- text = toolbar_content_get_overflow_text (content);
-
- content->has_menu = text ? YES : NO;
-
- return text != NULL;
-}
-
-static void
-toolbar_content_set_unknown_menu_status (ToolbarContent *content)
-{
- content->has_menu = UNKNOWN;
-}
-
-static GtkButtonRole
-toolbar_content_get_button_role (ToolbarContent *content)
-{
- if (GTK_IS_RADIO_TOOL_BUTTON (content->item))
- return GTK_BUTTON_ROLE_RADIO;
- else if (GTK_IS_TOGGLE_TOOL_BUTTON (content->item))
- return GTK_BUTTON_ROLE_CHECK;
- else
- return GTK_BUTTON_ROLE_NORMAL;
-}
-
-static gboolean
-toolbar_content_get_active (ToolbarContent *content)
-{
- if (GTK_IS_TOGGLE_TOOL_BUTTON (content->item))
- return gtk_toggle_tool_button_get_active (GTK_TOGGLE_TOOL_BUTTON (content->item));
- else
- return FALSE;
-}
-
-static gboolean
-toolbar_content_is_separator (ToolbarContent *content)
-{
- return GTK_IS_SEPARATOR_TOOL_ITEM (content->item);
-}
-
-static void
-toolbar_content_set_expand (ToolbarContent *content,
- gboolean expand)
-{
- gtk_tool_item_set_expand (content->item, expand);
-}
-
-/* GTK+ internal methods */
-gchar *
-_gtk_toolbar_elide_underscores (const gchar *original)
-{
- gchar *q, *result;
- const gchar *p, *end;
- gsize len;
- gboolean last_underscore;
-
- if (!original)
- return NULL;
-
- len = strlen (original);
- q = result = g_malloc (len + 1);
- last_underscore = FALSE;
-
- end = original + len;
- for (p = original; p < end; p++)
- {
- if (!last_underscore && *p == '_')
- last_underscore = TRUE;
- else
- {
- last_underscore = FALSE;
- if (original + 2 <= p && p + 1 <= end &&
- p[-2] == '(' && p[-1] == '_' && p[0] != '_' && p[1] == ')')
- {
- q--;
- *q = '\0';
- p++;
- }
- else
- *q++ = *p;
- }
- }
-
- if (last_underscore)
- *q++ = '_';
-
- *q = '\0';
-
- return result;
-}
-
-static GtkOrientation
-toolbar_get_orientation (GtkToolShell *shell)
-{
- GtkToolbar *toolbar = GTK_TOOLBAR (shell);
- GtkToolbarPrivate *priv = toolbar->priv;
-
- return priv->orientation;
-}
-
-static GtkToolbarStyle
-toolbar_get_style (GtkToolShell *shell)
-{
- GtkToolbar *toolbar = GTK_TOOLBAR (shell);
- GtkToolbarPrivate *priv = toolbar->priv;
-
- return priv->style;
-}
-
-static void
-toolbar_rebuild_menu (GtkToolShell *shell)
-{
- GtkToolbar *toolbar = GTK_TOOLBAR (shell);
- GtkToolbarPrivate *priv = toolbar->priv;
- GList *list;
-
- priv->need_rebuild = TRUE;
-
- for (list = priv->content; list != NULL; list = list->next)
- {
- ToolbarContent *content = list->data;
-
- toolbar_content_set_unknown_menu_status (content);
- }
-
- gtk_widget_queue_resize (GTK_WIDGET (shell));
-}
+++ /dev/null
-/* GTK - The GIMP Toolkit
- * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
- * GtkToolbar copyright (C) Federico Mena
- *
- * Copyright (C) 2002 Anders Carlsson <andersca@gnome.org>
- * Copyright (C) 2002 James Henstridge <james@daa.com.au>
- * Copyright (C) 2003 Soeren Sandmann <sandmann@daimi.au.dk>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/*
- * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
- * file for a list of people on the GTK+ Team. See the ChangeLog
- * files for a list of changes. These files are distributed with
- * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
- */
-
-#ifndef __GTK_TOOLBAR_H__
-#define __GTK_TOOLBAR_H__
-
-
-#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
-#error "Only <gtk/gtk.h> can be included directly."
-#endif
-
-#include <gtk/gtkcontainer.h>
-#include <gtk/gtktoolitem.h>
-
-G_BEGIN_DECLS
-
-
-#define GTK_TYPE_TOOLBAR (gtk_toolbar_get_type ())
-#define GTK_TOOLBAR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_TOOLBAR, GtkToolbar))
-#define GTK_IS_TOOLBAR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_TOOLBAR))
-
-typedef struct _GtkToolbar GtkToolbar;
-
-GDK_AVAILABLE_IN_ALL
-GType gtk_toolbar_get_type (void) G_GNUC_CONST;
-GDK_AVAILABLE_IN_ALL
-GtkWidget * gtk_toolbar_new (void);
-
-GDK_AVAILABLE_IN_ALL
-void gtk_toolbar_insert (GtkToolbar *toolbar,
- GtkToolItem *item,
- gint pos);
-
-GDK_AVAILABLE_IN_ALL
-gint gtk_toolbar_get_item_index (GtkToolbar *toolbar,
- GtkToolItem *item);
-GDK_AVAILABLE_IN_ALL
-gint gtk_toolbar_get_n_items (GtkToolbar *toolbar);
-GDK_AVAILABLE_IN_ALL
-GtkToolItem * gtk_toolbar_get_nth_item (GtkToolbar *toolbar,
- gint n);
-
-GDK_AVAILABLE_IN_ALL
-gboolean gtk_toolbar_get_show_arrow (GtkToolbar *toolbar);
-GDK_AVAILABLE_IN_ALL
-void gtk_toolbar_set_show_arrow (GtkToolbar *toolbar,
- gboolean show_arrow);
-
-GDK_AVAILABLE_IN_ALL
-GtkToolbarStyle gtk_toolbar_get_style (GtkToolbar *toolbar);
-GDK_AVAILABLE_IN_ALL
-void gtk_toolbar_set_style (GtkToolbar *toolbar,
- GtkToolbarStyle style);
-GDK_AVAILABLE_IN_ALL
-void gtk_toolbar_unset_style (GtkToolbar *toolbar);
-
-GDK_AVAILABLE_IN_ALL
-gint gtk_toolbar_get_drop_index (GtkToolbar *toolbar,
- gint x,
- gint y);
-GDK_AVAILABLE_IN_ALL
-void gtk_toolbar_set_drop_highlight_item (GtkToolbar *toolbar,
- GtkToolItem *tool_item,
- gint index_);
-
-
-G_END_DECLS
-
-#endif /* __GTK_TOOLBAR_H__ */
+++ /dev/null
-/* GTK - The GIMP Toolkit
- * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
- * GtkToolbar copyright (C) Federico Mena
- *
- * Copyright (C) 2002 Anders Carlsson <andersca@gnome.org>
- * Copyright (C) 2002 James Henstridge <james@daa.com.au>
- * Copyright (C) 2003 Soeren Sandmann <sandmann@daimi.au.dk>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/*
- * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
- * file for a list of people on the GTK+ Team. See the ChangeLog
- * files for a list of changes. These files are distributed with
- * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
- */
-
-#ifndef __GTK_TOOLBAR_PRIVATE_H__
-#define __GTK_TOOLBAR_PRIVATE_H__
-
-#include <gtk/gtktoolbar.h>
-
-G_BEGIN_DECLS
-
-gchar * _gtk_toolbar_elide_underscores (const gchar *original);
-
-G_END_DECLS
-
-#endif /* __GTK_TOOLBAR_PRIVATE_H__ */
+++ /dev/null
-/* gtktoolbutton.c
- *
- * Copyright (C) 2002 Anders Carlsson <andersca@gnome.org>
- * Copyright (C) 2002 James Henstridge <james@daa.com.au>
- * Copyright (C) 2003 Soeren Sandmann <sandmann@daimi.au.dk>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "config.h"
-#include "gtktoolbutton.h"
-#include "gtkbutton.h"
-#include "gtkimageprivate.h"
-#include "gtklabel.h"
-#include "gtkbox.h"
-#include "gtkintl.h"
-#include "gtktoolbarprivate.h"
-#include "gtkicontheme.h"
-#include "gtkactionable.h"
-#include "gtkprivate.h"
-#include "gtkstylecontext.h"
-
-#include <string.h>
-
-
-/**
- * SECTION:gtktoolbutton
- * @Short_description: A GtkToolItem subclass that displays buttons
- * @Title: GtkToolButton
- * @See_also: #GtkToolbar, #GtkMenuToolButton, #GtkToggleToolButton,
- * #GtkRadioToolButton, #GtkSeparatorToolItem
- *
- * #GtkToolButtons are #GtkToolItems containing buttons.
- *
- * Use gtk_tool_button_new() to create a new #GtkToolButton.
- *
- * The label of a #GtkToolButton is determined by the properties
- * #GtkToolButton:label-widget and #GtkToolButton:label.
- * If #GtkToolButton:label-widget is
- * non-%NULL, then that widget is used as the label. Otherwise, if
- * #GtkToolButton:label is non-%NULL, that string is used as the label.
- *
- * The icon of a #GtkToolButton is determined by the
- * #GtkToolButton:icon-widget property. If
- * #GtkToolButton:icon-widget is non-%NULL, then
- * that widget is used as the icon. Otherwise it does not have an icon.
- *
- * # CSS nodes
- *
- * GtkToolButton has a single CSS node with name toolbutton.
- */
-
-
-#define MENU_ID "gtk-tool-button-menu-id"
-
-enum {
- CLICKED,
- LAST_SIGNAL
-};
-
-enum {
- PROP_0,
- PROP_LABEL,
- PROP_USE_UNDERLINE,
- PROP_LABEL_WIDGET,
- PROP_ICON_NAME,
- PROP_ICON_WIDGET,
- PROP_ACTION_NAME,
- PROP_ACTION_TARGET
-};
-
-static void gtk_tool_button_init (GtkToolButton *button,
- GtkToolButtonClass *klass);
-static void gtk_tool_button_class_init (GtkToolButtonClass *klass);
-static void gtk_tool_button_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec);
-static void gtk_tool_button_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec);
-static void gtk_tool_button_property_notify (GObject *object,
- GParamSpec *pspec);
-static void gtk_tool_button_finalize (GObject *object);
-
-static void gtk_tool_button_toolbar_reconfigured (GtkToolItem *tool_item);
-static void button_clicked (GtkWidget *widget,
- GtkToolButton *button);
-
-static void gtk_tool_button_construct_contents (GtkToolItem *tool_item);
-
-static void gtk_tool_button_actionable_iface_init (GtkActionableInterface *iface);
-
-
-struct _GtkToolButtonPrivate
-{
- GtkWidget *button;
-
- gchar *icon_name;
- gchar *label_text;
- GtkWidget *label_widget;
- GtkWidget *icon_widget;
-
- GtkSizeGroup *text_size_group;
-
- guint use_underline : 1;
- guint contents_invalid : 1;
-};
-
-static GObjectClass *parent_class = NULL;
-static guint toolbutton_signals[LAST_SIGNAL] = { 0 };
-
-GType
-gtk_tool_button_get_type (void)
-{
- static GType g_define_type_id = 0;
-
- if (!g_define_type_id)
- {
- const GInterfaceInfo actionable_info =
- {
- (GInterfaceInitFunc) gtk_tool_button_actionable_iface_init,
- (GInterfaceFinalizeFunc) NULL,
- NULL
- };
-
- g_define_type_id = g_type_register_static_simple (GTK_TYPE_TOOL_ITEM,
- I_("GtkToolButton"),
- sizeof (GtkToolButtonClass),
- (GClassInitFunc) gtk_tool_button_class_init,
- sizeof (GtkToolButton),
- (GInstanceInitFunc) gtk_tool_button_init,
- 0);
-
- g_type_add_interface_static (g_define_type_id,
- GTK_TYPE_ACTIONABLE, &actionable_info);
- }
- return g_define_type_id;
-}
-
-static void
-gtk_tool_button_class_init (GtkToolButtonClass *klass)
-{
- GObjectClass *object_class;
- GtkWidgetClass *widget_class;
- GtkToolItemClass *tool_item_class;
-
- parent_class = g_type_class_peek_parent (klass);
-
- object_class = (GObjectClass *)klass;
- widget_class = (GtkWidgetClass *)klass;
- tool_item_class = (GtkToolItemClass *)klass;
-
- object_class->set_property = gtk_tool_button_set_property;
- object_class->get_property = gtk_tool_button_get_property;
- object_class->notify = gtk_tool_button_property_notify;
- object_class->finalize = gtk_tool_button_finalize;
-
- tool_item_class->toolbar_reconfigured = gtk_tool_button_toolbar_reconfigured;
-
- klass->button_type = GTK_TYPE_BUTTON;
-
- /* Properties are interpreted like this:
- *
- * - if the tool button has an icon_widget, then that widget
- * will be used as the icon. Otherwise, if the tool button has
- * an icon name, the corresponding icon from the theme will be used.
- * Otherwise, the tool button will not have an icon.
- *
- * - if the tool button has a label_widget then that widget
- * will be used as the label. Otherwise, if the tool button
- * has a label text, that text will be used as label. Otherwise,
- * if the tool button has an icon name, the corresponding icon name
- * from the theme will be used. Otherwise, the toolbutton will have
- * an empty label.
- *
- * - The use_underline property only has an effect when the label
- * on the toolbutton comes from the label property (ie. not from
- * label_widget).
- *
- * In that case, if use_underline is set,
- *
- * - underscores are removed from the label text before
- * the label is shown on the toolbutton unless the
- * underscore is followed by another underscore
- *
- * - an underscore indicates that the next character when
- * used in the overflow menu should be used as a
- * mnemonic.
- *
- * In short: use_underline = TRUE means that the label text has
- * the form "_Open" and the toolbar should take appropriate
- * action.
- */
-
- g_object_class_install_property (object_class,
- PROP_LABEL,
- g_param_spec_string ("label",
- P_("Label"),
- P_("Text to show in the item."),
- NULL,
- GTK_PARAM_READWRITE));
- g_object_class_install_property (object_class,
- PROP_USE_UNDERLINE,
- g_param_spec_boolean ("use-underline",
- P_("Use underline"),
- P_("If set, an underline in the label property indicates that the next character should be used for the mnemonic accelerator key in the overflow menu"),
- FALSE,
- GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
- g_object_class_install_property (object_class,
- PROP_LABEL_WIDGET,
- g_param_spec_object ("label-widget",
- P_("Label widget"),
- P_("Widget to use as the item label"),
- GTK_TYPE_WIDGET,
- GTK_PARAM_READWRITE));
- /**
- * GtkToolButton:icon-name:
- *
- * The name of the themed icon displayed on the item.
- * This property only has an effect if not overridden by
- * #GtkToolButton:label-widget or #GtkToolButton:icon-widget
- */
- g_object_class_install_property (object_class,
- PROP_ICON_NAME,
- g_param_spec_string ("icon-name",
- P_("Icon name"),
- P_("The name of the themed icon displayed on the item"),
- NULL,
- GTK_PARAM_READWRITE));
- g_object_class_install_property (object_class,
- PROP_ICON_WIDGET,
- g_param_spec_object ("icon-widget",
- P_("Icon widget"),
- P_("Icon widget to display in the item"),
- GTK_TYPE_WIDGET,
- GTK_PARAM_READWRITE));
-
- g_object_class_override_property (object_class, PROP_ACTION_NAME, "action-name");
- g_object_class_override_property (object_class, PROP_ACTION_TARGET, "action-target");
-
-/**
- * GtkToolButton::clicked:
- * @toolbutton: the object that emitted the signal
- *
- * This signal is emitted when the tool button is clicked with the mouse
- * or activated with the keyboard.
- **/
- toolbutton_signals[CLICKED] =
- g_signal_new (I_("clicked"),
- G_OBJECT_CLASS_TYPE (klass),
- G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
- G_STRUCT_OFFSET (GtkToolButtonClass, clicked),
- NULL, NULL,
- NULL,
- G_TYPE_NONE, 0);
-
- g_type_class_add_private (object_class, sizeof (GtkToolButtonPrivate));
-
- gtk_widget_class_set_css_name (widget_class, I_("toolbutton"));
-}
-
-static void
-gtk_tool_button_init (GtkToolButton *button,
- GtkToolButtonClass *klass)
-{
- GtkToolItem *toolitem = GTK_TOOL_ITEM (button);
-
- /* We still need to use G_TYPE_INSTANCE_GET_PRIVATE() because GtkToolButton
- need to access the class pointer inside instance_init
- See a detailed explanation of this at
- https://gitlab.gnome.org/GNOME/gtk/merge_requests/402#note_361210 */
- button->priv = G_TYPE_INSTANCE_GET_PRIVATE (button,
- GTK_TYPE_TOOL_BUTTON,
- GtkToolButtonPrivate);
-
- button->priv->contents_invalid = TRUE;
-
- gtk_tool_item_set_homogeneous (toolitem, TRUE);
-
- /* create button */
- button->priv->button = g_object_new (klass->button_type, NULL);
- gtk_widget_set_focus_on_click (GTK_WIDGET (button->priv->button), FALSE);
- g_signal_connect_object (button->priv->button, "clicked",
- G_CALLBACK (button_clicked), button, 0);
-
- gtk_container_add (GTK_CONTAINER (button), button->priv->button);
-}
-
-static void
-gtk_tool_button_construct_contents (GtkToolItem *tool_item)
-{
- GtkToolButton *button = GTK_TOOL_BUTTON (tool_item);
- GtkWidget *child;
- GtkWidget *label = NULL;
- GtkWidget *icon = NULL;
- GtkToolbarStyle style;
- gboolean need_label = FALSE;
- gboolean need_icon = FALSE;
- GtkWidget *box = NULL;
- GtkOrientation text_orientation = GTK_ORIENTATION_HORIZONTAL;
- GtkSizeGroup *size_group = NULL;
- GtkWidget *parent;
-
- button->priv->contents_invalid = FALSE;
-
- if (button->priv->icon_widget)
- {
- parent = gtk_widget_get_parent (button->priv->icon_widget);
- if (parent)
- {
- gtk_container_remove (GTK_CONTAINER (parent),
- button->priv->icon_widget);
- }
- }
-
- if (button->priv->label_widget)
- {
- parent = gtk_widget_get_parent (button->priv->label_widget);
- if (parent)
- {
- gtk_container_remove (GTK_CONTAINER (parent),
- button->priv->label_widget);
- }
- }
-
- child = gtk_bin_get_child (GTK_BIN (button->priv->button));
- if (child)
- {
- /* Note: we are not destroying the label_widget or icon_widget
- * here because they were removed from their containers above
- */
- gtk_widget_destroy (child);
- }
-
- style = gtk_tool_item_get_toolbar_style (GTK_TOOL_ITEM (button));
-
- if (style != GTK_TOOLBAR_TEXT)
- need_icon = TRUE;
-
- if (style != GTK_TOOLBAR_ICONS && style != GTK_TOOLBAR_BOTH_HORIZ)
- need_label = TRUE;
-
- if (style == GTK_TOOLBAR_BOTH_HORIZ &&
- (gtk_tool_item_get_is_important (GTK_TOOL_ITEM (button)) ||
- gtk_tool_item_get_orientation (GTK_TOOL_ITEM (button)) == GTK_ORIENTATION_VERTICAL ||
- gtk_tool_item_get_text_orientation (GTK_TOOL_ITEM (button)) == GTK_ORIENTATION_VERTICAL))
- {
- need_label = TRUE;
- }
-
- if (style != GTK_TOOLBAR_TEXT && button->priv->icon_widget == NULL &&
- button->priv->icon_name == NULL)
- {
- need_label = TRUE;
- need_icon = FALSE;
- style = GTK_TOOLBAR_TEXT;
- }
-
- if (style == GTK_TOOLBAR_TEXT && button->priv->label_widget == NULL &&
- button->priv->label_text == NULL)
- {
- need_label = FALSE;
- need_icon = TRUE;
- style = GTK_TOOLBAR_ICONS;
- }
-
- if (need_label)
- {
- if (button->priv->label_widget)
- {
- label = button->priv->label_widget;
- }
- else
- {
- gboolean elide;
- const char *orig_label;
- gchar *label_text;
-
- if (button->priv->label_text)
- {
- orig_label = button->priv->label_text;
- elide = button->priv->use_underline;
- }
- else
- {
- orig_label = "";
- elide = FALSE;
- }
-
- if (elide)
- label_text = _gtk_toolbar_elide_underscores (orig_label);
- else
- label_text = g_strdup (orig_label);
-
- label = gtk_label_new (label_text);
-
- g_free (label_text);
- }
-
- if (GTK_IS_LABEL (label))
- {
- gtk_label_set_ellipsize (GTK_LABEL (label),
- gtk_tool_item_get_ellipsize_mode (GTK_TOOL_ITEM (button)));
- text_orientation = gtk_tool_item_get_text_orientation (GTK_TOOL_ITEM (button));
- if (text_orientation == GTK_ORIENTATION_HORIZONTAL)
- {
- gfloat align;
-
- align = gtk_tool_item_get_text_alignment (GTK_TOOL_ITEM (button));
- if (align < 0.4)
- gtk_widget_set_halign (label, GTK_ALIGN_START);
- else if (align > 0.6)
- gtk_widget_set_halign (label, GTK_ALIGN_END);
- else
- gtk_widget_set_halign (label, GTK_ALIGN_CENTER);
- }
- else
- {
- gfloat align;
-
- gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_NONE);
- align = gtk_tool_item_get_text_alignment (GTK_TOOL_ITEM (button));
- if (align < 0.4)
- gtk_widget_set_valign (label, GTK_ALIGN_END);
- else if (align > 0.6)
- gtk_widget_set_valign (label, GTK_ALIGN_START);
- else
- gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
- }
- }
- }
-
- if (need_icon)
- {
- if (button->priv->icon_widget)
- {
- icon = button->priv->icon_widget;
- }
- else if (button->priv->icon_name)
- {
- icon = gtk_image_new_from_icon_name (button->priv->icon_name);
- }
-
- if (icon)
- {
- if (text_orientation == GTK_ORIENTATION_HORIZONTAL)
- {
- gfloat align;
-
- align = gtk_tool_item_get_text_alignment (GTK_TOOL_ITEM (button));
- if (align > 0.6)
- gtk_widget_set_halign (icon, GTK_ALIGN_START);
- else if (align < 0.4)
- gtk_widget_set_halign (icon, GTK_ALIGN_END);
- else
- gtk_widget_set_halign (icon, GTK_ALIGN_CENTER);
- }
- else
- {
- gfloat align;
-
- align = gtk_tool_item_get_text_alignment (GTK_TOOL_ITEM (button));
- if (align > 0.6)
- gtk_widget_set_valign (icon, GTK_ALIGN_END);
- else if (align < 0.4)
- gtk_widget_set_valign (icon, GTK_ALIGN_START);
- else
- gtk_widget_set_valign (icon, GTK_ALIGN_CENTER);
- }
-
- size_group = gtk_tool_item_get_text_size_group (GTK_TOOL_ITEM (button));
- if (size_group != NULL)
- gtk_size_group_add_widget (size_group, icon);
- }
- }
-
- switch (style)
- {
- default:
- case GTK_TOOLBAR_ICONS:
- if (icon)
- gtk_container_add (GTK_CONTAINER (button->priv->button), icon);
- gtk_style_context_add_class (gtk_widget_get_style_context (button->priv->button), "image-button");
- gtk_style_context_remove_class (gtk_widget_get_style_context (button->priv->button), "text-button");
- break;
-
- case GTK_TOOLBAR_BOTH:
- if (text_orientation == GTK_ORIENTATION_HORIZONTAL)
- box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
- else
- box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL,0);
-
- if (icon)
- gtk_container_add (GTK_CONTAINER (box), icon);
-
- gtk_container_add (GTK_CONTAINER (box), label);
- gtk_container_add (GTK_CONTAINER (button->priv->button), box);
- gtk_style_context_add_class (gtk_widget_get_style_context (button->priv->button), "image-button");
- gtk_style_context_add_class (gtk_widget_get_style_context (button->priv->button), "text-button");
- break;
-
- case GTK_TOOLBAR_BOTH_HORIZ:
- if (text_orientation == GTK_ORIENTATION_HORIZONTAL)
- {
- box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
- if (icon)
- {
- gtk_container_add (GTK_CONTAINER (box), icon);
- if (!label)
- gtk_widget_set_hexpand (icon, TRUE);
- }
- if (label)
- gtk_container_add (GTK_CONTAINER (box), label);
- }
- else
- {
- box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
- if (icon)
- {
- gtk_container_add (GTK_CONTAINER (box), icon);
- if (!label)
- gtk_widget_set_vexpand (icon, TRUE);
- }
- if (label)
- gtk_container_add (GTK_CONTAINER (box), label);
- }
- gtk_container_add (GTK_CONTAINER (button->priv->button), box);
- gtk_style_context_add_class (gtk_widget_get_style_context (button->priv->button), "image-button");
- gtk_style_context_add_class (gtk_widget_get_style_context (button->priv->button), "text-button");
- break;
-
- case GTK_TOOLBAR_TEXT:
- gtk_container_add (GTK_CONTAINER (button->priv->button), label);
- gtk_style_context_add_class (gtk_widget_get_style_context (button->priv->button), "text-button");
- gtk_style_context_remove_class (gtk_widget_get_style_context (button->priv->button), "image-button");
- break;
- }
-
- if (box)
- gtk_widget_show (box);
-
- gtk_tool_item_rebuild_menu (tool_item);
-
- gtk_widget_queue_resize (GTK_WIDGET (button));
-}
-
-static void
-gtk_tool_button_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- GtkToolButton *button = GTK_TOOL_BUTTON (object);
-
- switch (prop_id)
- {
- case PROP_LABEL:
- gtk_tool_button_set_label (button, g_value_get_string (value));
- break;
- case PROP_USE_UNDERLINE:
- gtk_tool_button_set_use_underline (button, g_value_get_boolean (value));
- break;
- case PROP_LABEL_WIDGET:
- gtk_tool_button_set_label_widget (button, g_value_get_object (value));
- break;
- case PROP_ICON_NAME:
- gtk_tool_button_set_icon_name (button, g_value_get_string (value));
- break;
- case PROP_ICON_WIDGET:
- gtk_tool_button_set_icon_widget (button, g_value_get_object (value));
- break;
- case PROP_ACTION_NAME:
- g_object_set_property (G_OBJECT (button->priv->button), "action-name", value);
- break;
- case PROP_ACTION_TARGET:
- g_object_set_property (G_OBJECT (button->priv->button), "action-target", value);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static void
-gtk_tool_button_property_notify (GObject *object,
- GParamSpec *pspec)
-{
- GtkToolButton *button = GTK_TOOL_BUTTON (object);
-
- if (button->priv->contents_invalid ||
- strcmp ("is-important", pspec->name) == 0)
- gtk_tool_button_construct_contents (GTK_TOOL_ITEM (object));
-
- if (parent_class->notify)
- parent_class->notify (object, pspec);
-}
-
-static void
-gtk_tool_button_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- GtkToolButton *button = GTK_TOOL_BUTTON (object);
-
- switch (prop_id)
- {
- case PROP_LABEL:
- g_value_set_string (value, gtk_tool_button_get_label (button));
- break;
- case PROP_LABEL_WIDGET:
- g_value_set_object (value, gtk_tool_button_get_label_widget (button));
- break;
- case PROP_USE_UNDERLINE:
- g_value_set_boolean (value, gtk_tool_button_get_use_underline (button));
- break;
- case PROP_ICON_NAME:
- g_value_set_string (value, button->priv->icon_name);
- break;
- case PROP_ICON_WIDGET:
- g_value_set_object (value, button->priv->icon_widget);
- break;
- case PROP_ACTION_NAME:
- g_object_get_property (G_OBJECT (button->priv->button), "action-name", value);
- break;
- case PROP_ACTION_TARGET:
- g_object_get_property (G_OBJECT (button->priv->button), "action-target", value);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static const gchar *
-gtk_tool_button_get_action_name (GtkActionable *actionable)
-{
- GtkToolButton *button = GTK_TOOL_BUTTON (actionable);
-
- return gtk_actionable_get_action_name (GTK_ACTIONABLE (button->priv->button));
-}
-
-static void
-gtk_tool_button_set_action_name (GtkActionable *actionable,
- const gchar *action_name)
-{
- GtkToolButton *button = GTK_TOOL_BUTTON (actionable);
-
- gtk_actionable_set_action_name (GTK_ACTIONABLE (button->priv->button), action_name);
-}
-
-static GVariant *
-gtk_tool_button_get_action_target_value (GtkActionable *actionable)
-{
- GtkToolButton *button = GTK_TOOL_BUTTON (actionable);
-
- return gtk_actionable_get_action_target_value (GTK_ACTIONABLE (button->priv->button));
-}
-
-static void
-gtk_tool_button_set_action_target_value (GtkActionable *actionable,
- GVariant *action_target)
-{
- GtkToolButton *button = GTK_TOOL_BUTTON (actionable);
-
- gtk_actionable_set_action_target_value (GTK_ACTIONABLE (button->priv->button), action_target);
-}
-
-static void
-gtk_tool_button_actionable_iface_init (GtkActionableInterface *iface)
-{
- iface->get_action_name = gtk_tool_button_get_action_name;
- iface->set_action_name = gtk_tool_button_set_action_name;
- iface->get_action_target_value = gtk_tool_button_get_action_target_value;
- iface->set_action_target_value = gtk_tool_button_set_action_target_value;
-}
-
-static void
-gtk_tool_button_finalize (GObject *object)
-{
- GtkToolButton *button = GTK_TOOL_BUTTON (object);
-
- g_free (button->priv->icon_name);
- g_free (button->priv->label_text);
-
- if (button->priv->label_widget)
- g_object_unref (button->priv->label_widget);
-
- if (button->priv->icon_widget)
- g_object_unref (button->priv->icon_widget);
-
- parent_class->finalize (object);
-}
-
-static void
-button_clicked (GtkWidget *widget,
- GtkToolButton *button)
-{
- g_signal_emit_by_name (button, "clicked");
-}
-
-static void
-gtk_tool_button_toolbar_reconfigured (GtkToolItem *tool_item)
-{
- gtk_tool_button_construct_contents (tool_item);
-}
-
-/**
- * gtk_tool_button_new:
- * @label: (allow-none): a string that will be used as label, or %NULL
- * @icon_widget: (allow-none): a widget that will be used as the button contents, or %NULL
- *
- * Creates a new #GtkToolButton using @icon_widget as contents and @label as
- * label.
- *
- * Returns: A new #GtkToolButton
- **/
-GtkToolItem *
-gtk_tool_button_new (GtkWidget *icon_widget,
- const gchar *label)
-{
- GtkToolButton *button;
-
- g_return_val_if_fail (icon_widget == NULL || GTK_IS_WIDGET (icon_widget), NULL);
-
- button = g_object_new (GTK_TYPE_TOOL_BUTTON,
- "label", label,
- "icon-widget", icon_widget,
- NULL);
-
- return GTK_TOOL_ITEM (button);
-}
-
-/**
- * gtk_tool_button_set_label:
- * @button: a #GtkToolButton
- * @label: (allow-none): a string that will be used as label, or %NULL.
- *
- * Sets @label as the label used for the tool button. The #GtkToolButton:label
- * property only has an effect if not overridden by a non-%NULL
- * #GtkToolButton:label-widget property. If both the #GtkToolButton:label-widget
- * and #GtkToolButton:label properties are %NULL, @button will not have a label.
- **/
-void
-gtk_tool_button_set_label (GtkToolButton *button,
- const gchar *label)
-{
- gchar *old_label;
- gchar *elided_label;
- AtkObject *accessible;
- const char *old_overflow_text;
-
- g_return_if_fail (GTK_IS_TOOL_BUTTON (button));
-
- old_label = button->priv->label_text;
-
- button->priv->label_text = g_strdup (label);
- button->priv->contents_invalid = TRUE;
-
- if (label)
- {
- elided_label = _gtk_toolbar_elide_underscores (label);
- accessible = gtk_widget_get_accessible (GTK_WIDGET (button->priv->button));
- atk_object_set_name (accessible, elided_label);
- g_free (elided_label);
- }
-
- old_overflow_text = gtk_tool_item_get_overflow_text (GTK_TOOL_ITEM (button));
- if (old_overflow_text == NULL ||
- (old_label && strcmp (old_overflow_text, old_label) == 0))
- gtk_tool_item_set_overflow_text (GTK_TOOL_ITEM (button), label);
-
- g_free (old_label);
-
- g_object_notify (G_OBJECT (button), "label");
-}
-
-/**
- * gtk_tool_button_get_label:
- * @button: a #GtkToolButton
- *
- * Returns the label used by the tool button, or %NULL if the tool button
- * doesn’t have a label. The returned
- * string is owned by GTK+, and must not be modified or freed.
- *
- * Returns: (nullable) (transfer none): The label, or %NULL
- **/
-const gchar *
-gtk_tool_button_get_label (GtkToolButton *button)
-{
- g_return_val_if_fail (GTK_IS_TOOL_BUTTON (button), NULL);
-
- return button->priv->label_text;
-}
-
-/**
- * gtk_tool_button_set_use_underline:
- * @button: a #GtkToolButton
- * @use_underline: whether the button label has the form “_Open”
- *
- * If set, an underline in the label property indicates that the next character
- * should be used for the mnemonic accelerator key in the overflow menu. For
- * example, if the label property is “_Open” and @use_underline is %TRUE,
- * the label on the tool button will be “Open” and the item on the overflow
- * menu will have an underlined “O”.
- *
- * Labels shown on tool buttons never have mnemonics on them; this property
- * only affects the menu item on the overflow menu.
- **/
-void
-gtk_tool_button_set_use_underline (GtkToolButton *button,
- gboolean use_underline)
-{
- g_return_if_fail (GTK_IS_TOOL_BUTTON (button));
-
- use_underline = use_underline != FALSE;
-
- if (use_underline != button->priv->use_underline)
- {
- button->priv->use_underline = use_underline;
- button->priv->contents_invalid = TRUE;
-
- g_object_notify (G_OBJECT (button), "use-underline");
- }
-}
-
-/**
- * gtk_tool_button_get_use_underline:
- * @button: a #GtkToolButton
- *
- * Returns whether underscores in the label property are used as mnemonics
- * on menu items on the overflow menu. See gtk_tool_button_set_use_underline().
- *
- * Returns: %TRUE if underscores in the label property are used as
- * mnemonics on menu items on the overflow menu.
- **/
-gboolean
-gtk_tool_button_get_use_underline (GtkToolButton *button)
-{
- g_return_val_if_fail (GTK_IS_TOOL_BUTTON (button), FALSE);
-
- return button->priv->use_underline;
-}
-
-/**
- * gtk_tool_button_set_icon_name:
- * @button: a #GtkToolButton
- * @icon_name: (allow-none): the name of the themed icon
- *
- * Sets the icon for the tool button from a named themed icon.
- * See the docs for #GtkIconTheme for more details.
- * The #GtkToolButton:icon-name property only has an effect if not
- * overridden by non-%NULL #GtkToolButton:label-widget or
- * #GtkToolButton:icon-widget properties.
- **/
-void
-gtk_tool_button_set_icon_name (GtkToolButton *button,
- const gchar *icon_name)
-{
- gchar *old_icon_name;
-
- g_return_if_fail (GTK_IS_TOOL_BUTTON (button));
-
- old_icon_name = button->priv->icon_name;
-
- button->priv->icon_name = g_strdup (icon_name);
- button->priv->contents_invalid = TRUE;
-
- g_free (old_icon_name);
-
- g_object_notify (G_OBJECT (button), "icon-name");
-}
-
-/**
- * gtk_tool_button_get_icon_name:
- * @button: a #GtkToolButton
- *
- * Returns the name of the themed icon for the tool button,
- * see gtk_tool_button_set_icon_name().
- *
- * Returns: (nullable): the icon name or %NULL if the tool button has
- * no themed icon
- **/
-const gchar*
-gtk_tool_button_get_icon_name (GtkToolButton *button)
-{
- g_return_val_if_fail (GTK_IS_TOOL_BUTTON (button), NULL);
-
- return button->priv->icon_name;
-}
-
-/**
- * gtk_tool_button_set_icon_widget:
- * @button: a #GtkToolButton
- * @icon_widget: (allow-none): the widget used as icon, or %NULL
- *
- * Sets @icon as the widget used as icon on @button.
- **/
-void
-gtk_tool_button_set_icon_widget (GtkToolButton *button,
- GtkWidget *icon_widget)
-{
- g_return_if_fail (GTK_IS_TOOL_BUTTON (button));
- g_return_if_fail (icon_widget == NULL || GTK_IS_WIDGET (icon_widget));
-
- if (icon_widget != button->priv->icon_widget)
- {
- if (button->priv->icon_widget)
- {
- GtkWidget *parent;
-
- parent = gtk_widget_get_parent (button->priv->icon_widget);
- if (parent)
- gtk_container_remove (GTK_CONTAINER (parent),
- button->priv->icon_widget);
-
- g_object_unref (button->priv->icon_widget);
- }
-
- if (icon_widget)
- g_object_ref_sink (icon_widget);
-
- button->priv->icon_widget = icon_widget;
- button->priv->contents_invalid = TRUE;
-
- g_object_notify (G_OBJECT (button), "icon-widget");
- }
-}
-
-/**
- * gtk_tool_button_set_label_widget:
- * @button: a #GtkToolButton
- * @label_widget: (allow-none): the widget used as label, or %NULL
- *
- * Sets @label_widget as the widget that will be used as the label
- * for @button. If @label_widget is %NULL the #GtkToolButton:label property is used
- * as label. If #GtkToolButton:label is also %NULL, @button does not have a label.
- **/
-void
-gtk_tool_button_set_label_widget (GtkToolButton *button,
- GtkWidget *label_widget)
-{
- g_return_if_fail (GTK_IS_TOOL_BUTTON (button));
- g_return_if_fail (label_widget == NULL || GTK_IS_WIDGET (label_widget));
-
- if (label_widget != button->priv->label_widget)
- {
- if (button->priv->label_widget)
- {
- GtkWidget *parent;
-
- parent = gtk_widget_get_parent (button->priv->label_widget);
- if (parent)
- gtk_container_remove (GTK_CONTAINER (parent),
- button->priv->label_widget);
-
- g_object_unref (button->priv->label_widget);
- }
-
- if (label_widget)
- g_object_ref_sink (label_widget);
-
- button->priv->label_widget = label_widget;
- button->priv->contents_invalid = TRUE;
-
- g_object_notify (G_OBJECT (button), "label-widget");
- }
-}
-
-/**
- * gtk_tool_button_get_label_widget:
- * @button: a #GtkToolButton
- *
- * Returns the widget used as label on @button.
- * See gtk_tool_button_set_label_widget().
- *
- * Returns: (nullable) (transfer none): The widget used as label
- * on @button, or %NULL.
- **/
-GtkWidget *
-gtk_tool_button_get_label_widget (GtkToolButton *button)
-{
- g_return_val_if_fail (GTK_IS_TOOL_BUTTON (button), NULL);
-
- return button->priv->label_widget;
-}
-
-/**
- * gtk_tool_button_get_icon_widget:
- * @button: a #GtkToolButton
- *
- * Return the widget used as icon widget on @button.
- * See gtk_tool_button_set_icon_widget().
- *
- * Returns: (nullable) (transfer none): The widget used as icon
- * on @button, or %NULL.
- **/
-GtkWidget *
-gtk_tool_button_get_icon_widget (GtkToolButton *button)
-{
- g_return_val_if_fail (GTK_IS_TOOL_BUTTON (button), NULL);
-
- return button->priv->icon_widget;
-}
-
-GtkWidget *
-_gtk_tool_button_get_button (GtkToolButton *button)
-{
- g_return_val_if_fail (GTK_IS_TOOL_BUTTON (button), NULL);
-
- return button->priv->button;
-}
+++ /dev/null
-/* gtktoolbutton.h
- *
- * Copyright (C) 2002 Anders Carlsson <andersca@gnome.org>
- * Copyright (C) 2002 James Henstridge <james@daa.com.au>
- * Copyright (C) 2003 Soeren Sandmann <sandmann@daimi.au.dk>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef __GTK_TOOL_BUTTON_H__
-#define __GTK_TOOL_BUTTON_H__
-
-#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
-#error "Only <gtk/gtk.h> can be included directly."
-#endif
-
-#include <gtk/gtktoolitem.h>
-
-G_BEGIN_DECLS
-
-#define GTK_TYPE_TOOL_BUTTON (gtk_tool_button_get_type ())
-#define GTK_TOOL_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_TOOL_BUTTON, GtkToolButton))
-#define GTK_TOOL_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_TOOL_BUTTON, GtkToolButtonClass))
-#define GTK_IS_TOOL_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_TOOL_BUTTON))
-#define GTK_IS_TOOL_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_TOOL_BUTTON))
-#define GTK_TOOL_BUTTON_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GTK_TYPE_TOOL_BUTTON, GtkToolButtonClass))
-
-typedef struct _GtkToolButton GtkToolButton;
-typedef struct _GtkToolButtonClass GtkToolButtonClass;
-typedef struct _GtkToolButtonPrivate GtkToolButtonPrivate;
-
-struct _GtkToolButton
-{
- GtkToolItem parent;
-
- /*< private >*/
- GtkToolButtonPrivate *priv;
-};
-
-/**
- * GtkToolButtonClass:
- * @parent_class: The parent class.
- * @button_type:
- * @clicked: Signal emitted when the tool button is clicked with the
- * mouse or activated with the keyboard.
- */
-struct _GtkToolButtonClass
-{
- GtkToolItemClass parent_class;
-
- GType button_type;
-
- /*< public >*/
-
- /* signal */
- void (* clicked) (GtkToolButton *tool_item);
-
- /*< private >*/
-
- gpointer padding[8];
-};
-
-GDK_AVAILABLE_IN_ALL
-GType gtk_tool_button_get_type (void) G_GNUC_CONST;
-GDK_AVAILABLE_IN_ALL
-GtkToolItem *gtk_tool_button_new (GtkWidget *icon_widget,
- const gchar *label);
-
-GDK_AVAILABLE_IN_ALL
-void gtk_tool_button_set_label (GtkToolButton *button,
- const gchar *label);
-GDK_AVAILABLE_IN_ALL
-const gchar * gtk_tool_button_get_label (GtkToolButton *button);
-GDK_AVAILABLE_IN_ALL
-void gtk_tool_button_set_use_underline (GtkToolButton *button,
- gboolean use_underline);
-GDK_AVAILABLE_IN_ALL
-gboolean gtk_tool_button_get_use_underline (GtkToolButton *button);
-GDK_AVAILABLE_IN_ALL
-void gtk_tool_button_set_icon_name (GtkToolButton *button,
- const gchar *icon_name);
-GDK_AVAILABLE_IN_ALL
-const gchar * gtk_tool_button_get_icon_name (GtkToolButton *button);
-GDK_AVAILABLE_IN_ALL
-void gtk_tool_button_set_icon_widget (GtkToolButton *button,
- GtkWidget *icon_widget);
-GDK_AVAILABLE_IN_ALL
-GtkWidget * gtk_tool_button_get_icon_widget (GtkToolButton *button);
-GDK_AVAILABLE_IN_ALL
-void gtk_tool_button_set_label_widget (GtkToolButton *button,
- GtkWidget *label_widget);
-GDK_AVAILABLE_IN_ALL
-GtkWidget * gtk_tool_button_get_label_widget (GtkToolButton *button);
-
-
-/* internal function */
-GtkWidget *_gtk_tool_button_get_button (GtkToolButton *button);
-
-G_END_DECLS
-
-#endif /* __GTK_TOOL_BUTTON_H__ */
+++ /dev/null
-/* gtktoolitem.c
- *
- * Copyright (C) 2002 Anders Carlsson <andersca@gnome.org>
- * Copyright (C) 2002 James Henstridge <james@daa.com.au>
- * Copyright (C) 2003 Soeren Sandmann <sandmann@daimi.au.dk>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "config.h"
-
-#include "gtktoolitem.h"
-
-#include <string.h>
-
-#include "gtkmarshalers.h"
-#include "gtktoolshell.h"
-#include "gtksizerequest.h"
-#include "gtkintl.h"
-#include "gtkprivate.h"
-#include "gtkwidgetprivate.h"
-
-/**
- * SECTION:gtktoolitem
- * @short_description: The base class of widgets that can be added to GtkToolShell
- * @Title: GtkToolItem
- * @see_also: #GtkToolbar, #GtkToolButton, #GtkSeparatorToolItem
- *
- * #GtkToolItems are widgets that can appear on a toolbar. To
- * create a toolbar item that contain something else than a button, use
- * gtk_tool_item_new(). Use gtk_container_add() to add a child
- * widget to the tool item.
- *
- * For toolbar items that contain buttons, see the #GtkToolButton,
- * #GtkToggleToolButton and #GtkRadioToolButton classes.
- *
- * See the #GtkToolbar class for a description of the toolbar widget, and
- * #GtkToolShell for a description of the tool shell interface.
- */
-
-/**
- * GtkToolItem:
- *
- * The GtkToolItem struct contains only private data.
- * It should only be accessed through the functions described below.
- */
-
-enum {
- CREATE_MENU_PROXY,
- TOOLBAR_RECONFIGURED,
- LAST_SIGNAL
-};
-
-enum {
- PROP_0,
- PROP_VISIBLE_HORIZONTAL,
- PROP_VISIBLE_VERTICAL,
- PROP_IS_IMPORTANT,
- PROP_HOMOGENEOUS,
- PROP_EXPAND_ITEM,
- PROP_OVERFLOW_TEXT
-};
-
-
-struct _GtkToolItemPrivate
-{
- guint visible_horizontal : 1;
- guint visible_vertical : 1;
- guint homogeneous : 1;
- guint expand : 1;
- guint is_important : 1;
-
- char *overflow_text;
-};
-
-static void gtk_tool_item_finalize (GObject *object);
-static void gtk_tool_item_parent_cb (GObject *object,
- GParamSpec *pspec,
- gpointer user_data);
-static void gtk_tool_item_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec);
-static void gtk_tool_item_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec);
-
-static guint toolitem_signals[LAST_SIGNAL] = { 0 };
-
-G_DEFINE_TYPE_WITH_CODE (GtkToolItem, gtk_tool_item, GTK_TYPE_BIN,
- G_ADD_PRIVATE (GtkToolItem));
-
-static void
-gtk_tool_item_class_init (GtkToolItemClass *klass)
-{
- GObjectClass *object_class;
- GtkWidgetClass *widget_class;
-
- object_class = (GObjectClass *)klass;
- widget_class = (GtkWidgetClass *)klass;
-
- object_class->set_property = gtk_tool_item_set_property;
- object_class->get_property = gtk_tool_item_get_property;
- object_class->finalize = gtk_tool_item_finalize;
-
- g_object_class_install_property (object_class,
- PROP_VISIBLE_HORIZONTAL,
- g_param_spec_boolean ("visible-horizontal",
- P_("Visible when horizontal"),
- P_("Whether the toolbar item is visible when the toolbar is in a horizontal orientation."),
- TRUE,
- GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
- g_object_class_install_property (object_class,
- PROP_VISIBLE_VERTICAL,
- g_param_spec_boolean ("visible-vertical",
- P_("Visible when vertical"),
- P_("Whether the toolbar item is visible when the toolbar is in a vertical orientation."),
- TRUE,
- GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
- g_object_class_install_property (object_class,
- PROP_IS_IMPORTANT,
- g_param_spec_boolean ("is-important",
- P_("Is important"),
- P_("Whether the toolbar item is considered important. When TRUE, toolbar buttons show text in GTK_TOOLBAR_BOTH_HORIZ mode"),
- FALSE,
- GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
-
- g_object_class_install_property (object_class,
- PROP_EXPAND_ITEM,
- g_param_spec_boolean ("expand-item",
- P_("Expand Item"),
- P_("Whether the item should receive extra space when the toolbar grows"),
- FALSE,
- GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
-
- g_object_class_install_property (object_class,
- PROP_HOMOGENEOUS,
- g_param_spec_boolean ("homogeneous",
- P_("Homogeneous"),
- P_("Whether the item should be the same size as other homogeneous items"),
- FALSE,
- GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
-
- /**
- * GtkToolItem:overflow-text:
- *
- * The text to use as label in the overflow menu item for this
- * toolitem.
- *
- * If unset, #GtkToolButton:label is used for #GtkToolButtons.
- */
- g_object_class_install_property (object_class,
- PROP_OVERFLOW_TEXT,
- g_param_spec_string ("overflow-text",
- P_("Overflow text"),
- P_("Label to use in the overflow menu"),
- NULL,
- GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
-
-/**
- * GtkToolItem::toolbar-reconfigured:
- * @tool_item: the object the signal was emitted on
- *
- * This signal is emitted when some property of the toolbar that the
- * item is a child of changes. For custom subclasses of #GtkToolItem,
- * the default handler of this signal use the functions
- * - gtk_tool_shell_get_orientation()
- * - gtk_tool_shell_get_style()
- * - gtk_tool_shell_get_icon_size()
- * to find out what the toolbar should look like and change
- * themselves accordingly.
- **/
- toolitem_signals[TOOLBAR_RECONFIGURED] =
- g_signal_new (I_("toolbar-reconfigured"),
- G_OBJECT_CLASS_TYPE (klass),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (GtkToolItemClass, toolbar_reconfigured),
- NULL, NULL,
- NULL,
- G_TYPE_NONE, 0);
-
- gtk_widget_class_set_css_name (widget_class, I_("toolitem"));
-}
-
-static void
-gtk_tool_item_init (GtkToolItem *toolitem)
-{
- gtk_widget_set_can_focus (GTK_WIDGET (toolitem), FALSE);
-
- toolitem->priv = gtk_tool_item_get_instance_private (toolitem);
- toolitem->priv->visible_horizontal = TRUE;
- toolitem->priv->visible_vertical = TRUE;
- toolitem->priv->homogeneous = FALSE;
- toolitem->priv->expand = FALSE;
-
- g_signal_connect (toolitem, "notify::parent", G_CALLBACK (gtk_tool_item_parent_cb), NULL);
-}
-
-static void
-gtk_tool_item_finalize (GObject *object)
-{
- GtkToolItemPrivate *priv = gtk_tool_item_get_instance_private (GTK_TOOL_ITEM (object));
-
- g_clear_pointer (&priv->overflow_text, g_free);
-
- G_OBJECT_CLASS (gtk_tool_item_parent_class)->finalize (object);
-}
-
-static void
-gtk_tool_item_parent_cb (GObject *object,
- GParamSpec *pspec,
- gpointer user_data)
-{
- GtkToolItem *toolitem = GTK_TOOL_ITEM (object);
-
- if (gtk_widget_get_parent (GTK_WIDGET (toolitem)) != NULL)
- gtk_tool_item_toolbar_reconfigured (toolitem);
-}
-
-static void
-gtk_tool_item_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- GtkToolItem *toolitem = GTK_TOOL_ITEM (object);
-
- switch (prop_id)
- {
- case PROP_VISIBLE_HORIZONTAL:
- gtk_tool_item_set_visible_horizontal (toolitem, g_value_get_boolean (value));
- break;
- case PROP_VISIBLE_VERTICAL:
- gtk_tool_item_set_visible_vertical (toolitem, g_value_get_boolean (value));
- break;
- case PROP_IS_IMPORTANT:
- gtk_tool_item_set_is_important (toolitem, g_value_get_boolean (value));
- break;
- case PROP_EXPAND_ITEM:
- gtk_tool_item_set_expand (toolitem, g_value_get_boolean (value));
- break;
- case PROP_HOMOGENEOUS:
- gtk_tool_item_set_homogeneous (toolitem, g_value_get_boolean (value));
- break;
- case PROP_OVERFLOW_TEXT:
- gtk_tool_item_set_overflow_text (toolitem, g_value_get_string (value));
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static void
-gtk_tool_item_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- GtkToolItem *toolitem = GTK_TOOL_ITEM (object);
-
- switch (prop_id)
- {
- case PROP_VISIBLE_HORIZONTAL:
- g_value_set_boolean (value, toolitem->priv->visible_horizontal);
- break;
- case PROP_VISIBLE_VERTICAL:
- g_value_set_boolean (value, toolitem->priv->visible_vertical);
- break;
- case PROP_IS_IMPORTANT:
- g_value_set_boolean (value, toolitem->priv->is_important);
- break;
- case PROP_EXPAND_ITEM:
- g_value_set_boolean (value, toolitem->priv->expand);
- break;
- case PROP_HOMOGENEOUS:
- g_value_set_boolean (value, toolitem->priv->homogeneous);
- break;
- case PROP_OVERFLOW_TEXT:
- g_value_set_string (value, toolitem->priv->overflow_text);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-/**
- * gtk_tool_item_new:
- *
- * Creates a new #GtkToolItem
- *
- * Returns: the new #GtkToolItem
- **/
-GtkToolItem *
-gtk_tool_item_new (void)
-{
- GtkToolItem *item;
-
- item = g_object_new (GTK_TYPE_TOOL_ITEM, NULL);
-
- return item;
-}
-
-/**
- * gtk_tool_item_get_ellipsize_mode:
- * @tool_item: a #GtkToolItem
- *
- * Returns the ellipsize mode used for @tool_item. Custom subclasses of
- * #GtkToolItem should call this function to find out how text should
- * be ellipsized.
- *
- * Returns: a #PangoEllipsizeMode indicating how text in @tool_item
- * should be ellipsized.
- **/
-PangoEllipsizeMode
-gtk_tool_item_get_ellipsize_mode (GtkToolItem *tool_item)
-{
- GtkWidget *parent;
-
- g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), PANGO_ELLIPSIZE_NONE);
-
- parent = gtk_widget_get_parent (GTK_WIDGET (tool_item));
- if (!parent || !GTK_IS_TOOL_SHELL (parent))
- return PANGO_ELLIPSIZE_NONE;
-
- return gtk_tool_shell_get_ellipsize_mode (GTK_TOOL_SHELL (parent));
-}
-
-/**
- * gtk_tool_item_get_orientation:
- * @tool_item: a #GtkToolItem
- *
- * Returns the orientation used for @tool_item. Custom subclasses of
- * #GtkToolItem should call this function to find out what size icons
- * they should use.
- *
- * Returns: a #GtkOrientation indicating the orientation
- * used for @tool_item
- **/
-GtkOrientation
-gtk_tool_item_get_orientation (GtkToolItem *tool_item)
-{
- GtkWidget *parent;
-
- g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_ORIENTATION_HORIZONTAL);
-
- parent = gtk_widget_get_parent (GTK_WIDGET (tool_item));
- if (!parent || !GTK_IS_TOOL_SHELL (parent))
- return GTK_ORIENTATION_HORIZONTAL;
-
- return gtk_tool_shell_get_orientation (GTK_TOOL_SHELL (parent));
-}
-
-/**
- * gtk_tool_item_get_toolbar_style:
- * @tool_item: a #GtkToolItem
- *
- * Returns the toolbar style used for @tool_item. Custom subclasses of
- * #GtkToolItem should call this function in the handler of the
- * GtkToolItem::toolbar_reconfigured signal to find out in what style
- * the toolbar is displayed and change themselves accordingly
- *
- * Possibilities are:
- * - %GTK_TOOLBAR_BOTH, meaning the tool item should show
- * both an icon and a label, stacked vertically
- * - %GTK_TOOLBAR_ICONS, meaning the toolbar shows only icons
- * - %GTK_TOOLBAR_TEXT, meaning the tool item should only show text
- * - %GTK_TOOLBAR_BOTH_HORIZ, meaning the tool item should show
- * both an icon and a label, arranged horizontally
- *
- * Returns: A #GtkToolbarStyle indicating the toolbar style used
- * for @tool_item.
- **/
-GtkToolbarStyle
-gtk_tool_item_get_toolbar_style (GtkToolItem *tool_item)
-{
- GtkWidget *parent;
-
- g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_TOOLBAR_ICONS);
-
- parent = gtk_widget_get_parent (GTK_WIDGET (tool_item));
- if (!parent || !GTK_IS_TOOL_SHELL (parent))
- return GTK_TOOLBAR_ICONS;
-
- return gtk_tool_shell_get_style (GTK_TOOL_SHELL (parent));
-}
-
-/**
- * gtk_tool_item_get_text_alignment:
- * @tool_item: a #GtkToolItem:
- *
- * Returns the text alignment used for @tool_item. Custom subclasses of
- * #GtkToolItem should call this function to find out how text should
- * be aligned.
- *
- * Returns: a #gfloat indicating the horizontal text alignment
- * used for @tool_item
- **/
-gfloat
-gtk_tool_item_get_text_alignment (GtkToolItem *tool_item)
-{
- GtkWidget *parent;
-
- g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_ORIENTATION_HORIZONTAL);
-
- parent = gtk_widget_get_parent (GTK_WIDGET (tool_item));
- if (!parent || !GTK_IS_TOOL_SHELL (parent))
- return 0.5;
-
- return gtk_tool_shell_get_text_alignment (GTK_TOOL_SHELL (parent));
-}
-
-/**
- * gtk_tool_item_get_text_orientation:
- * @tool_item: a #GtkToolItem
- *
- * Returns the text orientation used for @tool_item. Custom subclasses of
- * #GtkToolItem should call this function to find out how text should
- * be orientated.
- *
- * Returns: a #GtkOrientation indicating the text orientation
- * used for @tool_item
- */
-GtkOrientation
-gtk_tool_item_get_text_orientation (GtkToolItem *tool_item)
-{
- GtkWidget *parent;
-
- g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_ORIENTATION_HORIZONTAL);
-
- parent = gtk_widget_get_parent (GTK_WIDGET (tool_item));
- if (!parent || !GTK_IS_TOOL_SHELL (parent))
- return GTK_ORIENTATION_HORIZONTAL;
-
- return gtk_tool_shell_get_text_orientation (GTK_TOOL_SHELL (parent));
-}
-
-/**
- * gtk_tool_item_get_text_size_group:
- * @tool_item: a #GtkToolItem
- *
- * Returns the size group used for labels in @tool_item.
- * Custom subclasses of #GtkToolItem should call this function
- * and use the size group for labels.
- *
- * Returns: (transfer none): a #GtkSizeGroup
- */
-GtkSizeGroup *
-gtk_tool_item_get_text_size_group (GtkToolItem *tool_item)
-{
- GtkWidget *parent;
-
- g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), NULL);
-
- parent = gtk_widget_get_parent (GTK_WIDGET (tool_item));
- if (!parent || !GTK_IS_TOOL_SHELL (parent))
- return NULL;
-
- return gtk_tool_shell_get_text_size_group (GTK_TOOL_SHELL (parent));
-}
-
-/**
- * gtk_tool_item_set_expand:
- * @tool_item: a #GtkToolItem
- * @expand: Whether @tool_item is allocated extra space
- *
- * Sets whether @tool_item is allocated extra space when there
- * is more room on the toolbar then needed for the items. The
- * effect is that the item gets bigger when the toolbar gets bigger
- * and smaller when the toolbar gets smaller.
- */
-void
-gtk_tool_item_set_expand (GtkToolItem *tool_item,
- gboolean expand)
-{
- g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
-
- expand = expand != FALSE;
-
- if (tool_item->priv->expand != expand)
- {
- tool_item->priv->expand = expand;
- g_object_notify (G_OBJECT (tool_item), "expand-item");
- gtk_widget_queue_resize (GTK_WIDGET (tool_item));
- }
-}
-
-/**
- * gtk_tool_item_get_expand:
- * @tool_item: a #GtkToolItem
- *
- * Returns whether @tool_item is allocated extra space.
- * See gtk_tool_item_set_expand().
- *
- * Returns: %TRUE if @tool_item is allocated extra space.
- **/
-gboolean
-gtk_tool_item_get_expand (GtkToolItem *tool_item)
-{
- g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), FALSE);
-
- return tool_item->priv->expand;
-}
-
-/**
- * gtk_tool_item_set_homogeneous:
- * @tool_item: a #GtkToolItem
- * @homogeneous: whether @tool_item is the same size as other homogeneous items
- *
- * Sets whether @tool_item is to be allocated the same size as other
- * homogeneous items. The effect is that all homogeneous items will have
- * the same width as the widest of the items.
- **/
-void
-gtk_tool_item_set_homogeneous (GtkToolItem *tool_item,
- gboolean homogeneous)
-{
- g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
-
- homogeneous = homogeneous != FALSE;
-
- if (tool_item->priv->homogeneous != homogeneous)
- {
- tool_item->priv->homogeneous = homogeneous;
- g_object_notify (G_OBJECT (tool_item), "homogeneous");
- gtk_widget_queue_resize (GTK_WIDGET (tool_item));
- }
-}
-
-/**
- * gtk_tool_item_get_homogeneous:
- * @tool_item: a #GtkToolItem
- *
- * Returns whether @tool_item is the same size as other homogeneous
- * items. See gtk_tool_item_set_homogeneous().
- *
- * Returns: %TRUE if the item is the same size as other homogeneous
- * items.
- **/
-gboolean
-gtk_tool_item_get_homogeneous (GtkToolItem *tool_item)
-{
- g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), FALSE);
-
- return tool_item->priv->homogeneous;
-}
-
-/**
- * gtk_tool_item_get_is_important:
- * @tool_item: a #GtkToolItem
- *
- * Returns whether @tool_item is considered important. See
- * gtk_tool_item_set_is_important()
- *
- * Returns: %TRUE if @tool_item is considered important.
- **/
-gboolean
-gtk_tool_item_get_is_important (GtkToolItem *tool_item)
-{
- g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), FALSE);
-
- return tool_item->priv->is_important;
-}
-
-/**
- * gtk_tool_item_set_is_important:
- * @tool_item: a #GtkToolItem
- * @is_important: whether the tool item should be considered important
- *
- * Sets whether @tool_item should be considered important. The #GtkToolButton
- * class uses this property to determine whether to show or hide its label
- * when the toolbar style is %GTK_TOOLBAR_BOTH_HORIZ. The result is that
- * only tool buttons with the “is_important” property set have labels, an
- * effect known as “priority text”
- **/
-void
-gtk_tool_item_set_is_important (GtkToolItem *tool_item, gboolean is_important)
-{
- g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
-
- is_important = is_important != FALSE;
-
- if (is_important != tool_item->priv->is_important)
- {
- tool_item->priv->is_important = is_important;
-
- gtk_widget_queue_resize (GTK_WIDGET (tool_item));
-
- g_object_notify (G_OBJECT (tool_item), "is-important");
- }
-}
-
-/**
- * gtk_tool_item_set_tooltip_text:
- * @tool_item: a #GtkToolItem
- * @text: text to be used as tooltip for @tool_item
- *
- * Sets the text to be displayed as tooltip on the item.
- * See gtk_widget_set_tooltip_text().
- **/
-void
-gtk_tool_item_set_tooltip_text (GtkToolItem *tool_item,
- const gchar *text)
-{
- GtkWidget *child;
-
- g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
-
- child = gtk_bin_get_child (GTK_BIN (tool_item));
- if (child)
- gtk_widget_set_tooltip_text (child, text);
-}
-
-/**
- * gtk_tool_item_set_tooltip_markup:
- * @tool_item: a #GtkToolItem
- * @markup: markup text to be used as tooltip for @tool_item
- *
- * Sets the markup text to be displayed as tooltip on the item.
- * See gtk_widget_set_tooltip_markup().
- **/
-void
-gtk_tool_item_set_tooltip_markup (GtkToolItem *tool_item,
- const gchar *markup)
-{
- GtkWidget *child;
-
- g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
-
- child = gtk_bin_get_child (GTK_BIN (tool_item));
- if (child)
- gtk_widget_set_tooltip_markup (child, markup);
-}
-
-/**
- * gtk_tool_item_set_visible_horizontal:
- * @tool_item: a #GtkToolItem
- * @visible_horizontal: Whether @tool_item is visible when in horizontal mode
- *
- * Sets whether @tool_item is visible when the toolbar is docked horizontally.
- **/
-void
-gtk_tool_item_set_visible_horizontal (GtkToolItem *toolitem,
- gboolean visible_horizontal)
-{
- g_return_if_fail (GTK_IS_TOOL_ITEM (toolitem));
-
- visible_horizontal = visible_horizontal != FALSE;
-
- if (toolitem->priv->visible_horizontal != visible_horizontal)
- {
- toolitem->priv->visible_horizontal = visible_horizontal;
-
- g_object_notify (G_OBJECT (toolitem), "visible-horizontal");
-
- gtk_widget_queue_resize (GTK_WIDGET (toolitem));
- }
-}
-
-/**
- * gtk_tool_item_get_visible_horizontal:
- * @tool_item: a #GtkToolItem
- *
- * Returns whether the @tool_item is visible on toolbars that are
- * docked horizontally.
- *
- * Returns: %TRUE if @tool_item is visible on toolbars that are
- * docked horizontally.
- **/
-gboolean
-gtk_tool_item_get_visible_horizontal (GtkToolItem *toolitem)
-{
- g_return_val_if_fail (GTK_IS_TOOL_ITEM (toolitem), FALSE);
-
- return toolitem->priv->visible_horizontal;
-}
-
-/**
- * gtk_tool_item_set_visible_vertical:
- * @tool_item: a #GtkToolItem
- * @visible_vertical: whether @tool_item is visible when the toolbar
- * is in vertical mode
- *
- * Sets whether @tool_item is visible when the toolbar is docked
- * vertically. Some tool items, such as text entries, are too wide to be
- * useful on a vertically docked toolbar. If @visible_vertical is %FALSE
- * @tool_item will not appear on toolbars that are docked vertically.
- **/
-void
-gtk_tool_item_set_visible_vertical (GtkToolItem *toolitem,
- gboolean visible_vertical)
-{
- g_return_if_fail (GTK_IS_TOOL_ITEM (toolitem));
-
- visible_vertical = visible_vertical != FALSE;
-
- if (toolitem->priv->visible_vertical != visible_vertical)
- {
- toolitem->priv->visible_vertical = visible_vertical;
-
- g_object_notify (G_OBJECT (toolitem), "visible-vertical");
-
- gtk_widget_queue_resize (GTK_WIDGET (toolitem));
- }
-}
-
-/**
- * gtk_tool_item_get_visible_vertical:
- * @tool_item: a #GtkToolItem
- *
- * Returns whether @tool_item is visible when the toolbar is docked vertically.
- * See gtk_tool_item_set_visible_vertical().
- *
- * Returns: Whether @tool_item is visible when the toolbar is docked vertically
- **/
-gboolean
-gtk_tool_item_get_visible_vertical (GtkToolItem *toolitem)
-{
- g_return_val_if_fail (GTK_IS_TOOL_ITEM (toolitem), FALSE);
-
- return toolitem->priv->visible_vertical;
-}
-
-/**
- * gtk_tool_item_rebuild_menu:
- * @tool_item: a #GtkToolItem
- *
- * Calling this function signals to the toolbar that the
- * overflow menu item for @tool_item has changed. If the
- * overflow menu is visible when this function it called,
- * the menu will be rebuilt.
- *
- * The function must be called when the tool item changes what it
- * will do in response to the #GtkToolItem::create-menu-proxy signal.
- */
-void
-gtk_tool_item_rebuild_menu (GtkToolItem *tool_item)
-{
- GtkWidget *parent;
- GtkWidget *widget;
-
- g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
-
- widget = GTK_WIDGET (tool_item);
-
- parent = gtk_widget_get_parent (widget);
- if (GTK_IS_TOOL_SHELL (parent))
- gtk_tool_shell_rebuild_menu (GTK_TOOL_SHELL (parent));
-}
-
-/**
- * gtk_tool_item_toolbar_reconfigured:
- * @tool_item: a #GtkToolItem
- *
- * Emits the signal #GtkToolItem::toolbar_reconfigured on @tool_item.
- * #GtkToolbar and other #GtkToolShell implementations use this function
- * to notify children, when some aspect of their configuration changes.
- **/
-void
-gtk_tool_item_toolbar_reconfigured (GtkToolItem *tool_item)
-{
- /* The slightely inaccurate name "gtk_tool_item_toolbar_reconfigured" was
- * choosen over "gtk_tool_item_tool_shell_reconfigured", since the function
- * emits the "toolbar-reconfigured" signal, not "tool-shell-reconfigured".
- * It's not possible to rename the signal, and emitting another name than
- * indicated by the function name would be quite confusing. That's the
- * price of providing stable APIs.
- */
- g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
-
- g_signal_emit (tool_item, toolitem_signals[TOOLBAR_RECONFIGURED], 0);
-
- gtk_widget_queue_resize (GTK_WIDGET (tool_item));
-}
-
-/**
- * gtk_tool_item_set_overflow_text:
- * @tool_item: a #GtkToolItem
- * @overflow_text: (nullable): Label to use in the overflow menu
- *
- * Sets the label to use for @tool_item in the overflow menu.
- */
-void
-gtk_tool_item_set_overflow_text (GtkToolItem *tool_item,
- const char *overflow_text)
-{
- g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
-
- g_free (tool_item->priv->overflow_text);
- tool_item->priv->overflow_text = g_strdup (overflow_text);
-
- g_object_notify (G_OBJECT (tool_item), "overflow-text");
-}
-
-/**
- * gtk_tool_item_get_overflow_text:
- * @tool_item: a #GtkToolItem
- *
- * Gets the label that is used for @tool_item in the overflow menu.
- *
- * Return: the overflow menu label for @tool_item
- */
-const char *
-gtk_tool_item_get_overflow_text (GtkToolItem *tool_item)
-{
- g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), NULL);
-
- return tool_item->priv->overflow_text;
-}
+++ /dev/null
-/* gtktoolitem.c
- *
- * Copyright (C) 2002 Anders Carlsson <andersca@gnome.org>
- * Copyright (C) 2002 James Henstridge <james@daa.com.au>
- * Copyright (C) 2003 Soeren Sandmann <sandmann@daimi.au.dk>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef __GTK_TOOL_ITEM_H__
-#define __GTK_TOOL_ITEM_H__
-
-#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
-#error "Only <gtk/gtk.h> can be included directly."
-#endif
-
-#include <gtk/gtkbin.h>
-#include <gtk/gtksizegroup.h>
-
-G_BEGIN_DECLS
-
-#define GTK_TYPE_TOOL_ITEM (gtk_tool_item_get_type ())
-#define GTK_TOOL_ITEM(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GTK_TYPE_TOOL_ITEM, GtkToolItem))
-#define GTK_TOOL_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_TOOL_ITEM, GtkToolItemClass))
-#define GTK_IS_TOOL_ITEM(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GTK_TYPE_TOOL_ITEM))
-#define GTK_IS_TOOL_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_TOOL_ITEM))
-#define GTK_TOOL_ITEM_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS((o), GTK_TYPE_TOOL_ITEM, GtkToolItemClass))
-
-typedef struct _GtkToolItem GtkToolItem;
-typedef struct _GtkToolItemClass GtkToolItemClass;
-typedef struct _GtkToolItemPrivate GtkToolItemPrivate;
-
-struct _GtkToolItem
-{
- GtkBin parent;
-
- /*< private >*/
- GtkToolItemPrivate *priv;
-};
-
-/**
- * GtkToolItemClass:
- * @parent_class: The parent class.
- * @toolbar_reconfigured: Signal emitted when some property of the
- * toolbar that the item is a child of changes.
- */
-struct _GtkToolItemClass
-{
- GtkBinClass parent_class;
-
- /* signals */
- void (* toolbar_reconfigured) (GtkToolItem *tool_item);
-
- /*< private >*/
-
- gpointer padding[8];
-};
-
-
-GDK_AVAILABLE_IN_ALL
-GType gtk_tool_item_get_type (void) G_GNUC_CONST;
-GDK_AVAILABLE_IN_ALL
-GtkToolItem *gtk_tool_item_new (void);
-
-GDK_AVAILABLE_IN_ALL
-void gtk_tool_item_set_homogeneous (GtkToolItem *tool_item,
- gboolean homogeneous);
-GDK_AVAILABLE_IN_ALL
-gboolean gtk_tool_item_get_homogeneous (GtkToolItem *tool_item);
-
-GDK_AVAILABLE_IN_ALL
-void gtk_tool_item_set_expand (GtkToolItem *tool_item,
- gboolean expand);
-GDK_AVAILABLE_IN_ALL
-gboolean gtk_tool_item_get_expand (GtkToolItem *tool_item);
-GDK_AVAILABLE_IN_ALL
-void gtk_tool_item_set_tooltip_text (GtkToolItem *tool_item,
- const gchar *text);
-GDK_AVAILABLE_IN_ALL
-void gtk_tool_item_set_tooltip_markup (GtkToolItem *tool_item,
- const gchar *markup);
-GDK_AVAILABLE_IN_ALL
-void gtk_tool_item_set_visible_horizontal (GtkToolItem *tool_item,
- gboolean visible_horizontal);
-GDK_AVAILABLE_IN_ALL
-gboolean gtk_tool_item_get_visible_horizontal (GtkToolItem *tool_item);
-
-GDK_AVAILABLE_IN_ALL
-void gtk_tool_item_set_visible_vertical (GtkToolItem *tool_item,
- gboolean visible_vertical);
-GDK_AVAILABLE_IN_ALL
-gboolean gtk_tool_item_get_visible_vertical (GtkToolItem *tool_item);
-
-GDK_AVAILABLE_IN_ALL
-gboolean gtk_tool_item_get_is_important (GtkToolItem *tool_item);
-GDK_AVAILABLE_IN_ALL
-void gtk_tool_item_set_is_important (GtkToolItem *tool_item,
- gboolean is_important);
-
-GDK_AVAILABLE_IN_ALL
-PangoEllipsizeMode gtk_tool_item_get_ellipsize_mode (GtkToolItem *tool_item);
-GDK_AVAILABLE_IN_ALL
-GtkOrientation gtk_tool_item_get_orientation (GtkToolItem *tool_item);
-GDK_AVAILABLE_IN_ALL
-GtkToolbarStyle gtk_tool_item_get_toolbar_style (GtkToolItem *tool_item);
-GDK_AVAILABLE_IN_ALL
-gfloat gtk_tool_item_get_text_alignment (GtkToolItem *tool_item);
-GDK_AVAILABLE_IN_ALL
-GtkOrientation gtk_tool_item_get_text_orientation (GtkToolItem *tool_item);
-GDK_AVAILABLE_IN_ALL
-GtkSizeGroup * gtk_tool_item_get_text_size_group (GtkToolItem *tool_item);
-
-GDK_AVAILABLE_IN_ALL
-const char * gtk_tool_item_get_overflow_text (GtkToolItem *tool_item);
-GDK_AVAILABLE_IN_ALL
-void gtk_tool_item_set_overflow_text (GtkToolItem *tool_item,
- const char *overflow_text);
-GDK_AVAILABLE_IN_ALL
-void gtk_tool_item_rebuild_menu (GtkToolItem *tool_item);
-
-GDK_AVAILABLE_IN_ALL
-void gtk_tool_item_toolbar_reconfigured (GtkToolItem *tool_item);
-
-/* private */
-
-gboolean _gtk_tool_item_create_menu_proxy (GtkToolItem *tool_item);
-
-G_END_DECLS
-
-#endif /* __GTK_TOOL_ITEM_H__ */
+++ /dev/null
-/* gtktoolshell.c
- * Copyright (C) 2007 Openismus GmbH
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- *
- * Author:
- * Mathias Hasselmann
- */
-
-#include "config.h"
-#include "gtktoolshell.h"
-#include "gtkwidget.h"
-#include "gtkintl.h"
-
-
-/**
- * SECTION:gtktoolshell
- * @Short_description: Interface for containers containing GtkToolItem widgets
- * @Title: GtkToolShell
- * @see_also: #GtkToolbar, #GtkToolItem
- *
- * The #GtkToolShell interface allows container widgets to provide additional
- * information when embedding #GtkToolItem widgets.
- */
-
-/**
- * GtkToolShell:
- *
- * Dummy structure for accessing instances of #GtkToolShellIface.
- */
-
-
-typedef GtkToolShellIface GtkToolShellInterface;
-G_DEFINE_INTERFACE (GtkToolShell, gtk_tool_shell, GTK_TYPE_WIDGET);
-
-static GtkOrientation gtk_tool_shell_real_get_text_orientation (GtkToolShell *shell);
-static gfloat gtk_tool_shell_real_get_text_alignment (GtkToolShell *shell);
-static PangoEllipsizeMode gtk_tool_shell_real_get_ellipsize_mode (GtkToolShell *shell);
-
-static void
-gtk_tool_shell_default_init (GtkToolShellInterface *iface)
-{
- iface->get_text_orientation = gtk_tool_shell_real_get_text_orientation;
- iface->get_text_alignment = gtk_tool_shell_real_get_text_alignment;
- iface->get_ellipsize_mode = gtk_tool_shell_real_get_ellipsize_mode;
-}
-
-static GtkOrientation
-gtk_tool_shell_real_get_text_orientation (GtkToolShell *shell)
-{
- return GTK_ORIENTATION_HORIZONTAL;
-}
-
-static gfloat
-gtk_tool_shell_real_get_text_alignment (GtkToolShell *shell)
-{
- return 0.5f;
-}
-
-static PangoEllipsizeMode
-gtk_tool_shell_real_get_ellipsize_mode (GtkToolShell *shell)
-{
- return PANGO_ELLIPSIZE_NONE;
-}
-
-
-/**
- * gtk_tool_shell_get_orientation:
- * @shell: a #GtkToolShell
- *
- * Retrieves the current orientation for the tool shell. Tool items must not
- * call this function directly, but rely on gtk_tool_item_get_orientation()
- * instead.
- *
- * Returns: the current orientation of @shell
- **/
-GtkOrientation
-gtk_tool_shell_get_orientation (GtkToolShell *shell)
-{
- return GTK_TOOL_SHELL_GET_IFACE (shell)->get_orientation (shell);
-}
-
-/**
- * gtk_tool_shell_get_style:
- * @shell: a #GtkToolShell
- *
- * Retrieves whether the tool shell has text, icons, or both. Tool items must
- * not call this function directly, but rely on gtk_tool_item_get_toolbar_style()
- * instead.
- *
- * Returns: the current style of @shell
- **/
-GtkToolbarStyle
-gtk_tool_shell_get_style (GtkToolShell *shell)
-{
- return GTK_TOOL_SHELL_GET_IFACE (shell)->get_style (shell);
-}
-
-/**
- * gtk_tool_shell_rebuild_menu:
- * @shell: a #GtkToolShell
- *
- * Calling this function signals the tool shell that the overflow menu item for
- * tool items have changed. If there is an overflow menu and if it is visible
- * when this function it called, the menu will be rebuilt.
- *
- * Tool items must not call this function directly, but rely on
- * gtk_tool_item_rebuild_menu() instead.
- **/
-void
-gtk_tool_shell_rebuild_menu (GtkToolShell *shell)
-{
- GtkToolShellIface *iface = GTK_TOOL_SHELL_GET_IFACE (shell);
-
- if (iface->rebuild_menu)
- iface->rebuild_menu (shell);
-}
-
-/**
- * gtk_tool_shell_get_text_orientation:
- * @shell: a #GtkToolShell
- *
- * Retrieves the current text orientation for the tool shell. Tool items must not
- * call this function directly, but rely on gtk_tool_item_get_text_orientation()
- * instead.
- *
- * Returns: the current text orientation of @shell
- **/
-GtkOrientation
-gtk_tool_shell_get_text_orientation (GtkToolShell *shell)
-{
- GtkToolShellIface *iface = GTK_TOOL_SHELL_GET_IFACE (shell);
-
- return iface->get_text_orientation (shell);
-}
-
-/**
- * gtk_tool_shell_get_text_alignment:
- * @shell: a #GtkToolShell
- *
- * Retrieves the current text alignment for the tool shell. Tool items must not
- * call this function directly, but rely on gtk_tool_item_get_text_alignment()
- * instead.
- *
- * Returns: the current text alignment of @shell
- **/
-gfloat
-gtk_tool_shell_get_text_alignment (GtkToolShell *shell)
-{
- GtkToolShellIface *iface = GTK_TOOL_SHELL_GET_IFACE (shell);
-
- return iface->get_text_alignment (shell);
-}
-
-/**
- * gtk_tool_shell_get_ellipsize_mode:
- * @shell: a #GtkToolShell
- *
- * Retrieves the current ellipsize mode for the tool shell. Tool items must not
- * call this function directly, but rely on gtk_tool_item_get_ellipsize_mode()
- * instead.
- *
- * Returns: the current ellipsize mode of @shell
- **/
-PangoEllipsizeMode
-gtk_tool_shell_get_ellipsize_mode (GtkToolShell *shell)
-{
- GtkToolShellIface *iface = GTK_TOOL_SHELL_GET_IFACE (shell);
-
- return iface->get_ellipsize_mode (shell);
-}
-
-/**
- * gtk_tool_shell_get_text_size_group:
- * @shell: a #GtkToolShell
- *
- * Retrieves the current text size group for the tool shell. Tool items must not
- * call this function directly, but rely on gtk_tool_item_get_text_size_group()
- * instead.
- *
- * Returns: (transfer none): the current text size group of @shell
- **/
-GtkSizeGroup *
-gtk_tool_shell_get_text_size_group (GtkToolShell *shell)
-{
- GtkToolShellIface *iface = GTK_TOOL_SHELL_GET_IFACE (shell);
-
- if (iface->get_text_size_group)
- return GTK_TOOL_SHELL_GET_IFACE (shell)->get_text_size_group (shell);
-
- return NULL;
-}
+++ /dev/null
-/* GTK - The GIMP Toolkit
- * Copyright (C) 2007 Openismus GmbH
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- *
- * Author:
- * Mathias Hasselmann
- */
-
-#ifndef __GTK_TOOL_SHELL_H__
-#define __GTK_TOOL_SHELL_H__
-
-
-#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
-#error "Only <gtk/gtk.h> can be included directly."
-#endif
-
-#include <gtk/gtkenums.h>
-#include <pango/pango.h>
-#include <gtk/gtksizegroup.h>
-
-
-G_BEGIN_DECLS
-
-#define GTK_TYPE_TOOL_SHELL (gtk_tool_shell_get_type ())
-#define GTK_TOOL_SHELL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_TOOL_SHELL, GtkToolShell))
-#define GTK_IS_TOOL_SHELL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_TOOL_SHELL))
-#define GTK_TOOL_SHELL_GET_IFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), GTK_TYPE_TOOL_SHELL, GtkToolShellIface))
-
-typedef struct _GtkToolShell GtkToolShell; /* dummy typedef */
-typedef struct _GtkToolShellIface GtkToolShellIface;
-
-/**
- * GtkToolShellIface:
- * @get_orientation: mandatory implementation of gtk_tool_shell_get_orientation().
- * @get_style: mandatory implementation of gtk_tool_shell_get_style().
- * @rebuild_menu: optional implementation of gtk_tool_shell_rebuild_menu().
- * @get_text_orientation: optional implementation of gtk_tool_shell_get_text_orientation().
- * @get_text_alignment: optional implementation of gtk_tool_shell_get_text_alignment().
- * @get_ellipsize_mode: optional implementation of gtk_tool_shell_get_ellipsize_mode().
- * @get_text_size_group: optional implementation of gtk_tool_shell_get_text_size_group().
- *
- * Virtual function table for the #GtkToolShell interface.
- */
-struct _GtkToolShellIface
-{
- /*< private >*/
- GTypeInterface g_iface;
-
- /*< public >*/
- GtkOrientation (*get_orientation) (GtkToolShell *shell);
- GtkToolbarStyle (*get_style) (GtkToolShell *shell);
- void (*rebuild_menu) (GtkToolShell *shell);
- GtkOrientation (*get_text_orientation) (GtkToolShell *shell);
- gfloat (*get_text_alignment) (GtkToolShell *shell);
- PangoEllipsizeMode (*get_ellipsize_mode) (GtkToolShell *shell);
- GtkSizeGroup * (*get_text_size_group) (GtkToolShell *shell);
-};
-
-GDK_AVAILABLE_IN_ALL
-GType gtk_tool_shell_get_type (void) G_GNUC_CONST;
-
-GDK_AVAILABLE_IN_ALL
-GtkOrientation gtk_tool_shell_get_orientation (GtkToolShell *shell);
-GDK_AVAILABLE_IN_ALL
-GtkToolbarStyle gtk_tool_shell_get_style (GtkToolShell *shell);
-GDK_AVAILABLE_IN_ALL
-void gtk_tool_shell_rebuild_menu (GtkToolShell *shell);
-GDK_AVAILABLE_IN_ALL
-GtkOrientation gtk_tool_shell_get_text_orientation (GtkToolShell *shell);
-GDK_AVAILABLE_IN_ALL
-gfloat gtk_tool_shell_get_text_alignment (GtkToolShell *shell);
-GDK_AVAILABLE_IN_ALL
-PangoEllipsizeMode gtk_tool_shell_get_ellipsize_mode (GtkToolShell *shell);
-GDK_AVAILABLE_IN_ALL
-GtkSizeGroup * gtk_tool_shell_get_text_size_group (GtkToolShell *shell);
-
-G_END_DECLS
-
-#endif /* __GTK_TOOL_SHELL_H__ */
'gtkmediafile.c',
'gtkmediastream.c',
'gtkmenubutton.c',
- 'gtkmenutoolbutton.c',
'gtkmessagedialog.c',
'gtkmodelbutton.c',
'gtkmodules.c',
'gtkprogressbar.c',
'gtkpropertylookuplistmodel.c',
'gtkradiobutton.c',
- 'gtkradiotoolbutton.c',
'gtkrange.c',
'gtktreerbtree.c',
'gtkrecentmanager.c',
'gtkselection.c',
'gtkselectionmodel.c',
'gtkseparator.c',
- 'gtkseparatortoolitem.c',
'gtksettings.c',
'gtkshortcutlabel.c',
'gtkshortcutsgroup.c',
'gtktextutil.c',
'gtktextview.c',
'gtktogglebutton.c',
- 'gtktoggletoolbutton.c',
- 'gtktoolbar.c',
- 'gtktoolbutton.c',
- 'gtktoolitem.c',
- 'gtktoolshell.c',
'gtktooltip.c',
'gtktooltipwindow.c',
'gtktreednd.c',
'gtkmediafile.h',
'gtkmediastream.h',
'gtkmenubutton.h',
- 'gtkmenutoolbutton.h',
'gtkmessagedialog.h',
'gtkmountoperation.h',
'gtknative.h',
'gtkprintsettings.h',
'gtkprogressbar.h',
'gtkradiobutton.h',
- 'gtkradiotoolbutton.h',
'gtkrange.h',
'gtkrecentmanager.h',
'gtkrender.h',
'gtkselection.h',
'gtkselectionmodel.h',
'gtkseparator.h',
- 'gtkseparatortoolitem.h',
'gtksettings.h',
'gtkshortcutlabel.h',
'gtkshortcutsgroup.h',
'gtktexttagtable.h',
'gtktextview.h',
'gtktogglebutton.h',
- 'gtktoggletoolbutton.h',
- 'gtktoolbar.h',
- 'gtktoolbutton.h',
- 'gtktoolitem.h',
- 'gtktoolshell.h',
'gtktooltip.h',
'gtktreednd.h',
'gtktreelistmodel.h',
['testscale'],
['testselectionmode'],
['testspinbutton'],
- ['testtoolbar'],
['testtoolbar2'],
- ['stresstest-toolbar'],
['testtreechanging'],
['testtreednd'],
['testtreeedit'],
+++ /dev/null
-/* stresstest-toolbar.c
- *
- * Copyright (C) 2003 Soeren Sandmann <sandmann@daimi.au.dk>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- */
-#include "config.h"
-#include <gtk/gtk.h>
-
-typedef struct _Info Info;
-struct _Info
-{
- GtkWindow *window;
- GtkToolbar *toolbar;
- gint counter;
-};
-
-static void
-add_random (GtkToolbar *toolbar, gint n)
-{
- gint n_items;
- gint position;
- gchar *label = g_strdup_printf ("Button %d", n);
-
- GtkToolItem *toolitem = gtk_tool_button_new (NULL, label);
- gtk_tool_item_set_tooltip_text (toolitem, "Bar");
-
- g_free (label);
-
- n_items = gtk_toolbar_get_n_items (toolbar);
- if (n_items == 0)
- position = 0;
- else
- position = g_random_int_range (0, n_items);
-
- gtk_toolbar_insert (toolbar, toolitem, position);
-}
-
-static void
-remove_random (GtkToolbar *toolbar)
-{
- GtkToolItem *tool_item;
- gint n_items;
- gint position;
-
- n_items = gtk_toolbar_get_n_items (toolbar);
-
- if (n_items == 0)
- return;
-
- position = g_random_int_range (0, n_items);
-
- tool_item = gtk_toolbar_get_nth_item (toolbar, position);
-
- gtk_container_remove (GTK_CONTAINER (toolbar),
- GTK_WIDGET (tool_item));
-}
-
-static gboolean
-stress_test_old_api (gpointer data)
-{
- typedef enum {
- ADD_RANDOM,
- REMOVE_RANDOM,
- LAST_ACTION
- } Action;
-
- Info *info = data;
- Action action;
- gint n_items;
-
- if (info->counter++ == 200)
- {
- gtk_main_quit ();
- return FALSE;
- }
-
- if (!info->toolbar)
- {
- info->toolbar = GTK_TOOLBAR (gtk_toolbar_new ());
- gtk_container_add (GTK_CONTAINER (info->window),
- GTK_WIDGET (info->toolbar));
- gtk_widget_show (GTK_WIDGET (info->toolbar));
- }
-
- n_items = gtk_toolbar_get_n_items (info->toolbar);
- if (n_items == 0)
- {
- add_random (info->toolbar, info->counter);
- return TRUE;
- }
- else if (n_items > 50)
- {
- int i;
- for (i = 0; i < 25; i++)
- remove_random (info->toolbar);
- return TRUE;
- }
-
- action = g_random_int_range (0, LAST_ACTION);
-
- switch (action)
- {
- case ADD_RANDOM:
- add_random (info->toolbar, info->counter);
- break;
-
- case REMOVE_RANDOM:
- remove_random (info->toolbar);
- break;
-
- default:
- g_assert_not_reached();
- break;
- }
-
- return TRUE;
-}
-
-
-gint
-main (gint argc, gchar **argv)
-{
- Info info;
-
- gtk_init ();
-
- info.toolbar = NULL;
- info.counter = 0;
- info.window = GTK_WINDOW (gtk_window_new (GTK_WINDOW_TOPLEVEL));
-
- gtk_widget_show (GTK_WIDGET (info.window));
-
- g_idle_add (stress_test_old_api, &info);
-
- gtk_widget_show (GTK_WIDGET (info.window));
-
- gtk_main ();
-
- gtk_widget_destroy (GTK_WIDGET (info.window));
-
- info.toolbar = NULL;
- info.window = NULL;
-
- return 0;
-}
+++ /dev/null
-/* testtoolbar.c
- *
- * Copyright (C) 2002 Anders Carlsson <andersca@codefactory.se>
- * Copyright (C) 2002 James Henstridge <james@daa.com.au>
- * Copyright (C) 2003 Soeren Sandmann <sandmann@daimi.au.dk>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- */
-#include "config.h"
-#include <gtk/gtk.h>
-
-static void
-change_orientation (GtkWidget *button, GtkWidget *toolbar)
-{
- GtkWidget *grid;
- GtkOrientation orientation;
-
- grid = gtk_widget_get_parent (toolbar);
- if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)))
- orientation = GTK_ORIENTATION_VERTICAL;
- else
- orientation = GTK_ORIENTATION_HORIZONTAL;
-
- g_object_ref (toolbar);
- gtk_container_remove (GTK_CONTAINER (grid), toolbar);
- gtk_orientable_set_orientation (GTK_ORIENTABLE (toolbar), orientation);
- if (orientation == GTK_ORIENTATION_HORIZONTAL)
- {
- gtk_widget_set_hexpand (toolbar, TRUE);
- gtk_widget_set_vexpand (toolbar, FALSE);
- gtk_grid_attach (GTK_GRID (grid), toolbar, 0, 0, 2, 1);
- }
- else
- {
- gtk_widget_set_hexpand (toolbar, FALSE);
- gtk_widget_set_vexpand (toolbar, TRUE);
- gtk_grid_attach (GTK_GRID (grid), toolbar, 0, 0, 1, 5);
- }
- g_object_unref (toolbar);
-}
-
-static void
-change_show_arrow (GtkWidget *button, GtkWidget *toolbar)
-{
- gtk_toolbar_set_show_arrow (GTK_TOOLBAR (toolbar),
- gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)));
-}
-
-static void
-set_toolbar_style_toggled (GtkCheckButton *button, GtkToolbar *toolbar)
-{
- GtkWidget *option_menu;
- int style;
-
- option_menu = g_object_get_data (G_OBJECT (button), "option-menu");
-
- if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)))
- {
- style = gtk_combo_box_get_active (GTK_COMBO_BOX (option_menu));
-
- gtk_toolbar_set_style (toolbar, style);
- gtk_widget_set_sensitive (option_menu, TRUE);
- }
- else
- {
- gtk_toolbar_unset_style (toolbar);
- gtk_widget_set_sensitive (option_menu, FALSE);
- }
-}
-
-static void
-change_toolbar_style (GtkWidget *option_menu, GtkWidget *toolbar)
-{
- GtkToolbarStyle style;
-
- style = gtk_combo_box_get_active (GTK_COMBO_BOX (option_menu));
- gtk_toolbar_set_style (GTK_TOOLBAR (toolbar), style);
-}
-
-static void
-set_visible_func(GtkTreeViewColumn *tree_column, GtkCellRenderer *cell,
- GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
-{
- GtkToolItem *tool_item;
- gboolean visible;
-
- gtk_tree_model_get (model, iter, 0, &tool_item, -1);
-
- g_object_get (tool_item, "visible", &visible, NULL);
- g_object_set (cell, "active", visible, NULL);
- g_object_unref (tool_item);
-}
-
-static void
-visibile_toggled(GtkCellRendererToggle *cell, const gchar *path_str,
- GtkTreeModel *model)
-{
- GtkTreePath *path;
- GtkTreeIter iter;
- GtkToolItem *tool_item;
- gboolean visible;
-
- path = gtk_tree_path_new_from_string (path_str);
- gtk_tree_model_get_iter (model, &iter, path);
-
- gtk_tree_model_get (model, &iter, 0, &tool_item, -1);
- g_object_get (tool_item, "visible", &visible, NULL);
- g_object_set (tool_item, "visible", !visible, NULL);
- g_object_unref (tool_item);
-
- gtk_tree_model_row_changed (model, path, &iter);
- gtk_tree_path_free (path);
-}
-
-static void
-set_expand_func(GtkTreeViewColumn *tree_column, GtkCellRenderer *cell,
- GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
-{
- GtkToolItem *tool_item;
-
- gtk_tree_model_get (model, iter, 0, &tool_item, -1);
-
- g_object_set (cell, "active", gtk_tool_item_get_expand (tool_item), NULL);
- g_object_unref (tool_item);
-}
-
-static void
-expand_toggled(GtkCellRendererToggle *cell, const gchar *path_str,
- GtkTreeModel *model)
-{
- GtkTreePath *path;
- GtkTreeIter iter;
- GtkToolItem *tool_item;
-
- path = gtk_tree_path_new_from_string (path_str);
- gtk_tree_model_get_iter (model, &iter, path);
-
- gtk_tree_model_get (model, &iter, 0, &tool_item, -1);
- gtk_tool_item_set_expand (tool_item, !gtk_tool_item_get_expand (tool_item));
- g_object_unref (tool_item);
-
- gtk_tree_model_row_changed (model, path, &iter);
- gtk_tree_path_free (path);
-}
-
-static void
-set_homogeneous_func(GtkTreeViewColumn *tree_column, GtkCellRenderer *cell,
- GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
-{
- GtkToolItem *tool_item;
-
- gtk_tree_model_get (model, iter, 0, &tool_item, -1);
-
- g_object_set (cell, "active", gtk_tool_item_get_homogeneous (tool_item), NULL);
- g_object_unref (tool_item);
-}
-
-static void
-homogeneous_toggled(GtkCellRendererToggle *cell, const gchar *path_str,
- GtkTreeModel *model)
-{
- GtkTreePath *path;
- GtkTreeIter iter;
- GtkToolItem *tool_item;
-
- path = gtk_tree_path_new_from_string (path_str);
- gtk_tree_model_get_iter (model, &iter, path);
-
- gtk_tree_model_get (model, &iter, 0, &tool_item, -1);
- gtk_tool_item_set_homogeneous (tool_item, !gtk_tool_item_get_homogeneous (tool_item));
- g_object_unref (tool_item);
-
- gtk_tree_model_row_changed (model, path, &iter);
- gtk_tree_path_free (path);
-}
-
-
-static void
-set_important_func(GtkTreeViewColumn *tree_column, GtkCellRenderer *cell,
- GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
-{
- GtkToolItem *tool_item;
-
- gtk_tree_model_get (model, iter, 0, &tool_item, -1);
-
- g_object_set (cell, "active", gtk_tool_item_get_is_important (tool_item), NULL);
- g_object_unref (tool_item);
-}
-
-static void
-important_toggled(GtkCellRendererToggle *cell, const gchar *path_str,
- GtkTreeModel *model)
-{
- GtkTreePath *path;
- GtkTreeIter iter;
- GtkToolItem *tool_item;
-
- path = gtk_tree_path_new_from_string (path_str);
- gtk_tree_model_get_iter (model, &iter, path);
-
- gtk_tree_model_get (model, &iter, 0, &tool_item, -1);
- gtk_tool_item_set_is_important (tool_item, !gtk_tool_item_get_is_important (tool_item));
- g_object_unref (tool_item);
-
- gtk_tree_model_row_changed (model, path, &iter);
- gtk_tree_path_free (path);
-}
-
-static GtkListStore *
-create_items_list (GtkWidget **tree_view_p)
-{
- GtkWidget *tree_view;
- GtkListStore *list_store;
- GtkCellRenderer *cell;
-
- list_store = gtk_list_store_new (2, GTK_TYPE_TOOL_ITEM, G_TYPE_STRING);
-
- tree_view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (list_store));
-
- gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree_view),
- -1, "Tool Item",
- gtk_cell_renderer_text_new (),
- "text", 1, NULL);
-
- cell = gtk_cell_renderer_toggle_new ();
- g_signal_connect (cell, "toggled", G_CALLBACK (visibile_toggled),
- list_store);
- gtk_tree_view_insert_column_with_data_func (GTK_TREE_VIEW (tree_view),
- -1, "Visible",
- cell,
- set_visible_func, NULL, NULL);
-
- cell = gtk_cell_renderer_toggle_new ();
- g_signal_connect (cell, "toggled", G_CALLBACK (expand_toggled),
- list_store);
- gtk_tree_view_insert_column_with_data_func (GTK_TREE_VIEW (tree_view),
- -1, "Expand",
- cell,
- set_expand_func, NULL, NULL);
-
- cell = gtk_cell_renderer_toggle_new ();
- g_signal_connect (cell, "toggled", G_CALLBACK (homogeneous_toggled),
- list_store);
- gtk_tree_view_insert_column_with_data_func (GTK_TREE_VIEW (tree_view),
- -1, "Homogeneous",
- cell,
- set_homogeneous_func, NULL,NULL);
-
- cell = gtk_cell_renderer_toggle_new ();
- g_signal_connect (cell, "toggled", G_CALLBACK (important_toggled),
- list_store);
- gtk_tree_view_insert_column_with_data_func (GTK_TREE_VIEW (tree_view),
- -1, "Important",
- cell,
- set_important_func, NULL,NULL);
-
- g_object_unref (list_store);
-
- *tree_view_p = tree_view;
-
- return list_store;
-}
-
-static void
-add_item_to_list (GtkListStore *store, GtkToolItem *item, const gchar *text)
-{
- GtkTreeIter iter;
-
- gtk_list_store_append (store, &iter);
- gtk_list_store_set (store, &iter,
- 0, item,
- 1, text,
- -1);
-
-}
-
-static void
-bold_toggled (GtkToggleToolButton *button)
-{
- g_message ("Bold toggled (active=%d)",
- gtk_toggle_tool_button_get_active (button));
-}
-
-static gboolean
-toolbar_drag_drop (GtkDropTarget *dest,
- GdkDrop *drop,
- gint x, gint y,
- GtkWidget *label)
-{
- GtkWidget *widget = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (dest));
- gchar buf[32];
-
- g_snprintf(buf, sizeof(buf), "%d",
- gtk_toolbar_get_drop_index (GTK_TOOLBAR (widget), x, y));
- gtk_label_set_label (GTK_LABEL (label), buf);
-
- return TRUE;
-}
-
-static const char *target_table[] = {
- "application/x-toolbar-item"
-};
-
-static void
-rtl_toggled (GtkCheckButton *check)
-{
- if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check)))
- gtk_widget_set_default_direction (GTK_TEXT_DIR_RTL);
- else
- gtk_widget_set_default_direction (GTK_TEXT_DIR_LTR);
-}
-
-static GtkToolItem *drag_item = NULL;
-
-static gboolean
-toolbar_drag_motion (GtkDropTarget *dest,
- GdkDrop *drop,
- gint x,
- gint y,
- GtkToolbar *toolbar)
-{
- gint index;
-
- if (!drag_item)
- {
- drag_item = gtk_tool_button_new (NULL, "A quite long button");
- g_object_ref_sink (g_object_ref (drag_item));
- }
-
- gdk_drop_status (drop, GDK_ACTION_MOVE);
-
- index = gtk_toolbar_get_drop_index (toolbar, x, y);
-
- gtk_toolbar_set_drop_highlight_item (toolbar, drag_item, index);
-
- return TRUE;
-}
-
-static void
-toolbar_drag_leave (GtkDropTarget *dest,
- GdkDrop *drop,
- GtkToolbar *toolbar)
-{
- if (drag_item)
- {
- g_object_unref (drag_item);
- drag_item = NULL;
- }
-
- gtk_toolbar_set_drop_highlight_item (toolbar, NULL, 0);
-}
-
-static gboolean
-timeout_cb (GtkWidget *widget)
-{
- static gboolean sensitive = TRUE;
-
- sensitive = !sensitive;
-
- gtk_widget_set_sensitive (widget, sensitive);
-
- return TRUE;
-}
-
-static gboolean
-timeout_cb1 (GtkWidget *widget)
-{
- static gboolean sensitive = TRUE;
- sensitive = !sensitive;
- gtk_widget_set_sensitive (widget, sensitive);
- return TRUE;
-}
-
-gint
-main (gint argc, gchar **argv)
-{
- GtkWidget *window, *toolbar, *grid, *treeview, *scrolled_window;
- GtkWidget *hbox, *hbox1, *hbox2, *checkbox, *option_menu, *menu;
- gint i;
- GdkContentFormats *targets;
- GdkContentProvider *content;
- GtkDragSource *source;
- GtkDropTarget *dest;
- static const gchar *toolbar_styles[] = { "icons", "text", "both (vertical)",
- "both (horizontal)" };
- GtkToolItem *item;
- GtkListStore *store;
- GtkWidget *image;
- GtkWidget *menuitem;
- GtkWidget *box;
- GtkWidget *button;
- GtkWidget *label;
- GIcon *gicon;
- GSList *group;
-
- gtk_init ();
-
- window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
-
- g_signal_connect (window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
-
- grid = gtk_grid_new ();
- gtk_container_add (GTK_CONTAINER (window), grid);
-
- toolbar = gtk_toolbar_new ();
- gtk_grid_attach (GTK_GRID (grid), toolbar, 0, 0, 2, 1);
-
- hbox1 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 3);
- gtk_grid_attach (GTK_GRID (grid), hbox1, 1, 1, 1, 1);
-
- hbox2 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
- gtk_grid_attach (GTK_GRID (grid), hbox2, 1, 2, 1, 1);
-
- checkbox = gtk_check_button_new_with_mnemonic("_Vertical");
- gtk_container_add (GTK_CONTAINER (hbox1), checkbox);
- g_signal_connect (checkbox, "toggled",
- G_CALLBACK (change_orientation), toolbar);
-
- checkbox = gtk_check_button_new_with_mnemonic("_Show Arrow");
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (checkbox), TRUE);
- gtk_container_add (GTK_CONTAINER (hbox1), checkbox);
- g_signal_connect (checkbox, "toggled",
- G_CALLBACK (change_show_arrow), toolbar);
-
- checkbox = gtk_check_button_new_with_mnemonic("_Set Toolbar Style:");
- g_signal_connect (checkbox, "toggled", G_CALLBACK (set_toolbar_style_toggled), toolbar);
- gtk_container_add (GTK_CONTAINER (hbox1), checkbox);
-
- option_menu = gtk_combo_box_text_new ();
- gtk_widget_set_sensitive (option_menu, FALSE);
- g_object_set_data (G_OBJECT (checkbox), "option-menu", option_menu);
-
- for (i = 0; i < G_N_ELEMENTS (toolbar_styles); i++)
- gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (option_menu), toolbar_styles[i]);
- gtk_combo_box_set_active (GTK_COMBO_BOX (option_menu),
- gtk_toolbar_get_style (GTK_TOOLBAR (toolbar)));
- gtk_container_add (GTK_CONTAINER (hbox2), option_menu);
- g_signal_connect (option_menu, "changed",
- G_CALLBACK (change_toolbar_style), toolbar);
-
- scrolled_window = gtk_scrolled_window_new (NULL, NULL);
- gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
- GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
- gtk_widget_set_hexpand (scrolled_window, TRUE);
- gtk_widget_set_vexpand (scrolled_window, TRUE);
- gtk_grid_attach (GTK_GRID (grid), scrolled_window, 1, 3, 1, 1);
-
- store = create_items_list (&treeview);
- gtk_container_add (GTK_CONTAINER (scrolled_window), treeview);
-
- item = gtk_tool_button_new (NULL, NULL);
- gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (item), "document-new");
- gtk_tool_button_set_label (GTK_TOOL_BUTTON (item), "Custom label");
- add_item_to_list (store, item, "New");
- gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
- g_timeout_add (3000, (GSourceFunc) timeout_cb, item);
- gtk_tool_item_set_expand (item, TRUE);
-
- menu = gtk_popover_new (NULL);
- box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
- gtk_container_add (GTK_CONTAINER (menu), box);
- for (i = 0; i < 20; i++)
- {
- char *text;
- text = g_strdup_printf ("Menuitem %d", i);
- menuitem = gtk_button_new_with_label (text);
- g_free (text);
- gtk_container_add (GTK_CONTAINER (box), menuitem);
- }
-
- item = gtk_menu_tool_button_new (NULL, NULL);
- gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (item), "document-open");
- gtk_tool_button_set_label (GTK_TOOL_BUTTON (item), "Open");
- gtk_menu_tool_button_set_popover (GTK_MENU_TOOL_BUTTON (item), menu);
- add_item_to_list (store, item, "Open");
- gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
- g_timeout_add (3000, (GSourceFunc) timeout_cb1, item);
-
- menu = gtk_popover_new (NULL);
- box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
- gtk_container_add (GTK_CONTAINER (menu), box);
- for (i = 0; i < 20; i++)
- {
- char *text;
- text = g_strdup_printf ("A%d", i);
- menuitem = gtk_button_new_with_label (text);
- g_free (text);
- gtk_container_add (GTK_CONTAINER (box), menuitem);
- }
-
- item = gtk_menu_tool_button_new (NULL, NULL);
- gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (item), "go-previous");
- gtk_tool_button_set_label (GTK_TOOL_BUTTON (item), "Back");
- gtk_menu_tool_button_set_popover (GTK_MENU_TOOL_BUTTON (item), menu);
- add_item_to_list (store, item, "BackWithHistory");
- gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
-
- item = gtk_separator_tool_item_new ();
- add_item_to_list (store, item, "-----");
- gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
-
- image = gtk_image_new_from_icon_name ("dialog-warning");
- gtk_image_set_icon_size (GTK_IMAGE (image), GTK_ICON_SIZE_LARGE);
- item = gtk_tool_item_new ();
- gtk_widget_show (image);
- gtk_container_add (GTK_CONTAINER (item), image);
- add_item_to_list (store, item, "(Custom Item)");
- gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
-
- item = gtk_tool_button_new (NULL, NULL);
- gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (item), "go-previous");
- gtk_tool_button_set_label (GTK_TOOL_BUTTON (item), "Back");
- add_item_to_list (store, item, "Back");
- gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
-
- item = gtk_separator_tool_item_new ();
- add_item_to_list (store, item, "-----");
- gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
-
- item = gtk_tool_button_new (NULL, NULL);
- gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (item), "go-next");
- gtk_tool_button_set_label (GTK_TOOL_BUTTON (item), "Forward");
- add_item_to_list (store, item, "Forward");
- gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
-
- item = gtk_toggle_tool_button_new ();
- gtk_tool_button_set_label (GTK_TOOL_BUTTON (item), "Bold");
- gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (item), "format-text-bold");
- g_signal_connect (item, "toggled", G_CALLBACK (bold_toggled), NULL);
- add_item_to_list (store, item, "Bold");
- gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
- gtk_widget_set_sensitive (GTK_WIDGET (item), FALSE);
-
- item = gtk_separator_tool_item_new ();
- add_item_to_list (store, item, "-----");
- gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
- gtk_tool_item_set_expand (item, TRUE);
- gtk_separator_tool_item_set_draw (GTK_SEPARATOR_TOOL_ITEM (item), FALSE);
- g_assert (gtk_toolbar_get_nth_item (GTK_TOOLBAR (toolbar), 0) != 0);
-
- item = gtk_radio_tool_button_new (NULL);
- gtk_tool_button_set_label (GTK_TOOL_BUTTON (item), "Left");
- gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (item), "format-justify-left");
- group = gtk_radio_tool_button_get_group (GTK_RADIO_TOOL_BUTTON (item));
- add_item_to_list (store, item, "Left");
- gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
-
-
- item = gtk_radio_tool_button_new (group);
- gtk_tool_button_set_label (GTK_TOOL_BUTTON (item), "Center");
- gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (item), "format-justify-center");
- group = gtk_radio_tool_button_get_group (GTK_RADIO_TOOL_BUTTON (item));
- add_item_to_list (store, item, "Center");
- gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
-
- item = gtk_radio_tool_button_new (group);
- gtk_tool_button_set_label (GTK_TOOL_BUTTON (item), "Right");
- gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (item), "format-justify-right");
- add_item_to_list (store, item, "Right");
- gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
-
- item = gtk_tool_button_new (gtk_image_new_from_file ("apple-red.png"), "_Apple");
- add_item_to_list (store, item, "Apple");
- gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
- gtk_tool_button_set_use_underline (GTK_TOOL_BUTTON (item), TRUE);
-
- gicon = g_content_type_get_icon ("video/ogg");
- image = gtk_image_new_from_gicon (gicon);
- g_object_unref (gicon);
- item = gtk_tool_button_new (image, "Video");
- add_item_to_list (store, item, "Video");
- gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
-
- image = gtk_image_new_from_icon_name ("utilities-terminal");
- item = gtk_tool_button_new (image, "Terminal");
- add_item_to_list (store, item, "Terminal");
- gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
-
- image = gtk_spinner_new ();
- gtk_spinner_start (GTK_SPINNER (image));
- item = gtk_tool_button_new (image, "Spinner");
- add_item_to_list (store, item, "Spinner");
- gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
-
- hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 5);
- gtk_widget_set_hexpand (hbox, TRUE);
- gtk_grid_attach (GTK_GRID (grid), hbox, 1, 4, 1, 1);
-
- button = gtk_button_new_with_label ("Drag me to the toolbar");
- gtk_container_add (GTK_CONTAINER (hbox), button);
-
- label = gtk_label_new ("Drop index:");
- gtk_container_add (GTK_CONTAINER (hbox), label);
-
- label = gtk_label_new ("");
- gtk_widget_set_hexpand (label, TRUE);
- gtk_widget_set_halign (label, GTK_ALIGN_START);
- gtk_container_add (GTK_CONTAINER (hbox), label);
-
-
- checkbox = gtk_check_button_new_with_mnemonic("_Right to left");
- if (gtk_widget_get_default_direction () == GTK_TEXT_DIR_RTL)
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (checkbox), TRUE);
- else
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (checkbox), FALSE);
- g_signal_connect (checkbox, "toggled", G_CALLBACK (rtl_toggled), NULL);
-
- gtk_container_add (GTK_CONTAINER (hbox), checkbox);
-
- targets = gdk_content_formats_new (target_table, G_N_ELEMENTS (target_table));
- content = gdk_content_provider_new_for_bytes (target_table[0], g_bytes_new ("", 1));
- source = gtk_drag_source_new ();
- gtk_drag_source_set_content (source, content);
- gtk_drag_source_set_actions (source, GDK_ACTION_MOVE);
- g_object_unref (content);
- gtk_widget_add_controller (button, GTK_EVENT_CONTROLLER (source));
- dest = gtk_drop_target_new (targets, GDK_ACTION_MOVE);
- g_signal_connect (dest, "drag_motion", G_CALLBACK (toolbar_drag_motion), toolbar);
- g_signal_connect (dest, "drag_leave", G_CALLBACK (toolbar_drag_leave), toolbar);
- g_signal_connect (dest, "drag_drop", G_CALLBACK (toolbar_drag_drop), label);
- gtk_widget_add_controller (toolbar, GTK_EVENT_CONTROLLER (dest));
- gdk_content_formats_unref (targets);
-
- gtk_widget_show (window);
-
- g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
-
- gtk_main ();
-
- return 0;
-}