ToolTipEx.cpp 32 KB

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