MainFrm.cpp 28 KB

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