Merge old a new signals code into one set of classes.
[ardour.git] / libs / clearlooks-newer / clearlooks_style.c
1 /* Clearlooks theme engine
2  * Copyright (C) 2005 Richard Stellingwerff.
3  * Copyright (C) 2007 Benjamin Berg <benjamin@sipsolutions.net>.
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  *
20  */
21
22 #include <gtk/gtk.h>
23 #include <cairo.h>
24 #include <math.h>
25 #include <string.h>
26
27 #include <ge-support.h>
28 #include "clearlooks_style.h"
29 #include "clearlooks_rc_style.h"
30 #include "clearlooks_draw.h"
31 #include "support.h"
32
33 /* #define DEBUG 1 */
34
35 #define DETAIL(xx)   ((detail) && (!strcmp(xx, detail)))
36
37 #define DRAW_ARGS    GtkStyle       *style, \
38                      GdkWindow      *window, \
39                      GtkStateType    state_type, \
40                      GtkShadowType   shadow_type, \
41                      GdkRectangle   *area, \
42                      GtkWidget      *widget, \
43                      const gchar    *detail, \
44                      gint            x, \
45                      gint            y, \
46                      gint            width, \
47                      gint            height
48
49 #ifdef HAVE_ANIMATION
50 #include "animation.h"
51 #endif
52
53 #define STYLE_FUNCTION(function) (clearlooks_style_class->style_functions[CLEARLOOKS_STYLE (style)->style].function)
54
55 static ClearlooksStyleClass *clearlooks_style_class;
56 static GtkStyleClass *clearlooks_parent_class;
57
58 static void
59 clearlooks_set_widget_parameters (const GtkWidget      *widget,
60                                   const GtkStyle       *style,
61                                   GtkStateType          state_type,
62                                   WidgetParameters     *params)
63 {
64         params->style_functions = &(clearlooks_style_class->style_functions[CLEARLOOKS_STYLE (style)->style]);
65
66         params->active      = (state_type == GTK_STATE_ACTIVE);
67         params->prelight    = (state_type == GTK_STATE_PRELIGHT);
68         params->disabled    = (state_type == GTK_STATE_INSENSITIVE);                    
69         params->state_type  = (ClearlooksStateType)state_type;
70         params->corners     = CR_CORNER_ALL;
71         params->ltr         = ge_widget_is_ltr ((GtkWidget*)widget);
72         params->focus       = widget && GTK_WIDGET_HAS_FOCUS (widget);
73         params->is_default  = widget && GE_WIDGET_HAS_DEFAULT (widget);
74         params->enable_glow = FALSE;
75         params->radius      = CLEARLOOKS_STYLE (style)->radius;
76
77         if (!params->active && widget && GE_IS_TOGGLE_BUTTON (widget))
78                 params->active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget));
79                 
80         params->xthickness = style->xthickness;
81         params->ythickness = style->ythickness;
82                 
83         /* This is used in GtkEntry to fake transparency. The reason to do this
84          * is that the entry has it's entire background filled with base[STATE].
85          * This is not a very good solution as it will eg. fail if one changes
86          * the background color of a notebook. */
87         params->parentbg = CLEARLOOKS_STYLE (style)->colors.bg[state_type];
88         clearlooks_get_parent_bg (widget, &params->parentbg);
89 }
90
91 static void
92 clearlooks_style_draw_flat_box (DRAW_ARGS)
93 {
94         if (detail &&   
95             state_type == GTK_STATE_SELECTED && (
96             !strncmp ("cell_even", detail, 9) ||
97             !strncmp ("cell_odd", detail, 8)))
98         {
99                 WidgetParameters params;
100                 ClearlooksStyle  *clearlooks_style;
101                 ClearlooksColors *colors;
102                 cairo_t          *cr;
103
104                 CHECK_ARGS
105                 SANITIZE_SIZE
106
107                 clearlooks_style = CLEARLOOKS_STYLE (style);
108                 clearlooks_set_widget_parameters (widget, style, state_type, &params);
109                 colors = &clearlooks_style->colors;
110                 cr = ge_gdk_drawable_to_cairo (window, area);
111
112                 /* XXX: We could expose the side details by setting params->corners accordingly
113                  *      or adding another option. */
114                 STYLE_FUNCTION (draw_selected_cell) (cr, colors, &params, x, y, width, height);
115
116                 cairo_destroy (cr);
117         }
118         else if (DETAIL ("tooltip"))
119         {
120                 WidgetParameters params;
121                 ClearlooksStyle  *clearlooks_style;
122                 ClearlooksColors *colors;
123                 cairo_t          *cr;
124
125                 CHECK_ARGS
126                 SANITIZE_SIZE
127
128                 clearlooks_style = CLEARLOOKS_STYLE (style);
129                 clearlooks_set_widget_parameters (widget, style, state_type, &params);
130                 colors = &clearlooks_style->colors;
131                 cr = ge_gdk_drawable_to_cairo (window, area);
132
133                 STYLE_FUNCTION (draw_tooltip) (cr, colors, &params, x, y, width, height);
134
135                 cairo_destroy (cr);
136         }
137         else if ((CLEARLOOKS_STYLE (style)->style == CL_STYLE_GLOSSY || CLEARLOOKS_STYLE (style)->style == CL_STYLE_GUMMY) &&
138                  ((DETAIL("checkbutton") || DETAIL("radiobutton")) && state_type == GTK_STATE_PRELIGHT))
139         {
140                 /* XXX: Don't draw any check/radiobutton bg in GLOSSY or GUMMY mode. */
141         }
142         else
143         {
144                 clearlooks_parent_class->draw_flat_box (style, window, state_type,
145                                              shadow_type,
146                                              area, widget, detail,
147                                              x, y, width, height);
148         }
149 }
150
151 static void
152 clearlooks_style_draw_shadow (DRAW_ARGS)
153 {
154         ClearlooksStyle  *clearlooks_style = CLEARLOOKS_STYLE (style);
155         ClearlooksColors *colors = &clearlooks_style->colors;
156         cairo_t          *cr     = ge_gdk_drawable_to_cairo (window, area);
157
158         CHECK_ARGS
159         SANITIZE_SIZE
160
161         if ((DETAIL ("entry") && !(widget && widget->parent && GE_IS_TREE_VIEW (widget->parent))) ||
162             (DETAIL ("frame") && ge_is_in_combo_box (widget)))
163         {
164                 WidgetParameters params;
165                 
166                 clearlooks_set_widget_parameters (widget, style, state_type, &params);
167
168                 /* Override the entries state type, because we are too lame to handle this via
169                  * the focus ring, and GtkEntry doesn't even set the INSENSITIVE state ... */
170                 if (state_type == GTK_STATE_NORMAL && widget && GE_IS_ENTRY (widget))
171                         params.state_type = GTK_WIDGET_STATE (widget);
172
173                 if (widget && (ge_is_in_combo_box (widget) || GE_IS_SPIN_BUTTON (widget)))
174                 {
175                         width += style->xthickness;
176                         if (!params.ltr)
177                                 x -= style->xthickness;
178                         
179                         if (params.ltr)
180                                 params.corners = CR_CORNER_TOPLEFT | CR_CORNER_BOTTOMLEFT;
181                         else
182                                 params.corners = CR_CORNER_TOPRIGHT | CR_CORNER_BOTTOMRIGHT;
183                 }
184                 
185                 STYLE_FUNCTION (draw_entry) (cr, &clearlooks_style->colors, &params,
186                                        x, y, width, height);
187         }
188         else if (DETAIL ("frame") && widget && GE_IS_STATUSBAR (widget->parent))
189         {
190                 WidgetParameters params;
191                 
192                 clearlooks_set_widget_parameters (widget, style, state_type, &params);
193
194                 gtk_style_apply_default_background (style, window, TRUE, state_type,
195                                                     area, x, y, width, height);
196                 
197                 STYLE_FUNCTION (draw_statusbar) (cr, colors, &params,
198                                            x, y, width, height);
199         }
200         else if (DETAIL ("frame"))
201         {
202                 WidgetParameters params;
203                 FrameParameters  frame;
204                 frame.shadow  = shadow_type;
205                 frame.gap_x   = -1;                 /* No gap will be drawn */
206                 frame.border  = &colors->shade[4];
207                 
208                 clearlooks_set_widget_parameters (widget, style, state_type, &params);
209                 params.corners = CR_CORNER_NONE;
210         
211                 if (widget && !g_str_equal ("XfcePanelWindow", gtk_widget_get_name (gtk_widget_get_toplevel (widget))))
212                         STYLE_FUNCTION(draw_frame) (cr, colors, &params, &frame,
213                                                x, y, width, height);
214         }
215         else if (DETAIL ("scrolled_window") || DETAIL ("viewport") || detail == NULL)
216         {
217                 CairoColor *border = (CairoColor*)&colors->shade[5];
218                 cairo_rectangle (cr, x+0.5, y+0.5, width-1, height-1);
219                 ge_cairo_set_color (cr, border);
220                 cairo_set_line_width (cr, 1);
221                 cairo_stroke (cr);
222         }
223         else
224         {
225                 WidgetParameters params;
226                 FrameParameters frame;
227
228                 frame.shadow = shadow_type;
229                 frame.gap_x  = -1;
230                 frame.border = &colors->shade[5];
231                 clearlooks_set_widget_parameters (widget, style, state_type, &params);
232                 params.corners = CR_CORNER_ALL;
233                 
234                 STYLE_FUNCTION(draw_frame) (cr, colors, &params, &frame, x, y, width, height);
235         }
236         
237         cairo_destroy (cr);
238 }
239
240 static void 
241 clearlooks_style_draw_box_gap (DRAW_ARGS,
242                   GtkPositionType gap_side,
243                   gint            gap_x,
244                   gint            gap_width)
245 {
246         ClearlooksStyle  *clearlooks_style = CLEARLOOKS_STYLE (style);
247         ClearlooksColors *colors = &clearlooks_style->colors;
248         cairo_t          *cr;
249
250         CHECK_ARGS
251         SANITIZE_SIZE
252
253         cr = ge_gdk_drawable_to_cairo (window, area);
254
255         if (DETAIL ("notebook"))
256         {
257                 WidgetParameters params;
258                 FrameParameters  frame;
259                 gboolean start, end;
260                 
261                 frame.shadow    = shadow_type;
262                 frame.gap_side  = gap_side;
263                 frame.gap_x     = gap_x;
264                 frame.gap_width = gap_width;
265                 frame.border    = &colors->shade[5];
266                 
267                 clearlooks_set_widget_parameters (widget, style, state_type, &params);
268
269                 clearlooks_get_notebook_tab_position (widget, &start, &end);
270
271                 params.corners = CR_CORNER_ALL;
272                 switch (gap_side) {
273                         case GTK_POS_LEFT:
274                                 if (start)
275                                         params.corners ^= CR_CORNER_TOPLEFT;
276                                 if (end)
277                                         params.corners ^= CR_CORNER_BOTTOMLEFT;
278                         break;
279                         case GTK_POS_RIGHT:
280                                 if (start)
281                                         params.corners ^= CR_CORNER_TOPRIGHT;
282                                 if (end)
283                                         params.corners ^= CR_CORNER_BOTTOMRIGHT;
284                         break;
285                         case GTK_POS_TOP:
286                                 if (ge_widget_is_ltr (widget)) {
287                                         if (start)
288                                                 params.corners ^= CR_CORNER_TOPLEFT;
289                                         if (end)
290                                                 params.corners ^= CR_CORNER_TOPRIGHT;
291                                 } else {
292                                         if (start)
293                                                 params.corners ^= CR_CORNER_TOPRIGHT;
294                                         if (end)
295                                                 params.corners ^= CR_CORNER_TOPLEFT;
296                                 }
297                         break;
298                         case GTK_POS_BOTTOM:
299                                 if (ge_widget_is_ltr (widget)) {
300                                         if (start)
301                                                 params.corners ^= CR_CORNER_BOTTOMLEFT;
302                                         if (end)
303                                                 params.corners ^= CR_CORNER_BOTTOMRIGHT;
304                                 } else {
305                                         if (start)
306                                                 params.corners ^= CR_CORNER_BOTTOMRIGHT;
307                                         if (end)
308                                                 params.corners ^= CR_CORNER_BOTTOMLEFT;
309                                 }
310                         break;
311                 }
312
313                 /* Fill the background with bg[NORMAL] */
314                 ge_cairo_rounded_rectangle (cr, x, y, width, height, params.radius, params.corners);
315                 ge_cairo_set_color (cr, &colors->bg[GTK_STATE_NORMAL]);
316                 cairo_fill (cr);
317                 
318                 STYLE_FUNCTION(draw_frame) (cr, colors, &params, &frame,
319                                        x, y, width, height);
320         }
321         else
322         {
323                 clearlooks_parent_class->draw_box_gap (style, window, state_type, shadow_type,
324                                                                            area, widget, detail,
325                                                                            x, y, width, height,
326                                                                            gap_side, gap_x, gap_width);
327         }
328         
329         cairo_destroy (cr);     
330 }
331
332 static void
333 clearlooks_style_draw_extension (DRAW_ARGS, GtkPositionType gap_side)
334 {
335         ClearlooksStyle  *clearlooks_style = CLEARLOOKS_STYLE (style);
336         ClearlooksColors *colors = &clearlooks_style->colors;
337         cairo_t          *cr;
338
339         CHECK_ARGS
340         SANITIZE_SIZE
341
342         cr = ge_gdk_drawable_to_cairo (window, area);
343         
344         if (DETAIL ("tab"))
345         {
346                 WidgetParameters params;
347                 TabParameters    tab;
348                 
349                 clearlooks_set_widget_parameters (widget, style, state_type, &params);
350                 
351                 tab.gap_side = (ClearlooksGapSide)gap_side;
352                 
353                 switch (gap_side)
354                 {
355                         case CL_GAP_BOTTOM:
356                                 params.corners = CR_CORNER_TOPLEFT | CR_CORNER_TOPRIGHT;
357                                 break;
358                         case CL_GAP_TOP:
359                                 params.corners = CR_CORNER_BOTTOMLEFT | CR_CORNER_BOTTOMRIGHT;
360                                 break;
361                         case CL_GAP_RIGHT:
362                                 params.corners = CR_CORNER_TOPLEFT | CR_CORNER_BOTTOMLEFT;
363                                 break;
364                         case CL_GAP_LEFT:
365                                 params.corners = CR_CORNER_TOPRIGHT | CR_CORNER_BOTTOMRIGHT;
366                 }
367                 
368                 STYLE_FUNCTION(draw_tab) (cr, colors, &params, &tab,
369                                      x, y, width, height);
370         }
371         else
372         {
373                 clearlooks_parent_class->draw_extension (style, window, state_type, shadow_type, area,
374                                               widget, detail, x, y, width, height,
375                                               gap_side);
376
377         }
378         
379         cairo_destroy (cr);
380 }
381
382 static void 
383 clearlooks_style_draw_handle (DRAW_ARGS, GtkOrientation orientation)
384 {
385         ClearlooksStyle  *clearlooks_style = CLEARLOOKS_STYLE (style);
386         ClearlooksColors *colors = &clearlooks_style->colors;
387         cairo_t          *cr;
388         gboolean         is_horizontal;
389         
390         CHECK_ARGS
391         SANITIZE_SIZE
392         
393         cr = ge_gdk_drawable_to_cairo (window, area);
394         
395         /* Evil hack to work around broken orientation for toolbars */
396         is_horizontal = (width > height);
397         
398         if (DETAIL ("handlebox"))
399         {
400                 WidgetParameters params;
401                 HandleParameters handle;
402
403                 clearlooks_set_widget_parameters (widget, style, state_type, &params);
404                 handle.type = CL_HANDLE_TOOLBAR;
405                 handle.horizontal = is_horizontal;
406                 
407                 /* Is this ever true? -Daniel */
408                 if (GE_IS_TOOLBAR (widget) && shadow_type != GTK_SHADOW_NONE)
409                 {
410                         ToolbarParameters toolbar;
411
412                         clearlooks_set_toolbar_parameters (&toolbar, widget, window, x, y);
413
414                         toolbar.style = clearlooks_style->toolbarstyle;
415
416                         cairo_save (cr);
417                         STYLE_FUNCTION(draw_toolbar) (cr, colors, &params, &toolbar, x, y, width, height);
418                         cairo_restore (cr);
419                 }
420                 
421                 STYLE_FUNCTION(draw_handle) (cr, colors, &params, &handle,
422                                         x, y, width, height);
423         }
424         else if (DETAIL ("paned"))
425         {
426                 WidgetParameters params;
427                 HandleParameters handle;
428
429                 clearlooks_set_widget_parameters (widget, style, state_type, &params);
430                 handle.type = CL_HANDLE_SPLITTER;
431                 handle.horizontal = orientation == GTK_ORIENTATION_HORIZONTAL;
432                         
433                 STYLE_FUNCTION(draw_handle) (cr, colors, &params, &handle,
434                                         x, y, width, height);
435         }
436         else
437         {
438                 WidgetParameters params;
439                 HandleParameters handle;
440
441                 clearlooks_set_widget_parameters (widget, style, state_type, &params);
442                 handle.type = CL_HANDLE_TOOLBAR;
443                 handle.horizontal = is_horizontal;
444                 
445                 /* Is this ever true? -Daniel */
446                 if (GE_IS_TOOLBAR (widget) && shadow_type != GTK_SHADOW_NONE)
447                 {
448                         ToolbarParameters toolbar;
449
450                         clearlooks_set_toolbar_parameters (&toolbar, widget, window, x, y);
451
452                         toolbar.style = clearlooks_style->toolbarstyle;
453
454                         cairo_save (cr);
455                         STYLE_FUNCTION(draw_toolbar) (cr, colors, &params, &toolbar, x, y, width, height);
456                         cairo_restore (cr);
457                 }
458                 
459                 STYLE_FUNCTION(draw_handle) (cr, colors, &params, &handle,
460                                         x, y, width, height);
461         }
462
463         cairo_destroy (cr);
464 }
465
466 static void
467 clearlooks_style_draw_box (DRAW_ARGS)
468 {
469         ClearlooksStyle *clearlooks_style = CLEARLOOKS_STYLE (style);
470         const ClearlooksColors *colors;
471         cairo_t *cr;
472
473         cr     = ge_gdk_drawable_to_cairo (window, area);
474         colors = &clearlooks_style->colors;
475
476         CHECK_ARGS
477         SANITIZE_SIZE
478
479         if (DETAIL ("menubar") && !ge_is_panel_widget_item(widget))
480         {
481                 WidgetParameters params;
482                 MenuBarParameters menubar;
483                 
484                 clearlooks_set_widget_parameters (widget, style, state_type, &params);
485
486                 menubar.style = clearlooks_style->menubarstyle;
487
488                 STYLE_FUNCTION(draw_menubar) (cr, colors, &params, &menubar,
489                                          x, y, width, height);
490         }
491         else if (DETAIL ("button") && widget && widget->parent &&
492                   (GE_IS_TREE_VIEW(widget->parent) ||
493                    GE_IS_CLIST (widget->parent) ||
494                    ge_object_is_a (G_OBJECT(widget->parent), "ETree"))) /* ECanvas inside ETree */
495         {
496                 WidgetParameters params;
497                 ListViewHeaderParameters header;
498                 
499                 gint columns, column_index;
500                 gboolean resizable = TRUE;
501                 
502                 /* XXX: This makes unknown treeview header CL_ORDER_MIDDLE, in need for something nicer */
503                 columns = 3;
504                 column_index = 1;
505                 
506                 clearlooks_set_widget_parameters (widget, style, state_type, &params);
507                 
508                 params.corners = CR_CORNER_NONE;
509                 
510                 if (GE_IS_TREE_VIEW (widget->parent))
511                 {
512                         clearlooks_treeview_get_header_index (GTK_TREE_VIEW(widget->parent),
513                                                                                    widget, &column_index, &columns,
514                                                                                    &resizable);
515                 }
516                 else if (GE_IS_CLIST (widget->parent))
517                 {
518                         clearlooks_clist_get_header_index (GTK_CLIST(widget->parent),
519                                                                                 widget, &column_index, &columns);
520                 }
521                 
522                 header.resizable = resizable;
523                 
524                 if (column_index == 0)
525                         header.order = params.ltr ? CL_ORDER_FIRST : CL_ORDER_LAST;
526                 else if (column_index == columns-1)
527                         header.order = params.ltr ? CL_ORDER_LAST : CL_ORDER_FIRST;
528                 else
529                         header.order = CL_ORDER_MIDDLE;
530                 
531                 gtk_style_apply_default_background (style, window, FALSE, state_type, area, x, y, width, height);
532                 
533                 STYLE_FUNCTION(draw_list_view_header) (cr, colors, &params, &header,
534                                                   x, y, width, height);
535         }
536         else if (DETAIL ("button") || DETAIL ("buttondefault"))
537         {
538                 WidgetParameters params;
539                 ShadowParameters shadow = { CR_CORNER_ALL, CL_SHADOW_NONE } ;
540                 clearlooks_set_widget_parameters (widget, style, state_type, &params);
541
542                 if (ge_is_in_combo_box(widget))
543                 {
544                         if (params.ltr)
545                                 params.corners = CR_CORNER_TOPRIGHT | CR_CORNER_BOTTOMRIGHT;
546                         else
547                                 params.corners = CR_CORNER_TOPLEFT | CR_CORNER_BOTTOMLEFT;
548                         
549                         shadow.shadow = CL_SHADOW_IN;
550
551                         if (params.xthickness > 2)
552                         {
553                                 if (params.ltr)
554                                         x--;
555                                 width++;
556                         }                       
557                 }
558                 else
559                 {
560                         params.corners    = CR_CORNER_ALL;
561                         /* if (!(ge_is_combo_box (widget, FALSE))) */
562                         params.enable_glow = TRUE;
563                 }               
564         
565                 if (GE_IS_TOGGLE_BUTTON (widget) &&
566                     gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)))
567                         params.active = TRUE;
568                 
569                 STYLE_FUNCTION(draw_button) (cr, &clearlooks_style->colors, &params,
570                                              x, y, width, height);
571         }
572         else if (DETAIL ("spinbutton_up") || DETAIL ("spinbutton_down"))
573         {
574                 if (state_type == GTK_STATE_ACTIVE)
575                 {
576                         WidgetParameters params;
577                         clearlooks_set_widget_parameters (widget, style, state_type, &params);
578                         
579                         if (style->xthickness == 3)
580                         {
581                                 width++;
582                                 if (params.ltr)
583                                         x--;
584                         }
585                         
586                         if (DETAIL ("spinbutton_up"))
587                         {
588                                 height+=2;
589                                 if (params.ltr)
590                                         params.corners = CR_CORNER_TOPRIGHT;
591                                 else
592                                         params.corners = CR_CORNER_TOPLEFT;
593                         }
594                         else
595                         {
596                                 if (params.ltr)
597                                         params.corners = CR_CORNER_BOTTOMRIGHT;
598                                 else
599                                         params.corners = CR_CORNER_BOTTOMLEFT;
600                         }
601                         
602                         STYLE_FUNCTION(draw_spinbutton_down) (cr, &clearlooks_style->colors, &params, x, y, width, height);
603                 }
604         }
605         else if (DETAIL ("spinbutton"))
606         {
607                 WidgetParameters params;
608                 
609                 clearlooks_set_widget_parameters (widget, style, state_type, &params);
610                 
611                 if (params.ltr)
612                         params.corners = CR_CORNER_TOPRIGHT | CR_CORNER_BOTTOMRIGHT;
613                 else
614                         params.corners = CR_CORNER_TOPLEFT | CR_CORNER_BOTTOMLEFT;
615                 
616                 if (style->xthickness == 3)
617                 {
618                         if (params.ltr)
619                                 x--;
620                         width++;
621                 }
622                 
623                 STYLE_FUNCTION(draw_spinbutton) (cr, &clearlooks_style->colors, &params,
624                                             x, y, width, height);
625         }
626         else if (detail && g_str_has_prefix (detail, "trough") && GE_IS_SCALE (widget))
627         {
628                 WidgetParameters params;
629                 SliderParameters slider;
630                 
631                 clearlooks_set_widget_parameters (widget, style, state_type, &params);
632                 params.corners    = CR_CORNER_NONE;
633                 
634                 slider.lower = DETAIL ("trough-lower");
635                 slider.fill_level = DETAIL ("trough-fill-level") || DETAIL ("trough-fill-level-full");
636
637                 slider.horizontal = (GTK_RANGE (widget)->orientation == GTK_ORIENTATION_HORIZONTAL);
638                 
639                 STYLE_FUNCTION(draw_scale_trough) (cr, &clearlooks_style->colors,
640                                               &params, &slider,
641                                               x, y, width, height);
642         }
643         else if (DETAIL ("trough") && widget && GE_IS_PROGRESS_BAR (widget))
644         {
645                 WidgetParameters params;
646                 
647                 clearlooks_set_widget_parameters (widget, style, state_type, &params);          
648                 
649                 STYLE_FUNCTION(draw_progressbar_trough) (cr, colors, &params, 
650                                                     x, y, width, height);
651         }
652         else if (DETAIL ("trough") && widget && (GE_IS_VSCROLLBAR (widget) || GE_IS_HSCROLLBAR (widget)))
653         {
654                 WidgetParameters params;
655                 ScrollBarParameters scrollbar;
656                 
657                 clearlooks_set_widget_parameters (widget, style, state_type, &params);
658                 params.corners = CR_CORNER_NONE;
659                 
660                 scrollbar.horizontal = TRUE;
661                 scrollbar.junction   = clearlooks_scrollbar_get_junction (widget);
662                 
663                 if (GE_IS_RANGE (widget))
664                         scrollbar.horizontal = GTK_RANGE (widget)->orientation == GTK_ORIENTATION_HORIZONTAL;
665                 
666                 if (scrollbar.horizontal)
667                 {
668                         x += 2;
669                         width -= 4;
670                 }
671                 else
672                 {
673                         y += 2;
674                         height -= 4;
675                 }
676                 
677                 STYLE_FUNCTION(draw_scrollbar_trough) (cr, colors, &params, &scrollbar,
678                                                   x, y, width, height);
679         }
680         else if (DETAIL ("bar"))
681         {
682                 WidgetParameters      params;
683                 ProgressBarParameters progressbar;
684                 gdouble               elapsed = 0.0;
685
686 #ifdef HAVE_ANIMATION
687                 if(clearlooks_style->animation && CL_IS_PROGRESS_BAR (widget))
688                 {       
689                         gboolean activity_mode = GTK_PROGRESS (widget)->activity_mode;
690                         
691                         if (!activity_mode)
692                                 clearlooks_animation_progressbar_add ((gpointer)widget);
693                 }
694
695                 elapsed = clearlooks_animation_elapsed (widget);
696 #endif
697
698                 clearlooks_set_widget_parameters (widget, style, state_type, &params);
699
700                 if (widget && GE_IS_PROGRESS_BAR (widget))
701                 {
702                         progressbar.orientation = gtk_progress_bar_get_orientation (GTK_PROGRESS_BAR (widget));
703                         progressbar.value = gtk_progress_bar_get_fraction(GTK_PROGRESS_BAR(widget));
704                         progressbar.pulsing = GTK_PROGRESS (widget)->activity_mode;
705                 }
706                 else
707                 {
708                         progressbar.orientation = CL_ORIENTATION_LEFT_TO_RIGHT;
709                         progressbar.value = 0;
710                         progressbar.pulsing = FALSE;
711                 }
712                 
713                 if (!params.ltr)
714                 {
715                         if (progressbar.orientation == GTK_PROGRESS_LEFT_TO_RIGHT)
716                                 progressbar.orientation = GTK_PROGRESS_RIGHT_TO_LEFT;
717                         else if (progressbar.orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
718                                 progressbar.orientation = GTK_PROGRESS_LEFT_TO_RIGHT;
719                 }
720
721                 /* Following is a hack to have a larger clip area, the one passed in
722                  * does not allow for the shadow. */
723                 if (area)
724                 {
725                         GdkRectangle tmp = *area;
726                         if (!progressbar.pulsing)
727                         {
728                                 switch (progressbar.orientation)
729                                 {
730                                         case GTK_PROGRESS_RIGHT_TO_LEFT:
731                                                 tmp.x -= 1;
732                                         case GTK_PROGRESS_LEFT_TO_RIGHT:
733                                                 tmp.width += 1;
734                                                 break;
735                                         case GTK_PROGRESS_BOTTOM_TO_TOP:
736                                                 tmp.y -= 1;
737                                         case GTK_PROGRESS_TOP_TO_BOTTOM:
738                                                 tmp.height += 1;
739                                                 break;
740                                 }
741                         }
742                         else
743                         {
744                                 if (progressbar.orientation == GTK_PROGRESS_RIGHT_TO_LEFT ||
745                                     progressbar.orientation == GTK_PROGRESS_LEFT_TO_RIGHT)
746                                 {
747                                         tmp.x -= 1;
748                                         tmp.width += 2;
749                                 }
750                                 else
751                                 {
752                                         tmp.y -= 1;
753                                         tmp.height += 2;
754                                 }
755                         }
756                         
757                         cairo_reset_clip (cr);
758                         gdk_cairo_rectangle (cr, &tmp);
759                         cairo_clip (cr);
760                 }
761                 
762                 STYLE_FUNCTION(draw_progressbar_fill) (cr, colors, &params, &progressbar,
763                                                   x, y, width, height,
764                                                   10 - (int)(elapsed * 10.0) % 10);
765         }
766         else if (DETAIL ("optionmenu"))
767         {
768                 WidgetParameters params;
769                 OptionMenuParameters optionmenu;
770                 
771                 GtkRequisition indicator_size;
772                 GtkBorder indicator_spacing;
773                 
774                 clearlooks_set_widget_parameters (widget, style, state_type, &params);
775                 
776                 params.enable_glow = TRUE;
777
778                 ge_option_menu_get_props (widget, &indicator_size, &indicator_spacing);
779                 
780                 if (ge_widget_is_ltr (widget))
781                         optionmenu.linepos = width - (indicator_size.width + indicator_spacing.left + indicator_spacing.right) - 1;
782                 else
783                         optionmenu.linepos = (indicator_size.width + indicator_spacing.left + indicator_spacing.right) + 1;
784                         
785                 STYLE_FUNCTION(draw_optionmenu) (cr, colors, &params, &optionmenu,
786                                                  x, y, width, height);          
787         }
788         else if (DETAIL ("menuitem"))
789         {
790                 WidgetParameters params;
791                 clearlooks_set_widget_parameters (widget, style, state_type, &params);
792                 
793                 if (widget && GE_IS_MENU_BAR (widget->parent))
794                 {
795                         params.corners = CR_CORNER_TOPLEFT | CR_CORNER_TOPRIGHT;
796                         height += 1;
797                         STYLE_FUNCTION(draw_menubaritem) (cr, colors, &params, x, y, width, height);
798                 }
799                 else
800                 {       
801                         params.corners = CR_CORNER_ALL;
802                         STYLE_FUNCTION(draw_menuitem) (cr, colors, &params, x, y, width, height);
803                 }
804         }
805         else if (DETAIL ("hscrollbar") || DETAIL ("vscrollbar")) /* This can't be "stepper" for scrollbars ... */
806         {
807                 WidgetParameters    params;
808                 ScrollBarParameters scrollbar;
809                 ScrollBarStepperParameters stepper;
810                 GdkRectangle this_rectangle;
811                 
812                 this_rectangle.x = x;
813                 this_rectangle.y = y;
814                 this_rectangle.width  = width;
815                 this_rectangle.height = height;
816                 
817                 clearlooks_set_widget_parameters (widget, style, state_type, &params);
818                 params.corners = CR_CORNER_NONE;
819                 
820                 scrollbar.has_color  = FALSE;
821                 scrollbar.horizontal = TRUE;
822                 scrollbar.junction   = clearlooks_scrollbar_get_junction (widget);
823
824                 if (clearlooks_style->colorize_scrollbar || clearlooks_style->has_scrollbar_color) {
825                         scrollbar.has_color = TRUE;
826                 }
827
828                 scrollbar.horizontal = DETAIL ("hscrollbar");
829                 
830                 stepper.stepper = clearlooks_scrollbar_get_stepper (widget, &this_rectangle);
831
832                 STYLE_FUNCTION(draw_scrollbar_stepper) (cr, colors, &params, &scrollbar, &stepper,
833                                                         x, y, width, height);
834         }
835         else if (DETAIL ("toolbar") || DETAIL ("handlebox_bin") || DETAIL ("dockitem_bin"))
836         {
837                 WidgetParameters  params;
838                 ToolbarParameters toolbar;
839
840                 clearlooks_set_widget_parameters (widget, style, state_type, &params);
841                 clearlooks_set_toolbar_parameters (&toolbar, widget, window, x, y);
842
843                 toolbar.style = clearlooks_style->toolbarstyle;
844
845                 /* Only draw the shadows on horizontal toolbars */
846                 if (shadow_type != GTK_SHADOW_NONE && height < 2*width )
847                         STYLE_FUNCTION(draw_toolbar) (cr, colors, &params, &toolbar, x, y, width, height);
848         }
849         else if (DETAIL ("trough"))
850         {
851                         
852         }
853         else if (DETAIL ("menu"))
854         {
855                 WidgetParameters params;
856                 
857                 clearlooks_set_widget_parameters (widget, style, state_type, &params);
858                 
859                 STYLE_FUNCTION(draw_menu_frame) (cr, colors, &params, x, y, width, height);
860         }
861         else if (DETAIL ("hseparator") || DETAIL ("vseparator"))
862         {
863                 const gchar *new_detail = detail;
864                 /* Draw a normal separator, we just use this because it gives more control
865                  * over sizing (currently). */
866
867                 /* This isn't nice ... but it seems like the best cleanest way to me right now.
868                  * It will get slightly nicer in the future hopefully. */
869                 if (GE_IS_MENU_ITEM (widget))
870                         new_detail = "menuitem";
871
872                 if (DETAIL ("hseparator")) {
873                         gtk_paint_hline (style, window, state_type, area, widget, new_detail,
874                                          x, x + width - 1, y + height/2);
875                 } else
876                         gtk_paint_vline (style, window, state_type, area, widget, new_detail,
877                                          y, y + height - 1, x + width/2);
878         }
879         else
880         {
881                 clearlooks_parent_class->draw_box (style, window, state_type, shadow_type, area,
882                                         widget, detail, x, y, width, height);
883         }
884         
885         cairo_destroy (cr);
886 }
887
888 static void
889 clearlooks_style_draw_slider (DRAW_ARGS, GtkOrientation orientation)
890 {
891         ClearlooksStyle *clearlooks_style = CLEARLOOKS_STYLE (style);
892         const ClearlooksColors *colors;
893         cairo_t *cr;
894
895         cr     = ge_gdk_drawable_to_cairo (window, area);
896         colors = &clearlooks_style->colors;
897
898         CHECK_ARGS
899         SANITIZE_SIZE
900         
901         if (DETAIL ("hscale") || DETAIL ("vscale"))
902         {
903                 WidgetParameters params;
904                 SliderParameters slider;
905                 
906                 clearlooks_set_widget_parameters (widget, style, state_type, &params);
907                 
908                 slider.horizontal = (orientation == GTK_ORIENTATION_HORIZONTAL);
909                 slider.lower = FALSE;
910                 slider.fill_level = FALSE;
911                 
912                 if (clearlooks_style->style == CL_STYLE_GLOSSY) /* XXX! */
913                         params.corners = CR_CORNER_ALL;
914                 
915                 STYLE_FUNCTION(draw_slider_button) (cr, &clearlooks_style->colors,
916                                                &params, &slider,
917                                                x, y, width, height);
918         }
919         else if (DETAIL ("slider"))
920         {
921                 WidgetParameters    params;
922                 ScrollBarParameters scrollbar;
923
924                 clearlooks_set_widget_parameters (widget, style, state_type, &params);
925                 params.corners = CR_CORNER_NONE;
926
927                 scrollbar.has_color  = FALSE;
928                 scrollbar.horizontal = (orientation == GTK_ORIENTATION_HORIZONTAL);
929                 scrollbar.junction   = clearlooks_scrollbar_get_junction (widget);
930
931                 if (clearlooks_style->colorize_scrollbar) {
932                         scrollbar.color = colors->spot[1];
933                         scrollbar.has_color = TRUE;
934                 }
935
936                 /* Set scrollbar color */
937                 if (clearlooks_style->has_scrollbar_color)
938                 {
939                         ge_gdk_color_to_cairo (&clearlooks_style->scrollbar_color, &scrollbar.color);
940                         scrollbar.has_color = TRUE;
941                 }
942
943                 if ((clearlooks_style->style == CL_STYLE_GLOSSY || clearlooks_style->style == CL_STYLE_GUMMY)
944                         && !scrollbar.has_color)
945                         scrollbar.color = colors->bg[0];
946                 
947                 STYLE_FUNCTION(draw_scrollbar_slider) (cr, colors, &params, &scrollbar,
948                                                        x, y, width, height);
949         }
950         else
951         {
952                 clearlooks_parent_class->draw_slider (style, window, state_type, shadow_type, area,
953                                            widget, detail, x, y, width, height, orientation);
954         }
955
956         cairo_destroy (cr);
957 }
958
959 static void
960 clearlooks_style_draw_option (DRAW_ARGS)
961 {
962         (void) detail;
963                 
964         ClearlooksStyle *clearlooks_style = CLEARLOOKS_STYLE (style);
965         const ClearlooksColors *colors;
966         WidgetParameters params;
967         CheckboxParameters checkbox;
968         cairo_t *cr;
969         
970         CHECK_ARGS
971         SANITIZE_SIZE
972
973         cr = ge_gdk_drawable_to_cairo (window, area);
974         colors = &clearlooks_style->colors;
975         
976         checkbox.shadow_type = shadow_type;
977         checkbox.in_menu = (widget && GTK_IS_MENU(widget->parent));
978                 
979         clearlooks_set_widget_parameters (widget, style, state_type, &params);
980         
981         STYLE_FUNCTION(draw_radiobutton) (cr, colors, &params, &checkbox, x, y, width, height);
982
983         cairo_destroy (cr);
984 }
985
986 static void
987 clearlooks_style_draw_check (DRAW_ARGS)
988 {
989         ClearlooksStyle *clearlooks_style = CLEARLOOKS_STYLE (style);
990         WidgetParameters params;
991         CheckboxParameters checkbox;
992         cairo_t *cr;
993
994         CHECK_ARGS
995         SANITIZE_SIZE
996
997         cr = ge_gdk_drawable_to_cairo (window, area);
998         
999         clearlooks_set_widget_parameters (widget, style, state_type, &params);
1000         
1001         params.corners = CR_CORNER_ALL;
1002         
1003         checkbox.shadow_type = shadow_type;
1004         checkbox.in_cell = DETAIL("cellcheck");
1005
1006         checkbox.in_menu = (widget && widget->parent && GTK_IS_MENU(widget->parent));
1007
1008         STYLE_FUNCTION(draw_checkbox) (cr, &clearlooks_style->colors, &params, &checkbox,
1009                                   x, y, width, height);
1010         
1011         cairo_destroy (cr);
1012 }
1013
1014 static void
1015 clearlooks_style_draw_vline (GtkStyle               *style,
1016                              GdkWindow              *window,
1017                              GtkStateType            state_type,
1018                              GdkRectangle           *area,
1019                              GtkWidget              *widget,
1020                              const gchar            *detail,
1021                              gint                    y1,
1022                              gint                    y2,
1023                              gint                    x)
1024 {
1025         (void) state_type;
1026         (void) widget;
1027         (void) detail;
1028         
1029         ClearlooksStyle *clearlooks_style = CLEARLOOKS_STYLE (style);
1030         const ClearlooksColors *colors;
1031         SeparatorParameters separator = { FALSE };
1032         cairo_t *cr;
1033
1034         CHECK_ARGS
1035
1036         colors = &clearlooks_style->colors;
1037
1038         cr = ge_gdk_drawable_to_cairo (window, area);
1039
1040         /* There is no such thing as a vertical menu separator
1041          * (and even if, a normal one should be better on menu bars) */
1042         STYLE_FUNCTION(draw_separator) (cr, colors, NULL, &separator,
1043                                         x, y1, 2, y2-y1+1);
1044         
1045         cairo_destroy (cr);
1046 }
1047
1048 static void
1049 clearlooks_style_draw_hline (GtkStyle               *style,
1050                              GdkWindow              *window,
1051                              GtkStateType            state_type,
1052                              GdkRectangle           *area,
1053                              GtkWidget              *widget,
1054                              const gchar            *detail,
1055                              gint                    x1,
1056                              gint                    x2,
1057                              gint                    y)
1058 {
1059         (void) state_type;
1060         (void) widget;
1061         
1062         ClearlooksStyle *clearlooks_style = CLEARLOOKS_STYLE (style);
1063         const ClearlooksColors *colors;
1064         cairo_t *cr;
1065         SeparatorParameters separator;
1066
1067         CHECK_ARGS
1068
1069         colors = &clearlooks_style->colors;
1070
1071         cr = ge_gdk_drawable_to_cairo (window, area);
1072         
1073         separator.horizontal = TRUE;
1074         
1075         if (!DETAIL ("menuitem"))
1076                 STYLE_FUNCTION(draw_separator) (cr, colors, NULL, &separator,
1077                                                 x1, y, x2-x1+1, 2);
1078         else
1079                 STYLE_FUNCTION(draw_menu_item_separator) (cr, colors, NULL, &separator,
1080                                                            x1, y, x2-x1+1, 2);
1081         
1082         cairo_destroy (cr);
1083 }
1084
1085 static void 
1086 clearlooks_style_draw_shadow_gap (DRAW_ARGS,
1087                  GtkPositionType gap_side,
1088                  gint            gap_x,
1089                  gint            gap_width)
1090 {
1091         ClearlooksStyle *clearlooks_style = CLEARLOOKS_STYLE (style);
1092         const ClearlooksColors *colors;
1093         cairo_t *cr;
1094
1095         CHECK_ARGS
1096         SANITIZE_SIZE
1097
1098         cr     = ge_gdk_drawable_to_cairo (window, area);
1099         colors = &clearlooks_style->colors;
1100         
1101         if (DETAIL ("frame"))
1102         {
1103                 WidgetParameters params;
1104                 FrameParameters  frame;
1105                 
1106                 frame.shadow    = shadow_type;
1107                 frame.gap_side  = gap_side;
1108                 frame.gap_x     = gap_x;
1109                 frame.gap_width = gap_width;
1110                 frame.border    = &colors->shade[5];
1111                 
1112                 clearlooks_set_widget_parameters (widget, style, state_type, &params);
1113
1114                 params.corners = CR_CORNER_ALL;
1115                 
1116                 STYLE_FUNCTION(draw_frame) (cr, colors, &params, &frame,
1117                                        x, y, width, height);
1118         }
1119         else
1120         {
1121                 clearlooks_parent_class->draw_shadow_gap (style, window, state_type, shadow_type, area,
1122                                                                            widget, detail, x, y, width, height,
1123                                                                            gap_side, gap_x, gap_width);
1124         }
1125         
1126         cairo_destroy (cr);
1127 }
1128
1129 static void
1130 clearlooks_style_draw_resize_grip (GtkStyle       *style,
1131                   GdkWindow      *window,
1132                   GtkStateType    state_type,
1133                   GdkRectangle   *area,
1134                   GtkWidget      *widget,
1135                   const gchar    *detail,
1136                   GdkWindowEdge   edge,
1137                   gint            x,
1138                   gint            y,
1139                   gint            width,
1140                   gint            height)
1141 {
1142         (void) detail;
1143         
1144         ClearlooksStyle *clearlooks_style = CLEARLOOKS_STYLE (style);
1145         ClearlooksColors *colors = &clearlooks_style->colors;
1146         cairo_t *cr;
1147         WidgetParameters params;
1148         ResizeGripParameters grip;
1149
1150         CHECK_ARGS
1151         SANITIZE_SIZE
1152
1153         grip.edge = (ClearlooksWindowEdge)edge;
1154
1155         g_return_if_fail (window != NULL);
1156
1157         cr = ge_gdk_drawable_to_cairo (window, area);
1158
1159         clearlooks_set_widget_parameters (widget, style, state_type, &params);  
1160
1161         STYLE_FUNCTION(draw_resize_grip) (cr, colors, &params, &grip,
1162                                      x, y, width, height);
1163
1164         cairo_destroy (cr);
1165 }
1166
1167 static void
1168 clearlooks_style_draw_tab (DRAW_ARGS)
1169 {
1170         (void) shadow_type;
1171         (void) detail;
1172         
1173         ClearlooksStyle *clearlooks_style = CLEARLOOKS_STYLE (style);
1174         ClearlooksColors *colors = &clearlooks_style->colors;
1175         WidgetParameters params;
1176         ArrowParameters  arrow;          
1177         cairo_t *cr;
1178
1179         CHECK_ARGS
1180         SANITIZE_SIZE
1181         
1182         cr = ge_gdk_drawable_to_cairo (window, area);
1183
1184         clearlooks_set_widget_parameters (widget, style, state_type, &params);
1185         arrow.type      = CL_ARROW_COMBO;
1186         arrow.direction = CL_DIRECTION_DOWN;     
1187
1188         STYLE_FUNCTION(draw_arrow) (cr, colors, &params, &arrow, x, y, width, height);
1189
1190         cairo_destroy (cr);
1191 }
1192
1193 static void
1194 clearlooks_style_draw_arrow (GtkStyle  *style,
1195                        GdkWindow     *window,
1196                        GtkStateType   state_type,
1197                        GtkShadowType  shadow,
1198                        GdkRectangle  *area,
1199                        GtkWidget     *widget,
1200                        const gchar   *detail,
1201                        GtkArrowType   arrow_type,
1202                        gboolean       fill,
1203                        gint           x,
1204                        gint           y,
1205                        gint           width,
1206                        gint           height)
1207 {
1208         (void) shadow;
1209         (void) detail;
1210         (void) fill;
1211         
1212         ClearlooksStyle  *clearlooks_style = CLEARLOOKS_STYLE (style);
1213         ClearlooksColors *colors = &clearlooks_style->colors;
1214         WidgetParameters params;
1215         ArrowParameters  arrow;
1216         cairo_t *cr = ge_gdk_drawable_to_cairo (window, area);
1217
1218         CHECK_ARGS
1219         SANITIZE_SIZE
1220
1221         if (arrow_type == GTK_ARROW_NONE) {
1222                 cairo_destroy (cr);
1223                 return;
1224         }
1225
1226         clearlooks_set_widget_parameters (widget, style, state_type, &params);
1227         arrow.type = CL_ARROW_NORMAL;
1228         arrow.direction = (ClearlooksDirection)arrow_type;
1229         
1230         if (ge_is_combo_box (widget, FALSE) && !ge_is_combo_box_entry (widget))
1231         {
1232                 arrow.type = CL_ARROW_COMBO;
1233         }
1234         
1235         /* I have no idea why, but the arrow of GtkCombo is larger than in other places.
1236          * Subtracting 3 seems to fix this. */
1237         if (widget && widget->parent && GE_IS_COMBO (widget->parent->parent))
1238         {
1239                 if (params.ltr)
1240                         x += 1;
1241                 else
1242                         x += 2;
1243                 width -= 3;
1244         }
1245         
1246         STYLE_FUNCTION(draw_arrow) (cr, colors, &params, &arrow, x, y, width, height);
1247         
1248         cairo_destroy (cr);
1249 }
1250
1251 static void
1252 clearlooks_style_init_from_rc (GtkStyle * style,
1253                                GtkRcStyle * rc_style)
1254 {
1255         ClearlooksStyle *clearlooks_style = CLEARLOOKS_STYLE (style);
1256         
1257         clearlooks_parent_class->init_from_rc (style, rc_style);
1258         
1259         g_assert ((CLEARLOOKS_RC_STYLE (rc_style)->style < CL_NUM_STYLES));
1260         clearlooks_style->style         = CLEARLOOKS_RC_STYLE (rc_style)->style;
1261         
1262         clearlooks_style->menubarstyle      = CLEARLOOKS_RC_STYLE (rc_style)->menubarstyle;
1263         clearlooks_style->toolbarstyle      = CLEARLOOKS_RC_STYLE (rc_style)->toolbarstyle;
1264         clearlooks_style->has_scrollbar_color = CLEARLOOKS_RC_STYLE (rc_style)->flags & CL_FLAG_SCROLLBAR_COLOR;
1265         clearlooks_style->colorize_scrollbar = CLEARLOOKS_RC_STYLE (rc_style)->colorize_scrollbar;
1266         clearlooks_style->animation         = CLEARLOOKS_RC_STYLE (rc_style)->animation;
1267         clearlooks_style->radius            = CLAMP (CLEARLOOKS_RC_STYLE (rc_style)->radius, 0.0, 10.0);
1268
1269         if (clearlooks_style->has_scrollbar_color)
1270                 clearlooks_style->scrollbar_color = CLEARLOOKS_RC_STYLE (rc_style)->scrollbar_color;
1271 }
1272
1273 static void
1274 clearlooks_style_realize (GtkStyle * style)
1275 {
1276         ClearlooksStyle *clearlooks_style = CLEARLOOKS_STYLE (style);
1277         double shades[] = {1.15, 0.95, 0.896, 0.82, 0.7, 0.665, 0.475, 0.45, 0.4};
1278         CairoColor spot_color;
1279         CairoColor bg_normal;
1280         double contrast;
1281         int i;
1282         
1283         clearlooks_parent_class->realize (style);
1284
1285         contrast = CLEARLOOKS_RC_STYLE (style->rc_style)->contrast;
1286         
1287         /* Lighter to darker */
1288         ge_gdk_color_to_cairo (&style->bg[GTK_STATE_NORMAL], &bg_normal);
1289
1290         for (i = 0; i < 9; i++)
1291         {
1292                 ge_shade_color(&bg_normal, (shades[i]-0.7) * contrast + 0.7, &clearlooks_style->colors.shade[i]);
1293         }
1294                 
1295         ge_gdk_color_to_cairo (&style->bg[GTK_STATE_SELECTED], &spot_color);
1296         
1297         ge_shade_color(&spot_color, 1.42, &clearlooks_style->colors.spot[0]);
1298         ge_shade_color(&spot_color, 1.05, &clearlooks_style->colors.spot[1]);
1299         ge_shade_color(&spot_color, 0.65, &clearlooks_style->colors.spot[2]);
1300         
1301         for (i=0; i<5; i++)
1302         {
1303                 ge_gdk_color_to_cairo (&style->fg[i], &clearlooks_style->colors.fg[i]);
1304                 ge_gdk_color_to_cairo (&style->bg[i], &clearlooks_style->colors.bg[i]);
1305                 ge_gdk_color_to_cairo (&style->base[i], &clearlooks_style->colors.base[i]);
1306                 ge_gdk_color_to_cairo (&style->text[i], &clearlooks_style->colors.text[i]);
1307         }
1308 }
1309
1310 static void
1311 clearlooks_style_draw_focus (GtkStyle *style, GdkWindow *window, GtkStateType state_type,
1312             GdkRectangle *area, GtkWidget *widget, const gchar *detail,
1313             gint x, gint y, gint width, gint height)
1314 {
1315         cairo_t *cr;
1316         gboolean free_dash_list = FALSE;
1317         gint line_width = 1;
1318         gint8 *dash_list = (gint8 *)"\1\1";
1319
1320         if (widget)
1321         {
1322                 gtk_widget_style_get (widget,
1323                                       "focus-line-width", &line_width,
1324                                       "focus-line-pattern",
1325                                       (gchar *) & dash_list, NULL);
1326
1327                 free_dash_list = TRUE;
1328         }
1329
1330         if (detail && !strcmp (detail, "add-mode"))
1331         {
1332                 if (free_dash_list)
1333                         g_free (dash_list);
1334
1335                 dash_list = (gint8 *)"\4\4";
1336                 free_dash_list = FALSE;
1337         }
1338
1339         CHECK_ARGS
1340         SANITIZE_SIZE
1341
1342         cr = gdk_cairo_create (window);
1343
1344         if (detail && !strcmp (detail, "colorwheel_light"))
1345                 cairo_set_source_rgb (cr, 0., 0., 0.);
1346         else if (detail && !strcmp (detail, "colorwheel_dark"))
1347                 cairo_set_source_rgb (cr, 1., 1., 1.);
1348         else
1349                 ge_cairo_set_gdk_color_with_alpha (cr, &style->fg[state_type],
1350                                                        0.7);
1351
1352         cairo_set_line_width (cr, line_width);
1353
1354         if (dash_list[0])
1355         {
1356                 gint n_dashes = strlen ((gchar *)dash_list);
1357                 gdouble *dashes = g_new (gdouble, n_dashes);
1358                 gdouble total_length = 0;
1359                 gdouble dash_offset;
1360                 gint i;
1361
1362                 for (i = 0; i < n_dashes; i++)
1363                 {
1364                         dashes[i] = dash_list[i];
1365                         total_length += dash_list[i];
1366                 }
1367
1368                 /* The dash offset here aligns the pattern to integer pixels
1369                  * by starting the dash at the right side of the left border
1370                  * Negative dash offsets in cairo don't work
1371                  * (https://bugs.freedesktop.org/show_bug.cgi?id=2729)
1372                  */
1373                 dash_offset = -line_width / 2.;
1374                 while (dash_offset < 0)
1375                         dash_offset += total_length;
1376
1377                 cairo_set_dash (cr, dashes, n_dashes, dash_offset);
1378                 g_free (dashes);
1379         }
1380
1381         if (area)
1382         {
1383                 gdk_cairo_rectangle (cr, area);
1384                 cairo_clip (cr);
1385         }
1386
1387         cairo_rectangle (cr,
1388                          x + line_width / 2.,
1389                          y + line_width / 2.,
1390                          width - line_width, height - line_width);
1391         cairo_stroke (cr);
1392         cairo_destroy (cr);
1393
1394         if (free_dash_list)
1395                 g_free (dash_list);
1396 }
1397
1398 static void
1399 clearlooks_style_copy (GtkStyle * style, GtkStyle * src)
1400 {
1401         ClearlooksStyle * cl_style = CLEARLOOKS_STYLE (style);
1402         ClearlooksStyle * cl_src = CLEARLOOKS_STYLE (src);
1403         
1404         cl_style->colors              = cl_src->colors;
1405         cl_style->menubarstyle        = cl_src->menubarstyle;
1406         cl_style->toolbarstyle        = cl_src->toolbarstyle;
1407         cl_style->scrollbar_color     = cl_src->scrollbar_color;
1408         cl_style->has_scrollbar_color = cl_src->has_scrollbar_color;
1409         cl_style->colorize_scrollbar  = cl_src->colorize_scrollbar;
1410         cl_style->animation           = cl_src->animation;
1411         cl_style->radius              = cl_src->radius;
1412         cl_style->style               = cl_src->style;
1413         
1414         clearlooks_parent_class->copy (style, src);
1415 }
1416
1417 static void
1418 clearlooks_style_unrealize (GtkStyle * style)
1419 {
1420         clearlooks_parent_class->unrealize (style);
1421 }
1422
1423 static GdkPixbuf *
1424 set_transparency (const GdkPixbuf *pixbuf, gdouble alpha_percent)
1425 {
1426         GdkPixbuf *target;
1427         guchar *data, *current;
1428         guint x, y, rowstride, height, width;
1429
1430         g_return_val_if_fail (pixbuf != NULL, NULL);
1431         g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), NULL);
1432
1433         /* Returns a copy of pixbuf with it's non-completely-transparent pixels to
1434            have an alpha level "alpha_percent" of their original value. */
1435
1436         target = gdk_pixbuf_add_alpha (pixbuf, FALSE, 0, 0, 0);
1437
1438         if (alpha_percent == 1.0)
1439                 return target;
1440         width = gdk_pixbuf_get_width (target);
1441         height = gdk_pixbuf_get_height (target);
1442         rowstride = gdk_pixbuf_get_rowstride (target);
1443         data = gdk_pixbuf_get_pixels (target);
1444
1445         for (y = 0; y < height; y++) {
1446                 for (x = 0; x < width; x++) {
1447                         /* The "4" is the number of chars per pixel, in this case, RGBA,
1448                            the 3 means "skip to the alpha" */
1449                         current = data + (y * rowstride) + (x * 4) + 3; 
1450                         *(current) = (guchar) (*(current) * alpha_percent);
1451                 }
1452         }
1453
1454         return target;
1455 }
1456
1457 static GdkPixbuf*
1458 scale_or_ref (GdkPixbuf *src,
1459               int width,
1460               int height)
1461 {
1462         if (width == gdk_pixbuf_get_width (src) &&
1463             height == gdk_pixbuf_get_height (src)) {
1464                 return g_object_ref (src);
1465         } else {
1466                 return gdk_pixbuf_scale_simple (src,
1467                                         width, height,
1468                                         GDK_INTERP_BILINEAR);
1469         }
1470 }
1471
1472 static void
1473 clearlooks_style_draw_layout (GtkStyle * style,
1474              GdkWindow * window,
1475              GtkStateType state_type,
1476              gboolean use_text,
1477              GdkRectangle * area,
1478              GtkWidget * widget,
1479              const gchar * detail, gint x, gint y, PangoLayout * layout)
1480 {
1481         (void) detail;
1482
1483         GdkGC *gc;
1484
1485         g_return_if_fail (GTK_IS_STYLE (style));
1486         g_return_if_fail (window != NULL);
1487
1488         gc = use_text ? style->text_gc[state_type] : style->fg_gc[state_type];
1489
1490         if (area)
1491                 gdk_gc_set_clip_rectangle (gc, area);
1492
1493         if (state_type == GTK_STATE_INSENSITIVE) {
1494                 ClearlooksStyle *clearlooks_style = CLEARLOOKS_STYLE (style);
1495                 ClearlooksColors *colors = &clearlooks_style->colors;
1496
1497                 WidgetParameters params;
1498                 GdkColor etched;
1499                 CairoColor temp;
1500
1501                 clearlooks_set_widget_parameters (widget, style, state_type, &params);
1502
1503                 if (GTK_WIDGET_NO_WINDOW (widget))
1504                         ge_shade_color (&params.parentbg, 1.2, &temp);
1505                 else
1506                         ge_shade_color (&colors->bg[widget->state], 1.2, &temp);
1507                 
1508                 etched.red = (int) (temp.r * 65535);
1509                 etched.green = (int) (temp.g * 65535);
1510                 etched.blue = (int) (temp.b * 65535);
1511
1512                 gdk_draw_layout_with_colors (window, gc, x + 1, y + 1, layout, &etched, NULL);
1513                 gdk_draw_layout (window, gc, x, y, layout);
1514         }
1515         else
1516                 gdk_draw_layout (window, gc, x, y, layout);
1517
1518         if (area)
1519                 gdk_gc_set_clip_rectangle (gc, NULL);
1520 }
1521
1522 static GdkPixbuf *
1523 clearlooks_style_draw_render_icon (GtkStyle            *style,
1524              const GtkIconSource *source,
1525              GtkTextDirection     direction,
1526              GtkStateType         state,
1527              GtkIconSize          size,
1528              GtkWidget           *widget,
1529              const char          *detail)
1530 {
1531         (void) direction;
1532         (void) detail;
1533         
1534         int width = 1;
1535         int height = 1;
1536         GdkPixbuf *scaled;
1537         GdkPixbuf *stated;
1538         GdkPixbuf *base_pixbuf;
1539         GdkScreen *screen;
1540         GtkSettings *settings;
1541         
1542         /* Oddly, style can be NULL in this function, because
1543          * GtkIconSet can be used without a style and if so
1544          * it uses this function.
1545          */
1546         
1547         base_pixbuf = gtk_icon_source_get_pixbuf (source);
1548         
1549         g_return_val_if_fail (base_pixbuf != NULL, NULL);
1550         
1551         if (widget && gtk_widget_has_screen (widget)) {
1552                 screen = gtk_widget_get_screen (widget);
1553                 settings = gtk_settings_get_for_screen (screen);
1554         } else if (style->colormap) {
1555                 screen = gdk_colormap_get_screen (style->colormap);
1556                 settings = gtk_settings_get_for_screen (screen);
1557         } else {
1558                 settings = gtk_settings_get_default ();
1559                 GTK_NOTE (MULTIHEAD,
1560                           g_warning ("Using the default screen for gtk_default_render_icon()"));
1561         }
1562         
1563   
1564         if (size != (GtkIconSize) -1 && !gtk_icon_size_lookup_for_settings (settings, size, &width, &height)) {
1565                 g_warning (G_STRLOC ": invalid icon size '%d'", size);
1566                 return NULL;
1567         }
1568
1569         /* If the size was wildcarded, and we're allowed to scale, then scale; otherwise,
1570          * leave it alone.
1571          */
1572         if (size != (GtkIconSize)-1 && gtk_icon_source_get_size_wildcarded (source))
1573                 scaled = scale_or_ref (base_pixbuf, width, height);
1574         else
1575                 scaled = g_object_ref (base_pixbuf);
1576         
1577         /* If the state was wildcarded, then generate a state. */
1578         if (gtk_icon_source_get_state_wildcarded (source)) {
1579                 if (state == GTK_STATE_INSENSITIVE) {
1580                         stated = set_transparency (scaled, 0.3);
1581                         gdk_pixbuf_saturate_and_pixelate (stated, stated,
1582                                                           0.1, FALSE);
1583                         
1584                         g_object_unref (scaled);
1585                 } else if (state == GTK_STATE_PRELIGHT) {
1586                         stated = gdk_pixbuf_copy (scaled);      
1587                         
1588                         gdk_pixbuf_saturate_and_pixelate (scaled, stated,
1589                                                           1.2, FALSE);
1590                         
1591                         g_object_unref (scaled);
1592                 } else {
1593                         stated = scaled;
1594                 }
1595         }
1596         else
1597                 stated = scaled;
1598   
1599   return stated;
1600 }
1601
1602 static void
1603 clearlooks_style_init (ClearlooksStyle * style)
1604 {
1605         (void) style;
1606 }
1607
1608 static void
1609 clearlooks_style_class_init (ClearlooksStyleClass * klass)
1610 {
1611         GtkStyleClass *style_class = GTK_STYLE_CLASS (klass);
1612         
1613         clearlooks_style_class = CLEARLOOKS_STYLE_CLASS (klass);
1614         clearlooks_parent_class = g_type_class_peek_parent (klass);
1615
1616         style_class->copy             = clearlooks_style_copy;
1617         style_class->realize          = clearlooks_style_realize;
1618         style_class->unrealize        = clearlooks_style_unrealize;
1619         style_class->init_from_rc     = clearlooks_style_init_from_rc;
1620         style_class->draw_handle      = clearlooks_style_draw_handle;
1621         style_class->draw_slider      = clearlooks_style_draw_slider;
1622         style_class->draw_shadow_gap  = clearlooks_style_draw_shadow_gap;
1623         style_class->draw_focus       = clearlooks_style_draw_focus;
1624         style_class->draw_box         = clearlooks_style_draw_box;
1625         style_class->draw_shadow      = clearlooks_style_draw_shadow;
1626         style_class->draw_box_gap     = clearlooks_style_draw_box_gap;
1627         style_class->draw_extension   = clearlooks_style_draw_extension;
1628         style_class->draw_option      = clearlooks_style_draw_option;
1629         style_class->draw_check       = clearlooks_style_draw_check;
1630         style_class->draw_flat_box    = clearlooks_style_draw_flat_box;
1631         style_class->draw_vline       = clearlooks_style_draw_vline;
1632         style_class->draw_hline       = clearlooks_style_draw_hline;
1633         style_class->draw_resize_grip = clearlooks_style_draw_resize_grip;
1634         style_class->draw_tab         = clearlooks_style_draw_tab;
1635         style_class->draw_arrow       = clearlooks_style_draw_arrow;
1636         style_class->draw_layout      = clearlooks_style_draw_layout;
1637         style_class->render_icon      = clearlooks_style_draw_render_icon;
1638
1639         clearlooks_register_style_classic (&clearlooks_style_class->style_functions[CL_STYLE_CLASSIC]);
1640         clearlooks_style_class->style_functions[CL_STYLE_GLOSSY] = clearlooks_style_class->style_functions[CL_STYLE_CLASSIC];
1641         clearlooks_register_style_glossy (&clearlooks_style_class->style_functions[CL_STYLE_GLOSSY]);
1642         clearlooks_style_class->style_functions[CL_STYLE_INVERTED] = clearlooks_style_class->style_functions[CL_STYLE_CLASSIC];
1643         clearlooks_register_style_inverted (&clearlooks_style_class->style_functions[CL_STYLE_INVERTED]);
1644         clearlooks_style_class->style_functions[CL_STYLE_GUMMY] = clearlooks_style_class->style_functions[CL_STYLE_CLASSIC];
1645         clearlooks_register_style_gummy (&clearlooks_style_class->style_functions[CL_STYLE_GUMMY]);
1646 }
1647
1648 GType clearlooks_type_style = 0;
1649
1650 void
1651 clearlooks_style_register_type (GTypeModule * module)
1652 {
1653         static const GTypeInfo object_info =
1654         {
1655                 sizeof (ClearlooksStyleClass),
1656                 (GBaseInitFunc) NULL,
1657                 (GBaseFinalizeFunc) NULL,
1658                 (GClassInitFunc) clearlooks_style_class_init,
1659                 NULL,         /* class_finalize */
1660                 NULL,         /* class_data */
1661                 sizeof (ClearlooksStyle),
1662                 0,            /* n_preallocs */
1663                 (GInstanceInitFunc) clearlooks_style_init,
1664                 NULL
1665         };
1666
1667         clearlooks_type_style = g_type_module_register_type (module,
1668                                                              GTK_TYPE_STYLE,
1669                                                              "ClearlooksStyle",
1670                                                              &object_info, 0);
1671 }