MainFrm.cpp 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059
  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. SetTimer(READ_RANDOM_DB_FILE, g_Opt.ReadRandomFileInterval() * 1000, 0);
  100. SetWindowText(_T("Ditto"));
  101. HICON hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  102. m_TrayIcon.Create(NULL, WM_ICON_NOTIFY, _T("Ditto"), hIcon, IDR_MENU, FALSE, _T(""), _T(""), NULL, 20);
  103. m_TrayIcon.SetSingleClickSelect(TRUE);
  104. m_TrayIcon.MinimiseToTray(this);
  105. m_TrayIcon.SetMenuDefaultItem(ID_FIRST_SHOWQUICKPASTE, FALSE);
  106. //Only if in release
  107. #ifndef _DEBUG
  108. {
  109. //If not showing the icon show it for 40 seconds so they can get to the option
  110. //in case they can't remember the hot keys or something like that
  111. if(!(CGetSetOptions::GetShowIconInSysTray()))
  112. {
  113. SetTimer(HIDE_ICON_TIMER, 40000, 0);
  114. }
  115. }
  116. #endif
  117. //SetTimer(CLOSE_WINDOW_TIMER, ONE_HOUR*24, 0);
  118. SetTimer(REMOVE_OLD_REMOTE_COPIES, ONE_DAY, 0);
  119. SetTimer(REMOVE_OLD_ENTRIES_TIMER, ONE_MINUTE*15, 0);
  120. //found on some computers GetTickCount gettickcount returns a smaller value than other, can't explain
  121. //check here to see if we need to make an adjustment
  122. IdleSeconds();
  123. m_ulCopyGap = CGetSetOptions::GetCopyGap();
  124. theApp.AfterMainCreate();
  125. m_thread.Start(this);
  126. return 0;
  127. }
  128. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT &cs)
  129. {
  130. if(cs.hMenu != NULL)
  131. {
  132. ::DestroyMenu(cs.hMenu); // delete menu if loaded
  133. cs.hMenu = NULL; // no menu for this window
  134. }
  135. if(!CFrameWnd::PreCreateWindow(cs))
  136. {
  137. return FALSE;
  138. }
  139. WNDCLASS wc;
  140. wc.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;
  141. wc.lpfnWndProc = AfxWndProc;
  142. wc.cbClsExtra = 0;
  143. wc.cbWndExtra = 0;
  144. wc.hInstance = AfxGetInstanceHandle();
  145. wc.hIcon = NULL;
  146. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  147. wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
  148. wc.lpszMenuName = NULL;
  149. wc.lpszClassName = _T("Ditto");
  150. // Create the QPaste window class
  151. if(!AfxRegisterClass(&wc))
  152. {
  153. return FALSE;
  154. }
  155. cs.lpszClass = wc.lpszClassName;
  156. return TRUE;
  157. }
  158. /////////////////////////////////////////////////////////////////////////////
  159. // CMainFrame diagnostics
  160. #ifdef _DEBUG
  161. void CMainFrame::AssertValid()const
  162. {
  163. CFrameWnd::AssertValid();
  164. }
  165. void CMainFrame::Dump(CDumpContext &dc)const
  166. {
  167. CFrameWnd::Dump(dc);
  168. }
  169. #endif //_DEBUG
  170. /////////////////////////////////////////////////////////////////////////////
  171. // CMainFrame message handlers
  172. void CMainFrame::OnFirstExit()
  173. {
  174. this->SendMessage(WM_CLOSE, 0, 0);
  175. }
  176. LRESULT CMainFrame::OnHotKey(WPARAM wParam, LPARAM lParam)
  177. {
  178. if(theApp.m_pDittoHotKey && wParam == theApp.m_pDittoHotKey->m_Atom)
  179. {
  180. //If they still have the shift/ctrl keys down
  181. if(m_keyStateModifiers != 0 && m_quickPaste.IsWindowVisibleEx())
  182. {
  183. Log(_T("On Show Ditto HotKey, key state modifiers are still down, moving selection"));
  184. if(m_bMovedSelectionMoveKeyState == false)
  185. {
  186. Log(_T("Setting flag m_bMovedSelectionMoveKeyState to true, will paste when modifer keys are up"));
  187. }
  188. m_quickPaste.MoveSelection(true);
  189. m_bMovedSelectionMoveKeyState = true;
  190. }
  191. else if(g_Opt.m_HideDittoOnHotKeyIfAlreadyShown && m_quickPaste.IsWindowTopLevel() && g_Opt.GetShowPersistent() == FALSE)
  192. {
  193. Log(_T("On Show Ditto HotKey, window is alread visible, hiding window"));
  194. m_quickPaste.HideQPasteWnd();
  195. }
  196. else
  197. {
  198. Log(_T("On Show Ditto HotKey, showing window"));
  199. StartKeyModifyerTimer();
  200. //Before we show our window find the current focused window for paste into
  201. theApp.m_activeWnd.TrackActiveWnd(true);
  202. m_quickPaste.ShowQPasteWnd(this, false, true, FALSE);
  203. }
  204. //KillTimer(CLOSE_WINDOW_TIMER);
  205. //SetTimer(CLOSE_WINDOW_TIMER, ONE_HOUR *24, 0);
  206. }
  207. else if(theApp.m_pPosOne && wParam == theApp.m_pPosOne->m_Atom)
  208. {
  209. Log(_T("Pos 1 hot key"));
  210. DoFirstTenPositionsPaste(0);
  211. }
  212. else if(theApp.m_pPosTwo && wParam == theApp.m_pPosTwo->m_Atom)
  213. {
  214. Log(_T("Pos 2 hot key"));
  215. DoFirstTenPositionsPaste(1);
  216. }
  217. else if(theApp.m_pPosThree && wParam == theApp.m_pPosThree->m_Atom)
  218. {
  219. Log(_T("Pos 3 hot key"));
  220. DoFirstTenPositionsPaste(2);
  221. }
  222. else if(theApp.m_pPosFour && wParam == theApp.m_pPosFour->m_Atom)
  223. {
  224. Log(_T("Pos 4 hot key"));
  225. DoFirstTenPositionsPaste(3);
  226. }
  227. else if(theApp.m_pPosFive && wParam == theApp.m_pPosFive->m_Atom)
  228. {
  229. Log(_T("Pos 5 hot key"));
  230. DoFirstTenPositionsPaste(4);
  231. }
  232. else if(theApp.m_pPosSix && wParam == theApp.m_pPosSix->m_Atom)
  233. {
  234. Log(_T("Pos 6 hot key"));
  235. DoFirstTenPositionsPaste(5);
  236. }
  237. else if(theApp.m_pPosSeven && wParam == theApp.m_pPosSeven->m_Atom)
  238. {
  239. Log(_T("Pos 7 hot key"));
  240. DoFirstTenPositionsPaste(6);
  241. }
  242. else if(theApp.m_pPosEight && wParam == theApp.m_pPosEight->m_Atom)
  243. {
  244. Log(_T("Pos 8 hot key"));
  245. DoFirstTenPositionsPaste(7);
  246. }
  247. else if(theApp.m_pPosNine && wParam == theApp.m_pPosNine->m_Atom)
  248. {
  249. Log(_T("Pos 9 hot key"));
  250. DoFirstTenPositionsPaste(8);
  251. }
  252. else if(theApp.m_pPosTen && wParam == theApp.m_pPosTen->m_Atom)
  253. {
  254. Log(_T("Pos 10 hot key"));
  255. DoFirstTenPositionsPaste(9);
  256. }
  257. else if(theApp.m_pCopyBuffer1 && wParam == theApp.m_pCopyBuffer1->m_Atom)
  258. {
  259. Log(_T("Copy buffer 1 hot key"));
  260. theApp.m_CopyBuffer.StartCopy(0);
  261. }
  262. else if(theApp.m_pPasteBuffer1 && wParam == theApp.m_pPasteBuffer1->m_Atom)
  263. {
  264. Log(_T("Paste buffer 1 hot key"));
  265. theApp.m_CopyBuffer.PastCopyBuffer(0);
  266. }
  267. else if(theApp.m_pCutBuffer1 && wParam == theApp.m_pCutBuffer1->m_Atom)
  268. {
  269. Log(_T("Cut buffer 1 hot key"));
  270. theApp.m_CopyBuffer.StartCopy(0, true);
  271. }
  272. else if(theApp.m_pCopyBuffer2 && wParam == theApp.m_pCopyBuffer2->m_Atom)
  273. {
  274. Log(_T("Copy buffer 2 hot key"));
  275. theApp.m_CopyBuffer.StartCopy(1);
  276. }
  277. else if(theApp.m_pPasteBuffer2 && wParam == theApp.m_pPasteBuffer2->m_Atom)
  278. {
  279. Log(_T("Paste buffer 2 hot key"));
  280. theApp.m_CopyBuffer.PastCopyBuffer(1);
  281. }
  282. else if(theApp.m_pCutBuffer2 && wParam == theApp.m_pCutBuffer2->m_Atom)
  283. {
  284. Log(_T("Cut buffer 2 hot key"));
  285. theApp.m_CopyBuffer.StartCopy(1, true);
  286. }
  287. else if(theApp.m_pCopyBuffer3 && wParam == theApp.m_pCopyBuffer3->m_Atom)
  288. {
  289. Log(_T("Copy buffer 3 hot key"));
  290. theApp.m_CopyBuffer.StartCopy(2);
  291. }
  292. else if(theApp.m_pPasteBuffer3 && wParam == theApp.m_pPasteBuffer3->m_Atom)
  293. {
  294. Log(_T("Paste buffer 3 hot key"));
  295. theApp.m_CopyBuffer.PastCopyBuffer(2);
  296. }
  297. else if(theApp.m_pCutBuffer3 && wParam == theApp.m_pCutBuffer3->m_Atom)
  298. {
  299. Log(_T("Cut buffer 3 hot key"));
  300. theApp.m_CopyBuffer.StartCopy(2, true);
  301. }
  302. else if(theApp.m_pTextOnlyPaste && wParam == theApp.m_pTextOnlyPaste->m_Atom)
  303. {
  304. DoTextOnlyPaste();
  305. }
  306. else
  307. {
  308. for(int i = 0; i < g_HotKeys.GetCount(); i++)
  309. {
  310. if(g_HotKeys[i] != NULL &&
  311. g_HotKeys[i]->m_Atom == wParam &&
  312. g_HotKeys[i]->m_clipId > 0)
  313. {
  314. Log(StrF(_T("Pasting clip from global shortcut, clipId: %d"), g_HotKeys[i]->m_clipId));
  315. PasteOrShowGroup(g_HotKeys[i]->m_clipId, -1, FALSE, TRUE);
  316. break;
  317. }
  318. }
  319. }
  320. return TRUE;
  321. }
  322. void CMainFrame::DoTextOnlyPaste()
  323. {
  324. CClipboardSaveRestore textOnlyPaste;
  325. Log(_T("Text Only paste, saving clipboard to be restored later"));
  326. textOnlyPaste.Save(TRUE);
  327. Log(_T("Text Only paste, Add cf_text or cf_unicodetext to clipboard"));
  328. textOnlyPaste.RestoreTextOnly();
  329. DWORD pasteDelay = g_Opt.GetTextOnlyPasteDelay();
  330. Log(StrF(_T("Text Only paste, delaying %d ms before sending paste"), pasteDelay));
  331. Sleep(pasteDelay);
  332. Log(_T("Text Only paste, Sending paste"));
  333. theApp.m_activeWnd.SendPaste(false);
  334. Log(_T("Text Only paste, Post sending paste"));
  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 READ_RANDOM_DB_FILE:
  485. {
  486. m_thread.FireReadDbFile();
  487. }
  488. break;
  489. }
  490. CFrameWnd::OnTimer(nIDEvent);
  491. }
  492. LRESULT CMainFrame::OnShowTrayIcon(WPARAM wParam, LPARAM lParam)
  493. {
  494. if(lParam)
  495. {
  496. if(!m_TrayIcon.Visible())
  497. {
  498. KillTimer(HIDE_ICON_TIMER);
  499. SetTimer(HIDE_ICON_TIMER, 40000, 0);
  500. }
  501. }
  502. if(wParam)
  503. {
  504. m_TrayIcon.ShowIcon();
  505. }
  506. else
  507. {
  508. m_TrayIcon.HideIcon();
  509. }
  510. return TRUE;
  511. }
  512. void CMainFrame::OnFirstShowquickpaste()
  513. {
  514. m_quickPaste.ShowQPasteWnd(this, false, false, FALSE);
  515. }
  516. void CMainFrame::OnFirstToggleConnectCV()
  517. {
  518. theApp.ToggleConnectCV();
  519. }
  520. void CMainFrame::OnUpdateFirstToggleConnectCV(CCmdUI *pCmdUI)
  521. {
  522. theApp.UpdateMenuConnectCV(pCmdUI->m_pMenu, ID_FIRST_TOGGLECONNECTCV);
  523. }
  524. LRESULT CMainFrame::OnClipboardCopied(WPARAM wParam, LPARAM lParam)
  525. {
  526. Log(_T("Start of function OnClipboardCopied, adding clip to thread for processing"));
  527. CClip *pClip = (CClip*)wParam;
  528. if(pClip != NULL)
  529. {
  530. m_thread.AddClipToSave(pClip);
  531. }
  532. Log(_T("End of function OnClipboardCopied"));
  533. return TRUE;
  534. }
  535. BOOL CMainFrame::PreTranslateMessage(MSG *pMsg)
  536. {
  537. // target before mouse messages change the focus
  538. /*if(theApp.m_bShowingQuickPaste && WM_MOUSEFIRST <= pMsg->message && pMsg->message <= WM_MOUSELAST)
  539. {
  540. theApp.m_activeWnd.TrackActiveWnd(true);
  541. }*/
  542. return CFrameWnd::PreTranslateMessage(pMsg);
  543. }
  544. void CMainFrame::OnClose()
  545. {
  546. CloseAllOpenDialogs();
  547. if(m_pEditFrameWnd)
  548. {
  549. if(m_pEditFrameWnd->CloseAll() == false)
  550. {
  551. return ;
  552. }
  553. }
  554. Log(_T("OnClose - before stop MainFrm thread"));
  555. m_thread.Stop();
  556. Log(_T("OnClose - after stop MainFrm thread"));
  557. theApp.BeforeMainClose();
  558. CFrameWnd::OnClose();
  559. }
  560. bool CMainFrame::CloseAllOpenDialogs()
  561. {
  562. bool bRet = false;
  563. DWORD dwordProcessId;
  564. DWORD dwordChildWindowProcessId;
  565. GetWindowThreadProcessId(this->m_hWnd, &dwordProcessId);
  566. ASSERT(dwordProcessId);
  567. CWnd *pTempWnd = GetDesktopWindow()->GetWindow(GW_CHILD);
  568. while((pTempWnd = pTempWnd->GetWindow(GW_HWNDNEXT)) != NULL)
  569. {
  570. if(pTempWnd->GetSafeHwnd() == NULL)
  571. {
  572. break;
  573. }
  574. GetWindowThreadProcessId(pTempWnd->GetSafeHwnd(), &dwordChildWindowProcessId);
  575. if(dwordChildWindowProcessId == dwordProcessId)
  576. {
  577. TCHAR szTemp[100];
  578. GetClassName(pTempWnd->GetSafeHwnd(), szTemp, 100);
  579. // #32770 is class name for dialogs so don't process the message if it is a dialog
  580. if(STRCMP(szTemp, _T("#32770")) == 0)
  581. {
  582. pTempWnd->SendMessage(WM_CLOSE, 0, 0);
  583. bRet = true;
  584. }
  585. }
  586. }
  587. MSG msg;
  588. while(PeekMessage(&msg, NULL, NULL, NULL, PM_REMOVE))
  589. {
  590. TranslateMessage(&msg);
  591. DispatchMessage(&msg);
  592. }
  593. return bRet;
  594. }
  595. LRESULT CMainFrame::OnSystemTrayMouseMove(WPARAM wParam, LPARAM lParam)
  596. {
  597. theApp.m_activeWnd.TrackActiveWnd(true);
  598. return 0;
  599. }
  600. LRESULT CMainFrame::OnLoadClipOnClipboard(WPARAM wParam, LPARAM lParam)
  601. {
  602. CClip *pClip = (CClip*)wParam;
  603. if(pClip == NULL)
  604. {
  605. LogSendRecieveInfo("---------ERROR OnLoadClipOnClipboard pClip == NULL");
  606. return FALSE;
  607. }
  608. if(pClip)
  609. {
  610. CProcessPaste paste;
  611. paste.m_bSendPaste = false;
  612. paste.m_bActivateTarget = false;
  613. LogSendRecieveInfo("---------OnLoadClipOnClipboard - Before PutFormats on clipboard");
  614. paste.m_pOle->PutFormatOnClipboard(&pClip->m_Formats);
  615. paste.m_pOle->CacheGlobalData(theApp.m_cfIgnoreClipboard, NewGlobalP("Ignore", sizeof("Ignore")));
  616. LogSendRecieveInfo("---------OnLoadClipOnClipboard - After PutFormats on clipboard");
  617. LogSendRecieveInfo(StrF(_T("---------OnLoadClipOnClipboard - Setting clip id: %d on ole clipboard"), pClip->m_id));
  618. paste.GetClipIDs().Add(pClip->m_id);
  619. paste.DoPaste();
  620. LogSendRecieveInfo(StrF(_T("---------OnLoadClipOnClipboard - After paste clip id: %d on ole clipboard"), pClip->m_id));
  621. }
  622. delete pClip;
  623. return TRUE;
  624. }
  625. LRESULT CMainFrame::OnAddToDatabaseFromSocket(WPARAM wParam, LPARAM lParam)
  626. {
  627. CClipList *pClipList = (CClipList*)wParam;
  628. if(pClipList == NULL)
  629. {
  630. LogSendRecieveInfo("---------OnAddToDatabaseFromSocket - ERROR pClipList == NULL");
  631. return FALSE;
  632. }
  633. BOOL bSetToClipBoard = (BOOL)lParam;
  634. if(bSetToClipBoard)
  635. {
  636. CClip *pClip = pClipList->GetTail();
  637. if(pClip)
  638. {
  639. LogSendRecieveInfo("OnAddToDatabaseFromSocket - Adding clip from socket setting clip to be put on clipboard");
  640. pClip->m_param1 = TRUE;
  641. }
  642. }
  643. m_thread.AddRemoteClipToSave(pClipList);
  644. delete pClipList;
  645. return TRUE;
  646. }
  647. LRESULT CMainFrame::OnErrorOnSendRecieve(WPARAM wParam, LPARAM lParam)
  648. {
  649. CString csNewText = (TCHAR*)wParam;
  650. ShowErrorMessage(_T("Ditto - Send/Receive Error"), csNewText);
  651. return TRUE;
  652. }
  653. CString WndName(HWND hParent)
  654. {
  655. TCHAR cWindowText[200];
  656. ::GetWindowText(hParent, cWindowText, 100);
  657. int nCount = 0;
  658. while(STRLEN(cWindowText) <= 0)
  659. {
  660. hParent = ::GetParent(hParent);
  661. if(hParent == NULL)
  662. {
  663. break;
  664. }
  665. ::GetWindowText(hParent, cWindowText, 100);
  666. nCount++;
  667. if(nCount > 100)
  668. {
  669. Log(_T("GetTargetName reached maximum search depth of 100"));
  670. break;
  671. }
  672. }
  673. return cWindowText;
  674. }
  675. void CMainFrame::OnFirstHelp()
  676. {
  677. CString csFile = CGetSetOptions::GetPath(PATH_HELP);
  678. csFile += "DittoGettingStarted.htm";
  679. CHyperLink::GotoURL(csFile, SW_SHOW);
  680. }
  681. LRESULT CMainFrame::OnCustomizeTrayMenu(WPARAM wParam, LPARAM lParam)
  682. {
  683. CMenu *pMenu = (CMenu*)wParam;
  684. if(pMenu)
  685. {
  686. theApp.m_Language.UpdateTrayIconRightClickMenu(pMenu);
  687. }
  688. return true;
  689. }
  690. void CMainFrame::ShowErrorMessage(CString csTitle, CString csMessage)
  691. {
  692. Log(StrF(_T("ShowErrorMessage %s - %s"), csTitle, csMessage));
  693. CToolTipEx *pErrorWnd = new CToolTipEx;
  694. pErrorWnd->Create(this);
  695. pErrorWnd->SetToolTipText(csTitle + "\n\n" + csMessage);
  696. CPoint pt;
  697. CRect rcScreen;
  698. GetMonitorRect(0, &rcScreen);
  699. pt = rcScreen.BottomRight();
  700. CRect cr = pErrorWnd->GetBoundsRect();
  701. pt.x -= max(cr.Width() + 50, 150);
  702. pt.y -= max(cr.Height() + 50, 150);
  703. pErrorWnd->Show(pt);
  704. pErrorWnd->HideWindowInXMilliSeconds(4000);
  705. }
  706. void CMainFrame::OnFirstImport()
  707. {
  708. theApp.ImportClips(theApp.m_MainhWnd);
  709. }
  710. void CMainFrame::ShowEditWnd(CClipIDs &Ids)
  711. {
  712. CWaitCursor wait;
  713. bool bCreatedWindow = false;
  714. if(m_pEditFrameWnd == NULL)
  715. {
  716. m_pEditFrameWnd = new CEditFrameWnd;
  717. m_pEditFrameWnd->LoadFrame(IDR_MAINFRAME);
  718. bCreatedWindow = true;
  719. }
  720. if(m_pEditFrameWnd)
  721. {
  722. m_pEditFrameWnd->EditIds(Ids);
  723. m_pEditFrameWnd->SetNotifyWnd(m_hWnd);
  724. if(bCreatedWindow)
  725. {
  726. CSize sz;
  727. CPoint pt;
  728. CGetSetOptions::GetEditWndSize(sz);
  729. CGetSetOptions::GetEditWndPoint(pt);
  730. CRect cr(pt, sz);
  731. EnsureWindowVisible(&cr);
  732. m_pEditFrameWnd->MoveWindow(cr);
  733. }
  734. m_pEditFrameWnd->ShowWindow(SW_SHOW);
  735. m_pEditFrameWnd->SetForegroundWindow();
  736. m_pEditFrameWnd->SetFocus();
  737. }
  738. }
  739. LRESULT CMainFrame::OnEditWndClose(WPARAM wParam, LPARAM lParam)
  740. {
  741. m_pEditFrameWnd = NULL;
  742. return TRUE;
  743. }
  744. LRESULT CMainFrame::OnSetConnected(WPARAM wParam, LPARAM lParam)
  745. {
  746. if(wParam)
  747. {
  748. theApp.SetConnectCV(true);
  749. }
  750. else if(lParam)
  751. {
  752. theApp.SetConnectCV(false);
  753. }
  754. return TRUE;
  755. }
  756. LRESULT CMainFrame::OnOpenCloseWindow(WPARAM wParam, LPARAM lParam)
  757. {
  758. if(wParam)
  759. {
  760. m_quickPaste.ShowQPasteWnd(this, false, false, FALSE);
  761. }
  762. else if(lParam)
  763. {
  764. m_quickPaste.HideQPasteWnd();
  765. }
  766. return TRUE;
  767. }
  768. void CMainFrame::OnDestroy()
  769. {
  770. CFrameWnd::OnDestroy();
  771. if(m_pEditFrameWnd)
  772. {
  773. m_pEditFrameWnd->DestroyWindow();
  774. }
  775. }
  776. void CMainFrame::OnFirstNewclip()
  777. {
  778. CClipIDs IDs;
  779. IDs.Add( - 1);
  780. theApp.EditItems(IDs, true);
  781. }
  782. void CMainFrame::OnFirstOption()
  783. {
  784. if(m_pOptions != NULL)
  785. {
  786. ::SetForegroundWindow(m_pOptions->m_hWnd);
  787. }
  788. else
  789. {
  790. m_pOptions = new COptionsSheet(_T(""));
  791. if(m_pOptions != NULL)
  792. {
  793. ((COptionsSheet*)m_pOptions)->SetNotifyWnd(m_hWnd);
  794. m_pOptions->Create();
  795. m_pOptions->ShowWindow(SW_SHOW);
  796. }
  797. }
  798. }
  799. void CMainFrame::OnFirstGlobalhotkeys()
  800. {
  801. if(m_pGlobalClips != NULL)
  802. {
  803. ::SetForegroundWindow(m_pGlobalClips->m_hWnd);
  804. }
  805. else
  806. {
  807. m_pGlobalClips = new GlobalClips();
  808. CAlphaBlend tran;
  809. tran.SetTransparent(m_hWnd, 0, 1);
  810. if(m_pGlobalClips != NULL)
  811. {
  812. ((GlobalClips*)m_pGlobalClips)->SetNotifyWnd(m_hWnd);
  813. m_pGlobalClips->Create(IDD_GLOBAL_CLIPS, NULL);
  814. m_pGlobalClips->ShowWindow(SW_SHOW);
  815. }
  816. }
  817. }
  818. LRESULT CMainFrame::OnShowOptions(WPARAM wParam, LPARAM lParam)
  819. {
  820. OnFirstOption();
  821. return 0;
  822. }
  823. LRESULT CMainFrame::OnOptionsClosed(WPARAM wParam, LPARAM lParam)
  824. {
  825. m_TrayIcon.MinimiseToTray(this);
  826. CAlphaBlend tran;
  827. tran.SetTransparent(m_hWnd, 255, 0);
  828. delete m_pOptions;
  829. m_pOptions = NULL;
  830. if(m_quickPaste.m_pwndPaste != NULL)
  831. {
  832. m_quickPaste.m_pwndPaste->PostMessage(NM_POST_OPTIONS_WINDOW);
  833. }
  834. return 0;
  835. }
  836. LRESULT CMainFrame::OnGlobalClipsClosed(WPARAM wParam, LPARAM lParam)
  837. {
  838. m_TrayIcon.MinimiseToTray(this);
  839. CAlphaBlend tran;
  840. tran.SetTransparent(m_hWnd, 255, 0);
  841. delete m_pGlobalClips;
  842. m_pGlobalClips = NULL;
  843. return 0;
  844. }
  845. void CMainFrame::RefreshShowInTaskBar()
  846. {
  847. BOOL windowVisible = m_quickPaste.IsWindowVisibleEx();
  848. m_quickPaste.CloseQPasteWnd();
  849. if (windowVisible)
  850. {
  851. m_quickPaste.ShowQPasteWnd(this, true, false, true);
  852. }
  853. }
  854. LRESULT CMainFrame::OnDeleteClipDataClosed(WPARAM wParam, LPARAM lParam)
  855. {
  856. m_TrayIcon.MinimiseToTray(this);
  857. CAlphaBlend tran;
  858. tran.SetTransparent(m_hWnd, 255, 0);
  859. delete m_pDeleteClips;
  860. m_pDeleteClips = NULL;
  861. return 0;
  862. }
  863. void CMainFrame::OnFirstDeleteclipdata()
  864. {
  865. //this->ShowWindow(SW_HIDE);
  866. if (m_pDeleteClips != NULL)
  867. {
  868. ::SetForegroundWindow(m_pDeleteClips->m_hWnd);
  869. }
  870. else
  871. {
  872. m_pDeleteClips = new CDeleteClipData();
  873. CAlphaBlend tran;
  874. tran.SetTransparent(m_hWnd, 0, 1);
  875. if (m_pDeleteClips != NULL)
  876. {
  877. ((CDeleteClipData*) m_pDeleteClips)->SetNotifyWnd(m_hWnd);
  878. m_pDeleteClips->Create(IDD_DELETE_CLIP_DATA, NULL);
  879. m_pDeleteClips->ShowWindow(SW_SHOW);
  880. }
  881. }
  882. }