ToolTipEx.cpp 33 KB

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