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.39 2001/06/25 15:19:26 skimo Exp $ (Berkeley) $Date: 2001/06/25 15:19: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"
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" ) );
256 main(int argc
, char **argv
)
260 * Initialize the X widgetry. We must do this before picking off
261 * arguments as well-behaved X programs have common argument lists
262 * (e.g. -rv for reverse video).
264 create_top_level_shell(&argc
, argv
);
266 /* We need to know if the child process goes away. */
267 (void)signal(SIGCHLD
, onchld
);
270 (void)ipvi
->run(ipvi
, argc
, argv
);
271 ipvi
->new_window(ipvi
,&ipvi_motif
,-1);
272 ipvi_motif
->set_ops(ipvi_motif
, &ipsi_ops_motif
);
273 /* Run vi: the parent returns, the child is the vi process. */
274 vi_ifd
= ipvi_motif
->ifd
;
275 vi_ofd
= ipvi_motif
->ofd
;
278 /* Tell X that we are interested in input on the pipe. */
279 XtAppAddInput(ctx
, vi_ifd
,
280 (XtPointer
)XtInputReadMask
, vi_input_func
, NULL
);
290 XutSetIcon(Widget wid
, int height
, int width
, Pixmap p
)
292 Display
*display
= XtDisplay(wid
);
295 /* best bet is to set the icon window */
296 XtVaGetValues( wid
, XtNiconWindow
, &win
, 0 );
299 win
= XCreateSimpleWindow( display
,
301 DefaultScreen( display
) ),
311 XtVaSetValues( wid
, XtNiconWindow
, win
, 0 );
312 XSetWindowBackgroundPixmap( display
, win
, p
);
316 /* do it the old fashioned way */
317 XtVaSetValues( wid
, XtNiconPixmap
, p
, 0 );
321 /* Support for multiple colormaps
323 * XutInstallColormap( String name, Widget wid )
324 * The first time called, this routine checks to see if the
325 * resource "name*installColormap" is "True". If so, the
326 * widget is assigned a newly allocated colormap.
328 * Subsequent calls ignore the "name" parameter and use the
331 * Future versions of this routine may handle multiple colormaps
334 static enum { cmap_look
, cmap_use
, cmap_ignore
} cmap_state
= cmap_look
;
336 static Boolean use_colormap
= False
;
338 static XutResource colormap_resources
[] = {
339 { "installColormap", XutRKboolean
, &use_colormap
}
343 XutInstallColormap(String name
, Widget wid
)
345 static Colormap cmap
= 0;
346 static Display
*cmap_display
= 0;
347 Display
*display
= XtDisplay(wid
);
349 /* what is the current finite state? */
350 if ( cmap_state
== cmap_look
) {
352 /* what does the resource say? */
353 __XutConvertResources( wid
,
356 XtNumber(colormap_resources
)
359 /* was the result "True"? */
360 if ( ! use_colormap
) {
361 cmap_state
= cmap_ignore
;
366 cmap_state
= cmap_use
;
367 cmap_display
= display
;
368 cmap
= XCopyColormapAndFree( display
,
369 DefaultColormap( display
,
370 DefaultScreen( display
)
375 /* use the private colormap? */
376 if ( cmap_state
== cmap_use
) {
377 XtVaSetValues( wid
, XtNcolormap
, cmap
, 0 );
388 /* If the vi process goes away, we exit as well. */
390 vi_fatal_message(top_level
, "The vi process died. Exiting.");
395 * Function called when the editor "quits".