Fix arrangement of containers having the AutoResize property set and get rid of many deprecated GTK+ API on GTK+3.
[GB.GTK] * BUG: Fix arrangement of containers having the AutoResize property set. * BUG: TabStrip: Fix the client area computing routine. [GB.GTK3] * BUG: Fix arrangement of containers having the AutoResize property set. * BUG: Get rid of many deprecated GTK+ API (not all yet). * BUG: TabStrip: Fix the client area computing routine.
This commit is contained in:
parent
96c271fccf
commit
0d076a7b7c
10 changed files with 228 additions and 236 deletions
|
@ -406,7 +406,9 @@ void gButton::setText(const char *st)
|
|||
gtk_button_set_label(GTK_BUTTON(widget), "");
|
||||
|
||||
_label = gtk_bin_get_child(GTK_BIN(widget));
|
||||
#ifndef GTK3
|
||||
set_gdk_fg_color(_label, foreground());
|
||||
#endif
|
||||
}
|
||||
|
||||
updateFont();
|
||||
|
|
|
@ -70,8 +70,8 @@ static void cb_before_arrange(gContainer *sender)
|
|||
|
||||
static void resize_container(gContainer *cont, int w, int h)
|
||||
{
|
||||
w += cont->width() - cont->containerWidth();
|
||||
h += cont->height() - cont->containerHeight();
|
||||
/*w += cont->width() - cont->containerWidth();
|
||||
h += cont->height() - cont->containerHeight();*/
|
||||
|
||||
if (w >= 0 && h >= 0)
|
||||
cont->resize(w, h);
|
||||
|
@ -108,7 +108,7 @@ static void resize_container(gContainer *cont, int w, int h)
|
|||
#define MOVE_WIDGET(_object, _widget, _x, _y) (((gControl*)_widget)->move( _x, _y))
|
||||
#define RESIZE_WIDGET(_object, _widget, _w, _h) (((gControl*)_widget)->resize( _w, _h))
|
||||
#define MOVE_RESIZE_WIDGET(_object, _widget, _x, _y, _w, _h) (((gControl*)_widget)->moveResize( _x, _y, _w, _h))
|
||||
#define RESIZE_CONTAINER(_widget, _cont, _w, _h) resize_container((gContainer *)(_cont), _w, _h)
|
||||
#define RESIZE_CONTAINER(_object, _cont, _w, _h) resize_container((gContainer *)(_cont), _w, _h)
|
||||
|
||||
#define INIT_CHECK_CHILDREN_LIST(_widget) \
|
||||
gContainer *gtk_control=(gContainer*)_widget; \
|
||||
|
|
|
@ -2068,9 +2068,7 @@ void gControl::updateStyleSheet()
|
|||
GtkStyleContext *context;
|
||||
GString *css;
|
||||
char *css_str;
|
||||
int s;
|
||||
gColor fg;
|
||||
char buffer[32];
|
||||
|
||||
wid = getStyleSheetWidget();
|
||||
context = gtk_widget_get_style_context(wid);
|
||||
|
@ -2083,73 +2081,13 @@ void gControl::updateStyleSheet()
|
|||
if (_bg != COLOR_DEFAULT || fg != COLOR_DEFAULT)
|
||||
{
|
||||
setStyleSheetNode(css, getStyleSheetColorNode());
|
||||
|
||||
if (_bg != COLOR_DEFAULT)
|
||||
{
|
||||
gt_to_css_color(buffer, _bg);
|
||||
g_string_append(css, "background-color:");
|
||||
g_string_append(css, buffer);
|
||||
g_string_append(css, ";\nbackground-image:none;\n");
|
||||
}
|
||||
|
||||
if (fg != COLOR_DEFAULT)
|
||||
{
|
||||
gt_to_css_color(buffer, fg);
|
||||
g_string_append(css, "color:");
|
||||
g_string_append(css, buffer);
|
||||
g_string_append(css, ";\n");
|
||||
}
|
||||
gt_css_add_color(css, _bg, _fg);
|
||||
}
|
||||
|
||||
if (_font)
|
||||
{
|
||||
setStyleSheetNode(css, getStyleSheetFontNode());
|
||||
|
||||
if (_font->_name_set)
|
||||
{
|
||||
g_string_append(css, "font-family:\"");
|
||||
g_string_append(css, _font->name());
|
||||
g_string_append(css, "\";\n");
|
||||
}
|
||||
|
||||
if (_font->_size_set)
|
||||
{
|
||||
s = (int)(_font->size() * 10 + 0.5);
|
||||
sprintf(buffer, "%dpt;\n", s / 10); //, s % 10);
|
||||
g_string_append(css, "font-size:");
|
||||
g_string_append(css, buffer);
|
||||
}
|
||||
|
||||
if (_font->_bold_set)
|
||||
{
|
||||
g_string_append(css, "font-weight:");
|
||||
g_string_append(css, _font->bold() ? "bold" : "normal");
|
||||
g_string_append(css, ";\n");
|
||||
}
|
||||
|
||||
if (_font->_italic_set)
|
||||
{
|
||||
g_string_append(css, "font-style:");
|
||||
g_string_append(css, _font->italic() ? "italic" : "normal");
|
||||
g_string_append(css, ";\n");
|
||||
}
|
||||
|
||||
if (_font->_underline_set || _font->_strikeout_set)
|
||||
{
|
||||
g_string_append(css, "text-decoration-line:");
|
||||
if (_font->strikeout())
|
||||
g_string_append(css, "line-through");
|
||||
else if (_font->underline())
|
||||
g_string_append(css, "underline");
|
||||
else
|
||||
g_string_append(css, "none");
|
||||
g_string_append(css, ";\n");
|
||||
}
|
||||
|
||||
if (_font->mustFixSpacing())
|
||||
{
|
||||
g_string_append(css, "letter-spacing:1px;\n");
|
||||
}
|
||||
gt_css_add_font(css, _font);
|
||||
}
|
||||
|
||||
customStyleSheet(css);
|
||||
|
@ -2759,7 +2697,7 @@ void gControl::updateColor()
|
|||
{
|
||||
}
|
||||
|
||||
void gControl::setColorNames(const char *bg_names[], const char *fg_names[])
|
||||
/*void gControl::setColorNames(const char *bg_names[], const char *fg_names[])
|
||||
{
|
||||
_bg_name_list = bg_names;
|
||||
_fg_name_list = fg_names;
|
||||
|
@ -2790,7 +2728,7 @@ void gControl::setColorButton()
|
|||
const char *fg_names[] = { "button_fg_color", "theme_button_fg_color", "theme_fg_color", NULL };
|
||||
setColorNames(bg_names, fg_names);
|
||||
use_base = FALSE;
|
||||
}
|
||||
}*/
|
||||
#endif
|
||||
|
||||
GtkIMContext *gControl::getInputMethod()
|
||||
|
@ -2871,12 +2809,6 @@ void gControl::createBorder(GtkWidget *new_border, bool keep_widget)
|
|||
#ifdef GTK3
|
||||
void gControl::setWidgetName()
|
||||
{
|
||||
static int count = 0;
|
||||
|
||||
char buffer[16];
|
||||
|
||||
count++;
|
||||
sprintf(buffer, "g%d", count);
|
||||
gtk_widget_set_name(getStyleSheetWidget(), buffer);
|
||||
gt_widget_set_name(getStyleSheetWidget());
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -159,14 +159,11 @@ public:
|
|||
virtual void customStyleSheet(GString *css);
|
||||
void setStyleSheetNode(GString *css, const char *node);
|
||||
virtual void updateColor();
|
||||
void setColorNames(const char *bg_names[], const char *fg_names[]);
|
||||
void setColorBase();
|
||||
void setColorButton();
|
||||
#else
|
||||
void setColorNames(const char **, const char **) {}
|
||||
#endif
|
||||
void setColorBase() { use_base = TRUE; }
|
||||
void setColorButton() { use_base = FALSE; }
|
||||
#endif
|
||||
|
||||
virtual bool canFocus() const;
|
||||
bool canFocusOnClick() const;
|
||||
|
|
|
@ -288,7 +288,9 @@ void gDrawingArea::setCached(bool vl)
|
|||
if (!_cached)
|
||||
{
|
||||
UNREF_BUFFER();
|
||||
#ifndef GTK3
|
||||
set_gdk_bg_color(border, background());
|
||||
#endif
|
||||
}
|
||||
|
||||
create();
|
||||
|
|
|
@ -299,7 +299,11 @@ void gMenu::update()
|
|||
label = gtk_label_new_with_mnemonic("");
|
||||
shlabel = gtk_label_new("");
|
||||
|
||||
#if GTK_CHECK_VERSION(3, 16, 0)
|
||||
gtk_label_set_xalign(GTK_LABEL(shlabel), 0);
|
||||
#else
|
||||
gtk_misc_set_alignment(GTK_MISC(shlabel), 0, 0.5);
|
||||
#endif
|
||||
gtk_size_group_add_widget(parentMenu()->getSizeGroup(), shlabel);
|
||||
|
||||
size = window()->font()->height();
|
||||
|
@ -1126,8 +1130,8 @@ void gMenu::setFont()
|
|||
{
|
||||
gMainWindow *win = window();
|
||||
#ifdef GTK3
|
||||
if (label) gtk_widget_override_font(GTK_WIDGET(label), win->font()->desc());
|
||||
if (shlabel) gtk_widget_override_font(GTK_WIDGET(shlabel), win->font()->desc());
|
||||
if (label) gt_widget_update_css(GTK_WIDGET(label), win->font(), COLOR_DEFAULT, COLOR_DEFAULT);
|
||||
if (shlabel) gt_widget_update_css(GTK_WIDGET(shlabel), win->font(), COLOR_DEFAULT, COLOR_DEFAULT);
|
||||
#else
|
||||
if (label) gtk_widget_modify_font(GTK_WIDGET(label), win->font()->desc());
|
||||
if (shlabel) gtk_widget_modify_font(GTK_WIDGET(shlabel), win->font()->desc());
|
||||
|
@ -1153,8 +1157,12 @@ void gMenu::updateColor(gMainWindow *win)
|
|||
if (!win->menuBar)
|
||||
return;
|
||||
|
||||
#ifdef GTK3
|
||||
gt_widget_update_css(GTK_WIDGET(win->menuBar), NULL, win->background(), win->foreground());
|
||||
#else
|
||||
set_gdk_bg_color(GTK_WIDGET(win->menuBar), win->background());
|
||||
set_gdk_fg_color(GTK_WIDGET(win->menuBar), win->foreground());
|
||||
#endif
|
||||
|
||||
/*if (!menus)
|
||||
return;
|
||||
|
@ -1178,7 +1186,7 @@ void gMenu::updateFont(gMainWindow *win)
|
|||
{
|
||||
//fprintf(stderr, "set menu bar font\n");
|
||||
#ifdef GTK3
|
||||
gtk_widget_override_font(GTK_WIDGET(win->menuBar), win->ownFont() ? win->font()->desc() : NULL);
|
||||
gt_widget_update_css(GTK_WIDGET(win->menuBar), win->ownFont() ? win->font() : NULL, COLOR_DEFAULT, COLOR_DEFAULT);
|
||||
#else
|
||||
gtk_widget_modify_font(GTK_WIDGET(win->menuBar), win->ownFont() ? win->font()->desc() : NULL);
|
||||
#endif
|
||||
|
|
|
@ -83,10 +83,13 @@ static void cb_size_allocate(GtkWidget *wid, GtkAllocation *alloc, gTabStrip *da
|
|||
{
|
||||
if (wid == data->getContainer() && (alloc->width != data->_client_w || alloc->height != data->_client_h))
|
||||
{
|
||||
int tx, ty, px, py;
|
||||
GdkWindow *win;
|
||||
GtkAllocation alloc_parent;
|
||||
/*int tx, ty, px, py;
|
||||
GdkWindow *win;*/
|
||||
|
||||
if (data->getScreenPos(&tx, &ty))
|
||||
gtk_widget_get_allocation(data->widget, &alloc_parent);
|
||||
|
||||
/*if (data->getScreenPos(&tx, &ty))
|
||||
return;
|
||||
|
||||
win = gtk_widget_get_window(wid);
|
||||
|
@ -95,13 +98,13 @@ static void cb_size_allocate(GtkWidget *wid, GtkAllocation *alloc, gTabStrip *da
|
|||
|
||||
gdk_window_get_origin(win, &px, &py);
|
||||
//fprintf(stderr, "alloc: tab = %d %d page = %d %d alloc = %d %d\n", tx, ty, px, py, alloc->x, alloc->y);
|
||||
|
||||
data->_client_x = px - tx + alloc->x;
|
||||
data->_client_y = py - ty + alloc->y;
|
||||
*/
|
||||
|
||||
data->_client_x = alloc->x - alloc_parent.x;
|
||||
data->_client_y = alloc->y - alloc_parent.y;
|
||||
data->_client_w = alloc->width;
|
||||
data->_client_h = alloc->height;
|
||||
//fprintf(stderr, "alloc: %s: %d %d %d %d\n", data->name(), data->_client_x, data->_client_y, alloc->width, alloc->height);
|
||||
data->performArrange();
|
||||
//data->performArrange();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -232,8 +235,14 @@ public:
|
|||
void setEnabled(bool v);
|
||||
/*int count() const;
|
||||
gControl *child(int n) const;*/
|
||||
#ifdef GTK3
|
||||
void updateStyleSheet();
|
||||
void updateColors() { updateStyleSheet(); }
|
||||
void updateFont() { updateStyleSheet(); }
|
||||
#else
|
||||
void updateColors();
|
||||
void updateFont();
|
||||
#endif
|
||||
void updateButton();
|
||||
|
||||
GtkWidget *fix;
|
||||
|
@ -272,8 +281,12 @@ gTabStripPage::gTabStripPage(gTabStrip *tab)
|
|||
//gtk_container_add(GTK_CONTAINER(hbox), label);
|
||||
gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
|
||||
|
||||
#ifdef GTK3
|
||||
updateStyleSheet();
|
||||
#else
|
||||
updateColors();
|
||||
updateFont();
|
||||
#endif
|
||||
|
||||
g_signal_connect_after(G_OBJECT(widget), "size-allocate", G_CALLBACK(cb_size_allocate), (gpointer)parent);
|
||||
|
||||
|
@ -312,37 +325,39 @@ gTabStripPage::~gTabStripPage()
|
|||
g_object_unref(widget);
|
||||
}
|
||||
|
||||
#ifdef GTK3
|
||||
|
||||
void gTabStripPage::updateStyleSheet()
|
||||
{
|
||||
gt_widget_update_css(widget, NULL, parent->background(), COLOR_DEFAULT);
|
||||
gt_widget_update_css(label, parent->textFont(), COLOR_DEFAULT, COLOR_DEFAULT);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
void gTabStripPage::updateColors()
|
||||
{
|
||||
#ifdef GTK3
|
||||
gt_widget_set_color(widget, FALSE, parent->realBackground());
|
||||
#else
|
||||
set_gdk_bg_color(widget, parent->realBackground());
|
||||
set_gdk_fg_color(label, parent->realForeground());
|
||||
#endif
|
||||
}
|
||||
|
||||
void gTabStripPage::updateFont()
|
||||
{
|
||||
PangoFontDescription *desc = NULL;
|
||||
gFont *fnt;
|
||||
|
||||
fnt = parent->textFont();
|
||||
gFont *fnt = parent->textFont();
|
||||
|
||||
if (!fnt)
|
||||
fnt = parent->font();
|
||||
|
||||
if (fnt)
|
||||
desc = fnt->desc();
|
||||
|
||||
#ifdef GTK3
|
||||
gtk_widget_override_font(widget, desc);
|
||||
gtk_widget_override_font(label, desc);
|
||||
#else
|
||||
gtk_widget_modify_font(widget, desc);
|
||||
gtk_widget_modify_font(label, desc);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void gTabStripPage::setText(char *text)
|
||||
{
|
||||
char *buf;
|
||||
|
@ -758,12 +773,21 @@ GtkWidget *gTabStrip::getContainer()
|
|||
}
|
||||
|
||||
#ifdef GTK3
|
||||
|
||||
void gTabStrip::customStyleSheet(GString *css)
|
||||
{
|
||||
gColor bg = background();
|
||||
if (bg == COLOR_DEFAULT)
|
||||
return;
|
||||
|
||||
setStyleSheetNode(css, " > header");
|
||||
gt_css_add_color(css, bg, COLOR_DEFAULT);
|
||||
setStyleSheetNode(css, " > header tab:checked");
|
||||
gt_css_add_color(css, bg, COLOR_DEFAULT);
|
||||
}
|
||||
|
||||
void gTabStrip::updateColor()
|
||||
{
|
||||
//fprintf(stderr, "%s: updateColors\n", name());
|
||||
gt_widget_set_color(border, false, realBackground());
|
||||
gt_widget_set_color(widget, false, realBackground());
|
||||
|
||||
for (int i = 0; i < count(); i++)
|
||||
get(i)->updateColors();
|
||||
}
|
||||
|
|
|
@ -60,10 +60,11 @@ public:
|
|||
virtual int childCount() const;
|
||||
virtual gControl *child(int index) const;
|
||||
|
||||
#ifndef GTK3
|
||||
virtual void setRealBackground(gColor color);
|
||||
#else
|
||||
#ifdef GTK3
|
||||
virtual void customStyleSheet(GString *css);
|
||||
virtual void updateColor();
|
||||
#else
|
||||
virtual void setRealBackground(gColor color);
|
||||
#endif
|
||||
virtual void setRealForeground(gColor color);
|
||||
virtual void updateFont();
|
||||
|
|
|
@ -47,10 +47,7 @@ Conversion between GDK and long type colors
|
|||
#define SCALE(i) ((int)(i * 255.0 / 65535.0 + 0.5))
|
||||
#define UNSCALE(d) ((int)(d / 255.0 * 65535.0 + 0.5))
|
||||
|
||||
#ifdef GTK3
|
||||
static GtkStateFlags _color_style_bg[] = { GTK_STATE_FLAG_NORMAL, GTK_STATE_FLAG_INSENSITIVE, (GtkStateFlags)-1 };
|
||||
static GtkStateFlags _color_style_fg[] = { GTK_STATE_FLAG_NORMAL, GTK_STATE_FLAG_ACTIVE, GTK_STATE_FLAG_PRELIGHT, (GtkStateFlags)-1 };
|
||||
#else
|
||||
#ifndef GTK3
|
||||
static GtkStateType _color_style_bg[] = { GTK_STATE_INSENSITIVE, GTK_STATE_ACTIVE, GTK_STATE_PRELIGHT, GTK_STATE_NORMAL };
|
||||
static GtkStateType _color_style_fg[] = { GTK_STATE_ACTIVE, GTK_STATE_PRELIGHT, GTK_STATE_NORMAL };
|
||||
#endif
|
||||
|
@ -89,45 +86,7 @@ gColor gt_gdkcolor_to_color(GdkColor *gcol)
|
|||
return gt_rgb_to_color(SCALE(gcol->red), SCALE(gcol->green), SCALE(gcol->blue));
|
||||
}
|
||||
|
||||
#ifdef GTK3
|
||||
|
||||
static void set_color(GtkWidget *wid, gColor color, void (*func)(GtkWidget *, GtkStateFlags, const GdkRGBA *), bool fg)
|
||||
{
|
||||
GdkRGBA gcol;
|
||||
GdkRGBA *pcol;
|
||||
int i;
|
||||
//GtkStyleContext *style;
|
||||
GtkStateFlags st;
|
||||
|
||||
if (color == COLOR_DEFAULT)
|
||||
{
|
||||
pcol = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
gt_from_color(color, &gcol);
|
||||
pcol = &gcol;
|
||||
|
||||
/*style = gtk_widget_get_style_context(wid);
|
||||
if (fg)
|
||||
gtk_style_context_get_color(style, GTK_STATE_FLAG_SELECTED, &scol);
|
||||
else
|
||||
gtk_style_context_get_background_color(style, GTK_STATE_FLAG_SELECTED, &scol);*/
|
||||
}
|
||||
|
||||
for (i = 0;; i++)
|
||||
{
|
||||
st = fg ? _color_style_fg[i] : _color_style_bg[i];
|
||||
if (st < 0)
|
||||
break;
|
||||
(*func)(wid, st, pcol);
|
||||
}
|
||||
|
||||
/*if (color != COLOR_DEFAULT)
|
||||
(*func)(wid, GTK_STATE_FLAG_SELECTED, &scol);*/
|
||||
}
|
||||
|
||||
#else
|
||||
#ifndef GTK3
|
||||
|
||||
static void set_color(GtkWidget *wid, gColor color, void (*func)(GtkWidget *, GtkStateType, const GdkColor *), bool fg)
|
||||
{
|
||||
|
@ -155,9 +114,6 @@ static void set_color(GtkWidget *wid, gColor color, void (*func)(GtkWidget *, Gt
|
|||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef GTK3
|
||||
gColor get_gdk_fg_color(GtkWidget *wid, bool enabled)
|
||||
{
|
||||
GtkStyle* st;
|
||||
|
@ -165,18 +121,12 @@ gColor get_gdk_fg_color(GtkWidget *wid, bool enabled)
|
|||
st=gtk_widget_get_style(wid);
|
||||
return gt_gdkcolor_to_color(&st->fg[enabled ? GTK_STATE_NORMAL : GTK_STATE_INSENSITIVE]);
|
||||
}
|
||||
#endif
|
||||
|
||||
void set_gdk_fg_color(GtkWidget *wid, gColor color)
|
||||
{
|
||||
#ifdef GTK3
|
||||
set_color(wid, color, gtk_widget_override_color, true);
|
||||
#else
|
||||
set_color(wid, color, gtk_widget_modify_fg, true);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifndef GTK3
|
||||
gColor get_gdk_bg_color(GtkWidget *wid, bool enabled)
|
||||
{
|
||||
GtkStyle* st;
|
||||
|
@ -184,18 +134,12 @@ gColor get_gdk_bg_color(GtkWidget *wid, bool enabled)
|
|||
st=gtk_widget_get_style(wid);
|
||||
return gt_gdkcolor_to_color(&st->bg[enabled ? GTK_STATE_NORMAL : GTK_STATE_INSENSITIVE]);
|
||||
}
|
||||
#endif
|
||||
|
||||
void set_gdk_bg_color(GtkWidget *wid,gColor color)
|
||||
{
|
||||
#ifdef GTK3
|
||||
set_color(wid, color, gtk_widget_override_background_color, false);
|
||||
#else
|
||||
set_color(wid, color, gtk_widget_modify_bg, false);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifndef GTK3
|
||||
gColor get_gdk_text_color(GtkWidget *wid, bool enabled)
|
||||
{
|
||||
GtkStyle* st;
|
||||
|
@ -203,18 +147,12 @@ gColor get_gdk_text_color(GtkWidget *wid, bool enabled)
|
|||
st=gtk_widget_get_style(wid);
|
||||
return gt_gdkcolor_to_color(&st->text[enabled ? GTK_STATE_NORMAL : GTK_STATE_INSENSITIVE]);
|
||||
}
|
||||
#endif
|
||||
|
||||
void set_gdk_text_color(GtkWidget *wid,gColor color)
|
||||
{
|
||||
#ifdef GTK3
|
||||
set_color(wid, color, gtk_widget_override_color, true);
|
||||
#else
|
||||
set_color(wid, color, gtk_widget_modify_text, true);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifndef GTK3
|
||||
gColor get_gdk_base_color(GtkWidget *wid, bool enabled)
|
||||
{
|
||||
GtkStyle* st;
|
||||
|
@ -222,16 +160,12 @@ gColor get_gdk_base_color(GtkWidget *wid, bool enabled)
|
|||
st=gtk_widget_get_style(wid);
|
||||
return gt_gdkcolor_to_color(&st->base[enabled ? GTK_STATE_NORMAL : GTK_STATE_INSENSITIVE]);
|
||||
}
|
||||
#endif
|
||||
|
||||
void set_gdk_base_color(GtkWidget *wid,gColor color)
|
||||
{
|
||||
#ifdef GTK3
|
||||
set_color(wid, color, gtk_widget_override_background_color, false);
|
||||
#else
|
||||
set_color(wid, color, gtk_widget_modify_base, false);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
void gt_color_to_rgb(gColor color, int *r, int *g, int *b)
|
||||
{
|
||||
|
@ -2266,58 +2200,6 @@ void gt_draw_border(cairo_t *cr, GtkStyleContext *st, GtkStateFlags state, int b
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifdef GTK3
|
||||
|
||||
void gt_widget_set_color(GtkWidget *widget, bool fg, gColor color, const char *name, const GdkRGBA *def_color)
|
||||
{
|
||||
if (color == COLOR_DEFAULT)
|
||||
{
|
||||
if (name)
|
||||
gtk_widget_override_symbolic_color(widget, name, def_color);
|
||||
|
||||
if (fg)
|
||||
gtk_widget_override_color(widget, GTK_STATE_FLAG_NORMAL, NULL);
|
||||
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);
|
||||
|
||||
if (fg)
|
||||
gtk_widget_override_color(widget, GTK_STATE_FLAG_NORMAL, &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
|
||||
|
||||
bool gt_grab(GtkWidget *widget, bool owner_event, guint32 time)
|
||||
{
|
||||
GdkWindow *win = gtk_widget_get_window(widget);
|
||||
|
@ -2445,3 +2327,144 @@ int gt_find_monitor(GdkMonitor *monitor)
|
|||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef GTK3
|
||||
const char *gt_widget_set_name(GtkWidget *widget)
|
||||
{
|
||||
static int count = 0;
|
||||
|
||||
char buffer[16];
|
||||
const char *name;
|
||||
|
||||
name = gtk_widget_get_name(widget);
|
||||
if (name && name[0] == 'g')
|
||||
return name;
|
||||
|
||||
count++;
|
||||
sprintf(buffer, "g%d", count);
|
||||
gtk_widget_set_name(widget, buffer);
|
||||
return gtk_widget_get_name(widget);
|
||||
}
|
||||
|
||||
void gt_css_add_color(GString *css, gColor bg, gColor fg)
|
||||
{
|
||||
char buffer[32];
|
||||
|
||||
if (bg != COLOR_DEFAULT)
|
||||
{
|
||||
gt_to_css_color(buffer, bg);
|
||||
g_string_append(css, "background-color:");
|
||||
g_string_append(css, buffer);
|
||||
g_string_append(css, ";\nbackground-image:none;\n");
|
||||
}
|
||||
|
||||
if (fg != COLOR_DEFAULT)
|
||||
{
|
||||
gt_to_css_color(buffer, fg);
|
||||
g_string_append(css, "color:");
|
||||
g_string_append(css, buffer);
|
||||
g_string_append(css, ";\n");
|
||||
}
|
||||
}
|
||||
|
||||
void gt_css_add_font(GString *css, gFont *font)
|
||||
{
|
||||
int s;
|
||||
char buffer[32];
|
||||
|
||||
if (!font)
|
||||
return;
|
||||
|
||||
if (font->_name_set)
|
||||
{
|
||||
g_string_append(css, "font-family:\"");
|
||||
g_string_append(css, font->name());
|
||||
g_string_append(css, "\";\n");
|
||||
}
|
||||
|
||||
if (font->_size_set)
|
||||
{
|
||||
s = (int)(font->size() * 10 + 0.5);
|
||||
sprintf(buffer, "%dpt;\n", s / 10); //, s % 10);
|
||||
g_string_append(css, "font-size:");
|
||||
g_string_append(css, buffer);
|
||||
}
|
||||
|
||||
if (font->_bold_set)
|
||||
{
|
||||
g_string_append(css, "font-weight:");
|
||||
g_string_append(css, font->bold() ? "bold" : "normal");
|
||||
g_string_append(css, ";\n");
|
||||
}
|
||||
|
||||
if (font->_italic_set)
|
||||
{
|
||||
g_string_append(css, "font-style:");
|
||||
g_string_append(css, font->italic() ? "italic" : "normal");
|
||||
g_string_append(css, ";\n");
|
||||
}
|
||||
|
||||
if (font->_underline_set || font->_strikeout_set)
|
||||
{
|
||||
g_string_append(css, "text-decoration-line:");
|
||||
if (font->strikeout())
|
||||
g_string_append(css, "line-through");
|
||||
else if (font->underline())
|
||||
g_string_append(css, "underline");
|
||||
else
|
||||
g_string_append(css, "none");
|
||||
g_string_append(css, ";\n");
|
||||
}
|
||||
|
||||
if (font->mustFixSpacing())
|
||||
{
|
||||
g_string_append(css, "letter-spacing:1px;\n");
|
||||
}
|
||||
}
|
||||
|
||||
void gt_widget_update_css(GtkWidget *widget, gFont *font, gColor bg, gColor fg)
|
||||
{
|
||||
GtkStyleContext *context;
|
||||
GtkStyleProvider *css_provider;
|
||||
const char *name;
|
||||
GString *css;
|
||||
char *css_str;
|
||||
|
||||
context = gtk_widget_get_style_context(widget);
|
||||
name = gt_widget_set_name(widget);
|
||||
|
||||
css = g_string_new(NULL);
|
||||
|
||||
if (font || bg != COLOR_DEFAULT || fg != COLOR_DEFAULT)
|
||||
{
|
||||
g_string_append_printf(css, "#%s {\ntransition:none;\n", name);
|
||||
gt_css_add_color(css, bg, fg);
|
||||
gt_css_add_font(css, font);
|
||||
g_string_append(css, "}\n");
|
||||
}
|
||||
|
||||
css_provider = (GtkStyleProvider *)g_object_get_data(G_OBJECT(widget), "gambas-css");
|
||||
|
||||
if (css->len)
|
||||
{
|
||||
if (!css_provider)
|
||||
{
|
||||
css_provider = GTK_STYLE_PROVIDER(gtk_css_provider_new());
|
||||
g_object_set_data_full(G_OBJECT(widget), "gambas-css", (gpointer)css_provider, g_object_unref);
|
||||
}
|
||||
css_str = g_string_free(css, FALSE);
|
||||
gtk_css_provider_load_from_data(GTK_CSS_PROVIDER(css_provider), css_str, -1, NULL);
|
||||
g_free(css_str);
|
||||
gtk_style_context_add_provider(context, css_provider, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (css_provider)
|
||||
{
|
||||
gtk_style_context_remove_provider(context, css_provider);
|
||||
g_object_set_data(G_OBJECT(widget), "gambas-css", NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -153,7 +153,6 @@ gColor gt_gdkcolor_to_color(GdkColor *gcol);
|
|||
void fill_gdk_color(GdkColor *gcol, gColor color);
|
||||
#else
|
||||
void fill_gdk_color(GdkColor *gcol, gColor color, GdkColormap *cmap = NULL);
|
||||
#endif
|
||||
gColor get_gdk_text_color(GtkWidget *wid, bool enabled);
|
||||
void set_gdk_text_color(GtkWidget *wid,gColor color);
|
||||
gColor get_gdk_base_color(GtkWidget *wid, bool enabled);
|
||||
|
@ -162,6 +161,7 @@ gColor get_gdk_fg_color(GtkWidget *wid, bool enabled);
|
|||
void set_gdk_fg_color(GtkWidget *wid,gColor color);
|
||||
gColor get_gdk_bg_color(GtkWidget *wid, bool enabled);
|
||||
void set_gdk_bg_color(GtkWidget *wid,gColor color);
|
||||
#endif
|
||||
|
||||
void gt_color_to_rgb(gColor color, int *r, int *g, int *b);
|
||||
gColor gt_rgb_to_color(int r, int g, int b);
|
||||
|
@ -177,10 +177,6 @@ gColor gt_frgba_to_color(double r, double g, double b, double a);
|
|||
void gt_from_color(gColor color, GdkRGBA *rgba);
|
||||
gColor gt_to_color(GdkRGBA *rgba);
|
||||
void gt_to_css_color(char *css, gColor color);
|
||||
|
||||
void gt_widget_set_color(GtkWidget *widget, bool fg, 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
|
||||
|
@ -233,4 +229,11 @@ void gt_widget_reparent(GtkWidget *widget, GtkWidget *new_parent);
|
|||
int gt_find_monitor(GdkMonitor *monitor);
|
||||
#endif
|
||||
|
||||
#ifdef GTK3
|
||||
void gt_css_add_font(GString *css, gFont *font);
|
||||
void gt_css_add_color(GString *css, gColor bg, gColor fg);
|
||||
const char *gt_widget_set_name(GtkWidget *widget);
|
||||
void gt_widget_update_css(GtkWidget *widget, gFont *font, gColor bg, gColor fg);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue