home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / library / dos / tvision / gravis / gv / gvedit.int < prev    next >
Encoding:
Text File  |  1994-05-23  |  8.7 KB  |  324 lines

  1. unit GVEdit;
  2.  
  3.  
  4. interface
  5.  
  6. uses Drivers, GVDriver, Objects, Views, GVViews, GVDialog;
  7.  
  8. const
  9.   cmFind        = 82;
  10.   cmReplace     = 83;
  11.   cmSearchAgain = 84;
  12.  
  13. const
  14.   cmCharLeft    = 500;
  15.   cmCharRight   = 501;
  16.   cmWordLeft    = 502;
  17.   cmWordRight   = 503;
  18.   cmLineStart   = 504;
  19.   cmLineEnd     = 505;
  20.   cmLineUp      = 506;
  21.   cmLineDown    = 507;
  22.   cmPageUp      = 508;
  23.   cmPageDown    = 509;
  24.   cmTextStart   = 510;
  25.   cmTextEnd     = 511;
  26.   cmNewLine     = 512;
  27.   cmBackSpace   = 513;
  28.   cmDelChar     = 514;
  29.   cmDelWord     = 515;
  30.   cmDelStart    = 516;
  31.   cmDelEnd      = 517;
  32.   cmDelLine     = 518;
  33.   cmInsMode     = 519;
  34.   cmStartSelect = 520;
  35.   cmHideSelect  = 521;
  36.   cmIndentMode  = 522;
  37.   cmUpdateTitle = 523;
  38.  
  39. const
  40.   edOutOfMemory   = 0;
  41.   edReadError     = 1;
  42.   edWriteError    = 2;
  43.   edCreateError   = 3;
  44.   edSaveModify    = 4;
  45.   edSaveUntitled  = 5;
  46.   edSaveAs        = 6;
  47.   edFind          = 7;
  48.   edSearchFailed  = 8;
  49.   edReplace       = 9;
  50.   edReplacePrompt = 10;
  51.  
  52. const
  53.   efCaseSensitive   = $0001;
  54.   efWholeWordsOnly  = $0002;
  55.   efPromptOnReplace = $0004;
  56.   efReplaceAll      = $0008;
  57.   efDoReplace       = $0010;
  58.   efBackupFiles     = $0100;
  59.  
  60. const
  61.   CIndicator = #1#8;
  62.   CEditor    = #19#20#21#22;
  63.  
  64. const
  65.   MaxLineLength = 254;
  66.  
  67. type
  68.  
  69.   TEditorDialog = function(Dialog: Integer; Info: Pointer): Word;
  70.  
  71. { TIndicator object }
  72.  
  73.   { Palette layout }
  74.   { 1 = background }
  75.   { 2 = text }
  76.  
  77.   PIndicator = ^TIndicator;
  78.   TIndicator = object(TGView)
  79.     Location: TPoint;
  80.     Modified: Boolean;
  81.     constructor Init(var Bounds: TRect);
  82.     procedure Draw; virtual;
  83.     function GetPalette: PPalette; virtual;
  84.     procedure SetState(AState: Word; Enable: Boolean); virtual;
  85.     procedure SetValue(ALocation: TPoint; AModified: Boolean);
  86.   end;
  87.  
  88. { TEditBuffer array }
  89.  
  90.   PEditBuffer = ^TEditBuffer;
  91.   TEditBuffer = array[0..65519] of Char;
  92.  
  93. { TEditor object }
  94.  
  95.   { Palette layout }
  96.   { 1 = Normal text }
  97.   { 2 = Selected text }
  98.   { 3 = Normal background }
  99.   { 4 = Selected background }
  100.  
  101.   PEditor = ^TEditor;
  102.   TEditor = object(TGView)
  103.     HScrollBar: PScrollBar;
  104.     VScrollBar: PScrollBar;
  105.     Indicator: PIndicator;
  106.     Buffer: PEditBuffer;
  107.     BufSize: Word;
  108.     BufLen: Word;
  109.     GapLen: Word;
  110.     SelStart: Word;
  111.     SelEnd: Word;
  112.     CurPtr: Word;
  113.     CurPos: TPoint;
  114.     Delta: TPoint;
  115.     Limit: TPoint;
  116.     TextSize: TPoint;
  117.     DrawLine: Integer;
  118.     DrawPtr: Word;
  119.     DelCount: Word;
  120.     InsCount: Word;
  121.     IsValid: Boolean;
  122.     CanUndo: Boolean;
  123.     Modified: Boolean;
  124.     Selecting: Boolean;
  125.     Overwrite: Boolean;
  126.     AutoIndent: Boolean;
  127.     constructor Init(var Bounds: TRect;
  128.       AHScrollBar, AVScrollBar: PScrollBar;
  129.       AIndicator: PIndicator; ABufSize: Word);
  130.     constructor Load(var S: TStream);
  131.     destructor Done; virtual;
  132.     function BufChar(P: Word): Char;
  133.     function BufPtr(P: Word): Word;
  134.     procedure ChangeBounds(var Bounds: TRect); virtual;
  135.     procedure ConvertEvent(var Event: TEvent); virtual;
  136.     function CursorVisible: Boolean;
  137.     procedure DeleteSelect;
  138.     procedure DoneBuffer; virtual;
  139.     procedure Draw; virtual;
  140.     function GetPalette: PPalette; virtual;
  141.     procedure HandleEvent(var Event: TEvent); virtual;
  142.     procedure InitBuffer; virtual;
  143.     function InsertBuffer(var P: PEditBuffer; Offset, Length: Word;
  144.       AllowUndo, SelectText: Boolean): Boolean;
  145.     function InsertFrom(Editor: PEditor): Boolean; virtual;
  146.     function InsertText(Text: Pointer; Length: Word;
  147.       SelectText: Boolean): Boolean;
  148.     procedure ScrollTo(X, Y: Integer);
  149.     function Search(FindStr: String; Opts: Word): Boolean;
  150.     function SetBufSize(NewSize: Word): Boolean; virtual;
  151.     procedure SetCmdState(Command: Word; Enable: Boolean);
  152.     procedure SetSelect(NewStart, NewEnd: Word; CurStart: Boolean);
  153.     procedure SetState(AState: Word; Enable: Boolean); virtual;
  154.     procedure Store(var S: TStream);
  155.     procedure TrackCursor(Center: Boolean);
  156.     procedure Undo;
  157.     procedure UpdateCommands; virtual;
  158.     function Valid(Command: Word): Boolean; virtual;
  159.   private
  160.     OldClip: TRect;
  161.     Temp: TPoint;
  162.     LockCount: Byte;
  163.     UpdateFlags: Byte;
  164.     KeyState: Integer;
  165.     LineAnz, StartLn, AddLine: Integer;
  166.     function CharPos(P, Target: Word): Integer;
  167.     function CharPtr(P: Word; Target: Integer): Word;
  168.     function ClipCopy: Boolean;
  169.     procedure ClipCut;
  170.     procedure ClipPaste;
  171.     procedure DeleteRange(StartPtr, EndPtr: Word; DelSelect: Boolean);
  172.     procedure DoUpdate;
  173.     procedure DoSearchReplace;
  174.     procedure DrawLines(Y, Count: Integer; LinePtr: Word);
  175.     procedure FormatLine(var S: String; LinePtr: Word;
  176.       Width: Integer);
  177.     procedure Find;
  178.     function GetMousePtr(Mouse: TPoint): Word;
  179.     function HasSelection: Boolean;
  180.     procedure HideSelect;
  181.     function IsClipboard: Boolean;
  182.     function LineEnd(P: Word): Word;
  183.     function LineMove(P: Word; Count: Integer): Word;
  184.     function LineStart(P: Word): Word;
  185.     procedure Lock;
  186.     procedure NewLine;
  187.     function NextChar(P: Word): Word;
  188.     function NextLine(P: Word): Word;
  189.     function NextWord(P: Word): Word;
  190.     function PrevChar(P: Word): Word;
  191.     function PrevLine(P: Word): Word;
  192.     function PrevWord(P: Word): Word;
  193.     procedure Replace;
  194.     procedure SetBufLen(Length: Word);
  195.     procedure SetCurPtr(P: Word; SelectMode: Byte);
  196.     procedure StartSelect;
  197.     procedure ToggleInsMode;
  198.     procedure Unlock;
  199.     procedure Update(AFlags: Byte);
  200.   end;
  201.  
  202. { TMemoData record }
  203.  
  204.   TMemoData = record
  205.     Length: Word;
  206.     Buffer: TEditBuffer;
  207.   end;
  208.  
  209. { TMemo object }
  210.  
  211.   { Palette layout = TEditor }
  212.  
  213.   PMemo = ^TMemo;
  214.   TMemo = object(TEditor)
  215.     constructor Load(var S: TStream);
  216.     function DataSize: Word; virtual;
  217.     procedure GetData(var Rec); virtual;
  218.     procedure HandleEvent(var Event: TEvent); virtual;
  219.     procedure SetData(var Rec); virtual;
  220.     procedure Store(var S: TStream);
  221.   end;
  222.  
  223. { TFileEditor object }
  224.  
  225.   { Palette layout = TEditor }
  226.  
  227.   PFileEditor = ^TFileEditor;
  228.   TFileEditor = object(TEditor)
  229.     FileName: FNameStr;
  230.     constructor Init(var Bounds: TRect;
  231.       AHScrollBar, AVScrollBar: PScrollBar;
  232.       AIndicator: PIndicator; AFileName: FNameStr);
  233.     constructor Load(var S: TStream);
  234.     procedure DoneBuffer; virtual;
  235.     procedure HandleEvent(var Event: TEvent); virtual;
  236.     procedure InitBuffer; virtual;
  237.     function LoadFile: Boolean;
  238.     function Save: Boolean;
  239.     function SaveAs: Boolean;
  240.     function SaveFile: Boolean;
  241.     function SetBufSize(NewSize: Word): Boolean; virtual;
  242.     procedure Store(var S: TStream);
  243.     procedure UpdateCommands; virtual;
  244.     function Valid(Command: Word): Boolean; virtual;
  245.   end;
  246.  
  247. { TEditWindow object }
  248.  
  249.   { Palette layout = TWindow }
  250.  
  251.   PEditWindow = ^TEditWindow;
  252.   TEditWindow = object(TWindow)
  253.     Editor: PFileEditor;
  254.     constructor Init(var Bounds: TRect; FileName: FNameStr);
  255.     constructor Load(var S: TStream);
  256.     procedure Close; virtual;
  257.     function GetTitle(MaxSize: Integer): TTitleStr; virtual;
  258.     procedure HandleEvent(var Event: TEvent); virtual;
  259.     procedure SizeLimits(var Min, Max: TPoint); virtual;
  260.     procedure Store(var S: TStream);
  261.   end;
  262.  
  263. function DefEditorDialog(Dialog: Integer; Info: Pointer): Word;
  264. function CreateFindDialog: PDialog;
  265. function CreateReplaceDialog: PDialog;
  266. function StdEditorDialog(Dialog: Integer; Info: Pointer): Word;
  267.  
  268. const
  269.   WordChars: set of Char = ['0'..'9', 'A'..'Z', '_', 'a'..'z'];
  270.   EditorDialog: TEditorDialog = DefEditorDialog;
  271.   EditorFlags: Word = efBackupFiles + efPromptOnReplace;
  272.   FindStr: String[80] = '';
  273.   ReplaceStr: String[80] = '';
  274.   Clipboard: PEditor = nil;
  275.  
  276. type
  277.   TFindDialogRec = record
  278.     Find: String[80];
  279.     Options: LongInt;
  280.   end;
  281.  
  282. type
  283.   TReplaceDialogRec = record
  284.     Find: String[80];
  285.     Replace: String[80];
  286.     Options: LongInt;
  287.   end;
  288.  
  289. const
  290.   REditor: TStreamRec = (
  291.     ObjType: 70;
  292.     VmtLink: Ofs(TypeOf(TEditor)^);
  293.     Load: @TEditor.Load;
  294.     Store: @TEditor.Store
  295.   );
  296.   RMemo: TStreamRec = (
  297.     ObjType: 71;
  298.     VmtLink: Ofs(TypeOf(TMemo)^);
  299.     Load: @TMemo.Load;
  300.     Store: @TMemo.Store
  301.   );
  302.   RFileEditor: TStreamRec = (
  303.     ObjType: 72;
  304.     VmtLink: Ofs(TypeOf(TFileEditor)^);
  305.     Load: @TFileEditor.Load;
  306.     Store: @TFileEditor.Store
  307.   );
  308.   RIndicator: TStreamRec = (
  309.     ObjType: 73;
  310.     VmtLink: Ofs(TypeOf(TIndicator)^);
  311.     Load: @TIndicator.Load;
  312.     Store: @TIndicator.Store
  313.   );
  314.   REditWindow: TStreamRec = (
  315.     ObjType: 74;
  316.     VmtLink: Ofs(TypeOf(TEditWindow)^);
  317.     Load: @TEditWindow.Load;
  318.     Store: @TEditWindow.Store
  319.   );
  320.  
  321. procedure RegisterEditors;
  322.  
  323. implementation
  324.