MainFrm.cpp 38 KB

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