ToolTipEx.cpp 26 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141
  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. END_MESSAGE_MAP()
  59. /////////////////////////////////////////////////////////////////////////////
  60. // CToolTipEx message handlers
  61. BOOL CToolTipEx::Create(CWnd *pParentWnd)
  62. {
  63. m_saveWindowLockout = true;
  64. // Get the class name and create the window
  65. CString szClassName = AfxRegisterWndClass(CS_CLASSDC | CS_SAVEBITS, LoadCursor(NULL, IDC_ARROW));
  66. // Create the window - just don't show it yet.
  67. if( !CWnd::CreateEx(0, szClassName, _T(""), WS_POPUP,
  68. 0, 0, 0, 0, pParentWnd->GetSafeHwnd(), 0, NULL))
  69. {
  70. return FALSE;
  71. }
  72. //CString szClassName2 = AfxRegisterWndClass(CS_CLASSDC | CS_SAVEBITS, LoadCursor(NULL, IDC_ARROW));
  73. //BOOL b = m_imageViewer.Create(_T(""), szClassName2, WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL, CRect(0, 0, 0, 0), this, 3);
  74. m_imageViewer.Create(this);
  75. m_DittoWindow.DoCreate(this);
  76. m_DittoWindow.SetCaptionColors(g_Opt.m_Theme.CaptionLeft(), g_Opt.m_Theme.CaptionRight(), g_Opt.m_Theme.Border());
  77. m_DittoWindow.SetCaptionOn(this, CGetSetOptions::GetCaptionPos(), true, g_Opt.m_Theme.GetCaptionSize(), g_Opt.m_Theme.GetCaptionFontSize());
  78. m_DittoWindow.m_bDrawMaximize = false;
  79. m_DittoWindow.m_bDrawMinimize = false;
  80. m_DittoWindow.m_bDrawChevron = true;
  81. m_DittoWindow.m_sendWMClose = false;
  82. m_RichEdit.Create(_T(""), _T(""), WS_CHILD | WS_VISIBLE | WS_VSCROLL |
  83. WS_HSCROLL | ES_MULTILINE | ES_AUTOVSCROLL | ES_NOHIDESEL |
  84. ES_AUTOHSCROLL, CRect(10, 10, 100, 200), this, 1);
  85. m_RichEdit.SetReadOnly();
  86. m_RichEdit.SetBackgroundColor(FALSE, g_Opt.m_Theme.DescriptionWindowBG());
  87. m_RichEdit.SetEventMask(m_RichEdit.GetEventMask() | ENM_SELCHANGE | ENM_LINK);
  88. m_RichEdit.SetAutoURLDetect(TRUE);
  89. ApplyWordWrap();
  90. SetLogFont(GetSystemToolTipFont(), FALSE);
  91. m_optionsButton.Create(NULL, WS_CHILD | BS_OWNERDRAW | WS_TABSTOP, CRect(0, 0, 0, 0), this, 2);
  92. m_optionsButton.LoadStdImageDPI(IDB_COG_16_16, IDB_COG_20_20, IDB_COG_24_24, cog_28, IDB_COG_32_32, _T("PNG"));
  93. m_optionsButton.SetToolTipText(theApp.m_Language.GetString(_T("DescriptionOptionsTooltip"), _T("Description Options")));
  94. m_optionsButton.ShowWindow(SW_SHOW);
  95. m_clipDataStatic.Create(_T("some text"), WS_CHILD | WS_VISIBLE | SS_SIMPLE, CRect(0, 0, 0, 0), this, 3);
  96. m_clipDataFont.CreateFont(-theApp.m_metrics.PointsToPixels(8), 0, 0, 0, 400, 0, 0, 0, DEFAULT_CHARSET, 3, 2, 1, 34, _T("Segoe UI"));
  97. m_clipDataStatic.SetFont(&m_clipDataFont);
  98. m_clipDataStatic.SetBkColor(g_Opt.m_Theme.DescriptionWindowBG());
  99. m_clipDataStatic.SetTextColor(RGB(80, 80, 80));
  100. m_saveWindowLockout = false;
  101. return TRUE;
  102. }
  103. BOOL CToolTipEx::Show(CPoint point)
  104. {
  105. m_reducedWindowSize = false;
  106. if(m_imageViewer.m_pGdiplusBitmap)
  107. {
  108. m_RichEdit.ShowWindow(SW_HIDE);
  109. m_imageViewer.ShowWindow(SW_SHOW);
  110. m_imageViewer.UpdateBitmapSize();
  111. }
  112. else
  113. {
  114. m_RichEdit.ShowWindow(SW_SHOW);
  115. m_imageViewer.ShowWindow(SW_HIDE);
  116. }
  117. CRect rect;
  118. if(CGetSetOptions::GetSizeDescWindowToContent() == FALSE)
  119. {
  120. rect.left = point.x;
  121. rect.top = point.y;
  122. CSize size;
  123. CGetSetOptions::GetDescWndSize(size);
  124. rect.right = rect.left + size.cx;
  125. rect.bottom = rect.top + size.cy;
  126. EnsureWindowVisible(&rect);
  127. }
  128. else
  129. {
  130. rect = GetBoundsRect();
  131. //account for the scroll bars
  132. rect.right += 20;
  133. rect.bottom += 20;
  134. if (m_imageViewer.m_pGdiplusBitmap)
  135. {
  136. int nWidth = m_imageViewer.m_pGdiplusBitmap->GetWidth() + ::GetSystemMetrics(SM_CXVSCROLL);
  137. int nHeight = m_imageViewer.m_pGdiplusBitmap->GetHeight() + ::GetSystemMetrics(SM_CYHSCROLL);
  138. rect.right = rect.left + nWidth;
  139. rect.bottom = rect.top + nHeight;
  140. }
  141. else if(m_csRTF != "")
  142. {
  143. //if showing rtf then increase the size because
  144. //rtf will probably draw bigger
  145. long lNewWidth = (long)rect.Width() + (long)(rect.Width() *1.5);
  146. rect.right = rect.left + lNewWidth;
  147. long lNewHeight = (long)rect.Height() + (long)(rect.Height() *1.5);
  148. rect.bottom = rect.top + lNewHeight;
  149. }
  150. rect.right += CAPTION_BORDER * 2;
  151. rect.bottom += CAPTION_BORDER * 2;
  152. CRect rcScreen;
  153. ClientToScreen(rect);
  154. CRect cr(point, point);
  155. int nMonitor = GetMonitorFromRect(&cr);
  156. GetMonitorRect(nMonitor, &rcScreen);
  157. //ensure that we don't go outside the screen
  158. if(point.x < 0)
  159. {
  160. point.x = 5;
  161. m_reducedWindowSize = true;
  162. }
  163. if(point.y < 0)
  164. {
  165. point.y = 5;
  166. m_reducedWindowSize = true;
  167. }
  168. rcScreen.DeflateRect(0, 0, 5, 5);
  169. long lWidth = rect.Width();
  170. long lHeight = rect.Height();
  171. rect.left = point.x;
  172. rect.top = point.y;
  173. rect.right = rect.left + lWidth;
  174. rect.bottom = rect.top + lHeight;
  175. if (rect.right > rcScreen.right)
  176. {
  177. rect.right = rcScreen.right;
  178. m_reducedWindowSize = true;
  179. }
  180. if (rect.bottom > rcScreen.bottom)
  181. {
  182. rect.bottom = rcScreen.bottom;
  183. m_reducedWindowSize = true;
  184. }
  185. }
  186. m_clipDataStatic.SetWindowText(m_clipData);
  187. if (m_DittoWindow.m_bMinimized)
  188. {
  189. //m_DittoWindow.MinMaxWindow(this, FORCE_MAX);
  190. m_DittoWindow.m_bMinimized = false;
  191. }
  192. m_saveWindowLockout = true;
  193. MoveWindow(rect);
  194. ShowWindow(SW_SHOWNA);
  195. this->Invalidate();
  196. this->UpdateWindow();
  197. m_saveWindowLockout = false;
  198. return TRUE;
  199. }
  200. void CToolTipEx::GetWindowRectEx(LPRECT lpRect)
  201. {
  202. if (m_DittoWindow.m_bMinimized)
  203. {
  204. *lpRect = m_DittoWindow.m_crFullSizeWindow;
  205. return;
  206. }
  207. CWnd::GetWindowRect(lpRect);
  208. }
  209. BOOL CToolTipEx::Hide()
  210. {
  211. delete m_imageViewer.m_pGdiplusBitmap;
  212. m_imageViewer.m_pGdiplusBitmap = NULL;
  213. SaveWindowSize();
  214. ShowWindow(SW_HIDE);
  215. m_csRTF = "";
  216. m_csText = "";
  217. m_clipId = 0;
  218. m_clipRow = -1;
  219. m_searchText = _T("");
  220. m_showPersistant = false;
  221. return TRUE;
  222. }
  223. void CToolTipEx::OnNcLButtonDblClk(UINT nHitTest, CPoint point)
  224. {
  225. // toggle ShowPersistent when we double click the caption
  226. if (nHitTest == HTCAPTION)
  227. {
  228. OnFirstAlwaysontop();
  229. }
  230. CWnd::OnNcLButtonDblClk(nHitTest, point);
  231. }
  232. void CToolTipEx::SaveWindowSize()
  233. {
  234. if (::IsWindowVisible(m_hWnd))
  235. {
  236. CRect rect;
  237. if (m_DittoWindow.m_bMinimized)
  238. {
  239. rect = m_DittoWindow.m_crFullSizeWindow;
  240. }
  241. else
  242. {
  243. this->GetWindowRect(&rect);
  244. }
  245. CGetSetOptions::SetDescWndSize(rect.Size());
  246. CGetSetOptions::SetDescWndPoint(rect.TopLeft());
  247. OutputDebugString(_T("Saving tooltip size"));
  248. }
  249. }
  250. void CToolTipEx::PostNcDestroy()
  251. {
  252. CWnd::PostNcDestroy();
  253. delete this;
  254. }
  255. BOOL CToolTipEx::PreTranslateMessage(MSG *pMsg)
  256. {
  257. m_DittoWindow.DoPreTranslateMessage(pMsg);
  258. switch (pMsg->message)
  259. {
  260. case WM_KEYDOWN:
  261. switch(pMsg->wParam)
  262. {
  263. case 'C':
  264. if(GetKeyState(VK_CONTROL) &0x8000)
  265. {
  266. m_RichEdit.Copy();
  267. }
  268. break;
  269. }
  270. break;
  271. case WM_RBUTTONDOWN:
  272. {
  273. if (m_RichEdit.m_hWnd == GetFocus()->m_hWnd ||
  274. m_imageViewer.m_hWnd == GetFocus()->m_hWnd)
  275. {
  276. OnOptions();
  277. return TRUE;
  278. }
  279. }
  280. break;
  281. }
  282. if (m_pToolTipActions != NULL)
  283. {
  284. CAccel a;
  285. if (m_pToolTipActions->OnMsg(pMsg, a))
  286. {
  287. switch (a.Cmd)
  288. {
  289. case ActionEnums::CLOSEWINDOW:
  290. /*if (this->m_showPersistant &&
  291. m_DittoWindow.m_bMinimized == false)
  292. {
  293. m_DittoWindow.MinMaxWindow(this, FORCE_MIN);
  294. theApp.m_activeWnd.ReleaseFocus();
  295. return TRUE;
  296. }*/
  297. break;
  298. }
  299. }
  300. }
  301. return CWnd::PreTranslateMessage(pMsg);
  302. }
  303. BOOL CToolTipEx::OnMsg(MSG *pMsg)
  304. {
  305. if(FALSE == IsWindowVisible())
  306. {
  307. return FALSE;
  308. }
  309. switch(pMsg->message)
  310. {
  311. case WM_WINDOWPOSCHANGING:
  312. case WM_LBUTTONDOWN:
  313. {
  314. if (m_showPersistant == false)
  315. {
  316. if (CGetSetOptions::GetMouseClickHidesDescription())
  317. {
  318. if (!IsCursorInToolTip())
  319. {
  320. Hide();
  321. }
  322. }
  323. }
  324. }
  325. break;
  326. case WM_KEYDOWN:
  327. {
  328. WPARAM vk = pMsg->wParam;
  329. if(vk == VK_TAB)
  330. {
  331. m_RichEdit.SetFocus();
  332. return TRUE;
  333. }
  334. else if (vk == VK_CONTROL || vk == VK_SHIFT)
  335. {
  336. return FALSE;
  337. }
  338. else if (vk == VK_UP)
  339. {
  340. return FALSE;
  341. }
  342. else if (vk == VK_DOWN)
  343. {
  344. return FALSE;
  345. }
  346. else if (vk == VK_NEXT)
  347. {
  348. return FALSE;
  349. }
  350. else if (vk == VK_PRIOR)
  351. {
  352. return FALSE;
  353. }
  354. if (m_pToolTipActions != NULL)
  355. {
  356. if (m_pToolTipActions->ContainsKey((int)vk))
  357. {
  358. return FALSE;
  359. }
  360. }
  361. if (m_showPersistant == false)
  362. {
  363. Hide();
  364. }
  365. break;
  366. }
  367. case WM_LBUTTONDBLCLK:
  368. case WM_RBUTTONDBLCLK:
  369. case WM_MBUTTONDOWN:
  370. case WM_MBUTTONDBLCLK:
  371. case WM_NCLBUTTONDOWN:
  372. case WM_NCLBUTTONDBLCLK:
  373. case WM_NCRBUTTONDOWN:
  374. case WM_NCRBUTTONDBLCLK:
  375. case WM_NCMBUTTONDOWN:
  376. case WM_NCMBUTTONDBLCLK:
  377. {
  378. if (m_showPersistant == false)
  379. {
  380. Hide();
  381. }
  382. break;
  383. }
  384. case WM_MOUSEWHEEL:
  385. {
  386. if (m_imageViewer.m_pGdiplusBitmap)
  387. {
  388. m_imageViewer.PostMessageW(pMsg->message, pMsg->wParam, pMsg->lParam);
  389. return TRUE;
  390. }
  391. else
  392. {
  393. m_RichEdit.PostMessageW(pMsg->message, pMsg->wParam, pMsg->lParam);
  394. return TRUE;
  395. }
  396. }
  397. break;
  398. }
  399. return FALSE;
  400. }
  401. CRect CToolTipEx::GetBoundsRect()
  402. {
  403. DWORD d = GetTickCount();
  404. CWindowDC dc(NULL);
  405. int nLineWidth = 0;
  406. CRect rect(0, 0, 0, 0);
  407. if(nLineWidth == 0)
  408. {
  409. // Count the number of lines of text
  410. int nStart = 0;
  411. INT nNumLines = 0;
  412. int longestLength = 0;
  413. CString longestString;
  414. do
  415. {
  416. int newStart = m_csText.Find(_T("\n"), nStart);
  417. if (newStart < 0)
  418. {
  419. int length = m_csText.GetLength() - nStart;
  420. if (length > longestLength)
  421. {
  422. longestString = m_csText.Mid(nStart, length);
  423. longestLength = length;
  424. }
  425. break;
  426. }
  427. int length = newStart - nStart;
  428. if(length > longestLength)
  429. {
  430. longestString = m_csText.Mid(nStart, length);
  431. longestLength = length;
  432. }
  433. nNumLines++;
  434. nStart = newStart + 1;
  435. }
  436. while(nStart >= 0 && nNumLines < 100);
  437. CFont *pOldFont = (CFont*)dc.SelectObject((CFont*)&m_Font);
  438. CSize size = dc.GetTextExtent(longestString);
  439. dc.SelectObject(pOldFont);
  440. rect.right = size.cx;
  441. rect.bottom = size.cy * nNumLines;
  442. }
  443. rect.bottom += m_rectMargin.top + m_rectMargin.bottom;
  444. rect.right += m_rectMargin.left + m_rectMargin.right + 2;
  445. if(m_imageViewer.m_pGdiplusBitmap)
  446. {
  447. int nWidth = m_imageViewer.m_pGdiplusBitmap->GetWidth();
  448. int nHeight = m_imageViewer.m_pGdiplusBitmap->GetHeight();
  449. rect.bottom += nHeight;
  450. if((rect.left + nWidth) > rect.right)
  451. {
  452. rect.right = rect.left + nWidth;
  453. }
  454. }
  455. DWORD diff = GetTickCount() - d;
  456. if (diff > 10)
  457. {
  458. Log(StrF(_T("Size To Content: %d\n"), diff));
  459. }
  460. return rect;
  461. }
  462. CString CToolTipEx::GetFieldFromString(CString ref, int nIndex, TCHAR ch)
  463. {
  464. CString strReturn;
  465. LPCTSTR pstrStart = ref.LockBuffer();
  466. LPCTSTR pstrBuffer = pstrStart;
  467. int nCurrent = 0;
  468. int nStart = 0;
  469. int nEnd = 0;
  470. int nOldStart = 0;
  471. while(nCurrent <= nIndex && *pstrBuffer != _T('\0'))
  472. {
  473. if(*pstrBuffer == ch)
  474. {
  475. nOldStart = nStart;
  476. nStart = nEnd + 1;
  477. nCurrent++;
  478. }
  479. nEnd++;
  480. pstrBuffer++;
  481. }
  482. // May have reached the end of the string
  483. if(*pstrBuffer == _T('\0'))
  484. {
  485. nOldStart = nStart;
  486. nEnd++;
  487. }
  488. ref.UnlockBuffer();
  489. if(nCurrent < nIndex)
  490. {
  491. //TRACE1("Warning: GetStringField - Couldn't find field %d.\n", nIndex);
  492. return strReturn;
  493. }
  494. return ref.Mid(nOldStart, nEnd - nOldStart - 1);
  495. }
  496. LPLOGFONT CToolTipEx::GetSystemToolTipFont()
  497. {
  498. static LOGFONT LogFont;
  499. NONCLIENTMETRICS ncm;
  500. ncm.cbSize = sizeof(NONCLIENTMETRICS);
  501. if(!SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS),
  502. &ncm, 0))
  503. {
  504. return FALSE;
  505. }
  506. memcpy(&LogFont, &(ncm.lfStatusFont), sizeof(LOGFONT));
  507. return &LogFont;
  508. }
  509. BOOL CToolTipEx::SetLogFont(LPLOGFONT lpLogFont, BOOL bRedraw /*=TRUE*/)
  510. {
  511. ASSERT(lpLogFont);
  512. if(!lpLogFont)
  513. {
  514. return FALSE;
  515. }
  516. LOGFONT LogFont;
  517. // Store font as the global default
  518. memcpy(&LogFont, lpLogFont, sizeof(LOGFONT));
  519. // Create the actual font object
  520. m_Font.DeleteObject();
  521. m_Font.CreateFontIndirect(&LogFont);
  522. if(bRedraw && ::IsWindow(GetSafeHwnd()))
  523. {
  524. Invalidate();
  525. }
  526. return TRUE;
  527. }
  528. void CToolTipEx::SetGdiplusBitmap(Gdiplus::Bitmap *gdiplusBitmap)
  529. {
  530. delete m_imageViewer.m_pGdiplusBitmap;
  531. m_imageViewer.m_pGdiplusBitmap = NULL;
  532. m_imageViewer.m_pGdiplusBitmap = gdiplusBitmap;
  533. m_imageViewer.UpdateBitmapSize();
  534. Invalidate();
  535. }
  536. void CToolTipEx::OnSize(UINT nType, int cx, int cy)
  537. {
  538. CWnd::OnSize(nType, cx, cy);
  539. if(::IsWindow(m_RichEdit.GetSafeHwnd()) == FALSE)
  540. {
  541. return ;
  542. }
  543. CRect cr;
  544. GetClientRect(cr);
  545. cr.DeflateRect(0, 0, 0, theApp.m_metrics.ScaleY(21));
  546. m_RichEdit.MoveWindow(cr);
  547. m_imageViewer.MoveWindow(cr);
  548. m_optionsButton.MoveWindow(cr.left, cr.bottom + theApp.m_metrics.ScaleY(2), theApp.m_metrics.ScaleX(17), theApp.m_metrics.ScaleY(17));
  549. m_clipDataStatic.MoveWindow(cr.left + theApp.m_metrics.ScaleX(19), cr.bottom + theApp.m_metrics.ScaleY(2), cr.Width() - cr.left + theApp.m_metrics.ScaleX(19), theApp.m_metrics.ScaleY(17));
  550. this->Invalidate();
  551. m_DittoWindow.DoSetRegion(this);
  552. if (m_saveWindowLockout == false)
  553. {
  554. SetTimer(SAVE_SIZE, 250, NULL);
  555. }
  556. }
  557. BOOL CToolTipEx::IsCursorInToolTip()
  558. {
  559. CRect cr;
  560. GetWindowRect(cr);
  561. CPoint cursorPos;
  562. GetCursorPos(&cursorPos);
  563. return cr.PtInRect(cursorPos);
  564. }
  565. void CToolTipEx::SetRTFText(const char *pRTF)
  566. {
  567. m_RichEdit.SetRTF(pRTF);
  568. m_csRTF = pRTF;
  569. m_RichEdit.SetSel(0, 0);
  570. HighlightSearchText();
  571. }
  572. //void CToolTipEx::SetRTFText(const CString &csRTF)
  573. //{
  574. // m_RichEdit.SetRTF(csRTF);
  575. // m_csRTF = csRTF;
  576. //}
  577. void CToolTipEx::SetToolTipText(const CString &csText)
  578. {
  579. m_csText = csText;
  580. m_RichEdit.SetFont(&m_Font);
  581. m_RichEdit.SetText(csText);
  582. m_RichEdit.SetSel(0, 0);
  583. CHARFORMAT cfNew;
  584. cfNew.cbSize = sizeof(CHARFORMAT);
  585. cfNew.dwMask = CFM_COLOR;
  586. cfNew.dwEffects = CFM_COLOR;
  587. cfNew.dwEffects &= ~CFE_AUTOCOLOR;
  588. cfNew.crTextColor = g_Opt.m_Theme.DescriptionWindowText();
  589. m_RichEdit.SetDefaultCharFormat(cfNew);
  590. HighlightSearchText();
  591. }
  592. void CToolTipEx::HighlightSearchText()
  593. {
  594. if (m_searchText.GetLength() <= 0)
  595. return;
  596. FINDTEXTEX ft;
  597. long n = -1;
  598. ft.lpstrText = m_searchText;
  599. ft.chrg.cpMin = 0;
  600. ft.chrg.cpMax = -1;
  601. CHARFORMAT cf;
  602. cf.cbSize = sizeof(cf);
  603. cf.dwMask = CFM_COLOR;
  604. cf.dwEffects = CFE_BOLD | ~CFE_AUTOCOLOR;
  605. cf.crTextColor = RGB(255, 0, 0);
  606. do
  607. {
  608. ft.chrg.cpMin = n+1;
  609. n = m_RichEdit.FindText(FR_DOWN, &ft);
  610. if (n != -1)
  611. {
  612. m_RichEdit.SetSel(ft.chrgText);
  613. m_RichEdit.SetSelectionCharFormat(cf);
  614. }
  615. } while (n != -1);
  616. m_RichEdit.SetSel(0, 0);
  617. }
  618. void CToolTipEx::DoSearch()
  619. {
  620. if (m_searchText.GetLength() <= 0)
  621. return;
  622. FINDTEXTEX ft;
  623. long n = -1;
  624. ft.lpstrText = m_searchText;
  625. long start;
  626. long end;
  627. m_RichEdit.GetSel(start, end);
  628. ft.chrg.cpMin = end;
  629. ft.chrg.cpMax = -1;
  630. int searchDirection = FR_DOWN;
  631. if (GetKeyState(VK_SHIFT) & 0x8000)
  632. {
  633. searchDirection = 0;
  634. ft.chrg.cpMin = start;
  635. }
  636. n = m_RichEdit.FindText(searchDirection, &ft);
  637. if (n != -1)
  638. {
  639. m_RichEdit.SetSel(ft.chrgText);
  640. }
  641. else
  642. {
  643. if (searchDirection == 0)
  644. {
  645. ft.chrg.cpMin = m_RichEdit.GetTextLength();
  646. }
  647. else
  648. {
  649. ft.chrg.cpMin = 0;
  650. }
  651. ft.chrg.cpMax = -1;
  652. n = m_RichEdit.FindText(searchDirection, &ft);
  653. if (n != -1)
  654. {
  655. m_RichEdit.SetSel(ft.chrgText);
  656. }
  657. }
  658. }
  659. void CToolTipEx::OnActivate(UINT nState, CWnd *pWndOther, BOOL bMinimized)
  660. {
  661. CWnd::OnActivate(nState, pWndOther, bMinimized);
  662. if (nState == WA_INACTIVE)
  663. {
  664. if(m_pNotifyWnd)
  665. {
  666. m_pNotifyWnd->PostMessage(NM_INACTIVE_TOOLTIPWND, 0, 0);
  667. }
  668. }
  669. }
  670. void CToolTipEx::OnTimer(UINT_PTR nIDEvent)
  671. {
  672. switch(nIDEvent)
  673. {
  674. case HIDE_WINDOW_TIMER:
  675. Hide();
  676. PostMessage(WM_DESTROY, 0, 0);
  677. break;
  678. case SAVE_SIZE:
  679. SaveWindowSize();
  680. KillTimer(SAVE_SIZE);
  681. break;
  682. case TIMER_BUTTON_UP:
  683. {
  684. if ((GetKeyState(VK_LBUTTON) & 0x100) == 0)
  685. {
  686. m_DittoWindow.DoNcLButtonUp(this, 0, CPoint(0, 0));
  687. KillTimer(TIMER_BUTTON_UP);
  688. }
  689. break;
  690. }
  691. case TIMER_AUTO_MAX:
  692. {
  693. if (m_DittoWindow.m_bMinimized)
  694. {
  695. CPoint cp;
  696. GetCursorPos(&cp);
  697. UINT nHitTest = (UINT)OnNcHitTest(cp);
  698. ScreenToClient(&cp);
  699. if (nHitTest == HTCAPTION)
  700. {
  701. if (m_DittoWindow.m_crCloseBT.PtInRect(cp) == false)
  702. {
  703. if (m_DittoWindow.m_crMinimizeBT.PtInRect(cp) == false)
  704. {
  705. m_DittoWindow.MinMaxWindow(this, FORCE_MAX);
  706. }
  707. }
  708. }
  709. }
  710. KillTimer(TIMER_AUTO_MAX);
  711. m_bMaxSetTimer = false;
  712. }
  713. }
  714. CWnd::OnTimer(nIDEvent);
  715. }
  716. void CToolTipEx::OnNcPaint()
  717. {
  718. m_DittoWindow.DoNcPaint(this);
  719. }
  720. void CToolTipEx::OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS FAR* lpncsp)
  721. {
  722. CWnd::OnNcCalcSize(bCalcValidRects, lpncsp);
  723. m_DittoWindow.DoNcCalcSize(bCalcValidRects, lpncsp);
  724. }
  725. HITTEST_RET CToolTipEx::OnNcHitTest(CPoint point)
  726. {
  727. UINT Ret = m_DittoWindow.DoNcHitTest(this, point);
  728. if(Ret == -1)
  729. return CWnd::OnNcHitTest(point);
  730. return Ret;
  731. }
  732. void CToolTipEx::OnNcLButtonDown(UINT nHitTest, CPoint point)
  733. {
  734. int buttonPressed = m_DittoWindow.DoNcLButtonDown(this, nHitTest, point);
  735. if (buttonPressed != 0)
  736. {
  737. SetTimer(TIMER_BUTTON_UP, 100, NULL);
  738. }
  739. CWnd::OnNcLButtonDown(nHitTest, point);
  740. }
  741. void CToolTipEx::OnNcLButtonUp(UINT nHitTest, CPoint point)
  742. {
  743. long lRet = m_DittoWindow.DoNcLButtonUp(this, nHitTest, point);
  744. switch(lRet)
  745. {
  746. case BUTTON_CLOSE:
  747. Hide();
  748. break;
  749. case BUTTON_CHEVRON:
  750. m_DittoWindow.MinMaxWindow(this, SWAP_MIN_MAX);
  751. OnNcPaint();
  752. break;
  753. }
  754. KillTimer(TIMER_BUTTON_UP);
  755. CWnd::OnNcLButtonUp(nHitTest, point);
  756. }
  757. void CToolTipEx::OnNcMouseMove(UINT nHitTest, CPoint point)
  758. {
  759. m_DittoWindow.DoNcMouseMove(this, nHitTest, point);
  760. if ((m_bMaxSetTimer == false) && m_DittoWindow.m_bMinimized)
  761. {
  762. COleDateTimeSpan sp = COleDateTime::GetCurrentTime() - m_DittoWindow.m_TimeMinimized;
  763. if (sp.GetTotalSeconds() >= m_lDelayMaxSeconds)
  764. {
  765. SetTimer(TIMER_AUTO_MAX, CGetSetOptions::GetTimeBeforeExpandWindow(), NULL);
  766. m_bMaxSetTimer = true;
  767. }
  768. }
  769. CWnd::OnNcMouseMove(nHitTest, point);
  770. }
  771. void CToolTipEx::OnOptions()
  772. {
  773. POINT pp;
  774. CMenu cmPopUp;
  775. CMenu *cmSubMenu = NULL;
  776. GetCursorPos(&pp);
  777. if(cmPopUp.LoadMenu(IDR_DESC_OPTIONS_MENU) != 0)
  778. {
  779. cmSubMenu = cmPopUp.GetSubMenu(0);
  780. if(!cmSubMenu)
  781. {
  782. return ;
  783. }
  784. GetCursorPos(&pp);
  785. //theApp.m_Language.UpdateRightClickMenu(cmSubMenu);
  786. if(CGetSetOptions::GetRememberDescPos())
  787. cmSubMenu->CheckMenuItem(ID_FIRST_REMEMBERWINDOWPOSITION, MF_CHECKED);
  788. if(CGetSetOptions::GetSizeDescWindowToContent())
  789. cmSubMenu->CheckMenuItem(ID_FIRST_SIZEWINDOWTOCONTENT, MF_CHECKED);
  790. if(CGetSetOptions::GetScaleImagesToDescWindow())
  791. cmSubMenu->CheckMenuItem(ID_FIRST_SCALEIMAGESTOFITWINDOW, MF_CHECKED);
  792. if (CGetSetOptions::GetMouseClickHidesDescription())
  793. cmSubMenu->CheckMenuItem(ID_FIRST_HIDEDESCRIPTIONWINDOWONM, MF_CHECKED);
  794. if (CGetSetOptions::GetWrapDescriptionText())
  795. cmSubMenu->CheckMenuItem(ID_FIRST_WRAPTEXT, MF_CHECKED);
  796. if (m_showPersistant)
  797. cmSubMenu->CheckMenuItem(ID_FIRST_ALWAYSONTOP, MF_CHECKED);
  798. UpdateMenuShortCut(cmSubMenu, ID_FIRST_WRAPTEXT, ActionEnums::TOGGLE_DESCRIPTION_WORD_WRAP);
  799. UpdateMenuShortCut(cmSubMenu, ID_FIRST_ALWAYSONTOP, ActionEnums::TOGGLESHOWPERSISTANT);
  800. cmSubMenu->TrackPopupMenu(TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RIGHTBUTTON, pp.x, pp.y, this, NULL);
  801. }
  802. }
  803. void CToolTipEx::UpdateMenuShortCut(CMenu *subMenu, int id, DWORD action)
  804. {
  805. if (m_pToolTipActions != NULL)
  806. {
  807. CString cs;
  808. subMenu->GetMenuString(id, cs, MF_BYCOMMAND);
  809. CString shortcutText = m_pToolTipActions->GetCmdKeyText(action);
  810. if (shortcutText != _T("") &&
  811. cs.Find("\t" + shortcutText) < 0)
  812. {
  813. cs += "\t";
  814. cs += shortcutText;
  815. subMenu->ModifyMenu(id, MF_BYCOMMAND, id, cs);
  816. }
  817. }
  818. }
  819. void CToolTipEx::OnRememberwindowposition()
  820. {
  821. CGetSetOptions::SetRememberDescPos(!CGetSetOptions::GetRememberDescPos());
  822. }
  823. void CToolTipEx::OnSizewindowtocontent()
  824. {
  825. CGetSetOptions::SetSizeDescWindowToContent(!CGetSetOptions::GetSizeDescWindowToContent());
  826. CRect rect;
  827. this->GetWindowRect(&rect);
  828. Show(rect.TopLeft());
  829. }
  830. void CToolTipEx::OnScaleimagestofitwindow()
  831. {
  832. CGetSetOptions::SetScaleImagesToDescWindow(!CGetSetOptions::GetScaleImagesToDescWindow());
  833. m_imageViewer.UpdateBitmapSize();
  834. Invalidate();
  835. }
  836. void CToolTipEx::OnRButtonDown(UINT nFlags, CPoint point)
  837. {
  838. OnOptions();
  839. CWnd::OnRButtonDown(nFlags, point);
  840. }
  841. void CToolTipEx::OnSetFocus(CWnd* pOldWnd)
  842. {
  843. CWnd::OnSetFocus(pOldWnd);
  844. m_RichEdit.SetFocus();
  845. }
  846. void CToolTipEx::OnPaint()
  847. {
  848. CPaintDC dc(this); // device context for painting
  849. CRect rect;
  850. GetClientRect(rect);
  851. CBrush Brush, *pOldBrush;
  852. Brush.CreateSolidBrush(g_Opt.m_Theme.DescriptionWindowBG());
  853. pOldBrush = dc.SelectObject(&Brush);
  854. dc.FillRect(&rect, &Brush);
  855. // Cleanup
  856. dc.SelectObject(pOldBrush);
  857. }
  858. void CToolTipEx::OnFirstHidedescriptionwindowonm()
  859. {
  860. CGetSetOptions::SetMouseClickHidesDescription(!CGetSetOptions::GetMouseClickHidesDescription());
  861. }
  862. bool CToolTipEx::ToggleWordWrap()
  863. {
  864. bool didWordWrap = false;
  865. if (m_RichEdit.IsWindowVisible())
  866. {
  867. OnFirstWraptext();
  868. didWordWrap = true;
  869. }
  870. return didWordWrap;
  871. }
  872. void CToolTipEx::OnFirstWraptext()
  873. {
  874. CGetSetOptions::SetWrapDescriptionText(!CGetSetOptions::GetWrapDescriptionText());
  875. ApplyWordWrap();
  876. }
  877. void CToolTipEx::ApplyWordWrap()
  878. {
  879. if (CGetSetOptions::GetWrapDescriptionText())
  880. {
  881. m_RichEdit.SetTargetDevice(NULL, 0);
  882. }
  883. else
  884. {
  885. m_RichEdit.SetTargetDevice(NULL, 1);
  886. }
  887. }
  888. void CToolTipEx::HideWindowInXMilliSeconds(long lms)
  889. {
  890. SetTimer(HIDE_WINDOW_TIMER, lms, NULL);
  891. }
  892. void CToolTipEx::OnWindowPosChanging(WINDOWPOS* lpwndpos)
  893. {
  894. CWnd::OnWindowPosChanging(lpwndpos);
  895. m_DittoWindow.SnapToEdge(this, lpwndpos);
  896. }
  897. void CToolTipEx::OnFirstAlwaysontop()
  898. {
  899. m_showPersistant = !m_showPersistant;
  900. if (m_showPersistant)
  901. {
  902. m_DittoWindow.m_customWindowTitle = _T("[Always on top]");
  903. m_DittoWindow.m_useCustomWindowTitle = true;
  904. ::SetWindowPos(m_hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_SHOWWINDOW | SWP_NOACTIVATE);
  905. }
  906. else
  907. {
  908. m_DittoWindow.m_customWindowTitle = _T("");
  909. m_DittoWindow.m_useCustomWindowTitle = true;
  910. }
  911. ::SetWindowPos(m_hWnd, NULL, 0, 0, 0, 0, SWP_DRAWFRAME | SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
  912. }
  913. BOOL CToolTipEx::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
  914. {
  915. switch (((LPNMHDR)lParam)->code)
  916. {
  917. case EN_LINK:
  918. {
  919. ENLINK *enLinkInfo = (ENLINK *)lParam; // pointer to a ENLINK structure
  920. if (enLinkInfo->msg == WM_LBUTTONUP)
  921. {
  922. CString s;
  923. m_RichEdit.GetTextRange(enLinkInfo->chrg.cpMin, enLinkInfo->chrg.cpMax, s);
  924. CHyperLink::GotoURL(s, SW_SHOW);
  925. }
  926. }
  927. break;
  928. }
  929. return CWnd::OnNotify(wParam, lParam, pResult);
  930. }