3 * Rob Zimmermann. All rights reserved.
5 * Keith Bostic. All rights reserved.
7 * See the LICENSE file for redistribution information.
13 static const char sccsid
[] = "$Id: m_main.c,v 8.24 1996/12/11 13:34:34 bostic Exp $ (Berkeley) $Date: 1996/12/11 13:34:34 $";
16 #include <sys/types.h>
17 #include <sys/queue.h>
19 #include <X11/Intrinsic.h>
20 #include <X11/StringDefs.h>
23 #include <bitstring.h>
32 #include "../common/common.h"
33 #include "../ip_vi/ip.h"
34 #include "ipc_motif.h"
35 #include "ipc_mutil.h"
36 #include "ipc_mextern.h"
37 #include "pathnames.h"
39 #include "nvi.xbm" /* Icon bitmap. */
41 int vi_ofd
; /* GLOBAL: known to vi_pipe_input_func(). */
46 static Pixmap icon_pm
;
47 static Widget top_level
;
48 static XtAppContext ctx
;
50 static void onchld
__P((int));
51 static void onexit
__P((void));
54 /* resources for the vi widgets unless the user overrides them */
55 String fallback_rsrcs
[] = {
57 "*font: -*-*-*-r-*--14-*-*-*-m-*-*-*",
58 "*pointerShape: xterm",
62 /* coloring for the icons */
63 "*iconForeground: XtDefaultForeground",
64 "*iconBackground: XtDefaultBackground",
66 /* layout for the temporary preferences page */
67 "*toggleOptions.numColumns: 6",
68 "*intOptions.numColumns: 4",
69 "*otherOptions.numColumns: 3",
70 "*intOptions*columns: 10",
71 "*otherOptions*columns: 18",
73 /* --------------------------------------------------------------------- *
74 * anything below this point is only defined when we are not running CDE *
75 * --------------------------------------------------------------------- */
77 /* Do not define default colors when running under CDE
78 * (e.g. VUE on HPUX). The result is that you don't look
79 * like a normal desktop application
81 "?highlightColor: red",
82 "?background: gray75",
83 "?screen.background: wheat",
84 "?highlightColor: red"
87 static XutResource resource
[] = {
88 { "iconForeground", XutRKpixel
, &icon_fg
},
89 { "iconBackground", XutRKpixel
, &icon_bg
},
93 static String
*get_fallback_rsrcs( String name
)
95 static String
*get_fallback_rsrcs( name
)
99 String
*copy
= (String
*) malloc( (1+XtNumber(fallback_rsrcs
))*sizeof(String
) );
103 /* connect to server and see if the CDE atoms are present */
105 running_cde
= __vi_is_cde( d
);
108 for ( i
=0; i
<XtNumber(fallback_rsrcs
); i
++ ) {
110 /* stop here if running CDE */
111 if ( fallback_rsrcs
[i
][0] == '?' ) {
112 if ( running_cde
) break;
113 fallback_rsrcs
[i
] = strdup(fallback_rsrcs
[i
]);
114 fallback_rsrcs
[i
][0] = '*';
117 copy
[i
] = malloc( strlen(name
) + strlen(fallback_rsrcs
[i
]) + 1 );
118 strcpy( copy
[i
], name
);
119 strcat( copy
[i
], fallback_rsrcs
[i
] );
127 /* create the shell widgetry */
129 #if defined(__STDC__)
130 static void create_top_level_shell( int *argc
, char **argv
)
132 static void create_top_level_shell( argc
, argv
)
138 Widget main_w
, menu_b
;
141 /* X gets quite upset if the program name is not simple */
142 if (( ptr
= strrchr( argv
[0], '/' )) != NULL
) argv
[0] = ++ptr
;
143 vi_progname
= argv
[0];
145 /* create a top-level shell for the window manager */
146 top_level
= XtVaAppInitialize( &ctx
,
148 NULL
, 0, /* options */
150 argv
, /* might get modified */
151 get_fallback_rsrcs( argv
[0] ),
154 display
= XtDisplay(top_level
);
156 /* might need to go technicolor... */
157 XutInstallColormap( argv
[0], top_level
);
160 * do this *before* realizing the shell widget in case the -iconic
161 * option was specified.
163 icon_pm
= XCreatePixmapFromBitmapData(
165 DefaultRootWindow(display
),
171 DefaultDepth( display
, DefaultScreen(display
) )
173 XutSetIcon( top_level
, nvi_height
, nvi_width
, icon_pm
);
175 /* in the shell, we will stack a menubar an editor */
176 main_w
= XtVaCreateManagedWidget( "main",
177 xmMainWindowWidgetClass
,
182 /* create the menubar */
183 menu_b
= (Widget
) vi_create_menubar( main_w
);
184 XtManageChild( menu_b
);
186 /* add the VI widget from the library */
187 vi_create_editor( "editor", main_w
, onexit
);
190 XtRealizeWidget( top_level
);
202 * Initialize the X widgetry. We must do this before picking off
203 * arguments as well-behaved X programs have common argument lists
204 * (e.g. -rv for reverse video).
206 create_top_level_shell(&argc
, argv
);
208 /* We need to know if the child process goes away. */
209 (void)signal(SIGCHLD
, onchld
);
211 /* Run vi: the parent returns, the child is the vi process. */
212 (void)vi_run(argc
, argv
, &i_fd
, &vi_ofd
, &pid
);
214 /* Tell X that we are interested in input on the pipe. */
215 XtAppAddInput(ctx
, i_fd
,
216 (XtPointer
)XtInputReadMask
, vi_pipe_input_func
, NULL
);
233 /* If the vi process goes away, we exit as well. */
235 vi_fatal_message(top_level
, "The vi process died. Exiting.");
240 * Function called when the editor "quits".