During load, restore callback functions of figure handle at the end
[scilab.git] / scilab / modules / io / macros / %_sodload.sci
1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2 // Copyright (C) 2012 - DIGITEO - Antoine ELIAS
3 // Copyright (C) 2012 - DIGITEO - Vincent COUVERT
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 function %_sodload(%__filename__, varargin)
12
13     function [varValues] = %__convertVariable__(varValues, varNames)
14         for i = 1:size(varValues)
15             if typeof(varValues(i)) == "ScilabMatrixHandle" then
16                 //convert tlist to handle
17                 varValues(i) = createMatrixHandle(varValues(i));
18             elseif typeof(varValues(i)) == "ScilabMacro" then
19                 //convert tlist to macro
20                 varValues(i) = createMacro(varValues(i), varNames(i));
21             elseif isList(varValues(i)) then
22                 //list container
23                 varValues(i) = parseList(varValues(i));
24             end
25         end
26     endfunction
27
28     function result = isList(var)
29         //15 : list
30         //16 : tlist
31         //17 : mlist
32         if or(type(var) == [15, 16, 17]) then
33             result  = %t;
34         else
35             result = %f;
36         end
37     endfunction
38
39     function varValue = parseList(varValue)
40         if typeof(varValue)=="list" then
41             for i = definedfields(varValue)
42                 if typeof(varValue(i)) == "ScilabMatrixHandle" then
43                     varValue(i) = createMatrixHandle(varValue(i));
44                 elseif typeof(varValue(i)) == "ScilabMacro" then
45                     //convert tlist to macro
46                     varValue(i) = createMacro(varValue(i), "function");
47                 elseif isList(varValue(i)) then
48                     varValue(i) = parseList(varValue(i));
49                 else
50                     varValue(i) = varValue(i);
51                 end
52             end
53         else
54             fieldNb = size(getfield(1, varValue), "*");
55             for kField = 2:fieldNb // Do not inspect first field (field names)
56                 fieldValue = getfield(kField, varValue);
57                 if typeof(fieldValue) == "ScilabMatrixHandle" then
58                     fieldValue = createMatrixHandle(fieldValue);
59                 elseif typeof(fieldValue) == "ScilabMacro" then
60                     //convert tlist to macro
61                     fieldValue = createMacro(fieldValue, "function");
62                 elseif isList(fieldValue) then
63                     fieldValue = parseList(fieldValue);
64                 end
65                 setfield(kField, fieldValue, varValue);
66             end
67         end
68     endfunction
69
70     function h = createMatrixHandle(matrixHandle)
71         h = [];
72         if typeof(matrixHandle) <> "ScilabMatrixHandle" then
73             return;
74         end
75
76         for i = prod(matrixHandle.dims):-1:1
77             h($+1) = createSingleHandle(matrixHandle.values(i));
78             if or(fieldnames(matrixHandle.values(i))=="user_data") then // TODO Remove after graphic branch merge
79                 if isList(matrixHandle.values(i).user_data) then
80                     set(h($), "user_data", parseList(matrixHandle.values(i).user_data));
81                 elseif typeof(matrixHandle.values(i).user_data) == "ScilabMatrixHandle" then
82                     set(h($), "user_data", createMatrixHandle(matrixHandle.values(i).user_data));
83                 end
84             end
85         end
86         h = matrix(h, matrixHandle.dims);
87     endfunction
88
89     function h = createSingleHandle(item)
90         select item.type
91         case "Figure"
92             h = createFigure(item);
93         case "Axes"
94             h = createAxes(item);
95         case "Polyline"
96             h = createPolyline(item);
97         case "Plot3d"
98             h = createPlot3d(item);
99         case "Fac3d"
100             h = createFac3d(item);
101         case "Compound"
102             h = createCompound(item);
103         case "Rectangle"
104             h = createRectangle(item);
105         case "Arc"
106             h = createArc(item);
107         case "Champ"
108             h = createChamp(item);
109         case "Segs"
110             h = createSegs(item);
111         case "Grayplot"
112             h = createGrayplot(item);
113         case "Matplot"
114             h = createMatplot(item);
115         case "Fec"
116             h = createFec(item);
117         case "Legend"
118             h = createLegend(item);
119         case "Text"
120             h = createText(item);
121         case "Axis"
122             h = createAxis(item);
123         case "uimenu"
124             h = createuimenu(item);
125         case "uicontextmenu"
126             h = createuicontextmenu(item);
127         case "uicontrol"
128             h = createuicontrol(item);
129         else
130             error("handle of type " + item.type + " unhandled");
131             h = [];
132         end
133     endfunction
134
135     //
136     // FIGURE
137     //
138     function h = createFigure(figureProperties)
139         fields = fieldnames(figureProperties);
140         fields(1) = [];
141
142         h = gcf();
143         isVisible = h.visible;
144         resizefcn = "";
145         event_handler = "";
146         h.visible = "off";
147
148         fields(fields=="figure_id") = [];
149
150         h.figure_position=figureProperties.figure_position;
151         fields(fields=="figure_position") = [];
152         // set auto_resize first otherwise viewport modification may not have any effect.
153         h.auto_resize = figureProperties.auto_resize;
154         fields(fields=="auto_resize") = [];
155         h.figure_size = figureProperties.figure_size;
156         fields(fields=="figure_size") = [];
157         // set axes_size last because it's more important than figure_size
158         h.axes_size = figureProperties.axes_size;
159         fields(fields=="axes_size") = [];
160
161         for i = 1:size(fields, "*")
162             if fields(i) == "children" then
163                 c = figureProperties(fields(i));
164                 s = prod(c.dims);
165                 createSingleHandle(c.values(s));
166                 for  i = s-1:-1:1
167                     xsetech(wrect=[0 0 .1 .1])
168                     createSingleHandle(c.values(i));
169                 end
170             elseif fields(i) == "event_handler" then
171                 event_handler = figureProperties(fields(i));
172             elseif fields(i) == "resizefcn" then
173                 resizefcn = figureProperties(fields(i));
174             elseif fields(i) == "visible" then
175                 isVisible = figureProperties(fields(i));// do not set visible = "true" before the end of load.
176             else
177                 set(h, fields(i), figureProperties(fields(i)));
178             end
179         end
180
181         h.visible = isVisible;
182         h.resizefcn = resizefcn;
183         h.event_handler = event_handler;
184     endfunction
185
186     //
187     // LABEL
188     //
189     function h = createLabel(labelProperties, h)
190         fields = fieldnames(labelProperties);
191         fields(1) = [];
192         for i = 1:size(fields, "*")
193             set(h, fields(i), labelProperties(fields(i)));
194         end
195     endfunction
196
197     //
198     // TICKS
199     //
200     function h = createTicks(ticksProperties)
201         h = tlist(['ticks','locations','labels'], [], []);
202         fields = fieldnames(ticksProperties);
203         for i = 1:size(fields, "*")
204             h(fields(i)) = ticksProperties(fields(i));
205         end
206     endfunction
207
208     //
209     // AXES
210     //
211     function h = createAxes(axesProperties)
212         // Hack to determine whether %h_load has been called by the %h_copy macro
213         // in which case a new Axes object is created
214         [lnums, fnames] = where();
215         ind = grep(fnames, '%h_copy');
216         if ~isempty(ind) then
217           newaxes();
218         end;
219
220         h = gca();
221         fields = fieldnames(axesProperties);
222         fields(1) = [];
223
224         // Get log_flags to be sure to set them after data_bounds
225         log_flags = axesProperties.log_flags;
226         fields(fields=="log_flags") = [];
227
228         // Get mark_mode to be sure to set it after mark_style
229         mark_mode = axesProperties.mark_mode;
230         fields(fields=="mark_mode") = [];
231
232         // Get auto_ticks to be sure to set it after ticks labels
233         auto_ticks = axesProperties.auto_ticks;
234         fields(fields=="auto_ticks") = [];
235
236         for i = 1:size(fields, "*")
237             if or(fields(i) == ["title","x_label","y_label","z_label"]) then
238                 createLabel(axesProperties(fields(i)), h(fields(i)));
239             elseif or(fields(i) == ["x_ticks", "y_ticks", "z_ticks"]) then
240                 h(fields(i)) = createTicks(axesProperties(fields(i)));
241             elseif fields(i) == "children" then
242                 createMatrixHandle(axesProperties(fields(i)));
243             elseif fields(i) == "clip_state" then
244                 if axesProperties.clip_state=="on" then
245                     set(h,"clip_box",axesProperties.clip_box);
246                 end
247                 set(h,"clip_state", axesProperties.clip_state);
248             elseif fields(i) == "clip_box" then
249                 // managed with 'clip_state'
250             elseif fields(i) == "data_bounds" then
251                 set(h, "data_bounds", axesProperties.data_bounds);
252                 set(h, "log_flags", log_flags);
253             elseif fields(i) == "mark_style" then
254                 set(h, "mark_style", axesProperties.mark_style);
255                 set(h, "mark_mode", mark_mode);
256             else
257                 set(h, fields(i), axesProperties(fields(i)));;
258             end
259         end
260
261         set(h, "auto_ticks", auto_ticks);
262
263         // Legend management
264         global %LEG
265         if ~isempty(%LEG) then
266             // Get handles from paths
267             links=getlinksfrompath(h, %LEG.paths)
268             if ~isempty(links) then
269                 L = captions(links, %LEG.text)
270                 L.visible         = %LEG.visible
271                 L.font_style      = %LEG.font_style
272                 L.font_size       = %LEG.font_size
273                 L.font_color      = %LEG.font_color
274                 L.fractional_font = %LEG.fractional_font
275                 L.mark_mode       = 'off';
276                 L.legend_location = %LEG.legend_location
277                 L.position        = %LEG.position
278                 L.line_mode       = %LEG.line_mode
279                 L.thickness       = %LEG.thickness
280                 L.foreground      = %LEG.foreground
281                 L.fill_mode       = %LEG.fill_mode
282                 L.background      = %LEG.background
283                 if %LEG.clip_state=="on" then
284                     L.clip_box      = %LEG.clip_box
285                 end
286                 L.clip_state      = %LEG.clip_state
287                 L.user_data       = %LEG.user_data
288             else
289                 warning(msprintf(_("%s: Legend does not fit with the current context. Skipped\n"), "load"));
290             end
291         end
292         clearglobal %LEG
293     endfunction
294
295     //
296     // POLYLINE
297     //
298     function h = createPolyline(polylineProperties)
299         fields = fieldnames(polylineProperties);
300         fields(1) = [];
301
302         xpoly(polylineProperties.data(:,1), polylineProperties.data(:,2))
303
304         h = gce();
305
306         if polylineProperties.clip_state=="on" then
307             set(h, "clip_box", polylineProperties.clip_box)
308         end
309         set(h, "clip_state", polylineProperties.clip_state);
310         fields(fields=="clip_box") = [];
311         fields(fields=="clip_state") = [];
312
313         if polylineProperties.interp_color_mode=="on" & ~isempty(polylineProperties.interp_color_vector) then
314             set(h, "interp_color_vector", polylineProperties.interp_color_vector);
315             set(h, "interp_color_mode", polylineProperties.interp_color_mode);
316         else
317             if ~isempty(polylineProperties.interp_color_vector) then
318                 h.interp_color_vector = polylineProperties.interp_color_vector;
319             end
320             h.interp_color_mode = polylineProperties.interp_color_mode;
321         end
322         fields(fields=="interp_color_vector") = [];
323         fields(fields=="interp_color_mode") = [];
324
325         // Get mark_mode to be sure to set it after mark_style
326         mark_mode = polylineProperties.mark_mode;
327         fields(fields=="mark_mode") = [];
328
329         for i = 1:size(fields, "*")
330             if fields(i) == "mark_style" then
331                 set(h, "mark_style", polylineProperties.mark_style);
332                 set(h, "mark_mode", mark_mode);
333             else
334                 h(fields(i)) = polylineProperties(fields(i));
335             end
336         end
337     endfunction
338
339     //
340     // PLOT3D
341     //
342     function h = createPlot3d(plot3dProperties)
343         h = createSurface(plot3dProperties);
344     endfunction
345
346     //
347     // FAC3D
348     //
349     function h = createFac3d(fac3dProperties)
350         h = createSurface(fac3dProperties);
351     endfunction
352
353     //
354     // SURFACE
355     //
356     function h = createSurface(surfaceProperties)
357         fields = fieldnames(surfaceProperties);
358         fields(1) = [];
359         // plot3d modify the axes properties
360         //  - Save it
361         // - Draw plot3d
362         // - Restore it
363         a=gca();
364         rotation_angles = a.rotation_angles;
365         axes_visible = a.axes_visible;
366         box = a.box;
367         margins = a.margins;
368         x_label_visible = a.x_label.visible;
369         y_label_visible = a.y_label.visible;
370         z_label_visible = a.z_label.visible;
371         x_label_text = a.x_label.text;
372         y_label_text = a.y_label.text;
373         z_label_text = a.z_label.text;
374         axes_isoview = a.isoview;
375
376         if (or(surfaceProperties.color_flag==[2 5]) & ~or(fields=="cdata_mapping")) | ..
377             ((surfaceProperties.color_flag>=2) & or(fields=="cdata_mapping")) then
378             plot3d1(surfaceProperties.data.x, surfaceProperties.data.y, list(surfaceProperties.data.z, surfaceProperties.data.color))
379         else
380             plot3d(surfaceProperties.data.x,surfaceProperties.data.y,surfaceProperties.data.z)
381         end
382         fields(fields=="data") = [];
383
384         // Restore this properties after plot3d.
385         a.rotation_angles = rotation_angles;
386         a.axes_visible = axes_visible;
387         a.box = box;
388         a.margins = margins;
389         a.x_label.visible = x_label_visible;
390         a.y_label.visible = y_label_visible;
391         a.z_label.visible = z_label_visible;
392         a.x_label.text = x_label_text;
393         a.y_label.text = y_label_text;
394         a.z_label.text = z_label_text;
395         a.isoview = axes_isoview;
396
397         // Get mark_mode to be sure to set it after mark_style
398         mark_mode = surfaceProperties.mark_mode;
399         fields(fields=="mark_mode") = [];
400
401         h=gce();
402
403         if or(fields=="cdata_mapping") then // Fac3d specific
404             if surfaceProperties.color_flag >= 2 then
405                 set(h, "cdata_mapping", surfaceProperties.cdata_mapping);
406             end
407             fields(fields=="cdata_mapping") = [];
408         end
409
410         if surfaceProperties.clip_state == "on" then
411             set(h,"clip_box", surfaceProperties.clip_box);
412         end
413         set(h,"clip_state",surfaceProperties.clip_state);
414         fields(fields=="clip_box") = [];
415         fields(fields=="clip_state") = [];
416
417         for i = 1:size(fields, "*")
418             if fields(i) == "mark_style" then
419                 set(h, "mark_style", surfaceProperties.mark_style);
420                 set(h, "mark_mode", mark_mode);
421             else
422                 h(fields(i)) = surfaceProperties(fields(i));
423             end
424         end
425     endfunction
426
427     //
428     // COMPOUND
429     //
430     function h = createCompound(compoundProperties)
431         fields = fieldnames(compoundProperties);
432         fields(1) = [];
433
434         h = glue(createMatrixHandle(compoundProperties.children));
435         fields(fields=="children") = [];
436
437         for i = 1:size(fields, "*")
438             set(h, fields(i), compoundProperties(fields(i)));
439         end
440     endfunction
441
442     //
443     // RECTANGLE
444     //
445     function h = createRectangle(rectangleProperties)
446         fields = fieldnames(rectangleProperties);
447         fields(1) = [];
448
449         xrect(0,1,1,1); // create the rectangle with dummy values
450         h = gce();
451
452         if rectangleProperties.clip_state == "on" then
453             set(h,"clip_box", rectangleProperties.clip_box);
454         end
455         set(h,"clip_state",rectangleProperties.clip_state);
456         fields(fields=="clip_box") = [];
457         fields(fields=="clip_state") = [];
458
459         // Get mark_mode to be sure to set it after mark_style
460         mark_mode = rectangleProperties.mark_mode;
461         fields(fields=="mark_mode") = [];
462
463         for i = 1:size(fields, "*")
464             if fields(i) == "mark_style" then
465                 set(h, "mark_style", rectangleProperties.mark_style);
466                 set(h, "mark_mode", mark_mode);
467             else
468                 h(fields(i)) = rectangleProperties(fields(i));
469             end
470         end
471     endfunction
472
473     //
474     // ARC
475     //
476     function h = createArc(arcProperties)
477         fields = fieldnames(arcProperties);
478         fields(1) = [];
479
480         xarc(0,1,1,1,0,360); // create the arc with dummy values
481         h = gce();
482
483         if arcProperties.clip_state == "on" then
484             set(h,"clip_box", arcProperties.clip_box);
485         end
486         set(h,"clip_state",arcProperties.clip_state);
487         fields(fields=="clip_box") = [];
488         fields(fields=="clip_state") = [];
489
490         for i = 1:size(fields, "*")
491             set(h, fields(i), arcProperties(fields(i)));
492         end
493     endfunction
494
495     //
496     // CHAMP
497     //
498     function h = createChamp(champProperties)
499         fields = fieldnames(champProperties);
500         fields(1) = [];
501
502         champ(champProperties.data.x, champProperties.data.y, champProperties.data.fx, champProperties.data.fy);
503         fields(fields=="data") = [];
504
505         h=gce();
506
507         if champProperties.clip_state == "on" then
508             set(h,"clip_box", champProperties.clip_box);
509         end
510         set(h,"clip_state",champProperties.clip_state);
511         fields(fields=="clip_box") = [];
512         fields(fields=="clip_state") = [];
513
514         for i = 1:size(fields, "*")
515             set(h, fields(i), champProperties(fields(i)));
516         end
517     endfunction
518
519     //
520     // SEG
521     //
522     function h = createSegs(segsProperties)
523         fields = fieldnames(segsProperties);
524         fields(1) = [];
525
526         xsegs(segsProperties.data(:,1), segsProperties.data(:,2))
527
528         h=gce()
529
530         if segsProperties.clip_state == "on" then
531             set(h,"clip_box", segsProperties.clip_box);
532         end
533         set(h,"clip_state",segsProperties.clip_state);
534         fields(fields=="clip_box") = [];
535         fields(fields=="clip_state") = [];
536
537         // Get mark_mode to be sure to set it after mark_style
538         mark_mode = segsProperties.mark_mode;
539         fields(fields=="mark_mode") = [];
540
541         for i = 1:size(fields, "*")
542             if fields(i) == "mark_style" then
543                 set(h, "mark_style", segsProperties.mark_style);
544                 set(h, "mark_mode", mark_mode);
545             else
546                 h(fields(i)) = segsProperties(fields(i));
547             end
548         end
549     endfunction
550
551     //
552     // GRAYPLOT
553     //
554     function h = createGrayplot(grayplotProperties)
555         fields = fieldnames(grayplotProperties);
556         fields(1) = [];
557
558         grayplot(grayplotProperties.data.x, grayplotProperties.data.y, grayplotProperties.data.z);
559         fields(fields=="data") = [];
560
561         h = gce();
562
563         if grayplotProperties.clip_state=="on" then
564             set(h, "clip_box", grayplotProperties.clip_box)
565         end
566         set(h, "clip_state", grayplotProperties.clip_state);
567         fields(fields=="clip_box") = [];
568         fields(fields=="clip_state") = [];
569
570         for i = 1:size(fields, "*")
571             set(h, fields(i), grayplotProperties(fields(i)));
572         end
573     endfunction
574
575     //
576     // MATPLOT
577     //
578     function h = createMatplot(matplotProperties)
579         fields = fieldnames(matplotProperties);
580         fields(1) = [];
581
582         Matplot(matplotProperties.data);
583         fields(fields=="data") = [];
584
585         h = gce();
586
587         if matplotProperties.clip_state=="on" then
588             set(h, "clip_box", matplotProperties.clip_box)
589         end
590         set(h, "clip_state", matplotProperties.clip_state);
591         fields(fields=="clip_box") = [];
592         fields(fields=="clip_state") = [];
593
594         for i = 1:size(fields, "*")
595             set(h, fields(i), matplotProperties(fields(i)));
596         end
597     endfunction
598
599     //
600     // FEC
601     //
602     function h = createFec(fecProperties)
603         fields = fieldnames(fecProperties);
604         fields(1) = [];
605
606         fec(fecProperties.data(:,1), fecProperties.data(:,2), fecProperties.triangles, fecProperties.data(:,3));
607         fields(fields=="data") = [];
608         fields(fields=="triangles") = [];
609
610         h = unglue(gce());
611
612         if fecProperties.clip_state=="on" then
613             set(h, "clip_box", fecProperties.clip_box)
614         end
615         set(h, "clip_state", fecProperties.clip_state);
616         fields(fields=="clip_box") = [];
617         fields(fields=="clip_state") = [];
618
619         for i = 1:size(fields, "*")
620             set(h, fields(i), fecProperties(fields(i)));
621         end
622     endfunction
623
624     //
625     // LEGEND
626     //
627     function h = createLegend(legendProperties)
628         global %LEG
629         %LEG = legendProperties;
630         endfunction
631
632         //
633         // TEXT
634         //
635         function h = createText(textProperties)
636         fields = fieldnames(textProperties);
637         fields(1) = [];
638
639         if textProperties.text_box_mode == 'off' then
640             xstring(textProperties.data(1), textProperties.data(2), textProperties.text)
641         else
642             xstringb(textProperties.data(1), textProperties.data(2), textProperties.text, textProperties.text_box(1), textProperties.text_box(2))
643         end
644
645         h = gce();
646
647         if textProperties.clip_state=="on" then
648             set(h, "clip_box", textProperties.clip_box)
649         end
650         set(h, "clip_state", textProperties.clip_state);
651         fields(fields=="clip_box") = [];
652         fields(fields=="clip_state") = [];
653
654         for i = 1:size(fields, "*")
655             set(h, fields(i), textProperties(fields(i)));
656         end
657     endfunction
658
659     //
660     // AXIS
661     //
662     function h = createAxis(axisProperties)
663         fields = fieldnames(axisProperties);
664         fields(1) = [];
665
666         if axisProperties.tics_direction == "bottom" then
667             axisdir='d';
668         elseif axisProperties.tics_direction == "top" then
669             axisdir='u';
670         elseif axisProperties.tics_direction == "left" then
671             axisdir='l';
672         elseif axisProperties.tics_direction == "right" then
673             axisdir='r';
674         elseif size(axisProperties.xtics_coord, "*") > 1 then
675             axisdir='u';
676         else
677             axisdir='l';
678         end
679         fields(fields=="tics_direction") = [];
680
681         drawaxis(x=axisProperties.xtics_coord,y=axisProperties.ytics_coord,dir=axisdir);
682         fields(fields=="xtics_coord") = [];
683         fields(fields=="ytics_coord") = [];
684
685         h=gce()
686
687         if axisProperties.clip_state=="on" then
688             set(h, "clip_box", axisProperties.clip_box)
689         end
690         set(h, "clip_state", axisProperties.clip_state);
691         fields(fields=="clip_box") = [];
692         fields(fields=="clip_state") = [];
693
694         for i = 1:size(fields, "*")
695             set(h, fields(i), axisProperties(fields(i)));
696         end
697     endfunction
698
699     //
700     // uimenu
701     //
702     function h = createuimenu(uimenuProperties)
703         fields = fieldnames(uimenuProperties);
704         fields(1) = [];
705
706         h = uimenu();
707
708         for i = 1:size(fields, "*")
709             if fields(i) == "children" then
710                 children = createMatrixHandle(uimenuProperties(fields(i)));
711                 for k=1:size(children, "*")
712                     set(children(k), "parent", h);
713                 end
714             else
715                 set(h, fields(i), uimenuProperties(fields(i)));
716             end
717         end
718     endfunction
719
720     //
721     // UICONTEXTMENU
722     //
723     function h = createuicontextmenu(uicontextmenuProperties)
724         fields = fieldnames(uicontextmenuProperties);
725         fields(1) = [];
726
727         h = uicontextmenu();
728
729         for i = 1:size(fields, "*")
730             if fields(i) == "children" then
731                 children = createMatrixHandle(uicontextmenuProperties(fields(i)));
732                 for k=1:size(children, "*")
733                     set(children(k), "parent", h);
734                 end
735             else
736                 set(h, fields(i), uicontextmenuProperties(fields(i)));
737             end
738         end
739     endfunction
740
741     //
742     // uicontrol
743     //
744     function h = createuicontrol(uicontrolProperties)
745         fields = fieldnames(uicontrolProperties);
746         fields(1) = [];
747
748         h = uicontrol("Style", uicontrolProperties.style);
749         fields(fields=="style") = [];
750
751         for i = 1:size(fields, "*")
752             if fields(i) == "children" then
753                 children = createMatrixHandle(uicontrolProperties(fields(i)));
754                 for k=1:size(children, "*")
755                     set(children(k), "parent", h);
756                 end
757             else
758                 set(h, fields(i), uicontrolProperties(fields(i)));
759             end
760         end
761     endfunction
762
763     // Utility function for legends, copy/paste from %h_load
764     function links=getlinksfrompath(ax,paths)
765         //  ax is a  handle on an axes entity
766         //  paths a list or row vector which gives the set of paths relative to
767         //  the axes
768         links=[];
769         ok=%t;
770         for p=paths
771             e=ax;
772             p(1)=p(1)-1// the caption does not exists yet
773             for kp=1:size(p,'*'),
774                 if or(e.type==['Axes','Compound'])&p(kp)<=size(e.children,'*') then
775                     e=e.children(p(kp)),
776                 else
777                     ok=%f
778                     break
779                 end
780             end
781             if ~ok then
782                 break
783             end
784             links=[links,e]
785         end
786         if ~ok then
787             links=[];
788         end
789     endfunction
790
791     function macro = createMacro(macroStr, macroName)
792         macroSt = macroStr(3);
793         if macroStr(2) == %t then
794             flag = "c";
795         else
796             flag = "n";
797         end
798         header = strsubst(macroSt(1), "function ", "");
799         body = macroSt(2:$-1);
800         if body == [] then
801             body = "";
802         end
803         deff(header, body, flag);
804         execstr("macro = " + macroName);
805     endfunction
806
807     [%__lhs__, %__rhs__] = argn();
808     %__resumeList__ = list();
809     %__resumeVarlist__ = [];
810     if %__rhs__ < 1 then
811         error(999, msprintf(gettext("%s: Wrong number of input arguments: %d expected.\n"), "load", 1));
812     end
813
814     if %__rhs__ >= 1 then
815         if typeof(%__filename__) <> "string" | size(%__filename__, "*") <> 1 then
816             error(999, msprintf(gettext("%s: Wrong type for input argument #%d: String expected.\n"), "load", 1));
817         end
818     end
819
820     if isfile(%__filename__) & is_hdf5_file(%__filename__) then
821         %__loadFunction__ = import_from_hdf5;
822     else
823         %__loadFunction__ = %_load;
824     end
825
826     //multiple output variables to prevent listinfile prints
827     [%__variableList__, %__varB__, %__varC__, %__varD__] = listvarinfile(%__filename__);
828     //
829     if size(varargin) <> 0 then
830         for i = 1:size(varargin)
831             %__variableName__ = varargin(i);
832             if typeof(%__variableName__) <> "string" | size(%__variableName__, "*") <> 1 then
833                 error(999, msprintf(gettext("%s: Wrong type for input argument #%d: String expected.\n"), "load", i));
834             end
835
836             if or(%__variableList__ == %__variableName__) then
837                 %__loadFunction__(%__filename__, %__variableName__);
838                 %__resumeList__($+1) = evstr(%__variableName__);
839                 %__resumeVarlist__($+1) = %__variableName__;
840             else
841                 error(999, msprintf(gettext("%s: variable ''%s'' does not exist in ''%s''.\n"), "load", %__variableName__, %__filename__));
842             end
843         end
844     else
845         for i = 1:size(%__variableList__, "*")
846             %__variableName__ = %__variableList__(i);
847             %__loadFunction__(%__filename__, %__variableName__);
848             %__resumeList__($+1) = evstr(%__variableName__);
849             %__resumeVarlist__($+1) = %__variableName__;
850         end
851     end
852
853     if isfile(%__filename__) & is_hdf5_file(%__filename__) then
854         %__resumeList__ = %__convertVariable__(%__resumeList__, %__resumeVarlist__);
855     end
856
857     execstr("[" + strcat(%__resumeVarlist__, ",") + "] = resume(%__resumeList__(:))");
858 endfunction