ToolTipEx.cpp 34 KB

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