ToolTipEx.cpp 31 KB

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