Re: Centering a sub-popup menu on an item



On Mon, Feb 19, 2007 at 12:52:44PM -0500, Mike Taht wrote:
> 
> I am thinking in my carpal fashion that centering sub-popup menus on an item 
> would be a good thing, if doable in a gtk app. 
>
> ...
> 
> But forget about the justifications for a bit, I'm trying to figure out
> how to do it. If I were to write a  ...(GtkMenuPositionFunc)...
> and pass in, say, the name of the menu item to center around in user_data,
>  how would I go about getting the effective x and y offset from the top 
> of the menu of the menu item before its realized? 

Positioning is the easy part, just take the absolute screen
coordinates of the parent item and use them, see gtkmenuitem.c
(greetings to everyone shocked by the suggestion to learn
from Gtk+ source code).

The hard part is (a) convincing GtkMenuItem to behave as if
had a submenu attached but letting you to handle it itself
(b) writing a properly behaving popup menu widget from
scratch.  Since you will probably have to copy Gtk+ code or
patch it, here's a demo Gtk+ patch:


--- gtk+-2.10.6/gtk/gtkmenuitem.c.orig	2006-06-09 17:20:53.000000000 +0200
+++ gtk+-2.10.6/gtk/gtkmenuitem.c	2007-02-19 20:23:33.000000000 +0100
@@ -1175,6 +1175,7 @@ gtk_menu_item_position_menu (GtkMenu  *m
       break;
 
     case GTK_LEFT_RIGHT:
+      ty -= (theight - widget->allocation.height)/2;
       if (GTK_IS_MENU (widget->parent))
 	parent_menu_item = GTK_MENU_ITEM (GTK_MENU (widget->parent)->parent_menu_item);
       else


Yeti


--
Whatever.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]