7332204e0c7f909c6721a3901d6bca3daaed7376
[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-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  * number of properties
46  * don't forget to modify it each time the propertyTable
47  * is modified.
48  */
49 #define NB_PROPERTIES 162
50
51 /**
52  * list of all property names and associated functions in scilab
53  * This is inserted in the hashTable
54  */
55 static getHashTableCouple propertyTable[NB_PROPERTIES] =
56 {
57     {"figures_id", get_figures_id_property},
58     {"visible", get_visible_property},
59     {"pixel_drawing_mode", get_pixel_drawing_mode_property},
60     {"old_style", get_old_style_property},
61     {"figure_style", get_figure_style_property},
62     {"auto_resize", get_auto_resize_property},
63     {"figure_position", get_figure_position_property},
64     {"axes_size", get_axes_size_property},
65     {"figure_size", get_figure_size_property},
66     {"figure_name", get_figure_name_property},
67     {"figure_id", get_figure_id_property},
68     {"rotation_style", get_rotation_style_property},
69     {"immediate_drawing", get_immediate_drawing_property},
70     {"pixmap", get_pixmap_property},
71     {"type", get_type_property},
72     {"parent", get_parent_property},
73     {"current_axes", get_current_axes_property},
74     {"current_figure", get_current_figure_property},
75     {"current_obj", get_current_entity_property},
76     {"current_entity", get_current_entity_property},
77     {"hdl", get_current_entity_property},
78     {"children", get_children_property},
79     {"default_figure", get_default_figure_property},
80     {"default_axes", get_default_axes_property},
81     {"color_map", get_color_map_property},
82     {"interp_color_vector", get_interp_color_vector_property},
83     {"interp_color_mode", get_interp_color_mode_property},
84     {"background", get_background_property},
85     {"foreground", get_foreground_property},
86     {"fill_mode", get_fill_mode_property},
87     {"thickness", get_thickness_property},
88     {"arrow_size_factor", get_arrow_size_factor_property},
89     {"segs_color", get_segs_color_property},
90     {"line_style", get_line_style_property},
91     {"line_mode", get_line_mode_property},
92     {"surface_mode", get_surface_mode_property},
93     {"mark_style", get_mark_style_property},
94     {"mark_mode", get_mark_mode_property},
95     {"mark_size_unit", get_mark_size_unit_property},
96     {"mark_size", get_mark_size_property},
97     {"mark_foreground", get_mark_foreground_property},
98     {"mark_background", get_mark_background_property},
99     {"bar_layout", get_bar_layout_property},
100     {"bar_width", get_bar_width_property},
101     {"x_shift", get_x_shift_property},
102     {"y_shift", get_y_shift_property},
103     {"z_shift", get_z_shift_property},
104     {"polyline_style", get_polyline_style_property},
105     {"font_size", get_font_size_property},
106     {"font_angle", get_font_angle_property},
107     {"font_foreground", get_font_foreground_property},
108     {"font_color", get_font_color_property},
109     {"font_style", get_font_style_property},
110     {"text_box_mode", get_text_box_mode_property},
111     {"auto_dimensionning", get_auto_dimensionning_property},
112     {"alignment", get_alignment_property},
113     {"text_box", get_text_box_property},
114     {"text", get_text_property},
115     {"auto_clear", get_auto_clear_property},
116     {"auto_scale", get_auto_scale_property},
117     {"zoom_box", get_zoom_box_property},
118     {"zoom_state", get_zoom_state_property},
119     {"clip_box", get_clip_box_property},
120     {"clip_state", get_clip_state_property},
121     {"data", get_data_property},
122     {"callback", get_callback_property},
123     {"x_label", get_x_label_property},
124     {"y_label", get_y_label_property},
125     {"z_label", get_z_label_property},
126     {"title", get_title_property},
127     {"log_flags", get_log_flags_property},
128     {"tics_direction", get_tics_direction_property},
129     {"x_location", get_x_location_property},
130     {"y_location", get_y_location_property},
131     {"tight_limits", get_tight_limits_property},
132     {"closed", get_closed_property},
133     {"auto_position", get_auto_position_property},
134     {"auto_rotation", get_auto_rotation_property},
135     {"position", get_position_property},
136     {"auto_ticks", get_auto_ticks_property},
137     {"axes_reverse", get_axes_reverse_property},
138     {"view", get_view_property},
139     {"axes_bounds", get_axes_bounds_property},
140     {"data_bounds", get_data_bounds_property},
141     {"margins", get_margins_property},
142     {"tics_color", get_tics_color_property},
143     {"tics_style", get_tics_style_property},
144     {"sub_tics", get_sub_tics_property},
145     {"sub_ticks", get_sub_tics_property},
146     {"tics_segment", get_tics_segment_property},
147     {"labels_font_size", get_labels_font_size_property},
148     {"labels_font_color", get_labels_font_color_property},
149     {"labels_font_style", get_labels_font_style_property},
150     {"format_n", get_format_n_property},
151     {"xtics_coord", get_xtics_coord_property},
152     {"ytics_coord", get_ytics_coord_property},
153     {"tics_labels", get_tics_labels_property},
154     {"box", get_box_property},
155     {"grid", get_grid_property},
156     {"axes_visible", get_axes_visible_property},
157     {"hiddencolor", get_hidden_color_property},
158     {"isoview", get_isoview_property},
159     {"cube_scaling", get_cube_scaling_property},
160     {"arrow_size", get_arrow_size_property},
161     {"colored", get_colored_property},
162     {"data_mapping", get_data_mapping_property},
163     {"rotation_angles", get_rotation_angles_property},
164     {"color_mode", get_color_mode_property},
165     {"color_flag", get_color_flag_property},
166     {"cdata_mapping", get_cdata_mapping_property},
167     {"surface_color", get_surface_color_property},
168     {"triangles", get_triangles_property},
169     {"z_bounds", get_z_bounds_property},
170     {"user_data", get_user_data_property},
171     {"userdata", get_user_data_property},   /* Compatibility with TK uicontrols */
172     {"handle_visible", get_handle_visible_property},
173     {"callback_type", get_callback_type_property},
174     {"enable", GetUiobjectEnable},
175     {"hidden_axis_color", get_hidden_axis_color_property},
176     {"x_ticks", get_x_ticks_property},
177     {"y_ticks", get_y_ticks_property},
178     {"z_ticks", get_z_ticks_property},
179     {"viewport", get_viewport_property},
180     {"info_message", get_info_message_property},
181     {"screen_position", get_screen_position_property},
182     {"event_handler_enable", get_event_handler_enable_property},
183     {"event_handler", get_event_handler_property},
184     {"label", GetUimenuLabel},
185     {"string", GetUicontrolString},
186     {"style", GetUicontrolStyle},
187     {"backgroundcolor", GetUicontrolBackgroundColor},
188     {"foregroundcolor", GetUiobjectForegroundColor},
189     {"fontweight", GetUicontrolFontWeight},
190     {"fontunits", GetUicontrolFontUnits},
191     {"fontsize", GetUicontrolFontSize},
192     {"fontangle", GetUicontrolFontAngle},
193     {"min", GetUicontrolMin},
194     {"max", GetUicontrolMax},
195     {"tag", get_tag_property},
196     {"listboxtop", GetUicontrolListboxTop},
197     {"value", GetUicontrolValue},
198     {"units", GetUicontrolUnits},
199     {"relief", GetUicontrolRelief},
200     {"horizontalalignment", GetUicontrolHorizontalAlignment},
201     {"verticalalignment", GetUicontrolVerticalAlignment},
202     {"fontname", GetUicontrolFontName},
203     {"sliderstep", GetUicontrolSliderStep},
204     {"checked", GetUimenuChecked},
205     {"arc_drawing_method", get_arc_drawing_method_property},
206     {"fractional_font", get_fractional_font_property},
207     {"links", get_links_property},
208     {"legend_location", get_legend_location_property},
209     {"filled", get_filled_property},
210     {"outside_colors", get_outside_colors_property},
211     {"color_range", get_color_range_property},
212     {"grid_position", get_grid_position_property},
213     {"anti_aliasing", get_anti_aliasing_property},
214     {"UID", get_UID},
215     {"rownames", GetUiobjectRowNames},
216     {"columnnames", GetUiobjectColumnNames},
217     {"tabledata", GetUiobjectTableData},
218     {"showhiddenhandles", GetConsoleShowHiddenHandles}
219 };
220
221 /*--------------------------------------------------------------------------*/
222 GetPropertyHashTable *createScilabGetHashTable(void)
223 {
224     int i;
225
226     if (getHashTableCreated)
227     {
228         /* hastable already created, return */
229         return getHashTable;
230     }
231
232     /* create the hash table */
233     getHashTable = createGetHashTable();
234
235     if (getHashTable == NULL)
236     {
237         return NULL;
238     }
239
240     /* insert every couple */
241     for (i = 0; i < NB_PROPERTIES; i++)
242     {
243         insertGetHashtable(getHashTable, propertyTable[i].key, propertyTable[i].accessor);
244     }
245
246     getHashTableCreated = TRUE;
247
248     return getHashTable;
249
250 }
251
252 /*--------------------------------------------------------------------------*/
253 int callGetProperty(char *pObjUID, char *propertyName)
254 {
255     getPropertyFunc accessor = searchGetHashtable(getHashTable, propertyName);
256
257     if (accessor == NULL)
258     {
259         Scierror(999, _("Unknown property: %s.\n"), propertyName);
260         return -1;
261     }
262     return accessor(pObjUID);
263 }
264
265 /*--------------------------------------------------------------------------*/
266 void destroyScilabGetHashTable(void)
267 {
268     if (!getHashTableCreated)
269     {
270         return;
271     }
272
273     destroyGetHashTable(getHashTable);
274     getHashTableCreated = FALSE;
275 }
276
277 /*--------------------------------------------------------------------------*/
278 char **getDictionaryGetProperties(int *sizearray)
279 {
280     char **dictionary = NULL;
281
282     *sizearray = 0;
283
284     dictionary = (char **)MALLOC(sizeof(char *) * NB_PROPERTIES);
285     if (dictionary)
286     {
287         int i = 0;
288
289         *sizearray = NB_PROPERTIES;
290         for (i = 0; i < NB_PROPERTIES; i++)
291         {
292             char *propertyname = (char *)MALLOC(sizeof(char) * (strlen(propertyTable[i].key) + 1));
293
294             if (propertyname)
295                 strcpy(propertyname, propertyTable[i].key);
296             dictionary[i] = propertyname;
297         }
298     }
299     return dictionary;
300 }
301
302 /*--------------------------------------------------------------------------*/
303 #undef NB_PROPERTIES