CP_Main.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. #pragma once
  2. #ifndef __AFXWIN_H__
  3. #error include 'stdafx.h' before including this file for PCH
  4. #endif
  5. #include "resource.h" // main symbols
  6. #include "Clip.h"
  7. #include "DatabaseUtilities.h"
  8. #include "Misc.h"
  9. #include "Options.h"
  10. #include "Shared/ArrayEx.h"
  11. #include "MainFrm.h"
  12. #include "ProcessPaste.h"
  13. #include "MultiLanguage.h"
  14. #include "CopyThread.h"
  15. #include "ClipboardSaveRestore.h"
  16. #include "DittoCopyBuffer.h"
  17. #include "sqlite\CppSQLite3.h"
  18. #include "DittoAddins.h"
  19. #include "externalwindowtracker.h"
  20. #include "HotKeys.h"
  21. #include "DPI.h"
  22. #include "UAC_Thread.h"
  23. extern class CCP_MainApp theApp;
  24. #define BORDER 2
  25. #define CAPTION_BORDER theApp.m_metrics.ScaleX(25)
  26. class CCP_MainApp : public CWinApp
  27. {
  28. public:
  29. CCP_MainApp();
  30. ~CCP_MainApp();
  31. CppSQLite3DB m_db;
  32. HANDLE m_hMutex; // for singleton app
  33. HANDLE m_adminPasteMutex;
  34. // track stages of startup / shutdown
  35. bool m_bAppRunning;
  36. bool m_bAppExiting;
  37. int m_connectOnStartup;
  38. bool m_bExitServerThread;
  39. // MainFrame
  40. HWND m_MainhWnd;
  41. CMainFrame* m_pMainFrame;
  42. void AfterMainCreate(); // called after main window creation
  43. void BeforeMainClose(); // called before main window close
  44. // System-wide HotKeys
  45. CHotKey* m_pDittoHotKey; // activate ditto's qpaste window
  46. CHotKey* m_pDittoHotKey2; // activate ditto's qpaste window
  47. CHotKey* m_pDittoHotKey3; // activate ditto's qpaste window
  48. CHotKey* m_pPosOne;
  49. CHotKey* m_pPosTwo;
  50. CHotKey* m_pPosThree;
  51. CHotKey* m_pPosFour;
  52. CHotKey* m_pPosFive;
  53. CHotKey* m_pPosSix;
  54. CHotKey* m_pPosSeven;
  55. CHotKey* m_pPosEight;
  56. CHotKey* m_pPosNine;
  57. CHotKey* m_pPosTen;
  58. CHotKey *m_pCopyBuffer1;
  59. CHotKey *m_pPasteBuffer1;
  60. CHotKey *m_pCutBuffer1;
  61. CHotKey *m_pCopyBuffer2;
  62. CHotKey *m_pPasteBuffer2;
  63. CHotKey *m_pCutBuffer2;
  64. CHotKey *m_pCopyBuffer3;
  65. CHotKey *m_pPasteBuffer3;
  66. CHotKey *m_pCutBuffer3;
  67. CHotKey *m_pTextOnlyPaste;
  68. CHotKey *m_pSaveClipboard;
  69. ExternalWindowTracker m_activeWnd;
  70. // CopyThread and ClipViewer (Copy and Paste Management)
  71. CCopyThread m_CopyThread;
  72. void StartCopyThread();
  73. void StopCopyThread();
  74. // for posting messages
  75. HWND GetClipboardViewer() { return m_CopyThread.m_pClipboardViewer->m_hWnd; }
  76. bool EnableCbCopy(bool bState) { return m_CopyThread.SetCopyOnChange(bState); }
  77. bool IsClipboardViewerConnected() { return m_CopyThread.IsClipboardViewerConnected(); }
  78. bool GetConnectCV() { return m_CopyThread.GetConnectCV(); }
  79. void SetConnectCV(bool bConnect);
  80. bool ToggleConnectCV();
  81. void UpdateMenuConnectCV(CMenu* pMenu, UINT nMenuID);
  82. bool ImportClips(HWND hWnd);
  83. void LoadGlobalClips();
  84. void OnDeleteID(long lID);
  85. BOOL GetClipData(long lID, CClipFormat &Clip);
  86. bool EditItems(CClipIDs &Ids, bool bShowError);
  87. CClipTypes* LoadTypesFromDB(); // returns a "new" allocated object
  88. void ReloadTypes();
  89. void RefreshView(); // refreshes the view if it is visible
  90. void RefreshClipAfterPaste(int clipId);
  91. void OnCopyCompleted( long lLastID, int count = 1 );
  92. void OnPasteCompleted();
  93. // Internal Clipboard for cut/copy/paste items between Groups
  94. bool m_IC_bCopy; // true to copy the items, false to move them
  95. CClipIDs m_IC_IDs; // buffer
  96. void IC_Cut(ARRAY* pIDs = NULL); // if NULL, this uses the current QPaste selection
  97. void IC_Copy(ARRAY* pIDs = NULL); // if NULL, this uses the current QPaste selection
  98. void IC_Paste();
  99. // Groups
  100. long m_GroupDefaultID; // new clips are saved to this group
  101. long m_GroupID; // current group
  102. long m_GroupParentID; // current group's parent
  103. CString m_GroupText; // current group's description
  104. long m_oldGroupID;
  105. long m_oldGroupParentID;
  106. CString m_oldGroupText;
  107. void SaveCurrentGroupState();
  108. void ClearOldGroupState();
  109. BOOL TryEnterOldGroupState();
  110. BOOL EnterGroupID(long lID, BOOL clearOldGroupState = TRUE, BOOL saveCurrentGroupState = FALSE);
  111. long GetValidGroupID(); // returns a valid id (not negative)
  112. void SetGroupDefaultID(long lID); // sets a valid id
  113. // Window States
  114. // the ID given focus by CQPasteWnd::FillList
  115. long m_FocusID;
  116. bool m_bShowingQuickPaste;
  117. bool m_bRefreshView;
  118. CString m_Status;
  119. CQPasteWnd* QPasteWnd();
  120. HWND QPastehWnd();
  121. void SetStatus(const TCHAR* status = NULL, bool bRepaintImmediately = false);
  122. void ShowPersistent(bool bVal);
  123. bool m_bAsynchronousRefreshView;
  124. //Socket Info
  125. SOCKET m_sSocket;
  126. void StartStopServerThread();
  127. void StopServerThread();
  128. long m_lClipsSent;
  129. long m_lClipsRecieved;
  130. long m_lLastGoodIndexForNextworkPassword;
  131. CLIPFORMAT m_cfIgnoreClipboard; // used by CClip::LoadFromClipboard
  132. CLIPFORMAT m_cfDelaySavingData;
  133. CLIPFORMAT m_PingFormat;
  134. CLIPFORMAT m_HTML_Format;
  135. CLIPFORMAT m_RemoteCF_HDROP;
  136. CLIPFORMAT m_RTFFormat;
  137. COleDateTime m_oldtStartUp;
  138. CMultiLanguage m_Language;
  139. CDittoCopyBuffer m_CopyBuffer;
  140. void PumpMessageEx(HWND hWnd = NULL);
  141. CDittoAddins m_Addins;
  142. CDPI m_metrics;
  143. ULONG_PTR m_gdiplusToken;
  144. bool UACPaste();
  145. bool UACCopy();
  146. bool UACCut();
  147. bool UACThreadRunning();
  148. void RefreshShowInTaskBar();
  149. void SetActiveGroupId(int groupId);
  150. int GetActiveGroupId();
  151. void SetCopyReason(CopyReasonEnum::CopyReason copyReason);
  152. CopyReasonEnum::CopyReason GetCopyReason();
  153. public:
  154. virtual BOOL InitInstance();
  155. virtual int ExitInstance();
  156. afx_msg void OnAppAbout();
  157. DECLARE_MESSAGE_MAP()
  158. virtual BOOL OnIdle(LONG lCount);
  159. protected:
  160. void ShowCommandLineError(CString csTitle, CString csMessage);
  161. CUAC_Thread *m_pUacPasteThread;
  162. int m_activeGroupId;
  163. DWORD m_activeGroupStartTime;
  164. CopyReasonEnum::CopyReason m_copyReason;
  165. DWORD m_copyReasonStartTime;
  166. };