|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T d
Length: 19549 (0x4c5d) Types: TextFile Names: »display.c«
└─⟦3d0c2be1b⟧ Bits:30001254 ISODE-5.0 Tape └─⟦eba4602b1⟧ »./isode-5.0.tar.Z« └─⟦d3ac74d73⟧ └─⟦this⟧ »isode-5.0/others/max/display.c« └─⟦2d1937cfd⟧ Bits:30007241 EUUGD22: P.P 5.0 └─⟦35176feda⟧ »EurOpenD22/isode/isode-6.tar.Z« └─⟦de7628f85⟧ └─⟦this⟧ »isode-6.0/others/max/display.c«
/* display.c - max -- X-based display */ #include <signal.h> #include <stdio.h> #include "max.h" /* \f DATA */ char *geometry = NULL; static char *topname = "Directory Browser"; static Window topwindow; static OpaqueFrame topframe; static DI topDI; DI curDI; static int topindex; static int hangingedge; static Window fnxwindow; struct ufx UFhead; static struct ufx WDhead; static Window cmdwindow; static Window optwindow; static int oldraise; static Window msgwindow; static int armed; void add1_DI (), add2_DI (), add3_DI (), delete_DI (); void add_functions (), delete_functions (); void add_commands (), delete_commands (); void add_options (), delete_options (); void add_messages (), delete_messages (); int remove_message (); int numselected = 0; void FIfnx (), OPTfnx (); Window add_command (); Window add_boolean (); void XtFlipPixmaps (); int XtVPanedAddButtonBox (); XtGeometryReturnCode ButtonBoxGeometryRequest (); void exit (); /* \f */ void display_init () { int width, height, x, y; char def[BUFSIZ]; Arg args[6]; DI di, ti; WindowInfo info; topframe.bdrwidth = 1; topframe.height = DisplayHeight () / 2 - topframe.bdrwidth * 2; topframe.width = DisplayWidth () / 2 - topframe.bdrwidth * 2; topframe.border = BlackPixmap; topframe.background = WhitePixmap; topframe.x = DisplayWidth () - topframe.width - 2 * topframe.bdrwidth; if (topframe.x < 0) topframe.x = 0; topframe.y = DisplayHeight () - topframe.height - 2 * topframe.bdrwidth; if (topframe.y < 0) topframe.y = 0; (void) sprintf (def, "=%dx%d+%d+%d", topframe.width, topframe.height, topframe.x, topframe.y); topwindow = XCreate (topname, myname, geometry, def, &topframe, topframe.width, topframe.height); (void) XQueryWindow (topwindow, &info); XDestroyWindow (topwindow); width = info.width; height = info.height; x = info.x; y = info.y; XtSetArg (args[0], XtNname, myname); XtSetArg (args[1], XtNwidth, width); XtSetArg (args[2], XtNheight, height); XtSetArg (args[3], XtNx, x); XtSetArg (args[4], XtNy, y); XtSetArg (args[5], XtNautoRaise, autoraisesw); topwindow = XtVPanedWindowCreate (RootWindow, args, 6); XStoreName (topwindow, topname); XDefineCursor (topwindow, XtGetCursor ("left_ptr")); XMapWindow (topwindow); XtVPanedRefigureMode (topwindow, FALSE); fnxwindow = cmdwindow = optwindow = msgwindow = NULL; if ((di = buildDI (mycwd, &ti)) == NULLDI) adios (mycwd, "unable to search"); if (ti == NULLDI) adios (NULLCP, "buildDI lost tail"); topDI = di; curDI = ti; topindex = 0; hangingedge = 0; add1_DI (di, ti); add2_DI (di); add3_DI (di); add_functions (); add_commands (); add_options (); add_messages (); XtVPanedRefigureMode (topwindow, TRUE); numselected = 0; } /* \f */ static void add1_DI (di, ti) register DI di; DI ti; { Arg args[4]; char path[MAXPATHLEN]; register FI fi; if (di == NULLDI) return; if (di -> di_index < 0) { XtSetArg (args[0], XtNname, di != ti ? "view" : "current"); XtSetArg (args[1], XtNwidth, topframe.width); di -> di_window = XtButtonBoxCreate (topwindow, args, 2); (void) XtSetGeometryHandler (di -> di_window, ButtonBoxGeometryRequest); XLowerWindow (di -> di_window); } if ((fi = di -> di_up) == NULLFI) XtSetArg (args[0], XtNlabel, di -> di_path); else XtSetArg (args[0], XtNlabel, fi -> fi_direct -> d_name); XtSetArg (args[1], XtNfunction, CDfnx); XtSetArg (args[2], XtNparameter, di); XtSetArg (args[3], XtNreason, 1); di -> di_button = XtCommandCreate (di -> di_window, args, 4); XtSetArg (args[0], XtNwindow, di -> di_button); (void) XtButtonBoxAddButton (di -> di_window, args, 1); for (fi = di -> di_parts.fi_forw; fi != &di -> di_parts; fi = fi -> fi_forw) { if (di != ti) { XtSetArg (args[0], XtNlabel, fi -> fi_direct -> d_name); if (FI_ISDIR (fi)) { XtSetArg (args[1], XtNfunction, CDfnx); XtSetArg (args[2], XtNparameter, fi); XtSetArg (args[3], XtNreason, 0); fi -> fi_button = XtCommandCreate (di -> di_window, args, 4); if (fi -> fi_dir != NULLDI) XtFlipPixmaps (fi -> fi_button, XtCommandGetValues, XtCommandSetValues); } else fi -> fi_button = XtLabelCreate (di -> di_window, args, 1); } else { (void) sprintf (path, "%s%c", fi -> fi_direct -> d_name, fi -> fi_type); fi -> fi_label = strdup (path); XtSetArg (args[0], XtNlabel, fi -> fi_label); XtSetArg (args[1], XtNvalue, &fi -> fi_selected); XtSetArg (args[2], XtNfunction, FIfnx); XtSetArg (args[3], XtNparameter, fi); fi -> fi_button = XtBooleanCreate (di -> di_window, args, 4); } XtSetArg (args[0], XtNwindow, fi -> fi_button); (void) XtButtonBoxAddButton (di -> di_window, args, 1); if (FI_ISDIR (fi)) add1_DI (fi -> fi_dir, ti); } } /* \f */ static void add2_DI (di) register DI di; { int i; Arg args[1]; register FI fi; WindowInfo info; if (di == NULLDI) return; XtSetArg (args[0], XtNhSpace, NULL); XtButtonBoxGetValues (di -> di_window, args, 1); (void) XQueryWindow (di -> di_button, &info); if ((i = 5 * ((int) args[0].value) + info.width + 2 * info.bdrwidth) > hangingedge) hangingedge = i; for (fi = di -> di_parts.fi_forw; fi != &di -> di_parts; fi = fi -> fi_forw) if (FI_ISDIR (fi)) add2_DI (fi -> fi_dir); } /* \f */ static void add3_DI (di) register DI di; { Arg args[1]; register FI fi; if (di == NULLDI) return; XtSetArg (args[0], XtNhangingEdge, hangingedge); XtButtonBoxSetValues (di -> di_window, args, 1); if (di -> di_index < 0) di -> di_index = XtVPanedAddButtonBox (di -> di_window, di -> di_button); for (fi = di -> di_parts.fi_forw; fi != &di -> di_parts; fi = fi -> fi_forw) if (FI_ISDIR (fi)) add3_DI (fi -> fi_dir); } /* \f */ static void delete_DI (di) register DI di; { register FI fi; if (di == NULLDI) return; XtVPanedWindowDeletePane (topwindow, di -> di_window); (void) XtSendDestroyNotify (di -> di_window); XDestroyWindow (di -> di_window); for (fi = di -> di_parts.fi_forw; fi != &di -> di_parts; fi = fi -> fi_forw) if (FI_ISDIR (fi)) delete_DI (fi -> fi_dir); } /* \f */ static void add_functions () { caddr_t tag; Arg args[2]; FILE *fp; ResourceDataBase rdb, odb; Window w, u, v; UF uf; XtContext DIcontext; (void) sprintf (curDI -> di_pp, ".maXdefaults"); fp = fopen (curDI -> di_path, "r"); *curDI -> di_pp = NULL; if (fp) { XtGetCurrentDataBase (&odb); XtGetDataBase (fp, &rdb); XtSetCurrentDataBase (rdb); (void) fclose (fp); } else rdb = NULL; buildUF (rdb, &WDhead); XtSetArg (args[0], XtNname, "functions"); XtSetArg (args[1], XtNwidth, topframe.width); fnxwindow = XtButtonBoxCreate (topwindow, args, 2); (void) XtSetGeometryHandler (fnxwindow, ButtonBoxGeometryRequest); XLowerWindow (fnxwindow); DIcontext = XtUniqueContext (); w = NULL; for (uf = WDhead.uf_forw; uf != &WDhead; uf = uf -> uf_forw) { if (!XtFindContext (u = XtNameToWindow (uf -> uf_name), DIcontext, &tag)) continue; tag = NULL; if (XtSaveContext (uf -> uf_window = u, DIcontext, tag)) adios (NULLCP, "unable to save context"); v = add_command (fnxwindow, uf -> uf_name, uf -> uf_proc, (caddr_t)uf); if (w == NULL) w = v; } for (uf = UFhead.uf_forw; uf != &UFhead; uf = uf -> uf_forw) { if (!XtFindContext (u = XtNameToWindow (uf -> uf_name), DIcontext, &tag)) continue; tag = NULL; if (XtSaveContext (uf -> uf_window = u, DIcontext, tag)) adios (NULLCP, "unable to save context"); v = add_command (fnxwindow, uf -> uf_name, uf -> uf_proc, (caddr_t)uf); if (w == NULL) w = v; } for (uf = WDhead.uf_forw; uf != &WDhead; uf = uf -> uf_forw) if (uf -> uf_window) { (void) XtDeleteContext (uf -> uf_window, DIcontext); uf -> uf_window = NULL; } for (uf = UFhead.uf_forw; uf != &UFhead; uf = uf -> uf_forw) if (uf -> uf_window) { (void) XtDeleteContext (uf -> uf_window, DIcontext); uf -> uf_window = NULL; } if (rdb) { XtSetCurrentDataBase (odb); XtFreeDataBase (rdb); } (void) XtVPanedAddButtonBox (fnxwindow, w); } /* \f */ static void delete_functions () { freeUF (&WDhead); XtVPanedWindowDeletePane (topwindow, fnxwindow); (void) XtSendDestroyNotify (fnxwindow); XDestroyWindow (fnxwindow); fnxwindow = NULL; } /* \f */ static void add_commands () { Arg args[2]; Window w; XtSetArg (args[0], XtNname, "commands"); XtSetArg (args[1], XtNwidth, topframe.width); cmdwindow = XtButtonBoxCreate (topwindow, args, 2); (void) XtSetGeometryHandler (cmdwindow, ButtonBoxGeometryRequest); XLowerWindow (cmdwindow); w = add_command (cmdwindow, "Clear", doSelect, (caddr_t) 0); (void) add_command (cmdwindow, "Set", doSelect, (caddr_t) 1); (void) add_command (cmdwindow, "Invert", doInvert, (caddr_t) 0); (void) add_command (cmdwindow, "Next", doAdvance, (caddr_t) 1); (void) add_command (cmdwindow, "Previous", doAdvance, (caddr_t) 0); (void) add_command (cmdwindow, "ChangeDirectory", doCD, (caddr_t) 0); (void) add_command (cmdwindow, "Exit", exit, (caddr_t) 0); (void) XtVPanedAddButtonBox (cmdwindow, w); } /* \f */ #ifdef notdef static void delete_commands () { XtVPanedWindowDeletePane (topwindow, cmdwindow); (void) XtSendDestroyNotify (cmdwindow); XDestroyWindow (cmdwindow); cmdwindow = NULL; } #endif /* \f */ static void add_options () { Arg args[2]; Window w; XtSetArg (args[0], XtNname, "options"); XtSetArg (args[1], XtNwidth, topframe.width); optwindow = XtButtonBoxCreate (topwindow, args, 2); (void) XtSetGeometryHandler (optwindow, ButtonBoxGeometryRequest); XLowerWindow (optwindow); w = add_boolean (optwindow, "advance", &advancesw); (void) add_boolean (optwindow, "autoRaise", &autoraisesw); (void) add_boolean (optwindow, "dotFiles", &dotfilesw); (void) add_boolean (optwindow, "messageMode", &messagesw); (void) add_boolean (optwindow, "reSelect", &reselectsw); (void) add_boolean (optwindow, "sort", &sortsw); oldraise = autoraisesw; (void) XtVPanedAddButtonBox (optwindow, w); } /* \f */ #ifdef notdef static void delete_options () { XtVPanedWindowDeletePane (topwindow, optwindow); (void) XtSendDestroyNotify (optwindow); XDestroyWindow (optwindow); optwindow = NULL; } #endif /* \f */ static void add_messages () { Arg args[3]; WindowInfo info; XtSetArg (args[0], XtNname, "messages"); XtSetArg (args[1], XtNwidth, topframe.width); XtSetArg (args[2], XtNlabel, topname); msgwindow = XtLabelCreate (topwindow, args, 3); XtFlipPixmaps (msgwindow, XtLabelGetValues, XtLabelSetValues); (void) XQueryWindow (msgwindow, &info); XtVPanedWindowAddPane (topwindow, msgwindow, topindex++, info.height, info.height, FALSE); } /* \f */ #ifdef notdef static void delete_messages () { (void) alarm ((unsigned) 0); XtVPanedWindowDeletePane (topwindow, msgwindow); (void) XtSendDestroyNotify (msgwindow); XDestroyWindow (msgwindow); msgwindow = NULL; } #endif /* \f */ /* VARARGS2 */ void display_message (what, fmt, a, b, c, d) char *what, *fmt, *a, *b, *c, *d; { int eindex; register char *bp; Arg args[1]; static char buffer[BUFSIZ]; eindex = errno; (void) sprintf (bp = buffer, fmt, a, b, c, d); bp += strlen (bp); if (what) { if (*what) { (void) sprintf (bp, " %s: ", what); bp += strlen (bp); } if (eindex > 0 && eindex < sys_nerr) (void) sprintf (bp, "%s", sys_errlist[eindex]); else (void) sprintf (bp, "Error %d", eindex); bp += strlen (bp); } if (msgwindow == NULL) { advise (NULLCP, "%s", buffer); return; } XtSetArg (args[0], XtNlabel, buffer); XtLabelSetValues (msgwindow, args, 1); XFlush (); /* right away! */ armed = 1; (void) alarm ((unsigned) (what ? 60 : 30)); (void) signal (SIGALRM, remove_message); } /* \f */ /* ARGSUSED */ int remove_message (i) int i; { Arg args[1]; if (msgwindow == NULL || !armed) return; XtSetArg (args[0], XtNlabel, topname); XtLabelSetValues (msgwindow, args, 1); XFlush (); /* right away! */ armed = 0; } /* \f */ void CDfnx (tag, reason) caddr_t tag; unsigned long reason; { Arg args[1]; char path[MAXPATHLEN]; register DI di; DI si, ti; register FI fi, gi; WindowInfo info; if (reason) di = (DI) tag; else { fi = (FI) tag; if ((di = fi -> fi_up) == NULLDI) { display_message (NULLCP, "internal error: no back pointer"); return; } (void) sprintf (di -> di_pp, fi -> fi_direct -> d_name); } display_message (NULLCP, reason != 2 ? "cd %s" : "working...", di -> di_path); (void) strcpy (path, di -> di_path); if (!reason) *di -> di_pp = NULL; if ((si = newDI (path, NULLCP, &ti)) == NULLDI) { display_message (path, "unable to search"); return; } if (chdir (path) == NOTOK) { display_message (path, "unable to change to"); freeDI (si); return; } free (mycwd); mycwd = strdup (path); (void) XQueryWindow (topwindow, &info); topframe.x = info.x; topframe.y = info.y; topframe.width = info.width; topframe.height = info.height; topframe.bdrwidth = info.bdrwidth; XtVPanedRefigureMode (topwindow, FALSE); for (gi = di -> di_parts.fi_forw; gi != &di -> di_parts; gi = gi -> fi_forw) if (FI_ISDIR (gi)) { if (gi -> fi_dir != NULLDI) XtFlipPixmaps (gi -> fi_button, XtCommandGetValues, XtCommandSetValues); delete_DI (gi -> fi_dir); freeDI (gi -> fi_dir); gi -> fi_dir = NULLDI; } numselected = 0; if (reason) { if (di == curDI) { /* quadratic, yuk! */ for (gi = di -> di_parts.fi_forw; gi != &di -> di_parts; gi = gi -> fi_forw) for (fi = si -> di_parts.fi_forw; fi != &si -> di_parts; fi = fi -> fi_forw) if (strcmp (gi -> fi_direct -> d_name, fi -> fi_direct -> d_name) == 0) { if (fi -> fi_selected = gi -> fi_selected) { fi -> fi_selectpos = gi -> fi_selectpos; numselected++; } break; } } if ((fi = di -> di_up) == NULLFI) topDI = si; else { si -> di_up = fi; fi -> fi_dir = si; } topindex = di -> di_index; delete_DI (di); freeDI (di); } else { XtFlipPixmaps (fi -> fi_button, XtCommandGetValues, XtCommandSetValues); si -> di_up = fi; fi -> fi_dir = si; topindex = di -> di_index + 1; } delete_functions (); hangingedge = 0; if (!reason && di == curDI) { XUnmapWindow (di -> di_window); XtSetArg (args[0], XtNwindow, di -> di_button); (void) XtButtonBoxDeleteButton (di -> di_button, args, 1); (void) XtSendDestroyNotify (di -> di_button); XDestroyWindow (di -> di_button); for (gi = di -> di_parts.fi_forw; gi != &di -> di_parts; gi = gi -> fi_forw) { XtSetArg (args[0], XtNwindow, gi -> fi_button); (void) XtButtonBoxDeleteButton (di -> di_window, args, 1); (void) XtSendDestroyNotify (gi -> fi_button); XDestroyWindow (gi -> fi_button); } add1_DI (di, si); XMapWindow (di -> di_window); XLowerWindow (di -> di_window); } curDI = si; add1_DI (si, si); add2_DI (topDI); add3_DI (topDI); add_functions (); XtVPanedRefigureMode (topwindow, TRUE); if (reason == 2) remove_message (0); } /* \f */ /* ARGSUSED */ static void FIfnx (tag, reason) caddr_t tag; unsigned long reason; { register FI fi = (FI) tag; remove_message (0); if (fi -> fi_selected) fi -> fi_selectpos = ++numselected; else numselected--; } /* \f */ /* ARGSUSED */ static void OPTfnx (tag, reason) caddr_t tag; unsigned long reason; { Arg args[1]; remove_message (0); if (autoraisesw != oldraise) { XtSetArg (args[0], XtNautoRaise, autoraisesw); XtVPanedSetValues (topwindow, args, 1); oldraise = autoraisesw; } } /* \f */ static Window add_command (parent, name, fnx, tag) Window parent; char *name; void (*fnx) (); caddr_t tag; { Arg args[3]; Window w; XtSetArg (args[0], XtNname, name); XtSetArg (args[1], XtNfunction, fnx); XtSetArg (args[2], XtNparameter, tag); w = XtCommandCreate (parent, args, 3); XtSetArg (args[0], XtNwindow, w); (void) XtButtonBoxAddButton (parent, args, 1); return w; } /* \f */ static Window add_boolean (parent, name, value) Window parent; char *name; int *value; { Arg args[3]; Window w; XtSetArg (args[0], XtNname, name); XtSetArg (args[1], XtNvalue, value); XtSetArg (args[2], XtNfunction, OPTfnx); w = XtBooleanCreate (parent, args, 3); XtSetArg (args[0], XtNwindow, w); (void) XtButtonBoxAddButton (parent, args, 1); return w; } /* \f */ void XtFlipPixmaps (w, getf, setf) Window w; void (*getf) (), (*setf) (); { caddr_t x; Arg args[2]; Pixel pixel; Pixmap tile; XtSetArg (args[0], XtNforeground, -1); XtSetArg (args[1], XtNbackground, -1); (*getf) (w, args, 2); if (args[0].value == (caddr_t) -1 || args[1].value == (caddr_t) -1) return; pixel = (Pixel) args[0].value; if (pixel == XtDefaultFGPixel) XChangeBackground (w, XtDefaultFGPixmap); else if (pixel == XtDefaultBGPixel) XChangeBackground (w, XtDefaultBGPixmap); else { tile = XMakeTile ((Pixel) pixel); XChangeBackground (w, tile); XFreePixmap (tile); } x = args[0].value; args[0].value = args[1].value; args[1].value = x; (*setf) (w, args, 2); } /* \f */ static int XtVPanedAddButtonBox (w, b) Window w, b; { int height, minheight, maxheight; Arg args[1]; WindowInfo info; XtSetArg (args[0], XtNheight, NULL); XtButtonBoxGetValues (w, args, 1); maxheight = (int) args[0].value; if (b) { (void) XQueryWindow (b, &info); minheight = info.height + 2 * info.bdrwidth; } else minheight = info.height = 0; XtSetArg (args[0], XtNvSpace, NULL); XtButtonBoxGetValues (w, args, 1); minheight += 2 * ((int) args[0].value); if ((height = minheight + info.height / 2) < maxheight) minheight = height; XtVPanedWindowAddPane (topwindow, w, topindex, minheight, maxheight, TRUE); return topindex++; } /* \f */ static XtGeometryReturnCode ButtonBoxGeometryRequest (w, request, reqBox, replBox) Window w; int request; WindowBox *reqBox, *replBox; { XtGeometryReturnCode status; if (request != geometryRESIZE) return XtgeometryNo; status = XtgeometryYes; *replBox = *reqBox; /* struct copy */ if (reqBox -> width != topframe.width) { replBox -> width = topframe.width; status = XtgeometryAlmost; } if (reqBox -> height > topframe.height) { replBox -> height = topframe.height; status = XtgeometryAlmost; } if (status == XtgeometryYes) XChangeWindow (w, reqBox -> width, reqBox -> height); return status; }