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.32 1996/12/17 17:03:36 bostic Exp $ (Berkeley) $Date: 1996/12/17 17:03:36 $";
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 "../motif_l/m_motif.h"
31 #include "../motif_l/vi_mextern.h"
34 #if XtSpecificationRelease == 4
35 #define ArgcType Cardinal *
37 #define ArgcType int *
40 #if defined(ColorIcon)
42 #include "nvi.xpm" /* Icon pixmap. */
44 #include "nvi.xbm" /* Icon bitmap. */
50 static Pixmap icon_pm
;
51 static Widget top_level
;
52 static XtAppContext ctx
;
54 static void XutInstallColormap
__P((String
, Widget
));
55 static void XutSetIcon
__P((Widget
, int, int, Pixmap
));
56 static void onchld
__P((int));
57 static void onexit
__P((void));
59 #if ! defined(ColorIcon)
60 static XutResource resource
[] = {
61 { "iconForeground", XutRKpixel
, &icon_fg
},
62 { "iconBackground", XutRKpixel
, &icon_bg
},
67 /* resources for the vi widgets unless the user overrides them */
68 String fallback_rsrcs
[] = {
70 "*font: -*-*-*-r-*--14-*-*-*-m-*-*-*",
71 "*text*fontList: -*-*-*-r-*--14-*-*-*-m-*-*-*",
72 "*Menu*fontList: -*-helvetica-bold-r-normal--14-*-*-*-*-*-*-*",
73 "*fontList: -*-helvetica-medium-r-normal--14-*-*-*-*-*-*-*",
74 "*pointerShape: xterm",
78 #if ! defined(ColorIcon)
79 /* coloring for the icons */
80 "*iconForeground: XtDefaultForeground",
81 "*iconBackground: XtDefaultBackground",
84 /* layout for the tag stack dialog */
85 "*Tags*visibleItemCount: 5",
87 /* for the text ruler */
88 "*rulerFont: -*-helvetica-medium-r-normal--14-*-*-*-*-*-*-*",
91 /* layout for the new, temporary preferences page */
92 "*toggleOptions.numColumns: 6", /* also used by Find */
93 "*Preferences*tabWidthPercentage: 0",
94 "*Preferences*tabs.shadowThickness: 2",
95 "*Preferences*tabs.font: -*-helvetica-bold-r-normal--14-*-*-*-*-*-*-*",
97 /* --------------------------------------------------------------------- *
98 * anything below this point is only defined when we are not running CDE *
99 * --------------------------------------------------------------------- */
101 /* Do not define default colors when running under CDE
102 * (e.g. VUE on HPUX). The result is that you don't look
103 * like a normal desktop application
105 "?background: gray75",
106 "?screen.background: wheat",
107 "?highlightColor: red",
108 "?Preferences*options.background: gray90",
111 #if defined(__STDC__)
112 static String
*get_fallback_rsrcs( String name
)
114 static String
*get_fallback_rsrcs( name
)
118 String
*copy
= (String
*) malloc( (1+XtNumber(fallback_rsrcs
))*sizeof(String
) );
122 /* connect to server and see if the CDE atoms are present */
124 running_cde
= is_cde( d
);
127 for ( i
=0; i
<XtNumber(fallback_rsrcs
); i
++ ) {
129 /* stop here if running CDE */
130 if ( fallback_rsrcs
[i
][0] == '?' ) {
131 if ( running_cde
) break;
132 fallback_rsrcs
[i
] = strdup(fallback_rsrcs
[i
]);
133 fallback_rsrcs
[i
][0] = '*';
136 copy
[i
] = malloc( strlen(name
) + strlen(fallback_rsrcs
[i
]) + 1 );
137 strcpy( copy
[i
], name
);
138 strcat( copy
[i
], fallback_rsrcs
[i
] );
146 /* create the shell widgetry */
148 #if defined(__STDC__)
149 static void create_top_level_shell( int *argc
, char **argv
)
151 static void create_top_level_shell( argc
, argv
)
157 Widget main_w
, editor
;
160 /* X gets quite upset if the program name is not simple */
161 if (( ptr
= strrchr( argv
[0], '/' )) != NULL
) argv
[0] = ++ptr
;
162 vi_progname
= argv
[0];
164 /* create a top-level shell for the window manager */
165 top_level
= XtVaAppInitialize( &ctx
,
167 NULL
, 0, /* options */
169 argv
, /* might get modified */
170 get_fallback_rsrcs( argv
[0] ),
173 display
= XtDisplay(top_level
);
175 /* might need to go technicolor... */
176 XutInstallColormap( argv
[0], top_level
);
179 * do this *before* realizing the shell widget in case the -iconic
180 * option was specified.
183 #if defined(ColorIcon)
184 int nvi_width
, nvi_height
;
188 XpmCreatePixmapFromData( display
,
189 DefaultRootWindow(display
),
195 nvi_width
= attr
.width
;
196 nvi_height
= attr
.height
;
198 /* check the resource database for interesting resources */
199 __XutConvertResources( top_level
,
205 icon_pm
= XCreatePixmapFromBitmapData(
207 DefaultRootWindow(display
),
213 DefaultDepth( display
, DefaultScreen(display
) )
216 XutSetIcon( top_level
, nvi_height
, nvi_width
, icon_pm
);
219 /* in the shell, we will stack a menubar an editor */
220 main_w
= XtVaCreateManagedWidget( "main",
221 xmMainWindowWidgetClass
,
226 /* create the menubar */
227 XtManageChild( (Widget
) vi_create_menubar( main_w
) );
229 /* add the VI widget from the library */
230 editor
= vi_create_editor( "editor", main_w
, onexit
);
233 XtRealizeWidget( top_level
);
235 /* We *may* want all keyboard events to go to the editing screen.
236 * If the editor is the only widget in the shell that accepts
237 * keyboard input, then the user will expect that he can type when
238 * the pointer is over the scrollbar (for example). This call
239 * causes that to happen.
241 XtSetKeyboardFocus( top_level
, XtNameToWidget( editor
, "*screen" ) );
253 * Initialize the X widgetry. We must do this before picking off
254 * arguments as well-behaved X programs have common argument lists
255 * (e.g. -rv for reverse video).
257 create_top_level_shell(&argc
, argv
);
259 /* We need to know if the child process goes away. */
260 (void)signal(SIGCHLD
, onchld
);
262 /* Run vi: the parent returns, the child is the vi process. */
263 (void)vi_run(argc
, argv
, &i_fd
, &vi_ofd
, &pid
);
265 /* Tell X that we are interested in input on the pipe. */
266 XtAppAddInput(ctx
, i_fd
,
267 (XtPointer
)XtInputReadMask
, vi_input_func
, NULL
);
277 XutSetIcon(wid
, height
, width
, p
)
282 Display
*display
= XtDisplay(wid
);
285 /* best bet is to set the icon window */
286 XtVaGetValues( wid
, XtNiconWindow
, &win
, 0 );
289 win
= XCreateSimpleWindow( display
,
291 DefaultScreen( display
) ),
301 XtVaSetValues( wid
, XtNiconWindow
, win
, 0 );
302 XSetWindowBackgroundPixmap( display
, win
, p
);
306 /* do it the old fashioned way */
307 XtVaSetValues( wid
, XtNiconPixmap
, p
, 0 );
311 /* Support for multiple colormaps
313 * XutInstallColormap( String name, Widget wid )
314 * The first time called, this routine checks to see if the
315 * resource "name*installColormap" is "True". If so, the
316 * widget is assigned a newly allocated colormap.
318 * Subsequent calls ignore the "name" parameter and use the
321 * Future versions of this routine may handle multiple colormaps
324 static enum { cmap_look
, cmap_use
, cmap_ignore
} cmap_state
= cmap_look
;
326 static Boolean use_colormap
= False
;
328 static XutResource colormap_resources
[] = {
329 { "installColormap", XutRKboolean
, &use_colormap
}
333 XutInstallColormap(name
, wid
)
337 static Colormap cmap
= 0;
338 static Display
*cmap_display
= 0;
339 Display
*display
= XtDisplay(wid
);
341 /* what is the current finite state? */
342 if ( cmap_state
== cmap_look
) {
344 /* what does the resource say? */
345 __XutConvertResources( wid
,
348 XtNumber(colormap_resources
)
351 /* was the result "True"? */
352 if ( ! use_colormap
) {
353 cmap_state
= cmap_ignore
;
358 cmap_state
= cmap_use
;
359 cmap_display
= display
;
360 cmap
= XCopyColormapAndFree( display
,
361 DefaultColormap( display
,
362 DefaultScreen( display
)
367 /* use the private colormap? */
368 if ( cmap_state
== cmap_use
) {
369 XtVaSetValues( wid
, XtNcolormap
, cmap
, 0 );
381 /* If the vi process goes away, we exit as well. */
383 vi_fatal_message(top_level
, "The vi process died. Exiting.");
388 * Function called when the editor "quits".