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.29 1996/12/16 17:24:17 bostic Exp $ (Berkeley) $Date: 1996/12/16 17:24:17 $";
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/vi_mextern.h"
33 #if XtSpecificationRelease == 4
34 #define ArgcType Cardinal *
36 #define ArgcType int *
39 #include "nvi.xbm" /* Icon bitmap. */
44 static Pixmap icon_pm
;
45 static Widget top_level
;
46 static XtAppContext ctx
;
48 static void onchld
__P((int));
49 static void onexit
__P((void));
52 /* resources for the vi widgets unless the user overrides them */
53 String fallback_rsrcs
[] = {
55 "*font: -*-*-*-r-*--14-*-*-*-m-*-*-*",
56 "*text*fontList: -*-*-*-r-*--14-*-*-*-m-*-*-*",
57 "*Menu*fontList: -*-helvetica-bold-r-normal--14-*-*-*-*-*-*-*",
58 "*fontList: -*-helvetica-medium-r-normal--14-*-*-*-*-*-*-*",
59 "*pointerShape: xterm",
63 /* coloring for the icons */
64 "*iconForeground: XtDefaultForeground",
65 "*iconBackground: XtDefaultBackground",
67 /* layout for the tag stack dialog */
68 "*Tags*visibleItemCount: 5",
70 /* for the text ruler */
71 "*rulerFont: -*-helvetica-medium-r-normal--14-*-*-*-*-*-*-*",
74 /* layout for the new, temporary preferences page */
75 "*toggleOptions.numColumns: 6", /* also used by Find */
76 "*Preferences*tabWidthPercentage: 0",
77 "*Preferences*tabs.shadowThickness: 2",
78 "*Preferences*tabs.font: -*-helvetica-bold-r-normal--14-*-*-*-*-*-*-*",
80 /* --------------------------------------------------------------------- *
81 * anything below this point is only defined when we are not running CDE *
82 * --------------------------------------------------------------------- */
84 /* Do not define default colors when running under CDE
85 * (e.g. VUE on HPUX). The result is that you don't look
86 * like a normal desktop application
88 "?background: gray75",
89 "?screen.background: wheat",
90 "?highlightColor: red",
91 "?Preferences*options.background: gray90",
95 static String
*get_fallback_rsrcs( String name
)
97 static String
*get_fallback_rsrcs( name
)
101 String
*copy
= (String
*) malloc( (1+XtNumber(fallback_rsrcs
))*sizeof(String
) );
105 /* connect to server and see if the CDE atoms are present */
107 running_cde
= is_cde( d
);
110 for ( i
=0; i
<XtNumber(fallback_rsrcs
); i
++ ) {
112 /* stop here if running CDE */
113 if ( fallback_rsrcs
[i
][0] == '?' ) {
114 if ( running_cde
) break;
115 fallback_rsrcs
[i
] = strdup(fallback_rsrcs
[i
]);
116 fallback_rsrcs
[i
][0] = '*';
119 copy
[i
] = malloc( strlen(name
) + strlen(fallback_rsrcs
[i
]) + 1 );
120 strcpy( copy
[i
], name
);
121 strcat( copy
[i
], fallback_rsrcs
[i
] );
129 /* create the shell widgetry */
131 #if defined(__STDC__)
132 static void create_top_level_shell( int *argc
, char **argv
)
134 static void create_top_level_shell( argc
, argv
)
140 Widget main_w
, editor
;
143 /* X gets quite upset if the program name is not simple */
144 if (( ptr
= strrchr( argv
[0], '/' )) != NULL
) argv
[0] = ++ptr
;
145 vi_progname
= argv
[0];
147 /* create a top-level shell for the window manager */
148 top_level
= XtVaAppInitialize( &ctx
,
150 NULL
, 0, /* options */
152 argv
, /* might get modified */
153 get_fallback_rsrcs( argv
[0] ),
156 display
= XtDisplay(top_level
);
158 /* might need to go technicolor... */
159 XutInstallColormap( argv
[0], top_level
);
162 * do this *before* realizing the shell widget in case the -iconic
163 * option was specified.
165 icon_pm
= XCreatePixmapFromBitmapData(
167 DefaultRootWindow(display
),
173 DefaultDepth( display
, DefaultScreen(display
) )
175 XutSetIcon( top_level
, nvi_height
, nvi_width
, icon_pm
);
177 /* in the shell, we will stack a menubar an editor */
178 main_w
= XtVaCreateManagedWidget( "main",
179 xmMainWindowWidgetClass
,
184 /* create the menubar */
185 XtManageChild( (Widget
) vi_create_menubar( main_w
) );
187 /* add the VI widget from the library */
188 editor
= vi_create_editor( "editor", main_w
, onexit
);
191 XtRealizeWidget( top_level
);
193 /* We *may* want all keyboard events to go to the editing screen.
194 * If the editor is the only widget in the shell that accepts
195 * keyboard input, then the user will expect that he can type when
196 * the pointer is over the scrollbar (for example). This call
197 * causes that to happen.
199 XtSetKeyboardFocus( top_level
, XtNameToWidget( editor
, "*screen" ) );
211 * Initialize the X widgetry. We must do this before picking off
212 * arguments as well-behaved X programs have common argument lists
213 * (e.g. -rv for reverse video).
215 create_top_level_shell(&argc
, argv
);
217 /* We need to know if the child process goes away. */
218 (void)signal(SIGCHLD
, onchld
);
220 /* Run vi: the parent returns, the child is the vi process. */
221 (void)vi_run(argc
, argv
, &i_fd
, &vi_ofd
, &pid
);
223 /* Tell X that we are interested in input on the pipe. */
224 XtAppAddInput(ctx
, i_fd
,
225 (XtPointer
)XtInputReadMask
, vi_input_func
, NULL
);
242 /* If the vi process goes away, we exit as well. */
244 vi_fatal_message(top_level
, "The vi process died. Exiting.");
249 * Function called when the editor "quits".