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
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
|
/*
*
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
*/
#include <X11/Xmu/EditresP.h>
#include <X11/Xresource.h>
#define DEBUG
#ifdef DEBUG
# define CLIENT_TIME_OUT 60000 /* wait sixty seconds for the client. */
#else
# define CLIENT_TIME_OUT 5000 /* wait five seconds for the client. */
#endif /* DEBUG */
#define PROTOCOL_VERSION_ONE_POINT_ONE 5 /* version 1.1 */
#define ONE_POINT_ONE_STRING "1.1"
#define PROTOCOL_VERSION_ONE_POINT_ZERO 4 /* version 1.0 */
#define ONE_POINT_ZERO_STRING "1.0" ONE_POINT_ONE_STRING
#define CURRENT_PROTOCOL_VERSION PROTOCOL_VERSION_ONE_POINT_ONE
#define CURRENT_PROTOCOL_VERSION_STRING ONE_POINT_ONE_STRING
#define FLASH_TIME 1000 /* Default flash time in microseconds */
#define NUM_FLASHES 3 /* Default number of flashes. */
#define NO_IDENT 0 /* an ident that will match nothing. */
#define NUM_INC 10 /* amount to increment allocators. */
#define ANY_RADIO_DATA ("the any widget")
#define RESOURCE_BOX ("resourceBox")
/*
* Retrieving ResType and Boolean is the same as retrieving a Card8 except
* possibly for signedness.
*/
#define _XEditResGetBoolean(_s, _r) _XEditResGet8((_s), (unsigned char *)(_r))
#define _XEditResGetResType _XEditResGet8
/*
* Contexts to use with the X Context Manager.
*/
#define NODE_INFO ((XContext) 42)
/*
* Error codes for X Server errors.
*/
#define NO_ERROR 0
#define NO_WINDOW 1
typedef enum {LocalSendWidgetTree, LocalSetValues, LocalFindChild,
LocalFlashWidget, LocalGetGeometry, LocalGetResources,
LocalGetValues} ResCommand;
typedef enum {ClassLabel, NameLabel, IDLabel, WindowLabel,
ToggleLabel} LabelTypes;
typedef enum {SelectWidget, SelectAll, SelectNone, SelectInvert, SelectParent,
SelectChildren, SelectDescendants, SelectAncestors} SelectTypes;
typedef struct _NameInfo {
struct _NameInfo * next; /* Next element in the linked list. */
Widget sep_leader; /* The separator toggle group leader. */
Widget name_leader; /* The name toggle group leader. */
} NameInfo;
typedef struct _ResourceBoxInfo {
Widget value_wid; /* The string containing the value. */
Widget res_label; /* The label containing current resoruce. */
Widget shell; /* Shell widget containing resource box. */
Widget norm_list; /* The List widget for the normal list. */
Widget cons_list; /* The List widget for the
Constriaint Resources */
NameInfo * name_info; /* The info about the widgets for each
name and class in the instance heirarchy. */
} ResourceBoxInfo;
typedef struct _WidgetResourceInfo {
char * name, * class, *type; /* Name, Class and Type of each resource. */
} WidgetResourceInfo;
typedef struct _WidgetResources {
int num_normal, num_constraint;
WidgetResourceInfo *normal, *constraint;
ResourceBoxInfo * res_box;
} WidgetResources;
typedef struct _WNode {
char * name;
char * class;
unsigned long id, window;
struct _WNode * parent;
struct _WNode ** children;
struct _TreeInfo * tree_info;
Cardinal num_children, alloc_children;
Widget widget;
WidgetResources * resources;
} WNode;
/*
* Information for the Select any widget, toggle buttons in the resource
* boxes.
*/
typedef struct _AnyInfo {
WNode * node; /* A Pointer off to the node corrsponding to
this resource box. */
Widget left_dot, left_star; /* The dot and star widgets to our left. */
Widget right_dot, right_star; /* The dot and star widgets to our right. */
int left_count, *right_count; /* If count > 0 then desensitize the left or
right dot and star widgets. */
} AnyInfo;
/*
* Information about the client we are currently working with.
*/
typedef struct _CurrentClient {
ResCommand command; /* the command sent. */
ResIdent ident;
ProtocolStream stream; /* protocol stream for this client. */
XtIntervalId timeout; /* timeout set in case he doesn't answer. */
Window window; /* window to communicate with. */
Atom atom; /* Atom used to communicate with this client.*/
} CurrentClient;
/*
* Information about a tree we can display.
*/
typedef struct _TreeInfo {
Widget tree_widget; /* The Tree widget that contains all nodes */
WNode * top_node; /* The top node in the tree. */
WNode ** active_nodes; /* The currently active nodes. */
Cardinal num_nodes, alloc_nodes; /* number of active nodes, and space */
Widget * flash_widgets; /* list of widgets to flash on and off. */
Cardinal num_flash_widgets, alloc_flash_widgets; /* number of flash wids.*/
} TreeInfo;
/*
* Information specific to a give APPLICATION screen.
*/
typedef struct _ScreenData {
Widget set_values_popup; /* The SetValues popup. */
Widget res_text; /* SetValues resource text widget. */
Widget val_text; /* SetValues value text widget. */
Widget info_label; /* The information label. */
} ScreenData;
typedef struct _AppResources {
Boolean debug; /* Is debugging on? */
int num_flashes, flash_time; /* Number and duration of flashes. */
Pixel flash_color; /* Color of flash window. */
char * save_resources_file; /* File to save the resources into. */
/* Private state */
Boolean allocated_save_resources_file;
} AppResources;
/*
* Information needed to apply the resource string to all widgets.
*/
typedef struct _ApplyResourcesInfo {
char * name, *class; /* name and class of this resource. */
unsigned short count;
ProtocolStream * stream;
XrmDatabase database;
} ApplyResourcesInfo;
/*
* Information needed to get a resource string from a widget.
*/
typedef struct _ObtainResourcesInfo {
char * name, *class; /* name and class of this resource. */
unsigned short count;
ProtocolStream * stream;
XrmDatabase database;
} ObtainResourcesInfo;
/************************************************************
*
* The Event Structures.
*
************************************************************/
typedef struct _AnyEvent {
EditresCommand type;
} AnyEvent;
typedef struct _WidgetTreeInfo {
WidgetInfo widgets;
char * name;
char * class;
unsigned long window;
} WidgetTreeInfo;
typedef struct _SendWidgetTreeEvent {
EditresCommand type;
char * toolkit;
unsigned short num_entries;
WidgetTreeInfo * info;
} SendWidgetTreeEvent;
typedef struct _SetValuesInfo {
WidgetInfo widgets;
char * message;
} SetValuesInfo;
typedef struct _SetValuesEvent {
EditresCommand type;
unsigned short num_entries;
SetValuesInfo * info;
} SetValuesEvent;
typedef struct _GetValuesInfo {
WidgetInfo widgets;
char * value;
} GetValuesInfo;
typedef struct _GetValuesEvent {
EditresCommand type;
unsigned short num_entries;
GetValuesInfo * info;
} GetValuesEvent;
typedef struct _ResourceInfo {
ResourceType res_type;
char * name, *class, *type;
} ResourceInfo;
typedef struct _GetResourcesInfo {
WidgetInfo widgets;
Boolean error;
char * message;
unsigned short num_resources;
ResourceInfo * res_info;
} GetResourcesInfo;
typedef struct _GetResourcesEvent {
EditresCommand type;
unsigned short num_entries;
GetResourcesInfo * info;
} GetResourcesEvent;
typedef struct _GetGeomInfo {
EditresCommand type;
WidgetInfo widgets;
Boolean error;
char * message;
Boolean visable;
short x, y;
unsigned short width, height, border_width;
} GetGeomInfo;
typedef struct _GetGeomEvent {
EditresCommand type;
unsigned short num_entries;
GetGeomInfo * info;
} GetGeomEvent;
typedef struct _FindChildEvent {
EditresCommand type;
WidgetInfo widgets;
} FindChildEvent;
typedef union _Event {
AnyEvent any_event;
SendWidgetTreeEvent send_widget_tree_event;
SetValuesEvent set_values_event;
GetResourcesEvent get_resources_event;
GetGeomEvent get_geom_event;
FindChildEvent find_child_event;
GetValuesEvent get_values_event;
} Event;
/*
* number of application resource labels.
*/
#define NUM_RES_LABELS 37
/*
* Global variables.
*/
extern int global_effective_protocol_version;
extern char* global_effective_toolkit;
extern int global_error_code;
extern unsigned long global_serial_num;
extern int (*global_old_error_handler)(Display *, XErrorEvent *);
extern Boolean global_resource_box_up;
extern TreeInfo *global_tree_info;
extern CurrentClient global_client;
extern ScreenData global_screen_data;
extern Widget global_tree_parent;
extern Widget global_paned; /* named after toolkit */
extern Widget global_toplevel;
extern AppResources global_resources;
extern String res_labels[NUM_RES_LABELS];
extern Boolean do_get_values;
extern Atom wm_delete_window;
/* number of entries in the command menu */
#define NUM_CM_ENTRIES 8
extern Widget CM_entries[NUM_CM_ENTRIES];
/* number of entries in the tree menu */
#define NUM_TM_ENTRIES 16
extern Widget TM_entries[NUM_TM_ENTRIES];
/*
* Macros.
*/
#define streq(a, b) ( strcmp((a), (b)) == 0 )
/* offset into CM entries for setting insensitive */
#define CM_OFFSET 1
/* number of CM entries to make insensitive */
#define CM_NUM 5
#define TM_OFFSET 0
#define TM_NUM 16
/*
* Prototypes
*/
extern void ActivateResourceWidgets ( Widget w, XtPointer node_ptr, XtPointer junk );
extern void ActivateWidgetsAndSetResourceString ( Widget w, XtPointer node_ptr, XtPointer call_data );
extern void AddString ( char ** str, char *add );
extern void AddTreeNode ( Widget tree, WNode * top );
extern void AnyChosen ( Widget w, XtPointer any_info_ptr, XtPointer state_ptr );
extern void ApplyResource ( Widget w, XtPointer node_ptr, XtPointer junk );
extern void BuildVisualTree ( Widget tree_parent, Event * event );
extern void BuildWidgetTree ( Widget parent );
extern Boolean CheckDatabase ( XrmDatabase db, XrmQuarkList names, XrmQuarkList classes );
extern void CreateResourceBox ( WNode * node, char ** errors );
extern void CreateResourceBoxWidgets ( WNode * node, char **names, char **cons_names );
extern TreeInfo * CreateTree ( Event * event );
extern void DisplayChild ( Event * event );
extern void DumpTreeToFile ( Widget w, XtPointer junk, XtPointer garbage );
extern void ExecuteOverAllNodes ( WNode * top_node, void (*func)(WNode *, XtPointer), XtPointer data );
extern WNode * FindNode ( WNode *top_node, unsigned long * ids, Cardinal number );
extern void FindWidget ( Widget w, XtPointer client_data, XtPointer call_data );
extern WNode * FindWidgetFromWindow ( TreeInfo * tree_info, Window win );
extern void FlashActiveWidgets ( Widget w, XtPointer junk, XtPointer garbage );
extern void GetAllStrings ( char *in, char sep, char ***out, int * num );
extern Window GetClientWindow ( Widget w, int *x, int *y );
extern char * GetFailureMessage ( ProtocolStream * stream );
extern void GetNamesAndClasses ( WNode * node, char *** names, char ***classes );
extern ResIdent GetNewIdent ( void );
extern void GetResourceList ( Widget w, XtPointer junk, XtPointer garbage );
extern char * GetResourceValueForSetValues ( WNode * node, unsigned short * size );
extern char * HandleFlashWidget ( Event * event );
extern char * HandleGetResources ( Event * event );
extern int HandleXErrors ( Display * display, XErrorEvent * error );
extern void InitSetValues ( Widget w, XtPointer client_data, XtPointer call_data );
extern void InsertWidgetFromNode ( ProtocolStream * stream, WNode * node );
extern void InternAtoms ( Display * dpy );
extern void LayoutTree ( Widget tree );
extern int main ( int argc, char **argv );
extern void ModifySVEntry ( Widget w, XEvent *event, String * params, Cardinal * num_params );
extern void PannerCallback ( Widget w, XtPointer closure, XtPointer report_ptr );
extern void PerformTreeToFileDump ( WNode * node, int num_tabs, FILE * fp );
extern void PopdownResBox ( Widget w, XtPointer shell_ptr, XtPointer junk );
extern void PopupCentered ( XEvent * event, Widget w, XtGrabKind mode );
extern void PopupSetValues ( Widget parent, XEvent * event );
extern void PortholeCallback ( Widget w, XtPointer panner_ptr, XtPointer report_ptr );
extern void PrepareToLayoutTree ( Widget tree );
extern void PrintNodes ( WNode * top );
extern char * PrintSetValuesError ( Event * event );
extern char * ProtocolFailure ( ProtocolStream * stream );
extern XrmQuarkList Quarkify ( char ** list, char * ptr );
extern void Quit ( Widget w, XtPointer client_data, XtPointer call_data );
extern void RebuildMenusAndLabel ( String toolkit );
extern void ResourceListCallback ( Widget list, XtPointer node_ptr, XtPointer junk );
extern void SaveResource ( Widget w, XtPointer res_box_ptr, XtPointer junk );
extern void SendTree ( Widget w, XtPointer value, XtPointer call_data );
extern void SetAndCenterTreeNode ( WNode * node );
extern void SetApplicationActions ( XtAppContext app_con );
extern void SetCommand ( Widget w, ResCommand command, char * msg );
extern void SetEntriesSensitive ( Widget *entries, int num, Boolean sensitive );
extern void SetFile ( Widget w, XtPointer junk, XtPointer garbage );
extern void SetMessage ( Widget w, char * str );
extern void SetResourceString ( Widget w, XtPointer node_ptr, XtPointer junk );
extern void TreeRelabel ( Widget w, XtPointer client_data, XtPointer call_data );
extern void TreeSelect ( Widget w, XtPointer client_data, XtPointer call_data );
extern void TreeToggle ( Widget w, XtPointer node_ptr, XtPointer state_ptr );
extern void _DumpTreeToFile ( Widget w, XtPointer tree_ptr, XtPointer filename );
extern void _FindWidget ( Widget w );
extern void _FlashActiveWidgets ( TreeInfo * tree_info );
extern void _PopdownFileDialog ( Widget w, XtPointer client_data, XtPointer junk );
extern void _PopupFileDialog ( Widget w, String str, String default_value, XtCallbackProc func, XtPointer data );
extern void _TreeActivateNode ( WNode * node, SelectTypes type );
extern void _TreeRelabel ( TreeInfo * tree_info, LabelTypes type );
extern void _TreeRelabelNode ( WNode * node, LabelTypes type, Boolean recurse );
extern void _TreeSelect ( TreeInfo * tree_info, SelectTypes type );
extern void _TreeSelectNode ( WNode * node, SelectTypes type, Boolean recurse );
|