-
Notifications
You must be signed in to change notification settings - Fork 179
Widget boilerplate
saivert edited this page Jun 24, 2018
·
1 revision
In your plugin's connect function call this:
gtkui_plugin->w_reg_widget ("Your widget", 0, w_yourwidget_create, "yourwidgetid", NULL);
#include <gtk/gtk.h>
#include <deadbeef/gtkui_api.h>
#include <stdint.h>
typedef struct {
ddb_gtkui_widget_t base;
GtkWidget *child;
} w_yourwidget_t;
static int
w_yourwidget_message (ddb_gtkui_widget_t *base, uint32_t id, uintptr_t ctx, uint32_t p1, uint32_t p2) {
w_yourwidget_t *w = base;
}
static void
w_yourwidget_init (ddb_gtkui_widget_t *base) {
w_yourwidget_t *w = base;
}
static void
w_yourwidget_destroy (ddb_gtkui_widget_t *base) {
w_yourwidget_t *w = base;
}
static void
w_yourwidget_initmenu (struct ddb_gtkui_widget_s *w, GtkWidget *menu) {
GtkWidget *item;
item = gtk_menu_item_new_with_mnemonic (_("Configure my widget"));
gtk_widget_show (item);
gtk_container_add (GTK_CONTAINER (menu), item);
g_signal_connect ((gpointer) item, "activate", G_CALLBACK (on_button_config), w);
}
ddb_gtkui_widget_t *
w_yourwidget_create (void) {
w_yourwidget_t *w = malloc (sizeof (w_yourwidget_t));
memset (w, 0, sizeof (w_yourwidget_t));
w->base.widget = gtk_event_box_new ();
w->base.message = w_yourwidget_message;
w->base.init = w_yourwidget_init;
w->base.destroy = w_yourwidget_destroy;
w->base.initmenu = w_yourwidget_initmenu;
gtk_widget_set_can_focus (w->base.widget, FALSE);
// Create your child widget here
w->child = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
gtk_container_add (GTK_CONTAINER (w->base.widget), w->child);
gtkui_plugin->w_override_signals (w->base.widget, w);
return (ddb_gtkui_widget_t *)w;
}