ToolTipEx.cpp 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402
  1. #include "stdafx.h"
  2. #include "cp_main.h"
  3. #include "ToolTipEx.h"
  4. #include "BitmapHelper.h"
  5. #include "Options.h"
  6. #include "ActionEnums.h"
  7. #include "HyperLink.h"
  8. #include <Richedit.h>
  9. #ifdef _DEBUG
  10. #define new DEBUG_NEW
  11. #undef THIS_FILE
  12. static char THIS_FILE[] = __FILE__;
  13. #endif
  14. #define HIDE_WINDOW_TIMER 1
  15. #define SAVE_SIZE 2
  16. #define TIMER_BUTTON_UP 3
  17. #define TIMER_AUTO_MAX 4
  18. /////////////////////////////////////////////////////////////////////////////
  19. // CToolTipEx
  20. CToolTipEx::CToolTipEx(): m_dwTextStyle(DT_EXPANDTABS | DT_EXTERNALLEADING |
  21. DT_NOPREFIX | DT_WORDBREAK), m_rectMargin(2, 2, 3, 3),
  22. m_pNotifyWnd(NULL), m_clipId(0), m_clipRow(-1)
  23. {
  24. m_showPersistant = false;
  25. m_pToolTipActions = NULL;
  26. m_bMaxSetTimer = false;
  27. m_lDelayMaxSeconds = 2;
  28. }
  29. CToolTipEx::~CToolTipEx()
  30. {
  31. m_Font.DeleteObject();
  32. m_clipDataFont.DeleteObject();
  33. }
  34. BEGIN_MESSAGE_MAP(CToolTipEx, CWnd)
  35. //{{AFX_MSG_MAP(CToolTipEx)
  36. ON_WM_PAINT()
  37. ON_WM_SIZE()
  38. ON_WM_NCHITTEST()
  39. ON_WM_ACTIVATE()
  40. ON_WM_TIMER()
  41. ON_WM_NCLBUTTONDBLCLK()
  42. ON_WM_NCPAINT()
  43. ON_WM_NCCALCSIZE()
  44. ON_WM_NCLBUTTONDOWN()
  45. ON_WM_NCMOUSEMOVE()
  46. ON_WM_NCLBUTTONUP()
  47. ON_WM_ERASEBKGND()
  48. ON_COMMAND(ID_FIRST_REMEMBERWINDOWPOSITION, &CToolTipEx::OnRememberwindowposition)
  49. ON_COMMAND(ID_FIRST_SIZEWINDOWTOCONTENT, &CToolTipEx::OnSizewindowtocontent)
  50. ON_COMMAND(ID_FIRST_SCALEIMAGESTOFITWINDOW, &CToolTipEx::OnScaleimagestofitwindow)
  51. ON_COMMAND(2, OnOptions)
  52. ON_WM_RBUTTONDOWN()
  53. ON_WM_SETFOCUS()
  54. ON_COMMAND(ID_FIRST_HIDEDESCRIPTIONWINDOWONM, &CToolTipEx::OnFirstHidedescriptionwindowonm)
  55. ON_COMMAND(ID_FIRST_WRAPTEXT, &CToolTipEx::OnFirstWraptext)
  56. ON_WM_WINDOWPOSCHANGING()
  57. ON_COMMAND(ID_FIRST_ALWAYSONTOP, &CToolTipEx::OnFirstAlwaysontop)
  58. ON_NOTIFY(EN_MSGFILTER, 1, &CToolTipEx::OnEnMsgfilterRichedit21)
  59. ON_MESSAGE(WM_DPICHANGED, OnDpiChanged)
  60. ON_WM_MOVING()
  61. ON_WM_ENTERSIZEMOVE()
  62. ON_WM_HSCROLL()
  63. END_MESSAGE_MAP()
  64. /////////////////////////////////////////////////////////////////////////////
  65. // CToolTipEx message handlers
  66. BOOL CToolTipEx::Create(CWnd *pParentWnd)
  67. {
  68. m_saveWindowLockout = true;
  69. // Get the class name and create the window
  70. CString szClassName = AfxRegisterWndClass(CS_CLASSDC | CS_SAVEBITS, LoadCursor(NULL, IDC_ARROW));
  71. // Create the window - just don't show it yet.
  72. if( !CWnd::CreateEx(0, szClassName, _T(""), WS_POPUP,
  73. 0, 0, 0, 0, pParentWnd->GetSafeHwnd(), 0, NULL))
  74. {
  75. return FALSE;
  76. }
  77. HICON b = (HICON)LoadImage(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDR_MAINFRAME), IMAGE_ICON, 64, 64, LR_SHARED);
  78. SetIcon(b, TRUE);
  79. //CString szClassName2 = AfxRegisterWndClass(CS_CLASSDC | CS_SAVEBITS, LoadCursor(NULL, IDC_ARROW));
  80. //BOOL b = m_imageViewer.Create(_T(""), szClassName2, WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL, CRect(0, 0, 0, 0), this, 3);
  81. m_imageViewer.Create(this);
  82. m_DittoWindow.DoCreate(this);
  83. m_DittoWindow.SetCaptionColors(g_Opt.m_Theme.CaptionLeft(), g_Opt.m_Theme.CaptionRight(), g_Opt.m_Theme.Border());
  84. m_DittoWindow.SetCaptionOn(this, CGetSetOptions::GetCaptionPos(), true, g_Opt.m_Theme.GetCaptionSize(), g_Opt.m_Theme.GetCaptionFontSize());
  85. m_DittoWindow.m_bDrawMaximize = false;
  86. m_DittoWindow.m_bDrawMinimize = false;
  87. m_DittoWindow.m_bDrawChevron = true;
  88. m_DittoWindow.m_sendWMClose = false;
  89. m_RichEdit.Create(_T(""), _T(""), WS_CHILD | WS_VISIBLE | WS_VSCROLL |
  90. WS_HSCROLL | ES_MULTILINE | ES_AUTOVSCROLL | ES_NOHIDESEL |
  91. ES_AUTOHSCROLL, CRect(10, 10, 100, 200), this, 1);
  92. m_RichEdit.SetReadOnly();
  93. m_RichEdit.SetBackgroundColor(FALSE, g_Opt.m_Theme.DescriptionWindowBG());
  94. m_RichEdit.SetEventMask(m_RichEdit.GetEventMask() | ENM_SELCHANGE | ENM_LINK | ENM_MOUSEEVENTS | ENM_SCROLLEVENTS);
  95. m_RichEdit.SetAutoURLDetect(TRUE);
  96. ApplyWordWrap();
  97. m_optionsButton.Create(NULL, WS_CHILD | BS_OWNERDRAW | WS_TABSTOP, CRect(0, 0, 0, 0), this, 2);
  98. m_optionsButton.LoadStdImageDPI(m_DittoWindow.m_dpi.GetDPI(), IDB_COG_16_16, IDB_COG_20_20, IDB_COG_24_24, cog_28, IDB_COG_32_32, _T("PNG"));
  99. m_optionsButton.SetToolTipText(theApp.m_Language.GetString(_T("DescriptionOptionsTooltip"), _T("Description Options")));
  100. m_optionsButton.ShowWindow(SW_SHOW);
  101. m_clipDataStatic.Create(_T("some text"), WS_CHILD | WS_VISIBLE | SS_SIMPLE, CRect(0, 0, 0, 0), this, 3);
  102. m_folderPathStatic.Create(_T("some text"), WS_CHILD | WS_VISIBLE | SS_SIMPLE, CRect(0, 0, 0, 0), this, 4);
  103. m_clipDataFont.CreateFont(-m_DittoWindow.m_dpi.Scale(11), 0, 0, 0, 400, 0, 0, 0, DEFAULT_CHARSET, 3, 2, 1, 34, _T("Segoe UI"));
  104. m_Font.CreateFont(-m_DittoWindow.m_dpi.Scale(13), 0, 0, 0, 400, 0, 0, 0, DEFAULT_CHARSET, 3, 2, 1, 34, _T("Segoe UI"));
  105. m_fontHeight = -13;
  106. m_clipDataStatic.SetFont(&m_clipDataFont);
  107. m_clipDataStatic.SetBkColor(g_Opt.m_Theme.DescriptionWindowBG());
  108. m_clipDataStatic.SetTextColor(RGB(80, 80, 80));
  109. m_folderPathStatic.SetFont(&m_clipDataFont);
  110. m_folderPathStatic.SetBkColor(g_Opt.m_Theme.DescriptionWindowBG());
  111. m_folderPathStatic.SetTextColor(RGB(80, 80, 80));
  112. m_saveWindowLockout = false;
  113. return TRUE;
  114. }
  115. BOOL CToolTipEx::Show(CPoint point)
  116. {
  117. if(m_imageViewer.m_pGdiplusBitmap)
  118. {
  119. m_clipData += _T(" | ") + StrF(_T("%d x %d"), m_imageViewer.m_pGdiplusBitmap->GetWidth(), m_imageViewer.m_pGdiplusBitmap->GetHeight());
  120. m_imageViewer.ShowWindow(SW_SHOW);
  121. m_RichEdit.ShowWindow(SW_HIDE);
  122. if (::IsWindow(m_browser.m_hWnd))
  123. {
  124. m_browser.ShowWindow(SW_HIDE);
  125. }
  126. m_imageViewer.UpdateBitmapSize();
  127. }
  128. else if (m_html.GetLength() > 0)
  129. {
  130. if (::IsWindow(m_browser.m_hWnd))
  131. {
  132. m_browser.ShowWindow(SW_SHOW);
  133. }
  134. m_imageViewer.ShowWindow(SW_HIDE);
  135. m_RichEdit.ShowWindow(SW_HIDE);
  136. }
  137. else
  138. {
  139. m_RichEdit.ShowWindow(SW_SHOW);
  140. m_imageViewer.ShowWindow(SW_HIDE);
  141. if (::IsWindow(m_browser.m_hWnd))
  142. {
  143. m_browser.ShowWindow(SW_HIDE);
  144. }
  145. }
  146. CRect rect;
  147. if(CGetSetOptions::GetSizeDescWindowToContent() == FALSE)
  148. {
  149. rect.left = point.x;
  150. rect.top = point.y;
  151. CSize size;
  152. CGetSetOptions::GetDescWndSize(size);
  153. rect.right = rect.left + m_DittoWindow.m_dpi.Scale(size.cx);
  154. rect.bottom = rect.top + m_DittoWindow.m_dpi.Scale(size.cy);
  155. EnsureWindowVisible(&rect);
  156. }
  157. else
  158. {
  159. rect = GetBoundsRect();
  160. //account for the scroll bars
  161. rect.right += 20;
  162. rect.bottom += 20;
  163. if (m_imageViewer.m_pGdiplusBitmap)
  164. {
  165. int nWidth = m_imageViewer.m_pGdiplusBitmap->GetWidth() + ::GetSystemMetrics(SM_CXVSCROLL);
  166. int nHeight = m_imageViewer.m_pGdiplusBitmap->GetHeight() + ::GetSystemMetrics(SM_CYHSCROLL);
  167. rect.right = rect.left + nWidth;
  168. rect.bottom = rect.top + nHeight;
  169. }
  170. else if(m_csRTF != "")
  171. {
  172. //if showing rtf then increase the size because
  173. //rtf will probably draw bigger
  174. long lNewWidth = (long)rect.Width() + (long)(rect.Width() *1.5);
  175. rect.right = rect.left + lNewWidth;
  176. long lNewHeight = (long)rect.Height() + (long)(rect.Height() *1.5);
  177. rect.bottom = rect.top + lNewHeight;
  178. }
  179. //rect.right += CAPTION_BORDER * 2;
  180. //rect.bottom += CAPTION_BORDER * 2;
  181. ClientToScreen(rect);
  182. CRect cr(point, point);
  183. CRect rcScreen = MonitorRectFromRect(cr);
  184. //ensure that we don't go outside the screen
  185. if(point.x < 0)
  186. {
  187. point.x = 5;
  188. //m_reducedWindowSize = true;
  189. }
  190. if(point.y < 0)
  191. {
  192. point.y = 5;
  193. //m_reducedWindowSize = true;
  194. }
  195. rcScreen.DeflateRect(0, 0, 5, 5);
  196. long lWidth = rect.Width();
  197. long lHeight = rect.Height();
  198. rect.left = point.x;
  199. rect.top = point.y;
  200. rect.right = rect.left + lWidth;
  201. rect.bottom = rect.top + lHeight;
  202. if (rect.right > rcScreen.right)
  203. {
  204. rect.right = rcScreen.right;
  205. //m_reducedWindowSize = true;
  206. }
  207. if (rect.bottom > rcScreen.bottom)
  208. {
  209. rect.bottom = rcScreen.bottom;
  210. //m_reducedWindowSize = true;
  211. }
  212. }
  213. m_clipDataStatic.SetWindowText(m_clipData);
  214. m_folderPathStatic.SetWindowText(m_folderPath);
  215. if (m_DittoWindow.m_bMinimized)
  216. {
  217. //m_DittoWindow.MinMaxWindow(this, FORCE_MAX);
  218. m_DittoWindow.m_bMinimized = false;
  219. }
  220. m_saveWindowLockout = true;
  221. MoveWindow(rect);
  222. ShowWindow(SW_SHOWNA);
  223. this->Invalidate();
  224. this->UpdateWindow();
  225. MoveControls();
  226. m_saveWindowLockout = false;
  227. return TRUE;
  228. }
  229. void CToolTipEx::GetWindowRectEx(LPRECT lpRect)
  230. {
  231. if (m_DittoWindow.m_bMinimized)
  232. {
  233. *lpRect = m_DittoWindow.m_crFullSizeWindow;
  234. return;
  235. }
  236. CWnd::GetWindowRect(lpRect);
  237. }
  238. BOOL CToolTipEx::Hide()
  239. {
  240. delete m_imageViewer.m_pGdiplusBitmap;
  241. m_imageViewer.m_pGdiplusBitmap = NULL;
  242. SaveWindowSize();
  243. ShowWindow(SW_HIDE);
  244. m_csRTF = "";
  245. m_csText = "";
  246. m_html = "";
  247. m_clipId = 0;
  248. m_clipRow = -1;
  249. m_searchText = _T("");
  250. m_showPersistant = false;
  251. return TRUE;
  252. }
  253. void CToolTipEx::OnNcLButtonDblClk(UINT nHitTest, CPoint point)
  254. {
  255. // toggle ShowPersistent when we double click the caption
  256. if (nHitTest == HTCAPTION)
  257. {
  258. OnFirstAlwaysontop();
  259. }
  260. CWnd::OnNcLButtonDblClk(nHitTest, point);
  261. }
  262. void CToolTipEx::SaveWindowSize()
  263. {
  264. if (::IsWindowVisible(m_hWnd))
  265. {
  266. CRect rect;
  267. if (m_DittoWindow.m_bMinimized)
  268. {
  269. rect = m_DittoWindow.m_crFullSizeWindow;
  270. }
  271. else
  272. {
  273. this->GetWindowRect(&rect);
  274. }
  275. CSize s = rect.Size();
  276. CGetSetOptions::SetDescWndSize(CSize(m_DittoWindow.m_dpi.UnScale(s.cx), m_DittoWindow.m_dpi.UnScale(s.cy)));
  277. CGetSetOptions::SetDescWndPoint(rect.TopLeft());
  278. OutputDebugString(_T("Saving tooltip size"));
  279. }
  280. }
  281. void CToolTipEx::PostNcDestroy()
  282. {
  283. CWnd::PostNcDestroy();
  284. delete this;
  285. }
  286. BOOL CToolTipEx::PreTranslateMessage(MSG *pMsg)
  287. {
  288. m_DittoWindow.DoPreTranslateMessage(pMsg);
  289. switch (pMsg->message)
  290. {
  291. case WM_KEYDOWN:
  292. switch(pMsg->wParam)
  293. {
  294. case 'C':
  295. if(GetKeyState(VK_CONTROL) &0x8000)
  296. {
  297. m_RichEdit.Copy();
  298. }
  299. break;
  300. }
  301. break;
  302. case WM_RBUTTONDOWN:
  303. {
  304. auto f = GetFocus();
  305. if (f != NULL &&
  306. (m_RichEdit.m_hWnd == f->m_hWnd ||
  307. m_imageViewer.m_hWnd == f->m_hWnd))
  308. {
  309. OnOptions();
  310. return TRUE;
  311. }
  312. }
  313. break;
  314. case WM_LBUTTONUP:
  315. auto f = GetFocus();
  316. if (f != NULL &&
  317. m_RichEdit.m_hWnd != f->m_hWnd &&
  318. m_optionsButton.m_hWnd != f->m_hWnd)
  319. {
  320. auto p = GetParent();
  321. if (p != NULL)
  322. {
  323. p->SetFocus();
  324. }
  325. }
  326. break;
  327. }
  328. if (m_pToolTipActions != NULL)
  329. {
  330. CAccel a;
  331. if (m_pToolTipActions->OnMsg(pMsg, a))
  332. {
  333. switch (a.Cmd)
  334. {
  335. case ActionEnums::CLOSEWINDOW:
  336. /*if (this->m_showPersistant &&
  337. m_DittoWindow.m_bMinimized == false)
  338. {
  339. m_DittoWindow.MinMaxWindow(this, FORCE_MIN);
  340. theApp.m_activeWnd.ReleaseFocus();
  341. return TRUE;
  342. }*/
  343. break;
  344. }
  345. }
  346. }
  347. return CWnd::PreTranslateMessage(pMsg);
  348. }
  349. BOOL CToolTipEx::OnMsg(MSG *pMsg)
  350. {
  351. if(FALSE == IsWindowVisible())
  352. {
  353. return FALSE;
  354. }
  355. switch(pMsg->message)
  356. {
  357. case WM_WINDOWPOSCHANGING:
  358. case WM_LBUTTONDOWN:
  359. {
  360. if (m_showPersistant == false)
  361. {
  362. if (CGetSetOptions::GetMouseClickHidesDescription())
  363. {
  364. if (!IsCursorInToolTip())
  365. {
  366. Hide();
  367. }
  368. }
  369. }
  370. }
  371. break;
  372. case WM_KEYDOWN:
  373. {
  374. WPARAM vk = pMsg->wParam;
  375. if(vk == VK_TAB)
  376. {
  377. m_RichEdit.SetFocus();
  378. return TRUE;
  379. }
  380. else if (vk == VK_CONTROL || vk == VK_SHIFT)
  381. {
  382. return FALSE;
  383. }
  384. else if (vk == VK_UP)
  385. {
  386. return FALSE;
  387. }
  388. else if (vk == VK_DOWN)
  389. {
  390. return FALSE;
  391. }
  392. else if (vk == VK_NEXT)
  393. {
  394. return FALSE;
  395. }
  396. else if (vk == VK_PRIOR)
  397. {
  398. return FALSE;
  399. }
  400. else if (vk == VK_DELETE)
  401. {
  402. return FALSE;
  403. }
  404. if (m_pToolTipActions != NULL)
  405. {
  406. if (m_pToolTipActions->ContainsKey((int)vk))
  407. {
  408. return FALSE;
  409. }
  410. }
  411. if (m_showPersistant == false)
  412. {
  413. Hide();
  414. }
  415. break;
  416. }
  417. case WM_LBUTTONDBLCLK:
  418. case WM_RBUTTONDBLCLK:
  419. case WM_MBUTTONDOWN:
  420. case WM_MBUTTONDBLCLK:
  421. case WM_NCLBUTTONDOWN:
  422. case WM_NCLBUTTONDBLCLK:
  423. case WM_NCRBUTTONDOWN:
  424. case WM_NCRBUTTONDBLCLK:
  425. case WM_NCMBUTTONDOWN:
  426. case WM_NCMBUTTONDBLCLK:
  427. {
  428. if (m_showPersistant == false)
  429. {
  430. Hide();
  431. }
  432. break;
  433. }
  434. case WM_MOUSEWHEEL:
  435. case WM_MOUSEHWHEEL:
  436. {
  437. if (m_imageViewer.m_pGdiplusBitmap)
  438. {
  439. m_imageViewer.PostMessageW(pMsg->message, pMsg->wParam, pMsg->lParam);
  440. return TRUE;
  441. }
  442. else
  443. {
  444. m_RichEdit.PostMessageW(pMsg->message, pMsg->wParam, pMsg->lParam);
  445. return TRUE;
  446. }
  447. }
  448. break;
  449. }
  450. return FALSE;
  451. }
  452. CRect CToolTipEx::GetBoundsRect()
  453. {
  454. DWORD d = GetTickCount();
  455. CWindowDC dc(NULL);
  456. int nLineWidth = 0;
  457. CRect rect(0, 0, 0, 0);
  458. if(nLineWidth == 0)
  459. {
  460. // Count the number of lines of text
  461. int nStart = 0;
  462. INT nNumLines = 0;
  463. int longestLength = 0;
  464. CString longestString;
  465. do
  466. {
  467. nNumLines++;
  468. int newStart = m_csText.Find(_T("\n"), nStart);
  469. if (newStart < 0)
  470. {
  471. int length = m_csText.GetLength() - nStart;
  472. if (length > longestLength)
  473. {
  474. longestString = m_csText.Mid(nStart, length);
  475. longestLength = length;
  476. }
  477. break;
  478. }
  479. int length = newStart - nStart;
  480. if(length > longestLength)
  481. {
  482. longestString = m_csText.Mid(nStart, length);
  483. longestLength = length;
  484. }
  485. nStart = newStart + 1;
  486. }
  487. while(nStart >= 0 && nNumLines < 100);
  488. CFont *pOldFont = (CFont*)dc.SelectObject((CFont*)&m_Font);
  489. CSize size = dc.GetTextExtent(longestString);
  490. dc.SelectObject(pOldFont);
  491. rect.right = size.cx;
  492. rect.bottom = size.cy * nNumLines;
  493. }
  494. rect.bottom += m_rectMargin.top + m_rectMargin.bottom + GetSystemMetrics(SM_CYVSCROLL);
  495. rect.right += m_rectMargin.left + m_rectMargin.right + GetSystemMetrics(SM_CXVSCROLL);
  496. if(m_imageViewer.m_pGdiplusBitmap)
  497. {
  498. int nWidth = m_imageViewer.m_pGdiplusBitmap->GetWidth();
  499. int nHeight = m_imageViewer.m_pGdiplusBitmap->GetHeight();
  500. rect.bottom += nHeight;
  501. if((rect.left + nWidth) > rect.right)
  502. {
  503. rect.right = rect.left + nWidth;
  504. }
  505. }
  506. DWORD diff = GetTickCount() - d;
  507. if (diff > 10)
  508. {
  509. Log(StrF(_T("Size To Content: %d\n"), diff));
  510. }
  511. return rect;
  512. }
  513. CString CToolTipEx::GetFieldFromString(CString ref, int nIndex, TCHAR ch)
  514. {
  515. CString strReturn;
  516. LPCTSTR pstrStart = ref.LockBuffer();
  517. LPCTSTR pstrBuffer = pstrStart;
  518. int nCurrent = 0;
  519. int nStart = 0;
  520. int nEnd = 0;
  521. int nOldStart = 0;
  522. while(nCurrent <= nIndex && *pstrBuffer != _T('\0'))
  523. {
  524. if(*pstrBuffer == ch)
  525. {
  526. nOldStart = nStart;
  527. nStart = nEnd + 1;
  528. nCurrent++;
  529. }
  530. nEnd++;
  531. pstrBuffer++;
  532. }
  533. // May have reached the end of the string
  534. if(*pstrBuffer == _T('\0'))
  535. {
  536. nOldStart = nStart;
  537. nEnd++;
  538. }
  539. ref.UnlockBuffer();
  540. if(nCurrent < nIndex)
  541. {
  542. //TRACE1("Warning: GetStringField - Couldn't find field %d.\n", nIndex);
  543. return strReturn;
  544. }
  545. return ref.Mid(nOldStart, nEnd - nOldStart - 1);
  546. }
  547. BOOL CToolTipEx::SetLogFont(LPLOGFONT lpLogFont, BOOL bRedraw /*=TRUE*/)
  548. {
  549. ASSERT(lpLogFont);
  550. if(!lpLogFont)
  551. {
  552. return FALSE;
  553. }
  554. LOGFONT LogFont;
  555. // Store font as the global default
  556. memcpy(&LogFont, lpLogFont, sizeof(LOGFONT));
  557. m_fontHeight = lpLogFont->lfHeight;
  558. LogFont.lfHeight = m_DittoWindow.m_dpi.Scale(LogFont.lfHeight);
  559. // Create the actual font object
  560. m_Font.DeleteObject();
  561. m_Font.CreateFontIndirect(&LogFont);
  562. if(bRedraw && ::IsWindow(GetSafeHwnd()))
  563. {
  564. Invalidate();
  565. }
  566. return TRUE;
  567. }
  568. void CToolTipEx::SetGdiplusBitmap(Gdiplus::Bitmap *gdiplusBitmap)
  569. {
  570. delete m_imageViewer.m_pGdiplusBitmap;
  571. m_imageViewer.m_pGdiplusBitmap = NULL;
  572. m_imageViewer.m_pGdiplusBitmap = gdiplusBitmap;
  573. m_imageViewer.UpdateBitmapSize();
  574. Invalidate();
  575. }
  576. void CToolTipEx::OnSize(UINT nType, int cx, int cy)
  577. {
  578. CWnd::OnSize(nType, cx, cy);
  579. if(::IsWindow(m_RichEdit.GetSafeHwnd()) == FALSE)
  580. {
  581. return ;
  582. }
  583. MoveControls();
  584. }
  585. void CToolTipEx::MoveControls()
  586. {
  587. CRect cr;
  588. GetClientRect(cr);
  589. int bottom = m_DittoWindow.m_dpi.Scale(22);
  590. int optionsExtra = 0;
  591. if (m_folderPath != _T(""))
  592. {
  593. bottom += m_DittoWindow.m_dpi.Scale(17);
  594. optionsExtra += m_DittoWindow.m_dpi.Scale(10);
  595. m_folderPathStatic.ShowWindow(SW_SHOW);
  596. }
  597. else
  598. {
  599. m_folderPathStatic.ShowWindow(SW_HIDE);
  600. }
  601. cr.DeflateRect(0, 0, 0, bottom);
  602. m_RichEdit.MoveWindow(cr);
  603. m_imageViewer.MoveWindow(cr);
  604. if (::IsWindow(m_browser.m_hWnd))
  605. {
  606. m_browser.MoveWindow(cr);
  607. }
  608. m_optionsButton.MoveWindow(cr.left, cr.bottom + m_DittoWindow.m_dpi.Scale(3) + optionsExtra, m_DittoWindow.m_dpi.Scale(17), m_DittoWindow.m_dpi.Scale(17));
  609. m_clipDataStatic.MoveWindow(cr.left + m_DittoWindow.m_dpi.Scale(19), cr.bottom + m_DittoWindow.m_dpi.Scale(4), cr.Width() - cr.left + m_DittoWindow.m_dpi.Scale(19), m_DittoWindow.m_dpi.Scale(20));
  610. m_folderPathStatic.MoveWindow(cr.left + m_DittoWindow.m_dpi.Scale(19), cr.bottom + m_DittoWindow.m_dpi.Scale(20), cr.Width() - cr.left + m_DittoWindow.m_dpi.Scale(19), m_DittoWindow.m_dpi.Scale(20));
  611. this->Invalidate();
  612. if (m_saveWindowLockout == false)
  613. {
  614. SetTimer(SAVE_SIZE, 250, NULL);
  615. }
  616. }
  617. BOOL CToolTipEx::IsCursorInToolTip()
  618. {
  619. CRect cr;
  620. GetWindowRect(cr);
  621. CPoint cursorPos;
  622. GetCursorPos(&cursorPos);
  623. return cr.PtInRect(cursorPos);
  624. }
  625. void CToolTipEx::SetHtmlText(const CString &html)
  626. {
  627. if (html.GetLength() > 0 &&
  628. ::IsWindow(m_browser.m_hWnd) == FALSE)
  629. {
  630. m_browser.Create(WS_CHILD | WS_VISIBLE, CRect(10, 10, 100, 200), this, 2);
  631. }
  632. if (::IsWindow(m_browser.m_hWnd))
  633. {
  634. int pos = html.Find(_T("<html"));
  635. if (pos >= 0)
  636. {
  637. m_html = html.Mid(pos);
  638. }
  639. else
  640. {
  641. m_html = html;
  642. }
  643. COLORREF c = g_Opt.m_Theme.DescriptionWindowBG();
  644. DWORD dwR = GetRValue(c);
  645. DWORD dwG = GetGValue(c);
  646. DWORD dwB = GetBValue(c);
  647. CString colorHex;
  648. colorHex.Format(_T("#%02X%02X%02X"), dwR, dwG, dwB);
  649. m_html.Replace(_T("<body>"), StrF(_T("<body bgcolor=\"%s\">"), colorHex));
  650. m_browser.PutSilent(true);
  651. m_browser.Clear();
  652. m_browser.Write(m_html);
  653. }
  654. }
  655. void CToolTipEx::SetRTFText(const char *pRTF)
  656. {
  657. m_RichEdit.SetRTF(pRTF);
  658. m_csRTF = pRTF;
  659. m_RichEdit.SetSel(0, 0);
  660. HighlightSearchText();
  661. }
  662. //void CToolTipEx::SetRTFText(const CString &csRTF)
  663. //{
  664. // m_RichEdit.SetRTF(csRTF);
  665. // m_csRTF = csRTF;
  666. //}
  667. void CToolTipEx::SetToolTipText(const CString &csText)
  668. {
  669. m_csText = csText;
  670. m_RichEdit.SetFont(&m_Font);
  671. m_RichEdit.SetText(csText);
  672. m_RichEdit.SetSel(0, 0);
  673. CHARFORMAT cfNew;
  674. cfNew.cbSize = sizeof(CHARFORMAT);
  675. cfNew.dwMask = CFM_COLOR;
  676. cfNew.dwEffects = CFM_COLOR;
  677. cfNew.dwEffects &= ~CFE_AUTOCOLOR;
  678. cfNew.crTextColor = g_Opt.m_Theme.DescriptionWindowText();
  679. m_RichEdit.SetDefaultCharFormat(cfNew);
  680. HighlightSearchText();
  681. }
  682. void CToolTipEx::HighlightSearchText()
  683. {
  684. if (m_searchText.GetLength() <= 0)
  685. return;
  686. FINDTEXTEX ft;
  687. long n = -1;
  688. ft.lpstrText = m_searchText;
  689. ft.chrg.cpMin = 0;
  690. ft.chrg.cpMax = -1;
  691. CHARFORMAT cf;
  692. cf.cbSize = sizeof(cf);
  693. cf.dwMask = CFM_COLOR;
  694. cf.dwEffects = CFE_BOLD | ~CFE_AUTOCOLOR;
  695. cf.crTextColor = RGB(255, 0, 0);
  696. do
  697. {
  698. ft.chrg.cpMin = n+1;
  699. n = m_RichEdit.FindText(FR_DOWN, &ft);
  700. if (n != -1)
  701. {
  702. m_RichEdit.SetSel(ft.chrgText);
  703. m_RichEdit.SetSelectionCharFormat(cf);
  704. }
  705. } while (n != -1);
  706. m_RichEdit.SetSel(0, 0);
  707. }
  708. void CToolTipEx::DoSearch()
  709. {
  710. if (m_searchText.GetLength() <= 0)
  711. return;
  712. FINDTEXTEX ft;
  713. long n = -1;
  714. ft.lpstrText = m_searchText;
  715. long start;
  716. long end;
  717. m_RichEdit.GetSel(start, end);
  718. ft.chrg.cpMin = end;
  719. ft.chrg.cpMax = -1;
  720. int searchDirection = FR_DOWN;
  721. if (GetKeyState(VK_SHIFT) & 0x8000)
  722. {
  723. searchDirection = 0;
  724. ft.chrg.cpMin = start;
  725. }
  726. n = m_RichEdit.FindText(searchDirection, &ft);
  727. if (n != -1)
  728. {
  729. m_RichEdit.SetSel(ft.chrgText);
  730. }
  731. else
  732. {
  733. if (searchDirection == 0)
  734. {
  735. ft.chrg.cpMin = m_RichEdit.GetTextLength();
  736. }
  737. else
  738. {
  739. ft.chrg.cpMin = 0;
  740. }
  741. ft.chrg.cpMax = -1;
  742. n = m_RichEdit.FindText(searchDirection, &ft);
  743. if (n != -1)
  744. {
  745. m_RichEdit.SetSel(ft.chrgText);
  746. }
  747. }
  748. }
  749. void CToolTipEx::OnActivate(UINT nState, CWnd *pWndOther, BOOL bMinimized)
  750. {
  751. CWnd::OnActivate(nState, pWndOther, bMinimized);
  752. if (nState == WA_INACTIVE)
  753. {
  754. if(m_pNotifyWnd)
  755. {
  756. m_pNotifyWnd->PostMessage(NM_INACTIVE_TOOLTIPWND, 0, 0);
  757. }
  758. }
  759. }
  760. void CToolTipEx::OnTimer(UINT_PTR nIDEvent)
  761. {
  762. switch(nIDEvent)
  763. {
  764. case HIDE_WINDOW_TIMER:
  765. Hide();
  766. PostMessage(WM_DESTROY, 0, 0);
  767. break;
  768. case SAVE_SIZE:
  769. SaveWindowSize();
  770. KillTimer(SAVE_SIZE);
  771. break;
  772. case TIMER_BUTTON_UP:
  773. {
  774. if ((GetKeyState(VK_LBUTTON) & 0x100) == 0)
  775. {
  776. m_DittoWindow.DoNcLButtonUp(this, 0, CPoint(0, 0));
  777. KillTimer(TIMER_BUTTON_UP);
  778. auto f = GetFocus();
  779. if (f != NULL &&
  780. m_RichEdit.m_hWnd != f->m_hWnd)
  781. {
  782. auto p = GetParent();
  783. if (p != NULL)
  784. {
  785. p->SetFocus();
  786. }
  787. }
  788. }
  789. break;
  790. }
  791. case TIMER_AUTO_MAX:
  792. {
  793. if (m_DittoWindow.m_bMinimized)
  794. {
  795. CPoint cp;
  796. GetCursorPos(&cp);
  797. UINT nHitTest = (UINT)OnNcHitTest(cp);
  798. ScreenToClient(&cp);
  799. if (nHitTest == HTCAPTION)
  800. {
  801. if (m_DittoWindow.m_crCloseBT.PtInRect(cp) == false)
  802. {
  803. if (m_DittoWindow.m_crMinimizeBT.PtInRect(cp) == false)
  804. {
  805. m_DittoWindow.MinMaxWindow(this, FORCE_MAX);
  806. }
  807. }
  808. }
  809. }
  810. KillTimer(TIMER_AUTO_MAX);
  811. m_bMaxSetTimer = false;
  812. }
  813. }
  814. CWnd::OnTimer(nIDEvent);
  815. }
  816. void CToolTipEx::OnNcPaint()
  817. {
  818. m_DittoWindow.DoNcPaint(this);
  819. }
  820. void CToolTipEx::OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS FAR* lpncsp)
  821. {
  822. CWnd::OnNcCalcSize(bCalcValidRects, lpncsp);
  823. m_DittoWindow.DoNcCalcSize(bCalcValidRects, lpncsp);
  824. }
  825. HITTEST_RET CToolTipEx::OnNcHitTest(CPoint point)
  826. {
  827. UINT Ret = m_DittoWindow.DoNcHitTest(this, point);
  828. if(Ret == -1)
  829. return CWnd::OnNcHitTest(point);
  830. return Ret;
  831. }
  832. void CToolTipEx::OnNcLButtonDown(UINT nHitTest, CPoint point)
  833. {
  834. int buttonPressed = m_DittoWindow.DoNcLButtonDown(this, nHitTest, point);
  835. SetTimer(TIMER_BUTTON_UP, 100, NULL);
  836. CWnd::OnNcLButtonDown(nHitTest, point);
  837. }
  838. void CToolTipEx::OnNcLButtonUp(UINT nHitTest, CPoint point)
  839. {
  840. long lRet = m_DittoWindow.DoNcLButtonUp(this, nHitTest, point);
  841. switch(lRet)
  842. {
  843. case BUTTON_CLOSE:
  844. Hide();
  845. break;
  846. case BUTTON_CHEVRON:
  847. m_DittoWindow.MinMaxWindow(this, SWAP_MIN_MAX);
  848. OnNcPaint();
  849. break;
  850. }
  851. KillTimer(TIMER_BUTTON_UP);
  852. auto f = GetFocus();
  853. if (f != NULL &&
  854. m_RichEdit.m_hWnd != f->m_hWnd)
  855. {
  856. auto p = GetParent();
  857. if (p != NULL)
  858. {
  859. p->SetFocus();
  860. }
  861. }
  862. CWnd::OnNcLButtonUp(nHitTest, point);
  863. }
  864. void CToolTipEx::OnNcMouseMove(UINT nHitTest, CPoint point)
  865. {
  866. m_DittoWindow.DoNcMouseMove(this, nHitTest, point);
  867. if ((m_bMaxSetTimer == false) && m_DittoWindow.m_bMinimized)
  868. {
  869. COleDateTimeSpan sp = COleDateTime::GetCurrentTime() - m_DittoWindow.m_TimeMinimized;
  870. if (sp.GetTotalSeconds() >= m_lDelayMaxSeconds)
  871. {
  872. SetTimer(TIMER_AUTO_MAX, CGetSetOptions::GetTimeBeforeExpandWindow(), NULL);
  873. m_bMaxSetTimer = true;
  874. }
  875. }
  876. CWnd::OnNcMouseMove(nHitTest, point);
  877. }
  878. void CToolTipEx::OnOptions()
  879. {
  880. POINT pp;
  881. CMenu cmPopUp;
  882. CMenu *cmSubMenu = NULL;
  883. GetCursorPos(&pp);
  884. if(cmPopUp.LoadMenu(IDR_DESC_OPTIONS_MENU) != 0)
  885. {
  886. cmSubMenu = cmPopUp.GetSubMenu(0);
  887. if(!cmSubMenu)
  888. {
  889. return ;
  890. }
  891. GetCursorPos(&pp);
  892. //theApp.m_Language.UpdateRightClickMenu(cmSubMenu);
  893. if(CGetSetOptions::GetRememberDescPos())
  894. cmSubMenu->CheckMenuItem(ID_FIRST_REMEMBERWINDOWPOSITION, MF_CHECKED);
  895. if(CGetSetOptions::GetSizeDescWindowToContent())
  896. cmSubMenu->CheckMenuItem(ID_FIRST_SIZEWINDOWTOCONTENT, MF_CHECKED);
  897. if(CGetSetOptions::GetScaleImagesToDescWindow())
  898. cmSubMenu->CheckMenuItem(ID_FIRST_SCALEIMAGESTOFITWINDOW, MF_CHECKED);
  899. if (CGetSetOptions::GetMouseClickHidesDescription())
  900. cmSubMenu->CheckMenuItem(ID_FIRST_HIDEDESCRIPTIONWINDOWONM, MF_CHECKED);
  901. if (CGetSetOptions::GetWrapDescriptionText())
  902. cmSubMenu->CheckMenuItem(ID_FIRST_WRAPTEXT, MF_CHECKED);
  903. if (m_showPersistant)
  904. cmSubMenu->CheckMenuItem(ID_FIRST_ALWAYSONTOP, MF_CHECKED);
  905. UpdateMenuShortCut(cmSubMenu, ID_FIRST_WRAPTEXT, ActionEnums::TOGGLE_DESCRIPTION_WORD_WRAP);
  906. UpdateMenuShortCut(cmSubMenu, ID_FIRST_ALWAYSONTOP, ActionEnums::TOGGLESHOWPERSISTANT);
  907. cmSubMenu->TrackPopupMenu(TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RIGHTBUTTON, pp.x, pp.y, this, NULL);
  908. }
  909. }
  910. void CToolTipEx::UpdateMenuShortCut(CMenu *subMenu, int id, DWORD action)
  911. {
  912. if (m_pToolTipActions != NULL)
  913. {
  914. CString cs;
  915. subMenu->GetMenuString(id, cs, MF_BYCOMMAND);
  916. CString shortcutText = m_pToolTipActions->GetCmdKeyText(action);
  917. if (shortcutText != _T("") &&
  918. cs.Find("\t" + shortcutText) < 0)
  919. {
  920. cs += "\t";
  921. cs += shortcutText;
  922. subMenu->ModifyMenu(id, MF_BYCOMMAND, id, cs);
  923. }
  924. }
  925. }
  926. void CToolTipEx::OnRememberwindowposition()
  927. {
  928. CGetSetOptions::SetRememberDescPos(!CGetSetOptions::GetRememberDescPos());
  929. }
  930. void CToolTipEx::OnSizewindowtocontent()
  931. {
  932. CGetSetOptions::SetSizeDescWindowToContent(!CGetSetOptions::GetSizeDescWindowToContent());
  933. CRect rect;
  934. this->GetWindowRect(&rect);
  935. Show(rect.TopLeft());
  936. }
  937. void CToolTipEx::OnScaleimagestofitwindow()
  938. {
  939. CGetSetOptions::SetScaleImagesToDescWindow(!CGetSetOptions::GetScaleImagesToDescWindow());
  940. m_imageViewer.UpdateBitmapSize();
  941. Invalidate();
  942. }
  943. void CToolTipEx::OnRButtonDown(UINT nFlags, CPoint point)
  944. {
  945. OnOptions();
  946. CWnd::OnRButtonDown(nFlags, point);
  947. }
  948. void CToolTipEx::OnSetFocus(CWnd* pOldWnd)
  949. {
  950. CWnd::OnSetFocus(pOldWnd);
  951. if (m_RichEdit.IsWindowVisible())
  952. {
  953. m_RichEdit.SetFocus();
  954. }
  955. }
  956. void CToolTipEx::OnPaint()
  957. {
  958. CPaintDC dc(this); // device context for painting
  959. CRect rect;
  960. GetClientRect(rect);
  961. CBrush Brush, *pOldBrush;
  962. Brush.CreateSolidBrush(g_Opt.m_Theme.DescriptionWindowBG());
  963. pOldBrush = dc.SelectObject(&Brush);
  964. dc.FillRect(&rect, &Brush);
  965. // Cleanup
  966. dc.SelectObject(pOldBrush);
  967. }
  968. void CToolTipEx::OnFirstHidedescriptionwindowonm()
  969. {
  970. CGetSetOptions::SetMouseClickHidesDescription(!CGetSetOptions::GetMouseClickHidesDescription());
  971. }
  972. bool CToolTipEx::ToggleWordWrap()
  973. {
  974. bool didWordWrap = false;
  975. if (m_RichEdit.IsWindowVisible())
  976. {
  977. OnFirstWraptext();
  978. didWordWrap = true;
  979. }
  980. return didWordWrap;
  981. }
  982. void CToolTipEx::OnFirstWraptext()
  983. {
  984. CGetSetOptions::SetWrapDescriptionText(!CGetSetOptions::GetWrapDescriptionText());
  985. ApplyWordWrap();
  986. }
  987. void CToolTipEx::ApplyWordWrap()
  988. {
  989. if (CGetSetOptions::GetWrapDescriptionText())
  990. {
  991. m_RichEdit.SetTargetDevice(NULL, 0);
  992. }
  993. else
  994. {
  995. m_RichEdit.SetTargetDevice(NULL, 1);
  996. }
  997. }
  998. void CToolTipEx::HideWindowInXMilliSeconds(long lms)
  999. {
  1000. SetTimer(HIDE_WINDOW_TIMER, lms, NULL);
  1001. }
  1002. void CToolTipEx::OnWindowPosChanging(WINDOWPOS* lpwndpos)
  1003. {
  1004. CWnd::OnWindowPosChanging(lpwndpos);
  1005. //m_DittoWindow.SnapToEdge(this, lpwndpos);
  1006. }
  1007. void CToolTipEx::OnFirstAlwaysontop()
  1008. {
  1009. m_showPersistant = !m_showPersistant;
  1010. if (m_showPersistant)
  1011. {
  1012. m_DittoWindow.m_customWindowTitle = _T("[Always on top]");
  1013. m_DittoWindow.m_useCustomWindowTitle = true;
  1014. ::SetWindowPos(m_hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_SHOWWINDOW | SWP_NOACTIVATE);
  1015. }
  1016. else
  1017. {
  1018. m_DittoWindow.m_customWindowTitle = _T("");
  1019. m_DittoWindow.m_useCustomWindowTitle = true;
  1020. }
  1021. ::SetWindowPos(m_hWnd, NULL, 0, 0, 0, 0, SWP_DRAWFRAME | SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
  1022. }
  1023. BOOL CToolTipEx::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
  1024. {
  1025. CString cs;
  1026. cs.Format(_T("On Notify: %d\r\n"), ((LPNMHDR)lParam)->code);
  1027. OutputDebugString(cs);
  1028. switch (((LPNMHDR)lParam)->code)
  1029. {
  1030. case EN_LINK:
  1031. {
  1032. ENLINK *enLinkInfo = (ENLINK *)lParam; // pointer to a ENLINK structure
  1033. if (enLinkInfo->msg == WM_LBUTTONUP)
  1034. {
  1035. CString s;
  1036. m_RichEdit.GetTextRange(enLinkInfo->chrg.cpMin, enLinkInfo->chrg.cpMax, s);
  1037. if (s == m_mouseDownOnLink)
  1038. {
  1039. CHyperLink::GotoURL(s, SW_SHOW);
  1040. }
  1041. m_mouseDownOnLink = _T("");
  1042. }
  1043. if (enLinkInfo->msg == WM_LBUTTONDOWN)
  1044. {
  1045. m_RichEdit.GetTextRange(enLinkInfo->chrg.cpMin, enLinkInfo->chrg.cpMax, m_mouseDownOnLink);
  1046. }
  1047. }
  1048. break;
  1049. case SimpleBrowser::NotificationType::BeforeNavigate2:
  1050. {
  1051. SimpleBrowser::Notification * not = (SimpleBrowser::Notification *)lParam;
  1052. if (not != NULL)
  1053. {
  1054. if (not->URL.Find(_T("http")) >= 0)
  1055. {
  1056. CHyperLink::GotoURL(not->URL, SW_SHOW);
  1057. *pResult = TRUE;
  1058. //return TRUE;
  1059. }
  1060. }
  1061. }
  1062. break;
  1063. case 5:
  1064. int x = 0;
  1065. break;
  1066. }
  1067. return CWnd::OnNotify(wParam, lParam, pResult);
  1068. }
  1069. void CToolTipEx::OnEnMsgfilterRichedit21(NMHDR *pNMHDR, LRESULT *pResult)
  1070. {
  1071. MSGFILTER *pMsgFilter = reinterpret_cast<MSGFILTER *>(pNMHDR);
  1072. if (pMsgFilter != NULL)
  1073. {
  1074. switch (pMsgFilter->msg)
  1075. {
  1076. //handle click on the rich text control when it doesn't have focus
  1077. //set focus so the first click is handled by the rich text control
  1078. case WM_MOUSEACTIVATE:
  1079. m_RichEdit.SetFocus();
  1080. break;
  1081. case WM_MOUSEHWHEEL:
  1082. int delta = GET_WHEEL_DELTA_WPARAM(pMsgFilter->wParam);
  1083. if (delta < 0)
  1084. {
  1085. m_RichEdit.SendMessage(WM_HSCROLL, SB_LINERIGHT, NULL);
  1086. }
  1087. else
  1088. {
  1089. m_RichEdit.SendMessage(WM_HSCROLL, SB_LINELEFT, NULL);
  1090. }
  1091. break;
  1092. }
  1093. }
  1094. *pResult = 0;
  1095. }
  1096. LRESULT CToolTipEx::OnDpiChanged(WPARAM wParam, LPARAM lParam)
  1097. {
  1098. int dpi = HIWORD(wParam);
  1099. m_DittoWindow.OnDpiChanged(this, dpi);
  1100. RECT* const prcNewWindow = (RECT*)lParam;
  1101. SetWindowPos(NULL,
  1102. prcNewWindow->left,
  1103. prcNewWindow->top,
  1104. prcNewWindow->right - prcNewWindow->left,
  1105. prcNewWindow->bottom - prcNewWindow->top,
  1106. SWP_NOZORDER | SWP_NOACTIVATE);
  1107. m_optionsButton.Reset();
  1108. m_optionsButton.LoadStdImageDPI(m_DittoWindow.m_dpi.GetDPI(), IDB_COG_16_16, IDB_COG_20_20, IDB_COG_24_24, cog_28, IDB_COG_32_32, _T("PNG"));
  1109. m_clipDataFont.Detach();
  1110. m_clipDataFont.CreateFont(-m_DittoWindow.m_dpi.Scale(8), 0, 0, 0, 400, 0, 0, 0, DEFAULT_CHARSET, 3, 2, 1, 34, _T("Segoe UI"));
  1111. m_clipDataStatic.SetFont(&m_clipDataFont);
  1112. m_clipDataStatic.SetBkColor(g_Opt.m_Theme.DescriptionWindowBG());
  1113. m_clipDataStatic.SetTextColor(RGB(80, 80, 80));
  1114. m_folderPathStatic.SetFont(&m_clipDataFont);
  1115. m_folderPathStatic.SetBkColor(g_Opt.m_Theme.DescriptionWindowBG());
  1116. m_folderPathStatic.SetTextColor(RGB(80, 80, 80));
  1117. LOGFONT lf;
  1118. m_Font.GetLogFont(&lf);
  1119. lf.lfHeight = m_DittoWindow.m_dpi.Scale(m_fontHeight);
  1120. // Create the actual font object
  1121. m_Font.DeleteObject();
  1122. m_Font.CreateFontIndirect(&lf);
  1123. m_RichEdit.SetFont(&m_Font);
  1124. this->MoveControls();
  1125. this->Invalidate();
  1126. this->UpdateWindow();
  1127. return TRUE;
  1128. }
  1129. void CToolTipEx::OnMoving(UINT fwSide, LPRECT pRect)
  1130. {
  1131. CWnd::OnMoving(fwSide, pRect);
  1132. m_snap.OnSnapMoving(m_hWnd, pRect);
  1133. // TODO: Add your message handler code here
  1134. }
  1135. void CToolTipEx::OnEnterSizeMove()
  1136. {
  1137. m_snap.OnSnapEnterSizeMove(m_hWnd);
  1138. CWnd::OnEnterSizeMove();
  1139. }
  1140. void CToolTipEx::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
  1141. {
  1142. int x = 9;
  1143. //m_scrollHelper.OnHScroll(nSBCode, nPos, pScrollBar);
  1144. }