/************************************************************************ ** ** FILE : diwinpop.c ** ** ZWECK : Enthaelt die oeffentlichen Funktionen der DiWin-Funktionen ** DiWinPopup erzeugt und blendet Widget ein ** DiWinPopupC schreibt File falls gueltiges File ** existiert, sonst Aufruf DiWinPopupC ** DiWinInit Initialisiert DiWin (in main) ** DiWinPopdown schliesst und zerstoert Widget ** ** ANMERK: Ich habe es nicht geschafft es auf EINFACHE Weise hinzubekommen, ** dass der Text im TexteingabeWidget nach links gescrollt wird, ** sobald der Cursor beim Eintippen an den rechten Fensterrand ** stoesst. Deshalb habe ich den ScrollBalken eingestellt, falls ** doch mal laengere Namen editiert werden muessen. ** ** AUTOR : Michael C. Ancutici ** Universitaet Stuttgart, Fakultaet Informatik ** ** DATUM : 14.03.93 ** *************************************************************************/ #include "diwin.H" #include "fileio.h" #include "hamess.h" #include "hawin.h" #include "haka.H" /************************************************************************* ** FUNKTION: DiWinPopdown ** ZWECK: schliesst und zerstoert Widget *************************************************************************/ void DiWinPopdown() { XtPopdown( DiShell); XSync( MyDisplay,0); HaKaRedraw(); XtDestroyWidget( DiShell); } /************************************************************************* ** FUNKTION: DiWinInit ** ZWECK: Initialisiert Pfad, File und Breite Statuszeile *************************************************************************/ void DiWinInit() { if (!(getcwd( DirInh.Pfad, MAXPATHLEN))) /* bestimme momentanen */ strcpy( DirInh.Pfad, "/"); /* Pfad, sonst root */ DirInh.File[ 0] = EOL; /* Filename ungueltig */ DirInh.ScanNew = TRUE; /* Inhalt DirInh inkons.*/ DiStatWidth = DI_FI_VIEW_WIDTH + DI_PA_VIEW_WIDTH - 5; } /************************************************************************* ** FUNKTION: DiWinPopupC ** ZWECK: Schreibt File, falls gueltiger Filename esistiert, sonst ** Aufruf von DiWinPopup, d.h. Dir-Fenster geht auf. ** "C" steht fuer Condition. ** INPUT: Im 2. Fall wird Parent Widget w und Schreibbefehl in ** client_data an DiWinPopup weitergegeben *************************************************************************/ void DiWinPopupC( w, client_data, call_data) Widget w; XtPointer client_data, call_data; { STRING PfadPLUSFile; FILE *fp; if (DirInh.File[ 0] == EOL) /* Filename gueltig ? */ DiWinPopup( w, client_data, call_data); /* Fenster auf ! */ else { /* sonst schreiben */ sprintf( PfadPLUSFile, "%s%s", DirInh.Pfad, DirInh.File); if (!(fp=fopen( PfadPLUSFile, "w"))) { /* File ueberschreibbar ? */ DiMessage( DI_CANNOT_WRITE_OVER); /* Nein: Meldung */ return; } else fclose( fp); FileSave( PfadPLUSFile); HaMessage( HA_FILE_SAVED); } } /************************************************************************* ** FUNKTION: DiWinPopup ** ZWECK: Oeffnet Directory-Widget mit dem Ziel, dem Benutzer ** das Bestimmen eines Filenamens zu erleichtern ** INPUT: Parentwidget w und Auftrag LESEN oder SCHREIBEN ueber ** client_data *************************************************************************/ void DiWinPopup( w, client_data, call_data) Widget w; XtPointer client_data, call_data; { Position x, y; Dimension width, height, w1, w2; static char *label[] = { /* Ueberschrift Widget */ "Save Netfile", "Load Netfile"}; static char *command[] = { /* Label fuer Button */ "Save", "Load"}; static XtActionsRec DiSpec[] = { /* zusaetzliche Aktionen */ {"DiPaLoad", DiPaLoad}, {"DiFiAction", DiFiAction}, NULL}; DiOrder = (int)client_data; /* DATEI LESEN ODER SCHREIBEN */ if ((DirInh.ScanNew) && (SetPath( &DirInh, DirInh.Pfad))) { ScanDir( &DirInh); /* Verzeichnis nur scannen, wenn*/ DirInh.ScanNew = FALSE; /* DirInh ungueltig und Pfad */ } /* existiert */ /* XtVaGetValues( w, XtNwidth, &width, XtNheight, &height, NULL); */ XtTranslateCoords( HaGraphPlane, /* Mitte Parent-Widget als */ (Position) 40, /* absolute Koordinaten */ (Position) 40, &x, &y); DiShell = XtVaCreatePopupShell( /* Popup Shell */ "DiShell", transientShellWidgetClass, w, /* Parent Widget */ XtNx, x, XtNy, y, NULL); DiMaForm = XtVaCreateManagedWidget( /* Form Widget als Grund */ "DiMaForm", formWidgetClass, /* widget class */ DiShell, /* parent widget */ NULL); /* terminate argument list */ DiMaLabel = XtVaCreateManagedWidget( /* Ueberschrieft */ "DiMaLabel", /* widget name */ labelWidgetClass, /* widget class */ DiMaForm, /* parent widget */ XtNlabel, label[ DiOrder], NULL); /* terminate argument list */ DiFiPaned = XtVaCreateManagedWidget( /* fuer File-Seite */ "DiFiPaned", /* widget name */ panedWidgetClass, /* widget class */ DiMaForm, /* parent widget */ NULL); /* terminate argument list */ DiPaPaned = XtVaCreateManagedWidget( /* fuer Pfad-Seite */ "DiPaPaned", /* widget name */ panedWidgetClass, /* widget class */ DiMaForm, /* parent widget */ NULL); /* terminate argument list */ DiFiLabel = XtVaCreateManagedWidget( /* File Etikett */ "DiFiLabel", /* widget name */ labelWidgetClass, /* widget class */ DiFiPaned, /* parent widget */ NULL); /* terminate argument list */ DiFiText = XtVaCreateManagedWidget( /* File-Eingabefenster */ "DiFiText", /* widget name */ asciiTextWidgetClass, /* widget class */ DiFiPaned, /* parent widget */ XtNeditType,XawtextEdit, /* argument list */ XtNstring, DirInh.File, XtNscrollHorizontal, XawtextScrollAlways, XtNwidth, DI_FI_TEXT_WIDTH, NULL); /* terminate argument list */ XtVaSetValues( DiFiText, /* Textcursor in File-Eingabefenster */ XtNinsertPosition, strlen(DirInh.File), NULL); /* ans rechte Ende bewegen */ DiFiView = XtVaCreateManagedWidget( /* fuer File Liste */ "DiFiView", /* widget name */ viewportWidgetClass, /* widget class */ DiFiPaned, /* parent widget */ XtNallowVert, TRUE, /* argument list */ XtNuseRight, TRUE, /* argument list */ XtNwidth, DI_FI_VIEW_WIDTH, NULL); /* terminate argument list */ DiFiList = XtVaCreateManagedWidget( /* File-Liste */ "DiFiList", /* widget name */ listWidgetClass, /* widget class */ DiFiView, /* parent widget */ XtNlist, DirInh.Name+DirInh.nSubDir, /* Ort File Namen */ XtNnumberStrings, DirInh.nFiles-DirInh.nSubDir, /* Anzahl */ NULL); /* terminate argument list */ DiPaLabel = XtVaCreateManagedWidget( /* Label fuer Pfadseite */ "DiPaLabel", /* widget name */ labelWidgetClass, /* widget class */ DiPaPaned, /* parent widget */ NULL); /* terminate argument list */ DiPaText = XtVaCreateManagedWidget( /* Pfad-EingabeTextfeld */ "DiPaText", /* widget name */ asciiTextWidgetClass, /* widget class */ DiPaPaned, /* parent widget */ XtNeditType,XawtextEdit, /* argument list */ XtNscrollHorizontal, XawtextScrollAlways, XtNstring, DirInh.Pfad, XtNwidth, DI_PA_TEXT_WIDTH, NULL); /* terminate argument list */ XtVaSetValues( DiPaText, /* Textcursor ans rechte Ende */ XtNinsertPosition, strlen(DirInh.Pfad), NULL); DiPaView = XtVaCreateManagedWidget( /* fuer Pfad-Liste */ "DiPaView", /* widget name */ viewportWidgetClass, /* widget class */ DiPaPaned, /* parent widget */ XtNallowVert, TRUE, /* argument list */ XtNuseRight, TRUE, /* argument list */ XtNwidth, DI_PA_VIEW_WIDTH, NULL); /* terminate argument list */ DiPaList = XtVaCreateManagedWidget( /* Pfad-Liste */ "DiPaList", /* widget name */ listWidgetClass, /* widget class */ DiPaView, /* parent widget */ XtNlist, DirInh.Name, XtNnumberStrings, DirInh.nSubDir, NULL); /* terminate argument list */ DiAcCom = XtVaCreateManagedWidget( /* Action Button (Lesen/Schreiben) */ "DiAcCom", /* widget name */ commandWidgetClass, /* widget class */ DiMaForm, /* parent widget */ XtNlabel, command[ DiOrder], NULL); /* terminate argument list */ DiCanCom = XtVaCreateManagedWidget( /* Cancel Button */ "DiCanCom", /* widget name */ commandWidgetClass, /* widget class */ DiMaForm, /* parent widget */ XtNlabel, "Cancel", NULL); /* terminate argument list */ XtVaGetValues( DiCanCom, /* Breite Cancel Widget holen */ XtNwidth, &w1, NULL); XtVaGetValues( DiAcCom, /* Breite Action Widget holen */ XtNwidth, &w2, NULL); DiStatLabel = XtVaCreateManagedWidget( /* Statuszeile */ "DiStatLabel", /* widget name */ labelWidgetClass, /* widget class */ DiMaForm, /* parent widget */ XtNwidth, DiStatWidth-w1-w2, NULL); /* terminate argument list */ /* Breite: Status=ViewFile+ViewPfad-5-Action-Cancel */ XtAddCallback( DiCanCom, XtNcallback, DiCancel, 0); XtAddCallback( DiAcCom, XtNcallback, DiFiAction, 0); XtAddCallback( DiFiList, XtNcallback, DiFiSelect, 0); XtAddCallback( DiPaList, XtNcallback, DiPaSelect, 0); XtAppAddActions( AppContext, DiSpec, XtNumber( DiSpec)); XtPopup( DiShell, XtGrabExclusive); XFlush( XtDisplay( DiShell)); }