home *** CD-ROM | disk | FTP | other *** search
- unit GVEdit;
-
-
- interface
-
- uses Drivers, GVDriver, Objects, Views, GVViews, GVDialog;
-
- const
- cmFind = 82;
- cmReplace = 83;
- cmSearchAgain = 84;
-
- const
- cmCharLeft = 500;
- cmCharRight = 501;
- cmWordLeft = 502;
- cmWordRight = 503;
- cmLineStart = 504;
- cmLineEnd = 505;
- cmLineUp = 506;
- cmLineDown = 507;
- cmPageUp = 508;
- cmPageDown = 509;
- cmTextStart = 510;
- cmTextEnd = 511;
- cmNewLine = 512;
- cmBackSpace = 513;
- cmDelChar = 514;
- cmDelWord = 515;
- cmDelStart = 516;
- cmDelEnd = 517;
- cmDelLine = 518;
- cmInsMode = 519;
- cmStartSelect = 520;
- cmHideSelect = 521;
- cmIndentMode = 522;
- cmUpdateTitle = 523;
-
- const
- edOutOfMemory = 0;
- edReadError = 1;
- edWriteError = 2;
- edCreateError = 3;
- edSaveModify = 4;
- edSaveUntitled = 5;
- edSaveAs = 6;
- edFind = 7;
- edSearchFailed = 8;
- edReplace = 9;
- edReplacePrompt = 10;
-
- const
- efCaseSensitive = $0001;
- efWholeWordsOnly = $0002;
- efPromptOnReplace = $0004;
- efReplaceAll = $0008;
- efDoReplace = $0010;
- efBackupFiles = $0100;
-
- const
- CIndicator = #1#8;
- CEditor = #19#20#21#22;
-
- const
- MaxLineLength = 254;
-
- type
-
- TEditorDialog = function(Dialog: Integer; Info: Pointer): Word;
-
- { TIndicator object }
-
- { Palette layout }
- { 1 = background }
- { 2 = text }
-
- PIndicator = ^TIndicator;
- TIndicator = object(TGView)
- Location: TPoint;
- Modified: Boolean;
- constructor Init(var Bounds: TRect);
- procedure Draw; virtual;
- function GetPalette: PPalette; virtual;
- procedure SetState(AState: Word; Enable: Boolean); virtual;
- procedure SetValue(ALocation: TPoint; AModified: Boolean);
- end;
-
- { TEditBuffer array }
-
- PEditBuffer = ^TEditBuffer;
- TEditBuffer = array[0..65519] of Char;
-
- { TEditor object }
-
- { Palette layout }
- { 1 = Normal text }
- { 2 = Selected text }
- { 3 = Normal background }
- { 4 = Selected background }
-
- PEditor = ^TEditor;
- TEditor = object(TGView)
- HScrollBar: PScrollBar;
- VScrollBar: PScrollBar;
- Indicator: PIndicator;
- Buffer: PEditBuffer;
- BufSize: Word;
- BufLen: Word;
- GapLen: Word;
- SelStart: Word;
- SelEnd: Word;
- CurPtr: Word;
- CurPos: TPoint;
- Delta: TPoint;
- Limit: TPoint;
- TextSize: TPoint;
- DrawLine: Integer;
- DrawPtr: Word;
- DelCount: Word;
- InsCount: Word;
- IsValid: Boolean;
- CanUndo: Boolean;
- Modified: Boolean;
- Selecting: Boolean;
- Overwrite: Boolean;
- AutoIndent: Boolean;
- constructor Init(var Bounds: TRect;
- AHScrollBar, AVScrollBar: PScrollBar;
- AIndicator: PIndicator; ABufSize: Word);
- constructor Load(var S: TStream);
- destructor Done; virtual;
- function BufChar(P: Word): Char;
- function BufPtr(P: Word): Word;
- procedure ChangeBounds(var Bounds: TRect); virtual;
- procedure ConvertEvent(var Event: TEvent); virtual;
- function CursorVisible: Boolean;
- procedure DeleteSelect;
- procedure DoneBuffer; virtual;
- procedure Draw; virtual;
- function GetPalette: PPalette; virtual;
- procedure HandleEvent(var Event: TEvent); virtual;
- procedure InitBuffer; virtual;
- function InsertBuffer(var P: PEditBuffer; Offset, Length: Word;
- AllowUndo, SelectText: Boolean): Boolean;
- function InsertFrom(Editor: PEditor): Boolean; virtual;
- function InsertText(Text: Pointer; Length: Word;
- SelectText: Boolean): Boolean;
- procedure ScrollTo(X, Y: Integer);
- function Search(FindStr: String; Opts: Word): Boolean;
- function SetBufSize(NewSize: Word): Boolean; virtual;
- procedure SetCmdState(Command: Word; Enable: Boolean);
- procedure SetSelect(NewStart, NewEnd: Word; CurStart: Boolean);
- procedure SetState(AState: Word; Enable: Boolean); virtual;
- procedure Store(var S: TStream);
- procedure TrackCursor(Center: Boolean);
- procedure Undo;
- procedure UpdateCommands; virtual;
- function Valid(Command: Word): Boolean; virtual;
- private
- OldClip: TRect;
- Temp: TPoint;
- LockCount: Byte;
- UpdateFlags: Byte;
- KeyState: Integer;
- LineAnz, StartLn, AddLine: Integer;
- function CharPos(P, Target: Word): Integer;
- function CharPtr(P: Word; Target: Integer): Word;
- function ClipCopy: Boolean;
- procedure ClipCut;
- procedure ClipPaste;
- procedure DeleteRange(StartPtr, EndPtr: Word; DelSelect: Boolean);
- procedure DoUpdate;
- procedure DoSearchReplace;
- procedure DrawLines(Y, Count: Integer; LinePtr: Word);
- procedure FormatLine(var S: String; LinePtr: Word;
- Width: Integer);
- procedure Find;
- function GetMousePtr(Mouse: TPoint): Word;
- function HasSelection: Boolean;
- procedure HideSelect;
- function IsClipboard: Boolean;
- function LineEnd(P: Word): Word;
- function LineMove(P: Word; Count: Integer): Word;
- function LineStart(P: Word): Word;
- procedure Lock;
- procedure NewLine;
- function NextChar(P: Word): Word;
- function NextLine(P: Word): Word;
- function NextWord(P: Word): Word;
- function PrevChar(P: Word): Word;
- function PrevLine(P: Word): Word;
- function PrevWord(P: Word): Word;
- procedure Replace;
- procedure SetBufLen(Length: Word);
- procedure SetCurPtr(P: Word; SelectMode: Byte);
- procedure StartSelect;
- procedure ToggleInsMode;
- procedure Unlock;
- procedure Update(AFlags: Byte);
- end;
-
- { TMemoData record }
-
- TMemoData = record
- Length: Word;
- Buffer: TEditBuffer;
- end;
-
- { TMemo object }
-
- { Palette layout = TEditor }
-
- PMemo = ^TMemo;
- TMemo = object(TEditor)
- constructor Load(var S: TStream);
- function DataSize: Word; virtual;
- procedure GetData(var Rec); virtual;
- procedure HandleEvent(var Event: TEvent); virtual;
- procedure SetData(var Rec); virtual;
- procedure Store(var S: TStream);
- end;
-
- { TFileEditor object }
-
- { Palette layout = TEditor }
-
- PFileEditor = ^TFileEditor;
- TFileEditor = object(TEditor)
- FileName: FNameStr;
- constructor Init(var Bounds: TRect;
- AHScrollBar, AVScrollBar: PScrollBar;
- AIndicator: PIndicator; AFileName: FNameStr);
- constructor Load(var S: TStream);
- procedure DoneBuffer; virtual;
- procedure HandleEvent(var Event: TEvent); virtual;
- procedure InitBuffer; virtual;
- function LoadFile: Boolean;
- function Save: Boolean;
- function SaveAs: Boolean;
- function SaveFile: Boolean;
- function SetBufSize(NewSize: Word): Boolean; virtual;
- procedure Store(var S: TStream);
- procedure UpdateCommands; virtual;
- function Valid(Command: Word): Boolean; virtual;
- end;
-
- { TEditWindow object }
-
- { Palette layout = TWindow }
-
- PEditWindow = ^TEditWindow;
- TEditWindow = object(TWindow)
- Editor: PFileEditor;
- constructor Init(var Bounds: TRect; FileName: FNameStr);
- constructor Load(var S: TStream);
- procedure Close; virtual;
- function GetTitle(MaxSize: Integer): TTitleStr; virtual;
- procedure HandleEvent(var Event: TEvent); virtual;
- procedure SizeLimits(var Min, Max: TPoint); virtual;
- procedure Store(var S: TStream);
- end;
-
- function DefEditorDialog(Dialog: Integer; Info: Pointer): Word;
- function CreateFindDialog: PDialog;
- function CreateReplaceDialog: PDialog;
- function StdEditorDialog(Dialog: Integer; Info: Pointer): Word;
-
- const
- WordChars: set of Char = ['0'..'9', 'A'..'Z', '_', 'a'..'z'];
- EditorDialog: TEditorDialog = DefEditorDialog;
- EditorFlags: Word = efBackupFiles + efPromptOnReplace;
- FindStr: String[80] = '';
- ReplaceStr: String[80] = '';
- Clipboard: PEditor = nil;
-
- type
- TFindDialogRec = record
- Find: String[80];
- Options: LongInt;
- end;
-
- type
- TReplaceDialogRec = record
- Find: String[80];
- Replace: String[80];
- Options: LongInt;
- end;
-
- const
- REditor: TStreamRec = (
- ObjType: 70;
- VmtLink: Ofs(TypeOf(TEditor)^);
- Load: @TEditor.Load;
- Store: @TEditor.Store
- );
- RMemo: TStreamRec = (
- ObjType: 71;
- VmtLink: Ofs(TypeOf(TMemo)^);
- Load: @TMemo.Load;
- Store: @TMemo.Store
- );
- RFileEditor: TStreamRec = (
- ObjType: 72;
- VmtLink: Ofs(TypeOf(TFileEditor)^);
- Load: @TFileEditor.Load;
- Store: @TFileEditor.Store
- );
- RIndicator: TStreamRec = (
- ObjType: 73;
- VmtLink: Ofs(TypeOf(TIndicator)^);
- Load: @TIndicator.Load;
- Store: @TIndicator.Store
- );
- REditWindow: TStreamRec = (
- ObjType: 74;
- VmtLink: Ofs(TypeOf(TEditWindow)^);
- Load: @TEditWindow.Load;
- Store: @TEditWindow.Store
- );
-
- procedure RegisterEditors;
-
- implementation
-