1 /*
2 *
3 Copyright 1989, 1998 The Open Group
4
5 Permission to use, copy, modify, distribute, and sell this software and its
6 documentation for any purpose is hereby granted without fee, provided that
7 the above copyright notice appear in all copies and that both that
8 copyright notice and this permission notice appear in supporting
9 documentation.
10
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
13
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
21 Except as contained in this notice, the name of The Open Group shall not be
22 used in advertising or otherwise to promote the sale, use or other dealings
23 in this Software without prior written authorization from The Open Group.
24 *
25 * Author: Chris D. Peterson, MIT X Consortium
26 */
27
28 #include <X11/Intrinsic.h>
29 #include <X11/StringDefs.h> /* Get standard string definations. */
30 #include <X11/Xatom.h>
31 #include <X11/cursorfont.h>
32 #include <X11/Shell.h>
33
34 #include <X11/Xaw/AsciiText.h>
35 #include <X11/Xaw/Cardinals.h>
36 #include <X11/Xaw/Command.h>
37 #include <X11/Xaw/Form.h>
38 #include <X11/Xaw/Label.h>
39
40 #include <stdio.h>
41
42 #ifdef XKB
43 #include <X11/extensions/XKBbells.h>
44 #endif
45
46 #include "editresP.h"
47
48 static void _SetField ( Widget new, Widget old );
49 static void CreateSetValuesPopup ( Widget parent, ScreenData * scr_data );
50 static void DoSetValues ( Widget w, XtPointer junk, XtPointer garbage );
51 static void CancelSetValues ( Widget w, XtPointer junk, XtPointer garbage );
52
53 /* Function Name: PopupSetValues
54 * Description: This function pops up the setvalues dialog
55 * Arguments: parent - the parent of the setvalues popup.
56 * event - the event that caused this popup, or NULL.
57 * Returns: none
58 */
59
60 /* ARGSUSED */
61 void
PopupSetValues(Widget parent,XEvent * event)62 PopupSetValues(Widget parent, XEvent *event)
63 {
64 Arg args[1];
65
66 if (global_tree_info == NULL) {
67 SetMessage(global_screen_data.info_label,
68 res_labels[17]);
69 return;
70 }
71
72 /*
73 * Check and possibly create the popup.
74 */
75
76 if (global_screen_data.set_values_popup == NULL)
77 CreateSetValuesPopup(parent, &global_screen_data);
78
79 /*
80 * Clear out the old strings, and set the active widget to the name widget.
81 */
82
83 XtSetArg(args[0], XtNstring, "");
84 XtSetValues(global_screen_data.res_text, args, ONE);
85 XtSetValues(global_screen_data.val_text, args, ONE);
86
87 _SetField(global_screen_data.res_text, global_screen_data.val_text);
88
89 /*
90 * Pop it up.
91 */
92
93 PopupCentered(event, global_screen_data.set_values_popup, XtGrabNone);
94 }
95
96 /* Function Name: ModifySVEntry
97 * Description: Action routine that can be bound to the set values
98 * dialog box's Text Widget that will send input to the
99 * field specified.
100 * Arguments: (Standard Action Routine args)
101 * Returns: none.
102 */
103
104 /* ARGSUSED */
105 void
ModifySVEntry(Widget w,XEvent * event,String * params,Cardinal * num_params)106 ModifySVEntry(Widget w, XEvent *event, String *params, Cardinal *num_params)
107 {
108 Widget new, old;
109 char msg[BUFSIZ];
110
111 if (*num_params != 1) {
112 strcpy(msg,
113 res_labels[21]);
114 SetMessage(global_screen_data.info_label, msg);
115 return;
116 }
117
118 switch (params[0][0]) {
119 case 'r':
120 case 'R':
121 new = global_screen_data.res_text;
122 old = global_screen_data.val_text;
123 break;
124 case 'v':
125 case 'V':
126 new = global_screen_data.val_text;
127 old = global_screen_data.res_text;
128 break;
129 default:
130 snprintf(msg, sizeof(msg), res_labels[22]);
131 SetMessage(global_screen_data.info_label, msg);
132 return;
133 }
134
135 _SetField(new, old);
136 }
137
138 /************************************************************
139 *
140 * Private Functions
141 *
142 ************************************************************/
143
144 /* Function Name: _SetField
145 * Description: Sets the current text entry field.
146 * Arguments: new, old - new and old text fields.
147 * Returns: none
148 */
149
150 static void
_SetField(Widget new,Widget old)151 _SetField(Widget new, Widget old)
152 {
153 Arg args[2];
154 Pixel new_border, old_border, old_bg;
155
156 if (!XtIsSensitive(new)) {
157 #ifdef XKB
158 /* Don't set field to an inactive Widget. */
159 XkbStdBell(XtDisplay(old), XtWindow(new), 0, XkbBI_InvalidLocation);
160 #else
161 XBell(XtDisplay(old), 0); /* Don't set field to an inactive Widget. */
162 #endif
163 return;
164 }
165
166 XtSetKeyboardFocus(XtParent(new), new);
167
168 XtSetArg(args[0], XtNborderColor, &old_border);
169 XtSetArg(args[1], XtNbackground, &old_bg);
170 XtGetValues(new, args, TWO);
171
172 XtSetArg(args[0], XtNborderColor, &new_border);
173 XtGetValues(old, args, ONE);
174
175 if (old_border != old_bg) /* Colors are already correct, return. */
176 return;
177
178 XtSetArg(args[0], XtNborderColor, old_border);
179 XtSetValues(old, args, ONE);
180
181 XtSetArg(args[0], XtNborderColor, new_border);
182 XtSetValues(new, args, ONE);
183 }
184
185 /* Function Name: CreateSetValuesPopup
186 * Description: Creates the setvalues popup.
187 * Arguments: parent - the parent of the popup.
188 * scr_data - the data about this screen.
189 * Returns: the set values popup.
190 */
191
192 static void
CreateSetValuesPopup(Widget parent,ScreenData * scr_data)193 CreateSetValuesPopup(Widget parent, ScreenData *scr_data)
194 {
195 Widget form, cancel, do_it, label;
196 Widget res_label;
197 Arg args[10];
198 Cardinal num_args;
199
200 scr_data->set_values_popup = XtCreatePopupShell("setValuesPopup",
201 transientShellWidgetClass,
202 parent, NULL, ZERO);
203
204 form = XtCreateManagedWidget("form", formWidgetClass,
205 scr_data->set_values_popup, NULL, ZERO);
206
207 num_args = 0;
208 label = XtCreateManagedWidget("label", labelWidgetClass,
209 form, args, num_args);
210
211
212 num_args = 0;
213 XtSetArg(args[num_args], XtNfromVert, label); num_args++;
214 res_label = XtCreateManagedWidget("resourceLabel", labelWidgetClass,
215 form, args, num_args);
216
217 num_args = 0;
218 XtSetArg(args[num_args], XtNfromVert, label); num_args++;
219 XtSetArg(args[num_args], XtNfromHoriz, res_label); num_args++;
220 scr_data->res_text = XtCreateManagedWidget("resourceText",
221 asciiTextWidgetClass,
222 form, args, num_args);
223
224 num_args = 0;
225 XtSetArg(args[num_args], XtNfromVert, scr_data->res_text); num_args++;
226 (void) XtCreateManagedWidget("valueLabel", labelWidgetClass,
227 form, args, num_args);
228
229 num_args = 0;
230 XtSetArg(args[num_args], XtNfromHoriz, res_label); num_args++;
231 XtSetArg(args[num_args], XtNfromVert, scr_data->res_text); num_args++;
232 scr_data->val_text = XtCreateManagedWidget("valueText",
233 asciiTextWidgetClass,
234 form, args, num_args);
235
236 num_args = 0;
237 XtSetArg(args[num_args], XtNfromVert, scr_data->val_text); num_args++;
238 do_it = XtCreateManagedWidget("setValues", commandWidgetClass,
239 form, args, num_args);
240
241 num_args = 0;
242 XtSetArg(args[num_args], XtNfromVert, scr_data->val_text); num_args++;
243 XtSetArg(args[num_args], XtNfromHoriz, do_it); num_args++;
244 cancel = XtCreateManagedWidget("cancel", commandWidgetClass,
245 form, args, num_args);
246
247 XtAddCallback(do_it, XtNcallback, DoSetValues, NULL);
248 XtAddCallback(cancel, XtNcallback, CancelSetValues, NULL);
249
250 /*
251 * Initialize the text entry fields.
252 */
253
254 {
255 Pixel color;
256
257 num_args = 0;
258 XtSetArg(args[num_args], XtNbackground, &color); num_args++;
259 XtGetValues(scr_data->val_text, args, num_args);
260
261 num_args = 0;
262 XtSetArg(args[num_args], XtNborderColor, color); num_args++;
263 XtSetValues(scr_data->val_text, args, num_args);
264
265 XtSetKeyboardFocus(form, scr_data->res_text);
266 }
267 }
268
269 /* Function Name: DoSetValues
270 * Description: Performs a SetValues.
271 * Arguments: w - the widget that called this.
272 * junk, garbage - ** UNUSED **.
273 * Returns: none.
274 */
275
276 /* ARGSUSED */
277 static void
DoSetValues(Widget w,XtPointer junk,XtPointer garbage)278 DoSetValues(Widget w, XtPointer junk, XtPointer garbage)
279 {
280 ProtocolStream * stream = &(global_client.stream);
281 char *res_name, *res_value;
282 Arg args[1];
283 Cardinal i;
284
285 if (global_tree_info->num_nodes == 0) {
286 SetMessage(global_screen_data.info_label,
287 res_labels[23]);
288 return;
289 }
290
291 XtSetArg(args[0], XtNstring, &res_name);
292 XtGetValues(global_screen_data.res_text, args, ONE);
293
294 XtSetArg(args[0], XtNstring, &res_value);
295 XtGetValues(global_screen_data.val_text, args, ONE);
296
297 _XEditResResetStream(stream);
298 _XEditResPutString8(stream, res_name);
299 _XEditResPutString8(stream, XtRString);
300 _XEditResPutString8(stream, res_value);
301 _XEditResPut16(stream, global_tree_info->num_nodes);
302
303 for (i = 0; i < global_tree_info->num_nodes; i++)
304 InsertWidgetFromNode(stream, global_tree_info->active_nodes[i]);
305
306 SetCommand(w, LocalSetValues, NULL);
307 }
308
309 /* Function Name: CancelSetValues
310 * Description: Pops down the setvalues popup.
311 * Arguments: w - any grandchild of the popup.
312 * junk, garbage - ** UNUSED **.
313 * Returns: none.
314 */
315
316 /* ARGSUSED */
317 static void
CancelSetValues(Widget w,XtPointer junk,XtPointer garbage)318 CancelSetValues(Widget w, XtPointer junk, XtPointer garbage)
319 {
320 XtPopdown(XtParent(XtParent(w)));
321 }
322