-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmagstep.c
286 lines (242 loc) · 6.61 KB
/
magstep.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
/*
* magstep.c
* Magstep menu callbacks for mgv.
*
* Copyright (C) 1996 Eric A. Howe
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* Authors: Matthew D. Francey
* Eric A. Howe ([email protected])
*/
#include <wlib/rcs.h>
MU_ID("$Mu: mgv/magstep.c 1.62 2001/03/11 18:18:05 $")
#include <Xm/ToggleB.h>
#include <Xm/TextF.h>
#include <wlib/stdlib.h>
#include <wlib/typesanity.h>
#include <wlib/wlib.h>
#include <wlib/sanity.h>
#include <wlib/callbacks.h>
#include <wlib/help.h>
#include <mine/mgv.h>
#include <mine/app.h>
#include <mine/magstep.h>
/*
* Set magstep and synchronize the widgets.
*
* If you are looking for a way to prevent high magsteps from griding your
* machine into the ground, this is the place for the limits. All of the
* magstep setting goes through here.
*/
int
mgv_ui_magnify(MGV *m, int magstep)
{
int different;
char s[64];
MGVR *r = mgv_app_res(m->main);
different = mgv_magnify(m, r->magstep = magstep);
/*
* If the magstep is in the range of the radio buttons, we
* need to turn the correct one on and the old one off.
*/
if(magstep >= MGV_MAGMIN && magstep <= MGV_MAGMAX) {
sprintf(s, "*menuBar*magstep_pd*%d", magstep);
if(m->magstep != NULL)
XmToggleButtonSetState(m->magstep, False, False);
m->magstep = wl_find1(m->main, s);
XmToggleButtonSetState(m->magstep, True, False);
}
else {
if(m->magstep != NULL)
XmToggleButtonSetState(m->magstep, False, False);
m->magstep = NULL;
}
sprintf(s, "%+d", magstep);
/*
* Update the status line thingy.
*/
XtVaSetValues(wl_find1(m->main, "*statusLine*magstepFrame*value"),
XtVaTypedArg, XmNlabelString,
XtRString, s,
strlen(s) + 1,
NULL);
/*
* Update the magstepdlg->set dialog (if it exists).
*/
if(m->magstepdlg != NULL) {
Arg a;
XtSetArg(a, XmNvalue, s);
XtSetValues(wl_find1(m->magstepdlg, "*text"), &a, 1);
}
return different;
}
/*
* Magstep->increase
*/
void
mgv_magstep_increase(Widget w, XtPointer closure, XtPointer call)
{
MGV *m = (MGV *)closure;
USEUP(w); USEUP(call);
wl_assert(MgvOK(m));
if(mgv_ui_magnify(m, m->magnification + 1))
mgv_show(m, m->page);
}
/*
* Magstep->decrease
*/
void
mgv_magstep_decrease(Widget w, XtPointer closure, XtPointer call)
{
MGV *m = (MGV *)closure;
USEUP(w); USEUP(call);
wl_assert(MgvOK(m));
if(mgv_ui_magnify(m, m->magnification - 1))
mgv_show(m, m->page);
}
/*
* magstep->set
*/
static WLW inner_form[] = {
{"label", wlLabel, 0, NULL},
{"decr", wlArrowB, 0, NULL},
{"incr", wlArrowB, 0, NULL},
{"text", wlTextField, 0, NULL},
{NULL, NULL, 0, NULL}
};
static WLW magstep_form[] = {
{"form", wlForm, WL_MANAGE, inner_form},
{"apply", wlPushB, 0, NULL},
{"dismiss", wlPushB, 0, NULL},
{"help", wlPushB, 0, NULL},
{"sep", wlSeparator, 0, NULL},
{NULL, NULL, 0, NULL}
};
static WLW magstep_dlg[] = {
{"magstepDialog", wlFormDialog, 0, magstep_form},
{NULL, NULL, 0, NULL}
};
static void
magstep_apply(Widget w, XtPointer closure, XtPointer call)
{
MGV *m = (MGV *)closure;
String s;
Arg a;
USEUP(w); USEUP(call);
wl_assert(MgvOK(m));
XtSetArg(a, XmNvalue, &s);
XtGetValues(wl_find1(m->magstepdlg, "*text"), &a, 1);
if(mgv_ui_magnify(m, atoi(s)))
mgv_show(m, m->page);
wl_dlg_popdown(m->magstepdlg);
}
static void
magstep_updown(Widget w, XtPointer closure, XtPointer call)
{
MGV *m = (MGV *)closure;
int n;
String s;
char buf[64];
USEUP(call);
wl_assert(MgvOK(m));
switch(*XtName(w)) {
case 'i': n = +1; break;
case 'd': n = -1; break;
default: wl_assert("arrow buttons are busted!" != NULL); return;
}
w = wl_find1(m->magstepdlg, "*text");
sprintf(buf, "%+d", atoi(s = XmTextFieldGetString(w)) + n);
XtFree(s);
XmTextFieldSetString(w, buf);
}
static WLC magstep_cb[] = {
{"*incr", XmNactivateCallback, NULL, magstep_updown},
{"*decr", XmNactivateCallback, NULL, magstep_updown},
{"*apply", XmNactivateCallback, NULL, magstep_apply},
{"*dismiss", XmNactivateCallback, NULL, wl_dismiss},
{"*help", XmNactivateCallback, NULL, wl_help},
{NULL, NULL, NULL, NULL}
};
void
mgv_magstep_set(Widget w, XtPointer closure, XtPointer call)
{
MGV *m = (MGV *)closure;
USEUP(w); USEUP(call);
wl_assert(MgvOK(m));
if(m->magstepdlg == NULL) {
char s[64];
m->magstepdlg = wl_create(m->main, magstep_dlg);
wl_callback(m->magstepdlg, &magstep_cb[0], (XtPointer)m);
sprintf(s, "%+d", m->magnification);
XmTextFieldSetString(wl_find1(m->magstepdlg, "*text"), s);
}
wl_dlg_popup(m->magstepdlg);
}
void
mgv_magstep_edit(Widget w, XtPointer closure, XtPointer call)
{
MGV *m = (MGV *)closure;
Widget text;
Arg a;
USEUP(w); USEUP(call);
wl_assert(MgvOK(m));
text = wl_find1(m->main, "*statusLine*magstepFrame*text");
XtManageChild(text);
XtSetArg(a, XmNrightWidget, text);
XtSetValues(wl_find1(m->main, "*statusLine*magstepFrame*label"), &a, 1);
XtUnmanageChild(wl_find1(m->main, "*statusLine*magstepFrame*value"));
XmProcessTraversal(text, XmTRAVERSE_CURRENT);
}
void
mgv_magstep_text(Widget w, XtPointer closure, XtPointer call)
{
MGV *m = (MGV *)closure;
Widget label, text, value;
String s;
Arg a;
USEUP(w);
wl_assert(MgvOK(m));
wl_find(m->main,
&text, "*statusLine*magstepFrame*text",
&label, "*statusLine*magstepFrame*label",
&value, "*statusLine*magstepFrame*value",
NULL);
XtUnmanageChild(text);
XtManageChild(value);
XtSetArg(a, XmNrightWidget, value);
XtSetValues(label, &a, 1);
if(((XmAnyCallbackStruct *)call)->reason == XmCR_ACTIVATE) {
Arg a;
XtSetArg(a, XmNvalue, &s);
XtGetValues(text, &a, 1);
if(mgv_ui_magnify(m, atoi(s)))
mgv_show(m, m->page);
}
}
void
mgv_magstep_n(Widget w, XtPointer closure, XtPointer call)
{
MGV *m = (MGV *)closure;
XmTBS *cbs = (XmTBS *)call;
int magstep;
wl_assert(MgvOK(m));
if(!cbs->set)
return;
magstep = atoi(XtName(w));
wl_assert(magstep >= MGV_MAGMIN && magstep <= MGV_MAGMAX);
if(mgv_ui_magnify(m, magstep))
mgv_show(m, m->page);
}