2 * Grace - GRaphing, Advanced Computation and Exploration of data
4 * Home page: http://plasma-gate.weizmann.ac.il/Grace/
6 * Copyright (c) 1996-2004 Grace Development Team
8 * Maintained by Evgeny Stambulchik
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
30 #include "core_utils.h"
34 FrameUI
*create_frame_ui(ExplorerUI
*eui
)
39 Widget rc
, rc1
, rc2
, fr
;
41 ui
= xmalloc(sizeof(FrameUI
));
43 /* ------------ Tabs -------------- */
45 tab
= CreateTab(eui
->scrolled_window
);
46 AddHelpCB(tab
, "doc/UsersGuide.html#frame-properties");
49 /* ------------ Main tab -------------- */
51 ui
->main_tp
= CreateTabPage(tab
, "Main");
53 fr
= CreateFrame(ui
->main_tp
, "Viewport");
54 rc
= CreateVContainer(fr
);
56 rc1
= CreateHContainer(rc
);
57 ui
->view_xv1
= CreateText2(rc1
, "Xmin:", 8);
58 AddTextActivateCB(ui
->view_xv1
, text_explorer_cb
, eui
);
59 ui
->view_xv2
= CreateText2(rc1
, "Xmax:", 8);
60 AddTextActivateCB(ui
->view_xv2
, text_explorer_cb
, eui
);
62 rc1
= CreateHContainer(rc
);
63 ui
->view_yv1
= CreateText2(rc1
, "Ymin:", 8);
64 AddTextActivateCB(ui
->view_yv1
, text_explorer_cb
, eui
);
65 ui
->view_yv2
= CreateText2(rc1
, "Ymax:", 8);
66 AddTextActivateCB(ui
->view_yv2
, text_explorer_cb
, eui
);
68 fr
= CreateFrame(ui
->main_tp
, "Frame box");
69 rc
= CreateVContainer(fr
);
70 ui
->frame_framestyle_choice
= CreateFrameTypeChoice(rc
, "Frame type:");
71 AddOptionChoiceCB(ui
->frame_framestyle_choice
, oc_explorer_cb
, eui
);
73 rc2
= CreateHContainer(rc
);
74 ui
->frame_linew_choice
= CreateLineWidthChoice(rc2
, "Width:");
75 AddSpinChoiceCB(ui
->frame_linew_choice
, sp_explorer_cb
, eui
);
76 ui
->frame_lines_choice
= CreateLineStyleChoice(rc2
, "Style:");
77 AddOptionChoiceCB(ui
->frame_lines_choice
, oc_explorer_cb
, eui
);
79 rc2
= CreateHContainer(rc
);
80 ui
->frame_pen
= CreatePenChoice(rc2
, "Outline pen:");
81 AddPenChoiceCB(ui
->frame_pen
, pen_explorer_cb
, eui
);
82 ui
->frame_fillpen
= CreatePenChoice(rc2
, "Fill pen:");
83 AddPenChoiceCB(ui
->frame_fillpen
, pen_explorer_cb
, eui
);
85 fr
= CreateFrame(ui
->main_tp
, "Display options");
86 rc
= CreateHContainer(fr
);
87 ui
->toggle_legends
= CreateToggleButton(rc
, "Display legend");
88 AddToggleButtonCB(ui
->toggle_legends
, tb_explorer_cb
, eui
);
91 /* ------------ Legend frame tab -------------- */
93 ui
->legendbox_tp
= CreateTabPage(tab
, "Leg. box");
95 fr
= CreateFrame(ui
->legendbox_tp
, "Anchor point");
97 rc1
= CreateHContainer(fr
);
98 ui
->legend_anchor_x
= CreateSpinChoice(rc1
, "X:", 5,
99 SPIN_TYPE_FLOAT
, 0.0, 1.0, 0.01);
100 AddSpinChoiceCB(ui
->legend_anchor_x
, sp_explorer_cb
, eui
);
101 ui
->legend_anchor_y
= CreateSpinChoice(rc1
, "Y:", 5,
102 SPIN_TYPE_FLOAT
, 0.0, 1.0, 0.01);
103 AddSpinChoiceCB(ui
->legend_anchor_y
, sp_explorer_cb
, eui
);
105 fr
= CreateFrame(ui
->legendbox_tp
, "Offset");
106 rc1
= CreateHContainer(fr
);
107 ui
->legend_dx
= CreateSpinChoice(rc1
, "dX:", 5,
108 SPIN_TYPE_FLOAT
, -1.0, 1.0, 0.01);
109 AddSpinChoiceCB(ui
->legend_dx
, sp_explorer_cb
, eui
);
110 ui
->legend_dy
= CreateSpinChoice(rc1
, "dY:", 5,
111 SPIN_TYPE_FLOAT
, -1.0, 1.0, 0.01);
112 AddSpinChoiceCB(ui
->legend_dy
, sp_explorer_cb
, eui
);
114 fr
= CreateFrame(ui
->legendbox_tp
, "Frame box");
115 rc
= CreateVContainer(fr
);
117 ui
->legend_just
= CreateJustChoice(rc
, "Justification:");
118 AddOptionChoiceCB(ui
->legend_just
, oc_explorer_cb
, eui
);
120 rc2
= CreateHContainer(rc
);
121 ui
->legend_boxlinew
= CreateLineWidthChoice(rc2
, "Width:");
122 AddSpinChoiceCB(ui
->legend_boxlinew
, sp_explorer_cb
, eui
);
123 ui
->legend_boxlines
= CreateLineStyleChoice(rc2
, "Style:");
124 AddOptionChoiceCB(ui
->legend_boxlines
, oc_explorer_cb
, eui
);
126 rc2
= CreateHContainer(rc
);
127 ui
->legend_boxpen
= CreatePenChoice(rc2
, "Outline pen:");
128 AddPenChoiceCB(ui
->legend_boxpen
, pen_explorer_cb
, eui
);
129 ui
->legend_boxfillpen
= CreatePenChoice(rc2
, "Fill pen:");
130 AddPenChoiceCB(ui
->legend_boxfillpen
, pen_explorer_cb
, eui
);
132 /* ------------ Legends tab -------------- */
134 ui
->legends_tp
= CreateTabPage(tab
, "Legends");
136 fr
= CreateFrame(ui
->legends_tp
, "Text properties");
137 rc
= CreateVContainer(fr
);
138 ui
->legend_font
= CreateFontChoice(rc
, "Font:");
139 AddOptionChoiceCB(ui
->legend_font
, oc_explorer_cb
, eui
);
140 rc1
= CreateHContainer(rc
);
141 ui
->legend_charsize
= CreateCharSizeChoice(rc1
, "Size:");
142 AddSpinChoiceCB(ui
->legend_charsize
, sp_explorer_cb
, eui
);
143 ui
->legend_color
= CreateColorChoice(rc1
, "Color:");
144 AddOptionChoiceCB(ui
->legend_color
, oc_explorer_cb
, eui
);
146 fr
= CreateFrame(ui
->legends_tp
, "Placement");
147 rc
= CreateVContainer(fr
);
148 rc1
= CreateHContainer(rc
);
149 ui
->legends_vgap
= CreateSpinChoice(rc1
, "V-gap:",
150 4, SPIN_TYPE_FLOAT
, 0.0, 1.0, 0.01);
151 AddSpinChoiceCB(ui
->legends_vgap
, sp_explorer_cb
, eui
);
152 ui
->legends_hgap
= CreateSpinChoice(rc1
, "H-gap:",
153 4, SPIN_TYPE_FLOAT
, 0.0, 1.0, 0.01);
154 AddSpinChoiceCB(ui
->legends_hgap
, sp_explorer_cb
, eui
);
155 ui
->legends_len
= CreateSpinChoice(rc
, "Line length:",
156 4, SPIN_TYPE_FLOAT
, 0.0, 1.0, 0.01);
157 AddSpinChoiceCB(ui
->legends_len
, sp_explorer_cb
, eui
);
158 rc1
= CreateHContainer(rc
);
159 ui
->legends_invert
= CreateToggleButton(rc1
, "Put in reverse order");
160 AddToggleButtonCB(ui
->legends_invert
, tb_explorer_cb
, eui
);
161 ui
->legends_singlesym
= CreateToggleButton(rc1
, "Single symbol");
162 AddToggleButtonCB(ui
->legends_singlesym
, tb_explorer_cb
, eui
);
165 SelectTabPage(tab
, ui
->main_tp
);
172 void update_frame_ui(FrameUI
*ui
, Quark
*q
)
174 frame
*f
= frame_get_data(q
);
180 frame_get_view(q
, &v
);
181 l
= frame_get_legend(q
);
183 sprintf(buf
, "%.9g", v
.xv1
);
184 TextSetString(ui
->view_xv1
, buf
);
185 sprintf(buf
, "%.9g", v
.xv2
);
186 TextSetString(ui
->view_xv2
, buf
);
187 sprintf(buf
, "%.9g", v
.yv1
);
188 TextSetString(ui
->view_yv1
, buf
);
189 sprintf(buf
, "%.9g", v
.yv2
);
190 TextSetString(ui
->view_yv2
, buf
);
192 SetOptionChoice(ui
->frame_framestyle_choice
, f
->type
);
193 SetPenChoice(ui
->frame_pen
, &f
->outline
.pen
);
194 SpinChoiceSetValue(ui
->frame_linew_choice
, f
->outline
.width
);
195 SetOptionChoice(ui
->frame_lines_choice
, f
->outline
.style
);
196 SetPenChoice(ui
->frame_fillpen
, &f
->fillpen
);
198 SpinChoiceSetValue(ui
->legend_charsize
, l
->charsize
);
200 ToggleButtonSetState(ui
->toggle_legends
, l
->active
== TRUE
);
202 SpinChoiceSetValue(ui
->legend_anchor_x
, l
->anchor
.x
);
203 SpinChoiceSetValue(ui
->legend_anchor_y
, l
->anchor
.y
);
204 SetOptionChoice(ui
->legend_just
, l
->just
);
205 SpinChoiceSetValue(ui
->legend_dx
, l
->offset
.x
);
206 SpinChoiceSetValue(ui
->legend_dy
, l
->offset
.y
);
208 SpinChoiceSetValue(ui
->legends_vgap
, l
->vgap
);
209 SpinChoiceSetValue(ui
->legends_hgap
, l
->hgap
);
210 SpinChoiceSetValue(ui
->legends_len
, l
->len
);
211 ToggleButtonSetState(ui
->legends_invert
, l
->invert
);
212 ToggleButtonSetState(ui
->legends_singlesym
, l
->singlesym
);
214 SetOptionChoice(ui
->legend_font
, l
->font
);
215 SetOptionChoice(ui
->legend_color
, l
->color
);
216 SpinChoiceSetValue(ui
->legend_boxlinew
, l
->boxline
.width
);
217 SetOptionChoice(ui
->legend_boxlines
, l
->boxline
.style
);
218 SetPenChoice(ui
->legend_boxpen
, &l
->boxline
.pen
);
219 SetPenChoice(ui
->legend_boxfillpen
, &l
->boxfillpen
);
223 int set_frame_data(FrameUI
*ui
, Quark
*q
, void *caller
)
225 frame
*f
= frame_get_data(q
);
230 frame_get_view(q
, &vtmp
);
231 l
= frame_get_legend(q
);
233 if (!caller
|| caller
== ui
->view_xv1
) {
234 xv_evalexpr(ui
->view_xv1
, &vtmp
.xv1
);
236 if (!caller
|| caller
== ui
->view_xv2
) {
237 xv_evalexpr(ui
->view_xv2
, &vtmp
.xv2
);
239 if (!caller
|| caller
== ui
->view_yv1
) {
240 xv_evalexpr(ui
->view_yv1
, &vtmp
.yv1
);
242 if (!caller
|| caller
== ui
->view_yv2
) {
243 xv_evalexpr(ui
->view_yv2
, &vtmp
.yv2
);
245 if (!isvalid_viewport(&vtmp
)) {
246 errmsg("Invalid viewport coordinates");
247 return RETURN_FAILURE
;
249 frame_set_view(q
, &vtmp
);
252 if (!caller
|| caller
== ui
->frame_framestyle_choice
) {
253 f
->type
= GetOptionChoice(ui
->frame_framestyle_choice
);
255 if (!caller
|| caller
== ui
->frame_pen
) {
256 GetPenChoice(ui
->frame_pen
, &f
->outline
.pen
);
258 if (!caller
|| caller
== ui
->frame_linew_choice
) {
259 f
->outline
.width
= SpinChoiceGetValue(ui
->frame_linew_choice
);
261 if (!caller
|| caller
== ui
->frame_lines_choice
) {
262 f
->outline
.style
= GetOptionChoice(ui
->frame_lines_choice
);
264 if (!caller
|| caller
== ui
->frame_fillpen
) {
265 GetPenChoice(ui
->frame_fillpen
, &f
->fillpen
);
267 if (!caller
|| caller
== ui
->legend_charsize
) {
268 l
->charsize
= SpinChoiceGetValue(ui
->legend_charsize
);
270 if (!caller
|| caller
== ui
->toggle_legends
) {
271 l
->active
= ToggleButtonGetState(ui
->toggle_legends
);
273 if (!caller
|| caller
== ui
->legends_vgap
) {
274 l
->vgap
= SpinChoiceGetValue(ui
->legends_vgap
);
276 if (!caller
|| caller
== ui
->legends_hgap
) {
277 l
->hgap
= SpinChoiceGetValue(ui
->legends_hgap
);
279 if (!caller
|| caller
== ui
->legends_len
) {
280 l
->len
= SpinChoiceGetValue(ui
->legends_len
);
282 if (!caller
|| caller
== ui
->legends_invert
) {
283 l
->invert
= ToggleButtonGetState(ui
->legends_invert
);
285 if (!caller
|| caller
== ui
->legends_singlesym
) {
286 l
->singlesym
= ToggleButtonGetState(ui
->legends_singlesym
);
288 if (!caller
|| caller
== ui
->legend_anchor_x
) {
289 l
->anchor
.x
= SpinChoiceGetValue(ui
->legend_anchor_x
);
291 if (!caller
|| caller
== ui
->legend_anchor_y
) {
292 l
->anchor
.y
= SpinChoiceGetValue(ui
->legend_anchor_y
);
294 if (!caller
|| caller
== ui
->legend_just
) {
295 l
->just
= GetOptionChoice(ui
->legend_just
);
297 if (!caller
|| caller
== ui
->legend_dx
) {
298 l
->offset
.x
= SpinChoiceGetValue(ui
->legend_dx
);
300 if (!caller
|| caller
== ui
->legend_dy
) {
301 l
->offset
.y
= SpinChoiceGetValue(ui
->legend_dy
);
303 if (!caller
|| caller
== ui
->legend_font
) {
304 l
->font
= GetOptionChoice(ui
->legend_font
);
306 if (!caller
|| caller
== ui
->legend_color
) {
307 l
->color
= GetOptionChoice(ui
->legend_color
);
309 if (!caller
|| caller
== ui
->legend_boxpen
) {
310 GetPenChoice(ui
->legend_boxpen
, &l
->boxline
.pen
);
312 if (!caller
|| caller
== ui
->legend_boxlinew
) {
313 l
->boxline
.width
= SpinChoiceGetValue(ui
->legend_boxlinew
);
315 if (!caller
|| caller
== ui
->legend_boxlines
) {
316 l
->boxline
.style
= GetOptionChoice(ui
->legend_boxlines
);
318 if (!caller
|| caller
== ui
->legend_boxfillpen
) {
319 GetPenChoice(ui
->legend_boxfillpen
, &l
->boxfillpen
);
322 quark_dirtystate_set(q
, TRUE
);
324 return RETURN_SUCCESS
;
326 return RETURN_FAILURE
;