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.38 2000/07/11 15:11:00 skimo Exp $ (Berkeley) $Date: 2000/07/11 15:11:00 $";
16 #include <sys/types.h>
17 #include <sys/queue.h>
19 #include <X11/Intrinsic.h>
20 #include <X11/StringDefs.h>
23 #include <bitstring.h>
29 #include "../common/common.h"
30 #include "../ipc/ip.h"
31 #include "../motif_l/m_motif.h"
32 #include "../motif_l/vi_mextern.h"
39 #if XtSpecificationRelease == 4
40 #define ArgcType Cardinal *
42 #define ArgcType int *
45 #if defined(ColorIcon)
52 #include "nvi.xpm" /* Icon pixmap. */
54 #include "nvi.xbm" /* Icon bitmap. */
60 static Pixmap icon_pm
;
61 static Widget top_level
;
62 static XtAppContext ctx
;
64 static void XutInstallColormap
__P((String
, Widget
));
65 static void XutSetIcon
__P((Widget
, int, int, Pixmap
));
66 static void onchld
__P((int));
67 static void onexit
__P((void));
69 #if ! defined(ColorIcon)
70 static XutResource resource
[] = {
71 { "iconForeground", XutRKpixel
, &icon_fg
},
72 { "iconBackground", XutRKpixel
, &icon_bg
},
77 /* resources for the vi widgets unless the user overrides them */
78 String fallback_rsrcs
[] = {
80 "*font: -*-*-*-r-*--14-*-*-*-m-*-*-*",
81 "*text*fontList: -*-*-*-r-*--14-*-*-*-m-*-*-*",
82 "*Menu*fontList: -*-helvetica-bold-r-normal--14-*-*-*-*-*-*-*",
83 "*fontList: -*-helvetica-medium-r-normal--14-*-*-*-*-*-*-*",
84 "*pointerShape: xterm",
88 #if ! defined(ColorIcon)
89 /* coloring for the icons */
90 "*iconForeground: XtDefaultForeground",
91 "*iconBackground: XtDefaultBackground",
94 /* layout for the tag stack dialog */
95 "*Tags*visibleItemCount: 5",
97 /* for the text ruler */
98 "*rulerFont: -*-helvetica-medium-r-normal--14-*-*-*-*-*-*-*",
101 /* layout for the new, temporary preferences page */
102 "*toggleOptions.numColumns: 6", /* also used by Find */
103 "*Preferences*tabWidthPercentage: 0",
104 "*Preferences*tabs.shadowThickness: 2",
105 "*Preferences*tabs.font: -*-helvetica-bold-r-normal--14-*-*-*-*-*-*-*",
107 /* --------------------------------------------------------------------- *
108 * anything below this point is only defined when we are not running CDE *
109 * --------------------------------------------------------------------- */
111 /* Do not define default colors when running under CDE
112 * (e.g. VUE on HPUX). The result is that you don't look
113 * like a normal desktop application
115 "?background: gray75",
116 "?screen.background: wheat",
117 "?highlightColor: red",
118 "?Preferences*options.background: gray90",
121 #if defined(__STDC__)
122 static String
*get_fallback_rsrcs( String name
)
124 static String
*get_fallback_rsrcs( name
)
128 String
*copy
= (String
*) malloc( (1+XtNumber(fallback_rsrcs
))*sizeof(String
) );
132 /* connect to server and see if the CDE atoms are present */
134 running_cde
= is_cde( d
);
137 for ( i
=0; i
<XtNumber(fallback_rsrcs
); i
++ ) {
139 /* stop here if running CDE */
140 if ( fallback_rsrcs
[i
][0] == '?' ) {
141 if ( running_cde
) break;
142 fallback_rsrcs
[i
] = strdup(fallback_rsrcs
[i
]);
143 fallback_rsrcs
[i
][0] = '*';
146 copy
[i
] = malloc( strlen(name
) + strlen(fallback_rsrcs
[i
]) + 1 );
147 strcpy( copy
[i
], name
);
148 strcat( copy
[i
], fallback_rsrcs
[i
] );
156 /* create the shell widgetry */
158 #if defined(__STDC__)
159 static void create_top_level_shell( int *argc
, char **argv
)
161 static void create_top_level_shell( argc
, argv
)
167 Widget main_w
, editor
;
170 /* X gets quite upset if the program name is not simple */
171 if (( ptr
= strrchr( argv
[0], '/' )) != NULL
) argv
[0] = ++ptr
;
172 vi_progname
= argv
[0];
174 /* create a top-level shell for the window manager */
175 top_level
= XtVaAppInitialize( &ctx
,
177 NULL
, 0, /* options */
179 argv
, /* might get modified */
180 get_fallback_rsrcs( argv
[0] ),
183 display
= XtDisplay(top_level
);
185 /* might need to go technicolor... */
186 XutInstallColormap( argv
[0], top_level
);
189 * do this *before* realizing the shell widget in case the -iconic
190 * option was specified.
193 #if defined(ColorIcon)
194 int nvi_width
, nvi_height
;
198 XpmCreatePixmapFromData( display
,
199 DefaultRootWindow(display
),
205 nvi_width
= attr
.width
;
206 nvi_height
= attr
.height
;
208 /* check the resource database for interesting resources */
209 __XutConvertResources( top_level
,
215 icon_pm
= XCreatePixmapFromBitmapData(
217 DefaultRootWindow(display
),
223 DefaultDepth( display
, DefaultScreen(display
) )
226 XutSetIcon( top_level
, nvi_height
, nvi_width
, icon_pm
);
229 /* in the shell, we will stack a menubar an editor */
230 main_w
= XtVaCreateManagedWidget( "main",
231 xmMainWindowWidgetClass
,
236 /* create the menubar */
237 XtManageChild( (Widget
) vi_create_menubar( main_w
) );
239 /* add the VI widget from the library */
240 editor
= vi_create_editor( "editor", main_w
, onexit
);
243 XtRealizeWidget( top_level
);
245 /* We *may* want all keyboard events to go to the editing screen.
246 * If the editor is the only widget in the shell that accepts
247 * keyboard input, then the user will expect that he can type when
248 * the pointer is over the scrollbar (for example). This call
249 * causes that to happen.
251 XtSetKeyboardFocus( top_level
, XtNameToWidget( editor
, "*screen" ) );
262 * Initialize the X widgetry. We must do this before picking off
263 * arguments as well-behaved X programs have common argument lists
264 * (e.g. -rv for reverse video).
266 create_top_level_shell(&argc
, argv
);
268 /* We need to know if the child process goes away. */
269 (void)signal(SIGCHLD
, onchld
);
272 (void)ipvi
->run(ipvi
, argc
, argv
);
273 ipvi
->new_window(ipvi
,&ipvi_motif
,-1);
274 ipvi_motif
->set_ops(ipvi_motif
, &ipsi_ops_motif
);
275 /* Run vi: the parent returns, the child is the vi process. */
276 vi_ifd
= ipvi_motif
->ifd
;
277 vi_ofd
= ipvi_motif
->ofd
;
280 /* Tell X that we are interested in input on the pipe. */
281 XtAppAddInput(ctx
, vi_ifd
,
282 (XtPointer
)XtInputReadMask
, vi_input_func
, NULL
);
292 XutSetIcon(wid
, height
, width
, p
)
297 Display
*display
= XtDisplay(wid
);
300 /* best bet is to set the icon window */
301 XtVaGetValues( wid
, XtNiconWindow
, &win
, 0 );
304 win
= XCreateSimpleWindow( display
,
306 DefaultScreen( display
) ),
316 XtVaSetValues( wid
, XtNiconWindow
, win
, 0 );
317 XSetWindowBackgroundPixmap( display
, win
, p
);
321 /* do it the old fashioned way */
322 XtVaSetValues( wid
, XtNiconPixmap
, p
, 0 );
326 /* Support for multiple colormaps
328 * XutInstallColormap( String name, Widget wid )
329 * The first time called, this routine checks to see if the
330 * resource "name*installColormap" is "True". If so, the
331 * widget is assigned a newly allocated colormap.
333 * Subsequent calls ignore the "name" parameter and use the
336 * Future versions of this routine may handle multiple colormaps
339 static enum { cmap_look
, cmap_use
, cmap_ignore
} cmap_state
= cmap_look
;
341 static Boolean use_colormap
= False
;
343 static XutResource colormap_resources
[] = {
344 { "installColormap", XutRKboolean
, &use_colormap
}
348 XutInstallColormap(name
, wid
)
352 static Colormap cmap
= 0;
353 static Display
*cmap_display
= 0;
354 Display
*display
= XtDisplay(wid
);
356 /* what is the current finite state? */
357 if ( cmap_state
== cmap_look
) {
359 /* what does the resource say? */
360 __XutConvertResources( wid
,
363 XtNumber(colormap_resources
)
366 /* was the result "True"? */
367 if ( ! use_colormap
) {
368 cmap_state
= cmap_ignore
;
373 cmap_state
= cmap_use
;
374 cmap_display
= display
;
375 cmap
= XCopyColormapAndFree( display
,
376 DefaultColormap( display
,
377 DefaultScreen( display
)
382 /* use the private colormap? */
383 if ( cmap_state
== cmap_use
) {
384 XtVaSetValues( wid
, XtNcolormap
, cmap
, 0 );
396 /* If the vi process goes away, we exit as well. */
398 vi_fatal_message(top_level
, "The vi process died. Exiting.");
403 * Function called when the editor "quits".