tags:

views:

58

answers:

1

I have a GtkMenu Widget and i am adding it to screen on button click,, but it gets added at mouse location but i want to add it to end edge of button widget like,

+-------+
|BUTTON |
+-------+
+------------+
|Menu Item 1 |
|Menu Item 2 |
+------------+

I am using following code to add popup menu

    // Add popup menu.
    gtk_menu_popup( GTK_MENU (widget), NULL, NULL, NULL, NULL,                    
                    bevent->button, bevent->time);

Ok added this function but popup menu gets added to end of window not at the end of button widget...

void set_position (GtkMenu *menu, gint *px, gint *py, gboolean *push_in, gpointer data)
{
    gint w, h;
    GtkBuilder *builder = GetBuilderPointer();
    GtkWidget *button = GTK_WIDGET( gtk_builder_get_object( builder, "button_presence"));

    gdk_window_get_size (button->window, &w, &h);
    gdk_window_get_origin (button->window, px, py);
    *py = h;

    printf("\n\n w[%d] h[%d] px[%d] py[%d]\n\n", w, h, *px, *py );
    *push_in = TRUE;
}


Printf gives output like follows,
w[350] h[400] px[341] py[607]

i am not able to retrieve x, y, height, width of button widget...
Note: This button is a custom widget with (GtkHBox+(GtkImage+GtkLabel)) in it.

thanks unwind for your answer.

+1  A: 

The fourth argument to gtk_menu_popup() is a pointer to a GtkMenuPositionFunc, which is a callback that you can define. You need to add such a callback, and have it return the desired position, by reading it out of the button widget's GdkWindow.

It's been a while since I did this, but you might also have to read out the parent window's position on-screen, and add the widget's position to them to get the absolute coordinates where you want the menu to pop up.

unwind
Thanks, Added this function but still have some problems... please sea updated part in question.
PP