editres.c revision 352bf44e
1/*
2 *
3Copyright 1989, 1998  The Open Group
4
5Permission to use, copy, modify, distribute, and sell this software and its
6documentation for any purpose is hereby granted without fee, provided that
7the above copyright notice appear in all copies and that both that
8copyright notice and this permission notice appear in supporting
9documentation.
10
11The above copyright notice and this permission notice shall be included in
12all copies or substantial portions of the Software.
13
14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
17OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
21Except as contained in this notice, the name of The Open Group shall not be
22used in advertising or otherwise to promote the sale, use or other dealings
23in this Software without prior written authorization from The Open Group.
24 */
25
26#include <stdio.h>
27#include <stdlib.h>
28#include <X11/Intrinsic.h>
29#include <X11/StringDefs.h>
30#include <X11/Xaw/Cardinals.h>
31
32#define THIS_IS_MAIN		/* Don't get extern definitions of global
33				   variables. */
34
35#include "editresP.h"
36
37/*
38 * Global variables.
39 */
40
41/* array of toolkit dependent labels taken from the resource file */
42String res_labels[NUM_RES_LABELS];
43
44/* decremented if the target client does not speak the current version */
45int global_effective_protocol_version = CURRENT_PROTOCOL_VERSION;
46
47/* toolkit type of client whose "resources" we are currently editing */
48String global_effective_toolkit = "xt";
49
50int global_error_code;
51unsigned long global_serial_num;
52int (*global_old_error_handler)(Display *, XErrorEvent *);
53
54Boolean global_resource_box_up = FALSE;
55TreeInfo *global_tree_info = NULL;
56CurrentClient global_client;
57ScreenData global_screen_data;
58Widget global_tree_parent;
59Widget global_paned = NULL;		/* named after toolkit */
60Widget global_toplevel;
61AppResources global_resources;
62
63
64static void Syntax ( XtAppContext app_con, char *call ) _X_NORETURN;
65
66static String fallback_resources[] = {
67    NULL,
68};
69
70#define Offset(field) (XtOffsetOf(AppResources, field))
71
72static XtResource editres_resources[] = {
73  {"debug", "Debug", XtRBoolean, sizeof(Boolean),
74     Offset(debug), XtRImmediate, (XtPointer) FALSE},
75  {"numFlashes", "NumFlashes", XtRInt, sizeof(int),
76     Offset(num_flashes), XtRImmediate, (XtPointer) NUM_FLASHES},
77  {"flashTime", "FlashTime", XtRInt, sizeof(int),
78     Offset(flash_time), XtRImmediate, (XtPointer) FLASH_TIME},
79  {"flashColor", XtCForeground, XtRPixel, sizeof(Pixel),
80     Offset(flash_color), XtRImmediate, (XtPointer) XtDefaultForeground},
81  {"saveResourceFile", "SaveResourcesFile", XtRString, sizeof(String),
82     Offset(save_resources_file), XtRString, (XtPointer) ""},
83};
84
85Atom wm_delete_window;
86
87int
88main(int argc, char **argv)
89{
90    XtAppContext app_con;
91
92    global_toplevel = XtAppInitialize(&app_con, "Editres", NULL, ZERO,
93			       &argc, argv, fallback_resources,
94			       NULL, ZERO);
95
96    if (argc != 1)
97	Syntax(app_con, argv[0]);
98
99    SetApplicationActions(app_con);
100    XtGetApplicationResources(global_toplevel, (XtPointer) &global_resources,
101			      editres_resources, XtNumber(editres_resources),
102			      NULL, (Cardinal) 0);
103    global_resources.allocated_save_resources_file = FALSE;
104
105    XtOverrideTranslations
106      (global_toplevel,
107       XtParseTranslationTable ("<Message>WM_PROTOCOLS: quit()"));
108
109    /* build tree for Xt intrinsics */
110    BuildWidgetTree(global_toplevel);
111
112    SetMessage(global_screen_data.info_label,
113	       res_labels[13]);
114
115    global_screen_data.set_values_popup = NULL;
116
117    InternAtoms(XtDisplay(global_toplevel));
118
119    XtRealizeWidget(global_toplevel);
120
121    wm_delete_window =
122      XInternAtom(XtDisplay(global_toplevel), "WM_DELETE_WINDOW",
123				   False);
124    (void) XSetWMProtocols (XtDisplay(global_toplevel),
125			    XtWindow(global_toplevel),
126                            &wm_delete_window, 1);
127    XtAppMainLoop(app_con);
128    exit(0);
129}
130
131/*	Function Name: Syntax
132 *	Description: Prints a the calling syntax for this function to stdout.
133 *	Arguments: app_con - the application context.
134 *                 call - the name of the application.
135 *	Returns: none - exits though.
136 */
137
138static void
139Syntax(XtAppContext app_con, char *call)
140{
141    XtDestroyApplicationContext(app_con);
142    fprintf(stderr, "Usage: %s\n", call);
143    exit(1);
144}
145