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 34
#include "gtkthemes.h"
#include "gdk/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);
368
  
369 370
  return new_style;
}
Elliot Lee's avatar
Elliot Lee committed
371

372
static GtkStyle*
373
gtk_style_duplicate (GtkStyle *style)
374 375
{
  GtkStyle *new_style;
376
  
377
  g_return_val_if_fail (style != NULL, NULL);
378
  
379
  new_style = gtk_style_copy (style);
380
  
381 382
  style->styles = g_slist_append (style->styles, new_style);
  new_style->styles = style->styles;  
383
  
384 385 386 387 388 389 390 391 392 393 394
  if (style->rc_style)
    {
      new_style->rc_style = style->rc_style;
      gtk_rc_style_ref (style->rc_style);
    }
  
  if (style->engine)
    {
      new_style->engine = style->engine;
      new_style->engine->duplicate_style (new_style, style);
    }
395
  
396 397 398
  return new_style;
}

Elliot Lee's avatar
Elliot Lee committed
399
GtkStyle*
400
gtk_style_new (void)
Elliot Lee's avatar
Elliot Lee committed
401 402 403
{
  GtkStyle *style;
  gint i;
404
  
405
  style = g_new0 (GtkStyle, 1);
406
  
Elliot Lee's avatar
Elliot Lee committed
407
  if (!default_font)
408 409 410 411 412 413 414 415
    {
      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.");
    }
416
  
Elliot Lee's avatar
Elliot Lee committed
417 418
  style->font = default_font;
  gdk_font_ref (style->font);
419
  
420
  style->ref_count = 1;
Elliot Lee's avatar
Elliot Lee committed
421 422 423 424
  style->attach_count = 0;
  style->colormap = NULL;
  style->depth = -1;
  style->klass = &default_class;
425
  
Elliot Lee's avatar
Elliot Lee committed
426 427 428
  style->black.red = 0;
  style->black.green = 0;
  style->black.blue = 0;
429
  
Elliot Lee's avatar
Elliot Lee committed
430 431 432
  style->white.red = 65535;
  style->white.green = 65535;
  style->white.blue = 65535;
433
  
Elliot Lee's avatar
Elliot Lee committed
434 435
  style->black_gc = NULL;
  style->white_gc = NULL;
436
  
Elliot Lee's avatar
Elliot Lee committed
437 438 439 440 441
  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;
442
  
Elliot Lee's avatar
Elliot Lee committed
443 444 445 446 447
  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;
448
  
449
  for (i = 0; i < 4; i++)
Elliot Lee's avatar
Elliot Lee committed
450 451 452 453
    {
      style->text[i] = style->fg[i];
      style->base[i] = style->white;
    }
454
  
455 456
  style->base[GTK_STATE_INSENSITIVE] = gtk_default_insensitive_bg;
  style->text[GTK_STATE_INSENSITIVE] = gtk_default_insensitive_bg;
457
  
Elliot Lee's avatar
Elliot Lee committed
458 459
  for (i = 0; i < 5; i++)
    style->bg_pixmap[i] = NULL;
460
  
461 462
  style->engine = NULL;
  style->engine_data = NULL;
463
  
464
  style->rc_style = NULL;
465
  
Elliot Lee's avatar
Elliot Lee committed
466 467 468 469 470 471 472 473 474 475
  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;
    }
476
  
Elliot Lee's avatar
Elliot Lee committed
477 478 479
  return style;
}

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

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

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

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

580
static void
581 582 583
gtk_style_init (GtkStyle    *style,
                GdkColormap *colormap,
                gint         depth)
584 585 586 587
{
  GdkGCValues gc_values;
  GdkGCValuesMask gc_values_mask;
  gint i;
588
  
589
  g_return_if_fail (style != NULL);
590
  
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
  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])
626 627 628
        style->bg_pixmap[i] = gtk_rc_load_image (style->colormap,
                                                 &style->bg[i],
                                                 style->rc_style->bg_pixmap_name[i]);
629 630
      
      if (!gdk_color_alloc (colormap, &style->fg[i]))
631 632
        g_warning ("unable to allocate color: ( %d %d %d )",
                   style->fg[i].red, style->fg[i].green, style->fg[i].blue);
633
      if (!gdk_color_alloc (colormap, &style->bg[i]))
634 635
        g_warning ("unable to allocate color: ( %d %d %d )",
                   style->bg[i].red, style->bg[i].green, style->bg[i].blue);
636
      if (!gdk_color_alloc (colormap, &style->light[i]))
637 638
        g_warning ("unable to allocate color: ( %d %d %d )",
                   style->light[i].red, style->light[i].green, style->light[i].blue);
639
      if (!gdk_color_alloc (colormap, &style->dark[i]))
640 641
        g_warning ("unable to allocate color: ( %d %d %d )",
                   style->dark[i].red, style->dark[i].green, style->dark[i].blue);
642
      if (!gdk_color_alloc (colormap, &style->mid[i]))
643 644
        g_warning ("unable to allocate color: ( %d %d %d )",
                   style->mid[i].red, style->mid[i].green, style->mid[i].blue);
645
      if (!gdk_color_alloc (colormap, &style->text[i]))
646 647
        g_warning ("unable to allocate color: ( %d %d %d )",
                   style->text[i].red, style->text[i].green, style->text[i].blue);
648
      if (!gdk_color_alloc (colormap, &style->base[i]))
649 650
        g_warning ("unable to allocate color: ( %d %d %d )",
                   style->base[i].red, style->base[i].green, style->base[i].blue);
651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668
      
      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);
669
      
670 671 672
      gc_values.foreground = style->base[i];
      style->base_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
    }
673
  
674 675 676 677 678 679 680 681
  if (style->engine)
    style->engine->realize_style (style);
}

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

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


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


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

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

void
gtk_draw_arrow (GtkStyle      *style,
780 781 782 783 784 785 786 787 788
                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
789 790 791 792
{
  g_return_if_fail (style != NULL);
  g_return_if_fail (style->klass != NULL);
  g_return_if_fail (style->klass->draw_arrow != NULL);
793
  
794
  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
795 796 797 798 799
}


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


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

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

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

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

882
void
883 884 885 886 887 888 889 890
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
891
{
892 893 894 895
  g_return_if_fail (style != NULL);
  g_return_if_fail (style->klass != NULL);
  g_return_if_fail (style->klass->draw_check != NULL);
  
896
  style->klass->draw_check (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
Elliot Lee's avatar
Elliot Lee committed
897 898
}

899
void
900 901 902 903 904 905 906 907
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
908
{
909 910 911 912
  g_return_if_fail (style != NULL);
  g_return_if_fail (style->klass != NULL);
  g_return_if_fail (style->klass->draw_option != NULL);
  
913
  style->klass->draw_option (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
Elliot Lee's avatar
Elliot Lee committed
914 915
}

916
void
917 918 919 920 921 922 923 924
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
925
{
926 927 928 929
  g_return_if_fail (style != NULL);
  g_return_if_fail (style->klass != NULL);
  g_return_if_fail (style->klass->draw_cross != NULL);
  
930
  style->klass->draw_cross (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
931
}
Elliot Lee's avatar
Elliot Lee committed
932

933
void
934 935 936 937 938 939 940 941 942
gtk_draw_ramp (GtkStyle      *style,
	       GdkWindow     *window,
	       GtkStateType   state_type,
	       GtkShadowType  shadow_type,
	       GtkArrowType   arrow_type,
	       gint           x,
	       gint           y,
	       gint           width,
	       gint           height)
943
{
944 945 946 947
  g_return_if_fail (style != NULL);
  g_return_if_fail (style->klass != NULL);
  g_return_if_fail (style->klass->draw_ramp != NULL);
  
948
  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
949 950
}

951
void
952 953 954 955 956 957 958 959
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
960
{
961 962 963 964
  g_return_if_fail (style != NULL);
  g_return_if_fail (style->klass != NULL);
  g_return_if_fail (style->klass->draw_tab != NULL);
  
965
  style->klass->draw_tab (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
966
}
Elliot Lee's avatar
Elliot Lee committed
967

968 969
void
gtk_draw_shadow_gap (GtkStyle       *style,
970 971 972 973 974 975 976 977 978 979
                     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)
980
{
981 982 983 984
  g_return_if_fail (style != NULL);
  g_return_if_fail (style->klass != NULL);
  g_return_if_fail (style->klass->draw_shadow_gap != NULL);
  
985
  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
986 987
}

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

1008 1009
void
gtk_draw_extension (GtkStyle       *style,
1010 1011 1012 1013 1014 1015 1016 1017
                    GdkWindow      *window,
                    GtkStateType    state_type,
                    GtkShadowType   shadow_type,
                    gint            x,
                    gint            y,
                    gint            width,
                    gint            height,
                    GtkPositionType gap_side)
1018
{
1019 1020 1021 1022
  g_return_if_fail (style != NULL);
  g_return_if_fail (style->klass != NULL);
  g_return_if_fail (style->klass->draw_extension != NULL);
  
1023
  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
1024 1025
}

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

1041
void 
1042 1043 1044 1045 1046 1047 1048 1049 1050
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
1051
{
1052 1053 1054 1055
  g_return_if_fail (style != NULL);
  g_return_if_fail (style->klass != NULL);
  g_return_if_fail (style->klass->draw_slider != NULL);
  
1056
  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
1057 1058
}

1059
void 
1060 1061 1062 1063 1064 1065 1066 1067 1068
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
1069
{
1070 1071 1072 1073
  g_return_if_fail (style != NULL);
  g_return_if_fail (style->klass != NULL);
  g_return_if_fail (style->klass->draw_handle != NULL);
  
1074
  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
1075 1076
}

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


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

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


static void
gtk_default_draw_vline (GtkStyle     *style,
1239 1240 1241 1242 1243 1244 1245 1246
                        GdkWindow    *window,
                        GtkStateType  state_type,
                        GdkRectangle  *area,
                        GtkWidget     *widget,
                        gchar         *detail,
                        gint          y1,
                        gint          y2,
                        gint          x)
Elliot Lee's avatar
Elliot Lee committed
1247
{
1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265
  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
1266
      gdk_draw_line (window, style->dark_gc[state_type], x + i, y1, x + i, y2 - i - 1);
1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279
    }
  
  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
1280 1281 1282 1283 1284
}


static void
gtk_default_draw_shadow (GtkStyle      *style,
1285 1286 1287 1288 1289 1290 1291 1292 1293 1294
                         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
1295
{
1296 1297
  GdkGC *gc1 = NULL;
  GdkGC *gc2 = NULL;
Elliot Lee's avatar
Elliot Lee committed
1298 1299 1300
  gint thickness_light;
  gint thickness_dark;
  gint i;
1301
  
Elliot Lee's avatar
Elliot Lee committed
1302 1303
  g_return_if_fail (style != NULL);
  g_return_if_fail (window != NULL);
1304
  
Elliot Lee's avatar
Elliot Lee committed
1305 1306 1307 1308 1309 1310
  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);
1311
  
Elliot Lee's avatar
Elliot Lee committed
1312 1313 1314
  switch (shadow_type)
    {
    case GTK_SHADOW_NONE:
1315
      return;
Elliot Lee's avatar
Elliot Lee committed
1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326
    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;
    }
1327 1328 1329 1330 1331 1332
  
  if (area)
    {
      gdk_gc_set_clip_rectangle (gc1, area);
      gdk_gc_set_clip_rectangle (gc2, area);
      if (shadow_type == GTK_SHADOW_IN || 
1333