* Boston, MA 02111-1307, USA.
*/
-#include <config.h>
+#include "config.h"
+
#include "gtkmenutoolbutton.h"
-#include "gtkintl.h"
#include "gtktogglebutton.h"
#include "gtkarrow.h"
#include "gtkhbox.h"
#include "gtkmenu.h"
#include "gtkmain.h"
#include "gtkprivate.h"
-#include "gtkalias.h"
-
+#include "gtkintl.h"
-#define GTK_MENU_TOOL_BUTTON_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), GTK_TYPE_MENU_TOOL_BUTTON, GtkMenuToolButtonPrivate))
struct _GtkMenuToolButtonPrivate
{
GtkMenu *menu;
};
-static void gtk_menu_tool_button_init (GtkMenuToolButton *button);
-static void gtk_menu_tool_button_class_init (GtkMenuToolButtonClass *klass);
static void gtk_menu_tool_button_destroy (GtkObject *object);
static int menu_deactivate_cb (GtkMenuShell *menu_shell,
enum
{
PROP_0,
- PROP_MENU,
- LAST_PROP
+ PROP_MENU
};
static gint signals[LAST_SIGNAL];
-static GObjectClass *parent_class = NULL;
-
-GType
-gtk_menu_tool_button_get_type (void)
-{
- static GType type = 0;
-
- if (type == 0)
- {
- static const GTypeInfo info =
- {
- sizeof (GtkMenuToolButtonClass),
- (GBaseInitFunc) 0,
- (GBaseFinalizeFunc) 0,
- (GClassInitFunc) gtk_menu_tool_button_class_init,
- (GClassFinalizeFunc) 0,
- NULL,
- sizeof (GtkMenuToolButton),
- 0, /* n_preallocs */
- (GInstanceInitFunc) gtk_menu_tool_button_init
- };
-
- type = g_type_register_static (GTK_TYPE_TOOL_BUTTON,
- g_intern_static_string ("GtkMenuToolButton"),
- &info, 0);
- }
-
- return type;
-}
-
-static gboolean
-gtk_menu_tool_button_set_tooltip (GtkToolItem *tool_item,
- GtkTooltips *tooltips,
- const char *tip_text,
- const char *tip_private)
-{
- GtkMenuToolButton *button;
-
- g_return_val_if_fail (GTK_IS_MENU_TOOL_BUTTON (tool_item), FALSE);
-
- button = GTK_MENU_TOOL_BUTTON (tool_item);
- gtk_tooltips_set_tip (tooltips, button->priv->button, tip_text, tip_private);
-
- return TRUE;
-}
+G_DEFINE_TYPE (GtkMenuToolButton, gtk_menu_tool_button, GTK_TYPE_TOOL_BUTTON)
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));
gtk_arrow_set (GTK_ARROW (priv->arrow), GTK_ARROW_RIGHT, GTK_SHADOW_NONE);
}
- if (priv->button && priv->button->parent)
+ parent = gtk_widget_get_parent (priv->button);
+ if (priv->button && parent)
{
g_object_ref (priv->button);
- gtk_container_remove (GTK_CONTAINER (priv->button->parent),
+ gtk_container_remove (GTK_CONTAINER (parent),
priv->button);
gtk_container_add (GTK_CONTAINER (box), priv->button);
g_object_unref (priv->button);
}
- if (priv->arrow_button && priv->arrow_button->parent)
+ parent = gtk_widget_get_parent (priv->arrow_button);
+ if (priv->arrow_button && parent)
{
g_object_ref (priv->arrow_button);
- gtk_container_remove (GTK_CONTAINER (priv->arrow_button->parent),
+ gtk_container_remove (GTK_CONTAINER (parent),
priv->arrow_button);
gtk_box_pack_end (GTK_BOX (box), priv->arrow_button,
FALSE, FALSE, 0);
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_menu_tool_button_construct_contents (GTK_MENU_TOOL_BUTTON (toolitem));
/* chain up */
- GTK_TOOL_ITEM_CLASS (parent_class)->toolbar_reconfigured (toolitem);
+ GTK_TOOL_ITEM_CLASS (gtk_menu_tool_button_parent_class)->toolbar_reconfigured (toolitem);
}
static void
GtkMenuToolButton *button = GTK_MENU_TOOL_BUTTON (widget);
GtkMenuToolButtonPrivate *priv = button->priv;
- if (!GTK_WIDGET_IS_SENSITIVE (widget) && priv->menu)
+ if (!gtk_widget_is_sensitive (widget) && priv->menu)
{
gtk_menu_shell_deactivate (GTK_MENU_SHELL (priv->menu));
}
GtkObjectClass *gtk_object_class;
GtkWidgetClass *widget_class;
GtkToolItemClass *toolitem_class;
- GtkToolButtonClass *toolbutton_class;
-
- parent_class = g_type_class_peek_parent (klass);
object_class = (GObjectClass *)klass;
gtk_object_class = (GtkObjectClass *)klass;
widget_class = (GtkWidgetClass *)klass;
toolitem_class = (GtkToolItemClass *)klass;
- toolbutton_class = (GtkToolButtonClass *)klass;
object_class->set_property = gtk_menu_tool_button_set_property;
object_class->get_property = gtk_menu_tool_button_get_property;
gtk_object_class->destroy = gtk_menu_tool_button_destroy;
widget_class->state_changed = gtk_menu_tool_button_state_changed;
- toolitem_class->set_tooltip = gtk_menu_tool_button_set_tooltip;
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_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.
+ */
signals[SHOW_MENU] =
- g_signal_new ("show-menu",
+ g_signal_new (I_("show-menu"),
G_OBJECT_CLASS_TYPE (klass),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (GtkMenuToolButtonClass, show_menu),
GtkMenuToolButton *button)
{
GtkMenuToolButtonPrivate *priv = button->priv;
+ GtkAllocation arrow_allocation;
GtkWidget *widget = GTK_WIDGET (button);
GtkRequisition req;
GtkRequisition menu_req;
GdkRectangle monitor;
gint monitor_num;
GdkScreen *screen;
+ GdkWindow *window;
gtk_widget_size_request (GTK_WIDGET (priv->menu), &menu_req);
orientation = gtk_tool_item_get_orientation (GTK_TOOL_ITEM (button));
direction = gtk_widget_get_direction (widget);
+ window = gtk_widget_get_window (widget);
screen = gtk_widget_get_screen (GTK_WIDGET (menu));
- monitor_num = gdk_screen_get_monitor_at_window (screen, widget->window);
+ monitor_num = gdk_screen_get_monitor_at_window (screen, window);
if (monitor_num < 0)
monitor_num = 0;
gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
if (orientation == GTK_ORIENTATION_HORIZONTAL)
{
- gdk_window_get_origin (widget->window, x, y);
- *x += widget->allocation.x;
- *y += widget->allocation.y;
+ 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;
if (direction == GTK_TEXT_DIR_LTR)
- *x += MAX (widget->allocation.width - menu_req.width, 0);
- else if (menu_req.width > widget->allocation.width)
- *x -= menu_req.width - widget->allocation.width;
+ *x += MAX (allocation.width - menu_req.width, 0);
+ else if (menu_req.width > allocation.width)
+ *x -= menu_req.width - allocation.width;
- if ((*y + priv->arrow_button->allocation.height + menu_req.height) <= monitor.y + monitor.height)
- *y += priv->arrow_button->allocation.height;
+ if ((*y + arrow_allocation.height + menu_req.height) <= monitor.y + monitor.height)
+ *y += arrow_allocation.height;
else if ((*y - menu_req.height) >= monitor.y)
*y -= menu_req.height;
- else if (monitor.y + monitor.height - (*y + priv->arrow_button->allocation.height) > *y)
- *y += priv->arrow_button->allocation.height;
+ else if (monitor.y + monitor.height - (*y + arrow_allocation.height) > *y)
+ *y += arrow_allocation.height;
else
*y -= menu_req.height;
}
gdk_window_get_origin (GTK_BUTTON (priv->arrow_button)->event_window, x, y);
gtk_widget_size_request (priv->arrow_button, &req);
+ gtk_widget_get_allocation (priv->arrow_button, &arrow_allocation);
+
if (direction == GTK_TEXT_DIR_LTR)
- *x += priv->arrow_button->allocation.width;
+ *x += arrow_allocation.width;
else
*x -= menu_req.width;
if (*y + menu_req.height > monitor.y + monitor.height &&
- *y + priv->arrow_button->allocation.height - monitor.y > monitor.y + monitor.height - *y)
- *y += priv->arrow_button->allocation.height - menu_req.height;
+ *y + arrow_allocation.height - monitor.y > monitor.y + monitor.height - *y)
+ *y += arrow_allocation.height - menu_req.height;
}
*push_in = FALSE;
return;
if (gtk_toggle_button_get_active (togglebutton) &&
- !GTK_WIDGET_VISIBLE (priv->menu))
+ !gtk_widget_get_visible (GTK_WIDGET (priv->menu)))
{
/* we get here only when the menu is activated by a key
* press, so that we can select the first menu item */
GtkWidget *arrow_button;
GtkWidget *real_button;
- button->priv = GTK_MENU_TOOL_BUTTON_GET_PRIVATE (button);
+ button->priv = G_TYPE_INSTANCE_GET_PRIVATE (button,
+ GTK_TYPE_MENU_TOOL_BUTTON,
+ GtkMenuToolButtonPrivate);
gtk_tool_item_set_homogeneous (GTK_TOOL_ITEM (button), FALSE);
box = gtk_hbox_new (FALSE, 0);
- real_button = GTK_BIN (button)->child;
+ 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_signal_connect (arrow_button, "toggled",
G_CALLBACK (arrow_button_toggled_cb), button);
- g_signal_connect (arrow_button, "button_press_event",
+ g_signal_connect (arrow_button, "button-press-event",
G_CALLBACK (arrow_button_button_press_event_cb), button);
}
g_signal_handlers_disconnect_by_func (button->priv->menu,
menu_deactivate_cb,
button);
- g_object_unref (button->priv->menu);
- button->priv->menu = NULL;
+ gtk_menu_detach (button->priv->menu);
g_signal_handlers_disconnect_by_func (button->priv->arrow_button,
arrow_button_toggled_cb,
arrow_button_button_press_event_cb,
button);
}
-
- if (GTK_OBJECT_CLASS (parent_class)->destroy)
- (*GTK_OBJECT_CLASS (parent_class)->destroy) (object);
+
+ GTK_OBJECT_CLASS (gtk_menu_tool_button_parent_class)->destroy (object);
}
/**
* gtk_menu_tool_button_new:
- * @icon_widget: a widget that will be used as icon widget, or %NULL
- * @label: a string that will be used as label, or %NULL
+ * @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.
return TRUE;
}
+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;
+}
+
/**
* gtk_menu_tool_button_set_menu:
* @button: a #GtkMenuToolButton
if (priv->menu != GTK_MENU (menu))
{
- if (priv->menu && GTK_WIDGET_VISIBLE (priv->menu))
+ if (priv->menu && gtk_widget_get_visible (GTK_WIDGET (priv->menu)))
gtk_menu_shell_deactivate (GTK_MENU_SHELL (priv->menu));
if (priv->menu)
g_signal_handlers_disconnect_by_func (priv->menu,
menu_deactivate_cb,
button);
- g_object_unref (priv->menu);
+ gtk_menu_detach (priv->menu);
}
priv->menu = GTK_MENU (menu);
if (priv->menu)
{
- g_object_ref (priv->menu);
- gtk_object_sink (GTK_OBJECT (priv->menu));
+ gtk_menu_attach_to_widget (priv->menu, GTK_WIDGET (button),
+ menu_detacher);
gtk_widget_set_sensitive (priv->arrow_button, TRUE);
- g_signal_connect (button->priv->menu, "deactivate",
+ g_signal_connect (priv->menu, "deactivate",
G_CALLBACK (menu_deactivate_cb), button);
}
else
}
/**
- * gtk_menu_tool_button_set_arrow_tooltip:
+ * gtk_menu_tool_button_set_arrow_tooltip_text:
* @button: a #GtkMenuToolButton
- * @tooltips: the #GtkTooltips object to be used
- * @tip_text: text to be used as tooltip text for tool_item
- * @tip_private: text to be used as private tooltip text
+ * @text: text to be used as tooltip text for button's arrow button
*
- * Sets the #GtkTooltips object to be used for arrow button which
- * pops up the menu. See gtk_tool_item_set_tooltip() for setting
- * a tooltip on the whole #GtkMenuToolButton.
+ * 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.
*
- * Since: 2.6
+ * Since: 2.12
**/
void
-gtk_menu_tool_button_set_arrow_tooltip (GtkMenuToolButton *button,
- GtkTooltips *tooltips,
- const gchar *tip_text,
- const gchar *tip_private)
+gtk_menu_tool_button_set_arrow_tooltip_text (GtkMenuToolButton *button,
+ const gchar *text)
{
g_return_if_fail (GTK_IS_MENU_TOOL_BUTTON (button));
- gtk_tooltips_set_tip (tooltips, button->priv->arrow_button, tip_text, tip_private);
+ gtk_widget_set_tooltip_text (button->priv->arrow_button, text);
}
-#define __GTK_MENU_TOOL_BUTTON_C__
-#include "gtkaliasdef.c"
+/**
+ * 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.
+ *
+ * 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);
+}