MainFrm.cpp 37 KB

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