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