diff options
Diffstat (limited to 'src/gtkext')
-rw-r--r-- | src/gtkext/easygtk.c | 77 | ||||
-rw-r--r-- | src/gtkext/easygtk.h | 3 | ||||
-rw-r--r-- | src/gtkext/gtkdockstation.c | 65 | ||||
-rw-r--r-- | src/gtkext/gtkdockstation.h | 3 |
4 files changed, 146 insertions, 2 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; + +} diff --git a/src/gtkext/easygtk.h b/src/gtkext/easygtk.h index 02f2f18..ead9822 100644 --- a/src/gtkext/easygtk.h +++ b/src/gtkext/easygtk.h @@ -124,6 +124,9 @@ GtkWidget *qck_create_tool_separator(GObject *, const char *); /* Affiche une boîte de dialogue offrant un choix "Oui/Non". */ gint qck_show_question(GtkWindow *, const char *, const char *); +/* Détermine la position d'un menu associé à un composant. */ +void attach_popup_menu_to_widget(GtkMenu *, gint *, gint *, gboolean *, GtkWidget *); + #endif /* _EASYGTK_H */ diff --git a/src/gtkext/gtkdockstation.c b/src/gtkext/gtkdockstation.c index 35006ef..1672d5e 100644 --- a/src/gtkext/gtkdockstation.c +++ b/src/gtkext/gtkdockstation.c @@ -50,6 +50,11 @@ static gboolean gtk_dock_station_switch_panel(GtkNotebook *, gpointer *, guint, /* Révèle ou cache la zone de recherches. */ static void on_toggle_revealer(GtkToggleButton *, GtkDockStation *); +/* Demande l'apparition d'un menu pour inclure des composants. */ +static void on_click_for_menu(GtkButton *, GtkDockStation *); + +/* Demande la disparition du composant courant. */ +static void on_click_for_close(GtkButton *, GtkDockStation *); @@ -98,6 +103,22 @@ static void gtk_dock_station_class_init(GtkDockStationClass *class) g_cclosure_user_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GTK_TYPE_WIDGET); + g_signal_new("menu-requested", + GTK_TYPE_DOCK_STATION, + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET(GtkDockStationClass, menu_requested), + NULL, NULL, + g_cclosure_marshal_VOID__OBJECT, + G_TYPE_NONE, 1, GTK_TYPE_WIDGET); + + g_signal_new("close-requested", + GTK_TYPE_DOCK_STATION, + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET(GtkDockStationClass, close_requested), + NULL, NULL, + g_cclosure_marshal_VOID__OBJECT, + G_TYPE_NONE, 1, GTK_TYPE_WIDGET); + } @@ -139,13 +160,13 @@ static void gtk_dock_station_init(GtkDockStation *station) button = qck_create_button_with_named_img(G_OBJECT(station), "menu", "go-down-symbolic", GTK_ICON_SIZE_MENU, NULL, - G_CALLBACK(NULL), station); + G_CALLBACK(on_click_for_menu), station); gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE); gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); button = qck_create_button_with_named_img(G_OBJECT(station), "close", "window-close-symbolic", GTK_ICON_SIZE_MENU, NULL, - G_CALLBACK(NULL), station); + G_CALLBACK(on_click_for_close), station); gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE); gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); @@ -470,3 +491,43 @@ static void on_toggle_revealer(GtkToggleButton *button, GtkDockStation *station) gtk_dockable_toggle_revealer(dockable, widget, gtk_toggle_button_get_active(button)); } + + +/****************************************************************************** +* * +* Paramètres : button = bouton à l'origine de la procédure. * +* station = station d'accueil pour différents composants. * +* * +* Description : Demande l'apparition d'un menu pour inclure des composants. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void on_click_for_menu(GtkButton *button, GtkDockStation *station) +{ + g_signal_emit_by_name(station, "menu-requested", button); + +} + + +/****************************************************************************** +* * +* Paramètres : button = bouton à l'origine de la procédure. * +* station = station d'accueil pour différents composants. * +* * +* Description : Demande la disparition du composant courant. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void on_click_for_close(GtkButton *button, GtkDockStation *station) +{ + g_signal_emit_by_name(station, "close-requested", button); + +} diff --git a/src/gtkext/gtkdockstation.h b/src/gtkext/gtkdockstation.h index 953ceb8..82b41c6 100644 --- a/src/gtkext/gtkdockstation.h +++ b/src/gtkext/gtkdockstation.h @@ -67,6 +67,9 @@ struct _GtkDockStationClass void (* switch_widget) (GtkDockStation *, GtkWidget *); + void (* menu_requested) (GtkDockStation *, GtkWidget *); + void (* close_requested) (GtkDockStation *, GtkWidget *); + }; |