break Motif code up into motif and motif_l
[nvi.git] / motif / m_main.c
blob181a9345fd4f4522d70533239459972a6a775ee9
1 /*-
2 * Copyright (c) 1996
3 * Rob Zimmermann. All rights reserved.
4 * Copyright (c) 1996
5 * Keith Bostic. All rights reserved.
7 * See the LICENSE file for redistribution information.
8 */
10 #include "config.h"
12 #ifndef lint
13 static const char sccsid[] = "$Id: m_main.c,v 8.26 1996/12/11 20:56:43 bostic Exp $ (Berkeley) $Date: 1996/12/11 20:56:43 $";
14 #endif /* not lint */
16 #include <sys/types.h>
17 #include <sys/queue.h>
19 #include <X11/Intrinsic.h>
20 #include <X11/StringDefs.h>
21 #include <Xm/MainW.h>
23 #include <signal.h>
24 #include <stdlib.h>
26 #include "../motif_l/vi_mextern.h"
27 #include "extern.h"
29 #if XtSpecificationRelease == 4
30 #define ArgcType Cardinal *
31 #else
32 #define ArgcType int *
33 #endif
35 #include "nvi.xbm" /* Icon bitmap. */
37 static pid_t pid;
38 static Pixel icon_fg,
39 icon_bg;
40 static Pixmap icon_pm;
41 static Widget top_level;
42 static XtAppContext ctx;
44 static void onchld __P((int));
45 static void onexit __P((void));
48 /* resources for the vi widgets unless the user overrides them */
49 String fallback_rsrcs[] = {
51 "*font: -*-*-*-r-*--14-*-*-*-m-*-*-*",
52 "*text*fontList: -*-*-*-r-*--14-*-*-*-m-*-*-*",
53 "*Menu*fontList: -*-helvetica-bold-r-normal--14-*-*-*-*-*-*-*",
54 "*fontList: -*-helvetica-medium-r-normal--14-*-*-*-*-*-*-*",
55 "*pointerShape: xterm",
56 "*busyShape: watch",
57 "*iconName: vi",
59 /* coloring for the icons */
60 "*iconForeground: XtDefaultForeground",
61 "*iconBackground: XtDefaultBackground",
63 /* layout for the tag stack dialog */
64 "*Tags*visibleItemCount: 5",
66 /* layout for the new, temporary preferences page */
67 "*toggleOptions.numColumns: 6", /* also used by Find */
68 "*Preferences*tabWidthPercentage: 0",
69 "*Preferences*tabs.shadowThickness: 2",
70 "*Preferences*tabs.font: -*-helvetica-bold-r-normal--14-*-*-*-*-*-*-*",
72 /* --------------------------------------------------------------------- *
73 * anything below this point is only defined when we are not running CDE *
74 * --------------------------------------------------------------------- */
76 /* Do not define default colors when running under CDE
77 * (e.g. VUE on HPUX). The result is that you don't look
78 * like a normal desktop application
80 "?highlightColor: red",
81 "?background: gray75",
82 "?screen.background: wheat",
83 "?highlightColor: red",
84 "?Preferences*options.background: gray90",
87 #if defined(__STDC__)
88 static String *get_fallback_rsrcs( String name )
89 #else
90 static String *get_fallback_rsrcs( name )
91 String name;
92 #endif
94 String *copy = (String *) malloc( (1+XtNumber(fallback_rsrcs))*sizeof(String) );
95 int i, running_cde;
96 Display *d;
98 /* connect to server and see if the CDE atoms are present */
99 d = XOpenDisplay(0);
100 running_cde = is_cde( d );
101 XCloseDisplay(d);
103 for ( i=0; i<XtNumber(fallback_rsrcs); i++ ) {
105 /* stop here if running CDE */
106 if ( fallback_rsrcs[i][0] == '?' ) {
107 if ( running_cde ) break;
108 fallback_rsrcs[i] = strdup(fallback_rsrcs[i]);
109 fallback_rsrcs[i][0] = '*';
112 copy[i] = malloc( strlen(name) + strlen(fallback_rsrcs[i]) + 1 );
113 strcpy( copy[i], name );
114 strcat( copy[i], fallback_rsrcs[i] );
117 copy[i] = NULL;
118 return copy;
122 /* create the shell widgetry */
124 #if defined(__STDC__)
125 static void create_top_level_shell( int *argc, char **argv )
126 #else
127 static void create_top_level_shell( argc, argv )
128 int *argc;
129 char **argv;
130 #endif
132 char *ptr;
133 Widget main_w, menu_b;
134 Display *display;
136 /* X gets quite upset if the program name is not simple */
137 if (( ptr = strrchr( argv[0], '/' )) != NULL ) argv[0] = ++ptr;
138 vi_progname = argv[0];
140 /* create a top-level shell for the window manager */
141 top_level = XtVaAppInitialize( &ctx,
142 vi_progname,
143 NULL, 0, /* options */
144 (ArgcType) argc,
145 argv, /* might get modified */
146 get_fallback_rsrcs( argv[0] ),
147 NULL
149 display = XtDisplay(top_level);
151 /* might need to go technicolor... */
152 XutInstallColormap( argv[0], top_level );
154 /* create our icon
155 * do this *before* realizing the shell widget in case the -iconic
156 * option was specified.
158 icon_pm = XCreatePixmapFromBitmapData(
159 display,
160 DefaultRootWindow(display),
161 (char *) nvi_bits,
162 nvi_width,
163 nvi_height,
164 icon_fg,
165 icon_bg,
166 DefaultDepth( display, DefaultScreen(display) )
168 XutSetIcon( top_level, nvi_height, nvi_width, icon_pm );
170 /* in the shell, we will stack a menubar an editor */
171 main_w = XtVaCreateManagedWidget( "main",
172 xmMainWindowWidgetClass,
173 top_level,
174 NULL
177 /* create the menubar */
178 menu_b = (Widget) vi_create_menubar( main_w );
179 XtManageChild( menu_b );
181 /* add the VI widget from the library */
182 vi_create_editor( "editor", main_w, onexit );
184 /* put it up */
185 XtRealizeWidget( top_level );
190 main(argc, argv)
191 int argc;
192 char *argv[];
194 int i_fd;
197 * Initialize the X widgetry. We must do this before picking off
198 * arguments as well-behaved X programs have common argument lists
199 * (e.g. -rv for reverse video).
201 create_top_level_shell(&argc, argv);
203 /* We need to know if the child process goes away. */
204 (void)signal(SIGCHLD, onchld);
206 /* Run vi: the parent returns, the child is the vi process. */
207 (void)vi_run(argc, argv, &i_fd, &vi_ofd, &pid);
209 /* Tell X that we are interested in input on the pipe. */
210 XtAppAddInput(ctx, i_fd,
211 (XtPointer)XtInputReadMask, vi_input_func, NULL);
213 /* Main loop. */
214 XtAppMainLoop(ctx);
216 /* NOTREACHED */
217 abort();
221 * onchld --
222 * Handle SIGCHLD.
224 static void
225 onchld(signo)
226 int signo;
228 /* If the vi process goes away, we exit as well. */
229 if (kill(pid, 0))
230 vi_fatal_message(top_level, "The vi process died. Exiting.");
234 * onexit --
235 * Function called when the editor "quits".
237 static void
238 onexit()
240 exit (0);