ToolTipEx.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983
  1. #include "stdafx.h"
  2. #include "cp_main.h"
  3. #include "ToolTipEx.h"
  4. #include "BitmapHelper.h"
  5. #include "Options.h"
  6. #include <Richedit.h>
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. #define DELETE_BITMAP if(m_imageViewer.m_pBitmap) \
  13. { \
  14. m_imageViewer.m_pBitmap->DeleteObject(); \
  15. delete m_imageViewer.m_pBitmap; \
  16. m_imageViewer.m_pBitmap = NULL; \
  17. }
  18. #define HIDE_WINDOW_TIMER 1
  19. #define SAVE_SIZE 2
  20. #define TIMER_BUTTON_UP 3
  21. /////////////////////////////////////////////////////////////////////////////
  22. // CToolTipEx
  23. CToolTipEx::CToolTipEx(): m_dwTextStyle(DT_EXPANDTABS | DT_EXTERNALLEADING |
  24. DT_NOPREFIX | DT_WORDBREAK), m_rectMargin(2, 2, 3, 3),
  25. m_pNotifyWnd(NULL), m_clipId(0), m_clipRow(-1)
  26. {
  27. }
  28. CToolTipEx::~CToolTipEx()
  29. {
  30. DELETE_BITMAP
  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_NCPAINT()
  42. ON_WM_NCCALCSIZE()
  43. ON_WM_NCLBUTTONDOWN()
  44. ON_WM_NCMOUSEMOVE()
  45. ON_WM_NCLBUTTONUP()
  46. ON_WM_ERASEBKGND()
  47. ON_COMMAND(ID_FIRST_REMEMBERWINDOWPOSITION, &CToolTipEx::OnRememberwindowposition)
  48. ON_COMMAND(ID_FIRST_SIZEWINDOWTOCONTENT, &CToolTipEx::OnSizewindowtocontent)
  49. ON_COMMAND(ID_FIRST_SCALEIMAGESTOFITWINDOW, &CToolTipEx::OnScaleimagestofitwindow)
  50. ON_COMMAND(2, OnOptions)
  51. ON_WM_RBUTTONDOWN()
  52. ON_WM_SETFOCUS()
  53. ON_COMMAND(ID_FIRST_HIDEDESCRIPTIONWINDOWONM, &CToolTipEx::OnFirstHidedescriptionwindowonm)
  54. ON_COMMAND(ID_FIRST_WRAPTEXT, &CToolTipEx::OnFirstWraptext)
  55. ON_WM_WINDOWPOSCHANGING()
  56. END_MESSAGE_MAP()
  57. /////////////////////////////////////////////////////////////////////////////
  58. // CToolTipEx message handlers
  59. BOOL CToolTipEx::Create(CWnd *pParentWnd)
  60. {
  61. m_saveWindowLockout = true;
  62. // Get the class name and create the window
  63. CString szClassName = AfxRegisterWndClass(CS_CLASSDC | CS_SAVEBITS, LoadCursor(NULL, IDC_ARROW));
  64. // Create the window - just don't show it yet.
  65. if( !CWnd::CreateEx(0, szClassName, _T(""), WS_POPUP,
  66. 0, 0, 0, 0, pParentWnd->GetSafeHwnd(), 0, NULL))
  67. {
  68. return FALSE;
  69. }
  70. //CString szClassName2 = AfxRegisterWndClass(CS_CLASSDC | CS_SAVEBITS, LoadCursor(NULL, IDC_ARROW));
  71. //BOOL b = m_imageViewer.Create(_T(""), szClassName2, WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL, CRect(0, 0, 0, 0), this, 3);
  72. m_imageViewer.Create(this);
  73. m_DittoWindow.DoCreate(this);
  74. m_DittoWindow.SetCaptionColors(g_Opt.m_Theme.CaptionLeft(), g_Opt.m_Theme.CaptionRight(), g_Opt.m_Theme.Border());
  75. m_DittoWindow.SetCaptionOn(this, CGetSetOptions::GetCaptionPos(), true, g_Opt.m_Theme.GetCaptionSize(), g_Opt.m_Theme.GetCaptionFontSize());
  76. m_DittoWindow.m_bDrawMaximize = false;
  77. m_DittoWindow.m_bDrawMinimize = false;
  78. m_DittoWindow.m_bDrawChevron = false;
  79. m_DittoWindow.m_sendWMClose = false;
  80. m_RichEdit.Create(_T(""), _T(""), WS_CHILD | WS_VISIBLE | WS_VSCROLL |
  81. WS_HSCROLL | ES_MULTILINE | ES_AUTOVSCROLL | ES_NOHIDESEL |
  82. ES_AUTOHSCROLL, CRect(10, 10, 100, 200), this, 1);
  83. m_RichEdit.SetReadOnly();
  84. m_RichEdit.SetBackgroundColor(FALSE, g_Opt.m_Theme.DescriptionWindowBG());
  85. ApplyWordWrap();
  86. SetLogFont(GetSystemToolTipFont(), FALSE);
  87. m_optionsButton.Create(NULL, WS_CHILD | BS_OWNERDRAW | WS_TABSTOP, CRect(0, 0, 0, 0), this, 2);
  88. m_optionsButton.LoadStdImageDPI(IDB_COG_16_16, IDB_COG_20_20, IDB_COG_24_24, cog_28, IDB_COG_32_32, _T("PNG"));
  89. m_optionsButton.SetToolTipText(theApp.m_Language.GetString(_T("DescriptionOptionsTooltip"), _T("Description Options")));
  90. m_optionsButton.ShowWindow(SW_SHOW);
  91. m_clipDataStatic.Create(_T("some text"), WS_CHILD | WS_VISIBLE | SS_SIMPLE, CRect(0, 0, 0, 0), this, 3);
  92. m_clipDataFont.CreateFont(-theApp.m_metrics.PointsToPixels(8), 0, 0, 0, 400, 0, 0, 0, DEFAULT_CHARSET, 3, 2, 1, 34, _T("Segoe UI"));
  93. m_clipDataStatic.SetFont(&m_clipDataFont);
  94. m_clipDataStatic.SetBkColor(g_Opt.m_Theme.DescriptionWindowBG());
  95. m_clipDataStatic.SetTextColor(RGB(80, 80, 80));
  96. m_saveWindowLockout = false;
  97. return TRUE;
  98. }
  99. BOOL CToolTipEx::Show(CPoint point)
  100. {
  101. m_reducedWindowSize = false;
  102. if(m_imageViewer.m_pBitmap)
  103. {
  104. m_RichEdit.ShowWindow(SW_HIDE);
  105. m_imageViewer.ShowWindow(SW_SHOW);
  106. m_imageViewer.UpdateBitmapSize();
  107. }
  108. else
  109. {
  110. m_RichEdit.ShowWindow(SW_SHOW);
  111. m_imageViewer.ShowWindow(SW_HIDE);
  112. }
  113. CRect rect;
  114. if(CGetSetOptions::GetSizeDescWindowToContent() == FALSE)
  115. {
  116. rect.left = point.x;
  117. rect.top = point.y;
  118. CSize size;
  119. CGetSetOptions::GetDescWndSize(size);
  120. rect.right = rect.left + size.cx;
  121. rect.bottom = rect.top + size.cy;
  122. EnsureWindowVisible(&rect);
  123. }
  124. else
  125. {
  126. rect = GetBoundsRect();
  127. //account for the scroll bars
  128. rect.right += 20;
  129. rect.bottom += 20;
  130. if (m_imageViewer.m_pBitmap)
  131. {
  132. int nWidth = CBitmapHelper::GetCBitmapWidth(*m_imageViewer.m_pBitmap) + ::GetSystemMetrics(SM_CXVSCROLL);
  133. int nHeight = CBitmapHelper::GetCBitmapHeight(*m_imageViewer.m_pBitmap) + ::GetSystemMetrics(SM_CYHSCROLL);
  134. rect.right = rect.left + nWidth;
  135. rect.bottom = rect.top + nHeight;
  136. }
  137. else if(m_csRTF != "")
  138. {
  139. //if showing rtf then increase the size because
  140. //rtf will probably draw bigger
  141. long lNewWidth = (long)rect.Width() + (long)(rect.Width() *1.5);
  142. rect.right = rect.left + lNewWidth;
  143. long lNewHeight = (long)rect.Height() + (long)(rect.Height() *1.5);
  144. rect.bottom = rect.top + lNewHeight;
  145. }
  146. rect.right += CAPTION_BORDER * 2;
  147. rect.bottom += CAPTION_BORDER * 2;
  148. CRect rcScreen;
  149. ClientToScreen(rect);
  150. CRect cr(point, point);
  151. int nMonitor = GetMonitorFromRect(&cr);
  152. GetMonitorRect(nMonitor, &rcScreen);
  153. //ensure that we don't go outside the screen
  154. if(point.x < 0)
  155. {
  156. point.x = 5;
  157. m_reducedWindowSize = true;
  158. }
  159. if(point.y < 0)
  160. {
  161. point.y = 5;
  162. m_reducedWindowSize = true;
  163. }
  164. rcScreen.DeflateRect(0, 0, 5, 5);
  165. long lWidth = rect.Width();
  166. long lHeight = rect.Height();
  167. rect.left = point.x;
  168. rect.top = point.y;
  169. rect.right = rect.left + lWidth;
  170. rect.bottom = rect.top + lHeight;
  171. if (rect.right > rcScreen.right)
  172. {
  173. rect.right = rcScreen.right;
  174. m_reducedWindowSize = true;
  175. }
  176. if (rect.bottom > rcScreen.bottom)
  177. {
  178. rect.bottom = rcScreen.bottom;
  179. m_reducedWindowSize = true;
  180. }
  181. }
  182. m_clipDataStatic.SetWindowText(m_clipData);
  183. m_saveWindowLockout = true;
  184. MoveWindow(rect);
  185. ShowWindow(SW_SHOWNA);
  186. this->Invalidate();
  187. this->UpdateWindow();
  188. m_saveWindowLockout = false;
  189. return TRUE;
  190. }
  191. BOOL CToolTipEx::Hide()
  192. {
  193. DELETE_BITMAP
  194. SaveWindowSize();
  195. ShowWindow(SW_HIDE);
  196. m_csRTF = "";
  197. m_csText = "";
  198. m_clipId = 0;
  199. m_clipRow = -1;
  200. m_searchText = _T("");
  201. return TRUE;
  202. }
  203. void CToolTipEx::SaveWindowSize()
  204. {
  205. if (::IsWindowVisible(m_hWnd))
  206. {
  207. CRect rect;
  208. this->GetWindowRect(&rect);
  209. CGetSetOptions::SetDescWndSize(rect.Size());
  210. CGetSetOptions::SetDescWndPoint(rect.TopLeft());
  211. OutputDebugString(_T("Saving tooltip size"));
  212. }
  213. }
  214. void CToolTipEx::PostNcDestroy()
  215. {
  216. CWnd::PostNcDestroy();
  217. delete this;
  218. }
  219. BOOL CToolTipEx::PreTranslateMessage(MSG *pMsg)
  220. {
  221. m_DittoWindow.DoPreTranslateMessage(pMsg);
  222. switch(pMsg->message)
  223. {
  224. case WM_KEYDOWN:
  225. switch(pMsg->wParam)
  226. {
  227. case VK_ESCAPE:
  228. Hide();
  229. return TRUE;
  230. case 'C':
  231. if(GetKeyState(VK_CONTROL) &0x8000)
  232. {
  233. m_RichEdit.Copy();
  234. }
  235. break;
  236. case VK_F3:
  237. {
  238. DoSearch();
  239. }
  240. break;
  241. }
  242. break;
  243. case WM_RBUTTONDOWN:
  244. {
  245. if (m_RichEdit.m_hWnd == GetFocus()->m_hWnd ||
  246. m_imageViewer.m_hWnd == GetFocus()->m_hWnd)
  247. {
  248. OnOptions();
  249. return TRUE;
  250. }
  251. }
  252. break;
  253. }
  254. return CWnd::PreTranslateMessage(pMsg);
  255. }
  256. BOOL CToolTipEx::OnMsg(MSG *pMsg)
  257. {
  258. if(FALSE == IsWindowVisible())
  259. {
  260. return FALSE;
  261. }
  262. switch(pMsg->message)
  263. {
  264. case WM_WINDOWPOSCHANGING:
  265. case WM_LBUTTONDOWN:
  266. {
  267. if (CGetSetOptions::GetMouseClickHidesDescription())
  268. {
  269. if (!IsCursorInToolTip())
  270. {
  271. Hide();
  272. }
  273. }
  274. }
  275. break;
  276. case WM_KEYDOWN:
  277. {
  278. WPARAM vk = pMsg->wParam;
  279. if(vk == VK_ESCAPE)
  280. {
  281. Hide();
  282. return TRUE;
  283. }
  284. else if(vk == VK_TAB)
  285. {
  286. m_RichEdit.SetFocus();
  287. return TRUE;
  288. }
  289. else if(vk == 'N')
  290. {
  291. return FALSE;
  292. }
  293. else if (vk == 'P')
  294. {
  295. return FALSE;
  296. }
  297. else if (vk == VK_UP)
  298. {
  299. return FALSE;
  300. }
  301. else if (vk == VK_DOWN)
  302. {
  303. return FALSE;
  304. }
  305. else if(vk == VK_F3)
  306. {
  307. DoSearch();
  308. return TRUE;
  309. }
  310. else if(vk == VK_SHIFT)
  311. {
  312. return FALSE;
  313. }
  314. else if(vk == VK_NEXT)
  315. {
  316. return FALSE;
  317. }
  318. else if (vk == VK_PRIOR)
  319. {
  320. return FALSE;
  321. }
  322. Hide();
  323. break;
  324. }
  325. case WM_LBUTTONDBLCLK:
  326. case WM_RBUTTONDBLCLK:
  327. case WM_MBUTTONDOWN:
  328. case WM_MBUTTONDBLCLK:
  329. case WM_NCLBUTTONDOWN:
  330. case WM_NCLBUTTONDBLCLK:
  331. case WM_NCRBUTTONDOWN:
  332. case WM_NCRBUTTONDBLCLK:
  333. case WM_NCMBUTTONDOWN:
  334. case WM_NCMBUTTONDBLCLK:
  335. {
  336. Hide();
  337. break;
  338. }
  339. case WM_MOUSEWHEEL:
  340. {
  341. if (m_imageViewer.m_pBitmap)
  342. {
  343. m_imageViewer.PostMessageW(pMsg->message, pMsg->wParam, pMsg->lParam);
  344. return TRUE;
  345. }
  346. else
  347. {
  348. m_RichEdit.PostMessageW(pMsg->message, pMsg->wParam, pMsg->lParam);
  349. return TRUE;
  350. }
  351. }
  352. break;
  353. }
  354. return FALSE;
  355. }
  356. CRect CToolTipEx::GetBoundsRect()
  357. {
  358. DWORD d = GetTickCount();
  359. CWindowDC dc(NULL);
  360. int nLineWidth = 0;
  361. CRect rect(0, 0, 0, 0);
  362. if(nLineWidth == 0)
  363. {
  364. // Count the number of lines of text
  365. int nStart = 0;
  366. INT nNumLines = 0;
  367. int longestLength = 0;
  368. CString longestString;
  369. do
  370. {
  371. int newStart = m_csText.Find(_T("\n"), nStart);
  372. if (newStart < 0)
  373. {
  374. int length = m_csText.GetLength() - nStart;
  375. if (length > longestLength)
  376. {
  377. longestString = m_csText.Mid(nStart, length);
  378. longestLength = length;
  379. }
  380. break;
  381. }
  382. int length = newStart - nStart;
  383. if(length > longestLength)
  384. {
  385. longestString = m_csText.Mid(nStart, length);
  386. longestLength = length;
  387. }
  388. nNumLines++;
  389. nStart = newStart + 1;
  390. }
  391. while(nStart >= 0 && nNumLines < 100);
  392. CFont *pOldFont = (CFont*)dc.SelectObject((CFont*)&m_Font);
  393. CSize size = dc.GetTextExtent(longestString);
  394. dc.SelectObject(pOldFont);
  395. rect.right = size.cx;
  396. rect.bottom = size.cy * nNumLines;
  397. }
  398. rect.bottom += m_rectMargin.top + m_rectMargin.bottom;
  399. rect.right += m_rectMargin.left + m_rectMargin.right + 2;
  400. if(m_imageViewer.m_pBitmap)
  401. {
  402. int nWidth = CBitmapHelper::GetCBitmapWidth(*m_imageViewer.m_pBitmap);
  403. int nHeight = CBitmapHelper::GetCBitmapHeight(*m_imageViewer.m_pBitmap);
  404. rect.bottom += nHeight;
  405. if((rect.left + nWidth) > rect.right)
  406. {
  407. rect.right = rect.left + nWidth;
  408. }
  409. }
  410. DWORD diff = GetTickCount() - d;
  411. if (diff > 10)
  412. {
  413. Log(StrF(_T("Size To Content: %d\n"), diff));
  414. }
  415. return rect;
  416. }
  417. CString CToolTipEx::GetFieldFromString(CString ref, int nIndex, TCHAR ch)
  418. {
  419. CString strReturn;
  420. LPCTSTR pstrStart = ref.LockBuffer();
  421. LPCTSTR pstrBuffer = pstrStart;
  422. int nCurrent = 0;
  423. int nStart = 0;
  424. int nEnd = 0;
  425. int nOldStart = 0;
  426. while(nCurrent <= nIndex && *pstrBuffer != _T('\0'))
  427. {
  428. if(*pstrBuffer == ch)
  429. {
  430. nOldStart = nStart;
  431. nStart = nEnd + 1;
  432. nCurrent++;
  433. }
  434. nEnd++;
  435. pstrBuffer++;
  436. }
  437. // May have reached the end of the string
  438. if(*pstrBuffer == _T('\0'))
  439. {
  440. nOldStart = nStart;
  441. nEnd++;
  442. }
  443. ref.UnlockBuffer();
  444. if(nCurrent < nIndex)
  445. {
  446. //TRACE1("Warning: GetStringField - Couldn't find field %d.\n", nIndex);
  447. return strReturn;
  448. }
  449. return ref.Mid(nOldStart, nEnd - nOldStart - 1);
  450. }
  451. LPLOGFONT CToolTipEx::GetSystemToolTipFont()
  452. {
  453. static LOGFONT LogFont;
  454. NONCLIENTMETRICS ncm;
  455. ncm.cbSize = sizeof(NONCLIENTMETRICS);
  456. if(!SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS),
  457. &ncm, 0))
  458. {
  459. return FALSE;
  460. }
  461. memcpy(&LogFont, &(ncm.lfStatusFont), sizeof(LOGFONT));
  462. return &LogFont;
  463. }
  464. BOOL CToolTipEx::SetLogFont(LPLOGFONT lpLogFont, BOOL bRedraw /*=TRUE*/)
  465. {
  466. ASSERT(lpLogFont);
  467. if(!lpLogFont)
  468. {
  469. return FALSE;
  470. }
  471. LOGFONT LogFont;
  472. // Store font as the global default
  473. memcpy(&LogFont, lpLogFont, sizeof(LOGFONT));
  474. // Create the actual font object
  475. m_Font.DeleteObject();
  476. m_Font.CreateFontIndirect(&LogFont);
  477. if(bRedraw && ::IsWindow(GetSafeHwnd()))
  478. {
  479. Invalidate();
  480. }
  481. return TRUE;
  482. }
  483. void CToolTipEx::SetBitmap(CBitmap *pBitmap)
  484. {
  485. DELETE_BITMAP
  486. m_imageViewer.m_pBitmap = pBitmap;
  487. m_imageViewer.UpdateBitmapSize();
  488. if (m_imageViewer.m_pBitmap != NULL)
  489. {
  490. int nWidth = CBitmapHelper::GetCBitmapWidth(*m_imageViewer.m_pBitmap);
  491. int nHeight = CBitmapHelper::GetCBitmapHeight(*m_imageViewer.m_pBitmap);
  492. Invalidate();
  493. }
  494. }
  495. void CToolTipEx::OnSize(UINT nType, int cx, int cy)
  496. {
  497. CWnd::OnSize(nType, cx, cy);
  498. if(::IsWindow(m_RichEdit.GetSafeHwnd()) == FALSE)
  499. {
  500. return ;
  501. }
  502. CRect cr;
  503. GetClientRect(cr);
  504. cr.DeflateRect(0, 0, 0, theApp.m_metrics.ScaleY(21));
  505. m_RichEdit.MoveWindow(cr);
  506. m_imageViewer.MoveWindow(cr);
  507. m_optionsButton.MoveWindow(cr.left, cr.bottom + theApp.m_metrics.ScaleY(2), theApp.m_metrics.ScaleX(17), theApp.m_metrics.ScaleY(17));
  508. 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));
  509. this->Invalidate();
  510. m_DittoWindow.DoSetRegion(this);
  511. if (m_saveWindowLockout == false)
  512. {
  513. SetTimer(SAVE_SIZE, 250, NULL);
  514. }
  515. }
  516. BOOL CToolTipEx::IsCursorInToolTip()
  517. {
  518. CRect cr;
  519. GetWindowRect(cr);
  520. CPoint cursorPos;
  521. GetCursorPos(&cursorPos);
  522. return cr.PtInRect(cursorPos);
  523. }
  524. void CToolTipEx::SetRTFText(const char *pRTF)
  525. {
  526. m_RichEdit.SetRTF(pRTF);
  527. m_csRTF = pRTF;
  528. m_RichEdit.SetSel(0, 0);
  529. HighlightSearchText();
  530. }
  531. //void CToolTipEx::SetRTFText(const CString &csRTF)
  532. //{
  533. // m_RichEdit.SetRTF(csRTF);
  534. // m_csRTF = csRTF;
  535. //}
  536. void CToolTipEx::SetToolTipText(const CString &csText)
  537. {
  538. m_csText = csText;
  539. m_RichEdit.SetFont(&m_Font);
  540. m_RichEdit.SetText(csText);
  541. m_RichEdit.SetSel(0, 0);
  542. CHARFORMAT cfNew;
  543. cfNew.cbSize = sizeof(CHARFORMAT);
  544. cfNew.dwMask = CFM_COLOR;
  545. cfNew.dwEffects = CFM_COLOR;
  546. cfNew.dwEffects &= ~CFE_AUTOCOLOR;
  547. cfNew.crTextColor = g_Opt.m_Theme.DescriptionWindowText();
  548. m_RichEdit.SetDefaultCharFormat(cfNew);
  549. HighlightSearchText();
  550. }
  551. void CToolTipEx::HighlightSearchText()
  552. {
  553. if (m_searchText.GetLength() <= 0)
  554. return;
  555. FINDTEXTEX ft;
  556. long n = -1;
  557. ft.lpstrText = m_searchText;
  558. ft.chrg.cpMin = 0;
  559. ft.chrg.cpMax = -1;
  560. CHARFORMAT cf;
  561. cf.cbSize = sizeof(cf);
  562. cf.dwMask = CFM_COLOR;
  563. cf.dwEffects = CFE_BOLD | ~CFE_AUTOCOLOR;
  564. cf.crTextColor = RGB(255, 0, 0);
  565. do
  566. {
  567. ft.chrg.cpMin = n+1;
  568. n = m_RichEdit.FindText(FR_DOWN, &ft);
  569. if (n != -1)
  570. {
  571. m_RichEdit.SetSel(ft.chrgText);
  572. m_RichEdit.SetSelectionCharFormat(cf);
  573. }
  574. } while (n != -1);
  575. m_RichEdit.SetSel(0, 0);
  576. }
  577. void CToolTipEx::DoSearch()
  578. {
  579. if (m_searchText.GetLength() <= 0)
  580. return;
  581. FINDTEXTEX ft;
  582. long n = -1;
  583. ft.lpstrText = m_searchText;
  584. long start;
  585. long end;
  586. m_RichEdit.GetSel(start, end);
  587. ft.chrg.cpMin = end;
  588. ft.chrg.cpMax = -1;
  589. int searchDirection = FR_DOWN;
  590. if (GetKeyState(VK_SHIFT) & 0x8000)
  591. {
  592. searchDirection = 0;
  593. ft.chrg.cpMin = start;
  594. }
  595. n = m_RichEdit.FindText(searchDirection, &ft);
  596. if (n != -1)
  597. {
  598. m_RichEdit.SetSel(ft.chrgText);
  599. }
  600. else
  601. {
  602. if (searchDirection == 0)
  603. {
  604. ft.chrg.cpMin = m_RichEdit.GetTextLength();
  605. }
  606. else
  607. {
  608. ft.chrg.cpMin = 0;
  609. }
  610. ft.chrg.cpMax = -1;
  611. n = m_RichEdit.FindText(searchDirection, &ft);
  612. if (n != -1)
  613. {
  614. m_RichEdit.SetSel(ft.chrgText);
  615. }
  616. }
  617. }
  618. void CToolTipEx::OnActivate(UINT nState, CWnd *pWndOther, BOOL bMinimized)
  619. {
  620. CWnd::OnActivate(nState, pWndOther, bMinimized);
  621. if (nState == WA_INACTIVE)
  622. {
  623. if(m_pNotifyWnd)
  624. {
  625. m_pNotifyWnd->PostMessage(NM_INACTIVE_TOOLTIPWND, 0, 0);
  626. }
  627. }
  628. }
  629. void CToolTipEx::OnTimer(UINT_PTR nIDEvent)
  630. {
  631. switch(nIDEvent)
  632. {
  633. case HIDE_WINDOW_TIMER:
  634. Hide();
  635. PostMessage(WM_DESTROY, 0, 0);
  636. break;
  637. case SAVE_SIZE:
  638. SaveWindowSize();
  639. KillTimer(SAVE_SIZE);
  640. break;
  641. case TIMER_BUTTON_UP:
  642. {
  643. if ((GetKeyState(VK_LBUTTON) & 0x100) == 0)
  644. {
  645. m_DittoWindow.DoNcLButtonUp(this, 0, CPoint(0, 0));
  646. KillTimer(TIMER_BUTTON_UP);
  647. }
  648. break;
  649. }
  650. }
  651. CWnd::OnTimer(nIDEvent);
  652. }
  653. void CToolTipEx::OnNcPaint()
  654. {
  655. m_DittoWindow.DoNcPaint(this);
  656. }
  657. void CToolTipEx::OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS FAR* lpncsp)
  658. {
  659. CWnd::OnNcCalcSize(bCalcValidRects, lpncsp);
  660. m_DittoWindow.DoNcCalcSize(bCalcValidRects, lpncsp);
  661. }
  662. HITTEST_RET CToolTipEx::OnNcHitTest(CPoint point)
  663. {
  664. UINT Ret = m_DittoWindow.DoNcHitTest(this, point);
  665. if(Ret == -1)
  666. return CWnd::OnNcHitTest(point);
  667. return Ret;
  668. }
  669. void CToolTipEx::OnNcLButtonDown(UINT nHitTest, CPoint point)
  670. {
  671. int buttonPressed = m_DittoWindow.DoNcLButtonDown(this, nHitTest, point);
  672. if (buttonPressed != 0)
  673. {
  674. SetTimer(TIMER_BUTTON_UP, 100, NULL);
  675. }
  676. CWnd::OnNcLButtonDown(nHitTest, point);
  677. }
  678. void CToolTipEx::OnNcLButtonUp(UINT nHitTest, CPoint point)
  679. {
  680. long lRet = m_DittoWindow.DoNcLButtonUp(this, nHitTest, point);
  681. switch(lRet)
  682. {
  683. case BUTTON_CLOSE:
  684. Hide();
  685. break;
  686. }
  687. KillTimer(TIMER_BUTTON_UP);
  688. CWnd::OnNcLButtonUp(nHitTest, point);
  689. }
  690. void CToolTipEx::OnNcMouseMove(UINT nHitTest, CPoint point)
  691. {
  692. m_DittoWindow.DoNcMouseMove(this, nHitTest, point);
  693. CWnd::OnNcMouseMove(nHitTest, point);
  694. }
  695. void CToolTipEx::OnOptions()
  696. {
  697. POINT pp;
  698. CMenu cmPopUp;
  699. CMenu *cmSubMenu = NULL;
  700. GetCursorPos(&pp);
  701. if(cmPopUp.LoadMenu(IDR_DESC_OPTIONS_MENU) != 0)
  702. {
  703. cmSubMenu = cmPopUp.GetSubMenu(0);
  704. if(!cmSubMenu)
  705. {
  706. return ;
  707. }
  708. GetCursorPos(&pp);
  709. //theApp.m_Language.UpdateRightClickMenu(cmSubMenu);
  710. if(CGetSetOptions::GetRememberDescPos())
  711. cmSubMenu->CheckMenuItem(ID_FIRST_REMEMBERWINDOWPOSITION, MF_CHECKED);
  712. if(CGetSetOptions::GetSizeDescWindowToContent())
  713. cmSubMenu->CheckMenuItem(ID_FIRST_SIZEWINDOWTOCONTENT, MF_CHECKED);
  714. if(CGetSetOptions::GetScaleImagesToDescWindow())
  715. cmSubMenu->CheckMenuItem(ID_FIRST_SCALEIMAGESTOFITWINDOW, MF_CHECKED);
  716. if (CGetSetOptions::GetMouseClickHidesDescription())
  717. cmSubMenu->CheckMenuItem(ID_FIRST_HIDEDESCRIPTIONWINDOWONM, MF_CHECKED);
  718. if (CGetSetOptions::GetWrapDescriptionText())
  719. cmSubMenu->CheckMenuItem(ID_FIRST_WRAPTEXT, MF_CHECKED);
  720. cmSubMenu->TrackPopupMenu(TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RIGHTBUTTON, pp.x, pp.y, this, NULL);
  721. }
  722. }
  723. void CToolTipEx::OnRememberwindowposition()
  724. {
  725. CGetSetOptions::SetRememberDescPos(!CGetSetOptions::GetRememberDescPos());
  726. }
  727. void CToolTipEx::OnSizewindowtocontent()
  728. {
  729. CGetSetOptions::SetSizeDescWindowToContent(!CGetSetOptions::GetSizeDescWindowToContent());
  730. CRect rect;
  731. this->GetWindowRect(&rect);
  732. Show(rect.TopLeft());
  733. }
  734. void CToolTipEx::OnScaleimagestofitwindow()
  735. {
  736. CGetSetOptions::SetScaleImagesToDescWindow(!CGetSetOptions::GetScaleImagesToDescWindow());
  737. m_imageViewer.UpdateBitmapSize();
  738. Invalidate();
  739. }
  740. void CToolTipEx::OnRButtonDown(UINT nFlags, CPoint point)
  741. {
  742. OnOptions();
  743. CWnd::OnRButtonDown(nFlags, point);
  744. }
  745. void CToolTipEx::OnSetFocus(CWnd* pOldWnd)
  746. {
  747. CWnd::OnSetFocus(pOldWnd);
  748. m_RichEdit.SetFocus();
  749. }
  750. void CToolTipEx::OnPaint()
  751. {
  752. CPaintDC dc(this); // device context for painting
  753. CRect rect;
  754. GetClientRect(rect);
  755. CBrush Brush, *pOldBrush;
  756. Brush.CreateSolidBrush(g_Opt.m_Theme.DescriptionWindowBG());
  757. pOldBrush = dc.SelectObject(&Brush);
  758. dc.FillRect(&rect, &Brush);
  759. // Cleanup
  760. dc.SelectObject(pOldBrush);
  761. }
  762. void CToolTipEx::OnFirstHidedescriptionwindowonm()
  763. {
  764. CGetSetOptions::SetMouseClickHidesDescription(!CGetSetOptions::GetMouseClickHidesDescription());
  765. }
  766. void CToolTipEx::OnFirstWraptext()
  767. {
  768. CGetSetOptions::SetWrapDescriptionText(!CGetSetOptions::GetWrapDescriptionText());
  769. ApplyWordWrap();
  770. }
  771. void CToolTipEx::ApplyWordWrap()
  772. {
  773. if (CGetSetOptions::GetWrapDescriptionText())
  774. {
  775. m_RichEdit.SetTargetDevice(NULL, 0);
  776. }
  777. else
  778. {
  779. m_RichEdit.SetTargetDevice(NULL, 1);
  780. }
  781. }
  782. void CToolTipEx::HideWindowInXMilliSeconds(long lms)
  783. {
  784. SetTimer(HIDE_WINDOW_TIMER, lms, NULL);
  785. }
  786. void CToolTipEx::OnWindowPosChanging(WINDOWPOS* lpwndpos)
  787. {
  788. CWnd::OnWindowPosChanging(lpwndpos);
  789. m_DittoWindow.SnapToEdge(this, lpwndpos);
  790. }