redo how we do styles

This commit is contained in:
cinamod 2003-10-03 17:02:45 +00:00
parent 0f5490e5de
commit 2af224b3a5
4 changed files with 75 additions and 58 deletions

View File

@ -1,3 +1,7 @@
2003-10-03 Dom Lachowicz <cinamod@hotmail.com>
* src/wimp_style.c wimp_style_main.c: Refactor how we're doing styles. Much faster, lower memory consumption
2003-10-03 Dom Lachowicz <cinamod@hotmail.com>
* src/wimp_style_main.c: Catch theme and color changes. Needs more testing and fine-tuning

View File

@ -219,7 +219,7 @@ sys_font_to_pango_font (SystemFontType type, char * buf)
#endif
static void
setup_system_settings (GtkStyle * style)
setup_system_settings (void)
{
GtkSettings * settings;
int menu_delay, cursor_blink_time;
@ -316,53 +316,28 @@ sys_color_to_gtk_color(int id, GdkColor *pcolor)
}
static void
setup_system_styles(GtkStyle *style)
setup_wimp_rc_style(void)
{
/* TODO: Owen says:
"If your setup_system_styles() function called gtk_rc_parse_string(), then you are just piling a new set of strings on top each time the theme changes .. the old ones won't be removed" */
char buf[1024], font_buf[256], *font_ptr;
GdkColor menu_color;
GdkColor menu_text_color;
GdkColor fg_prelight;
GdkColor bg_prelight;
GdkColor base_prelight;
GdkColor text_prelight;
GdkColor tooltip_back;
GdkColor tooltip_fore;
GdkColor btn_fore;
GdkColor progress_back;
GdkColor fg_prelight;
GdkColor bg_prelight;
GdkColor base_prelight;
GdkColor text_prelight;
NONCLIENTMETRICS nc;
gint paned_size = 15;
int i;
/* Default forgeground */
sys_color_to_gtk_color(COLOR_WINDOWTEXT, &style->fg[GTK_STATE_NORMAL]);
sys_color_to_gtk_color(COLOR_WINDOWTEXT, &style->fg[GTK_STATE_ACTIVE]);
sys_color_to_gtk_color(COLOR_WINDOWTEXT, &style->fg[GTK_STATE_PRELIGHT]);
sys_color_to_gtk_color(COLOR_HIGHLIGHTTEXT, &style->fg[GTK_STATE_SELECTED]);
sys_color_to_gtk_color(COLOR_GRAYTEXT, &style->fg[GTK_STATE_INSENSITIVE]);
/* Default background */
sys_color_to_gtk_color(COLOR_3DFACE, &style->bg[GTK_STATE_NORMAL]);
sys_color_to_gtk_color(COLOR_SCROLLBAR, &style->bg[GTK_STATE_ACTIVE]);
sys_color_to_gtk_color(COLOR_3DFACE, &style->bg[GTK_STATE_PRELIGHT]);
sys_color_to_gtk_color(COLOR_HIGHLIGHT, &style->bg[GTK_STATE_SELECTED]);
sys_color_to_gtk_color(COLOR_3DFACE, &style->bg[GTK_STATE_INSENSITIVE]);
/* Default base */
sys_color_to_gtk_color(COLOR_WINDOW, &style->base[GTK_STATE_NORMAL]);
sys_color_to_gtk_color(COLOR_HIGHLIGHT, &style->base[GTK_STATE_ACTIVE]);
sys_color_to_gtk_color(COLOR_WINDOW, &style->base[GTK_STATE_PRELIGHT]);
sys_color_to_gtk_color(COLOR_HIGHLIGHT, &style->base[GTK_STATE_SELECTED]);
sys_color_to_gtk_color(COLOR_3DFACE, &style->base[GTK_STATE_INSENSITIVE]);
/* Default text */
sys_color_to_gtk_color(COLOR_WINDOWTEXT, &style->text[GTK_STATE_NORMAL]);
sys_color_to_gtk_color(COLOR_HIGHLIGHTTEXT, &style->text[GTK_STATE_ACTIVE]);
sys_color_to_gtk_color(COLOR_WINDOWTEXT, &style->text[GTK_STATE_PRELIGHT]);
sys_color_to_gtk_color(COLOR_HIGHLIGHTTEXT, &style->text[GTK_STATE_SELECTED]);
sys_color_to_gtk_color(COLOR_GRAYTEXT, &style->text[GTK_STATE_INSENSITIVE]);
/* Prelight */
sys_color_to_gtk_color(COLOR_HIGHLIGHTTEXT, &fg_prelight);
sys_color_to_gtk_color(COLOR_HIGHLIGHT, &bg_prelight);
@ -382,20 +357,6 @@ setup_system_styles(GtkStyle *style)
/* progress bar background color */
sys_color_to_gtk_color(COLOR_HIGHLIGHT, &progress_back);
for (i = 0; i < 5; i++)
{
sys_color_to_gtk_color(COLOR_3DSHADOW, &style->dark[i]);
sys_color_to_gtk_color(COLOR_3DHILIGHT, &style->light[i]);
style->mid[i].red = (style->light[i].red + style->dark[i].red) / 2;
style->mid[i].green = (style->light[i].green + style->dark[i].green) / 2;
style->mid[i].blue = (style->light[i].blue + style->dark[i].blue) / 2;
style->text_aa[i].red = (style->text[i].red + style->base[i].red) / 2;
style->text_aa[i].green = (style->text[i].green + style->base[i].green) / 2;
style->text_aa[i].blue = (style->text[i].blue + style->base[i].blue) / 2;
}
/* Enable coloring for menus. */
font_ptr = sys_font_to_pango_font (MENU_FONT,font_buf);
sprintf(buf, "style \"wimp-menu\" = \"wimp-default\"\n"
@ -519,6 +480,54 @@ setup_system_styles(GtkStyle *style)
gtk_rc_parse_string(buf);
}
static void
setup_system_styles(GtkStyle *style)
{
int i;
/* Default forgeground */
sys_color_to_gtk_color(COLOR_WINDOWTEXT, &style->fg[GTK_STATE_NORMAL]);
sys_color_to_gtk_color(COLOR_WINDOWTEXT, &style->fg[GTK_STATE_ACTIVE]);
sys_color_to_gtk_color(COLOR_WINDOWTEXT, &style->fg[GTK_STATE_PRELIGHT]);
sys_color_to_gtk_color(COLOR_HIGHLIGHTTEXT, &style->fg[GTK_STATE_SELECTED]);
sys_color_to_gtk_color(COLOR_GRAYTEXT, &style->fg[GTK_STATE_INSENSITIVE]);
/* Default background */
sys_color_to_gtk_color(COLOR_3DFACE, &style->bg[GTK_STATE_NORMAL]);
sys_color_to_gtk_color(COLOR_SCROLLBAR, &style->bg[GTK_STATE_ACTIVE]);
sys_color_to_gtk_color(COLOR_3DFACE, &style->bg[GTK_STATE_PRELIGHT]);
sys_color_to_gtk_color(COLOR_HIGHLIGHT, &style->bg[GTK_STATE_SELECTED]);
sys_color_to_gtk_color(COLOR_3DFACE, &style->bg[GTK_STATE_INSENSITIVE]);
/* Default base */
sys_color_to_gtk_color(COLOR_WINDOW, &style->base[GTK_STATE_NORMAL]);
sys_color_to_gtk_color(COLOR_HIGHLIGHT, &style->base[GTK_STATE_ACTIVE]);
sys_color_to_gtk_color(COLOR_WINDOW, &style->base[GTK_STATE_PRELIGHT]);
sys_color_to_gtk_color(COLOR_HIGHLIGHT, &style->base[GTK_STATE_SELECTED]);
sys_color_to_gtk_color(COLOR_3DFACE, &style->base[GTK_STATE_INSENSITIVE]);
/* Default text */
sys_color_to_gtk_color(COLOR_WINDOWTEXT, &style->text[GTK_STATE_NORMAL]);
sys_color_to_gtk_color(COLOR_HIGHLIGHTTEXT, &style->text[GTK_STATE_ACTIVE]);
sys_color_to_gtk_color(COLOR_WINDOWTEXT, &style->text[GTK_STATE_PRELIGHT]);
sys_color_to_gtk_color(COLOR_HIGHLIGHTTEXT, &style->text[GTK_STATE_SELECTED]);
sys_color_to_gtk_color(COLOR_GRAYTEXT, &style->text[GTK_STATE_INSENSITIVE]);
for (i = 0; i < 5; i++)
{
sys_color_to_gtk_color(COLOR_3DSHADOW, &style->dark[i]);
sys_color_to_gtk_color(COLOR_3DHILIGHT, &style->light[i]);
style->mid[i].red = (style->light[i].red + style->dark[i].red) / 2;
style->mid[i].green = (style->light[i].green + style->dark[i].green) / 2;
style->mid[i].blue = (style->light[i].blue + style->dark[i].blue) / 2;
style->text_aa[i].red = (style->text[i].red + style->base[i].red) / 2;
style->text_aa[i].green = (style->text[i].green + style->base[i].green) / 2;
style->text_aa[i].blue = (style->text[i].blue + style->base[i].blue) / 2;
}
}
static gboolean
sanitize_size (GdkWindow *window,
gint *width,
@ -1515,16 +1524,9 @@ wimp_style_init_from_rc (GtkStyle * style, GtkRcStyle * rc_style)
{
setup_system_font (style);
setup_system_styles (style);
setup_system_settings (style);
parent_class->init_from_rc(style, rc_style);
}
static void
wimp_style_init (WimpStyle * style)
{
xp_theme_init ();
}
static void
wimp_style_class_init (WimpStyleClass *klass)
{
@ -1563,7 +1565,7 @@ wimp_style_register_type (GTypeModule *module)
NULL, /* class_data */
sizeof (WimpStyle),
0, /* n_preallocs */
(GInstanceInitFunc) wimp_style_init,
(GInstanceInitFunc) NULL,
};
wimp_type_style = g_type_module_register_type (module,
@ -1571,3 +1573,11 @@ wimp_style_register_type (GTypeModule *module)
"WimpStyle",
&object_info, 0);
}
void
wimp_init (void)
{
xp_theme_init ();
setup_system_settings ();
setup_wimp_rc_style ();
}

View File

@ -48,5 +48,6 @@ struct _WimpStyleClass
};
void wimp_style_register_type (GTypeModule *module);
void wimp_style_init (void);
#endif /* WIMP_TYPE_STYLE */

View File

@ -43,6 +43,7 @@ global_filter_func (void *xevent,
case WM_THEMECHANGED:
case WM_SYSCOLORCHANGE:
xp_theme_exit();
wimp_init ();
gtk_rc_reparse_all_for_settings (gtk_settings_get_default(), TRUE);
return GDK_FILTER_REMOVE;
default:
@ -56,6 +57,7 @@ theme_init (GTypeModule *module)
wimp_rc_style_register_type (module);
wimp_style_register_type (module);
wimp_init ();
gdk_window_add_filter (NULL, global_filter_func, NULL);
}