diff options
author | 2010-02-18 20:02:57 +0100 | |
---|---|---|
committer | 2010-02-18 20:02:57 +0100 | |
commit | 989d4cfba237ae44734b59d16f4970b05764f9dd (patch) | |
tree | 1ac7bc93f8bbc3e0ac07a18f99ea507cd16d56c7 /plugins/gtkui | |
parent | 707719656e6fc7c6e45f616f7e16cac424693013 (diff) |
ported tabstrip widget to gobject
Diffstat (limited to 'plugins/gtkui')
-rw-r--r-- | plugins/gtkui/Makefile.am | 2 | ||||
-rw-r--r-- | plugins/gtkui/callbacks.c | 9 | ||||
-rw-r--r-- | plugins/gtkui/callbacks.h | 4 | ||||
-rw-r--r-- | plugins/gtkui/ddbtabstrip.c (renamed from plugins/gtkui/tabs.c) | 162 | ||||
-rw-r--r-- | plugins/gtkui/ddbtabstrip.h | 52 | ||||
-rw-r--r-- | plugins/gtkui/deadbeef.glade | 12 | ||||
-rw-r--r-- | plugins/gtkui/gtkui.c | 6 | ||||
-rw-r--r-- | plugins/gtkui/interface.c | 30 | ||||
-rw-r--r-- | plugins/gtkui/tabs.h | 26 |
9 files changed, 218 insertions, 85 deletions
diff --git a/plugins/gtkui/Makefile.am b/plugins/gtkui/Makefile.am index 6d5216aa..196eaa23 100644 --- a/plugins/gtkui/Makefile.am +++ b/plugins/gtkui/Makefile.am @@ -10,7 +10,7 @@ gtkui_la_SOURCES = gtkui.c gtkui.h\ fileman.c\ pluginconf.c\ parser.c parser.h\ - tabs.c tabs.h\ + ddbtabstrip.c ddbtabstrip.h\ trkproperties.c trkproperties.h gtkui_la_LDFLAGS = -module diff --git a/plugins/gtkui/callbacks.c b/plugins/gtkui/callbacks.c index f7cbcd39..9053b4c2 100644 --- a/plugins/gtkui/callbacks.c +++ b/plugins/gtkui/callbacks.c @@ -33,6 +33,7 @@ #include "support.h" #include "ddblistview.h" +#include "ddbtabstrip.h" #include "search.h" #include "progress.h" #include "../../session.h" @@ -1457,3 +1458,11 @@ create_ddb_listview_widget (gchar *widget_name, gchar *string1, gchar *string2, return ddb_listview_new (); } + +GtkWidget* +create_tabstrip_widget (gchar *widget_name, gchar *string1, gchar *string2, + gint int1, gint int2) +{ + return ddb_tabstrip_new (); +} + diff --git a/plugins/gtkui/callbacks.h b/plugins/gtkui/callbacks.h index 67220e06..c6065a78 100644 --- a/plugins/gtkui/callbacks.h +++ b/plugins/gtkui/callbacks.h @@ -709,3 +709,7 @@ GtkWidget* create_ddb_listview_widget (gchar *widget_name, gchar *string1, gchar *string2, gint int1, gint int2); + +GtkWidget* +create_tabstrip_widget (gchar *widget_name, gchar *string1, gchar *string2, + gint int1, gint int2); diff --git a/plugins/gtkui/tabs.c b/plugins/gtkui/ddbtabstrip.c index cf891980..82cb76c9 100644 --- a/plugins/gtkui/tabs.c +++ b/plugins/gtkui/ddbtabstrip.c @@ -16,16 +16,133 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#include "../../deadbeef.h" -#include <gtk/gtk.h> -#ifdef HAVE_CONFIG_H -#include "../../config.h" -#endif #include <string.h> +#include "ddbtabstrip.h" +#include "drawing.h" #include "gtkui.h" #include "interface.h" #include "support.h" -#include "drawing.h" + +G_DEFINE_TYPE (DdbTabStrip, ddb_tabstrip, GTK_TYPE_WIDGET); + +static void +ddb_tabstrip_send_configure (DdbTabStrip *darea) +{ + GtkWidget *widget; + GdkEvent *event = gdk_event_new (GDK_CONFIGURE); + + widget = GTK_WIDGET (darea); + + event->configure.window = g_object_ref (widget->window); + event->configure.send_event = TRUE; + event->configure.x = widget->allocation.x; + event->configure.y = widget->allocation.y; + event->configure.width = widget->allocation.width; + event->configure.height = widget->allocation.height; + + gtk_widget_event (widget, event); + gdk_event_free (event); +} + +static void +ddb_tabstrip_realize (GtkWidget *widget) { + DdbTabStrip *darea = DDB_TABSTRIP (widget); + GdkWindowAttr attributes; + gint attributes_mask; + + if (GTK_WIDGET_NO_WINDOW (widget)) + { + GTK_WIDGET_CLASS (ddb_tabstrip_parent_class)->realize (widget); + } + else + { + GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED); + + attributes.window_type = GDK_WINDOW_CHILD; + attributes.x = widget->allocation.x; + attributes.y = widget->allocation.y; + attributes.width = widget->allocation.width; + attributes.height = widget->allocation.height; + attributes.wclass = GDK_INPUT_OUTPUT; + attributes.visual = gtk_widget_get_visual (widget); + attributes.colormap = gtk_widget_get_colormap (widget); + attributes.event_mask = gtk_widget_get_events (widget); + attributes.event_mask |= GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK; + + attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP; + + widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), + &attributes, attributes_mask); + gdk_window_set_user_data (widget->window, darea); + + widget->style = gtk_style_attach (widget->style, widget->window); + gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL); + } + + ddb_tabstrip_send_configure (DDB_TABSTRIP (widget)); +} + +static void +ddb_tabstrip_size_allocate (GtkWidget *widget, + GtkAllocation *allocation) +{ + g_return_if_fail (DDB_IS_TABSTRIP (widget)); + g_return_if_fail (allocation != NULL); + + widget->allocation = *allocation; + + if (GTK_WIDGET_REALIZED (widget)) + { + if (!GTK_WIDGET_NO_WINDOW (widget)) + gdk_window_move_resize (widget->window, + allocation->x, allocation->y, + allocation->width, allocation->height); + + ddb_tabstrip_send_configure (DDB_TABSTRIP (widget)); + } +} + +gboolean +on_tabstrip_button_press_event (GtkWidget *widget, + GdkEventButton *event); + +gboolean +on_tabstrip_button_release_event (GtkWidget *widget, + GdkEventButton *event); + +gboolean +on_tabstrip_configure_event (GtkWidget *widget, + GdkEventConfigure *event); + +gboolean +on_tabstrip_expose_event (GtkWidget *widget, + GdkEventExpose *event); + +gboolean +on_tabstrip_motion_notify_event (GtkWidget *widget, + GdkEventMotion *event); + +static void +ddb_tabstrip_class_init(DdbTabStripClass *class) +{ + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class); + widget_class->realize = ddb_tabstrip_realize; + widget_class->size_allocate = ddb_tabstrip_size_allocate; + widget_class->expose_event = on_tabstrip_expose_event; + widget_class->button_press_event = on_tabstrip_button_press_event; + widget_class->button_release_event = on_tabstrip_button_release_event; + widget_class->configure_event = on_tabstrip_configure_event; + widget_class->motion_notify_event = on_tabstrip_motion_notify_event; +} + +GtkWidget * ddb_tabstrip_new() { + return g_object_new (DDB_TYPE_TABSTRIP, NULL); +} + +static void +ddb_tabstrip_init(DdbTabStrip *tabstrip) +{ +} static int margin_size = 10; static int tab_dragging = -1; @@ -33,7 +150,7 @@ static int tab_movepos; static int tab_clicked = -1; void -tabbar_draw (GtkWidget *widget) { +tabstrip_draw (GtkWidget *widget) { GdkDrawable *backbuf = widget->window; int hscrollpos = 0; int x = -hscrollpos; @@ -102,7 +219,7 @@ tabbar_draw (GtkWidget *widget) { draw_set_fg_color (fg); char tab_title[100]; deadbeef->plt_get_title (idx, tab_title, sizeof (tab_title)); - draw_text (x + margin_size + 5, h/2-draw_get_font_size()/2, w - margin_size, 0, tab_title); + draw_text (x + margin_size + 5, h/2-draw_get_font_size()/2-1, w - margin_size, 0, tab_title); } if (need_draw_moving) { x = -hscrollpos; @@ -157,9 +274,8 @@ get_tab_under_cursor (int x) { } gboolean -on_tabbar_button_press_event (GtkWidget *widget, - GdkEventButton *event, - gpointer user_data) +on_tabstrip_button_press_event (GtkWidget *widget, + GdkEventButton *event) { tab_clicked = get_tab_under_cursor (event->x); if (event->button == 1) @@ -177,9 +293,8 @@ on_tabbar_button_press_event (GtkWidget *widget, gboolean -on_tabbar_button_release_event (GtkWidget *widget, - GdkEventButton *event, - gpointer user_data) +on_tabstrip_button_release_event (GtkWidget *widget, + GdkEventButton *event) { return FALSE; @@ -187,9 +302,8 @@ on_tabbar_button_release_event (GtkWidget *widget, gboolean -on_tabbar_configure_event (GtkWidget *widget, - GdkEventConfigure *event, - gpointer user_data) +on_tabstrip_configure_event (GtkWidget *widget, + GdkEventConfigure *event) { return FALSE; @@ -197,19 +311,17 @@ on_tabbar_configure_event (GtkWidget *widget, gboolean -on_tabbar_expose_event (GtkWidget *widget, - GdkEventExpose *event, - gpointer user_data) +on_tabstrip_expose_event (GtkWidget *widget, + GdkEventExpose *event) { - tabbar_draw (widget); + tabstrip_draw (widget); return FALSE; } gboolean -on_tabbar_motion_notify_event (GtkWidget *widget, - GdkEventMotion *event, - gpointer user_data) +on_tabstrip_motion_notify_event (GtkWidget *widget, + GdkEventMotion *event) { return FALSE; } @@ -225,7 +337,7 @@ on_rename_playlist1_activate (GtkMenuItem *menuitem, const char *text = gtk_entry_get_text (GTK_ENTRY (e)); deadbeef->plt_set_title (tab_clicked, text); extern GtkWidget *mainwin; - tabbar_draw (lookup_widget (mainwin, "tabbar")); + tabstrip_draw (lookup_widget (mainwin, "tabstrip")); } gtk_widget_destroy (dlg); } diff --git a/plugins/gtkui/ddbtabstrip.h b/plugins/gtkui/ddbtabstrip.h new file mode 100644 index 00000000..c1a7cac7 --- /dev/null +++ b/plugins/gtkui/ddbtabstrip.h @@ -0,0 +1,52 @@ +/* + DeaDBeeF - ultimate music player for GNU/Linux systems with X11 + Copyright (C) 2009-2010 Alexey Yakovenko <waker@users.sourceforge.net> + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ +#ifndef __DDBTABSTRIP_H +#define __DDBTABSTRIP_H + +#include <gtk/gtk.h> + +G_BEGIN_DECLS + +#define DDB_TYPE_TABSTRIP (ddb_tabstrip_get_type ()) +#define DDB_TABSTRIP(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), DDB_TYPE_TABSTRIP, DdbTabStrip)) +#define DDB_TABSTRIP_CLASS(obj) (G_TYPE_CHECK_CLASS_CAST((obj), DDB_TYPE_TABSTRIP, DdbTabStripClass)) +#define DDB_IS_TABSTRIP(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DDB_TYPE_TABSTRIP)) +#define DDB_IS_TABSTRIP_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE ((obj), DDB_TYPE_TABSTRIP)) +#define DDB_TABSTRIP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DDB_TYPE_TABSTRIP, DdbTabStripClass)) + +typedef struct _DdbTabStrip DdbTabStrip; +typedef struct _DdbTabStripClass DdbTabStripClass; + +typedef void * DdbTabStripIter; +typedef void * DdbTabStripColIter; + +struct _DdbTabStrip { + GtkWidget parent; +}; + +struct _DdbTabStripClass { + GtkWidgetClass parent_class; +}; + +GType ddb_tabstrip_get_type(void) G_GNUC_CONST; +GtkWidget * ddb_tabstrip_new(void); + +G_END_DECLS + +#endif // __DDBTABSTRIP_H diff --git a/plugins/gtkui/deadbeef.glade b/plugins/gtkui/deadbeef.glade index f0d0fec5..352d5474 100644 --- a/plugins/gtkui/deadbeef.glade +++ b/plugins/gtkui/deadbeef.glade @@ -794,15 +794,13 @@ </child> <child> - <widget class="GtkDrawingArea" id="tabbar"> + <widget class="Custom" id="tabstrip"> <property name="height_request">24</property> <property name="visible">True</property> - <property name="events">GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK | GDK_BUTTON_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property> - <signal name="button_press_event" handler="on_tabbar_button_press_event" last_modification_time="Sun, 07 Feb 2010 19:07:32 GMT"/> - <signal name="button_release_event" handler="on_tabbar_button_release_event" last_modification_time="Sun, 07 Feb 2010 19:07:35 GMT"/> - <signal name="configure_event" handler="on_tabbar_configure_event" last_modification_time="Sun, 07 Feb 2010 19:07:41 GMT"/> - <signal name="expose_event" handler="on_tabbar_expose_event" last_modification_time="Sun, 07 Feb 2010 19:07:50 GMT"/> - <signal name="motion_notify_event" handler="on_tabbar_motion_notify_event" last_modification_time="Sun, 07 Feb 2010 19:08:05 GMT"/> + <property name="creation_function">create_tabstrip_widget</property> + <property name="int1">0</property> + <property name="int2">0</property> + <property name="last_modification_time">Thu, 18 Feb 2010 18:05:36 GMT</property> </widget> <packing> <property name="padding">0</property> diff --git a/plugins/gtkui/gtkui.c b/plugins/gtkui/gtkui.c index b34bb36e..1830a9c5 100644 --- a/plugins/gtkui/gtkui.c +++ b/plugins/gtkui/gtkui.c @@ -35,7 +35,6 @@ #include "interface.h" #include "callbacks.h" #include "support.h" -#include "tabs.h" #include "parser.h" #include "drawing.h" #include "trkproperties.h" @@ -490,11 +489,10 @@ gtkui_on_playlistchanged (DB_event_t *ev, uintptr_t data) { static gboolean playlistswitch_cb (gpointer none) { + GtkWidget *tabstrip = lookup_widget (mainwin, "tabstrip"); + gdk_window_invalidate_rect (tabstrip->window, NULL, FALSE); playlist_refresh (); search_refresh (); - tabbar_draw (lookup_widget (mainwin, "tabbar")); - //GtkWidget *widget = lookup_widget (mainwin, "tabbar"); - //gdk_window_invalidate_rect (widget->window, NULL, FALSE); return FALSE; } diff --git a/plugins/gtkui/interface.c b/plugins/gtkui/interface.c index cca1e04f..643c7c7e 100644 --- a/plugins/gtkui/interface.c +++ b/plugins/gtkui/interface.c @@ -110,7 +110,7 @@ create_mainwin (void) GtkWidget *image5; GtkWidget *seekbar; GtkWidget *volumebar; - GtkWidget *tabbar; + GtkWidget *tabstrip; GtkWidget *frame1; GtkWidget *playlist; GtkWidget *statusbar; @@ -496,11 +496,12 @@ create_mainwin (void) gtk_widget_set_size_request (volumebar, 70, -1); gtk_widget_set_events (volumebar, GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK); - tabbar = gtk_drawing_area_new (); - gtk_widget_show (tabbar); - gtk_box_pack_start (GTK_BOX (vbox1), tabbar, FALSE, TRUE, 0); - gtk_widget_set_size_request (tabbar, -1, 24); - gtk_widget_set_events (tabbar, GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK | GDK_BUTTON_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK); + tabstrip = create_tabstrip_widget ("tabstrip", "", "", 0, 0); + gtk_widget_show (tabstrip); + gtk_box_pack_start (GTK_BOX (vbox1), tabstrip, FALSE, TRUE, 0); + gtk_widget_set_size_request (tabstrip, -1, 24); + GTK_WIDGET_UNSET_FLAGS (tabstrip, GTK_CAN_FOCUS); + GTK_WIDGET_UNSET_FLAGS (tabstrip, GTK_CAN_DEFAULT); frame1 = gtk_frame_new (NULL); gtk_widget_show (frame1); @@ -670,21 +671,6 @@ create_mainwin (void) g_signal_connect ((gpointer) volumebar, "scroll_event", G_CALLBACK (on_volumebar_scroll_event), NULL); - g_signal_connect ((gpointer) tabbar, "button_press_event", - G_CALLBACK (on_tabbar_button_press_event), - NULL); - g_signal_connect ((gpointer) tabbar, "button_release_event", - G_CALLBACK (on_tabbar_button_release_event), - NULL); - g_signal_connect ((gpointer) tabbar, "configure_event", - G_CALLBACK (on_tabbar_configure_event), - NULL); - g_signal_connect ((gpointer) tabbar, "expose_event", - G_CALLBACK (on_tabbar_expose_event), - NULL); - g_signal_connect ((gpointer) tabbar, "motion_notify_event", - G_CALLBACK (on_tabbar_motion_notify_event), - NULL); /* Store pointers to all widgets, for use by lookup_widget(). */ GLADE_HOOKUP_OBJECT_NO_REF (mainwin, mainwin, "mainwin"); @@ -766,7 +752,7 @@ create_mainwin (void) GLADE_HOOKUP_OBJECT (mainwin, image5, "image5"); GLADE_HOOKUP_OBJECT (mainwin, seekbar, "seekbar"); GLADE_HOOKUP_OBJECT (mainwin, volumebar, "volumebar"); - GLADE_HOOKUP_OBJECT (mainwin, tabbar, "tabbar"); + GLADE_HOOKUP_OBJECT (mainwin, tabstrip, "tabstrip"); GLADE_HOOKUP_OBJECT (mainwin, frame1, "frame1"); GLADE_HOOKUP_OBJECT (mainwin, playlist, "playlist"); GLADE_HOOKUP_OBJECT (mainwin, statusbar, "statusbar"); diff --git a/plugins/gtkui/tabs.h b/plugins/gtkui/tabs.h deleted file mode 100644 index ede72979..00000000 --- a/plugins/gtkui/tabs.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - DeaDBeeF - ultimate music player for GNU/Linux systems with X11 - Copyright (C) 2009-2010 Alexey Yakovenko <waker@users.sourceforge.net> - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License - as published by the Free Software Foundation; either version 2 - of the License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -*/ - -#ifndef __TABS_H -#define __TABS_H - -void -tabbar_draw (GtkWidget *widget); - -#endif |