MainFrm.cpp 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527
  1. // MainFrm.cpp : implementation of the CMainFrame class
  2. //
  3. #include "stdafx.h"
  4. #include "CP_Main.h"
  5. #include "MainFrm.h"
  6. #include "afxole.h"
  7. #include "Misc.h"
  8. #include "CopyProperties.h"
  9. #include "InternetUpdate.h"
  10. #include ".\mainfrm.h"
  11. #include "HyperLink.h"
  12. #include "tinyxml\tinyxml.h"
  13. #include "Path.h"
  14. #include "DittoCopyBuffer.h"
  15. #include "HotKeys.h"
  16. #include "GlobalClips.h"
  17. #include "OptionsSheet.h"
  18. #include "DeleteClipData.h"
  19. #include "DatabaseUtilities.h"
  20. #ifdef _DEBUG
  21. #define new DEBUG_NEW
  22. #undef THIS_FILE
  23. static char THIS_FILE[] = __FILE__;
  24. #endif
  25. #define WM_ICON_NOTIFY WM_APP+10
  26. #define MYWM_NOTIFYICON (WM_USER+1)
  27. #define WM_TRAYNOTIFY WM_USER + 100
  28. IMPLEMENT_DYNAMIC(CMainFrame, CFrameWnd)
  29. BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
  30. //{{AFX_MSG_MAP(CMainFrame)
  31. ON_WM_CREATE()
  32. ON_COMMAND(ID_FIRST_OPTION, OnFirstOption)
  33. ON_COMMAND(ID_FIRST_EXIT, OnFirstExit)
  34. ON_WM_TIMER()
  35. ON_COMMAND(ID_FIRST_SHOWQUICKPASTE, OnFirstShowquickpaste)
  36. ON_COMMAND(ID_FIRST_TOGGLECONNECTCV, OnFirstToggleConnectCV)
  37. ON_UPDATE_COMMAND_UI(ID_FIRST_TOGGLECONNECTCV, OnUpdateFirstToggleConnectCV)
  38. ON_COMMAND(ID_FIRST_HELP, OnFirstHelp)
  39. //}}AFX_MSG_MAP
  40. ON_MESSAGE(WM_HOTKEY, OnHotKey)
  41. ON_MESSAGE(WM_SHOW_TRAY_ICON, OnShowTrayIcon)
  42. ON_MESSAGE(WM_CLIPBOARD_COPIED, OnClipboardCopied)
  43. ON_WM_CLOSE()
  44. ON_MESSAGE(WM_ADD_TO_DATABASE_FROM_SOCKET, OnAddToDatabaseFromSocket)
  45. ON_MESSAGE(WM_SEND_RECIEVE_ERROR, OnErrorOnSendRecieve)
  46. ON_MESSAGE(WM_SHOW_ERROR_MSG, OnErrorMsg)
  47. ON_COMMAND(ID_FIRST_IMPORT, OnFirstImport)
  48. ON_MESSAGE(WM_EDIT_WND_CLOSING, OnEditWndClose)
  49. ON_WM_DESTROY()
  50. ON_COMMAND(ID_FIRST_NEWCLIP, OnFirstNewclip)
  51. ON_MESSAGE(WM_SET_CONNECTED, OnSetConnected)
  52. ON_MESSAGE(WM_OPEN_CLOSE_WINDWOW, OnOpenCloseWindow)
  53. ON_MESSAGE(WM_LOAD_ClIP_ON_CLIPBOARD, OnLoadClipOnClipboard)
  54. ON_COMMAND(ID_FIRST_GLOBALHOTKEYS, &CMainFrame::OnFirstGlobalhotkeys)
  55. ON_MESSAGE(WM_GLOBAL_CLIPS_CLOSED, OnGlobalClipsClosed)
  56. ON_MESSAGE(WM_OPTIONS_CLOSED, OnOptionsClosed)
  57. ON_MESSAGE(WM_SHOW_OPTIONS, OnShowOptions)
  58. ON_COMMAND(ID_FIRST_DELETECLIPDATA, &CMainFrame::OnFirstDeleteclipdata)
  59. ON_MESSAGE(WM_DELETE_CLIPS_CLOSED, OnDeleteClipDataClosed)
  60. ON_COMMAND(ID_FIRST_SAVECURRENTCLIPBOARD, &CMainFrame::OnFirstSavecurrentclipboard)
  61. ON_MESSAGE(WM_SAVE_CLIPBOARD, &CMainFrame::OnSaveClipboardMessage)
  62. ON_MESSAGE(WM_READD_TASKBAR_ICON, OnReAddTaskBarIcon)
  63. ON_MESSAGE(WM_REOPEN_DATABASE, &CMainFrame::OnReOpenDatabase)
  64. ON_MESSAGE(WM_SHOW_MSG_WINDOW, &CMainFrame::OnShowMsgWindow)
  65. ON_MESSAGE(WM_SHOW_DITTO_GROUP, &CMainFrame::OnShowDittoGroup)
  66. ON_COMMAND(ID_FIRST_FIXUPSTICKYCLIPORDER, &CMainFrame::OnFirstFixupstickycliporder)
  67. ON_MESSAGE(WM_DISPLAYCHANGE, &CMainFrame::OnResolutionChange)
  68. ON_MESSAGE(WM_TRAYNOTIFY, &CMainFrame::OnTrayNotification)
  69. ON_MESSAGE(WM_PLAIN_TEXT_PASTE, &CMainFrame::OnPlainTextPaste)
  70. ON_WM_WININICHANGE()
  71. ON_COMMAND(ID_FIRST_SHOWSTARTUPMESSAGE, &CMainFrame::OnFirstShowstartupmessage)
  72. ON_UPDATE_COMMAND_UI(ID_FIRST_SHOWSTARTUPMESSAGE, &CMainFrame::OnUpdateFirstShowstartupmessage)
  73. ON_COMMAND(ID_FIRST_BACKUPDATABASE, &CMainFrame::OnFirstBackupdatabase)
  74. ON_COMMAND(ID_FIRST_RESTOREDATABASE, &CMainFrame::OnFirstRestoredatabase)
  75. ON_MESSAGE(WM_BACKUP_DB, OnBackupDb)
  76. ON_MESSAGE(WM_RESTORE_DB, OnRestoreDb)
  77. ON_COMMAND(ID_FIRST_DELETEALLNONUSEDCLIPS, &CMainFrame::OnFirstDeleteallnonusedclips)
  78. END_MESSAGE_MAP()
  79. static UINT indicators[] =
  80. {
  81. ID_SEPARATOR, // status line indicator
  82. ID_INDICATOR_CAPS, ID_INDICATOR_NUM, ID_INDICATOR_SCRL,
  83. };
  84. /////////////////////////////////////////////////////////////////////////////
  85. // CMainFrame construction/destruction
  86. CMainFrame::CMainFrame()
  87. {
  88. m_pEditFrameWnd = NULL;
  89. m_keyStateModifiers = 0;
  90. m_startKeyStateTime = 0;
  91. m_bMovedSelectionMoveKeyState = false;
  92. m_keyModifiersTimerCount = 0;
  93. m_pGlobalClips = NULL;
  94. m_pOptions = NULL;
  95. m_pDeleteClips = NULL;
  96. m_doubleClickGroupId = -1;
  97. m_doubleClickGroupStartTime = 0;
  98. }
  99. CMainFrame::~CMainFrame()
  100. {
  101. CGetSetOptions::SetMainHWND(0);
  102. }
  103. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  104. {
  105. if(CFrameWnd::OnCreate(lpCreateStruct) == - 1)
  106. {
  107. return - 1;
  108. }
  109. m_PowerManager.Start(m_hWnd);
  110. ////Center the main window so message boxes are in the center
  111. CRect rcScreen = DefaultMonitorRect();
  112. CPoint cpCenter = rcScreen.CenterPoint();
  113. MoveWindow(cpCenter.x, cpCenter.x, 1, 1);
  114. m_startupScreenWidth = GetScreenWidth();
  115. m_startupScreenHeight = GetScreenHeight();
  116. //Then set the main window to transparent so it's never shown
  117. //if it is shown then only the task tray icon
  118. //m_Transparency.SetTransparent(m_hWnd, 0, true);
  119. SetWindowText(_T(""));
  120. Log(_T("Setting polling timer to track focus"));
  121. SetTimer(ACTIVE_WINDOW_TIMER, g_Opt.FocusWndTimerTimeout(), 0);
  122. SetTimer(READ_RANDOM_DB_FILE, g_Opt.ReadRandomFileInterval() * 1000, 0);
  123. SetWindowText(_T("Ditto"));
  124. m_trayIcon.Create(this, IDR_MENU, _T("Ditto"), CTrayNotifyIcon::LoadIcon(IDR_MAINFRAME), WM_TRAYNOTIFY, 0, 1);
  125. m_trayIcon.SetDefaultMenuItem(ID_FIRST_SHOWQUICKPASTE, FALSE);
  126. m_trayIcon.MinimiseToTray(this);
  127. if (CGetSetOptions::GetShowStartupMessage())
  128. {
  129. CString msg = theApp.m_Language.GetString(_T("StartupMsg"), _T("Ditto is running minimized, Ditto can be opened by hot keys or by clicking the task tray icon"));
  130. m_trayIcon.SetBalloonDetails(msg, _T("Ditto"), CTrayNotifyIcon::BalloonStyle::Info, CGetSetOptions::GetBalloonTimeout());
  131. }
  132. theApp.m_Language.UpdateTrayIconRightClickMenu(&m_trayIcon.GetMenu());
  133. //Only if in release
  134. #ifndef _DEBUG
  135. {
  136. //If not showing the icon show it for 40 seconds so they can get to the option
  137. //in case they can't remember the hot keys or something like that
  138. if(!(CGetSetOptions::GetShowIconInSysTray()))
  139. {
  140. SetTimer(HIDE_ICON_TIMER, 40000, 0);
  141. }
  142. }
  143. #endif
  144. //SetTimer(CLOSE_WINDOW_TIMER, ONE_HOUR*24, 0);
  145. SetTimer(REMOVE_OLD_TEMP_FILES, ONE_HOUR * 6, 0);
  146. SetTimer(REMOVE_OLD_ENTRIES_TIMER, ONE_MINUTE*15, 0);
  147. SetTimer(CLOSE_NO_DB_WINDOW_TIMER, 10000, 0);
  148. //found on some computers GetTickCount gettickcount returns a smaller value than other, can't explain
  149. //check here to see if we need to make an adjustment
  150. IdleSeconds();
  151. m_ulCopyGap = CGetSetOptions::GetCopyGap();
  152. theApp.AfterMainCreate();
  153. m_thread.Start(this);
  154. return 0;
  155. }
  156. LRESULT CMainFrame::OnPlainTextPaste(WPARAM wParam, LPARAM lParam)
  157. {
  158. DoTextOnlyPaste();
  159. return 1;
  160. }
  161. LRESULT CMainFrame::OnTrayNotification(WPARAM wParam, LPARAM lParam)
  162. {
  163. if (WM_MOUSEFIRST <= LOWORD(lParam) && LOWORD(lParam) <= WM_MOUSELAST)
  164. {
  165. theApp.m_activeWnd.TrackActiveWnd(true);
  166. }
  167. //click on balloon
  168. if (lParam == 0x405)
  169. {
  170. SetTimer(DELAYED_SHOW_DITTO_TIMER, 100, NULL);
  171. }
  172. m_trayIcon.OnTrayNotification(wParam, lParam);
  173. return 0L;
  174. }
  175. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT &cs)
  176. {
  177. if(cs.hMenu != NULL)
  178. {
  179. ::DestroyMenu(cs.hMenu); // delete menu if loaded
  180. cs.hMenu = NULL; // no menu for this window
  181. }
  182. if(!CFrameWnd::PreCreateWindow(cs))
  183. {
  184. return FALSE;
  185. }
  186. WNDCLASS wc;
  187. wc.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;
  188. wc.lpfnWndProc = AfxWndProc;
  189. wc.cbClsExtra = 0;
  190. wc.cbWndExtra = 0;
  191. wc.hInstance = AfxGetInstanceHandle();
  192. wc.hIcon = NULL;
  193. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  194. wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
  195. wc.lpszMenuName = NULL;
  196. wc.lpszClassName = _T("Ditto");
  197. // Create the QPaste window class
  198. if(!AfxRegisterClass(&wc))
  199. {
  200. return FALSE;
  201. }
  202. cs.lpszClass = wc.lpszClassName;
  203. return TRUE;
  204. }
  205. /////////////////////////////////////////////////////////////////////////////
  206. // CMainFrame diagnostics
  207. #ifdef _DEBUG
  208. void CMainFrame::AssertValid()const
  209. {
  210. CFrameWnd::AssertValid();
  211. }
  212. void CMainFrame::Dump(CDumpContext &dc)const
  213. {
  214. CFrameWnd::Dump(dc);
  215. }
  216. #endif //_DEBUG
  217. /////////////////////////////////////////////////////////////////////////////
  218. // CMainFrame message handlers
  219. void CMainFrame::OnFirstExit()
  220. {
  221. this->SendMessage(WM_CLOSE, 0, 0);
  222. }
  223. LRESULT CMainFrame::OnHotKey(WPARAM wParam, LPARAM lParam)
  224. {
  225. if(theApp.m_pDittoHotKey && wParam == theApp.m_pDittoHotKey->m_Atom ||
  226. theApp.m_pDittoHotKey2 && wParam == theApp.m_pDittoHotKey2->m_Atom ||
  227. theApp.m_pDittoHotKey3 && wParam == theApp.m_pDittoHotKey3->m_Atom)
  228. {
  229. //If they still have the shift/ctrl keys down
  230. if(m_keyStateModifiers != 0 && m_quickPaste.IsWindowVisibleEx())
  231. {
  232. Log(_T("On Show Ditto HotKey, key state modifiers are still down, moving selection"));
  233. if(m_bMovedSelectionMoveKeyState == false)
  234. {
  235. Log(_T("Setting flag m_bMovedSelectionMoveKeyState to true, will paste when modifer keys are up"));
  236. }
  237. m_quickPaste.MoveSelection(true);
  238. m_bMovedSelectionMoveKeyState = true;
  239. }
  240. else if(g_Opt.m_HideDittoOnHotKeyIfAlreadyShown && m_quickPaste.IsWindowTopLevel() && g_Opt.GetShowPersistent() == FALSE)
  241. {
  242. Log(_T("On Show Ditto HotKey, window is alread visible, hiding window"));
  243. m_quickPaste.HideQPasteWnd();
  244. }
  245. else
  246. {
  247. Log(_T("On Show Ditto HotKey, showing window"));
  248. StartKeyModifyerTimer();
  249. ShowQPasteWithActiveWindowCheck();
  250. }
  251. //KillTimer(CLOSE_WINDOW_TIMER);
  252. //SetTimer(CLOSE_WINDOW_TIMER, ONE_HOUR *24, 0);
  253. }
  254. else if(theApp.m_pPosOne && wParam == theApp.m_pPosOne->m_Atom)
  255. {
  256. Log(_T("Pos 1 hot key"));
  257. DoFirstTenPositionsPaste(0);
  258. }
  259. else if(theApp.m_pPosTwo && wParam == theApp.m_pPosTwo->m_Atom)
  260. {
  261. Log(_T("Pos 2 hot key"));
  262. DoFirstTenPositionsPaste(1);
  263. }
  264. else if(theApp.m_pPosThree && wParam == theApp.m_pPosThree->m_Atom)
  265. {
  266. Log(_T("Pos 3 hot key"));
  267. DoFirstTenPositionsPaste(2);
  268. }
  269. else if(theApp.m_pPosFour && wParam == theApp.m_pPosFour->m_Atom)
  270. {
  271. Log(_T("Pos 4 hot key"));
  272. DoFirstTenPositionsPaste(3);
  273. }
  274. else if(theApp.m_pPosFive && wParam == theApp.m_pPosFive->m_Atom)
  275. {
  276. Log(_T("Pos 5 hot key"));
  277. DoFirstTenPositionsPaste(4);
  278. }
  279. else if(theApp.m_pPosSix && wParam == theApp.m_pPosSix->m_Atom)
  280. {
  281. Log(_T("Pos 6 hot key"));
  282. DoFirstTenPositionsPaste(5);
  283. }
  284. else if(theApp.m_pPosSeven && wParam == theApp.m_pPosSeven->m_Atom)
  285. {
  286. Log(_T("Pos 7 hot key"));
  287. DoFirstTenPositionsPaste(6);
  288. }
  289. else if(theApp.m_pPosEight && wParam == theApp.m_pPosEight->m_Atom)
  290. {
  291. Log(_T("Pos 8 hot key"));
  292. DoFirstTenPositionsPaste(7);
  293. }
  294. else if(theApp.m_pPosNine && wParam == theApp.m_pPosNine->m_Atom)
  295. {
  296. Log(_T("Pos 9 hot key"));
  297. DoFirstTenPositionsPaste(8);
  298. }
  299. else if(theApp.m_pPosTen && wParam == theApp.m_pPosTen->m_Atom)
  300. {
  301. Log(_T("Pos 10 hot key"));
  302. DoFirstTenPositionsPaste(9);
  303. }
  304. else if(theApp.m_pCopyBuffer1 && wParam == theApp.m_pCopyBuffer1->m_Atom)
  305. {
  306. Log(_T("Copy buffer 1 hot key"));
  307. theApp.m_CopyBuffer.StartCopy(0);
  308. }
  309. else if(theApp.m_pPasteBuffer1 && wParam == theApp.m_pPasteBuffer1->m_Atom)
  310. {
  311. Log(_T("Paste buffer 1 hot key"));
  312. theApp.m_CopyBuffer.PastCopyBuffer(0);
  313. }
  314. else if(theApp.m_pCutBuffer1 && wParam == theApp.m_pCutBuffer1->m_Atom)
  315. {
  316. Log(_T("Cut buffer 1 hot key"));
  317. theApp.m_CopyBuffer.StartCopy(0, true);
  318. }
  319. else if(theApp.m_pCopyBuffer2 && wParam == theApp.m_pCopyBuffer2->m_Atom)
  320. {
  321. Log(_T("Copy buffer 2 hot key"));
  322. theApp.m_CopyBuffer.StartCopy(1);
  323. }
  324. else if(theApp.m_pPasteBuffer2 && wParam == theApp.m_pPasteBuffer2->m_Atom)
  325. {
  326. Log(_T("Paste buffer 2 hot key"));
  327. theApp.m_CopyBuffer.PastCopyBuffer(1);
  328. }
  329. else if(theApp.m_pCutBuffer2 && wParam == theApp.m_pCutBuffer2->m_Atom)
  330. {
  331. Log(_T("Cut buffer 2 hot key"));
  332. theApp.m_CopyBuffer.StartCopy(1, true);
  333. }
  334. else if(theApp.m_pCopyBuffer3 && wParam == theApp.m_pCopyBuffer3->m_Atom)
  335. {
  336. Log(_T("Copy buffer 3 hot key"));
  337. theApp.m_CopyBuffer.StartCopy(2);
  338. }
  339. else if(theApp.m_pPasteBuffer3 && wParam == theApp.m_pPasteBuffer3->m_Atom)
  340. {
  341. Log(_T("Paste buffer 3 hot key"));
  342. theApp.m_CopyBuffer.PastCopyBuffer(2);
  343. }
  344. else if(theApp.m_pCutBuffer3 && wParam == theApp.m_pCutBuffer3->m_Atom)
  345. {
  346. Log(_T("Cut buffer 3 hot key"));
  347. theApp.m_CopyBuffer.StartCopy(2, true);
  348. }
  349. else if(theApp.m_pTextOnlyPaste && wParam == theApp.m_pTextOnlyPaste->m_Atom)
  350. {
  351. DoTextOnlyPaste();
  352. }
  353. else if(theApp.m_pSaveClipboard && wParam == theApp.m_pSaveClipboard->m_Atom)
  354. {
  355. OnFirstSavecurrentclipboard();
  356. }
  357. else if (theApp.m_pCopyAndSaveClipboard && wParam == theApp.m_pCopyAndSaveClipboard->m_Atom)
  358. {
  359. Log(StrF(_T("START of copy and save clipboard, sending copy")));
  360. theApp.m_activeWnd.SendCopy(CopyReasonEnum::COPY_TO_UNKOWN);
  361. int delay = g_Opt.GetCopyAndSveDelay();
  362. Log(StrF(_T("Copy and save clipboard, sending copy, delaying %dms before saving clipboard"), delay));
  363. Sleep(delay);
  364. Log(StrF(_T("Copy and save clipboard, saving clipboard")));
  365. OnFirstSavecurrentclipboard();
  366. Log(StrF(_T("END of copy and save clipboard")));
  367. }
  368. else
  369. {
  370. for(int i = 0; i < g_HotKeys.GetCount(); i++)
  371. {
  372. if(g_HotKeys[i] != NULL &&
  373. g_HotKeys[i]->m_Atom == wParam &&
  374. g_HotKeys[i]->m_clipId > 0)
  375. {
  376. if(g_HotKeys[i]->m_hkType == CHotKey::PASTE_OPEN_CLIP)
  377. {
  378. Log(StrF(_T("Pasting clip from global shortcut, clipId: %d"), g_HotKeys[i]->m_clipId));
  379. PasteOrShowGroup(g_HotKeys[i]->m_clipId, -1, FALSE, TRUE, false);
  380. }
  381. else if(g_HotKeys[i]->m_hkType == CHotKey::MOVE_TO_GROUP)
  382. {
  383. Log(StrF(_T("Global hot key to save clip to group Id: %d, Sending copy to save selection to this group"), g_HotKeys[i]->m_clipId));
  384. KillTimer(GROUP_DOUBLE_CLICK);
  385. m_doubleClickGroupId = -1;
  386. m_doubleClickGroupStartTime = 0;
  387. theApp.SetActiveGroupId(g_HotKeys[i]->m_clipId);
  388. theApp.m_activeWnd.SendCopy(CopyReasonEnum::COPY_TO_GROUP);
  389. }
  390. break;
  391. }
  392. }
  393. }
  394. return TRUE;
  395. }
  396. void CMainFrame::ShowQPasteWithActiveWindowCheck()
  397. {
  398. //Before we show our window find the current focused window for paste into
  399. theApp.m_activeWnd.TrackActiveWnd(true);
  400. if (CGetSetOptions::GetOpenToGroupByActiveExe() &&
  401. theApp.m_activeWnd.ActiveWnd() != NULL)
  402. {
  403. CString exeName = GetProcessName(theApp.m_activeWnd.ActiveWnd());
  404. if (exeName != _T(""))
  405. {
  406. theApp.TryEnterOldGroupState();
  407. CString query = StrF(_T("SELECT lID FROM Main WHERE bIsGroup = 1 AND mText = '%s' COLLATE NOCASE"), exeName);
  408. CppSQLite3Query q = theApp.m_db.execQueryEx(query);
  409. if (q.eof() == false)
  410. {
  411. int groupId = q.getIntField(_T("lID"));
  412. //this will revert back to the old group on hide of ditto
  413. theApp.EnterGroupID(groupId, TRUE, TRUE);
  414. Log(StrF(_T("Opening Ditto to Group based on found group name, name: %s, GroupId: %d"), exeName, groupId));
  415. }
  416. else
  417. {
  418. theApp.TryEnterOldGroupState();
  419. }
  420. }
  421. }
  422. m_quickPaste.ShowQPasteWnd(this, false, true, FALSE);
  423. }
  424. void CMainFrame::DoTextOnlyPaste()
  425. {
  426. CClipboardSaveRestore textOnlyPaste;
  427. Log(_T("Text Only paste, saving clipboard to be restored later"));
  428. textOnlyPaste.Save(TRUE);
  429. Log(_T("Text Only paste, Add cf_text or cf_unicodetext to clipboard"));
  430. textOnlyPaste.RestoreTextOnly();
  431. DWORD pasteDelay = g_Opt.GetTextOnlyPasteDelay();
  432. Log(StrF(_T("Text Only paste, delaying %d ms before sending paste"), pasteDelay));
  433. Sleep(pasteDelay);
  434. Log(_T("Text Only paste, Sending paste"));
  435. theApp.m_activeWnd.SendPaste(false);
  436. Log(_T("Text Only paste, Post sending paste"));
  437. }
  438. void CMainFrame::DoFirstTenPositionsPaste(int nPos)
  439. {
  440. try
  441. {
  442. CString csSort = _T("");
  443. CString strFilter = _T("");
  444. bool pastedFromGroup = false;
  445. if (theApp.m_GroupID < 0 ||
  446. CGetSetOptions::GetUseUISelectedGroupForLastTenCopies() == FALSE)
  447. {
  448. //do not change this this directly relates to the views in the Main table
  449. csSort = "Main.bIsGroup ASC, "
  450. "Main.stickyClipOrder DESC, "
  451. "Main.clipOrder DESC";
  452. if (g_Opt.m_bShowAllClipsInMainList)
  453. {
  454. if (CGetSetOptions::GetShowGroupsInMainList())
  455. {
  456. //found to be slower on large databases
  457. strFilter = "((Main.bIsGroup = 1 AND Main.lParentID = -1) OR Main.bIsGroup = 0)";
  458. }
  459. else
  460. {
  461. strFilter = "(Main.bIsGroup = 0)";
  462. }
  463. }
  464. else
  465. {
  466. strFilter = "((Main.bIsGroup = 1 AND Main.lParentID = -1) OR (Main.bIsGroup = 0 AND Main.lParentID = -1))";
  467. }
  468. }
  469. else
  470. {
  471. pastedFromGroup = true;
  472. //do not change this this directly relates to the views in the Main table
  473. csSort = "Main.bIsGroup ASC, "
  474. "Main.stickyClipGroupOrder DESC, "
  475. "Main.clipGroupOrder DESC";
  476. if (theApp.m_GroupID >= 0)
  477. {
  478. strFilter.Format(_T("Main.lParentID = %d"), theApp.m_GroupID);
  479. }
  480. }
  481. CString query = StrF(_T("SELECT lID, bIsGroup FROM Main WHERE %s ORDER BY %s LIMIT 1 OFFSET %d"), strFilter, csSort, nPos);
  482. Log(StrF(_T("Doing Last Ten Paste, Index: %d Query: %s"), nPos, query));
  483. CppSQLite3Query q = theApp.m_db.execQueryEx(query);
  484. if(q.eof() == false)
  485. {
  486. PasteOrShowGroup(q.getIntField(_T("lID")), CGetSetOptions::GetMoveClipsOnGlobal10(), false, g_Opt.m_bSendPasteOnFirstTenHotKeys, pastedFromGroup);
  487. }
  488. }
  489. CATCH_SQLITE_EXCEPTION
  490. }
  491. void CMainFrame::StartKeyModifyerTimer()
  492. {
  493. m_keyModifiersTimerCount = 0;
  494. m_bMovedSelectionMoveKeyState = false;
  495. m_startKeyStateTime = GetTickCount();
  496. m_keyStateModifiers = CAccels::GetKeyStateModifiers();
  497. SetTimer(KEY_STATE_MODIFIERS, 50, NULL);
  498. }
  499. void CMainFrame::PasteOrShowGroup(int dbId, BOOL updateClipTime, BOOL activeTarget, BOOL sendPaste, bool pastedFromGroup)
  500. {
  501. try
  502. {
  503. bool isGroup = false;
  504. CppSQLite3Query q = theApp.m_db.execQueryEx(_T("SELECT bIsGroup FROM Main WHERE lID = %d"), dbId);
  505. if(q.eof() == false)
  506. {
  507. if(q.getIntField(_T("bIsGroup")) > 0)
  508. {
  509. isGroup = true;
  510. }
  511. }
  512. if(isGroup)
  513. {
  514. DWORD maxDiff = (DWORD)CGetSetOptions::GetGroupDoubleClickTimeMS();
  515. DWORD diff = GetTickCount() - m_doubleClickGroupStartTime;
  516. if(m_doubleClickGroupId == dbId &&
  517. diff < maxDiff)
  518. {
  519. Log(StrF(_T("Second Press of group hot key, group Id: %d, Sending copy to save selection to this group"), dbId));
  520. KillTimer(GROUP_DOUBLE_CLICK);
  521. m_doubleClickGroupId = -1;
  522. m_doubleClickGroupStartTime = 0;
  523. theApp.SetActiveGroupId(dbId);
  524. theApp.m_activeWnd.SendCopy(CopyReasonEnum::COPY_TO_GROUP);
  525. }
  526. else
  527. {
  528. m_doubleClickGroupId = dbId;
  529. m_doubleClickGroupStartTime = GetTickCount();
  530. int doubleClickTime = CGetSetOptions::GetGroupDoubleClickTimeMS();
  531. SetTimer(GROUP_DOUBLE_CLICK, doubleClickTime, 0);
  532. Log(StrF(_T("First Press of group hot key, group Id: %d, timout: %d"), dbId, doubleClickTime));
  533. }
  534. }
  535. else
  536. {
  537. KillTimer(GROUP_DOUBLE_CLICK);
  538. m_doubleClickGroupId = -1;
  539. m_doubleClickGroupStartTime = 0;
  540. BOOL bItWas = g_Opt.m_bUpdateTimeOnPaste;
  541. if (updateClipTime != -1)
  542. {
  543. g_Opt.m_bUpdateTimeOnPaste = updateClipTime;
  544. }
  545. CProcessPaste paste;
  546. paste.m_pastedFromGroup = pastedFromGroup;
  547. paste.GetClipIDs().Add(dbId);
  548. if (activeTarget != -1)
  549. {
  550. paste.m_bActivateTarget = activeTarget ? true : false;;
  551. }
  552. if (sendPaste != -1)
  553. {
  554. paste.m_bSendPaste = sendPaste ? true : false;
  555. }
  556. paste.DoPaste();
  557. theApp.OnPasteCompleted();
  558. if (updateClipTime != -1)
  559. {
  560. g_Opt.m_bUpdateTimeOnPaste = bItWas;
  561. }
  562. }
  563. }
  564. CATCH_SQLITE_EXCEPTION
  565. }
  566. void CMainFrame::DoDittoCopyBufferPaste(int nCopyBuffer)
  567. {
  568. try
  569. {
  570. CppSQLite3Query q = theApp.m_db.execQueryEx(_T("SELECT lID FROM Main WHERE CopyBuffer = %d"), nCopyBuffer);
  571. if(q.eof() == false)
  572. {
  573. //Don't move these to the top
  574. BOOL bItWas = g_Opt.m_bUpdateTimeOnPaste;
  575. g_Opt.m_bUpdateTimeOnPaste = FALSE;
  576. CProcessPaste paste;
  577. paste.GetClipIDs().Add(q.getIntField(_T("lID")));
  578. paste.m_bActivateTarget = false;
  579. paste.DoPaste();
  580. theApp.OnPasteCompleted();
  581. g_Opt.m_bUpdateTimeOnPaste = bItWas;
  582. }
  583. }
  584. CATCH_SQLITE_EXCEPTION
  585. }
  586. void CMainFrame::OnTimer(UINT_PTR nIDEvent)
  587. {
  588. switch(nIDEvent)
  589. {
  590. case HIDE_ICON_TIMER:
  591. {
  592. m_trayIcon.Hide();
  593. KillTimer(nIDEvent);
  594. }
  595. break;
  596. case CLOSE_WINDOW_TIMER:
  597. {
  598. //m_quickPaste.CloseQPasteWnd();
  599. }
  600. break;
  601. case REMOVE_OLD_ENTRIES_TIMER:
  602. {
  603. m_thread.FireDeleteEntries();
  604. }
  605. break;
  606. case REMOVE_OLD_TEMP_FILES:
  607. {
  608. m_thread.FireRemoveTempFiles();
  609. }
  610. break;
  611. case KEY_STATE_MODIFIERS:
  612. m_keyModifiersTimerCount++;
  613. if(m_keyStateModifiers != 0)
  614. {
  615. BYTE keyState = CAccels::GetKeyStateModifiers();
  616. //Have they release the key state modifiers yet(ctrl, shift, alt)
  617. if((m_keyStateModifiers &keyState) == 0)
  618. {
  619. KillTimer(KEY_STATE_MODIFIERS);
  620. long waitTime = (long)(GetTickCount() - m_startKeyStateTime);
  621. if(m_bMovedSelectionMoveKeyState || m_keyModifiersTimerCount > g_Opt.GetKeyStateWaitTimerCount())
  622. {
  623. Log(StrF(_T("Timer KEY_STATE_MODIFIERS timeout count hit(%d), count (%d), time (%d), Move Selection from Modifer (%d) sending paste"), g_Opt.GetKeyStateWaitTimerCount(), m_keyModifiersTimerCount, waitTime, m_bMovedSelectionMoveKeyState));
  624. m_quickPaste.OnKeyStateUp();
  625. }
  626. else
  627. {
  628. Log(StrF(_T("Timer KEY_STATE_MODIFIERS count NOT hit(%d), count (%d) time (%d)"), g_Opt.GetKeyStateWaitTimerCount(), m_keyModifiersTimerCount, waitTime));
  629. m_quickPaste.SetKeyModiferState(false);
  630. }
  631. m_keyStateModifiers = 0;
  632. m_keyModifiersTimerCount = 0;
  633. m_bMovedSelectionMoveKeyState = 0;
  634. }
  635. }
  636. else
  637. {
  638. KillTimer(KEY_STATE_MODIFIERS);
  639. }
  640. break;
  641. case ACTIVE_WINDOW_TIMER:
  642. {
  643. if(theApp.m_bShowingQuickPaste)
  644. {
  645. theApp.m_activeWnd.TrackActiveWnd(false);
  646. }
  647. }
  648. break;
  649. case READ_RANDOM_DB_FILE:
  650. {
  651. m_thread.FireReadDbFile();
  652. }
  653. break;
  654. case GROUP_DOUBLE_CLICK:
  655. {
  656. KillTimer(GROUP_DOUBLE_CLICK);
  657. Log(StrF(_T("Processing single click of groupId %d in timer, opening ditto to this group"), m_doubleClickGroupId));
  658. DWORD maxDiff = (DWORD)(CGetSetOptions::GetGroupDoubleClickTimeMS() * 1.5);
  659. DWORD diff = GetTickCount() - m_doubleClickGroupStartTime;
  660. if(diff < maxDiff)
  661. {
  662. if(m_doubleClickGroupId > -1)
  663. {
  664. if (theApp.EnterGroupID(m_doubleClickGroupId, FALSE, TRUE))
  665. {
  666. theApp.m_activeWnd.TrackActiveWnd(true);
  667. StartKeyModifyerTimer();
  668. m_quickPaste.ShowQPasteWnd(this, false, true, FALSE);
  669. }
  670. }
  671. }
  672. else
  673. {
  674. Log(StrF(_T("Something happened and we didn't process the group timer in time, Id: %d, Diff ms: %d, maxDiff: %d"), m_doubleClickGroupId, diff, maxDiff));
  675. }
  676. m_doubleClickGroupId = -1;
  677. m_doubleClickGroupStartTime = 0;
  678. }
  679. break;
  680. case SCREEN_RESOLUTION_CHANGED:
  681. {
  682. KillTimer(SCREEN_RESOLUTION_CHANGED);
  683. m_quickPaste.OnScreenResolutionChange();
  684. }
  685. break;
  686. case DELAYED_SHOW_DITTO_TIMER:
  687. {
  688. KillTimer(DELAYED_SHOW_DITTO_TIMER);
  689. m_quickPaste.ShowQPasteWnd(this, false, false, FALSE);
  690. }
  691. break;
  692. case SET_WINDOWS_THEME_TIMER:
  693. {
  694. KillTimer(SET_WINDOWS_THEME_TIMER);
  695. auto theme = g_Opt.GetTheme();
  696. if (theme == _T(""))
  697. {
  698. g_Opt.m_Theme.Load(theme);
  699. auto visible = m_quickPaste.IsWindowVisibleEx();
  700. m_quickPaste.CloseQPasteWnd();
  701. if (visible)
  702. {
  703. m_quickPaste.ShowQPasteWnd(this, true, false, true);
  704. }
  705. }
  706. }
  707. break;
  708. case CLOSE_NO_DB_WINDOW_TIMER:
  709. KillTimer(CLOSE_NO_DB_WINDOW_TIMER);
  710. theApp.CloseNoDbWindow();
  711. break;
  712. }
  713. CFrameWnd::OnTimer(nIDEvent);
  714. }
  715. LRESULT CMainFrame::OnShowTrayIcon(WPARAM wParam, LPARAM lParam)
  716. {
  717. if(lParam)
  718. {
  719. if(!m_trayIcon.IsHidden())
  720. {
  721. KillTimer(HIDE_ICON_TIMER);
  722. SetTimer(HIDE_ICON_TIMER, 40000, 0);
  723. }
  724. }
  725. if(wParam)
  726. {
  727. m_trayIcon.Show();
  728. }
  729. else
  730. {
  731. m_trayIcon.Hide();
  732. }
  733. return TRUE;
  734. }
  735. void CMainFrame::OnFirstShowquickpaste()
  736. {
  737. m_quickPaste.ShowQPasteWnd(this, false, false, FALSE);
  738. }
  739. void CMainFrame::OnFirstToggleConnectCV()
  740. {
  741. theApp.ToggleConnectCV();
  742. }
  743. void CMainFrame::OnUpdateFirstToggleConnectCV(CCmdUI *pCmdUI)
  744. {
  745. theApp.UpdateMenuConnectCV(pCmdUI->m_pMenu, ID_FIRST_TOGGLECONNECTCV);
  746. }
  747. LRESULT CMainFrame::OnClipboardCopied(WPARAM wParam, LPARAM lParam)
  748. {
  749. Log(_T("Start of function OnClipboardCopied, adding clip to thread for processing"));
  750. CClip *pClip = (CClip*)wParam;
  751. if(pClip != NULL)
  752. {
  753. m_thread.AddClipToSave(pClip);
  754. }
  755. Log(_T("End of function OnClipboardCopied"));
  756. return TRUE;
  757. }
  758. BOOL CMainFrame::PreTranslateMessage(MSG *pMsg)
  759. {
  760. //forward the mouse wheel onto the window under the cursor
  761. //normally windows only sends it to the window with focus, bypass this
  762. if ((pMsg->message == WM_MOUSEWHEEL || pMsg->message == WM_MOUSEHWHEEL) &&
  763. ::GetCapture() == nullptr)
  764. {
  765. POINT mouse;
  766. GetCursorPos(&mouse);
  767. HWND hwndFromPoint = ::WindowFromPoint(mouse);
  768. if (pMsg->hwnd != hwndFromPoint)
  769. {
  770. DWORD winProcessId = 0;
  771. ::GetWindowThreadProcessId(hwndFromPoint, &winProcessId);
  772. if (winProcessId == ::GetCurrentProcessId()) //no-fail!
  773. {
  774. pMsg->hwnd = hwndFromPoint;
  775. }
  776. }
  777. if (GetKeyState(VK_SHIFT) & 0x8000)
  778. pMsg->message = WM_MOUSEHWHEEL;
  779. }
  780. return CFrameWnd::PreTranslateMessage(pMsg);
  781. }
  782. void CMainFrame::OnClose()
  783. {
  784. CloseAllOpenDialogs();
  785. if(m_pEditFrameWnd)
  786. {
  787. if(m_pEditFrameWnd->CloseAll() == false)
  788. {
  789. return ;
  790. }
  791. }
  792. Log(_T("OnClose - before stop MainFrm thread"));
  793. m_thread.Stop();
  794. Log(_T("OnClose - after stop MainFrm thread"));
  795. theApp.BeforeMainClose();
  796. m_PowerManager.Close();
  797. CFrameWnd::OnClose();
  798. }
  799. bool CMainFrame::CloseAllOpenDialogs()
  800. {
  801. bool bRet = false;
  802. DWORD dwordProcessId;
  803. DWORD dwordChildWindowProcessId;
  804. GetWindowThreadProcessId(this->m_hWnd, &dwordProcessId);
  805. ASSERT(dwordProcessId);
  806. CWnd *pTempWnd = GetDesktopWindow()->GetWindow(GW_CHILD);
  807. while((pTempWnd = pTempWnd->GetWindow(GW_HWNDNEXT)) != NULL)
  808. {
  809. if(pTempWnd->GetSafeHwnd() == NULL)
  810. {
  811. break;
  812. }
  813. GetWindowThreadProcessId(pTempWnd->GetSafeHwnd(), &dwordChildWindowProcessId);
  814. if(dwordChildWindowProcessId == dwordProcessId)
  815. {
  816. TCHAR szTemp[100];
  817. GetClassName(pTempWnd->GetSafeHwnd(), szTemp, 100);
  818. // #32770 is class name for dialogs so don't process the message if it is a dialog
  819. if(STRCMP(szTemp, _T("#32770")) == 0)
  820. {
  821. pTempWnd->SendMessage(WM_CLOSE, 0, 0);
  822. bRet = true;
  823. }
  824. }
  825. }
  826. MSG msg;
  827. while(PeekMessage(&msg, NULL, NULL, NULL, PM_REMOVE))
  828. {
  829. TranslateMessage(&msg);
  830. DispatchMessage(&msg);
  831. }
  832. return bRet;
  833. }
  834. LRESULT CMainFrame::OnLoadClipOnClipboard(WPARAM wParam, LPARAM lParam)
  835. {
  836. CClip *pClip = (CClip*)wParam;
  837. if(pClip == NULL)
  838. {
  839. LogSendRecieveInfo("---------ERROR OnLoadClipOnClipboard pClip == NULL");
  840. return FALSE;
  841. }
  842. if(pClip)
  843. {
  844. CProcessPaste paste;
  845. paste.m_bSendPaste = false;
  846. paste.m_bActivateTarget = false;
  847. paste.m_pasteOptions.m_delayRenderLockout = GetTickCount();
  848. LogSendRecieveInfo("---------OnLoadClipOnClipboard - Before PutFormats on clipboard");
  849. paste.m_pOle->PutFormatOnClipboard(&pClip->m_Formats);
  850. paste.m_pOle->CacheGlobalData(theApp.m_cfIgnoreClipboard, NewGlobalP("Ignore", sizeof("Ignore")));
  851. LogSendRecieveInfo("---------OnLoadClipOnClipboard - After PutFormats on clipboard");
  852. LogSendRecieveInfo(StrF(_T("---------OnLoadClipOnClipboard - Setting clip id: %d on ole clipboard"), pClip->m_id));
  853. paste.GetClipIDs().Add(pClip->m_id);
  854. paste.DoPaste();
  855. LogSendRecieveInfo(StrF(_T("---------OnLoadClipOnClipboard - After paste clip id: %d on ole clipboard"), pClip->m_id));
  856. }
  857. delete pClip;
  858. return TRUE;
  859. }
  860. LRESULT CMainFrame::OnAddToDatabaseFromSocket(WPARAM wParam, LPARAM lParam)
  861. {
  862. CClipList *pClipList = (CClipList*)wParam;
  863. if(pClipList == NULL)
  864. {
  865. LogSendRecieveInfo("---------OnAddToDatabaseFromSocket - ERROR pClipList == NULL");
  866. return FALSE;
  867. }
  868. DWORD flags = (DWORD)lParam;
  869. if(flags & REMOTE_CLIP_ADD_TO_CLIPBOARD)
  870. {
  871. CClip *pClip = pClipList->GetTail();
  872. if(pClip)
  873. {
  874. LogSendRecieveInfo("OnAddToDatabaseFromSocket - Adding clip from socket setting clip to be put on clipboard");
  875. pClip->m_param1 |= REMOTE_CLIP_ADD_TO_CLIPBOARD;
  876. }
  877. }
  878. if (flags & REMOTE_CLIP_MANUAL_SEND)
  879. {
  880. CClip *pClip = pClipList->GetTail();
  881. if (pClip)
  882. {
  883. LogSendRecieveInfo("OnAddToDatabaseFromSocket - Adding clip from socket setting clip was a manual send from other side");
  884. pClip->m_param1 |= REMOTE_CLIP_MANUAL_SEND;
  885. }
  886. }
  887. m_thread.AddRemoteClipToSave(pClipList);
  888. delete pClipList;
  889. return TRUE;
  890. }
  891. LRESULT CMainFrame::OnErrorOnSendRecieve(WPARAM wParam, LPARAM lParam)
  892. {
  893. CString csNewText = (TCHAR*)wParam;
  894. ShowErrorMessage(_T("Ditto - Send/Receive Error"), csNewText);
  895. return TRUE;
  896. }
  897. LRESULT CMainFrame::OnErrorMsg(WPARAM wParam, LPARAM lParam)
  898. {
  899. CString csNewText = (TCHAR*)wParam;
  900. ShowErrorMessage(_T("Ditto"), csNewText);
  901. return TRUE;
  902. }
  903. CString WndName(HWND hParent)
  904. {
  905. TCHAR cWindowText[200];
  906. ::GetWindowText(hParent, cWindowText, 100);
  907. int nCount = 0;
  908. while(STRLEN(cWindowText) <= 0)
  909. {
  910. hParent = ::GetParent(hParent);
  911. if(hParent == NULL)
  912. {
  913. break;
  914. }
  915. ::GetWindowText(hParent, cWindowText, 100);
  916. nCount++;
  917. if(nCount > 100)
  918. {
  919. Log(_T("GetTargetName reached maximum search depth of 100"));
  920. break;
  921. }
  922. }
  923. return cWindowText;
  924. }
  925. void CMainFrame::OnFirstHelp()
  926. {
  927. CHyperLink::GotoURL(_T("https://sourceforge.net/p/ditto-cp/wiki/"), SW_SHOW);
  928. }
  929. void CMainFrame::ShowErrorMessage(CString csTitle, CString csMessage)
  930. {
  931. Log(StrF(_T("ShowErrorMessage %s - %s"), csTitle, csMessage));
  932. m_trayIcon.SetBalloonDetails(csMessage, csTitle, CTrayNotifyIcon::BalloonStyle::Error, CGetSetOptions::GetBalloonTimeout());
  933. }
  934. void CMainFrame::OnFirstImport()
  935. {
  936. theApp.ImportClips(theApp.m_MainhWnd);
  937. }
  938. void CMainFrame::ShowEditWnd(CClipIDs &Ids)
  939. {
  940. CWaitCursor wait;
  941. bool bCreatedWindow = false;
  942. if(m_pEditFrameWnd == NULL)
  943. {
  944. m_pEditFrameWnd = new CEditFrameWnd;
  945. m_pEditFrameWnd->LoadFrame(IDR_MAINFRAME);
  946. bCreatedWindow = true;
  947. }
  948. if(m_pEditFrameWnd)
  949. {
  950. m_pEditFrameWnd->EditIds(Ids);
  951. m_pEditFrameWnd->SetNotifyWnd(m_hWnd);
  952. if(bCreatedWindow)
  953. {
  954. CSize sz;
  955. CPoint pt;
  956. CGetSetOptions::GetEditWndSize(sz);
  957. CGetSetOptions::GetEditWndPoint(pt);
  958. CRect cr(pt, sz);
  959. EnsureWindowVisible(&cr);
  960. m_pEditFrameWnd->MoveWindow(cr);
  961. }
  962. m_pEditFrameWnd->ShowWindow(SW_SHOW);
  963. m_pEditFrameWnd->SetForegroundWindow();
  964. m_pEditFrameWnd->SetFocus();
  965. }
  966. }
  967. LRESULT CMainFrame::OnEditWndClose(WPARAM wParam, LPARAM lParam)
  968. {
  969. m_pEditFrameWnd = NULL;
  970. return TRUE;
  971. }
  972. LRESULT CMainFrame::OnSetConnected(WPARAM wParam, LPARAM lParam)
  973. {
  974. if(wParam)
  975. {
  976. theApp.SetConnectCV(true);
  977. }
  978. else if(lParam)
  979. {
  980. theApp.SetConnectCV(false);
  981. }
  982. return TRUE;
  983. }
  984. LRESULT CMainFrame::OnOpenCloseWindow(WPARAM wParam, LPARAM lParam)
  985. {
  986. if(wParam)
  987. {
  988. StartKeyModifyerTimer();
  989. ShowQPasteWithActiveWindowCheck();
  990. }
  991. else if(lParam)
  992. {
  993. m_quickPaste.HideQPasteWnd();
  994. }
  995. return TRUE;
  996. }
  997. void CMainFrame::OnDestroy()
  998. {
  999. CFrameWnd::OnDestroy();
  1000. if(m_pEditFrameWnd)
  1001. {
  1002. m_pEditFrameWnd->DestroyWindow();
  1003. }
  1004. }
  1005. void CMainFrame::OnFirstNewclip()
  1006. {
  1007. CClipIDs IDs;
  1008. IDs.Add( - 1);
  1009. theApp.EditItems(IDs, true);
  1010. }
  1011. void CMainFrame::OnFirstOption()
  1012. {
  1013. if(m_pOptions != NULL)
  1014. {
  1015. ::SetForegroundWindow(m_pOptions->m_hWnd);
  1016. }
  1017. else
  1018. {
  1019. m_pOptions = new COptionsSheet(_T(""));
  1020. if(m_pOptions != NULL)
  1021. {
  1022. ((COptionsSheet*)m_pOptions)->SetNotifyWnd(m_hWnd);
  1023. m_pOptions->Create();
  1024. m_pOptions->ShowWindow(SW_SHOW);
  1025. }
  1026. }
  1027. }
  1028. void CMainFrame::OnFirstGlobalhotkeys()
  1029. {
  1030. if(m_pGlobalClips != NULL)
  1031. {
  1032. ::SetForegroundWindow(m_pGlobalClips->m_hWnd);
  1033. }
  1034. else
  1035. {
  1036. m_pGlobalClips = new GlobalClips();
  1037. CAlphaBlend tran;
  1038. tran.SetTransparent(m_hWnd, 0, 1);
  1039. if(m_pGlobalClips != NULL)
  1040. {
  1041. ((GlobalClips*)m_pGlobalClips)->SetNotifyWnd(m_hWnd);
  1042. m_pGlobalClips->Create(IDD_GLOBAL_CLIPS, NULL);
  1043. m_pGlobalClips->ShowWindow(SW_SHOW);
  1044. }
  1045. }
  1046. }
  1047. LRESULT CMainFrame::OnShowOptions(WPARAM wParam, LPARAM lParam)
  1048. {
  1049. OnFirstOption();
  1050. return 0;
  1051. }
  1052. LRESULT CMainFrame::OnOptionsClosed(WPARAM wParam, LPARAM lParam)
  1053. {
  1054. BOOL themeChanged = (BOOL)wParam;
  1055. m_trayIcon.MinimiseToTray(this);
  1056. CAlphaBlend tran;
  1057. tran.SetTransparent(m_hWnd, 255, 0);
  1058. delete m_pOptions;
  1059. m_pOptions = NULL;
  1060. if (themeChanged)
  1061. {
  1062. g_Opt.m_Theme.Load(g_Opt.GetTheme());
  1063. m_quickPaste.CloseQPasteWnd();
  1064. }
  1065. else
  1066. {
  1067. if (m_quickPaste.m_pwndPaste != NULL)
  1068. {
  1069. m_quickPaste.m_pwndPaste->PostMessage(NM_POST_OPTIONS_WINDOW);
  1070. }
  1071. }
  1072. m_trayIcon.SetMenu(NULL, IDR_MENU);
  1073. theApp.m_Language.UpdateTrayIconRightClickMenu(&m_trayIcon.GetMenu());
  1074. if (CGetSetOptions::GetShowIconInSysTray())
  1075. {
  1076. m_trayIcon.Show();
  1077. }
  1078. else
  1079. {
  1080. m_trayIcon.Hide();
  1081. }
  1082. return 0;
  1083. }
  1084. LRESULT CMainFrame::OnGlobalClipsClosed(WPARAM wParam, LPARAM lParam)
  1085. {
  1086. m_trayIcon.MinimiseToTray(this);
  1087. CAlphaBlend tran;
  1088. tran.SetTransparent(m_hWnd, 255, 0);
  1089. delete m_pGlobalClips;
  1090. m_pGlobalClips = NULL;
  1091. return 0;
  1092. }
  1093. void CMainFrame::RefreshShowInTaskBar()
  1094. {
  1095. BOOL windowVisible = m_quickPaste.IsWindowVisibleEx();
  1096. m_quickPaste.CloseQPasteWnd();
  1097. if (windowVisible)
  1098. {
  1099. m_quickPaste.ShowQPasteWnd(this, true, false, true);
  1100. }
  1101. }
  1102. LRESULT CMainFrame::OnDeleteClipDataClosed(WPARAM wParam, LPARAM lParam)
  1103. {
  1104. m_trayIcon.MinimiseToTray(this);
  1105. CAlphaBlend tran;
  1106. tran.SetTransparent(m_hWnd, 255, 0);
  1107. delete m_pDeleteClips;
  1108. m_pDeleteClips = NULL;
  1109. return 0;
  1110. }
  1111. void CMainFrame::OnFirstDeleteclipdata()
  1112. {
  1113. //this->ShowWindow(SW_HIDE);
  1114. if (m_pDeleteClips != NULL)
  1115. {
  1116. ::SetForegroundWindow(m_pDeleteClips->m_hWnd);
  1117. }
  1118. else
  1119. {
  1120. m_pDeleteClips = new CDeleteClipData();
  1121. CAlphaBlend tran;
  1122. tran.SetTransparent(m_hWnd, 0, 1);
  1123. if (m_pDeleteClips != NULL)
  1124. {
  1125. ((CDeleteClipData*) m_pDeleteClips)->SetNotifyWnd(m_hWnd);
  1126. m_pDeleteClips->Create(IDD_DELETE_CLIP_DATA, NULL);
  1127. m_pDeleteClips->ShowWindow(SW_SHOW);
  1128. }
  1129. }
  1130. }
  1131. LRESULT CMainFrame::OnSaveClipboardMessage(WPARAM wParam, LPARAM lParam)
  1132. {
  1133. OnFirstSavecurrentclipboard();
  1134. return TRUE;
  1135. }
  1136. void CMainFrame::OnFirstSavecurrentclipboard()
  1137. {
  1138. Log(_T("Start Saving the current clipboard to the database"));
  1139. CClip* pClip = new CClip;
  1140. if(pClip)
  1141. {
  1142. CClipTypes* pTypes = theApp.LoadTypesFromDB();
  1143. if(pTypes)
  1144. {
  1145. if(pClip->LoadFromClipboard(pTypes, false, _T("")))
  1146. {
  1147. Log(_T("Loaded clips from the clipboard, sending message to save to the db"));
  1148. ::PostMessage(m_hWnd, WM_CLIPBOARD_COPIED, (WPARAM)pClip, 0);
  1149. }
  1150. else
  1151. {
  1152. Log(_T("Failed to load clips from the clipboard, not saving to db"));
  1153. delete pClip;
  1154. pClip = NULL;
  1155. }
  1156. }
  1157. else
  1158. {
  1159. Log(_T("Failed to load supported types from the db, not saving to the db"));
  1160. }
  1161. }
  1162. Log(_T("Start Saving the current clipboard to the database"));
  1163. }
  1164. LRESULT CMainFrame::OnReAddTaskBarIcon(WPARAM wParam, LPARAM lParam)
  1165. {
  1166. if(CGetSetOptions::GetShowIconInSysTray())
  1167. {
  1168. m_trayIcon.SetIcon(CTrayNotifyIcon::LoadIcon(IDR_MAINFRAME));
  1169. }
  1170. return TRUE;
  1171. }
  1172. LRESULT CMainFrame::OnReOpenDatabase(WPARAM wParam, LPARAM lParam)
  1173. {
  1174. Log(StrF(_T("OnReOpenDatabase, Start closing and reopening database Delay: %d"), CGetSetOptions::GetWindowsResumeDelayReOpenDbMS()));
  1175. try
  1176. {
  1177. Sleep(CGetSetOptions::GetWindowsResumeDelayReOpenDbMS());
  1178. m_quickPaste.CloseQPasteWnd();
  1179. theApp.m_db.close();
  1180. OpenDatabase(CGetSetOptions::GetDBPath());
  1181. }
  1182. CATCH_SQLITE_EXCEPTION
  1183. Log(StrF(_T("OnReOpenDatabase, End closing and reopening database Delay: %d"), CGetSetOptions::GetWindowsResumeDelayReOpenDbMS()));
  1184. return TRUE;
  1185. }
  1186. LRESULT CMainFrame::OnShowMsgWindow(WPARAM wParam, LPARAM lParam)
  1187. {
  1188. CString *pMsg = (CString*)wParam;
  1189. int clipId = (int)lParam;
  1190. m_trayIcon.SetBalloonDetails(pMsg->GetBuffer(), _T("Ditto"), CTrayNotifyIcon::BalloonStyle::Info, CGetSetOptions::GetBalloonTimeout());
  1191. delete pMsg;
  1192. return TRUE;
  1193. }
  1194. LRESULT CMainFrame::OnShowDittoGroup(WPARAM wParam, LPARAM lParam)
  1195. {
  1196. int groupId = (int)wParam;
  1197. CppSQLite3Query q = theApp.m_db.execQueryEx(_T("SELECT bIsGroup FROM Main WHERE lID = %d"), groupId);
  1198. if(q.eof() == false)
  1199. {
  1200. if(q.getIntField(_T("bIsGroup")) > 0)
  1201. {
  1202. PasteOrShowGroup(groupId, FALSE, FALSE, FALSE, false);
  1203. }
  1204. }
  1205. return TRUE;
  1206. }
  1207. void CMainFrame::OnFirstFixupstickycliporder()
  1208. {
  1209. ReOrderStickyClips(-1, theApp.m_db);
  1210. }
  1211. LRESULT CMainFrame::OnResolutionChange(WPARAM wParam, LPARAM lParam)
  1212. {
  1213. if (m_startupScreenWidth != GetScreenWidth() ||
  1214. m_startupScreenHeight != GetScreenHeight())
  1215. {
  1216. m_startupScreenWidth = GetScreenWidth();
  1217. m_startupScreenHeight = GetScreenHeight();
  1218. SetTimer(SCREEN_RESOLUTION_CHANGED, 1000, NULL);
  1219. }
  1220. return TRUE;
  1221. }
  1222. void CMainFrame::OnWinIniChange(LPCTSTR lpszSection)
  1223. {
  1224. CFrameWnd::OnWinIniChange(lpszSection);
  1225. if (lpszSection != NULL &&
  1226. wcscmp(lpszSection, L"ImmersiveColorSet") == 0)
  1227. {
  1228. Log(StrF(_T("OnWinIniChange %s, setting timer to 1000ms to change theme"), lpszSection));
  1229. KillTimer(SET_WINDOWS_THEME_TIMER);
  1230. SetTimer(SET_WINDOWS_THEME_TIMER, 1000, NULL);
  1231. }
  1232. }
  1233. void CMainFrame::OnFirstShowstartupmessage()
  1234. {
  1235. BOOL existing = CGetSetOptions::GetShowStartupMessage();
  1236. CGetSetOptions::SetShowStartupMessage(!existing);
  1237. }
  1238. void CMainFrame::OnUpdateFirstShowstartupmessage(CCmdUI *pCmdUI)
  1239. {
  1240. if (pCmdUI == NULL ||
  1241. pCmdUI->m_pMenu == NULL)
  1242. {
  1243. return;
  1244. }
  1245. if (CGetSetOptions::GetShowStartupMessage())
  1246. {
  1247. pCmdUI->m_pMenu->CheckMenuItem(ID_FIRST_SHOWSTARTUPMESSAGE, MF_CHECKED);
  1248. }
  1249. else
  1250. {
  1251. pCmdUI->m_pMenu->CheckMenuItem(ID_FIRST_SHOWSTARTUPMESSAGE, MF_UNCHECKED);
  1252. }
  1253. }
  1254. void CMainFrame::OnFirstBackupdatabase()
  1255. {
  1256. BackupDbPrompt(m_hWnd);
  1257. }
  1258. void CMainFrame::OnFirstRestoredatabase()
  1259. {
  1260. RestoreDbPrompt(m_hWnd);
  1261. }
  1262. LRESULT CMainFrame::OnBackupDb(WPARAM wParam, LPARAM lParam)
  1263. {
  1264. OnFirstBackupdatabase();
  1265. return TRUE;
  1266. }
  1267. LRESULT CMainFrame::OnRestoreDb(WPARAM wParam, LPARAM lParam)
  1268. {
  1269. OnFirstRestoredatabase();
  1270. return TRUE;
  1271. }
  1272. void CMainFrame::OnFirstDeleteallnonusedclips()
  1273. {
  1274. int nRet = MessageBox(theApp.m_Language.GetString("Delete_All_Non_Used_Clips", "Delete all clips that are not groups, in groups, marked as never auto delete, has a shortcut key or marked as sticky.\r\n\r\nThis cannot be undone."), _T("Ditto"), MB_YESNO | MB_TOPMOST);
  1275. if (nRet == IDNO)
  1276. {
  1277. return;
  1278. }
  1279. DeleteNonUsedClips(false);
  1280. theApp.RefreshView();
  1281. }