diff options
Diffstat (limited to 'plugins/gtkui')
-rw-r--r-- | plugins/gtkui/gtkui.c | 30 | ||||
-rw-r--r-- | plugins/gtkui/gtkui_api.h | 16 | ||||
-rw-r--r-- | plugins/gtkui/widgets.c | 50 | ||||
-rw-r--r-- | plugins/gtkui/widgets.h | 2 |
4 files changed, 62 insertions, 36 deletions
diff --git a/plugins/gtkui/gtkui.c b/plugins/gtkui/gtkui.c index 12cc8ec1..19abe3e3 100644 --- a/plugins/gtkui/gtkui.c +++ b/plugins/gtkui/gtkui.c @@ -966,21 +966,21 @@ gtkui_thread (void *ctx) { gtk_init (&argc, (char ***)&argv); // register widget types - w_reg_widget ("tabbed_playlist", _("Playlist with tabs"), w_tabbed_playlist_create); - w_reg_widget ("box", NULL, w_box_create); - w_reg_widget ("vsplitter", _("Splitter (top and bottom)"), w_vsplitter_create); - w_reg_widget ("hsplitter", _("Splitter (left and right)"), w_hsplitter_create); - w_reg_widget ("placeholder", NULL, w_placeholder_create); - w_reg_widget ("tabs", _("Tabs"), w_tabs_create); - w_reg_widget ("tabstrip", _("Playlist tabs"), w_tabstrip_create); - w_reg_widget ("playlist", _("Playlist"), w_playlist_create); - w_reg_widget ("selproperties", _("Selection properties"), w_selproperties_create); - w_reg_widget ("coverart", _("Album art display"), w_coverart_create); - w_reg_widget ("scope", _("Scope"), w_scope_create); - w_reg_widget ("spectrum", _("Spectrum"), w_spectrum_create); - w_reg_widget ("hbox", _("HBox"), w_hbox_create); - w_reg_widget ("vbox", _("VBox"), w_vbox_create); - w_reg_widget ("button", _("Button"), w_button_create); + w_reg_widget (_("Playlist with tabs"), w_tabbed_playlist_create, "tabbed_playlist", NULL); + w_reg_widget (NULL, w_box_create, "box", NULL); + w_reg_widget (_("Splitter (top and bottom)"), w_vsplitter_create, "vsplitter", NULL); + w_reg_widget (_("Splitter (left and right)"), w_hsplitter_create, "hsplitter", NULL); + w_reg_widget (NULL, w_placeholder_create, "placeholder", NULL); + w_reg_widget (_("Tabs"), w_tabs_create, "tabs", NULL); + w_reg_widget (_("Playlist tabs"), w_tabstrip_create, "tabstrip", NULL); + w_reg_widget (_("Playlist"), w_playlist_create, "playlist", NULL); + w_reg_widget (_("Selection properties"), w_selproperties_create, "selproperties", NULL); + w_reg_widget (_("Album art display"), w_coverart_create, "coverart", NULL); + w_reg_widget (_("Scope"), w_scope_create, "scope", NULL); + w_reg_widget (_("Spectrum"), w_spectrum_create, "spectrum", NULL); + w_reg_widget (_("HBox"), w_hbox_create, "hbox", NULL); + w_reg_widget (_("VBox"), w_vbox_create, "vbox", NULL); + w_reg_widget (_("Button"), w_button_create, "button", NULL); mainwin = create_mainwin (); diff --git a/plugins/gtkui/gtkui_api.h b/plugins/gtkui/gtkui_api.h index a1e88afd..9f11ed9b 100644 --- a/plugins/gtkui/gtkui_api.h +++ b/plugins/gtkui/gtkui_api.h @@ -58,11 +58,14 @@ typedef struct ddb_gtkui_widget_s { // strncat (s, "100 200", sz); void (*save) (struct ddb_gtkui_widget_s *w, char *s, int sz); - // this is to read custom widget parameters, e.g. width and height + // this is to read custom widget parameters, e.g. width and height; // you will be passed a string looking like "100 200 {" // you will need to read params, and return the new pointer, normally it // should be pointing to the "{" - const char *(*load) (struct ddb_gtkui_widget_s *w, const char *s); + // + // type string is necessary for backwards compatibility, so that load + // function knows which type it's loading + const char *(*load) (struct ddb_gtkui_widget_s *w, const char *type, const char *s); // custom destructor code void (*destroy) (struct ddb_gtkui_widget_s *w); @@ -105,8 +108,13 @@ typedef struct { // returns main window ptr GtkWidget * (*get_mainwin) (void); - // register new widget type - void (*w_reg_widget) (const char *type, const char *title, ddb_gtkui_widget_t *(*create_func) (void)); + // register new widget type; + // type strings are passed at the end of argument list terminated with NULL + // for example: + // w_reg_widget("My Visualization", my_viz_create, "my_viz_ng", "my_viz", NULL); + // this call will register new type "my_viz_ng", with support for another + // "my_viz" type string + void (*w_reg_widget) (const char *title, ddb_gtkui_widget_t *(*create_func) (void), ...); // unregister existing widget type void (*w_unreg_widget) (const char *type); diff --git a/plugins/gtkui/widgets.c b/plugins/gtkui/widgets.c index 3c4f213a..6d74125c 100644 --- a/plugins/gtkui/widgets.c +++ b/plugins/gtkui/widgets.c @@ -41,6 +41,7 @@ typedef struct w_creator_s { const char *type; const char *title; // set to NULL to avoid exposing this widget type to user + int compat; // when this is set to 1 -- it's a backwards compatibility creator, and must be skipped in GUI ddb_gtkui_widget_t *(*create_func) (void); struct w_creator_s *next; } w_creator_t; @@ -243,7 +244,8 @@ w_create_from_string (const char *s, ddb_gtkui_widget_t **parent) { if (!s) { return NULL; } - ddb_gtkui_widget_t *w = w_create (t); + char *type = strdupa (t); + ddb_gtkui_widget_t *w = w_create (type); if (!w) { fprintf (stderr, "failed to create widget for type %s\n", t); return NULL; @@ -265,7 +267,7 @@ w_create_from_string (const char *s, ddb_gtkui_widget_t **parent) { // load widget params if (w->load) { - s = w->load (w, s); + s = w->load (w, type, s); if (!s) { w_destroy (w); return NULL; @@ -576,21 +578,34 @@ w_override_signals (GtkWidget *widget, gpointer user_data) { } void -w_reg_widget (const char *type, const char *title, ddb_gtkui_widget_t *(*create_func) (void)) { - w_creator_t *c; - for (c = w_creators; c; c = c->next) { - if (!strcmp (c->type, type)) { - fprintf (stderr, "gtkui w_reg_widget: widget type %s already registered\n", type); - return; +w_reg_widget (const char *title, ddb_gtkui_widget_t *(*create_func) (void), ...) { + int compat = 0; + + va_list vl; + va_start (vl, create_func); + for (;;) { + const char *type = va_arg(vl, const char *); + if (!type) { + break; + } + w_creator_t *c; + for (c = w_creators; c; c = c->next) { + if (!strcmp (c->type, type)) { + fprintf (stderr, "gtkui w_reg_widget: widget type %s already registered\n", type); + return; + } } + c = malloc (sizeof (w_creator_t)); + memset (c, 0, sizeof (w_creator_t)); + c->type = type; + c->title = title; + c->compat = compat; + c->create_func = create_func; + c->next = w_creators; + w_creators = c; + compat = 1; } - c = malloc (sizeof (w_creator_t)); - memset (c, 0, sizeof (w_creator_t)); - c->type = type; - c->title = title; - c->create_func = create_func; - c->next = w_creators; - w_creators = c; + va_end(vl); } void @@ -736,7 +751,10 @@ w_placeholder_create (void) { // common splitter funcs const char * -w_splitter_load (struct ddb_gtkui_widget_s *w, const char *s) { +w_splitter_load (struct ddb_gtkui_widget_s *w, const char *type, const char *s) { + if (strcmp (type, "vsplitter") && strcmp (type, "hsplitter")) { + return NULL; + } char t[MAX_TOKEN]; s = gettoken (s, t); if (!s) { diff --git a/plugins/gtkui/widgets.h b/plugins/gtkui/widgets.h index 38ca7f5e..d0672ff4 100644 --- a/plugins/gtkui/widgets.h +++ b/plugins/gtkui/widgets.h @@ -37,7 +37,7 @@ void w_set_design_mode (int active); void -w_reg_widget (const char *type, const char *title, ddb_gtkui_widget_t *(*create_func) (void)); +w_reg_widget (const char *title, ddb_gtkui_widget_t *(*create_func) (void), ...); void w_unreg_widget (const char *type); |