MainFrm.cpp 35 KB

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