ToolTipEx.cpp 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409
  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. m_RichEdit.SetRedraw(0);
  697. auto mask = m_RichEdit.GetEventMask();
  698. m_RichEdit.SetEventMask(0);
  699. do
  700. {
  701. ft.chrg.cpMin = n+1;
  702. n = m_RichEdit.FindText(FR_DOWN, &ft);
  703. if (n != -1)
  704. {
  705. m_RichEdit.SetSel(ft.chrgText);
  706. m_RichEdit.SetSelectionCharFormat(cf);
  707. }
  708. } while (n != -1);
  709. m_RichEdit.SetSel(0, 0);
  710. m_RichEdit.SetEventMask(mask);
  711. m_RichEdit.SetRedraw(1);
  712. m_RichEdit.UpdateWindow();
  713. }
  714. void CToolTipEx::DoSearch()
  715. {
  716. if (m_searchText.GetLength() <= 0)
  717. return;
  718. FINDTEXTEX ft;
  719. long n = -1;
  720. ft.lpstrText = m_searchText;
  721. long start;
  722. long end;
  723. m_RichEdit.GetSel(start, end);
  724. ft.chrg.cpMin = end;
  725. ft.chrg.cpMax = -1;
  726. int searchDirection = FR_DOWN;
  727. if (GetKeyState(VK_SHIFT) & 0x8000)
  728. {
  729. searchDirection = 0;
  730. ft.chrg.cpMin = start;
  731. }
  732. n = m_RichEdit.FindText(searchDirection, &ft);
  733. if (n != -1)
  734. {
  735. m_RichEdit.SetSel(ft.chrgText);
  736. }
  737. else
  738. {
  739. if (searchDirection == 0)
  740. {
  741. ft.chrg.cpMin = m_RichEdit.GetTextLength();
  742. }
  743. else
  744. {
  745. ft.chrg.cpMin = 0;
  746. }
  747. ft.chrg.cpMax = -1;
  748. n = m_RichEdit.FindText(searchDirection, &ft);
  749. if (n != -1)
  750. {
  751. m_RichEdit.SetSel(ft.chrgText);
  752. }
  753. }
  754. }
  755. void CToolTipEx::OnActivate(UINT nState, CWnd *pWndOther, BOOL bMinimized)
  756. {
  757. CWnd::OnActivate(nState, pWndOther, bMinimized);
  758. if (nState == WA_INACTIVE)
  759. {
  760. if(m_pNotifyWnd)
  761. {
  762. m_pNotifyWnd->PostMessage(NM_INACTIVE_TOOLTIPWND, 0, 0);
  763. }
  764. }
  765. }
  766. void CToolTipEx::OnTimer(UINT_PTR nIDEvent)
  767. {
  768. switch(nIDEvent)
  769. {
  770. case HIDE_WINDOW_TIMER:
  771. Hide();
  772. PostMessage(WM_DESTROY, 0, 0);
  773. break;
  774. case SAVE_SIZE:
  775. SaveWindowSize();
  776. KillTimer(SAVE_SIZE);
  777. break;
  778. case TIMER_BUTTON_UP:
  779. {
  780. if ((GetKeyState(VK_LBUTTON) & 0x100) == 0)
  781. {
  782. m_DittoWindow.DoNcLButtonUp(this, 0, CPoint(0, 0));
  783. KillTimer(TIMER_BUTTON_UP);
  784. auto f = GetFocus();
  785. if (f != NULL &&
  786. m_RichEdit.m_hWnd != f->m_hWnd)
  787. {
  788. auto p = GetParent();
  789. if (p != NULL)
  790. {
  791. p->SetFocus();
  792. }
  793. }
  794. }
  795. break;
  796. }
  797. case TIMER_AUTO_MAX:
  798. {
  799. if (m_DittoWindow.m_bMinimized)
  800. {
  801. CPoint cp;
  802. GetCursorPos(&cp);
  803. UINT nHitTest = (UINT)OnNcHitTest(cp);
  804. ScreenToClient(&cp);
  805. if (nHitTest == HTCAPTION)
  806. {
  807. if (m_DittoWindow.m_crCloseBT.PtInRect(cp) == false)
  808. {
  809. if (m_DittoWindow.m_crMinimizeBT.PtInRect(cp) == false)
  810. {
  811. m_DittoWindow.MinMaxWindow(this, FORCE_MAX);
  812. }
  813. }
  814. }
  815. }
  816. KillTimer(TIMER_AUTO_MAX);
  817. m_bMaxSetTimer = false;
  818. }
  819. }
  820. CWnd::OnTimer(nIDEvent);
  821. }
  822. void CToolTipEx::OnNcPaint()
  823. {
  824. m_DittoWindow.DoNcPaint(this);
  825. }
  826. void CToolTipEx::OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS FAR* lpncsp)
  827. {
  828. CWnd::OnNcCalcSize(bCalcValidRects, lpncsp);
  829. m_DittoWindow.DoNcCalcSize(bCalcValidRects, lpncsp);
  830. }
  831. HITTEST_RET CToolTipEx::OnNcHitTest(CPoint point)
  832. {
  833. UINT Ret = m_DittoWindow.DoNcHitTest(this, point);
  834. if(Ret == -1)
  835. return CWnd::OnNcHitTest(point);
  836. return Ret;
  837. }
  838. void CToolTipEx::OnNcLButtonDown(UINT nHitTest, CPoint point)
  839. {
  840. int buttonPressed = m_DittoWindow.DoNcLButtonDown(this, nHitTest, point);
  841. SetTimer(TIMER_BUTTON_UP, 100, NULL);
  842. CWnd::OnNcLButtonDown(nHitTest, point);
  843. }
  844. void CToolTipEx::OnNcLButtonUp(UINT nHitTest, CPoint point)
  845. {
  846. long lRet = m_DittoWindow.DoNcLButtonUp(this, nHitTest, point);
  847. switch(lRet)
  848. {
  849. case BUTTON_CLOSE:
  850. Hide();
  851. break;
  852. case BUTTON_CHEVRON:
  853. m_DittoWindow.MinMaxWindow(this, SWAP_MIN_MAX);
  854. OnNcPaint();
  855. break;
  856. }
  857. KillTimer(TIMER_BUTTON_UP);
  858. auto f = GetFocus();
  859. if (f != NULL &&
  860. m_RichEdit.m_hWnd != f->m_hWnd)
  861. {
  862. auto p = GetParent();
  863. if (p != NULL)
  864. {
  865. p->SetFocus();
  866. }
  867. }
  868. CWnd::OnNcLButtonUp(nHitTest, point);
  869. }
  870. void CToolTipEx::OnNcMouseMove(UINT nHitTest, CPoint point)
  871. {
  872. m_DittoWindow.DoNcMouseMove(this, nHitTest, point);
  873. if ((m_bMaxSetTimer == false) && m_DittoWindow.m_bMinimized)
  874. {
  875. COleDateTimeSpan sp = COleDateTime::GetCurrentTime() - m_DittoWindow.m_TimeMinimized;
  876. if (sp.GetTotalSeconds() >= m_lDelayMaxSeconds)
  877. {
  878. SetTimer(TIMER_AUTO_MAX, CGetSetOptions::GetTimeBeforeExpandWindow(), NULL);
  879. m_bMaxSetTimer = true;
  880. }
  881. }
  882. CWnd::OnNcMouseMove(nHitTest, point);
  883. }
  884. void CToolTipEx::OnOptions()
  885. {
  886. POINT pp;
  887. CMenu cmPopUp;
  888. CMenu *cmSubMenu = NULL;
  889. GetCursorPos(&pp);
  890. if(cmPopUp.LoadMenu(IDR_DESC_OPTIONS_MENU) != 0)
  891. {
  892. cmSubMenu = cmPopUp.GetSubMenu(0);
  893. if(!cmSubMenu)
  894. {
  895. return ;
  896. }
  897. GetCursorPos(&pp);
  898. //theApp.m_Language.UpdateRightClickMenu(cmSubMenu);
  899. if(CGetSetOptions::GetRememberDescPos())
  900. cmSubMenu->CheckMenuItem(ID_FIRST_REMEMBERWINDOWPOSITION, MF_CHECKED);
  901. if(CGetSetOptions::GetSizeDescWindowToContent())
  902. cmSubMenu->CheckMenuItem(ID_FIRST_SIZEWINDOWTOCONTENT, MF_CHECKED);
  903. if(CGetSetOptions::GetScaleImagesToDescWindow())
  904. cmSubMenu->CheckMenuItem(ID_FIRST_SCALEIMAGESTOFITWINDOW, MF_CHECKED);
  905. if (CGetSetOptions::GetMouseClickHidesDescription())
  906. cmSubMenu->CheckMenuItem(ID_FIRST_HIDEDESCRIPTIONWINDOWONM, MF_CHECKED);
  907. if (CGetSetOptions::GetWrapDescriptionText())
  908. cmSubMenu->CheckMenuItem(ID_FIRST_WRAPTEXT, MF_CHECKED);
  909. if (m_showPersistant)
  910. cmSubMenu->CheckMenuItem(ID_FIRST_ALWAYSONTOP, MF_CHECKED);
  911. UpdateMenuShortCut(cmSubMenu, ID_FIRST_WRAPTEXT, ActionEnums::TOGGLE_DESCRIPTION_WORD_WRAP);
  912. UpdateMenuShortCut(cmSubMenu, ID_FIRST_ALWAYSONTOP, ActionEnums::TOGGLESHOWPERSISTANT);
  913. cmSubMenu->TrackPopupMenu(TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RIGHTBUTTON, pp.x, pp.y, this, NULL);
  914. }
  915. }
  916. void CToolTipEx::UpdateMenuShortCut(CMenu *subMenu, int id, DWORD action)
  917. {
  918. if (m_pToolTipActions != NULL)
  919. {
  920. CString cs;
  921. subMenu->GetMenuString(id, cs, MF_BYCOMMAND);
  922. CString shortcutText = m_pToolTipActions->GetCmdKeyText(action);
  923. if (shortcutText != _T("") &&
  924. cs.Find("\t" + shortcutText) < 0)
  925. {
  926. cs += "\t";
  927. cs += shortcutText;
  928. subMenu->ModifyMenu(id, MF_BYCOMMAND, id, cs);
  929. }
  930. }
  931. }
  932. void CToolTipEx::OnRememberwindowposition()
  933. {
  934. CGetSetOptions::SetRememberDescPos(!CGetSetOptions::GetRememberDescPos());
  935. }
  936. void CToolTipEx::OnSizewindowtocontent()
  937. {
  938. CGetSetOptions::SetSizeDescWindowToContent(!CGetSetOptions::GetSizeDescWindowToContent());
  939. CRect rect;
  940. this->GetWindowRect(&rect);
  941. Show(rect.TopLeft());
  942. }
  943. void CToolTipEx::OnScaleimagestofitwindow()
  944. {
  945. CGetSetOptions::SetScaleImagesToDescWindow(!CGetSetOptions::GetScaleImagesToDescWindow());
  946. m_imageViewer.UpdateBitmapSize();
  947. Invalidate();
  948. }
  949. void CToolTipEx::OnRButtonDown(UINT nFlags, CPoint point)
  950. {
  951. OnOptions();
  952. CWnd::OnRButtonDown(nFlags, point);
  953. }
  954. void CToolTipEx::OnSetFocus(CWnd* pOldWnd)
  955. {
  956. CWnd::OnSetFocus(pOldWnd);
  957. if (m_RichEdit.IsWindowVisible())
  958. {
  959. m_RichEdit.SetFocus();
  960. }
  961. }
  962. void CToolTipEx::OnPaint()
  963. {
  964. CPaintDC dc(this); // device context for painting
  965. CRect rect;
  966. GetClientRect(rect);
  967. CBrush Brush, *pOldBrush;
  968. Brush.CreateSolidBrush(g_Opt.m_Theme.DescriptionWindowBG());
  969. pOldBrush = dc.SelectObject(&Brush);
  970. dc.FillRect(&rect, &Brush);
  971. // Cleanup
  972. dc.SelectObject(pOldBrush);
  973. }
  974. void CToolTipEx::OnFirstHidedescriptionwindowonm()
  975. {
  976. CGetSetOptions::SetMouseClickHidesDescription(!CGetSetOptions::GetMouseClickHidesDescription());
  977. }
  978. bool CToolTipEx::ToggleWordWrap()
  979. {
  980. bool didWordWrap = false;
  981. if (m_RichEdit.IsWindowVisible())
  982. {
  983. OnFirstWraptext();
  984. didWordWrap = true;
  985. }
  986. return didWordWrap;
  987. }
  988. void CToolTipEx::OnFirstWraptext()
  989. {
  990. CGetSetOptions::SetWrapDescriptionText(!CGetSetOptions::GetWrapDescriptionText());
  991. ApplyWordWrap();
  992. }
  993. void CToolTipEx::ApplyWordWrap()
  994. {
  995. if (CGetSetOptions::GetWrapDescriptionText())
  996. {
  997. m_RichEdit.SetTargetDevice(NULL, 0);
  998. }
  999. else
  1000. {
  1001. m_RichEdit.SetTargetDevice(NULL, 1);
  1002. }
  1003. }
  1004. void CToolTipEx::HideWindowInXMilliSeconds(long lms)
  1005. {
  1006. SetTimer(HIDE_WINDOW_TIMER, lms, NULL);
  1007. }
  1008. void CToolTipEx::OnWindowPosChanging(WINDOWPOS* lpwndpos)
  1009. {
  1010. CWnd::OnWindowPosChanging(lpwndpos);
  1011. //m_DittoWindow.SnapToEdge(this, lpwndpos);
  1012. }
  1013. void CToolTipEx::OnFirstAlwaysontop()
  1014. {
  1015. m_showPersistant = !m_showPersistant;
  1016. if (m_showPersistant)
  1017. {
  1018. m_DittoWindow.m_customWindowTitle = _T("[Always on top]");
  1019. m_DittoWindow.m_useCustomWindowTitle = true;
  1020. ::SetWindowPos(m_hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_SHOWWINDOW | SWP_NOACTIVATE);
  1021. }
  1022. else
  1023. {
  1024. m_DittoWindow.m_customWindowTitle = _T("");
  1025. m_DittoWindow.m_useCustomWindowTitle = true;
  1026. }
  1027. ::SetWindowPos(m_hWnd, NULL, 0, 0, 0, 0, SWP_DRAWFRAME | SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
  1028. }
  1029. BOOL CToolTipEx::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
  1030. {
  1031. CString cs;
  1032. cs.Format(_T("On Notify: %d\r\n"), ((LPNMHDR)lParam)->code);
  1033. OutputDebugString(cs);
  1034. switch (((LPNMHDR)lParam)->code)
  1035. {
  1036. case EN_LINK:
  1037. {
  1038. ENLINK *enLinkInfo = (ENLINK *)lParam; // pointer to a ENLINK structure
  1039. if (enLinkInfo->msg == WM_LBUTTONUP)
  1040. {
  1041. CString s;
  1042. m_RichEdit.GetTextRange(enLinkInfo->chrg.cpMin, enLinkInfo->chrg.cpMax, s);
  1043. if (s == m_mouseDownOnLink)
  1044. {
  1045. CHyperLink::GotoURL(s, SW_SHOW);
  1046. }
  1047. m_mouseDownOnLink = _T("");
  1048. }
  1049. if (enLinkInfo->msg == WM_LBUTTONDOWN)
  1050. {
  1051. m_RichEdit.GetTextRange(enLinkInfo->chrg.cpMin, enLinkInfo->chrg.cpMax, m_mouseDownOnLink);
  1052. }
  1053. }
  1054. break;
  1055. case SimpleBrowser::NotificationType::BeforeNavigate2:
  1056. {
  1057. SimpleBrowser::Notification * not = (SimpleBrowser::Notification *)lParam;
  1058. if (not != NULL)
  1059. {
  1060. if (not->URL.Find(_T("http")) >= 0)
  1061. {
  1062. CHyperLink::GotoURL(not->URL, SW_SHOW);
  1063. *pResult = TRUE;
  1064. //return TRUE;
  1065. }
  1066. }
  1067. }
  1068. break;
  1069. case 5:
  1070. int x = 0;
  1071. break;
  1072. }
  1073. return CWnd::OnNotify(wParam, lParam, pResult);
  1074. }
  1075. void CToolTipEx::OnEnMsgfilterRichedit21(NMHDR *pNMHDR, LRESULT *pResult)
  1076. {
  1077. MSGFILTER *pMsgFilter = reinterpret_cast<MSGFILTER *>(pNMHDR);
  1078. if (pMsgFilter != NULL)
  1079. {
  1080. switch (pMsgFilter->msg)
  1081. {
  1082. //handle click on the rich text control when it doesn't have focus
  1083. //set focus so the first click is handled by the rich text control
  1084. case WM_MOUSEACTIVATE:
  1085. m_RichEdit.SetFocus();
  1086. break;
  1087. case WM_MOUSEHWHEEL:
  1088. int delta = GET_WHEEL_DELTA_WPARAM(pMsgFilter->wParam);
  1089. if (delta < 0)
  1090. {
  1091. m_RichEdit.SendMessage(WM_HSCROLL, SB_LINERIGHT, NULL);
  1092. }
  1093. else
  1094. {
  1095. m_RichEdit.SendMessage(WM_HSCROLL, SB_LINELEFT, NULL);
  1096. }
  1097. break;
  1098. }
  1099. }
  1100. *pResult = 0;
  1101. }
  1102. LRESULT CToolTipEx::OnDpiChanged(WPARAM wParam, LPARAM lParam)
  1103. {
  1104. int dpi = HIWORD(wParam);
  1105. m_DittoWindow.OnDpiChanged(this, dpi);
  1106. RECT* const prcNewWindow = (RECT*)lParam;
  1107. SetWindowPos(NULL,
  1108. prcNewWindow->left,
  1109. prcNewWindow->top,
  1110. prcNewWindow->right - prcNewWindow->left,
  1111. prcNewWindow->bottom - prcNewWindow->top,
  1112. SWP_NOZORDER | SWP_NOACTIVATE);
  1113. m_optionsButton.Reset();
  1114. 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"));
  1115. m_clipDataFont.Detach();
  1116. 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"));
  1117. m_clipDataStatic.SetFont(&m_clipDataFont);
  1118. m_clipDataStatic.SetBkColor(g_Opt.m_Theme.DescriptionWindowBG());
  1119. m_clipDataStatic.SetTextColor(RGB(80, 80, 80));
  1120. m_folderPathStatic.SetFont(&m_clipDataFont);
  1121. m_folderPathStatic.SetBkColor(g_Opt.m_Theme.DescriptionWindowBG());
  1122. m_folderPathStatic.SetTextColor(RGB(80, 80, 80));
  1123. LOGFONT lf;
  1124. m_Font.GetLogFont(&lf);
  1125. lf.lfHeight = m_DittoWindow.m_dpi.Scale(m_fontHeight);
  1126. // Create the actual font object
  1127. m_Font.DeleteObject();
  1128. m_Font.CreateFontIndirect(&lf);
  1129. m_RichEdit.SetFont(&m_Font);
  1130. this->MoveControls();
  1131. this->Invalidate();
  1132. this->UpdateWindow();
  1133. return TRUE;
  1134. }
  1135. void CToolTipEx::OnMoving(UINT fwSide, LPRECT pRect)
  1136. {
  1137. CWnd::OnMoving(fwSide, pRect);
  1138. m_snap.OnSnapMoving(m_hWnd, pRect);
  1139. // TODO: Add your message handler code here
  1140. }
  1141. void CToolTipEx::OnEnterSizeMove()
  1142. {
  1143. m_snap.OnSnapEnterSizeMove(m_hWnd);
  1144. CWnd::OnEnterSizeMove();
  1145. }
  1146. void CToolTipEx::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
  1147. {
  1148. int x = 9;
  1149. //m_scrollHelper.OnHScroll(nSBCode, nPos, pScrollBar);
  1150. }