Path: utzoo!attcan!uunet!cs.utexas.edu!tut.cis.ohio-state.edu!ucbvax!hplabs!hplabsz!dayoung From: dayoung@hplabsz.HPL.HP.COM (Doug A. Young) Newsgroups: comp.windows.x Subject: Re: Programs relying on app-defaults files (was: Re: xclipboard bug?) Keywords: app-defaults Message-ID: <3401@hplabsz.HPL.HP.COM> Date: 26 May 89 15:57:36 GMT References: <8905151402.AA06843@THANATOS.MIT.EDU> <773@acorn.co.uk> <1041@sragwa.sra.JUNET> Reply-To: dayoung@hplabsz.UUCP (Doug A. Young) Organization: Hewlett-Packard Laboratories Lines: 211 In article <1041@sragwa.sra.JUNET> erik%sra.junet@uunet.uu.net (Erik M. van der Poel) writes: >I agree. I propose adding a function to Xt that would allow specifying the >app-defaults in a string in the program instead of in a separate file. This >would have to be called before calling XtInitialize(). This is an interesting co-incidence. I had the same idea, which I implemented a few days ago. I called my function XtRegisterApplicationDefaults(). The enclosed shar file contains a patch file for the R3 Intrinsics and a simple dummy example, to show how it can be used. It has been very useful so far, and I would certainly like to see this or something like it in the standard. Doug Young # This is a shell archive. Remove anything before this line, # then unpack it by saving it in a file and typing "sh file". # # Wrapped by Doug Young on Fri May 26 08:45:19 1989 # # This archive contains: # patches draw.c # LANG=""; export LANG PATH=/bin:/usr/bin:$PATH; export PATH echo x - patches cat >patches <<'@EOF' *** Initialize.orig Thu May 25 22:37:18 1989 --- Initialize.c Thu May 25 22:37:26 1989 *************** *** 122,127 *buf = '\0'; return buf; } static XrmDatabase GetAppSystemDefaults(classname) char *classname; --- 122,137 ----- *buf = '\0'; return buf; } + #define PROG_APP_DEFS + #ifdef PROG_APP_DEFS + /* + * This is a hack to allow the programmer to specify *default* resources. Because + * the resources are loaded into the resource database first, the user's resource files + * override them. This essentially give the programmer the option of compiling the app-defaults + * file into the application. + */ + static char **app_def; + static int n_app_defaults; XtRegisterApplicationDefaults(defs, n_defs) char *defs[]; *************** *** 123,128 return buf; } static XrmDatabase GetAppSystemDefaults(classname) char *classname; { --- 133,158 ----- static char **app_def; static int n_app_defaults; + XtRegisterApplicationDefaults(defs, n_defs) + char *defs[]; + int n_defs; + { + app_def = defs; + n_app_defaults = n_defs; + } + + static XrmDatabase GetProgramDefaults(def_res, n_res) + char *def_res[]; + int n_res; + { + int i; + XrmDatabase rdb = NULL; + for(i=0;idb = NULL; rdb = GetAppSystemDefaults(classname); if (rdb != NULL) XrmMergeDatabases(rdb, &(dpy->db)); --- 237,246 ----- dpy->db = NULL; + #ifdef PROG_APP_DEFS + rdb = GetProgramDefaults(app_def, n_app_defaults); + if (rdb != NULL) XrmMergeDatabases(rdb, &(dpy->db)); + #endif rdb = GetAppSystemDefaults(classname); if (rdb != NULL) XrmMergeDatabases(rdb, &(dpy->db)); @EOF chmod 666 patches echo x - draw.c cat >draw.c <<'@EOF' /* * Example using the program-compiled resource mechanism * provided by the function: * XtRegisterApplicationDefaults(); * To use, just create an array of strings, just like any X resource file, * Then call XtRegisterApplicationDefaults(resources, n_resources) * The specified resources will be entered into the resource data base * before any other resources, allowing the programmer to specify * reasonable defaults for applications without disallowing users * to override the chioces. */ #include #include #include #include #include #include #include static char * app_defaults[] = { "Draw*mode: one_of_many", "Draw*commands*PushButton*translations: : select() ", "Draw*options*PushButton*translations: : select() ", "Draw*commands.layoutType: maximum_columns", "Draw*commands*singleRow: True", "Draw*yResizable: True", "Draw*xResizable: True", "Draw*canvas.xRefName: options", "Draw*canvas.xAddWidth: True", "Draw*canvas.xAttachRight: True", "Draw*canvas.xAttachLeft: True", "Draw*canvas.yAttachBottom: True", "Draw*canvas.yAttachTop: True", "Draw*canvas.yRefName: commands", "Draw*canvas.yAddHeight: True", "Draw*commands.xRefName: options", "Draw*commands*xAddWidth: True", "Draw*commands.xAttachRight: True", "Draw*options.yAttachBottom: True", "*button1.label: dash", "*button2.label: dot-dash", "*options*button3.label: solid", "*commands*button1*label: Line", "*commands*button2*label: Circle", "*commands*button3*label: Square", }; main(argc, argv) int argc; char **argv; { Widget toplevel, canvas, panel, commands, options; XtRegisterApplicationDefaults(app_defaults, XtNumber(app_defaults)); toplevel = XtInitialize(argv[0], "Draw", NULL, 0, &argc, argv); panel = XtCreateManagedWidget("panel", XwformWidgetClass, toplevel, NULL, 0); options = XtCreateManagedWidget("options", XwrowColWidgetClass, panel, NULL, 0); commands = XtCreateManagedWidget("commands", XwrowColWidgetClass, panel, NULL, 0); canvas = XtCreateManagedWidget("canvas", XwworkSpaceWidgetClass, panel, NULL, 0); XtCreateManagedWidget("button1", XwpushButtonWidgetClass, commands, NULL, 0); XtCreateManagedWidget("button2", XwpushButtonWidgetClass, commands, NULL, 0); XtCreateManagedWidget("button3", XwpushButtonWidgetClass, commands, NULL, 0); XtCreateManagedWidget("button1", XwpushButtonWidgetClass, options, NULL, 0); XtCreateManagedWidget("button2", XwpushButtonWidgetClass, options, NULL, 0); XtCreateManagedWidget("button3", XwpushButtonWidgetClass, options, NULL, 0); XtRealizeWidget(toplevel); XtMainLoop(); } @EOF chmod 666 draw.c exit 0