MainFrm.cpp 29 KB

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