|
|
@@ -1,16 +1,42 @@
|
|
|
+{ This example is part of FPC Free Vision package.
|
|
|
+
|
|
|
+ Program demonstrates Editor use in your Free Vision Application
|
|
|
+ and manual clipboard manipulations.
|
|
|
+
|
|
|
+ To have clipboard functionally all you have to do is to add Editor
|
|
|
+ (TFileEditor) to Clipboard. By default Free Vision will try to use your OS
|
|
|
+ clipboard as long there is one and as long it is supported by Free Vision.
|
|
|
+ Otherwise it will fall back to local clipboard. Use of local clipboard can
|
|
|
+ be triggered manually if desired. As well OS clipboard can be used directly
|
|
|
+ via FVClip unit.
|
|
|
+
|
|
|
+ Note. On Unix/Linux systems Free Vision uses OSC 52 clipboard and bracketed
|
|
|
+ paste. It is assumed that OSC 52 clipboard is available. While real
|
|
|
+ availability depends on particular terminal in use and particular
|
|
|
+ configuration of it.
|
|
|
+}
|
|
|
program DemoEditor;
|
|
|
{$mode fpc}
|
|
|
|
|
|
+{ Have FV_UNICODE defined to compile and run with Free Vision Unicode version,
|
|
|
+ otherwise single byte code page ShortString Free Vision version will be used }
|
|
|
+{$define FV_UNICODE}
|
|
|
+
|
|
|
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;
|
|
|
+{$ifdef FV_UNICODE}
|
|
|
+ uDrivers, uViews, uMenus, uStdDlg, uApp, uEditors,uMsgbox,ufvclip,uFVCommon;
|
|
|
+{$else}
|
|
|
+ Drivers, Views, Menus, StdDlg, App, Editors,Msgbox,fvclip,FVCommon;
|
|
|
+{$endif}
|
|
|
|
|
|
|
|
|
const
|
|
|
cmShowClip = 102;
|
|
|
cmCopyWin = 240;
|
|
|
cmPasteWin = 241;
|
|
|
+ cmLocalClip = 242;
|
|
|
+ cmOSClip = 243;
|
|
|
|
|
|
type
|
|
|
PEditorApp = ^TEditorApp;
|
|
|
@@ -46,24 +72,21 @@ 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}
|
|
|
+ { This is where the magic happens. Parameters are PAnsiChar and Length of data to be copied to OS clipboard }
|
|
|
+ SetTextWinClipboardData( @Editor^.Buffer^[Editor^.BufPtr(Editor^.SelStart)], Editor^.SelEnd - Editor^.SelStart);
|
|
|
end;
|
|
|
|
|
|
procedure ClipPasteWin;
|
|
|
+var P : PAnsiChar; Len: Longint;
|
|
|
begin
|
|
|
-{$ifdef unix}
|
|
|
- GetGlobalClipboardData; {Request data from global Clipboard. That's it}
|
|
|
-{$else}
|
|
|
- MessageBox('Not implemented for this platform!', nil, mfInformation + mfOkButton);
|
|
|
-{$endif}
|
|
|
+ { Get OS clipboard data }
|
|
|
+ if GetTextWinClipboardData (P, Len) then
|
|
|
+ if assigned(P) then
|
|
|
+ begin
|
|
|
+ Editor^.InsertText (P, Len, False); { On success insert into Editor window }
|
|
|
+ FreeMem(P); { Our responsibility to free memory }
|
|
|
+ end;
|
|
|
end;
|
|
|
|
|
|
begin
|
|
|
@@ -73,6 +96,13 @@ begin
|
|
|
case Event.Command of
|
|
|
cmCopyWin : ClipCopyWin;
|
|
|
cmPasteWin : ClipPasteWin;
|
|
|
+ { Information. cmPasteText is triggered by Bracketed paste and
|
|
|
+ OSC 52 paste. It is necessary handle cmPasteText event only for
|
|
|
+ your own Views that are not descendants of TInputLine or TEditro.
|
|
|
+ cmPasteText is not part of legacy Turbo Vision v2.0.
|
|
|
+ Here Event.Id holds length of data in Event.InfoPtr PAnsiChar.
|
|
|
+ cmPasteText : Editor^.InsertText(Event.InfoPtr,Event.Id,false);
|
|
|
+ }
|
|
|
else
|
|
|
Exit;
|
|
|
end;
|
|
|
@@ -89,14 +119,16 @@ var
|
|
|
begin
|
|
|
inherited Init;
|
|
|
DisableCommands([cmSave, cmSaveAs, cmCut, cmCopy, cmPaste,
|
|
|
- {cmCopyWin, cmPasteWin,}
|
|
|
cmClear, cmUndo, cmFind, cmReplace, cmSearchAgain]);
|
|
|
+ if not WinClipboardSupported then
|
|
|
+ DisableCommands([cmCopyWin, cmPasteWin, cmOSClip]);
|
|
|
EditorDialog := @StdEditorDialog;
|
|
|
ClipWindow := OpenEditor('', False);
|
|
|
if ClipWindow <> nil then
|
|
|
begin
|
|
|
+ { Add Editor to Clipboard and by that clipboard functionality is enabled }
|
|
|
Clipboard := ClipWindow^.Editor;
|
|
|
- Clipboard^.CanUndo := False;
|
|
|
+ Clipboard^.CanUndo := False; { No Undo for clipboard }
|
|
|
end;
|
|
|
end;
|
|
|
|
|
|
@@ -137,6 +169,16 @@ begin
|
|
|
cmNew: FileNew;
|
|
|
cmChangeDir : ChangeDir;
|
|
|
cmShowClip : ShowClip;
|
|
|
+ cmLocalClip :
|
|
|
+ begin
|
|
|
+ SetGlobalClipboard( False );
|
|
|
+ MessageBox('Set to use local clipboard!', nil, mfInformation + mfOkButton);
|
|
|
+ end;
|
|
|
+ cmOSClip :
|
|
|
+ begin
|
|
|
+ SetGlobalClipboard( True );
|
|
|
+ MessageBox('Set to use OS clipboard!', nil, mfInformation + mfOkButton);
|
|
|
+ end;
|
|
|
else
|
|
|
Exit;
|
|
|
end;
|
|
|
@@ -161,9 +203,12 @@ begin
|
|
|
NewLine(
|
|
|
NewItem('~S~hwo clipboard', '', kbNoKey, cmShowClip, hcNoContext,
|
|
|
NewLine(
|
|
|
+ NewItem('Use ~l~ocal clipboard', '', kbNoKey, cmLocalClip, hcNoContext,
|
|
|
+ NewItem('Use ~O~S clipboard', '', kbNoKey, cmOSClip, hcNoContext,
|
|
|
+ NewLine(
|
|
|
NewItem('Cop~y~ to Windows', '', kbNoKey, cmCopyWin, hcNoContext,
|
|
|
NewItem('Paste from ~W~indows', '', kbNoKey, cmPasteWin, hcNoContext,
|
|
|
- nil))))))),
|
|
|
+ nil)))))))))),
|
|
|
NewSubMenu('~S~earch', hcNoContext, NewMenu(
|
|
|
NewItem('~F~ind...', '', kbNoKey, cmFind, hcNoContext,
|
|
|
NewItem('~R~eplace...', '', kbNoKey, cmReplace, hcNoContext,
|