MainFrm.cpp 40 KB

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