This repository has been archived by the owner on Nov 17, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gtkstyle.c
4071 lines (3571 loc) · 117 KB
/
gtkstyle.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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
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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
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
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
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
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* 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 Lesser 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
/*
* Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
* file for a list of people on the GTK+ Team. See the ChangeLog
* files for a list of changes. These files are distributed with
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
*/
#include "config.h"
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <gobject/gvaluecollector.h>
#include "gtkmarshalers.h"
#include "gtkpango.h"
#include "gtkrc.h"
#include "gtkspinbutton.h"
#include "gtkstyle.h"
#include "gtkstylecontextprivate.h"
#include "gtkwidget.h"
#include "gtkiconfactory.h"
#include "gtkintl.h"
#include "gtkdebug.h"
#include "gtkspinner.h"
#include "gtkborder.h"
/**
* SECTION:gtkstyle
* @Short_description: Deprecated object that holds style information
* for widgets
* @Title: GtkStyle
*
* A #GtkStyle object encapsulates the information that provides the look and
* feel for a widget.
*
* <warning>
* In GTK+ 3.0, GtkStyle has been deprecated and replaced by #GtkStyleContext.
* </warning>
*
* Each #GtkWidget has an associated #GtkStyle object that is used when
* rendering that widget. Also, a #GtkStyle holds information for the five
* possible widget states though not every widget supports all five
* states; see #GtkStateType.
*
* Usually the #GtkStyle for a widget is the same as the default style that
* is set by GTK+ and modified the theme engine.
*
* Usually applications should not need to use or modify the #GtkStyle of
* their widgets.
*/
#define LIGHTNESS_MULT 1.3
#define DARKNESS_MULT 0.7
/* --- typedefs & structures --- */
typedef struct {
GType widget_type;
GParamSpec *pspec;
GValue value;
} PropertyValue;
#define GTK_STYLE_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_STYLE, GtkStylePrivate))
typedef struct _GtkStylePrivate GtkStylePrivate;
struct _GtkStylePrivate {
GtkStyleContext *context;
gulong context_changed_id;
};
enum {
PROP_0,
PROP_CONTEXT
};
/* --- prototypes --- */
static void gtk_style_finalize (GObject *object);
static void gtk_style_constructed (GObject *object);
static void gtk_style_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec);
static void gtk_style_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec);
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);
static GdkPixbuf *gtk_default_render_icon (GtkStyle *style,
const GtkIconSource *source,
GtkTextDirection direction,
GtkStateType state,
GtkIconSize size,
GtkWidget *widget,
const gchar *detail);
static void gtk_default_draw_hline (GtkStyle *style,
cairo_t *cr,
GtkStateType state_type,
GtkWidget *widget,
const gchar *detail,
gint x1,
gint x2,
gint y);
static void gtk_default_draw_vline (GtkStyle *style,
cairo_t *cr,
GtkStateType state_type,
GtkWidget *widget,
const gchar *detail,
gint y1,
gint y2,
gint x);
static void gtk_default_draw_shadow (GtkStyle *style,
cairo_t *cr,
GtkStateType state_type,
GtkShadowType shadow_type,
GtkWidget *widget,
const gchar *detail,
gint x,
gint y,
gint width,
gint height);
static void gtk_default_draw_arrow (GtkStyle *style,
cairo_t *cr,
GtkStateType state_type,
GtkShadowType shadow_type,
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,
cairo_t *cr,
GtkStateType state_type,
GtkShadowType shadow_type,
GtkWidget *widget,
const gchar *detail,
gint x,
gint y,
gint width,
gint height);
static void gtk_default_draw_box (GtkStyle *style,
cairo_t *cr,
GtkStateType state_type,
GtkShadowType shadow_type,
GtkWidget *widget,
const gchar *detail,
gint x,
gint y,
gint width,
gint height);
static void gtk_default_draw_flat_box (GtkStyle *style,
cairo_t *cr,
GtkStateType state_type,
GtkShadowType shadow_type,
GtkWidget *widget,
const gchar *detail,
gint x,
gint y,
gint width,
gint height);
static void gtk_default_draw_check (GtkStyle *style,
cairo_t *cr,
GtkStateType state_type,
GtkShadowType shadow_type,
GtkWidget *widget,
const gchar *detail,
gint x,
gint y,
gint width,
gint height);
static void gtk_default_draw_option (GtkStyle *style,
cairo_t *cr,
GtkStateType state_type,
GtkShadowType shadow_type,
GtkWidget *widget,
const gchar *detail,
gint x,
gint y,
gint width,
gint height);
static void gtk_default_draw_tab (GtkStyle *style,
cairo_t *cr,
GtkStateType state_type,
GtkShadowType shadow_type,
GtkWidget *widget,
const gchar *detail,
gint x,
gint y,
gint width,
gint height);
static void gtk_default_draw_shadow_gap (GtkStyle *style,
cairo_t *cr,
GtkStateType state_type,
GtkShadowType shadow_type,
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,
cairo_t *cr,
GtkStateType state_type,
GtkShadowType shadow_type,
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,
cairo_t *cr,
GtkStateType state_type,
GtkShadowType shadow_type,
GtkWidget *widget,
const gchar *detail,
gint x,
gint y,
gint width,
gint height,
GtkPositionType gap_side);
static void gtk_default_draw_focus (GtkStyle *style,
cairo_t *cr,
GtkStateType state_type,
GtkWidget *widget,
const gchar *detail,
gint x,
gint y,
gint width,
gint height);
static void gtk_default_draw_slider (GtkStyle *style,
cairo_t *cr,
GtkStateType state_type,
GtkShadowType shadow_type,
GtkWidget *widget,
const gchar *detail,
gint x,
gint y,
gint width,
gint height,
GtkOrientation orientation);
static void gtk_default_draw_handle (GtkStyle *style,
cairo_t *cr,
GtkStateType state_type,
GtkShadowType shadow_type,
GtkWidget *widget,
const gchar *detail,
gint x,
gint y,
gint width,
gint height,
GtkOrientation orientation);
static void gtk_default_draw_expander (GtkStyle *style,
cairo_t *cr,
GtkStateType state_type,
GtkWidget *widget,
const gchar *detail,
gint x,
gint y,
GtkExpanderStyle expander_style);
static void gtk_default_draw_layout (GtkStyle *style,
cairo_t *cr,
GtkStateType state_type,
gboolean use_text,
GtkWidget *widget,
const gchar *detail,
gint x,
gint y,
PangoLayout *layout);
static void gtk_default_draw_resize_grip (GtkStyle *style,
cairo_t *cr,
GtkStateType state_type,
GtkWidget *widget,
const gchar *detail,
GdkWindowEdge edge,
gint x,
gint y,
gint width,
gint height);
static void gtk_default_draw_spinner (GtkStyle *style,
cairo_t *cr,
GtkStateType state_type,
GtkWidget *widget,
const gchar *detail,
guint step,
gint x,
gint y,
gint width,
gint height);
static void rgb_to_hls (gdouble *r,
gdouble *g,
gdouble *b);
static void hls_to_rgb (gdouble *h,
gdouble *l,
gdouble *s);
static void transform_detail_string (const gchar *detail,
GtkStyleContext *context);
/*
* Data for default check and radio buttons
*/
static const GtkRequisition default_option_indicator_size = { 7, 13 };
static const GtkBorder default_option_indicator_spacing = { 7, 5, 2, 2 };
#define GTK_GRAY 0xdcdc, 0xdada, 0xd5d5
#define GTK_DARK_GRAY 0xc4c4, 0xc2c2, 0xbdbd
#define GTK_LIGHT_GRAY 0xeeee, 0xebeb, 0xe7e7
#define GTK_WHITE 0xffff, 0xffff, 0xffff
#define GTK_BLUE 0x4b4b, 0x6969, 0x8383
#define GTK_VERY_DARK_GRAY 0x9c9c, 0x9a9a, 0x9494
#define GTK_BLACK 0x0000, 0x0000, 0x0000
#define GTK_WEAK_GRAY 0x7530, 0x7530, 0x7530
/* --- variables --- */
static const GdkColor gtk_default_normal_fg = { 0, GTK_BLACK };
static const GdkColor gtk_default_active_fg = { 0, GTK_BLACK };
static const GdkColor gtk_default_prelight_fg = { 0, GTK_BLACK };
static const GdkColor gtk_default_selected_fg = { 0, GTK_WHITE };
static const GdkColor gtk_default_insensitive_fg = { 0, GTK_WEAK_GRAY };
static const GdkColor gtk_default_normal_bg = { 0, GTK_GRAY };
static const GdkColor gtk_default_active_bg = { 0, GTK_DARK_GRAY };
static const GdkColor gtk_default_prelight_bg = { 0, GTK_LIGHT_GRAY };
static const GdkColor gtk_default_selected_bg = { 0, GTK_BLUE };
static const GdkColor gtk_default_insensitive_bg = { 0, GTK_GRAY };
static const GdkColor gtk_default_selected_base = { 0, GTK_BLUE };
static const GdkColor gtk_default_active_base = { 0, GTK_VERY_DARK_GRAY };
/* --- signals --- */
static guint realize_signal = 0;
static guint unrealize_signal = 0;
G_DEFINE_TYPE (GtkStyle, gtk_style, G_TYPE_OBJECT)
/* --- functions --- */
static void
gtk_style_init (GtkStyle *style)
{
gint i;
style->font_desc = pango_font_description_from_string ("Sans 10");
style->attach_count = 0;
style->black.red = 0;
style->black.green = 0;
style->black.blue = 0;
style->white.red = 65535;
style->white.green = 65535;
style->white.blue = 65535;
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;
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;
for (i = 0; i < 4; i++)
{
style->text[i] = style->fg[i];
style->base[i] = style->white;
}
style->base[GTK_STATE_SELECTED] = gtk_default_selected_base;
style->text[GTK_STATE_SELECTED] = style->white;
style->base[GTK_STATE_ACTIVE] = gtk_default_active_base;
style->text[GTK_STATE_ACTIVE] = style->white;
style->base[GTK_STATE_INSENSITIVE] = gtk_default_prelight_bg;
style->text[GTK_STATE_INSENSITIVE] = gtk_default_insensitive_fg;
style->rc_style = NULL;
style->xthickness = 2;
style->ythickness = 2;
style->property_cache = NULL;
}
static void
gtk_style_class_init (GtkStyleClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->finalize = gtk_style_finalize;
object_class->set_property = gtk_style_set_property;
object_class->get_property = gtk_style_get_property;
object_class->constructed = gtk_style_constructed;
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;
klass->render_icon = gtk_default_render_icon;
klass->draw_hline = gtk_default_draw_hline;
klass->draw_vline = gtk_default_draw_vline;
klass->draw_shadow = gtk_default_draw_shadow;
klass->draw_arrow = gtk_default_draw_arrow;
klass->draw_diamond = gtk_default_draw_diamond;
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;
klass->draw_expander = gtk_default_draw_expander;
klass->draw_layout = gtk_default_draw_layout;
klass->draw_resize_grip = gtk_default_draw_resize_grip;
klass->draw_spinner = gtk_default_draw_spinner;
g_type_class_add_private (object_class, sizeof (GtkStylePrivate));
g_object_class_install_property (object_class,
PROP_CONTEXT,
g_param_spec_object ("context",
P_("Style context"),
P_("GtkStyleContext to get style from"),
GTK_TYPE_STYLE_CONTEXT,
G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE));
/**
* GtkStyle::realize:
* @style: the object which received the signal
*
* Emitted when the style has been initialized for a particular
* visual. Connecting to this signal is probably seldom
* useful since most of the time applications and widgets only
* deal with styles that have been already realized.
*
* Since: 2.4
*/
realize_signal = g_signal_new (I_("realize"),
G_TYPE_FROM_CLASS (object_class),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (GtkStyleClass, realize),
NULL, NULL,
_gtk_marshal_VOID__VOID,
G_TYPE_NONE, 0);
/**
* GtkStyle::unrealize:
* @style: the object which received the signal
*
* Emitted when the aspects of the style specific to a particular visual
* is being cleaned up. A connection to this signal can be useful
* if a widget wants to cache objects as object data on #GtkStyle.
* This signal provides a convenient place to free such cached objects.
*
* Since: 2.4
*/
unrealize_signal = g_signal_new (I_("unrealize"),
G_TYPE_FROM_CLASS (object_class),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (GtkStyleClass, unrealize),
NULL, NULL,
_gtk_marshal_VOID__VOID,
G_TYPE_NONE, 0);
}
static void
gtk_style_finalize (GObject *object)
{
GtkStyle *style = GTK_STYLE (object);
GtkStylePrivate *priv = GTK_STYLE_GET_PRIVATE (style);
gint i;
g_return_if_fail (style->attach_count == 0);
/* All the styles in the list have the same
* style->styles pointer. If we delete the
* *first* style from the list, we need to update
* the style->styles pointers from all the styles.
* Otherwise we simply remove the node from
* the list.
*/
if (style->styles)
{
if (style->styles->data != style)
style->styles = g_slist_remove (style->styles, style);
else
{
GSList *tmp_list = style->styles->next;
while (tmp_list)
{
GTK_STYLE (tmp_list->data)->styles = style->styles->next;
tmp_list = tmp_list->next;
}
g_slist_free_1 (style->styles);
}
}
g_slist_foreach (style->icon_factories, (GFunc) g_object_unref, NULL);
g_slist_free (style->icon_factories);
pango_font_description_free (style->font_desc);
if (style->private_font_desc)
pango_font_description_free (style->private_font_desc);
if (style->rc_style)
g_object_unref (style->rc_style);
if (priv->context)
{
if (priv->context_changed_id)
g_signal_handler_disconnect (priv->context, priv->context_changed_id);
g_object_unref (priv->context);
}
for (i = 0; i < 5; i++)
{
if (style->background[i])
cairo_pattern_destroy (style->background[i]);
}
G_OBJECT_CLASS (gtk_style_parent_class)->finalize (object);
}
static void
gtk_style_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
GtkStylePrivate *priv;
priv = GTK_STYLE_GET_PRIVATE (object);
switch (prop_id)
{
case PROP_CONTEXT:
priv->context = g_value_dup_object (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gtk_style_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
GtkStylePrivate *priv;
priv = GTK_STYLE_GET_PRIVATE (object);
switch (prop_id)
{
case PROP_CONTEXT:
g_value_set_object (value, priv->context);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
set_color (GtkStyle *style,
GtkStyleContext *context,
GtkStateType state,
GtkRcFlags prop)
{
GtkStateFlags flags;
GdkRGBA *color = NULL;
GdkColor *dest = { 0 }; /* Shut up gcc */
switch (state)
{
case GTK_STATE_ACTIVE:
flags = GTK_STATE_FLAG_ACTIVE;
break;
case GTK_STATE_PRELIGHT:
flags = GTK_STATE_FLAG_PRELIGHT;
break;
case GTK_STATE_SELECTED:
flags = GTK_STATE_FLAG_SELECTED;
break;
case GTK_STATE_INSENSITIVE:
flags = GTK_STATE_FLAG_INSENSITIVE;
break;
default:
flags = 0;
}
switch (prop)
{
case GTK_RC_BG:
gtk_style_context_get (context, flags,
"background-color", &color,
NULL);
dest = &style->bg[state];
break;
case GTK_RC_FG:
gtk_style_context_get (context, flags,
"color", &color,
NULL);
dest = &style->fg[state];
break;
case GTK_RC_TEXT:
gtk_style_context_get (context, flags,
"color", &color,
NULL);
dest = &style->text[state];
break;
case GTK_RC_BASE:
gtk_style_context_get (context, flags,
"background-color", &color,
NULL);
dest = &style->base[state];
break;
}
if (color)
{
dest->pixel = 0;
dest->red = CLAMP ((guint) (color->red * 65535), 0, 65535);
dest->green = CLAMP ((guint) (color->green * 65535), 0, 65535);
dest->blue = CLAMP ((guint) (color->blue * 65535), 0, 65535);
gdk_rgba_free (color);
}
}
static void
gtk_style_update_from_context (GtkStyle *style)
{
GtkStylePrivate *priv;
GtkStateType state;
GtkBorder padding;
gint i;
priv = GTK_STYLE_GET_PRIVATE (style);
for (state = GTK_STATE_NORMAL; state <= GTK_STATE_INSENSITIVE; state++)
{
if (gtk_style_context_has_class (priv->context, "entry"))
{
gtk_style_context_save (priv->context);
gtk_style_context_remove_class (priv->context, "entry");
set_color (style, priv->context, state, GTK_RC_BG);
set_color (style, priv->context, state, GTK_RC_FG);
gtk_style_context_restore (priv->context);
set_color (style, priv->context, state, GTK_RC_BASE);
set_color (style, priv->context, state, GTK_RC_TEXT);
}
else
{
gtk_style_context_save (priv->context);
gtk_style_context_add_class (priv->context, "entry");
set_color (style, priv->context, state, GTK_RC_BASE);
set_color (style, priv->context, state, GTK_RC_TEXT);
gtk_style_context_restore (priv->context);
set_color (style, priv->context, state, GTK_RC_BG);
set_color (style, priv->context, state, GTK_RC_FG);
}
}
if (style->font_desc)
pango_font_description_free (style->font_desc);
gtk_style_context_get (priv->context, 0,
"font", &style->font_desc,
NULL);
gtk_style_context_get_padding (priv->context, 0, &padding);
style->xthickness = padding.left;
style->ythickness = padding.top;
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;
style->text_aa[i].red = (style->text[i].red + style->base[i].red) / 2;
style->text_aa[i].green = (style->text[i].green + style->base[i].green) / 2;
style->text_aa[i].blue = (style->text[i].blue + style->base[i].blue) / 2;
}
style->black.red = 0x0000;
style->black.green = 0x0000;
style->black.blue = 0x0000;
style->white.red = 0xffff;
style->white.green = 0xffff;
style->white.blue = 0xffff;
for (i = 0; i < 5; i++)
{
if (style->background[i])
cairo_pattern_destroy (style->background[i]);
style->background[i] = cairo_pattern_create_rgb (style->bg[i].red / 65535.0,
style->bg[i].green / 65535.0,
style->bg[i].blue / 65535.0);
}
}
static void
style_context_changed (GtkStyleContext *context,
gpointer user_data)
{
gtk_style_update_from_context (GTK_STYLE (user_data));
}
static void
gtk_style_constructed (GObject *object)
{
GtkStylePrivate *priv;
priv = GTK_STYLE_GET_PRIVATE (object);
if (priv->context)
{
gtk_style_update_from_context (GTK_STYLE (object));
priv->context_changed_id = g_signal_connect (priv->context, "changed",
G_CALLBACK (style_context_changed), object);
}
}
/**
* gtk_style_copy:
* @style: a #GtkStyle
*
* Creates a copy of the passed in #GtkStyle object.
*
* Returns: (transfer full): a copy of @style
*
* Deprecated:3.0: Use #GtkStyleContext instead
*/
GtkStyle*
gtk_style_copy (GtkStyle *style)
{
GtkStyle *new_style;
g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
new_style = GTK_STYLE_GET_CLASS (style)->clone (style);
GTK_STYLE_GET_CLASS (style)->copy (new_style, style);
return new_style;
}
GtkStyle*
_gtk_style_new_for_path (GdkScreen *screen,
GtkWidgetPath *path)
{
GtkStyleContext *context;
GtkStyle *style;
context = gtk_style_context_new ();
if (screen)
gtk_style_context_set_screen (context, screen);
gtk_style_context_set_path (context, path);
style = g_object_new (GTK_TYPE_STYLE,
"context", context,
NULL);
g_object_unref (context);
return style;
}
/**
* gtk_style_new:
* @returns: a new #GtkStyle.
*
* Creates a new #GtkStyle.
*
* Deprecated: 3.0: Use #GtkStyleContext
**/
GtkStyle*
gtk_style_new (void)
{
GtkWidgetPath *path;
GtkStyle *style;
path = gtk_widget_path_new ();
gtk_widget_path_append_type (path, GTK_TYPE_WIDGET);
style = _gtk_style_new_for_path (gdk_screen_get_default (), path);
gtk_widget_path_free (path);
return style;
}
/**
* gtk_style_has_context:
* @style: a #GtkStyle
*
* Returns whether @style has an associated #GtkStyleContext.
*
* Returns: %TRUE if @style has a #GtkStyleContext
*
* Since: 3.0
*/
gboolean
gtk_style_has_context (GtkStyle *style)
{
GtkStylePrivate *priv;
priv = GTK_STYLE_GET_PRIVATE (style);
return priv->context != NULL;
}
/**
* gtk_style_attach: (skip)
* @style: a #GtkStyle.
* @window: a #GdkWindow.
*
* 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. 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 visual.
*
* Since this function may return a new object, you have to use it
* in the following way:
* <literal>style = gtk_style_attach (style, window)</literal>
*
* Returns: Either @style, or a newly-created #GtkStyle.
* If the style is newly created, the style parameter
* will be unref'ed, and the new style will have
* a reference count belonging to the caller.
*
* Deprecated:3.0: Use gtk_widget_style_attach() instead
*/
GtkStyle*
gtk_style_attach (GtkStyle *style,
GdkWindow *window)
{
g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
g_return_val_if_fail (window != NULL, NULL);
return style;
}
/**
* gtk_style_detach:
* @style: a #GtkStyle
*
* Detaches a style from a window. If the style is not attached
* to any windows anymore, it is unrealized. See gtk_style_attach().
*
* Deprecated:3.0: Use #GtkStyleContext instead
*/
void
gtk_style_detach (GtkStyle *style)
{
g_return_if_fail (GTK_IS_STYLE (style));
}
/**
* gtk_style_lookup_icon_set:
* @style: a #GtkStyle
* @stock_id: an icon name
*
* Looks up @stock_id in the icon factories associated with @style
* and the default icon factory, returning an icon set if found,
* otherwise %NULL.
*
* Return value: (transfer none): icon set of @stock_id
*
* Deprecated:3.0: Use gtk_style_context_lookup_icon_set() instead
*/
GtkIconSet*
gtk_style_lookup_icon_set (GtkStyle *style,
const char *stock_id)
{
GtkStylePrivate *priv;
g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
g_return_val_if_fail (stock_id != NULL, NULL);
priv = GTK_STYLE_GET_PRIVATE (style);
if (priv->context)
return gtk_style_context_lookup_icon_set (priv->context, stock_id);
return gtk_icon_factory_lookup_default (stock_id);
}
/**
* gtk_style_lookup_color:
* @style: a #GtkStyle
* @color_name: the name of the logical color to look up
* @color: (out): the #GdkColor to fill in
*
* Looks up @color_name in the style's logical color mappings,
* filling in @color and returning %TRUE if found, otherwise
* returning %FALSE. Do not cache the found mapping, because
* it depends on the #GtkStyle and might change when a theme
* switch occurs.
*
* Return value: %TRUE if the mapping was found.
*
* Since: 2.10
*
* Deprecated:3.0: Use gtk_style_context_lookup_color() instead
**/
gboolean
gtk_style_lookup_color (GtkStyle *style,
const char *color_name,
GdkColor *color)
{
GtkStylePrivate *priv;
gboolean result;
GdkRGBA rgba;
g_return_val_if_fail (GTK_IS_STYLE (style), FALSE);
g_return_val_if_fail (color_name != NULL, FALSE);
g_return_val_if_fail (color != NULL, FALSE);
priv = GTK_STYLE_GET_PRIVATE (style);
if (!priv->context)
return FALSE;
result = gtk_style_context_lookup_color (priv->context, color_name, &rgba);
if (color)
{
color->red = (guint16) (rgba.red * 65535);
color->green = (guint16) (rgba.green * 65535);
color->blue = (guint16) (rgba.blue * 65535);
color->pixel = 0;
}
return result;
}