MainFrm.cpp 37 KB

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