editres.c revision 278eca22
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
68static String 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(int argc, char **argv)
91{
92    XtAppContext app_con;
93
94    global_toplevel = XtAppInitialize(&app_con, "Editres", NULL, ZERO,
95			       &argc, argv, fallback_resources,
96			       NULL, ZERO);
97
98    if (argc != 1)
99	Syntax(app_con, argv[0]);
100
101    SetApplicationActions(app_con);
102    XtGetApplicationResources(global_toplevel, (XtPointer) &global_resources,
103			      editres_resources, XtNumber(editres_resources),
104			      NULL, (Cardinal) 0);
105    global_resources.allocated_save_resources_file = FALSE;
106
107    XtOverrideTranslations
108      (global_toplevel,
109       XtParseTranslationTable ("<Message>WM_PROTOCOLS: quit()"));
110
111    /* build tree for Xt intrinsics */
112    BuildWidgetTree(global_toplevel);
113
114    SetMessage(global_screen_data.info_label,
115	       res_labels[13]);
116
117    global_screen_data.set_values_popup = NULL;
118
119    InternAtoms(XtDisplay(global_toplevel));
120
121    XtRealizeWidget(global_toplevel);
122
123    wm_delete_window =
124      XInternAtom(XtDisplay(global_toplevel), "WM_DELETE_WINDOW",
125				   False);
126    (void) XSetWMProtocols (XtDisplay(global_toplevel),
127			    XtWindow(global_toplevel),
128                            &wm_delete_window, 1);
129    XtAppMainLoop(app_con);
130    exit(0);
131}
132
133/*	Function Name: Syntax
134 *	Description: Prints a the calling syntax for this function to stdout.
135 *	Arguments: app_con - the application context.
136 *                 call - the name of the application.
137 *	Returns: none - exits tho.
138 */
139
140static void
141Syntax(XtAppContext app_con, char *call)
142{
143    XtDestroyApplicationContext(app_con);
144    fprintf(stderr, "Usage: %s\n", call);
145    exit(1);
146}
147