Bladeren bron

Mechanism to take window screenshots without keyboard cues

Source commit: 76c1093ca5c53df13e999be4cb980e2c5b6a973c
Martin Prikryl 6 jaren geleden
bovenliggende
commit
8fd4df68dc

+ 5 - 0
source/forms/CustomScpExplorer.cpp

@@ -10473,3 +10473,8 @@ void __fastcall TCustomScpExplorerForm::DirViewChangeFocus(TObject *, TListItem
   }
 }
 //---------------------------------------------------------------------------
+void __fastcall TCustomScpExplorerForm::RemoteStatusBarMouseDown(TObject *, TMouseButton, TShiftState, int, int)
+{
+  CountClicksForWindowPrint(this);
+}
+//---------------------------------------------------------------------------

+ 1 - 0
source/forms/CustomScpExplorer.dfm

@@ -63,6 +63,7 @@ object CustomScpExplorerForm: TCustomScpExplorerForm
       ShowHint = True
       UseSystemFont = False
       OnClick = RemoteStatusBarClick
+      OnMouseDown = RemoteStatusBarMouseDown
     end
     object RemoteDirView: TUnixDirView
       Left = 172

+ 1 - 0
source/forms/CustomScpExplorer.h

@@ -199,6 +199,7 @@ __published:
   void __fastcall ApplicationEventsDeactivate(TObject *Sender);
   void __fastcall ApplicationEventsModalBegin(TObject *Sender);
   void __fastcall DirViewChangeFocus(TObject *Sender, TListItem *Item);
+  void __fastcall RemoteStatusBarMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y);
 
 private:
   TTerminal * FTerminal;

+ 5 - 0
source/forms/Login.cpp

@@ -3069,3 +3069,8 @@ void __fastcall TLoginDialog::ChangeScale(int M, int D)
   FNoteGroupOffset = MulDiv(FNoteGroupOffset, M, D);
 }
 //---------------------------------------------------------------------------
+void __fastcall TLoginDialog::ButtonPanelMouseDown(TObject *, TMouseButton, TShiftState, int, int)
+{
+  CountClicksForWindowPrint(this);
+}
+//---------------------------------------------------------------------------

+ 1 - 0
source/forms/Login.dfm

@@ -365,6 +365,7 @@ object LoginDialog: TLoginDialog
       Align = alBottom
       BevelOuter = bvNone
       TabOrder = 2
+      OnMouseDown = ButtonPanelMouseDown
       DesignSize = (
         361
         41)

+ 1 - 0
source/forms/Login.h

@@ -281,6 +281,7 @@ __published:
   void __fastcall SearchSiteNameStartOnlyActionExecute(TObject *Sender);
   void __fastcall SearchSiteNameActionExecute(TObject *Sender);
   void __fastcall SearchSiteActionExecute(TObject *Sender);
+  void __fastcall ButtonPanelMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y);
 
 private:
   int NoUpdate;

+ 78 - 0
source/windows/VCLCommon.cpp

@@ -846,6 +846,79 @@ static void __fastcall FormShowingChanged(TForm * Form, TWndMethod WndProc, TMes
   }
 }
 //---------------------------------------------------------------------------
+static TCustomForm * WindowPrintForm = NULL;
+static DWORD WindowPrintPrevClick = 0;
+static unsigned int WindowPrintClickCount = 0;
+//---------------------------------------------------------------------------
+void __fastcall CountClicksForWindowPrint(TForm * Form)
+{
+  if (WinConfiguration->AllowWindowPrint)
+  {
+    DWORD Tick = GetTickCount();
+    if (WindowPrintForm != Form)
+    {
+      WindowPrintForm = Form;
+      WindowPrintClickCount = 0;
+    }
+    if (WindowPrintPrevClick < Tick - 500)
+    {
+      WindowPrintClickCount = 0;
+    }
+    WindowPrintClickCount++;
+    WindowPrintPrevClick = Tick;
+    if (WindowPrintClickCount == 3)
+    {
+      WindowPrintClickCount = 0;
+
+      TInstantOperationVisualizer Visualizer;
+
+      // get the device context of the screen
+      HDC ScreenDC = CreateDC(L"DISPLAY", NULL, NULL, NULL);
+      // and a device context to put it in
+      HDC MemoryDC = CreateCompatibleDC(ScreenDC);
+
+      try
+      {
+        bool Sizable = (Form->BorderStyle == bsSizeable);
+        int Frame = GetSystemMetrics(Sizable ? SM_CXSIZEFRAME : SM_CXFIXEDFRAME) - 1;
+        int Width = Form->Width - 2*Frame;
+        int Height = Form->Height - Frame;
+
+        // maybe worth checking these are positive values
+        HBITMAP Bitmap = CreateCompatibleBitmap(ScreenDC, Width, Height);
+        try
+        {
+          // get a new bitmap
+          HBITMAP OldBitmap = static_cast<HBITMAP>(SelectObject(MemoryDC, Bitmap));
+
+          BitBlt(MemoryDC, 0, 0, Width, Height, ScreenDC, Form->Left + Frame, Form->Top, SRCCOPY);
+          Bitmap = static_cast<HBITMAP>(SelectObject(MemoryDC, OldBitmap));
+
+          OpenClipboard(NULL);
+          try
+          {
+            EmptyClipboard();
+            SetClipboardData(CF_BITMAP, Bitmap);
+          }
+          __finally
+          {
+            CloseClipboard();
+          }
+        }
+        __finally
+        {
+          DeleteObject(Bitmap);
+        }
+      }
+      __finally
+      {
+        DeleteDC(MemoryDC);
+        DeleteDC(ScreenDC);
+      }
+    }
+  }
+}
+//---------------------------------------------------------------------------
 inline void __fastcall DoFormWindowProc(TCustomForm * Form, TWndMethod WndProc,
   TMessage & Message)
 {
@@ -887,6 +960,11 @@ inline void __fastcall DoFormWindowProc(TCustomForm * Form, TWndMethod WndProc,
     ChangeFormPixelsPerInch(AForm, LOWORD(Message.WParam));
     WndProc(Message);
   }
+  else if ((Message.Msg == WM_LBUTTONDOWN) || (Message.Msg == WM_LBUTTONDBLCLK))
+  {
+    CountClicksForWindowPrint(AForm);
+    WndProc(Message);
+  }
   else
   {
     WndProc(Message);

+ 1 - 0
source/windows/VCLCommon.h

@@ -84,5 +84,6 @@ typedef void __fastcall (*TRescaleEvent)(TComponent * Sender, TObject * Token);
 void __fastcall SetRescaleFunction(
   TComponent * Component, TRescaleEvent OnRescale, TObject * Token = NULL, bool OwnsToken = false);
 void __fastcall RecordFormImplicitRescale(TForm * Form);
+void __fastcall CountClicksForWindowPrint(TForm * Form);
 //---------------------------------------------------------------------------
 #endif  // VCLCommonH

+ 7 - 0
source/windows/WinConfiguration.cpp

@@ -623,6 +623,7 @@ void __fastcall TWinConfiguration::Default()
   HonorDrivePolicy = true;
   TimeoutShellOperations = true;
   TimeoutShellIconRetrieval = false;
+  AllowWindowPrint = false;
 
   FEditor.Font.FontName = DefaultFixedWidthFontName;
   FEditor.Font.FontSize = DefaultFixedWidthFontSize;
@@ -1023,6 +1024,7 @@ THierarchicalStorage * TWinConfiguration::CreateScpStorage(bool & SessionList)
     KEYEX(String, FExtensionsShortCuts, L"ExtensionsShortCuts"); \
     KEY(Bool,     TimeoutShellOperations); \
     KEY(Bool,     TimeoutShellIconRetrieval); \
+    KEY(Bool,     AllowWindowPrint); \
   ); \
   BLOCK(L"Interface\\Editor", CANCREATE, \
     KEYEX(String,   Editor.Font.FontName, L"FontName2"); \
@@ -2673,6 +2675,11 @@ void __fastcall TWinConfiguration::SetTimeoutShellIconRetrieval(bool value)
   SET_CONFIG_PROPERTY(TimeoutShellIconRetrieval);
 }
 //---------------------------------------------------------------------------
+void __fastcall TWinConfiguration::SetAllowWindowPrint(bool value)
+{
+  SET_CONFIG_PROPERTY(AllowWindowPrint);
+}
+//---------------------------------------------------------------------------
 TStringList * __fastcall TWinConfiguration::LoadJumpList(
   THierarchicalStorage * Storage, UnicodeString Name)
 {

+ 3 - 0
source/windows/WinConfiguration.h

@@ -452,6 +452,7 @@ private:
   int FRunsSinceLastTip;
   bool FLockedInterface;
   bool FTimeoutShellIconRetrieval;
+  bool FAllowWindowPrint;
   int FDontDecryptPasswords;
   int FMasterPasswordSession;
   bool FMasterPasswordSessionAsked;
@@ -559,6 +560,7 @@ private:
   bool __fastcall GetTimeoutShellOperations();
   void __fastcall SetTimeoutShellOperations(bool value);
   void __fastcall SetTimeoutShellIconRetrieval(bool value);
+  void __fastcall SetAllowWindowPrint(bool value);
   int __fastcall GetLocaleCompletenessTreshold();
 
   bool __fastcall GetDDExtInstalled();
@@ -743,6 +745,7 @@ public:
   __property bool LockedInterface = { read = FLockedInterface, write = SetLockedInterface };
   __property bool TimeoutShellOperations = { read = GetTimeoutShellOperations, write = SetTimeoutShellOperations };
   __property bool TimeoutShellIconRetrieval = { read = FTimeoutShellIconRetrieval, write = SetTimeoutShellIconRetrieval };
+  __property bool AllowWindowPrint = { read = FAllowWindowPrint, write = SetAllowWindowPrint };
   __property LCID DefaultLocale = { read = FDefaultLocale };
   __property int LocaleCompletenessTreshold = { read = GetLocaleCompletenessTreshold };
 };