1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402
|
/*-
* Copyright (c) 1996
* Rob Zimmermann. All rights reserved.
* Copyright (c) 1996
* Keith Bostic. All rights reserved.
*
* See the LICENSE file for redistribution information.
*/
#include "config.h"
#ifndef lint
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 $";
#endif /* not lint */
#include <sys/types.h>
#include <sys/queue.h>
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include <Xm/MainW.h>
#include <bitstring.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#undef LOCK_SUCCESS
#include "../common/common.h"
#include "../ipc/ip.h"
#include "../motif_l/m_motif.h"
#include "../motif_l/vi_mextern.h"
#include "extern.h"
int vi_ifd = -1;
int vi_ofd = -1;
IPVIWIN *ipvi_motif;
#if XtSpecificationRelease == 4
#define ArgcType Cardinal *
#else
#define ArgcType int *
#endif
#if defined(ColorIcon)
#if XT_REVISION >= 6
#include <X11/xpm.h>
#else
#include "xpm.h"
#endif
#include "nvi.xpm" /* Icon pixmap. */
#else
#include "nvi.xbm" /* Icon bitmap. */
#endif
static pid_t pid;
static Pixel icon_fg,
icon_bg;
static Pixmap icon_pm;
static Widget top_level;
static XtAppContext ctx;
static void XutInstallColormap __P((String, Widget));
static void XutSetIcon __P((Widget, int, int, Pixmap));
static void onchld __P((int));
static void onexit __P((void));
#if ! defined(ColorIcon)
static XutResource resource[] = {
{ "iconForeground", XutRKpixel, &icon_fg },
{ "iconBackground", XutRKpixel, &icon_bg },
};
#endif
/* resources for the vi widgets unless the user overrides them */
String fallback_rsrcs[] = {
"*font: -*-*-*-r-*--14-*-*-*-m-*-*-*",
"*text*fontList: -*-*-*-r-*--14-*-*-*-m-*-*-*",
"*Menu*fontList: -*-helvetica-bold-r-normal--14-*-*-*-*-*-*-*",
"*fontList: -*-helvetica-medium-r-normal--14-*-*-*-*-*-*-*",
"*pointerShape: xterm",
"*busyShape: watch",
"*iconName: vi",
#if ! defined(ColorIcon)
/* coloring for the icons */
"*iconForeground: XtDefaultForeground",
"*iconBackground: XtDefaultBackground",
#endif
/* layout for the tag stack dialog */
"*Tags*visibleItemCount: 5",
/* for the text ruler */
"*rulerFont: -*-helvetica-medium-r-normal--14-*-*-*-*-*-*-*",
"*rulerBorder: 5",
/* layout for the new, temporary preferences page */
"*toggleOptions.numColumns: 6", /* also used by Find */
"*Preferences*tabWidthPercentage: 0",
"*Preferences*tabs.shadowThickness: 2",
"*Preferences*tabs.font: -*-helvetica-bold-r-normal--14-*-*-*-*-*-*-*",
/* --------------------------------------------------------------------- *
* anything below this point is only defined when we are not running CDE *
* --------------------------------------------------------------------- */
/* Do not define default colors when running under CDE
* (e.g. VUE on HPUX). The result is that you don't look
* like a normal desktop application
*/
"?background: gray75",
"?screen.background: wheat",
"?highlightColor: red",
"?Preferences*options.background: gray90",
};
#if defined(__STDC__)
static String *get_fallback_rsrcs( String name )
#else
static String *get_fallback_rsrcs( name )
String name;
#endif
{
String *copy = (String *) malloc( (1+XtNumber(fallback_rsrcs))*sizeof(String) );
int i, running_cde;
Display *d;
/* connect to server and see if the CDE atoms are present */
d = XOpenDisplay(0);
running_cde = is_cde( d );
XCloseDisplay(d);
for ( i=0; i<XtNumber(fallback_rsrcs); i++ ) {
/* stop here if running CDE */
if ( fallback_rsrcs[i][0] == '?' ) {
if ( running_cde ) break;
fallback_rsrcs[i] = strdup(fallback_rsrcs[i]);
fallback_rsrcs[i][0] = '*';
}
copy[i] = malloc( strlen(name) + strlen(fallback_rsrcs[i]) + 1 );
strcpy( copy[i], name );
strcat( copy[i], fallback_rsrcs[i] );
}
copy[i] = NULL;
return copy;
}
/* create the shell widgetry */
#if defined(__STDC__)
static void create_top_level_shell( int *argc, char **argv )
#else
static void create_top_level_shell( argc, argv )
int *argc;
char **argv;
#endif
{
char *ptr;
Widget main_w, editor;
Display *display;
/* X gets quite upset if the program name is not simple */
if (( ptr = strrchr( argv[0], '/' )) != NULL ) argv[0] = ++ptr;
vi_progname = argv[0];
/* create a top-level shell for the window manager */
top_level = XtVaAppInitialize( &ctx,
vi_progname,
NULL, 0, /* options */
(ArgcType) argc,
argv, /* might get modified */
get_fallback_rsrcs( argv[0] ),
NULL
);
display = XtDisplay(top_level);
/* might need to go technicolor... */
XutInstallColormap( argv[0], top_level );
/* create our icon
* do this *before* realizing the shell widget in case the -iconic
* option was specified.
*/
{
#if defined(ColorIcon)
int nvi_width, nvi_height;
XpmAttributes attr;
attr.valuemask = 0;
XpmCreatePixmapFromData( display,
DefaultRootWindow(display),
nvi_xpm,
&icon_pm,
NULL,
&attr
);
nvi_width = attr.width;
nvi_height = attr.height;
#else
/* check the resource database for interesting resources */
__XutConvertResources( top_level,
vi_progname,
resource,
XtNumber(resource)
);
icon_pm = XCreatePixmapFromBitmapData(
display,
DefaultRootWindow(display),
(char *) nvi_bits,
nvi_width,
nvi_height,
icon_fg,
icon_bg,
DefaultDepth( display, DefaultScreen(display) )
);
#endif
XutSetIcon( top_level, nvi_height, nvi_width, icon_pm );
}
/* in the shell, we will stack a menubar an editor */
main_w = XtVaCreateManagedWidget( "main",
xmMainWindowWidgetClass,
top_level,
NULL
);
/* create the menubar */
XtManageChild( (Widget) vi_create_menubar( main_w ) );
/* add the VI widget from the library */
editor = vi_create_editor( "editor", main_w, onexit );
/* put it up */
XtRealizeWidget( top_level );
/* We *may* want all keyboard events to go to the editing screen.
* If the editor is the only widget in the shell that accepts
* keyboard input, then the user will expect that he can type when
* the pointer is over the scrollbar (for example). This call
* causes that to happen.
*/
XtSetKeyboardFocus( top_level, XtNameToWidget( editor, "*screen" ) );
}
int
main(int argc, char **argv)
{
IPVI* ipvi;
/*
* Initialize the X widgetry. We must do this before picking off
* arguments as well-behaved X programs have common argument lists
* (e.g. -rv for reverse video).
*/
create_top_level_shell(&argc, argv);
/* We need to know if the child process goes away. */
(void)signal(SIGCHLD, onchld);
vi_create(&ipvi, 0);
(void)ipvi->run(ipvi, argc, argv);
ipvi->new_window(ipvi,&ipvi_motif,-1);
ipvi_motif->set_ops(ipvi_motif, &ipsi_ops_motif);
/* Run vi: the parent returns, the child is the vi process. */
vi_ifd = ipvi_motif->ifd;
vi_ofd = ipvi_motif->ofd;
pid = ipvi->pid;
/* Tell X that we are interested in input on the pipe. */
XtAppAddInput(ctx, vi_ifd,
(XtPointer)XtInputReadMask, vi_input_func, NULL);
/* Main loop. */
XtAppMainLoop(ctx);
/* NOTREACHED */
abort();
}
static void
XutSetIcon(Widget wid, int height, int width, Pixmap p)
{
Display *display = XtDisplay(wid);
Window win;
/* best bet is to set the icon window */
XtVaGetValues( wid, XtNiconWindow, &win, 0 );
if ( win == None ) {
win = XCreateSimpleWindow( display,
RootWindow( display,
DefaultScreen( display ) ),
0, 0,
width, height,
0,
CopyFromParent,
CopyFromParent
);
}
if ( win != None ) {
XtVaSetValues( wid, XtNiconWindow, win, 0 );
XSetWindowBackgroundPixmap( display, win, p );
}
else {
/* do it the old fashioned way */
XtVaSetValues( wid, XtNiconPixmap, p, 0 );
}
}
/* Support for multiple colormaps
*
* XutInstallColormap( String name, Widget wid )
* The first time called, this routine checks to see if the
* resource "name*installColormap" is "True". If so, the
* widget is assigned a newly allocated colormap.
*
* Subsequent calls ignore the "name" parameter and use the
* same colormap.
*
* Future versions of this routine may handle multiple colormaps
* by name.
*/
static enum { cmap_look, cmap_use, cmap_ignore } cmap_state = cmap_look;
static Boolean use_colormap = False;
static XutResource colormap_resources[] = {
{ "installColormap", XutRKboolean, &use_colormap }
};
static void
XutInstallColormap(String name, Widget wid)
{
static Colormap cmap = 0;
static Display *cmap_display = 0;
Display *display = XtDisplay(wid);
/* what is the current finite state? */
if ( cmap_state == cmap_look ) {
/* what does the resource say? */
__XutConvertResources( wid,
name,
colormap_resources,
XtNumber(colormap_resources)
);
/* was the result "True"? */
if ( ! use_colormap ) {
cmap_state = cmap_ignore;
return;
}
/* yes it was */
cmap_state = cmap_use;
cmap_display = display;
cmap = XCopyColormapAndFree( display,
DefaultColormap( display,
DefaultScreen( display )
)
);
}
/* use the private colormap? */
if ( cmap_state == cmap_use ) {
XtVaSetValues( wid, XtNcolormap, cmap, 0 );
}
}
/*
* onchld --
* Handle SIGCHLD.
*/
static void
onchld(int signo)
{
/* If the vi process goes away, we exit as well. */
if (kill(pid, 0))
vi_fatal_message(top_level, "The vi process died. Exiting.");
}
/*
* onexit --
* Function called when the editor "quits".
*/
static void
onexit(void)
{
exit (0);
}
|