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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
|
/*
*
Copyright 1989, 1998 The Open Group
Permission to use, copy, modify, distribute, and sell this software and its
documentation for any purpose is hereby granted without fee, provided that
the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation.
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the name of The Open Group shall not be
used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization from The Open Group.
*
* Author: Chris D. Peterson, MIT X Consortium
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h> /* Get standard string definitions. */
#include <X11/Xatom.h>
#include <X11/cursorfont.h>
#include <X11/Shell.h>
#include <X11/Xaw/AsciiText.h>
#include <X11/Xaw/Cardinals.h>
#include <X11/Xaw/Command.h>
#include <X11/Xaw/Form.h>
#include <X11/Xaw/Label.h>
#include <stdio.h>
#ifdef XKB
#include <X11/extensions/XKBbells.h>
#endif
#include "editresP.h"
static void _SetField ( Widget new, Widget old );
static void CreateSetValuesPopup ( Widget parent, ScreenData * scr_data );
static void DoSetValues ( Widget w, XtPointer junk, XtPointer garbage );
static void CancelSetValues ( Widget w, XtPointer junk, XtPointer garbage );
/* Function Name: PopupSetValues
* Description: This function pops up the setvalues dialog
* Arguments: parent - the parent of the setvalues popup.
* event - the event that caused this popup, or NULL.
* Returns: none
*/
/* ARGSUSED */
void
PopupSetValues(Widget parent, XEvent *event)
{
Arg args[1];
if (global_tree_info == NULL) {
SetMessage(global_screen_data.info_label,
res_labels[17]);
return;
}
/*
* Check and possibly create the popup.
*/
if (global_screen_data.set_values_popup == NULL)
CreateSetValuesPopup(parent, &global_screen_data);
/*
* Clear out the old strings, and set the active widget to the name widget.
*/
XtSetArg(args[0], (String)XtNstring, "");
XtSetValues(global_screen_data.res_text, args, ONE);
XtSetValues(global_screen_data.val_text, args, ONE);
_SetField(global_screen_data.res_text, global_screen_data.val_text);
/*
* Pop it up.
*/
PopupCentered(event, global_screen_data.set_values_popup, XtGrabNone);
}
/* Function Name: ModifySVEntry
* Description: Action routine that can be bound to the set values
* dialog box's Text Widget that will send input to the
* field specified.
* Arguments: (Standard Action Routine args)
* Returns: none.
*/
/* ARGSUSED */
void
ModifySVEntry(Widget w, XEvent *event, String *params, Cardinal *num_params)
{
Widget new, old;
char msg[BUFSIZ];
if (*num_params != 1) {
strcpy(msg,
res_labels[21]);
SetMessage(global_screen_data.info_label, msg);
return;
}
switch (params[0][0]) {
case 'r':
case 'R':
new = global_screen_data.res_text;
old = global_screen_data.val_text;
break;
case 'v':
case 'V':
new = global_screen_data.val_text;
old = global_screen_data.res_text;
break;
default:
snprintf(msg, sizeof(msg), res_labels[22]);
SetMessage(global_screen_data.info_label, msg);
return;
}
_SetField(new, old);
}
/************************************************************
*
* Private Functions
*
************************************************************/
/* Function Name: _SetField
* Description: Sets the current text entry field.
* Arguments: new, old - new and old text fields.
* Returns: none
*/
static void
_SetField(Widget new, Widget old)
{
Arg args[2];
Pixel new_border, old_border, old_bg;
if (!XtIsSensitive(new)) {
#ifdef XKB
/* Don't set field to an inactive Widget. */
XkbStdBell(XtDisplay(old), XtWindow(new), 0, XkbBI_InvalidLocation);
#else
XBell(XtDisplay(old), 0); /* Don't set field to an inactive Widget. */
#endif
return;
}
XtSetKeyboardFocus(XtParent(new), new);
XtSetArg(args[0], (String)XtNborderColor, &old_border);
XtSetArg(args[1], (String)XtNbackground, &old_bg);
XtGetValues(new, args, TWO);
XtSetArg(args[0], (String)XtNborderColor, &new_border);
XtGetValues(old, args, ONE);
if (old_border != old_bg) /* Colors are already correct, return. */
return;
XtSetArg(args[0], (String)XtNborderColor, old_border);
XtSetValues(old, args, ONE);
XtSetArg(args[0], (String)XtNborderColor, new_border);
XtSetValues(new, args, ONE);
}
/* Function Name: CreateSetValuesPopup
* Description: Creates the setvalues popup.
* Arguments: parent - the parent of the popup.
* scr_data - the data about this screen.
* Returns: the set values popup.
*/
static void
CreateSetValuesPopup(Widget parent, ScreenData *scr_data)
{
Widget form, cancel, do_it, label;
Widget res_label;
Arg args[10];
Cardinal num_args;
scr_data->set_values_popup = XtCreatePopupShell("setValuesPopup",
transientShellWidgetClass,
parent, NULL, ZERO);
form = XtCreateManagedWidget("form", formWidgetClass,
scr_data->set_values_popup, NULL, ZERO);
num_args = 0;
label = XtCreateManagedWidget("label", labelWidgetClass,
form, args, num_args);
num_args = 0;
XtSetArg(args[num_args], (String)XtNfromVert, label); num_args++;
res_label = XtCreateManagedWidget("resourceLabel", labelWidgetClass,
form, args, num_args);
num_args = 0;
XtSetArg(args[num_args], (String)XtNfromVert, label); num_args++;
XtSetArg(args[num_args], (String)XtNfromHoriz, res_label); num_args++;
scr_data->res_text = XtCreateManagedWidget("resourceText",
asciiTextWidgetClass,
form, args, num_args);
num_args = 0;
XtSetArg(args[num_args], (String)XtNfromVert, scr_data->res_text); num_args++;
(void) XtCreateManagedWidget("valueLabel", labelWidgetClass,
form, args, num_args);
num_args = 0;
XtSetArg(args[num_args], (String)XtNfromHoriz, res_label); num_args++;
XtSetArg(args[num_args], (String)XtNfromVert, scr_data->res_text); num_args++;
scr_data->val_text = XtCreateManagedWidget("valueText",
asciiTextWidgetClass,
form, args, num_args);
num_args = 0;
XtSetArg(args[num_args], (String)XtNfromVert, scr_data->val_text); num_args++;
do_it = XtCreateManagedWidget("setValues", commandWidgetClass,
form, args, num_args);
num_args = 0;
XtSetArg(args[num_args], (String)XtNfromVert, scr_data->val_text); num_args++;
XtSetArg(args[num_args], (String)XtNfromHoriz, do_it); num_args++;
cancel = XtCreateManagedWidget("cancel", commandWidgetClass,
form, args, num_args);
XtAddCallback(do_it, (String)XtNcallback, DoSetValues, NULL);
XtAddCallback(cancel, (String)XtNcallback, CancelSetValues, NULL);
/*
* Initialize the text entry fields.
*/
{
Pixel color;
num_args = 0;
XtSetArg(args[num_args], (String)XtNbackground, &color); num_args++;
XtGetValues(scr_data->val_text, args, num_args);
num_args = 0;
XtSetArg(args[num_args], (String)XtNborderColor, color); num_args++;
XtSetValues(scr_data->val_text, args, num_args);
XtSetKeyboardFocus(form, scr_data->res_text);
}
}
/* Function Name: DoSetValues
* Description: Performs a SetValues.
* Arguments: w - the widget that called this.
* junk, garbage - ** UNUSED **.
* Returns: none.
*/
/* ARGSUSED */
static void
DoSetValues(Widget w, XtPointer junk, XtPointer garbage)
{
ProtocolStream * stream = &(global_client.stream);
char *res_name, *res_value;
Arg args[1];
Cardinal i;
if (global_tree_info->num_nodes == 0) {
SetMessage(global_screen_data.info_label,
res_labels[23]);
return;
}
XtSetArg(args[0], (String)XtNstring, &res_name);
XtGetValues(global_screen_data.res_text, args, ONE);
XtSetArg(args[0], (String)XtNstring, &res_value);
XtGetValues(global_screen_data.val_text, args, ONE);
_XEditResResetStream(stream);
_XEditResPutString8(stream, res_name);
_XEditResPutString8(stream, XtRString);
_XEditResPutString8(stream, res_value);
_XEditResPut16(stream, global_tree_info->num_nodes);
for (i = 0; i < global_tree_info->num_nodes; i++)
InsertWidgetFromNode(stream, global_tree_info->active_nodes[i]);
SetCommand(w, LocalSetValues, NULL);
}
/* Function Name: CancelSetValues
* Description: Pops down the setvalues popup.
* Arguments: w - any grandchild of the popup.
* junk, garbage - ** UNUSED **.
* Returns: none.
*/
/* ARGSUSED */
static void
CancelSetValues(Widget w, XtPointer junk, XtPointer garbage)
{
XtPopdown(XtParent(XtParent(w)));
}
|