ToolTipEx.cpp 34 KB

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