diff options
author | Alexey Yakovenko <waker@users.sourceforge.net> | 2013-11-03 12:39:19 +0100 |
---|---|---|
committer | Alexey Yakovenko <waker@users.sourceforge.net> | 2013-11-03 12:39:19 +0100 |
commit | 7457e16d65f3595ec5eb22df58c2d667632f5f4c (patch) | |
tree | 5f4d6808ac4d21f8a4daf6b8355e488d2cbc5e0a /plugins | |
parent | 5d6556e72378fd85af8486eff0777bc320eaaa72 (diff) |
gtkui: added new API function to allow getting container widget from a composite widget
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/gtkui/gtkui_api.h | 10 | ||||
-rw-r--r-- | plugins/gtkui/widgets.c | 44 | ||||
-rw-r--r-- | plugins/gtkui/widgets.h | 5 |
3 files changed, 45 insertions, 14 deletions
diff --git a/plugins/gtkui/gtkui_api.h b/plugins/gtkui/gtkui_api.h index bb432d79..d4a05b24 100644 --- a/plugins/gtkui/gtkui_api.h +++ b/plugins/gtkui/gtkui_api.h @@ -107,6 +107,11 @@ typedef struct ddb_gtkui_widget_s { // look at the splitter and tabs implementation for more details void (*replace) (struct ddb_gtkui_widget_s *container, struct ddb_gtkui_widget_s *child, struct ddb_gtkui_widget_s *newchild); + // return the container widget of a composite widget + // e.g. HBox is contained in EventBox, this function should return the HBox + // the default implementation will always return the toplevel widget + GtkWidget * (*get_container) (struct ddb_gtkui_widget_s *w); + // implement this if you want to handle deadbeef broadcast messages/events int (*message) (struct ddb_gtkui_widget_s *w, uint32_t id, uintptr_t ctx, uint32_t p1, uint32_t p2); @@ -175,6 +180,11 @@ typedef struct { // remove the widget from its container void (*w_remove) (ddb_gtkui_widget_t *cont, ddb_gtkui_widget_t *child); + // return the container widget of a composite widget + // e.g. HBox is contained in EventBox, this function should return the HBox + // the default implementation will always return the toplevel widget + GtkWidget * (*w_get_container) (ddb_gtkui_widget_t *w); + // function to create the standard playlist context menu (the same as // appears when right-clicked on playlist tab) GtkWidget* (*create_pltmenu) (int plt_idx); diff --git a/plugins/gtkui/widgets.c b/plugins/gtkui/widgets.c index b8b529f2..2e3ff2e0 100644 --- a/plugins/gtkui/widgets.c +++ b/plugins/gtkui/widgets.c @@ -294,6 +294,14 @@ w_remove (ddb_gtkui_widget_t *cont, ddb_gtkui_widget_t *child) { child->parent = NULL; } +GtkWidget * +w_get_container (ddb_gtkui_widget_t *w) { + if (w->get_container) { + return w->get_container (w); + } + return w->widget; +} + void w_replace (ddb_gtkui_widget_t *w, ddb_gtkui_widget_t *from, ddb_gtkui_widget_t *to) { if (w->replace) { @@ -989,6 +997,17 @@ w_splitter_init_signals (w_splitter_t *w) { g_signal_connect ((gpointer) w->base.widget, "button_press_event", G_CALLBACK (w_button_press_event), w); } +GtkWidget * +w_splitter_get_container (struct ddb_gtkui_widget_s *b) { + w_splitter_t *w = (w_splitter_t *)b; + if (w->box) { + return w->box; + } + else { + return w->base.widget; + } +} + void w_splitter_lock (w_splitter_t *w) { // we can't change GtkPaned behavior, so convert to vbox for now @@ -1021,13 +1040,7 @@ w_splitter_lock (w_splitter_t *w) { ddb_gtkui_widget_t *parent = w->base.parent; GtkWidget *cont = NULL; if (parent) { - cont = parent->widget; - if (!strcmp (parent->type, "vsplitter") || !strcmp (parent->type, "hsplitter")) { - w_splitter_t *sp = (w_splitter_t *)parent; - if (sp->box) { - cont = sp->box; - } - } + cont = w_get_container (parent); gtk_container_remove (GTK_CONTAINER (cont), w->base.widget); } GtkWidget *eventbox = gtk_event_box_new (); @@ -1070,13 +1083,7 @@ w_splitter_unlock (w_splitter_t *w) { ddb_gtkui_widget_t *parent = w->base.parent; GtkWidget *cont = NULL; if (parent) { - cont = parent->widget; - if (!strcmp (parent->type, "vsplitter") || !strcmp (parent->type, "hsplitter")) { - w_splitter_t *sp = (w_splitter_t *)parent; - if (sp->box) { - cont = sp->box; - } - } + cont = w_get_container (parent); gtk_container_remove (GTK_CONTAINER (cont), w->base.widget); } w->base.widget = paned; @@ -1199,6 +1206,7 @@ w_vsplitter_create (void) { w->base.append = w_splitter_add; w->base.remove = w_splitter_remove; w->base.replace = w_splitter_replace; + w->base.get_container = w_splitter_get_container; w->base.load = w_splitter_load; w->base.save = w_splitter_save; w->base.init = w_vsplitter_init; @@ -1254,6 +1262,7 @@ w_hsplitter_create (void) { w->base.append = w_splitter_add; w->base.remove = w_splitter_remove; w->base.replace = w_splitter_replace; + w->base.get_container = w_splitter_get_container; w->base.load = w_splitter_load; w->base.save = w_splitter_save; w->base.init = w_hsplitter_init; @@ -3084,6 +3093,11 @@ w_hvbox_initchildmenu (struct ddb_gtkui_widget_s *w, GtkWidget *menu) { w); } +GtkWidget * +w_hvbox_get_container (struct ddb_gtkui_widget_s *b) { + return ((w_hvbox_t *)b)->box; +} + ddb_gtkui_widget_t * w_hbox_create (void) { w_hvbox_t *w = malloc (sizeof (w_hvbox_t)); @@ -3097,6 +3111,7 @@ w_hbox_create (void) { w->base.load = w_hvbox_load; w->base.save = w_hvbox_save; w->base.init = w_hvbox_init; + w->base.get_container = w_hvbox_get_container; w->box = gtk_hbox_new (TRUE, 3); w->homogeneous = 1; w->expand = -1; @@ -3120,6 +3135,7 @@ w_vbox_create (void) { w->base.append = w_hvbox_append; w->base.remove = w_hvbox_remove; w->base.replace = w_hvbox_replace; + w->base.get_container = w_hvbox_get_container; w->base.initmenu = w_hvbox_initmenu; w->base.initchildmenu = w_hvbox_initchildmenu; w->base.load = w_hvbox_load; diff --git a/plugins/gtkui/widgets.h b/plugins/gtkui/widgets.h index 147effbd..964fb665 100644 --- a/plugins/gtkui/widgets.h +++ b/plugins/gtkui/widgets.h @@ -69,6 +69,11 @@ w_replace (ddb_gtkui_widget_t *w, ddb_gtkui_widget_t *from, ddb_gtkui_widget_t * void w_remove (ddb_gtkui_widget_t *cont, ddb_gtkui_widget_t *child); +// returns actual container widget of a composite widget +// e.g. HBox is contained in EventBox, this function will return the HBox +GtkWidget * +w_get_container (ddb_gtkui_widget_t *w); + ddb_gtkui_widget_t * w_hsplitter_create (void); |