Style.BackgroundOf() method is now reliable.
[GB.GTK] * BUG: Style.BackgroundOf() method is now reliable. [GB.GTK3] * BUG: Style.BackgroundOf() method is now reliable. [GB.QT4] * BUG: Style.BackgroundOf() method is now reliable. [GB.QT5] * BUG: Style.BackgroundOf() method is now reliable.
This commit is contained in:
parent
cd6fb03bf7
commit
dedf7e17fe
@ -748,3 +748,11 @@ bool gButton::setInverted(bool v)
|
||||
gt_widget_set_inverted(_label, false);
|
||||
return false;
|
||||
}
|
||||
|
||||
gColor gButton::defaultBackground() const
|
||||
{
|
||||
if (type == Check || type == Radio)
|
||||
return gControl::defaultBackground();
|
||||
else
|
||||
return gDesktop::getColor(gDesktop::BUTTON_BACKGROUND, !isEnabled());
|
||||
}
|
||||
|
@ -67,6 +67,8 @@ public:
|
||||
virtual bool setInverted(bool v);
|
||||
|
||||
virtual void setRealForeground(gColor color);
|
||||
gColor defaultBackground() const;
|
||||
|
||||
//virtual void setRealBackground(gColor color);
|
||||
|
||||
//"Method"
|
||||
|
@ -2128,6 +2128,11 @@ void gControl::setName(char *name)
|
||||
if (name) _name = g_strdup(name);
|
||||
}
|
||||
|
||||
gColor gControl::defaultBackground() const
|
||||
{
|
||||
return gDesktop::getColor(gDesktop::BACKGROUND, !isEnabled());
|
||||
}
|
||||
|
||||
#ifdef GTK3
|
||||
|
||||
GtkWidget *gControl::getStyleSheetWidget()
|
||||
@ -2196,7 +2201,6 @@ void gControl::updateStyleSheet(bool dirty)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!isReallyVisible() || !_style_dirty)
|
||||
return;
|
||||
|
||||
@ -2238,10 +2242,8 @@ gColor gControl::realBackground(bool no_default)
|
||||
{
|
||||
if (_bg != COLOR_DEFAULT)
|
||||
return _bg;
|
||||
else if (pr)
|
||||
return pr->realBackground(no_default);
|
||||
else
|
||||
return no_default ? gDesktop::getColor(gDesktop::BACKGROUND) : COLOR_DEFAULT;
|
||||
return no_default ? defaultBackground() : COLOR_DEFAULT;
|
||||
}
|
||||
|
||||
void gControl::setRealBackground(gColor color)
|
||||
@ -2294,10 +2296,8 @@ gColor gControl::realBackground(bool no_default)
|
||||
{
|
||||
if (_bg_set)
|
||||
return use_base ? get_gdk_base_color(widget, isEnabled()) : get_gdk_bg_color(widget, isEnabled());
|
||||
else if (pr)
|
||||
return pr->realBackground(no_default);
|
||||
else
|
||||
return no_default ? gDesktop::getColor(gDesktop::BACKGROUND) : COLOR_DEFAULT;
|
||||
return no_default ? defaultBackground() : COLOR_DEFAULT;
|
||||
}
|
||||
|
||||
static void set_background(GtkWidget *widget, gColor color, bool use_base)
|
||||
|
@ -139,6 +139,7 @@ public:
|
||||
gColor foreground() const { return _fg; }
|
||||
virtual void setBackground(gColor color = COLOR_DEFAULT);
|
||||
virtual void setForeground(gColor color = COLOR_DEFAULT);
|
||||
virtual gColor defaultBackground() const;
|
||||
gColor realBackground(bool no_default = false);
|
||||
gColor realForeground(bool no_default = false);
|
||||
virtual void setRealBackground(gColor color);
|
||||
|
@ -40,6 +40,7 @@ Desktop
|
||||
|
||||
bool gDesktop::_colors_valid = false;
|
||||
gColor gDesktop::_colors[NUM_COLORS];
|
||||
gColor gDesktop::_colors_disabled[NUM_COLORS];
|
||||
gFont *gDesktop::_desktop_font = NULL;
|
||||
int gDesktop::_desktop_scale = 0;
|
||||
#ifdef GTK3
|
||||
@ -204,10 +205,13 @@ void gDesktop::onThemeChange()
|
||||
|
||||
#ifdef GTK3
|
||||
|
||||
static gColor get_color(GType type, bool fg, GtkStateFlags state)
|
||||
static gColor get_color(GType type, bool fg, GtkStateFlags state, bool disabled)
|
||||
{
|
||||
GtkStyleContext *style = gt_get_style(type, state == STATE_SELECTED ? "selection" : NULL, (type == GTK_TYPE_TOOLTIP && !fg) ? GTK_STYLE_CLASS_BACKGROUND : NULL);
|
||||
|
||||
if (disabled)
|
||||
state = (GtkStateFlags)(state | STATE_INSENSITIVE);
|
||||
|
||||
gtk_style_context_set_state(style, state);
|
||||
|
||||
if (!fg)
|
||||
@ -237,11 +241,14 @@ static gColor get_color(GType type, bool fg, GtkStateFlags state)
|
||||
|
||||
#else
|
||||
|
||||
static gColor get_color(GType type, bool fg, GtkStateType state)
|
||||
static gColor get_color(GType type, bool fg, GtkStateType state, bool disabled)
|
||||
{
|
||||
GtkStyle *st = gt_get_style(type);
|
||||
GdkColor *color;
|
||||
|
||||
if (disabled)
|
||||
state = STATE_INSENSITIVE;
|
||||
|
||||
if (type == GTK_TYPE_ENTRY)
|
||||
{
|
||||
if (fg)
|
||||
@ -262,42 +269,44 @@ static gColor get_color(GType type, bool fg, GtkStateType state)
|
||||
|
||||
#endif
|
||||
|
||||
void gDesktop::calcColors()
|
||||
void gDesktop::calc_colors(gColor colors[], bool disabled)
|
||||
{
|
||||
_colors[BACKGROUND] = get_color(GTK_TYPE_WINDOW, false, STATE_NORMAL);
|
||||
_colors[FOREGROUND] = get_color(GTK_TYPE_WINDOW, true, STATE_NORMAL);
|
||||
_colors[TEXT_BACKGROUND] = get_color(GTK_TYPE_ENTRY, false, STATE_NORMAL);
|
||||
_colors[TEXT_FOREGROUND] = get_color(GTK_TYPE_ENTRY, true, STATE_NORMAL);
|
||||
_colors[SELECTED_BACKGROUND] = get_color(GTK_TYPE_ENTRY, false, STATE_SELECTED);
|
||||
_colors[SELECTED_FOREGROUND] = get_color(GTK_TYPE_ENTRY, true, STATE_SELECTED);
|
||||
_colors[BUTTON_BACKGROUND] = get_color(GTK_TYPE_BUTTON, false, STATE_NORMAL);
|
||||
_colors[BUTTON_FOREGROUND] = get_color(GTK_TYPE_BUTTON, true, STATE_NORMAL);
|
||||
_colors[TOOLTIP_BACKGROUND] = get_color(GTK_TYPE_TOOLTIP, false, STATE_NORMAL);
|
||||
_colors[TOOLTIP_FOREGROUND] = get_color(GTK_TYPE_TOOLTIP, true, STATE_NORMAL);
|
||||
colors[BACKGROUND] = get_color(GTK_TYPE_WINDOW, false, STATE_NORMAL, disabled);
|
||||
colors[FOREGROUND] = get_color(GTK_TYPE_WINDOW, true, STATE_NORMAL, disabled);
|
||||
colors[TEXT_BACKGROUND] = get_color(GTK_TYPE_ENTRY, false, STATE_NORMAL, disabled);
|
||||
colors[TEXT_FOREGROUND] = get_color(GTK_TYPE_ENTRY, true, STATE_NORMAL, disabled);
|
||||
colors[SELECTED_BACKGROUND] = get_color(GTK_TYPE_ENTRY, false, STATE_SELECTED, disabled);
|
||||
colors[SELECTED_FOREGROUND] = get_color(GTK_TYPE_ENTRY, true, STATE_SELECTED, disabled);
|
||||
colors[BUTTON_BACKGROUND] = get_color(GTK_TYPE_BUTTON, false, STATE_NORMAL, disabled);
|
||||
colors[BUTTON_FOREGROUND] = get_color(GTK_TYPE_BUTTON, true, STATE_NORMAL, disabled);
|
||||
colors[TOOLTIP_BACKGROUND] = get_color(GTK_TYPE_TOOLTIP, false, STATE_NORMAL, disabled);
|
||||
colors[TOOLTIP_FOREGROUND] = get_color(GTK_TYPE_TOOLTIP, true, STATE_NORMAL, disabled);
|
||||
#ifdef GTK3
|
||||
#if GTK_CHECK_VERSION(3, 12, 0)
|
||||
_colors[LINK_FOREGROUND] = get_color(GTK_TYPE_LINK_BUTTON, true, STATE_LINK);
|
||||
_colors[VISITED_FOREGROUND] = get_color(GTK_TYPE_LINK_BUTTON, true, (STATE_T)((int)STATE_LINK + (int)STATE_VISITED));
|
||||
colors[LINK_FOREGROUND] = get_color(GTK_TYPE_LINK_BUTTON, true, STATE_LINK, disabled);
|
||||
colors[VISITED_FOREGROUND] = get_color(GTK_TYPE_LINK_BUTTON, true, (STATE_T)((int)STATE_LINK + (int)STATE_VISITED), disabled);
|
||||
#else
|
||||
_colors[LINK_FOREGROUND] = get_color(GTK_TYPE_LINK_BUTTON, true, STATE_NORMAL);
|
||||
_colors[VISITED_FOREGROUND] = IMAGE.DarkerColor(_colors[LINK_FOREGROUND]);
|
||||
colors[LINK_FOREGROUND] = get_color(GTK_TYPE_LINK_BUTTON, true, STATE_NORMAL, disabled);
|
||||
colors[VISITED_FOREGROUND] = IMAGE.DarkerColor(_colors[LINK_FOREGROUND]);
|
||||
#endif
|
||||
#else
|
||||
_colors[LINK_FOREGROUND] = IMAGE.LighterColor(_colors[SELECTED_BACKGROUND]);
|
||||
_colors[VISITED_FOREGROUND] = IMAGE.DarkerColor(_colors[LINK_FOREGROUND]);
|
||||
colors[LINK_FOREGROUND] = IMAGE.LighterColor(_colors[SELECTED_BACKGROUND]);
|
||||
colors[VISITED_FOREGROUND] = IMAGE.DarkerColor(_colors[LINK_FOREGROUND]);
|
||||
#endif
|
||||
_colors[LIGHT_BACKGROUND] = IMAGE.MergeColor(_colors[SELECTED_BACKGROUND], _colors[SELECTED_FOREGROUND], 0.3);
|
||||
_colors[LIGHT_FOREGROUND] = IMAGE.MergeColor(_colors[BACKGROUND], _colors[FOREGROUND], 0.3);
|
||||
|
||||
_colors_valid = true;
|
||||
colors[LIGHT_BACKGROUND] = IMAGE.MergeColor(_colors[SELECTED_BACKGROUND], _colors[SELECTED_FOREGROUND], 0.3);
|
||||
colors[LIGHT_FOREGROUND] = IMAGE.MergeColor(_colors[BACKGROUND], _colors[FOREGROUND], 0.3);
|
||||
}
|
||||
|
||||
gColor gDesktop::getColor(int color)
|
||||
gColor gDesktop::getColor(int color, bool disabled)
|
||||
{
|
||||
if (!_colors_valid)
|
||||
calcColors();
|
||||
{
|
||||
calc_colors(_colors, false);
|
||||
calc_colors(_colors_disabled, true);
|
||||
_colors_valid = true;
|
||||
}
|
||||
|
||||
return _colors[color];
|
||||
return disabled ? _colors_disabled[color] : _colors[color];
|
||||
}
|
||||
|
||||
void gDesktop::screenResolution(int screen, double *x, double *y)
|
||||
|
@ -74,7 +74,7 @@ public:
|
||||
|
||||
static void screenResolution(int screen, double *x, double *y);
|
||||
|
||||
static gColor getColor(int color);
|
||||
static gColor getColor(int color, bool disabled = false);
|
||||
|
||||
static void onThemeChange();
|
||||
|
||||
@ -84,8 +84,9 @@ private:
|
||||
static gFont *_desktop_font;
|
||||
static bool _colors_valid;
|
||||
static gColor _colors[NUM_COLORS];
|
||||
static gColor _colors_disabled[NUM_COLORS];
|
||||
|
||||
static void calcColors();
|
||||
static void calc_colors(gColor colors[], bool disabled);
|
||||
|
||||
#ifdef GTK3
|
||||
static GtkStyleProvider *_css;
|
||||
|
@ -149,8 +149,8 @@ static gboolean cb_map(GtkWidget *menu, gMenu *data)
|
||||
data->_mapping = true;
|
||||
|
||||
data->hideSeparators();
|
||||
gtk_widget_hide(menu);
|
||||
gtk_widget_show(menu);
|
||||
/*gtk_widget_hide(menu);
|
||||
gtk_widget_show(menu);*/
|
||||
//gtk_menu_reposition(GTK_MENU(menu));
|
||||
|
||||
data->_mapping = false;
|
||||
|
@ -1156,3 +1156,8 @@ void gTextArea::setBorder(bool b)
|
||||
gControl::setBorder(b);
|
||||
setFramePadding(hasBorder() ? gDesktop::scale() * 3 / 4 : 0);
|
||||
}
|
||||
|
||||
gColor gTextArea::defaultBackground() const
|
||||
{
|
||||
return gDesktop::getColor(gDesktop::TEXT_BACKGROUND, !isEnabled());
|
||||
}
|
||||
|
@ -98,6 +98,7 @@ public:
|
||||
virtual void setMinimumSize();
|
||||
virtual void setFont(gFont *ft);
|
||||
virtual void setBorder(bool b);
|
||||
virtual gColor defaultBackground() const;
|
||||
#ifdef GTK3
|
||||
virtual GtkWidget *getStyleSheetWidget();
|
||||
virtual const char *getStyleSheetColorNode();
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "widgets.h"
|
||||
#include "gapplication.h"
|
||||
#include "gkey.h"
|
||||
#include "gdesktop.h"
|
||||
#include "gtextbox.h"
|
||||
|
||||
#ifdef GTK3
|
||||
@ -559,3 +560,8 @@ void gTextBox::onLeaveEvent()
|
||||
gdk_window_hide(TEXT_AREA(entry));
|
||||
}
|
||||
#endif
|
||||
|
||||
gColor gTextBox::defaultBackground() const
|
||||
{
|
||||
return gDesktop::getColor(gDesktop::TEXT_BACKGROUND, !isEnabled());
|
||||
}
|
||||
|
@ -82,6 +82,8 @@ public:
|
||||
|
||||
virtual void setMinimumSize();
|
||||
virtual void setFont(gFont *ft);
|
||||
|
||||
virtual gColor defaultBackground() const;
|
||||
|
||||
#ifdef GTK3
|
||||
virtual void onEnterEvent();
|
||||
|
@ -1509,6 +1509,8 @@ GB_COLOR CWIDGET_get_real_background(CWIDGET *_object)
|
||||
if (bg != COLOR_DEFAULT)
|
||||
return bg;
|
||||
|
||||
return WIDGET->palette().color(WIDGET->backgroundRole()).rgb() & 0xFFFFFF;
|
||||
|
||||
CWIDGET *parent = (CWIDGET *)CWIDGET_get_parent(THIS);
|
||||
|
||||
if (parent)
|
||||
|
Loading…
x
Reference in New Issue
Block a user