eddyg@cogs.sussex.ac.uk (EdwardJ. Groenendaal) (05/19/91)
Submitted-by: Edward "J." Groenendaal <eddyg@cogs.sussex.ac.uk> Posting-number: Volume 13, Issue 10 Archive-name: xdtm/part05 Submitted-by: eddyg@cste Archive-name: xdtm/part05 ---- Cut Here and feed the following to sh ---- #!/bin/sh # This is part 05 of xdtm # ============= xdtm/bitmaps/file.icon ============== if test ! -d 'xdtm'; then echo 'x - creating directory xdtm' mkdir 'xdtm' fi if test ! -d 'xdtm/bitmaps'; then echo 'x - creating directory xdtm/bitmaps' mkdir 'xdtm/bitmaps' fi if test -f 'xdtm/bitmaps/file.icon' -a X"$1" != X"-c"; then echo 'x - skipping xdtm/bitmaps/file.icon (File already exists)' else echo 'x - extracting xdtm/bitmaps/file.icon (Text)' sed 's/^X//' << 'SHAR_EOF' > 'xdtm/bitmaps/file.icon' && X#define file_width 32 X#define file_height 32 Xstatic char file_bits[] = { X 0xf0, 0xff, 0x7f, 0x00, 0x10, 0x00, 0xc0, 0x00, 0x10, 0x00, 0x40, 0x01, X 0x10, 0x00, 0x40, 0x02, 0x10, 0x00, 0x40, 0x04, 0x10, 0x00, 0xc0, 0x0f, X 0x10, 0x00, 0x00, 0x08, 0x10, 0x00, 0x00, 0x08, 0x10, 0x00, 0x00, 0x08, X 0x10, 0x00, 0x00, 0x08, 0x10, 0x00, 0x00, 0x08, 0x10, 0x00, 0x00, 0x08, X 0x10, 0x00, 0x00, 0x08, 0x10, 0x00, 0x00, 0x08, 0x10, 0x00, 0x00, 0x08, X 0x10, 0x00, 0x00, 0x08, 0x10, 0x00, 0x00, 0x08, 0x10, 0x00, 0x00, 0x08, X 0x10, 0x00, 0x00, 0x08, 0x10, 0x00, 0x00, 0x08, 0x10, 0x00, 0x00, 0x08, X 0x10, 0x00, 0x00, 0x08, 0x10, 0x00, 0x00, 0x08, 0x10, 0x00, 0x00, 0x08, X 0x10, 0x00, 0x00, 0x08, 0x10, 0x00, 0x00, 0x08, 0x10, 0x00, 0x00, 0x08, X 0x10, 0x00, 0x00, 0x08, 0x10, 0x00, 0x00, 0x08, 0x10, 0x00, 0x00, 0x08, X 0x10, 0x00, 0x00, 0x08, 0xf0, 0xff, 0xff, 0x0f}; SHAR_EOF chmod 0644 xdtm/bitmaps/file.icon || echo 'restore of xdtm/bitmaps/file.icon failed' Wc_c="`wc -c < 'xdtm/bitmaps/file.icon'`" test 875 -eq "$Wc_c" || echo 'xdtm/bitmaps/file.icon: original size 875, current size' "$Wc_c" fi # ============= xdtm/bitmaps/folder.icon ============== if test -f 'xdtm/bitmaps/folder.icon' -a X"$1" != X"-c"; then echo 'x - skipping xdtm/bitmaps/folder.icon (File already exists)' else echo 'x - extracting xdtm/bitmaps/folder.icon (Text)' sed 's/^X//' << 'SHAR_EOF' > 'xdtm/bitmaps/folder.icon' && X#define folder_width 32 X#define folder_height 32 Xstatic char folder_bits[] = { X 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, X 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, X 0x00, 0x00, 0xf8, 0x03, 0x00, 0x00, 0x04, 0x04, 0x00, 0x00, 0x02, 0x08, X 0xfe, 0xff, 0xff, 0x7f, 0x02, 0x00, 0x00, 0x40, 0x02, 0x00, 0x00, 0x40, X 0x02, 0x00, 0x00, 0x40, 0x02, 0x00, 0x00, 0x40, 0x02, 0x00, 0x00, 0x40, X 0x02, 0x00, 0x00, 0x40, 0x02, 0x00, 0x00, 0x40, 0x02, 0x00, 0x00, 0x40, X 0x02, 0x00, 0x00, 0x40, 0x02, 0x00, 0x00, 0x40, 0x02, 0x00, 0x00, 0x40, X 0x02, 0x00, 0x00, 0x40, 0x02, 0x00, 0x00, 0x40, 0x02, 0x00, 0x00, 0x40, X 0x02, 0x00, 0x00, 0x40, 0x02, 0x00, 0x00, 0x40, 0x02, 0x00, 0x00, 0x40, X 0x02, 0x00, 0x00, 0x40, 0x02, 0x00, 0x00, 0x40, 0x02, 0x00, 0x00, 0x40, X 0xfe, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00}; SHAR_EOF chmod 0644 xdtm/bitmaps/folder.icon || echo 'restore of xdtm/bitmaps/folder.icon failed' Wc_c="`wc -c < 'xdtm/bitmaps/folder.icon'`" test 881 -eq "$Wc_c" || echo 'xdtm/bitmaps/folder.icon: original size 881, current size' "$Wc_c" fi # ============= xdtm/bitmaps/xdtm.xbm ============== if test -f 'xdtm/bitmaps/xdtm.xbm' -a X"$1" != X"-c"; then echo 'x - skipping xdtm/bitmaps/xdtm.xbm (File already exists)' else echo 'x - extracting xdtm/bitmaps/xdtm.xbm (Text)' sed 's/^X//' << 'SHAR_EOF' > 'xdtm/bitmaps/xdtm.xbm' && X/* This X bitmap is designed for use with the X Desktop Manager. X * it was designed by Edward Groenendaal, April 1991. X */ X#define xdtm_width 32 X#define xdtm_height 32 Xstatic char xdtm_bits[] = { X 0x00, 0x00, 0x00, 0x00, 0xfe, 0xff, 0xff, 0x7f, 0x4a, 0x06, 0x00, 0x58, X 0xfe, 0xff, 0xff, 0x7f, 0x02, 0x08, 0x10, 0x40, 0x02, 0x88, 0xff, 0x43, X 0x02, 0x88, 0x10, 0x42, 0xfe, 0xcf, 0x39, 0x47, 0x02, 0x48, 0x29, 0x45, X 0xe2, 0xc8, 0x39, 0x47, 0xa2, 0x88, 0x00, 0x42, 0xa2, 0xf8, 0x07, 0x42, X 0xe2, 0x88, 0x04, 0x42, 0x02, 0xf8, 0xff, 0x7f, 0xfa, 0x0b, 0x00, 0x40, X 0x02, 0xe8, 0x9c, 0x43, 0xe2, 0xa8, 0x94, 0x42, 0xa2, 0xa8, 0x94, 0x42, X 0xa2, 0xe8, 0x9c, 0x43, 0xe2, 0x08, 0x00, 0x40, 0x02, 0xe8, 0xb6, 0x43, X 0x7a, 0x0b, 0x00, 0x40, 0x02, 0xe8, 0x9c, 0x43, 0x02, 0xa8, 0x94, 0x42, X 0x02, 0xa8, 0x94, 0x42, 0x02, 0xe8, 0x9c, 0x43, 0xfe, 0x0f, 0x00, 0x40, X 0x92, 0xec, 0x9c, 0x43, 0x92, 0x0c, 0x00, 0x40, 0x92, 0x0c, 0x00, 0x40, X 0xfe, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00}; SHAR_EOF chmod 0644 xdtm/bitmaps/xdtm.xbm || echo 'restore of xdtm/bitmaps/xdtm.xbm failed' Wc_c="`wc -c < 'xdtm/bitmaps/xdtm.xbm'`" test 998 -eq "$Wc_c" || echo 'xdtm/bitmaps/xdtm.xbm: original size 998, current size' "$Wc_c" fi # ============= xdtm/buttons.c ============== if test -f 'xdtm/buttons.c' -a X"$1" != X"-c"; then echo 'x - skipping xdtm/buttons.c (File already exists)' else echo 'x - extracting xdtm/buttons.c (Text)' sed 's/^X//' << 'SHAR_EOF' > 'xdtm/buttons.c' && X/***************************************************************************** X ** File : buttons.c ** X ** Purpose : Initialise and Realise button dialogs ** X ** Author : Edward Groenendaal ** X ** Date : April 1991 ** X ** Documentation : Xdtm Design Folder ** X ** Related Files : ** X *****************************************************************************/ X X#include "xdtm.h" X#include "menus.h" X X#include <X11/Shell.h> X#include <X11/Xaw/Label.h> X#include <X11/Xaw/Command.h> X#include <X11/Xaw/Viewport.h> X#include "Xedw/XedwForm.h" X#include "Xedw/XedwList.h" X Xextern void realize_dialog(Widget); X X/* Widgets */ X Xprivate Widget buttonpopup; /* For confermation of move/copy/trash buttons */ Xprivate Widget buttonform; Xprivate Widget buttonlabel1; Xprivate Widget buttonlabel2; Xprivate Widget buttonyes; Xprivate Widget buttonno; Xprivate Widget fileview; Xprivate Widget filelist; X X/***************************************************************************** X * init_button * X *****************************************************************************/ Xpublic void init_button(Widget top) X{ X /* initialise the widget which display's a list of filenames with a message X * and a couple of buttons. X */ X X Arg arglist[5]; X Cardinal i; X XtTranslations translations; X Dimension height, space; X XFontStruct *font; X X buttonpopup = XtCreatePopupShell("buttonpopup", X transientShellWidgetClass, X top, X NULL, 0); X X X buttonform = XtCreateManagedWidget("buttonform", X xedwFormWidgetClass, X buttonpopup, X NULL, 0); X X i = 0; X XtSetArg(arglist[i], XtNjustify, XtJustifyCenter); i++; X XtSetArg(arglist[i], XtNfullWidth, True); i++; X XtSetArg(arglist[i], XtNborderWidth, 0); i++; X buttonlabel1 = XtCreateManagedWidget("buttonlabel1", X labelWidgetClass, X buttonform, X arglist, i); X X i = 3; X XtSetArg(arglist[i], XtNfromVert, buttonlabel1); i++; X buttonlabel2 = XtCreateManagedWidget("buttonlabel2", X labelWidgetClass, X buttonform, X arglist, i); X X i = 0; X XtSetArg(arglist[i], XtNfromVert, buttonlabel2); i++; X XtSetArg(arglist[i], XtNfullWidth, True); i++; X XtSetArg(arglist[i], XtNforceBars, True); i++; X XtSetArg(arglist[i], XtNallowVert, True); i++; X fileview = XtCreateManagedWidget("fileview", X viewportWidgetClass, X buttonform, X arglist, i); X X translations = XtParseTranslationTable(""); X i = 0; X XtSetArg(arglist[i], XtNdefaultColumns, 1); i++; X XtSetArg(arglist[i], XtNforceColumns, True); i++; X XtSetArg(arglist[i], XtNrowSpacing, 4); i++; X XtSetArg(arglist[i], XtNtranslations, translations); i++; X filelist = XtCreateManagedWidget("filelist", X xedwListWidgetClass, X fileview, X arglist, i); X X X /* Get font height from filelist, then set fileview to be 5 times that X * size. X */ X X i = 0; X XtSetArg(arglist[i], XtNfont, &font); i++; X XtSetArg(arglist[i], XtNrowSpacing, &space); i++; X XtGetValues(filelist, arglist, i); X X height = (font->max_bounds.ascent + X font->max_bounds.descent + X space) * 5; X X i = 0; X XtSetArg(arglist[i], XtNheight, height); i++; X XtSetValues(fileview, arglist, i); X X X i = 0; X XtSetArg(arglist[i], XtNfromVert, fileview); i++; X XtSetArg(arglist[i], XtNjustify, XtJustifyCenter); i++; X buttonno = XtCreateManagedWidget("buttonyes", X commandWidgetClass, X buttonform, X arglist, i); X X i = 2; X XtSetArg(arglist[i], XtNfromHoriz, buttonno); i++; X XtSetArg(arglist[i], XtNwidthLinked, buttonno); i++; X buttonyes = XtCreateManagedWidget("buttonyes", X commandWidgetClass, X buttonform, X arglist, i); X X} X X/***************************************************************************** X * button_dialog * X *****************************************************************************/ Xpublic void button_dialog(Cardinal type, XedwListReturnStruct *list) X{ X /* Set the resources of the dialog to the type of dialog required, X * the type is either Trash, Copy or Move then popup the dialog. X * X * - Takes the type of dialog, and the list of files to display. X */ X X private int buttoniconcmp(XedwList **, XedwList **); X extern String getfilename(String); X extern void setscroll(Widget, float); X X XedwListReturnStruct *tmp; X XedwList **buttonlist; X Arg arglist[5]; X Cardinal i, n; X private String CancelButtonLabel = "Cancel"; X X /* Count items in linked list */ X n = 0; X tmp = list; X while (tmp != NULL) { X tmp = tmp->next; X n++; X } X X /* Allocate an array of XedwList* of that size */ X buttonlist = (XedwList**) XtMalloc (sizeof(XedwList*) * (n+1)); X X /* Put Strings from linked list into array, using NULL icons */ X for (i = 0; i < n; i++) { X buttonlist[i] = XtNew(XedwList); X buttonlist[i]->string = list->string; X list = list->next; X } X buttonlist[i] = NULL; X X /* Sort the list */ X qsort((char*)buttonlist, n, sizeof(buttonlist[0]), buttoniconcmp); X X /* Reset view to top */ X X setscroll(fileview, 0.0); X X switch (type) { X case Trash: X { X extern void trashQueryResult(Widget, Boolean, caddr_t); X private String TrashLabel1 = "Delete these files"; X private String TrashLabel2 = "from current directory?"; X private String TrashButtonLabel = "Delete"; X X /* label */ X i = 0; X XtSetArg(arglist[i], XtNlabel, TrashLabel1); i++; X XtSetValues(buttonlabel1, arglist, i); X X /* label2 */ X i = 0; X XtSetArg(arglist[i], XtNlabel, TrashLabel2); i++; X XtSetValues(buttonlabel2, arglist, i); X X /* file list */ X i = 0; X XtSetArg(arglist[i], XtNlongest, 0); i++; X XtSetArg(arglist[i], XtNnumberStrings, 0); i++; X XtSetArg(arglist[i], XtNxedwList, buttonlist); i++; X XtSetValues(filelist, arglist, i); X X /* button1 */ X i = 0; X XtSetArg(arglist[i], XtNlabel, CancelButtonLabel); i++; X XtSetValues(buttonno, arglist, i); X X /* button2 */ X i = 0; X XtSetArg(arglist[i], XtNlabel, TrashButtonLabel); i++; X XtSetValues(buttonyes, arglist, i); X X XtAddCallback(buttonno, XtNcallback, trashQueryResult, False); X XtAddCallback(buttonyes, XtNcallback, trashQueryResult, True); X realize_dialog(buttonpopup); X break; X } X case Copy: X { X extern void copyQueryResult(Widget, Boolean, caddr_t); X private String CopyLabel1 = "Copy these files"; X private String CopyLabel2 = "to current directory?"; X private String CopyButtonLabel = "Copy"; X X /* label */ X i = 0; X XtSetArg(arglist[i], XtNlabel, CopyLabel1); i++; X XtSetValues(buttonlabel1, arglist, i); X X /* label2 */ X i = 0; X XtSetArg(arglist[i], XtNlabel, CopyLabel2); i++; X XtSetValues(buttonlabel2, arglist, i); X X /* file list */ X i = 0; X XtSetArg(arglist[i], XtNlongest, 0); i++; X XtSetArg(arglist[i], XtNnumberStrings, 0); i++; X XtSetArg(arglist[i], XtNxedwList, buttonlist); i++; X XtSetValues(filelist, arglist, i); X X /* button1 */ X i = 0; X XtSetArg(arglist[i], XtNlabel, CancelButtonLabel); i++; X XtSetValues(buttonno, arglist, i); X X /* button2 */ X i = 0; X XtSetArg(arglist[i], XtNlabel, CopyButtonLabel); i++; X XtSetValues(buttonyes, arglist, i); X X XtAddCallback(buttonno, XtNcallback, copyQueryResult, False); X XtAddCallback(buttonyes, XtNcallback, copyQueryResult, True); X realize_dialog(buttonpopup); X break; X } X case Move: X { X extern void moveQueryResult(Widget, Boolean, caddr_t); X private String MoveLabel1 = "Move these files"; X private String MoveLabel2 = "to current directory?"; X private String MoveButtonLabel = "Move"; X X /* label */ X i = 0; X XtSetArg(arglist[i], XtNlabel, MoveLabel1); i++; X XtSetValues(buttonlabel1, arglist, i); X X /* label2 */ X i = 0; X XtSetArg(arglist[i], XtNlabel, MoveLabel2); i++; X XtSetValues(buttonlabel2, arglist, i); X X /* file list */ X i = 0; X XtSetArg(arglist[i], XtNlongest, 0); i++; X XtSetArg(arglist[i], XtNnumberStrings, 0); i++; X XtSetArg(arglist[i], XtNxedwList, buttonlist); i++; X XtSetValues(filelist, arglist, i); X X /* button1 */ X i = 0; X XtSetArg(arglist[i], XtNlabel, CancelButtonLabel); i++; X XtSetValues(buttonno, arglist, i); X X /* button2 */ X i = 0; X XtSetArg(arglist[i], XtNlabel, MoveButtonLabel); i++; X XtSetValues(buttonyes, arglist, i); X X XtAddCallback(buttonno, XtNcallback, moveQueryResult, False); X XtAddCallback(buttonyes, XtNcallback, moveQueryResult, True); X realize_dialog(buttonpopup); X break; X } X X default: X fprintf(stderr, "Unrecognised button dialog request\n"); X break; X } X X} X X/***************************************************************************** X * destroy_button_dialog * X *****************************************************************************/ Xpublic void destroy_button_dialog(void) X{ X /* Popdown and destroy the callback lists of the dialog */ X X XtPopdown(buttonpopup); X X XtRemoveAllCallbacks(buttonyes, XtNcallback); X XtRemoveAllCallbacks(buttonno, XtNcallback); X X} X X/***************************************************************************** X * buttoniconcmp * X *****************************************************************************/ Xprivate int buttoniconcmp(XedwList **ip1, XedwList **ip2) X{ X /* compare the strings of 2 XedwList's */ X X return (strcmp((*ip1)->string, X (*ip2)->string)); X} SHAR_EOF chmod 0644 xdtm/buttons.c || echo 'restore of xdtm/buttons.c failed' Wc_c="`wc -c < 'xdtm/buttons.c'`" test 10282 -eq "$Wc_c" || echo 'xdtm/buttons.c: original size 10282, current size' "$Wc_c" fi # ============= xdtm/dialogs.c ============== if test -f 'xdtm/dialogs.c' -a X"$1" != X"-c"; then echo 'x - skipping xdtm/dialogs.c (File already exists)' else echo 'x - extracting xdtm/dialogs.c (Text)' sed 's/^X//' << 'SHAR_EOF' > 'xdtm/dialogs.c' && X/***************************************************************************** X ** File : dialogs.c ** X ** Purpose : Initialise and Realise dialogs ** X ** Author : Edward Groenendaal ** X ** Date : 18th Feb 1991 ** X ** Documentation : Xdtm Design Folder ** X ** Related Files : quit.c buttons.c listoption.c map.c select.c display.c ** X ** newfile.c ** X *****************************************************************************/ X X/* dialog box's provided: Quit - Quit (yes/no) X * Button - Do action to these files (yes/no) X * Longl - Select options on Long Listing X * Map - Map program x over selected files OR X * Select - Select files using RE x. X * Query - Display file? X * Display - Display a file. X * Newfile - Ask for filename, create empty file. X * X */ X X#include "xdtm.h" X X/***************************************************************************** X * createDialogWidgets * X *****************************************************************************/ Xpublic void createDialogWidgets(Widget top) X{ X /* Call the initialise procedures of all the xdtm dialogs */ X X extern void init_quit(Widget); X extern void init_button(Widget); X extern void init_listoption(Widget); X extern void init_map(Widget); X extern void init_query(Widget); X extern void init_display(Widget); X extern void init_newfile(Widget); X X init_quit(top); X init_button(top); X init_listoption(top); X init_map(top); X init_query(top); X init_display(top); X init_newfile(top); X X} X X/***************************************************************************** X * realize_dialog * X *****************************************************************************/ Xpublic void realize_dialog(Widget popup) X{ X /* Given a popup widget this procedure, modified from one in the X Toolkit X * Intrinsics Programmers Manual, O'Reilly & Associates, pops it up with X * the center of the popup over the center of the application. X */ X X extern Widget topLevel; X Position x,y; X Dimension appWidth, appHeight, qWidth, qHeight; X XtGeometryResult result; X XtWidgetGeometry answer, question; X Arg arglist[2]; X Cardinal i; X X /* You dont know the dimensions of a widget for certain until it is X * realized, therefore realize the dialog. X * NOTE: XtRealizeWidget returns without an error if widget is already X * realized, hence no check via XtIsRealized. X */ X X XtRealizeWidget(popup); X X /* Get dimensions of application */ X i = 0; X XtSetArg(arglist[i], XtNwidth, &appWidth); i++; X XtSetArg(arglist[i], XtNheight, &appHeight); i++; X XtGetValues(topLevel, arglist, i); X X /* Get dimensions of quit popup */ X i = 0; X XtSetArg(arglist[i], XtNwidth, &qWidth); i++; X XtSetArg(arglist[i], XtNheight, &qHeight); i++; X XtGetValues(popup, arglist, i); X X /* Translate application coordinates to screen coordinates */ X XtTranslateCoords(topLevel, X (Position) ((appWidth/2)-(qWidth/2)), X (Position) ((appHeight/2)-(qHeight/2)), X &x, &y); X X /* move popup shell to that position */ X i = 0; X XtSetArg(arglist[i], XtNx, x); i++; X XtSetArg(arglist[i], XtNy, y); i++; X XtSetValues(popup, arglist, i); X X XtPopup(popup, XtGrabNonexclusive); X X} SHAR_EOF chmod 0644 xdtm/dialogs.c || echo 'restore of xdtm/dialogs.c failed' Wc_c="`wc -c < 'xdtm/dialogs.c'`" test 3636 -eq "$Wc_c" || echo 'xdtm/dialogs.c: original size 3636, current size' "$Wc_c" fi # ============= xdtm/dirman.c ============== if test -f 'xdtm/dirman.c' -a X"$1" != X"-c"; then echo 'x - skipping xdtm/dirman.c (File already exists)' else echo 'x - extracting xdtm/dirman.c (Text)' sed 's/^X//' << 'SHAR_EOF' > 'xdtm/dirman.c' && X/***************************************************************************** X ** File : dirman.c ** X ** Purpose : Directory Manager ** X ** Author : Edward Groenendaal ** X ** Date : 18th Feb 1991 ** X ** Documentation : Xdtm Design Folder ** X *****************************************************************************/ X X/* Include the application header file */ X#include "xdtm.h" X X/* Include the local header files */ X#include <sys/types.h> X#include <dirent.h> X#include <sys/stat.h> X#include <sys/param.h> X#include <limits.h> X#include <X11/Xaw/AsciiText.h> X X#include "menus.h" X#include "Xedw/XedwList.h" X#include "Xedw/XedwForm.h" X X#define LISTSIZE 128 /* The initial size of the icon_list */ X#define LISTINCR 64 /* The steps by which it will increase */ X X#ifdef TRUE_SYSV X#ifndef MAXPATHLEN X#define MAXPATHLEN 512 /* jcc */ X#endif X#endif X Xpublic void changestate(Boolean); /* Change sensitivity */ Xpublic String getfilename(String); /* extract filename */ X Xpublic Widget directoryManager; Xpublic String cwd; /* current working directory */ Xpublic Cardinal icon_list_size = 0; Xpublic Cardinal icon_list_max_size = LISTSIZE; Xpublic XedwList **icon_list; /* List with icons and/or filenames */ X X/* local copies of the menu panes which are to be made insensitive when X * no there is no current selection. X */ Xprivate Widget duplicatemenu, trashmenu, X copymenu, movemenu, mapmenu; X X X/***************************************************************************** X * createDirectoryManagerWidgets * X *****************************************************************************/ Xpublic void createDirectoryManagerWidgets(Widget view) X{ X /* Create the directory manager widget X * X * - Takes the directoryManager's parent widget X */ X X public void selection_made(Widget, caddr_t, caddr_t); X private void DoubleClick(Widget, XButtonEvent*); X private void GoUp(Widget, XButtonEvent*); X private void SelectAll(Widget, XButtonEvent*); X private void Refresh(Widget, XButtonEvent*); X X extern Icon_mode current_mode; X Cardinal i; X Arg arglist[6]; X XtTranslations dirManTranslations; X X /* New actions for directoryManager */ X static XtActionsRec actions[] = { X {"DoubleClick", DoubleClick}, X {"GoUp", GoUp}, X {"SelectAll", SelectAll}, X {"Refresh", Refresh}, X {NULL, NULL} X }; X X /* New translations for directoryManager */ X static char defaultTranslations[] = X "<Btn1Up>(2): DoubleClick()\n\ X <Key>u: GoUp()\n\ X <Key>a: SelectAll()\n\ X Ctrl<Key>L: Refresh()"; X X /* Set the initial mode depending on the value set in the application X * defaults. (current_mode.mode set previously to this value when X * creating widgets. X */ X i = 0; X switch (current_mode.mode) { X case Icons: X XtSetArg(arglist[i], XtNshowIcons, True); i++; X break; X case Short: X XtSetArg(arglist[i], XtNshowIcons, False); i++; X XtSetArg(arglist[i], XtNrowSpacing, 5); i++; X break; X case Long: X XtSetArg(arglist[i], XtNshowIcons, False); i++; X XtSetArg(arglist[i], XtNrowSpacing, 5); i++; X XtSetArg(arglist[i], XtNforceColumns, True); i++; X XtSetArg(arglist[i], XtNdefaultColumns, 1); i++; X } X XtSetArg(arglist[i], XtNfont, app_data.dm_font); i++; X XtSetArg(arglist[i], XtNmSelections, True); i++; X directoryManager = XtCreateManagedWidget("directoryManager", X xedwListWidgetClass, X view, X arglist, i); X X /* Add callbacks and translations */ X XtAddCallback(directoryManager, XtNcallback, selection_made, 0); X XtAddActions(actions, XtNumber(actions)); X dirManTranslations = XtParseTranslationTable(defaultTranslations); X XtAugmentTranslations(directoryManager, dirManTranslations); X} X X/***************************************************************************** X * directoryManagerNewDirectory * X *****************************************************************************/ Xpublic Boolean directoryManagerNewDirectory(String newpath) X{ X /* Change the contents of the directoryManager to that of the directory X * contained in the string newpath. X */ X X extern Boolean getIconType(String, String, XedwList*); X extern void setCursor(Cursor); X extern void setscroll(Widget, float); X private int iconcmp(XedwList*, XedwList*); X X extern Icon_mode current_mode; X extern Cursor busy; X extern Widget dirSelector; X extern Widget directoryManagerView; X Arg args[1]; X XedwList temp; X DIR *dirp; X struct dirent *dp; X Cardinal i = 0, n; X Boolean result = False; /* Whether the change of directories succeeded */ X X /* create a new one */ X if ((dirp = opendir(newpath)) != NULL && chdir(newpath) == 0) { X X /* set cursor to busy */ X setCursor(busy); X X /* Trash old list */ X for(i=0; i < icon_list_size; i++) { X XtFree(icon_list[i]->string); X XtFree(icon_list[i]); X } X X /* Get icon type for each file */ X i = 0; X while ((dp = readdir(dirp)) != NULL) { X if (i == icon_list_max_size) { X icon_list_max_size += LISTINCR; X icon_list = (XedwList**) XtRealloc(icon_list, X sizeof(XedwList*) * X icon_list_max_size); X } else X if (getIconType(dp->d_name, newpath, &temp)) { X icon_list[i] = XtNew(XedwList); X icon_list[i]->string = temp.string; X icon_list[i]->icon = temp.icon; X i++; X } X } X icon_list[i] = NULL; /* NULL terminated */ X icon_list_size = i; X X /* Sort the list */ X qsort((char*)icon_list, icon_list_size, sizeof(icon_list[0]), iconcmp); X X /* Change the contents of the directory Manager */ X XedwListChange(directoryManager, icon_list, icon_list_size, 0, True); X X /* Set the scrollbar of the viewport to the top */ X setscroll(directoryManagerView, 0.0); X X closedir(dirp); X result = True; X X /* Change entry in the directory selector */ X XtSetArg(args[0], XtNstring, newpath); X XtSetValues(dirSelector, args, 1); X /* reset cursor */ X setCursor(NULL); X } else X XBell(XtDisplay(directoryManager), 100); X return(result); X} X X/***************************************************************************** X * iconcmp * X *****************************************************************************/ Xprivate int iconcmp(XedwList **ip1, XedwList **ip2) X{ X /* compare the strings of 2 XedwList's */ X X return (strcmp(getfilename((*ip1)->string), X getfilename((*ip2)->string))); X} X X/***************************************************************************** X * initDirectoryManager * X *****************************************************************************/ Xpublic void initDirectoryManager(void) X{ X /* Get the menubar pane widgets, create the initial icon_list, find X * out what the current directory is. X */ X X extern Boolean buttonSensitive; X extern Widget menuBar; X char tmpcwd[MAXPATHLEN]; X X /* Initialise the icon list */ X icon_list = (XedwList**) XtMalloc(sizeof(XedwList*) * LISTSIZE); X X /* Set the starting directory */ X#ifdef USE_CWD X if (getcwd(tmpcwd, MAXPATHLEN) != NULL) X#else X if (getwd(tmpcwd) != NULL) X#endif X cwd = XtNewString(tmpcwd); X else X if ((cwd = (char*) getenv("HOME")) == NULL) X cwd = XtNewString("/"); X else X cwd = XtNewString(cwd); X X /* Get the id's of the menu widgets which are to be toggled with the X * buttons. Note: This relies on the menus being created first, which X * they are. X */ X if ((duplicatemenu = X XtNameToWidget(menuBar, "fileMenuButton.fileMenu.duplicate")) == NULL) { X fprintf(stderr, "Directorymanager: Can't find duplicate menu widget\n"); X exit(2); X } X if ((trashmenu = X XtNameToWidget(menuBar, "fileMenuButton.fileMenu.trash")) == NULL) { X fprintf(stderr, "Directorymanager: Can't find trash menu widget\n"); X exit(2); X } X if ((copymenu = X XtNameToWidget(menuBar, "fileMenuButton.fileMenu.copy")) == NULL) { X fprintf(stderr, "Directorymanager: Can't find copy menu widget\n"); X exit(2); X } X if ((movemenu = X XtNameToWidget(menuBar, "fileMenuButton.fileMenu.move")) == NULL) { X fprintf(stderr, "Directorymanager: Can't find move menu widget\n"); X exit(2); X } X if ((mapmenu = X XtNameToWidget(menuBar, "optionMenuButton.optionMenu.map")) == NULL) { X fprintf(stderr, "Directorymanager: Can't find map menu widget\n"); X exit(2); X } X (void) directoryManagerNewDirectory(cwd); X buttonSensitive = True; X changestate(False); /* Insure that menus are insensitive */ X} X X/***************************************************************************** X * selection_made * X *****************************************************************************/ Xpublic void selection_made(Widget w, caddr_t client_data, caddr_t call_data) X{ X /* Someone has either selected or deselected an item. X * If there's nothing selected then buttons are changed to X * not sensitive. X */ X X extern Boolean buttonSensitive; X extern Widget trashButton, copyButton, moveButton; X Arg arglist[1]; X Cardinal i; X X X if (XedwListSelection(w) != buttonSensitive) X if (buttonSensitive == False) { X changestate(True); X } else { X changestate(False); X } X} X X/***************************************************************************** X * DoubleClick * X *****************************************************************************/ Xprivate void DoubleClick(Widget w, XButtonEvent *event) X{ X /* Either Start a program, View a file or change directory. X * executable = try to exec it. X * directory = try to enter it. X * otherwise offer to view it. X * X * Maybe add stuff here to start a predefined application with this X * file as an argument if the filename matches a particular pattern, X * (James Beal, Henry Thomas) X * X * e.g. "\.ps$" -> "xps !@" X * "\.man$" -> "xterm -T 'Manual Page' -e sh -c 'nroff -man !@ | less'" X * "\.gif$" -> "xview !@" X */ X X extern void query_dialog(String, Boolean); X extern int execute(String, String, String, Boolean); X X extern Boolean buttonSensitive; X extern Widget trashButton, moveButton, copyButton; X X struct stat filestatus; X String fullname, filename, temp; X XedwListReturnStruct *highlighted; X Arg arglist[1]; X Cardinal i; X X selection_made(w, (caddr_t)0, (caddr_t)0); X highlighted = XedwListShowCurrent(w); X X if (highlighted->xedwList_index != XDTM_LIST_NONE) { X filename = getfilename(highlighted->string); X fullname=(String) XtMalloc((strlen(filename)+strlen(cwd)+2) * sizeof(char)); X strcpy(fullname, cwd); X if (strcmp(cwd, "/") != 0) X strcat(fullname, "/"); X strcat(fullname, filename); X X /* Use normal stat.. follows symbolic links */ X if (stat(fullname, &filestatus) == -1) { X fprintf(stderr,"xdtm: ARRRGGHHH stat error\n"); X } else { X if ((filestatus.st_mode & S_IFMT) == S_IFDIR) { X if (strcmp(filename, "..") == 0) { X strcpy(fullname, cwd); X if ((temp = (char*) strrchr(fullname, '/')) == NULL) X fprintf(stderr, "xdtm: impossible error\n"); X if (temp == fullname) X *(temp+1) = '\0'; X else X *temp = '\0'; X } X if (strcmp(filename, ".") == 0) { X XtFree(fullname); X fullname=XtNewString(cwd); X } X if (directoryManagerNewDirectory(fullname) == True) { X XtFree(cwd); X cwd=fullname; X changestate(False); X } else XBell(XtDisplay(w), 100); X } else { X /* Not a directory, is it executable? */ X if ((filestatus.st_mode & S_IXUSR) != 0 || X (filestatus.st_mode & S_IXGRP) != 0 || X (filestatus.st_mode & S_IXOTH) != 0) { X extern void setCursor(Cursor); X extern Cursor busy; X X setCursor(busy); X execute(fullname, filename, filename, False); X setCursor(NULL); X } else X if ((filestatus.st_mode & S_IFMT) == S_IFREG) { X /* Display dialog box to ask whether to display file */ X query_dialog(fullname, True); X } else XBell(XtDisplay(w), 100); X XtFree(fullname); X } X } X XtFree(highlighted); X } X} X X/***************************************************************************** X * GoUp * X *****************************************************************************/ Xprivate void GoUp(Widget w, XButtonEvent *event) X{ X /* Change to the directory immeditaly above the current one, X * does this by highlighting the .. directory, then calling X * DoubleClick to change to the highlighted directory. X * I used this longwinded approach because it showed on screen X * what was actually happening. X */ X X Cardinal i; X /* Find entry with .. */ X for (i=0; i < icon_list_size && X (strcmp(getfilename(icon_list[i]->string), "..") != 0); i++); X X XedwListUnhighlight(w, XedwAll); X /* Call XedwListHighlight with item number */ X XedwListHighlight(w, i); X X /* Call double click */ X X DoubleClick(w, (XButtonEvent*) NULL); X X} X X/***************************************************************************** X * SelectAll * X *****************************************************************************/ Xprivate void SelectAll(Widget w, XButtonEvent *event) X{ X /* Select All the files in the current directory except for . and .. */ X X extern Boolean buttonSensitive; X extern Widget trashButton, moveButton, copyButton; X public void changestate(Boolean); X extern void setCursor(Cursor); X extern Mode mode; X extern Cursor busy; X X Arg arglist[1]; X Cardinal i; X X /* Don't do it if in copy or move mode */ X if (mode == NormalMode) { X setCursor(busy); X XedwListHighlight(w, XedwAll); X X /* unhighlight . and .. */ X for (i=0; i < icon_list_size && X (strcmp(getfilename(icon_list[i]->string), ".") != 0); i++); X XedwListUnhighlight(w, i); X for (i=i; i < icon_list_size && X (strcmp(getfilename(icon_list[i]->string), "..") != 0); i++); X XedwListUnhighlight(w, i); X setCursor(NULL); X } else X XBell(XtDisplay(w), 100); X X /* do buttons */ X if (icon_list_size > 2) { X changestate(True); X } X} X X/***************************************************************************** X * Refresh * X *****************************************************************************/ Xprivate void Refresh(Widget w, XButtonEvent *event) X{ X /* Refresh the current directory contents to the actual contents. X */ X X directoryManagerNewDirectory(cwd); X} X X/***************************************************************************** X * changestate * X *****************************************************************************/ Xpublic void changestate(Boolean new) X{ X /* Toggle the sensitivity of all the widgets which may not be used X * when no files are highlighted. X * X * - Takes the new state for widgets. X */ X X extern Boolean buttonSensitive; X extern Widget trashButton, copyButton, moveButton; X extern Mode mode; X X if (buttonSensitive == True) { X if (mode == MoveMode) { X /* Turn off Trash and Copy */ X XtSetSensitive(copyButton, False); X XtSetSensitive(trashButton, False); X XtSetSensitive(copymenu, False); X XtSetSensitive(trashmenu, False); X XtSetSensitive(mapmenu, False); X XtSetSensitive(duplicatemenu, False); X buttonSensitive = False; X } else if (mode == CopyMode) { X /* Turn off Trash and Move */ X XtSetSensitive(moveButton, False); X XtSetSensitive(trashButton, False); X XtSetSensitive(movemenu, False); X XtSetSensitive(trashmenu, False); X XtSetSensitive(mapmenu, False); X XtSetSensitive(duplicatemenu, False); X buttonSensitive = False; X } else if (new == False) { X /* Turn off All */ X XtSetSensitive(moveButton, False); X XtSetSensitive(copyButton, False); X XtSetSensitive(trashButton, False); X XtSetSensitive(copymenu, False); X XtSetSensitive(movemenu, False); X XtSetSensitive(trashmenu, False); X XtSetSensitive(mapmenu, False); X XtSetSensitive(duplicatemenu, False); X buttonSensitive = False; X } X } else { X /* buttonSensitive == False */ X X /* If in MoveMode or CopyMode, then everything is set anyway */ X if (mode == NormalMode && new == True) { X /* Set all to True */ X XtSetSensitive(trashButton, True); X XtSetSensitive(moveButton, True); X XtSetSensitive(copyButton, True); X XtSetSensitive(trashmenu, True); X XtSetSensitive(movemenu, True); X XtSetSensitive(copymenu, True); X XtSetSensitive(duplicatemenu, True); X XtSetSensitive(mapmenu, True); X buttonSensitive = True; X } X } X} X X/***************************************************************************** X * getfilename * X *****************************************************************************/ Xpublic String getfilename(String s) X{ X /* If in Long Listing mode this function returns the filename part X * of the string used in the directory list. If not in Long Listing X * then return the string unmolested. X */ X extern Icon_mode current_mode; X X if (current_mode.mode == Long && (strlen(s) > current_mode.length)) X return (s+current_mode.length); X else X return (s); X} SHAR_EOF chmod 0644 xdtm/dirman.c || echo 'restore of xdtm/dirman.c failed' Wc_c="`wc -c < 'xdtm/dirman.c'`" test 17893 -eq "$Wc_c" || echo 'xdtm/dirman.c: original size 17893, current size' "$Wc_c" fi true || echo 'restore of xdtm/display.c failed' echo End of part 5, continue with part 6 exit 0 -- Dan Heller O'Reilly && Associates Z-Code Software Comp-sources-x: Senior Writer President comp-sources-x@uunet.uu.net argv@ora.com argv@zipcode.com