GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Wed Jul 30, 2014 3:00 am

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Menu - How to draw a menu in UPWARD direction.
PostPosted: Sun Nov 27, 2011 2:06 am 
Offline
Familiar Face

Joined: Wed Aug 10, 2011 3:55 pm
Posts: 6
Hi


|----------------
| Menu Item 1 |
|----------------
| Menu Item 2 |
|----------------
| Menu Item 3 |
|----------------
| Menu Btn |
|----------------------- DIALOG BOTTOM ------------


I have a simple button (touching the bottom of a dialog) and when clicked on that button,
I would like to add a popup menu that pops in the UP DIRECTION above the button as shown.

Issue is, the pop up menu displays in the DOWN direction when shown.
I tried handling this in GtkMenuPositionFun() in the gtk_menu_popup().
It works. But its getting messy there. I have to know size of each menu item to set a
starting point correctly above the button; when the Menu draws down, its bottom just
touches the button top; Also with the resolution etc. its kind of clumsy handling.

I tried "Menu bar", instead of a "Button and pop up menu". That also draws the menu down,
unless the the menu goes out of the physical screen below; then it draws up.

Requirement is, draw the menu above the button or the menu bar as shown, in the "up" direction ALWAYS!

I have found no GTK settings that can instruct the menu to draw in the UPWARD direction; be it pop up
or menu bar menus.

Can any one help?

Thank you very much!
Ganesan


Top
 Profile  
 
 Post subject: Re: Menu - How to draw a menu in UPWARD direction.
PostPosted: Sun Nov 27, 2011 10:52 am 
Offline

Joined: Sun Nov 27, 2011 8:29 am
Posts: 3
This is something I'm going to need to do in a few weeks and I'm not sure if it can be done without any tricks. One idea is to cap menu with a clipping region below the pointer to force the menu above, but i think this is more work than the manual approach.

Looking for hints:
http://git.gnome.org/browse/gtk+/tree/gtk/gtkmenu.c

gtk_menu_position() starts at line 4680

There is mention about a hint at line 4721,
Code:
* Set the type hint here to allow custom position functions
   * to set a different hint
   */
  if (!gtk_widget_get_visible (priv->toplevel))
    gtk_window_set_type_hint (GTK_WINDOW (priv->toplevel), GDK_WINDOW_TYPE_HINT_POPUP_MENU);


Around line 4744 we see:
Code:
gboolean rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);


So, it is possible to change RTL and LTR packing, probably using gtk_widget_set_direction(), but that's still no good for us.


Line 4763:
Code:
* Positioning in the vertical direction is similar: first try below
       * mouse cursor, then above.


Line 4828 is the vertical code:
Code:
/* Position vertically.
       * The algorithm is the same as above, but simpler
       * because we don't have to take RTL into account.
       */
      needed_height = requisition.height - padding.top;

      if (needed_height <= space_above ||
          needed_height <= space_below)
        {
          if (needed_height <= space_below)
            y = y - padding.top;
          else
            y = y + padding.bottom - requisition.height + 1;

          y = CLAMP (y, monitor.y,
                     monitor.y + monitor.height - requisition.height);
        }
      else if (needed_height > space_below && needed_height > space_above)
        {
          if (space_below >= space_above)
            y = monitor.y + monitor.height - requisition.height;
          else
            y = monitor.y;
        }
      else
        {
          y = monitor.y;
        }


If we are lucky there is a function that will clamp space_below to 0
if we are not lucky...

Hopefully a solution shows up.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google Adsense [Bot] and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group