From 41d97ec87ed209d58e96ef800c85d4a217bfb94f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Minisini?= Date: Wed, 1 Jan 2014 16:37:50 +0000 Subject: [PATCH] [GB.GTK] * NEW: Support for GTK+3 continues. git-svn-id: svn://localhost/gambas/trunk@6046 867c0c6c-44f3-4631-809d-bfa615b0a4ec --- gb.gtk/src/gbutton.cpp | 5 +- gb.gtk/src/gcombobox.cpp | 29 ++++++------ gb.gtk/src/gcombobox.h | 4 ++ gb.gtk/src/gcontainer.cpp | 18 ++++++- gb.gtk/src/gcontainer.h | 4 ++ gb.gtk/src/gcontrol.cpp | 94 ++++++++++++++++++++++++++++++------- gb.gtk/src/gcontrol.h | 19 ++++++++ gb.gtk/src/gdesktop.cpp | 15 +++++- gb.gtk/src/gframe.cpp | 8 ++++ gb.gtk/src/gframe.h | 4 ++ gb.gtk/src/gprogressbar.cpp | 1 + gb.gtk/src/gspinbox.cpp | 16 ++++++- gb.gtk/src/gspinbox.h | 2 + gb.gtk/src/gtabstrip.cpp | 22 +++++++-- gb.gtk/src/gtabstrip.h | 4 ++ gb.gtk/src/gtextarea.cpp | 11 ++++- gb.gtk/src/gtextarea.h | 3 ++ gb.gtk/src/gtextbox.cpp | 3 +- gb.gtk/src/gtools.cpp | 56 ++++++++++++++++++++-- gb.gtk/src/gtools.h | 5 ++ 20 files changed, 278 insertions(+), 45 deletions(-) diff --git a/gb.gtk/src/gbutton.cpp b/gb.gtk/src/gbutton.cpp index b6c366405..81c873d67 100644 --- a/gb.gtk/src/gbutton.cpp +++ b/gb.gtk/src/gbutton.cpp @@ -385,14 +385,17 @@ gButton::gButton(gContainer *par, Type typ) : gControl(par) realize(); gtk_widget_add_events(widget, GDK_POINTER_MOTION_MASK); - onClick=NULL; + onClick = NULL; if (type == Radio) g_signal_connect(G_OBJECT(widget),"clicked",G_CALLBACK(cb_click_radio),(gpointer)this); else if (type == Check) g_signal_connect(G_OBJECT(widget), "clicked", G_CALLBACK(cb_click_check), (gpointer)this); else + { g_signal_connect(G_OBJECT(widget),"clicked",G_CALLBACK(cb_click),(gpointer)this); + setBackgroundButton(); + } setText(NULL); diff --git a/gb.gtk/src/gcombobox.cpp b/gb.gtk/src/gcombobox.cpp index 945367458..855775254 100644 --- a/gb.gtk/src/gcombobox.cpp +++ b/gb.gtk/src/gcombobox.cpp @@ -155,7 +155,6 @@ void gComboBox::create(bool readOnly) { widget = gtk_combo_box_new_with_model(GTK_TREE_MODEL(tree->store)); entry = NULL; - use_base = false; cell = gtk_cell_renderer_text_new (); g_object_ref_sink(cell); @@ -177,7 +176,6 @@ void gComboBox::create(bool readOnly) #ifdef GTK3 gtk_widget_set_hexpand(entry, FALSE); #endif - use_base = true; g_signal_handler_disconnect(widget, g_signal_handler_find(widget, G_SIGNAL_MATCH_ID, g_signal_lookup("changed", G_OBJECT_TYPE(widget)), 0, 0, 0, 0)); @@ -189,7 +187,7 @@ void gComboBox::create(bool readOnly) //g_object_set(cell, "ypad", 0, (void *)NULL); gtk_cell_layout_set_cell_data_func(GTK_CELL_LAYOUT(widget), cell, (GtkCellLayoutDataFunc)combo_cell_text, (gpointer)tree, NULL); } - + if (first) { realize(false); @@ -206,11 +204,14 @@ void gComboBox::create(bool readOnly) if (entry) { initEntry(); + setBackgroundBase(); //g_signal_connect(G_OBJECT(entry), "key-press-event", G_CALLBACK(gcb_keypress), (gpointer)this); //g_signal_connect(G_OBJECT(entry), "key-release-event", G_CALLBACK(gcb_keyrelease), (gpointer)this); g_signal_connect(G_OBJECT(entry), "focus-in-event", G_CALLBACK(gcb_focus_in), (gpointer)this); g_signal_connect(G_OBJECT(entry), "focus-out-event", G_CALLBACK(gcb_focus_out), (gpointer)this); } + else + setBackgroundButton(); updateFocusHandler(); setBackground(background()); @@ -225,21 +226,11 @@ void gComboBox::create(bool readOnly) gComboBox::gComboBox(gContainer *parent) : gTextBox(parent, true) { - /*if (!_style_init) - { - gtk_rc_parse_string( - "style \"gambas-default-combo-box-style\" {\n" - " GtkComboBox::appears-as-list = 1\n" - "}\n" - "class \"GtkComboBox\" style : gtk \"gambas-default-combo-box-style\"\n" - ); - _style_init = TRUE; - }*/ - onChange = NULL; onClick = NULL; onActivate = NULL; + _no_background = TRUE; _last_key = 0; _model_dirty = false; _model_dirty_timeout = 0; @@ -276,13 +267,21 @@ void gComboBox::popup() gtk_combo_box_popup(GTK_COMBO_BOX(widget)); } +#ifdef GTK3 +void gComboBox::updateColor() +{ + gTextBox::updateColor(); + if (entry) + gt_widget_set_background(entry, background(), _bg_name, &_bg_default); +} +#else void gComboBox::setRealBackground(gColor color) { gControl::setRealBackground(color); if (entry) set_gdk_base_color(entry, color); } - +#endif void gComboBox::setRealForeground(gColor color) { diff --git a/gb.gtk/src/gcombobox.h b/gb.gtk/src/gcombobox.h index 57b1443d8..cdb91e267 100644 --- a/gb.gtk/src/gcombobox.h +++ b/gb.gtk/src/gcombobox.h @@ -60,7 +60,11 @@ public: void remove(int pos); virtual void resize(int w, int h); +#ifdef GTK3 + virtual void updateColor(); +#else virtual void setRealBackground(gColor vl); +#endif virtual void setRealForeground(gColor vl); virtual void setFocus(); diff --git a/gb.gtk/src/gcontainer.cpp b/gb.gtk/src/gcontainer.cpp index 030757643..ddd0aa449 100644 --- a/gb.gtk/src/gcontainer.cpp +++ b/gb.gtk/src/gcontainer.cpp @@ -495,9 +495,11 @@ void gContainer::insert(gControl *child, bool realize) gtk_widget_realize(child->border); gtk_widget_show_all(child->border); } - + +#ifndef GTK3 if (hasBackground() && !child->_bg_set) child->setBackground(); if (hasForeground() && !child->_fg_set) child->setForeground(); +#endif child->updateFont(); } @@ -539,6 +541,7 @@ gControl *gContainer::find(int x, int y) } +#ifndef GTK3 void gContainer::setBackground(gColor color) { int i; @@ -551,8 +554,19 @@ void gContainer::setBackground(gColor color) ch = gContainer::child(i); if (!ch->_bg_set) ch->setBackground(); - } + } } +#endif + +#ifdef GTK3 +void gContainer::updateColor() +{ + int i; + + for (i = 0; i < childCount(); i++) + gContainer::child(i)->updateColor(); +} +#endif void gContainer::setForeground(gColor color) { diff --git a/gb.gtk/src/gcontainer.h b/gb.gtk/src/gcontainer.h index 3064b24cb..a476e4e86 100644 --- a/gb.gtk/src/gcontainer.h +++ b/gb.gtk/src/gcontainer.h @@ -86,7 +86,11 @@ public: virtual void performArrange(); +#ifndef GTK3 virtual void setBackground(gColor color = COLOR_DEFAULT); +#else + virtual void updateColor(); +#endif virtual void setForeground(gColor color = COLOR_DEFAULT); virtual void updateFont(); diff --git a/gb.gtk/src/gcontrol.cpp b/gb.gtk/src/gcontrol.cpp index 9926c59f2..30e4f57c9 100644 --- a/gb.gtk/src/gcontrol.cpp +++ b/gb.gtk/src/gcontrol.cpp @@ -284,6 +284,11 @@ void gControl::initAll(gContainer *parent) hFree = NULL; _grab = false; +#ifdef GTK3 + _fg = _bg = COLOR_DEFAULT; + _fg_name = _bg_name = NULL; +#endif + controls = g_list_append(controls,this); } @@ -1609,13 +1614,16 @@ void gControl::realizeScrolledWindow(GtkWidget *wid, bool doNotRealize) { _scroll = GTK_SCROLLED_WINDOW(gtk_scrolled_window_new(NULL, NULL)); - border = GTK_WIDGET(_scroll); + border = gtk_alignment_new(0, 0, 1, 1); + gtk_widget_set_redraw_on_allocate(border, TRUE); widget = wid; - frame = 0; + frame = border; _no_auto_grab = true; //gtk_container_add(GTK_CONTAINER(border), GTK_WIDGET(_scroll)); gtk_scrolled_window_set_policy(_scroll, GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); + gtk_scrolled_window_set_shadow_type(_scroll, GTK_SHADOW_NONE); + gtk_container_add(GTK_CONTAINER(border), GTK_WIDGET(_scroll)); gtk_container_add(GTK_CONTAINER(_scroll), widget); if (!doNotRealize) @@ -1692,24 +1700,12 @@ void gControl::setFrameBorder(int border) bool gControl::hasBorder() const { - if (_scroll) - return gtk_scrolled_window_get_shadow_type(_scroll) != GTK_SHADOW_NONE; - else - return getFrameBorder() != BORDER_NONE; + return getFrameBorder() != BORDER_NONE; } void gControl::setBorder(bool vl) { - if (_scroll) - { - if (vl) - gtk_scrolled_window_set_shadow_type(_scroll, GTK_SHADOW_IN); - else - gtk_scrolled_window_set_shadow_type(_scroll, GTK_SHADOW_NONE); - } - else - setFrameBorder(vl ? BORDER_SUNKEN : BORDER_NONE); - + setFrameBorder(vl ? BORDER_SUNKEN : BORDER_NONE); _has_border = vl; } @@ -1730,6 +1726,38 @@ void gControl::setName(char *name) if (name) _name = g_strdup(name); } +#ifdef GTK3 + +gColor gControl::realBackground() +{ + if (_bg != COLOR_DEFAULT) + return _bg; + else if (pr) + return pr->realBackground(); + else + return gDesktop::bgColor(); +} + +gColor gControl::background() +{ + return _bg; +} + +void gControl::setRealBackground(gColor color) +{ +} + +void gControl::setBackground(gColor color) +{ + _bg = color; + //if (gtk_widget_get_has_window(border)) + //gt_widget_set_background(border, realBackground()); + //else + gt_widget_set_background(border, _bg, _bg_name, &_bg_default); + updateColor(); +} + +#else gColor gControl::realBackground() { @@ -1779,6 +1807,8 @@ void gControl::setBackground(gColor color) setRealBackground(color); } +#endif + gColor gControl::realForeground() { if (_fg_set) @@ -2262,3 +2292,35 @@ void gControl::setCanFocus(bool vl) gtk_widget_set_can_focus(widget, vl); } +#ifdef GTK3 +void gControl::updateColor() +{ +} + +void gControl::setBackgroundName(const char *names[]) +{ + _bg_name_list = names; + if (!names) + { + _bg_name = NULL; + use_base = FALSE; + return; + } + + if (!gt_style_lookup_color(gtk_widget_get_style_context(widget), names, &_bg_name, &_bg_default)) + return; +} + +void gControl::setBackgroundBase() +{ + static const char *bg_names[] = { "base_color", "theme_base_color", NULL }; + setBackgroundName(bg_names); + use_base = TRUE; +} + +void gControl::setBackgroundButton() +{ + const char *bg_names[] = { "button_bg_color", "theme_button_bg_color", "theme_bg_color", NULL }; + setBackgroundName(bg_names); +} +#endif \ No newline at end of file diff --git a/gb.gtk/src/gcontrol.h b/gb.gtk/src/gcontrol.h index 0ec03f21b..baac10a84 100644 --- a/gb.gtk/src/gcontrol.h +++ b/gb.gtk/src/gcontrol.h @@ -120,6 +120,16 @@ public: bool ownFont() { return _font != NULL; } virtual void updateFont(); virtual void updateSize(); +#ifdef GTK3 + virtual void updateColor(); + void setBackgroundName(const char *names[]); + void setBackgroundBase(); + void setBackgroundButton(); +#else + void setBackgroundName(const char **) {} + void setBackgroundBase() { use_base = TRUE; } + void setBackgroundButton() {} +#endif bool canFocus() const; void setCanFocus(bool vl); @@ -196,6 +206,15 @@ public: short g_typ; short _mouse; gControl *_proxy, *_proxy_for; +#ifdef GTK3 + gColor _bg, _fg; + const char *_bg_name; + const char **_bg_name_list; + GdkRGBA _bg_default; + const char *_fg_name; + const char **_fg_name_list; + GdkRGBA _fg_default; +#endif unsigned dsg : 1; unsigned expa : 1; diff --git a/gb.gtk/src/gdesktop.cpp b/gb.gtk/src/gdesktop.cpp index ad52c6e57..efab8b10f 100644 --- a/gb.gtk/src/gdesktop.cpp +++ b/gb.gtk/src/gdesktop.cpp @@ -106,9 +106,20 @@ gMainWindow* gDesktop::activeWindow() #ifdef GTK3 static gColor get_color(GType type, gColor default_color, GtkStateFlags state, bool fg, bool text) { + static const char *bg_names[] = { "bg_color", "theme_bg_color", NULL }; + static const char *fg_names[] = { "fg_color", "theme_fg_color", NULL }; + GtkStyleContext *st = gt_get_style(type); GdkRGBA rgba; + if (type == GTK_TYPE_WINDOW) + { + if (gt_style_lookup_color(st, fg ? fg_names : bg_names, NULL, &rgba)) + return default_color; + else + return gt_to_color(&rgba); + } + if (!st) return default_color; @@ -158,12 +169,12 @@ gColor gDesktop::buttonbgColor() gColor gDesktop::fgColor() { - return get_color(GTK_TYPE_LAYOUT, 0, STATE_NORMAL, true, false); + return get_color(GTK_TYPE_WINDOW, 0, STATE_NORMAL, true, false); } gColor gDesktop::bgColor() { - return get_color(GTK_TYPE_LAYOUT, 0xC0C0C0, STATE_NORMAL, false, false); + return get_color(GTK_TYPE_WINDOW, 0xC0C0C0, STATE_NORMAL, false, false); } gColor gDesktop::textfgColor() diff --git a/gb.gtk/src/gframe.cpp b/gb.gtk/src/gframe.cpp index c770fd8e3..5acb61ac3 100644 --- a/gb.gtk/src/gframe.cpp +++ b/gb.gtk/src/gframe.cpp @@ -205,8 +205,16 @@ void gFrame::updateFont() gtk_widget_modify_font(label, font()->desc()); } +#ifdef GTK3 +void gFrame::updateColor() +{ + gContainer::updateColor(); + gt_widget_set_background(fr, background()); +} +#else void gFrame::setRealForeground(gColor color) { gControl::setRealForeground(color); if (label) set_gdk_fg_color(label, color); } +#endif diff --git a/gb.gtk/src/gframe.h b/gb.gtk/src/gframe.h index 30894d382..cf41dae45 100644 --- a/gb.gtk/src/gframe.h +++ b/gb.gtk/src/gframe.h @@ -50,7 +50,11 @@ public: void setText(char* vl); virtual void updateFont(); +#ifdef GTK3 + virtual void updateColor(); +#else virtual void setRealForeground(gColor color); +#endif //"Private" GtkWidget *fr; diff --git a/gb.gtk/src/gprogressbar.cpp b/gb.gtk/src/gprogressbar.cpp index 2d14262d3..16e7c2e1a 100644 --- a/gb.gtk/src/gprogressbar.cpp +++ b/gb.gtk/src/gprogressbar.cpp @@ -27,6 +27,7 @@ gProgressBar::gProgressBar(gContainer *parent) : gControl(parent) { _label = true; + _no_background = TRUE; g_typ = Type_gProgressBar; diff --git a/gb.gtk/src/gspinbox.cpp b/gb.gtk/src/gspinbox.cpp index 5e75659a8..46f69bdc1 100644 --- a/gb.gtk/src/gspinbox.cpp +++ b/gb.gtk/src/gspinbox.cpp @@ -61,7 +61,7 @@ gSpinBox::gSpinBox(gContainer *parent) : gControl(parent) { g_typ=Type_gSpinBox; have_cursor = true; - use_base = true; + _no_background = TRUE; _min = 0; _max = 100; @@ -80,6 +80,7 @@ gSpinBox::gSpinBox(gContainer *parent) : gControl(parent) #endif realize(); + setBackgroundBase(); onChange = NULL; @@ -197,3 +198,16 @@ void gSpinBox::setBorder(bool vl) { gtk_entry_set_has_frame(GTK_ENTRY(widget), vl); } + +#ifdef GTK3 +void gSpinBox::resize(int w, int h) +{ + int mw; + + gtk_widget_get_preferred_width(widget, NULL, &mw); + if (w < mw) + w = mw; + + gControl::resize(w, h); +} +#endif \ No newline at end of file diff --git a/gb.gtk/src/gspinbox.h b/gb.gtk/src/gspinbox.h index 22f24fa02..d53648388 100644 --- a/gb.gtk/src/gspinbox.h +++ b/gb.gtk/src/gspinbox.h @@ -52,6 +52,8 @@ public: #ifndef GTK3 virtual void updateCursor(GdkCursor *cursor); +#else + virtual void resize(int w, int h); #endif //"Private" diff --git a/gb.gtk/src/gtabstrip.cpp b/gb.gtk/src/gtabstrip.cpp index 11ab06548..e2e6adaf7 100644 --- a/gb.gtk/src/gtabstrip.cpp +++ b/gb.gtk/src/gtabstrip.cpp @@ -327,8 +327,12 @@ gTabStripPage::~gTabStripPage() void gTabStripPage::updateColors() { +#ifdef GTK3 + gt_widget_set_background(widget, parent->realBackground()); +#else set_gdk_bg_color(widget, parent->realBackground()); set_gdk_fg_color(label, parent->realForeground()); +#endif } void gTabStripPage::updateFont() @@ -788,13 +792,25 @@ GtkWidget *gTabStrip::getContainer() return NULL; } -void gTabStrip::setRealBackground(gColor color) +#ifdef GTK3 +void gTabStrip::updateColor() { - gControl::setRealBackground(color); - + //fprintf(stderr, "%s: updateColors\n", name()); + gt_widget_set_background(border, realBackground()); + gt_widget_set_background(widget, realBackground()); + for (int i = 0; i < count(); i++) get(i)->updateColors(); } +#else +void gTabStrip::setRealBackground(gColor color) +{ + gControl::setRealBackground(color); + + for (int i = 0; i < count(); i++) + get(i)->updateColors(); +} +#endif void gTabStrip::setRealForeground(gColor color) { diff --git a/gb.gtk/src/gtabstrip.h b/gb.gtk/src/gtabstrip.h index 9872ad910..5a80aa29b 100644 --- a/gb.gtk/src/gtabstrip.h +++ b/gb.gtk/src/gtabstrip.h @@ -60,7 +60,11 @@ public: virtual int childCount() const; virtual gControl *child(int index) const; +#ifndef GTK3 virtual void setRealBackground(gColor color); +#else + virtual void updateColor(); +#endif virtual void setRealForeground(gColor color); virtual void updateFont(); diff --git a/gb.gtk/src/gtextarea.cpp b/gb.gtk/src/gtextarea.cpp index 8e4486c1a..8f934615a 100644 --- a/gb.gtk/src/gtextarea.cpp +++ b/gb.gtk/src/gtextarea.cpp @@ -315,7 +315,6 @@ gTextArea::gTextArea(gContainer *parent) : gControl(parent) _align_normal = false; have_cursor = true; - use_base = true; _undo_stack = NULL; _redo_stack = NULL; _not_undoable_action = 0; @@ -327,6 +326,8 @@ gTextArea::gTextArea(gContainer *parent) : gControl(parent) textview = gtk_text_view_new(); realizeScrolledWindow(textview); + setBackgroundBase(); + //g_signal_connect_after(G_OBJECT(textview), "motion-notify-event", G_CALLBACK(cb_motion_notify_event), (gpointer)this); g_signal_connect(G_OBJECT(textview), "key-press-event", G_CALLBACK(cb_keypress), (gpointer)this); @@ -854,3 +855,11 @@ void gTextArea::clear() clearUndoStack(); clearRedoStack(); } + +#ifdef GTK3 +void gTextArea::updateColor() +{ + gt_widget_set_background(textview, background(), _bg_name, &_bg_default); +} +#endif + diff --git a/gb.gtk/src/gtextarea.h b/gb.gtk/src/gtextarea.h index e47a66b49..a0431a2f3 100644 --- a/gb.gtk/src/gtextarea.h +++ b/gb.gtk/src/gtextarea.h @@ -91,6 +91,9 @@ public: //"Private" virtual void updateCursor(GdkCursor *cursor); +#ifdef GTK3 + virtual void updateColor(); +#endif //void waitForLayout(int *tw, int *th); void clearUndoStack(); void clearRedoStack(); diff --git a/gb.gtk/src/gtextbox.cpp b/gb.gtk/src/gtextbox.cpp index 1c7b7bc87..36a58af25 100644 --- a/gb.gtk/src/gtextbox.cpp +++ b/gb.gtk/src/gtextbox.cpp @@ -143,10 +143,11 @@ gTextBox::gTextBox(gContainer *parent, bool combo) : gControl(parent) g_typ=Type_gTextBox; have_cursor = true; - use_base = true; + _no_background = TRUE; entry = widget = gtk_entry_new(); realize(); + setBackgroundBase(); initEntry(); } diff --git a/gb.gtk/src/gtools.cpp b/gb.gtk/src/gtools.cpp index 84f6267f6..effdb8014 100644 --- a/gb.gtk/src/gtools.cpp +++ b/gb.gtk/src/gtools.cpp @@ -256,6 +256,7 @@ void gt_color_to_frgba(gColor color, double *r, double *g, double *b, double *a) } #ifdef GTK3 + void gt_from_color(gColor color, GdkRGBA *rgba) { gt_color_to_frgba(color, &rgba->red, &rgba->green, &rgba->blue, &rgba->alpha); @@ -265,6 +266,7 @@ gColor gt_to_color(GdkRGBA *rgba) { return gt_frgba_to_color(rgba->red, rgba->green, rgba->blue, rgba->alpha); } + #endif gColor gt_frgba_to_color(double r, double g, double b, double a) @@ -1924,12 +1926,14 @@ void gt_cairo_draw_pixbuf(cairo_t *cr, GdkPixbuf *pixbuf, float x, float y, floa // Style management +#define NUM_STYLES 12 + #ifdef GTK3 static int _style_context_loaded = 0; -static GtkStyleContext *_style_context[11]; +static GtkStyleContext *_style_context[NUM_STYLES]; #endif static int _style_loaded = 0; -static GtkStyle *_style[11]; +static GtkStyle *_style[NUM_STYLES]; static int type_to_index(GType type) { @@ -1953,6 +1957,8 @@ static int type_to_index(GType type) return 9; else if (type == GTK_TYPE_BUTTON) return 10; + else if (type == GTK_TYPE_WINDOW) + return 11; else return 0; } @@ -1964,7 +1970,7 @@ const char *gt_get_style_class(GType type) static const char *_class[] = { GTK_STYLE_CLASS_DEFAULT, GTK_STYLE_CLASS_ENTRY, GTK_STYLE_CLASS_BACKGROUND, GTK_STYLE_CLASS_TOOLTIP, GTK_STYLE_CLASS_SCROLLBAR, GTK_STYLE_CLASS_DEFAULT, GTK_STYLE_CLASS_CHECK, GTK_STYLE_CLASS_RADIO, - GTK_STYLE_CLASS_FRAME, GTK_STYLE_CLASS_BACKGROUND, GTK_STYLE_CLASS_BUTTON + GTK_STYLE_CLASS_FRAME, GTK_STYLE_CLASS_BACKGROUND, GTK_STYLE_CLASS_BUTTON, GTK_STYLE_CLASS_DEFAULT }; int index = type_to_index(type); @@ -2089,3 +2095,47 @@ void gt_draw_border(cairo_t *cr, GtkStyleContext *st, GtkStateFlags state, int b } #endif +#ifdef GTK3 + +void gt_widget_set_background(GtkWidget *widget, gColor color, const char *name, const GdkRGBA *def_color) +{ + if (color == COLOR_DEFAULT) + { + if (name) + gtk_widget_override_symbolic_color(widget, name, def_color); + else + gtk_widget_override_background_color(widget, GTK_STATE_FLAG_NORMAL, NULL); + } + else + { + GdkRGBA rgba; + gt_from_color(color, &rgba); + if (name) + gtk_widget_override_symbolic_color(widget, name, &rgba); + else + gtk_widget_override_background_color(widget, GTK_STATE_FLAG_NORMAL, &rgba); + } +} + +bool gt_style_lookup_color(GtkStyleContext *style, const char **names, const char **pname, GdkRGBA *rgba) +{ + const char **p = names; + const char *name; + + while((name = *p++)) + { + if (gtk_style_context_lookup_color(style, name, rgba)) + break; + } + + if (name) + { + if (pname) + *pname = name; + return FALSE; + } + else + return TRUE; +} + +#endif \ No newline at end of file diff --git a/gb.gtk/src/gtools.h b/gb.gtk/src/gtools.h index b60d76578..47bfd2c82 100644 --- a/gb.gtk/src/gtools.h +++ b/gb.gtk/src/gtools.h @@ -171,8 +171,13 @@ void gt_color_to_frgba(gColor color, double *r, double *g, double *b, double *a) gColor gt_frgba_to_color(double r, double g, double b, double a); #ifdef GTK3 + void gt_from_color(gColor color, GdkRGBA *rgba); gColor gt_to_color(GdkRGBA *rgba); + +void gt_widget_set_background(GtkWidget *widget, gColor color, const char *name = NULL, const GdkRGBA *def_color = NULL); +bool gt_style_lookup_color(GtkStyleContext *style, const char **names, const char **pname, GdkRGBA *rgba); + #endif // Draw a control border