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.34 1996/12/18 14:49:49 bostic Exp $ (Berkeley) $Date: 1996/12/18 14:49:49 $";
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)
48 #include "nvi.xpm" /* Icon pixmap. */
50 #include "nvi.xbm" /* Icon bitmap. */
56 static Pixmap icon_pm
;
57 static Widget top_level
;
58 static XtAppContext ctx
;
60 static void XutInstallColormap
__P((String
, Widget
));
61 static void XutSetIcon
__P((Widget
, int, int, Pixmap
));
62 static void onchld
__P((int));
63 static void onexit
__P((void));
65 #if ! defined(ColorIcon)
66 static XutResource resource
[] = {
67 { "iconForeground", XutRKpixel
, &icon_fg
},
68 { "iconBackground", XutRKpixel
, &icon_bg
},
73 /* resources for the vi widgets unless the user overrides them */
74 String fallback_rsrcs
[] = {
76 "*font: -*-*-*-r-*--14-*-*-*-m-*-*-*",
77 "*text*fontList: -*-*-*-r-*--14-*-*-*-m-*-*-*",
78 "*Menu*fontList: -*-helvetica-bold-r-normal--14-*-*-*-*-*-*-*",
79 "*fontList: -*-helvetica-medium-r-normal--14-*-*-*-*-*-*-*",
80 "*pointerShape: xterm",
84 #if ! defined(ColorIcon)
85 /* coloring for the icons */
86 "*iconForeground: XtDefaultForeground",
87 "*iconBackground: XtDefaultBackground",
90 /* layout for the tag stack dialog */
91 "*Tags*visibleItemCount: 5",
93 /* for the text ruler */
94 "*rulerFont: -*-helvetica-medium-r-normal--14-*-*-*-*-*-*-*",
97 /* layout for the new, temporary preferences page */
98 "*toggleOptions.numColumns: 6", /* also used by Find */
99 "*Preferences*tabWidthPercentage: 0",
100 "*Preferences*tabs.shadowThickness: 2",
101 "*Preferences*tabs.font: -*-helvetica-bold-r-normal--14-*-*-*-*-*-*-*",
103 /* --------------------------------------------------------------------- *
104 * anything below this point is only defined when we are not running CDE *
105 * --------------------------------------------------------------------- */
107 /* Do not define default colors when running under CDE
108 * (e.g. VUE on HPUX). The result is that you don't look
109 * like a normal desktop application
111 "?background: gray75",
112 "?screen.background: wheat",
113 "?highlightColor: red",
114 "?Preferences*options.background: gray90",
117 #if defined(__STDC__)
118 static String
*get_fallback_rsrcs( String name
)
120 static String
*get_fallback_rsrcs( name
)
124 String
*copy
= (String
*) malloc( (1+XtNumber(fallback_rsrcs
))*sizeof(String
) );
128 /* connect to server and see if the CDE atoms are present */
130 running_cde
= is_cde( d
);
133 for ( i
=0; i
<XtNumber(fallback_rsrcs
); i
++ ) {
135 /* stop here if running CDE */
136 if ( fallback_rsrcs
[i
][0] == '?' ) {
137 if ( running_cde
) break;
138 fallback_rsrcs
[i
] = strdup(fallback_rsrcs
[i
]);
139 fallback_rsrcs
[i
][0] = '*';
142 copy
[i
] = malloc( strlen(name
) + strlen(fallback_rsrcs
[i
]) + 1 );
143 strcpy( copy
[i
], name
);
144 strcat( copy
[i
], fallback_rsrcs
[i
] );
152 /* create the shell widgetry */
154 #if defined(__STDC__)
155 static void create_top_level_shell( int *argc
, char **argv
)
157 static void create_top_level_shell( argc
, argv
)
163 Widget main_w
, editor
;
166 /* X gets quite upset if the program name is not simple */
167 if (( ptr
= strrchr( argv
[0], '/' )) != NULL
) argv
[0] = ++ptr
;
168 vi_progname
= argv
[0];
170 /* create a top-level shell for the window manager */
171 top_level
= XtVaAppInitialize( &ctx
,
173 NULL
, 0, /* options */
175 argv
, /* might get modified */
176 get_fallback_rsrcs( argv
[0] ),
179 display
= XtDisplay(top_level
);
181 /* might need to go technicolor... */
182 XutInstallColormap( argv
[0], top_level
);
185 * do this *before* realizing the shell widget in case the -iconic
186 * option was specified.
189 #if defined(ColorIcon)
190 int nvi_width
, nvi_height
;
194 XpmCreatePixmapFromData( display
,
195 DefaultRootWindow(display
),
201 nvi_width
= attr
.width
;
202 nvi_height
= attr
.height
;
204 /* check the resource database for interesting resources */
205 __XutConvertResources( top_level
,
211 icon_pm
= XCreatePixmapFromBitmapData(
213 DefaultRootWindow(display
),
219 DefaultDepth( display
, DefaultScreen(display
) )
222 XutSetIcon( top_level
, nvi_height
, nvi_width
, icon_pm
);
225 /* in the shell, we will stack a menubar an editor */
226 main_w
= XtVaCreateManagedWidget( "main",
227 xmMainWindowWidgetClass
,
232 /* create the menubar */
233 XtManageChild( (Widget
) vi_create_menubar( main_w
) );
235 /* add the VI widget from the library */
236 editor
= vi_create_editor( "editor", main_w
, onexit
);
239 XtRealizeWidget( top_level
);
241 /* We *may* want all keyboard events to go to the editing screen.
242 * If the editor is the only widget in the shell that accepts
243 * keyboard input, then the user will expect that he can type when
244 * the pointer is over the scrollbar (for example). This call
245 * causes that to happen.
247 XtSetKeyboardFocus( top_level
, XtNameToWidget( editor
, "*screen" ) );
259 * Initialize the X widgetry. We must do this before picking off
260 * arguments as well-behaved X programs have common argument lists
261 * (e.g. -rv for reverse video).
263 create_top_level_shell(&argc
, argv
);
265 /* We need to know if the child process goes away. */
266 (void)signal(SIGCHLD
, onchld
);
268 /* Run vi: the parent returns, the child is the vi process. */
269 (void)vi_run(argc
, argv
, &i_fd
, &vi_ofd
, &pid
);
271 /* Tell X that we are interested in input on the pipe. */
272 XtAppAddInput(ctx
, i_fd
,
273 (XtPointer
)XtInputReadMask
, vi_input_func
, NULL
);
283 XutSetIcon(wid
, height
, width
, p
)
288 Display
*display
= XtDisplay(wid
);
291 /* best bet is to set the icon window */
292 XtVaGetValues( wid
, XtNiconWindow
, &win
, 0 );
295 win
= XCreateSimpleWindow( display
,
297 DefaultScreen( display
) ),
307 XtVaSetValues( wid
, XtNiconWindow
, win
, 0 );
308 XSetWindowBackgroundPixmap( display
, win
, p
);
312 /* do it the old fashioned way */
313 XtVaSetValues( wid
, XtNiconPixmap
, p
, 0 );
317 /* Support for multiple colormaps
319 * XutInstallColormap( String name, Widget wid )
320 * The first time called, this routine checks to see if the
321 * resource "name*installColormap" is "True". If so, the
322 * widget is assigned a newly allocated colormap.
324 * Subsequent calls ignore the "name" parameter and use the
327 * Future versions of this routine may handle multiple colormaps
330 static enum { cmap_look
, cmap_use
, cmap_ignore
} cmap_state
= cmap_look
;
332 static Boolean use_colormap
= False
;
334 static XutResource colormap_resources
[] = {
335 { "installColormap", XutRKboolean
, &use_colormap
}
339 XutInstallColormap(name
, wid
)
343 static Colormap cmap
= 0;
344 static Display
*cmap_display
= 0;
345 Display
*display
= XtDisplay(wid
);
347 /* what is the current finite state? */
348 if ( cmap_state
== cmap_look
) {
350 /* what does the resource say? */
351 __XutConvertResources( wid
,
354 XtNumber(colormap_resources
)
357 /* was the result "True"? */
358 if ( ! use_colormap
) {
359 cmap_state
= cmap_ignore
;
364 cmap_state
= cmap_use
;
365 cmap_display
= display
;
366 cmap
= XCopyColormapAndFree( display
,
367 DefaultColormap( display
,
368 DefaultScreen( display
)
373 /* use the private colormap? */
374 if ( cmap_state
== cmap_use
) {
375 XtVaSetValues( wid
, XtNcolormap
, cmap
, 0 );
387 /* If the vi process goes away, we exit as well. */
389 vi_fatal_message(top_level
, "The vi process died. Exiting.");
394 * Function called when the editor "quits".