Reset parser in grace_set_project().
[grace.git] / src / frame_ui.c
blob7f346ea0e5e09d2733efc9c7caa395b31517634c
1 /*
2 * Grace - GRaphing, Advanced Computation and Exploration of data
3 *
4 * Home page: http://plasma-gate.weizmann.ac.il/Grace/
5 *
6 * Copyright (c) 1996-2004 Grace Development Team
7 *
8 * Maintained by Evgeny Stambulchik
9 *
11 * All Rights Reserved
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.
28 /* Frame UI */
30 #include "core_utils.h"
31 #include "explorer.h"
32 #include "protos.h"
34 #include "cbitmaps.h"
36 FrameUI *create_frame_ui(ExplorerUI *eui)
38 FrameUI *ui;
40 Widget tab;
41 Widget rc, rc1, rc2, fr;
43 BitmapOptionItem opitems[4] = {
44 {CORNER_UL, ul_bits},
45 {CORNER_LL, ll_bits},
46 {CORNER_UR, ur_bits},
47 {CORNER_LR, lr_bits}
50 ui = xmalloc(sizeof(FrameUI));
52 /* ------------ Tabs -------------- */
54 tab = CreateTab(eui->scrolled_window);
55 AddHelpCB(tab, "doc/UsersGuide.html#frame-properties");
58 /* ------------ Main tab -------------- */
60 ui->main_tp = CreateTabPage(tab, "Main");
62 fr = CreateFrame(ui->main_tp, "Viewport");
63 rc = CreateVContainer(fr);
65 rc1 = CreateHContainer(rc);
66 ui->view_xv1 = CreateTextItem2(rc1, 8, "Xmin:");
67 AddTextItemCB(ui->view_xv1, titem_explorer_cb, eui);
68 ui->view_xv2 = CreateTextItem2(rc1, 8, "Xmax:");
69 AddTextItemCB(ui->view_xv2, titem_explorer_cb, eui);
71 rc1 = CreateHContainer(rc);
72 ui->view_yv1 = CreateTextItem2(rc1, 8, "Ymin:");
73 AddTextItemCB(ui->view_yv1, titem_explorer_cb, eui);
74 ui->view_yv2 = CreateTextItem2(rc1, 8, "Ymax:");
75 AddTextItemCB(ui->view_yv2, titem_explorer_cb, eui);
77 fr = CreateFrame(ui->main_tp, "Frame box");
78 rc = CreateVContainer(fr);
79 ui->frame_framestyle_choice = CreatePanelChoice(rc, "Frame type:",
80 "Closed",
81 "Half open",
82 "Break top",
83 "Break bottom",
84 "Break left",
85 "Break right",
86 NULL);
87 AddOptionChoiceCB(ui->frame_framestyle_choice, oc_explorer_cb, eui);
89 rc2 = CreateHContainer(rc);
90 ui->frame_linew_choice = CreateLineWidthChoice(rc2, "Width:");
91 AddSpinChoiceCB(ui->frame_linew_choice, sp_explorer_cb, eui);
92 ui->frame_lines_choice = CreateLineStyleChoice(rc2, "Style:");
93 AddOptionChoiceCB(ui->frame_lines_choice, oc_explorer_cb, eui);
95 rc2 = CreateHContainer(rc);
96 ui->frame_pen = CreatePenChoice(rc2, "Outline pen:");
97 AddPenChoiceCB(ui->frame_pen, pen_explorer_cb, eui);
98 ui->frame_fillpen = CreatePenChoice(rc2, "Fill pen:");
99 AddPenChoiceCB(ui->frame_fillpen, pen_explorer_cb, eui);
101 fr = CreateFrame(ui->main_tp, "Display options");
102 rc = CreateHContainer(fr);
103 ui->toggle_legends = CreateToggleButton(rc, "Display legend");
104 AddToggleButtonCB(ui->toggle_legends, tb_explorer_cb, eui);
107 /* ------------ Legend frame tab -------------- */
109 ui->legendbox_tp = CreateTabPage(tab, "Leg. box");
111 fr = CreateFrame(ui->legendbox_tp, "Anchor point");
112 rc = CreateVContainer(fr);
113 ui->legend_acorner = CreateBitmapOptionChoice(rc,
114 "Corner:", 2, 4, CBITMAP_WIDTH, CBITMAP_HEIGHT, opitems);
115 AddOptionChoiceCB(ui->legend_acorner, oc_explorer_cb, eui);
117 rc1 = CreateHContainer(rc);
118 ui->legend_x = CreateSpinChoice(rc1, "dX:", 4,
119 SPIN_TYPE_FLOAT, -1.0, 1.0, 0.01);
120 AddSpinChoiceCB(ui->legend_x, sp_explorer_cb, eui);
121 ui->legend_y = CreateSpinChoice(rc1, "dY:", 4,
122 SPIN_TYPE_FLOAT, -1.0, 1.0, 0.01);
123 AddSpinChoiceCB(ui->legend_y, sp_explorer_cb, eui);
125 fr = CreateFrame(ui->legendbox_tp, "Frame box");
126 rc = CreateVContainer(fr);
128 rc2 = CreateHContainer(rc);
129 ui->legend_boxlinew = CreateLineWidthChoice(rc2, "Width:");
130 AddSpinChoiceCB(ui->legend_boxlinew, sp_explorer_cb, eui);
131 ui->legend_boxlines = CreateLineStyleChoice(rc2, "Style:");
132 AddOptionChoiceCB(ui->legend_boxlines, oc_explorer_cb, eui);
134 rc2 = CreateHContainer(rc);
135 ui->legend_boxpen = CreatePenChoice(rc2, "Outline pen:");
136 AddPenChoiceCB(ui->legend_boxpen, pen_explorer_cb, eui);
137 ui->legend_boxfillpen = CreatePenChoice(rc2, "Fill pen:");
138 AddPenChoiceCB(ui->legend_boxfillpen, pen_explorer_cb, eui);
140 /* ------------ Legends tab -------------- */
142 ui->legends_tp = CreateTabPage(tab, "Legends");
144 fr = CreateFrame(ui->legends_tp, "Text properties");
145 rc = CreateVContainer(fr);
146 ui->legend_font = CreateFontChoice(rc, "Font:");
147 AddOptionChoiceCB(ui->legend_font, oc_explorer_cb, eui);
148 rc1 = CreateHContainer(rc);
149 ui->legend_charsize = CreateCharSizeChoice(rc1, "Size:");
150 AddSpinChoiceCB(ui->legend_charsize, sp_explorer_cb, eui);
151 ui->legend_color = CreateColorChoice(rc1, "Color:");
152 AddOptionChoiceCB(ui->legend_color, oc_explorer_cb, eui);
154 fr = CreateFrame(ui->legends_tp, "Placement");
155 rc = CreateVContainer(fr);
156 rc1 = CreateHContainer(rc);
157 ui->legends_vgap = CreateSpinChoice(rc1, "V-gap:",
158 4, SPIN_TYPE_FLOAT, 0.0, 1.0, 0.01);
159 AddSpinChoiceCB(ui->legends_vgap, sp_explorer_cb, eui);
160 ui->legends_hgap = CreateSpinChoice(rc1, "H-gap:",
161 4, SPIN_TYPE_FLOAT, 0.0, 1.0, 0.01);
162 AddSpinChoiceCB(ui->legends_hgap, sp_explorer_cb, eui);
163 ui->legends_len = CreateSpinChoice(rc, "Line length:",
164 4, SPIN_TYPE_FLOAT, 0.0, 1.0, 0.01);
165 AddSpinChoiceCB(ui->legends_len, sp_explorer_cb, eui);
166 rc1 = CreateHContainer(rc);
167 ui->legends_invert = CreateToggleButton(rc1, "Put in reverse order");
168 AddToggleButtonCB(ui->legends_invert, tb_explorer_cb, eui);
169 ui->legends_singlesym = CreateToggleButton(rc1, "Single symbol");
170 AddToggleButtonCB(ui->legends_singlesym, tb_explorer_cb, eui);
173 SelectTabPage(tab, ui->main_tp);
175 ui->top = tab;
177 return ui;
180 void update_frame_ui(FrameUI *ui, Quark *q)
182 frame *f = frame_get_data(q);
183 if (f) {
184 char buf[32];
185 view v;
186 legend *l;
188 frame_get_view(q, &v);
189 l = frame_get_legend(q);
191 sprintf(buf, "%.9g", v.xv1);
192 xv_setstr(ui->view_xv1, buf);
193 sprintf(buf, "%.9g", v.xv2);
194 xv_setstr(ui->view_xv2, buf);
195 sprintf(buf, "%.9g", v.yv1);
196 xv_setstr(ui->view_yv1, buf);
197 sprintf(buf, "%.9g", v.yv2);
198 xv_setstr(ui->view_yv2, buf);
200 SetOptionChoice(ui->frame_framestyle_choice, f->type);
201 SetPenChoice(ui->frame_pen, &f->outline.pen);
202 SetSpinChoice(ui->frame_linew_choice, f->outline.width);
203 SetOptionChoice(ui->frame_lines_choice, f->outline.style);
204 SetPenChoice(ui->frame_fillpen, &f->fillpen);
206 SetSpinChoice(ui->legend_charsize, l->charsize);
208 SetToggleButtonState(ui->toggle_legends, l->active == TRUE);
210 SetOptionChoice(ui->legend_acorner, l->acorner);
211 SetSpinChoice(ui->legend_x, l->offset.x);
212 SetSpinChoice(ui->legend_y, l->offset.y);
214 SetSpinChoice(ui->legends_vgap, l->vgap);
215 SetSpinChoice(ui->legends_hgap, l->hgap);
216 SetSpinChoice(ui->legends_len, l->len);
217 SetToggleButtonState(ui->legends_invert, l->invert);
218 SetToggleButtonState(ui->legends_singlesym, l->singlesym);
220 SetOptionChoice(ui->legend_font, l->font);
221 SetOptionChoice(ui->legend_color, l->color);
222 SetSpinChoice(ui->legend_boxlinew, l->boxline.width);
223 SetOptionChoice(ui->legend_boxlines, l->boxline.style);
224 SetPenChoice(ui->legend_boxpen, &l->boxline.pen);
225 SetPenChoice(ui->legend_boxfillpen, &l->boxfillpen);
229 int set_frame_data(FrameUI *ui, Quark *q, void *caller)
231 frame *f = frame_get_data(q);
232 if (f) {
233 view vtmp;
234 legend *l;
236 frame_get_view(q, &vtmp);
237 l = frame_get_legend(q);
239 if (!caller || caller == ui->view_xv1) {
240 xv_evalexpr(ui->view_xv1, &vtmp.xv1);
242 if (!caller || caller == ui->view_xv2) {
243 xv_evalexpr(ui->view_xv2, &vtmp.xv2);
245 if (!caller || caller == ui->view_yv1) {
246 xv_evalexpr(ui->view_yv1, &vtmp.yv1);
248 if (!caller || caller == ui->view_yv2) {
249 xv_evalexpr(ui->view_yv2, &vtmp.yv2);
251 if (!isvalid_viewport(&vtmp)) {
252 errmsg("Invalid viewport coordinates");
253 return RETURN_FAILURE;
254 } else {
255 frame_set_view(q, &vtmp);
258 if (!caller || caller == ui->frame_framestyle_choice) {
259 f->type = GetOptionChoice(ui->frame_framestyle_choice);
261 if (!caller || caller == ui->frame_pen) {
262 GetPenChoice(ui->frame_pen, &f->outline.pen);
264 if (!caller || caller == ui->frame_linew_choice) {
265 f->outline.width = GetSpinChoice(ui->frame_linew_choice);
267 if (!caller || caller == ui->frame_lines_choice) {
268 f->outline.style = GetOptionChoice(ui->frame_lines_choice);
270 if (!caller || caller == ui->frame_fillpen) {
271 GetPenChoice(ui->frame_fillpen, &f->fillpen);
273 if (!caller || caller == ui->legend_charsize) {
274 l->charsize = GetSpinChoice(ui->legend_charsize);
276 if (!caller || caller == ui->toggle_legends) {
277 l->active = GetToggleButtonState(ui->toggle_legends);
279 if (!caller || caller == ui->legends_vgap) {
280 l->vgap = GetSpinChoice(ui->legends_vgap);
282 if (!caller || caller == ui->legends_hgap) {
283 l->hgap = GetSpinChoice(ui->legends_hgap);
285 if (!caller || caller == ui->legends_len) {
286 l->len = GetSpinChoice(ui->legends_len);
288 if (!caller || caller == ui->legends_invert) {
289 l->invert = GetToggleButtonState(ui->legends_invert);
291 if (!caller || caller == ui->legends_singlesym) {
292 l->singlesym = GetToggleButtonState(ui->legends_singlesym);
294 if (!caller || caller == ui->legend_acorner) {
295 l->acorner = GetOptionChoice(ui->legend_acorner);
297 if (!caller || caller == ui->legend_x) {
298 l->offset.x = GetSpinChoice(ui->legend_x);
300 if (!caller || caller == ui->legend_y) {
301 l->offset.y = GetSpinChoice(ui->legend_y);
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 = GetSpinChoice(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;
325 } else {
326 return RETURN_FAILURE;