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.33 1996/12/18 10:27:26 bostic Exp $ (Berkeley) $Date: 1996/12/18 10:27:26 $";
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"
35 #if XtSpecificationRelease == 4
36 #define ArgcType Cardinal *
38 #define ArgcType int *
41 #if defined(ColorIcon)
43 #include "nvi.xpm" /* Icon pixmap. */
45 #include "nvi.xbm" /* Icon bitmap. */
51 static Pixmap icon_pm
;
52 static Widget top_level
;
53 static XtAppContext ctx
;
55 static void XutInstallColormap
__P((String
, Widget
));
56 static void XutSetIcon
__P((Widget
, int, int, Pixmap
));
57 static void onchld
__P((int));
58 static void onexit
__P((void));
60 #if ! defined(ColorIcon)
61 static XutResource resource
[] = {
62 { "iconForeground", XutRKpixel
, &icon_fg
},
63 { "iconBackground", XutRKpixel
, &icon_bg
},
68 /* resources for the vi widgets unless the user overrides them */
69 String fallback_rsrcs
[] = {
71 "*font: -*-*-*-r-*--14-*-*-*-m-*-*-*",
72 "*text*fontList: -*-*-*-r-*--14-*-*-*-m-*-*-*",
73 "*Menu*fontList: -*-helvetica-bold-r-normal--14-*-*-*-*-*-*-*",
74 "*fontList: -*-helvetica-medium-r-normal--14-*-*-*-*-*-*-*",
75 "*pointerShape: xterm",
79 #if ! defined(ColorIcon)
80 /* coloring for the icons */
81 "*iconForeground: XtDefaultForeground",
82 "*iconBackground: XtDefaultBackground",
85 /* layout for the tag stack dialog */
86 "*Tags*visibleItemCount: 5",
88 /* for the text ruler */
89 "*rulerFont: -*-helvetica-medium-r-normal--14-*-*-*-*-*-*-*",
92 /* layout for the new, temporary preferences page */
93 "*toggleOptions.numColumns: 6", /* also used by Find */
94 "*Preferences*tabWidthPercentage: 0",
95 "*Preferences*tabs.shadowThickness: 2",
96 "*Preferences*tabs.font: -*-helvetica-bold-r-normal--14-*-*-*-*-*-*-*",
98 /* --------------------------------------------------------------------- *
99 * anything below this point is only defined when we are not running CDE *
100 * --------------------------------------------------------------------- */
102 /* Do not define default colors when running under CDE
103 * (e.g. VUE on HPUX). The result is that you don't look
104 * like a normal desktop application
106 "?background: gray75",
107 "?screen.background: wheat",
108 "?highlightColor: red",
109 "?Preferences*options.background: gray90",
112 #if defined(__STDC__)
113 static String
*get_fallback_rsrcs( String name
)
115 static String
*get_fallback_rsrcs( name
)
119 String
*copy
= (String
*) malloc( (1+XtNumber(fallback_rsrcs
))*sizeof(String
) );
123 /* connect to server and see if the CDE atoms are present */
125 running_cde
= is_cde( d
);
128 for ( i
=0; i
<XtNumber(fallback_rsrcs
); i
++ ) {
130 /* stop here if running CDE */
131 if ( fallback_rsrcs
[i
][0] == '?' ) {
132 if ( running_cde
) break;
133 fallback_rsrcs
[i
] = strdup(fallback_rsrcs
[i
]);
134 fallback_rsrcs
[i
][0] = '*';
137 copy
[i
] = malloc( strlen(name
) + strlen(fallback_rsrcs
[i
]) + 1 );
138 strcpy( copy
[i
], name
);
139 strcat( copy
[i
], fallback_rsrcs
[i
] );
147 /* create the shell widgetry */
149 #if defined(__STDC__)
150 static void create_top_level_shell( int *argc
, char **argv
)
152 static void create_top_level_shell( argc
, argv
)
158 Widget main_w
, editor
;
161 /* X gets quite upset if the program name is not simple */
162 if (( ptr
= strrchr( argv
[0], '/' )) != NULL
) argv
[0] = ++ptr
;
163 vi_progname
= argv
[0];
165 /* create a top-level shell for the window manager */
166 top_level
= XtVaAppInitialize( &ctx
,
168 NULL
, 0, /* options */
170 argv
, /* might get modified */
171 get_fallback_rsrcs( argv
[0] ),
174 display
= XtDisplay(top_level
);
176 /* might need to go technicolor... */
177 XutInstallColormap( argv
[0], top_level
);
180 * do this *before* realizing the shell widget in case the -iconic
181 * option was specified.
184 #if defined(ColorIcon)
185 int nvi_width
, nvi_height
;
189 XpmCreatePixmapFromData( display
,
190 DefaultRootWindow(display
),
196 nvi_width
= attr
.width
;
197 nvi_height
= attr
.height
;
199 /* check the resource database for interesting resources */
200 __XutConvertResources( top_level
,
206 icon_pm
= XCreatePixmapFromBitmapData(
208 DefaultRootWindow(display
),
214 DefaultDepth( display
, DefaultScreen(display
) )
217 XutSetIcon( top_level
, nvi_height
, nvi_width
, icon_pm
);
220 /* in the shell, we will stack a menubar an editor */
221 main_w
= XtVaCreateManagedWidget( "main",
222 xmMainWindowWidgetClass
,
227 /* create the menubar */
228 XtManageChild( (Widget
) vi_create_menubar( main_w
) );
230 /* add the VI widget from the library */
231 editor
= vi_create_editor( "editor", main_w
, onexit
);
234 XtRealizeWidget( top_level
);
236 /* We *may* want all keyboard events to go to the editing screen.
237 * If the editor is the only widget in the shell that accepts
238 * keyboard input, then the user will expect that he can type when
239 * the pointer is over the scrollbar (for example). This call
240 * causes that to happen.
242 XtSetKeyboardFocus( top_level
, XtNameToWidget( editor
, "*screen" ) );
254 * Initialize the X widgetry. We must do this before picking off
255 * arguments as well-behaved X programs have common argument lists
256 * (e.g. -rv for reverse video).
258 create_top_level_shell(&argc
, argv
);
260 /* We need to know if the child process goes away. */
261 (void)signal(SIGCHLD
, onchld
);
263 /* Run vi: the parent returns, the child is the vi process. */
264 (void)vi_run(argc
, argv
, &i_fd
, &vi_ofd
, &pid
);
266 /* Tell X that we are interested in input on the pipe. */
267 XtAppAddInput(ctx
, i_fd
,
268 (XtPointer
)XtInputReadMask
, vi_input_func
, NULL
);
278 XutSetIcon(wid
, height
, width
, p
)
283 Display
*display
= XtDisplay(wid
);
286 /* best bet is to set the icon window */
287 XtVaGetValues( wid
, XtNiconWindow
, &win
, 0 );
290 win
= XCreateSimpleWindow( display
,
292 DefaultScreen( display
) ),
302 XtVaSetValues( wid
, XtNiconWindow
, win
, 0 );
303 XSetWindowBackgroundPixmap( display
, win
, p
);
307 /* do it the old fashioned way */
308 XtVaSetValues( wid
, XtNiconPixmap
, p
, 0 );
312 /* Support for multiple colormaps
314 * XutInstallColormap( String name, Widget wid )
315 * The first time called, this routine checks to see if the
316 * resource "name*installColormap" is "True". If so, the
317 * widget is assigned a newly allocated colormap.
319 * Subsequent calls ignore the "name" parameter and use the
322 * Future versions of this routine may handle multiple colormaps
325 static enum { cmap_look
, cmap_use
, cmap_ignore
} cmap_state
= cmap_look
;
327 static Boolean use_colormap
= False
;
329 static XutResource colormap_resources
[] = {
330 { "installColormap", XutRKboolean
, &use_colormap
}
334 XutInstallColormap(name
, wid
)
338 static Colormap cmap
= 0;
339 static Display
*cmap_display
= 0;
340 Display
*display
= XtDisplay(wid
);
342 /* what is the current finite state? */
343 if ( cmap_state
== cmap_look
) {
345 /* what does the resource say? */
346 __XutConvertResources( wid
,
349 XtNumber(colormap_resources
)
352 /* was the result "True"? */
353 if ( ! use_colormap
) {
354 cmap_state
= cmap_ignore
;
359 cmap_state
= cmap_use
;
360 cmap_display
= display
;
361 cmap
= XCopyColormapAndFree( display
,
362 DefaultColormap( display
,
363 DefaultScreen( display
)
368 /* use the private colormap? */
369 if ( cmap_state
== cmap_use
) {
370 XtVaSetValues( wid
, XtNcolormap
, cmap
, 0 );
382 /* If the vi process goes away, we exit as well. */
384 vi_fatal_message(top_level
, "The vi process died. Exiting.");
389 * Function called when the editor "quits".