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.40 2003/11/05 17:09:58 skimo Exp $ (Berkeley) $Date: 2003/11/05 17:09:58 $";
16 #include <sys/types.h>
17 #include <sys/queue.h>
19 #include <X11/Intrinsic.h>
20 #include <X11/StringDefs.h>
23 #include <bitstring.h>
30 #include "../common/common.h"
31 #include "../ipc/ip.h"
32 #include "../motif_l/m_motif.h"
33 #include "../motif_l/vi_mextern.h"
40 #if XtSpecificationRelease == 4
41 #define ArgcType Cardinal *
43 #define ArgcType int *
46 #if defined(ColorIcon)
53 #include "nvi.xpm" /* Icon pixmap. */
55 #include "nvi.xbm" /* Icon bitmap. */
61 static Pixmap icon_pm
;
62 static Widget top_level
;
63 static XtAppContext ctx
;
65 static void XutInstallColormap
__P((String
, Widget
));
66 static void XutSetIcon
__P((Widget
, int, int, Pixmap
));
67 static void onchld
__P((int));
68 static void onexit
__P((void));
70 #if ! defined(ColorIcon)
71 static XutResource resource
[] = {
72 { "iconForeground", XutRKpixel
, &icon_fg
},
73 { "iconBackground", XutRKpixel
, &icon_bg
},
78 /* resources for the vi widgets unless the user overrides them */
79 String fallback_rsrcs
[] = {
81 "*font: -*-*-*-r-*--14-*-*-*-m-*-*-*",
82 "*text*fontList: -*-*-*-r-*--14-*-*-*-m-*-*-*",
83 "*Menu*fontList: -*-helvetica-bold-r-normal--14-*-*-*-*-*-*-*",
84 "*fontList: -*-helvetica-medium-r-normal--14-*-*-*-*-*-*-*",
85 "*pointerShape: xterm",
89 #if ! defined(ColorIcon)
90 /* coloring for the icons */
91 "*iconForeground: XtDefaultForeground",
92 "*iconBackground: XtDefaultBackground",
95 /* layout for the tag stack dialog */
96 "*Tags*visibleItemCount: 5",
98 /* for the text ruler */
99 "*rulerFont: -*-helvetica-medium-r-normal--14-*-*-*-*-*-*-*",
102 /* layout for the new, temporary preferences page */
103 "*toggleOptions.numColumns: 6", /* also used by Find */
104 "*Preferences*tabWidthPercentage: 0",
105 "*Preferences*tabs.shadowThickness: 2",
106 "*Preferences*tabs.font: -*-helvetica-bold-r-normal--14-*-*-*-*-*-*-*",
108 /* --------------------------------------------------------------------- *
109 * anything below this point is only defined when we are not running CDE *
110 * --------------------------------------------------------------------- */
112 /* Do not define default colors when running under CDE
113 * (e.g. VUE on HPUX). The result is that you don't look
114 * like a normal desktop application
116 "?background: gray75",
117 "?screen.background: wheat",
118 "?highlightColor: red",
119 "?Preferences*options.background: gray90",
122 #if defined(__STDC__)
123 static String
*get_fallback_rsrcs( String name
)
125 static String
*get_fallback_rsrcs( name
)
129 String
*copy
= (String
*) malloc( (1+XtNumber(fallback_rsrcs
))*sizeof(String
) );
133 /* connect to server and see if the CDE atoms are present */
135 running_cde
= is_cde( d
);
138 for ( i
=0; i
<XtNumber(fallback_rsrcs
); i
++ ) {
140 /* stop here if running CDE */
141 if ( fallback_rsrcs
[i
][0] == '?' ) {
142 if ( running_cde
) break;
143 fallback_rsrcs
[i
] = strdup(fallback_rsrcs
[i
]);
144 fallback_rsrcs
[i
][0] = '*';
147 copy
[i
] = malloc( strlen(name
) + strlen(fallback_rsrcs
[i
]) + 1 );
148 strcpy( copy
[i
], name
);
149 strcat( copy
[i
], fallback_rsrcs
[i
] );
157 /* create the shell widgetry */
159 #if defined(__STDC__)
160 static void create_top_level_shell( int *argc
, char **argv
)
162 static void create_top_level_shell( argc
, argv
)
168 Widget main_w
, editor
;
171 /* X gets quite upset if the program name is not simple */
172 if (( ptr
= strrchr( argv
[0], '/' )) != NULL
) argv
[0] = ++ptr
;
173 vi_progname
= argv
[0];
175 /* create a top-level shell for the window manager */
176 top_level
= XtVaAppInitialize( &ctx
,
178 NULL
, 0, /* options */
180 argv
, /* might get modified */
181 get_fallback_rsrcs( argv
[0] ),
184 display
= XtDisplay(top_level
);
186 /* might need to go technicolor... */
187 XutInstallColormap( argv
[0], top_level
);
190 * do this *before* realizing the shell widget in case the -iconic
191 * option was specified.
194 #if defined(ColorIcon)
195 int nvi_width
, nvi_height
;
199 XpmCreatePixmapFromData( display
,
200 DefaultRootWindow(display
),
206 nvi_width
= attr
.width
;
207 nvi_height
= attr
.height
;
209 /* check the resource database for interesting resources */
210 __XutConvertResources( top_level
,
216 icon_pm
= XCreatePixmapFromBitmapData(
218 DefaultRootWindow(display
),
224 DefaultDepth( display
, DefaultScreen(display
) )
227 XutSetIcon( top_level
, nvi_height
, nvi_width
, icon_pm
);
230 /* in the shell, we will stack a menubar an editor */
231 main_w
= XtVaCreateManagedWidget( "main",
232 xmMainWindowWidgetClass
,
237 /* create the menubar */
238 XtManageChild( (Widget
) vi_create_menubar( main_w
) );
240 /* add the VI widget from the library */
241 editor
= vi_create_editor( "editor", main_w
, onexit
);
244 XtRealizeWidget( top_level
);
246 /* We *may* want all keyboard events to go to the editing screen.
247 * If the editor is the only widget in the shell that accepts
248 * keyboard input, then the user will expect that he can type when
249 * the pointer is over the scrollbar (for example). This call
250 * causes that to happen.
252 XtSetKeyboardFocus( top_level
, XtNameToWidget( editor
, "*screen" ) );
257 main(int argc
, char **argv
)
261 * Initialize the X widgetry. We must do this before picking off
262 * arguments as well-behaved X programs have common argument lists
263 * (e.g. -rv for reverse video).
265 create_top_level_shell(&argc
, argv
);
267 /* We need to know if the child process goes away. */
268 (void)signal(SIGCHLD
, onchld
);
271 (void)ipvi
->run(ipvi
, argc
, argv
);
272 ipvi
->new_window(ipvi
,&ipvi_motif
,-1);
273 ipvi_motif
->set_ops(ipvi_motif
, &ipsi_ops_motif
);
274 /* Run vi: the parent returns, the child is the vi process. */
275 vi_ifd
= ipvi_motif
->ifd
;
276 vi_ofd
= ipvi_motif
->ofd
;
279 /* Tell X that we are interested in input on the pipe. */
280 XtAppAddInput(ctx
, vi_ifd
,
281 (XtPointer
)XtInputReadMask
, vi_input_func
, NULL
);
291 XutSetIcon(Widget wid
, int height
, int width
, Pixmap p
)
293 Display
*display
= XtDisplay(wid
);
296 /* best bet is to set the icon window */
297 XtVaGetValues( wid
, XtNiconWindow
, &win
, 0 );
300 win
= XCreateSimpleWindow( display
,
302 DefaultScreen( display
) ),
312 XtVaSetValues( wid
, XtNiconWindow
, win
, 0 );
313 XSetWindowBackgroundPixmap( display
, win
, p
);
317 /* do it the old fashioned way */
318 XtVaSetValues( wid
, XtNiconPixmap
, p
, 0 );
322 /* Support for multiple colormaps
324 * XutInstallColormap( String name, Widget wid )
325 * The first time called, this routine checks to see if the
326 * resource "name*installColormap" is "True". If so, the
327 * widget is assigned a newly allocated colormap.
329 * Subsequent calls ignore the "name" parameter and use the
332 * Future versions of this routine may handle multiple colormaps
335 static enum { cmap_look
, cmap_use
, cmap_ignore
} cmap_state
= cmap_look
;
337 static Boolean use_colormap
= False
;
339 static XutResource colormap_resources
[] = {
340 { "installColormap", XutRKboolean
, &use_colormap
}
344 XutInstallColormap(String name
, Widget wid
)
346 static Colormap cmap
= 0;
347 static Display
*cmap_display
= 0;
348 Display
*display
= XtDisplay(wid
);
350 /* what is the current finite state? */
351 if ( cmap_state
== cmap_look
) {
353 /* what does the resource say? */
354 __XutConvertResources( wid
,
357 XtNumber(colormap_resources
)
360 /* was the result "True"? */
361 if ( ! use_colormap
) {
362 cmap_state
= cmap_ignore
;
367 cmap_state
= cmap_use
;
368 cmap_display
= display
;
369 cmap
= XCopyColormapAndFree( display
,
370 DefaultColormap( display
,
371 DefaultScreen( display
)
376 /* use the private colormap? */
377 if ( cmap_state
== cmap_use
) {
378 XtVaSetValues( wid
, XtNcolormap
, cmap
, 0 );
389 /* If the vi process goes away, we exit as well. */
391 vi_fatal_message(top_level
, "The vi process died. Exiting.");
396 * Function called when the editor "quits".