MainFrm.cpp 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297
  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 "focusdll\focusdll.h"
  12. #include "HyperLink.h"
  13. #include "tinyxml.h"
  14. #include "Path.h"
  15. #include "DittoCopyBuffer.h"
  16. #ifdef _DEBUG
  17. #define new DEBUG_NEW
  18. #undef THIS_FILE
  19. static char THIS_FILE[] = __FILE__;
  20. #endif
  21. #define WM_ICON_NOTIFY WM_APP+10
  22. #define MYWM_NOTIFYICON (WM_USER+1)
  23. bool CShowMainFrame::m_bShowingMainFrame = false;
  24. CShowMainFrame::CShowMainFrame() :
  25. m_bHideMainFrameOnExit(false),
  26. m_hWnd(NULL)
  27. {
  28. if(m_bShowingMainFrame == false)
  29. {
  30. theApp.m_pMainFrame->m_TrayIcon.MaximiseFromTray(theApp.m_pMainFrame);
  31. m_bHideMainFrameOnExit = true;
  32. m_bShowingMainFrame = true;
  33. }
  34. m_hWnd = theApp.m_pMainFrame->GetSafeHwnd();
  35. }
  36. CShowMainFrame::~CShowMainFrame()
  37. {
  38. if(m_bHideMainFrameOnExit && m_hWnd && ::IsWindow(m_hWnd))
  39. {
  40. theApp.m_pMainFrame->m_TrayIcon.MinimiseToTray(theApp.m_pMainFrame);
  41. m_bShowingMainFrame = false;
  42. }
  43. }
  44. IMPLEMENT_DYNAMIC(CMainFrame, CFrameWnd)
  45. BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
  46. //{{AFX_MSG_MAP(CMainFrame)
  47. ON_WM_CREATE()
  48. ON_COMMAND(ID_FIRST_OPTION, OnFirstOption)
  49. ON_COMMAND(ID_FIRST_EXIT, OnFirstExit)
  50. ON_WM_TIMER()
  51. ON_COMMAND(ID_FIRST_SHOWQUICKPASTE, OnFirstShowquickpaste)
  52. ON_COMMAND(ID_FIRST_TOGGLECONNECTCV, OnFirstToggleConnectCV)
  53. ON_UPDATE_COMMAND_UI(ID_FIRST_TOGGLECONNECTCV, OnUpdateFirstToggleConnectCV)
  54. ON_COMMAND(ID_FIRST_HELP, OnFirstHelp)
  55. //}}AFX_MSG_MAP
  56. ON_MESSAGE(WM_HOTKEY, OnHotKey)
  57. ON_MESSAGE(WM_SHOW_TRAY_ICON, OnShowTrayIcon)
  58. ON_MESSAGE(WM_COPYPROPERTIES, OnCopyProperties)
  59. ON_MESSAGE(WM_CLOSE_APP, OnShutDown)
  60. ON_MESSAGE(WM_CLIPBOARD_COPIED, OnClipboardCopied)
  61. ON_WM_CLOSE()
  62. ON_MESSAGE(WM_ADD_TO_DATABASE_FROM_SOCKET, OnAddToDatabaseFromSocket)
  63. ON_MESSAGE(WM_SEND_RECIEVE_ERROR, OnErrorOnSendRecieve)
  64. ON_MESSAGE(WM_FOCUS_CHANGED, OnFocusChanged)
  65. ON_MESSAGE(WM_FOCUS_CHANGED+1, OnKeyBoardChanged)
  66. ON_MESSAGE(WM_CUSTOMIZE_TRAY_MENU, OnCustomizeTrayMenu)
  67. ON_COMMAND(ID_FIRST_IMPORT, OnFirstImport)
  68. ON_MESSAGE(WM_EDIT_WND_CLOSING, OnEditWndClose)
  69. ON_WM_DESTROY()
  70. ON_COMMAND(ID_FIRST_NEWCLIP, OnFirstNewclip)
  71. ON_MESSAGE(WM_SET_CONNECTED, OnSetConnected)
  72. ON_MESSAGE(MYWM_NOTIFYICON, OnTrayNotify)
  73. END_MESSAGE_MAP()
  74. static UINT indicators[] =
  75. {
  76. ID_SEPARATOR, // status line indicator
  77. ID_INDICATOR_CAPS,
  78. ID_INDICATOR_NUM,
  79. ID_INDICATOR_SCRL,
  80. };
  81. /////////////////////////////////////////////////////////////////////////////
  82. // CMainFrame construction/destruction
  83. CMainFrame::CMainFrame()
  84. {
  85. m_pEditFrameWnd = NULL;
  86. m_keyStateModifiers = 0;
  87. m_startKeyStateTime = 0;
  88. m_bMovedSelectionMoveKeyState = false;
  89. m_keyModifiersTimerCount = 0;
  90. }
  91. CMainFrame::~CMainFrame()
  92. {
  93. if(g_Opt.m_bUseHookDllForFocus)
  94. {
  95. Log(_T("Unloading focus dll for tracking focus changes"));
  96. StopMonitoringFocusChanges();
  97. }
  98. CGetSetOptions::SetMainHWND(0);
  99. }
  100. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  101. {
  102. if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
  103. return -1;
  104. //Center the main window so message boxes are in the center
  105. CRect rcScreen;
  106. GetMonitorRect(0, &rcScreen);
  107. CPoint cpCenter = rcScreen.CenterPoint();
  108. MoveWindow(cpCenter.x,cpCenter.x, -2, -2);
  109. //Then set the main window to transparent so it's never shown
  110. //if it is shown then only the task tray icon
  111. m_Transparency.SetTransparent(m_hWnd, 0, true);
  112. SetWindowText(_T(""));
  113. if(g_Opt.m_bUseHookDllForFocus)
  114. {
  115. Log(_T("Loading hook dll to track focus changes"));
  116. MonitorFocusChanges(m_hWnd, WM_FOCUS_CHANGED);
  117. }
  118. else
  119. {
  120. Log(_T("Setting polling timer to track focus"));
  121. SetTimer(ACTIVE_WINDOW_TIMER, g_Opt.FocusWndTimerTimeout(), 0);
  122. }
  123. SetWindowText(_T("Ditto"));
  124. HICON hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  125. m_TrayIcon.Create(NULL, // Let icon deal with its own messages
  126. WM_ICON_NOTIFY, // Icon notify message to use
  127. _T("Ditto"), // tooltip
  128. hIcon,
  129. IDR_MENU, // ID of tray icon
  130. FALSE,
  131. _T(""), // balloon tip
  132. _T(""), // balloon title
  133. NULL, // balloon icon
  134. 20 );
  135. m_TrayIcon.SetSingleClickSelect(TRUE);
  136. m_TrayIcon.MinimiseToTray(this);
  137. m_TrayIcon.SetMenuDefaultItem(ID_FIRST_SHOWQUICKPASTE, FALSE);
  138. //Only if in release
  139. #ifndef _DEBUG
  140. {
  141. //If not showing the icon show it for 40 seconds so they can get to the option
  142. //in case they can't remember the hot keys or something like that
  143. if(!(CGetSetOptions::GetShowIconInSysTray()))
  144. SetTimer(HIDE_ICON_TIMER, 40000, 0);
  145. }
  146. #endif
  147. //don't check for updates if running from a U3 device
  148. if(!g_Opt.m_bU3)
  149. {
  150. SetTimer(CHECK_FOR_UPDATE, ONE_MINUTE*5, 0);
  151. }
  152. SetTimer(CLOSE_WINDOW_TIMER, ONE_MINUTE*60, 0);
  153. SetTimer(REMOVE_OLD_REMOTE_COPIES, ONE_DAY, 0);
  154. SetTimer(REMOVE_OLD_ENTRIES_TIMER, 3000, 0);
  155. m_ulCopyGap = CGetSetOptions::GetCopyGap();
  156. theApp.AfterMainCreate();
  157. m_thread.Start(this);
  158. return 0;
  159. }
  160. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  161. {
  162. if(cs.hMenu!=NULL)
  163. {
  164. ::DestroyMenu(cs.hMenu); // delete menu if loaded
  165. cs.hMenu = NULL; // no menu for this window
  166. }
  167. if( !CFrameWnd::PreCreateWindow(cs) )
  168. return FALSE;
  169. WNDCLASS wc;
  170. wc.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;
  171. wc.lpfnWndProc = AfxWndProc;
  172. wc.cbClsExtra = 0;
  173. wc.cbWndExtra = 0;
  174. wc.hInstance = AfxGetInstanceHandle();
  175. wc.hIcon = NULL;
  176. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  177. wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
  178. wc.lpszMenuName = NULL;
  179. wc.lpszClassName = _T("Ditto");
  180. // Create the QPaste window class
  181. if (!AfxRegisterClass(&wc))
  182. return FALSE;
  183. cs.lpszClass = wc.lpszClassName;
  184. return TRUE;
  185. }
  186. /////////////////////////////////////////////////////////////////////////////
  187. // CMainFrame diagnostics
  188. #ifdef _DEBUG
  189. void CMainFrame::AssertValid() const
  190. {
  191. CFrameWnd::AssertValid();
  192. }
  193. void CMainFrame::Dump(CDumpContext& dc) const
  194. {
  195. CFrameWnd::Dump(dc);
  196. }
  197. #endif //_DEBUG
  198. /////////////////////////////////////////////////////////////////////////////
  199. // CMainFrame message handlers
  200. void CMainFrame::OnFirstOption()
  201. {
  202. theApp.ShowOptionsDlg();
  203. }
  204. void CMainFrame::OnFirstExit()
  205. {
  206. // CloseAllOpenDialogs();
  207. this->SendMessage(WM_CLOSE, 0, 0);
  208. }
  209. LRESULT CMainFrame::OnHotKey(WPARAM wParam, LPARAM lParam)
  210. {
  211. if(theApp.m_pDittoHotKey && wParam == theApp.m_pDittoHotKey->m_Atom)
  212. {
  213. //If they still have the shift/ctrl keys down
  214. if(m_keyStateModifiers != 0 && m_quickPaste.IsWindowVisibleEx())
  215. {
  216. if(m_bMovedSelectionMoveKeyState == false)
  217. {
  218. Log(_T("Setting flag m_bMovedSelectionMoveKeyState to true, will paste when modifer keys are up"));
  219. }
  220. m_quickPaste.MoveSelection(true);
  221. m_bMovedSelectionMoveKeyState = true;
  222. }
  223. else if(g_Opt.m_HideDittoOnHotKeyIfAlreadyShown && m_quickPaste.IsWindowVisibleEx())
  224. {
  225. m_quickPaste.HideQPasteWnd();
  226. }
  227. else
  228. {
  229. m_keyModifiersTimerCount = 0;
  230. m_bMovedSelectionMoveKeyState = false;
  231. m_startKeyStateTime = GetTickCount();
  232. m_keyStateModifiers = GetKeyStateModifiers();
  233. SetTimer(KEY_STATE_MODIFIERS, 50, NULL);
  234. theApp.m_activeWnd.TrackActiveWnd(NULL);
  235. m_quickPaste.ShowQPasteWnd(this, false, true, FALSE);
  236. }
  237. }
  238. else if(theApp.m_pNamedCopy && wParam == theApp.m_pNamedCopy->m_Atom)
  239. {
  240. if(g_Opt.m_bU3 == false)
  241. {
  242. if(theApp.m_QuickPasteMode == CCP_MainApp::NONE_QUICK_PASTE)
  243. {
  244. theApp.m_QuickPasteMode = CCP_MainApp::ADDING_QUICK_PASTE;
  245. theApp.m_activeWnd.SendCopy();
  246. m_pTypingToolTip = new CToolTipEx;
  247. m_pTypingToolTip->Create(this);
  248. csTypeToolTipTitle = theApp.m_Language.GetString("Named_Copy_Title", "Ditto - Named Copy");
  249. m_pTypingToolTip->SetToolTipText(csTypeToolTipTitle);
  250. CRect rcScreen;
  251. GetMonitorRect(0, &rcScreen);
  252. m_ToolTipPoint = theApp.m_activeWnd.FocusCaret();
  253. if(m_ToolTipPoint.x < 0 || m_ToolTipPoint.y < 0)
  254. {
  255. CRect cr;
  256. ::GetWindowRect(theApp.m_activeWnd.FocusWnd(), cr);
  257. m_ToolTipPoint = cr.CenterPoint();
  258. }
  259. m_ToolTipPoint.Offset(-15, 15);
  260. m_pTypingToolTip->Show(m_ToolTipPoint);
  261. //If they don't type anything for 2 seconds stop looking
  262. SetTimer(STOP_LOOKING_FOR_KEYBOARD, 20000, NULL);
  263. MonitorKeyboardChanges(m_hWnd, WM_FOCUS_CHANGED+1);
  264. SetCaptureKeys(true);
  265. }
  266. }
  267. }
  268. else if(theApp.m_pNamedPaste && wParam == theApp.m_pNamedPaste->m_Atom)
  269. {
  270. if(g_Opt.m_bU3 == false)
  271. {
  272. if(theApp.m_QuickPasteMode == CCP_MainApp::NONE_QUICK_PASTE)
  273. {
  274. theApp.m_QuickPasteMode = CCP_MainApp::PASTING_QUICK_PASTE;
  275. m_pTypingToolTip = new CToolTipEx;
  276. m_pTypingToolTip->Create(this);
  277. csTypeToolTipTitle = theApp.m_Language.GetString("Named_Paste_Title", "Ditto - Named Paste");
  278. m_pTypingToolTip->SetToolTipText(csTypeToolTipTitle);
  279. CRect rcScreen;
  280. m_ToolTipPoint = theApp.m_activeWnd.FocusCaret();
  281. if(m_ToolTipPoint.x < 0 || m_ToolTipPoint.y < 0)
  282. {
  283. CRect cr;
  284. ::GetWindowRect(theApp.m_activeWnd.FocusWnd(), cr);
  285. m_ToolTipPoint = cr.CenterPoint();
  286. }
  287. m_ToolTipPoint.Offset(-15, 15);
  288. m_pTypingToolTip->Show(m_ToolTipPoint);
  289. //If they don't type anything for 2 seconds stop looking
  290. SetTimer(STOP_LOOKING_FOR_KEYBOARD, 20000, NULL);
  291. MonitorKeyboardChanges(m_hWnd, WM_FOCUS_CHANGED+1);
  292. SetCaptureKeys(true);
  293. }
  294. }
  295. }
  296. else if(theApp.m_pPosOne && wParam == theApp.m_pPosOne->m_Atom)
  297. {
  298. DoFirstTenPositionsPaste(0);
  299. }
  300. else if(theApp.m_pPosTwo && wParam == theApp.m_pPosTwo->m_Atom)
  301. {
  302. DoFirstTenPositionsPaste(1);
  303. }
  304. else if(theApp.m_pPosThree && wParam == theApp.m_pPosThree->m_Atom)
  305. {
  306. DoFirstTenPositionsPaste(2);
  307. }
  308. else if(theApp.m_pPosFour && wParam == theApp.m_pPosFour->m_Atom)
  309. {
  310. DoFirstTenPositionsPaste(3);
  311. }
  312. else if(theApp.m_pPosFive && wParam == theApp.m_pPosFive->m_Atom)
  313. {
  314. DoFirstTenPositionsPaste(4);
  315. }
  316. else if(theApp.m_pPosSix && wParam == theApp.m_pPosSix->m_Atom)
  317. {
  318. DoFirstTenPositionsPaste(5);
  319. }
  320. else if(theApp.m_pPosSeven && wParam == theApp.m_pPosSeven->m_Atom)
  321. {
  322. DoFirstTenPositionsPaste(6);
  323. }
  324. else if(theApp.m_pPosEight && wParam == theApp.m_pPosEight->m_Atom)
  325. {
  326. DoFirstTenPositionsPaste(7);
  327. }
  328. else if(theApp.m_pPosNine && wParam == theApp.m_pPosNine->m_Atom)
  329. {
  330. DoFirstTenPositionsPaste(8);
  331. }
  332. else if(theApp.m_pPosTen && wParam == theApp.m_pPosTen->m_Atom)
  333. {
  334. DoFirstTenPositionsPaste(9);
  335. }
  336. else if(theApp.m_pCopyBuffer1 && wParam == theApp.m_pCopyBuffer1->m_Atom)
  337. {
  338. theApp.m_CopyBuffer.StartCopy(0);
  339. }
  340. else if(theApp.m_pPasteBuffer1 && wParam == theApp.m_pPasteBuffer1->m_Atom)
  341. {
  342. theApp.m_CopyBuffer.PastCopyBuffer(0);
  343. }
  344. else if(theApp.m_pCutBuffer1 && wParam == theApp.m_pCutBuffer1->m_Atom)
  345. {
  346. theApp.m_CopyBuffer.StartCopy(0, true);
  347. }
  348. else if(theApp.m_pCopyBuffer2 && wParam == theApp.m_pCopyBuffer2->m_Atom)
  349. {
  350. theApp.m_CopyBuffer.StartCopy(1);
  351. }
  352. else if(theApp.m_pPasteBuffer2 && wParam == theApp.m_pPasteBuffer2->m_Atom)
  353. {
  354. theApp.m_CopyBuffer.PastCopyBuffer(1);
  355. }
  356. else if(theApp.m_pCutBuffer2 && wParam == theApp.m_pCutBuffer2->m_Atom)
  357. {
  358. theApp.m_CopyBuffer.StartCopy(1, true);
  359. }
  360. else if(theApp.m_pCopyBuffer3 && wParam == theApp.m_pCopyBuffer3->m_Atom)
  361. {
  362. theApp.m_CopyBuffer.StartCopy(2);
  363. }
  364. else if(theApp.m_pPasteBuffer3 && wParam == theApp.m_pPasteBuffer3->m_Atom)
  365. {
  366. theApp.m_CopyBuffer.PastCopyBuffer(2);
  367. }
  368. else if(theApp.m_pCutBuffer3 && wParam == theApp.m_pCutBuffer3->m_Atom)
  369. {
  370. theApp.m_CopyBuffer.StartCopy(2, true);
  371. }
  372. return TRUE;
  373. }
  374. void CMainFrame::DoFirstTenPositionsPaste(int nPos)
  375. {
  376. try
  377. {
  378. CppSQLite3Query q = theApp.m_db.execQueryEx(_T("SELECT lID, bIsGroup, lDate FROM Main ")
  379. _T("WHERE ((bIsGroup = 1 AND lParentID = -1) OR bIsGroup = 0) ")
  380. _T("ORDER BY bIsGroup ASC, lDate DESC ")
  381. _T("LIMIT 1 OFFSET %d"), nPos);
  382. if(q.eof() == false)
  383. {
  384. if(q.getIntField(_T("bIsGroup")) == FALSE)
  385. {
  386. //Don't move these to the top
  387. BOOL bItWas = g_Opt.m_bUpdateTimeOnPaste;
  388. g_Opt.m_bUpdateTimeOnPaste = FALSE;
  389. CProcessPaste paste;
  390. paste.GetClipIDs().Add(q.getIntField(_T("lID")));
  391. paste.m_bActivateTarget = false;
  392. paste.m_bSendPaste = g_Opt.m_bSendPasteOnFirstTenHotKeys ? true : false;
  393. paste.DoPaste();
  394. theApp.OnPasteCompleted();
  395. g_Opt.m_bUpdateTimeOnPaste = bItWas;
  396. }
  397. }
  398. }
  399. CATCH_SQLITE_EXCEPTION
  400. }
  401. void CMainFrame::DoDittoCopyBufferPaste(int nCopyBuffer)
  402. {
  403. try
  404. {
  405. CppSQLite3Query q = theApp.m_db.execQueryEx(_T("SELECT lID FROM Main WHERE CopyBuffer = %d"), nCopyBuffer);
  406. if(q.eof() == false)
  407. {
  408. //Don't move these to the top
  409. BOOL bItWas = g_Opt.m_bUpdateTimeOnPaste;
  410. g_Opt.m_bUpdateTimeOnPaste = FALSE;
  411. CProcessPaste paste;
  412. paste.GetClipIDs().Add(q.getIntField(_T("lID")));
  413. paste.m_bActivateTarget = false;
  414. paste.DoPaste();
  415. theApp.OnPasteCompleted();
  416. g_Opt.m_bUpdateTimeOnPaste = bItWas;
  417. }
  418. }
  419. CATCH_SQLITE_EXCEPTION
  420. }
  421. void CMainFrame::OnTimer(UINT nIDEvent)
  422. {
  423. switch(nIDEvent)
  424. {
  425. case HIDE_ICON_TIMER:
  426. {
  427. m_TrayIcon.HideIcon();
  428. KillTimer(nIDEvent);
  429. break;
  430. }
  431. case CLOSE_WINDOW_TIMER:
  432. {
  433. m_quickPaste.CloseQPasteWnd();
  434. break;
  435. }
  436. case REMOVE_OLD_ENTRIES_TIMER:
  437. {
  438. m_thread.FireDeleteEntries();
  439. break;
  440. }
  441. case CHECK_FOR_UPDATE:
  442. {
  443. KillTimer(CHECK_FOR_UPDATE);
  444. CInternetUpdate Update;
  445. if(Update.CheckForUpdate(NULL, TRUE, FALSE))
  446. {
  447. PostMessage(WM_CLOSE, 0, 0);
  448. }
  449. else
  450. {
  451. SetTimer(CHECK_FOR_UPDATE, ONE_MINUTE*60*24, NULL);
  452. }
  453. break;
  454. }
  455. case CLOSE_APP:
  456. {
  457. PostMessage(WM_CLOSE, 0, 0);
  458. KillTimer(CLOSE_APP);
  459. break;
  460. }
  461. case STOP_MONITORING_KEYBOARD_TIMER:
  462. {
  463. StopLookingForKeystrokes(false);
  464. if(m_csKeyboardPaste.IsEmpty() == FALSE)
  465. {
  466. if(theApp.m_QuickPasteMode == CCP_MainApp::PASTING_QUICK_PASTE)
  467. {
  468. PasteQuickPasteEntry(m_csKeyboardPaste);
  469. }
  470. else
  471. {
  472. SaveQuickPasteEntry(m_csKeyboardPaste, theApp.m_pQuickPasteClip);
  473. }
  474. StopLookingForKeystrokes(true);
  475. }
  476. break;
  477. }
  478. case STOP_LOOKING_FOR_KEYBOARD:
  479. {
  480. if(theApp.m_QuickPasteMode == CCP_MainApp::ADDING_QUICK_PASTE)
  481. {
  482. SaveQuickPasteEntry(m_csKeyboardPaste, theApp.m_pQuickPasteClip);
  483. }
  484. //They didn't type anything within 2 seconds stop looking
  485. StopLookingForKeystrokes(true);
  486. break;
  487. }
  488. case REMOVE_OLD_REMOTE_COPIES:
  489. AfxBeginThread(CMainFrame::RemoteOldRemoteFilesThread, NULL);
  490. break;
  491. case KEY_STATE_MODIFIERS:
  492. m_keyModifiersTimerCount++;
  493. if(m_keyStateModifiers != 0)
  494. {
  495. BYTE keyState = GetKeyStateModifiers();
  496. //Have they release the key state modifiers yet(ctrl, shift, alt)
  497. if((m_keyStateModifiers & keyState) == 0)
  498. {
  499. KillTimer(KEY_STATE_MODIFIERS);
  500. long waitTime = (long)(GetTickCount() - m_startKeyStateTime);
  501. if(m_bMovedSelectionMoveKeyState || m_keyModifiersTimerCount > g_Opt.GetKeyStateWaitTimerCount())
  502. {
  503. 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));
  504. m_quickPaste.OnKeyStateUp();
  505. }
  506. else
  507. {
  508. Log(StrF(_T("Timer KEY_STATE_MODIFIERS count NOT hit(%d), count (%d) time (%d)"), g_Opt.GetKeyStateWaitTimerCount(), m_keyModifiersTimerCount, waitTime));
  509. m_quickPaste.SetKeyModiferState(false);
  510. }
  511. m_keyStateModifiers = 0;
  512. m_keyModifiersTimerCount = 0;
  513. m_bMovedSelectionMoveKeyState = 0;
  514. }
  515. }
  516. else
  517. {
  518. KillTimer(KEY_STATE_MODIFIERS);
  519. }
  520. break;
  521. case ACTIVE_WINDOW_TIMER:
  522. if(m_quickPaste.IsWindowVisibleEx())
  523. {
  524. theApp.m_activeWnd.TrackActiveWnd(NULL);
  525. }
  526. break;
  527. case FOCUS_CHANGED_TIMER:
  528. KillTimer(FOCUS_CHANGED_TIMER);
  529. //Log(StrF(_T("Focus Timer %d"), m_tempFocusWnd));
  530. theApp.m_activeWnd.TrackActiveWnd(m_tempFocusWnd);
  531. break;
  532. }
  533. CFrameWnd::OnTimer(nIDEvent);
  534. }
  535. void CMainFrame::StopLookingForKeystrokes(bool bInitAppVaribles)
  536. {
  537. StopMonitoringKeyboardChanges();
  538. SetCaptureKeys(false);
  539. KillTimer(STOP_MONITORING_KEYBOARD_TIMER);
  540. KillTimer(STOP_LOOKING_FOR_KEYBOARD);
  541. if(bInitAppVaribles)
  542. {
  543. theApp.m_QuickPasteMode = CCP_MainApp::NONE_QUICK_PASTE;
  544. m_csKeyboardPaste.Empty();
  545. delete theApp.m_pQuickPasteClip;
  546. theApp.m_pQuickPasteClip = NULL;
  547. m_pTypingToolTip->Hide();
  548. m_pTypingToolTip->DestroyWindow();
  549. }
  550. }
  551. LRESULT CMainFrame::OnShowTrayIcon(WPARAM wParam, LPARAM lParam)
  552. {
  553. if(lParam)
  554. {
  555. if(!m_TrayIcon.Visible())
  556. {
  557. KillTimer(HIDE_ICON_TIMER);
  558. SetTimer(HIDE_ICON_TIMER, 40000, 0);
  559. }
  560. }
  561. if(wParam)
  562. m_TrayIcon.ShowIcon();
  563. else
  564. m_TrayIcon.HideIcon();
  565. return TRUE;
  566. }
  567. void CMainFrame::OnFirstShowquickpaste()
  568. {
  569. m_quickPaste.ShowQPasteWnd(this, true, false, FALSE);
  570. }
  571. void CMainFrame::OnFirstToggleConnectCV()
  572. {
  573. theApp.ToggleConnectCV();
  574. }
  575. void CMainFrame::OnUpdateFirstToggleConnectCV(CCmdUI* pCmdUI)
  576. {
  577. theApp.UpdateMenuConnectCV( pCmdUI->m_pMenu, ID_FIRST_TOGGLECONNECTCV );
  578. }
  579. LRESULT CMainFrame::OnCopyProperties(WPARAM wParam, LPARAM lParam)
  580. {
  581. long lID = (long)wParam;
  582. if(lID > 0)
  583. {
  584. bool bOldState = theApp.EnableCbCopy(false);
  585. CCopyProperties props(lID, this);
  586. props.SetHideOnKillFocus(true);
  587. props.DoModal();
  588. theApp.EnableCbCopy( bOldState );
  589. }
  590. return TRUE;
  591. }
  592. LRESULT CMainFrame::OnShutDown(WPARAM wParam, LPARAM lParam)
  593. {
  594. SetTimer(CLOSE_APP, 100, NULL);
  595. return TRUE;
  596. }
  597. LRESULT CMainFrame::OnClipboardCopied(WPARAM wParam, LPARAM lParam)
  598. {
  599. Log(_T("Start of function OnClipboardCopied"));
  600. // if the delay is undesirable, this could be altered to save one at a time,
  601. // allowing the processing of other messages between saving clips.
  602. theApp.SaveCopyClips();
  603. Log(_T("End of function OnClipboardCopied"));
  604. return TRUE;
  605. }
  606. BOOL CMainFrame::PreTranslateMessage(MSG* pMsg)
  607. {
  608. // target before mouse messages change the focus
  609. if( theApp.m_bShowingQuickPaste &&
  610. WM_MOUSEFIRST <= pMsg->message && pMsg->message <= WM_MOUSELAST )
  611. {
  612. if(g_Opt.m_bUseHookDllForFocus == false)
  613. {
  614. theApp.m_activeWnd.TrackActiveWnd(NULL);
  615. }
  616. }
  617. return CFrameWnd::PreTranslateMessage(pMsg);
  618. }
  619. void CMainFrame::OnClose()
  620. {
  621. CloseAllOpenDialogs();
  622. if(m_pEditFrameWnd)
  623. {
  624. if(m_pEditFrameWnd->CloseAll() == false)
  625. return;
  626. }
  627. Log(_T("OnClose - before stop MainFrm thread"));
  628. m_thread.Stop();
  629. Log(_T("OnClose - after stop MainFrm thread"));
  630. theApp.BeforeMainClose();
  631. CFrameWnd::OnClose();
  632. }
  633. bool CMainFrame::CloseAllOpenDialogs()
  634. {
  635. bool bRet = false;
  636. DWORD dwordProcessId;
  637. DWORD dwordChildWindowProcessId;
  638. GetWindowThreadProcessId(this->m_hWnd, &dwordProcessId);
  639. ASSERT(dwordProcessId);
  640. CWnd *pTempWnd = GetDesktopWindow()->GetWindow(GW_CHILD);
  641. while((pTempWnd = pTempWnd->GetWindow(GW_HWNDNEXT)) != NULL)
  642. {
  643. if(pTempWnd->GetSafeHwnd() == NULL)
  644. break;
  645. GetWindowThreadProcessId(pTempWnd->GetSafeHwnd(), &dwordChildWindowProcessId);
  646. if(dwordChildWindowProcessId == dwordProcessId)
  647. {
  648. TCHAR szTemp[100];
  649. GetClassName(pTempWnd->GetSafeHwnd(), szTemp, 100);
  650. // #32770 is class name for dialogs so don't process the message if it is a dialog
  651. if(STRCMP(szTemp, _T("#32770")) == 0)
  652. {
  653. pTempWnd->SendMessage(WM_CLOSE, 0, 0);
  654. bRet = true;
  655. }
  656. }
  657. }
  658. MSG msg;
  659. while(PeekMessage(&msg, NULL, NULL, NULL, PM_REMOVE))
  660. {
  661. TranslateMessage(&msg);
  662. DispatchMessage(&msg);
  663. }
  664. return bRet;
  665. }
  666. LRESULT CMainFrame::OnAddToDatabaseFromSocket(WPARAM wParam, LPARAM lParam)
  667. {
  668. LogSendRecieveInfo("---------Start of OnAddToDatabaseFromSocket");
  669. CProcessPaste paste;
  670. CClipList *pClipList = (CClipList*)wParam;
  671. if(pClipList == NULL)
  672. {
  673. LogSendRecieveInfo("---------ERROR pClipList == NULL");
  674. return FALSE;
  675. }
  676. BOOL bSetToClipBoard = (BOOL)lParam;
  677. if(bSetToClipBoard)
  678. {
  679. LogSendRecieveInfo("---------Start of Set to ClipBoard");
  680. CClip *pClip = pClipList->GetTail();
  681. if(pClip)
  682. {
  683. CClip NewClip;
  684. NewClip = *pClip;
  685. LogSendRecieveInfo("---------After =");
  686. //Don't send the paste just load it into memory
  687. paste.m_bSendPaste = false;
  688. paste.m_pOle->PutFormatOnClipboard(&NewClip.m_Formats);
  689. paste.m_pOle->CacheGlobalData(theApp.m_cfIgnoreClipboard, NewGlobalP("Ignore", sizeof("Ignore")));
  690. LogSendRecieveInfo("---------After LoadFormats");
  691. }
  692. else
  693. {
  694. LogSendRecieveInfo("---------GetTail returned NULL");
  695. }
  696. LogSendRecieveInfo("---------Start of Set to ClipBoard");
  697. }
  698. pClipList->AddToDB(true);
  699. LogSendRecieveInfo("---------After AddToDB");
  700. CClip *pClip = pClipList->GetTail();
  701. if(pClip)
  702. {
  703. theApp.m_FocusID = pClip->m_ID;
  704. //Wait till after we add the clip to the db before we call DoPaste
  705. if(bSetToClipBoard)
  706. {
  707. LogSendRecieveInfo(StrF(_T("---------Setting clip id: %d on ole clipboard"), pClip->m_ID));
  708. paste.GetClipIDs().Add(pClip->m_ID);
  709. paste.DoPaste();
  710. }
  711. }
  712. theApp.RefreshView();
  713. delete pClipList;
  714. pClipList = NULL;
  715. LogSendRecieveInfo("---------End of OnAddToDatabaseFromSocket");
  716. return TRUE;
  717. }
  718. LRESULT CMainFrame::OnErrorOnSendRecieve(WPARAM wParam, LPARAM lParam)
  719. {
  720. CString csNewText = (TCHAR*)wParam;
  721. ShowErrorMessage(_T("Ditto - Send/Receive Error"), csNewText);
  722. return TRUE;
  723. }
  724. LRESULT CMainFrame::OnKeyBoardChanged(WPARAM wParam, LPARAM lParam)
  725. {
  726. if(wParam == VK_ESCAPE)
  727. {
  728. StopLookingForKeystrokes(true);
  729. }
  730. else if(wParam == VK_RETURN)
  731. {
  732. StopLookingForKeystrokes(false);
  733. if(m_csKeyboardPaste.IsEmpty() == FALSE)
  734. {
  735. if(theApp.m_QuickPasteMode == CCP_MainApp::PASTING_QUICK_PASTE)
  736. {
  737. PasteQuickPasteEntry(m_csKeyboardPaste);
  738. }
  739. else
  740. {
  741. SaveQuickPasteEntry(m_csKeyboardPaste, theApp.m_pQuickPasteClip);
  742. }
  743. }
  744. StopLookingForKeystrokes(true);
  745. }
  746. else if((wParam >= 32 && wParam <= 96) || wParam == VK_BACK)
  747. {
  748. KillTimer(STOP_LOOKING_FOR_KEYBOARD);
  749. KillTimer(STOP_MONITORING_KEYBOARD_TIMER);
  750. bool bContinue = true;
  751. if(wParam == VK_BACK)
  752. {
  753. m_csKeyboardPaste = m_csKeyboardPaste.Left(m_csKeyboardPaste.GetLength()-1);
  754. }
  755. else
  756. {
  757. CString cs((char)wParam);
  758. m_csKeyboardPaste += cs;
  759. if(theApp.m_QuickPasteMode == CCP_MainApp::PASTING_QUICK_PASTE)
  760. {
  761. try
  762. {
  763. int nCount = theApp.m_db.execScalarEx(_T("SELECT COUNT(lID) FROM Main WHERE QuickPasteText LIKE \'%%%s%%\'"), m_csKeyboardPaste);
  764. if(nCount == 1)
  765. {
  766. nCount = theApp.m_db.execScalarEx(_T("SELECT COUNT(lID) FROM Main WHERE QuickPasteText = \'%s\'"), m_csKeyboardPaste);
  767. if(nCount == 1)
  768. {
  769. StopLookingForKeystrokes(false);
  770. PasteQuickPasteEntry(m_csKeyboardPaste);
  771. StopLookingForKeystrokes(true);
  772. bContinue = false;
  773. }
  774. }
  775. }
  776. CATCH_SQLITE_EXCEPTION
  777. }
  778. }
  779. if(bContinue)
  780. {
  781. m_pTypingToolTip->SetToolTipText(csTypeToolTipTitle + "\n\n" + m_csKeyboardPaste);
  782. m_pTypingToolTip->Show(m_ToolTipPoint);
  783. SetTimer(STOP_MONITORING_KEYBOARD_TIMER, 10000, NULL);
  784. Log(StrF(_T("OnKeyboard Changed - %d - %s"), wParam, m_csKeyboardPaste));
  785. }
  786. }
  787. else
  788. {
  789. CString cs((char)wParam);
  790. Log(StrF(_T("INVALID Key OnKeyboard Changed - %d - %s"), wParam, m_csKeyboardPaste));
  791. }
  792. return TRUE;
  793. }
  794. CString WndName(HWND hParent)
  795. {
  796. TCHAR cWindowText[200];
  797. ::GetWindowText(hParent, cWindowText, 100);
  798. int nCount = 0;
  799. while(STRLEN(cWindowText) <= 0)
  800. {
  801. hParent = ::GetParent(hParent);
  802. if(hParent == NULL)
  803. break;
  804. ::GetWindowText(hParent, cWindowText, 100);
  805. nCount++;
  806. if(nCount > 100)
  807. {
  808. Log(_T("GetTargetName reached maximum search depth of 100"));
  809. break;
  810. }
  811. }
  812. return cWindowText;
  813. }
  814. LRESULT CMainFrame::OnFocusChanged(WPARAM wParam, LPARAM lParam)
  815. {
  816. if(m_quickPaste.IsWindowVisibleEx())
  817. {
  818. HWND focus = (HWND)wParam;
  819. static DWORD dLastDittoHasFocusTick = 0;
  820. //Sometimes when we bring ditto up there will come a null focus
  821. //rite after that
  822. if(focus == NULL && (GetTickCount() - dLastDittoHasFocusTick < 500))
  823. {
  824. Log(_T("NULL focus within 500 ticks of bringing up ditto"));
  825. return TRUE;
  826. }
  827. else if(focus == NULL)
  828. {
  829. Log(_T("NULL focus received"));
  830. }
  831. if(theApp.m_activeWnd.DittoHasFocus())
  832. {
  833. dLastDittoHasFocusTick = GetTickCount();
  834. }
  835. //Log(StrF(_T("OnFocusChanged %d, title %s"), focus, WndName(focus)));
  836. m_tempFocusWnd = focus;
  837. KillTimer(FOCUS_CHANGED_TIMER);
  838. SetTimer(FOCUS_CHANGED_TIMER, g_Opt.FocusChangedDelay(), NULL);
  839. }
  840. return TRUE;
  841. }
  842. void CMainFrame::OnFirstHelp()
  843. {
  844. CString csFile = CGetSetOptions::GetPath(PATH_HELP);
  845. csFile += "DittoGettingStarted.htm";
  846. CHyperLink::GotoURL(csFile, SW_SHOW);
  847. }
  848. LRESULT CMainFrame::OnCustomizeTrayMenu(WPARAM wParam, LPARAM lParam)
  849. {
  850. CMenu *pMenu = (CMenu*)wParam;
  851. if(pMenu)
  852. {
  853. theApp.m_Language.UpdateTrayIconRightClickMenu(pMenu);
  854. }
  855. return true;
  856. }
  857. bool CMainFrame::PasteQuickPasteEntry(CString csQuickPaste)
  858. {
  859. Log(StrF(_T("PasteQuickPasteEntry -- %s"), csQuickPaste));
  860. CString csTitle = theApp.m_Language.GetString("Named_Paste_Title", "Ditto - Named Paste");
  861. bool bRet = false;
  862. try
  863. {
  864. csQuickPaste.Replace(_T("'"), _T("''"));
  865. CppSQLite3Query q = theApp.m_db.execQueryEx(_T("SELECT lID FROM Main WHERE QuickPasteText = '%s'"), csQuickPaste);
  866. if(q.eof() == false)
  867. {
  868. CClip Clip;
  869. if(Clip.LoadFormats(q.getIntField(_T("lID"))))
  870. {
  871. CProcessPaste paste;
  872. paste.m_pOle->PutFormatOnClipboard(&Clip.m_Formats);
  873. paste.m_pOle->CacheGlobalData(theApp.m_cfIgnoreClipboard, NewGlobalP("Ignore", sizeof("Ignore")));
  874. if(paste.DoPaste())
  875. {
  876. bRet = TRUE;
  877. }
  878. }
  879. else
  880. {
  881. CString csError = theApp.m_Language.GetString("Named_Paste_Error1", "Error loading data");
  882. ShowErrorMessage(csTitle, StrF(_T("%s - id:%d"), csError, q.getIntField(_T("lID"))));
  883. }
  884. }
  885. else
  886. {
  887. CString csError = theApp.m_Language.GetString("Named_Paste_Error2", "Error finding clip with QuickPaste Text of");
  888. ShowErrorMessage(csTitle, StrF(_T("%s - '%s'"), csError, csQuickPaste));
  889. }
  890. }
  891. catch (CppSQLite3Exception& e)
  892. {
  893. CString csError = theApp.m_Language.GetString("Named_Paste_Error3", "Exception finding the clip");
  894. ShowErrorMessage(csTitle, StrF(_T("%s - '%s' - %s"), csError, csQuickPaste, e.errorMessage()));
  895. }
  896. return bRet;
  897. }
  898. bool CMainFrame::SaveQuickPasteEntry(CString csQuickPaste, CClipList *pClipList)
  899. {
  900. Log(StrF(_T("SaveQuickPasteEntry text = %s - recived copy = %d"), csQuickPaste, pClipList != NULL));
  901. CString csTitle = theApp.m_Language.GetString("Named_Copy_Title", "Ditto - Named Copy");
  902. bool bRet = false;
  903. if(pClipList)
  904. {
  905. try
  906. {
  907. CClip *pClip = pClipList->GetHead();
  908. pClip->m_csQuickPaste = csQuickPaste;
  909. pClip->m_lDontAutoDelete = (long)CTime::GetCurrentTime().GetTime();
  910. if(csQuickPaste.IsEmpty() == FALSE)
  911. {
  912. //Remove any other instances of this quick paste
  913. csQuickPaste.Replace(_T("'"), _T("''"));
  914. int nCount = theApp.m_db.execDMLEx(_T("UPDATE Main SET QuickPasteText = '' WHERE QuickPasteText = '%s';"), csQuickPaste);
  915. if(nCount > 0)
  916. {
  917. Log(StrF(_T("Removed quick paste '%s', count = %d"), csQuickPaste, nCount));
  918. }
  919. }
  920. int count = pClipList->AddToDB(true);
  921. if(count > 0)
  922. {
  923. long lID = pClipList->GetTail()->m_ID;
  924. theApp.OnCopyCompleted(lID, count);
  925. bRet = true;
  926. }
  927. else
  928. {
  929. CString csError = theApp.m_Language.GetString("Named_Copy_Error1", "Error saving Named Coy to Database");
  930. ShowErrorMessage(csTitle, csError);
  931. }
  932. }
  933. catch (CppSQLite3Exception& e)
  934. {
  935. Log(StrF(_T("SQLITE Exception %d - %s"), e.errorCode(), e.errorMessage()));
  936. ASSERT(FALSE);
  937. CString csError = theApp.m_Language.GetString("Named_Copy_Error2", "Exception saving Named Copy");
  938. ShowErrorMessage(csTitle, StrF(_T("%s - %s"), csError, e.errorMessage()));
  939. }
  940. }
  941. else
  942. {
  943. CString csError = theApp.m_Language.GetString("Named_Copy_Error3", "Ditto did not receive a copy");
  944. ShowErrorMessage(csTitle, csError);
  945. }
  946. return bRet;
  947. }
  948. void CMainFrame::ShowErrorMessage(CString csTitle, CString csMessage)
  949. {
  950. Log(StrF(_T("ShowErrorMessage %s - %s"), csTitle, csMessage));
  951. CToolTipEx *pErrorWnd = new CToolTipEx;
  952. pErrorWnd->Create(this);
  953. pErrorWnd->SetToolTipText(csTitle + "\n\n" + csMessage);
  954. CPoint pt;
  955. CRect rcScreen;
  956. GetMonitorRect(0, &rcScreen);
  957. pt = rcScreen.BottomRight();
  958. CRect cr = pErrorWnd->GetBoundsRect();
  959. pt.x -= max(cr.Width()+50, 150);
  960. pt.y -= max(cr.Height()+50, 150);
  961. pErrorWnd->Show(pt);
  962. pErrorWnd->HideWindowInXMilliSeconds(4000);
  963. }
  964. void CMainFrame::DeleteOldRemoteCopies(CString csDir)
  965. {
  966. //must be deleting a sub folder in the musicgen directory
  967. if(csDir.Find(_T("\\ReceivedFiles\\")) == -1)
  968. return;
  969. FIX_CSTRING_PATH(csDir);
  970. CTime ctOld = CTime::GetCurrentTime();
  971. CTime ctFile;
  972. ctOld -= CTimeSpan(0, 0, 0, 1);
  973. CFileFind Find;
  974. CString csFindString;
  975. csFindString.Format(_T("%s*.*"), csDir);
  976. BOOL bFound = Find.FindFile(csFindString);
  977. while(bFound)
  978. {
  979. bFound = Find.FindNextFile();
  980. if(Find.IsDots())
  981. continue;
  982. if(Find.IsDirectory())
  983. {
  984. CString csDir(Find.GetFilePath());
  985. DeleteOldRemoteCopies(csDir);
  986. RemoveDirectory(csDir);
  987. }
  988. if(Find.GetLastAccessTime(ctFile))
  989. {
  990. //Delete the remote copied file if it has'nt been used for the last day
  991. if(ctFile < ctOld)
  992. {
  993. DeleteFile(Find.GetFilePath());
  994. }
  995. }
  996. else
  997. {
  998. DeleteFile(Find.GetFilePath());
  999. }
  1000. }
  1001. }
  1002. UINT CMainFrame::RemoteOldRemoteFilesThread(LPVOID pParam)
  1003. {
  1004. CString csDir = CGetSetOptions::GetPath(PATH_REMOTE_FILES);
  1005. if(FileExists(csDir))
  1006. {
  1007. DeleteOldRemoteCopies(csDir);
  1008. }
  1009. return TRUE;
  1010. }
  1011. void CMainFrame::OnFirstImport()
  1012. {
  1013. theApp.ImportClips(theApp.m_MainhWnd);
  1014. }
  1015. void CMainFrame::ShowEditWnd(CClipIDs &Ids)
  1016. {
  1017. CWaitCursor wait;
  1018. bool bCreatedWindow = false;
  1019. if(m_pEditFrameWnd == NULL)
  1020. {
  1021. m_pEditFrameWnd = new CEditFrameWnd;
  1022. m_pEditFrameWnd->LoadFrame(IDR_MAINFRAME);
  1023. bCreatedWindow = true;
  1024. }
  1025. if(m_pEditFrameWnd)
  1026. {
  1027. m_pEditFrameWnd->EditIds(Ids);
  1028. m_pEditFrameWnd->SetNotifyWnd(m_hWnd);
  1029. if(bCreatedWindow)
  1030. {
  1031. CSize sz;
  1032. CPoint pt;
  1033. CGetSetOptions::GetEditWndSize(sz);
  1034. CGetSetOptions::GetEditWndPoint(pt);
  1035. CRect cr(pt, sz);
  1036. EnsureWindowVisible(&cr);
  1037. m_pEditFrameWnd->MoveWindow(cr);
  1038. }
  1039. m_pEditFrameWnd->ShowWindow(SW_SHOW);
  1040. m_pEditFrameWnd->SetForegroundWindow();
  1041. m_pEditFrameWnd->SetFocus();
  1042. }
  1043. }
  1044. LRESULT CMainFrame::OnEditWndClose(WPARAM wParam, LPARAM lParam)
  1045. {
  1046. m_pEditFrameWnd = NULL;
  1047. return TRUE;
  1048. }
  1049. LRESULT CMainFrame::OnSetConnected(WPARAM wParam, LPARAM lParam)
  1050. {
  1051. if(wParam)
  1052. theApp.SetConnectCV(true);
  1053. else if(lParam)
  1054. theApp.SetConnectCV(false);
  1055. return TRUE;
  1056. }
  1057. void CMainFrame::OnDestroy()
  1058. {
  1059. Shell_NotifyIcon(NIM_DELETE, &tnd);
  1060. m_TrayMenu.DestroyMenu();
  1061. CFrameWnd::OnDestroy();
  1062. if(m_pEditFrameWnd)
  1063. {
  1064. m_pEditFrameWnd->DestroyWindow();
  1065. }
  1066. }
  1067. void CMainFrame::OnFirstNewclip()
  1068. {
  1069. CClipIDs IDs;
  1070. IDs.Add(-1);
  1071. theApp.EditItems(IDs, true);
  1072. }
  1073. LRESULT CMainFrame::OnTrayNotify(WPARAM wParam, LPARAM lParam)
  1074. {
  1075. UINT uMsg = (UINT) lParam;
  1076. switch (uMsg )
  1077. {
  1078. case WM_LBUTTONDBLCLK:
  1079. //this->ShowWindow(SW_SHOW);
  1080. m_TrayMenu.DestroyMenu();
  1081. this->OnClose();
  1082. break;
  1083. case WM_RBUTTONUP:
  1084. CPoint pt;
  1085. GetCursorPos(&pt);
  1086. m_TrayMenu.GetSubMenu(0)->TrackPopupMenu(TPM_RIGHTALIGN|TPM_LEFTBUTTON|TPM_RIGHTBUTTON,pt.x,pt.y,this);
  1087. break;
  1088. }
  1089. return TRUE;
  1090. }