5 * Rob Zimmermann. All rights reserved.
7 * Keith Bostic. All rights reserved.
9 * See the LICENSE file for redistribution information.
15 static const char sccsid
[] = "Id: m_main.c,v 8.40 2003/11/05 17:09:58 skimo Exp (Berkeley) Date: 2003/11/05 17:09:58";
18 #include <sys/types.h>
19 #include <sys/queue.h>
21 #include <X11/Intrinsic.h>
22 #include <X11/StringDefs.h>
25 #include <bitstring.h>
32 #include "../common/common.h"
33 #include "../ipc/ip.h"
34 #include "../motif_l/m_motif.h"
35 #include "../motif_l/vi_mextern.h"
42 #if XtSpecificationRelease == 4
43 #define ArgcType Cardinal *
45 #define ArgcType int *
48 #if defined(ColorIcon)
55 #include "nvi.xpm" /* Icon pixmap. */
57 #include "nvi.xbm" /* Icon bitmap. */
63 static Pixmap icon_pm
;
64 static Widget top_level
;
65 static XtAppContext ctx
;
67 static void XutInstallColormap
__P((String
, Widget
));
68 static void XutSetIcon
__P((Widget
, int, int, Pixmap
));
69 static void onchld
__P((int));
70 static void onexit
__P((void));
72 #if ! defined(ColorIcon)
73 static XutResource resource
[] = {
74 { "iconForeground", XutRKpixel
, &icon_fg
},
75 { "iconBackground", XutRKpixel
, &icon_bg
},
80 /* resources for the vi widgets unless the user overrides them */
81 String fallback_rsrcs
[] = {
83 "*font: -*-*-*-r-*--14-*-*-*-m-*-*-*",
84 "*text*fontList: -*-*-*-r-*--14-*-*-*-m-*-*-*",
85 "*Menu*fontList: -*-helvetica-bold-r-normal--14-*-*-*-*-*-*-*",
86 "*fontList: -*-helvetica-medium-r-normal--14-*-*-*-*-*-*-*",
87 "*pointerShape: xterm",
91 #if ! defined(ColorIcon)
92 /* coloring for the icons */
93 "*iconForeground: XtDefaultForeground",
94 "*iconBackground: XtDefaultBackground",
97 /* layout for the tag stack dialog */
98 "*Tags*visibleItemCount: 5",
100 /* for the text ruler */
101 "*rulerFont: -*-helvetica-medium-r-normal--14-*-*-*-*-*-*-*",
104 /* layout for the new, temporary preferences page */
105 "*toggleOptions.numColumns: 6", /* also used by Find */
106 "*Preferences*tabWidthPercentage: 0",
107 "*Preferences*tabs.shadowThickness: 2",
108 "*Preferences*tabs.font: -*-helvetica-bold-r-normal--14-*-*-*-*-*-*-*",
110 /* --------------------------------------------------------------------- *
111 * anything below this point is only defined when we are not running CDE *
112 * --------------------------------------------------------------------- */
114 /* Do not define default colors when running under CDE
115 * (e.g. VUE on HPUX). The result is that you don't look
116 * like a normal desktop application
118 "?background: gray75",
119 "?screen.background: wheat",
120 "?highlightColor: red",
121 "?Preferences*options.background: gray90",
124 #if defined(__STDC__)
125 static String
*get_fallback_rsrcs( String name
)
127 static String
*get_fallback_rsrcs( name
)
131 String
*copy
= (String
*) malloc( (1+XtNumber(fallback_rsrcs
))*sizeof(String
) );
135 /* connect to server and see if the CDE atoms are present */
137 running_cde
= is_cde( d
);
140 for ( i
=0; i
<XtNumber(fallback_rsrcs
); i
++ ) {
142 /* stop here if running CDE */
143 if ( fallback_rsrcs
[i
][0] == '?' ) {
144 if ( running_cde
) break;
145 fallback_rsrcs
[i
] = strdup(fallback_rsrcs
[i
]);
146 fallback_rsrcs
[i
][0] = '*';
149 copy
[i
] = malloc( strlen(name
) + strlen(fallback_rsrcs
[i
]) + 1 );
150 strcpy( copy
[i
], name
);
151 strcat( copy
[i
], fallback_rsrcs
[i
] );
159 /* create the shell widgetry */
161 #if defined(__STDC__)
162 static void create_top_level_shell( int *argc
, char **argv
)
164 static void create_top_level_shell( argc
, argv
)
170 Widget main_w
, editor
;
173 /* X gets quite upset if the program name is not simple */
174 if (( ptr
= strrchr( argv
[0], '/' )) != NULL
) argv
[0] = ++ptr
;
175 vi_progname
= argv
[0];
177 /* create a top-level shell for the window manager */
178 top_level
= XtVaAppInitialize( &ctx
,
180 NULL
, 0, /* options */
182 argv
, /* might get modified */
183 get_fallback_rsrcs( argv
[0] ),
186 display
= XtDisplay(top_level
);
188 /* might need to go technicolor... */
189 XutInstallColormap( argv
[0], top_level
);
192 * do this *before* realizing the shell widget in case the -iconic
193 * option was specified.
196 #if defined(ColorIcon)
197 int nvi_width
, nvi_height
;
201 XpmCreatePixmapFromData( display
,
202 DefaultRootWindow(display
),
208 nvi_width
= attr
.width
;
209 nvi_height
= attr
.height
;
211 /* check the resource database for interesting resources */
212 __XutConvertResources( top_level
,
218 icon_pm
= XCreatePixmapFromBitmapData(
220 DefaultRootWindow(display
),
226 DefaultDepth( display
, DefaultScreen(display
) )
229 XutSetIcon( top_level
, nvi_height
, nvi_width
, icon_pm
);
232 /* in the shell, we will stack a menubar an editor */
233 main_w
= XtVaCreateManagedWidget( "main",
234 xmMainWindowWidgetClass
,
239 /* create the menubar */
240 XtManageChild( (Widget
) vi_create_menubar( main_w
) );
242 /* add the VI widget from the library */
243 editor
= vi_create_editor( "editor", main_w
, onexit
);
246 XtRealizeWidget( top_level
);
248 /* We *may* want all keyboard events to go to the editing screen.
249 * If the editor is the only widget in the shell that accepts
250 * keyboard input, then the user will expect that he can type when
251 * the pointer is over the scrollbar (for example). This call
252 * causes that to happen.
254 XtSetKeyboardFocus( top_level
, XtNameToWidget( editor
, "*screen" ) );
259 main(int argc
, char **argv
)
263 * Initialize the X widgetry. We must do this before picking off
264 * arguments as well-behaved X programs have common argument lists
265 * (e.g. -rv for reverse video).
267 create_top_level_shell(&argc
, argv
);
269 /* We need to know if the child process goes away. */
270 (void)signal(SIGCHLD
, onchld
);
273 (void)ipvi
->run(ipvi
, argc
, argv
);
274 ipvi
->new_window(ipvi
,&ipvi_motif
,-1);
275 ipvi_motif
->set_ops(ipvi_motif
, &ipsi_ops_motif
);
276 /* Run vi: the parent returns, the child is the vi process. */
277 vi_ifd
= ipvi_motif
->ifd
;
278 vi_ofd
= ipvi_motif
->ofd
;
281 /* Tell X that we are interested in input on the pipe. */
282 XtAppAddInput(ctx
, vi_ifd
,
283 (XtPointer
)XtInputReadMask
, vi_input_func
, NULL
);
293 XutSetIcon(Widget wid
, int height
, int width
, Pixmap p
)
295 Display
*display
= XtDisplay(wid
);
298 /* best bet is to set the icon window */
299 XtVaGetValues( wid
, XtNiconWindow
, &win
, 0 );
302 win
= XCreateSimpleWindow( display
,
304 DefaultScreen( display
) ),
314 XtVaSetValues( wid
, XtNiconWindow
, win
, 0 );
315 XSetWindowBackgroundPixmap( display
, win
, p
);
319 /* do it the old fashioned way */
320 XtVaSetValues( wid
, XtNiconPixmap
, p
, 0 );
324 /* Support for multiple colormaps
326 * XutInstallColormap( String name, Widget wid )
327 * The first time called, this routine checks to see if the
328 * resource "name*installColormap" is "True". If so, the
329 * widget is assigned a newly allocated colormap.
331 * Subsequent calls ignore the "name" parameter and use the
334 * Future versions of this routine may handle multiple colormaps
337 static enum { cmap_look
, cmap_use
, cmap_ignore
} cmap_state
= cmap_look
;
339 static Boolean use_colormap
= False
;
341 static XutResource colormap_resources
[] = {
342 { "installColormap", XutRKboolean
, &use_colormap
}
346 XutInstallColormap(String name
, Widget wid
)
348 static Colormap cmap
= 0;
349 static Display
*cmap_display
= 0;
350 Display
*display
= XtDisplay(wid
);
352 /* what is the current finite state? */
353 if ( cmap_state
== cmap_look
) {
355 /* what does the resource say? */
356 __XutConvertResources( wid
,
359 XtNumber(colormap_resources
)
362 /* was the result "True"? */
363 if ( ! use_colormap
) {
364 cmap_state
= cmap_ignore
;
369 cmap_state
= cmap_use
;
370 cmap_display
= display
;
371 cmap
= XCopyColormapAndFree( display
,
372 DefaultColormap( display
,
373 DefaultScreen( display
)
378 /* use the private colormap? */
379 if ( cmap_state
== cmap_use
) {
380 XtVaSetValues( wid
, XtNcolormap
, cmap
, 0 );
391 /* If the vi process goes away, we exit as well. */
393 vi_fatal_message(top_level
, "The vi process died. Exiting.");
398 * Function called when the editor "quits".