3 * Rob Zimmermann. All rights reserved.
5 * Keith Bostic. All rights reserved.
7 * See the LICENSE file for redistribution information.
12 #include <sys/cdefs.h>
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 __RCSID("$NetBSD: m_main.c,v 1.3 2014/01/26 21:43:45 christos Exp $");
21 #include <sys/types.h>
22 #include <sys/queue.h>
24 #include <X11/Intrinsic.h>
25 #include <X11/StringDefs.h>
28 #include <bitstring.h>
35 #include "../common/common.h"
36 #include "../ipc/ip.h"
37 #include "../motif_l/m_motif.h"
38 #include "../motif_l/vi_mextern.h"
44 #if XtSpecificationRelease == 4
45 #define ArgcType Cardinal *
47 #define ArgcType int *
50 #if defined(ColorIcon)
57 #include "nvi.xpm" /* Icon pixmap. */
59 #include "nvi.xbm" /* Icon bitmap. */
65 static Pixmap icon_pm
;
66 static Widget top_level
;
67 static XtAppContext ctx
;
69 static void XutInstallColormap
__P((String
, Widget
));
70 static void XutSetIcon
__P((Widget
, int, int, Pixmap
));
71 static void onchld
__P((int));
72 static void onexit
__P((void));
74 #if ! defined(ColorIcon)
75 static XutResource resource
[] = {
76 { "iconForeground", XutRKpixel
, &icon_fg
},
77 { "iconBackground", XutRKpixel
, &icon_bg
},
82 /* resources for the vi widgets unless the user overrides them */
83 String fallback_rsrcs
[] = {
85 "*font: -*-*-*-r-*--14-*-*-*-m-*-*-*",
86 "*text*fontList: -*-*-*-r-*--14-*-*-*-m-*-*-*",
87 "*Menu*fontList: -*-helvetica-bold-r-normal--14-*-*-*-*-*-*-*",
88 "*fontList: -*-helvetica-medium-r-normal--14-*-*-*-*-*-*-*",
89 "*pointerShape: xterm",
93 #if ! defined(ColorIcon)
94 /* coloring for the icons */
95 "*iconForeground: XtDefaultForeground",
96 "*iconBackground: XtDefaultBackground",
99 /* layout for the tag stack dialog */
100 "*Tags*visibleItemCount: 5",
102 /* for the text ruler */
103 "*rulerFont: -*-helvetica-medium-r-normal--14-*-*-*-*-*-*-*",
106 /* layout for the new, temporary preferences page */
107 "*toggleOptions.numColumns: 6", /* also used by Find */
108 "*Preferences*tabWidthPercentage: 0",
109 "*Preferences*tabs.shadowThickness: 2",
110 "*Preferences*tabs.font: -*-helvetica-bold-r-normal--14-*-*-*-*-*-*-*",
112 /* --------------------------------------------------------------------- *
113 * anything below this point is only defined when we are not running CDE *
114 * --------------------------------------------------------------------- */
116 /* Do not define default colors when running under CDE
117 * (e.g. VUE on HPUX). The result is that you don't look
118 * like a normal desktop application
120 "?background: gray75",
121 "?screen.background: wheat",
122 "?highlightColor: red",
123 "?Preferences*options.background: gray90",
126 #if defined(__STDC__)
127 static String
*get_fallback_rsrcs( String name
)
129 static String
*get_fallback_rsrcs( name
)
133 String
*copy
= (String
*) malloc( (1+XtNumber(fallback_rsrcs
))*sizeof(String
) );
137 /* connect to server and see if the CDE atoms are present */
139 running_cde
= is_cde( d
);
142 for ( i
=0; i
<XtNumber(fallback_rsrcs
); i
++ ) {
144 /* stop here if running CDE */
145 if ( fallback_rsrcs
[i
][0] == '?' ) {
146 if ( running_cde
) break;
147 fallback_rsrcs
[i
] = strdup(fallback_rsrcs
[i
]);
148 fallback_rsrcs
[i
][0] = '*';
151 copy
[i
] = malloc( strlen(name
) + strlen(fallback_rsrcs
[i
]) + 1 );
152 strcpy( copy
[i
], name
);
153 strcat( copy
[i
], fallback_rsrcs
[i
] );
161 /* create the shell widgetry */
163 #if defined(__STDC__)
164 static void create_top_level_shell( int *argc
, char **argv
)
166 static void create_top_level_shell( argc
, argv
)
172 Widget main_w
, editor
;
175 /* X gets quite upset if the program name is not simple */
176 if (( ptr
= strrchr( argv
[0], '/' )) != NULL
) argv
[0] = ++ptr
;
177 vi_progname
= argv
[0];
179 /* create a top-level shell for the window manager */
180 top_level
= XtVaAppInitialize( &ctx
,
182 NULL
, 0, /* options */
184 argv
, /* might get modified */
185 get_fallback_rsrcs( argv
[0] ),
188 display
= XtDisplay(top_level
);
190 /* might need to go technicolor... */
191 XutInstallColormap( argv
[0], top_level
);
194 * do this *before* realizing the shell widget in case the -iconic
195 * option was specified.
198 #if defined(ColorIcon)
199 int nvi_width
, nvi_height
;
203 XpmCreatePixmapFromData( display
,
204 DefaultRootWindow(display
),
210 nvi_width
= attr
.width
;
211 nvi_height
= attr
.height
;
213 /* check the resource database for interesting resources */
214 __XutConvertResources( top_level
,
220 icon_pm
= XCreatePixmapFromBitmapData(
222 DefaultRootWindow(display
),
228 DefaultDepth( display
, DefaultScreen(display
) )
231 XutSetIcon( top_level
, nvi_height
, nvi_width
, icon_pm
);
234 /* in the shell, we will stack a menubar an editor */
235 main_w
= XtVaCreateManagedWidget( "main",
236 xmMainWindowWidgetClass
,
241 /* create the menubar */
242 XtManageChild( (Widget
) vi_create_menubar( main_w
) );
244 /* add the VI widget from the library */
245 editor
= vi_create_editor( "editor", main_w
, onexit
);
248 XtRealizeWidget( top_level
);
250 /* We *may* want all keyboard events to go to the editing screen.
251 * If the editor is the only widget in the shell that accepts
252 * keyboard input, then the user will expect that he can type when
253 * the pointer is over the scrollbar (for example). This call
254 * causes that to happen.
256 XtSetKeyboardFocus( top_level
, XtNameToWidget( editor
, "*screen" ) );
261 main(int argc
, char **argv
)
265 * Initialize the X widgetry. We must do this before picking off
266 * arguments as well-behaved X programs have common argument lists
267 * (e.g. -rv for reverse video).
269 create_top_level_shell(&argc
, argv
);
271 /* We need to know if the child process goes away. */
272 (void)signal(SIGCHLD
, onchld
);
275 (void)ipvi
->run(ipvi
, argc
, argv
);
276 ipvi
->new_window(ipvi
,&ipvi_motif
,-1);
277 ipvi_motif
->set_ops(ipvi_motif
, &ipsi_ops_motif
);
278 /* Run vi: the parent returns, the child is the vi process. */
279 vi_ifd
= ipvi_motif
->ifd
;
280 vi_ofd
= ipvi_motif
->ofd
;
283 /* Tell X that we are interested in input on the pipe. */
284 XtAppAddInput(ctx
, vi_ifd
,
285 (XtPointer
)XtInputReadMask
, vi_input_func
, NULL
);
295 XutSetIcon(Widget wid
, int height
, int width
, Pixmap p
)
297 Display
*display
= XtDisplay(wid
);
300 /* best bet is to set the icon window */
301 XtVaGetValues( wid
, XtNiconWindow
, &win
, 0 );
304 win
= XCreateSimpleWindow( display
,
306 DefaultScreen( display
) ),
316 XtVaSetValues( wid
, XtNiconWindow
, win
, 0 );
317 XSetWindowBackgroundPixmap( display
, win
, p
);
321 /* do it the old fashioned way */
322 XtVaSetValues( wid
, XtNiconPixmap
, p
, 0 );
326 /* Support for multiple colormaps
328 * XutInstallColormap( String name, Widget wid )
329 * The first time called, this routine checks to see if the
330 * resource "name*installColormap" is "True". If so, the
331 * widget is assigned a newly allocated colormap.
333 * Subsequent calls ignore the "name" parameter and use the
336 * Future versions of this routine may handle multiple colormaps
339 static enum { cmap_look
, cmap_use
, cmap_ignore
} cmap_state
= cmap_look
;
341 static Boolean use_colormap
= False
;
343 static XutResource colormap_resources
[] = {
344 { "installColormap", XutRKboolean
, &use_colormap
}
348 XutInstallColormap(String name
, Widget wid
)
350 static Colormap cmap
= 0;
351 static Display
*cmap_display
= 0;
352 Display
*display
= XtDisplay(wid
);
354 /* what is the current finite state? */
355 if ( cmap_state
== cmap_look
) {
357 /* what does the resource say? */
358 __XutConvertResources( wid
,
361 XtNumber(colormap_resources
)
364 /* was the result "True"? */
365 if ( ! use_colormap
) {
366 cmap_state
= cmap_ignore
;
371 cmap_state
= cmap_use
;
372 cmap_display
= display
;
373 cmap
= XCopyColormapAndFree( display
,
374 DefaultColormap( display
,
375 DefaultScreen( display
)
380 /* use the private colormap? */
381 if ( cmap_state
== cmap_use
) {
382 XtVaSetValues( wid
, XtNcolormap
, cmap
, 0 );
393 /* If the vi process goes away, we exit as well. */
395 vi_fatal_message(top_level
, "The vi process died. Exiting.");
400 * Function called when the editor "quits".