tags:

views:

28

answers:

1

Hello every one,

I have added GtkMenu using following code:

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

And to adjust this GtkMenu under my button i have used this function:

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;
}


but popup is getting displayed at the end of the whole window not at the end of the button...

Out put of the printf:
w[350] h[400] px[341] py[607]

what is going wrong why it is not giving x, y and height, width of button correctly?
Note: The button widget used in this, is a custom composite widget with (GtkHBox+(GtkImage+GtkLabel)) in it.

I have tried same code with normal label button but still GtkMenu is getting displayed under root window not under button.

Why this might be happening... i am relay stuck on this...

thnaks,
PP

A: 

Ok Let me answer this.... if anyone is facing the same problem he/she can refer this..

To Adjust GtkMenu under GtkButton (Custom Composite Button).. use following set position callback function...

static void
pos_func( GtkMenu   *menu,
          gint      *x,
          gint      *y,
          gboolean  *push,
          GtkWidget *widget )
{
    GtkRequisition req;

    gtk_widget_size_request( widget, &req );
    gdk_window_get_origin( gtk_widget_get_window( widget ), x, y );
    *x += widget->allocation.x;
    *y += widget->allocation.y + req.height;

    *push = TRUE;
}

This will set position of GtkMenu under GtkButton Widget!

PP