123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201 |
- program DemoEditor;
- {$mode fpc}
- uses
- {$ifdef UNIX}cwstring,{$endif}Objects,fvconsts,
- //Drivers, Views, Menus, StdDlg, App, Editors,Msgbox{$ifdef unix},fvclip { OSC 52 support unit } {$endif},FVCommon;
- uDrivers, uViews, uMenus, uStdDlg, uApp, uEditors,uMsgbox{$ifdef unix},ufvclip { OSC 52 support unit } {$endif},uFVCommon;
- const
- cmShowClip = 102;
- cmCopyWin = 240;
- cmPasteWin = 241;
- type
- PEditorApp = ^TEditorApp;
- TEditorApp = object(TApplication)
- constructor Init;
- procedure HandleEvent(var Event: TEvent); virtual;
- procedure InitMenuBar; virtual;
- procedure InitStatusLine; virtual;
- end;
- PMyEditWindow = ^TMyEditWindow;
- TMyEditWindow = object(TEditWindow)
- procedure HandleEvent(var Event: TEvent); virtual;
- end;
- var
- EditorApp: TEditorApp;
- ClipWindow: PEditWindow;
- function OpenEditor(FileName: FNameStr; Visible: Boolean): PEditWindow;
- var
- P: PWindow;
- R: TRect;
- begin
- DeskTop^.GetExtent(R);
- P := New(PMyEditWindow, Init(R, FileName, wnNoNumber));
- if not Visible then P^.Hide;
- OpenEditor := PEditWindow(Application^.InsertWindow(P));
- end;
- procedure TMyEditWindow.HandleEvent(var Event: TEvent);
- procedure ClipCopyWin;
- var p : pointer;
- begin
- {$ifdef unix}
- if Editor^.SelStart<>Editor^.SelEnd then { Text selected? }
- begin
- {This is where the magic happens. Parameters are PAnsiChar and Length of data to be copied to global clipboard}
- SetGlobalClipboardData( @Editor^.Buffer^[Editor^.BufPtr(Editor^.SelStart)], Editor^.SelEnd - Editor^.SelStart);
- end;
- {$else}
- MessageBox('Not implemented for this platform!', nil, mfInformation + mfOkButton);
- {$endif}
- end;
- procedure ClipPasteWin;
- begin
- {$ifdef unix}
- GetGlobalClipboardData; {Request data from global Clipboard. That's it}
- {$else}
- MessageBox('Not implemented for this platform!', nil, mfInformation + mfOkButton);
- {$endif}
- end;
- begin
- inherited HandleEvent(Event);
- case Event.What of
- evCommand:
- case Event.Command of
- cmCopyWin : ClipCopyWin;
- cmPasteWin : ClipPasteWin;
- else
- Exit;
- end;
- else
- Exit;
- end;
- ClearEvent(Event);
- end;
- constructor TEditorApp.Init;
- var
- H: Word;
- R: TRect;
- begin
- inherited Init;
- DisableCommands([cmSave, cmSaveAs, cmCut, cmCopy, cmPaste,
- {cmCopyWin, cmPasteWin,}
- cmClear, cmUndo, cmFind, cmReplace, cmSearchAgain]);
- EditorDialog := @StdEditorDialog;
- ClipWindow := OpenEditor('', False);
- if ClipWindow <> nil then
- begin
- Clipboard := ClipWindow^.Editor;
- Clipboard^.CanUndo := False;
- end;
- end;
- procedure TEditorApp.HandleEvent(var Event: TEvent);
- procedure FileOpen;
- var
- FileName: FNameStr;
- begin
- FileName := '*.*';
- if ExecuteDialog(New(PFileDialog, Init('*.*', 'Open file',
- '~N~ame', fdOpenButton, 100)), @FileName) <> cmCancel then
- OpenEditor(FileName, True);
- end;
- procedure FileNew;
- begin
- OpenEditor('', True);
- end;
- procedure ChangeDir;
- begin
- ExecuteDialog(New(PChDirDialog, Init(cdNormal, 0)), nil);
- end;
- procedure ShowClip;
- begin
- ClipWindow^.Select;
- ClipWindow^.Show;
- end;
- begin
- inherited HandleEvent(Event);
- case Event.What of
- evCommand:
- case Event.Command of
- cmOpen: FileOpen;
- cmNew: FileNew;
- cmChangeDir : ChangeDir;
- cmShowClip : ShowClip;
- else
- Exit;
- end;
- else
- Exit;
- end;
- ClearEvent(Event);
- end;
- procedure TEditorApp.InitMenuBar;
- var
- R: TRect;
- begin
- GetExtent(R);
- R.B.Y := R.A.Y + 1;
- MenuBar := New(PMenuBar, Init(R, NewMenu(
- NewSubMenu('~F~ile', hcNoContext, NewMenu(
- StdFileMenuItems(
- nil)),
- NewSubMenu('~E~dit', hcNoContext, NewMenu(
- StdEditMenuItems(
- NewLine(
- NewItem('~S~hwo clipboard', '', kbNoKey, cmShowClip, hcNoContext,
- NewLine(
- NewItem('Cop~y~ to Windows', '', kbNoKey, cmCopyWin, hcNoContext,
- NewItem('Paste from ~W~indows', '', kbNoKey, cmPasteWin, hcNoContext,
- nil))))))),
- NewSubMenu('~S~earch', hcNoContext, NewMenu(
- NewItem('~F~ind...', '', kbNoKey, cmFind, hcNoContext,
- NewItem('~R~eplace...', '', kbNoKey, cmReplace, hcNoContext,
- NewItem('~S~earch again', '', kbNoKey, cmSearchAgain, hcNoContext,
- nil)))),
- NewSubMenu('~W~indows', hcNoContext, NewMenu(
- StdWindowMenuItems(
- nil)),
- nil)))))));
- end;
- procedure TEditorApp.InitStatusLine;
- var
- R: TRect;
- begin
- GetExtent(R);
- R.A.Y := R.B.Y - 1;
- New(StatusLine, Init(R,
- NewStatusDef(0, $FFFF,
- NewStatusKey('~F2~ Save', kbF2, cmSave,
- NewStatusKey('~F3~ Open', kbF3, cmOpen,
- NewStatusKey('~Alt-F3~ Close', kbAltF3, cmClose,
- NewStatusKey('~F5~ Zoom', kbF5, cmZoom,
- NewStatusKey('~F6~ Next', kbF6, cmNext,
- NewStatusKey('~F10~ Menu', kbF10, cmMenu,
- NewStatusKey('', kbCtrlF5, cmResize,
- nil))))))),
- nil)));
- end;
- begin
- EditorApp.Init;
- EditorApp.Run;
- EditorApp.Done;
- end.
|