Fix some compilation warnings
[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                 clearlooks_set_widget_parameters (widget, style, state_type, &params);
540
541                 if (ge_is_in_combo_box(widget))
542                 {
543                         if (params.ltr)
544                                 params.corners = CR_CORNER_TOPRIGHT | CR_CORNER_BOTTOMRIGHT;
545                         else
546                                 params.corners = CR_CORNER_TOPLEFT | CR_CORNER_BOTTOMLEFT;
547
548                         if (params.xthickness > 2)
549                         {
550                                 if (params.ltr)
551                                         x--;
552                                 width++;
553                         }
554                 }
555                 else
556                 {
557                         params.corners    = CR_CORNER_ALL;
558                         /* if (!(ge_is_combo_box (widget, FALSE))) */
559                         params.enable_glow = TRUE;
560                 }
561
562                 if (GE_IS_TOGGLE_BUTTON (widget) &&
563                     gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)))
564                         params.active = TRUE;
565                 
566                 STYLE_FUNCTION(draw_button) (cr, &clearlooks_style->colors, &params,
567                                              x, y, width, height);
568         }
569         else if (DETAIL ("spinbutton_up") || DETAIL ("spinbutton_down"))
570         {
571                 if (state_type == GTK_STATE_ACTIVE)
572                 {
573                         WidgetParameters params;
574                         clearlooks_set_widget_parameters (widget, style, state_type, &params);
575                         
576                         if (style->xthickness == 3)
577                         {
578                                 width++;
579                                 if (params.ltr)
580                                         x--;
581                         }
582                         
583                         if (DETAIL ("spinbutton_up"))
584                         {
585                                 height+=2;
586                                 if (params.ltr)
587                                         params.corners = CR_CORNER_TOPRIGHT;
588                                 else
589                                         params.corners = CR_CORNER_TOPLEFT;
590                         }
591                         else
592                         {
593                                 if (params.ltr)
594                                         params.corners = CR_CORNER_BOTTOMRIGHT;
595                                 else
596                                         params.corners = CR_CORNER_BOTTOMLEFT;
597                         }
598                         
599                         STYLE_FUNCTION(draw_spinbutton_down) (cr, &clearlooks_style->colors, &params, x, y, width, height);
600                 }
601         }
602         else if (DETAIL ("spinbutton"))
603         {
604                 WidgetParameters params;
605                 
606                 clearlooks_set_widget_parameters (widget, style, state_type, &params);
607                 
608                 if (params.ltr)
609                         params.corners = CR_CORNER_TOPRIGHT | CR_CORNER_BOTTOMRIGHT;
610                 else
611                         params.corners = CR_CORNER_TOPLEFT | CR_CORNER_BOTTOMLEFT;
612                 
613                 if (style->xthickness == 3)
614                 {
615                         if (params.ltr)
616                                 x--;
617                         width++;
618                 }
619                 
620                 STYLE_FUNCTION(draw_spinbutton) (cr, &clearlooks_style->colors, &params,
621                                             x, y, width, height);
622         }
623         else if (detail && g_str_has_prefix (detail, "trough") && GE_IS_SCALE (widget))
624         {
625                 WidgetParameters params;
626                 SliderParameters slider;
627                 
628                 clearlooks_set_widget_parameters (widget, style, state_type, &params);
629                 params.corners    = CR_CORNER_NONE;
630                 
631                 slider.lower = DETAIL ("trough-lower");
632                 slider.fill_level = DETAIL ("trough-fill-level") || DETAIL ("trough-fill-level-full");
633
634                 slider.horizontal = (GTK_RANGE (widget)->orientation == GTK_ORIENTATION_HORIZONTAL);
635                 
636                 STYLE_FUNCTION(draw_scale_trough) (cr, &clearlooks_style->colors,
637                                               &params, &slider,
638                                               x, y, width, height);
639         }
640         else if (DETAIL ("trough") && widget && GE_IS_PROGRESS_BAR (widget))
641         {
642                 WidgetParameters params;
643                 
644                 clearlooks_set_widget_parameters (widget, style, state_type, &params);          
645                 
646                 STYLE_FUNCTION(draw_progressbar_trough) (cr, colors, &params, 
647                                                     x, y, width, height);
648         }
649         else if (DETAIL ("trough") && widget && (GE_IS_VSCROLLBAR (widget) || GE_IS_HSCROLLBAR (widget)))
650         {
651                 WidgetParameters params;
652                 ScrollBarParameters scrollbar;
653                 
654                 clearlooks_set_widget_parameters (widget, style, state_type, &params);
655                 params.corners = CR_CORNER_NONE;
656                 
657                 scrollbar.horizontal = TRUE;
658                 scrollbar.junction   = clearlooks_scrollbar_get_junction (widget);
659                 
660                 if (GE_IS_RANGE (widget))
661                         scrollbar.horizontal = GTK_RANGE (widget)->orientation == GTK_ORIENTATION_HORIZONTAL;
662                 
663                 if (scrollbar.horizontal)
664                 {
665                         x += 2;
666                         width -= 4;
667                 }
668                 else
669                 {
670                         y += 2;
671                         height -= 4;
672                 }
673                 
674                 STYLE_FUNCTION(draw_scrollbar_trough) (cr, colors, &params, &scrollbar,
675                                                   x, y, width, height);
676         }
677         else if (DETAIL ("bar"))
678         {
679                 WidgetParameters      params;
680                 ProgressBarParameters progressbar;
681                 gdouble               elapsed = 0.0;
682
683 #ifdef HAVE_ANIMATION
684                 if(clearlooks_style->animation && CL_IS_PROGRESS_BAR (widget))
685                 {       
686                         gboolean activity_mode = GTK_PROGRESS (widget)->activity_mode;
687                         
688                         if (!activity_mode)
689                                 clearlooks_animation_progressbar_add ((gpointer)widget);
690                 }
691
692                 elapsed = clearlooks_animation_elapsed (widget);
693 #endif
694
695                 clearlooks_set_widget_parameters (widget, style, state_type, &params);
696
697                 if (widget && GE_IS_PROGRESS_BAR (widget))
698                 {
699                         progressbar.orientation = gtk_progress_bar_get_orientation (GTK_PROGRESS_BAR (widget));
700                         progressbar.value = gtk_progress_bar_get_fraction(GTK_PROGRESS_BAR(widget));
701                         progressbar.pulsing = GTK_PROGRESS (widget)->activity_mode;
702                 }
703                 else
704                 {
705                         progressbar.orientation = CL_ORIENTATION_LEFT_TO_RIGHT;
706                         progressbar.value = 0;
707                         progressbar.pulsing = FALSE;
708                 }
709                 
710                 if (!params.ltr)
711                 {
712                         if (progressbar.orientation == GTK_PROGRESS_LEFT_TO_RIGHT)
713                                 progressbar.orientation = GTK_PROGRESS_RIGHT_TO_LEFT;
714                         else if (progressbar.orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
715                                 progressbar.orientation = GTK_PROGRESS_LEFT_TO_RIGHT;
716                 }
717
718                 /* Following is a hack to have a larger clip area, the one passed in
719                  * does not allow for the shadow. */
720                 if (area)
721                 {
722                         GdkRectangle tmp = *area;
723                         if (!progressbar.pulsing)
724                         {
725                                 switch (progressbar.orientation)
726                                 {
727                                         case GTK_PROGRESS_RIGHT_TO_LEFT:
728                                                 tmp.x -= 1;
729                                         case GTK_PROGRESS_LEFT_TO_RIGHT:
730                                                 tmp.width += 1;
731                                                 break;
732                                         case GTK_PROGRESS_BOTTOM_TO_TOP:
733                                                 tmp.y -= 1;
734                                         case GTK_PROGRESS_TOP_TO_BOTTOM:
735                                                 tmp.height += 1;
736                                                 break;
737                                 }
738                         }
739                         else
740                         {
741                                 if (progressbar.orientation == GTK_PROGRESS_RIGHT_TO_LEFT ||
742                                     progressbar.orientation == GTK_PROGRESS_LEFT_TO_RIGHT)
743                                 {
744                                         tmp.x -= 1;
745                                         tmp.width += 2;
746                                 }
747                                 else
748                                 {
749                                         tmp.y -= 1;
750                                         tmp.height += 2;
751                                 }
752                         }
753                         
754                         cairo_reset_clip (cr);
755                         gdk_cairo_rectangle (cr, &tmp);
756                         cairo_clip (cr);
757                 }
758                 
759                 STYLE_FUNCTION(draw_progressbar_fill) (cr, colors, &params, &progressbar,
760                                                   x, y, width, height,
761                                                   10 - (int)(elapsed * 10.0) % 10);
762         }
763         else if (DETAIL ("optionmenu"))
764         {
765                 WidgetParameters params;
766                 OptionMenuParameters optionmenu;
767                 
768                 GtkRequisition indicator_size;
769                 GtkBorder indicator_spacing;
770                 
771                 clearlooks_set_widget_parameters (widget, style, state_type, &params);
772                 
773                 params.enable_glow = TRUE;
774
775                 ge_option_menu_get_props (widget, &indicator_size, &indicator_spacing);
776                 
777                 if (ge_widget_is_ltr (widget))
778                         optionmenu.linepos = width - (indicator_size.width + indicator_spacing.left + indicator_spacing.right) - 1;
779                 else
780                         optionmenu.linepos = (indicator_size.width + indicator_spacing.left + indicator_spacing.right) + 1;
781                         
782                 STYLE_FUNCTION(draw_optionmenu) (cr, colors, &params, &optionmenu,
783                                                  x, y, width, height);          
784         }
785         else if (DETAIL ("menuitem"))
786         {
787                 WidgetParameters params;
788                 clearlooks_set_widget_parameters (widget, style, state_type, &params);
789                 
790                 if (widget && GE_IS_MENU_BAR (widget->parent))
791                 {
792                         params.corners = CR_CORNER_TOPLEFT | CR_CORNER_TOPRIGHT;
793                         height += 1;
794                         STYLE_FUNCTION(draw_menubaritem) (cr, colors, &params, x, y, width, height);
795                 }
796                 else
797                 {       
798                         params.corners = CR_CORNER_ALL;
799                         STYLE_FUNCTION(draw_menuitem) (cr, colors, &params, x, y, width, height);
800                 }
801         }
802         else if (DETAIL ("hscrollbar") || DETAIL ("vscrollbar")) /* This can't be "stepper" for scrollbars ... */
803         {
804                 WidgetParameters    params;
805                 ScrollBarParameters scrollbar;
806                 ScrollBarStepperParameters stepper;
807                 GdkRectangle this_rectangle;
808                 
809                 this_rectangle.x = x;
810                 this_rectangle.y = y;
811                 this_rectangle.width  = width;
812                 this_rectangle.height = height;
813                 
814                 clearlooks_set_widget_parameters (widget, style, state_type, &params);
815                 params.corners = CR_CORNER_NONE;
816                 
817                 scrollbar.has_color  = FALSE;
818                 scrollbar.horizontal = TRUE;
819                 scrollbar.junction   = clearlooks_scrollbar_get_junction (widget);
820
821                 if (clearlooks_style->colorize_scrollbar || clearlooks_style->has_scrollbar_color) {
822                         scrollbar.has_color = TRUE;
823                 }
824
825                 scrollbar.horizontal = DETAIL ("hscrollbar");
826                 
827                 stepper.stepper = clearlooks_scrollbar_get_stepper (widget, &this_rectangle);
828
829                 STYLE_FUNCTION(draw_scrollbar_stepper) (cr, colors, &params, &scrollbar, &stepper,
830                                                         x, y, width, height);
831         }
832         else if (DETAIL ("toolbar") || DETAIL ("handlebox_bin") || DETAIL ("dockitem_bin"))
833         {
834                 WidgetParameters  params;
835                 ToolbarParameters toolbar;
836
837                 clearlooks_set_widget_parameters (widget, style, state_type, &params);
838                 clearlooks_set_toolbar_parameters (&toolbar, widget, window, x, y);
839
840                 toolbar.style = clearlooks_style->toolbarstyle;
841
842                 /* Only draw the shadows on horizontal toolbars */
843                 if (shadow_type != GTK_SHADOW_NONE && height < 2*width )
844                         STYLE_FUNCTION(draw_toolbar) (cr, colors, &params, &toolbar, x, y, width, height);
845         }
846         else if (DETAIL ("trough"))
847         {
848                         
849         }
850         else if (DETAIL ("menu"))
851         {
852                 WidgetParameters params;
853                 
854                 clearlooks_set_widget_parameters (widget, style, state_type, &params);
855                 
856                 STYLE_FUNCTION(draw_menu_frame) (cr, colors, &params, x, y, width, height);
857         }
858         else if (DETAIL ("hseparator") || DETAIL ("vseparator"))
859         {
860                 const gchar *new_detail = detail;
861                 /* Draw a normal separator, we just use this because it gives more control
862                  * over sizing (currently). */
863
864                 /* This isn't nice ... but it seems like the best cleanest way to me right now.
865                  * It will get slightly nicer in the future hopefully. */
866                 if (GE_IS_MENU_ITEM (widget))
867                         new_detail = "menuitem";
868
869                 if (DETAIL ("hseparator")) {
870                         gtk_paint_hline (style, window, state_type, area, widget, new_detail,
871                                          x, x + width - 1, y + height/2);
872                 } else
873                         gtk_paint_vline (style, window, state_type, area, widget, new_detail,
874                                          y, y + height - 1, x + width/2);
875         }
876         else
877         {
878                 clearlooks_parent_class->draw_box (style, window, state_type, shadow_type, area,
879                                         widget, detail, x, y, width, height);
880         }
881         
882         cairo_destroy (cr);
883 }
884
885 static void
886 clearlooks_style_draw_slider (DRAW_ARGS, GtkOrientation orientation)
887 {
888         ClearlooksStyle *clearlooks_style = CLEARLOOKS_STYLE (style);
889         const ClearlooksColors *colors;
890         cairo_t *cr;
891
892         cr     = ge_gdk_drawable_to_cairo (window, area);
893         colors = &clearlooks_style->colors;
894
895         CHECK_ARGS
896         SANITIZE_SIZE
897         
898         if (DETAIL ("hscale") || DETAIL ("vscale"))
899         {
900                 WidgetParameters params;
901                 SliderParameters slider;
902                 
903                 clearlooks_set_widget_parameters (widget, style, state_type, &params);
904                 
905                 slider.horizontal = (orientation == GTK_ORIENTATION_HORIZONTAL);
906                 slider.lower = FALSE;
907                 slider.fill_level = FALSE;
908                 
909                 if (clearlooks_style->style == CL_STYLE_GLOSSY) /* XXX! */
910                         params.corners = CR_CORNER_ALL;
911                 
912                 STYLE_FUNCTION(draw_slider_button) (cr, &clearlooks_style->colors,
913                                                &params, &slider,
914                                                x, y, width, height);
915         }
916         else if (DETAIL ("slider"))
917         {
918                 WidgetParameters    params;
919                 ScrollBarParameters scrollbar;
920
921                 clearlooks_set_widget_parameters (widget, style, state_type, &params);
922                 params.corners = CR_CORNER_NONE;
923
924                 scrollbar.has_color  = FALSE;
925                 scrollbar.horizontal = (orientation == GTK_ORIENTATION_HORIZONTAL);
926                 scrollbar.junction   = clearlooks_scrollbar_get_junction (widget);
927
928                 if (clearlooks_style->colorize_scrollbar) {
929                         scrollbar.color = colors->spot[1];
930                         scrollbar.has_color = TRUE;
931                 }
932
933                 /* Set scrollbar color */
934                 if (clearlooks_style->has_scrollbar_color)
935                 {
936                         ge_gdk_color_to_cairo (&clearlooks_style->scrollbar_color, &scrollbar.color);
937                         scrollbar.has_color = TRUE;
938                 }
939
940                 if ((clearlooks_style->style == CL_STYLE_GLOSSY || clearlooks_style->style == CL_STYLE_GUMMY)
941                         && !scrollbar.has_color)
942                         scrollbar.color = colors->bg[0];
943                 
944                 STYLE_FUNCTION(draw_scrollbar_slider) (cr, colors, &params, &scrollbar,
945                                                        x, y, width, height);
946         }
947         else
948         {
949                 clearlooks_parent_class->draw_slider (style, window, state_type, shadow_type, area,
950                                            widget, detail, x, y, width, height, orientation);
951         }
952
953         cairo_destroy (cr);
954 }
955
956 static void
957 clearlooks_style_draw_option (DRAW_ARGS)
958 {
959         (void) detail;
960                 
961         ClearlooksStyle *clearlooks_style = CLEARLOOKS_STYLE (style);
962         const ClearlooksColors *colors;
963         WidgetParameters params;
964         CheckboxParameters checkbox;
965         cairo_t *cr;
966         
967         CHECK_ARGS
968         SANITIZE_SIZE
969
970         cr = ge_gdk_drawable_to_cairo (window, area);
971         colors = &clearlooks_style->colors;
972         
973         checkbox.shadow_type = shadow_type;
974         checkbox.in_menu = (widget && GTK_IS_MENU(widget->parent));
975                 
976         clearlooks_set_widget_parameters (widget, style, state_type, &params);
977         
978         STYLE_FUNCTION(draw_radiobutton) (cr, colors, &params, &checkbox, x, y, width, height);
979
980         cairo_destroy (cr);
981 }
982
983 static void
984 clearlooks_style_draw_check (DRAW_ARGS)
985 {
986         ClearlooksStyle *clearlooks_style = CLEARLOOKS_STYLE (style);
987         WidgetParameters params;
988         CheckboxParameters checkbox;
989         cairo_t *cr;
990
991         CHECK_ARGS
992         SANITIZE_SIZE
993
994         cr = ge_gdk_drawable_to_cairo (window, area);
995         
996         clearlooks_set_widget_parameters (widget, style, state_type, &params);
997         
998         params.corners = CR_CORNER_ALL;
999         
1000         checkbox.shadow_type = shadow_type;
1001         checkbox.in_cell = DETAIL("cellcheck");
1002
1003         checkbox.in_menu = (widget && widget->parent && GTK_IS_MENU(widget->parent));
1004
1005         STYLE_FUNCTION(draw_checkbox) (cr, &clearlooks_style->colors, &params, &checkbox,
1006                                   x, y, width, height);
1007         
1008         cairo_destroy (cr);
1009 }
1010
1011 static void
1012 clearlooks_style_draw_vline (GtkStyle               *style,
1013                              GdkWindow              *window,
1014                              GtkStateType            state_type,
1015                              GdkRectangle           *area,
1016                              GtkWidget              *widget,
1017                              const gchar            *detail,
1018                              gint                    y1,
1019                              gint                    y2,
1020                              gint                    x)
1021 {
1022         (void) state_type;
1023         (void) widget;
1024         (void) detail;
1025         
1026         ClearlooksStyle *clearlooks_style = CLEARLOOKS_STYLE (style);
1027         const ClearlooksColors *colors;
1028         SeparatorParameters separator = { FALSE };
1029         cairo_t *cr;
1030
1031         CHECK_ARGS
1032
1033         colors = &clearlooks_style->colors;
1034
1035         cr = ge_gdk_drawable_to_cairo (window, area);
1036
1037         /* There is no such thing as a vertical menu separator
1038          * (and even if, a normal one should be better on menu bars) */
1039         STYLE_FUNCTION(draw_separator) (cr, colors, NULL, &separator,
1040                                         x, y1, 2, y2-y1+1);
1041         
1042         cairo_destroy (cr);
1043 }
1044
1045 static void
1046 clearlooks_style_draw_hline (GtkStyle               *style,
1047                              GdkWindow              *window,
1048                              GtkStateType            state_type,
1049                              GdkRectangle           *area,
1050                              GtkWidget              *widget,
1051                              const gchar            *detail,
1052                              gint                    x1,
1053                              gint                    x2,
1054                              gint                    y)
1055 {
1056         (void) state_type;
1057         (void) widget;
1058         
1059         ClearlooksStyle *clearlooks_style = CLEARLOOKS_STYLE (style);
1060         const ClearlooksColors *colors;
1061         cairo_t *cr;
1062         SeparatorParameters separator;
1063
1064         CHECK_ARGS
1065
1066         colors = &clearlooks_style->colors;
1067
1068         cr = ge_gdk_drawable_to_cairo (window, area);
1069         
1070         separator.horizontal = TRUE;
1071         
1072         if (!DETAIL ("menuitem"))
1073                 STYLE_FUNCTION(draw_separator) (cr, colors, NULL, &separator,
1074                                                 x1, y, x2-x1+1, 2);
1075         else
1076                 STYLE_FUNCTION(draw_menu_item_separator) (cr, colors, NULL, &separator,
1077                                                            x1, y, x2-x1+1, 2);
1078         
1079         cairo_destroy (cr);
1080 }
1081
1082 static void 
1083 clearlooks_style_draw_shadow_gap (DRAW_ARGS,
1084                  GtkPositionType gap_side,
1085                  gint            gap_x,
1086                  gint            gap_width)
1087 {
1088         ClearlooksStyle *clearlooks_style = CLEARLOOKS_STYLE (style);
1089         const ClearlooksColors *colors;
1090         cairo_t *cr;
1091
1092         CHECK_ARGS
1093         SANITIZE_SIZE
1094
1095         cr     = ge_gdk_drawable_to_cairo (window, area);
1096         colors = &clearlooks_style->colors;
1097         
1098         if (DETAIL ("frame"))
1099         {
1100                 WidgetParameters params;
1101                 FrameParameters  frame;
1102                 
1103                 frame.shadow    = shadow_type;
1104                 frame.gap_side  = gap_side;
1105                 frame.gap_x     = gap_x;
1106                 frame.gap_width = gap_width;
1107                 frame.border    = &colors->shade[5];
1108                 
1109                 clearlooks_set_widget_parameters (widget, style, state_type, &params);
1110
1111                 params.corners = CR_CORNER_ALL;
1112                 
1113                 STYLE_FUNCTION(draw_frame) (cr, colors, &params, &frame,
1114                                        x, y, width, height);
1115         }
1116         else
1117         {
1118                 clearlooks_parent_class->draw_shadow_gap (style, window, state_type, shadow_type, area,
1119                                                                            widget, detail, x, y, width, height,
1120                                                                            gap_side, gap_x, gap_width);
1121         }
1122         
1123         cairo_destroy (cr);
1124 }
1125
1126 static void
1127 clearlooks_style_draw_resize_grip (GtkStyle       *style,
1128                   GdkWindow      *window,
1129                   GtkStateType    state_type,
1130                   GdkRectangle   *area,
1131                   GtkWidget      *widget,
1132                   const gchar    *detail,
1133                   GdkWindowEdge   edge,
1134                   gint            x,
1135                   gint            y,
1136                   gint            width,
1137                   gint            height)
1138 {
1139         (void) detail;
1140         
1141         ClearlooksStyle *clearlooks_style = CLEARLOOKS_STYLE (style);
1142         ClearlooksColors *colors = &clearlooks_style->colors;
1143         cairo_t *cr;
1144         WidgetParameters params;
1145         ResizeGripParameters grip;
1146
1147         CHECK_ARGS
1148         SANITIZE_SIZE
1149
1150         grip.edge = (ClearlooksWindowEdge)edge;
1151
1152         g_return_if_fail (window != NULL);
1153
1154         cr = ge_gdk_drawable_to_cairo (window, area);
1155
1156         clearlooks_set_widget_parameters (widget, style, state_type, &params);  
1157
1158         STYLE_FUNCTION(draw_resize_grip) (cr, colors, &params, &grip,
1159                                      x, y, width, height);
1160
1161         cairo_destroy (cr);
1162 }
1163
1164 static void
1165 clearlooks_style_draw_tab (DRAW_ARGS)
1166 {
1167         (void) shadow_type;
1168         (void) detail;
1169         
1170         ClearlooksStyle *clearlooks_style = CLEARLOOKS_STYLE (style);
1171         ClearlooksColors *colors = &clearlooks_style->colors;
1172         WidgetParameters params;
1173         ArrowParameters  arrow;          
1174         cairo_t *cr;
1175
1176         CHECK_ARGS
1177         SANITIZE_SIZE
1178         
1179         cr = ge_gdk_drawable_to_cairo (window, area);
1180
1181         clearlooks_set_widget_parameters (widget, style, state_type, &params);
1182         arrow.type      = CL_ARROW_COMBO;
1183         arrow.direction = CL_DIRECTION_DOWN;     
1184
1185         STYLE_FUNCTION(draw_arrow) (cr, colors, &params, &arrow, x, y, width, height);
1186
1187         cairo_destroy (cr);
1188 }
1189
1190 static void
1191 clearlooks_style_draw_arrow (GtkStyle  *style,
1192                        GdkWindow     *window,
1193                        GtkStateType   state_type,
1194                        GtkShadowType  shadow,
1195                        GdkRectangle  *area,
1196                        GtkWidget     *widget,
1197                        const gchar   *detail,
1198                        GtkArrowType   arrow_type,
1199                        gboolean       fill,
1200                        gint           x,
1201                        gint           y,
1202                        gint           width,
1203                        gint           height)
1204 {
1205         (void) shadow;
1206         (void) detail;
1207         (void) fill;
1208         
1209         ClearlooksStyle  *clearlooks_style = CLEARLOOKS_STYLE (style);
1210         ClearlooksColors *colors = &clearlooks_style->colors;
1211         WidgetParameters params;
1212         ArrowParameters  arrow;
1213         cairo_t *cr = ge_gdk_drawable_to_cairo (window, area);
1214
1215         CHECK_ARGS
1216         SANITIZE_SIZE
1217
1218         if (arrow_type == GTK_ARROW_NONE) {
1219                 cairo_destroy (cr);
1220                 return;
1221         }
1222
1223         clearlooks_set_widget_parameters (widget, style, state_type, &params);
1224         arrow.type = CL_ARROW_NORMAL;
1225         arrow.direction = (ClearlooksDirection)arrow_type;
1226         
1227         if (ge_is_combo_box (widget, FALSE) && !ge_is_combo_box_entry (widget))
1228         {
1229                 arrow.type = CL_ARROW_COMBO;
1230         }
1231         
1232         /* I have no idea why, but the arrow of GtkCombo is larger than in other places.
1233          * Subtracting 3 seems to fix this. */
1234         if (widget && widget->parent && GE_IS_COMBO (widget->parent->parent))
1235         {
1236                 if (params.ltr)
1237                         x += 1;
1238                 else
1239                         x += 2;
1240                 width -= 3;
1241         }
1242         
1243         STYLE_FUNCTION(draw_arrow) (cr, colors, &params, &arrow, x, y, width, height);
1244         
1245         cairo_destroy (cr);
1246 }
1247
1248 static void
1249 clearlooks_style_init_from_rc (GtkStyle * style,
1250                                GtkRcStyle * rc_style)
1251 {
1252         ClearlooksStyle *clearlooks_style = CLEARLOOKS_STYLE (style);
1253         
1254         clearlooks_parent_class->init_from_rc (style, rc_style);
1255         
1256         g_assert ((CLEARLOOKS_RC_STYLE (rc_style)->style < CL_NUM_STYLES));
1257         clearlooks_style->style         = CLEARLOOKS_RC_STYLE (rc_style)->style;
1258         
1259         clearlooks_style->menubarstyle      = CLEARLOOKS_RC_STYLE (rc_style)->menubarstyle;
1260         clearlooks_style->toolbarstyle      = CLEARLOOKS_RC_STYLE (rc_style)->toolbarstyle;
1261         clearlooks_style->has_scrollbar_color = CLEARLOOKS_RC_STYLE (rc_style)->flags & CL_FLAG_SCROLLBAR_COLOR;
1262         clearlooks_style->colorize_scrollbar = CLEARLOOKS_RC_STYLE (rc_style)->colorize_scrollbar;
1263         clearlooks_style->animation         = CLEARLOOKS_RC_STYLE (rc_style)->animation;
1264         clearlooks_style->radius            = CLAMP (CLEARLOOKS_RC_STYLE (rc_style)->radius, 0.0, 10.0);
1265
1266         if (clearlooks_style->has_scrollbar_color)
1267                 clearlooks_style->scrollbar_color = CLEARLOOKS_RC_STYLE (rc_style)->scrollbar_color;
1268 }
1269
1270 static void
1271 clearlooks_style_realize (GtkStyle * style)
1272 {
1273         ClearlooksStyle *clearlooks_style = CLEARLOOKS_STYLE (style);
1274         double shades[] = {1.15, 0.95, 0.896, 0.82, 0.7, 0.665, 0.475, 0.45, 0.4};
1275         CairoColor spot_color;
1276         CairoColor bg_normal;
1277         double contrast;
1278         int i;
1279         
1280         clearlooks_parent_class->realize (style);
1281
1282         contrast = CLEARLOOKS_RC_STYLE (style->rc_style)->contrast;
1283         
1284         /* Lighter to darker */
1285         ge_gdk_color_to_cairo (&style->bg[GTK_STATE_NORMAL], &bg_normal);
1286
1287         for (i = 0; i < 9; i++)
1288         {
1289                 ge_shade_color(&bg_normal, (shades[i]-0.7) * contrast + 0.7, &clearlooks_style->colors.shade[i]);
1290         }
1291                 
1292         ge_gdk_color_to_cairo (&style->bg[GTK_STATE_SELECTED], &spot_color);
1293         
1294         ge_shade_color(&spot_color, 1.42, &clearlooks_style->colors.spot[0]);
1295         ge_shade_color(&spot_color, 1.05, &clearlooks_style->colors.spot[1]);
1296         ge_shade_color(&spot_color, 0.65, &clearlooks_style->colors.spot[2]);
1297         
1298         for (i=0; i<5; i++)
1299         {
1300                 ge_gdk_color_to_cairo (&style->fg[i], &clearlooks_style->colors.fg[i]);
1301                 ge_gdk_color_to_cairo (&style->bg[i], &clearlooks_style->colors.bg[i]);
1302                 ge_gdk_color_to_cairo (&style->base[i], &clearlooks_style->colors.base[i]);
1303                 ge_gdk_color_to_cairo (&style->text[i], &clearlooks_style->colors.text[i]);
1304         }
1305 }
1306
1307 static void
1308 clearlooks_style_draw_focus (GtkStyle *style, GdkWindow *window, GtkStateType state_type,
1309             GdkRectangle *area, GtkWidget *widget, const gchar *detail,
1310             gint x, gint y, gint width, gint height)
1311 {
1312         cairo_t *cr;
1313         gboolean free_dash_list = FALSE;
1314         gint line_width = 1;
1315         gint8 *dash_list = (gint8 *)"\1\1";
1316
1317         if (widget)
1318         {
1319                 gtk_widget_style_get (widget,
1320                                       "focus-line-width", &line_width,
1321                                       "focus-line-pattern",
1322                                       (gchar *) & dash_list, NULL);
1323
1324                 free_dash_list = TRUE;
1325         }
1326
1327         if (detail && !strcmp (detail, "add-mode"))
1328         {
1329                 if (free_dash_list)
1330                         g_free (dash_list);
1331
1332                 dash_list = (gint8 *)"\4\4";
1333                 free_dash_list = FALSE;
1334         }
1335
1336         CHECK_ARGS
1337         SANITIZE_SIZE
1338
1339         cr = gdk_cairo_create (window);
1340
1341         if (detail && !strcmp (detail, "colorwheel_light"))
1342                 cairo_set_source_rgb (cr, 0., 0., 0.);
1343         else if (detail && !strcmp (detail, "colorwheel_dark"))
1344                 cairo_set_source_rgb (cr, 1., 1., 1.);
1345         else
1346                 ge_cairo_set_gdk_color_with_alpha (cr, &style->fg[state_type],
1347                                                        0.7);
1348
1349         cairo_set_line_width (cr, line_width);
1350
1351         if (dash_list[0])
1352         {
1353                 gint n_dashes = strlen ((gchar *)dash_list);
1354                 gdouble *dashes = g_new (gdouble, n_dashes);
1355                 gdouble total_length = 0;
1356                 gdouble dash_offset;
1357                 gint i;
1358
1359                 for (i = 0; i < n_dashes; i++)
1360                 {
1361                         dashes[i] = dash_list[i];
1362                         total_length += dash_list[i];
1363                 }
1364
1365                 /* The dash offset here aligns the pattern to integer pixels
1366                  * by starting the dash at the right side of the left border
1367                  * Negative dash offsets in cairo don't work
1368                  * (https://bugs.freedesktop.org/show_bug.cgi?id=2729)
1369                  */
1370                 dash_offset = -line_width / 2.;
1371                 while (dash_offset < 0)
1372                         dash_offset += total_length;
1373
1374                 cairo_set_dash (cr, dashes, n_dashes, dash_offset);
1375                 g_free (dashes);
1376         }
1377
1378         if (area)
1379         {
1380                 gdk_cairo_rectangle (cr, area);
1381                 cairo_clip (cr);
1382         }
1383
1384         cairo_rectangle (cr,
1385                          x + line_width / 2.,
1386                          y + line_width / 2.,
1387                          width - line_width, height - line_width);
1388         cairo_stroke (cr);
1389         cairo_destroy (cr);
1390
1391         if (free_dash_list)
1392                 g_free (dash_list);
1393 }
1394
1395 static void
1396 clearlooks_style_copy (GtkStyle * style, GtkStyle * src)
1397 {
1398         ClearlooksStyle * cl_style = CLEARLOOKS_STYLE (style);
1399         ClearlooksStyle * cl_src = CLEARLOOKS_STYLE (src);
1400         
1401         cl_style->colors              = cl_src->colors;
1402         cl_style->menubarstyle        = cl_src->menubarstyle;
1403         cl_style->toolbarstyle        = cl_src->toolbarstyle;
1404         cl_style->scrollbar_color     = cl_src->scrollbar_color;
1405         cl_style->has_scrollbar_color = cl_src->has_scrollbar_color;
1406         cl_style->colorize_scrollbar  = cl_src->colorize_scrollbar;
1407         cl_style->animation           = cl_src->animation;
1408         cl_style->radius              = cl_src->radius;
1409         cl_style->style               = cl_src->style;
1410         
1411         clearlooks_parent_class->copy (style, src);
1412 }
1413
1414 static void
1415 clearlooks_style_unrealize (GtkStyle * style)
1416 {
1417         clearlooks_parent_class->unrealize (style);
1418 }
1419
1420 static GdkPixbuf *
1421 set_transparency (const GdkPixbuf *pixbuf, gdouble alpha_percent)
1422 {
1423         GdkPixbuf *target;
1424         guchar *data, *current;
1425         guint x, y, rowstride, height, width;
1426
1427         g_return_val_if_fail (pixbuf != NULL, NULL);
1428         g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), NULL);
1429
1430         /* Returns a copy of pixbuf with it's non-completely-transparent pixels to
1431            have an alpha level "alpha_percent" of their original value. */
1432
1433         target = gdk_pixbuf_add_alpha (pixbuf, FALSE, 0, 0, 0);
1434
1435         if (alpha_percent == 1.0)
1436                 return target;
1437         width = gdk_pixbuf_get_width (target);
1438         height = gdk_pixbuf_get_height (target);
1439         rowstride = gdk_pixbuf_get_rowstride (target);
1440         data = gdk_pixbuf_get_pixels (target);
1441
1442         for (y = 0; y < height; y++) {
1443                 for (x = 0; x < width; x++) {
1444                         /* The "4" is the number of chars per pixel, in this case, RGBA,
1445                            the 3 means "skip to the alpha" */
1446                         current = data + (y * rowstride) + (x * 4) + 3; 
1447                         *(current) = (guchar) (*(current) * alpha_percent);
1448                 }
1449         }
1450
1451         return target;
1452 }
1453
1454 static GdkPixbuf*
1455 scale_or_ref (GdkPixbuf *src,
1456               int width,
1457               int height)
1458 {
1459         if (width == gdk_pixbuf_get_width (src) &&
1460             height == gdk_pixbuf_get_height (src)) {
1461                 return g_object_ref (src);
1462         } else {
1463                 return gdk_pixbuf_scale_simple (src,
1464                                         width, height,
1465                                         GDK_INTERP_BILINEAR);
1466         }
1467 }
1468
1469 static void
1470 clearlooks_style_draw_layout (GtkStyle * style,
1471              GdkWindow * window,
1472              GtkStateType state_type,
1473              gboolean use_text,
1474              GdkRectangle * area,
1475              GtkWidget * widget,
1476              const gchar * detail, gint x, gint y, PangoLayout * layout)
1477 {
1478         (void) detail;
1479
1480         GdkGC *gc;
1481
1482         g_return_if_fail (GTK_IS_STYLE (style));
1483         g_return_if_fail (window != NULL);
1484
1485         gc = use_text ? style->text_gc[state_type] : style->fg_gc[state_type];
1486
1487         if (area)
1488                 gdk_gc_set_clip_rectangle (gc, area);
1489
1490         if (state_type == GTK_STATE_INSENSITIVE) {
1491                 ClearlooksStyle *clearlooks_style = CLEARLOOKS_STYLE (style);
1492                 ClearlooksColors *colors = &clearlooks_style->colors;
1493
1494                 WidgetParameters params;
1495                 GdkColor etched;
1496                 CairoColor temp;
1497
1498                 clearlooks_set_widget_parameters (widget, style, state_type, &params);
1499
1500                 if (GTK_WIDGET_NO_WINDOW (widget))
1501                         ge_shade_color (&params.parentbg, 1.2, &temp);
1502                 else
1503                         ge_shade_color (&colors->bg[widget->state], 1.2, &temp);
1504                 
1505                 etched.red = (int) (temp.r * 65535);
1506                 etched.green = (int) (temp.g * 65535);
1507                 etched.blue = (int) (temp.b * 65535);
1508
1509                 gdk_draw_layout_with_colors (window, gc, x + 1, y + 1, layout, &etched, NULL);
1510                 gdk_draw_layout (window, gc, x, y, layout);
1511         }
1512         else
1513                 gdk_draw_layout (window, gc, x, y, layout);
1514
1515         if (area)
1516                 gdk_gc_set_clip_rectangle (gc, NULL);
1517 }
1518
1519 static GdkPixbuf *
1520 clearlooks_style_draw_render_icon (GtkStyle            *style,
1521              const GtkIconSource *source,
1522              GtkTextDirection     direction,
1523              GtkStateType         state,
1524              GtkIconSize          size,
1525              GtkWidget           *widget,
1526              const char          *detail)
1527 {
1528         (void) direction;
1529         (void) detail;
1530         
1531         int width = 1;
1532         int height = 1;
1533         GdkPixbuf *scaled;
1534         GdkPixbuf *stated;
1535         GdkPixbuf *base_pixbuf;
1536         GdkScreen *screen;
1537         GtkSettings *settings;
1538         
1539         /* Oddly, style can be NULL in this function, because
1540          * GtkIconSet can be used without a style and if so
1541          * it uses this function.
1542          */
1543         
1544         base_pixbuf = gtk_icon_source_get_pixbuf (source);
1545         
1546         g_return_val_if_fail (base_pixbuf != NULL, NULL);
1547         
1548         if (widget && gtk_widget_has_screen (widget)) {
1549                 screen = gtk_widget_get_screen (widget);
1550                 settings = gtk_settings_get_for_screen (screen);
1551         } else if (style->colormap) {
1552                 screen = gdk_colormap_get_screen (style->colormap);
1553                 settings = gtk_settings_get_for_screen (screen);
1554         } else {
1555                 settings = gtk_settings_get_default ();
1556                 GTK_NOTE (MULTIHEAD,
1557                           g_warning ("Using the default screen for gtk_default_render_icon()"));
1558         }
1559         
1560   
1561         if (size != (GtkIconSize) -1 && !gtk_icon_size_lookup_for_settings (settings, size, &width, &height)) {
1562                 g_warning (G_STRLOC ": invalid icon size '%d'", size);
1563                 return NULL;
1564         }
1565
1566         /* If the size was wildcarded, and we're allowed to scale, then scale; otherwise,
1567          * leave it alone.
1568          */
1569         if (size != (GtkIconSize)-1 && gtk_icon_source_get_size_wildcarded (source))
1570                 scaled = scale_or_ref (base_pixbuf, width, height);
1571         else
1572                 scaled = g_object_ref (base_pixbuf);
1573         
1574         /* If the state was wildcarded, then generate a state. */
1575         if (gtk_icon_source_get_state_wildcarded (source)) {
1576                 if (state == GTK_STATE_INSENSITIVE) {
1577                         stated = set_transparency (scaled, 0.3);
1578                         gdk_pixbuf_saturate_and_pixelate (stated, stated,
1579                                                           0.1, FALSE);
1580                         
1581                         g_object_unref (scaled);
1582                 } else if (state == GTK_STATE_PRELIGHT) {
1583                         stated = gdk_pixbuf_copy (scaled);      
1584                         
1585                         gdk_pixbuf_saturate_and_pixelate (scaled, stated,
1586                                                           1.2, FALSE);
1587                         
1588                         g_object_unref (scaled);
1589                 } else {
1590                         stated = scaled;
1591                 }
1592         }
1593         else
1594                 stated = scaled;
1595   
1596   return stated;
1597 }
1598
1599 static void
1600 clearlooks_style_init (ClearlooksStyle * style)
1601 {
1602         (void) style;
1603 }
1604
1605 static void
1606 clearlooks_style_class_init (ClearlooksStyleClass * klass)
1607 {
1608         GtkStyleClass *style_class = GTK_STYLE_CLASS (klass);
1609         
1610         clearlooks_style_class = CLEARLOOKS_STYLE_CLASS (klass);
1611         clearlooks_parent_class = g_type_class_peek_parent (klass);
1612
1613         style_class->copy             = clearlooks_style_copy;
1614         style_class->realize          = clearlooks_style_realize;
1615         style_class->unrealize        = clearlooks_style_unrealize;
1616         style_class->init_from_rc     = clearlooks_style_init_from_rc;
1617         style_class->draw_handle      = clearlooks_style_draw_handle;
1618         style_class->draw_slider      = clearlooks_style_draw_slider;
1619         style_class->draw_shadow_gap  = clearlooks_style_draw_shadow_gap;
1620         style_class->draw_focus       = clearlooks_style_draw_focus;
1621         style_class->draw_box         = clearlooks_style_draw_box;
1622         style_class->draw_shadow      = clearlooks_style_draw_shadow;
1623         style_class->draw_box_gap     = clearlooks_style_draw_box_gap;
1624         style_class->draw_extension   = clearlooks_style_draw_extension;
1625         style_class->draw_option      = clearlooks_style_draw_option;
1626         style_class->draw_check       = clearlooks_style_draw_check;
1627         style_class->draw_flat_box    = clearlooks_style_draw_flat_box;
1628         style_class->draw_vline       = clearlooks_style_draw_vline;
1629         style_class->draw_hline       = clearlooks_style_draw_hline;
1630         style_class->draw_resize_grip = clearlooks_style_draw_resize_grip;
1631         style_class->draw_tab         = clearlooks_style_draw_tab;
1632         style_class->draw_arrow       = clearlooks_style_draw_arrow;
1633         style_class->draw_layout      = clearlooks_style_draw_layout;
1634         style_class->render_icon      = clearlooks_style_draw_render_icon;
1635
1636         clearlooks_register_style_classic (&clearlooks_style_class->style_functions[CL_STYLE_CLASSIC]);
1637         clearlooks_style_class->style_functions[CL_STYLE_GLOSSY] = clearlooks_style_class->style_functions[CL_STYLE_CLASSIC];
1638         clearlooks_register_style_glossy (&clearlooks_style_class->style_functions[CL_STYLE_GLOSSY]);
1639         clearlooks_style_class->style_functions[CL_STYLE_INVERTED] = clearlooks_style_class->style_functions[CL_STYLE_CLASSIC];
1640         clearlooks_register_style_inverted (&clearlooks_style_class->style_functions[CL_STYLE_INVERTED]);
1641         clearlooks_style_class->style_functions[CL_STYLE_GUMMY] = clearlooks_style_class->style_functions[CL_STYLE_CLASSIC];
1642         clearlooks_register_style_gummy (&clearlooks_style_class->style_functions[CL_STYLE_GUMMY]);
1643 }
1644
1645 GType clearlooks_type_style = 0;
1646
1647 void
1648 clearlooks_style_register_type (GTypeModule * module)
1649 {
1650         static const GTypeInfo object_info =
1651         {
1652                 sizeof (ClearlooksStyleClass),
1653                 (GBaseInitFunc) NULL,
1654                 (GBaseFinalizeFunc) NULL,
1655                 (GClassInitFunc) clearlooks_style_class_init,
1656                 NULL,         /* class_finalize */
1657                 NULL,         /* class_data */
1658                 sizeof (ClearlooksStyle),
1659                 0,            /* n_preallocs */
1660                 (GInstanceInitFunc) clearlooks_style_init,
1661                 NULL
1662         };
1663
1664         clearlooks_type_style = g_type_module_register_type (module,
1665                                                              GTK_TYPE_STYLE,
1666                                                              "ClearlooksStyle",
1667                                                              &object_info, 0);
1668 }