Ejemplo n.º 1
0
static void
popup_menu (GtkMenuButton  *menu_button,
            GdkEventButton *event)
{
  GtkMenuButtonPrivate *priv = menu_button->priv;
  GtkMenuPositionFunc func;

  if (priv->func)
    priv->func (priv->user_data);

  if (!priv->menu)
    return;

  switch (priv->arrow_type)
    {
      case GTK_ARROW_LEFT:
      case GTK_ARROW_RIGHT:
        func = (GtkMenuPositionFunc) menu_position_side_func;
        break;
      default:
        func = (GtkMenuPositionFunc) menu_position_up_down_func;
        break;
  }

  gtk_menu_popup_for_device (GTK_MENU (priv->menu),
                             event ? event->device : NULL,
                             NULL, NULL,
                             func,
                             GTK_WIDGET (menu_button),
                             NULL,
                             event ? event->button : 0,
                             event ? event->time : gtk_get_current_event_time ());
}
Ejemplo n.º 2
0
static void
popup_menu (GtkMenuButton *menu_button,
            GdkEvent      *event)
{
  GtkMenuButtonPrivate *priv = menu_button->priv;
  GdkGravity widget_anchor = GDK_GRAVITY_SOUTH_WEST;
  GdkGravity menu_anchor = GDK_GRAVITY_NORTH_WEST;

  if (priv->func)
    priv->func (priv->user_data);

  if (!priv->menu)
    return;

  switch (priv->arrow_type)
    {
    case GTK_ARROW_UP:
      g_object_set (priv->menu,
                    "anchor-hints", (GDK_ANCHOR_FLIP_Y |
                                     GDK_ANCHOR_SLIDE |
                                     GDK_ANCHOR_RESIZE),
                    NULL);

      switch (gtk_widget_get_halign (priv->menu))
        {
        case GTK_ALIGN_FILL:
        case GTK_ALIGN_START:
        case GTK_ALIGN_BASELINE:
          widget_anchor = GDK_GRAVITY_NORTH_WEST;
          menu_anchor = GDK_GRAVITY_SOUTH_WEST;
          break;

        case GTK_ALIGN_END:
          widget_anchor = GDK_GRAVITY_NORTH_EAST;
          menu_anchor = GDK_GRAVITY_SOUTH_EAST;
          break;

        case GTK_ALIGN_CENTER:
          widget_anchor = GDK_GRAVITY_NORTH;
          menu_anchor = GDK_GRAVITY_SOUTH;
          break;
        }

      break;

    case GTK_ARROW_DOWN:
      /* In the common case the menu button is showing a dropdown menu, set the
       * corresponding type hint on the toplevel, so the WM can omit the top side
       * of the shadows.
       */
      g_object_set (priv->menu,
                    "anchor-hints", (GDK_ANCHOR_FLIP_Y |
                                     GDK_ANCHOR_SLIDE |
                                     GDK_ANCHOR_RESIZE),
                    "menu-type-hint", GDK_WINDOW_TYPE_HINT_DROPDOWN_MENU,
                    NULL);

      switch (gtk_widget_get_halign (priv->menu))
        {
        case GTK_ALIGN_FILL:
        case GTK_ALIGN_START:
        case GTK_ALIGN_BASELINE:
          widget_anchor = GDK_GRAVITY_SOUTH_WEST;
          menu_anchor = GDK_GRAVITY_NORTH_WEST;
          break;

        case GTK_ALIGN_END:
          widget_anchor = GDK_GRAVITY_SOUTH_EAST;
          menu_anchor = GDK_GRAVITY_NORTH_EAST;
          break;

        case GTK_ALIGN_CENTER:
          widget_anchor = GDK_GRAVITY_SOUTH;
          menu_anchor = GDK_GRAVITY_NORTH;
          break;
        }

      break;

    case GTK_ARROW_LEFT:
      g_object_set (priv->menu,
                    "anchor-hints", (GDK_ANCHOR_FLIP_X |
                                     GDK_ANCHOR_SLIDE |
                                     GDK_ANCHOR_RESIZE),
                    NULL);

      switch (gtk_widget_get_valign (priv->menu))
        {
        case GTK_ALIGN_FILL:
        case GTK_ALIGN_START:
        case GTK_ALIGN_BASELINE:
          widget_anchor = GDK_GRAVITY_NORTH_WEST;
          menu_anchor = GDK_GRAVITY_NORTH_EAST;
          break;

        case GTK_ALIGN_END:
          widget_anchor = GDK_GRAVITY_SOUTH_WEST;
          menu_anchor = GDK_GRAVITY_SOUTH_EAST;
          break;

        case GTK_ALIGN_CENTER:
          widget_anchor = GDK_GRAVITY_WEST;
          menu_anchor = GDK_GRAVITY_EAST;
          break;
        }

      break;

    case GTK_ARROW_RIGHT:
      g_object_set (priv->menu,
                    "anchor-hints", (GDK_ANCHOR_FLIP_X |
                                     GDK_ANCHOR_SLIDE |
                                     GDK_ANCHOR_RESIZE),
                    NULL);

      switch (gtk_widget_get_valign (priv->menu))
        {
        case GTK_ALIGN_FILL:
        case GTK_ALIGN_START:
        case GTK_ALIGN_BASELINE:
          widget_anchor = GDK_GRAVITY_NORTH_EAST;
          menu_anchor = GDK_GRAVITY_NORTH_WEST;
          break;

        case GTK_ALIGN_END:
          widget_anchor = GDK_GRAVITY_SOUTH_EAST;
          menu_anchor = GDK_GRAVITY_SOUTH_WEST;
          break;

        case GTK_ALIGN_CENTER:
          widget_anchor = GDK_GRAVITY_EAST;
          menu_anchor = GDK_GRAVITY_WEST;
          break;
        }

      break;

    case GTK_ARROW_NONE:
      g_object_set (priv->menu,
                    "anchor-hints", (GDK_ANCHOR_FLIP_Y |
                                     GDK_ANCHOR_SLIDE |
                                     GDK_ANCHOR_RESIZE),
                    NULL);

      break;
    }

  gtk_menu_popup_at_widget (GTK_MENU (priv->menu),
                            GTK_WIDGET (menu_button),
                            widget_anchor,
                            menu_anchor,
                            event);
}