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
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
|
/*
*
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.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <stdio.h>
#include <stdlib.h>
#include <X11/Intrinsic.h>
#include <X11/Xutil.h>
#include <X11/Xaw/Cardinals.h>
#include <X11/Xmu/CharSet.h>
#include "editresP.h"
/*
* Private data.
*/
//struct ActionValues {
// String name;
// int type;
//};
struct ActionValues {
const char * name;
int type;
};
static struct ActionValues select_values[] = {
{ "widget", (int) SelectWidget },
{ "all", (int) SelectAll },
{ "nothing", (int) SelectNone },
{ "invert", (int) SelectInvert },
{ "children", (int) SelectChildren },
{ "descendants", (int) SelectDescendants },
{ "parent", (int) SelectParent },
{ "ancestors", (int) SelectAncestors }
};
static struct ActionValues label_values[] = {
{ "name", (int) NameLabel },
{ "class", (int) ClassLabel },
{ "id", (int) IDLabel },
{ "window", (int) WindowLabel },
{ "toggle", (int) ToggleLabel }
};
static void EnableGetVal ( Widget w, XEvent *event,
String *params, Cardinal * num_params );
static void SelectAction ( Widget w, XEvent *event,
String *params, Cardinal *num_params );
static void RelabelAction ( Widget w, XEvent *event,
String *params, Cardinal *num_params );
static void PopdownFileDialogAction ( Widget w, XEvent *event,
String *params, Cardinal *num_params );
static void ActionQuit ( Widget w, XEvent *event,
String *params, Cardinal *num_params );
static WNode * FindTreeNodeFromWidget ( Widget w );
static Boolean CheckAndFindEntry ( const char *action_name,
String * params, Cardinal num_params,
struct ActionValues * table,
Cardinal num_table, int * type );
/* Function Name: EnableGetVal
* Description: sets a global variable to notify the Notify action
* for the resource list widet to do GetValues.
* Arguments: w - any widget in the widget tree.
* event - NOT USED.
* params, num_params - the parameters paseed to the action
* routine.
*
*/
Boolean do_get_values = False;
/* ARGSUSED */
static void
EnableGetVal(Widget w, XEvent *event, String *params, Cardinal *num_params)
{
do_get_values = True;
}
/* Function Name: SelectAction
* Description:
* Arguments: w - any widget in the widget tree.
* event - NOT USED.
* params, num_params - the parameters paseed to the action
* routine.
*
* params[0] - One of "nothing", "parent", "children", "ancestors",
* "descendants", "invert", "all"
* num_params - must be one.
*/
/* ARGSUSED */
static void
SelectAction(Widget w, XEvent *event, String *params, Cardinal *num_params)
{
WNode * node;
int type;
if (!CheckAndFindEntry("Select", params, *num_params,
select_values, XtNumber(select_values), &type))
return;
switch(type) {
case SelectAll:
case SelectNone:
case SelectInvert:
_TreeSelect(global_tree_info, (SelectTypes)type);
break;
case SelectWidget:
_FindWidget(XtParent(w));
break;
default:
node = FindTreeNodeFromWidget(w);
if (node)
_TreeActivateNode(node, (SelectTypes)type);
else
_TreeSelect(global_tree_info, (SelectTypes)type);
break;
}
}
/* Function Name: RelabelAction
* Description:
* Arguments: w - any widget in the widget tree.
* event - NOT USED.
* params, num_params - the parameters paseed to the action
* routine.
*
* params[0] - One of "name", "class", "id"
* num_params - must be one.
*/
/* ARGSUSED */
static void
RelabelAction(Widget w, XEvent *event, String *params, Cardinal *num_params)
{
WNode * node;
int type;
if (!CheckAndFindEntry("Relabel", params, *num_params,
label_values, XtNumber(label_values), &type))
return;
if ((node = FindTreeNodeFromWidget(w)) == NULL)
_TreeRelabel(global_tree_info, (LabelTypes)type);
else {
PrepareToLayoutTree(global_tree_info->tree_widget);
_TreeRelabelNode(node, (LabelTypes)type, FALSE);
LayoutTree(global_tree_info->tree_widget);
}
}
/* Function Name: PopdownFileDialogAction
* Description: Pops down the file dialog widget.
* and calls the approipriate handler.
* Arguments: w - any child of the dialog widget.
* event - the event that caused this action.
* params, num_params - params passed to the action routine.
* RETURNED none.
*/
/* ARGSUSED */
static void
PopdownFileDialogAction(Widget w, XEvent *event,
String *params, Cardinal *num_params)
{
char buf[BUFSIZ];
Boolean val;
if (*num_params != 1) {
snprintf(buf, sizeof(buf), res_labels[2], "PopdownFileDialog");
SetMessage(global_screen_data.info_label, buf);
return;
}
XmuCopyISOLatin1Lowered(buf, params[0]);
if (streq(buf, "cancel"))
val = FALSE;
else if (streq(buf, "okay"))
val = TRUE;
else {
snprintf(buf, sizeof(buf), res_labels[1], "PopdownFileDialog");
SetMessage(global_screen_data.info_label, buf);
return;
}
_PopdownFileDialog(w, (XtPointer)(long) val, NULL);
}
/* Function Name: ActionQuit
* Description: This function prints a message to stdout.
* Arguments: w - ** UNUSED **
* call_data - ** UNUSED **
* client_data - ** UNUSED **
* Returns: none
*/
/* ARGSUSED */
static void
ActionQuit(Widget w, XEvent *event, String *params, Cardinal *num_params)
{
if (w==global_toplevel) {
XtDestroyApplicationContext(XtWidgetToApplicationContext(w));
exit(0);
}
else {
if (streq(XtName(w), RESOURCE_BOX))
global_resource_box_up = FALSE;
XtPopdown(w);
XtDestroyWidget(w);
}
}
/* Function Name: SetApplicationActions
* Description: Sets my application actions.
* Arguments: app_con - the application context.
* Returns: none.
*/
static XtActionsRec actions[] = {
{(String)"EnableGetVal", EnableGetVal},
{(String)"Select", SelectAction},
{(String)"SVActiveEntry", ModifySVEntry},
{(String)"Relabel", RelabelAction},
{(String)"PopdownFileDialog", PopdownFileDialogAction},
{(String)"quit", ActionQuit}
};
void
SetApplicationActions(XtAppContext app_con)
{
XtAppAddActions(app_con, actions, XtNumber(actions));
}
/************************************************************
*
* Private functions
*
************************************************************/
/* Function Name: CheckAndFindEntry
* Description: Checks the args to make sure they are valid,
* then parses the arg list to find the correct action
* to take.
* Arguments: action_name - name of the action (for error messages).
* params, num_params - params passed to the action routine.
* table, num_table - table to check the parameters against.
* RETURNED type - info about the action to take.
* Returns: TRUE if the arguments are okay.
*/
static Boolean
CheckAndFindEntry(const char *action_name, String *params, Cardinal num_params,
struct ActionValues *table, Cardinal num_table, int *type)
{
char buf[BUFSIZ];
Cardinal i;
if (num_params != 1) {
snprintf(buf, sizeof(buf), res_labels[2], action_name);
SetMessage(global_screen_data.info_label, buf);
return(FALSE);
}
XmuCopyISOLatin1Lowered(buf, params[0]);
for ( i = 0 ; i < num_table; i++ )
if (streq(buf, table[i].name)) {
*type = table[i].type;
return(TRUE);
}
snprintf(buf, sizeof(buf), res_labels[3], action_name);
for (i = 0; i < num_table; ) {
strcat(buf, table[i++].name);
if (i == (num_table - 1))
strcat(buf, ", or ");
else if (i < num_table)
strcat(buf, ", ");
}
SetMessage(global_screen_data.info_label, buf);
return(FALSE);
}
/* Function Name: FindTreeNodeFromWidget
* Description: finds the tree node associated with a widget.
* Arguments: w - widget to check.
* Returns: the node associated with this widget, or NULL.
*/
static WNode *
FindTreeNodeFromWidget(Widget w)
{
int ret_val;
XPointer data_return;
/*
* Yes, I really am casting a widget to a window ** TRUST ME ***
*/
ret_val = XFindContext(XtDisplay(w), (Window) w, NODE_INFO, &data_return);
if (ret_val == 0)
return((WNode *) data_return);
return(NULL);
}
|