editres.c revision 278eca22
133c89af1Smrg/*
233c89af1Smrg * $Xorg: editres.c,v 1.4 2001/02/09 02:05:29 xorgcvs Exp $
333c89af1Smrg *
433c89af1SmrgCopyright 1989, 1998  The Open Group
533c89af1Smrg
633c89af1SmrgPermission to use, copy, modify, distribute, and sell this software and its
733c89af1Smrgdocumentation for any purpose is hereby granted without fee, provided that
833c89af1Smrgthe above copyright notice appear in all copies and that both that
933c89af1Smrgcopyright notice and this permission notice appear in supporting
1033c89af1Smrgdocumentation.
1133c89af1Smrg
1233c89af1SmrgThe above copyright notice and this permission notice shall be included in
1333c89af1Smrgall copies or substantial portions of the Software.
1433c89af1Smrg
1533c89af1SmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1633c89af1SmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1733c89af1SmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
1833c89af1SmrgOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
1933c89af1SmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
2033c89af1SmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2133c89af1Smrg
2233c89af1SmrgExcept as contained in this notice, the name of The Open Group shall not be
2333c89af1Smrgused in advertising or otherwise to promote the sale, use or other dealings
2433c89af1Smrgin this Software without prior written authorization from The Open Group.
2533c89af1Smrg */
2633c89af1Smrg/* $XFree86: xc/programs/editres/editres.c,v 1.6 2001/04/01 14:00:17 tsi Exp $ */
2733c89af1Smrg
2833c89af1Smrg#include <stdio.h>
2933c89af1Smrg#include <stdlib.h>
3033c89af1Smrg#include <X11/Intrinsic.h>
3133c89af1Smrg#include <X11/StringDefs.h>
3233c89af1Smrg#include <X11/Xaw/Cardinals.h>
3333c89af1Smrg
3433c89af1Smrg#define THIS_IS_MAIN		/* Don't get extern definitions of global
3533c89af1Smrg				   variables. */
3633c89af1Smrg
3733c89af1Smrg#include "editresP.h"
3833c89af1Smrg
3933c89af1Smrg/*
4033c89af1Smrg * Global variables.
4133c89af1Smrg */
4233c89af1Smrg
4333c89af1Smrg/* array of toolkit dependent labels taken from the resource file */
4433c89af1SmrgString res_labels[NUM_RES_LABELS];
4533c89af1Smrg
4633c89af1Smrg/* decremented if the target client does not speak the current version */
4733c89af1Smrgint global_effective_protocol_version = CURRENT_PROTOCOL_VERSION;
4833c89af1Smrg
4933c89af1Smrg/* toolkit type of client whose "resources" we are currently editing */
5033c89af1Smrgchar *global_effective_toolkit = "xt";
5133c89af1Smrg
5233c89af1Smrgint global_error_code;
5333c89af1Smrgunsigned long global_serial_num;
5433c89af1Smrgint (*global_old_error_handler)(Display *, XErrorEvent *);
5533c89af1Smrg
5633c89af1SmrgBoolean global_resource_box_up = FALSE;
5733c89af1SmrgTreeInfo *global_tree_info = NULL;
5833c89af1SmrgCurrentClient global_client;
5933c89af1SmrgScreenData global_screen_data;
6033c89af1SmrgWidget global_tree_parent;
6133c89af1SmrgWidget global_paned = NULL;		/* named after toolkit */
6233c89af1SmrgWidget global_toplevel;
6333c89af1SmrgAppResources global_resources;
6433c89af1Smrg
6533c89af1Smrg
6633c89af1Smrgstatic void Syntax ( XtAppContext app_con, char *call );
6733c89af1Smrg
68278eca22Smrgstatic String fallback_resources[] = {
6933c89af1Smrg    NULL,
7033c89af1Smrg};
7133c89af1Smrg
7233c89af1Smrg#define Offset(field) (XtOffsetOf(AppResources, field))
7333c89af1Smrg
7433c89af1Smrgstatic XtResource editres_resources[] = {
7533c89af1Smrg  {"debug", "Debug", XtRBoolean, sizeof(Boolean),
7633c89af1Smrg     Offset(debug), XtRImmediate, (XtPointer) FALSE},
7733c89af1Smrg  {"numFlashes", "NumFlashes", XtRInt, sizeof(int),
7833c89af1Smrg     Offset(num_flashes), XtRImmediate, (XtPointer) NUM_FLASHES},
7933c89af1Smrg  {"flashTime", "FlashTime", XtRInt, sizeof(int),
8033c89af1Smrg     Offset(flash_time), XtRImmediate, (XtPointer) FLASH_TIME},
8133c89af1Smrg  {"flashColor", XtCForeground, XtRPixel, sizeof(Pixel),
8233c89af1Smrg     Offset(flash_color), XtRImmediate, (XtPointer) XtDefaultForeground},
8333c89af1Smrg  {"saveResourceFile", "SaveResourcesFile", XtRString, sizeof(String),
8433c89af1Smrg     Offset(save_resources_file), XtRString, (XtPointer) ""},
8533c89af1Smrg};
8633c89af1Smrg
8733c89af1SmrgAtom wm_delete_window;
8833c89af1Smrg
8933c89af1Smrgint
90278eca22Smrgmain(int argc, char **argv)
9133c89af1Smrg{
9233c89af1Smrg    XtAppContext app_con;
9333c89af1Smrg
9433c89af1Smrg    global_toplevel = XtAppInitialize(&app_con, "Editres", NULL, ZERO,
9533c89af1Smrg			       &argc, argv, fallback_resources,
9633c89af1Smrg			       NULL, ZERO);
9733c89af1Smrg
9833c89af1Smrg    if (argc != 1)
9933c89af1Smrg	Syntax(app_con, argv[0]);
10033c89af1Smrg
10133c89af1Smrg    SetApplicationActions(app_con);
10233c89af1Smrg    XtGetApplicationResources(global_toplevel, (XtPointer) &global_resources,
10333c89af1Smrg			      editres_resources, XtNumber(editres_resources),
10433c89af1Smrg			      NULL, (Cardinal) 0);
10533c89af1Smrg    global_resources.allocated_save_resources_file = FALSE;
10633c89af1Smrg
10733c89af1Smrg    XtOverrideTranslations
10833c89af1Smrg      (global_toplevel,
10933c89af1Smrg       XtParseTranslationTable ("<Message>WM_PROTOCOLS: quit()"));
11033c89af1Smrg
11133c89af1Smrg    /* build tree for Xt intrinsics */
11233c89af1Smrg    BuildWidgetTree(global_toplevel);
11333c89af1Smrg
11433c89af1Smrg    SetMessage(global_screen_data.info_label,
11533c89af1Smrg	       res_labels[13]);
11633c89af1Smrg
11733c89af1Smrg    global_screen_data.set_values_popup = NULL;
11833c89af1Smrg
11933c89af1Smrg    InternAtoms(XtDisplay(global_toplevel));
12033c89af1Smrg
12133c89af1Smrg    XtRealizeWidget(global_toplevel);
12233c89af1Smrg
12333c89af1Smrg    wm_delete_window =
12433c89af1Smrg      XInternAtom(XtDisplay(global_toplevel), "WM_DELETE_WINDOW",
12533c89af1Smrg				   False);
12633c89af1Smrg    (void) XSetWMProtocols (XtDisplay(global_toplevel),
12733c89af1Smrg			    XtWindow(global_toplevel),
12833c89af1Smrg                            &wm_delete_window, 1);
12933c89af1Smrg    XtAppMainLoop(app_con);
13033c89af1Smrg    exit(0);
13133c89af1Smrg}
13233c89af1Smrg
13333c89af1Smrg/*	Function Name: Syntax
13433c89af1Smrg *	Description: Prints a the calling syntax for this function to stdout.
13533c89af1Smrg *	Arguments: app_con - the application context.
13633c89af1Smrg *                 call - the name of the application.
13733c89af1Smrg *	Returns: none - exits tho.
13833c89af1Smrg */
13933c89af1Smrg
14033c89af1Smrgstatic void
141278eca22SmrgSyntax(XtAppContext app_con, char *call)
14233c89af1Smrg{
14333c89af1Smrg    XtDestroyApplicationContext(app_con);
14433c89af1Smrg    fprintf(stderr, "Usage: %s\n", call);
14533c89af1Smrg    exit(1);
14633c89af1Smrg}
147