2
#include "smooth_rc_style.h"
3
#include "smooth_style.h"
5
/* Main Theme Functions */
8
theme_init (GTypeModule *module)
10
smooth_rc_style_register_type (module);
11
smooth_style_register_type (module);
17
cleanup_gdk_pixbuf_cache(TRUE);
20
G_MODULE_EXPORT GtkRcStyle *
21
theme_create_rc_style (void)
25
ptr = GTK_RC_STYLE (g_object_new (SMOOTH_TYPE_RC_STYLE, NULL));
26
return (GtkRcStyle *)ptr;
29
/* The following function will be called by GTK+ when the module
30
* is loaded and checks to see if we are compatible with the
31
* version of GTK+ that loads us.
33
G_MODULE_EXPORT const gchar *g_module_check_init (GModule * module);
37
g_module_check_init (GModule * module)
39
return gtk_check_version (GTK_MAJOR_VERSION,
41
GTK_MICRO_VERSION - GTK_INTERFACE_AGE);
44
/* Style Function Overrides */
47
draw_shadow(GtkStyle * style,
49
GtkStateType state_type,
50
GtkShadowType shadow_type,
59
g_return_if_fail(sanitize_parameters(style, window, &width, &height));
61
if (!(widget) || (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR))
62
smooth_draw_shadow(style, window, state_type, shadow_type, area, widget, detail, x, y, width, height, GTK_POS_RIGHT);
64
smooth_draw_shadow(style, window, state_type, shadow_type, area, widget, detail, x, y, width, height, GTK_POS_LEFT);
68
draw_hline(GtkStyle * style,
70
GtkStateType state_type,
78
g_return_if_fail(sanitize_parameters(style, window, NULL, NULL));
80
smooth_draw_line(style, window, state_type, area, widget, detail, x1, x2, y, GTK_ORIENTATION_HORIZONTAL);
85
draw_vline(GtkStyle * style,
87
GtkStateType state_type,
95
g_return_if_fail(sanitize_parameters(style, window, NULL, NULL));
97
smooth_draw_line(style, window, state_type, area, widget, detail, y1, y2, x, GTK_ORIENTATION_VERTICAL);
101
draw_polygon(GtkStyle * style,
103
GtkStateType state_type,
104
GtkShadowType shadow_type,
107
detail_char * detail,
112
g_return_if_fail(sanitize_parameters(style, window, NULL, NULL));
114
smooth_draw_polygon(style, window, state_type, shadow_type, area, widget, detail, points, npoints, fill);
118
draw_arrow(GtkStyle * style,
120
GtkStateType state_type,
121
GtkShadowType shadow_type,
124
detail_char * detail,
125
GtkArrowType arrow_type,
134
g_return_if_fail(sanitize_parameters(style, window, &width, &height));
136
reverse_engineer_arrow_box (widget, detail, arrow_type, &x, &y, &width, &height);
138
x+=ARROW_XPADDING(style);
139
y+=ARROW_YPADDING(style);
140
width-=2*ARROW_XPADDING(style);
141
height-=2*ARROW_YPADDING(style);
143
smooth_draw_arrow(style, window, state_type, shadow_type, area, widget, detail, arrow_type, fill, x, y, width, height);
147
draw_focus(GtkStyle *style,
149
GtkStateType state_type,
158
gboolean free_dash_list = FALSE;
160
gint8 *dash_list = NULL;
163
g_return_if_fail(sanitize_parameters(style, window, &width, &height));
167
if (FOCUS_USE_PATTERN(style, state_type))
168
gtk_widget_style_get (widget,
169
"focus-line-width", &line_width,
172
gtk_widget_style_get (widget,
173
"focus-line-width", &line_width,
174
"focus-line-pattern", (gchar *)&dash_list,
177
free_dash_list = TRUE;
181
smooth_draw_focus(style, window, state_type, area, widget, detail, x, y, width, height, dash_list, line_width);
189
draw_slider(GtkStyle * style,
191
GtkStateType state_type,
192
GtkShadowType shadow_type,
195
detail_char * detail,
200
GtkOrientation orientation)
202
g_return_if_fail(sanitize_parameters(style, window, &width, &height));
204
smooth_draw_slider(style, window, state_type, shadow_type, area, widget, detail, x, y, width, height, orientation);
208
draw_extension(GtkStyle * style,
210
GtkStateType state_type,
211
GtkShadowType shadow_type,
214
detail_char * detail,
219
GtkPositionType gap_side)
221
g_return_if_fail(sanitize_parameters(style, window, &width, &height));
223
smooth_draw_extension(style, window, state_type, shadow_type, area, widget, detail, x, y, width, height, gap_side);
226
static const GtkBorder default_default_border = { 1, 1, 1, 1 };
227
static const GtkBorder default_default_outside_border = { 0, 0, 0, 0 };
230
gtk_button_get_props (GtkWidget *widget,
231
GtkBorder *default_border,
232
GtkBorder *default_outside_border,
233
gboolean *interior_focus)
235
GtkBorder *tmp_border;
239
gtk_widget_style_get (widget, "default_border", &tmp_border, NULL);
243
*default_border = *tmp_border;
247
*default_border = default_default_border;
250
if (default_outside_border)
252
gtk_widget_style_get (widget, "default_outside_border", &tmp_border, NULL);
256
*default_outside_border = *tmp_border;
260
*default_outside_border = default_default_outside_border;
264
gtk_widget_style_get (widget, "interior_focus", interior_focus, NULL);
268
draw_box(GtkStyle * style,
270
GtkStateType state_type,
271
GtkShadowType shadow_type,
274
detail_char * detail,
280
GtkOrientation orientation;
282
g_return_if_fail(sanitize_parameters(style, window, &width, &height));
284
if (DETAIL("buttondefault"))
288
gint border_width = GTK_CONTAINER (widget)->border_width;
289
GtkBorder default_border;
290
GtkBorder default_outside_border;
291
gboolean interior_focus;
295
gtk_button_get_props (widget, &default_border, &default_outside_border, &interior_focus);
296
gtk_widget_style_get (widget,
297
"focus-line-width", &focus_width,
298
"focus-padding", &focus_pad,
301
button.x = widget->allocation.x + border_width + default_outside_border.left;
302
button.y = widget->allocation.y + border_width + default_outside_border.top;
303
button.width = (widget->allocation.width - border_width * 2) - (default_outside_border.left + default_outside_border.right);
304
button.height = (widget->allocation.height - border_width * 2) - (default_outside_border.top + default_outside_border.bottom);
308
button.x += focus_width + focus_pad;
309
button.y += focus_width + focus_pad;
310
button.width -= 2 * (focus_width + focus_pad);
311
button.height -= 2 * (focus_width + focus_pad);
314
smooth_draw_button_default(style, window, state_type, area, &button, widget, x, y, width, height);
319
if (DETAIL("togglebutton") || DETAIL("button") || DETAIL("spinbutton_up") || DETAIL("spinbutton_down") || GTK_IS_BUTTON(widget))
320
orientation = GTK_ORIENTATION_HORIZONTAL;
321
else if (DETAIL("hscrollbar"))
322
orientation = GTK_ORIENTATION_HORIZONTAL;
323
else if (DETAIL("vscrollbar"))
324
orientation = GTK_ORIENTATION_VERTICAL;
325
else if (DETAIL("menubar") || DETAIL("menuitem") || DETAIL("optionmenu") || DETAIL("optionmenutab") || DETAIL("metacity"))
326
orientation = GTK_ORIENTATION_HORIZONTAL;
327
else if (DETAIL("hruler"))
328
orientation = GTK_ORIENTATION_HORIZONTAL;
329
else if (DETAIL("vruler"))
330
orientation = GTK_ORIENTATION_VERTICAL;
331
else if (GTK_IS_PROGRESS_BAR(widget))
333
switch (GTK_PROGRESS_BAR(widget)->orientation) {
334
case GTK_PROGRESS_LEFT_TO_RIGHT:
335
case GTK_PROGRESS_RIGHT_TO_LEFT:
336
orientation = GTK_ORIENTATION_HORIZONTAL;
338
case GTK_PROGRESS_BOTTOM_TO_TOP:
339
case GTK_PROGRESS_TOP_TO_BOTTOM:
340
orientation = GTK_ORIENTATION_VERTICAL;
344
else if (GTK_IS_SCROLLBAR(widget))
345
orientation = (GTK_IS_VSCROLLBAR(widget))?GTK_ORIENTATION_VERTICAL:GTK_ORIENTATION_HORIZONTAL;
346
else if (GTK_IS_SCALE(widget))
347
orientation = (GTK_IS_VSCALE(widget))?GTK_ORIENTATION_VERTICAL:GTK_ORIENTATION_HORIZONTAL;
348
else if (height > width)
349
orientation = GTK_ORIENTATION_VERTICAL;
351
orientation = GTK_ORIENTATION_HORIZONTAL;
353
smooth_draw_box(style, window, state_type, shadow_type, area, widget, detail, x, y, width, height, orientation);
357
draw_box_gap (GtkStyle * style,
359
GtkStateType state_type,
360
GtkShadowType shadow_type,
363
detail_char * detail,
368
GtkPositionType gap_side,
372
g_return_if_fail(sanitize_parameters(style, window, &width, &height));
374
smooth_draw_box_gap(style, window, state_type, shadow_type, area, widget, detail, x, y, width, height, gap_side, gap_pos-1, gap_width+1);
378
draw_shadow_gap (GtkStyle * style,
380
GtkStateType state_type,
381
GtkShadowType shadow_type,
384
detail_char * detail,
389
GtkPositionType gap_side,
393
g_return_if_fail(sanitize_parameters(style, window, &width, &height));
395
smooth_draw_box_gap(style, window, state_type, shadow_type, area, widget, detail, x, y, width, height, gap_side, gap_pos, gap_width);
399
draw_option(GtkStyle * style,
401
GtkStateType state_type,
402
GtkShadowType shadow_type,
411
g_return_if_fail(sanitize_parameters(style, window, &width, &height));
413
smooth_draw_option(style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
417
draw_check(GtkStyle * style,
419
GtkStateType state_type,
420
GtkShadowType shadow_type,
423
detail_char * detail,
429
g_return_if_fail(sanitize_parameters(style, window, &width, &height));
431
smooth_draw_check(style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
435
draw_diamond(GtkStyle * style,
437
GtkStateType state_type,
438
GtkShadowType shadow_type,
441
detail_char * detail,
447
g_return_if_fail(sanitize_parameters(style, window, &width, &height));
449
smooth_draw_diamond(style, window, state_type, shadow_type, area, widget, detail, x, y, width, height);
453
draw_handle(GtkStyle * style,
455
GtkStateType state_type,
456
GtkShadowType shadow_type,
459
detail_char * detail,
464
GtkOrientation orientation)
466
GdkGC *light_gc, *dark_gc;
468
smooth_grip_style *grip;
469
gint ax=x, ay=y, aw=width, ah=height;
470
gboolean toolbar_overlap = (GRIP_OVERLAP_TOOLBAR(style) && (DETAIL("dockitem")));
471
gboolean horiz=(DETAIL("handlebox") || (DETAIL("dockitem") && !IS_HANDLE_BOX_ITEM(widget)))?(orientation==GTK_ORIENTATION_HORIZONTAL):(orientation==GTK_ORIENTATION_VERTICAL);
472
gint gap_size=(!horiz)?y+height:x+width;
473
gboolean vert=(!horiz);
474
g_return_if_fail(sanitize_parameters(style, window, &width, &height));
478
grip = GRIP_PART(style);
480
if (!GTK_IS_PANED(widget)) {
483
thick = EDGE_LINE_THICKNESS(style, NULL)*2;
484
gradient_fill_background(style, window, state_type, area, widget, THEME_PART(grip), x, y, width+thick*horiz, height+thick*vert, shadow_type == GTK_SHADOW_IN, orientation);
486
FLAT_FILL_BACKGROUND(style, window, state_type, area, widget, THEME_PART(grip), x, y, width, height);
488
switch (PART_STYLE(grip)) {
494
gint w=width, h=height;
497
if (DETAIL("handlebox")) {
501
if (DETAIL("dockitem")) {
503
h = MIN(height+1, width + height/7);
504
y = y + (height - h)/2;
505
orientation = GTK_ORIENTATION_HORIZONTAL;
506
if (!toolbar_overlap) y -=1;
511
w = MIN(width+1, width/7 + height);
512
x = x + (width - w)/2;
515
if (DETAIL("handlebox")) {
518
orientation = GTK_ORIENTATION_VERTICAL;
520
if (DETAIL("dockitem")) {
522
w = MIN(width+1, width/7 + height);
523
x = x + (width - w)/2;
524
orientation = GTK_ORIENTATION_VERTICAL;
525
if (!toolbar_overlap) x -=1;
529
h = MIN(height+1, width + height/7);
530
y = y + (height - h)/2;
539
case LINES_OUT_GRIP :
541
gint w=width, h=height;
545
h = MIN(height+1, width + height/7);
546
y = y + (height - h)/2;
547
if ((GTK_IS_PANED(widget)) || (GTK_IS_RANGE(widget))) orientation = GTK_ORIENTATION_HORIZONTAL;
548
if (!GRIP_OVERLAP_TOOLBAR(style) && DETAIL("dockitem")) y -=1;
550
w = MIN(width+1, width/7 + height);
551
x = x + (width - w)/2;
552
if ((GTK_IS_PANED(widget)) || (GTK_IS_RANGE(widget))) orientation = GTK_ORIENTATION_VERTICAL;
553
if (!GRIP_OVERLAP_TOOLBAR(style) && DETAIL("dockitem")) x -=1;
556
if (DETAIL("dockitem") || DETAIL("handlebox"))
557
orientation = GTK_ORIENTATION_VERTICAL;
566
case SMALLDOTS_IN_GRIP :
567
case SMALLDOTS_OUT_GRIP :
568
if (DETAIL("dockitem") || DETAIL("handlebox"))
569
orientation = GTK_ORIENTATION_VERTICAL;
571
case FIXEDLINES_OUT_GRIP:
572
case FIXEDLINES_IN_GRIP:
573
if (DETAIL("dockitem") || DETAIL("handlebox"))
574
orientation = GTK_ORIENTATION_VERTICAL;
576
case MAC_BUDS_IN_GRIP:
577
case MAC_BUDS_OUT_GRIP:
578
case NS_BUDS_IN_GRIP:
579
case NS_BUDS_OUT_GRIP:
584
orientation = GTK_ORIENTATION_VERTICAL;
588
smooth_draw_grip(style, window, state_type, area, x+PART_XPADDING(grip), y+PART_YPADDING(grip), width-PART_XPADDING(grip)*2, height-PART_YPADDING(grip)*2, orientation);
590
switch (PART_STYLE(grip)) {
594
case LINES_OUT_GRIP :
601
case MAC_BUDS_IN_GRIP:
602
case MAC_BUDS_OUT_GRIP:
603
case NS_BUDS_IN_GRIP:
604
case NS_BUDS_OUT_GRIP:
612
if ((THEME_PART(grip)->use_line || THEME_PART(grip)->edge.use_line)) {
616
thick = EDGE_LINE_THICKNESS(style, grip)*2;
620
smooth_draw_shadow_with_gap(style, window, state_type, shadow_type, area, widget, detail, THEME_PART(grip), x, y, width+horiz*thick, height+vert*thick, vert?GTK_POS_BOTTOM:GTK_POS_RIGHT, 0, gap_size);
625
thick = EDGE_LINE_THICKNESS(style, NULL)*2;
629
smooth_draw_shadow_with_gap(style, window, state_type, shadow_type, area, widget, detail, NULL, x, y, width+horiz*thick, height+vert*thick, vert?GTK_POS_BOTTOM:GTK_POS_RIGHT, 0, gap_size);
633
static void make_square(gint * value1, gint * value2)
635
if (*value1 < *value2)
639
static void make_square_offset(gint * value1, gint * value2, gint * value3)
641
if (*value1 < *value2)
643
*value3 += (*value1 - *value2);
649
draw_resize_grip (GtkStyle *style,
651
GtkStateType state_type,
661
g_return_if_fail (GTK_IS_STYLE (style));
662
g_return_if_fail (window != NULL);
664
if (widget && GTK_IS_STATUSBAR(widget) && !RESIZE_GRIP(style)) {
665
gtk_statusbar_set_has_resize_grip(GTK_STATUSBAR(widget), FALSE);
671
gdk_gc_set_clip_rectangle (style->light_gc[state_type], area);
672
gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
673
gdk_gc_set_clip_rectangle (style->bg_gc[state_type], area);
678
case GDK_WINDOW_EDGE_WEST:
679
case GDK_WINDOW_EDGE_EAST:
683
if (edge==GDK_WINDOW_EDGE_WEST)
684
make_square(&height, &width);
686
make_square_offset(&height, &width, &x);
690
while (xi < x + width)
692
gdk_draw_line (window,
693
style->light_gc[state_type],
698
gdk_draw_line (window,
699
style->dark_gc[state_type],
707
case GDK_WINDOW_EDGE_NORTH:
708
case GDK_WINDOW_EDGE_SOUTH:
712
if (edge==GDK_WINDOW_EDGE_NORTH)
713
make_square(&width, &height);
715
make_square_offset(&width, &height, &y);
719
while (yi < y + height)
721
gdk_draw_line (window,
722
style->light_gc[state_type],
727
gdk_draw_line (window,
728
style->dark_gc[state_type],
736
case GDK_WINDOW_EDGE_NORTH_WEST:
740
make_square(&width, &height);
741
make_square(&height, &width);
748
gdk_draw_line (window,
749
style->dark_gc[state_type],
756
gdk_draw_line (window,
757
style->dark_gc[state_type],
764
gdk_draw_line (window,
765
style->light_gc[state_type],
775
case GDK_WINDOW_EDGE_NORTH_EAST:
779
make_square(&width, &height);
780
make_square_offset(&height, &width, &x);
785
while (xi < (x + width - 3))
787
gdk_draw_line (window,
788
style->light_gc[state_type],
795
gdk_draw_line (window,
796
style->dark_gc[state_type],
803
gdk_draw_line (window,
804
style->dark_gc[state_type],
813
case GDK_WINDOW_EDGE_SOUTH_WEST:
817
make_square_offset(&width, &height, &y);
818
make_square(&height, &width);
825
gdk_draw_line (window,
826
style->dark_gc[state_type],
833
gdk_draw_line (window,
834
style->dark_gc[state_type],
841
gdk_draw_line (window,
842
style->light_gc[state_type],
852
case GDK_WINDOW_EDGE_SOUTH_EAST:
856
make_square_offset(&width, &height, &y);
857
make_square_offset(&height, &width, &x);
862
while (xi < (x + width - 3))
864
gdk_draw_line (window,
865
style->light_gc[state_type],
872
gdk_draw_line (window,
873
style->dark_gc[state_type],
880
gdk_draw_line (window,
881
style->dark_gc[state_type],
897
gdk_gc_set_clip_rectangle (style->light_gc[state_type], NULL);
898
gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
899
gdk_gc_set_clip_rectangle (style->bg_gc[state_type], NULL);
903
static const GtkRequisition default_option_indicator_size = { 7, 13 };
904
static const GtkBorder default_option_indicator_spacing = { 7, 5, 2, 2 };
907
option_menu_get_props (GtkWidget *widget,
908
GtkRequisition *indicator_size,
909
GtkBorder *indicator_spacing)
911
GtkRequisition *tmp_size = NULL;
912
GtkBorder *tmp_spacing = NULL;
915
gtk_widget_style_get (widget,
916
"indicator_size", &tmp_size,
917
"indicator_spacing", &tmp_spacing,
922
*indicator_size = *tmp_size;
926
*indicator_size = default_option_indicator_size;
930
*indicator_spacing = *tmp_spacing;
931
g_free (tmp_spacing);
934
*indicator_spacing = default_option_indicator_spacing;
938
draw_tab (GtkStyle *style,
940
GtkStateType state_type,
941
GtkShadowType shadow_type,
950
#define ARROW_SPACE 0
952
GtkRequisition indicator_size;
953
GtkBorder indicator_spacing;
955
gboolean solid = SOLID_ARROW(style);
956
GdkGC * border_gc = style->fg_gc[state_type], * fill_gc = style->fg_gc[state_type];
959
g_return_if_fail(sanitize_parameters(style, window, &width, &height));
961
alternate = ARROW_STYLE(style);
964
fill_gc = style->base_gc[state_type];
966
option_menu_get_props (widget, &indicator_size, &indicator_spacing);
968
indicator_size.width += 2;
969
arrow_height = indicator_size.width;
971
x += (width - indicator_size.width) / 2;
972
y += (height - (2 * arrow_height + ARROW_SPACE)) / 2;
974
if (state_type == GTK_STATE_INSENSITIVE)
977
border_gc = style->dark_gc[state_type];
978
fill_gc = style->dark_gc[state_type];
979
do_draw_arrow(window, area, GTK_ARROW_UP, style->light_gc[state_type], style->light_gc[state_type], x+1, y+1, indicator_size.width, arrow_height, alternate);
980
do_draw_arrow(window, area, GTK_ARROW_DOWN, style->light_gc[state_type], style->light_gc[state_type], x+1, y + arrow_height + ARROW_SPACE + 1, indicator_size.width, arrow_height, alternate);
983
do_draw_arrow(window, area, GTK_ARROW_UP, fill_gc, border_gc, x, y, indicator_size.width, arrow_height, alternate);
984
do_draw_arrow(window, area, GTK_ARROW_DOWN, fill_gc, border_gc, x, y + arrow_height + ARROW_SPACE, indicator_size.width, arrow_height, alternate);
988
draw_flat_box (GtkStyle * style,
990
GtkStateType state_type,
991
GtkShadowType shadow_type,
994
const gchar * detail,
995
gint x, gint y, gint width, gint height)
997
g_return_if_fail(sanitize_parameters(style, window, &width, &height));
999
/* we always want call to the default for treeviews and such */
1001
if ((DETAIL("text")) || (DETAIL("viewportbin")) || (DETAIL("entry_bg")) || ((DETAIL("cell_even")) ||
1002
(DETAIL("cell_odd")) || (DETAIL("cell_even_ruled")) || (DETAIL("cell_odd_ruled")) || (DETAIL("cell_even_sorted")) ||
1003
(DETAIL("cell_odd_sorted")) || (DETAIL("cell_even_ruled_sorted")) || (DETAIL("cell_odd_ruled_sorted"))))
1005
parent_class->draw_flat_box (style, window, state_type, shadow_type,
1006
area, widget, detail, x, y, width, height);
1009
FLAT_FILL_BACKGROUND(style, window, state_type, area, widget, NULL, x, y, width, height);
1011
if (DETAIL("tooltip"))
1012
gdk_draw_rectangle(window, style->dark_gc[state_type], FALSE, x, y, width - 1, height - 1);
1017
smooth_style_class_init (SmoothStyleClass *klass)
1019
GtkStyleClass *style_class = GTK_STYLE_CLASS (klass);
1021
parent_class = g_type_class_peek_parent (klass);
1023
style_class->draw_hline = draw_hline;
1024
style_class->draw_vline = draw_vline;
1025
style_class->draw_shadow = draw_shadow;
1027
style_class->draw_polygon = draw_polygon;
1028
style_class->draw_diamond = draw_diamond;
1030
style_class->draw_box = draw_box;
1031
style_class->draw_flat_box = draw_flat_box;
1032
style_class->draw_check = draw_check;
1033
style_class->draw_option = draw_option;
1034
style_class->draw_tab = draw_tab;
1035
style_class->draw_shadow_gap = draw_shadow_gap;
1036
style_class->draw_box_gap = draw_box_gap;
1037
style_class->draw_extension = draw_extension;
1038
style_class->draw_slider = draw_slider;
1039
style_class->draw_handle = draw_handle;
1041
style_class->draw_focus = draw_focus;
1043
style_class->draw_arrow = draw_arrow;
1044
style_class->draw_resize_grip = draw_resize_grip;
1047
GType smooth_type_style = 0;
1050
smooth_style_register_type (GTypeModule *module)
1052
static const GTypeInfo object_info =
1054
sizeof (SmoothStyleClass),
1055
(GBaseInitFunc) NULL,
1056
(GBaseFinalizeFunc) NULL,
1057
(GClassInitFunc) smooth_style_class_init,
1058
NULL, /* class_finalize */
1059
NULL, /* class_data */
1060
sizeof (SmoothStyle),
1061
0, /* n_preallocs */
1062
(GInstanceInitFunc) NULL,
1065
smooth_type_style = g_type_module_register_type (module,