1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * enums.cpp: various enumerated types + enum -> str helpers
5 * Copyright 2008 Novell, Inc. (http://www.novell.com)
7 * See the LICENSE file included with the distribution for details.
17 // XXX enums are contained in these headers and should be moved to
23 static GHashTable
*enum_map
= NULL
;
25 #define MAP_ENUM_FULL(n,v) { (n), (v) }
27 // use this when the name is the same as the quoted value
28 #define MAP_NAME(n) MAP_ENUM_FULL(#n, n)
30 // use these when the name is the same as the quoted value, but with the enum type prefixed
31 #define MAP_ENUM(t,n) MAP_ENUM_FULL(#n, t##n)
33 #define END_MAPPING { NULL, 0 }
40 static enum_map_t alignment_x_map
[] = {
41 MAP_ENUM (AlignmentX
, Left
),
42 MAP_ENUM (AlignmentX
, Center
),
43 MAP_ENUM (AlignmentX
, Right
),
47 static enum_map_t alignment_y_map
[] = {
48 MAP_ENUM (AlignmentY
, Top
),
49 MAP_ENUM (AlignmentY
, Center
),
50 MAP_ENUM (AlignmentY
, Bottom
),
54 static enum_map_t binding_mode_map
[] = {
55 MAP_ENUM (BindingMode
, OneWay
),
56 MAP_ENUM (BindingMode
, OneTime
),
57 MAP_ENUM (BindingMode
, TwoWay
),
61 static enum_map_t brush_mapping_mode_map
[] = {
62 MAP_ENUM (BrushMappingMode
, Absolute
),
63 MAP_ENUM (BrushMappingMode
, RelativeToBoundingBox
),
67 static enum_map_t color_interpolation_mode_map
[] = {
68 MAP_ENUM (ColorInterpolationMode
, ScRgbLinearInterpolation
),
69 MAP_ENUM (ColorInterpolationMode
, SRgbLinearInterpolation
),
73 static enum_map_t cursors_map
[] = {
74 MAP_ENUM (MouseCursor
, Default
),
75 MAP_ENUM (MouseCursor
, Arrow
),
76 MAP_ENUM (MouseCursor
, Hand
),
77 MAP_ENUM (MouseCursor
, Wait
),
78 MAP_ENUM (MouseCursor
, IBeam
),
79 MAP_ENUM (MouseCursor
, Stylus
),
80 MAP_ENUM (MouseCursor
, Eraser
),
81 MAP_ENUM (MouseCursor
, SizeNS
),
82 MAP_ENUM (MouseCursor
, SizeWE
),
83 MAP_ENUM (MouseCursor
, None
),
87 static enum_map_t error_type_map
[] = {
89 MAP_NAME (UnknownError
),
90 MAP_NAME (InitializeError
),
91 MAP_NAME (ParserError
),
92 MAP_NAME (ObjectModelError
),
93 MAP_NAME (RuntimeError
),
94 MAP_NAME (DownloadError
),
95 MAP_NAME (MediaError
),
96 MAP_NAME (ImageError
),
100 static enum_map_t fill_behavior_map
[] = {
101 MAP_ENUM (FillBehavior
, HoldEnd
),
102 MAP_ENUM (FillBehavior
, Stop
),
106 static enum_map_t fill_rule_map
[] = {
107 MAP_ENUM (FillRule
, EvenOdd
),
108 MAP_ENUM (FillRule
, Nonzero
),
112 static enum_map_t font_stretches_map
[] = {
113 MAP_ENUM (FontStretches
, UltraCondensed
),
114 MAP_ENUM (FontStretches
, ExtraCondensed
),
115 MAP_ENUM (FontStretches
, Condensed
),
116 MAP_ENUM (FontStretches
, SemiCondensed
),
117 MAP_ENUM (FontStretches
, Normal
),
118 MAP_ENUM (FontStretches
, Medium
),
119 MAP_ENUM (FontStretches
, SemiExpanded
),
120 MAP_ENUM (FontStretches
, Expanded
),
121 MAP_ENUM (FontStretches
, ExtraExpanded
),
122 MAP_ENUM (FontStretches
, UltraExpanded
),
126 static enum_map_t font_styles_map
[] = {
127 MAP_ENUM (FontStyles
, Normal
),
128 MAP_ENUM (FontStyles
, Oblique
),
129 MAP_ENUM (FontStyles
, Italic
),
133 static enum_map_t font_weights_map
[] = {
134 MAP_ENUM (FontWeights
, Thin
),
135 MAP_ENUM (FontWeights
, ExtraLight
),
136 MAP_ENUM_FULL ("UltraLight", FontWeightsExtraLight
), // deprecated as of July 2007
137 MAP_ENUM (FontWeights
, Light
),
138 MAP_ENUM (FontWeights
, Normal
),
139 MAP_ENUM_FULL ("Regular", FontWeightsNormal
), // deprecated as of July 2007
140 MAP_ENUM (FontWeights
, Medium
),
141 MAP_ENUM (FontWeights
, SemiBold
),
142 MAP_ENUM_FULL ("DemiBold", FontWeightsSemiBold
), // deprecated as of July 2007
143 MAP_ENUM (FontWeights
, Bold
),
144 MAP_ENUM (FontWeights
, ExtraBold
),
145 MAP_ENUM_FULL ("UltraBold", FontWeightsExtraBold
), // deprecated as of July 2007
146 MAP_ENUM (FontWeights
, Black
),
147 MAP_ENUM_FULL ("Heavy", FontWeightsBlack
), // deprecated as of July 2007
148 MAP_ENUM (FontWeights
, ExtraBlack
),
149 MAP_ENUM_FULL ("UltraBlack", FontWeightsExtraBlack
), // deprecated as of July 2007
153 static enum_map_t line_stacking_strategy_map
[] = {
154 MAP_ENUM (LineStackingStrategy
, MaxHeight
),
155 MAP_ENUM (LineStackingStrategy
, BlockLineHeight
),
159 static enum_map_t horizontal_alignment_map
[] = {
160 MAP_ENUM (HorizontalAlignment
, Left
),
161 MAP_ENUM (HorizontalAlignment
, Center
),
162 MAP_ENUM (HorizontalAlignment
, Right
),
163 MAP_ENUM (HorizontalAlignment
, Stretch
),
167 static enum_map_t gradient_spread_method_map
[] = {
168 MAP_ENUM (GradientSpreadMethod
, Pad
),
169 MAP_ENUM (GradientSpreadMethod
, Reflect
),
170 MAP_ENUM (GradientSpreadMethod
, Repeat
),
174 static enum_map_t keyboard_navigation_mode_map
[] = {
175 MAP_ENUM (KeyboardNavigationMode
, Local
),
176 MAP_ENUM (KeyboardNavigationMode
, Cycle
),
177 MAP_ENUM (KeyboardNavigationMode
, Once
),
181 static enum_map_t media_element_state_map
[] = {
182 MAP_ENUM (MediaState
, Closed
),
183 MAP_ENUM (MediaState
, Opening
),
184 MAP_ENUM (MediaState
, Buffering
),
185 MAP_ENUM (MediaState
, Playing
),
186 MAP_ENUM (MediaState
, Paused
),
187 MAP_ENUM (MediaState
, Stopped
),
188 MAP_ENUM (MediaState
, Individualizing
),
189 MAP_ENUM (MediaState
, AcquiringLicense
),
190 MAP_ENUM (MediaState
, Error
),
194 static enum_map_t pen_line_cap_map
[] = {
195 MAP_ENUM (PenLineCap
, Flat
),
196 MAP_ENUM (PenLineCap
, Square
),
197 MAP_ENUM (PenLineCap
, Round
),
198 MAP_ENUM (PenLineCap
, Triangle
),
202 static enum_map_t pen_line_join_map
[] = {
203 MAP_ENUM (PenLineJoin
, Miter
),
204 MAP_ENUM (PenLineJoin
, Bevel
),
205 MAP_ENUM (PenLineJoin
, Round
),
209 static enum_map_t stretch_map
[] = {
210 MAP_ENUM (Stretch
, None
),
211 MAP_ENUM (Stretch
, Fill
),
212 MAP_ENUM (Stretch
, Uniform
),
213 MAP_ENUM (Stretch
, UniformToFill
),
217 static enum_map_t style_simulations_map
[] = {
218 MAP_ENUM (StyleSimulations
, None
),
219 MAP_ENUM_FULL ("BoldSimulation", StyleSimulationsBold
),
220 MAP_ENUM_FULL ("ItalicSimulation", StyleSimulationsItalic
),
221 MAP_ENUM_FULL ("BoldItalicSimulation", StyleSimulationsBoldItalic
),
225 static enum_map_t sweep_direction_map
[] = {
226 MAP_ENUM (SweepDirection
, Counterclockwise
),
227 MAP_ENUM (SweepDirection
, Clockwise
),
231 static enum_map_t tablet_device_type_map
[] = {
232 MAP_ENUM (TabletDeviceType
, Mouse
),
233 MAP_ENUM (TabletDeviceType
, Stylus
),
234 MAP_ENUM (TabletDeviceType
, Touch
),
238 static enum_map_t text_alignment_map
[] = {
239 MAP_ENUM (TextAlignment
, Center
),
240 MAP_ENUM (TextAlignment
, Left
),
241 MAP_ENUM (TextAlignment
, Right
),
245 static enum_map_t text_decorations_map
[] = {
246 MAP_ENUM (TextDecorations
, None
),
247 MAP_ENUM (TextDecorations
, Underline
),
251 static enum_map_t text_wrapping_map
[] = {
252 MAP_ENUM (TextWrapping
, Wrap
),
253 MAP_ENUM (TextWrapping
, NoWrap
),
254 MAP_ENUM (TextWrapping
, WrapWithOverflow
),
258 static enum_map_t scrollbar_visibility_map
[] = {
259 MAP_ENUM (ScrollBarVisibility
, Disabled
),
260 MAP_ENUM (ScrollBarVisibility
, Auto
),
261 MAP_ENUM (ScrollBarVisibility
, Hidden
),
262 MAP_ENUM (ScrollBarVisibility
, Visible
),
266 static enum_map_t vertical_alignment_map
[] = {
267 MAP_ENUM (VerticalAlignment
, Top
),
268 MAP_ENUM (VerticalAlignment
, Center
),
269 MAP_ENUM (VerticalAlignment
, Bottom
),
270 MAP_ENUM (VerticalAlignment
, Stretch
),
274 static enum_map_t visibility_map
[] = {
275 MAP_ENUM (Visibility
, Visible
),
276 MAP_ENUM (Visibility
, Collapsed
),
280 static enum_map_t orientation_map
[] = {
281 MAP_ENUM (Orientation
, Vertical
),
282 MAP_ENUM (Orientation
, Horizontal
),
286 static enum_map_t cross_domain_access_map
[] = {
287 MAP_ENUM (CrossDomainAccess
, NoAccess
),
288 MAP_ENUM (CrossDomainAccess
, ScriptableOnly
),
292 static enum_map_t grid_unit_type_map
[] = {
293 MAP_ENUM (GridUnitType
, Auto
),
294 MAP_ENUM (GridUnitType
, Pixel
),
295 MAP_ENUM (GridUnitType
, Star
),
299 static enum_map_t easing_mode_map
[] = {
300 MAP_ENUM_FULL ("EaseIn", EasingModeIn
),
301 MAP_ENUM_FULL ("EaseOut", EasingModeOut
),
302 MAP_ENUM_FULL ("EaseInOut", EasingModeInOut
),
307 initialize_enums (void)
309 enum_map
= g_hash_table_new (g_str_hash
, g_str_equal
);
311 g_hash_table_insert (enum_map
, (char *) "AlignmentX", alignment_x_map
);
312 g_hash_table_insert (enum_map
, (char *) "AlignmentY", alignment_y_map
);
313 g_hash_table_insert (enum_map
, (char *) "MappingMode", brush_mapping_mode_map
);
314 g_hash_table_insert (enum_map
, (char *) "ColorInterpolationMode", color_interpolation_mode_map
);
315 g_hash_table_insert (enum_map
, (char *) "Cursor", cursors_map
);
316 g_hash_table_insert (enum_map
, (char *) "ErrorType", error_type_map
);
317 g_hash_table_insert (enum_map
, (char *) "FillBehavior", fill_behavior_map
);
318 g_hash_table_insert (enum_map
, (char *) "FillRule", fill_rule_map
);
319 g_hash_table_insert (enum_map
, (char *) "FontStretch", font_stretches_map
);
320 g_hash_table_insert (enum_map
, (char *) "FontStyle", font_styles_map
);
321 g_hash_table_insert (enum_map
, (char *) "FontWeight", font_weights_map
);
322 g_hash_table_insert (enum_map
, (char *) "SpreadMethod", gradient_spread_method_map
);
324 g_hash_table_insert (enum_map
, (char *) "StrokeDashCap", pen_line_cap_map
);
325 g_hash_table_insert (enum_map
, (char *) "StrokeStartLineCap", pen_line_cap_map
);
326 g_hash_table_insert (enum_map
, (char *) "StrokeEndLineCap", pen_line_cap_map
);
328 g_hash_table_insert (enum_map
, (char *) "StrokeLineJoin", pen_line_join_map
);
329 g_hash_table_insert (enum_map
, (char *) "Stretch", stretch_map
);
330 g_hash_table_insert (enum_map
, (char *) "StyleSimulations", style_simulations_map
);
331 g_hash_table_insert (enum_map
, (char *) "SweepDirection", sweep_direction_map
);
332 g_hash_table_insert (enum_map
, (char *) "DeviceType", tablet_device_type_map
);
333 g_hash_table_insert (enum_map
, (char *) "TextDecorations", text_decorations_map
);
334 g_hash_table_insert (enum_map
, (char *) "TextWrapping", text_wrapping_map
);
335 g_hash_table_insert (enum_map
, (char *) "Visibility", visibility_map
);
337 g_hash_table_insert (enum_map
, (char *) "BindingMode", binding_mode_map
);
338 g_hash_table_insert (enum_map
, (char *) "ExternalCallersFromCrossDomain", cross_domain_access_map
);
339 g_hash_table_insert (enum_map
, (char *) "HorizontalScrollBarVisibility", scrollbar_visibility_map
);
340 g_hash_table_insert (enum_map
, (char *) "VerticalScrollBarVisibility", scrollbar_visibility_map
);
341 g_hash_table_insert (enum_map
, (char *) "LineStackingStrategy", line_stacking_strategy_map
);
342 g_hash_table_insert (enum_map
, (char *) "HorizontalAlignment", horizontal_alignment_map
);
343 g_hash_table_insert (enum_map
, (char *) "HorizontalContentAlignment", horizontal_alignment_map
);
344 g_hash_table_insert (enum_map
, (char *) "VerticalAlignment", vertical_alignment_map
);
345 g_hash_table_insert (enum_map
, (char *) "VerticalContentAlignment", vertical_alignment_map
);
346 g_hash_table_insert (enum_map
, (char *) "TextAlignment", text_alignment_map
);
347 g_hash_table_insert (enum_map
, (char *) "Orientation", orientation_map
);
349 g_hash_table_insert (enum_map
, (char *) "TabNavigation", keyboard_navigation_mode_map
);
351 g_hash_table_insert (enum_map
, (char *) "MediaState", media_element_state_map
);
352 g_hash_table_insert (enum_map
, (char *) "GridUnitType", grid_unit_type_map
);
354 g_hash_table_insert (enum_map
, (char *) "EasingMode", easing_mode_map
);
358 enum_from_str (const enum_map_t
*emu
, const char *str
)
361 for (i
= 0; emu
[i
].name
; i
++) {
362 if (!g_ascii_strcasecmp (emu
[i
].name
, str
))
363 return emu
[i
].value
;
370 str_from_enum (const enum_map_t
*emu
, int e
)
373 for (i
= 0; emu
[i
].name
; i
++) {
374 if (emu
[i
].value
== e
)
382 // Converts a string representing an enum (ie. "FillEnd") to int.
383 // Returns -1 if no property or enum found.
386 enums_str_to_int (const char *prop_name
, const char *str
)
388 if (enum_map
== NULL
)
391 enum_map_t
*emu
= (enum_map_t
*) g_hash_table_lookup (enum_map
, prop_name
);
395 return enum_from_str (emu
, str
);
399 // Converts an int enum to a string representation.
400 // Returns NULL if no match found.
403 enums_int_to_str (const char *prop_name
, int e
)
405 if (enum_map
== NULL
)
408 enum_map_t
*emu
= (enum_map_t
*) g_hash_table_lookup (enum_map
, prop_name
);
412 return str_from_enum (emu
, e
);
416 enums_is_enum_name (const char *enum_name
)
418 if (enum_map
== NULL
)
421 return g_hash_table_lookup (enum_map
, enum_name
) != NULL
;