Added some missing headers reported by /usr/lib/build/checks-data/check_gcc_output
[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 159
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 { "callbackmevent"      , get_callbackmevent_property       },
123 { "callback"            , get_callback_property             },
124 { "x_label"             , get_x_label_property              },
125 { "y_label"             , get_y_label_property              },
126 { "z_label"             , get_z_label_property              },
127 { "title"               , get_title_property                },
128 { "log_flags"           , get_log_flags_property            },
129 { "tics_direction"      , get_tics_direction_property       },
130 { "x_location"          , get_x_location_property           },
131 { "y_location"          , get_y_location_property           },
132 { "tight_limits"        , get_tight_limits_property         },
133 { "closed"              , get_closed_property               },
134 { "auto_position"       , get_auto_position_property        },
135 { "auto_rotation"       , get_auto_rotation_property        },
136 { "position"            , get_position_property             },
137 { "auto_ticks"          , get_auto_ticks_property           },
138 { "axes_reverse"        , get_axes_reverse_property         },
139 { "view"                , get_view_property                 },
140 { "axes_bounds"         , get_axes_bounds_property          },
141 { "data_bounds"         , get_data_bounds_property          },
142 { "margins"             , get_margins_property              },
143 { "tics_color"          , get_tics_color_property           },
144 { "tics_style"          , get_tics_style_property           },
145 { "sub_tics"            , get_sub_tics_property             },
146 { "sub_ticks"           , get_sub_tics_property             },
147 { "tics_segment"        , get_tics_segment_property         },
148 { "labels_font_size"    , get_labels_font_size_property     },
149 { "labels_font_color"   , get_labels_font_color_property    },
150 { "labels_font_style"   , get_labels_font_style_property    },
151 { "format_n"            , get_format_n_property             },
152 { "xtics_coord"         , get_xtics_coord_property          },
153 { "ytics_coord"         , get_ytics_coord_property          },
154 { "tics_labels"         , get_tics_labels_property          },
155 { "box"                 , get_box_property                  },
156 { "grid"                , get_grid_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 { "dimension"           , get_dimension_property            },
184 { "event_handler_enable", get_event_handler_enable_property },
185 { "event_handler"       , get_event_handler_property        },
186 { "label"               , GetUimenuLabel                    },  
187 { "string"              , GetUicontrolString                },  
188 { "style"               , GetUicontrolStyle                 },
189 { "backgroundcolor"     , GetUicontrolBackgroundColor       },
190 { "foregroundcolor"     , GetUiobjectForegroundColor        },
191 { "fontweight"          , GetUicontrolFontWeight            },
192 { "fontunits"           , GetUicontrolFontUnits             },
193 { "fontsize"            , GetUicontrolFontSize              },
194 { "fontangle"           , GetUicontrolFontAngle             },
195 { "min"                 , GetUicontrolMin                   },
196 { "max"                 , GetUicontrolMax                   },
197 { "tag"                 , GetUiobjectTag                    },
198 { "listboxtop"          , GetUicontrolListboxTop            },
199 { "value"               , GetUicontrolValue                 },
200 { "units"               , GetUicontrolUnits                 },
201 { "relief"              , GetUicontrolRelief                },
202 { "horizontalalignment" , GetUicontrolHorizontalAlignment   },
203 { "verticalalignment"   , GetUicontrolVerticalAlignment     },
204 { "fontname"            , GetUicontrolFontName              },
205 { "sliderstep"          , GetUicontrolSliderStep            },
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 } ;
217
218 /*--------------------------------------------------------------------------*/
219 GetPropertyHashTable * createScilabGetHashTable( void )
220 {
221   int i ;
222   if ( getHashTableCreated )
223   {
224     /* hastable already created, return */
225     return getHashTable ;
226   }
227
228   /* create the hash table */
229   getHashTable = createGetHashTable() ;
230
231   if ( getHashTable == NULL )
232   {
233     return NULL ;
234   }
235
236   /* insert every couple */
237   for ( i = 0 ; i < NB_PROPERTIES ; i++ )
238   {
239     insertGetHashtable( getHashTable, propertyTable[i].key, propertyTable[i].accessor ) ;
240   }
241
242   getHashTableCreated = TRUE ;
243
244   return getHashTable ;
245
246 }
247 /*--------------------------------------------------------------------------*/
248 int callGetProperty( sciPointObj * pObj, char * propertyName )
249 {
250   getPropertyFunc accessor = searchGetHashtable( getHashTable, propertyName ) ;
251   if ( accessor == NULL )
252   {Scierror(999, _("Unknown property: %s.\n"), propertyName ) ;
253     return -1 ;
254   }
255   return accessor( pObj ) ;
256 }
257 /*--------------------------------------------------------------------------*/
258 void destroyScilabGetHashTable( void )
259 {
260   if ( !getHashTableCreated )
261   {
262     return ;
263   }
264   
265   destroyGetHashTable( getHashTable ) ;
266   getHashTableCreated = FALSE ;
267 }
268 /*--------------------------------------------------------------------------*/
269 char **getDictionaryGetProperties(int *sizearray)
270 {
271         char **dictionary = NULL;
272         *sizearray = 0;
273
274         dictionary = (char **)MALLOC(sizeof(char*)*NB_PROPERTIES);
275         if (dictionary)
276         {
277                 int i = 0;
278                 *sizearray = NB_PROPERTIES;
279                 for (i = 0;i < NB_PROPERTIES; i++)
280                 {
281                         char *propertyname = (char*)MALLOC(sizeof(char)*(strlen(propertyTable[i].key)+1));
282                         if (propertyname) strcpy(propertyname,propertyTable[i].key);
283                         dictionary [i] = propertyname;
284                 }
285         }
286         return dictionary;
287 }
288 /*--------------------------------------------------------------------------*/
289 #undef NB_PROPERTIES