ToolTipEx.cpp 32 KB

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