gtkstyle.c 160 KB
Newer Older
Elliot Lee's avatar
Elliot Lee committed
1 2 3 4
/* 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
5
 * modify it under the terms of the GNU Lesser General Public
Elliot Lee's avatar
Elliot Lee committed
6 7 8 9 10 11
 * 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
12
 * Lesser General Public License for more details.
Elliot Lee's avatar
Elliot Lee committed
13
 *
14
 * You should have received a copy of the GNU Lesser 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
 * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
22 23 24 25 26
 * 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
#include <math.h>
28
#include <stdlib.h>
29
#include <string.h>
Elliot Lee's avatar
Elliot Lee committed
30
#include "gtkgc.h"
31
#include "gtkrc.h"
32
#include "gtkspinbutton.h"
Elliot Lee's avatar
Elliot Lee committed
33
#include "gtkstyle.h"
34
#include "gtkwidget.h"
35
#include "gtkthemes.h"
36
#include "gtkiconfactory.h"
37
#include "gtksettings.h"	/* _gtk_settings_parse_convert() */
Elliot Lee's avatar
Elliot Lee committed
38 39 40 41

#define LIGHTNESS_MULT  1.3
#define DARKNESS_MULT   0.7

42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
/* --- typedefs & structures --- */
typedef struct {
  GType       widget_type;
  GParamSpec *pspec;
  GValue      value;
} PropertyValue;


/* --- prototypes --- */
static void	 gtk_style_init			(GtkStyle	*style);
static void	 gtk_style_class_init		(GtkStyleClass	*klass);
static void	 gtk_style_finalize		(GObject	*object);
static void	 gtk_style_realize		(GtkStyle	*style,
						 GdkColormap	*colormap);
static void      gtk_style_real_realize        (GtkStyle	*style);
static void      gtk_style_real_unrealize      (GtkStyle	*style);
static void      gtk_style_real_copy           (GtkStyle	*style,
						GtkStyle	*src);
static void      gtk_style_real_set_background (GtkStyle	*style,
						GdkWindow	*window,
						GtkStateType	 state_type);
static GtkStyle *gtk_style_real_clone          (GtkStyle	*style);
static void      gtk_style_real_init_from_rc   (GtkStyle	*style,
                                                GtkRcStyle	*rc_style);
66 67 68 69
static GdkPixbuf *gtk_default_render_icon      (GtkStyle            *style,
                                                const GtkIconSource *source,
                                                GtkTextDirection     direction,
                                                GtkStateType         state,
70
                                                GtkIconSize          size,
71 72
                                                GtkWidget           *widget,
                                                const gchar         *detail);
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 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
static void gtk_default_draw_hline      (GtkStyle        *style,
					 GdkWindow       *window,
					 GtkStateType     state_type,
					 GdkRectangle    *area,
					 GtkWidget       *widget,
					 const gchar     *detail,
					 gint             x1,
					 gint             x2,
					 gint             y);
static void gtk_default_draw_vline      (GtkStyle        *style,
					 GdkWindow       *window,
					 GtkStateType     state_type,
					 GdkRectangle    *area,
					 GtkWidget       *widget,
					 const gchar     *detail,
					 gint             y1,
					 gint             y2,
					 gint             x);
static void gtk_default_draw_shadow     (GtkStyle        *style,
					 GdkWindow       *window,
					 GtkStateType     state_type,
					 GtkShadowType    shadow_type,
					 GdkRectangle    *area,
					 GtkWidget       *widget,
					 const gchar     *detail,
					 gint             x,
					 gint             y,
					 gint             width,
					 gint             height);
static void gtk_default_draw_polygon    (GtkStyle        *style,
					 GdkWindow       *window,
					 GtkStateType     state_type,
					 GtkShadowType    shadow_type,
					 GdkRectangle    *area,
					 GtkWidget       *widget,
					 const gchar     *detail,
					 GdkPoint        *points,
					 gint             npoints,
					 gboolean         fill);
static void gtk_default_draw_arrow      (GtkStyle        *style,
					 GdkWindow       *window,
					 GtkStateType     state_type,
					 GtkShadowType    shadow_type,
					 GdkRectangle    *area,
					 GtkWidget       *widget,
					 const gchar     *detail,
					 GtkArrowType     arrow_type,
					 gboolean         fill,
					 gint             x,
					 gint             y,
					 gint             width,
					 gint             height);
static void gtk_default_draw_diamond    (GtkStyle        *style,
					 GdkWindow       *window,
					 GtkStateType     state_type,
					 GtkShadowType    shadow_type,
					 GdkRectangle    *area,
					 GtkWidget       *widget,
					 const gchar     *detail,
					 gint             x,
					 gint             y,
					 gint             width,
					 gint             height);
static void gtk_default_draw_string     (GtkStyle        *style,
					 GdkWindow       *window,
					 GtkStateType     state_type,
					 GdkRectangle    *area,
					 GtkWidget       *widget,
					 const gchar     *detail,
					 gint             x,
					 gint             y,
					 const gchar     *string);
static void gtk_default_draw_box        (GtkStyle        *style,
					 GdkWindow       *window,
					 GtkStateType     state_type,
					 GtkShadowType    shadow_type,
					 GdkRectangle    *area,
					 GtkWidget       *widget,
					 const 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,
					 const 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,
					 const 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,
					 const gchar     *detail,
					 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,
					 const 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,
					 const 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,
					 const 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,
					 const gchar     *detail,
					 gint             x,
					 gint             y,
					 gint             width,
					 gint             height,
					 GtkPositionType  gap_side);
static void gtk_default_draw_focus      (GtkStyle        *style,
					 GdkWindow       *window,
242
					 GtkStateType     state_type,
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
					 GdkRectangle    *area,
					 GtkWidget       *widget,
					 const 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,
					 const 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,
					 const gchar     *detail,
					 gint             x,
					 gint             y,
					 gint             width,
					 gint             height,
					 GtkOrientation   orientation);
274 275 276 277 278 279 280 281
static void gtk_default_draw_expander   (GtkStyle        *style,
                                         GdkWindow       *window,
                                         GtkStateType     state_type,
                                         GdkRectangle    *area,
                                         GtkWidget       *widget,
                                         const gchar     *detail,
                                         gint             x,
                                         gint             y,
282
					 GtkExpanderStyle expander_style);
283 284 285
static void gtk_default_draw_layout     (GtkStyle        *style,
                                         GdkWindow       *window,
                                         GtkStateType     state_type,
286
					 gboolean         use_text,
287 288 289 290 291 292
                                         GdkRectangle    *area,
                                         GtkWidget       *widget,
                                         const gchar     *detail,
                                         gint             x,
                                         gint             y,
                                         PangoLayout     *layout);
Owen Taylor's avatar
Owen Taylor committed
293 294 295 296 297 298 299 300 301 302 303 304
static void gtk_default_draw_resize_grip (GtkStyle       *style,
                                          GdkWindow      *window,
                                          GtkStateType    state_type,
                                          GdkRectangle   *area,
                                          GtkWidget      *widget,
                                          const gchar    *detail,
                                          GdkWindowEdge   edge,
                                          gint            x,
                                          gint            y,
                                          gint            width,
                                          gint            height);

305 306 307 308 309 310 311 312 313 314 315
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);


316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399
/*
 * Data for default check and radio buttons
 */

static GtkRequisition default_option_indicator_size = { 7, 13 };
static GtkBorder default_option_indicator_spacing = { 7, 5, 2, 2 };

#define INDICATOR_PART_SIZE 13

typedef enum {
  CHECK_AA,
  CHECK_BASE,
  CHECK_BLACK,
  CHECK_DARK,
  CHECK_LIGHT,
  CHECK_MID,
  CHECK_TEXT,
  RADIO_BASE,
  RADIO_BLACK,
  RADIO_DARK,
  RADIO_LIGHT,
  RADIO_MID,
  RADIO_TEXT
} IndicatorPart;

static char check_aa_bits[] = {
 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x58,0x00,0xa0,
 0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
static char check_base_bits[] = {
 0x00,0x00,0x00,0x00,0xfc,0x07,0xfc,0x07,0xfc,0x07,0xfc,0x07,0xfc,0x07,0xfc,
 0x07,0xfc,0x07,0xfc,0x07,0xfc,0x07,0x00,0x00,0x00,0x00};
static char check_black_bits[] = {
 0x00,0x00,0xfe,0x0f,0x02,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,
 0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x00,0x00};
static char check_dark_bits[] = {
 0xff,0x1f,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,
 0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00};
static char check_light_bits[] = {
 0x00,0x00,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,
 0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0xfe,0x1f};
static char check_mid_bits[] = {
 0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x08,0x00,0x08,0x00,0x08,0x00,0x08,0x00,
 0x08,0x00,0x08,0x00,0x08,0x00,0x08,0xfc,0x0f,0x00,0x00};
static char check_text_bits[] = {
 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x03,0x80,0x01,0x80,0x00,0xd8,
 0x00,0x60,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
static char radio_base_bits[] = {
 0x00,0x00,0x00,0x00,0xf0,0x01,0xf8,0x03,0xfc,0x07,0xfc,0x07,0xfc,0x07,0xfc,
 0x07,0xfc,0x07,0xf8,0x03,0xf0,0x01,0x00,0x00,0x00,0x00};
static char radio_black_bits[] = {
 0x00,0x00,0xf0,0x01,0x08,0x02,0x04,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,
 0x00,0x02,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
static char radio_dark_bits[] = {
 0xf0,0x01,0x08,0x02,0x04,0x04,0x02,0x04,0x01,0x00,0x01,0x00,0x01,0x00,0x01,
 0x00,0x01,0x00,0x02,0x00,0x0c,0x00,0x00,0x00,0x00,0x00};
static char radio_light_bits[] = {
 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x10,0x00,0x10,0x00,0x10,0x00,
 0x10,0x00,0x10,0x00,0x08,0x00,0x04,0x08,0x02,0xf0,0x01};
static char radio_mid_bits[] = {
 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x08,0x00,0x08,0x00,
 0x08,0x00,0x08,0x00,0x04,0x00,0x02,0xf0,0x01,0x00,0x00};
static char radio_text_bits[] = {
 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xe0,0x00,0xf0,0x01,0xf0,0x01,0xf0,
 0x01,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};

static struct {
  char      *bits;
  GdkBitmap *bmap;
} indicator_parts[] = {
  { check_aa_bits, NULL },
  { check_base_bits, NULL },
  { check_black_bits, NULL },
  { check_dark_bits, NULL },
  { check_light_bits, NULL },
  { check_mid_bits, NULL },
  { check_text_bits, NULL },
  { radio_base_bits, NULL },
  { radio_black_bits, NULL },
  { radio_dark_bits, NULL },
  { radio_light_bits, NULL },
  { radio_mid_bits, NULL },
  { radio_text_bits, NULL }
};

400
/* --- variables --- */
Elliot Lee's avatar
Elliot Lee committed
401 402 403 404 405 406 407 408 409 410 411
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 };
412 413
static GdkColor gtk_default_selected_base =  { 0, 0xa4a4, 0xdfdf, 0xffff };
static GdkColor gtk_default_active_base =    { 0, 0xbcbc, 0xd2d2, 0xeeee };
Elliot Lee's avatar
Elliot Lee committed
414

415 416 417
static gpointer parent_class = NULL;


418
/* --- functions --- */
419 420
GType
gtk_style_get_type (void)
421
{
422 423 424
  static GType style_type = 0;
  
  if (!style_type)
Stuart Parmenter's avatar
Stuart Parmenter committed
425
    {
426
      static const GTypeInfo style_info =
427 428 429 430 431 432 433 434 435 436 437 438
      {
        sizeof (GtkStyleClass),
        (GBaseInitFunc) NULL,
        (GBaseFinalizeFunc) NULL,
        (GClassInitFunc) gtk_style_class_init,
        NULL,           /* class_finalize */
        NULL,           /* class_data */
        sizeof (GtkStyle),
        0,              /* n_preallocs */
        (GInstanceInitFunc) gtk_style_init,
      };
      
439 440 441
      style_type = g_type_register_static (G_TYPE_OBJECT,
					   "GtkStyle",
					   &style_info, 0);
Stuart Parmenter's avatar
Stuart Parmenter committed
442
    }
443
  
444
  return style_type;
445
}
Elliot Lee's avatar
Elliot Lee committed
446

447 448
static void
gtk_style_init (GtkStyle *style)
Elliot Lee's avatar
Elliot Lee committed
449 450
{
  gint i;
451
  
452
  style->font_desc = pango_font_description_from_string ("Sans 10");
Elliot Lee's avatar
Elliot Lee committed
453

Elliot Lee's avatar
Elliot Lee committed
454 455 456
  style->attach_count = 0;
  style->colormap = NULL;
  style->depth = -1;
457
  
Elliot Lee's avatar
Elliot Lee committed
458 459 460
  style->black.red = 0;
  style->black.green = 0;
  style->black.blue = 0;
461
  
Elliot Lee's avatar
Elliot Lee committed
462 463 464
  style->white.red = 65535;
  style->white.green = 65535;
  style->white.blue = 65535;
465
  
Elliot Lee's avatar
Elliot Lee committed
466 467
  style->black_gc = NULL;
  style->white_gc = NULL;
468
  
Elliot Lee's avatar
Elliot Lee committed
469 470 471 472 473
  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;
474
  
Elliot Lee's avatar
Elliot Lee committed
475 476 477 478 479
  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;
480
  
481
  for (i = 0; i < 4; i++)
Elliot Lee's avatar
Elliot Lee committed
482 483 484 485
    {
      style->text[i] = style->fg[i];
      style->base[i] = style->white;
    }
Havoc Pennington's avatar
Havoc Pennington committed
486

487 488 489 490
  style->base[GTK_STATE_SELECTED] = gtk_default_selected_base;
  style->text[GTK_STATE_SELECTED] = style->black;
  style->base[GTK_STATE_ACTIVE] = gtk_default_active_base;
  style->text[GTK_STATE_ACTIVE] = style->black;
Owen Taylor's avatar
Owen Taylor committed
491 492
  style->base[GTK_STATE_INSENSITIVE] = gtk_default_prelight_bg;
  style->text[GTK_STATE_INSENSITIVE] = gtk_default_insensitive_fg;
493
  
Elliot Lee's avatar
Elliot Lee committed
494 495
  for (i = 0; i < 5; i++)
    style->bg_pixmap[i] = NULL;
496
  
497
  style->rc_style = NULL;
498
  
Elliot Lee's avatar
Elliot Lee committed
499 500 501 502 503 504 505 506 507
  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;
508
      style->text_aa_gc[i] = NULL;
Elliot Lee's avatar
Elliot Lee committed
509
    }
510 511 512

  style->xthickness = 2;
  style->ythickness = 2;
513 514

  style->property_cache = NULL;
515 516 517 518 519 520 521 522 523 524 525
}

static void
gtk_style_class_init (GtkStyleClass *klass)
{
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
  
  parent_class = g_type_class_peek_parent (klass);

  object_class->finalize = gtk_style_finalize;

526 527 528 529 530 531
  klass->clone = gtk_style_real_clone;
  klass->copy = gtk_style_real_copy;
  klass->init_from_rc = gtk_style_real_init_from_rc;
  klass->realize = gtk_style_real_realize;
  klass->unrealize = gtk_style_real_unrealize;
  klass->set_background = gtk_style_real_set_background;
532 533
  klass->render_icon = gtk_default_render_icon;

534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551
  klass->draw_hline = gtk_default_draw_hline;
  klass->draw_vline = gtk_default_draw_vline;
  klass->draw_shadow = gtk_default_draw_shadow;
  klass->draw_polygon = gtk_default_draw_polygon;
  klass->draw_arrow = gtk_default_draw_arrow;
  klass->draw_diamond = gtk_default_draw_diamond;
  klass->draw_string = gtk_default_draw_string;
  klass->draw_box = gtk_default_draw_box;
  klass->draw_flat_box = gtk_default_draw_flat_box;
  klass->draw_check = gtk_default_draw_check;
  klass->draw_option = gtk_default_draw_option;
  klass->draw_tab = gtk_default_draw_tab;
  klass->draw_shadow_gap = gtk_default_draw_shadow_gap;
  klass->draw_box_gap = gtk_default_draw_box_gap;
  klass->draw_extension = gtk_default_draw_extension;
  klass->draw_focus = gtk_default_draw_focus;
  klass->draw_slider = gtk_default_draw_slider;
  klass->draw_handle = gtk_default_draw_handle;
552 553
  klass->draw_expander = gtk_default_draw_expander;
  klass->draw_layout = gtk_default_draw_layout;
Owen Taylor's avatar
Owen Taylor committed
554
  klass->draw_resize_grip = gtk_default_draw_resize_grip;
555 556 557
}

static void
558
clear_property_cache (GtkStyle *style)
559
{
560 561 562 563
  if (style->property_cache)
    {
      guint i;

564
      for (i = 0; i < style->property_cache->len; i++)
565
	{
566
	  PropertyValue *node = &g_array_index (style->property_cache, PropertyValue, i);
567 568 569 570

	  g_param_spec_unref (node->pspec);
	  g_value_unset (&node->value);
	}
571
      g_array_free (style->property_cache, TRUE);
572 573
      style->property_cache = NULL;
    }
574 575 576 577 578 579 580 581 582 583
}

static void
gtk_style_finalize (GObject *object)
{
  GtkStyle *style = GTK_STYLE (object);

  g_return_if_fail (style->attach_count == 0);

  clear_property_cache (style);
584 585 586 587 588 589 590 591 592 593 594
  
  if (style->styles)
    {
      if (style->styles->data != style)
        g_slist_remove (style->styles, style);
      else
        {
          GSList *tmp_list = style->styles->next;
	  
          while (tmp_list)
            {
595
              GTK_STYLE (tmp_list->data)->styles = style->styles->next;
596 597 598 599 600
              tmp_list = tmp_list->next;
            }
          g_slist_free_1 (style->styles);
        }
    }
601

602 603
  pango_font_description_free (style->font_desc);
  
604 605 606 607 608 609
  if (style->private_font)
    gdk_font_unref (style->private_font);

  if (style->private_font_desc)
    pango_font_description_free (style->private_font_desc);
  
610 611 612 613 614 615 616 617 618 619 620 621
  if (style->rc_style)
    gtk_rc_style_unref (style->rc_style);
  
  G_OBJECT_CLASS (parent_class)->finalize (object);
}


GtkStyle*
gtk_style_copy (GtkStyle *style)
{
  GtkStyle *new_style;
  
622
  g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
623
  
624 625
  new_style = GTK_STYLE_GET_CLASS (style)->clone (style);
  GTK_STYLE_GET_CLASS (style)->copy (new_style, style);
626 627 628 629 630 631 632 633 634

  return new_style;
}

static GtkStyle*
gtk_style_duplicate (GtkStyle *style)
{
  GtkStyle *new_style;
  
635
  g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
636 637 638 639 640 641 642 643 644
  
  new_style = gtk_style_copy (style);
  
  style->styles = g_slist_append (style->styles, new_style);
  new_style->styles = style->styles;  
  
  return new_style;
}

Matthias Clasen's avatar
Matthias Clasen committed
645 646 647 648 649 650
/**
 * gtk_style_new:
 * @returns: a new #GtkStyle.
 *
 * Creates a new #GtkStyle.
 **/
651 652 653 654 655
GtkStyle*
gtk_style_new (void)
{
  GtkStyle *style;
  
656
  style = g_object_new (GTK_TYPE_STYLE, NULL);
657
  
Elliot Lee's avatar
Elliot Lee committed
658 659 660
  return style;
}

Matthias Clasen's avatar
Matthias Clasen committed
661
/**
662
 * gtk_style_attach:
Matthias Clasen's avatar
Matthias Clasen committed
663 664 665 666 667 668
 * @style: a #GtkStyle.
 * @window: a #GtkWindow.
 * @returns: Either @style, or a newly-created #GtkStyle.
 *   If the style is newly created, the style parameter
 *   will be dereferenced, and the new style will have
 *   a reference count belonging to the caller.
669
 *
Matthias Clasen's avatar
Matthias Clasen committed
670 671 672 673 674 675 676
 * Attaches a style to a window; this process allocates the
 * colors and creates the GC's for the style - it specializes
 * it to a particular visual and colormap. The process may 
 * involve the creation of a new style if the style has already 
 * been attached to a window with a different style and colormap.
 **/
 /*
677 678 679 680 681 682 683 684 685 686 687 688 689 690
 * FIXME: The sequence - 
 *    create a style => s1
 *    attach s1 to v1, c1 => s1
 *    attach s1 to v2, c2 => s2
 *    detach s1 from v1, c1
 *    attach s1 to v2, c2 => s3
 * results in two separate, unlinked styles s2 and s3 which
 * are identical and could be shared. To fix this, we would
 * want to never remove a style from the list of linked
 * styles as long as as it has a reference count. However, the 
 * disadvantage of doing it this way means that we would need two 
 * passes through the linked list when attaching (one to check for 
 * matching styles, one to look for empty unattached styles - but 
 * it will almost never be longer than 2 elements.
Matthias Clasen's avatar
Matthias Clasen committed
691
 */
692
GtkStyle*
Elliot Lee's avatar
Elliot Lee committed
693
gtk_style_attach (GtkStyle  *style,
694
                  GdkWindow *window)
Elliot Lee's avatar
Elliot Lee committed
695
{
696 697
  GSList *styles;
  GtkStyle *new_style = NULL;
Elliot Lee's avatar
Elliot Lee committed
698
  GdkColormap *colormap;
699
  
700
  g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
Elliot Lee's avatar
Elliot Lee committed
701
  g_return_val_if_fail (window != NULL, NULL);
702
  
Elliot Lee's avatar
Elliot Lee committed
703
  colormap = gdk_window_get_colormap (window);
704
  
705 706
  if (!style->styles)
    style->styles = g_slist_append (NULL, style);
707
  
708 709
  styles = style->styles;
  while (styles)
Elliot Lee's avatar
Elliot Lee committed
710
    {
711
      new_style = styles->data;
712
      
713
      if (new_style->attach_count == 0)
714
        {
715
          gtk_style_realize (new_style, colormap);
716 717
          break;
        }
718
      else if (new_style->colormap == colormap)
719
        break;
720
      
721 722
      new_style = NULL;
      styles = styles->next;
Elliot Lee's avatar
Elliot Lee committed
723
    }
724
  
725 726 727
  if (!new_style)
    {
      new_style = gtk_style_duplicate (style);
728
      gtk_style_realize (new_style, colormap);
729
    }
730 731

  /* A style gets a refcount from being attached */
732
  if (new_style->attach_count == 0)
733
    g_object_ref (new_style);
734 735 736 737

  /* Another refcount belongs to the parent */
  if (style != new_style) 
    {
738 739
      g_object_unref (style);
      g_object_ref (new_style);
740
    }
741
  
742
  new_style->attach_count++;
743
  
744
  return new_style;
Elliot Lee's avatar
Elliot Lee committed
745 746 747 748 749
}

void
gtk_style_detach (GtkStyle *style)
{
750
  g_return_if_fail (GTK_IS_STYLE (style));
751
  
Elliot Lee's avatar
Elliot Lee committed
752 753 754
  style->attach_count -= 1;
  if (style->attach_count == 0)
    {
755
      GTK_STYLE_GET_CLASS (style)->unrealize (style);
756
      
757 758 759
      gdk_colormap_unref (style->colormap);
      style->colormap = NULL;
      
760
      g_object_unref (style);
Elliot Lee's avatar
Elliot Lee committed
761 762 763
    }
}

Matthias Clasen's avatar
Matthias Clasen committed
764 765 766 767 768 769 770
/**
 * gtk_style_ref:
 * @style: a #GtkStyle.
 * @returns: @style.
 *
 * Deprecated equivalent of g_object_ref().
 **/
Elliot Lee's avatar
Elliot Lee committed
771 772 773
GtkStyle*
gtk_style_ref (GtkStyle *style)
{
774
  return (GtkStyle *) g_object_ref (G_OBJECT (style));
Elliot Lee's avatar
Elliot Lee committed
775 776
}

Matthias Clasen's avatar
Matthias Clasen committed
777 778 779 780 781 782
/**
 * gtk_style_unref:
 * @style: a #GtkStyle.
 *
 * Deprecated equivalent of g_object_unref().
 **/
Elliot Lee's avatar
Elliot Lee committed
783 784 785
void
gtk_style_unref (GtkStyle *style)
{
786
  g_object_unref (G_OBJECT (style));
Elliot Lee's avatar
Elliot Lee committed
787 788
}

789
static void
790
gtk_style_realize (GtkStyle    *style,
791
                   GdkColormap *colormap)
792
{
793
  g_return_if_fail (GTK_IS_STYLE (style));
Hans Breuer's avatar
Hans Breuer committed
794
  g_return_if_fail (GDK_IS_COLORMAP (colormap));
795
  
796
  style->colormap = gdk_colormap_ref (colormap);
797 798 799
  style->depth = gdk_colormap_get_visual (colormap)->depth;

  GTK_STYLE_GET_CLASS (style)->realize (style);
800 801
}

802 803 804 805 806 807 808 809 810 811 812 813
GtkIconSet*
gtk_style_lookup_icon_set (GtkStyle   *style,
                           const char *stock_id)
{
  GSList *iter;

  g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
  g_return_val_if_fail (stock_id != NULL, NULL);
  
  iter = style->icon_factories;
  while (iter != NULL)
    {
814 815
      GtkIconSet *icon_set = gtk_icon_factory_lookup (GTK_ICON_FACTORY (iter->data),
						      stock_id);
816 817 818 819 820 821 822 823 824
      if (icon_set)
        return icon_set;
      
      iter = g_slist_next (iter);
    }

  return gtk_icon_factory_lookup_default (stock_id);
}

Elliot Lee's avatar
Elliot Lee committed
825 826
void
gtk_draw_hline (GtkStyle     *style,
827 828 829 830 831
                GdkWindow    *window,
                GtkStateType  state_type,
                gint          x1,
                gint          x2,
                gint          y)
Elliot Lee's avatar
Elliot Lee committed
832
{
833
  g_return_if_fail (GTK_IS_STYLE (style));
834
  g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_hline != NULL);
835
  
836
  GTK_STYLE_GET_CLASS (style)->draw_hline (style, window, state_type, NULL, NULL, NULL, x1, x2, y);
Elliot Lee's avatar
Elliot Lee committed
837 838 839 840 841
}


void
gtk_draw_vline (GtkStyle     *style,
842 843 844 845 846
                GdkWindow    *window,
                GtkStateType  state_type,
                gint          y1,
                gint          y2,
                gint          x)
Elliot Lee's avatar
Elliot Lee committed
847
{
848
  g_return_if_fail (GTK_IS_STYLE (style));
849
  g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_vline != NULL);
850
  
851
  GTK_STYLE_GET_CLASS (style)->draw_vline (style, window, state_type, NULL, NULL, NULL, y1, y2, x);
Elliot Lee's avatar
Elliot Lee committed
852 853 854 855 856
}


void
gtk_draw_shadow (GtkStyle      *style,
857 858 859 860 861 862 863
                 GdkWindow     *window,
                 GtkStateType   state_type,
                 GtkShadowType  shadow_type,
                 gint           x,
                 gint           y,
                 gint           width,
                 gint           height)
Elliot Lee's avatar
Elliot Lee committed
864
{
865
  g_return_if_fail (GTK_IS_STYLE (style));
866
  g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow != NULL);
867
  
868
  GTK_STYLE_GET_CLASS (style)->draw_shadow (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
Elliot Lee's avatar
Elliot Lee committed
869 870 871 872
}

void
gtk_draw_polygon (GtkStyle      *style,
873 874 875 876 877 878
                  GdkWindow     *window,
                  GtkStateType   state_type,
                  GtkShadowType  shadow_type,
                  GdkPoint      *points,
                  gint           npoints,
                  gboolean       fill)
Elliot Lee's avatar
Elliot Lee committed
879
{
880
  g_return_if_fail (GTK_IS_STYLE (style));
881
  g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_polygon != NULL);
882
  
883
  GTK_STYLE_GET_CLASS (style)->draw_polygon (style, window, state_type, shadow_type, NULL, NULL, NULL, points, npoints, fill);
Elliot Lee's avatar
Elliot Lee committed
884 885 886 887
}

void
gtk_draw_arrow (GtkStyle      *style,
888 889 890 891 892 893 894 895 896
                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
897
{
898
  g_return_if_fail (GTK_IS_STYLE (style));
899
  g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_arrow != NULL);
900
  
901
  GTK_STYLE_GET_CLASS (style)->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
902 903 904 905 906
}


void
gtk_draw_diamond (GtkStyle      *style,
907 908 909 910 911 912 913
                  GdkWindow     *window,
                  GtkStateType   state_type,
                  GtkShadowType  shadow_type,
                  gint           x,
                  gint           y,
                  gint           width,
                  gint           height)
Elliot Lee's avatar
Elliot Lee committed
914
{
915
  g_return_if_fail (GTK_IS_STYLE (style));
916
  g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_diamond != NULL);
917
  
918
  GTK_STYLE_GET_CLASS (style)->draw_diamond (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
Elliot Lee's avatar
Elliot Lee committed
919 920 921 922 923
}


void
gtk_draw_string (GtkStyle      *style,
924 925 926 927 928
                 GdkWindow     *window,
                 GtkStateType   state_type,
                 gint           x,
                 gint           y,
                 const gchar   *string)
Elliot Lee's avatar
Elliot Lee committed
929
{
930
  g_return_if_fail (GTK_IS_STYLE (style));
931
  g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_string != NULL);
932
  
933
  GTK_STYLE_GET_CLASS (style)->draw_string (style, window, state_type, NULL, NULL, NULL, x, y, string);
Elliot Lee's avatar
Elliot Lee committed
934 935
}

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

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

968
void
969 970 971 972 973 974 975 976
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
977
{
978
  g_return_if_fail (GTK_IS_STYLE (style));
979
  g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_check != NULL);
980
  
981
  GTK_STYLE_GET_CLASS (style)->draw_check (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
Elliot Lee's avatar
Elliot Lee committed
982 983
}

984
void
985 986 987 988 989 990 991 992
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
993
{
994
  g_return_if_fail (GTK_IS_STYLE (style));
995
  g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_option != NULL);
996
  
997
  GTK_STYLE_GET_CLASS (style)->draw_option (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
Elliot Lee's avatar
Elliot Lee committed
998 999
}

1000
void
1001 1002 1003 1004 1005 1006 1007 1008
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
1009
{
1010
  g_return_if_fail (GTK_IS_STYLE (style));
1011
  g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_tab != NULL);
1012
  
1013
  GTK_STYLE_GET_CLASS (style)->draw_tab (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height);
1014
}
Elliot Lee's avatar
Elliot Lee committed
1015

1016 1017
void
gtk_draw_shadow_gap (GtkStyle       *style,
1018 1019 1020 1021 1022 1023 1024 1025 1026 1027
                     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)
1028
{
1029
  g_return_if_fail (GTK_IS_STYLE (style));
1030
  g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow_gap != NULL);
1031
  
1032
  GTK_STYLE_GET_CLASS (style)->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
1033 1034
}

1035 1036
void
gtk_draw_box_gap (GtkStyle       *style,
1037 1038 1039 1040 1041 1042 1043 1044 1045 1046
                  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
1047
{
1048
  g_return_if_fail (GTK_IS_STYLE (style));
1049
  g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box_gap != NULL);
1050
  
1051
  GTK_STYLE_GET_CLASS (style)->draw_box_gap (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height, gap_side, gap_x, gap_width);
1052
}
Elliot Lee's avatar
Elliot Lee committed
1053

1054 1055
void
gtk_draw_extension (GtkStyle       *style,
1056 1057 1058 1059 1060 1061 1062 1063
                    GdkWindow      *window,
                    GtkStateType    state_type,
                    GtkShadowType   shadow_type,
                    gint            x,
                    gint            y,
                    gint            width,
                    gint            height,
                    GtkPositionType gap_side)
1064
{
1065
  g_return_if_fail (GTK_IS_STYLE (style));
1066
  g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_extension != NULL);
1067
  
1068
  GTK_STYLE_GET_CLASS (style)->draw_extension (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height, gap_side);
Elliot Lee's avatar
Elliot Lee committed
1069 1070
}

1071
void
1072 1073 1074 1075 1076 1077
gtk_draw_focus (GtkStyle      *style,
		GdkWindow     *window,
		gint           x,
		gint           y,
		gint           width,
		gint           height)
Elliot Lee's avatar
Elliot Lee committed
1078
{
1079
  g_return_if_fail (GTK_IS_STYLE (style));
1080
  g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_focus != NULL);
1081
  
1082
  GTK_STYLE_GET_CLASS (style)->draw_focus (style, window, GTK_STATE_NORMAL, NULL, NULL, NULL, x, y, width, height);
Elliot Lee's avatar
Elliot Lee committed
1083 1084
}

1085
void 
1086 1087 1088 1089 1090 1091 1092 1093 1094
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
1095
{
1096
  g_return_if_fail (GTK_IS_STYLE (style));
1097
  g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_slider != NULL);
1098
  
1099
  GTK_STYLE_GET_CLASS (style)->draw_slider (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height, orientation);
Elliot Lee's avatar
Elliot Lee committed
1100 1101
}

1102
void 
1103 1104 1105 1106 1107 1108 1109 1110 1111
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
1112
{
1113
  g_return_if_fail (GTK_IS_STYLE (style));
1114
  g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_handle != NULL);
1115
  
1116
  GTK_STYLE_GET_CLASS (style)->draw_handle (style, window, state_type, shadow_type, NULL, NULL, NULL, x, y, width, height, orientation);
Elliot Lee's avatar
Elliot Lee committed
1117 1118
}

1119 1120 1121 1122 1123 1124
void
gtk_draw_expander (GtkStyle        *style,
                   GdkWindow       *window,
                   GtkStateType     state_type,
                   gint             x,
                   gint             y,
1125
		   GtkExpanderStyle expander_style)
1126 1127 1128 1129 1130 1131
{
  g_return_if_fail (GTK_IS_STYLE (style));
  g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_expander != NULL);
  
  GTK_STYLE_GET_CLASS (style)->draw_expander (style, window, state_type,
                                              NULL, NULL, NULL,
1132
                                              x, y, expander_style);
1133 1134 1135 1136 1137 1138
}

void
gtk_draw_layout (GtkStyle        *style,
                 GdkWindow       *window,
                 GtkStateType     state_type,
1139
		 gboolean         use_text,
1140 1141 1142 1143 1144 1145 1146
                 gint             x,
                 gint             y,
                 PangoLayout     *layout)
{
  g_return_if_fail (GTK_IS_STYLE (style));
  g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_layout != NULL);
  
1147
  GTK_STYLE_GET_CLASS (style)->draw_layout (style, window, state_type, use_text,
1148 1149 1150 1151
                                            NULL, NULL, NULL,
                                            x, y, layout);
}

Owen Taylor's avatar
Owen Taylor committed
1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171
void
gtk_draw_resize_grip (GtkStyle     *style,
                      GdkWindow    *window,
                      GtkStateType  state_type,
                      GdkWindowEdge edge,
                      gint          x,
                      gint          y,
                      gint          width,
                      gint          height)
{
  g_return_if_fail (GTK_IS_STYLE (style));
  g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_resize_grip != NULL);

  GTK_STYLE_GET_CLASS (style)->draw_resize_grip (style, window, state_type,
                                                 NULL, NULL, NULL,
                                                 edge,
                                                 x, y, width, height);
}


1172
void
1173 1174 1175
gtk_style_set_background (GtkStyle    *style,
                          GdkWindow   *window,
                          GtkStateType state_type)
1176
{
1177
  g_return_if_fail (GTK_IS_STYLE (style));
1178 1179
  g_return_if_fail (window != NULL);
  
1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205
  GTK_STYLE_GET_CLASS (style)->set_background (style, window, state_type);
}

/* Default functions */
static GtkStyle *
gtk_style_real_clone (GtkStyle *style)
{
  return GTK_STYLE (g_object_new (G_OBJECT_TYPE (style), NULL));
}

static void
gtk_style_real_copy (GtkStyle *style,
		     GtkStyle *src)
{
  gint i;
  
  for (i = 0; i < 5; i++)
    {
      style->fg[i] = src->fg[i];
      style->bg[i] = src->bg[i];
      style->text[i] = src->text[i];
      style->base[i] = src->base[i];
      
      style->bg_pixmap[i] = src->bg_pixmap[i];
    }

1206 1207 1208 1209 1210
  if (style->private_font)
    gdk_font_unref (style->private_font);
  style->private_font = src->private_font;
  if (style->private_font)
    gdk_font_ref (style->private_font);