* Bug #13794 fixed - Datatips display mode
[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  * 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 static 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     {"figure_id", get_figure_id_property},
64     {"rotation_style", get_rotation_style_property},
65     {"immediate_drawing", get_immediate_drawing_property},
66     {"type", get_type_property},
67     {"parent", get_parent_property},
68     {"current_axes", get_current_axes_property},
69     {"current_figure", get_current_figure_property},
70     {"current_obj", get_current_entity_property},
71     {"current_entity", get_current_entity_property},
72     {"hdl", get_current_entity_property},
73     {"children", get_children_property},
74     {"default_figure", get_default_figure_property},
75     {"default_axes", get_default_axes_property},
76     {"color_map", get_color_map_property},
77     {"interp_color_vector", get_interp_color_vector_property},
78     {"interp_color_mode", get_interp_color_mode_property},
79     {"background", get_background_property},
80     {"foreground", get_foreground_property},
81     {"fill_mode", get_fill_mode_property},
82     {"thickness", get_thickness_property},
83     {"arrow_size_factor", get_arrow_size_factor_property},
84     {"segs_color", get_segs_color_property},
85     {"line_style", get_line_style_property},
86     {"line_mode", get_line_mode_property},
87     {"surface_mode", get_surface_mode_property},
88     {"mark_style", get_mark_style_property},
89     {"mark_mode", get_mark_mode_property},
90     {"mark_size_unit", get_mark_size_unit_property},
91     {"mark_size", get_mark_size_property},
92     {"mark_foreground", get_mark_foreground_property},
93     {"mark_background", get_mark_background_property},
94     {"mark_offset", get_mark_offset_property},
95     {"mark_stride", get_mark_stride_property},
96     {"bar_layout", get_bar_layout_property},
97     {"bar_width", get_bar_width_property},
98     {"x_shift", get_x_shift_property},
99     {"y_shift", get_y_shift_property},
100     {"z_shift", get_z_shift_property},
101     {"polyline_style", get_polyline_style_property},
102     {"font_size", get_font_size_property},
103     {"font_angle", get_font_angle_property},
104     {"font_foreground", get_font_foreground_property},
105     {"font_color", get_font_color_property},
106     {"font_style", get_font_style_property},
107     {"text_box_mode", get_text_box_mode_property},
108     {"auto_dimensionning", get_auto_dimensionning_property},
109     {"alignment", get_alignment_property},
110     {"text_box", get_text_box_property},
111     {"text", get_text_property},
112     {"auto_clear", get_auto_clear_property},
113     {"auto_scale", get_auto_scale_property},
114     {"zoom_box", get_zoom_box_property},
115     {"zoom_state", get_zoom_state_property},
116     {"clip_box", get_clip_box_property},
117     {"clip_state", get_clip_state_property},
118     {"data", get_data_property},
119     {"callback", get_callback_property},
120     {"x_label", get_x_label_property},
121     {"y_label", get_y_label_property},
122     {"z_label", get_z_label_property},
123     {"title", get_title_property},
124     {"log_flags", get_log_flags_property},
125     {"tics_direction", get_tics_direction_property},
126     {"x_location", get_x_location_property},
127     {"y_location", get_y_location_property},
128     {"tight_limits", get_tight_limits_property},
129     {"closed", get_closed_property},
130     {"auto_position", get_auto_position_property},
131     {"auto_rotation", get_auto_rotation_property},
132     {"position", get_position_property},
133     {"auto_ticks", get_auto_ticks_property},
134     {"axes_reverse", get_axes_reverse_property},
135     {"view", get_view_property},
136     {"axes_bounds", get_axes_bounds_property},
137     {"data_bounds", get_data_bounds_property},
138     {"margins", get_margins_property},
139     {"auto_margins", get_auto_margins_property},
140     {"tics_color", get_tics_color_property},
141     {"tics_style", get_tics_style_property},
142     {"sub_tics", get_sub_tics_property},
143     {"sub_ticks", get_sub_tics_property},
144     {"tics_segment", get_tics_segment_property},
145     {"labels_font_size", get_labels_font_size_property},
146     {"labels_font_color", get_labels_font_color_property},
147     {"labels_font_style", get_labels_font_style_property},
148     {"format_n", get_format_n_property},
149     {"xtics_coord", get_xtics_coord_property},
150     {"ytics_coord", get_ytics_coord_property},
151     {"tics_labels", get_tics_labels_property},
152     {"box", get_box_property},
153     {"grid", get_grid_property},
154     {"grid_thickness", get_grid_thickness_property},
155     {"grid_style", get_grid_style_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     {"showhiddenhandles", GetConsoleShowHiddenHandles},
216     {"showhiddenproperties", GetConsoleShowHiddenProperties},
217     {"usedeprecatedskin", GetConsoleUseDeprecatedLF},
218     {"resizefcn", get_figure_resizefcn_property},
219     {"tooltipstring", GetUicontrolTooltipString},
220     {"closerequestfcn", get_figure_closerequestfcn_property},
221     {"orientation", get_tip_orientation_property},
222     {"z_component", get_tip_z_component_property},
223     {"display_components", get_tip_display_components_property},
224     {"datatip_display_mode", get_datatip_display_mode_property},
225     {"auto_orientation", get_tip_auto_orientation_property},
226     {"interp_mode", get_tip_interp_mode_property},
227     {"box_mode", get_tip_box_mode_property},
228     {"label_mode", get_tip_label_mode_property},
229     {"display_function", get_tip_disp_function_property},
230     {"detached_position", get_tip_detached_property},
231     {"ambient_color", get_ambient_color_property},
232     {"diffuse_color", get_diffuse_color_property},
233     {"specular_color", get_specular_color_property},
234     {"use_color_material", get_use_color_material_property},
235     {"material_shininess", get_material_shininess_property},
236     {"light_type", get_light_type_property},
237     {"direction", get_direction_property},
238     {"image_type", get_image_type_property},
239     {"datatips", get_datatips_property},
240     {"display_function_data", get_display_function_data_property},
241     {"resize", get_resize_property},
242     {"toolbar", get_toolbar_property},
243     {"toolbar_visible", get_toolbar_visible_property},
244     {"menubar", get_menubar_property},
245     {"menubar_visible", get_menubar_visible_property},
246     {"infobar_visible", get_infobar_visible_property},
247     {"dockable", get_dockable_property},
248     {"layout", get_layout_property},
249     {"constraints", get_constraints_property},
250     {"rect", get_rect_property},
251     {"layout_options", get_layout_options_property},
252     {"border", get_border_property},
253     {"groupname", get_groupname_property},
254     {"title_position", get_title_position_property},
255     {"title_scroll", get_title_scroll_property},
256     {"scrollable", get_scrollable_property},
257     {"icon", GetUicontrolIcon},
258     {"line_width", get_line_width_property},
259     {"marks_count", get_marks_count_property},
260     {"ticks_format", get_ticks_format_property},
261     {"ticks_st", get_ticks_st_property},
262     {"colors", get_colors_property}
263 };
264
265 /*--------------------------------------------------------------------------*/
266 GetPropertyHashTable *createScilabGetHashTable(void)
267 {
268     int i = 0;
269
270     int propertyCount = sizeof(propertyGetTable) / sizeof(getHashTableCouple);
271     if (getHashTableCreated)
272     {
273         /* hastable already created, return */
274         return getHashTable;
275     }
276
277     /* create the hash table */
278     getHashTable = createGetHashTable();
279
280     if (getHashTable == NULL)
281     {
282         return NULL;
283     }
284
285     /* insert every couple */
286     for (i = 0; i < propertyCount; i++)
287     {
288         insertGetHashtable(getHashTable, propertyGetTable[i].key, propertyGetTable[i].accessor);
289     }
290
291     getHashTableCreated = TRUE;
292
293     return getHashTable;
294
295 }
296
297 /*--------------------------------------------------------------------------*/
298
299 void* callGetProperty(void* _pvCtx, int iObjUID, char *propertyName)
300 {
301     getPropertyFunc accessor = searchGetHashtable(getHashTable, propertyName);
302
303     if (accessor == NULL)
304     {
305         Scierror(999, _("Unknown property: %s.\n"), propertyName);
306         return NULL;
307     }
308     return accessor(_pvCtx, iObjUID);
309 }
310
311 /*--------------------------------------------------------------------------*/
312 void destroyScilabGetHashTable(void)
313 {
314     if (!getHashTableCreated)
315     {
316         return;
317     }
318
319     destroyGetHashTable(getHashTable);
320     getHashTableCreated = FALSE;
321 }
322
323 /*--------------------------------------------------------------------------*/
324 char **getDictionaryGetProperties(int *sizearray)
325 {
326     char **dictionary = NULL;
327     int propertyCount = sizeof(propertyGetTable) / sizeof(getHashTableCouple);
328
329     *sizearray = 0;
330
331     dictionary = (char **)MALLOC(sizeof(char *) * propertyCount);
332     if (dictionary)
333     {
334         int i = 0;
335
336         *sizearray = propertyCount;
337         for (i = 0; i < propertyCount ; i++)
338         {
339             char *propertyname = (char *)MALLOC(sizeof(char) * (strlen(propertyGetTable[i].key) + 1));
340
341             if (propertyname)
342             {
343                 strcpy(propertyname, propertyGetTable[i].key);
344             }
345             dictionary[i] = propertyname;
346         }
347     }
348     return dictionary;
349 }
350 /*--------------------------------------------------------------------------*/