1 2 /* 3 * 4 Copyright 1989, 1998 The Open Group 5 6 Permission to use, copy, modify, distribute, and sell this software and its 7 documentation for any purpose is hereby granted without fee, provided that 8 the above copyright notice appear in all copies and that both that 9 copyright notice and this permission notice appear in supporting 10 documentation. 11 12 The above copyright notice and this permission notice shall be included in 13 all copies or substantial portions of the Software. 14 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 19 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 22 Except as contained in this notice, the name of The Open Group shall not be 23 used in advertising or otherwise to promote the sale, use or other dealings 24 in 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 #include <X11/Xmd.h> 33 34 #define DEBUG 35 36 #ifdef DEBUG 37 # define CLIENT_TIME_OUT 60000 /* wait sixty seconds for the client. */ 38 #else 39 # define CLIENT_TIME_OUT 5000 /* wait five seconds for the client. */ 40 #endif /* DEBUG */ 41 42 /** 43 * Current version of the editres protocol. Must be kept in sync with 44 * libXmu. 45 */ 46 #define CURRENT_PROTOCOL_VERSION 6 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 80 typedef enum {LocalSendWidgetTree, LocalSetValues, LocalFindChild, 81 LocalFlashWidget, LocalGetGeometry, LocalGetResources, 82 LocalGetValues} ResCommand; 83 84 typedef enum {ClassLabel, NameLabel, IDLabel, WindowLabel, 85 ToggleLabel} LabelTypes; 86 typedef enum {SelectWidget, SelectAll, SelectNone, SelectInvert, SelectParent, 87 SelectChildren, SelectDescendants, SelectAncestors} SelectTypes; 88 89 typedef 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 95 typedef struct _ResourceBoxInfo { 96 Widget value_wid; /* The string containing the value. */ 97 Widget res_label; /* The label containing current resource. */ 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 hierarchy. */ 104 } ResourceBoxInfo; 105 106 typedef struct _WidgetResourceInfo { 107 char * name, * class, *type; /* Name, Class and Type of each resource. */ 108 } WidgetResourceInfo; 109 110 typedef struct _WidgetResources { 111 int num_normal, num_constraint; 112 WidgetResourceInfo *normal, *constraint; 113 ResourceBoxInfo * res_box; 114 } WidgetResources; 115 116 typedef 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 133 typedef struct _AnyInfo { 134 WNode * node; /* A Pointer off to the node corresponding 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 146 typedef 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 159 typedef 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 172 typedef 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 179 typedef 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 193 typedef struct _ApplyResourcesInfo { 194 const 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 204 typedef struct _ObtainResourcesInfo { 205 const 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 217 typedef struct _AnyEvent { 218 EditresCommand type; 219 } AnyEvent; 220 221 typedef struct _WidgetTreeInfo { 222 WidgetInfo widgets; 223 char * name; 224 char * class; 225 CARD64 window; 226 } WidgetTreeInfo; 227 228 typedef struct _SendWidgetTreeEvent { 229 EditresCommand type; 230 char * toolkit; 231 unsigned short num_entries; 232 WidgetTreeInfo * info; 233 } SendWidgetTreeEvent; 234 235 typedef struct _SetValuesInfo { 236 WidgetInfo widgets; 237 char * message; 238 } SetValuesInfo; 239 240 typedef struct _SetValuesEvent { 241 EditresCommand type; 242 unsigned short num_entries; 243 SetValuesInfo * info; 244 } SetValuesEvent; 245 246 typedef struct _GetValuesInfo { 247 WidgetInfo widgets; 248 char * value; 249 } GetValuesInfo; 250 251 typedef struct _GetValuesEvent { 252 EditresCommand type; 253 unsigned short num_entries; 254 GetValuesInfo * info; 255 } GetValuesEvent; 256 257 typedef struct _ResourceInfo { 258 ResourceType res_type; 259 char * name, *class, *type; 260 } ResourceInfo; 261 262 typedef struct _GetResourcesInfo { 263 WidgetInfo widgets; 264 Boolean error; 265 char * message; 266 unsigned short num_resources; 267 ResourceInfo * res_info; 268 } GetResourcesInfo; 269 270 typedef struct _GetResourcesEvent { 271 EditresCommand type; 272 unsigned short num_entries; 273 GetResourcesInfo * info; 274 } GetResourcesEvent; 275 276 typedef struct _GetGeomInfo { 277 EditresCommand type; 278 WidgetInfo widgets; 279 Boolean error; 280 char * message; 281 Boolean visible; 282 short x, y; 283 unsigned short width, height, border_width; 284 } GetGeomInfo; 285 286 typedef struct _GetGeomEvent { 287 EditresCommand type; 288 unsigned short num_entries; 289 GetGeomInfo * info; 290 } GetGeomEvent; 291 292 typedef struct _FindChildEvent { 293 EditresCommand type; 294 WidgetInfo widgets; 295 } FindChildEvent; 296 297 typedef 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 */ 316 extern int global_effective_protocol_version; 317 extern const char *global_effective_toolkit; 318 extern int global_error_code; 319 extern unsigned long global_serial_num; 320 extern int (*global_old_error_handler)(Display *, XErrorEvent *); 321 extern Boolean global_resource_box_up; 322 323 extern TreeInfo *global_tree_info; 324 extern CurrentClient global_client; 325 extern ScreenData global_screen_data; 326 extern Widget global_tree_parent; 327 extern Widget global_paned; /* named after toolkit */ 328 extern Widget global_toplevel; 329 extern AppResources global_resources; 330 331 extern String res_labels[NUM_RES_LABELS]; 332 333 extern Boolean do_get_values; 334 extern Atom wm_delete_window; 335 336 /* number of entries in the command menu */ 337 #define NUM_CM_ENTRIES 8 338 extern Widget CM_entries[NUM_CM_ENTRIES]; 339 340 /* number of entries in the tree menu */ 341 #define NUM_TM_ENTRIES 16 342 extern 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 */ 360 extern void ActivateResourceWidgets ( Widget w, XtPointer node_ptr, XtPointer junk ); 361 extern void ActivateWidgetsAndSetResourceString ( Widget w, XtPointer node_ptr, XtPointer call_data ); 362 extern void AddString ( char ** str, const char *add ); 363 extern void AddTreeNode ( Widget tree, WNode * top ); 364 extern void AnyChosen ( Widget w, XtPointer any_info_ptr, XtPointer state_ptr ); 365 extern void ApplyResource ( Widget w, XtPointer node_ptr, XtPointer junk ); 366 extern void BuildVisualTree ( Widget tree_parent, Event * event ); 367 extern void BuildWidgetTree ( Widget parent ); 368 extern Boolean CheckDatabase ( XrmDatabase db, XrmQuarkList names, XrmQuarkList classes ); 369 extern void CreateResourceBox ( WNode * node, char ** errors ); 370 extern void CreateResourceBoxWidgets ( WNode * node, char **names, char **cons_names ); 371 extern TreeInfo * CreateTree ( Event * event ); 372 extern void DisplayChild ( Event * event ); 373 extern void DumpTreeToFile ( Widget w, XtPointer junk, XtPointer garbage ); 374 extern void ExecuteOverAllNodes ( WNode * top_node, void (*func)(WNode *, XtPointer), XtPointer data ); 375 extern WNode * FindNode ( WNode *top_node, CARD64 *ids, Cardinal number ); 376 extern void FindWidget ( Widget w, XtPointer client_data, XtPointer call_data ); 377 extern WNode * FindWidgetFromWindow ( TreeInfo * tree_info, Window win ); 378 extern void FlashActiveWidgets ( Widget w, XtPointer junk, XtPointer garbage ); 379 extern void GetAllStrings ( char *in, char sep, char ***out, int * num ); 380 extern Window GetClientWindow ( Widget w, int *x, int *y ); 381 extern char * GetFailureMessage ( ProtocolStream * stream ); 382 extern void GetNamesAndClasses ( WNode * node, char *** names, char ***classes ); 383 extern ResIdent GetNewIdent ( void ); 384 extern void GetResourceList ( Widget w, XtPointer junk, XtPointer garbage ); 385 extern char * GetResourceValueForSetValues ( WNode * node, unsigned short * size ); 386 extern char * HandleFlashWidget ( Event * event ); 387 extern char * HandleGetResources ( Event * event ); 388 extern int HandleXErrors ( Display * display, XErrorEvent * error ); 389 extern void InitSetValues ( Widget w, XtPointer client_data, XtPointer call_data ); 390 extern void InsertWidgetFromNode ( ProtocolStream * stream, WNode * node ); 391 extern void InternAtoms ( Display * dpy ); 392 extern void LayoutTree ( Widget tree ); 393 extern int main ( int argc, char **argv ); 394 extern void ModifySVEntry ( Widget w, XEvent *event, String * params, Cardinal * num_params ); 395 extern void PannerCallback ( Widget w, XtPointer closure, XtPointer report_ptr ); 396 extern void PerformTreeToFileDump ( WNode * node, Cardinal num_tabs, FILE * fp ); 397 extern void PopdownResBox ( Widget w, XtPointer shell_ptr, XtPointer junk ); 398 extern void PopupCentered ( XEvent * event, Widget w, XtGrabKind mode ); 399 extern void PopupSetValues ( Widget parent, XEvent * event ); 400 extern void PortholeCallback ( Widget w, XtPointer panner_ptr, XtPointer report_ptr ); 401 extern void PrepareToLayoutTree ( Widget tree ); 402 extern void PrintNodes ( WNode * top ); 403 extern char * PrintSetValuesError ( Event * event ); 404 extern char * ProtocolFailure ( ProtocolStream * stream ); 405 extern XrmQuarkList Quarkify ( char ** list, const char * ptr ); 406 extern void Quit ( Widget w, XtPointer client_data, XtPointer call_data ) _X_NORETURN; 407 extern void RebuildMenusAndLabel ( const char * toolkit ); 408 extern void ResourceListCallback ( Widget list, XtPointer node_ptr, XtPointer junk ); 409 extern void SaveResource ( Widget w, XtPointer res_box_ptr, XtPointer junk ); 410 extern void SendTree ( Widget w, XtPointer value, XtPointer call_data ); 411 extern void SetAndCenterTreeNode ( WNode * node ); 412 extern void SetApplicationActions ( XtAppContext app_con ); 413 extern void SetCommand ( Widget w, ResCommand command, String msg ); 414 extern void SetEntriesSensitive ( Widget *entries, int num, Boolean sensitive ); 415 extern void SetFile ( Widget w, XtPointer junk, XtPointer garbage ); 416 extern void SetMessage ( Widget w, const char * str ); 417 extern void SetResourceString ( Widget w, XtPointer node_ptr, XtPointer junk ); 418 extern void TreeRelabel ( Widget w, XtPointer client_data, XtPointer call_data ); 419 extern void TreeSelect ( Widget w, XtPointer client_data, XtPointer call_data ); 420 extern void TreeToggle ( Widget w, XtPointer node_ptr, XtPointer state_ptr ); 421 extern void _DumpTreeToFile ( Widget w, XtPointer tree_ptr, XtPointer filename ); 422 extern void _FindWidget ( Widget w ); 423 extern void _FlashActiveWidgets ( TreeInfo * tree_info ); 424 extern void _PopdownFileDialog ( Widget w, XtPointer client_data, XtPointer junk ); 425 extern void _PopupFileDialog ( Widget w, const char *str, const char *default_value, XtCallbackProc func, XtPointer data ); 426 extern void _TreeActivateNode ( WNode * node, SelectTypes type ); 427 extern void _TreeRelabel ( TreeInfo * tree_info, LabelTypes type ); 428 extern void _TreeRelabelNode ( WNode * node, LabelTypes type, Boolean recurse ); 429 extern void _TreeSelect ( TreeInfo * tree_info, SelectTypes type ); 430 extern void _TreeSelectNode ( WNode * node, SelectTypes type, Boolean recurse ); 431 432