MainFrm.cpp 34 KB

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