MainFrm.cpp 36 KB

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