Make testgtk load CSS for custom styling.

This commit is contained in:
Carlos Garnacho 2010-11-13 21:19:41 +01:00
parent 9ffaf1122d
commit 37f9f491d2
6 changed files with 77 additions and 272 deletions

View File

@ -396,8 +396,8 @@ testswitch_SOURCES = testswitch.c
EXTRA_DIST += \
prop-editor.h \
testgtk.1 \
testgtkrc \
testgtkrc2 \
testgtk.css \
testgtk2.css \
3DRings.xpm \
FilesQueue.xpm \
Modeller.xpm \

View File

@ -9985,7 +9985,7 @@ create_main_window (void)
int i;
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_widget_set_name (window, "main window");
gtk_widget_set_name (window, "main_window");
gtk_window_move (GTK_WINDOW (window), 50, 20);
gtk_window_set_default_size (GTK_WINDOW (window), -1, 400);
@ -10188,6 +10188,9 @@ usage (void)
int
main (int argc, char *argv[])
{
GtkCssProvider *provider, *memory_provider;
GdkDisplay *display;
GdkScreen *screen;
GtkBindingSet *binding_set;
int i;
gboolean done_benchmarks = FALSE;
@ -10196,20 +10199,29 @@ main (int argc, char *argv[])
test_init ();
/* Check to see if we are being run from the correct
* directory.
*/
if (file_exists ("testgtkrc"))
gtk_rc_add_default_file ("testgtkrc");
else if (file_exists ("tests/testgtkrc"))
gtk_rc_add_default_file ("tests/testgtkrc");
else
g_warning ("Couldn't find file \"testgtkrc\".");
g_set_application_name ("GTK+ Test Program");
gtk_init (&argc, &argv);
provider = gtk_css_provider_new ();
/* Check to see if we are being run from the correct
* directory.
*/
if (file_exists ("testgtk.css"))
gtk_css_provider_load_from_path (provider, "testgtk.css", NULL);
else if (file_exists ("tests/testgtkrc"))
gtk_css_provider_load_from_path (provider, "tests/testgtk.css", NULL);
else
g_warning ("Couldn't find file \"testgtk.css\".");
display = gdk_display_get_default ();
screen = gdk_display_get_default_screen (display);
gtk_style_context_add_provider_for_screen (screen, GTK_STYLE_PROVIDER (provider),
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
g_object_unref (provider);
gtk_accelerator_set_default_mod_mask (GDK_SHIFT_MASK |
GDK_CONTROL_MASK |
GDK_MOD1_MASK |
@ -10268,17 +10280,17 @@ main (int argc, char *argv[])
"debug_msg",
1,
G_TYPE_STRING, "GtkWidgetClass <ctrl><release>9 test");
/* We use gtk_rc_parse_string() here so we can make sure it works across theme
* changes
*/
gtk_rc_parse_string ("style \"testgtk-version-label\" { "
" fg[NORMAL] = \"#ff0000\"\n"
" font = \"Sans 18\"\n"
"}\n"
"widget \"*.testgtk-version-label\" style \"testgtk-version-label\"");
memory_provider = gtk_css_provider_new ();
gtk_css_provider_load_from_data (memory_provider,
"#testgtk-version-label {\n"
" color: #f00;\n"
" font: Sans 18;\n"
"}",
-1, NULL);
gtk_style_context_add_provider_for_screen (screen, GTK_STYLE_PROVIDER (memory_provider),
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION + 1);
create_main_window ();
gtk_main ();

33
tests/testgtk.css Normal file
View File

@ -0,0 +1,33 @@
/* testgtk2.css sets all the buttons in the main window to blue by default */
@import url(testgtk2.css);
* {
-GtkButton-child-displacement-x: 1;
-GtkButton-child-displacement-y: 1;
-GtkToolbar-space-size: 10;
-GtkToolbar-space-style: line;
-GtkToolbar-button-relief: none;
-GtkButtonBox-child-min-width: 0;
-GtkButtonBox-child-min-height: 0;
-GtkArrow-arrow-scaling: 1.0;
-GtkEntry-invisible-char: 10046;
font: Sans 12;
-Gtest-foo: 47;
-Gtest-bar: 47;
}
GtkLabel:selected {
background-color: gray;
}
GtkLabel:prelight {
background-color: mix (#a0a0a0, rgb (75%, 200, 0%), 0.9);
}
/* override testgtk2, introduce the green color in the button list */
#main_window GtkScrolledWindow GtkButton:prelight {
background-color: rgb (0%, 75%, 0);
}

9
tests/testgtk2.css Normal file
View File

@ -0,0 +1,9 @@
/* this file gets included from testgtk.css */
#main_window GtkButton {
font: Monospace 10;
}
#main_window GtkButton:hover {
background-color: rgba(0%, 0%, 75%, 0.1);
}

View File

@ -1,228 +0,0 @@
# pixmap_path "<dir 1>:<dir 2>:<dir 3>:..."
#
# include "rc-file"
#
# style <name> [= <name>]
# {
# <option>
# }
#
# widget <widget_set> style <style_name>
# widget_class <widget_class_set> style <style_name>
# testgtkrc2 sets all the buttons in the main window to blue by default
include "testgtkrc2"
double-click_timeout = 42
bell-duration = 39
bell_duration = 40
# gtk-cursor-blink-time = 200
# gtk-menu-bar-accel = F10
style "global-style-properties"
{
# xthickness = 20
GtkButton::child_displacement_x = 1
GtkButton::child_displacement_y = 1
# GtkWidget::cursor_color = "#ff0000"
GtkToolbar::space_size = 10
GtkToolbar::space_style = line
GtkToolbar::button_relief = none
GtkButtonBox::child_min_width = 0
GtkButtonBox::child_min_height = 0
GtkArrow::arrow-scaling = 1.0
GtkEntry::invisible-char = 10046
}
class "GtkWidget" style "global-style-properties"
style "defaultfont"
{
font_name = "Sans 12"
Gtest::foo = 47
Gtest::bar = 47
# GtkScrollbar::spacing = 33
# GtkButton::color = { 3, 2,45, 6, 6, 4, 23 }
}
style "myicons"
{
stock["gtk-dialog-warning"] =
{
{ "3DRings.xpm", *, *, *}
}
}
class "GtkImage" style "myicons"
# common default
class "GtkWidget" style "defaultfont"
style "window"
{
# bg_pixmap[NORMAL] = "marble.xpm"
}
style "scale"
{
fg[NORMAL] = { 1.0, 0, 0 }
bg_pixmap[NORMAL] = "<parent>"
}
style "button" = "default"
{
# fg[PRELIGHT] = { 1.0, 1.0, 1.0 }
# bg[PRELIGHT] = { 0, 0, 0.75 }
# bg[PRELIGHT] = { 0.75, 0, 0x00 }
}
style "label" = "default"
{
base[PRELIGHT] = "gray"
base[ACTIVE] = mix (0.9, "gray", "purple")
}
class "GtkLabel" style "label"
style "toggle_button" = "button"
{
fg[NORMAL] = { 1.0, 0, 0 }
fg[ACTIVE] = { 1.0, 0, 0 }
# bg_pixmap[ACTIVE] = "check-y.xpm"
# bg_pixmap[NORMAL] = "check-n.xpm"
}
style "text"
{
bg_pixmap[NORMAL] = "marble.xpm"
text[NORMAL] = { 1.0, 1.0, 1.0 }
fg[NORMAL] = { 1.0, 1.0, 1.0 }
base[NORMAL] = { 0.0, 0.0, 0.0 }
}
style "slider"
{
fg[NORMAL] = { 1.0, 1.0, 1.0 }
bg[NORMAL] = { 0.0, 0.0, 1.0 }
bg[ACTIVE] = { 0.0 ,0.0, 0.5 }
bg[PRELIGHT] = { 0.75 ,0.75, 1.0 }
}
style "ruler"
{
font_name = 'Sans 8'
}
style "curve"
{
fg[NORMAL] = { 58000, 0, 0 } # red
}
style "red-bar-parent"
{
color["my-red"] = "red"
color["my-other-red"] = { 0.95, .55, 0.55 }
}
style "red-bar" = "red-bar-parent"
{
color["my-light-red"] = lighter (lighter (@my-red))
bg[PRELIGHT] = @my-light-red
}
# override testgtk2, introduce the green color in the button list
style 'button_list' = 'button'
{
font_name = "Monospace 10"
bg[PRELIGHT] = { 0, 0.75, 0x00 }
}
widget "main window.*GtkScrolledWindow.*GtkButton*" style "button_list"
style "checkbutton" {
# GtkCheckButton::indicator-size = 27
}
class "GtkCheckButton" style "checkbutton"
class "GtkScrollbar" style "red-bar"
widget_class "GtkWindow" style "window"
widget_class "GtkDialog" style "window"
widget_class "GtkFileSelection" style "window"
widget_class "*Gtk*Scale" style "scale"
widget_class "*GtkCheckButton*" style "toggle_button"
widget_class "*GtkRadioButton*" style "toggle_button"
widget_class "*GtkButton*" style "button"
widget_class "*Ruler" style "ruler"
widget_class "*GtkText" style "text"
binding "test1"
{
bind "<ctrl>1" {
"debug-msg" ("jup!")
}
}
binding "test2"
{
bind "<ctrl>1" {
"debug-msg" ("hallo and")
"debug-msg" ("huhu")
}
}
# possible priorities are (in ascending order):
# lowest
# gtk (used by gtk for internal class bindings)
# application (for hard coded bindings on application basis)
# rc (used implicitel by rc files)
# highest
class "GtkCList" binding "test1" # implicit : rc
#class "GtkWindow" binding : highest "test2" # override "rc" priority
binding "clist-test"
{
bind "j" {
"scroll-vertical" (step-backward, 0.0)
}
bind "k" {
"scroll-vertical" (step-forward, 0.0)
}
}
class "GtkCList" binding "clist-test"
style "testthickness" {
xthickness = 15
ythickness = 15
}
#class "GtkFrame" style "testthickness"
# Test ordering of RC file priorities
style "testgtk-red-style" {
fg[NORMAL] = "red"
}
style "testgtk-green-style" {
fg[NORMAL] = "green"
}
style "testgtk-blue-style" {
fg[NORMAL] = "blue"
}
widget_class "*.GtkAspectFrame.*.GtkLabel" style "testgtk-green-style"
widget_class "*.GtkAspectFrame.*.GtkLabel" style "testgtk-blue-style" # override because it's later
widget "*.testgtk-red-label" style "testgtk-red-style" # override because it's widget, not widget_class
widget "*.testgtk-green-label" style : highest "testgtk-green-style"
# overrides the following, because it is higher priority
widget "*.testgtk-green-label" style "testgtk-red-style"

View File

@ -1,21 +0,0 @@
# pixmap_path "<dir 1>:<dir 2>:<dir 3>:..."
#
# include "rc-file"
#
# style <name> [= <name>]
# {
# <option>
# }
#
# widget <widget_set> style <style_name>
# widget_class <widget_class_set> style <style_name>
# this file gets included from testgtkrc
style 'main_buttons' = 'button'
{
font_name = "Monospace 10"
bg[PRELIGHT] = { 0, 0, 0.75 }
}
widget "main window.*GtkButton*" style "main_buttons"