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.26 1996/12/11 20:56:43 bostic Exp $ (Berkeley) $Date: 1996/12/11 20:56:43 $";
16 #include <sys/types.h>
17 #include <sys/queue.h>
19 #include <X11/Intrinsic.h>
20 #include <X11/StringDefs.h>
26 #include "../motif_l/vi_mextern.h"
29 #if XtSpecificationRelease == 4
30 #define ArgcType Cardinal *
32 #define ArgcType int *
35 #include "nvi.xbm" /* Icon bitmap. */
40 static Pixmap icon_pm
;
41 static Widget top_level
;
42 static XtAppContext ctx
;
44 static void onchld
__P((int));
45 static void onexit
__P((void));
48 /* resources for the vi widgets unless the user overrides them */
49 String fallback_rsrcs
[] = {
51 "*font: -*-*-*-r-*--14-*-*-*-m-*-*-*",
52 "*text*fontList: -*-*-*-r-*--14-*-*-*-m-*-*-*",
53 "*Menu*fontList: -*-helvetica-bold-r-normal--14-*-*-*-*-*-*-*",
54 "*fontList: -*-helvetica-medium-r-normal--14-*-*-*-*-*-*-*",
55 "*pointerShape: xterm",
59 /* coloring for the icons */
60 "*iconForeground: XtDefaultForeground",
61 "*iconBackground: XtDefaultBackground",
63 /* layout for the tag stack dialog */
64 "*Tags*visibleItemCount: 5",
66 /* layout for the new, temporary preferences page */
67 "*toggleOptions.numColumns: 6", /* also used by Find */
68 "*Preferences*tabWidthPercentage: 0",
69 "*Preferences*tabs.shadowThickness: 2",
70 "*Preferences*tabs.font: -*-helvetica-bold-r-normal--14-*-*-*-*-*-*-*",
72 /* --------------------------------------------------------------------- *
73 * anything below this point is only defined when we are not running CDE *
74 * --------------------------------------------------------------------- */
76 /* Do not define default colors when running under CDE
77 * (e.g. VUE on HPUX). The result is that you don't look
78 * like a normal desktop application
80 "?highlightColor: red",
81 "?background: gray75",
82 "?screen.background: wheat",
83 "?highlightColor: red",
84 "?Preferences*options.background: gray90",
88 static String
*get_fallback_rsrcs( String name
)
90 static String
*get_fallback_rsrcs( name
)
94 String
*copy
= (String
*) malloc( (1+XtNumber(fallback_rsrcs
))*sizeof(String
) );
98 /* connect to server and see if the CDE atoms are present */
100 running_cde
= is_cde( d
);
103 for ( i
=0; i
<XtNumber(fallback_rsrcs
); i
++ ) {
105 /* stop here if running CDE */
106 if ( fallback_rsrcs
[i
][0] == '?' ) {
107 if ( running_cde
) break;
108 fallback_rsrcs
[i
] = strdup(fallback_rsrcs
[i
]);
109 fallback_rsrcs
[i
][0] = '*';
112 copy
[i
] = malloc( strlen(name
) + strlen(fallback_rsrcs
[i
]) + 1 );
113 strcpy( copy
[i
], name
);
114 strcat( copy
[i
], fallback_rsrcs
[i
] );
122 /* create the shell widgetry */
124 #if defined(__STDC__)
125 static void create_top_level_shell( int *argc
, char **argv
)
127 static void create_top_level_shell( argc
, argv
)
133 Widget main_w
, menu_b
;
136 /* X gets quite upset if the program name is not simple */
137 if (( ptr
= strrchr( argv
[0], '/' )) != NULL
) argv
[0] = ++ptr
;
138 vi_progname
= argv
[0];
140 /* create a top-level shell for the window manager */
141 top_level
= XtVaAppInitialize( &ctx
,
143 NULL
, 0, /* options */
145 argv
, /* might get modified */
146 get_fallback_rsrcs( argv
[0] ),
149 display
= XtDisplay(top_level
);
151 /* might need to go technicolor... */
152 XutInstallColormap( argv
[0], top_level
);
155 * do this *before* realizing the shell widget in case the -iconic
156 * option was specified.
158 icon_pm
= XCreatePixmapFromBitmapData(
160 DefaultRootWindow(display
),
166 DefaultDepth( display
, DefaultScreen(display
) )
168 XutSetIcon( top_level
, nvi_height
, nvi_width
, icon_pm
);
170 /* in the shell, we will stack a menubar an editor */
171 main_w
= XtVaCreateManagedWidget( "main",
172 xmMainWindowWidgetClass
,
177 /* create the menubar */
178 menu_b
= (Widget
) vi_create_menubar( main_w
);
179 XtManageChild( menu_b
);
181 /* add the VI widget from the library */
182 vi_create_editor( "editor", main_w
, onexit
);
185 XtRealizeWidget( top_level
);
197 * Initialize the X widgetry. We must do this before picking off
198 * arguments as well-behaved X programs have common argument lists
199 * (e.g. -rv for reverse video).
201 create_top_level_shell(&argc
, argv
);
203 /* We need to know if the child process goes away. */
204 (void)signal(SIGCHLD
, onchld
);
206 /* Run vi: the parent returns, the child is the vi process. */
207 (void)vi_run(argc
, argv
, &i_fd
, &vi_ofd
, &pid
);
209 /* Tell X that we are interested in input on the pipe. */
210 XtAppAddInput(ctx
, i_fd
,
211 (XtPointer
)XtInputReadMask
, vi_input_func
, NULL
);
228 /* If the vi process goes away, we exit as well. */
230 vi_fatal_message(top_level
, "The vi process died. Exiting.");
235 * Function called when the editor "quits".