b3810c8664699767c6d41bf5f72b4b8e4755042c
[scilab.git] / scilab / modules / graphics / src / c / getHandleProperty / GetHashTable.c
1 /*
2  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3  * Copyright (C) 2006 - INRIA - Jean-Baptiste Silvy
4  *
5  * This file must be used under the terms of the CeCILL.
6  * This source file is licensed as described in the file COPYING, which
7  * you should have received as part of this distribution.  The terms
8  * are also available at
9  * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
10  *
11  */
12
13 /*------------------------------------------------------------------------*/
14 /* file: GetHashTable.c                                                   */
15 /* desc : implementation of the scilab hashtable for the get procedure    */
16 /*------------------------------------------------------------------------*/
17 #include <string.h>
18 #include "GetHashTable.h"
19 #include "getHandleProperty.h"
20 #include "Scierror.h"
21 #include "localization.h"
22 #include "getDictionaryGetProperties.h"
23 #include "MALLOC.h"
24 /**
25  * use for the singleton to know if the hashtable has already be created.
26  */
27 static BOOL getHashTableCreated = FALSE;
28
29 /**
30  * the get hashtable
31  */
32 static GetPropertyHashTable *getHashTable = NULL;
33
34 /**
35  * a couple of key (property name) and associated value
36  * (accessor name)
37  */
38 typedef struct
39 {
40     char *key;
41     getPropertyFunc accessor;
42 } getHashTableCouple;
43
44 /**
45  * list of all property names and associated functions in scilab
46  * This is inserted in the hashTable
47  */
48 static getHashTableCouple propertyGetTable[] =
49 {
50     {"figures_id", get_figures_id_property},
51     {"visible", get_visible_property},
52     {"pixel_drawing_mode", get_pixel_drawing_mode_property},
53     {"old_style", get_old_style_property},
54     {"figure_style", get_figure_style_property},
55     {"auto_resize", get_auto_resize_property},
56     {"figure_position", get_figure_position_property},
57     {"axes_size", get_axes_size_property},
58     {"figure_size", get_figure_size_property},
59     {"figure_name", get_figure_name_property},
60     {"figure_id", get_figure_id_property},
61     {"rotation_style", get_rotation_style_property},
62     {"immediate_drawing", get_immediate_drawing_property},
63     {"type", get_type_property},
64     {"parent", get_parent_property},
65     {"current_axes", get_current_axes_property},
66     {"current_figure", get_current_figure_property},
67     {"current_obj", get_current_entity_property},
68     {"current_entity", get_current_entity_property},
69     {"hdl", get_current_entity_property},
70     {"children", get_children_property},
71     {"default_figure", get_default_figure_property},
72     {"default_axes", get_default_axes_property},
73     {"color_map", get_color_map_property},
74     {"interp_color_vector", get_interp_color_vector_property},
75     {"interp_color_mode", get_interp_color_mode_property},
76     {"background", get_background_property},
77     {"foreground", get_foreground_property},
78     {"fill_mode", get_fill_mode_property},
79     {"thickness", get_thickness_property},
80     {"arrow_size_factor", get_arrow_size_factor_property},
81     {"segs_color", get_segs_color_property},
82     {"line_style", get_line_style_property},
83     {"line_mode", get_line_mode_property},
84     {"surface_mode", get_surface_mode_property},
85     {"mark_style", get_mark_style_property},
86     {"mark_mode", get_mark_mode_property},
87     {"mark_size_unit", get_mark_size_unit_property},
88     {"mark_size", get_mark_size_property},
89     {"mark_foreground", get_mark_foreground_property},
90     {"mark_background", get_mark_background_property},
91     {"mark_offset", get_mark_offset_property},
92     {"mark_stride", get_mark_stride_property},
93     {"bar_layout", get_bar_layout_property},
94     {"bar_width", get_bar_width_property},
95     {"x_shift", get_x_shift_property},
96     {"y_shift", get_y_shift_property},
97     {"z_shift", get_z_shift_property},
98     {"polyline_style", get_polyline_style_property},
99     {"font_size", get_font_size_property},
100     {"font_angle", get_font_angle_property},
101     {"font_foreground", get_font_foreground_property},
102     {"font_color", get_font_color_property},
103     {"font_style", get_font_style_property},
104     {"text_box_mode", get_text_box_mode_property},
105     {"auto_dimensionning", get_auto_dimensionning_property},
106     {"alignment", get_alignment_property},
107     {"text_box", get_text_box_property},
108     {"text", get_text_property},
109     {"auto_clear", get_auto_clear_property},
110     {"auto_scale", get_auto_scale_property},
111     {"zoom_box", get_zoom_box_property},
112     {"zoom_state", get_zoom_state_property},
113     {"clip_box", get_clip_box_property},
114     {"clip_state", get_clip_state_property},
115     {"data", get_data_property},
116     {"callback", get_callback_property},
117     {"x_label", get_x_label_property},
118     {"y_label", get_y_label_property},
119     {"z_label", get_z_label_property},
120     {"title", get_title_property},
121     {"log_flags", get_log_flags_property},
122     {"tics_direction", get_tics_direction_property},
123     {"x_location", get_x_location_property},
124     {"y_location", get_y_location_property},
125     {"tight_limits", get_tight_limits_property},
126     {"closed", get_closed_property},
127     {"auto_position", get_auto_position_property},
128     {"auto_rotation", get_auto_rotation_property},
129     {"position", get_position_property},
130     {"auto_ticks", get_auto_ticks_property},
131     {"axes_reverse", get_axes_reverse_property},
132     {"view", get_view_property},
133     {"axes_bounds", get_axes_bounds_property},
134     {"data_bounds", get_data_bounds_property},
135     {"margins", get_margins_property},
136     {"auto_margins", get_auto_margins_property},
137     {"tics_color", get_tics_color_property},
138     {"tics_style", get_tics_style_property},
139     {"sub_tics", get_sub_tics_property},
140     {"sub_ticks", get_sub_tics_property},
141     {"tics_segment", get_tics_segment_property},
142     {"labels_font_size", get_labels_font_size_property},
143     {"labels_font_color", get_labels_font_color_property},
144     {"labels_font_style", get_labels_font_style_property},
145     {"format_n", get_format_n_property},
146     {"xtics_coord", get_xtics_coord_property},
147     {"ytics_coord", get_ytics_coord_property},
148     {"tics_labels", get_tics_labels_property},
149     {"box", get_box_property},
150     {"grid", get_grid_property},
151     {"grid_thickness", get_grid_thickness_property},
152     {"grid_style", get_grid_style_property},
153     {"axes_visible", get_axes_visible_property},
154     {"hiddencolor", get_hidden_color_property},
155     {"isoview", get_isoview_property},
156     {"cube_scaling", get_cube_scaling_property},
157     {"arrow_size", get_arrow_size_property},
158     {"colored", get_colored_property},
159     {"data_mapping", get_data_mapping_property},
160     {"rotation_angles", get_rotation_angles_property},
161     {"color_mode", get_color_mode_property},
162     {"color_flag", get_color_flag_property},
163     {"cdata_mapping", get_cdata_mapping_property},
164     {"surface_color", get_surface_color_property},
165     {"triangles", get_triangles_property},
166     {"z_bounds", get_z_bounds_property},
167     {"user_data", get_user_data_property},
168     {"userdata", get_user_data_property},   /* Compatibility with TK uicontrols */
169     {"handle_visible", get_handle_visible_property},
170     {"callback_type", get_callback_type_property},
171     {"enable", GetUiobjectEnable},
172     {"hidden_axis_color", get_hidden_axis_color_property},
173     {"x_ticks", get_x_ticks_property},
174     {"y_ticks", get_y_ticks_property},
175     {"z_ticks", get_z_ticks_property},
176     {"viewport", get_viewport_property},
177     {"info_message", get_info_message_property},
178     {"screen_position", get_screen_position_property},
179     {"event_handler_enable", get_event_handler_enable_property},
180     {"event_handler", get_event_handler_property},
181     {"label", GetUimenuLabel},
182     {"string", GetUicontrolString},
183     {"style", GetUicontrolStyle},
184     {"backgroundcolor", GetUicontrolBackgroundColor},
185     {"foregroundcolor", GetUiobjectForegroundColor},
186     {"fontweight", GetUicontrolFontWeight},
187     {"fontunits", GetUicontrolFontUnits},
188     {"fontsize", GetUicontrolFontSize},
189     {"fontangle", GetUicontrolFontAngle},
190     {"min", GetUicontrolMin},
191     {"max", GetUicontrolMax},
192     {"tag", get_tag_property},
193     {"listboxtop", GetUicontrolListboxTop},
194     {"value", GetUicontrolValue},
195     {"units", GetUicontrolUnits},
196     {"relief", GetUicontrolRelief},
197     {"horizontalalignment", GetUicontrolHorizontalAlignment},
198     {"verticalalignment", GetUicontrolVerticalAlignment},
199     {"fontname", GetUicontrolFontName},
200     {"sliderstep", GetUicontrolSliderStep},
201     {"checked", GetUimenuChecked},
202     {"arc_drawing_method", get_arc_drawing_method_property},
203     {"fractional_font", get_fractional_font_property},
204     {"links", get_links_property},
205     {"legend_location", get_legend_location_property},
206     {"filled", get_filled_property},
207     {"outside_colors", get_outside_colors_property},
208     {"color_range", get_color_range_property},
209     {"grid_position", get_grid_position_property},
210     {"anti_aliasing", get_anti_aliasing_property},
211     {"UID", get_UID},
212     {"showhiddenhandles", GetConsoleShowHiddenHandles},
213     {"showhiddenproperties", GetConsoleShowHiddenProperties},
214     {"usedeprecatedskin", GetConsoleUseDeprecatedLF},
215     {"resizefcn", get_figure_resizefcn_property},
216     {"tooltipstring", GetUicontrolTooltipString},
217     {"closerequestfcn", get_figure_closerequestfcn_property},
218     {"orientation", get_tip_orientation_property},
219     {"z_component", get_tip_3component_property},
220     {"auto_orientation", get_tip_auto_orientation_property},
221     {"interp_mode", get_tip_interp_mode_property},
222     {"box_mode", get_tip_box_mode_property},
223     {"label_mode", get_tip_label_mode_property},
224     {"display_function", get_tip_disp_function_property},
225     {"ambient_color", get_ambient_color_property},
226     {"diffuse_color", get_diffuse_color_property},
227     {"specular_color", get_specular_color_property},
228     {"use_color_material", get_use_color_material_property},
229     {"material_shininess", get_material_shininess_property},
230     {"light_type", get_light_type_property},
231     {"direction", get_direction_property},
232     {"image_type", get_image_type_property},
233     {"datatips", get_datatips_property},
234     {"display_function_data", get_display_function_data_property},
235     {"resize", get_resize_property},
236     {"toolbar", get_toolbar_property},
237     {"toolbar_visible", get_toolbar_visible_property},
238     {"menubar", get_menubar_property},
239     {"menubar_visible", get_menubar_visible_property},
240     {"infobar_visible", get_infobar_visible_property},
241     {"dockable", get_dockable_property},
242     {"layout", get_layout_property},
243     {"constraints", get_constraints_property},
244     {"rect", get_rect_property},
245     {"layout_options", get_layout_options_property},
246     {"border", get_border_property},
247     {"groupname", get_groupname_property},
248     {"title_position", get_title_position_property},
249     {"title_scroll", get_title_scroll_property},
250     {"scrollable", get_scrollable_property},
251     {"icon", GetUicontrolIcon},
252     {"line_width", get_line_width_property},
253     {"marks_count", get_marks_count_property},
254     {"ticks_format", get_ticks_format_property},
255     {"ticks_st", get_ticks_st_property},
256     {"colors", get_colors_property},
257     {"sizes", get_sizes_property}
258 };
259
260 /*--------------------------------------------------------------------------*/
261 GetPropertyHashTable *createScilabGetHashTable(void)
262 {
263     int i = 0;
264
265     int propertyCount = sizeof(propertyGetTable) / sizeof(getHashTableCouple);
266     if (getHashTableCreated)
267     {
268         /* hastable already created, return */
269         return getHashTable;
270     }
271
272     /* create the hash table */
273     getHashTable = createGetHashTable();
274
275     if (getHashTable == NULL)
276     {
277         return NULL;
278     }
279
280     /* insert every couple */
281     for (i = 0; i < propertyCount; i++)
282     {
283         insertGetHashtable(getHashTable, propertyGetTable[i].key, propertyGetTable[i].accessor);
284     }
285
286     getHashTableCreated = TRUE;
287
288     return getHashTable;
289
290 }
291
292 /*--------------------------------------------------------------------------*/
293 int callGetProperty(void* _pvCtx, int iObjUID, char *propertyName)
294 {
295     getPropertyFunc accessor = searchGetHashtable(getHashTable, propertyName);
296
297     if (accessor == NULL)
298     {
299         Scierror(999, _("Unknown property: %s.\n"), propertyName);
300         return -1;
301     }
302     return accessor(_pvCtx, iObjUID);
303 }
304
305 /*--------------------------------------------------------------------------*/
306 void destroyScilabGetHashTable(void)
307 {
308     if (!getHashTableCreated)
309     {
310         return;
311     }
312
313     destroyGetHashTable(getHashTable);
314     getHashTableCreated = FALSE;
315 }
316
317 /*--------------------------------------------------------------------------*/
318 char **getDictionaryGetProperties(int *sizearray)
319 {
320     char **dictionary = NULL;
321     int propertyCount = sizeof(propertyGetTable) / sizeof(getHashTableCouple);
322
323     *sizearray = 0;
324
325     dictionary = (char **)MALLOC(sizeof(char *) * propertyCount);
326     if (dictionary)
327     {
328         int i = 0;
329
330         *sizearray = propertyCount;
331         for (i = 0; i < propertyCount ; i++)
332         {
333             char *propertyname = (char *)MALLOC(sizeof(char) * (strlen(propertyGetTable[i].key) + 1));
334
335             if (propertyname)
336             {
337                 strcpy(propertyname, propertyGetTable[i].key);
338             }
339             dictionary[i] = propertyname;
340         }
341     }
342     return dictionary;
343 }
344 /*--------------------------------------------------------------------------*/