gtkstyle.c 126 KB
Newer Older
Elliot Lee's avatar
Elliot Lee committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/* GTK - The GIMP Toolkit
 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
15 16 17
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
Elliot Lee's avatar
Elliot Lee committed
18
 */
19 20 21 22 23 24 25 26

/*
 * Modified by the GTK+ Team and others 1997-1999.  See the AUTHORS
 * file for a list of people on the GTK+ Team.  See the ChangeLog
 * files for a list of changes.  These files are distributed with
 * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
 */

Elliot Lee's avatar
Elliot Lee committed
27 28
#include <math.h>
#include "gtkgc.h"
29
#include "gtkrc.h"
Elliot Lee's avatar
Elliot Lee committed
30
#include "gtkstyle.h"
31
#include "gtkthemes.h"
32
#include "gtkwidget.h"
33
#include "gtkthemes.h"
34
#include "gdkprivate.h"
Elliot Lee's avatar
Elliot Lee committed
35 36 37 38 39


#define LIGHTNESS_MULT  1.3
#define DARKNESS_MULT   0.7

40 41 42 43 44 45 46 47
/* actually glib should do that for us */
#ifndef M_PI
#define M_PI    3.14159265358979323846
#endif /* M_PI */
#ifndef M_PI_4
#define M_PI_4  0.78539816339744830962
#endif /* M_PI_4 */

48
static void         gtk_style_init         (GtkStyle    *style,
49 50
                                            GdkColormap *colormap,
                                            gint         depth);
Elliot Lee's avatar
Elliot Lee committed
51 52 53
static void         gtk_style_destroy      (GtkStyle    *style);

static void gtk_default_draw_hline   (GtkStyle      *style,
54 55 56 57 58 59 60 61
                                      GdkWindow     *window,
                                      GtkStateType   state_type,
                                      GdkRectangle  *area,
                                      GtkWidget     *widget,
                                      gchar         *detail,
                                      gint           x1,
                                      gint           x2,
                                      gint           y);
Elliot Lee's avatar
Elliot Lee committed
62
static void gtk_default_draw_vline   (GtkStyle      *style,
63 64 65 66 67 68 69 70
                                      GdkWindow     *window,
                                      GtkStateType   state_type,
                                      GdkRectangle  *area,
                                      GtkWidget     *widget,
                                      gchar         *detail,
                                      gint           y1,
                                      gint           y2,
                                      gint           x);
Elliot Lee's avatar
Elliot Lee committed
71
static void gtk_default_draw_shadow  (GtkStyle      *style,
72 73 74 75 76 77 78 79 80 81
                                      GdkWindow     *window,
                                      GtkStateType   state_type,
                                      GtkShadowType  shadow_type,
                                      GdkRectangle  *area,
                                      GtkWidget     *widget,
                                      gchar         *detail,
                                      gint           x,
                                      gint           y,
                                      gint           width,
                                      gint           height);
82
static void gtk_default_draw_shadow  (GtkStyle      *style,
83 84 85 86 87 88 89 90 91 92
                                      GdkWindow     *window,
                                      GtkStateType   state_type,
                                      GtkShadowType  shadow_type,
                                      GdkRectangle  *area,
                                      GtkWidget     *widget,
                                      gchar         *detail,
                                      gint           x,
                                      gint           y,
                                      gint           width,
                                      gint           height);
Elliot Lee's avatar
Elliot Lee committed
93
static void gtk_default_draw_polygon (GtkStyle      *style,
94 95 96 97 98 99 100 101 102
                                      GdkWindow     *window,
                                      GtkStateType   state_type,
                                      GtkShadowType  shadow_type,
                                      GdkRectangle  *area,
                                      GtkWidget     *widget,
                                      gchar         *detail,
                                      GdkPoint      *points,
                                      gint           npoints,
                                      gboolean       fill);
Elliot Lee's avatar
Elliot Lee committed
103
static void gtk_default_draw_arrow   (GtkStyle      *style,
104 105 106 107 108 109 110 111 112 113 114 115
                                      GdkWindow     *window,
                                      GtkStateType   state_type,
                                      GtkShadowType  shadow_type,
                                      GdkRectangle  *area,
                                      GtkWidget     *widget,
                                      gchar         *detail,
                                      GtkArrowType   arrow_type,
                                      gboolean       fill,
                                      gint           x,
                                      gint           y,
                                      gint           width,
                                      gint           height);
Elliot Lee's avatar
Elliot Lee committed
116
static void gtk_default_draw_diamond (GtkStyle      *style,
117 118 119 120 121 122 123 124 125 126
                                      GdkWindow     *window,
                                      GtkStateType   state_type,
                                      GtkShadowType  shadow_type,
                                      GdkRectangle  *area,
                                      GtkWidget     *widget,
                                      gchar         *detail,
                                      gint           x,
                                      gint           y,
                                      gint           width,
                                      gint           height);
Elliot Lee's avatar
Elliot Lee committed
127
static void gtk_default_draw_oval    (GtkStyle      *style,
128 129 130 131 132 133 134 135 136 137
                                      GdkWindow     *window,
                                      GtkStateType   state_type,
                                      GtkShadowType  shadow_type,
                                      GdkRectangle  *area,
                                      GtkWidget     *widget,
                                      gchar         *detail,
                                      gint           x,
                                      gint           y,
                                      gint           width,
                                      gint           height);
Elliot Lee's avatar
Elliot Lee committed
138
static void gtk_default_draw_string  (GtkStyle      *style,
139 140 141 142 143 144 145 146
                                      GdkWindow     *window,
                                      GtkStateType   state_type,
                                      GdkRectangle  *area,
                                      GtkWidget     *widget,
                                      gchar         *detail,
                                      gint           x,
                                      gint           y,
                                      const gchar   *string);
147
static void gtk_default_draw_box     (GtkStyle      *style,
148 149 150 151 152 153 154 155 156 157
                                      GdkWindow     *window,
                                      GtkStateType   state_type,
                                      GtkShadowType  shadow_type,
                                      GdkRectangle  *area,
                                      GtkWidget     *widget,
                                      gchar         *detail,
                                      gint           x,
                                      gint           y,
                                      gint           width,
                                      gint           height);
158
static void gtk_default_draw_flat_box (GtkStyle      *style,
159 160 161 162 163 164 165 166 167 168
                                       GdkWindow     *window,
                                       GtkStateType   state_type,
                                       GtkShadowType  shadow_type,
                                       GdkRectangle  *area,
                                       GtkWidget     *widget,
                                       gchar         *detail,
                                       gint           x,
                                       gint           y,
                                       gint           width,
                                       gint           height);
169
static void gtk_default_draw_check   (GtkStyle      *style,
170 171 172 173 174 175 176 177 178 179
                                      GdkWindow     *window,
                                      GtkStateType   state_type,
                                      GtkShadowType  shadow_type,
                                      GdkRectangle  *area,
                                      GtkWidget     *widget,
                                      gchar         *detail,
                                      gint           x,
                                      gint           y,
                                      gint           width,
                                      gint           height);
180
static void gtk_default_draw_option  (GtkStyle      *style,
181 182 183 184 185 186 187 188 189 190
                                      GdkWindow     *window,
                                      GtkStateType   state_type,
                                      GtkShadowType  shadow_type,
                                      GdkRectangle  *area,
                                      GtkWidget     *widget,
                                      gchar         *detail,
                                      gint           x,
                                      gint           y,
                                      gint           width,
                                      gint           height);
191
static void gtk_default_draw_cross   (GtkStyle      *style,
192 193 194 195 196 197 198 199 200 201
                                      GdkWindow     *window,
                                      GtkStateType   state_type,
                                      GtkShadowType  shadow_type,
                                      GdkRectangle  *area,
                                      GtkWidget     *widget,
                                      gchar         *detail,
                                      gint           x,
                                      gint           y,
                                      gint           width,
                                      gint           height);
202
static void gtk_default_draw_ramp    (GtkStyle      *style,
203 204 205 206 207 208 209 210 211 212 213
                                      GdkWindow     *window,
                                      GtkStateType   state_type,
                                      GtkShadowType  shadow_type,
                                      GdkRectangle  *area,
                                      GtkWidget     *widget,
                                      gchar         *detail,
                                      GtkArrowType   arrow_type,
                                      gint           x,
                                      gint           y,
                                      gint           width,
                                      gint           height);
214
static void gtk_default_draw_tab     (GtkStyle      *style,
215 216 217 218 219 220 221 222 223 224
                                      GdkWindow     *window,
                                      GtkStateType   state_type,
                                      GtkShadowType  shadow_type,
                                      GdkRectangle  *area,
                                      GtkWidget     *widget,
                                      gchar         *detail,
                                      gint           x,
                                      gint           y,
                                      gint           width,
                                      gint           height);
225
static void gtk_default_draw_shadow_gap (GtkStyle       *style,
226 227 228 229 230 231 232 233 234 235 236 237 238
                                         GdkWindow      *window,
                                         GtkStateType    state_type,
                                         GtkShadowType   shadow_type,
                                         GdkRectangle   *area,
                                         GtkWidget      *widget,
                                         gchar          *detail,
                                         gint            x,
                                         gint            y,
                                         gint            width,
                                         gint            height,
                                         GtkPositionType gap_side,
                                         gint            gap_x,
                                         gint            gap_width);
239
static void gtk_default_draw_box_gap (GtkStyle       *style,
240 241 242 243 244 245 246 247 248 249 250 251 252
                                      GdkWindow      *window,
                                      GtkStateType    state_type,
                                      GtkShadowType   shadow_type,
                                      GdkRectangle   *area,
                                      GtkWidget      *widget,
                                      gchar          *detail,
                                      gint            x,
                                      gint            y,
                                      gint            width,
                                      gint            height,
                                      GtkPositionType gap_side,
                                      gint            gap_x,
                                      gint            gap_width);
253
static void gtk_default_draw_extension (GtkStyle       *style,
254 255 256 257 258 259 260 261 262 263 264
                                        GdkWindow      *window,
                                        GtkStateType    state_type,
                                        GtkShadowType   shadow_type,
                                        GdkRectangle   *area,
                                        GtkWidget      *widget,
                                        gchar          *detail,
                                        gint            x,
                                        gint            y,
                                        gint            width,
                                        gint            height,
                                        GtkPositionType gap_side);
265
static void gtk_default_draw_focus   (GtkStyle      *style,
266 267 268 269 270 271 272 273
                                      GdkWindow     *window,
                                      GdkRectangle  *area,
                                      GtkWidget     *widget,
                                      gchar         *detail,
                                      gint           x,
                                      gint           y,
                                      gint           width,
                                      gint           height);
274
static void gtk_default_draw_slider  (GtkStyle      *style,
275 276 277 278 279 280 281 282 283 284 285
                                      GdkWindow     *window,
                                      GtkStateType   state_type,
                                      GtkShadowType  shadow_type,
                                      GdkRectangle  *area,
                                      GtkWidget     *widget,
                                      gchar         *detail,
                                      gint           x,
                                      gint           y,
                                      gint           width,
                                      gint           height,
                                      GtkOrientation orientation);
286
static void gtk_default_draw_handle  (GtkStyle      *style,
287 288 289 290 291 292 293 294 295 296 297
                                      GdkWindow     *window,
                                      GtkStateType   state_type,
                                      GtkShadowType  shadow_type,
                                      GdkRectangle  *area,
                                      GtkWidget     *widget,
                                      gchar         *detail,
                                      gint           x,
                                      gint           y,
                                      gint           width,
                                      gint           height,
                                      GtkOrientation orientation);
298

Elliot Lee's avatar
Elliot Lee committed
299 300 301 302 303

static void gtk_style_shade (GdkColor *a, GdkColor *b, gdouble k);
static void rgb_to_hls (gdouble *r, gdouble *g, gdouble *b);
static void hls_to_rgb (gdouble *h, gdouble *l, gdouble *s);

304

305
static const GtkStyleClass default_class =
Elliot Lee's avatar
Elliot Lee committed
306
{
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329
  2,
  2,
  gtk_default_draw_hline,
  gtk_default_draw_vline,
  gtk_default_draw_shadow,
  gtk_default_draw_polygon,
  gtk_default_draw_arrow,
  gtk_default_draw_diamond,
  gtk_default_draw_oval,
  gtk_default_draw_string,
  gtk_default_draw_box,
  gtk_default_draw_flat_box,
  gtk_default_draw_check,
  gtk_default_draw_option,
  gtk_default_draw_cross,
  gtk_default_draw_ramp,
  gtk_default_draw_tab,
  gtk_default_draw_shadow_gap,
  gtk_default_draw_box_gap,
  gtk_default_draw_extension,
  gtk_default_draw_focus,
  gtk_default_draw_slider,
  gtk_default_draw_handle
Elliot Lee's avatar
Elliot Lee committed
330
};
331
GdkFont *default_font = NULL;
Elliot Lee's avatar
Elliot Lee committed
332 333 334 335 336 337 338 339 340 341 342 343 344

static GdkColor gtk_default_normal_fg =      { 0,      0,      0,      0 };
static GdkColor gtk_default_active_fg =      { 0,      0,      0,      0 };
static GdkColor gtk_default_prelight_fg =    { 0,      0,      0,      0 };
static GdkColor gtk_default_selected_fg =    { 0, 0xffff, 0xffff, 0xffff };
static GdkColor gtk_default_insensitive_fg = { 0, 0x7530, 0x7530, 0x7530 };

static GdkColor gtk_default_normal_bg =      { 0, 0xd6d6, 0xd6d6, 0xd6d6 };
static GdkColor gtk_default_active_bg =      { 0, 0xc350, 0xc350, 0xc350 };
static GdkColor gtk_default_prelight_bg =    { 0, 0xea60, 0xea60, 0xea60 };
static GdkColor gtk_default_selected_bg =    { 0,      0,      0, 0x9c40 };
static GdkColor gtk_default_insensitive_bg = { 0, 0xd6d6, 0xd6d6, 0xd6d6 };

345
GtkStyle*
346
gtk_style_copy (GtkStyle *style)
347 348 349
{
  GtkStyle *new_style;
  guint i;
350
  
351
  g_return_val_if_fail (style != NULL, NULL);
352
  
353
  new_style = gtk_style_new ();
354
  
355 356 357 358 359 360
  for (i = 0; i < 5; i++)
    {
      new_style->fg[i] = style->fg[i];
      new_style->bg[i] = style->bg[i];
      new_style->text[i] = style->text[i];
      new_style->base[i] = style->base[i];
361
      
362 363
      new_style->bg_pixmap[i] = style->bg_pixmap[i];
    }
364
  
365
  gdk_font_unref (new_style->font);
366 367
  new_style->font = style->font;
  gdk_font_ref (new_style->font);
Stuart Parmenter's avatar
Stuart Parmenter committed
368 369 370 371 372 373

  if (style->rc_style)
    {
      new_style->rc_style = style->rc_style;
      gtk_rc_style_ref (style->rc_style);
    }
374
  
Stuart Parmenter's avatar
Stuart Parmenter committed
375 376 377 378 379 380 381
  if (style->engine)
    {
      new_style->engine = style->engine;
      gtk_theme_engine_ref(new_style->engine);
      new_style->engine->duplicate_style (new_style, style);
    }

382 383
  return new_style;
}
Elliot Lee's avatar
Elliot Lee committed
384

385
static GtkStyle*
386
gtk_style_duplicate (GtkStyle *style)
387 388
{
  GtkStyle *new_style;
389
  
390
  g_return_val_if_fail (style != NULL, NULL);
391
  
392
  new_style = gtk_style_copy (style);
393
  
394 395
  style->styles = g_slist_append (style->styles, new_style);
  new_style->styles = style->styles;  
396
  
397 398 399
  return new_style;
}

Elliot Lee's avatar
Elliot Lee committed
400
GtkStyle*
401
gtk_style_new (void)
Elliot Lee's avatar
Elliot Lee committed
402 403 404
{
  GtkStyle *style;
  gint i;
405
  
406
  style = g_new0 (GtkStyle, 1);
407
  
Elliot Lee's avatar
Elliot Lee committed
408
  if (!default_font)
409 410 411 412 413 414 415 416
    {
      default_font =
	gdk_font_load ("-adobe-helvetica-medium-r-normal--*-120-*-*-*-*-*-*");
      if (!default_font)
	default_font = gdk_font_load ("fixed");
      if (!default_font)
	g_error ("Unable to load default font.");
    }
417
  
Elliot Lee's avatar
Elliot Lee committed
418 419
  style->font = default_font;
  gdk_font_ref (style->font);
420
  
421
  style->ref_count = 1;
Elliot Lee's avatar
Elliot Lee committed
422 423 424 425
  style->attach_count = 0;
  style->colormap = NULL;
  style->depth = -1;
  style->klass = &default_class;
426
  
Elliot Lee's avatar
Elliot Lee committed
427 428 429
  style->black.red = 0;
  style->black.green = 0;
  style->black.blue = 0;
430
  
Elliot Lee's avatar
Elliot Lee committed
431 432 433
  style->white.red = 65535;
  style->white.green = 65535;
  style->white.blue = 65535;
434
  
Elliot Lee's avatar
Elliot Lee committed
435 436
  style->black_gc = NULL;
  style->white_gc = NULL;
437
  
Elliot Lee's avatar
Elliot Lee committed
438 439 440 441 442
  style->fg[GTK_STATE_NORMAL] = gtk_default_normal_fg;
  style->fg[GTK_STATE_ACTIVE] = gtk_default_active_fg;
  style->fg[GTK_STATE_PRELIGHT] = gtk_default_prelight_fg;
  style->fg[GTK_STATE_SELECTED] = gtk_default_selected_fg;
  style->fg[GTK_STATE_INSENSITIVE] = gtk_default_insensitive_fg;
443
  
Elliot Lee's avatar
Elliot Lee committed
444 445 446 447 448
  style->bg[GTK_STATE_NORMAL] = gtk_default_normal_bg;
  style->bg[GTK_STATE_ACTIVE] = gtk_default_active_bg;
  style->bg[GTK_STATE_PRELIGHT] = gtk_default_prelight_bg;
  style->bg[GTK_STATE_SELECTED] = gtk_default_selected_bg;
  style->bg[GTK_STATE_INSENSITIVE] = gtk_default_insensitive_bg;
449
  
450
  for (i = 0; i < 4; i++)
Elliot Lee's avatar
Elliot Lee committed
451 452 453 454
    {
      style->text[i] = style->fg[i];
      style->base[i] = style->white;
    }
455
  
456 457
  style->base[GTK_STATE_INSENSITIVE] = gtk_default_insensitive_bg;
  style->text[GTK_STATE_INSENSITIVE] = gtk_default_insensitive_bg;
458
  
Elliot Lee's avatar
Elliot Lee committed
459 460
  for (i = 0; i < 5; i++)
    style->bg_pixmap[i] = NULL;
461
  
462 463
  style->engine = NULL;
  style->engine_data = NULL;
464
  
465
  style->rc_style = NULL;
466
  
Elliot Lee's avatar
Elliot Lee committed
467 468 469 470 471 472 473 474 475 476
  for (i = 0; i < 5; i++)
    {
      style->fg_gc[i] = NULL;
      style->bg_gc[i] = NULL;
      style->light_gc[i] = NULL;
      style->dark_gc[i] = NULL;
      style->mid_gc[i] = NULL;
      style->text_gc[i] = NULL;
      style->base_gc[i] = NULL;
    }
477
  
Elliot Lee's avatar
Elliot Lee committed
478 479 480
  return style;
}

481
GtkStyle*
Elliot Lee's avatar
Elliot Lee committed
482
gtk_style_attach (GtkStyle  *style,
483
                  GdkWindow *window)
Elliot Lee's avatar
Elliot Lee committed
484
{
485 486
  GSList *styles;
  GtkStyle *new_style = NULL;
Elliot Lee's avatar
Elliot Lee committed
487 488
  GdkColormap *colormap;
  gint depth;
489
  
Elliot Lee's avatar
Elliot Lee committed
490 491
  g_return_val_if_fail (style != NULL, NULL);
  g_return_val_if_fail (window != NULL, NULL);
492
  
Elliot Lee's avatar
Elliot Lee committed
493
  colormap = gdk_window_get_colormap (window);
494
  depth = gdk_window_get_visual (window)->depth;
495
  
496 497
  if (!style->styles)
    style->styles = g_slist_append (NULL, style);
498
  
499 500
  styles = style->styles;
  while (styles)
Elliot Lee's avatar
Elliot Lee committed
501
    {
502
      new_style = styles->data;
503
      
504
      if (new_style->attach_count == 0)
505 506 507 508 509 510 511
        {
          gtk_style_init (new_style, colormap, depth);
          break;
        }
      else if (new_style->colormap == colormap &&
               new_style->depth == depth)
        break;
512
      
513 514
      new_style = NULL;
      styles = styles->next;
Elliot Lee's avatar
Elliot Lee committed
515
    }
516
  
517 518 519 520 521
  if (!new_style)
    {
      new_style = gtk_style_duplicate (style);
      gtk_style_init (new_style, colormap, depth);
    }
522
  
523 524
  if (new_style->attach_count == 0)
    gtk_style_ref (new_style);
525
  
526
  new_style->attach_count++;
527
  
528
  return new_style;
Elliot Lee's avatar
Elliot Lee committed
529 530 531 532 533 534
}

void
gtk_style_detach (GtkStyle *style)
{
  gint i;
535
  
Elliot Lee's avatar
Elliot Lee committed
536
  g_return_if_fail (style != NULL);
537
  
Elliot Lee's avatar
Elliot Lee committed
538 539 540
  style->attach_count -= 1;
  if (style->attach_count == 0)
    {
541
      if (style->engine)
542
        style->engine->unrealize_style (style);
543
      
Elliot Lee's avatar
Elliot Lee committed
544 545
      gtk_gc_release (style->black_gc);
      gtk_gc_release (style->white_gc);
546
      
Elliot Lee's avatar
Elliot Lee committed
547
      for (i = 0; i < 5; i++)
548 549 550 551 552 553 554 555 556
        {
          gtk_gc_release (style->fg_gc[i]);
          gtk_gc_release (style->bg_gc[i]);
          gtk_gc_release (style->light_gc[i]);
          gtk_gc_release (style->dark_gc[i]);
          gtk_gc_release (style->mid_gc[i]);
          gtk_gc_release (style->text_gc[i]);
          gtk_gc_release (style->base_gc[i]);
        }
557
      
558
      gtk_style_unref (style);
Elliot Lee's avatar
Elliot Lee committed
559 560 561 562 563 564 565
    }
}

GtkStyle*
gtk_style_ref (GtkStyle *style)
{
  g_return_val_if_fail (style != NULL, NULL);
566
  
Elliot Lee's avatar
Elliot Lee committed
567 568 569 570 571 572 573 574
  style->ref_count += 1;
  return style;
}

void
gtk_style_unref (GtkStyle *style)
{
  g_return_if_fail (style != NULL);
575
  
Elliot Lee's avatar
Elliot Lee committed
576 577 578 579 580
  style->ref_count -= 1;
  if (style->ref_count == 0)
    gtk_style_destroy (style);
}

581
static void
582 583 584
gtk_style_init (GtkStyle    *style,
                GdkColormap *colormap,
                gint         depth)
585 586 587 588
{
  GdkGCValues gc_values;
  GdkGCValuesMask gc_values_mask;
  gint i;
589
  
590
  g_return_if_fail (style != NULL);
591
  
592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626
  style->colormap = colormap;
  style->depth = depth;
  
  for (i = 0; i < 5; i++)
    {
      gtk_style_shade (&style->bg[i], &style->light[i], LIGHTNESS_MULT);
      gtk_style_shade (&style->bg[i], &style->dark[i], DARKNESS_MULT);
      
      style->mid[i].red = (style->light[i].red + style->dark[i].red) / 2;
      style->mid[i].green = (style->light[i].green + style->dark[i].green) / 2;
      style->mid[i].blue = (style->light[i].blue + style->dark[i].blue) / 2;
    }
  
  gdk_color_black (colormap, &style->black);
  gdk_color_white (colormap, &style->white);
  
  gc_values_mask = GDK_GC_FOREGROUND | GDK_GC_FONT;
  if (style->font->type == GDK_FONT_FONT)
    {
      gc_values.font = style->font;
    }
  else if (style->font->type == GDK_FONT_FONTSET)
    {
      gc_values.font = default_font;
    }
  
  gc_values.foreground = style->black;
  style->black_gc = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
  
  gc_values.foreground = style->white;
  style->white_gc = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
  
  for (i = 0; i < 5; i++)
    {
      if (style->rc_style && style->rc_style->bg_pixmap_name[i])
627 628 629
        style->bg_pixmap[i] = gtk_rc_load_image (style->colormap,
                                                 &style->bg[i],
                                                 style->rc_style->bg_pixmap_name[i]);
630 631
      
      if (!gdk_color_alloc (colormap, &style->fg[i]))
632 633
        g_warning ("unable to allocate color: ( %d %d %d )",
                   style->fg[i].red, style->fg[i].green, style->fg[i].blue);
634
      if (!gdk_color_alloc (colormap, &style->bg[i]))
635 636
        g_warning ("unable to allocate color: ( %d %d %d )",
                   style->bg[i].red, style->bg[i].green, style->bg[i].blue);
637
      if (!gdk_color_alloc (colormap, &style->light[i]))
638 639
        g_warning ("unable to allocate color: ( %d %d %d )",
                   style->light[i].red, style->light[i].green, style->light[i].blue);
640
      if (!gdk_color_alloc (colormap, &style->dark[i]))
641 642
        g_warning ("unable to allocate color: ( %d %d %d )",
                   style->dark[i].red, style->dark[i].green, style->dark[i].blue);
643
      if (!gdk_color_alloc (colormap, &style->mid[i]))
644 645
        g_warning ("unable to allocate color: ( %d %d %d )",
                   style->mid[i].red, style->mid[i].green, style->mid[i].blue);
646
      if (!gdk_color_alloc (colormap, &style->text[i]))
647 648
        g_warning ("unable to allocate color: ( %d %d %d )",
                   style->text[i].red, style->text[i].green, style->text[i].blue);
649
      if (!gdk_color_alloc (colormap, &style->base[i]))
650 651
        g_warning ("unable to allocate color: ( %d %d %d )",
                   style->base[i].red, style->base[i].green, style->base[i].blue);
652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669
      
      gc_values.foreground = style->fg[i];
      style->fg_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
      
      gc_values.foreground = style->bg[i];
      style->bg_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
      
      gc_values.foreground = style->light[i];
      style->light_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
      
      gc_values.foreground = style->dark[i];
      style->dark_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
      
      gc_values.foreground = style->mid[i];
      style->mid_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
      
      gc_values.foreground = style->text[i];
      style->text_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
670
      
671 672 673
      gc_values.foreground = style->base[i];
      style->base_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
    }
674
  
675 676 677 678 679 680 681 682
  if (style->engine)
    style->engine->realize_style (style);
}

static void
gtk_style_destroy (GtkStyle *style)
{
  g_return_if_fail (style->attach_count == 0);
683
  
684 685 686
  if (style->styles)
    {
      if (style->styles->data != style)
687
        g_slist_remove (style->styles, style);
688
      else
689 690 691 692 693 694 695 696 697 698
        {
          GSList *tmp_list = style->styles->next;
	  
          while (tmp_list)
            {
              ((GtkStyle*) tmp_list->data)->styles = style->styles->next;
              tmp_list = tmp_list->next;
            }
          g_slist_free_1 (style->styles);
        }
699
    }
700
  
701 702 703 704 705
  if (style->engine)
    {
      style->engine->destroy_style (style);
      gtk_theme_engine_unref (style->engine);
    }
706
  
707 708 709
  gdk_font_unref (style->font);
  if (style->rc_style)
    gtk_rc_style_unref (style->rc_style);
710
  
711 712 713
  g_free (style);
}

Elliot Lee's avatar
Elliot Lee committed
714 715
void
gtk_draw_hline (GtkStyle     *style,
716 717 718 719 720
                GdkWindow    *window,
                GtkStateType  state_type,
                gint          x1,
                gint          x2,
                gint          y)
Elliot Lee's avatar
Elliot Lee committed
721 722 723 724
{
  g_return_if_fail (style != NULL);
  g_return_if_fail (style->klass != NULL);
  g_return_if_fail (style->klass->draw_hline != NULL);
725
  
726
  style->klass->draw_hline (style, window, state_type, NULL, NULL, NULL, x1, x2, y);
Elliot Lee's avatar
Elliot Lee committed
727 728 729 730 731
}


void
gtk_draw_vline (GtkStyle     *style,
732 733 734 735 736
                GdkWindow    *window,
                GtkStateType  state_type,
                gint          y1,
                gint          y2,
                gint          x)
Elliot Lee's avatar
Elliot Lee committed
737 738 739 740
{
  g_return_if_fail (style != NULL);
  g_return_if_fail (style->klass != NULL);
  g_return_if_fail (style->klass->draw_vline != NULL);
741
  
742
  style->klass->draw_vline (style, window, state_type, NULL, NULL, NULL, y1, y2, x);
Elliot Lee's avatar
Elliot Lee committed
743 744 745 746 747
}


void
gtk_draw_shadow (GtkStyle      *style,
748 749 750 751 752 753 754
                 GdkWindow     *window,
                 GtkStateType   state_type,
                 GtkShadowType  shadow_type,
                 gint           x,
                 gint           y,
                 gint           width,
                 gint           height)
Elliot Lee's avatar
Elliot Lee committed
755 756 757 758
{
  g_return_if_fail (style != NULL);
  g_return_if_fail (style->klass != NULL);
  g_return_if_fail (style->klass->draw_shadow != NULL);
759
  
760
  style->klass->draw_shadow (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
Elliot Lee's avatar
Elliot Lee committed
761 762 763 764
}

void
gtk_draw_polygon (GtkStyle      *style,
765 766 767 768 769 770
                  GdkWindow     *window,
                  GtkStateType   state_type,
                  GtkShadowType  shadow_type,
                  GdkPoint      *points,
                  gint           npoints,
                  gboolean       fill)
Elliot Lee's avatar
Elliot Lee committed
771 772 773
{
  g_return_if_fail (style != NULL);
  g_return_if_fail (style->klass != NULL);
774
  g_return_if_fail (style->klass->draw_polygon != NULL);
775
  
776
  style->klass->draw_polygon (style, window, state_type, shadow_type, NULL, NULL, NULL, points, npoints, fill);
Elliot Lee's avatar
Elliot Lee committed
777 778 779 780
}

void
gtk_draw_arrow (GtkStyle      *style,
781 782 783 784 785 786 787 788 789
                GdkWindow     *window,
                GtkStateType   state_type,
                GtkShadowType  shadow_type,
                GtkArrowType   arrow_type,
                gboolean       fill,
                gint           x,
                gint           y,
                gint           width,
                gint           height)
Elliot Lee's avatar
Elliot Lee committed
790 791 792 793
{
  g_return_if_fail (style != NULL);
  g_return_if_fail (style->klass != NULL);
  g_return_if_fail (style->klass->draw_arrow != NULL);
794
  
795
  style->klass->draw_arrow (style, window, state_type, shadow_type, NULL, NULL, NULL, arrow_type, fill, x, y, width, height);
Elliot Lee's avatar
Elliot Lee committed
796 797 798 799 800
}


void
gtk_draw_diamond (GtkStyle      *style,
801 802 803 804 805 806 807
                  GdkWindow     *window,
                  GtkStateType   state_type,
                  GtkShadowType  shadow_type,
                  gint           x,
                  gint           y,
                  gint           width,
                  gint           height)
Elliot Lee's avatar
Elliot Lee committed
808 809 810 811
{
  g_return_if_fail (style != NULL);
  g_return_if_fail (style->klass != NULL);
  g_return_if_fail (style->klass->draw_diamond != NULL);
812
  
813
  style->klass->draw_diamond (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
Elliot Lee's avatar
Elliot Lee committed
814 815 816 817 818
}


void
gtk_draw_oval (GtkStyle      *style,
819 820 821 822 823 824 825
               GdkWindow     *window,
               GtkStateType   state_type,
               GtkShadowType  shadow_type,
               gint           x,
               gint           y,
               gint           width,
               gint           height)
Elliot Lee's avatar
Elliot Lee committed
826 827 828 829
{
  g_return_if_fail (style != NULL);
  g_return_if_fail (style->klass != NULL);
  g_return_if_fail (style->klass->draw_oval != NULL);
830
  
831
  style->klass->draw_oval (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
Elliot Lee's avatar
Elliot Lee committed
832 833 834 835
}

void
gtk_draw_string (GtkStyle      *style,
836 837 838 839 840
                 GdkWindow     *window,
                 GtkStateType   state_type,
                 gint           x,
                 gint           y,
                 const gchar   *string)
Elliot Lee's avatar
Elliot Lee committed
841 842 843
{
  g_return_if_fail (style != NULL);
  g_return_if_fail (style->klass != NULL);
844
  g_return_if_fail (style->klass->draw_string != NULL);
845
  
846
  style->klass->draw_string (style, window, state_type, NULL, NULL, NULL, x, y, string);
Elliot Lee's avatar
Elliot Lee committed
847 848
}

849 850
void
gtk_draw_box (GtkStyle      *style,
851 852 853 854 855 856 857
              GdkWindow     *window,
              GtkStateType   state_type,
              GtkShadowType  shadow_type,
              gint           x,
              gint           y,
              gint           width,
              gint           height)
Elliot Lee's avatar
Elliot Lee committed
858
{
859 860 861 862
  g_return_if_fail (style != NULL);
  g_return_if_fail (style->klass != NULL);
  g_return_if_fail (style->klass->draw_box != NULL);
  
863
  style->klass->draw_box (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
Elliot Lee's avatar
Elliot Lee committed
864 865
}

866 867
void
gtk_draw_flat_box (GtkStyle      *style,
868 869 870 871 872 873 874
                   GdkWindow     *window,
                   GtkStateType   state_type,
                   GtkShadowType  shadow_type,
                   gint           x,
                   gint           y,
                   gint           width,
                   gint           height)
Elliot Lee's avatar
Elliot Lee committed
875
{
876 877 878 879
  g_return_if_fail (style != NULL);
  g_return_if_fail (style->klass != NULL);
  g_return_if_fail (style->klass->draw_flat_box != NULL);
  
880
  style->klass->draw_flat_box (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
Elliot Lee's avatar
Elliot Lee committed
881 882
}

883
void
884 885 886 887 888 889 890 891
gtk_draw_check (GtkStyle      *style,
                GdkWindow     *window,
                GtkStateType   state_type,
                GtkShadowType  shadow_type,
                gint           x,
                gint           y,
                gint           width,
                gint           height)
Elliot Lee's avatar
Elliot Lee committed
892
{
893 894 895 896
  g_return_if_fail (style != NULL);
  g_return_if_fail (style->klass != NULL);
  g_return_if_fail (style->klass->draw_check != NULL);
  
897
  style->klass->draw_check (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
Elliot Lee's avatar
Elliot Lee committed
898 899
}

900
void
901 902 903 904 905 906 907 908
gtk_draw_option (GtkStyle      *style,
		 GdkWindow     *window,
		 GtkStateType   state_type,
		 GtkShadowType  shadow_type,
		 gint           x,
		 gint           y,
		 gint           width,
		 gint           height)
Elliot Lee's avatar
Elliot Lee committed
909
{
910 911 912 913
  g_return_if_fail (style != NULL);
  g_return_if_fail (style->klass != NULL);
  g_return_if_fail (style->klass->draw_option != NULL);
  
914
  style->klass->draw_option (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
Elliot Lee's avatar
Elliot Lee committed
915 916
}

917
void
918 919 920 921 922 923 924 925
gtk_draw_cross (GtkStyle      *style,
		GdkWindow     *window,
		GtkStateType   state_type,
		GtkShadowType  shadow_type,
		gint           x,
		gint           y,
		gint           width,
		gint           height)
Elliot Lee's avatar
Elliot Lee committed
926
{
927 928 929 930
  g_return_if_fail (style != NULL);
  g_return_if_fail (style->klass != NULL);
  g_return_if_fail (style->klass->draw_cross != NULL);
  
931
  style->klass->draw_cross (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
932
}
Elliot Lee's avatar
Elliot Lee committed
933

934
void
935 936 937 938 939 940 941 942 943
gtk_draw_ramp (GtkStyle      *style,
	       GdkWindow     *window,
	       GtkStateType   state_type,
	       GtkShadowType  shadow_type,
	       GtkArrowType   arrow_type,
	       gint           x,
	       gint           y,
	       gint           width,
	       gint           height)
944
{
945 946 947 948
  g_return_if_fail (style != NULL);
  g_return_if_fail (style->klass != NULL);
  g_return_if_fail (style->klass->draw_ramp != NULL);
  
949
  style->klass->draw_ramp (style, window, state_type, shadow_type, NULL, NULL, NULL, arrow_type, x, y, width, height);
Elliot Lee's avatar
Elliot Lee committed
950 951
}

952
void
953 954 955 956 957 958 959 960
gtk_draw_tab (GtkStyle      *style,
	      GdkWindow     *window,
	      GtkStateType   state_type,
	      GtkShadowType  shadow_type,
	      gint           x,
	      gint           y,
	      gint           width,
	      gint           height)
Elliot Lee's avatar
Elliot Lee committed
961
{
962 963 964 965
  g_return_if_fail (style != NULL);
  g_return_if_fail (style->klass != NULL);
  g_return_if_fail (style->klass->draw_tab != NULL);
  
966
  style->klass->draw_tab (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
967
}
Elliot Lee's avatar
Elliot Lee committed
968

969 970
void
gtk_draw_shadow_gap (GtkStyle       *style,
971 972 973 974 975 976 977 978 979 980
                     GdkWindow      *window,
                     GtkStateType    state_type,
                     GtkShadowType   shadow_type,
                     gint            x,
                     gint            y,
                     gint            width,
                     gint            height,
                     GtkPositionType gap_side,
                     gint            gap_x,
                     gint            gap_width)
981
{
982 983 984 985
  g_return_if_fail (style != NULL);
  g_return_if_fail (style->klass != NULL);
  g_return_if_fail (style->klass->draw_shadow_gap != NULL);
  
986
  style->klass->draw_shadow_gap (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height, gap_side, gap_x, gap_width);
Elliot Lee's avatar
Elliot Lee committed
987 988
}

989 990
void
gtk_draw_box_gap (GtkStyle       *style,
991 992 993 994 995 996 997 998 999 1000
                  GdkWindow      *window,
                  GtkStateType    state_type,
                  GtkShadowType   shadow_type,
                  gint            x,
                  gint            y,
                  gint            width,
                  gint            height,
                  GtkPositionType gap_side,
                  gint            gap_x,
                  gint            gap_width)
Elliot Lee's avatar
Elliot Lee committed
1001
{
1002 1003 1004 1005
  g_return_if_fail (style != NULL);
  g_return_if_fail (style->klass != NULL);
  g_return_if_fail (style->klass->draw_box_gap != NULL);
  
1006
  style->klass->draw_box_gap (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height, gap_side, gap_x, gap_width);
1007
}
Elliot Lee's avatar
Elliot Lee committed
1008

1009 1010
void
gtk_draw_extension (GtkStyle       *style,
1011 1012 1013 1014 1015 1016 1017 1018
                    GdkWindow      *window,
                    GtkStateType    state_type,
                    GtkShadowType   shadow_type,
                    gint            x,
                    gint            y,
                    gint            width,
                    gint            height,
                    GtkPositionType gap_side)
1019
{
1020 1021 1022 1023
  g_return_if_fail (style != NULL);
  g_return_if_fail (style->klass != NULL);
  g_return_if_fail (style->klass->draw_extension != NULL);
  
1024
  style->klass->draw_extension (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height, gap_side);
Elliot Lee's avatar
Elliot Lee committed
1025 1026
}

1027
void
1028 1029 1030 1031 1032 1033
gtk_draw_focus (GtkStyle      *style,
		GdkWindow     *window,
		gint           x,
		gint           y,
		gint           width,
		gint           height)
Elliot Lee's avatar
Elliot Lee committed
1034
{
1035 1036 1037 1038
  g_return_if_fail (style != NULL);
  g_return_if_fail (style->klass != NULL);
  g_return_if_fail (style->klass->draw_focus != NULL);
  
1039
  style->klass->draw_focus (style, window, NULL, NULL, NULL, x, y, width, height);
Elliot Lee's avatar
Elliot Lee committed
1040 1041
}

1042
void 
1043 1044 1045 1046 1047 1048 1049 1050 1051
gtk_draw_slider (GtkStyle      *style,
		 GdkWindow     *window,
		 GtkStateType   state_type,
		 GtkShadowType  shadow_type,
		 gint           x,
		 gint           y,
		 gint           width,
		 gint           height,
		 GtkOrientation orientation)
Elliot Lee's avatar
Elliot Lee committed
1052
{
1053 1054 1055 1056
  g_return_if_fail (style != NULL);
  g_return_if_fail (style->klass != NULL);
  g_return_if_fail (style->klass->draw_slider != NULL);
  
1057
  style->klass->draw_slider (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height, orientation);
Elliot Lee's avatar
Elliot Lee committed
1058 1059
}

1060
void 
1061 1062 1063 1064 1065 1066 1067 1068 1069
gtk_draw_handle (GtkStyle      *style,
		 GdkWindow     *window,
		 GtkStateType   state_type,
		 GtkShadowType  shadow_type,
		 gint           x,
		 gint           y,
		 gint           width,
		 gint           height,
		 GtkOrientation orientation)
Elliot Lee's avatar
Elliot Lee committed
1070
{
1071 1072 1073 1074
  g_return_if_fail (style != NULL);
  g_return_if_fail (style->klass != NULL);
  g_return_if_fail (style->klass->draw_handle != NULL);
  
1075
  style->klass->draw_handle (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height, orientation);
Elliot Lee's avatar
Elliot Lee committed
1076 1077
}

1078
void
1079 1080 1081
gtk_style_set_background (GtkStyle    *style,
                          GdkWindow   *window,
                          GtkStateType state_type)
1082 1083 1084 1085
{
  GdkPixmap *pixmap;
  gint parent_relative;
  
1086 1087 1088
  g_return_if_fail (style != NULL);
  g_return_if_fail (window != NULL);
  
1089 1090
  if (style->engine && style->engine->set_background)
    {
1091 1092
      style->engine->set_background (style, window, state_type);
      
1093 1094 1095 1096 1097 1098
      return;
    }
  
  if (style->bg_pixmap[state_type])
    {
      if (style->bg_pixmap[state_type] == (GdkPixmap*) GDK_PARENT_RELATIVE)
1099 1100 1101 1102
        {
          pixmap = NULL;
          parent_relative = TRUE;
        }
1103
      else
1104 1105 1106 1107
        {
          pixmap = style->bg_pixmap[state_type];
          parent_relative = FALSE;
        }
1108 1109 1110 1111 1112 1113 1114 1115
      
      gdk_window_set_back_pixmap (window, pixmap, parent_relative);
    }
  else
    gdk_window_set_background (window, &style->bg[state_type]);
}


1116 1117
/* Default functions */
void
1118
gtk_style_apply_default_background (GtkStyle     *style,
1119 1120 1121 1122 1123 1124 1125 1126
                                    GdkWindow    *window,
                                    gboolean      set_bg,
                                    GtkStateType  state_type, 
                                    GdkRectangle *area, 
                                    gint          x, 
                                    gint          y, 
                                    gint          width, 
                                    gint          height)
Elliot Lee's avatar
Elliot Lee committed
1127
{
1128
  GdkRectangle new_rect, old_rect;
1129
  
1130
  if (area)
Elliot Lee's avatar
Elliot Lee committed
1131
    {
1132 1133 1134 1135 1136
      old_rect.x = x;
      old_rect.y = y;
      old_rect.width = width;
      old_rect.height = height;
      
1137
      if (!gdk_rectangle_intersect (area, &old_rect, &new_rect))
1138
        return;
1139 1140 1141 1142 1143 1144 1145 1146 1147 1148
    }
  else
    {
      new_rect.x = x;
      new_rect.y = y;
      new_rect.width = width;
      new_rect.height = height;
    }
  
  if (!style->bg_pixmap[state_type] ||
1149 1150
      gdk_window_get_type (window) == GDK_WINDOW_PIXMAP ||
      (!set_bg && style->bg_pixmap[state_type] != (GdkPixmap*) GDK_PARENT_RELATIVE))
1151 1152
    {
      GdkGC *gc = style->bg_gc[state_type];
1153
      
1154
      if (style->bg_pixmap[state_type])
1155 1156 1157 1158 1159
        {
          gdk_gc_set_fill (gc, GDK_TILED);
          gdk_gc_set_tile (gc, style->bg_pixmap[state_type]);
        }
      
1160
      gdk_draw_rectangle (window, gc, TRUE, 
1161
                          new_rect.x, new_rect.y, new_rect.width, new_rect.height);
1162
      if (style->bg_pixmap[state_type])
1163
        gdk_gc_set_fill (gc, GDK_SOLID);
1164
    }
1165
  else
1166
    {
1167
      if (set_bg)
1168 1169 1170 1171 1172 1173
        {
          if (style->bg_pixmap[state_type] == (GdkPixmap*) GDK_PARENT_RELATIVE)
            gdk_window_set_back_pixmap (window, NULL, TRUE);
          else
            gdk_window_set_back_pixmap (window, style->bg_pixmap[state_type], FALSE);
        }
1174
      
1175
      gdk_window_clear_area (window, 
1176 1177
                             new_rect.x, new_rect.y, 
                             new_rect.width, new_rect.height);
1178
    }
Elliot Lee's avatar
Elliot Lee committed
1179 1180 1181 1182
}

static void
gtk_default_draw_hline (GtkStyle     *style,
1183 1184 1185 1186 1187 1188 1189 1190
                        GdkWindow    *window,
                        GtkStateType  state_type,
                        GdkRectangle  *area,
                        GtkWidget     *widget,
                        gchar         *detail,
                        gint          x1,
                        gint          x2,
                        gint          y)
Elliot Lee's avatar
Elliot Lee committed
1191
{
1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210
  gint thickness_light;
  gint thickness_dark;
  gint i;
  
  g_return_if_fail (style != NULL);
  g_return_if_fail (window != NULL);
  
  thickness_light = style->klass->ythickness / 2;
  thickness_dark = style->klass->ythickness - thickness_light;
  
  if (area)
    {
      gdk_gc_set_clip_rectangle (style->light_gc[state_type], area);
      gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
    }
  
  if (detail && !strcmp (detail, "label"))
    {
      if (state_type == GTK_STATE_INSENSITIVE)
1211
        gdk_draw_line (window, style->white_gc, x1 + 1, y + 1, x2 + 1, y + 1);   
1212 1213 1214 1215 1216
      gdk_draw_line (window, style->fg_gc[state_type], x1, y, x2, y);     
    }
  else
    {
      for (i = 0; i < thickness_dark; i++)
1217 1218 1219 1220
        {
          gdk_draw_line (window, style->light_gc[state_type], x2 - i - 1, y + i, x2, y + i);
          gdk_draw_line (window, style->dark_gc[state_type], x1, y + i, x2 - i - 1, y + i);
        }
1221 1222 1223
      
      y += thickness_dark;
      for (i = 0; i < thickness_light; i++)
1224 1225 1226 1227
        {
          gdk_draw_line (window, style->dark_gc[state_type], x1, y + i, x1 + thickness_light - i - 1, y + i);
          gdk_draw_line (window, style->light_gc[state_type], x1 + thickness_light - i - 1, y + i, x2, y + i);
        }
1228 1229 1230 1231 1232 1233 1234
    }
  
  if (area)
    {
      gdk_gc_set_clip_rectangle (style->light_gc[state_type], NULL);
      gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
    }
Elliot Lee's avatar
Elliot Lee committed
1235 1236 1237 1238 1239
}


static void
gtk_default_draw_vline (GtkStyle     *style,
1240 1241 1242 1243 1244 1245 1246 1247
                        GdkWindow    *window,
                        GtkStateType  state_type,
                        GdkRectangle  *area,
                        GtkWidget     *widget,
                        gchar         *detail,
                        gint          y1,
                        gint          y2,
                        gint          x)
Elliot Lee's avatar
Elliot Lee committed
1248
{
1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266
  gint thickness_light;
  gint thickness_dark;
  gint i;
  
  g_return_if_fail (style != NULL);
  g_return_if_fail (window != NULL);
  
  thickness_light = style->klass->xthickness / 2;
  thickness_dark = style->klass->xthickness - thickness_light;
  
  if (area)
    {
      gdk_gc_set_clip_rectangle (style->light_gc[state_type], area);
      gdk_gc_set_clip_rectangle (style->dark_gc[state_type], area);
    }
  for (i = 0; i < thickness_dark; i++)
    {
      gdk_draw_line (window, style->light_gc[state_type], x + i, y2 - i - 1, x + i, y2);
Elliot Lee's avatar
Elliot Lee committed
1267
      gdk_draw_line (window, style->dark_gc[state_type], x + i, y1, x + i, y2 - i - 1);
1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280
    }
  
  x += thickness_dark;
  for (i = 0; i < thickness_light; i++)
    {
      gdk_draw_line (window, style->dark_gc[state_type], x + i, y1, x + i, y1 + thickness_light - i);
      gdk_draw_line (window, style->light_gc[state_type], x + i, y1 + thickness_light - i, x + i, y2);
    }
  if (area)
    {
      gdk_gc_set_clip_rectangle (style->light_gc[state_type], NULL);
      gdk_gc_set_clip_rectangle (style->dark_gc[state_type], NULL);
    }
Elliot Lee's avatar
Elliot Lee committed
1281 1282 1283 1284 1285
}


static void
gtk_default_draw_shadow (GtkStyle      *style,
1286 1287 1288 1289 1290 1291 1292 1293 1294 1295
                         GdkWindow     *window,
                         GtkStateType   state_type,
                         GtkShadowType  shadow_type,
                         GdkRectangle  *area,
                         GtkWidget     *widget,
                         gchar         *detail,
                         gint           x,
                         gint           y,
                         gint           width,
                         gint           height)
Elliot Lee's avatar
Elliot Lee committed
1296
{
1297 1298
  GdkGC *gc1 = NULL;
  GdkGC *gc2 = NULL;
Elliot Lee's avatar
Elliot Lee committed
1299 1300 1301
  gint thickness_light;
  gint thickness_dark;
  gint i;
1302
  
Elliot Lee's avatar
Elliot Lee committed
1303 1304
  g_return_if_fail (style != NULL);
  g_return_if_fail (window != NULL);
1305
  
Elliot Lee's avatar
Elliot Lee committed
1306 1307 1308 1309 1310 1311
  if ((width == -1) && (height == -1))
    gdk_window_get_size (window, &width, &height);
  else if (width == -1)
    gdk_window_get_size (window, &width, NULL);
  else if (height == -1)
    gdk_window_get_size (window, NULL, &height);
1312
  
Elliot Lee's avatar
Elliot Lee committed
1313 1314 1315
  switch (shadow_type)
    {
    case GTK_SHADOW_NONE:
1316
      return;
Elliot Lee's avatar
Elliot Lee committed
1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327
    case GTK_SHADOW_IN:
    case GTK_SHADOW_ETCHED_IN:
      gc1 = style->light_gc[state_type];
      gc2 = style->dark_gc[state_type];
      break;
    case GTK_SHADOW_OUT:
    case GTK_SHADOW_ETCHED_OUT:
      gc1 = style->dark_gc[state_type];
      gc2 = style->light_gc[state_type];
      break;
    }
1328 1329 1330 1331 1332 1333
  
  if (area)
    {
      gdk_gc_set_clip_rectangle (gc1, area);
      gdk_gc_set_clip_rectangle (gc2, area);
      if (shadow_type