home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-09-22 | 26.6 KB | 1,107 lines |
- /*
- * Copyright 1993 by Ove Kalkan, Cremlingen, Germany
- *
- * Permission to use, copy, modify, distribute and sell this software and it's
- * documentation for any purpose is hereby granted without fee, rpovided that
- * the above copyright notice and this permission appear in supporting
- * documentation, and that the name of Ove Kalkan not to be used in
- * advertising or publicity pertaining to distributiopn of the software without
- * specific, written prior permission. Ove Kalkan makes no representations
- * about the suitability of this software for any purpose. It is provided
- * as is without express or implied warranty.
- *
- * OVE KALKAN DISPLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABLILITY AND FITNESS, IN NO
- * EVENT SHALL OVE KALKAN BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- * PERFORMANCE OF THIS SOFTWARE.
- *
- * $Header: filename,v 1.0 yyyy/mm/dd hh:mm:ss loginname Exp $
- */
-
-
- #include <stdio.h>
- #include <dirent.h>
- #include <unistd.h>
- #include <sys/stat.h>
-
- #include <X11/X.h>
- #include <X11/cursorfont.h>
-
- #include <X11/Intrinsic.h>
- #include <X11/StringDefs.h>
-
- #ifdef HAVE_XPM
- #include <X11/xpm.h>
- #include "icons.h"
- #else
- #include "bitmaps.h"
- #endif
-
- #include "cursor.h"
- #include "cursorm.h"
- #include "fcursor.h"
- #include "fcursorm.h"
-
- #include <X11/Shell.h>
-
- #include <X11/Xaw/Paned.h>
- #include <X11/Xaw/Form.h>
- #include <X11/Xaw/Viewport.h>
- #include <X11/Xaw/Simple.h>
- #include <X11/Xaw/Label.h>
-
- #include "struct.h"
- #include "config.h"
-
-
- /*
- * Globale Variablen
- */
-
-
- Widget toplevel, /* Das toplevel Widget */
- dir_area, /* Die Area in die der Diretorybaum gezeichnet
- wird */
- dir_vp,
- file_label, /* File Label */
- file_area; /* Hier werden die Files gezeigt */
-
- XtAppContext app_context; /* Der ApplicationContext - wichtig
- fuer den periodischen Directory Scan */
-
- Dir_Glyph root; /* Das Root-Glyphe */
- Folder_Glyph folder; /* Der Main Folder */
-
- GC line_gc; /* Die GC fuer die Linien */
- GC back_gc; /* Die GC fuer den Background */
- GC selc_gc; /* Die GC fuer den Background */
-
- Font iconfont; /* der Font fuer die Icons */
-
- Pixmap Dir_Closed_PM; /* Geschlossene Dirs */
- Pixmap Dir_Opened_PM; /* Offenes Directory */
- Pixmap Dir_Locked_PM; /* Verschlossen fuer Read/Write */
-
- Pixmap File_Root_PM; /* Fuer das Parentdir */
- Pixmap File_Plain_PM; /* Fuer unknown Files */
- Pixmap File_Text_PM; /* Fuer Text-Files */
- Pixmap File_Link_PM; /* Fuer Links */
- Pixmap File_Lock_PM; /* Fuer readpermitted files */
- Pixmap File_Pic_PM; /* Fuer pictures */
-
- Boolean DIR_CHANGED = FALSE; /* Bildhintergrund refreshen */
- Boolean FILE_CHANGED = FALSE; /* Bildhintergrund refreshen */
-
- Dimension last_y = 16000; /* Fuer die MotionEvents */
- Dir_Glyph *last_g = NULL;
-
- Dimension last_v = 16000; /* Fuer die Motionevents in der File-liste */
-
- Dir_Glyph *grab_g = NULL; /* Gerade gegrabbte Glyph im Dir-Feld */
- File_Glyph *grab_f = NULL;
-
- Dir_Glyph selc_g = NULL
- Dimension selc_f = 16000;
- Time selc_t = 0;
-
- Cursor def_cursor;
- Cursor file_cursor;
-
- Atom wm_delete_window;
-
- int label_height, vp_width;
-
- Suffix_Glyph commands[] = {
- {"xv", ".gif,.jpg,.GIF,.JPG,.pbm,.xbm,.ppm,.pgm,.XBM,.BM,.bm,.PBM,.PPM,.PGM", FILE_PIC},
- {"xmore",".txt,.doc", FILE_TEXT},
- {NULL,NULL,FILE_PLAIN},
- };
-
-
- /*
- * Function Prototypes
- */
- void main (int argc, char **argv);
- void createWidgets (Widget parent);
- void FATAL_ERROR (char *message);
-
- extern void fillDir (Dir_Glyph *dir);
- extern void showDir (Widget window, Dir_Glyph *dir,
- Dimension x, Dimension y,
- Dimension *lx, Dimension *ly);
-
- extern void fillFolder (Folder_Glyph *folder);
- extern String getPath (Dir_Glyph *dir);
-
- Dir_Glyph *getGlyph (Dir_Glyph *d, Dimension x, Dimension y);
-
- XtActionProc refresh_dirs(Widget w, XEvent *e, String *s, Cardinal *c);
- XtActionProc button_press(Widget w, XButtonEvent *e, String *s, Cardinal *c);
- XtActionProc dir_mouse(Widget w, XMotionEvent *e, String *s, Cardinal *c);
- XtActionProc dir_unhighlight(Widget w, XMotionEvent *e, String *s, Cardinal *c);
- XtActionProc dir_ungrab(Widget w, XMotionEvent *e, String *s, Cardinal *c);
- XtActionProc dir_grab(Widget w, XMotionEvent *e, String *s, Cardinal *c);
-
- XtActionProc refresh_files(Widget w, XEvent *e, String *s, Cardinal *c);
- XtActionProc file_mouse(Widget w, XMotionEvent *e, String *s, Cardinal *c);
-
- XtActionProc mark_object(Widget w, XEvent *e, String *s, Cardinal *c);
-
- void DEBUG (char *message);
- void makeCursor ();
-
- #define EXIT (exit(0))
-
- /*
- * Den Actionsrec erzeugen
- */
- static XtActionsRec actions[] =
- {
- {"refresh-dirs",
- (XtActionProc) refresh_dirs
- },
- {"unhighlight-dir",
- (XtActionProc) dir_unhighlight
- },
- {"follow-dir",
- (XtActionProc) dir_mouse
- },
- {"grab-dir",
- (XtActionProc) dir_grab
- },
- {"grab-file",
- (XtActionProc) dir_grab
- },
- {"ungrab-dir",
- (XtActionProc) dir_ungrab
- },
- {"refresh-files",
- (XtActionProc) refresh_files
- },
- {"button-press",
- (XtActionProc) button_press
- },
- {"follow-file",
- (XtActionProc) file_mouse
- },
- {"mark",
- (XtActionProc) mark_object
- },
- };
-
-
- /*
- ** Function name : main
- **
- ** Description : Hauptinitialisierung
- ** Input : int argc, char **argv;
- ** Ouput : none
- */
- void main (int argc, char **argv)
- {
- Arg args[2];
-
- /*
- * Den App-Context initalisieren und das ToplevelWidget holen
- */
- XtSetArg(args[0],XtNminWidth, 200);
- XtSetArg(args[1],XtNminHeight,100);
- toplevel = XtAppInitialize(&app_context,"Xfilemanager",NULL,0,
- &argc,argv,NULL,args,2);
-
- XtAppAddActions (app_context, actions, XtNumber (actions));
-
- /*
- * Den Main-WidgetTree auf diesem Fenster erzeugen
- */
- createWidgets(toplevel);
-
- /*
- * Den Main-Folder setzen
- */
- folder.max_length = 0;
- folder.rows = 1;
- folder.file_count = 0;
- folder.dir = &root;
- folder.file = NULL;
-
- /*
- * Den Root-Glyph initialisieren
- */
- root.x = 0;
- root.y = 0;
- root.open = TRUE;
- root.name = (String) getenv("HOME");
- /* root.name = "";
- */ root.parent = NULL;
- root.dir = NULL;
- root.dir_count = 0;
-
- /*
- * Den Status des Root-Directories holen
- */
- {
- struct stat buf;
-
- (void) stat ("/",&buf);
- root.flags = (buf.st_mode&(S_IRUSR | S_IRGRP | S_IROTH) ? DIR_READABLE : 0)
- + (buf.st_mode&(S_IWUSR | S_IWGRP | S_IWOTH) ? DIR_WRITEABLE : 0);
- }
- fillDir(&root);
- fillFolder(&folder);
-
- /*
- * Jetzt die Widgets erst einmal darstellen
- */
- XtRealizeWidget(toplevel);
-
- /*
- * Die Pixmaps laden
- */
- #ifdef HAVE_XPM
- {
- Pixmap smap;
- XpmAttributes attr;
-
- if (XpmCreatePixmapFromData (XtDisplay(toplevel),
- XtWindow(toplevel), dir_closed,
- &Dir_Closed_PM, &smap,
- &attr) != XpmSuccess)
- FATAL_ERROR("main: Failed to get 1. Icon\n");
- if (XpmCreatePixmapFromData (XtDisplay(toplevel),
- XtWindow(toplevel), dir_opened,
- &Dir_Opened_PM, &smap,
- &attr) != XpmSuccess)
- FATAL_ERROR("main: Failed to get 2. Icon\n");
- if (XpmCreatePixmapFromData (XtDisplay(toplevel),
- XtWindow(toplevel), dir_locked,
- &Dir_Locked_PM, &smap,
- &attr) != XpmSuccess)
- FATAL_ERROR("main: Failed to get 3. Icon\n");
- if (XpmCreatePixmapFromData (XtDisplay(toplevel),
- XtWindow(toplevel), file_root,
- &File_Root_PM, &smap,
- &attr) != XpmSuccess)
- FATAL_ERROR("main: Failed to get 4. Icon\n");
- if (XpmCreatePixmapFromData (XtDisplay(toplevel),
- XtWindow(toplevel), file_plain,
- &File_Plain_PM, &smap,
- &attr) != XpmSuccess)
- FATAL_ERROR("main: Failed to get 5. Icon\n");
- if (XpmCreatePixmapFromData (XtDisplay(toplevel),
- XtWindow(toplevel), file_text,
- &File_Text_PM, &smap,
- &attr) != XpmSuccess)
- FATAL_ERROR("main: Failed to get 6. Icon\n");
- if (XpmCreatePixmapFromData (XtDisplay(toplevel),
- XtWindow(toplevel), file_lock,
- &File_Lock_PM, &smap,
- &attr) != XpmSuccess)
- FATAL_ERROR("main: Failed to get 7. Icon\n");
- if (XpmCreatePixmapFromData (XtDisplay(toplevel),
- XtWindow(toplevel), file_link,
- &File_Link_PM, &smap,
- &attr) != XpmSuccess)
- FATAL_ERROR("main: Failed to get 8. Icon\n");
- if (XpmCreatePixmapFromData (XtDisplay(toplevel),
- XtWindow(toplevel), file_pic,
- &File_Pic_PM, &smap,
- &attr) != XpmSuccess)
- FATAL_ERROR("main: Failed to get 9. Icon\n");
- }
- #else
- #endif
- /*
- * Die GC's zum Zeichnen des Dir-Trees initialisieren
- */
- iconfont = XLoadFont(XtDisplay(toplevel),DEFAULT_ICON_FONT);
- {
- XtGCMask mask;
- XGCValues values;
-
- mask = GCFont | GCForeground;
- values.font = iconfont;
- values.foreground = XBlackPixel (XtDisplay(toplevel),
- XDefaultScreen(XtDisplay(toplevel)));
- line_gc = XtGetGC (toplevel, mask, &values);
-
- mask = GCFont | GCForeground;
- values.font = iconfont;
- values.foreground = XWhitePixel (XtDisplay(toplevel),
- XDefaultScreen(XtDisplay(toplevel)));
- back_gc = XtGetGC (toplevel, mask, &values);
-
- mask = GCFont | GCForeground;
- values.font = iconfont;
- values.foreground = 6;
- selc_gc = XtGetGC (toplevel, mask, &values);
- }
- XtManageChild(dir_area);
- XtManageChild(file_area);
-
- {
- Arg args[1],largs[1];
-
- XtSetArg(args[0],XtNwidth,0);
- XtGetValues(dir_vp,args,1);
- XtSetArg(largs[0],XtNheight,0);
- XtGetValues(file_label,largs,1);
-
- label_height = largs[0].value;
- vp_width = args[0].value;
- }
-
- /*
- * Den Default Cursor setzen
- */
- makeCursor();
-
- XDefineCursor(XtDisplay(dir_area),XtWindow(dir_area), def_cursor);
- XDefineCursor(XtDisplay(file_area),XtWindow(file_area), def_cursor);
-
- /*
- * Den Quit-Button im WM-Menu als Quitbutton nutzen
- */
- wm_delete_window = XInternAtom(XtDisplay(toplevel),"WM_DELETE_WINDOW",
- FALSE);
- (void) XSetWMProtocols (XtDisplay(toplevel),XtWindow(toplevel),&wm_delete_window,1);
- /*
- * Der Main-Loop
- */
- XtAppMainLoop(app_context);
- }
-
-
-
-
- /*
- ** Function name : createWidgets
- **
- ** Description : Diese Funktion erzeugt ein Directoryfenster
- ** Input : Widget parent; Zeiger auf das Parentwidget
- ** Ouput : none
- */
- void createWidgets (Widget parent)
- {
- Arg args[10];
- Widget main_pane,
- field_pane,
- dummy,
- viewport;
-
-
- /*
- * Zunaechst erst einmal den main-pane erzeugen
- */
- main_pane = XtCreateManagedWidget("main_pane", panedWidgetClass,
- parent, args,0);
-
- /*
- * Die Seperator-pane fuer die Directoryfields setzen
- */
- XtSetArg(args[0],XtNorientation, XtorientHorizontal);
- field_pane = XtCreateManagedWidget("field_pane", panedWidgetClass,
- main_pane, args,1);
-
- /*
- * Auf dieses field_pane jetzt den Viewport setzen, der das
- * Simple-Widget fuer den Directory-Tree enthalten soll
- */
- XtSetArg(args[0],XtNallowHoriz, TRUE);
- XtSetArg(args[1],XtNallowVert, TRUE);
- XtSetArg(args[2],XtNwidth, 300);
- XtSetArg(args[3],XtNheight,400);
- XtSetArg(args[4],XtNforceBars, TRUE);
- XtSetArg(args[5],XtNuseBottom, TRUE);
- XtSetArg(args[6],XtNuseRight, TRUE);
- viewport = XtCreateManagedWidget("viewport", viewportWidgetClass,
- field_pane, args,7);
- dir_vp = viewport;
-
- /*
- * Auf das Viewport kommt jetzt das Simple-Widget fuer den
- * Directory Tree
- */
- XtSetArg(args[0],XtNwidth, 300);
- XtSetArg(args[1],XtNheight,400);
- dir_area = XtCreateWidget("dir_simple", simpleWidgetClass,
- viewport, args, 2);
- XtOverrideTranslations(dir_area,
- XtParseTranslationTable("<Expose>: refresh-dirs()\n\
- <Btn1Motion>: follow-dir() grab-dir()\n\
- <Btn1Down>: follow-dir() mark()\n\
- <Leave>: unhighlight-dir()\n\
- <Btn1Up>: button-press() unhighlight-dir() ungrab-dir()"));
-
- /*
- * Den Bereich fuer das Folder-Fenster
- */
- dummy = XtCreateManagedWidget("folder_pane", panedWidgetClass,
- field_pane, args,0);
-
- /*
- * darauf den File_label erzeugen
- */
- XtSetArg(args[0],XtNshowGrip, FALSE);
- file_label = XtCreateManagedWidget("file_label", labelWidgetClass,
- dummy, args,1);
-
- /*
- * Auf dieses field_pane jetzt den Viewport setzen, der das
- * Simple-Widget fuer den Directory-Tree enthalten soll
- */
- XtSetArg(args[0],XtNallowHoriz, TRUE);
- XtSetArg(args[1],XtNallowVert, TRUE);
- XtSetArg(args[2],XtNwidth, 400);
- XtSetArg(args[3],XtNheight,400);
- XtSetArg(args[4],XtNforceBars, TRUE);
- XtSetArg(args[5],XtNuseBottom, TRUE);
- XtSetArg(args[6],XtNuseRight, TRUE);
- viewport = XtCreateManagedWidget("viewport", viewportWidgetClass,
- dummy, args,7);
-
- /*
- * Auf das Viewport kommt jetzt das Simple-Widget fuer den
- * Directory Tree
- */
- XtSetArg(args[0],XtNwidth, 400);
- XtSetArg(args[1],XtNheight,400);
- file_area = XtCreateWidget("file_simple", simpleWidgetClass,
- viewport, args, 2);
- XtOverrideTranslations(file_area,
- XtParseTranslationTable("<Btn1Motion>: follow-file() grab-file()\n\
- <Btn1Down>: follow-file() mark()\n\
- <Leave>: unhighlight-dir()\n\
- <Btn1Up>: button-press() unhighlight-dir() ungrab-dir()\n\
- <Expose>: refresh-files()"));
-
- }
-
-
-
-
- /*
- ** Function name : FATAL_ERROR
- **
- ** Description : Bricht im Fehlerfall mit einer Fehlermeldung ab
- ** Input :
- ** Ouput :
- */
- void FATAL_ERROR (char *message)
- {
- fprintf(stderr,"%s",message);
- exit(1);
- }
-
-
-
- /*
- ** Function name : refresh_files
- **
- ** Description : Neuzeichnen des Directories nach einem Expose
- ** Input : none
- ** Ouput : none
- */
- XtActionProc refresh_files (Widget w, XEvent *e, String *s, Cardinal *c)
- {
- Dimension lx = 0, ly;
- Arg args[4];
-
- /*
- * Directorypfad neu Zeichnen
- */
- if (FILE_CHANGED) {
- XClearWindow(XtDisplay(file_area),XtWindow(file_area));
- FILE_CHANGED = FALSE;
- }
- showFolder (file_area, &folder, 20, 6, &lx, &ly);
- folder.max_length = lx + DIR_X_STEP;
-
- /*
- * Die Hoehe anpassen
- */
- XtSetArg(args[0],XtNheight, ly + 2*DIR_Y_STEP);
- XtSetArg(args[1],XtNwidth, lx + 2*DIR_X_STEP);
- XtSetArg(args[2],XtNx, 0);
- XtSetArg(args[3],XtNy, 0);
- XtSetValues(file_area,args,4);
- }
-
-
-
- /*
- ** Function name : refresh_dirs
- **
- ** Description : Neuzeichnen des Directories nach einem Expose
- ** Input : none
- ** Ouput : none
- */
- XtActionProc refresh_dirs (Widget w, XEvent *e, String *s, Cardinal *c)
- {
- Dimension lx = 0, ly;
- Arg args[2];
-
- /*
- * Directorypfad neu Zeichnen
- */
- if (DIR_CHANGED) {
- DIR_CHANGED = FALSE;
- XClearWindow(XtDisplay(dir_area),XtWindow(dir_area));
- }
- showDir (dir_area, &root, 20, 6, &lx, &ly);
-
- /*
- * Die Hoehe anpassen
- */
- XtSetArg(args[0],XtNheight, ly + 2*DIR_Y_STEP);
- XtSetArg(args[1],XtNwidth, lx + 2*DIR_X_STEP);
- XtSetValues(dir_area,args,2);
- }
-
-
-
-
- /*
- ** Function name : dir_mouse
- **
- ** Description : Sobald ein Button gedrueckt wurde.
- ** Input :
- ** Ouput :
- */
- XtActionProc dir_mouse (Widget w, XMotionEvent *e, String *s, Cardinal *c)
- {
- Dir_Glyph *dir;
- int y;
- Arg args[2];
-
- XtSetArg(args[0],XtNx,0);
- XtSetArg(args[1],XtNy,0);
- XtGetValues(dir_area,args,2);
-
- /*
- * Nachsehen ob eventuell wieder in einem neuen Feld
- */
- if (e->x-args[0].value > vp_width) {
- /*
- * Fenster wird verlassen, also Event an File-Handler weiterreichen
- */
- Arg largs[2];
- XtSetArg(largs[0],XtNx,0);
- XtSetArg(largs[1],XtNy,0);
- XtGetValues(file_area,largs,2);
-
- e->y -= label_height - (args[1].value - largs[1].value);
- e->x -= vp_width + (args[0].value - largs[0].value);
- file_mouse (w,e,s,c);
- }
- else {
- if (last_v < 16000) {
- XDrawRectangle(XtDisplay(file_area),XtWindow(file_area),
- back_gc, 16, last_v*DIR_Y_STEP + 4,
- folder.max_length, 20);
- last_v = 16000;
- }
- y = (e->y - last_y < 0) ? (last_y - e->y) : (e->y - last_y);
- if (y > DIR_Y_STEP/2) {
- if (last_y > 0 && last_y < 16000) {
- XDrawRectangle(XtDisplay(dir_area),XtWindow(dir_area),
- back_gc, last_g->x - 4, last_g->y - 2,
- 30 + 8*strlen(last_g->name), 20);
- last_y = 0;
- last_g = NULL;
- }
- dir = getGlyph(&root,e->x,e->y);
- if (dir) {
- last_g = dir;
- if (last_g != grab_g && (last_g->flags & DIR_WRITEABLE))
- XDrawRectangle(XtDisplay(dir_area),XtWindow(dir_area),
- selc_gc, last_g->x - 4, last_g->y - 2,
- 30 + strlen(last_g->name)*8, 20);
- last_y = dir->y + 8;
- }
- }
- }
- }
-
-
-
- /*
- ** Function name : dir_unhighlight
- **
- ** Description : Sobald ein Button gedrueckt wurde.
- ** Input :
- ** Ouput :
- */
- XtActionProc dir_unhighlight (Widget w, XMotionEvent *e, String *s, Cardinal *c)
- {
- /*
- * Nachsehen ob noch ein Eintrag gehighlighted ist
- */
- if (last_v < 16000) {
- XDrawRectangle(XtDisplay(file_area),XtWindow(file_area),
- back_gc, 16, last_v*DIR_Y_STEP + 4,
- folder.max_length, 20);
- last_v = 16000;
- }
- if (last_y > 0 && last_y < 16000) {
- XDrawRectangle(XtDisplay(dir_area),XtWindow(dir_area),
- back_gc, last_g->x - 4, last_g->y - 2,
- 30 + 8*strlen(last_g->name), 20);
- last_y = 0;
- }
- }
-
-
-
- /*
- ** Function name : button_press
- **
- ** Description : Sobald ein Button gedrueckt wurde.
- ** Input :
- ** Ouput :
- */
- XtActionProc button_press (Widget w, XButtonEvent *e, String *s, Cardinal *c)
- {
- Arg args[2],largs[2];
-
- XtSetArg(args[0],XtNx,0);
- XtSetArg(args[1],XtNy,0);
- XtGetValues(dir_area,args,2);
- XtSetArg(largs[0],XtNx,0);
- XtSetArg(largs[1],XtNy,0);
- XtGetValues(file_area,largs,2);
- /*
- * Der Endpunkt der Graboperation lag im Dir-Feld
- */
- if (w == dir_area && e->x - args[0].value > vp_width) {
- e->y -= label_height - (args[1].value - largs[1].value);
- e->x -= vp_width + (args[0].value - largs[0].value);
- w = file_area;
- }
- else if (w == file_area && e->x - largs[0].value < 0) {
- e->y += label_height + (args[1].value - largs[1].value);
- e->x += vp_width - (args[0].value - largs[0].value);
- w = dir_area;
- }
- if (w == dir_area) {
- Dir_Glyph *dir;
-
- /*
- * Zunaechst einmal muss anhand der Koordinaten das entsprechde
- * Dir_Glyph heraus gesucht werden
- */
- dir = last_g;
-
- if (dir) {
- /*
- * Nachsehen ob gerade eine Move-Grab operation ausgefuehrt wird
- */
- if (grab_g && dir != grab_g) {
- /*
- * Verschieben des Directories in das gerade selectierte
- */
- printf ("mv %s %s\n",getPath(grab_g),getPath(dir));
- }
- else if (grab_f && folder.dir != dir) {
- /*
- * Verschieben des Icons vom file_area in die Dir-area
- */
- printf("mv %s/%s %s\n",getPath(folder.dir),grab_f->name,
- getPath(dir));
- }
- else if (!grab_g && !grab_f) {
- /*
- * Nachpruefen ob Directory geoeffnet ist
- */
- if (dir->open) {
- if (dir->dir_count > 0)
- DIR_CHANGED = TRUE;
- dir->open = FALSE;
- refresh_dirs(NULL,NULL,NULL,NULL);
- }
- else {
- if (dir->flags & DIR_READABLE) {
- fillDir(dir);
- if (dir->dir_count > 0)
- DIR_CHANGED = TRUE;
- refresh_dirs(NULL,NULL,NULL,NULL);
- FILE_CHANGED = TRUE;
- folder.dir = dir;
- fillFolder(&folder);
- refresh_files(NULL,NULL,NULL,NULL);
- }
- }
- }
- }
- }
- /*
- * Der Endpunkt der Grabaktion lag im File-Feld
- */
- else if (w == file_area) {
- /*
- * Testen ob zum Schluss noch ein Argument aktiviert war
- */
- if (last_v < 16000) {
- if (grab_f && grab_f != folder.file[last_v]) {
- printf("mv %s/%s %s/%s\n",getPath(folder.dir),grab_f->name,
- getPath(folder.dir),folder.file[last_v]->name);
- }
- else if (grab_g) {
- printf("mv %s %s/%s\n",getPath(grab_g),
- getPath(folder.dir),folder.file[last_v]->name);
- }
- else if (!grab_f && !grab_g) {
- File_Glyph *file = folder.file[last_v];
-
- if (file->prog_type == FILE_ROOT && folder.dir->parent) {
- folder.dir = folder.dir->parent;
- fillFolder(&folder);
- FILE_CHANGED = TRUE;
- refresh_files(NULL,NULL,NULL,NULL);
- }
- else if (file->prog_type == FILE_DIR) {
- int i = 0, j = -1;
-
- while (i < folder.dir->dir_count) {
- if (!(strcmp(folder.dir->dir[i]->name,file->name))) {
- j = i;
- i = folder.dir->dir_count;
- }
- i++;
- }
- if (j > -1) {
- folder.dir = folder.dir->dir[j];
- if (!folder.dir->open && folder.dir->dir_count == 0) {
- fillDir (folder.dir);
- folder.dir->open = FALSE;
- }
- fillFolder (&folder);
- FILE_CHANGED = TRUE;
- refresh_files(NULL,NULL,NULL,NULL);
- }
- }
- else if (file->prog_type != FILE_PLAIN) {
- int i = 0;
-
- while (commands[i].cmd && commands[i].type != file->prog_type)
- i++;
-
- if (commands[i].type == file->prog_type) {
- char buf[200];
-
- sprintf(buf,"%s %s/%s &\0",commands[i].cmd,
- getPath(folder.dir),file->name);
- system(buf);
- }
- }
- }
- }
- }
- }
-
-
-
-
-
- /*
- ** Function name : getGlyph
- **
- ** Description : Prueft, ob an den Koordinaten x,y ein Glyph liegt
- ** Input : Dir_Glyph Root; Position x,y
- ** Ouput :
- */
- Dir_Glyph *getGlyph (Dir_Glyph *d, Dimension x, Dimension y)
- {
- /*
- * Pruefen ob Punkt ueberhaupt im Bereich liegen kann
- */
- if (y < d->y || x < d->x)
- return(NULL);
-
- /*
- * Pruefen ob das Icon das an dieser Position liegt
- */
- if ( y < d->y + 16 && x < d->x + 24 + 8*strlen(d->name))
- return(d);
-
- /*
- * Das Stammglyph war es nicht, also Verzeichnis durchsuchen
- */
- if (d->dir_count > 0 && d->open) {
- int i;
-
- /*
- * alle Glyphs durchprobieren
- */
- for (i = 0; i < d->dir_count; i++) {
- Dir_Glyph *b;
-
- b = getGlyph(d->dir[i],x,y);
- if (b != NULL)
- return(b);
- }
- }
- return(NULL);
- }
-
-
-
- /*
- ** Function name : DEBUG
- **
- ** Description : Gibt eine Debugmessage aus
- ** Input : char *message - Nachricht die ausgegeben werden soll
- ** Ouput :
- */
- void DEBUG (char *message)
- {
- printf("DEBUG: %s\n",message);
- }
-
-
-
- /*
- ** Function name : file_mouse
- **
- ** Description : Berechnet anhand der Mausposition, ob ein File angewaehlt wurde
- ** oder nicht.
- ** Input : nicht beachtet
- ** Ouput : unwichtig
- */
- XtActionProc file_mouse (Widget w, XMotionEvent *e, String *s, Cardinal *c)
- {
- int y;
- Arg largs[2];
-
- XtSetArg(largs[0],XtNx,0);
- XtSetArg(largs[1],XtNy,0);
- XtGetValues(file_area,largs,2);
-
- /*
- * Nachsehen ob eventuell wieder in einem neuen Feld
- */
- if (e->x - largs[0].value < 0) {
- /*
- * Es wird das Feld gewechselt, also Event an dir-handling-Routine
- * weiterreichen
- */
- Arg args[2];
-
- XtSetArg(args[0],XtNx,0);
- XtSetArg(args[1],XtNy,0);
- XtGetValues(dir_area,args,2);
-
- e->y += label_height - (args[1].value - largs[1].value);
- e->x += vp_width + (args[0].value - largs[0].value);
- dir_mouse(w,e,s,c);
- }
- else {
- y = (e->y - 4)/DIR_Y_STEP;
- if (last_y > 0 && last_y < 16000) {
- XDrawRectangle(XtDisplay(dir_area),XtWindow(dir_area),
- back_gc, last_g->x - 4, last_g->y - 2,
- 30 + 8*strlen(last_g->name), 20);
- last_y = 0;
- last_g = NULL;
- }
- if (y != last_v) {
- if (last_v < 16000) {
- XDrawRectangle(XtDisplay(file_area),XtWindow(file_area),
- back_gc, 16, last_v*DIR_Y_STEP + 4,
- folder.max_length, 20);
- last_v = 16000;
- }
- if (y < folder.file_count) {
- last_v = y;
- if (folder.file[last_v] != grab_f)
- XDrawRectangle(XtDisplay(file_area),XtWindow(file_area),
- selc_gc, 16, last_v*DIR_Y_STEP + 4,
- folder.max_length, 20);
- }
- }
- }
- }
-
-
-
-
- /*
- ** Function name : dir_grab
- **
- ** Description : Falls moeglich wird das Glyph in den Grab_buffer gepackt
- ** Input : Widget w - gibt an ob dir_area oder file_area, Rest unwichtig
- ** Ouput : nichts
- */
- XtActionProc dir_grab (Widget w, XMotionEvent *e, String *s, Cardinal *c)
- {
- if (!grab_g && !grab_f) {
- Pixmap pmap, mask;
- XColor fg,bg;
- Cursor cursor;
- GC gc;
-
- /*
- * Selected Widget setzen
- */
- Arg args[1],largs[1];
-
- XtSetArg(args[0],XtNwidth,0);
- XtGetValues(dir_vp,args,1);
- XtSetArg(largs[0],XtNheight,0);
- XtGetValues(file_label,largs,1);
-
- label_height = largs[0].value;
- vp_width = args[0].value;
-
- if (w == dir_area && last_g) {
- if (last_g->flags & DIR_WRITEABLE) {
- grab_g = last_g;
-
- /*
- * Cursor setzen
- */
- XDefineCursor(XtDisplay(dir_area),XtWindow(dir_area),file_cursor);
- XDefineCursor(XtDisplay(file_area),XtWindow(file_area),file_cursor);
- }
- }
- else if (w == file_area && last_v < 16000 &&
- folder.file[last_v]->prog_type != FILE_ROOT){
- grab_f = folder.file[last_v];
-
- /*
- * Cursor setzen
- */
- XDefineCursor(XtDisplay(dir_area),XtWindow(dir_area),file_cursor);
- XDefineCursor(XtDisplay(file_area),XtWindow(file_area),file_cursor);
- }
- }
- }
-
-
- /*
- ** Function name : dir_ungrab
- **
- ** Description : Loescht den Grabbuffer und resetet den Cursor
- ** Input : unwichtig das ActionProc
- ** Ouput : nichts
- */
- XtActionProc dir_ungrab (Widget w, XMotionEvent *e, String *s, Cardinal *c)
- {
- if (grab_g || grab_f) {
- /*
- * Selected Glyph = NULL
- */
- grab_g = NULL;
- grab_f = NULL;
- /*
- * Cursor ruecksetzen
- */
- XDefineCursor(XtDisplay(dir_area),XtWindow(dir_area), def_cursor);
- XDefineCursor(XtDisplay(file_area),XtWindow(file_area), def_cursor);
- }
- }
-
-
- /*********************************************************
- * name: makeCursor
- * description: Erzeugt einen Cursor aus einem Icon und einem Text
- * input: Pixmap icon
- * char *label
- * output: Zeiger auf den Cursor
- * date: Main 93
- *********************************************************/
- void makeCursor ()
- {
- Pixmap pmap;
- Pixmap smap;
- XColor fg,bg;
-
- /*
- * Die Pixmap erzeugen
- */
- fg.red = fg.blue = fg.green = 0;
- bg.red = bg.blue = bg.green = 0xffff;
- pmap = XCreatePixmapFromBitmapData(XtDisplay(toplevel), XtWindow(toplevel), cursor_bits,
- cursor_width,cursor_height, 1,0, 1);
- smap = XCreatePixmapFromBitmapData(XtDisplay(toplevel), XtWindow(toplevel), cursorm_bits,
- cursorm_width,cursorm_height, 1,0, 1);
-
- def_cursor = XCreatePixmapCursor(XtDisplay(toplevel),pmap,smap,&fg,&bg,
- cursor_x_hot,cursor_y_hot);
-
- pmap = XCreatePixmapFromBitmapData(XtDisplay(toplevel), XtWindow(toplevel), fcursor_bits,
- fcursor_width,fcursor_height, 1,0, 1);
- smap = XCreatePixmapFromBitmapData(XtDisplay(toplevel), XtWindow(toplevel), fcursorm_bits,
- fcursorm_width,fcursorm_height, 1,0, 1);
-
- file_cursor = XCreatePixmapCursor(XtDisplay(toplevel),pmap,smap,&fg,&bg,
- fcursor_x_hot,fcursor_y_hot);
- }
-
-
- /*
- ** Function name : mark_object
- **
- ** Description : markieren des gerade angewaehlten Icons und achten auf Doppelklicks
- ** Input : none
- ** Ouput : none
- */
- XtActionProc mark_object (Widget w, XButtonEvent *e, String *s, Cardinal *c)
- {
- #define ABSDIFF(a,b) (a - b < 0 ? b - a : a - b)
- #define MAX_INTERVAL 300
-
- if (w == file_area && last_v < 16000) {
- if (selc_f != last_v) {
- selc_t = e->time;
- if (selc_g) {
- /*
- * Demarkieren
- */
- selc_g = NULL;
- }
- else if (selc_f < 16000) {
- /*
- * demarkieren
- */
- }
- selc_f = last_v;
- /*
- * Markieren
- */
- }
- else if (ABSDIFF(selc_t,e->time) < MAX_INTERVAL) { /* Innerhalb der Doppelklickid */
- selc_t = e->time;
- }
- }
- else if (w == dir_area && last_g) {
- if (last_g != selc_g) {
- selc_t = e->time;
- if (selc_f) {
- /*
- * Demarkieren
- */
- selc_f = 16000;
- }
- if (selc_g) {
- /*
- * demarkieren
- */
- }
- selc_g = last_g;
- /*
- * Markieren
- */
- }
- else if (ABSDIFF(selc_t,e->time) < MAX_INTERVAL) { /* Innerhalb der Doppelklickid */
- selc_t = e->time;
- }
- }
- }
-
-
-
-