MainFrm.cpp 36 KB

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