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