tags:

views:

37

answers:

2

I am working on a defect in my GTK code for displaying context menus. After creating a menu with a number of menu items, I use gtk_menu_popup() to display the menu. This function takes a function pointer of type GtkMenuPositionFunc which lets me position the menu. I don't really do anything here except tell GTK to keep current position but push the menu in if part of the menu is outside the monitor (using the fourth argument to the function). My problem is that when GTK pushes the menu in, the absolute position of the menu items does not change. Hence their scroll position changes resulting in scroll bars in the menu. I want the relative position of the menu items w.r.t the menu to remain fixed. Is there any way I can do that? The GTK documentation does warn about this problem, but does not say anything about how to fix it. There is the link to it for reference:

http://library.gnome.org/devel/gtk/unstable/GtkMenu.html#GtkMenuPositionFunc

EDIT: I would have liked to include some code, but the logic is too scattered for that.

A: 

You don't need to provide a positioning function if you just want the default behavior. The default behavior is to keep the current position but make sure the menu fits on the monitor, so you can just pass NULL as the positioning function.

You can also take a look at how the default positioning function is written: http://git.gnome.org/browse/gtk+/tree/gtk/gtkmenu.c, gtk_menu_position() currently at line 4288.

PS. If your logic is too scattered to post a code sample, then you should consider cleaning it up.

ptomato
Passing `NULL` is not really an option as it is used in some cases. I tried passing `NULL` for this specific case and that solved the problem. Does that mean that I cannot ask GTK to reposition a menu and also ask it to push the menu inside if it goes outside the screen? That seems improbable.
Rajorshi
I included the link to the source code so that you can copy the default positioning function and start from there. If GTK can do what you want, then so can you.
ptomato
A: 

I was not able to find any way to readjust the scroll-offset of menu items once the menu is pushed in. So, the workaround I used was to avoid having GTK push the menu in vertically. Hence, the original request was to create the menu at position (x,y) but resulted in length L of the menu going out of the screen, I reposition the menu at (x,y-L) in my position function. Similarly, if y<0 I change set it to (x,0). I still tell GTK to push in any menu that goes outside the screen to take care of menus going over the left and right margins.

Rajorshi