MainFrm.cpp 38 KB

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