-static void
-button_state_changed_cb (GtkWidget *widget,
- GtkStateType previous_state,
- GtkMenuToolButton *button)
-{
- GtkMenuToolButtonPrivate *priv;
- GtkWidget *other;
- GtkStateType state = GTK_WIDGET_STATE (widget);
-
- if (state == GTK_STATE_INSENSITIVE)
- return;
-
- priv = GTK_MENU_TOOL_BUTTON_GET_PRIVATE (button);
-
- other = (widget == priv->arrow_button) ? priv->button : priv->arrow_button;
-
- g_signal_handlers_block_by_func (other,
- G_CALLBACK (button_state_changed_cb),
- button);
-
- if (state == GTK_STATE_PRELIGHT)
- {
- gtk_widget_set_state (other, state);
- }
- else if (state == GTK_STATE_NORMAL)
- {
- gtk_widget_set_state (other, state);
- }
- else if (state == GTK_STATE_ACTIVE ||
- (state == GTK_STATE_INSENSITIVE && other == priv->arrow_button))
- {
- gtk_widget_set_state (other, GTK_STATE_NORMAL);
- }
-
- if (state == GTK_STATE_INSENSITIVE && other == priv->arrow_button && button->priv->menu)
- {
- gtk_menu_shell_deactivate (GTK_MENU_SHELL (button->priv->menu));
- }
-
- g_signal_handlers_unblock_by_func (other,
- G_CALLBACK (button_state_changed_cb),
- button);
-}
-
-static void
-menu_position_func (GtkMenu *menu,
- int *x,
- int *y,
- gboolean *push_in,
- GtkMenuToolButton *button)
-{
- GtkMenuToolButtonPrivate *priv;
- GtkRequisition req;
- GtkRequisition menu_req;
- GtkOrientation orientation;
- GtkTextDirection direction;
-
- priv = GTK_MENU_TOOL_BUTTON_GET_PRIVATE (button);
-
- gdk_window_get_origin (GTK_BUTTON (priv->arrow_button)->event_window, x, y);
- gtk_widget_size_request (priv->arrow_button, &req);
- 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 (GTK_WIDGET (priv->arrow_button));
-
- if (orientation == GTK_ORIENTATION_HORIZONTAL)
- {
- if (direction == GTK_TEXT_DIR_LTR)
- *x += priv->arrow_button->allocation.width - req.width;
- else
- *x += req.width - menu_req.width;
- *y += priv->arrow_button->allocation.height;
- }
- else
- {
- if (direction == GTK_TEXT_DIR_LTR)
- *x += priv->arrow_button->allocation.width;
- else
- *x -= menu_req.width;
- *y += priv->arrow_button->allocation.height - req.height;
- }
-
- *push_in = TRUE;
-}
-
-static void
-popup_menu_under_arrow (GtkMenuToolButton *button,
- GdkEventButton *event)
-{
- GtkMenuToolButtonPrivate *priv;
-
- priv = GTK_MENU_TOOL_BUTTON_GET_PRIVATE (button);
-
- g_signal_emit (button, signals[SHOW_MENU], 0);
-
- 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)
-{
- GtkMenuToolButtonPrivate *priv;
-
- priv = GTK_MENU_TOOL_BUTTON_GET_PRIVATE (button);
-
- if (!priv->menu)
- return;
-
- if (gtk_toggle_button_get_active (togglebutton) &&
- !GTK_WIDGET_VISIBLE (priv->menu))
- {
- /* 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)
-{
- if (event->button == 1)
- {
- popup_menu_under_arrow (button, event);
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE);
-
- return TRUE;
- }
- else
- {
- return FALSE;
- }
-}
-