MainFrm.cpp 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308
  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. IMPLEMENT_DYNAMIC(CMainFrame, CFrameWnd)
  28. BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
  29. //{{AFX_MSG_MAP(CMainFrame)
  30. ON_WM_CREATE()
  31. ON_COMMAND(ID_FIRST_OPTION, OnFirstOption)
  32. ON_COMMAND(ID_FIRST_EXIT, OnFirstExit)
  33. ON_WM_TIMER()
  34. ON_COMMAND(ID_FIRST_SHOWQUICKPASTE, OnFirstShowquickpaste)
  35. ON_COMMAND(ID_FIRST_TOGGLECONNECTCV, OnFirstToggleConnectCV)
  36. ON_UPDATE_COMMAND_UI(ID_FIRST_TOGGLECONNECTCV, OnUpdateFirstToggleConnectCV)
  37. ON_COMMAND(ID_FIRST_HELP, OnFirstHelp)
  38. //}}AFX_MSG_MAP
  39. ON_MESSAGE(WM_HOTKEY, OnHotKey)
  40. ON_MESSAGE(WM_SHOW_TRAY_ICON, OnShowTrayIcon)
  41. ON_MESSAGE(WM_CLIPBOARD_COPIED, OnClipboardCopied)
  42. ON_WM_CLOSE()
  43. ON_MESSAGE(WM_ADD_TO_DATABASE_FROM_SOCKET, OnAddToDatabaseFromSocket)
  44. ON_MESSAGE(WM_SEND_RECIEVE_ERROR, OnErrorOnSendRecieve)
  45. ON_MESSAGE(WM_CUSTOMIZE_TRAY_MENU, OnCustomizeTrayMenu)
  46. ON_COMMAND(ID_FIRST_IMPORT, OnFirstImport)
  47. ON_MESSAGE(WM_EDIT_WND_CLOSING, OnEditWndClose)
  48. ON_WM_DESTROY()
  49. ON_COMMAND(ID_FIRST_NEWCLIP, OnFirstNewclip)
  50. ON_MESSAGE(WM_SET_CONNECTED, OnSetConnected)
  51. ON_MESSAGE(WM_OPEN_CLOSE_WINDWOW, OnOpenCloseWindow)
  52. ON_MESSAGE(WM_LOAD_ClIP_ON_CLIPBOARD, OnLoadClipOnClipboard)
  53. ON_MESSAGE(WM_TRAY_MENU_MOUSE_MOVE, OnSystemTrayMouseMove)
  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. END_MESSAGE_MAP()
  69. static UINT indicators[] =
  70. {
  71. ID_SEPARATOR, // status line indicator
  72. ID_INDICATOR_CAPS, ID_INDICATOR_NUM, ID_INDICATOR_SCRL,
  73. };
  74. /////////////////////////////////////////////////////////////////////////////
  75. // CMainFrame construction/destruction
  76. CMainFrame::CMainFrame()
  77. {
  78. m_pEditFrameWnd = NULL;
  79. m_keyStateModifiers = 0;
  80. m_startKeyStateTime = 0;
  81. m_bMovedSelectionMoveKeyState = false;
  82. m_keyModifiersTimerCount = 0;
  83. m_pGlobalClips = NULL;
  84. m_pOptions = NULL;
  85. m_pDeleteClips = NULL;
  86. m_doubleClickGroupId = -1;
  87. m_doubleClickGroupStartTime = 0;
  88. m_pPopupWindow = NULL;
  89. }
  90. CMainFrame::~CMainFrame()
  91. {
  92. CGetSetOptions::SetMainHWND(0);
  93. }
  94. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  95. {
  96. if(CFrameWnd::OnCreate(lpCreateStruct) == - 1)
  97. {
  98. return - 1;
  99. }
  100. m_PowerManager.Start(m_hWnd);
  101. //Center the main window so message boxes are in the center
  102. CRect rcScreen;
  103. GetMonitorRect(0, &rcScreen);
  104. CPoint cpCenter = rcScreen.CenterPoint();
  105. //MoveWindow(cpCenter.x, cpCenter.x, - 2, - 2);
  106. //Then set the main window to transparent so it's never shown
  107. //if it is shown then only the task tray icon
  108. //m_Transparency.SetTransparent(m_hWnd, 0, true);
  109. SetWindowText(_T(""));
  110. Log(_T("Setting polling timer to track focus"));
  111. SetTimer(ACTIVE_WINDOW_TIMER, g_Opt.FocusWndTimerTimeout(), 0);
  112. SetTimer(READ_RANDOM_DB_FILE, g_Opt.ReadRandomFileInterval() * 1000, 0);
  113. SetWindowText(_T("Ditto"));
  114. HICON hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  115. m_TrayIcon.Create(NULL, WM_ICON_NOTIFY, _T("Ditto"), hIcon, IDR_MENU, FALSE, _T(""), _T(""), NULL, 20);
  116. m_TrayIcon.SetSingleClickSelect(TRUE);
  117. m_TrayIcon.MinimiseToTray(this);
  118. m_TrayIcon.SetMenuDefaultItem(ID_FIRST_SHOWQUICKPASTE, FALSE);
  119. //Only if in release
  120. #ifndef _DEBUG
  121. {
  122. //If not showing the icon show it for 40 seconds so they can get to the option
  123. //in case they can't remember the hot keys or something like that
  124. if(!(CGetSetOptions::GetShowIconInSysTray()))
  125. {
  126. SetTimer(HIDE_ICON_TIMER, 40000, 0);
  127. }
  128. }
  129. #endif
  130. //SetTimer(CLOSE_WINDOW_TIMER, ONE_HOUR*24, 0);
  131. SetTimer(REMOVE_OLD_REMOTE_COPIES, ONE_DAY, 0);
  132. SetTimer(REMOVE_OLD_ENTRIES_TIMER, ONE_MINUTE*15, 0);
  133. //found on some computers GetTickCount gettickcount returns a smaller value than other, can't explain
  134. //check here to see if we need to make an adjustment
  135. IdleSeconds();
  136. m_ulCopyGap = CGetSetOptions::GetCopyGap();
  137. theApp.AfterMainCreate();
  138. m_thread.Start(this);
  139. return 0;
  140. }
  141. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT &cs)
  142. {
  143. if(cs.hMenu != NULL)
  144. {
  145. ::DestroyMenu(cs.hMenu); // delete menu if loaded
  146. cs.hMenu = NULL; // no menu for this window
  147. }
  148. if(!CFrameWnd::PreCreateWindow(cs))
  149. {
  150. return FALSE;
  151. }
  152. WNDCLASS wc;
  153. wc.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;
  154. wc.lpfnWndProc = AfxWndProc;
  155. wc.cbClsExtra = 0;
  156. wc.cbWndExtra = 0;
  157. wc.hInstance = AfxGetInstanceHandle();
  158. wc.hIcon = NULL;
  159. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  160. wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
  161. wc.lpszMenuName = NULL;
  162. wc.lpszClassName = _T("Ditto");
  163. // Create the QPaste window class
  164. if(!AfxRegisterClass(&wc))
  165. {
  166. return FALSE;
  167. }
  168. cs.lpszClass = wc.lpszClassName;
  169. return TRUE;
  170. }
  171. /////////////////////////////////////////////////////////////////////////////
  172. // CMainFrame diagnostics
  173. #ifdef _DEBUG
  174. void CMainFrame::AssertValid()const
  175. {
  176. CFrameWnd::AssertValid();
  177. }
  178. void CMainFrame::Dump(CDumpContext &dc)const
  179. {
  180. CFrameWnd::Dump(dc);
  181. }
  182. #endif //_DEBUG
  183. /////////////////////////////////////////////////////////////////////////////
  184. // CMainFrame message handlers
  185. void CMainFrame::OnFirstExit()
  186. {
  187. this->SendMessage(WM_CLOSE, 0, 0);
  188. }
  189. LRESULT CMainFrame::OnHotKey(WPARAM wParam, LPARAM lParam)
  190. {
  191. if(theApp.m_pDittoHotKey && wParam == theApp.m_pDittoHotKey->m_Atom)
  192. {
  193. //If they still have the shift/ctrl keys down
  194. if(m_keyStateModifiers != 0 && m_quickPaste.IsWindowVisibleEx())
  195. {
  196. Log(_T("On Show Ditto HotKey, key state modifiers are still down, moving selection"));
  197. if(m_bMovedSelectionMoveKeyState == false)
  198. {
  199. Log(_T("Setting flag m_bMovedSelectionMoveKeyState to true, will paste when modifer keys are up"));
  200. }
  201. m_quickPaste.MoveSelection(true);
  202. m_bMovedSelectionMoveKeyState = true;
  203. }
  204. else if(g_Opt.m_HideDittoOnHotKeyIfAlreadyShown && m_quickPaste.IsWindowTopLevel() && g_Opt.GetShowPersistent() == FALSE)
  205. {
  206. Log(_T("On Show Ditto HotKey, window is alread visible, hiding window"));
  207. m_quickPaste.HideQPasteWnd();
  208. }
  209. else
  210. {
  211. Log(_T("On Show Ditto HotKey, showing window"));
  212. StartKeyModifyerTimer();
  213. //Before we show our window find the current focused window for paste into
  214. theApp.m_activeWnd.TrackActiveWnd(true);
  215. m_quickPaste.ShowQPasteWnd(this, false, true, FALSE);
  216. }
  217. //KillTimer(CLOSE_WINDOW_TIMER);
  218. //SetTimer(CLOSE_WINDOW_TIMER, ONE_HOUR *24, 0);
  219. }
  220. else if(theApp.m_pPosOne && wParam == theApp.m_pPosOne->m_Atom)
  221. {
  222. Log(_T("Pos 1 hot key"));
  223. DoFirstTenPositionsPaste(0);
  224. }
  225. else if(theApp.m_pPosTwo && wParam == theApp.m_pPosTwo->m_Atom)
  226. {
  227. Log(_T("Pos 2 hot key"));
  228. DoFirstTenPositionsPaste(1);
  229. }
  230. else if(theApp.m_pPosThree && wParam == theApp.m_pPosThree->m_Atom)
  231. {
  232. Log(_T("Pos 3 hot key"));
  233. DoFirstTenPositionsPaste(2);
  234. }
  235. else if(theApp.m_pPosFour && wParam == theApp.m_pPosFour->m_Atom)
  236. {
  237. Log(_T("Pos 4 hot key"));
  238. DoFirstTenPositionsPaste(3);
  239. }
  240. else if(theApp.m_pPosFive && wParam == theApp.m_pPosFive->m_Atom)
  241. {
  242. Log(_T("Pos 5 hot key"));
  243. DoFirstTenPositionsPaste(4);
  244. }
  245. else if(theApp.m_pPosSix && wParam == theApp.m_pPosSix->m_Atom)
  246. {
  247. Log(_T("Pos 6 hot key"));
  248. DoFirstTenPositionsPaste(5);
  249. }
  250. else if(theApp.m_pPosSeven && wParam == theApp.m_pPosSeven->m_Atom)
  251. {
  252. Log(_T("Pos 7 hot key"));
  253. DoFirstTenPositionsPaste(6);
  254. }
  255. else if(theApp.m_pPosEight && wParam == theApp.m_pPosEight->m_Atom)
  256. {
  257. Log(_T("Pos 8 hot key"));
  258. DoFirstTenPositionsPaste(7);
  259. }
  260. else if(theApp.m_pPosNine && wParam == theApp.m_pPosNine->m_Atom)
  261. {
  262. Log(_T("Pos 9 hot key"));
  263. DoFirstTenPositionsPaste(8);
  264. }
  265. else if(theApp.m_pPosTen && wParam == theApp.m_pPosTen->m_Atom)
  266. {
  267. Log(_T("Pos 10 hot key"));
  268. DoFirstTenPositionsPaste(9);
  269. }
  270. else if(theApp.m_pCopyBuffer1 && wParam == theApp.m_pCopyBuffer1->m_Atom)
  271. {
  272. Log(_T("Copy buffer 1 hot key"));
  273. theApp.m_CopyBuffer.StartCopy(0);
  274. }
  275. else if(theApp.m_pPasteBuffer1 && wParam == theApp.m_pPasteBuffer1->m_Atom)
  276. {
  277. Log(_T("Paste buffer 1 hot key"));
  278. theApp.m_CopyBuffer.PastCopyBuffer(0);
  279. }
  280. else if(theApp.m_pCutBuffer1 && wParam == theApp.m_pCutBuffer1->m_Atom)
  281. {
  282. Log(_T("Cut buffer 1 hot key"));
  283. theApp.m_CopyBuffer.StartCopy(0, true);
  284. }
  285. else if(theApp.m_pCopyBuffer2 && wParam == theApp.m_pCopyBuffer2->m_Atom)
  286. {
  287. Log(_T("Copy buffer 2 hot key"));
  288. theApp.m_CopyBuffer.StartCopy(1);
  289. }
  290. else if(theApp.m_pPasteBuffer2 && wParam == theApp.m_pPasteBuffer2->m_Atom)
  291. {
  292. Log(_T("Paste buffer 2 hot key"));
  293. theApp.m_CopyBuffer.PastCopyBuffer(1);
  294. }
  295. else if(theApp.m_pCutBuffer2 && wParam == theApp.m_pCutBuffer2->m_Atom)
  296. {
  297. Log(_T("Cut buffer 2 hot key"));
  298. theApp.m_CopyBuffer.StartCopy(1, true);
  299. }
  300. else if(theApp.m_pCopyBuffer3 && wParam == theApp.m_pCopyBuffer3->m_Atom)
  301. {
  302. Log(_T("Copy buffer 3 hot key"));
  303. theApp.m_CopyBuffer.StartCopy(2);
  304. }
  305. else if(theApp.m_pPasteBuffer3 && wParam == theApp.m_pPasteBuffer3->m_Atom)
  306. {
  307. Log(_T("Paste buffer 3 hot key"));
  308. theApp.m_CopyBuffer.PastCopyBuffer(2);
  309. }
  310. else if(theApp.m_pCutBuffer3 && wParam == theApp.m_pCutBuffer3->m_Atom)
  311. {
  312. Log(_T("Cut buffer 3 hot key"));
  313. theApp.m_CopyBuffer.StartCopy(2, true);
  314. }
  315. else if(theApp.m_pTextOnlyPaste && wParam == theApp.m_pTextOnlyPaste->m_Atom)
  316. {
  317. DoTextOnlyPaste();
  318. }
  319. else if(theApp.m_pSaveClipboard && wParam == theApp.m_pSaveClipboard->m_Atom)
  320. {
  321. OnFirstSavecurrentclipboard();
  322. }
  323. else
  324. {
  325. for(int i = 0; i < g_HotKeys.GetCount(); i++)
  326. {
  327. if(g_HotKeys[i] != NULL &&
  328. g_HotKeys[i]->m_Atom == wParam &&
  329. g_HotKeys[i]->m_clipId > 0)
  330. {
  331. if(g_HotKeys[i]->m_hkType == CHotKey::PASTE_OPEN_CLIP)
  332. {
  333. Log(StrF(_T("Pasting clip from global shortcut, clipId: %d"), g_HotKeys[i]->m_clipId));
  334. PasteOrShowGroup(g_HotKeys[i]->m_clipId, -1, FALSE, TRUE);
  335. }
  336. else if(g_HotKeys[i]->m_hkType == CHotKey::MOVE_TO_GROUP)
  337. {
  338. 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));
  339. KillTimer(GROUP_DOUBLE_CLICK);
  340. m_doubleClickGroupId = -1;
  341. m_doubleClickGroupStartTime = 0;
  342. theApp.SetActiveGroupId(g_HotKeys[i]->m_clipId);
  343. theApp.m_activeWnd.SendCopy(CopyReasonEnum::COPY_TO_GROUP);
  344. }
  345. break;
  346. }
  347. }
  348. }
  349. return TRUE;
  350. }
  351. void CMainFrame::DoTextOnlyPaste()
  352. {
  353. CClipboardSaveRestore textOnlyPaste;
  354. Log(_T("Text Only paste, saving clipboard to be restored later"));
  355. textOnlyPaste.Save(TRUE);
  356. Log(_T("Text Only paste, Add cf_text or cf_unicodetext to clipboard"));
  357. textOnlyPaste.RestoreTextOnly();
  358. DWORD pasteDelay = g_Opt.GetTextOnlyPasteDelay();
  359. Log(StrF(_T("Text Only paste, delaying %d ms before sending paste"), pasteDelay));
  360. Sleep(pasteDelay);
  361. Log(_T("Text Only paste, Sending paste"));
  362. theApp.m_activeWnd.SendPaste(false);
  363. Log(_T("Text Only paste, Post sending paste"));
  364. }
  365. void CMainFrame::DoFirstTenPositionsPaste(int nPos)
  366. {
  367. try
  368. {
  369. CString csSort = _T("");
  370. csSort = "Main.bIsGroup ASC, "
  371. "Main.stickyClipOrder DESC, "
  372. "Main.clipOrder DESC";
  373. CString strFilter = _T("");
  374. if (g_Opt.m_bShowAllClipsInMainList)
  375. {
  376. if (CGetSetOptions::GetShowGroupsInMainList())
  377. {
  378. //found to be slower on large databases
  379. strFilter = "((Main.bIsGroup = 1 AND Main.lParentID = -1) OR Main.bIsGroup = 0)";
  380. }
  381. else
  382. {
  383. strFilter = "(Main.bIsGroup = 0)";
  384. }
  385. }
  386. else
  387. {
  388. strFilter = "((Main.bIsGroup = 1 AND Main.lParentID = -1) OR (Main.bIsGroup = 0 AND Main.lParentID = -1))";
  389. }
  390. CppSQLite3Query q = theApp.m_db.execQueryEx(_T("SELECT lID, bIsGroup FROM Main WHERE %s ORDER BY %s LIMIT 1 OFFSET %d"), strFilter, csSort, nPos);
  391. if(q.eof() == false)
  392. {
  393. PasteOrShowGroup(q.getIntField(_T("lID")), CGetSetOptions::GetMoveClipsOnGlobal10(), false, g_Opt.m_bSendPasteOnFirstTenHotKeys);
  394. }
  395. }
  396. CATCH_SQLITE_EXCEPTION
  397. }
  398. void CMainFrame::StartKeyModifyerTimer()
  399. {
  400. m_keyModifiersTimerCount = 0;
  401. m_bMovedSelectionMoveKeyState = false;
  402. m_startKeyStateTime = GetTickCount();
  403. m_keyStateModifiers = CAccels::GetKeyStateModifiers();
  404. SetTimer(KEY_STATE_MODIFIERS, 50, NULL);
  405. }
  406. void CMainFrame::PasteOrShowGroup(int dbId, BOOL updateClipTime, BOOL activeTarget, BOOL sendPaste)
  407. {
  408. try
  409. {
  410. bool isGroup = false;
  411. CppSQLite3Query q = theApp.m_db.execQueryEx(_T("SELECT bIsGroup FROM Main WHERE lID = %d"), dbId);
  412. if(q.eof() == false)
  413. {
  414. if(q.getIntField(_T("bIsGroup")) > 0)
  415. {
  416. isGroup = true;
  417. }
  418. }
  419. if(isGroup)
  420. {
  421. int maxDiff = CGetSetOptions::GetGroupDoubleClickTimeMS();
  422. DWORD diff = GetTickCount() - m_doubleClickGroupStartTime;
  423. if(m_doubleClickGroupId == dbId &&
  424. diff < maxDiff)
  425. {
  426. Log(StrF(_T("Second Press of group hot key, group Id: %d, Sending copy to save selection to this group"), dbId));
  427. KillTimer(GROUP_DOUBLE_CLICK);
  428. m_doubleClickGroupId = -1;
  429. m_doubleClickGroupStartTime = 0;
  430. theApp.SetActiveGroupId(dbId);
  431. theApp.m_activeWnd.SendCopy(CopyReasonEnum::COPY_TO_GROUP);
  432. }
  433. else
  434. {
  435. m_doubleClickGroupId = dbId;
  436. m_doubleClickGroupStartTime = GetTickCount();
  437. int doubleClickTime = CGetSetOptions::GetGroupDoubleClickTimeMS();
  438. SetTimer(GROUP_DOUBLE_CLICK, doubleClickTime, 0);
  439. Log(StrF(_T("First Press of group hot key, group Id: %d, timout: %d"), dbId, doubleClickTime));
  440. }
  441. }
  442. else
  443. {
  444. KillTimer(GROUP_DOUBLE_CLICK);
  445. m_doubleClickGroupId = -1;
  446. m_doubleClickGroupStartTime = 0;
  447. BOOL bItWas = g_Opt.m_bUpdateTimeOnPaste;
  448. if (updateClipTime != -1)
  449. {
  450. g_Opt.m_bUpdateTimeOnPaste = updateClipTime;
  451. }
  452. CProcessPaste paste;
  453. paste.GetClipIDs().Add(dbId);
  454. if (activeTarget != -1)
  455. {
  456. paste.m_bActivateTarget = activeTarget ? true : false;;
  457. }
  458. if (sendPaste != -1)
  459. {
  460. paste.m_bSendPaste = sendPaste ? true : false;
  461. }
  462. paste.DoPaste();
  463. theApp.OnPasteCompleted();
  464. if (updateClipTime != -1)
  465. {
  466. g_Opt.m_bUpdateTimeOnPaste = bItWas;
  467. }
  468. }
  469. }
  470. CATCH_SQLITE_EXCEPTION
  471. }
  472. void CMainFrame::DoDittoCopyBufferPaste(int nCopyBuffer)
  473. {
  474. try
  475. {
  476. CppSQLite3Query q = theApp.m_db.execQueryEx(_T("SELECT lID FROM Main WHERE CopyBuffer = %d"), nCopyBuffer);
  477. if(q.eof() == false)
  478. {
  479. //Don't move these to the top
  480. BOOL bItWas = g_Opt.m_bUpdateTimeOnPaste;
  481. g_Opt.m_bUpdateTimeOnPaste = FALSE;
  482. CProcessPaste paste;
  483. paste.GetClipIDs().Add(q.getIntField(_T("lID")));
  484. paste.m_bActivateTarget = false;
  485. paste.DoPaste();
  486. theApp.OnPasteCompleted();
  487. g_Opt.m_bUpdateTimeOnPaste = bItWas;
  488. }
  489. }
  490. CATCH_SQLITE_EXCEPTION
  491. }
  492. void CMainFrame::OnTimer(UINT_PTR nIDEvent)
  493. {
  494. switch(nIDEvent)
  495. {
  496. case HIDE_ICON_TIMER:
  497. {
  498. m_TrayIcon.HideIcon();
  499. KillTimer(nIDEvent);
  500. }
  501. break;
  502. case CLOSE_WINDOW_TIMER:
  503. {
  504. //m_quickPaste.CloseQPasteWnd();
  505. }
  506. break;
  507. case REMOVE_OLD_ENTRIES_TIMER:
  508. {
  509. m_thread.FireDeleteEntries();
  510. }
  511. break;
  512. case REMOVE_OLD_REMOTE_COPIES:
  513. {
  514. m_thread.FireRemoveRemoteFiles();
  515. }
  516. break;
  517. case KEY_STATE_MODIFIERS:
  518. m_keyModifiersTimerCount++;
  519. if(m_keyStateModifiers != 0)
  520. {
  521. BYTE keyState = CAccels::GetKeyStateModifiers();
  522. //Have they release the key state modifiers yet(ctrl, shift, alt)
  523. if((m_keyStateModifiers &keyState) == 0)
  524. {
  525. KillTimer(KEY_STATE_MODIFIERS);
  526. long waitTime = (long)(GetTickCount() - m_startKeyStateTime);
  527. if(m_bMovedSelectionMoveKeyState || m_keyModifiersTimerCount > g_Opt.GetKeyStateWaitTimerCount())
  528. {
  529. 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));
  530. m_quickPaste.OnKeyStateUp();
  531. }
  532. else
  533. {
  534. Log(StrF(_T("Timer KEY_STATE_MODIFIERS count NOT hit(%d), count (%d) time (%d)"), g_Opt.GetKeyStateWaitTimerCount(), m_keyModifiersTimerCount, waitTime));
  535. m_quickPaste.SetKeyModiferState(false);
  536. }
  537. m_keyStateModifiers = 0;
  538. m_keyModifiersTimerCount = 0;
  539. m_bMovedSelectionMoveKeyState = 0;
  540. }
  541. }
  542. else
  543. {
  544. KillTimer(KEY_STATE_MODIFIERS);
  545. }
  546. break;
  547. case ACTIVE_WINDOW_TIMER:
  548. {
  549. if(theApp.m_bShowingQuickPaste)
  550. {
  551. theApp.m_activeWnd.TrackActiveWnd(false);
  552. }
  553. }
  554. break;
  555. case READ_RANDOM_DB_FILE:
  556. {
  557. m_thread.FireReadDbFile();
  558. }
  559. break;
  560. case GROUP_DOUBLE_CLICK:
  561. {
  562. KillTimer(GROUP_DOUBLE_CLICK);
  563. Log(StrF(_T("Processing single click of groupId %d in timer, opening ditto to this group"), m_doubleClickGroupId));
  564. int maxDiff = (CGetSetOptions::GetGroupDoubleClickTimeMS() * 1.5);
  565. DWORD diff = GetTickCount() - m_doubleClickGroupStartTime;
  566. if(diff < maxDiff)
  567. {
  568. if(m_doubleClickGroupId > -1)
  569. {
  570. if (theApp.EnterGroupID(m_doubleClickGroupId, FALSE, TRUE))
  571. {
  572. theApp.m_activeWnd.TrackActiveWnd(true);
  573. StartKeyModifyerTimer();
  574. m_quickPaste.ShowQPasteWnd(this, false, true, FALSE);
  575. }
  576. }
  577. }
  578. else
  579. {
  580. 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));
  581. }
  582. m_doubleClickGroupId = -1;
  583. m_doubleClickGroupStartTime = 0;
  584. }
  585. break;
  586. case CLOSE_POPUP_MSG_WND:
  587. {
  588. KillTimer(CLOSE_POPUP_MSG_WND);
  589. if(m_pPopupWindow != NULL)
  590. {
  591. if(::IsWindow(m_pPopupWindow->m_hWnd))
  592. {
  593. m_pPopupWindow->DestroyWindow();
  594. }
  595. delete m_pPopupWindow;
  596. m_pPopupWindow = NULL;
  597. }
  598. }
  599. break;
  600. }
  601. CFrameWnd::OnTimer(nIDEvent);
  602. }
  603. LRESULT CMainFrame::OnShowTrayIcon(WPARAM wParam, LPARAM lParam)
  604. {
  605. if(lParam)
  606. {
  607. if(!m_TrayIcon.Visible())
  608. {
  609. KillTimer(HIDE_ICON_TIMER);
  610. SetTimer(HIDE_ICON_TIMER, 40000, 0);
  611. }
  612. }
  613. if(wParam)
  614. {
  615. m_TrayIcon.ShowIcon();
  616. }
  617. else
  618. {
  619. m_TrayIcon.HideIcon();
  620. }
  621. return TRUE;
  622. }
  623. void CMainFrame::OnFirstShowquickpaste()
  624. {
  625. m_quickPaste.ShowQPasteWnd(this, false, false, FALSE);
  626. }
  627. void CMainFrame::OnFirstToggleConnectCV()
  628. {
  629. theApp.ToggleConnectCV();
  630. }
  631. void CMainFrame::OnUpdateFirstToggleConnectCV(CCmdUI *pCmdUI)
  632. {
  633. theApp.UpdateMenuConnectCV(pCmdUI->m_pMenu, ID_FIRST_TOGGLECONNECTCV);
  634. }
  635. LRESULT CMainFrame::OnClipboardCopied(WPARAM wParam, LPARAM lParam)
  636. {
  637. Log(_T("Start of function OnClipboardCopied, adding clip to thread for processing"));
  638. CClip *pClip = (CClip*)wParam;
  639. if(pClip != NULL)
  640. {
  641. m_thread.AddClipToSave(pClip);
  642. }
  643. Log(_T("End of function OnClipboardCopied"));
  644. return TRUE;
  645. }
  646. BOOL CMainFrame::PreTranslateMessage(MSG *pMsg)
  647. {
  648. // target before mouse messages change the focus
  649. /*if(theApp.m_bShowingQuickPaste && WM_MOUSEFIRST <= pMsg->message && pMsg->message <= WM_MOUSELAST)
  650. {
  651. theApp.m_activeWnd.TrackActiveWnd(true);
  652. }*/
  653. return CFrameWnd::PreTranslateMessage(pMsg);
  654. }
  655. void CMainFrame::OnClose()
  656. {
  657. CloseAllOpenDialogs();
  658. if(m_pEditFrameWnd)
  659. {
  660. if(m_pEditFrameWnd->CloseAll() == false)
  661. {
  662. return ;
  663. }
  664. }
  665. Log(_T("OnClose - before stop MainFrm thread"));
  666. m_thread.Stop();
  667. Log(_T("OnClose - after stop MainFrm thread"));
  668. theApp.BeforeMainClose();
  669. m_PowerManager.Close();
  670. CFrameWnd::OnClose();
  671. }
  672. bool CMainFrame::CloseAllOpenDialogs()
  673. {
  674. bool bRet = false;
  675. DWORD dwordProcessId;
  676. DWORD dwordChildWindowProcessId;
  677. GetWindowThreadProcessId(this->m_hWnd, &dwordProcessId);
  678. ASSERT(dwordProcessId);
  679. CWnd *pTempWnd = GetDesktopWindow()->GetWindow(GW_CHILD);
  680. while((pTempWnd = pTempWnd->GetWindow(GW_HWNDNEXT)) != NULL)
  681. {
  682. if(pTempWnd->GetSafeHwnd() == NULL)
  683. {
  684. break;
  685. }
  686. GetWindowThreadProcessId(pTempWnd->GetSafeHwnd(), &dwordChildWindowProcessId);
  687. if(dwordChildWindowProcessId == dwordProcessId)
  688. {
  689. TCHAR szTemp[100];
  690. GetClassName(pTempWnd->GetSafeHwnd(), szTemp, 100);
  691. // #32770 is class name for dialogs so don't process the message if it is a dialog
  692. if(STRCMP(szTemp, _T("#32770")) == 0)
  693. {
  694. pTempWnd->SendMessage(WM_CLOSE, 0, 0);
  695. bRet = true;
  696. }
  697. }
  698. }
  699. MSG msg;
  700. while(PeekMessage(&msg, NULL, NULL, NULL, PM_REMOVE))
  701. {
  702. TranslateMessage(&msg);
  703. DispatchMessage(&msg);
  704. }
  705. return bRet;
  706. }
  707. LRESULT CMainFrame::OnSystemTrayMouseMove(WPARAM wParam, LPARAM lParam)
  708. {
  709. theApp.m_activeWnd.TrackActiveWnd(true);
  710. return 0;
  711. }
  712. LRESULT CMainFrame::OnLoadClipOnClipboard(WPARAM wParam, LPARAM lParam)
  713. {
  714. CClip *pClip = (CClip*)wParam;
  715. if(pClip == NULL)
  716. {
  717. LogSendRecieveInfo("---------ERROR OnLoadClipOnClipboard pClip == NULL");
  718. return FALSE;
  719. }
  720. if(pClip)
  721. {
  722. CProcessPaste paste;
  723. paste.m_bSendPaste = false;
  724. paste.m_bActivateTarget = false;
  725. LogSendRecieveInfo("---------OnLoadClipOnClipboard - Before PutFormats on clipboard");
  726. paste.m_pOle->PutFormatOnClipboard(&pClip->m_Formats);
  727. paste.m_pOle->CacheGlobalData(theApp.m_cfIgnoreClipboard, NewGlobalP("Ignore", sizeof("Ignore")));
  728. LogSendRecieveInfo("---------OnLoadClipOnClipboard - After PutFormats on clipboard");
  729. LogSendRecieveInfo(StrF(_T("---------OnLoadClipOnClipboard - Setting clip id: %d on ole clipboard"), pClip->m_id));
  730. paste.GetClipIDs().Add(pClip->m_id);
  731. paste.DoPaste();
  732. LogSendRecieveInfo(StrF(_T("---------OnLoadClipOnClipboard - After paste clip id: %d on ole clipboard"), pClip->m_id));
  733. }
  734. delete pClip;
  735. return TRUE;
  736. }
  737. LRESULT CMainFrame::OnAddToDatabaseFromSocket(WPARAM wParam, LPARAM lParam)
  738. {
  739. CClipList *pClipList = (CClipList*)wParam;
  740. if(pClipList == NULL)
  741. {
  742. LogSendRecieveInfo("---------OnAddToDatabaseFromSocket - ERROR pClipList == NULL");
  743. return FALSE;
  744. }
  745. BOOL bSetToClipBoard = (BOOL)lParam;
  746. if(bSetToClipBoard)
  747. {
  748. CClip *pClip = pClipList->GetTail();
  749. if(pClip)
  750. {
  751. LogSendRecieveInfo("OnAddToDatabaseFromSocket - Adding clip from socket setting clip to be put on clipboard");
  752. pClip->m_param1 = TRUE;
  753. }
  754. }
  755. m_thread.AddRemoteClipToSave(pClipList);
  756. delete pClipList;
  757. return TRUE;
  758. }
  759. LRESULT CMainFrame::OnErrorOnSendRecieve(WPARAM wParam, LPARAM lParam)
  760. {
  761. CString csNewText = (TCHAR*)wParam;
  762. ShowErrorMessage(_T("Ditto - Send/Receive Error"), csNewText);
  763. return TRUE;
  764. }
  765. CString WndName(HWND hParent)
  766. {
  767. TCHAR cWindowText[200];
  768. ::GetWindowText(hParent, cWindowText, 100);
  769. int nCount = 0;
  770. while(STRLEN(cWindowText) <= 0)
  771. {
  772. hParent = ::GetParent(hParent);
  773. if(hParent == NULL)
  774. {
  775. break;
  776. }
  777. ::GetWindowText(hParent, cWindowText, 100);
  778. nCount++;
  779. if(nCount > 100)
  780. {
  781. Log(_T("GetTargetName reached maximum search depth of 100"));
  782. break;
  783. }
  784. }
  785. return cWindowText;
  786. }
  787. void CMainFrame::OnFirstHelp()
  788. {
  789. CString csFile = CGetSetOptions::GetPath(PATH_HELP);
  790. csFile += "DittoGettingStarted.htm";
  791. CHyperLink::GotoURL(csFile, SW_SHOW);
  792. }
  793. LRESULT CMainFrame::OnCustomizeTrayMenu(WPARAM wParam, LPARAM lParam)
  794. {
  795. CMenu *pMenu = (CMenu*)wParam;
  796. if(pMenu)
  797. {
  798. theApp.m_Language.UpdateTrayIconRightClickMenu(pMenu);
  799. }
  800. return true;
  801. }
  802. void CMainFrame::ShowErrorMessage(CString csTitle, CString csMessage)
  803. {
  804. Log(StrF(_T("ShowErrorMessage %s - %s"), csTitle, csMessage));
  805. CToolTipEx *pErrorWnd = new CToolTipEx;
  806. pErrorWnd->Create(this);
  807. pErrorWnd->SetToolTipText(csTitle + "\n\n" + csMessage);
  808. CPoint pt;
  809. CRect rcScreen;
  810. GetMonitorRect(0, &rcScreen);
  811. pt = rcScreen.BottomRight();
  812. CRect cr = pErrorWnd->GetBoundsRect();
  813. pt.x -= max(cr.Width() + 50, 150);
  814. pt.y -= max(cr.Height() + 50, 150);
  815. pErrorWnd->Show(pt);
  816. pErrorWnd->HideWindowInXMilliSeconds(4000);
  817. }
  818. void CMainFrame::OnFirstImport()
  819. {
  820. theApp.ImportClips(theApp.m_MainhWnd);
  821. }
  822. void CMainFrame::ShowEditWnd(CClipIDs &Ids)
  823. {
  824. CWaitCursor wait;
  825. bool bCreatedWindow = false;
  826. if(m_pEditFrameWnd == NULL)
  827. {
  828. m_pEditFrameWnd = new CEditFrameWnd;
  829. m_pEditFrameWnd->LoadFrame(IDR_MAINFRAME);
  830. bCreatedWindow = true;
  831. }
  832. if(m_pEditFrameWnd)
  833. {
  834. m_pEditFrameWnd->EditIds(Ids);
  835. m_pEditFrameWnd->SetNotifyWnd(m_hWnd);
  836. if(bCreatedWindow)
  837. {
  838. CSize sz;
  839. CPoint pt;
  840. CGetSetOptions::GetEditWndSize(sz);
  841. CGetSetOptions::GetEditWndPoint(pt);
  842. CRect cr(pt, sz);
  843. EnsureWindowVisible(&cr);
  844. m_pEditFrameWnd->MoveWindow(cr);
  845. }
  846. m_pEditFrameWnd->ShowWindow(SW_SHOW);
  847. m_pEditFrameWnd->SetForegroundWindow();
  848. m_pEditFrameWnd->SetFocus();
  849. }
  850. }
  851. LRESULT CMainFrame::OnEditWndClose(WPARAM wParam, LPARAM lParam)
  852. {
  853. m_pEditFrameWnd = NULL;
  854. return TRUE;
  855. }
  856. LRESULT CMainFrame::OnSetConnected(WPARAM wParam, LPARAM lParam)
  857. {
  858. if(wParam)
  859. {
  860. theApp.SetConnectCV(true);
  861. }
  862. else if(lParam)
  863. {
  864. theApp.SetConnectCV(false);
  865. }
  866. return TRUE;
  867. }
  868. LRESULT CMainFrame::OnOpenCloseWindow(WPARAM wParam, LPARAM lParam)
  869. {
  870. if(wParam)
  871. {
  872. m_quickPaste.ShowQPasteWnd(this, false, false, FALSE);
  873. }
  874. else if(lParam)
  875. {
  876. m_quickPaste.HideQPasteWnd();
  877. }
  878. return TRUE;
  879. }
  880. void CMainFrame::OnDestroy()
  881. {
  882. CFrameWnd::OnDestroy();
  883. if(m_pEditFrameWnd)
  884. {
  885. m_pEditFrameWnd->DestroyWindow();
  886. }
  887. }
  888. void CMainFrame::OnFirstNewclip()
  889. {
  890. CClipIDs IDs;
  891. IDs.Add( - 1);
  892. theApp.EditItems(IDs, true);
  893. }
  894. void CMainFrame::OnFirstOption()
  895. {
  896. if(m_pOptions != NULL)
  897. {
  898. ::SetForegroundWindow(m_pOptions->m_hWnd);
  899. }
  900. else
  901. {
  902. m_pOptions = new COptionsSheet(_T(""));
  903. if(m_pOptions != NULL)
  904. {
  905. ((COptionsSheet*)m_pOptions)->SetNotifyWnd(m_hWnd);
  906. m_pOptions->Create();
  907. m_pOptions->ShowWindow(SW_SHOW);
  908. }
  909. }
  910. }
  911. void CMainFrame::OnFirstGlobalhotkeys()
  912. {
  913. if(m_pGlobalClips != NULL)
  914. {
  915. ::SetForegroundWindow(m_pGlobalClips->m_hWnd);
  916. }
  917. else
  918. {
  919. m_pGlobalClips = new GlobalClips();
  920. CAlphaBlend tran;
  921. tran.SetTransparent(m_hWnd, 0, 1);
  922. if(m_pGlobalClips != NULL)
  923. {
  924. ((GlobalClips*)m_pGlobalClips)->SetNotifyWnd(m_hWnd);
  925. m_pGlobalClips->Create(IDD_GLOBAL_CLIPS, NULL);
  926. m_pGlobalClips->ShowWindow(SW_SHOW);
  927. }
  928. }
  929. }
  930. LRESULT CMainFrame::OnShowOptions(WPARAM wParam, LPARAM lParam)
  931. {
  932. OnFirstOption();
  933. return 0;
  934. }
  935. LRESULT CMainFrame::OnOptionsClosed(WPARAM wParam, LPARAM lParam)
  936. {
  937. m_TrayIcon.MinimiseToTray(this);
  938. CAlphaBlend tran;
  939. tran.SetTransparent(m_hWnd, 255, 0);
  940. delete m_pOptions;
  941. m_pOptions = NULL;
  942. if(m_quickPaste.m_pwndPaste != NULL)
  943. {
  944. m_quickPaste.m_pwndPaste->PostMessage(NM_POST_OPTIONS_WINDOW);
  945. }
  946. return 0;
  947. }
  948. LRESULT CMainFrame::OnGlobalClipsClosed(WPARAM wParam, LPARAM lParam)
  949. {
  950. m_TrayIcon.MinimiseToTray(this);
  951. CAlphaBlend tran;
  952. tran.SetTransparent(m_hWnd, 255, 0);
  953. delete m_pGlobalClips;
  954. m_pGlobalClips = NULL;
  955. return 0;
  956. }
  957. void CMainFrame::RefreshShowInTaskBar()
  958. {
  959. BOOL windowVisible = m_quickPaste.IsWindowVisibleEx();
  960. m_quickPaste.CloseQPasteWnd();
  961. if (windowVisible)
  962. {
  963. m_quickPaste.ShowQPasteWnd(this, true, false, true);
  964. }
  965. }
  966. LRESULT CMainFrame::OnDeleteClipDataClosed(WPARAM wParam, LPARAM lParam)
  967. {
  968. m_TrayIcon.MinimiseToTray(this);
  969. CAlphaBlend tran;
  970. tran.SetTransparent(m_hWnd, 255, 0);
  971. delete m_pDeleteClips;
  972. m_pDeleteClips = NULL;
  973. return 0;
  974. }
  975. void CMainFrame::OnFirstDeleteclipdata()
  976. {
  977. //this->ShowWindow(SW_HIDE);
  978. if (m_pDeleteClips != NULL)
  979. {
  980. ::SetForegroundWindow(m_pDeleteClips->m_hWnd);
  981. }
  982. else
  983. {
  984. m_pDeleteClips = new CDeleteClipData();
  985. CAlphaBlend tran;
  986. tran.SetTransparent(m_hWnd, 0, 1);
  987. if (m_pDeleteClips != NULL)
  988. {
  989. ((CDeleteClipData*) m_pDeleteClips)->SetNotifyWnd(m_hWnd);
  990. m_pDeleteClips->Create(IDD_DELETE_CLIP_DATA, NULL);
  991. m_pDeleteClips->ShowWindow(SW_SHOW);
  992. }
  993. }
  994. }
  995. LRESULT CMainFrame::OnSaveClipboardMessage(WPARAM wParam, LPARAM lParam)
  996. {
  997. OnFirstSavecurrentclipboard();
  998. return TRUE;
  999. }
  1000. void CMainFrame::OnFirstSavecurrentclipboard()
  1001. {
  1002. Log(_T("Start Saving the current clipboard to the database"));
  1003. CClip* pClip = new CClip;
  1004. if(pClip)
  1005. {
  1006. CClipTypes* pTypes = theApp.LoadTypesFromDB();
  1007. if(pTypes)
  1008. {
  1009. if(pClip->LoadFromClipboard(pTypes, false))
  1010. {
  1011. Log(_T("Loaded clips from the clipboard, sending message to save to the db"));
  1012. ::PostMessage(m_hWnd, WM_CLIPBOARD_COPIED, (WPARAM)pClip, 0);
  1013. }
  1014. else
  1015. {
  1016. Log(_T("Failed to load clips from the clipboard, not saving to db"));
  1017. delete pClip;
  1018. pClip = NULL;
  1019. }
  1020. }
  1021. else
  1022. {
  1023. Log(_T("Failed to load supported types from the db, not saving to the db"));
  1024. }
  1025. }
  1026. Log(_T("Start Saving the current clipboard to the database"));
  1027. }
  1028. LRESULT CMainFrame::OnReAddTaskBarIcon(WPARAM wParam, LPARAM lParam)
  1029. {
  1030. if(CGetSetOptions::GetShowIconInSysTray())
  1031. {
  1032. m_TrayIcon.AddIcon();
  1033. }
  1034. return TRUE;
  1035. }
  1036. LRESULT CMainFrame::OnReOpenDatabase(WPARAM wParam, LPARAM lParam)
  1037. {
  1038. Log(StrF(_T("OnReOpenDatabase, Start closing and reopening database Delay: %d"), CGetSetOptions::GetWindowsResumeDelayReOpenDbMS()));
  1039. try
  1040. {
  1041. Sleep(CGetSetOptions::GetWindowsResumeDelayReOpenDbMS());
  1042. m_quickPaste.CloseQPasteWnd();
  1043. theApp.m_db.close();
  1044. OpenDatabase(CGetSetOptions::GetDBPath());
  1045. }
  1046. CATCH_SQLITE_EXCEPTION
  1047. Log(StrF(_T("OnReOpenDatabase, End closing and reopening database Delay: %d"), CGetSetOptions::GetWindowsResumeDelayReOpenDbMS()));
  1048. return TRUE;
  1049. }
  1050. LRESULT CMainFrame::OnShowMsgWindow(WPARAM wParam, LPARAM lParam)
  1051. {
  1052. if(m_pPopupWindow != NULL)
  1053. {
  1054. if(::IsWindow(m_pPopupWindow->m_hWnd))
  1055. {
  1056. m_pPopupWindow->DestroyWindow();
  1057. }
  1058. delete m_pPopupWindow;
  1059. m_pPopupWindow = NULL;
  1060. }
  1061. CString *pMsg = (CString*)wParam;
  1062. int clipId = (int)lParam;
  1063. CRect r;
  1064. GetMonitorRect(0, r);
  1065. m_pPopupWindow = new CDittoPopupWindow();
  1066. m_pPopupWindow->Create(CRect(r.right - 400, r.bottom - 100, r.right - 10, r.bottom - 10), this);
  1067. ::SetWindowPos(m_pPopupWindow->m_hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_SHOWWINDOW);
  1068. m_pPopupWindow->SetWindowText(_T("Saved clip to group"));
  1069. m_pPopupWindow->ShowWindow(SW_SHOW);
  1070. m_pPopupWindow->SetCopyToGroupId(clipId);
  1071. m_pPopupWindow->UpdateText(*pMsg);
  1072. SetTimer(CLOSE_POPUP_MSG_WND, 2500, 0);
  1073. delete pMsg;
  1074. return TRUE;
  1075. }
  1076. LRESULT CMainFrame::OnShowDittoGroup(WPARAM wParam, LPARAM lParam)
  1077. {
  1078. int groupId = (int)wParam;
  1079. CppSQLite3Query q = theApp.m_db.execQueryEx(_T("SELECT bIsGroup FROM Main WHERE lID = %d"), groupId);
  1080. if(q.eof() == false)
  1081. {
  1082. if(q.getIntField(_T("bIsGroup")) > 0)
  1083. {
  1084. PasteOrShowGroup(groupId, FALSE, FALSE, FALSE);
  1085. }
  1086. }
  1087. return TRUE;
  1088. }
  1089. void CMainFrame::OnFirstFixupstickycliporder()
  1090. {
  1091. ReOrderStickyClips(-1, theApp.m_db);
  1092. }
  1093. LRESULT CMainFrame::OnResolutionChange(WPARAM wParam, LPARAM lParam)
  1094. {
  1095. m_quickPaste.OnScreenResolutionChange();
  1096. return TRUE;
  1097. }