[GB.GTK3]

* BUG: Background and Foreground colors should work as expected now.
* BUG: SpinBox: Minimum width is a bit larger now.


git-svn-id: svn://localhost/gambas/trunk@7821 867c0c6c-44f3-4631-809d-bfa615b0a4ec
This commit is contained in:
Benoît Minisini 2016-07-16 18:03:47 +00:00
parent 8647a12953
commit f5c1dd7b00
9 changed files with 91 additions and 24 deletions

View file

@ -283,15 +283,11 @@ void gComboBox::popup()
}
#ifdef GTK3
void gComboBox::updateColor()
GtkWidget *gComboBox::getStyleSheetWidget()
{
gTextBox::updateColor();
if (entry)
{
gt_widget_set_color(entry, FALSE, background(), _bg_name, &_bg_default);
gt_widget_set_color(entry, TRUE, foreground(), _fg_name, &_fg_default);
}
return entry ? entry : border;
}
#else
void gComboBox::setRealBackground(gColor color)
{

View file

@ -61,7 +61,7 @@ public:
virtual void resize(int w, int h);
#ifdef GTK3
virtual void updateColor();
virtual GtkWidget *getStyleSheetWidget();
#else
virtual void setRealBackground(gColor vl);
#endif

View file

@ -329,6 +329,7 @@ void gControl::initAll(gContainer *parent)
_fg = _bg = COLOR_DEFAULT;
#ifdef GTK3
_css = NULL;
_fg_name = _bg_name = NULL;
#endif
@ -374,6 +375,11 @@ gControl::~gControl()
gFont::assign(&_resolved_font);
}
#ifdef GTK3
if (_css)
g_object_unref(_css);
#endif
//fprintf(stderr, "~gControl: %s\n", name());
setName(NULL);
@ -1828,6 +1834,70 @@ void gControl::setName(char *name)
#ifdef GTK3
GtkWidget *gControl::getStyleSheetWidget()
{
return border;
}
void gControl::updateStyleSheet()
{
static int count = 0;
GtkWidget *wid;
GtkStyleContext *context;
char *css = NULL;
const char *name;
char buffer[128];
wid = getStyleSheetWidget();
context = gtk_widget_get_style_context(wid);
if (_bg == COLOR_DEFAULT && _fg == COLOR_DEFAULT)
{
if (_css)
gtk_style_context_remove_provider(context, _css);
}
else
{
if (!_css)
{
count++;
sprintf(buffer, "g%d", count);
gtk_widget_set_name(wid, buffer);
_css = GTK_STYLE_PROVIDER(gtk_css_provider_new());
}
else
gtk_style_context_remove_provider(context, _css);
name = gtk_widget_get_name(wid);
sprintf(buffer, "#%s:not(:selected) {\n", name);
g_stradd(&css, buffer);
if (_bg != COLOR_DEFAULT)
{
sprintf(buffer, "#%06X;\n", _bg);
g_stradd(&css, "background-color:");
g_stradd(&css, buffer);
g_stradd(&css, "background-image:none;\n");
}
if (_fg != COLOR_DEFAULT)
{
sprintf(buffer, "#%06X;\n", _fg);
g_stradd(&css, "color:");
g_stradd(&css, buffer);
}
g_stradd(&css, "}\n");
fprintf(stderr, "---- %s\n%s", _name, css);
gtk_css_provider_load_from_data(GTK_CSS_PROVIDER(_css), css, -1, NULL);
gtk_style_context_add_provider(context, _css, GTK_STYLE_PROVIDER_PRIORITY_USER);
}
}
gColor gControl::realBackground(bool no_default)
{
if (_bg != COLOR_DEFAULT)
@ -1850,7 +1920,8 @@ void gControl::setRealBackground(gColor color)
void gControl::setBackground(gColor color)
{
_bg = color;
gt_widget_set_color(border, FALSE, _bg, _bg_name, &_bg_default);
updateStyleSheet();
//gt_widget_set_color(border, FALSE, _bg, _bg_name, &_bg_default);
updateColor();
}
@ -1876,7 +1947,8 @@ void gControl::setRealForeground(gColor color)
void gControl::setForeground(gColor color)
{
_fg = color;
gt_widget_set_color(border, TRUE, _fg, _fg_name, &_fg_default);
updateStyleSheet();
//gt_widget_set_color(border, TRUE, _fg, _fg_name, &_fg_default);
updateColor();
}

View file

@ -121,6 +121,8 @@ public:
virtual void updateFont();
virtual void updateSize();
#ifdef GTK3
virtual GtkWidget *getStyleSheetWidget();
void updateStyleSheet();
virtual void updateColor();
void setColorNames(const char *bg_names[], const char *fg_names[]);
void setColorBase();
@ -214,6 +216,7 @@ public:
gControl *_proxy, *_proxy_for;
gColor _bg, _fg;
#ifdef GTK3
GtkStyleProvider *_css;
const char *_bg_name;
const char **_bg_name_list;
GdkRGBA _bg_default;

View file

@ -221,10 +221,9 @@ void gFrame::updateFont()
}
#ifdef GTK3
void gFrame::updateColor()
GtkWidget *gFrame::getStyleSheetWidget()
{
gContainer::updateColor();
gt_widget_set_color(fr, FALSE, background());
return fr;
}
#else
void gFrame::setRealForeground(gColor color)

View file

@ -58,7 +58,7 @@ public:
virtual void updateFont();
#ifdef GTK3
virtual void updateColor();
virtual GtkWidget *getStyleSheetWidget();
#else
virtual void setRealForeground(gColor color);
#endif

View file

@ -189,6 +189,6 @@ void gSpinBox::resize(int w, int h)
int gSpinBox::minimumWidth() const
{
return _first_width + gDesktop::scale() * 6;
return _first_width + gDesktop::scale() * 7;
}
#endif

View file

@ -1007,14 +1007,6 @@ void gTextArea::clear()
end();
}
#ifdef GTK3
void gTextArea::updateColor()
{
gt_widget_set_color(textview, FALSE, background(), _bg_name, &_bg_default);
gt_widget_set_color(textview, TRUE, foreground(), _fg_name, &_fg_default);
}
#endif
GtkIMContext *gTextArea::getInputMethod()
{
#ifdef GTK3
@ -1025,6 +1017,11 @@ GtkIMContext *gTextArea::getInputMethod()
}
#ifdef GTK3
GtkWidget *gTextArea::getStyleSheetWidget()
{
return textview;
}
int gTextArea::minimumWidth() const
{
return gDesktop::scale() * 4;

View file

@ -92,7 +92,7 @@ public:
//"Private"
virtual void updateCursor(GdkCursor *cursor);
#ifdef GTK3
virtual void updateColor();
virtual GtkWidget *getStyleSheetWidget();
virtual int minimumWidth() const;
virtual int minimumHeight() const;
#endif