📄 selfile.c
字号:
/* $Id: SelFile.c,v 1.6 2005/11/13 01:35:10 ellson Exp $ $Revision: 1.6 $ *//* vim:set shiftwidth=4 ts=8: *//*********************************************************** This software is part of the graphviz package ** http://www.graphviz.org/ ** ** Copyright (c) 1994-2004 AT&T Corp. ** and is licensed under the ** Common Public License, Version 1.0 ** by AT&T Corp. ** ** Information and Software Systems Research ** AT&T Research, Florham Park NJ ***********************************************************/#ifdef FEATURE_CS#include <ast.h>#endif/* * Copyright 1989 Software Research Associates, Inc., Tokyo, Japan * * Permission to use, copy, modify, and distribute this software and its * documentation for any purpose and without fee is hereby granted, provided * that the above copyright notice appear in all copies and that both that * copyright notice and this permission notice appear in supporting * documentation, and that the name of Software Research Associates not be used * in advertising or publicity pertaining to distribution of the software * without specific, written prior permission. Software Research Associates * makes no representations about the suitability of this software for any * purpose. It is provided "as is" without express or implied warranty. * * SOFTWARE RESEARCH ASSOCIATES DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, * IN NO EVENT SHALL SOFTWARE RESEARCH ASSOCIATES 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. * * Author: Erik M. van der Poel * Software Research Associates, Inc., Tokyo, Japan * erik@sra.co.jp *//* * Author's address: * * erik@sra.co.jp * OR * erik%sra.co.jp@uunet.uu.net * OR * erik%sra.co.jp@mcvax.uucp * OR * try junet instead of co.jp * OR * Erik M. van der Poel * Software Research Associates, Inc. * 1-1-1 Hirakawa-cho, Chiyoda-ku * Tokyo 102 Japan. TEL +81-3-234-2692 */#ifdef HAVE_CONFIG_H#include "config.h"#endif#include <stdio.h>#ifdef HAVE_ERRNO_H#include <errno.h>#endif#ifndef HAVE_STRERROR# ifndef HAVE_ERRNO_DECLextern int errno;extern int sys_nerr;# if (linux)extern const char *const sys_errlist[];# elseextern char *sys_errlist[];# endif# endif#endif#include <sys/param.h>#include <X11/cursorfont.h>#include <X11/Intrinsic.h>#include <X11/StringDefs.h>#include <X11/Composite.h>#include <X11/Shell.h>#include <X11/Xaw/Form.h>#include <X11/Xaw/Command.h>#include <X11/Xaw/Scrollbar.h>#include <X11/Xaw/Label.h>#include <X11/Xaw/Cardinals.h>#include "SFinternal.h"#ifndef MAXPATHLEN#define MAXPATHLEN 1024#endif /* ndef MAXPATHLEN */#include "SFDecls.h"#if !defined (SVR4) && !defined (SYSV) && !defined (USG)extern char *getwd (char *);#endif /* !defined (SVR4) && !defined (SYSV) && !defined (USG) */#ifdef HAVE_STDLIB_H# include <stdlib.h>#endif#ifdef HAVE_STDINT_H#include <stdint.h>#endif#ifdef HAVE_INTTYPES_H#include <inttypes.h>#endif#ifdef HAVE_INTPTR_T#define INT2PTR(t,v) ((t)(intptr_t)(v))#define PTR2INT(v) ((Sflong_t)(intptr_t)(v))#else#define INT2PTR(t,v) ((t)(v))#define PTR2INT(v) ((Sflong_t)(v))#endifint SFstatus = SEL_FILE_NULL;char SFstartDir[MAXPATHLEN], SFcurrentPath[MAXPATHLEN];char SFcurrentDir[MAXPATHLEN];Widget selFile, selFileCancel, selFileField, selFileForm, selFileHScroll;Widget selFileHScrolls[3], selFileLists[3], selFileOK, selFilePrompt;Widget selFileVScrolls[3];Display *SFdisplay;Pixel SFfore, SFback;Atom SFwmDeleteWindow;XSegment SFsegs[2], SFcompletionSegs[2];XawTextPosition SFtextPos;int SFupperX, SFlowerY, SFupperY;int SFtextX, SFtextYoffset;int SFentryWidth, SFentryHeight;int SFlineToTextH = 3;int SFlineToTextV = 3;int SFbesideText = 3;int SFaboveAndBelowText = 2;int SFcharsPerEntry = 15;int SFlistSize = 10;int SFworkProcAdded = 0;XtWorkProcId SFworkProcId;XtAppContext SFapp;int SFpathScrollWidth, SFvScrollHeight, SFhScrollWidth;char SFtextBuffer[MAXPATHLEN];XtIntervalId SFdirModTimerId;int (*SFfunc) (char *, char **, struct stat *);static char *oneLineTextEditTranslations = "\ <Key>Return: redraw-display()\n\ Ctrl<Key>M: redraw-display()\n\";static void SFexposeList (Widget w, XtPointer n, XEvent *event, Boolean *cont) { if ((event->type == NoExpose) || event->xexpose.count) { return; } SFdrawList ((intptr_t) n, SF_DO_NOT_SCROLL);}static void SFmodVerifyCallback ( Widget w, XtPointer client_data, XEvent *event, Boolean *cont) { char buf[2]; if ( XLookupString (&event->xkey, buf, 2, NULL, NULL) == 1 && *buf == '\r' ) { SFstatus = SEL_FILE_OK; } else { SFstatus = SEL_FILE_TEXT; }}static void SFokCallback (Widget w, XtPointer cl, XtPointer cd) { SFstatus = SEL_FILE_OK;}static XtCallbackRec SFokSelect[] = { { SFokCallback, (XtPointer) NULL }, { NULL, (XtPointer) NULL },};static void SFcancelCallback (Widget w, XtPointer cl, XtPointer cd) { SFstatus = SEL_FILE_CANCEL;}static XtCallbackRec SFcancelSelect[] = { { SFcancelCallback, (XtPointer) NULL }, { NULL, (XtPointer) NULL },};static void SFdismissAction ( Widget w, XEvent *event, String *params, Cardinal *num_params) { if ( event->type == ClientMessage && event->xclient.data.l[0] != SFwmDeleteWindow ) return; SFstatus = SEL_FILE_CANCEL;}static char *wmDeleteWindowTranslation = "\ <Message>WM_PROTOCOLS: SelFileDismiss()\n\";static XtActionsRec actions[] = { { "SelFileDismiss", SFdismissAction },};static void SFcreateWidgets ( Widget toplevel, char *prompt, char *ok, char *cancel) { Cardinal i; intptr_t n; int listWidth, listHeight; int listSpacing = 10; int scrollThickness = 15; int hScrollX, hScrollY; int vScrollX, vScrollY; Cursor xtermCursor, sbRightArrowCursor, dotCursor; Arg arglist[20]; i = 0; XtSetArg (arglist[i], XtNtransientFor, toplevel); i++; selFile = XtAppCreateShell ( "selFile", "SelFile", transientShellWidgetClass, SFdisplay, arglist, i ); /* Add WM_DELETE_WINDOW protocol */ XtAppAddActions ( XtWidgetToApplicationContext (selFile), actions, XtNumber (actions) ); XtOverrideTranslations ( selFile, XtParseTranslationTable (wmDeleteWindowTranslation) ); i = 0; XtSetArg (arglist[i], XtNdefaultDistance, 30); i++; selFileForm = XtCreateManagedWidget ( "selFileForm", formWidgetClass, selFile, arglist, i ); i = 0; XtSetArg (arglist[i], XtNlabel, prompt); i++; XtSetArg (arglist[i], XtNresizable, True); i++; XtSetArg (arglist[i], XtNtop, XtChainTop); i++; XtSetArg (arglist[i], XtNbottom, XtChainTop); i++; XtSetArg (arglist[i], XtNleft, XtChainLeft); i++; XtSetArg (arglist[i], XtNright, XtChainLeft); i++; XtSetArg (arglist[i], XtNborderWidth, 0); i++; selFilePrompt = XtCreateManagedWidget ( "selFilePrompt", labelWidgetClass, selFileForm, arglist, i ); i = 0; XtSetArg (arglist[i], XtNforeground, &SFfore); i++; XtSetArg (arglist[i], XtNbackground, &SFback); i++; XtGetValues (selFilePrompt, arglist, i); SFinitFont (); SFentryWidth = SFbesideText + SFcharsPerEntry * SFcharWidth + SFbesideText; SFentryHeight = SFaboveAndBelowText + SFcharHeight + SFaboveAndBelowText; listWidth = ( SFlineToTextH + SFentryWidth + SFlineToTextH + 1 + scrollThickness ); listHeight = ( SFlineToTextV + SFentryHeight + SFlineToTextV + 1 + SFlineToTextV + SFlistSize * SFentryHeight + SFlineToTextV + 1 + scrollThickness ); SFpathScrollWidth = 3 * listWidth + 2 * listSpacing + 4; hScrollX = -1; hScrollY = ( SFlineToTextV + SFentryHeight + SFlineToTextV + 1 + SFlineToTextV + SFlistSize * SFentryHeight + SFlineToTextV ); SFhScrollWidth = SFlineToTextH + SFentryWidth + SFlineToTextH; vScrollX = SFlineToTextH + SFentryWidth + SFlineToTextH; vScrollY = SFlineToTextV + SFentryHeight + SFlineToTextV; SFvScrollHeight = ( SFlineToTextV + SFlistSize * SFentryHeight + SFlineToTextV ); SFupperX = SFlineToTextH + SFentryWidth + SFlineToTextH - 1; SFlowerY = ( SFlineToTextV + SFentryHeight + SFlineToTextV + 1 + SFlineToTextV ); SFupperY = ( SFlineToTextV + SFentryHeight + SFlineToTextV + 1 + SFlineToTextV + SFlistSize * SFentryHeight - 1 ); SFtextX = SFlineToTextH + SFbesideText; SFtextYoffset = SFlowerY + SFaboveAndBelowText + SFcharAscent; SFsegs[0].x1 = 0; SFsegs[0].y1 = vScrollY; SFsegs[0].x2 = vScrollX - 1; SFsegs[0].y2 = vScrollY; SFsegs[1].x1 = vScrollX; SFsegs[1].y1 = 0; SFsegs[1].x2 = vScrollX; SFsegs[1].y2 = vScrollY - 1; SFcompletionSegs[0].x1 = SFcompletionSegs[0].x2 = SFlineToTextH; SFcompletionSegs[1].x1 = SFcompletionSegs[1].x2 = ( SFlineToTextH + SFentryWidth - 1 ); i = 0; XtSetArg (arglist[i], XtNwidth, 3 * listWidth + 2 * listSpacing + 4); i++; XtSetArg (arglist[i], XtNborderColor, SFfore); i++; XtSetArg (arglist[i], XtNfromVert, selFilePrompt); i++; XtSetArg (arglist[i], XtNvertDistance, 10); i++; XtSetArg (arglist[i], XtNresizable, True); i++; XtSetArg (arglist[i], XtNtop, XtChainTop); i++; XtSetArg (arglist[i], XtNbottom, XtChainTop); i++; XtSetArg (arglist[i], XtNleft, XtChainLeft); i++; XtSetArg (arglist[i], XtNright, XtChainLeft); i++; XtSetArg (arglist[i], XtNstring, SFtextBuffer); i++; XtSetArg (arglist[i], XtNlength, MAXPATHLEN); i++; XtSetArg (arglist[i], XtNeditType, XawtextEdit); i++; XtSetArg (arglist[i], XtNwrap, XawtextWrapWord); i++; XtSetArg (arglist[i], XtNresize, XawtextResizeHeight); i++; XtSetArg (arglist[i], XtNuseStringInPlace, True); i++; selFileField = XtCreateManagedWidget ( "selFileField", asciiTextWidgetClass, selFileForm, arglist, i ); XtOverrideTranslations ( selFileField, XtParseTranslationTable (oneLineTextEditTranslations) ); XtSetKeyboardFocus (selFileForm, selFileField); i = 0; XtSetArg (arglist[i], XtNorientation, XtorientHorizontal); i++; XtSetArg (arglist[i], XtNwidth, SFpathScrollWidth); i++; XtSetArg (arglist[i], XtNheight, scrollThickness); i++; XtSetArg (arglist[i], XtNborderColor, SFfore); i++; XtSetArg (arglist[i], XtNfromVert, selFileField); i++; XtSetArg (arglist[i], XtNvertDistance, 30); i++; XtSetArg (arglist[i], XtNtop, XtChainTop); i++; XtSetArg (arglist[i], XtNbottom, XtChainTop); i++; XtSetArg (arglist[i], XtNleft, XtChainLeft); i++; XtSetArg (arglist[i], XtNright, XtChainLeft); i++; selFileHScroll = XtCreateManagedWidget ( "selFileHScroll", scrollbarWidgetClass, selFileForm, arglist, i ); XtAddCallback ( selFileHScroll, XtNjumpProc, SFpathSliderMovedCallback, (XtPointer) NULL ); XtAddCallback ( selFileHScroll, XtNscrollProc, SFpathAreaSelectedCallback,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -