Skip to content

Commit

Permalink
Manage the interruption of Copy and Cut operations from KNT when Clip…
Browse files Browse the repository at this point in the history
…Cap is active

We must call LogRTFHandleInClipboard from the very beginning of ClipCap detection, when internal ecCut or ecCopy operations have been interrupted
just after sending content to the clipboard, before they can do the call. We are using that handle to identify in several points if the Clipboard
content was copied by the application itself
It does not seem to have any impact on the ClipCap operation, beyond perhaps preventing some optimization of image processing.
But it seems coherent to ensure that it is called.
  • Loading branch information
dpradov committed Dec 24, 2023
1 parent 221ab64 commit e8ebc70
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 6 deletions.
24 changes: 24 additions & 0 deletions editor/kn_ClipUtils.pas
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ TClipboardHelper = class helper for TClipboard
function ClipboardContentWasCopiedByKNT: boolean;
function GetDropFiles(hDrop: THANDLE): TStringList;

procedure CopyToClipboard (Editor: TRxRichEdit);
procedure CutToClipboard (Editor: TRxRichEdit);


implementation

Expand Down Expand Up @@ -132,6 +135,27 @@ function ClipboardContentWasCopiedByKNT: boolean;
end;


procedure CopyToClipboard (Editor: TRxRichEdit);
begin
_IS_COPYING_TO_CLIPBOARD:= true;
try
Editor.CopyToClipboard;
finally
_IS_COPYING_TO_CLIPBOARD:= false;
end;
end;

procedure CutToClipboard (Editor: TRxRichEdit);
begin
_IS_COPYING_TO_CLIPBOARD:= true;
try
Editor.CutToClipboard;
finally
_IS_COPYING_TO_CLIPBOARD:= false;
end;
end;


function GetDropFiles(hDrop: THANDLE): TStringList;
var
CFileName : array[0..MAX_PATH] of Char;
Expand Down
2 changes: 2 additions & 0 deletions general/kn_Global.pas
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ interface
//================================================== CLIPBOARD
_IS_CAPTURING_CLIPBOARD : boolean;
_IS_CHAINING_CLIPBOARD : boolean;
_IS_COPYING_TO_CLIPBOARD : boolean;
ClipCapNextInChain : HWnd;
LastEvalExprResult : string; // remembered, so that we can paste it

Expand Down Expand Up @@ -476,6 +477,7 @@ procedure InitializeKeynote (Form_Main: TForm_Main);
_Global_Location := nil;
_IS_CAPTURING_CLIPBOARD := false;
_IS_CHAINING_CLIPBOARD := false;
_IS_COPYING_TO_CLIPBOARD:= false;
_IS_FAKING_MOUSECLICK := false;
_REOPEN_AUTOCLOSED_FILE := false;

Expand Down
6 changes: 3 additions & 3 deletions keynote.dproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<ProjectGuid>{D8BB21C7-F08A-4EC5-AA3A-B61205ECD2B8}</ProjectGuid>
<MainSource>keynote.dpr</MainSource>
<Base>True</Base>
<Config Condition="'$(Config)'==''">Release</Config>
<Config Condition="'$(Config)'==''">Debug</Config>
<TargetedPlatforms>32769</TargetedPlatforms>
<AppType>Application</AppType>
<FrameworkType>VCL</FrameworkType>
Expand Down Expand Up @@ -138,7 +138,7 @@
<AppDPIAwarenessMode>gdiScaling</AppDPIAwarenessMode>
<VerInfo_MinorVer>8</VerInfo_MinorVer>
<VerInfo_Release>2</VerInfo_Release>
<VerInfo_Keys>CompanyName=;FileDescription=KeyNote NF 1.8.2 .01;FileVersion=1.8.2.1;InternalName=;LegalCopyright=(c) Daniel Prado 2007-23 (c) Marek Jedlinski 2000-05;LegalTrademarks=Free software, MPL 2.0;OriginalFilename=keynote.exe;ProductName=KeyNote NF (New Features);ProductVersion=1.8.2.1;Comments=;ProgramID=</VerInfo_Keys>
<VerInfo_Keys>CompanyName=;FileDescription=KeyNote NF 1.8.2 .02;FileVersion=1.8.2.2;InternalName=;LegalCopyright=(c) Daniel Prado 2007-23 (c) Marek Jedlinski 2000-05;LegalTrademarks=Free software, MPL 2.0;OriginalFilename=keynote.exe;ProductName=KeyNote NF (New Features);ProductVersion=1.8.2.2;Comments=;ProgramID=</VerInfo_Keys>
<DCC_Define>VCL;$(DCC_Define)</DCC_Define>
<UsePackages>true</UsePackages>
<UWP_DelphiLogo44>keynote_Icon.ico</UWP_DelphiLogo44>
Expand All @@ -148,7 +148,7 @@
<DCC_DebugDCUs>true</DCC_DebugDCUs>
<DCC_AssertionsAtRuntime>true</DCC_AssertionsAtRuntime>
<Debugger_RunParams>Profiles\F9\keynote.ini</Debugger_RunParams>
<VerInfo_Build>1</VerInfo_Build>
<VerInfo_Build>2</VerInfo_Build>
</PropertyGroup>
<ItemGroup>
<DelphiCompile Include="$(MainSource)">
Expand Down
5 changes: 5 additions & 0 deletions kn_Main.pas
Original file line number Diff line number Diff line change
Expand Up @@ -4476,10 +4476,15 @@ procedure TForm_Main.WMDrawClipboard(var Msg: TWMDrawClipboard);
{*1 We need to calc CRC32 even if ClipOptions.TestDupClips=False, because it will be used for several other things,
but here, depending on that configuration (TestDupClips="Ignore duplicate clips") we will consider or not to paste the text }

{*2 We must register LogRTFHandleInClipboard, since the ecCut or ecCopy operations have been interrupted just after sending content to the
clipboard, before we can register the handle that we are using to identify if the Clipboard contains content copied by the application itself }


_IS_CAPTURING_CLIPBOARD:= True;
try
try
if _IS_COPYING_TO_CLIPBOARD then // *2
LogRTFHandleInClipboard();

if ( ClipCapActive and assigned( NoteFile ) and ( NoteFile.ClipCapNote <> nil )) then begin
if (( GetActiveWindow <> self.Handle ) or // only when inactive
Expand Down
6 changes: 3 additions & 3 deletions macros/kn_MacroMng.pas
Original file line number Diff line number Diff line change
Expand Up @@ -1581,7 +1581,7 @@ procedure PerformCmdEx( aCmd : TEditCmd );

RTFAux:= GetEditorWithNoKNTHiddenCharacters (ActiveNote.Editor, hmOnlyBookmarks, true); // Remove only hidden characters vinculated to bookmarks
try
RTFAux.CopyToClipboard;
CopyToClipboard (RTFAux);
LogRTFHandleInClipboard();

{ Replaced by the use of of LogRTFHandleInClipboard() / ClipboardContentWasCopiedByKNT()
Expand Down Expand Up @@ -1940,7 +1940,7 @@ procedure PerformCmd( aCmd : TEditCmd );
CheckToSelectLeftImageHiddenMark(ActiveNote.Editor, SelStartOrig, SelLengthOrig);
end;

ActiveNote.Editor.CutToClipboard;
CutToClipboard (ActiveNote.Editor);

if p >= 0 then begin
// We have not copied (cut) the hidden label along with the image, and we must delete it from the initial point
Expand All @@ -1952,7 +1952,7 @@ procedure PerformCmd( aCmd : TEditCmd );
ActiveNote.Editor.SetSelection(SelStartOrig, SelStartOrig + SelLengthOrig, true);
end
else
ActiveNote.Editor.CutToClipboard;
CutToClipboard (ActiveNote.Editor);


LogRTFHandleInClipboard();
Expand Down

0 comments on commit e8ebc70

Please sign in to comment.