gtkstyle.c 102 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
 */
#include <math.h>
#include "gtkgc.h"
21
#include "gtkrc.h"
Elliot Lee's avatar
Elliot Lee committed
22
#include "gtkstyle.h"
23
#include "gtkthemes.h"
24
#include "gtkwidget.h"
25 26
#include "gtkthemes.h"
#include "gdk/gdkprivate.h"
Elliot Lee's avatar
Elliot Lee committed
27 28 29 30 31


#define LIGHTNESS_MULT  1.3
#define DARKNESS_MULT   0.7

32 33
static void         gtk_style_init         (GtkStyle    *style,
					    GdkColormap *colormap,
Elliot Lee's avatar
Elliot Lee committed
34 35 36 37 38 39
					    gint         depth);
static void         gtk_style_destroy      (GtkStyle    *style);

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

Elliot Lee's avatar
Elliot Lee committed
283 284 285 286 287

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);

288

289
static const GtkStyleClass default_class =
Elliot Lee's avatar
Elliot Lee committed
290
{
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313
  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
314
};
315
GdkFont *default_font = NULL;
Elliot Lee's avatar
Elliot Lee committed
316 317 318 319 320 321 322 323 324 325 326 327 328

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 };

329 330 331 332 333
GtkStyle*
gtk_style_copy (GtkStyle     *style)
{
  GtkStyle *new_style;
  guint i;
334
  
335
  g_return_val_if_fail (style != NULL, NULL);
336
  
337
  new_style = gtk_style_new ();
338
  
339 340 341 342 343 344
  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];
345
      
346 347
      new_style->bg_pixmap[i] = style->bg_pixmap[i];
    }
348
  
349 350
  new_style->font = style->font;
  gdk_font_ref (new_style->font);
351
  
352 353
  return new_style;
}
Elliot Lee's avatar
Elliot Lee committed
354

355 356 357 358
static GtkStyle*
gtk_style_duplicate (GtkStyle     *style)
{
  GtkStyle *new_style;
359
  
360
  g_return_val_if_fail (style != NULL, NULL);
361
  
362
  new_style = gtk_style_copy (style);
363
  
364 365
  style->styles = g_slist_append (style->styles, new_style);
  new_style->styles = style->styles;  
366
  
367 368 369 370 371 372 373 374 375 376 377
  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);
    }
378
  
379 380 381
  return new_style;
}

Elliot Lee's avatar
Elliot Lee committed
382
GtkStyle*
383
gtk_style_new (void)
Elliot Lee's avatar
Elliot Lee committed
384 385 386
{
  GtkStyle *style;
  gint i;
387
  
388
  style = g_new0 (GtkStyle, 1);
389
  
Elliot Lee's avatar
Elliot Lee committed
390
  if (!default_font)
391 392
    default_font =
      gdk_font_load ("-adobe-helvetica-medium-r-normal--*-120-*-*-*-*-*-*");
393
  
Elliot Lee's avatar
Elliot Lee committed
394 395
  style->font = default_font;
  gdk_font_ref (style->font);
396
  
397
  style->ref_count = 1;
Elliot Lee's avatar
Elliot Lee committed
398 399 400 401
  style->attach_count = 0;
  style->colormap = NULL;
  style->depth = -1;
  style->klass = &default_class;
402
  
Elliot Lee's avatar
Elliot Lee committed
403 404 405
  style->black.red = 0;
  style->black.green = 0;
  style->black.blue = 0;
406
  
Elliot Lee's avatar
Elliot Lee committed
407 408 409
  style->white.red = 65535;
  style->white.green = 65535;
  style->white.blue = 65535;
410
  
Elliot Lee's avatar
Elliot Lee committed
411 412
  style->black_gc = NULL;
  style->white_gc = NULL;
413
  
Elliot Lee's avatar
Elliot Lee committed
414 415 416 417 418
  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;
419
  
Elliot Lee's avatar
Elliot Lee committed
420 421 422 423 424
  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;
425
  
426
  for (i = 0; i < 4; i++)
Elliot Lee's avatar
Elliot Lee committed
427 428 429 430
    {
      style->text[i] = style->fg[i];
      style->base[i] = style->white;
    }
431
  
432 433
  style->base[GTK_STATE_INSENSITIVE] = gtk_default_insensitive_bg;
  style->text[GTK_STATE_INSENSITIVE] = gtk_default_insensitive_bg;
434
  
Elliot Lee's avatar
Elliot Lee committed
435 436
  for (i = 0; i < 5; i++)
    style->bg_pixmap[i] = NULL;
437
  
438 439
  style->engine = NULL;
  style->engine_data = NULL;
440
  
441
  style->rc_style = NULL;
442
  
Elliot Lee's avatar
Elliot Lee committed
443 444 445 446 447 448 449 450 451 452
  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;
    }
453
  
Elliot Lee's avatar
Elliot Lee committed
454 455 456
  return style;
}

457
GtkStyle *
Elliot Lee's avatar
Elliot Lee committed
458 459 460
gtk_style_attach (GtkStyle  *style,
		  GdkWindow *window)
{
461 462
  GSList *styles;
  GtkStyle *new_style = NULL;
Elliot Lee's avatar
Elliot Lee committed
463 464
  GdkColormap *colormap;
  gint depth;
465
  
Elliot Lee's avatar
Elliot Lee committed
466 467
  g_return_val_if_fail (style != NULL, NULL);
  g_return_val_if_fail (window != NULL, NULL);
468
  
Elliot Lee's avatar
Elliot Lee committed
469
  colormap = gdk_window_get_colormap (window);
470
  depth = gdk_window_get_visual (window)->depth;
471
  
472 473
  if (!style->styles)
    style->styles = g_slist_append (NULL, style);
474
  
475 476
  styles = style->styles;
  while (styles)
Elliot Lee's avatar
Elliot Lee committed
477
    {
478
      new_style = styles->data;
479
      
480 481 482 483 484 485 486 487
      if (new_style->attach_count == 0)
	{
	  gtk_style_init (new_style, colormap, depth);
	  break;
	}
      else if ((new_style->colormap == colormap) &&
	       (new_style->depth == depth))
	break;
488
      
489 490
      new_style = NULL;
      styles = styles->next;
Elliot Lee's avatar
Elliot Lee committed
491
    }
492
  
493 494 495 496 497
  if (!new_style)
    {
      new_style = gtk_style_duplicate (style);
      gtk_style_init (new_style, colormap, depth);
    }
498
  
499 500
  if (new_style->attach_count == 0)
    gtk_style_ref (new_style);
501 502
  
  
503 504
  
  new_style->attach_count++;
505
  
506
  return new_style;
Elliot Lee's avatar
Elliot Lee committed
507 508 509 510 511 512
}

void
gtk_style_detach (GtkStyle *style)
{
  gint i;
513
  
Elliot Lee's avatar
Elliot Lee committed
514
  g_return_if_fail (style != NULL);
515
  
Elliot Lee's avatar
Elliot Lee committed
516 517 518
  style->attach_count -= 1;
  if (style->attach_count == 0)
    {
519 520
      if (style->engine)
	style->engine->unrealize_style (style);
521
      
Elliot Lee's avatar
Elliot Lee committed
522 523
      gtk_gc_release (style->black_gc);
      gtk_gc_release (style->white_gc);
524
      
Elliot Lee's avatar
Elliot Lee committed
525 526 527 528 529 530 531 532 533 534
      for (i = 0; i < 5; i++)
	{
	  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]);
	}
535
      
536
      gtk_style_unref (style);
Elliot Lee's avatar
Elliot Lee committed
537 538 539 540 541 542 543
    }
}

GtkStyle*
gtk_style_ref (GtkStyle *style)
{
  g_return_val_if_fail (style != NULL, NULL);
544
  
Elliot Lee's avatar
Elliot Lee committed
545 546 547 548 549 550 551 552
  style->ref_count += 1;
  return style;
}

void
gtk_style_unref (GtkStyle *style)
{
  g_return_if_fail (style != NULL);
553
  
Elliot Lee's avatar
Elliot Lee committed
554 555 556 557 558
  style->ref_count -= 1;
  if (style->ref_count == 0)
    gtk_style_destroy (style);
}

559 560 561 562 563 564 565 566
static void
gtk_style_init (GtkStyle *style,
		GdkColormap *colormap,
		gint         depth)
{
  GdkGCValues gc_values;
  GdkGCValuesMask gc_values_mask;
  gint i;
567
  
568
  g_return_if_fail (style != NULL);
569
  
570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 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 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647
  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])
	style->bg_pixmap[i] = gtk_rc_load_image (style->colormap,
						 &style->bg[i],
						 style->rc_style->bg_pixmap_name[i]);
      
      if (!gdk_color_alloc (colormap, &style->fg[i]))
	g_warning ("unable to allocate color: ( %d %d %d )",
		   style->fg[i].red, style->fg[i].green, style->fg[i].blue);
      if (!gdk_color_alloc (colormap, &style->bg[i]))
	g_warning ("unable to allocate color: ( %d %d %d )",
		   style->bg[i].red, style->bg[i].green, style->bg[i].blue);
      if (!gdk_color_alloc (colormap, &style->light[i]))
	g_warning ("unable to allocate color: ( %d %d %d )",
		   style->light[i].red, style->light[i].green, style->light[i].blue);
      if (!gdk_color_alloc (colormap, &style->dark[i]))
	g_warning ("unable to allocate color: ( %d %d %d )",
		   style->dark[i].red, style->dark[i].green, style->dark[i].blue);
      if (!gdk_color_alloc (colormap, &style->mid[i]))
	g_warning ("unable to allocate color: ( %d %d %d )",
		   style->mid[i].red, style->mid[i].green, style->mid[i].blue);
      if (!gdk_color_alloc (colormap, &style->text[i]))
	g_warning ("unable to allocate color: ( %d %d %d )",
		   style->text[i].red, style->text[i].green, style->text[i].blue);
      if (!gdk_color_alloc (colormap, &style->base[i]))
	g_warning ("unable to allocate color: ( %d %d %d )",
		   style->base[i].red, style->base[i].green, style->base[i].blue);
      
      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);
648
      
649 650 651 652 653 654 655 656 657 658 659
      gc_values.foreground = style->base[i];
      style->base_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
    }
  if (style->engine)
    style->engine->realize_style (style);
}

static void
gtk_style_destroy (GtkStyle *style)
{
  g_return_if_fail (style->attach_count == 0);
660
  
661 662 663 664 665 666 667 668 669 670 671 672 673 674 675
  if (style->styles)
    {
      if (style->styles->data != style)
	g_slist_remove (style->styles, style);
      else
	{
	  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);
	}
    }
676
  
677 678 679 680 681
  if (style->engine)
    {
      style->engine->destroy_style (style);
      gtk_theme_engine_unref (style->engine);
    }
682
  
683 684 685
  gdk_font_unref (style->font);
  if (style->rc_style)
    gtk_rc_style_unref (style->rc_style);
686
  
687 688 689
  g_free (style);
}

Elliot Lee's avatar
Elliot Lee committed
690 691 692 693 694 695 696 697 698 699 700
void
gtk_draw_hline (GtkStyle     *style,
		GdkWindow    *window,
		GtkStateType  state_type,
		gint          x1,
		gint          x2,
		gint          y)
{
  g_return_if_fail (style != NULL);
  g_return_if_fail (style->klass != NULL);
  g_return_if_fail (style->klass->draw_hline != NULL);
701
  
702
  (*style->klass->draw_hline) (style, window, state_type, NULL, NULL, NULL, x1, x2, y);
Elliot Lee's avatar
Elliot Lee committed
703 704 705 706 707 708 709 710 711 712 713 714 715 716
}


void
gtk_draw_vline (GtkStyle     *style,
		GdkWindow    *window,
		GtkStateType  state_type,
		gint          y1,
		gint          y2,
		gint          x)
{
  g_return_if_fail (style != NULL);
  g_return_if_fail (style->klass != NULL);
  g_return_if_fail (style->klass->draw_vline != NULL);
717
  
718
  (*style->klass->draw_vline) (style, window, state_type, NULL, NULL, NULL, y1, y2, x);
Elliot Lee's avatar
Elliot Lee committed
719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734
}


void
gtk_draw_shadow (GtkStyle      *style,
		 GdkWindow     *window,
		 GtkStateType   state_type,
		 GtkShadowType  shadow_type,
		 gint           x,
		 gint           y,
		 gint           width,
		 gint           height)
{
  g_return_if_fail (style != NULL);
  g_return_if_fail (style->klass != NULL);
  g_return_if_fail (style->klass->draw_shadow != NULL);
735 736
  
  (*style->klass->draw_shadow) (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
Elliot Lee's avatar
Elliot Lee committed
737 738 739 740 741 742 743 744 745
}

void
gtk_draw_polygon (GtkStyle      *style,
		  GdkWindow     *window,
		  GtkStateType   state_type,
		  GtkShadowType  shadow_type,
		  GdkPoint      *points,
		  gint           npoints,
746
		  gboolean       fill)
Elliot Lee's avatar
Elliot Lee committed
747 748 749 750
{
  g_return_if_fail (style != NULL);
  g_return_if_fail (style->klass != NULL);
  g_return_if_fail (style->klass->draw_shadow != NULL);
751
  
752
  (*style->klass->draw_polygon) (style, window, state_type, shadow_type, NULL, NULL, NULL, points, npoints, fill);
Elliot Lee's avatar
Elliot Lee committed
753 754 755 756 757 758 759 760
}

void
gtk_draw_arrow (GtkStyle      *style,
		GdkWindow     *window,
		GtkStateType   state_type,
		GtkShadowType  shadow_type,
		GtkArrowType   arrow_type,
761
		gboolean       fill,
Elliot Lee's avatar
Elliot Lee committed
762 763 764 765 766 767 768 769
		gint           x,
		gint           y,
		gint           width,
		gint           height)
{
  g_return_if_fail (style != NULL);
  g_return_if_fail (style->klass != NULL);
  g_return_if_fail (style->klass->draw_arrow != NULL);
770
  
771
  (*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
772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787
}


void
gtk_draw_diamond (GtkStyle      *style,
		  GdkWindow     *window,
		  GtkStateType   state_type,
		  GtkShadowType  shadow_type,
		  gint           x,
		  gint           y,
		  gint           width,
		  gint           height)
{
  g_return_if_fail (style != NULL);
  g_return_if_fail (style->klass != NULL);
  g_return_if_fail (style->klass->draw_diamond != NULL);
788
  
789
  (*style->klass->draw_diamond) (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
Elliot Lee's avatar
Elliot Lee committed
790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805
}


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

void
gtk_draw_string (GtkStyle      *style,
		 GdkWindow     *window,
		 GtkStateType   state_type,
		 gint           x,
		 gint           y,
		 const gchar   *string)
{
  g_return_if_fail (style != NULL);
  g_return_if_fail (style->klass != NULL);
  g_return_if_fail (style->klass->draw_oval != NULL);
821
  
822
  (*style->klass->draw_string) (style, window, state_type, NULL, NULL, NULL, x, y, string);
Elliot Lee's avatar
Elliot Lee committed
823 824
}

825 826
void
gtk_draw_box (GtkStyle      *style,
827 828 829 830 831 832 833
	      GdkWindow     *window,
	      GtkStateType   state_type,
	      GtkShadowType  shadow_type,
	      gint           x,
	      gint           y,
	      gint           width,
	      gint           height)
Elliot Lee's avatar
Elliot Lee committed
834
{
835 836 837 838 839
  g_return_if_fail (style != NULL);
  g_return_if_fail (style->klass != NULL);
  g_return_if_fail (style->klass->draw_box != NULL);
  
  (*style->klass->draw_box) (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
Elliot Lee's avatar
Elliot Lee committed
840 841
}

842 843 844 845 846 847 848 849 850
void
gtk_draw_flat_box (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
851
{
852 853 854 855 856
  g_return_if_fail (style != NULL);
  g_return_if_fail (style->klass != NULL);
  g_return_if_fail (style->klass->draw_flat_box != NULL);
  
  (*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
857 858
}

859 860 861 862 863 864 865 866 867
void
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
868
{
869 870 871 872 873
  g_return_if_fail (style != NULL);
  g_return_if_fail (style->klass != NULL);
  g_return_if_fail (style->klass->draw_check != NULL);
  
  (*style->klass->draw_check) (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
Elliot Lee's avatar
Elliot Lee committed
874 875
}

876 877 878 879 880 881 882 883 884
void
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
885
{
886 887 888 889 890
  g_return_if_fail (style != NULL);
  g_return_if_fail (style->klass != NULL);
  g_return_if_fail (style->klass->draw_option != NULL);
  
  (*style->klass->draw_option) (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
Elliot Lee's avatar
Elliot Lee committed
891 892
}

893 894 895 896 897 898 899 900 901
void
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
902
{
903 904 905 906 907
  g_return_if_fail (style != NULL);
  g_return_if_fail (style->klass != NULL);
  g_return_if_fail (style->klass->draw_cross != NULL);
  
  (*style->klass->draw_cross) (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
908
}
Elliot Lee's avatar
Elliot Lee committed
909

910 911 912 913 914 915 916 917 918 919 920
void
gtk_draw_ramp    (GtkStyle      *style,
		  GdkWindow     *window,
		  GtkStateType   state_type,
		  GtkShadowType  shadow_type,
		  GtkArrowType   arrow_type,
		  gint           x,
		  gint           y,
		  gint           width,
		  gint           height)
{
921 922 923 924 925
  g_return_if_fail (style != NULL);
  g_return_if_fail (style->klass != NULL);
  g_return_if_fail (style->klass->draw_ramp != NULL);
  
  (*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
926 927
}

928 929 930 931 932 933 934 935 936
void
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
937
{
938 939 940 941 942
  g_return_if_fail (style != NULL);
  g_return_if_fail (style->klass != NULL);
  g_return_if_fail (style->klass->draw_tab != NULL);
  
  (*style->klass->draw_tab) (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
943
}
Elliot Lee's avatar
Elliot Lee committed
944

945 946 947 948 949 950 951 952 953 954 955 956 957
void
gtk_draw_shadow_gap (GtkStyle       *style,
		     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)
{
958 959 960 961 962
  g_return_if_fail (style != NULL);
  g_return_if_fail (style->klass != NULL);
  g_return_if_fail (style->klass->draw_shadow_gap != NULL);
  
  (*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
963 964
}

965 966 967 968 969 970 971 972 973 974 975 976
void
gtk_draw_box_gap (GtkStyle       *style,
		  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
977
{
978 979 980 981 982
  g_return_if_fail (style != NULL);
  g_return_if_fail (style->klass != NULL);
  g_return_if_fail (style->klass->draw_box_gap != NULL);
  
  (*style->klass->draw_box_gap) (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height, gap_side, gap_x, gap_width);
983
}
Elliot Lee's avatar
Elliot Lee committed
984

985 986 987 988 989 990 991 992 993 994 995
void
gtk_draw_extension (GtkStyle       *style,
		    GdkWindow      *window,
		    GtkStateType    state_type,
		    GtkShadowType   shadow_type,
		    gint            x,
		    gint            y,
		    gint            width,
		    gint            height,
		    GtkPositionType gap_side)
{
996 997 998 999 1000
  g_return_if_fail (style != NULL);
  g_return_if_fail (style->klass != NULL);
  g_return_if_fail (style->klass->draw_extension != NULL);
  
  (*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
1001 1002
}

1003 1004 1005 1006 1007 1008 1009
void
gtk_draw_focus  (GtkStyle      *style,
		 GdkWindow     *window,
		 gint           x,
		 gint           y,
		 gint           width,
		 gint           height)
Elliot Lee's avatar
Elliot Lee committed
1010
{
1011 1012 1013 1014 1015
  g_return_if_fail (style != NULL);
  g_return_if_fail (style->klass != NULL);
  g_return_if_fail (style->klass->draw_focus != NULL);
  
  (*style->klass->draw_focus) (style, window, NULL, NULL, NULL, x, y, width, height);
Elliot Lee's avatar
Elliot Lee committed
1016 1017
}

1018 1019 1020 1021 1022 1023 1024 1025 1026 1027
void 
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
1028
{
1029 1030 1031 1032 1033
  g_return_if_fail (style != NULL);
  g_return_if_fail (style->klass != NULL);
  g_return_if_fail (style->klass->draw_slider != NULL);
  
  (*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
1034 1035
}

1036 1037 1038 1039 1040 1041 1042 1043 1044 1045
void 
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
1046
{
1047 1048 1049 1050 1051
  g_return_if_fail (style != NULL);
  g_return_if_fail (style->klass != NULL);
  g_return_if_fail (style->klass->draw_handle != NULL);
  
  (*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
1052 1053
}

1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090
void
gtk_style_set_background (GtkStyle     *style,
			  GdkWindow    *window,
			  GtkStateType  state_type)
{
  GdkPixmap *pixmap;
  gint parent_relative;
  
  if (style->engine && style->engine->set_background)
    {
      (*style->engine->set_background) (style, window, state_type);
      return;
    }
  
  g_return_if_fail (style != NULL);
  g_return_if_fail (window != NULL);
  
  if (style->bg_pixmap[state_type])
    {
      if (style->bg_pixmap[state_type] == (GdkPixmap*) GDK_PARENT_RELATIVE)
	{
	  pixmap = NULL;
	  parent_relative = TRUE;
	}
      else
	{
	  pixmap = style->bg_pixmap[state_type];
	  parent_relative = FALSE;
	}
      
      gdk_window_set_back_pixmap (window, pixmap, parent_relative);
    }
  else
    gdk_window_set_background (window, &style->bg[state_type]);
}


1091 1092
/* Default functions */
void
1093 1094
gtk_style_apply_default_background (GtkStyle     *style,
				    GdkWindow    *window,
1095
				    gboolean	  set_bg,
1096 1097 1098 1099 1100 1101
				    GtkStateType  state_type, 
				    GdkRectangle *area, 
				    gint          x, 
				    gint          y, 
				    gint          width, 
				    gint          height)
Elliot Lee's avatar
Elliot Lee committed
1102
{
1103
  GdkRectangle new_rect, old_rect;
1104
  
1105 1106

  if (area)
Elliot Lee's avatar
Elliot Lee committed
1107
    {
1108 1109 1110 1111 1112
      old_rect.x = x;
      old_rect.y = y;
      old_rect.width = width;
      old_rect.height = height;
      
1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130
      if (!gdk_rectangle_intersect (area, &old_rect, &new_rect))
	return;
    }
  else
    {
      new_rect.x = x;
      new_rect.y = y;
      new_rect.width = width;
      new_rect.height = height;
    }
  
  if (!style->bg_pixmap[state_type] ||
      (gdk_window_get_type (window) == GDK_WINDOW_PIXMAP) ||
      (!set_bg && (style->bg_pixmap[state_type]  != (GdkPixmap *) GDK_PARENT_RELATIVE)))
    {
      GdkGC *gc = style->bg_gc[state_type];

      if (style->bg_pixmap[state_type])
1131
	{
1132 1133
	  gdk_gc_set_fill (gc, GDK_TILED);
	  gdk_gc_set_tile (gc, style->bg_pixmap[state_type]);
1134
	}
1135 1136 1137 1138 1139
	
      gdk_draw_rectangle (window, gc, TRUE, 
			  new_rect.x, new_rect.y, new_rect.width, new_rect.height);
      if (style->bg_pixmap[state_type])
	gdk_gc_set_fill (gc, GDK_SOLID);
1140
    }
1141
  else
1142
    {
1143
      if (set_bg)
1144 1145 1146 1147 1148 1149
	{
	  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);
	}
1150
      
1151 1152 1153
      gdk_window_clear_area (window, 
			     new_rect.x, new_rect.y, 
			     new_rect.width, new_rect.height);
1154
    }
Elliot Lee's avatar
Elliot Lee committed
1155 1156
}

1157 1158 1159 1160 1161 1162 1163 1164 1165 1166
void 
gtk_style_apply_default_pixmap (GtkStyle     *style,
				GdkWindow    *window,
				GtkStateType  state_type, 
				GdkRectangle *area, 
				gint          x, 
				gint          y, 
				gint          width, 
				gint          height)
{
1167
  gtk_style_apply_default_background (style, window, TRUE, state_type,
1168 1169 1170
				      area, x, y, width, height);
}

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


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


static void
gtk_default_draw_shadow (GtkStyle      *style,
			 GdkWindow     *window,
			 GtkStateType   state_type,
			 GtkShadowType  shadow_type,
1279 1280 1281
			 GdkRectangle  *area,
			 GtkWidget     *widget,
			 gchar         *detail,
Elliot Lee's avatar
Elliot Lee committed
1282 1283 1284 1285 1286
			 gint           x,
			 gint           y,
			 gint           width,
			 gint           height)
{
1287 1288
  GdkGC *gc1 = NULL;
  GdkGC *gc2 = NULL;
Elliot Lee's avatar
Elliot Lee committed
1289 1290 1291
  gint thickness_light;
  gint thickness_dark;
  gint i;
1292
  
Elliot Lee's avatar
Elliot Lee committed
1293 1294
  g_return_if_fail (style != NULL);
  g_return_if_fail (window != NULL);
1295
  
Elliot Lee's avatar
Elliot Lee committed
1296 1297 1298 1299 1300 1301
  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);
1302
  
Elliot Lee's avatar
Elliot Lee committed
1303 1304 1305
  switch (shadow_type)
    {
    case GTK_SHADOW_NONE:
1306
      return;
Elliot Lee's avatar
Elliot Lee committed
1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317
    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;
    }
1318 1319 1320 1321 1322 1323 1324 1325 1326 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 || 
	  shadow_type == GTK_SHADOW_OUT)
	{
	  gdk_gc_set_clip_rectangle (style->black_gc, area);
	  gdk_gc_set_clip_rectangle (style->bg_gc[state_type], area);
	}
    }
  
  switch (shadow_type)
    {
Elliot Lee's avatar
Elliot Lee committed
1333 1334
    case GTK_SHADOW_NONE:
      break;
1335
      
Elliot Lee's avatar
Elliot Lee committed
1336 1337 1338 1339 1340
    case GTK_SHADOW_IN:
      gdk_draw_line (window, gc1,
                     x, y + height - 1, x + width - 1, y + height - 1);
      gdk_draw_line (window, gc1,
                     x + width - 1, y, x + width - 1, y + height - 1);
1341
      
Elliot Lee's avatar
Elliot Lee committed
1342 1343 1344 1345
      gdk_draw_line (window, style->bg_gc[state_type],
                     x + 1, y + height - 2, x + width - 2, y + height - 2);
      gdk_draw_line (window, style->bg_gc[state_type],
                     x + width - 2, y + 1, x + width - 2, y + height - 2);
1346
      
Elliot Lee's avatar
Elliot Lee committed
1347 1348 1349 1350
      gdk_draw_line (window, style->black_gc,
                     x + 1, y + 1, x + width - 2, y + 1);
      gdk_draw_line (window, style->black_gc,
                     x + 1, y + 1, x + 1, y + height - 2);
1351
      
Elliot Lee's avatar
Elliot Lee committed
1352 1353 1354 1355 1356
      gdk_draw_line (window, gc2,
                     x, y, x + width - 1, y);
      gdk_draw_line (window, gc2,
                     x, y, x, y + height - 1);
      break;
1357
      
Elliot Lee's avatar
Elliot Lee committed
1358 1359 1360 1361 1362
    case GTK_SHADOW_OUT:
      gdk_draw_line (window, gc1,
                     x + 1, y + height - 2, x + width - 2, y + height - 2);
      gdk_draw_line (window, gc1,
                     x + width - 2, y + 1, x + width - 2, y + height - 2);
1363
      
Elliot Lee's avatar
Elliot Lee committed
1364 1365 1366 1367
      gdk_draw_line (window, gc2,
                     x, y, x + width - 1, y);
      gdk_draw_line (window, gc2,
                     x, y, x, y + height - 1);
1368
      
Elliot Lee's avatar
Elliot Lee committed
1369 1370 1371 1372
      gdk_draw_line (window, style->bg_gc[state_type],
                     x + 1, y + 1, x + width - 2, y + 1);
      gdk_draw_line (window, style->bg_gc[state_type],
                     x + 1, y + 1, x + 1, y + height - 2);
1373
      
Elliot Lee's avatar
Elliot Lee committed
1374 1375 1376 1377 1378
      gdk_draw_line (window, style->black_gc,
                     x, y + height - 1, x + width - 1, y + height - 1);
      gdk_draw_line (window, style->black_gc,
                     x + width - 1, y, x + width - 1, y + height - 1);
      break;
1379
      
Elliot Lee's avatar
Elliot Lee committed
1380 1381 1382 1383
    case GTK_SHADOW_ETCHED_IN:
    case GTK_SHADOW_ETCHED_OUT:
      thickness_light = 1;
      thickness_dark = 1;
1384
      
Elliot Lee's avatar
Elliot Lee committed
1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396
      for (i = 0; i < thickness_dark; i++)
        {
          gdk_draw_line (window, gc1,
                         x + i,
                         y + height - i - 1,
                         x + width - i - 1,
                         y + height - i - 1);
          gdk_draw_line (window, gc1,
                         x + width - i - 1,
                         y + i,
                         x + width - i - 1,
                         y + height - i - 1);
1397
	  
Elliot Lee's avatar
Elliot Lee committed
1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408
          gdk_draw_line (window, gc2,
                         x + i,
                         y + i,
                         x + width - i - 2,
                         y + i);
          gdk_draw_line (window, gc2,
                         x + i,
                         y + i,
                         x + i,
                         y + height - i - 2);
        }
1409
      
Elliot Lee's avatar
Elliot Lee committed
1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421
      for (i = 0; i < thickness_light; i++)
        {
          gdk_draw_line (window, gc1,
                         x + thickness_dark + i,
                         y + thickness_dark + i,
                         x + width - thickness_dark - i - 1,
                         y + thickness_dark + i);
          gdk_draw_line (window, gc1,
                         x + thickness_dark + i,
                         y + thickness_dark + i,
                         x + thickness_dark + i,
                         y + height - thickness_dark - i - 1);
1422
	  
Elliot Lee's avatar
Elliot Lee committed
1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435
          gdk_draw_line (window, gc2,
                         x + thickness_dark + i,
                         y + height - thickness_light - i - 1,
                         x + width - thickness_light - 1,
                         y + height - thickness_light - i - 1);
          gdk_draw_line (window, gc2,
                         x + width - thickness_light - i - 1,
                         y + thickness_dark + i,
                         x + width - thickness_light - i - 1,
                         y + height - thickness_light - 1);
        }
      break;
    }
1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446
  if (area)
    {
      gdk_gc_set_clip_rectangle (gc1, NULL);
      gdk_gc_set_clip_rectangle (gc2, NULL);
      if (shadow_type == GTK_SHADOW_IN || 
	  shadow_type == GTK_SHADOW_OUT)
	{
	  gdk_gc_set_clip_rectangle (style->black_gc, NULL);
	  gdk_gc_set_clip_rectangle (style->bg_gc[state_type], NULL);
	}
    }
Elliot Lee's avatar
Elliot Lee committed
1447 1448 1449 1450 1451 1452 1453 1454
}


static void
gtk_default_draw_polygon (GtkStyle      *style,
			  GdkWindow     *window,
			  GtkStateType   state_type,
			  GtkShadowType  shadow_type,
1455 1456 1457
			  GdkRectangle  *area,
			  GtkWidget     *widget,
			  gchar         *detail,
Elliot Lee's avatar
Elliot Lee committed
1458 1459
			  GdkPoint      *points,
			  gint           npoints,
1460
			  gboolean       fill)
Elliot Lee's avatar
Elliot Lee committed
1461 1462 1463 1464 1465 1466 1467
{
#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 */
1468
  
Elliot Lee's avatar
Elliot Lee committed
1469 1470
  static const gdouble pi_over_4 = M_PI_4;
  static const gdouble pi_3_over_4 = M_PI_4 * 3;
1471
  
Elliot Lee's avatar
Elliot Lee committed
1472 1473 1474 1475 1476 1477 1478 1479
  GdkGC *gc1;
  GdkGC *gc2;
  GdkGC *gc3;
  GdkGC *gc4;
  gdouble angle;
  gint xadjust;
  gint yadjust;
  gint i;
1480
  
Elliot Lee's avatar
Elliot Lee committed
1481 1482 1483
  g_return_if_fail (style != NULL);
  g_return_if_fail (window != NULL);
  g_return_if_fail (points != NULL);
1484
  
Elliot Lee's avatar
Elliot Lee committed
1485 1486 1487 1488 1489 1490 1491 1492
  switch (shadow_type)
    {
    case GTK_SHADOW_IN:
      gc1 = style->bg_gc[state_type];
      gc2 = style->dark_gc[state_type];
      gc3 = style->light_gc[state_type];
      gc4 = style->black_gc;
      break;
1493
    case GTK_SHADOW_ETCHED_IN:
1494 1495 1496 1497 1498
      gc1 = style->light_gc[state_type];
      gc2 = style->dark_gc[state_type];
      gc3 = style->dark_gc[state_type];
      gc4 = style->light_gc[state_type];
      break;
Elliot Lee's avatar
Elliot Lee committed
1499 1500 1501 1502 1503 1504
    case GTK_SHADOW_OUT:
      gc1 = style->dark_gc[state_type];
      gc2 = style->light_gc[state_type];
      gc3 = style->black_gc;
      gc4 = style->bg_gc[state_type];
      break;
1505
    case GTK_SHADOW_ETCHED_OUT:
1506 1507 1508 1509 1510
      gc1 = style->dark_gc[state_type];
      gc2 = style->light_gc[state_type];
      gc3 = style->light_gc[state_type];
      gc4 = style->dark_gc[state_type];
      break;
Elliot Lee's avatar
Elliot Lee committed
1511 1512 1513
    default:
      return;
    }
1514 1515 1516 1517 1518 1519 1520 1521 1522 1523
  
  if (area)
    {
      gdk_gc_set_clip_rectangle (gc1, area);
      gdk_gc_set_clip_rectangle (gc2, area);
      gdk_gc_set_clip_rectangle (gc3, area);
      gdk_gc_set_clip_rectangle (gc4, area);
    }
  
  if (fill)
Elliot Lee's avatar
Elliot Lee committed
1524
    gdk_draw_polygon (window, style->bg_gc[state_type], TRUE, points, npoints);
1525
  
1526
  npoints--;
1527
  
Elliot Lee's avatar
Elliot Lee committed
1528 1529
  for (i = 0; i < npoints; i++)
    {
1530 1531
      if ((points[i].x == points[i+1].x) &&
	  (points[i].y == points[i+1].y))
Elliot Lee's avatar
Elliot Lee committed
1532 1533 1534 1535 1536
	{
	  angle = 0;
	}
      else
	{
1537 1538
	  angle = atan2 (points[i+1].y - points[i].y,
			 points[i+1].x - points[i].x);
Elliot Lee's avatar
Elliot Lee committed
1539
	}
1540
      
Elliot Lee's avatar
Elliot Lee committed
1541 1542
      if ((angle > -pi_3_over_4) && (angle < pi_over_4))
	{
1543
	  if (angle > -pi_over_4)
Elliot Lee's avatar
Elliot Lee committed
1544 1545 1546 1547 1548 1549 1550 1551 1552
	    {
	      xadjust = 0;
	      yadjust = 1;
	    }
	  else
	    {
	      xadjust = 1;
	      yadjust = 0;
	    }
1553
	  
Elliot Lee's avatar
Elliot Lee committed
1554 1555
	  gdk_draw_line (window, gc1,
			 points[i].x-xadjust, points[i].y-yadjust,
1556
			 points[i+1].x-xadjust, points[i+1].y-yadjust);
Elliot Lee's avatar
Elliot Lee committed
1557 1558
	  gdk_draw_line (window, gc3,
			 points[i].x, points[i].y,
1559
			 points[i+1].x, points[i+1].y);
Elliot Lee's avatar
Elliot Lee committed
1560 1561 1562
	}
      else
	{
1563
	  if ((angle < -pi_3_over_4) || (angle > pi_3_over_4))
Elliot Lee's avatar
Elliot Lee committed
1564 1565 1566 1567 1568 1569 1570 1571 1572
	    {
	      xadjust = 0;
	      yadjust = 1;
	    }
	  else
	    {
	      xadjust = 1;
	      yadjust = 0;
	    }
1573
	  
Elliot Lee's avatar
Elliot Lee committed
1574 1575
	  gdk_draw_line (window, gc4,
			 points[i].x+xadjust, points[i].y+yadjust,
1576
			 points[i+1].x+xadjust, points[i+1].y+yadjust);
Elliot Lee's avatar
Elliot Lee committed
1577 1578
	  gdk_draw_line (window, gc2,
			 points[i].x, points[i].y,
1579
			 points[i+1].x, points[i+1].y);
Elliot Lee's avatar
Elliot Lee committed
1580 1581
	}
    }
1582 1583 1584 1585 1586