summaryrefslogtreecommitdiff
path: root/plugins/gtkui
diff options
context:
space:
mode:
authorGravatar Alexey Yakovenko <wakeroid@gmail.com>2010-04-03 21:51:58 +0200
committerGravatar Alexey Yakovenko <wakeroid@gmail.com>2010-04-03 21:51:58 +0200
commitf896a3e7d10bc3d5cf6a9eb292159b676ef66ac5 (patch)
tree63c8b260c3b85d1baa613bd36db7727b41a77746 /plugins/gtkui
parentf5a42be89f5acd1a171a671a71cdd9b3a5f8991f (diff)
handle on the fly theme/font changing in custom widgets
Diffstat (limited to 'plugins/gtkui')
-rw-r--r--plugins/gtkui/ddblistview.c13
-rw-r--r--plugins/gtkui/ddbtabstrip.c7
-rw-r--r--plugins/gtkui/drawing.h3
-rw-r--r--plugins/gtkui/gdkdrawing.c37
-rw-r--r--plugins/gtkui/plcommon.c1
5 files changed, 45 insertions, 16 deletions
diff --git a/plugins/gtkui/ddblistview.c b/plugins/gtkui/ddblistview.c
index 8a417ce6..46b3684b 100644
--- a/plugins/gtkui/ddblistview.c
+++ b/plugins/gtkui/ddblistview.c
@@ -534,6 +534,14 @@ ddb_listview_list_configure_event (GtkWidget *widget,
gpointer user_data)
{
DdbListview *ps = DDB_LISTVIEW (gtk_object_get_data (GTK_OBJECT (widget), "owner"));
+
+ draw_init_font (widget->style);
+ int height = draw_get_font_size () + 12;
+ if (height != ps->rowheight) {
+ ps->rowheight = height;
+ ddb_listview_build_groups (ps);
+ }
+
ddb_listview_list_setup_vscroll (ps);
ddb_listview_list_setup_hscroll (ps);
widget = ps->list;
@@ -2040,6 +2048,11 @@ ddb_listview_header_configure_event (GtkWidget *widget,
gpointer user_data)
{
DdbListview *ps = DDB_LISTVIEW (gtk_object_get_data (GTK_OBJECT (widget), "owner"));
+ draw_init_font (widget->style);
+ int height = draw_get_font_size () + 12;
+ if (height != widget->allocation.height) {
+ gtk_widget_set_size_request (widget, -1, height);
+ }
if (ps->backbuf_header) {
g_object_unref (ps->backbuf_header);
ps->backbuf_header = NULL;
diff --git a/plugins/gtkui/ddbtabstrip.c b/plugins/gtkui/ddbtabstrip.c
index af04abc7..de5a3231 100644
--- a/plugins/gtkui/ddbtabstrip.c
+++ b/plugins/gtkui/ddbtabstrip.c
@@ -262,7 +262,7 @@ tabstrip_render (DdbTabStrip *ts) {
int x = -ts->hscrollpos;
int w = 0;
int h = draw_get_font_size ();
- gtk_widget_set_size_request (widget, -1, h + 9 + 4);
+// gtk_widget_set_size_request (widget, -1, h + 9 + 4);
h = widget->allocation.height;
tab_overlap_size = (h-4)/2;
text_right_padding = h - 3;
@@ -475,6 +475,11 @@ gboolean
on_tabstrip_configure_event (GtkWidget *widget,
GdkEventConfigure *event)
{
+ draw_init_font (widget->style);
+ int height = draw_get_font_size () + 13;
+ if (height != widget->allocation.height) {
+ gtk_widget_set_size_request (widget, -1, height);
+ }
DdbTabStrip *ts = DDB_TABSTRIP (widget);
if (ts->backbuf) {
g_object_unref (ts->backbuf);
diff --git a/plugins/gtkui/drawing.h b/plugins/gtkui/drawing.h
index 16f2c211..40196441 100644
--- a/plugins/gtkui/drawing.h
+++ b/plugins/gtkui/drawing.h
@@ -60,6 +60,9 @@ float
draw_get_font_size (void);
void
+draw_init_font (GtkStyle *style);
+
+void
draw_text (float x, float y, int width, int align, const char *text);
void
diff --git a/plugins/gtkui/gdkdrawing.c b/plugins/gtkui/gdkdrawing.c
index 84b07d29..b8e38b83 100644
--- a/plugins/gtkui/gdkdrawing.c
+++ b/plugins/gtkui/gdkdrawing.c
@@ -43,11 +43,6 @@ draw_begin (uintptr_t canvas) {
void
draw_end (void) {
-// if (pango_ready) {
-// g_object_unref (pangolayout);
-// g_object_unref (pangoctx);
-// pango_ready = 0;
-// }
drawable = NULL;
if (gc) {
g_object_unref (gc);
@@ -96,14 +91,26 @@ draw_rect (float x, float y, float w, float h, int fill) {
gdk_draw_rectangle (drawable, gc, fill, x, y, w, h);
}
-static inline void
-draw_init_font (void) {
- if (!pango_ready) {
+static GtkStyle *font_style = NULL;
+
+void
+draw_init_font (GtkStyle *new_font_style) {
+ if (!pango_ready || (new_font_style && font_style != new_font_style)) {
+ if (pangoctx) {
+ g_object_unref (pangoctx);
+ pangoctx = NULL;
+ }
+ if (pangolayout) {
+ g_object_unref (pangolayout);
+ pangolayout = NULL;
+ }
+
+ font_style = new_font_style ? new_font_style : gtk_widget_get_default_style ();
+
pangoctx = gdk_pango_context_get ();
pangolayout = pango_layout_new (pangoctx);
pango_layout_set_ellipsize (pangolayout, PANGO_ELLIPSIZE_END);
- GtkStyle *style = gtk_widget_get_default_style ();
- PangoFontDescription *desc = style->font_desc;
+ PangoFontDescription *desc = font_style->font_desc;
pango_layout_set_font_description (pangolayout, desc);
pango_ready = 1;
}
@@ -111,16 +118,16 @@ draw_init_font (void) {
float
draw_get_font_size (void) {
+ draw_init_font (NULL);
GdkScreen *screen = gdk_screen_get_default ();
float dpi = gdk_screen_get_resolution (screen);
- GtkStyle *style = gtk_widget_get_default_style ();
- PangoFontDescription *desc = style->font_desc;
+ PangoFontDescription *desc = font_style->font_desc;
return (float)(pango_font_description_get_size (desc) / PANGO_SCALE * dpi / 72);
}
void
draw_text (float x, float y, int width, int align, const char *text) {
- draw_init_font ();
+ draw_init_font (NULL);
pango_layout_set_width (pangolayout, width*PANGO_SCALE);
pango_layout_set_alignment (pangolayout, align ? PANGO_ALIGN_RIGHT : PANGO_ALIGN_LEFT);
pango_layout_set_text (pangolayout, text, -1);
@@ -129,7 +136,7 @@ draw_text (float x, float y, int width, int align, const char *text) {
void
draw_text_with_colors (float x, float y, int width, int align, const char *text) {
- draw_init_font ();
+ draw_init_font (NULL);
pango_layout_set_width (pangolayout, width*PANGO_SCALE);
pango_layout_set_alignment (pangolayout, align ? PANGO_ALIGN_RIGHT : PANGO_ALIGN_LEFT);
pango_layout_set_text (pangolayout, text, -1);
@@ -138,7 +145,7 @@ draw_text_with_colors (float x, float y, int width, int align, const char *text)
void
draw_get_text_extents (const char *text, int len, int *w, int *h) {
- draw_init_font ();
+ draw_init_font (NULL);
pango_layout_set_width (pangolayout, 1000 * PANGO_SCALE);
pango_layout_set_alignment (pangolayout, PANGO_ALIGN_LEFT);
pango_layout_set_text (pangolayout, text, len);
diff --git a/plugins/gtkui/plcommon.c b/plugins/gtkui/plcommon.c
index 24cf6c0c..006234c8 100644
--- a/plugins/gtkui/plcommon.c
+++ b/plugins/gtkui/plcommon.c
@@ -164,6 +164,7 @@ void draw_column_data (DdbListview *listview, GdkDrawable *drawable, DdbListview
float fg[3] = {(float)color->red/0xffff, (float)color->green/0xffff, (float)color->blue/0xffff};
draw_set_fg_color (fg);
+ draw_init_font (GTK_WIDGET (listview)->style);
if (calign_right) {
draw_text (x+5, y + height/2 - draw_get_font_size ()/2 - 2, cwidth-10, 1, text);
}