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