diff options
Diffstat (limited to 'src/gtkext/easygtk.c')
-rw-r--r-- | src/gtkext/easygtk.c | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/src/gtkext/easygtk.c b/src/gtkext/easygtk.c index 3ba6664..7db1bfc 100644 --- a/src/gtkext/easygtk.c +++ b/src/gtkext/easygtk.c @@ -1148,3 +1148,80 @@ gint qck_show_question(GtkWindow *parent, const char *title, const char *questio return result; } + + +/****************************************************************************** +* * +* Paramètres : menu = menu GTK à placer à l'écran. * +* x = abscisse absolue du coin supérieur du menu. [OUT] * +* y = ordonnée absolue du coin supérieur du menu. [OUT] * +* push = indique les relations avec les bordures. [OUT] * +* widget = composant auquel le menu doit être attaché. * +* * +* Description : Détermine la position d'un menu associé à un composant. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void attach_popup_menu_to_widget(GtkMenu *menu, gint *x, gint *y, gboolean *push, GtkWidget *widget) +{ + GtkTextDirection dir; /* Direction de l'affichage */ + GtkAllocation alloc; /* Emplacement alloué */ + GtkStyleContext *context; /* Style associé pour le rendu */ + GtkStateFlags state; /* Etat courant du composant */ + GtkBorder border; /* Bordure #1 à considérer */ + GtkBorder padding; /* Bordure #2 à considérer */ + GtkRequisition req; /* Taille requis */ + + *x = 0; + *y = 0; + + dir = gtk_widget_get_direction(widget); + + /* Emplacement du composant */ + + gtk_widget_get_allocation(widget, &alloc); + + if (!gtk_widget_get_has_window(widget)) + { + *x += alloc.x; + *y += alloc.y; + } + + gdk_window_get_root_coords(gtk_widget_get_window(widget), *x, *y, x, y); + + /* Extension supplémentaire */ + + context = gtk_widget_get_style_context(widget); + state = gtk_style_context_get_state(context); + + gtk_style_context_get_border(context, state, &border); + gtk_style_context_get_padding(context, state, &padding); + + if (dir == GTK_TEXT_DIR_RTL) + *x += border.left + padding.left; + else + *x -= (border.left + padding.left); + + *y += border.top + padding.top; + + /* Sens de lecture */ + + if (dir == GTK_TEXT_DIR_RTL) + { + gtk_widget_get_preferred_size(GTK_WIDGET(menu), NULL, &req); + + *x += alloc.width - req.width; + + } + + /* Finalisation... */ + + *y += alloc.height; + + *push = TRUE; + +} |