MainFrm.cpp 27 KB

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