editres.c revision 33c89af1
1/*
2 * $Xorg: editres.c,v 1.4 2001/02/09 02:05:29 xorgcvs Exp $
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/* $XFree86: xc/programs/editres/editres.c,v 1.6 2001/04/01 14:00:17 tsi Exp $ */
27
28#include <stdio.h>
29#include <stdlib.h>
30#include <X11/Intrinsic.h>
31#include <X11/StringDefs.h>
32#include <X11/Xaw/Cardinals.h>
33
34#define THIS_IS_MAIN		/* Don't get extern definitions of global
35				   variables. */
36
37#include "editresP.h"
38
39/*
40 * Global variables.
41 */
42
43/* array of toolkit dependent labels taken from the resource file */
44String res_labels[NUM_RES_LABELS];
45
46/* decremented if the target client does not speak the current version */
47int global_effective_protocol_version = CURRENT_PROTOCOL_VERSION;
48
49/* toolkit type of client whose "resources" we are currently editing */
50char *global_effective_toolkit = "xt";
51
52int global_error_code;
53unsigned long global_serial_num;
54int (*global_old_error_handler)(Display *, XErrorEvent *);
55
56Boolean global_resource_box_up = FALSE;
57TreeInfo *global_tree_info = NULL;
58CurrentClient global_client;
59ScreenData global_screen_data;
60Widget global_tree_parent;
61Widget global_paned = NULL;		/* named after toolkit */
62Widget global_toplevel;
63AppResources global_resources;
64
65
66static void Syntax ( XtAppContext app_con, char *call );
67
68String fallback_resources[] = {
69    NULL,
70};
71
72#define Offset(field) (XtOffsetOf(AppResources, field))
73
74static XtResource editres_resources[] = {
75  {"debug", "Debug", XtRBoolean, sizeof(Boolean),
76     Offset(debug), XtRImmediate, (XtPointer) FALSE},
77  {"numFlashes", "NumFlashes", XtRInt, sizeof(int),
78     Offset(num_flashes), XtRImmediate, (XtPointer) NUM_FLASHES},
79  {"flashTime", "FlashTime", XtRInt, sizeof(int),
80     Offset(flash_time), XtRImmediate, (XtPointer) FLASH_TIME},
81  {"flashColor", XtCForeground, XtRPixel, sizeof(Pixel),
82     Offset(flash_color), XtRImmediate, (XtPointer) XtDefaultForeground},
83  {"saveResourceFile", "SaveResourcesFile", XtRString, sizeof(String),
84     Offset(save_resources_file), XtRString, (XtPointer) ""},
85};
86
87Atom wm_delete_window;
88
89int
90main(argc, argv)
91int argc;
92char **argv;
93{
94    XtAppContext app_con;
95
96    global_toplevel = XtAppInitialize(&app_con, "Editres", NULL, ZERO,
97			       &argc, argv, fallback_resources,
98			       NULL, ZERO);
99
100    if (argc != 1)
101	Syntax(app_con, argv[0]);
102
103    SetApplicationActions(app_con);
104    XtGetApplicationResources(global_toplevel, (XtPointer) &global_resources,
105			      editres_resources, XtNumber(editres_resources),
106			      NULL, (Cardinal) 0);
107    global_resources.allocated_save_resources_file = FALSE;
108
109    XtOverrideTranslations
110      (global_toplevel,
111       XtParseTranslationTable ("<Message>WM_PROTOCOLS: quit()"));
112
113    /* build tree for Xt intrinsics */
114    BuildWidgetTree(global_toplevel);
115
116    SetMessage(global_screen_data.info_label,
117	       res_labels[13]);
118
119    global_screen_data.set_values_popup = NULL;
120
121    InternAtoms(XtDisplay(global_toplevel));
122
123    XtRealizeWidget(global_toplevel);
124
125    wm_delete_window =
126      XInternAtom(XtDisplay(global_toplevel), "WM_DELETE_WINDOW",
127				   False);
128    (void) XSetWMProtocols (XtDisplay(global_toplevel),
129			    XtWindow(global_toplevel),
130                            &wm_delete_window, 1);
131    XtAppMainLoop(app_con);
132    exit(0);
133}
134
135/*	Function Name: Syntax
136 *	Description: Prints a the calling syntax for this function to stdout.
137 *	Arguments: app_con - the application context.
138 *                 call - the name of the application.
139 *	Returns: none - exits tho.
140 */
141
142static void
143Syntax(app_con, call)
144XtAppContext app_con;
145char *call;
146{
147    XtDestroyApplicationContext(app_con);
148    fprintf(stderr, "Usage: %s\n", call);
149    exit(1);
150}
151