2008-07-01 22:57:50 +00:00
|
|
|
/* GTK - The GIMP Toolkit
|
2004-09-27 18:37:33 +00:00
|
|
|
*
|
|
|
|
* 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, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2008-06-22 14:28:52 +00:00
|
|
|
#include "config.h"
|
2008-06-17 14:11:26 +00:00
|
|
|
|
2004-09-27 18:37:33 +00:00
|
|
|
#include "gtkmenutoolbutton.h"
|
2010-09-14 01:33:06 +00:00
|
|
|
|
2004-09-27 18:37:33 +00:00
|
|
|
#include "gtktogglebutton.h"
|
|
|
|
#include "gtkarrow.h"
|
2011-08-28 05:40:10 +00:00
|
|
|
#include "gtkbox.h"
|
2004-09-27 18:37:33 +00:00
|
|
|
#include "gtkmenu.h"
|
|
|
|
#include "gtkmain.h"
|
2010-09-14 01:33:06 +00:00
|
|
|
#include "gtksizerequest.h"
|
2011-01-09 04:10:40 +00:00
|
|
|
#include "gtkbuildable.h"
|
2010-09-14 01:33:06 +00:00
|
|
|
|
2005-03-22 02:14:55 +00:00
|
|
|
#include "gtkprivate.h"
|
2008-06-17 14:11:26 +00:00
|
|
|
#include "gtkintl.h"
|
2004-09-27 18:37:33 +00:00
|
|
|
|
|
|
|
|
2011-04-14 23:08:33 +00:00
|
|
|
/**
|
|
|
|
* 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. Use gtk_menu_tool_button_new_from_stock() to
|
|
|
|
* create a new #GtkMenuToolButton containing a stock item.
|
|
|
|
*
|
|
|
|
* <refsect2 id="GtkMenuToolButton-BUILDER-UI">
|
|
|
|
* <title>GtkMenuToolButton as GtkBuildable</title>
|
|
|
|
* <para>
|
|
|
|
* The GtkMenuToolButton implementation of the GtkBuildable interface
|
|
|
|
* supports adding a menu by specifying "menu" as the "type"
|
|
|
|
* attribute of a <child> element.
|
|
|
|
*
|
|
|
|
* <example>
|
|
|
|
* <title>A UI definition fragment with menus</title>
|
|
|
|
* <programlisting><![CDATA[
|
|
|
|
* <object class="GtkMenuToolButton">
|
|
|
|
* <child type="menu">
|
|
|
|
* <object class="GtkMenu"/>
|
|
|
|
* </child>
|
|
|
|
* </object>
|
|
|
|
* ]]></programlisting>
|
|
|
|
* </example>
|
|
|
|
* </para>
|
|
|
|
* </refsect2>
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2004-09-27 18:37:33 +00:00
|
|
|
struct _GtkMenuToolButtonPrivate
|
|
|
|
{
|
|
|
|
GtkWidget *button;
|
|
|
|
GtkWidget *arrow;
|
|
|
|
GtkWidget *arrow_button;
|
|
|
|
GtkWidget *box;
|
|
|
|
GtkMenu *menu;
|
|
|
|
};
|
|
|
|
|
2010-09-18 23:55:42 +00:00
|
|
|
static void gtk_menu_tool_button_destroy (GtkWidget *widget);
|
2005-08-18 20:29:55 +00:00
|
|
|
|
|
|
|
static int menu_deactivate_cb (GtkMenuShell *menu_shell,
|
|
|
|
GtkMenuToolButton *button);
|
2004-09-27 18:37:33 +00:00
|
|
|
|
2011-01-09 04:10:40 +00:00
|
|
|
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);
|
|
|
|
|
2004-09-27 18:37:33 +00:00
|
|
|
enum
|
|
|
|
{
|
2004-10-05 14:19:54 +00:00
|
|
|
SHOW_MENU,
|
2004-09-27 18:37:33 +00:00
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
2008-05-19 14:15:34 +00:00
|
|
|
PROP_MENU
|
2004-09-27 18:37:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static gint signals[LAST_SIGNAL];
|
|
|
|
|
2011-01-09 04:10:40 +00:00
|
|
|
static GtkBuildableIface *parent_buildable_iface;
|
|
|
|
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (GtkMenuToolButton, gtk_menu_tool_button, GTK_TYPE_TOOL_BUTTON,
|
|
|
|
G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
|
|
|
|
gtk_menu_tool_button_buildable_interface_init))
|
2004-09-27 18:37:33 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_menu_tool_button_construct_contents (GtkMenuToolButton *button)
|
|
|
|
{
|
2005-08-08 18:14:26 +00:00
|
|
|
GtkMenuToolButtonPrivate *priv = button->priv;
|
2004-09-27 18:37:33 +00:00
|
|
|
GtkWidget *box;
|
2010-08-11 21:07:35 +00:00
|
|
|
GtkWidget *parent;
|
2004-09-27 18:37:33 +00:00
|
|
|
GtkOrientation orientation;
|
|
|
|
|
|
|
|
orientation = gtk_tool_item_get_orientation (GTK_TOOL_ITEM (button));
|
|
|
|
|
|
|
|
if (orientation == GTK_ORIENTATION_HORIZONTAL)
|
|
|
|
{
|
2010-10-31 17:07:20 +00:00
|
|
|
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
|
2004-09-27 18:37:33 +00:00
|
|
|
gtk_arrow_set (GTK_ARROW (priv->arrow), GTK_ARROW_DOWN, GTK_SHADOW_NONE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-10-31 17:07:20 +00:00
|
|
|
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
|
2004-09-27 18:37:33 +00:00
|
|
|
gtk_arrow_set (GTK_ARROW (priv->arrow), GTK_ARROW_RIGHT, GTK_SHADOW_NONE);
|
|
|
|
}
|
|
|
|
|
2010-08-11 21:07:35 +00:00
|
|
|
parent = gtk_widget_get_parent (priv->button);
|
|
|
|
if (priv->button && parent)
|
2004-09-27 18:37:33 +00:00
|
|
|
{
|
|
|
|
g_object_ref (priv->button);
|
2010-08-11 21:07:35 +00:00
|
|
|
gtk_container_remove (GTK_CONTAINER (parent),
|
2004-09-27 18:37:33 +00:00
|
|
|
priv->button);
|
|
|
|
gtk_container_add (GTK_CONTAINER (box), priv->button);
|
|
|
|
g_object_unref (priv->button);
|
|
|
|
}
|
|
|
|
|
2010-08-11 21:07:35 +00:00
|
|
|
parent = gtk_widget_get_parent (priv->arrow_button);
|
|
|
|
if (priv->arrow_button && parent)
|
2004-09-27 18:37:33 +00:00
|
|
|
{
|
|
|
|
g_object_ref (priv->arrow_button);
|
2010-08-11 21:07:35 +00:00
|
|
|
gtk_container_remove (GTK_CONTAINER (parent),
|
2004-09-27 18:37:33 +00:00
|
|
|
priv->arrow_button);
|
|
|
|
gtk_box_pack_end (GTK_BOX (box), priv->arrow_button,
|
|
|
|
FALSE, FALSE, 0);
|
|
|
|
g_object_unref (priv->arrow_button);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (priv->box)
|
|
|
|
{
|
2007-09-10 12:46:23 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2004-09-27 18:37:33 +00:00
|
|
|
/* 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_show_all (priv->box);
|
|
|
|
|
2005-08-05 20:55:48 +00:00
|
|
|
gtk_button_set_relief (GTK_BUTTON (priv->arrow_button),
|
|
|
|
gtk_tool_item_get_relief_style (GTK_TOOL_ITEM (button)));
|
|
|
|
|
2004-09-27 18:37:33 +00:00
|
|
|
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 */
|
2006-05-02 23:56:43 +00:00
|
|
|
GTK_TOOL_ITEM_CLASS (gtk_menu_tool_button_parent_class)->toolbar_reconfigured (toolitem);
|
2004-09-27 18:37:33 +00:00
|
|
|
}
|
|
|
|
|
2005-08-08 18:34:43 +00:00
|
|
|
static void
|
|
|
|
gtk_menu_tool_button_state_changed (GtkWidget *widget,
|
|
|
|
GtkStateType previous_state)
|
|
|
|
{
|
|
|
|
GtkMenuToolButton *button = GTK_MENU_TOOL_BUTTON (widget);
|
|
|
|
GtkMenuToolButtonPrivate *priv = button->priv;
|
|
|
|
|
2010-02-27 04:24:24 +00:00
|
|
|
if (!gtk_widget_is_sensitive (widget) && priv->menu)
|
2005-08-08 18:34:43 +00:00
|
|
|
{
|
|
|
|
gtk_menu_shell_deactivate (GTK_MENU_SHELL (priv->menu));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-09-27 18:37:33 +00:00
|
|
|
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_MENU:
|
|
|
|
gtk_menu_tool_button_set_menu (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_MENU:
|
|
|
|
g_value_set_object (value, button->priv->menu);
|
|
|
|
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;
|
2005-08-08 18:34:43 +00:00
|
|
|
GtkWidgetClass *widget_class;
|
2004-09-27 18:37:33 +00:00
|
|
|
GtkToolItemClass *toolitem_class;
|
|
|
|
|
|
|
|
object_class = (GObjectClass *)klass;
|
2005-08-08 18:34:43 +00:00
|
|
|
widget_class = (GtkWidgetClass *)klass;
|
2004-09-27 18:37:33 +00:00
|
|
|
toolitem_class = (GtkToolItemClass *)klass;
|
|
|
|
|
|
|
|
object_class->set_property = gtk_menu_tool_button_set_property;
|
|
|
|
object_class->get_property = gtk_menu_tool_button_get_property;
|
2010-09-18 23:55:42 +00:00
|
|
|
|
|
|
|
widget_class->destroy = gtk_menu_tool_button_destroy;
|
2005-08-08 18:34:43 +00:00
|
|
|
widget_class->state_changed = gtk_menu_tool_button_state_changed;
|
2010-09-18 23:55:42 +00:00
|
|
|
|
2004-09-27 18:37:33 +00:00
|
|
|
toolitem_class->toolbar_reconfigured = gtk_menu_tool_button_toolbar_reconfigured;
|
|
|
|
|
2008-12-30 05:49:05 +00:00
|
|
|
/**
|
|
|
|
* 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_get_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.
|
|
|
|
*/
|
2004-10-05 14:19:54 +00:00
|
|
|
signals[SHOW_MENU] =
|
2005-09-01 05:11:46 +00:00
|
|
|
g_signal_new (I_("show-menu"),
|
2004-09-27 18:37:33 +00:00
|
|
|
G_OBJECT_CLASS_TYPE (klass),
|
2004-10-05 14:19:54 +00:00
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
G_STRUCT_OFFSET (GtkMenuToolButtonClass, show_menu),
|
|
|
|
NULL, NULL,
|
|
|
|
g_cclosure_marshal_VOID__VOID,
|
|
|
|
G_TYPE_NONE, 0);
|
2004-09-27 18:37:33 +00:00
|
|
|
|
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
PROP_MENU,
|
|
|
|
g_param_spec_object ("menu",
|
|
|
|
P_("Menu"),
|
|
|
|
P_("The dropdown menu"),
|
|
|
|
GTK_TYPE_MENU,
|
2005-03-22 02:14:55 +00:00
|
|
|
GTK_PARAM_READWRITE));
|
2004-09-27 18:37:33 +00:00
|
|
|
|
|
|
|
g_type_class_add_private (object_class, sizeof (GtkMenuToolButtonPrivate));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
menu_position_func (GtkMenu *menu,
|
|
|
|
int *x,
|
|
|
|
int *y,
|
|
|
|
gboolean *push_in,
|
|
|
|
GtkMenuToolButton *button)
|
|
|
|
{
|
2005-08-08 18:14:26 +00:00
|
|
|
GtkMenuToolButtonPrivate *priv = button->priv;
|
2010-08-11 21:07:35 +00:00
|
|
|
GtkAllocation arrow_allocation;
|
2005-08-15 16:36:31 +00:00
|
|
|
GtkWidget *widget = GTK_WIDGET (button);
|
2004-09-27 18:37:33 +00:00
|
|
|
GtkRequisition req;
|
|
|
|
GtkRequisition menu_req;
|
|
|
|
GtkOrientation orientation;
|
|
|
|
GtkTextDirection direction;
|
2005-08-15 16:36:31 +00:00
|
|
|
GdkRectangle monitor;
|
|
|
|
gint monitor_num;
|
|
|
|
GdkScreen *screen;
|
2010-08-11 21:07:35 +00:00
|
|
|
GdkWindow *window;
|
2004-09-27 18:37:33 +00:00
|
|
|
|
2010-09-21 14:35:17 +00:00
|
|
|
gtk_widget_get_preferred_size (GTK_WIDGET (priv->menu),
|
|
|
|
&menu_req, NULL);
|
2004-09-27 18:37:33 +00:00
|
|
|
|
|
|
|
orientation = gtk_tool_item_get_orientation (GTK_TOOL_ITEM (button));
|
2005-08-15 16:36:31 +00:00
|
|
|
direction = gtk_widget_get_direction (widget);
|
2010-08-11 21:07:35 +00:00
|
|
|
window = gtk_widget_get_window (widget);
|
2005-08-15 16:36:31 +00:00
|
|
|
|
|
|
|
screen = gtk_widget_get_screen (GTK_WIDGET (menu));
|
2010-08-11 21:07:35 +00:00
|
|
|
monitor_num = gdk_screen_get_monitor_at_window (screen, window);
|
2005-08-15 16:36:31 +00:00
|
|
|
if (monitor_num < 0)
|
|
|
|
monitor_num = 0;
|
2011-12-18 19:28:01 +00:00
|
|
|
gdk_screen_get_monitor_workarea (screen, monitor_num, &monitor);
|
2004-09-27 18:37:33 +00:00
|
|
|
|
|
|
|
if (orientation == GTK_ORIENTATION_HORIZONTAL)
|
|
|
|
{
|
2010-08-11 21:07:35 +00:00
|
|
|
GtkAllocation allocation;
|
|
|
|
|
|
|
|
gtk_widget_get_allocation (widget, &allocation);
|
|
|
|
gtk_widget_get_allocation (priv->arrow_button, &arrow_allocation);
|
|
|
|
|
|
|
|
gdk_window_get_origin (window, x, y);
|
|
|
|
*x += allocation.x;
|
|
|
|
*y += allocation.y;
|
2005-08-15 16:36:31 +00:00
|
|
|
|
2004-09-27 18:37:33 +00:00
|
|
|
if (direction == GTK_TEXT_DIR_LTR)
|
2010-08-11 21:07:35 +00:00
|
|
|
*x += MAX (allocation.width - menu_req.width, 0);
|
|
|
|
else if (menu_req.width > allocation.width)
|
|
|
|
*x -= menu_req.width - allocation.width;
|
2005-08-15 16:36:31 +00:00
|
|
|
|
2010-08-11 21:07:35 +00:00
|
|
|
if ((*y + arrow_allocation.height + menu_req.height) <= monitor.y + monitor.height)
|
|
|
|
*y += arrow_allocation.height;
|
2005-08-15 16:36:31 +00:00
|
|
|
else if ((*y - menu_req.height) >= monitor.y)
|
|
|
|
*y -= menu_req.height;
|
2010-08-11 21:07:35 +00:00
|
|
|
else if (monitor.y + monitor.height - (*y + arrow_allocation.height) > *y)
|
|
|
|
*y += arrow_allocation.height;
|
2004-09-27 18:37:33 +00:00
|
|
|
else
|
2005-08-15 16:36:31 +00:00
|
|
|
*y -= menu_req.height;
|
2004-09-27 18:37:33 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-10-19 00:00:10 +00:00
|
|
|
gdk_window_get_origin (gtk_button_get_event_window (GTK_BUTTON (priv->arrow_button)), x, y);
|
2010-09-21 14:35:17 +00:00
|
|
|
gtk_widget_get_preferred_size (priv->arrow_button,
|
|
|
|
&req, NULL);
|
2005-08-15 16:36:31 +00:00
|
|
|
|
2010-08-11 21:07:35 +00:00
|
|
|
gtk_widget_get_allocation (priv->arrow_button, &arrow_allocation);
|
|
|
|
|
2004-09-27 18:37:33 +00:00
|
|
|
if (direction == GTK_TEXT_DIR_LTR)
|
2010-08-11 21:07:35 +00:00
|
|
|
*x += arrow_allocation.width;
|
2004-09-27 18:37:33 +00:00
|
|
|
else
|
|
|
|
*x -= menu_req.width;
|
2005-08-15 16:36:31 +00:00
|
|
|
|
|
|
|
if (*y + menu_req.height > monitor.y + monitor.height &&
|
2010-08-11 21:07:35 +00:00
|
|
|
*y + arrow_allocation.height - monitor.y > monitor.y + monitor.height - *y)
|
|
|
|
*y += arrow_allocation.height - menu_req.height;
|
2004-09-27 18:37:33 +00:00
|
|
|
}
|
|
|
|
|
2005-08-15 16:36:31 +00:00
|
|
|
*push_in = FALSE;
|
2004-09-27 18:37:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
popup_menu_under_arrow (GtkMenuToolButton *button,
|
|
|
|
GdkEventButton *event)
|
|
|
|
{
|
2005-08-08 18:34:43 +00:00
|
|
|
GtkMenuToolButtonPrivate *priv = button->priv;
|
2004-09-27 18:37:33 +00:00
|
|
|
|
2004-10-05 14:19:54 +00:00
|
|
|
g_signal_emit (button, signals[SHOW_MENU], 0);
|
2004-09-27 18:37:33 +00:00
|
|
|
|
|
|
|
if (!priv->menu)
|
|
|
|
return;
|
|
|
|
|
|
|
|
gtk_menu_popup (priv->menu, NULL, NULL,
|
|
|
|
(GtkMenuPositionFunc) menu_position_func,
|
|
|
|
button,
|
|
|
|
event ? event->button : 0,
|
|
|
|
event ? event->time : gtk_get_current_event_time ());
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
arrow_button_toggled_cb (GtkToggleButton *togglebutton,
|
|
|
|
GtkMenuToolButton *button)
|
|
|
|
{
|
2005-08-08 18:14:26 +00:00
|
|
|
GtkMenuToolButtonPrivate *priv = button->priv;
|
2004-09-27 18:37:33 +00:00
|
|
|
|
|
|
|
if (!priv->menu)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (gtk_toggle_button_get_active (togglebutton) &&
|
2010-03-01 06:47:38 +00:00
|
|
|
!gtk_widget_get_visible (GTK_WIDGET (priv->menu)))
|
2004-09-27 18:37:33 +00:00
|
|
|
{
|
|
|
|
/* we get here only when the menu is activated by a key
|
|
|
|
* press, so that we can select the first menu item */
|
|
|
|
popup_menu_under_arrow (button, NULL);
|
|
|
|
gtk_menu_shell_select_first (GTK_MENU_SHELL (priv->menu), FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
arrow_button_button_press_event_cb (GtkWidget *widget,
|
|
|
|
GdkEventButton *event,
|
|
|
|
GtkMenuToolButton *button)
|
|
|
|
{
|
2005-03-19 06:31:42 +00:00
|
|
|
if (event->button == 1)
|
|
|
|
{
|
|
|
|
popup_menu_under_arrow (button, event);
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE);
|
2004-09-27 18:37:33 +00:00
|
|
|
|
2005-03-19 06:31:42 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
2004-09-27 18:37:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_menu_tool_button_init (GtkMenuToolButton *button)
|
|
|
|
{
|
|
|
|
GtkWidget *box;
|
|
|
|
GtkWidget *arrow;
|
|
|
|
GtkWidget *arrow_button;
|
|
|
|
GtkWidget *real_button;
|
|
|
|
|
2010-07-02 13:30:57 +00:00
|
|
|
button->priv = G_TYPE_INSTANCE_GET_PRIVATE (button,
|
|
|
|
GTK_TYPE_MENU_TOOL_BUTTON,
|
|
|
|
GtkMenuToolButtonPrivate);
|
2004-09-27 18:37:33 +00:00
|
|
|
|
|
|
|
gtk_tool_item_set_homogeneous (GTK_TOOL_ITEM (button), FALSE);
|
|
|
|
|
2010-10-31 17:07:20 +00:00
|
|
|
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
|
2004-09-27 18:37:33 +00:00
|
|
|
|
2010-05-24 20:31:36 +00:00
|
|
|
real_button = gtk_bin_get_child (GTK_BIN (button));
|
2004-09-27 18:37:33 +00:00
|
|
|
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_toggle_button_new ();
|
|
|
|
arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE);
|
|
|
|
gtk_container_add (GTK_CONTAINER (arrow_button), arrow);
|
|
|
|
gtk_box_pack_end (GTK_BOX (box), arrow_button,
|
|
|
|
FALSE, FALSE, 0);
|
|
|
|
|
|
|
|
/* the arrow button is insentive until we set a menu */
|
|
|
|
gtk_widget_set_sensitive (arrow_button, FALSE);
|
|
|
|
|
|
|
|
gtk_widget_show_all (box);
|
|
|
|
|
|
|
|
gtk_container_add (GTK_CONTAINER (button), box);
|
|
|
|
|
|
|
|
button->priv->button = real_button;
|
|
|
|
button->priv->arrow = arrow;
|
|
|
|
button->priv->arrow_button = arrow_button;
|
|
|
|
button->priv->box = box;
|
|
|
|
|
|
|
|
g_signal_connect (arrow_button, "toggled",
|
2005-08-18 20:29:55 +00:00
|
|
|
G_CALLBACK (arrow_button_toggled_cb), button);
|
2008-08-11 09:17:49 +00:00
|
|
|
g_signal_connect (arrow_button, "button-press-event",
|
2005-08-18 20:29:55 +00:00
|
|
|
G_CALLBACK (arrow_button_button_press_event_cb), button);
|
2004-09-27 18:37:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-09-18 23:55:42 +00:00
|
|
|
gtk_menu_tool_button_destroy (GtkWidget *widget)
|
2004-09-27 18:37:33 +00:00
|
|
|
{
|
2010-09-18 23:55:42 +00:00
|
|
|
GtkMenuToolButton *button = GTK_MENU_TOOL_BUTTON (widget);
|
2004-09-27 18:37:33 +00:00
|
|
|
|
|
|
|
if (button->priv->menu)
|
2005-08-18 20:29:55 +00:00
|
|
|
{
|
|
|
|
g_signal_handlers_disconnect_by_func (button->priv->menu,
|
|
|
|
menu_deactivate_cb,
|
|
|
|
button);
|
2006-01-04 11:25:19 +00:00
|
|
|
gtk_menu_detach (button->priv->menu);
|
2005-08-18 20:29:55 +00:00
|
|
|
|
|
|
|
g_signal_handlers_disconnect_by_func (button->priv->arrow_button,
|
|
|
|
arrow_button_toggled_cb,
|
|
|
|
button);
|
|
|
|
g_signal_handlers_disconnect_by_func (button->priv->arrow_button,
|
|
|
|
arrow_button_button_press_event_cb,
|
|
|
|
button);
|
|
|
|
}
|
2008-08-07 14:12:32 +00:00
|
|
|
|
2010-09-18 23:55:42 +00:00
|
|
|
GTK_WIDGET_CLASS (gtk_menu_tool_button_parent_class)->destroy (widget);
|
2004-09-27 18:37:33 +00:00
|
|
|
}
|
|
|
|
|
2011-01-09 04:10:40 +00:00
|
|
|
static void
|
|
|
|
gtk_menu_tool_button_buildable_add_child (GtkBuildable *buildable,
|
|
|
|
GtkBuilder *builder,
|
|
|
|
GObject *child,
|
|
|
|
const gchar *type)
|
|
|
|
{
|
|
|
|
if (type && strcmp (type, "menu") == 0)
|
|
|
|
gtk_menu_tool_button_set_menu (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;
|
|
|
|
}
|
|
|
|
|
2004-09-27 18:37:33 +00:00
|
|
|
/**
|
|
|
|
* gtk_menu_tool_button_new:
|
2010-02-19 16:53:17 +00:00
|
|
|
* @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
|
2004-09-27 18:37:33 +00:00
|
|
|
*
|
|
|
|
* Creates a new #GtkMenuToolButton using @icon_widget as icon and
|
|
|
|
* @label as label.
|
|
|
|
*
|
|
|
|
* Return value: the new #GtkMenuToolButton
|
|
|
|
*
|
|
|
|
* Since: 2.6
|
|
|
|
**/
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_menu_tool_button_new_from_stock:
|
|
|
|
* @stock_id: the name of a stock item
|
|
|
|
*
|
|
|
|
* Creates a new #GtkMenuToolButton.
|
|
|
|
* The new #GtkMenuToolButton will contain an icon and label from
|
|
|
|
* the stock item indicated by @stock_id.
|
|
|
|
*
|
|
|
|
* Return value: the new #GtkMenuToolButton
|
|
|
|
*
|
|
|
|
* Since: 2.6
|
|
|
|
**/
|
|
|
|
GtkToolItem *
|
|
|
|
gtk_menu_tool_button_new_from_stock (const gchar *stock_id)
|
|
|
|
{
|
|
|
|
GtkMenuToolButton *button;
|
|
|
|
|
|
|
|
g_return_val_if_fail (stock_id != NULL, NULL);
|
|
|
|
|
|
|
|
button = g_object_new (GTK_TYPE_MENU_TOOL_BUTTON,
|
2005-03-26 05:49:15 +00:00
|
|
|
"stock-id", stock_id,
|
2004-09-27 18:37:33 +00:00
|
|
|
NULL);
|
|
|
|
|
|
|
|
return GTK_TOOL_ITEM (button);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Callback for the "deactivate" signal on the pop-up menu.
|
|
|
|
* This is used so that we unset the state of the toggle button
|
|
|
|
* when the pop-up menu disappears.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
menu_deactivate_cb (GtkMenuShell *menu_shell,
|
|
|
|
GtkMenuToolButton *button)
|
|
|
|
{
|
|
|
|
GtkMenuToolButtonPrivate *priv = button->priv;
|
|
|
|
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->arrow_button), FALSE);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2006-01-04 11:25:19 +00:00
|
|
|
static void
|
|
|
|
menu_detacher (GtkWidget *widget,
|
|
|
|
GtkMenu *menu)
|
|
|
|
{
|
|
|
|
GtkMenuToolButtonPrivate *priv = GTK_MENU_TOOL_BUTTON (widget)->priv;
|
|
|
|
|
|
|
|
g_return_if_fail (priv->menu == menu);
|
|
|
|
|
|
|
|
priv->menu = NULL;
|
|
|
|
}
|
|
|
|
|
2004-09-27 18:37:33 +00:00
|
|
|
/**
|
|
|
|
* gtk_menu_tool_button_set_menu:
|
|
|
|
* @button: a #GtkMenuToolButton
|
|
|
|
* @menu: the #GtkMenu associated with #GtkMenuToolButton
|
|
|
|
*
|
|
|
|
* Sets the #GtkMenu that is popped up when the user clicks on the arrow.
|
|
|
|
* If @menu is NULL, the arrow button becomes insensitive.
|
|
|
|
*
|
|
|
|
* Since: 2.6
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
gtk_menu_tool_button_set_menu (GtkMenuToolButton *button,
|
|
|
|
GtkWidget *menu)
|
|
|
|
{
|
|
|
|
GtkMenuToolButtonPrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_MENU_TOOL_BUTTON (button));
|
|
|
|
g_return_if_fail (GTK_IS_MENU (menu) || menu == NULL);
|
|
|
|
|
|
|
|
priv = button->priv;
|
|
|
|
|
|
|
|
if (priv->menu != GTK_MENU (menu))
|
|
|
|
{
|
2010-03-01 06:47:38 +00:00
|
|
|
if (priv->menu && gtk_widget_get_visible (GTK_WIDGET (priv->menu)))
|
2004-10-02 10:10:11 +00:00
|
|
|
gtk_menu_shell_deactivate (GTK_MENU_SHELL (priv->menu));
|
|
|
|
|
2004-09-27 18:37:33 +00:00
|
|
|
if (priv->menu)
|
2005-08-18 20:29:55 +00:00
|
|
|
{
|
|
|
|
g_signal_handlers_disconnect_by_func (priv->menu,
|
|
|
|
menu_deactivate_cb,
|
|
|
|
button);
|
2006-01-04 11:25:19 +00:00
|
|
|
gtk_menu_detach (priv->menu);
|
2005-08-18 20:29:55 +00:00
|
|
|
}
|
2004-09-27 18:37:33 +00:00
|
|
|
|
|
|
|
priv->menu = GTK_MENU (menu);
|
|
|
|
|
|
|
|
if (priv->menu)
|
|
|
|
{
|
2006-01-04 11:25:19 +00:00
|
|
|
gtk_menu_attach_to_widget (priv->menu, GTK_WIDGET (button),
|
|
|
|
menu_detacher);
|
2004-09-27 18:37:33 +00:00
|
|
|
|
|
|
|
gtk_widget_set_sensitive (priv->arrow_button, TRUE);
|
|
|
|
|
2006-01-04 11:25:19 +00:00
|
|
|
g_signal_connect (priv->menu, "deactivate",
|
2004-09-27 18:37:33 +00:00
|
|
|
G_CALLBACK (menu_deactivate_cb), button);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
gtk_widget_set_sensitive (priv->arrow_button, FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (button), "menu");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_menu_tool_button_get_menu:
|
|
|
|
* @button: a #GtkMenuToolButton
|
|
|
|
*
|
|
|
|
* Gets the #GtkMenu associated with #GtkMenuToolButton.
|
|
|
|
*
|
2010-09-21 04:18:11 +00:00
|
|
|
* Return value: (transfer none): the #GtkMenu associated
|
|
|
|
* with #GtkMenuToolButton
|
2004-09-27 18:37:33 +00:00
|
|
|
*
|
|
|
|
* Since: 2.6
|
|
|
|
**/
|
|
|
|
GtkWidget *
|
|
|
|
gtk_menu_tool_button_get_menu (GtkMenuToolButton *button)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_MENU_TOOL_BUTTON (button), NULL);
|
|
|
|
|
|
|
|
return GTK_WIDGET (button->priv->menu);
|
|
|
|
}
|
|
|
|
|
Replace non-deprecated API using old tooltips API, deprecate old tooltips
2007-07-09 Kristian Rietveld <kris@imendio.com>
Replace non-deprecated API using old tooltips API, deprecate
old tooltips API for real. (#451575).
* gtk/gtk.symbols: updated.
* gtk/gtkwidget.c (gtk_widget_real_show_help): don't call
_gtk_tooltips_toggle_keyboard_mode() anymore.
* gtk/gtkmenutoolbutton.[ch] (gtk_menu_tool_button_set_arrow_tooltip):
deprecated,
(gtk_menu_tool_button_set_arrow_tooltip_{text,markup}): replacements.
* gtk/gtktoolitem.[ch] (gtk_tool_item_real_set_tooltip): use
new API,
(gtk_tool_item_set_tooltip): deprecated,
(gtk_tool_item_set_tooltip_{text,markup): replacements.
(GtkToolItemClass:set_tooltip): deprecated.
* gtk/gtktooltips.[ch]: strip out all unused parts, made
gtk_tooltips_set_tip() call gtk_widget_set_tooltip_text(),
deprecate all of gtk_tooltips_*.
* gtk/gtktoolbar.[ch] (gtk_toolbar_get_tooltips): always return
TRUE,
(GtkToolbar:tooltips): deprecated, renamed.
* gtk/gtkaction.c (gtk_action_sync_tooltip): use new API to
set the tooltip text.
* tests/autotestfilechooser.c: #undef GTK_DISABLE_DEPRECATED for now,
will be removed GtkFileChooserDefault has been converted.
svn path=/trunk/; revision=18418
2007-07-09 19:23:18 +00:00
|
|
|
/**
|
|
|
|
* 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
|
2009-12-07 21:42:08 +00:00
|
|
|
* pops up the menu. See gtk_tool_item_set_tooltip_text() for setting a tooltip
|
Replace non-deprecated API using old tooltips API, deprecate old tooltips
2007-07-09 Kristian Rietveld <kris@imendio.com>
Replace non-deprecated API using old tooltips API, deprecate
old tooltips API for real. (#451575).
* gtk/gtk.symbols: updated.
* gtk/gtkwidget.c (gtk_widget_real_show_help): don't call
_gtk_tooltips_toggle_keyboard_mode() anymore.
* gtk/gtkmenutoolbutton.[ch] (gtk_menu_tool_button_set_arrow_tooltip):
deprecated,
(gtk_menu_tool_button_set_arrow_tooltip_{text,markup}): replacements.
* gtk/gtktoolitem.[ch] (gtk_tool_item_real_set_tooltip): use
new API,
(gtk_tool_item_set_tooltip): deprecated,
(gtk_tool_item_set_tooltip_{text,markup): replacements.
(GtkToolItemClass:set_tooltip): deprecated.
* gtk/gtktooltips.[ch]: strip out all unused parts, made
gtk_tooltips_set_tip() call gtk_widget_set_tooltip_text(),
deprecate all of gtk_tooltips_*.
* gtk/gtktoolbar.[ch] (gtk_toolbar_get_tooltips): always return
TRUE,
(GtkToolbar:tooltips): deprecated, renamed.
* gtk/gtkaction.c (gtk_action_sync_tooltip): use new API to
set the tooltip text.
* tests/autotestfilechooser.c: #undef GTK_DISABLE_DEPRECATED for now,
will be removed GtkFileChooserDefault has been converted.
svn path=/trunk/; revision=18418
2007-07-09 19:23:18 +00:00
|
|
|
* on the whole #GtkMenuToolButton.
|
|
|
|
*
|
|
|
|
* Since: 2.12
|
|
|
|
**/
|
|
|
|
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
|
2009-12-07 21:42:08 +00:00
|
|
|
* which pops up the menu. See gtk_tool_item_set_tooltip_text() for setting a
|
Replace non-deprecated API using old tooltips API, deprecate old tooltips
2007-07-09 Kristian Rietveld <kris@imendio.com>
Replace non-deprecated API using old tooltips API, deprecate
old tooltips API for real. (#451575).
* gtk/gtk.symbols: updated.
* gtk/gtkwidget.c (gtk_widget_real_show_help): don't call
_gtk_tooltips_toggle_keyboard_mode() anymore.
* gtk/gtkmenutoolbutton.[ch] (gtk_menu_tool_button_set_arrow_tooltip):
deprecated,
(gtk_menu_tool_button_set_arrow_tooltip_{text,markup}): replacements.
* gtk/gtktoolitem.[ch] (gtk_tool_item_real_set_tooltip): use
new API,
(gtk_tool_item_set_tooltip): deprecated,
(gtk_tool_item_set_tooltip_{text,markup): replacements.
(GtkToolItemClass:set_tooltip): deprecated.
* gtk/gtktooltips.[ch]: strip out all unused parts, made
gtk_tooltips_set_tip() call gtk_widget_set_tooltip_text(),
deprecate all of gtk_tooltips_*.
* gtk/gtktoolbar.[ch] (gtk_toolbar_get_tooltips): always return
TRUE,
(GtkToolbar:tooltips): deprecated, renamed.
* gtk/gtkaction.c (gtk_action_sync_tooltip): use new API to
set the tooltip text.
* tests/autotestfilechooser.c: #undef GTK_DISABLE_DEPRECATED for now,
will be removed GtkFileChooserDefault has been converted.
svn path=/trunk/; revision=18418
2007-07-09 19:23:18 +00:00
|
|
|
* tooltip on the whole #GtkMenuToolButton.
|
|
|
|
*
|
|
|
|
* Since: 2.12
|
|
|
|
**/
|
|
|
|
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);
|
|
|
|
}
|