* Bug #13794 fixed - Datatips display mode
[scilab.git] / scilab / modules / graphics / src / c / getHandleProperty / SetHashTable.c
1 /*
2  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3  * Copyright (C) 2006 - INRIA - Jean-Baptiste Silvy
4  * Copyright (C) 2007 - INRIA - Vincent Couvert
5  *
6  * Copyright (C) 2012 - 2016 - Scilab Enterprises
7  *
8  * This file is hereby licensed under the terms of the GNU GPL v2.0,
9  * pursuant to article 5.3.4 of the CeCILL v.2.1.
10  * This file was originally licensed under the terms of the CeCILL v2.1,
11  * and continues to be available under such terms.
12  * For more information, see the COPYING file which you should have received
13  * along with this program.
14  *
15  */
16
17 /*------------------------------------------------------------------------*/
18 /* file: SetHashTable.c                                                   */
19 /* desc : implementation of the scilab hashtable for the set procedure    */
20 /*------------------------------------------------------------------------*/
21 #include <string.h>
22 #include "SetHashTable.h"
23 #include "setHandleProperty.h"
24 #include "Scierror.h"
25 #include "localization.h"
26 #include "getDictionarySetProperties.h"
27 #include "sci_malloc.h"
28 #include "os_string.h"
29 #include "BOOL.h"
30
31 /**
32 * use for the singleton to know if the hashtable has already be created.
33 */
34 static BOOL setHashTableCreated = FALSE;
35
36 /**
37 * the get hashtable
38 */
39 static SetPropertyHashTable *setHashTable = NULL;
40
41 /**
42 * a couple of key (property name) and associated value
43 * (accessor name)
44 */
45 typedef struct
46 {
47     char *key;
48     setPropertyFunc accessor;
49 } setHashTableCouple;
50
51 /**
52 * list of all property names and associated functions in scilab
53 * This is inserted in the hashTable
54 */
55 static setHashTableCouple propertySetTable[] =
56 {
57     {"visible", set_visible_property},
58     {"pixel_drawing_mode", set_pixel_drawing_mode_property},
59     {"old_style", set_old_style_property},
60     {"figure_style", set_figure_style_property},
61     {"auto_resize", set_auto_resize_property},
62     {"figure_position", set_figure_position_property},
63     {"axes_size", set_axes_size_property},
64     {"figure_size", set_figure_size_property},
65     {"figure_name", set_figure_name_property},
66     {"figure_id", set_figure_id_property},
67     {"rotation_style", set_rotation_style_property},
68     {"immediate_drawing", set_immediate_drawing_property},
69     {"parent", set_parent_property},
70     {"current_axes", set_current_axes_property},
71     {"current_figure", set_current_figure_property},
72     {"current_obj", set_current_entity_property},
73     {"current_entity", set_current_entity_property},
74     {"hdl", set_current_entity_property},
75     {"children", set_children_property},
76     {"default_values", set_default_values_property},
77     {"color_map", set_color_map_property},
78     {"interp_color_vector", set_interp_color_vector_property},
79     {"interp_color_mode", set_interp_color_mode_property},
80     {"background", set_background_property},
81     {"foreground", set_foreground_property},
82     {"fill_mode", set_fill_mode_property},
83     {"thickness", set_thickness_property},
84     {"arrow_size_factor", set_arrow_size_factor_property},
85     {"segs_color", set_segs_color_property},
86     {"line_style", set_line_style_property},
87     {"line_mode", set_line_mode_property},
88     {"surface_mode", set_surface_mode_property},
89     {"mark_style", set_mark_style_property},
90     {"mark_mode", set_mark_mode_property},
91     {"mark_size_unit", set_mark_size_unit_property},
92     {"mark_size", set_mark_size_property},
93     {"mark_foreground", set_mark_foreground_property},
94     {"mark_background", set_mark_background_property},
95     {"mark_offset", set_mark_offset_property},
96     {"mark_stride", set_mark_stride_property},
97     {"bar_layout", set_bar_layout_property},
98     {"bar_width", set_bar_width_property},
99     {"x_shift", set_x_shift_property},
100     {"y_shift", set_y_shift_property},
101     {"z_shift", set_z_shift_property},
102     {"polyline_style", set_polyline_style_property},
103     {"font_size", set_font_size_property},
104     {"font_angle", set_font_angle_property},
105     {"font_foreground", set_font_foreground_property},
106     {"font_color", set_font_color_property},
107     {"font_style", set_font_style_property},
108     {"text_box_mode", set_text_box_mode_property},
109     {"auto_dimensionning", set_auto_dimensionning_property},
110     {"alignment", set_alignment_property},
111     {"text_box", set_text_box_property},
112     {"text", set_text_property},
113     {"auto_clear", set_auto_clear_property},
114     {"auto_scale", set_auto_scale_property},
115     {"zoom_box", set_zoom_box_property},
116     {"zoom_state", set_zoom_state_property},
117     {"clip_box", set_clip_box_property},
118     {"clip_state", set_clip_state_property},
119     {"data", set_data_property},
120     {"callback", set_callback_property},
121     {"x_label", set_x_label_property},
122     {"y_label", set_y_label_property},
123     {"z_label", set_z_label_property},
124     {"title", set_title_property},
125     {"log_flags", set_log_flags_property},
126     {"tics_direction", set_tics_direction_property},
127     {"x_location", set_x_location_property},
128     {"y_location", set_y_location_property},
129     {"tight_limits", set_tight_limits_property},
130     {"closed", set_closed_property},
131     {"auto_position", set_auto_position_property},
132     {"auto_rotation", set_auto_rotation_property},
133     {"position", set_position_property},
134     {"auto_ticks", set_auto_ticks_property},
135     {"axes_reverse", set_axes_reverse_property},
136     {"view", set_view_property},
137     {"axes_bounds", set_axes_bounds_property},
138     {"data_bounds", set_data_bounds_property},
139     {"margins", set_margins_property},
140     {"auto_margins", set_auto_margins_property},
141     {"tics_color", set_tics_color_property},
142     {"tics_style", set_tics_style_property},
143     {"sub_tics", set_sub_tics_property},
144     {"sub_ticks", set_sub_tics_property},
145     {"tics_segment", set_tics_segment_property},
146     {"labels_font_size", set_labels_font_size_property},
147     {"labels_font_color", set_labels_font_color_property},
148     {"labels_font_style", set_labels_font_style_property},
149     {"format_n", set_format_n_property},
150     {"xtics_coord", set_xtics_coord_property},
151     {"ytics_coord", set_ytics_coord_property},
152     {"tics_labels", set_tics_labels_property},
153     {"box", set_box_property},
154     {"grid", set_grid_property},
155     {"grid_thickness", set_grid_thickness_property},
156     {"grid_style", set_grid_style_property},
157     {"axes_visible", set_axes_visible_property},
158     {"hiddencolor", set_hidden_color_property},
159     {"isoview", set_isoview_property},
160     {"cube_scaling", set_cube_scaling_property},
161     {"arrow_size", set_arrow_size_property},
162     {"colored", set_colored_property},
163     {"data_mapping", set_data_mapping_property},
164     {"rotation_angles", set_rotation_angles_property},
165     {"color_mode", set_color_mode_property},
166     {"color_flag", set_color_flag_property},
167     {"cdata_mapping", set_cdata_mapping_property},
168     {"surface_color", set_surface_color_property},
169     {"triangles", set_triangles_property},
170     {"z_bounds", set_z_bounds_property},
171     {"user_data", set_user_data_property},
172     {"userdata", set_user_data_property},   /* Compatibility with TK uicontrols */
173     {"handle_visible", set_handle_visible_property},
174     {"callback_type", set_callback_type_property},
175     {"enable", SetUiobjectEnable},
176     {"hidden_axis_color", set_hidden_axis_color_property},
177     {"x_ticks", set_x_ticks_property},
178     {"y_ticks", set_y_ticks_property},
179     {"z_ticks", set_z_ticks_property},
180     {"viewport", set_viewport_property},
181     {"info_message", set_info_message_property},
182     {"screen_position", set_screen_position_property},
183     {"event_handler_enable", set_event_handler_enable_property},
184     {"event_handler", set_event_handler_property},
185     {"label", SetUimenuLabel},
186     {"string", SetUicontrolString},
187     {"backgroundcolor", SetUicontrolBackgroundColor},
188     {"foregroundcolor", SetUiobjectForegroundColor},
189     {"fontweight", SetUicontrolFontWeight},
190     {"fontunits", SetUicontrolFontUnits},
191     {"fontsize", SetUicontrolFontSize},
192     {"fontangle", SetUicontrolFontAngle},
193     {"min", SetUicontrolMin},
194     {"max", SetUicontrolMax},
195     {"tag", set_tag_property},
196     {"listboxtop", SetUicontrolListboxTop},
197     {"value", SetUicontrolValue},
198     {"units", SetUicontrolUnits},
199     {"relief", SetUicontrolRelief},
200     {"horizontalalignment", SetUicontrolHorizontalAlignment},
201     {"verticalalignment", SetUicontrolVerticalAlignment},
202     {"fontname", SetUicontrolFontName},
203     {"sliderstep", SetUicontrolSliderStep},
204     {"checked", SetUimenuChecked},
205     {"arc_drawing_method", set_arc_drawing_method_property},
206     {"fractional_font", set_fractional_font_property},
207     {"links", set_links_property},
208     {"legend_location", set_legend_location_property},
209     {"filled", set_filled_property},
210     {"outside_colors", set_outside_colors_property},
211     {"color_range", set_color_range_property},
212     {"grid_position", set_grid_position_property},
213     {"anti_aliasing", set_anti_aliasing_property},
214     {"showhiddenhandles", SetConsoleShowHiddenHandles},
215     {"showhiddenproperties", SetConsoleShowHiddenProperties},
216     {"usedeprecatedskin", SetConsoleUseDeprecatedLF},
217     {"resizefcn", set_figure_resizefcn_property},
218     {"tooltipstring", SetUicontrolTooltipString},
219     {"closerequestfcn", set_figure_closerequestfcn_property},
220     {"orientation", set_tip_orientation_property},
221     {"z_component", set_tip_z_component_property},
222     {"display_components", set_tip_display_components_property},
223     {"datatip_display_mode", set_datatip_display_mode_property},
224     {"auto_orientation", set_tip_auto_orientation_property},
225     {"interp_mode", set_tip_interp_mode_property},
226     {"box_mode", set_tip_box_mode_property},
227     {"label_mode", set_tip_label_mode_property},
228     {"display_function", set_tip_disp_function_property},
229     {"detached_position", set_tip_detached_property},
230     {"ambient_color", set_ambient_color_property},
231     {"diffuse_color", set_diffuse_color_property},
232     {"specular_color", set_specular_color_property},
233     {"use_color_material", set_use_color_material_property},
234     {"material_shininess", set_material_shininess_property},
235     {"light_type", set_light_type_property},
236     {"direction", set_direction_property},
237     {"image_type", set_image_type_property},
238     {"datatips", set_datatips_property},
239     {"display_function_data", set_display_function_data_property},
240     {"resize", set_resize_property},
241     {"toolbar", set_toolbar_property},
242     {"toolbar_visible", set_toolbar_visible_property},
243     {"menubar", set_menubar_property},
244     {"menubar_visible", set_menubar_visible_property},
245     {"infobar_visible", set_infobar_visible_property},
246     {"dockable", set_dockable_property},
247     {"layout", set_layout_property},
248     {"constraints", set_constraints_property},
249     {"rect", set_rect_property},
250     {"layout_options", set_layout_options_property},
251     {"border", set_border_property},
252     {"groupname", set_groupname_property},
253     {"title_position", set_title_position_property},
254     {"title_scroll", set_title_scroll_property},
255     {"default_axes", set_default_axes_property},
256     {"scrollable", set_scrollable_property},
257     {"icon", SetUicontrolIcon},
258     {"line_width", set_line_width_property},
259     {"marks_count", set_marks_count_property},
260     {"ticks_format", set_ticks_format_property},
261     {"ticks_st", set_ticks_st_property},
262     {"colors", set_colors_property}
263 };
264
265 /*--------------------------------------------------------------------------*/
266 SetPropertyHashTable *createScilabSetHashTable(void)
267 {
268     int i = 0;
269
270     int propertyCount = sizeof(propertySetTable) / sizeof(setHashTableCouple);
271     if (setHashTableCreated)
272     {
273         return setHashTable;
274     }
275
276     /* create the hash table */
277     setHashTable = createSetHashTable();
278
279     if (setHashTable == NULL)
280     {
281         return NULL;
282     }
283
284     /* insert every couple */
285
286     for (i = 0; i < propertyCount ; i++)
287     {
288         insertSetHashtable(setHashTable, propertySetTable[i].key, propertySetTable[i].accessor);
289     }
290
291     setHashTableCreated = TRUE;
292
293     return setHashTable;
294
295 }
296
297 /*--------------------------------------------------------------------------*/
298 int callSetProperty(void* _pvCtx, int iObjUID, void* _pvData, int valueType, int nbRow, int nbCol, const char *propertyName)
299 {
300     setPropertyFunc accessor = searchSetHashtable(setHashTable, propertyName);
301
302     if (accessor == NULL)
303     {
304         Scierror(999, _("Unknown property: %s.\n"), propertyName);
305         return NULL;
306     }
307     return accessor(_pvCtx, iObjUID, _pvData, valueType, nbRow, nbCol);
308 }
309
310 /*--------------------------------------------------------------------------*/
311 void destroyScilabSetHashTable(void)
312 {
313     if (!setHashTableCreated)
314     {
315         return;
316     }
317
318     destroySetHashTable(setHashTable);
319     setHashTableCreated = FALSE;
320 }
321
322 /*--------------------------------------------------------------------------*/
323 char **getDictionarySetProperties(int *sizearray)
324 {
325     char **dictionary = NULL;
326     int propertyCount = sizeof(propertySetTable) / sizeof(setHashTableCouple);
327
328     *sizearray = 0;
329     dictionary = (char **)MALLOC(sizeof(char *) * propertyCount);
330     if (dictionary)
331     {
332         int i = 0;
333
334         *sizearray = propertyCount;
335         for (i = 0; i < propertyCount ; i++)
336         {
337             dictionary[i] = os_strdup(propertySetTable[i].key);
338         }
339     }
340     return dictionary;
341 }
342
343 /*--------------------------------------------------------------------------*/
344 #undef NB_PROPERTIES