MainFrm.cpp 36 KB

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