ToolTipEx.cpp 31 KB

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