editresP.h revision 988795be
1
2/*
3 *
4Copyright 1989, 1998  The Open Group
5
6Permission to use, copy, modify, distribute, and sell this software and its
7documentation for any purpose is hereby granted without fee, provided that
8the above copyright notice appear in all copies and that both that
9copyright notice and this permission notice appear in supporting
10documentation.
11
12The above copyright notice and this permission notice shall be included in
13all copies or substantial portions of the Software.
14
15THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
18OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
19AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
22Except as contained in this notice, the name of The Open Group shall not be
23used in advertising or otherwise to promote the sale, use or other dealings
24in this Software without prior written authorization from The Open Group.
25 *
26 * Author:  Chris D. Peterson, MIT X Consortium
27 */
28
29#include <X11/Xmu/EditresP.h>
30#include <X11/Xresource.h>
31
32#define DEBUG
33
34#ifdef DEBUG
35#  define CLIENT_TIME_OUT 60000	/* wait sixty seconds for the client. */
36#else
37#  define CLIENT_TIME_OUT 5000	/* wait five seconds for the client. */
38#endif /* DEBUG */
39
40#define PROTOCOL_VERSION_ONE_POINT_ONE  5 /* version 1.1 */
41#define ONE_POINT_ONE_STRING "1.1"
42#define PROTOCOL_VERSION_ONE_POINT_ZERO 4 /* version 1.0 */
43#define ONE_POINT_ZERO_STRING "1.0" ONE_POINT_ONE_STRING
44
45#define CURRENT_PROTOCOL_VERSION PROTOCOL_VERSION_ONE_POINT_ONE
46#define CURRENT_PROTOCOL_VERSION_STRING ONE_POINT_ONE_STRING
47
48#define FLASH_TIME  1000	/* Default flash time in microseconds */
49#define NUM_FLASHES 3		/* Default number of flashes. */
50
51#define NO_IDENT 0		/* an ident that will match nothing. */
52
53#define NUM_INC 10		/* amount to increment allocators. */
54
55#define ANY_RADIO_DATA ("the any widget")
56#define RESOURCE_BOX ("resourceBox")
57
58
59/*
60 * Retrieving ResType and Boolean is the same as retrieving a Card8 except
61 * possibly for signedness.
62 */
63
64#define _XEditResGetBoolean(_s, _r) _XEditResGet8((_s), (unsigned char *)(_r))
65#define _XEditResGetResType _XEditResGet8
66
67/*
68 * Contexts to use with the X Context Manager.
69 */
70
71#define NODE_INFO ((XContext) 42)
72
73/*
74 * Error codes for X Server errors.
75 */
76
77#define NO_ERROR 0
78#define NO_WINDOW 1
79
80typedef enum {LocalSendWidgetTree, LocalSetValues, LocalFindChild,
81	      LocalFlashWidget, LocalGetGeometry, LocalGetResources,
82              LocalGetValues} ResCommand;
83
84typedef enum {ClassLabel, NameLabel, IDLabel, WindowLabel,
85	      ToggleLabel} LabelTypes;
86typedef enum {SelectWidget, SelectAll, SelectNone, SelectInvert, SelectParent,
87	      SelectChildren,  SelectDescendants, SelectAncestors} SelectTypes;
88
89typedef struct _NameInfo {
90    struct _NameInfo * next;	/* Next element in the linked list. */
91    Widget sep_leader;		/* The separator toggle group leader. */
92    Widget name_leader;		/* The name toggle group leader. */
93} NameInfo;
94
95typedef struct _ResourceBoxInfo {
96    Widget value_wid;		/* The string containing the value. */
97    Widget res_label;		/* The label containing current resoruce. */
98    Widget shell;		/* Shell widget containing resource box. */
99    Widget norm_list;		/* The List widget for the normal list. */
100    Widget cons_list;		/* The List widget for the
101				   Constriaint Resources */
102    NameInfo * name_info;	/* The info about the widgets for each
103				   name and class in the instance heirarchy. */
104} ResourceBoxInfo;
105
106typedef struct _WidgetResourceInfo {
107    char * name, * class, *type; /* Name, Class and Type of each resource. */
108} WidgetResourceInfo;
109
110typedef struct _WidgetResources {
111    int num_normal, num_constraint;
112    WidgetResourceInfo *normal, *constraint;
113    ResourceBoxInfo * res_box;
114} WidgetResources;
115
116typedef struct _WNode {
117    char * name;
118    char * class;
119    unsigned long id, window;
120    struct _WNode * parent;
121    struct _WNode ** children;
122    struct _TreeInfo * tree_info;
123    Cardinal num_children, alloc_children;
124    Widget widget;
125    WidgetResources * resources;
126} WNode;
127
128/*
129 * Information for the Select any widget, toggle buttons in the resource
130 * boxes.
131 */
132
133typedef struct _AnyInfo {
134    WNode * node;		/* A Pointer off to the node corrsponding to
135				   this resource box. */
136    Widget left_dot, left_star;	/* The dot and star widgets to our left. */
137    Widget right_dot, right_star; /* The dot and star widgets to our right. */
138    int left_count, *right_count; /* If count > 0 then desensitize the left or
139				    right dot and star widgets. */
140} AnyInfo;
141
142/*
143 * Information about the client we are currently working with.
144 */
145
146typedef struct _CurrentClient {
147    ResCommand command;		/* the command sent. */
148    ResIdent ident;
149    ProtocolStream stream;	/* protocol stream for this client. */
150    XtIntervalId timeout;	/* timeout set in case he doesn't answer. */
151    Window window;		/* window to communicate with. */
152    Atom atom;			/* Atom used to communicate with this client.*/
153} CurrentClient;
154
155/*
156 * Information about a tree we can display.
157 */
158
159typedef struct _TreeInfo {
160    Widget tree_widget;		/* The Tree widget that contains all nodes */
161    WNode * top_node;		/* The top node in the tree. */
162    WNode ** active_nodes;	/* The currently active nodes. */
163    Cardinal num_nodes, alloc_nodes; /* number of active nodes, and space */
164    Widget * flash_widgets;	/* list of widgets to flash on and off. */
165    Cardinal num_flash_widgets, alloc_flash_widgets; /* number of flash wids.*/
166} TreeInfo;
167
168/*
169 * Information specific to a give APPLICATION screen.
170 */
171
172typedef struct _ScreenData {
173    Widget set_values_popup;	/* The SetValues popup. */
174    Widget res_text;		/* SetValues resource text widget. */
175    Widget val_text;		/* SetValues value text widget. */
176    Widget info_label;	        /* The information label. */
177} ScreenData;
178
179typedef struct _AppResources {
180    Boolean debug;		/* Is debugging on? */
181    int num_flashes, flash_time; /* Number and duration of flashes. */
182    Pixel flash_color;		/* Color of flash window. */
183    char * save_resources_file;	/* File to save the resources into. */
184
185    /* Private state */
186    Boolean allocated_save_resources_file;
187} AppResources;
188
189/*
190 * Information needed to apply the resource string to all widgets.
191 */
192
193typedef struct _ApplyResourcesInfo {
194    char * name, *class;	/* name and class  of this resource. */
195    unsigned short count;
196    ProtocolStream * stream;
197    XrmDatabase database;
198} ApplyResourcesInfo;
199
200/*
201 * Information needed to get a resource string from a widget.
202 */
203
204typedef struct _ObtainResourcesInfo {
205    char * name, *class;	/* name and class  of this resource. */
206    unsigned short count;
207    ProtocolStream * stream;
208    XrmDatabase database;
209} ObtainResourcesInfo;
210
211/************************************************************
212 *
213 * The Event Structures.
214 *
215 ************************************************************/
216
217typedef struct _AnyEvent {
218    EditresCommand type;
219} AnyEvent;
220
221typedef struct _WidgetTreeInfo {
222    WidgetInfo widgets;
223    char * name;
224    char * class;
225    unsigned long window;
226} WidgetTreeInfo;
227
228typedef struct _SendWidgetTreeEvent {
229    EditresCommand type;
230    char * toolkit;
231    unsigned short num_entries;
232    WidgetTreeInfo * info;
233} SendWidgetTreeEvent;
234
235typedef struct _SetValuesInfo {
236    WidgetInfo widgets;
237    char * message;
238} SetValuesInfo;
239
240typedef struct _SetValuesEvent {
241    EditresCommand type;
242    unsigned short num_entries;
243    SetValuesInfo * info;
244} SetValuesEvent;
245
246typedef struct _GetValuesInfo {
247    WidgetInfo widgets;
248    char * value;
249} GetValuesInfo;
250
251typedef struct _GetValuesEvent {
252    EditresCommand type;
253    unsigned short num_entries;
254    GetValuesInfo * info;
255} GetValuesEvent;
256
257typedef struct _ResourceInfo {
258    ResourceType res_type;
259    char * name, *class, *type;
260} ResourceInfo;
261
262typedef struct _GetResourcesInfo {
263    WidgetInfo widgets;
264    Boolean error;
265    char * message;
266    unsigned short num_resources;
267    ResourceInfo * res_info;
268} GetResourcesInfo;
269
270typedef struct _GetResourcesEvent {
271    EditresCommand type;
272    unsigned short num_entries;
273    GetResourcesInfo * info;
274} GetResourcesEvent;
275
276typedef struct _GetGeomInfo {
277    EditresCommand type;
278    WidgetInfo widgets;
279    Boolean error;
280    char * message;
281    Boolean visable;
282    short x, y;
283    unsigned short width, height, border_width;
284} GetGeomInfo;
285
286typedef struct _GetGeomEvent {
287    EditresCommand type;
288    unsigned short num_entries;
289    GetGeomInfo * info;
290} GetGeomEvent;
291
292typedef struct _FindChildEvent {
293    EditresCommand type;
294    WidgetInfo widgets;
295} FindChildEvent;
296
297typedef union _Event {
298    AnyEvent any_event;
299    SendWidgetTreeEvent send_widget_tree_event;
300    SetValuesEvent set_values_event;
301    GetResourcesEvent get_resources_event;
302    GetGeomEvent get_geom_event;
303    FindChildEvent find_child_event;
304    GetValuesEvent get_values_event;
305} Event;
306
307/*
308 * number of application resource labels.
309 */
310
311#define NUM_RES_LABELS 37
312
313/*
314 * Global variables.
315 */
316extern int global_effective_protocol_version;
317extern char* global_effective_toolkit;
318extern int global_error_code;
319extern unsigned long global_serial_num;
320extern int (*global_old_error_handler)(Display *, XErrorEvent *);
321extern Boolean global_resource_box_up;
322
323extern TreeInfo *global_tree_info;
324extern CurrentClient global_client;
325extern ScreenData global_screen_data;
326extern Widget global_tree_parent;
327extern Widget global_paned;	/* named after toolkit */
328extern Widget global_toplevel;
329extern AppResources global_resources;
330
331extern String res_labels[NUM_RES_LABELS];
332
333extern Boolean do_get_values;
334extern Atom wm_delete_window;
335
336/* number of entries in the command menu */
337#define NUM_CM_ENTRIES 8
338extern Widget CM_entries[NUM_CM_ENTRIES];
339
340/* number of entries in the tree menu */
341#define NUM_TM_ENTRIES 16
342extern Widget TM_entries[NUM_TM_ENTRIES];
343
344/*
345 * Macros.
346 */
347
348#define streq(a, b)        ( strcmp((a), (b)) == 0 )
349
350/* offset into CM entries for setting insensitive */
351#define CM_OFFSET 1
352/* number of CM entries to make insensitive */
353#define CM_NUM 5
354#define TM_OFFSET 0
355#define TM_NUM 16
356
357/*
358 * Prototypes
359 */
360extern void ActivateResourceWidgets ( Widget w, XtPointer node_ptr, XtPointer junk );
361extern void ActivateWidgetsAndSetResourceString ( Widget w, XtPointer node_ptr, XtPointer call_data );
362extern void AddString ( char ** str, char *add );
363extern void AddTreeNode ( Widget tree, WNode * top );
364extern void AnyChosen ( Widget w, XtPointer any_info_ptr, XtPointer state_ptr );
365extern void ApplyResource ( Widget w, XtPointer node_ptr, XtPointer junk );
366extern void BuildVisualTree ( Widget tree_parent, Event * event );
367extern void BuildWidgetTree ( Widget parent );
368extern Boolean CheckDatabase ( XrmDatabase db, XrmQuarkList names, XrmQuarkList classes );
369extern void CreateResourceBox ( WNode * node, char ** errors );
370extern void CreateResourceBoxWidgets ( WNode * node, char **names, char **cons_names );
371extern TreeInfo * CreateTree ( Event * event );
372extern void DisplayChild ( Event * event );
373extern void DumpTreeToFile ( Widget w, XtPointer junk, XtPointer garbage );
374extern void ExecuteOverAllNodes ( WNode * top_node, void (*func)(WNode *, XtPointer), XtPointer data );
375extern WNode * FindNode ( WNode *top_node, unsigned long * ids, Cardinal number );
376extern void FindWidget ( Widget w, XtPointer client_data, XtPointer call_data );
377extern WNode * FindWidgetFromWindow ( TreeInfo * tree_info, Window win );
378extern void FlashActiveWidgets ( Widget w, XtPointer junk, XtPointer garbage );
379extern void GetAllStrings ( char *in, char sep, char ***out, int * num );
380extern Window GetClientWindow ( Widget w, int *x, int *y );
381extern char * GetFailureMessage ( ProtocolStream * stream );
382extern void GetNamesAndClasses ( WNode * node, char *** names, char ***classes );
383extern ResIdent GetNewIdent ( void );
384extern void GetResourceList ( Widget w, XtPointer junk, XtPointer garbage );
385extern char * GetResourceValueForSetValues ( WNode * node, unsigned short * size );
386extern char * HandleFlashWidget ( Event * event );
387extern char * HandleGetResources ( Event * event );
388extern int HandleXErrors ( Display * display, XErrorEvent * error );
389extern void InitSetValues ( Widget w, XtPointer client_data, XtPointer call_data );
390extern void InsertWidgetFromNode ( ProtocolStream * stream, WNode * node );
391extern void InternAtoms ( Display * dpy );
392extern void LayoutTree ( Widget tree );
393extern int main ( int argc, char **argv );
394extern void ModifySVEntry ( Widget w, XEvent *event, String * params, Cardinal * num_params );
395extern void PannerCallback ( Widget w, XtPointer closure, XtPointer report_ptr );
396extern void PerformTreeToFileDump ( WNode * node, int num_tabs, FILE * fp );
397extern void PopdownResBox ( Widget w, XtPointer shell_ptr, XtPointer junk );
398extern void PopupCentered ( XEvent * event, Widget w, XtGrabKind mode );
399extern void PopupSetValues ( Widget parent, XEvent * event );
400extern void PortholeCallback ( Widget w, XtPointer panner_ptr, XtPointer report_ptr );
401extern void PrepareToLayoutTree ( Widget tree );
402extern void PrintNodes ( WNode * top );
403extern char * PrintSetValuesError ( Event * event );
404extern char * ProtocolFailure ( ProtocolStream * stream );
405extern XrmQuarkList Quarkify ( char ** list, char * ptr );
406extern void Quit ( Widget w, XtPointer client_data, XtPointer call_data );
407extern void RebuildMenusAndLabel ( String toolkit );
408extern void ResourceListCallback ( Widget list, XtPointer node_ptr, XtPointer junk );
409extern void SaveResource ( Widget w, XtPointer res_box_ptr, XtPointer junk );
410extern void SendTree ( Widget w, XtPointer value, XtPointer call_data );
411extern void SetAndCenterTreeNode ( WNode * node );
412extern void SetApplicationActions ( XtAppContext app_con );
413extern void SetCommand ( Widget w, ResCommand command, char * msg );
414extern void SetEntriesSensitive ( Widget *entries, int num, Boolean sensitive );
415extern void SetFile ( Widget w, XtPointer junk, XtPointer garbage );
416extern void SetMessage ( Widget w, char * str );
417extern void SetResourceString ( Widget w, XtPointer node_ptr, XtPointer junk );
418extern void TreeRelabel ( Widget w, XtPointer client_data, XtPointer call_data );
419extern void TreeSelect ( Widget w, XtPointer client_data, XtPointer call_data );
420extern void TreeToggle ( Widget w, XtPointer node_ptr, XtPointer state_ptr );
421extern void _DumpTreeToFile ( Widget w, XtPointer tree_ptr, XtPointer filename );
422extern void _FindWidget ( Widget w );
423extern void _FlashActiveWidgets ( TreeInfo * tree_info );
424extern void _PopdownFileDialog ( Widget w, XtPointer client_data, XtPointer junk );
425extern void _PopupFileDialog ( Widget w, String str, String default_value, XtCallbackProc func, XtPointer data );
426extern void _TreeActivateNode ( WNode * node, SelectTypes type );
427extern void _TreeRelabel ( TreeInfo * tree_info, LabelTypes type );
428extern void _TreeRelabelNode ( WNode * node, LabelTypes type, Boolean recurse );
429extern void _TreeSelect ( TreeInfo * tree_info, SelectTypes type );
430extern void _TreeSelectNode ( WNode * node, SelectTypes type, Boolean recurse );
431
432