MainFrm.cpp 36 KB

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