MainFrm.cpp 41 KB

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