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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073 | /* CTK - The GIMP Toolkit
* Copyright (C) 2011 Red Hat, Inc.
*
* 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, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include "ctkcssenumvalueprivate.h"
#include "ctkcssstyleprivate.h"
#include "ctkcssnumbervalueprivate.h"
#include "ctkstyleproviderprivate.h"
#include "ctksettingsprivate.h"
/* repeated API */
struct _CtkCssValue {
CTK_CSS_VALUE_BASE
int value;
const char *name;
};
static void
ctk_css_value_enum_free (CtkCssValue *value)
{
g_slice_free (CtkCssValue, value);
}
static CtkCssValue *
ctk_css_value_enum_compute (CtkCssValue *value,
guint property_id G_GNUC_UNUSED,
CtkStyleProviderPrivate *provider G_GNUC_UNUSED,
CtkCssStyle *style G_GNUC_UNUSED,
CtkCssStyle *parent_style G_GNUC_UNUSED)
{
return _ctk_css_value_ref (value);
}
static gboolean
ctk_css_value_enum_equal (const CtkCssValue *enum1,
const CtkCssValue *enum2)
{
return enum1 == enum2;
}
static CtkCssValue *
ctk_css_value_enum_transition (CtkCssValue *start G_GNUC_UNUSED,
CtkCssValue *end G_GNUC_UNUSED,
guint property_id G_GNUC_UNUSED,
double progress G_GNUC_UNUSED)
{
return NULL;
}
static void
ctk_css_value_enum_print (const CtkCssValue *value,
GString *string)
{
g_string_append (string, value->name);
}
/* CtkBorderStyle */
static const CtkCssValueClass CTK_CSS_VALUE_BORDER_STYLE = {
ctk_css_value_enum_free,
ctk_css_value_enum_compute,
ctk_css_value_enum_equal,
ctk_css_value_enum_transition,
ctk_css_value_enum_print
};
static CtkCssValue border_style_values[] = {
{ &CTK_CSS_VALUE_BORDER_STYLE, 1, CTK_BORDER_STYLE_NONE, "none" },
{ &CTK_CSS_VALUE_BORDER_STYLE, 1, CTK_BORDER_STYLE_SOLID, "solid" },
{ &CTK_CSS_VALUE_BORDER_STYLE, 1, CTK_BORDER_STYLE_INSET, "inset" },
{ &CTK_CSS_VALUE_BORDER_STYLE, 1, CTK_BORDER_STYLE_OUTSET, "outset" },
{ &CTK_CSS_VALUE_BORDER_STYLE, 1, CTK_BORDER_STYLE_HIDDEN, "hidden" },
{ &CTK_CSS_VALUE_BORDER_STYLE, 1, CTK_BORDER_STYLE_DOTTED, "dotted" },
{ &CTK_CSS_VALUE_BORDER_STYLE, 1, CTK_BORDER_STYLE_DASHED, "dashed" },
{ &CTK_CSS_VALUE_BORDER_STYLE, 1, CTK_BORDER_STYLE_DOUBLE, "double" },
{ &CTK_CSS_VALUE_BORDER_STYLE, 1, CTK_BORDER_STYLE_GROOVE, "groove" },
{ &CTK_CSS_VALUE_BORDER_STYLE, 1, CTK_BORDER_STYLE_RIDGE, "ridge" }
};
CtkCssValue *
_ctk_css_border_style_value_new (CtkBorderStyle border_style)
{
g_return_val_if_fail (border_style < G_N_ELEMENTS (border_style_values), NULL);
return _ctk_css_value_ref (&border_style_values[border_style]);
}
CtkCssValue *
_ctk_css_border_style_value_try_parse (CtkCssParser *parser)
{
guint i;
g_return_val_if_fail (parser != NULL, NULL);
for (i = 0; i < G_N_ELEMENTS (border_style_values); i++)
{
if (_ctk_css_parser_try (parser, border_style_values[i].name, TRUE))
return _ctk_css_value_ref (&border_style_values[i]);
}
return NULL;
}
CtkBorderStyle
_ctk_css_border_style_value_get (const CtkCssValue *value)
{
g_return_val_if_fail (value->class == &CTK_CSS_VALUE_BORDER_STYLE, CTK_BORDER_STYLE_NONE);
return value->value;
}
/* CtkCssBlendMode */
static const CtkCssValueClass CTK_CSS_VALUE_BLEND_MODE = {
ctk_css_value_enum_free,
ctk_css_value_enum_compute,
ctk_css_value_enum_equal,
ctk_css_value_enum_transition,
ctk_css_value_enum_print
};
static CtkCssValue blend_mode_values[] = {
{ &CTK_CSS_VALUE_BLEND_MODE, 1, CTK_CSS_BLEND_MODE_COLOR_BURN, "color-burn" },
{ &CTK_CSS_VALUE_BLEND_MODE, 1, CTK_CSS_BLEND_MODE_COLOR_DODGE, "color-dodge" },
{ &CTK_CSS_VALUE_BLEND_MODE, 1, CTK_CSS_BLEND_MODE_COLOR, "color" },
{ &CTK_CSS_VALUE_BLEND_MODE, 1, CTK_CSS_BLEND_MODE_DARKEN, "darken" },
{ &CTK_CSS_VALUE_BLEND_MODE, 1, CTK_CSS_BLEND_MODE_DIFFERENCE, "difference" },
{ &CTK_CSS_VALUE_BLEND_MODE, 1, CTK_CSS_BLEND_MODE_EXCLUSION, "exclusion" },
{ &CTK_CSS_VALUE_BLEND_MODE, 1, CTK_CSS_BLEND_MODE_HARD_LIGHT, "hard-light" },
{ &CTK_CSS_VALUE_BLEND_MODE, 1, CTK_CSS_BLEND_MODE_HUE, "hue" },
{ &CTK_CSS_VALUE_BLEND_MODE, 1, CTK_CSS_BLEND_MODE_LIGHTEN, "lighten" },
{ &CTK_CSS_VALUE_BLEND_MODE, 1, CTK_CSS_BLEND_MODE_LUMINOSITY, "luminosity" },
{ &CTK_CSS_VALUE_BLEND_MODE, 1, CTK_CSS_BLEND_MODE_MULTIPLY, "multiply" },
{ &CTK_CSS_VALUE_BLEND_MODE, 1, CTK_CSS_BLEND_MODE_NORMAL, "normal" },
{ &CTK_CSS_VALUE_BLEND_MODE, 1, CTK_CSS_BLEND_MODE_OVERLAY, "overlay" },
{ &CTK_CSS_VALUE_BLEND_MODE, 1, CTK_CSS_BLEND_MODE_SATURATE, "saturate" },
{ &CTK_CSS_VALUE_BLEND_MODE, 1, CTK_CSS_BLEND_MODE_SCREEN, "screen" },
{ &CTK_CSS_VALUE_BLEND_MODE, 1, CTK_CSS_BLEND_MODE_SOFT_LIGHT, "soft-light" }
};
CtkCssValue *
_ctk_css_blend_mode_value_new (CtkCssBlendMode blend_mode)
{
g_return_val_if_fail (blend_mode < G_N_ELEMENTS (blend_mode_values), NULL);
return _ctk_css_value_ref (&blend_mode_values[blend_mode]);
}
CtkCssValue *
_ctk_css_blend_mode_value_try_parse (CtkCssParser *parser)
{
guint i;
g_return_val_if_fail (parser != NULL, NULL);
for (i = 0; i < G_N_ELEMENTS (blend_mode_values); i++)
{
if (_ctk_css_parser_try (parser, blend_mode_values[i].name, TRUE))
return _ctk_css_value_ref (&blend_mode_values[i]);
}
return NULL;
}
CtkCssBlendMode
_ctk_css_blend_mode_value_get (const CtkCssValue *value)
{
g_return_val_if_fail (value->class == &CTK_CSS_VALUE_BLEND_MODE, CTK_CSS_BLEND_MODE_NORMAL);
return value->value;
}
/* CtkCssFontSize */
static double
get_dpi (CtkCssStyle *style)
{
return _ctk_css_number_value_get (ctk_css_style_get_value (style, CTK_CSS_PROPERTY_DPI), 96);
}
/* XXX: Kinda bad to have that machinery here, nobody expects vital font
* size code to appear in ctkcssvalueenum.c.
*/
#define DEFAULT_FONT_SIZE_PT 10
double
ctk_css_font_size_get_default_px (CtkStyleProviderPrivate *provider,
CtkCssStyle *style)
{
CtkSettings *settings;
int font_size;
settings = _ctk_style_provider_private_get_settings (provider);
if (settings == NULL)
return DEFAULT_FONT_SIZE_PT * get_dpi (style) / 72.0;
font_size = ctk_settings_get_font_size (settings);
if (font_size == 0)
return DEFAULT_FONT_SIZE_PT * get_dpi (style) / 72.0;
else if (ctk_settings_get_font_size_is_absolute (settings))
return (double) font_size / PANGO_SCALE;
else
return ((double) font_size / PANGO_SCALE) * get_dpi (style) / 72.0;
}
static CtkCssValue *
ctk_css_value_font_size_compute (CtkCssValue *value,<--- Parameter 'value' can be declared as pointer to const
guint property_id G_GNUC_UNUSED,
CtkStyleProviderPrivate *provider,
CtkCssStyle *style,
CtkCssStyle *parent_style)
{
double font_size;
switch (value->value)
{
case CTK_CSS_FONT_SIZE_XX_SMALL:
font_size = ctk_css_font_size_get_default_px (provider, style) * 3. / 5;
break;
case CTK_CSS_FONT_SIZE_X_SMALL:
font_size = ctk_css_font_size_get_default_px (provider, style) * 3. / 4;
break;
case CTK_CSS_FONT_SIZE_SMALL:
font_size = ctk_css_font_size_get_default_px (provider, style) * 8. / 9;
break;
default:
g_assert_not_reached ();
/* fall thru */
case CTK_CSS_FONT_SIZE_MEDIUM:
font_size = ctk_css_font_size_get_default_px (provider, style);
break;
case CTK_CSS_FONT_SIZE_LARGE:
font_size = ctk_css_font_size_get_default_px (provider, style) * 6. / 5;
break;
case CTK_CSS_FONT_SIZE_X_LARGE:
font_size = ctk_css_font_size_get_default_px (provider, style) * 3. / 2;
break;
case CTK_CSS_FONT_SIZE_XX_LARGE:
font_size = ctk_css_font_size_get_default_px (provider, style) * 2;
break;
case CTK_CSS_FONT_SIZE_SMALLER:
if (parent_style)
font_size = _ctk_css_number_value_get (ctk_css_style_get_value (parent_style, CTK_CSS_PROPERTY_FONT_SIZE), 100);
else
font_size = ctk_css_font_size_get_default_px (provider, style);
/* XXX: This is what WebKit does... */
font_size /= 1.2;
break;
case CTK_CSS_FONT_SIZE_LARGER:
if (parent_style)
font_size = _ctk_css_number_value_get (ctk_css_style_get_value (parent_style, CTK_CSS_PROPERTY_FONT_SIZE), 100);
else
font_size = ctk_css_font_size_get_default_px (provider, style);
/* XXX: This is what WebKit does... */
font_size *= 1.2;
break;
}
return _ctk_css_number_value_new (font_size, CTK_CSS_PX);
}
static const CtkCssValueClass CTK_CSS_VALUE_FONT_SIZE = {
ctk_css_value_enum_free,
ctk_css_value_font_size_compute,<--- You might need to cast the function pointer here
ctk_css_value_enum_equal,
ctk_css_value_enum_transition,
ctk_css_value_enum_print
};
static CtkCssValue font_size_values[] = {
{ &CTK_CSS_VALUE_FONT_SIZE, 1, CTK_CSS_FONT_SIZE_SMALLER, "smaller" },
{ &CTK_CSS_VALUE_FONT_SIZE, 1, CTK_CSS_FONT_SIZE_LARGER, "larger" },
{ &CTK_CSS_VALUE_FONT_SIZE, 1, CTK_CSS_FONT_SIZE_XX_SMALL, "xx-small" },
{ &CTK_CSS_VALUE_FONT_SIZE, 1, CTK_CSS_FONT_SIZE_X_SMALL, "x-small" },
{ &CTK_CSS_VALUE_FONT_SIZE, 1, CTK_CSS_FONT_SIZE_SMALL, "small" },
{ &CTK_CSS_VALUE_FONT_SIZE, 1, CTK_CSS_FONT_SIZE_MEDIUM, "medium" },
{ &CTK_CSS_VALUE_FONT_SIZE, 1, CTK_CSS_FONT_SIZE_LARGE, "large" },
{ &CTK_CSS_VALUE_FONT_SIZE, 1, CTK_CSS_FONT_SIZE_X_LARGE, "x-large" },
{ &CTK_CSS_VALUE_FONT_SIZE, 1, CTK_CSS_FONT_SIZE_XX_LARGE, "xx-large" }
};
CtkCssValue *
_ctk_css_font_size_value_new (CtkCssFontSize font_size)
{
g_return_val_if_fail (font_size < G_N_ELEMENTS (font_size_values), NULL);
return _ctk_css_value_ref (&font_size_values[font_size]);
}
CtkCssValue *
_ctk_css_font_size_value_try_parse (CtkCssParser *parser)
{
guint i;
g_return_val_if_fail (parser != NULL, NULL);
for (i = 0; i < G_N_ELEMENTS (font_size_values); i++)
{
if (_ctk_css_parser_try (parser, font_size_values[i].name, TRUE))
return _ctk_css_value_ref (&font_size_values[i]);
}
return NULL;
}
CtkCssFontSize
_ctk_css_font_size_value_get (const CtkCssValue *value)
{
g_return_val_if_fail (value->class == &CTK_CSS_VALUE_FONT_SIZE, CTK_CSS_FONT_SIZE_MEDIUM);
return value->value;
}
/* PangoStyle */
static const CtkCssValueClass CTK_CSS_VALUE_FONT_STYLE = {
ctk_css_value_enum_free,
ctk_css_value_enum_compute,
ctk_css_value_enum_equal,
ctk_css_value_enum_transition,
ctk_css_value_enum_print
};
static CtkCssValue font_style_values[] = {
{ &CTK_CSS_VALUE_FONT_STYLE, 1, PANGO_STYLE_NORMAL, "normal" },
{ &CTK_CSS_VALUE_FONT_STYLE, 1, PANGO_STYLE_OBLIQUE, "oblique" },
{ &CTK_CSS_VALUE_FONT_STYLE, 1, PANGO_STYLE_ITALIC, "italic" }
};
CtkCssValue *
_ctk_css_font_style_value_new (PangoStyle font_style)
{
g_return_val_if_fail (font_style < G_N_ELEMENTS (font_style_values), NULL);
return _ctk_css_value_ref (&font_style_values[font_style]);
}
CtkCssValue *
_ctk_css_font_style_value_try_parse (CtkCssParser *parser)
{
guint i;
g_return_val_if_fail (parser != NULL, NULL);
for (i = 0; i < G_N_ELEMENTS (font_style_values); i++)
{
if (_ctk_css_parser_try (parser, font_style_values[i].name, TRUE))
return _ctk_css_value_ref (&font_style_values[i]);
}
return NULL;
}
PangoStyle
_ctk_css_font_style_value_get (const CtkCssValue *value)
{
g_return_val_if_fail (value->class == &CTK_CSS_VALUE_FONT_STYLE, PANGO_STYLE_NORMAL);
return value->value;
}
/* PangoVariant */
static const CtkCssValueClass CTK_CSS_VALUE_FONT_VARIANT = {
ctk_css_value_enum_free,
ctk_css_value_enum_compute,
ctk_css_value_enum_equal,
ctk_css_value_enum_transition,
ctk_css_value_enum_print
};
static CtkCssValue font_variant_values[] = {
{ &CTK_CSS_VALUE_FONT_VARIANT, 1, PANGO_VARIANT_NORMAL, "normal" },
{ &CTK_CSS_VALUE_FONT_VARIANT, 1, PANGO_VARIANT_SMALL_CAPS, "small-caps" }
};
CtkCssValue *
_ctk_css_font_variant_value_new (PangoVariant font_variant)
{
g_return_val_if_fail ((gint)font_variant < G_N_ELEMENTS (font_variant_values), NULL);
return _ctk_css_value_ref (&font_variant_values[font_variant]);
}
CtkCssValue *
_ctk_css_font_variant_value_try_parse (CtkCssParser *parser)
{
guint i;
g_return_val_if_fail (parser != NULL, NULL);
for (i = 0; i < G_N_ELEMENTS (font_variant_values); i++)
{
if (_ctk_css_parser_try (parser, font_variant_values[i].name, TRUE))
return _ctk_css_value_ref (&font_variant_values[i]);
}
return NULL;
}
PangoVariant
_ctk_css_font_variant_value_get (const CtkCssValue *value)
{
g_return_val_if_fail (value->class == &CTK_CSS_VALUE_FONT_VARIANT, PANGO_VARIANT_NORMAL);
return value->value;
}
/* PangoWeight */
#define BOLDER -1
#define LIGHTER -2
static CtkCssValue *
ctk_css_value_font_weight_compute (CtkCssValue *value,
guint property_id,
CtkStyleProviderPrivate *provider G_GNUC_UNUSED,
CtkCssStyle *style G_GNUC_UNUSED,
CtkCssStyle *parent_style)
{
PangoWeight new_weight;
int parent_value;
if (value->value >= 0)
return _ctk_css_value_ref (value);
if (parent_style)
parent_value = ctk_css_style_get_value (parent_style, property_id)->value;
else
parent_value = 400;
if (value->value == BOLDER)
{
if (parent_value < 400)
new_weight = PANGO_WEIGHT_NORMAL;
else if (parent_value < 600)
new_weight = PANGO_WEIGHT_BOLD;
else
new_weight = PANGO_WEIGHT_HEAVY;
}
else if (value->value == LIGHTER)
{
if (parent_value > 700)
new_weight = PANGO_WEIGHT_BOLD;
else if (parent_value > 500)
new_weight = PANGO_WEIGHT_NORMAL;
else
new_weight = PANGO_WEIGHT_THIN;
}
else
{
g_assert_not_reached ();
new_weight = PANGO_WEIGHT_NORMAL;
}
return _ctk_css_font_weight_value_new (new_weight);
}
static CtkCssValue *
ctk_css_value_font_weight_transition (CtkCssValue *start,<--- Parameter 'start' can be declared as pointer to const
CtkCssValue *end,<--- Parameter 'end' can be declared as pointer to const
guint property_id G_GNUC_UNUSED,
double progress G_GNUC_UNUSED)
{
PangoWeight new_weight;
if (start->value < 0 || end->value < 0)
return NULL;
new_weight = (start->value + end->value + 50) / 200 * 100;
return _ctk_css_font_weight_value_new (new_weight);
}
static const CtkCssValueClass CTK_CSS_VALUE_FONT_WEIGHT = {
ctk_css_value_enum_free,
ctk_css_value_font_weight_compute,
ctk_css_value_enum_equal,
ctk_css_value_font_weight_transition,<--- You might need to cast the function pointer here<--- You might need to cast the function pointer here
ctk_css_value_enum_print
};
static CtkCssValue font_weight_values[] = {
{ &CTK_CSS_VALUE_FONT_WEIGHT, 1, BOLDER, "bolder" },
{ &CTK_CSS_VALUE_FONT_WEIGHT, 1, LIGHTER, "lighter" },
{ &CTK_CSS_VALUE_FONT_WEIGHT, 1, PANGO_WEIGHT_THIN, "100" },
{ &CTK_CSS_VALUE_FONT_WEIGHT, 1, PANGO_WEIGHT_ULTRALIGHT, "200" },
{ &CTK_CSS_VALUE_FONT_WEIGHT, 1, PANGO_WEIGHT_LIGHT, "300" },
{ &CTK_CSS_VALUE_FONT_WEIGHT, 1, PANGO_WEIGHT_NORMAL, "normal" },
{ &CTK_CSS_VALUE_FONT_WEIGHT, 1, PANGO_WEIGHT_MEDIUM, "500" },
{ &CTK_CSS_VALUE_FONT_WEIGHT, 1, PANGO_WEIGHT_SEMIBOLD, "600" },
{ &CTK_CSS_VALUE_FONT_WEIGHT, 1, PANGO_WEIGHT_BOLD, "bold" },
{ &CTK_CSS_VALUE_FONT_WEIGHT, 1, PANGO_WEIGHT_ULTRABOLD, "800" },
{ &CTK_CSS_VALUE_FONT_WEIGHT, 1, PANGO_WEIGHT_HEAVY, "900" },
{ &CTK_CSS_VALUE_FONT_WEIGHT, 1, PANGO_WEIGHT_ULTRAHEAVY, "1000" }
};
CtkCssValue *
_ctk_css_font_weight_value_new (PangoWeight font_weight)
{
guint i;
gint w;
w = ((font_weight + 50) / 100) * 100;
for (i = 2; i < G_N_ELEMENTS (font_weight_values); i++)
{
if (font_weight_values[i].value == w)
return _ctk_css_value_ref (&font_weight_values[i]);
}
g_return_val_if_reached (NULL);
}
CtkCssValue *
_ctk_css_font_weight_value_try_parse (CtkCssParser *parser)
{
guint i;
g_return_val_if_fail (parser != NULL, NULL);
for (i = 0; i < G_N_ELEMENTS (font_weight_values); i++)
{
if (_ctk_css_parser_try (parser, font_weight_values[i].name, TRUE))
return _ctk_css_value_ref (&font_weight_values[i]);
}
/* special cases go here */
if (_ctk_css_parser_try (parser, "400", TRUE))
return _ctk_css_value_ref (&font_weight_values[5]);
if (_ctk_css_parser_try (parser, "700", TRUE))
return _ctk_css_value_ref (&font_weight_values[8]);
return NULL;
}
PangoWeight
_ctk_css_font_weight_value_get (const CtkCssValue *value)
{
g_return_val_if_fail (value->class == &CTK_CSS_VALUE_FONT_WEIGHT, PANGO_WEIGHT_NORMAL);
return value->value;
}
#undef BOLDER
#undef LIGHTER
/* PangoStretch */
static const CtkCssValueClass CTK_CSS_VALUE_FONT_STRETCH = {
ctk_css_value_enum_free,
ctk_css_value_enum_compute,
ctk_css_value_enum_equal,
ctk_css_value_enum_transition,
ctk_css_value_enum_print
};
static CtkCssValue font_stretch_values[] = {
{ &CTK_CSS_VALUE_FONT_STRETCH, 1, PANGO_STRETCH_ULTRA_CONDENSED, "ultra-condensed" },
{ &CTK_CSS_VALUE_FONT_STRETCH, 1, PANGO_STRETCH_EXTRA_CONDENSED, "extra-condensed" },
{ &CTK_CSS_VALUE_FONT_STRETCH, 1, PANGO_STRETCH_CONDENSED, "condensed" },
{ &CTK_CSS_VALUE_FONT_STRETCH, 1, PANGO_STRETCH_SEMI_CONDENSED, "semi-condensed" },
{ &CTK_CSS_VALUE_FONT_STRETCH, 1, PANGO_STRETCH_NORMAL, "normal" },
{ &CTK_CSS_VALUE_FONT_STRETCH, 1, PANGO_STRETCH_SEMI_EXPANDED, "semi-expanded" },
{ &CTK_CSS_VALUE_FONT_STRETCH, 1, PANGO_STRETCH_EXPANDED, "expanded" },
{ &CTK_CSS_VALUE_FONT_STRETCH, 1, PANGO_STRETCH_EXTRA_EXPANDED, "extra-expanded" },
{ &CTK_CSS_VALUE_FONT_STRETCH, 1, PANGO_STRETCH_ULTRA_EXPANDED, "ultra-expanded" },
};
CtkCssValue *
_ctk_css_font_stretch_value_new (PangoStretch font_stretch)
{
g_return_val_if_fail (font_stretch < G_N_ELEMENTS (font_stretch_values), NULL);
return _ctk_css_value_ref (&font_stretch_values[font_stretch]);
}
CtkCssValue *
_ctk_css_font_stretch_value_try_parse (CtkCssParser *parser)
{
guint i;
g_return_val_if_fail (parser != NULL, NULL);
for (i = 0; i < G_N_ELEMENTS (font_stretch_values); i++)
{
if (_ctk_css_parser_try (parser, font_stretch_values[i].name, TRUE))
return _ctk_css_value_ref (&font_stretch_values[i]);
}
return NULL;
}
PangoStretch
_ctk_css_font_stretch_value_get (const CtkCssValue *value)
{
g_return_val_if_fail (value->class == &CTK_CSS_VALUE_FONT_STRETCH, PANGO_STRETCH_NORMAL);
return value->value;
}
/* CtkTextDecorationLine */
static const CtkCssValueClass CTK_CSS_VALUE_TEXT_DECORATION_LINE = {
ctk_css_value_enum_free,
ctk_css_value_enum_compute,
ctk_css_value_enum_equal,
ctk_css_value_enum_transition,
ctk_css_value_enum_print
};
static CtkCssValue text_decoration_line_values[] = {
{ &CTK_CSS_VALUE_TEXT_DECORATION_LINE, 1, CTK_CSS_TEXT_DECORATION_LINE_NONE, "none" },
{ &CTK_CSS_VALUE_TEXT_DECORATION_LINE, 1, CTK_CSS_TEXT_DECORATION_LINE_UNDERLINE, "underline" },
{ &CTK_CSS_VALUE_TEXT_DECORATION_LINE, 1, CTK_CSS_TEXT_DECORATION_LINE_LINE_THROUGH, "line-through" },
};
CtkCssValue *
_ctk_css_text_decoration_line_value_new (CtkTextDecorationLine line)
{
g_return_val_if_fail (line < G_N_ELEMENTS (text_decoration_line_values), NULL);
return _ctk_css_value_ref (&text_decoration_line_values[line]);
}
CtkCssValue *
_ctk_css_text_decoration_line_value_try_parse (CtkCssParser *parser)
{
guint i;
g_return_val_if_fail (parser != NULL, NULL);
for (i = 0; i < G_N_ELEMENTS (text_decoration_line_values); i++)
{
if (_ctk_css_parser_try (parser, text_decoration_line_values[i].name, TRUE))
return _ctk_css_value_ref (&text_decoration_line_values[i]);
}
return NULL;
}
CtkTextDecorationLine
_ctk_css_text_decoration_line_value_get (const CtkCssValue *value)
{
g_return_val_if_fail (value->class == &CTK_CSS_VALUE_TEXT_DECORATION_LINE, CTK_CSS_TEXT_DECORATION_LINE_NONE);
return value->value;
}
/* CtkTextDecorationStyle */
static const CtkCssValueClass CTK_CSS_VALUE_TEXT_DECORATION_STYLE = {
ctk_css_value_enum_free,
ctk_css_value_enum_compute,
ctk_css_value_enum_equal,
ctk_css_value_enum_transition,
ctk_css_value_enum_print
};
static CtkCssValue text_decoration_style_values[] = {
{ &CTK_CSS_VALUE_TEXT_DECORATION_STYLE, 1, CTK_CSS_TEXT_DECORATION_STYLE_SOLID, "solid" },
{ &CTK_CSS_VALUE_TEXT_DECORATION_STYLE, 1, CTK_CSS_TEXT_DECORATION_STYLE_DOUBLE, "double" },
{ &CTK_CSS_VALUE_TEXT_DECORATION_STYLE, 1, CTK_CSS_TEXT_DECORATION_STYLE_WAVY, "wavy" },
};
CtkCssValue *
_ctk_css_text_decoration_style_value_new (CtkTextDecorationStyle style)
{
g_return_val_if_fail (style < G_N_ELEMENTS (text_decoration_style_values), NULL);
return _ctk_css_value_ref (&text_decoration_style_values[style]);
}
CtkCssValue *
_ctk_css_text_decoration_style_value_try_parse (CtkCssParser *parser)
{
guint i;
g_return_val_if_fail (parser != NULL, NULL);
for (i = 0; i < G_N_ELEMENTS (text_decoration_style_values); i++)
{
if (_ctk_css_parser_try (parser, text_decoration_style_values[i].name, TRUE))
return _ctk_css_value_ref (&text_decoration_style_values[i]);
}
return NULL;
}
CtkTextDecorationStyle
_ctk_css_text_decoration_style_value_get (const CtkCssValue *value)
{
g_return_val_if_fail (value->class == &CTK_CSS_VALUE_TEXT_DECORATION_STYLE, CTK_CSS_TEXT_DECORATION_STYLE_SOLID);
return value->value;
}
/* CtkCssArea */
static const CtkCssValueClass CTK_CSS_VALUE_AREA = {
ctk_css_value_enum_free,
ctk_css_value_enum_compute,
ctk_css_value_enum_equal,
ctk_css_value_enum_transition,
ctk_css_value_enum_print
};
static CtkCssValue area_values[] = {
{ &CTK_CSS_VALUE_AREA, 1, CTK_CSS_AREA_BORDER_BOX, "border-box" },
{ &CTK_CSS_VALUE_AREA, 1, CTK_CSS_AREA_PADDING_BOX, "padding-box" },
{ &CTK_CSS_VALUE_AREA, 1, CTK_CSS_AREA_CONTENT_BOX, "content-box" }
};
CtkCssValue *
_ctk_css_area_value_new (CtkCssArea area)
{
guint i;
for (i = 0; i < G_N_ELEMENTS (area_values); i++)
{
if (area_values[i].value == area)
return _ctk_css_value_ref (&area_values[i]);
}
g_return_val_if_reached (NULL);
}
CtkCssValue *
_ctk_css_area_value_try_parse (CtkCssParser *parser)
{
guint i;
g_return_val_if_fail (parser != NULL, NULL);
for (i = 0; i < G_N_ELEMENTS (area_values); i++)
{
if (_ctk_css_parser_try (parser, area_values[i].name, TRUE))
return _ctk_css_value_ref (&area_values[i]);
}
return NULL;
}
CtkCssArea
_ctk_css_area_value_get (const CtkCssValue *value)
{
g_return_val_if_fail (value->class == &CTK_CSS_VALUE_AREA, CTK_CSS_AREA_BORDER_BOX);
return value->value;
}
/* CtkCssDirection */
static const CtkCssValueClass CTK_CSS_VALUE_DIRECTION = {
ctk_css_value_enum_free,
ctk_css_value_enum_compute,
ctk_css_value_enum_equal,
ctk_css_value_enum_transition,
ctk_css_value_enum_print
};
static CtkCssValue direction_values[] = {
{ &CTK_CSS_VALUE_DIRECTION, 1, CTK_CSS_DIRECTION_NORMAL, "normal" },
{ &CTK_CSS_VALUE_DIRECTION, 1, CTK_CSS_DIRECTION_REVERSE, "reverse" },
{ &CTK_CSS_VALUE_DIRECTION, 1, CTK_CSS_DIRECTION_ALTERNATE, "alternate" },
{ &CTK_CSS_VALUE_DIRECTION, 1, CTK_CSS_DIRECTION_ALTERNATE_REVERSE, "alternate-reverse" }
};
CtkCssValue *
_ctk_css_direction_value_new (CtkCssDirection direction)
{
guint i;
for (i = 0; i < G_N_ELEMENTS (direction_values); i++)
{
if (direction_values[i].value == direction)
return _ctk_css_value_ref (&direction_values[i]);
}
g_return_val_if_reached (NULL);
}
CtkCssValue *
_ctk_css_direction_value_try_parse (CtkCssParser *parser)
{
int i;
g_return_val_if_fail (parser != NULL, NULL);
/* need to parse backwards here, otherwise "alternate" will also match "alternate-reverse".
* Our parser rocks!
*/
for (i = G_N_ELEMENTS (direction_values) - 1; i >= 0; i--)
{
if (_ctk_css_parser_try (parser, direction_values[i].name, TRUE))
return _ctk_css_value_ref (&direction_values[i]);
}
return NULL;
}
CtkCssDirection
_ctk_css_direction_value_get (const CtkCssValue *value)
{
g_return_val_if_fail (value->class == &CTK_CSS_VALUE_DIRECTION, CTK_CSS_DIRECTION_NORMAL);
return value->value;
}
/* CtkCssPlayState */
static const CtkCssValueClass CTK_CSS_VALUE_PLAY_STATE = {
ctk_css_value_enum_free,
ctk_css_value_enum_compute,
ctk_css_value_enum_equal,
ctk_css_value_enum_transition,
ctk_css_value_enum_print
};
static CtkCssValue play_state_values[] = {
{ &CTK_CSS_VALUE_PLAY_STATE, 1, CTK_CSS_PLAY_STATE_RUNNING, "running" },
{ &CTK_CSS_VALUE_PLAY_STATE, 1, CTK_CSS_PLAY_STATE_PAUSED, "paused" }
};
CtkCssValue *
_ctk_css_play_state_value_new (CtkCssPlayState play_state)
{
guint i;
for (i = 0; i < G_N_ELEMENTS (play_state_values); i++)
{
if (play_state_values[i].value == play_state)
return _ctk_css_value_ref (&play_state_values[i]);
}
g_return_val_if_reached (NULL);
}
CtkCssValue *
_ctk_css_play_state_value_try_parse (CtkCssParser *parser)
{
guint i;
g_return_val_if_fail (parser != NULL, NULL);
for (i = 0; i < G_N_ELEMENTS (play_state_values); i++)
{
if (_ctk_css_parser_try (parser, play_state_values[i].name, TRUE))
return _ctk_css_value_ref (&play_state_values[i]);
}
return NULL;
}
CtkCssPlayState
_ctk_css_play_state_value_get (const CtkCssValue *value)
{
g_return_val_if_fail (value->class == &CTK_CSS_VALUE_PLAY_STATE, CTK_CSS_PLAY_STATE_RUNNING);
return value->value;
}
/* CtkCssFillMode */
static const CtkCssValueClass CTK_CSS_VALUE_FILL_MODE = {
ctk_css_value_enum_free,
ctk_css_value_enum_compute,
ctk_css_value_enum_equal,
ctk_css_value_enum_transition,
ctk_css_value_enum_print
};
static CtkCssValue fill_mode_values[] = {
{ &CTK_CSS_VALUE_FILL_MODE, 1, CTK_CSS_FILL_NONE, "none" },
{ &CTK_CSS_VALUE_FILL_MODE, 1, CTK_CSS_FILL_FORWARDS, "forwards" },
{ &CTK_CSS_VALUE_FILL_MODE, 1, CTK_CSS_FILL_BACKWARDS, "backwards" },
{ &CTK_CSS_VALUE_FILL_MODE, 1, CTK_CSS_FILL_BOTH, "both" }
};
CtkCssValue *
_ctk_css_fill_mode_value_new (CtkCssFillMode fill_mode)
{
guint i;
for (i = 0; i < G_N_ELEMENTS (fill_mode_values); i++)
{
if (fill_mode_values[i].value == fill_mode)
return _ctk_css_value_ref (&fill_mode_values[i]);
}
g_return_val_if_reached (NULL);
}
CtkCssValue *
_ctk_css_fill_mode_value_try_parse (CtkCssParser *parser)
{
guint i;
g_return_val_if_fail (parser != NULL, NULL);
for (i = 0; i < G_N_ELEMENTS (fill_mode_values); i++)
{
if (_ctk_css_parser_try (parser, fill_mode_values[i].name, TRUE))
return _ctk_css_value_ref (&fill_mode_values[i]);
}
return NULL;
}
CtkCssFillMode
_ctk_css_fill_mode_value_get (const CtkCssValue *value)
{
g_return_val_if_fail (value->class == &CTK_CSS_VALUE_FILL_MODE, CTK_CSS_FILL_NONE);
return value->value;
}
/* CtkCssIconEffect */
static const CtkCssValueClass CTK_CSS_VALUE_ICON_EFFECT = {
ctk_css_value_enum_free,
ctk_css_value_enum_compute,
ctk_css_value_enum_equal,
ctk_css_value_enum_transition,
ctk_css_value_enum_print
};
static CtkCssValue image_effect_values[] = {
{ &CTK_CSS_VALUE_ICON_EFFECT, 1, CTK_CSS_ICON_EFFECT_NONE, "none" },
{ &CTK_CSS_VALUE_ICON_EFFECT, 1, CTK_CSS_ICON_EFFECT_HIGHLIGHT, "highlight" },
{ &CTK_CSS_VALUE_ICON_EFFECT, 1, CTK_CSS_ICON_EFFECT_DIM, "dim" }
};
CtkCssValue *
_ctk_css_icon_effect_value_new (CtkCssIconEffect image_effect)
{
guint i;
for (i = 0; i < G_N_ELEMENTS (image_effect_values); i++)
{
if (image_effect_values[i].value == image_effect)
return _ctk_css_value_ref (&image_effect_values[i]);
}
g_return_val_if_reached (NULL);
}
CtkCssValue *
_ctk_css_icon_effect_value_try_parse (CtkCssParser *parser)
{
guint i;
g_return_val_if_fail (parser != NULL, NULL);
for (i = 0; i < G_N_ELEMENTS (image_effect_values); i++)
{
if (_ctk_css_parser_try (parser, image_effect_values[i].name, TRUE))
return _ctk_css_value_ref (&image_effect_values[i]);
}
return NULL;
}
CtkCssIconEffect
_ctk_css_icon_effect_value_get (const CtkCssValue *value)
{
g_return_val_if_fail (value->class == &CTK_CSS_VALUE_ICON_EFFECT, CTK_CSS_ICON_EFFECT_NONE);
return value->value;
}
void
ctk_css_icon_effect_apply (CtkCssIconEffect icon_effect,
cairo_surface_t *surface)
{
cairo_t *cr;
switch (icon_effect)
{
case CTK_CSS_ICON_EFFECT_DIM:
cr = cairo_create (surface);
cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
cairo_set_source_rgba (cr, 0, 0, 0, 0); /* transparent */
cairo_paint_with_alpha (cr, 0.5);
cairo_destroy (cr);
break;
case CTK_CSS_ICON_EFFECT_HIGHLIGHT:
cr = cairo_create (surface);
cairo_set_source_rgb (cr, 0.1, 0.1, 0.1);
cairo_set_operator (cr, CAIRO_OPERATOR_COLOR_DODGE);
/* DANGER: We mask with ourself - that works for images, but... */
cairo_mask_surface (cr, surface, 0, 0);
cairo_destroy (cr);
break;
default:
g_warn_if_reached ();
/* fall through */
case CTK_CSS_ICON_EFFECT_NONE:
break;
}
}
/* CtkCssIconStyle */
static const CtkCssValueClass CTK_CSS_VALUE_ICON_STYLE = {
ctk_css_value_enum_free,
ctk_css_value_enum_compute,
ctk_css_value_enum_equal,
ctk_css_value_enum_transition,
ctk_css_value_enum_print
};
static CtkCssValue icon_style_values[] = {
{ &CTK_CSS_VALUE_ICON_STYLE, 1, CTK_CSS_ICON_STYLE_REQUESTED, "requested" },
{ &CTK_CSS_VALUE_ICON_STYLE, 1, CTK_CSS_ICON_STYLE_REGULAR, "regular" },
{ &CTK_CSS_VALUE_ICON_STYLE, 1, CTK_CSS_ICON_STYLE_SYMBOLIC, "symbolic" }
};
CtkCssValue *
_ctk_css_icon_style_value_new (CtkCssIconStyle icon_style)
{
guint i;
for (i = 0; i < G_N_ELEMENTS (icon_style_values); i++)
{
if (icon_style_values[i].value == icon_style)
return _ctk_css_value_ref (&icon_style_values[i]);
}
g_return_val_if_reached (NULL);
}
CtkCssValue *
_ctk_css_icon_style_value_try_parse (CtkCssParser *parser)
{
guint i;
g_return_val_if_fail (parser != NULL, NULL);
for (i = 0; i < G_N_ELEMENTS (icon_style_values); i++)
{
if (_ctk_css_parser_try (parser, icon_style_values[i].name, TRUE))
return _ctk_css_value_ref (&icon_style_values[i]);
}
return NULL;
}
CtkCssIconStyle
_ctk_css_icon_style_value_get (const CtkCssValue *value)
{
g_return_val_if_fail (value->class == &CTK_CSS_VALUE_ICON_STYLE, CTK_CSS_ICON_STYLE_REQUESTED);
return value->value;
}
|