2
* enums.cpp: various enumerated types + enum -> str helpers
4
* Copyright 2008 Novell, Inc. (http://www.novell.com)
6
* See the LICENSE file included with the distribution for details.
15
// XXX enums are contained in these headers and should be moved to
21
static GHashTable *enum_map = NULL;
23
#define MAPPING_FLAG_SL1 0x01
24
#define MAPPING_FLAG_SL2 0x02
26
#define MAP_ENUM_FULL(n,v,f) { (n), (v), (f) }
28
// use this when the name is the same as the quoted value
29
#define MAP_NAME(n) MAP_ENUM_FULL(#n, n, 0)
31
// use these when the name is the same as the quoted value, but with the enum type prefixed
32
#define MAP_ENUM(t,n) MAP_ENUM_FULL(#n, t##n, 0)
33
#define MAP_ENUM_SL1(t,n) MAP_ENUM_FULL(#n, t##n, MAPPING_FLAG_SL1)
34
#define MAP_ENUM_SL2(t,n) MAP_ENUM_FULL(#n, t##n, MAPPING_FLAG_SL2)
36
#define END_MAPPING { NULL, 0, 0 }
44
static enum_map_t alignment_x_map [] = {
45
MAP_ENUM (AlignmentX, Left),
46
MAP_ENUM (AlignmentX, Center),
47
MAP_ENUM (AlignmentX, Right),
51
static enum_map_t alignment_y_map [] = {
52
MAP_ENUM (AlignmentY, Top),
53
MAP_ENUM (AlignmentY, Center),
54
MAP_ENUM (AlignmentY, Bottom),
58
static enum_map_t brush_mapping_mode_map [] = {
59
MAP_ENUM (BrushMappingMode, Absolute),
60
MAP_ENUM (BrushMappingMode, RelativeToBoundingBox),
64
static enum_map_t color_interpolation_mode_map [] = {
65
MAP_ENUM (ColorInterpolationMode, ScRgbLinearInterpolation),
66
MAP_ENUM (ColorInterpolationMode, SRgbLinearInterpolation),
70
static enum_map_t cursors_map [] = {
71
MAP_ENUM (MouseCursor, Default),
72
MAP_ENUM (MouseCursor, Arrow),
73
MAP_ENUM (MouseCursor, Hand),
74
MAP_ENUM (MouseCursor, Wait),
75
MAP_ENUM (MouseCursor, IBeam),
76
MAP_ENUM (MouseCursor, Stylus),
77
MAP_ENUM (MouseCursor, Eraser),
78
MAP_ENUM (MouseCursor, None),
82
static enum_map_t error_type_map [] = {
84
MAP_NAME (UnknownError),
85
MAP_NAME (InitializeError),
86
MAP_NAME (ParserError),
87
MAP_NAME (ObjectModelError),
88
MAP_NAME (RuntimeError),
89
MAP_NAME (DownloadError),
90
MAP_NAME (MediaError),
91
MAP_NAME (ImageError),
95
static enum_map_t fill_behavior_map [] = {
96
MAP_ENUM (FillBehavior, HoldEnd),
97
MAP_ENUM (FillBehavior, Stop),
101
static enum_map_t fill_rule_map [] = {
102
MAP_ENUM (FillRule, EvenOdd),
103
MAP_ENUM (FillRule, Nonzero),
107
static enum_map_t font_stretches_map [] = {
108
MAP_ENUM (FontStretches, UltraCondensed),
109
MAP_ENUM (FontStretches, ExtraCondensed),
110
MAP_ENUM (FontStretches, Condensed),
111
MAP_ENUM (FontStretches, SemiCondensed),
112
MAP_ENUM (FontStretches, Normal),
113
MAP_ENUM (FontStretches, Medium),
114
MAP_ENUM (FontStretches, SemiExpanded),
115
MAP_ENUM (FontStretches, Expanded),
116
MAP_ENUM (FontStretches, ExtraExpanded),
117
MAP_ENUM (FontStretches, UltraExpanded),
121
static enum_map_t font_styles_map [] = {
122
MAP_ENUM (FontStyles, Normal),
123
MAP_ENUM (FontStyles, Oblique),
124
MAP_ENUM (FontStyles, Italic),
128
static enum_map_t font_weights_map [] = {
129
MAP_ENUM (FontWeights, Thin),
130
MAP_ENUM (FontWeights, ExtraLight),
131
MAP_ENUM_FULL ("UltraLight", FontWeightsExtraLight,0), // deprecated as of July 2007
132
MAP_ENUM (FontWeights, Light),
133
MAP_ENUM (FontWeights, Normal),
134
MAP_ENUM_FULL ("Regular", FontWeightsNormal,0), // deprecated as of July 2007
135
MAP_ENUM (FontWeights, Medium),
136
MAP_ENUM (FontWeights, SemiBold),
137
MAP_ENUM_FULL ("DemiBold", FontWeightsSemiBold,0), // deprecated as of July 2007
138
MAP_ENUM (FontWeights, Bold),
139
MAP_ENUM (FontWeights, ExtraBold),
140
MAP_ENUM_FULL ("UltraBold", FontWeightsExtraBold,0), // deprecated as of July 2007
141
MAP_ENUM (FontWeights, Black),
142
MAP_ENUM_FULL ("Heavy", FontWeightsBlack,0), // deprecated as of July 2007
143
MAP_ENUM (FontWeights, ExtraBlack),
144
MAP_ENUM_FULL ("UltraBlack", FontWeightsExtraBlack,0), // deprecated as of July 2007
149
static enum_map_t line_stacking_strategy_map [] = {
150
MAP_ENUM_SL2 (LineStackingStrategy, MaxHeight),
151
MAP_ENUM_SL2 (LineStackingStrategy, BlockLineHeight),
157
static enum_map_t horizontal_alignment_map [] = {
158
MAP_ENUM_SL2 (HorizontalAlignment, Left),
159
MAP_ENUM_SL2 (HorizontalAlignment, Center),
160
MAP_ENUM_SL2 (HorizontalAlignment, Right),
161
MAP_ENUM_SL2 (HorizontalAlignment, Stretch),
166
static enum_map_t gradient_spread_method_map [] = {
167
MAP_ENUM (GradientSpreadMethod, Pad),
168
MAP_ENUM (GradientSpreadMethod, Reflect),
169
MAP_ENUM (GradientSpreadMethod, Repeat),
173
static enum_map_t pen_line_cap_map [] = {
174
MAP_ENUM (PenLineCap, Flat),
175
MAP_ENUM (PenLineCap, Square),
176
MAP_ENUM (PenLineCap, Round),
177
MAP_ENUM (PenLineCap, Triangle),
181
static enum_map_t pen_line_join_map [] = {
182
MAP_ENUM (PenLineJoin, Miter),
183
MAP_ENUM (PenLineJoin, Bevel),
184
MAP_ENUM (PenLineJoin, Round),
188
static enum_map_t stretch_map [] = {
189
MAP_ENUM (Stretch, None),
190
MAP_ENUM (Stretch, Fill),
191
MAP_ENUM (Stretch, Uniform),
192
MAP_ENUM (Stretch, UniformToFill),
196
static enum_map_t style_simulations_map [] = {
197
MAP_ENUM (StyleSimulations, None),
201
static enum_map_t sweep_direction_map [] = {
202
MAP_ENUM (SweepDirection, Counterclockwise),
203
MAP_ENUM (SweepDirection, Clockwise),
207
static enum_map_t tablet_device_type_map [] = {
208
MAP_ENUM (TabletDeviceType, Mouse),
209
MAP_ENUM (TabletDeviceType, Stylus),
210
MAP_ENUM (TabletDeviceType, Touch),
215
static enum_map_t text_alignment_map [] = {
216
MAP_ENUM_SL2 (TextAlignment, Center),
217
MAP_ENUM_SL2 (TextAlignment, Left),
218
MAP_ENUM_SL2 (TextAlignment, Right),
223
static enum_map_t text_decorations_map [] = {
224
MAP_ENUM (TextDecorations, None),
225
MAP_ENUM (TextDecorations, Underline),
229
static enum_map_t text_wrapping_map [] = {
230
MAP_ENUM (TextWrapping, Wrap),
231
MAP_ENUM (TextWrapping, NoWrap),
232
MAP_ENUM (TextWrapping, WrapWithOverflow),
237
static enum_map_t scrollbar_visibility_map [] = {
238
MAP_ENUM_SL2 (ScrollBarVisibility, Disabled),
239
MAP_ENUM_SL2 (ScrollBarVisibility, Auto),
240
MAP_ENUM_SL2 (ScrollBarVisibility, Hidden),
241
MAP_ENUM_SL2 (ScrollBarVisibility, Visible),
247
static enum_map_t vertical_alignment_map [] = {
248
MAP_ENUM_SL2 (VerticalAlignment, Top),
249
MAP_ENUM_SL2 (VerticalAlignment, Center),
250
MAP_ENUM_SL2 (VerticalAlignment, Bottom),
251
MAP_ENUM_SL2 (VerticalAlignment, Stretch),
256
static enum_map_t visibility_map [] = {
257
MAP_ENUM (Visibility, Visible),
258
MAP_ENUM (Visibility, Collapsed),
263
static enum_map_t orientation_map [] = {
264
MAP_ENUM_SL2 (Orientation, Vertical),
265
MAP_ENUM_SL2 (Orientation, Horizontal),
269
static enum_map_t cross_domain_access_map [] = {
270
MAP_ENUM_SL2 (CrossDomainAccess, NoAccess),
271
MAP_ENUM_SL2 (CrossDomainAccess, FullAccess),
272
MAP_ENUM_SL2 (CrossDomainAccess, ScriptableOnly),
278
initialize_enums (void)
280
enum_map = g_hash_table_new (g_str_hash, g_str_equal);
282
g_hash_table_insert (enum_map, (char *) "AlignmentX", alignment_x_map);
283
g_hash_table_insert (enum_map, (char *) "AlignmentY", alignment_y_map);
284
g_hash_table_insert (enum_map, (char *) "MappingMode", brush_mapping_mode_map);
285
g_hash_table_insert (enum_map, (char *) "ColorInterpolationMode", color_interpolation_mode_map);
286
g_hash_table_insert (enum_map, (char *) "Cursor", cursors_map);
287
g_hash_table_insert (enum_map, (char *) "ErrorType", error_type_map);
288
g_hash_table_insert (enum_map, (char *) "FillBehavior", fill_behavior_map);
289
g_hash_table_insert (enum_map, (char *) "FillRule", fill_rule_map);
290
g_hash_table_insert (enum_map, (char *) "FontStretch", font_stretches_map);
291
g_hash_table_insert (enum_map, (char *) "FontStyle", font_styles_map);
292
g_hash_table_insert (enum_map, (char *) "FontWeight", font_weights_map);
293
g_hash_table_insert (enum_map, (char *) "SpreadMethod", gradient_spread_method_map);
295
g_hash_table_insert (enum_map, (char *) "StrokeDashCap", pen_line_cap_map);
296
g_hash_table_insert (enum_map, (char *) "StrokeStartLineCap", pen_line_cap_map);
297
g_hash_table_insert (enum_map, (char *) "StrokeEndLineCap", pen_line_cap_map);
299
g_hash_table_insert (enum_map, (char *) "StrokeLineJoin", pen_line_join_map);
300
g_hash_table_insert (enum_map, (char *) "Stretch", stretch_map);
301
g_hash_table_insert (enum_map, (char *) "StyleSimulations", style_simulations_map);
302
g_hash_table_insert (enum_map, (char *) "SweepDirection", sweep_direction_map);
303
g_hash_table_insert (enum_map, (char *) "DeviceType", tablet_device_type_map);
304
g_hash_table_insert (enum_map, (char *) "TextDecorations", text_decorations_map);
305
g_hash_table_insert (enum_map, (char *) "TextWrapping", text_wrapping_map);
306
g_hash_table_insert (enum_map, (char *) "Visibility", visibility_map);
309
g_hash_table_insert (enum_map, (char *) "ExternalCallersFromCrossDomain", cross_domain_access_map);
310
g_hash_table_insert (enum_map, (char *) "HorizontalScrollBarVisibility", scrollbar_visibility_map);
311
g_hash_table_insert (enum_map, (char *) "VerticalScrollBarVisibility", scrollbar_visibility_map);
312
g_hash_table_insert (enum_map, (char *) "LineStackingStrategy", line_stacking_strategy_map);
313
g_hash_table_insert (enum_map, (char *) "HorizontalAlignment", horizontal_alignment_map);
314
g_hash_table_insert (enum_map, (char *) "VerticalAlignment", vertical_alignment_map);
315
g_hash_table_insert (enum_map, (char *) "TextAlignment", text_alignment_map);
316
g_hash_table_insert (enum_map, (char *) "Orientation", orientation_map);
321
enum_from_str (const enum_map_t *emu, const char *str)
324
for (i = 0; emu [i].name; i++) {
325
if (!g_strcasecmp (emu [i].name, str))
326
return emu [i].value;
333
str_from_enum (const enum_map_t *emu, int e, bool sl2)
336
for (i = 0; emu [i].name; i++) {
337
if (emu [i].value == e) {
338
if (emu[i].flags != 0 // 0 means everything
340
((sl2 && ((emu[i].flags & MAPPING_FLAG_SL2) == 0)) ||
341
(!sl2 && ((emu[i].flags & MAPPING_FLAG_SL1) == 0))))
352
// Converts a string representing an enum (ie. "FillEnd") to int.
353
// Returns -1 if no property or enum found.
356
enums_str_to_int (const char *prop_name, const char *str, bool sl2)
358
if (enum_map == NULL)
361
enum_map_t *emu = (enum_map_t *) g_hash_table_lookup (enum_map, prop_name);
365
return enum_from_str (emu, str);
369
// Converts an int enum to a string representation.
370
// Returns NULL if no match found.
373
enums_int_to_str (const char *prop_name, int e, bool sl2)
375
if (enum_map == NULL)
378
enum_map_t *emu = (enum_map_t *) g_hash_table_lookup (enum_map, prop_name);
382
return str_from_enum (emu, e, sl2);