ToolTipEx.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848
  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_pBitmap) \
  13. { \
  14. m_pBitmap->DeleteObject(); \
  15. delete m_pBitmap; \
  16. m_pBitmap = NULL; \
  17. }
  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_pBitmap(NULL), m_pNotifyWnd(NULL), m_clipId(0){}
  23. CToolTipEx::~CToolTipEx()
  24. {
  25. DELETE_BITMAP
  26. m_Font.DeleteObject();
  27. }
  28. BEGIN_MESSAGE_MAP(CToolTipEx, CWnd)
  29. //{{AFX_MSG_MAP(CToolTipEx)
  30. ON_WM_PAINT()
  31. ON_WM_SIZE()
  32. ON_WM_NCHITTEST()
  33. ON_WM_ACTIVATE()
  34. ON_WM_TIMER()
  35. ON_WM_NCPAINT()
  36. ON_WM_NCCALCSIZE()
  37. ON_WM_NCLBUTTONDOWN()
  38. ON_WM_NCMOUSEMOVE()
  39. ON_WM_NCLBUTTONUP()
  40. ON_WM_ERASEBKGND()
  41. ON_COMMAND(ID_FIRST_REMEMBERWINDOWPOSITION, &CToolTipEx::OnRememberwindowposition)
  42. ON_COMMAND(ID_FIRST_SIZEWINDOWTOCONTENT, &CToolTipEx::OnSizewindowtocontent)
  43. ON_COMMAND(ID_FIRST_SCALEIMAGESTOFITWINDOW, &CToolTipEx::OnScaleimagestofitwindow)
  44. ON_COMMAND(2, OnOptions)
  45. ON_WM_RBUTTONDOWN()
  46. ON_WM_SETFOCUS()
  47. END_MESSAGE_MAP()
  48. /////////////////////////////////////////////////////////////////////////////
  49. // CToolTipEx message handlers
  50. BOOL CToolTipEx::Create(CWnd *pParentWnd)
  51. {
  52. // Get the class name and create the window
  53. CString szClassName = AfxRegisterWndClass(CS_CLASSDC | CS_SAVEBITS,
  54. LoadCursor(NULL, IDC_ARROW));
  55. // Create the window - just don't show it yet.
  56. if( !CWnd::CreateEx(WS_EX_TOPMOST, szClassName, _T(""), WS_POPUP,
  57. 0, 0, 0, 0, pParentWnd->GetSafeHwnd(), 0, NULL))
  58. {
  59. return FALSE;
  60. }
  61. m_DittoWindow.DoCreate(this);
  62. m_DittoWindow.SetCaptionColors(g_Opt.m_Theme.CaptionLeft(), g_Opt.m_Theme.CaptionRight());
  63. m_DittoWindow.SetCaptionOn(this, CGetSetOptions::GetCaptionPos(), true);
  64. m_DittoWindow.m_bDrawMinimize = false;
  65. m_DittoWindow.m_bDrawMinimize = false;
  66. m_DittoWindow.m_bDrawChevron = false;
  67. m_DittoWindow.m_sendWMClose = false;
  68. m_RichEdit.Create(_T(""), _T(""), WS_CHILD | WS_VISIBLE | WS_VSCROLL |
  69. WS_HSCROLL | ES_MULTILINE | ES_AUTOVSCROLL | ES_NOHIDESEL |
  70. ES_AUTOHSCROLL, CRect(10, 10, 100, 200), this, 1);
  71. m_RichEdit.SetReadOnly();
  72. m_RichEdit.SetBackgroundColor(FALSE, GetSysColor(COLOR_INFOBK));
  73. SetLogFont(GetSystemToolTipFont(), FALSE);
  74. m_optionsButton.Create(NULL, WS_CHILD | BS_OWNERDRAW | WS_TABSTOP, CRect(0, 0, 0, 0), this, 2);
  75. m_optionsButton.LoadStdImageDPI(IDB_COG_16_16, IDB_COG_20_20, IDB_COG_24_24, IDB_COG_32_32, _T("PNG"));
  76. m_optionsButton.SetToolTipText(theApp.m_Language.GetString(_T("DescriptionOptionsTooltip"), _T("Description Options")));
  77. m_optionsButton.ShowWindow(SW_SHOW);
  78. return TRUE;
  79. }
  80. BOOL CToolTipEx::Show(CPoint point)
  81. {
  82. m_reducedWindowSize = false;
  83. if(m_pBitmap)
  84. {
  85. m_RichEdit.ShowWindow(SW_HIDE);
  86. }
  87. else
  88. {
  89. m_RichEdit.ShowWindow(SW_SHOW);
  90. }
  91. CRect rect;
  92. if(CGetSetOptions::GetSizeDescWindowToContent() == FALSE)
  93. {
  94. rect.left = point.x;
  95. rect.top = point.y;
  96. CSize size;
  97. CGetSetOptions::GetDescWndSize(size);
  98. rect.right = rect.left + size.cx;
  99. rect.bottom = rect.top + size.cy;
  100. EnsureWindowVisible(&rect);
  101. }
  102. else
  103. {
  104. rect = GetBoundsRect();
  105. //account for the scroll bars
  106. rect.right += 20;
  107. rect.bottom += 20;
  108. if (m_pBitmap)
  109. {
  110. int nWidth = CBitmapHelper::GetCBitmapWidth(*m_pBitmap);
  111. int nHeight = CBitmapHelper::GetCBitmapHeight(*m_pBitmap);
  112. rect.right = rect.left + nWidth;
  113. rect.bottom = rect.top + nHeight;
  114. }
  115. else if(m_csRTF != "")
  116. {
  117. //if showing rtf then increase the size because
  118. //rtf will probably draw bigger
  119. long lNewWidth = (long)rect.Width() + (long)(rect.Width() *1.5);
  120. rect.right = rect.left + lNewWidth;
  121. long lNewHeight = (long)rect.Height() + (long)(rect.Height() *1.5);
  122. rect.bottom = rect.top + lNewHeight;
  123. }
  124. rect.right += CAPTION_BORDER * 2;
  125. rect.bottom += CAPTION_BORDER * 2;
  126. CRect rcScreen;
  127. ClientToScreen(rect);
  128. CRect cr(point, point);
  129. int nMonitor = GetMonitorFromRect(&cr);
  130. GetMonitorRect(nMonitor, &rcScreen);
  131. //ensure that we don't go outside the screen
  132. if(point.x < 0)
  133. {
  134. point.x = 5;
  135. m_reducedWindowSize = true;
  136. }
  137. if(point.y < 0)
  138. {
  139. point.y = 5;
  140. m_reducedWindowSize = true;
  141. }
  142. rcScreen.DeflateRect(0, 0, 5, 5);
  143. long lWidth = rect.Width();
  144. long lHeight = rect.Height();
  145. rect.left = point.x;
  146. rect.top = point.y;
  147. rect.right = rect.left + lWidth;
  148. rect.bottom = rect.top + lHeight;
  149. if (rect.right > rcScreen.right)
  150. {
  151. rect.right = rcScreen.right;
  152. m_reducedWindowSize = true;
  153. }
  154. if (rect.bottom > rcScreen.bottom)
  155. {
  156. rect.bottom = rcScreen.bottom;
  157. m_reducedWindowSize = true;
  158. }
  159. }
  160. SetWindowPos(&CWnd::wndTopMost, rect.left, rect.top, rect.Width(), rect.Height
  161. (), SWP_SHOWWINDOW | SWP_NOCOPYBITS | SWP_NOACTIVATE |
  162. SWP_NOZORDER);
  163. return TRUE;
  164. }
  165. BOOL CToolTipEx::Hide()
  166. {
  167. DELETE_BITMAP
  168. if(::IsWindowVisible(m_hWnd))
  169. {
  170. CRect rect;
  171. this->GetWindowRect(&rect);
  172. CGetSetOptions::SetDescWndSize(rect.Size());
  173. CGetSetOptions::SetDescWndPoint(rect.TopLeft());
  174. }
  175. ShowWindow(SW_HIDE);
  176. m_csRTF = "";
  177. m_csText = "";
  178. m_clipId = 0;
  179. m_searchText = _T("");
  180. return TRUE;
  181. }
  182. void CToolTipEx::OnPaint()
  183. {
  184. CPaintDC dc(this); // device context for painting
  185. CRect rect;
  186. GetClientRect(rect);
  187. // Draw Text
  188. // dc.SetBkMode(TRANSPARENT);
  189. // rect.DeflateRect(m_rectMargin);
  190. CBrush Brush, *pOldBrush;
  191. Brush.CreateSolidBrush(GetSysColor(COLOR_INFOBK));
  192. pOldBrush = dc.SelectObject(&Brush);
  193. CFont *pOldFont = dc.SelectObject(&m_Font);
  194. dc.FillRect(&rect, &Brush);
  195. if(m_pBitmap)
  196. {
  197. CDC MemDc;
  198. MemDc.CreateCompatibleDC(&dc);
  199. CBitmap *oldBitmap = MemDc.SelectObject(m_pBitmap);
  200. int nWidth = CBitmapHelper::GetCBitmapWidth(*m_pBitmap);
  201. int nHeight = CBitmapHelper::GetCBitmapHeight(*m_pBitmap);
  202. if(CGetSetOptions::GetScaleImagesToDescWindow())
  203. {
  204. dc.StretchBlt(rect.left, rect.top, rect.Width(), rect.Height(), &MemDc, 0, 0, nWidth, nHeight, SRCCOPY);
  205. //OutputDebugString(StrF(_T("scaling image, window size %d/%d, image %d/%d\n"), min(nWidth, rect.Width()), min(nHeight, rect.Height()), nWidth, nHeight));
  206. }
  207. else
  208. {
  209. dc.BitBlt(rect.left, rect.top, nWidth, nHeight, &MemDc, 0, 0, SRCCOPY);
  210. }
  211. //dc.StretchBlt(rect.left, rect.top, rect.Width(), rect.Height(), &MemDc, 0, 0, nWidth, nHeight, SRCCOPY);
  212. MemDc.SelectObject(oldBitmap);
  213. rect.top += nHeight;
  214. }
  215. //dc.DrawText(m_csText, rect, m_dwTextStyle);
  216. // Cleanup
  217. // dc.SelectObject(pOldBrush);
  218. // dc.SelectObject(pOldFont);
  219. }
  220. void CToolTipEx::PostNcDestroy()
  221. {
  222. CWnd::PostNcDestroy();
  223. delete this;
  224. }
  225. BOOL CToolTipEx::PreTranslateMessage(MSG *pMsg)
  226. {
  227. m_DittoWindow.DoPreTranslateMessage(pMsg);
  228. switch(pMsg->message)
  229. {
  230. case WM_KEYDOWN:
  231. switch(pMsg->wParam)
  232. {
  233. case VK_ESCAPE:
  234. Hide();
  235. return TRUE;
  236. case 'C':
  237. if(GetKeyState(VK_CONTROL) &0x8000)
  238. {
  239. m_RichEdit.Copy();
  240. }
  241. break;
  242. case VK_F3:
  243. {
  244. DoSearch();
  245. }
  246. break;
  247. }
  248. break;
  249. case WM_RBUTTONDOWN:
  250. {
  251. if (m_RichEdit.m_hWnd == GetFocus()->m_hWnd)
  252. {
  253. OnOptions();
  254. return TRUE;
  255. }
  256. }
  257. break;
  258. }
  259. return CWnd::PreTranslateMessage(pMsg);
  260. }
  261. BOOL CToolTipEx::OnMsg(MSG *pMsg)
  262. {
  263. if(FALSE == IsWindowVisible())
  264. {
  265. return FALSE;
  266. }
  267. switch(pMsg->message)
  268. {
  269. case WM_WINDOWPOSCHANGING:
  270. case WM_LBUTTONDOWN:
  271. {
  272. if(!IsCursorInToolTip())
  273. {
  274. Hide();
  275. }
  276. break;
  277. }
  278. case WM_KEYDOWN:
  279. {
  280. WPARAM vk = pMsg->wParam;
  281. if(vk == VK_ESCAPE)
  282. {
  283. Hide();
  284. return TRUE;
  285. }
  286. else if(vk == VK_TAB)
  287. {
  288. m_RichEdit.SetFocus();
  289. return TRUE;
  290. }
  291. else if(vk == 'N')
  292. {
  293. return FALSE;
  294. }
  295. else if (vk == 'P')
  296. {
  297. return FALSE;
  298. }
  299. else if(vk == VK_F3)
  300. {
  301. DoSearch();
  302. return TRUE;
  303. }
  304. else if(vk == VK_SHIFT)
  305. {
  306. return FALSE;
  307. }
  308. Hide();
  309. break;
  310. }
  311. case WM_LBUTTONDBLCLK:
  312. case WM_RBUTTONDBLCLK:
  313. case WM_MBUTTONDOWN:
  314. case WM_MBUTTONDBLCLK:
  315. case WM_NCLBUTTONDOWN:
  316. case WM_NCLBUTTONDBLCLK:
  317. case WM_NCRBUTTONDOWN:
  318. case WM_NCRBUTTONDBLCLK:
  319. case WM_NCMBUTTONDOWN:
  320. case WM_NCMBUTTONDBLCLK:
  321. {
  322. Hide();
  323. break;
  324. }
  325. }
  326. return FALSE;
  327. }
  328. CRect CToolTipEx::GetBoundsRect()
  329. {
  330. CWindowDC dc(NULL);
  331. CFont *pOldFont = (CFont*)dc.SelectObject((CFont*) &m_Font);
  332. int nLineWidth = 0;
  333. if(nLineWidth == 0)
  334. {
  335. // Count the number of lines of text
  336. int nStart = 0, nNumLines = 0;
  337. CString strTextCopy = m_csText;
  338. do
  339. {
  340. nStart = strTextCopy.Find(_T("\n"));
  341. // skip found character
  342. if(nStart >= 0)
  343. {
  344. strTextCopy = strTextCopy.Mid(nStart + 1);
  345. }
  346. nNumLines++;
  347. }
  348. while(nStart >= 0);
  349. // Find the widest line
  350. for(int i = 0; i < nNumLines; i++)
  351. {
  352. CString strLine = GetFieldFromString(m_csText, i, _T('\n')) + _T(
  353. " ");
  354. nLineWidth = max(nLineWidth, dc.GetTextExtent(strLine).cx);
  355. }
  356. }
  357. CRect rect(0, 0, max(0, nLineWidth), 0);
  358. dc.DrawText(m_csText, rect, DT_CALCRECT | m_dwTextStyle);
  359. dc.SelectObject(pOldFont);
  360. rect.bottom += m_rectMargin.top + m_rectMargin.bottom;
  361. rect.right += m_rectMargin.left + m_rectMargin.right + 2;
  362. if(m_pBitmap)
  363. {
  364. int nWidth = CBitmapHelper::GetCBitmapWidth(*m_pBitmap);
  365. int nHeight = CBitmapHelper::GetCBitmapHeight(*m_pBitmap);
  366. rect.bottom += nHeight;
  367. if((rect.left + nWidth) > rect.right)
  368. {
  369. rect.right = rect.left + nWidth;
  370. }
  371. }
  372. return rect;
  373. }
  374. CString CToolTipEx::GetFieldFromString(CString ref, int nIndex, TCHAR ch)
  375. {
  376. CString strReturn;
  377. LPCTSTR pstrStart = ref.LockBuffer();
  378. LPCTSTR pstrBuffer = pstrStart;
  379. int nCurrent = 0;
  380. int nStart = 0;
  381. int nEnd = 0;
  382. int nOldStart = 0;
  383. while(nCurrent <= nIndex && *pstrBuffer != _T('\0'))
  384. {
  385. if(*pstrBuffer == ch)
  386. {
  387. nOldStart = nStart;
  388. nStart = nEnd + 1;
  389. nCurrent++;
  390. }
  391. nEnd++;
  392. pstrBuffer++;
  393. }
  394. // May have reached the end of the string
  395. if(*pstrBuffer == _T('\0'))
  396. {
  397. nOldStart = nStart;
  398. nEnd++;
  399. }
  400. ref.UnlockBuffer();
  401. if(nCurrent < nIndex)
  402. {
  403. //TRACE1("Warning: GetStringField - Couldn't find field %d.\n", nIndex);
  404. return strReturn;
  405. }
  406. return ref.Mid(nOldStart, nEnd - nOldStart - 1);
  407. }
  408. LPLOGFONT CToolTipEx::GetSystemToolTipFont()
  409. {
  410. static LOGFONT LogFont;
  411. NONCLIENTMETRICS ncm;
  412. ncm.cbSize = sizeof(NONCLIENTMETRICS);
  413. if(!SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS),
  414. &ncm, 0))
  415. {
  416. return FALSE;
  417. }
  418. memcpy(&LogFont, &(ncm.lfStatusFont), sizeof(LOGFONT));
  419. return &LogFont;
  420. }
  421. BOOL CToolTipEx::SetLogFont(LPLOGFONT lpLogFont, BOOL bRedraw /*=TRUE*/)
  422. {
  423. ASSERT(lpLogFont);
  424. if(!lpLogFont)
  425. {
  426. return FALSE;
  427. }
  428. LOGFONT LogFont;
  429. // Store font as the global default
  430. memcpy(&LogFont, lpLogFont, sizeof(LOGFONT));
  431. // Create the actual font object
  432. m_Font.DeleteObject();
  433. m_Font.CreateFontIndirect(&LogFont);
  434. if(bRedraw && ::IsWindow(GetSafeHwnd()))
  435. {
  436. Invalidate();
  437. }
  438. return TRUE;
  439. }
  440. void CToolTipEx::SetBitmap(CBitmap *pBitmap)
  441. {
  442. DELETE_BITMAP
  443. m_pBitmap = pBitmap;
  444. if (m_pBitmap != NULL)
  445. {
  446. int nWidth = CBitmapHelper::GetCBitmapWidth(*m_pBitmap);
  447. int nHeight = CBitmapHelper::GetCBitmapHeight(*m_pBitmap);
  448. Invalidate();
  449. }
  450. }
  451. void CToolTipEx::OnSize(UINT nType, int cx, int cy)
  452. {
  453. CWnd::OnSize(nType, cx, cy);
  454. if(::IsWindow(m_RichEdit.GetSafeHwnd()) == FALSE)
  455. {
  456. return ;
  457. }
  458. CRect cr;
  459. GetClientRect(cr);
  460. cr.DeflateRect(0, 0, 0, theApp.m_metrics.ScaleY(21));
  461. m_RichEdit.MoveWindow(cr);
  462. m_optionsButton.MoveWindow(cr.left, cr.bottom + theApp.m_metrics.ScaleY(2), theApp.m_metrics.ScaleX(17), theApp.m_metrics.ScaleY(17));
  463. this->Invalidate();
  464. m_DittoWindow.DoSetRegion(this);
  465. }
  466. BOOL CToolTipEx::IsCursorInToolTip()
  467. {
  468. CRect cr;
  469. GetWindowRect(cr);
  470. CPoint cursorPos;
  471. GetCursorPos(&cursorPos);
  472. return cr.PtInRect(cursorPos);
  473. }
  474. void CToolTipEx::SetRTFText(const char *pRTF)
  475. {
  476. m_RichEdit.SetRTF(pRTF);
  477. m_csRTF = pRTF;
  478. m_RichEdit.SetSel(0, 0);
  479. HighlightSearchText();
  480. }
  481. //void CToolTipEx::SetRTFText(const CString &csRTF)
  482. //{
  483. // m_RichEdit.SetRTF(csRTF);
  484. // m_csRTF = csRTF;
  485. //}
  486. void CToolTipEx::SetToolTipText(const CString &csText)
  487. {
  488. m_csText = csText;
  489. m_RichEdit.SetFont(&m_Font);
  490. m_RichEdit.SetText(csText);
  491. m_RichEdit.SetSel(0, 0);
  492. HighlightSearchText();
  493. }
  494. void CToolTipEx::HighlightSearchText()
  495. {
  496. if (m_searchText.GetLength() <= 0)
  497. return;
  498. FINDTEXTEX ft;
  499. long n = -1;
  500. ft.lpstrText = m_searchText;
  501. ft.chrg.cpMin = 0;
  502. ft.chrg.cpMax = -1;
  503. CHARFORMAT cf;
  504. cf.cbSize = sizeof(cf);
  505. cf.dwMask = CFM_COLOR;
  506. cf.dwEffects = CFE_BOLD | ~CFE_AUTOCOLOR;
  507. cf.crTextColor = RGB(255, 0, 0);
  508. do
  509. {
  510. ft.chrg.cpMin = n+1;
  511. n = m_RichEdit.FindText(FR_DOWN, &ft);
  512. if (n != -1)
  513. {
  514. m_RichEdit.SetSel(ft.chrgText);
  515. m_RichEdit.SetSelectionCharFormat(cf);
  516. }
  517. } while (n != -1);
  518. m_RichEdit.SetSel(0, 0);
  519. }
  520. void CToolTipEx::DoSearch()
  521. {
  522. if (m_searchText.GetLength() <= 0)
  523. return;
  524. FINDTEXTEX ft;
  525. long n = -1;
  526. ft.lpstrText = m_searchText;
  527. long start;
  528. long end;
  529. m_RichEdit.GetSel(start, end);
  530. ft.chrg.cpMin = end;
  531. ft.chrg.cpMax = -1;
  532. int searchDirection = FR_DOWN;
  533. if (GetKeyState(VK_SHIFT) & 0x8000)
  534. {
  535. searchDirection = 0;
  536. ft.chrg.cpMin = start;
  537. }
  538. n = m_RichEdit.FindText(searchDirection, &ft);
  539. if (n != -1)
  540. {
  541. m_RichEdit.SetSel(ft.chrgText);
  542. }
  543. else
  544. {
  545. if (searchDirection == 0)
  546. {
  547. ft.chrg.cpMin = m_RichEdit.GetTextLength();
  548. }
  549. else
  550. {
  551. ft.chrg.cpMin = 0;
  552. }
  553. ft.chrg.cpMax = -1;
  554. n = m_RichEdit.FindText(searchDirection, &ft);
  555. if (n != -1)
  556. {
  557. m_RichEdit.SetSel(ft.chrgText);
  558. }
  559. }
  560. }
  561. void CToolTipEx::OnActivate(UINT nState, CWnd *pWndOther, BOOL bMinimized)
  562. {
  563. CWnd::OnActivate(nState, pWndOther, bMinimized);
  564. if(nState == WA_INACTIVE)
  565. {
  566. Hide();
  567. if(m_pNotifyWnd)
  568. {
  569. m_pNotifyWnd->PostMessage(NM_INACTIVE_TOOLTIPWND, 0, 0);
  570. }
  571. }
  572. }
  573. void CToolTipEx::OnTimer(UINT_PTR nIDEvent)
  574. {
  575. switch(nIDEvent)
  576. {
  577. case HIDE_WINDOW_TIMER:
  578. Hide();
  579. PostMessage(WM_DESTROY, 0, 0);
  580. break;
  581. }
  582. CWnd::OnTimer(nIDEvent);
  583. }
  584. void CToolTipEx::OnNcPaint()
  585. {
  586. m_DittoWindow.DoNcPaint(this);
  587. }
  588. void CToolTipEx::OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS FAR* lpncsp)
  589. {
  590. CWnd::OnNcCalcSize(bCalcValidRects, lpncsp);
  591. m_DittoWindow.DoNcCalcSize(bCalcValidRects, lpncsp);
  592. }
  593. HITTEST_RET CToolTipEx::OnNcHitTest(CPoint point)
  594. {
  595. UINT Ret = m_DittoWindow.DoNcHitTest(this, point);
  596. if(Ret == -1)
  597. return CWnd::OnNcHitTest(point);
  598. return Ret;
  599. }
  600. void CToolTipEx::OnNcLButtonDown(UINT nHitTest, CPoint point)
  601. {
  602. m_DittoWindow.DoNcLButtonDown(this, nHitTest, point);
  603. CWnd::OnNcLButtonDown(nHitTest, point);
  604. }
  605. void CToolTipEx::OnNcLButtonUp(UINT nHitTest, CPoint point)
  606. {
  607. long lRet = m_DittoWindow.DoNcLButtonUp(this, nHitTest, point);
  608. switch(lRet)
  609. {
  610. case BUTTON_CLOSE:
  611. Hide();
  612. break;
  613. }
  614. CWnd::OnNcLButtonUp(nHitTest, point);
  615. }
  616. void CToolTipEx::OnNcMouseMove(UINT nHitTest, CPoint point)
  617. {
  618. m_DittoWindow.DoNcMouseMove(this, nHitTest, point);
  619. CWnd::OnNcMouseMove(nHitTest, point);
  620. }
  621. void CToolTipEx::OnOptions()
  622. {
  623. POINT pp;
  624. CMenu cmPopUp;
  625. CMenu *cmSubMenu = NULL;
  626. GetCursorPos(&pp);
  627. if(cmPopUp.LoadMenu(IDR_DESC_OPTIONS_MENU) != 0)
  628. {
  629. cmSubMenu = cmPopUp.GetSubMenu(0);
  630. if(!cmSubMenu)
  631. {
  632. return ;
  633. }
  634. GetCursorPos(&pp);
  635. if(CGetSetOptions::GetRememberDescPos())
  636. cmSubMenu->CheckMenuItem(ID_FIRST_REMEMBERWINDOWPOSITION, MF_CHECKED);
  637. if(CGetSetOptions::GetSizeDescWindowToContent())
  638. cmSubMenu->CheckMenuItem(ID_FIRST_SIZEWINDOWTOCONTENT, MF_CHECKED);
  639. if(CGetSetOptions::GetScaleImagesToDescWindow())
  640. cmSubMenu->CheckMenuItem(ID_FIRST_SCALEIMAGESTOFITWINDOW, MF_CHECKED);
  641. //theApp.m_Language.UpdateRightClickMenu(cmSubMenu);
  642. cmSubMenu->TrackPopupMenu(TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RIGHTBUTTON, pp.x, pp.y, this, NULL);
  643. }
  644. }
  645. void CToolTipEx::OnRememberwindowposition()
  646. {
  647. CGetSetOptions::SetRememberDescPos(!CGetSetOptions::GetRememberDescPos());
  648. }
  649. void CToolTipEx::OnSizewindowtocontent()
  650. {
  651. CGetSetOptions::SetSizeDescWindowToContent(!CGetSetOptions::GetSizeDescWindowToContent());
  652. CRect rect;
  653. this->GetWindowRect(&rect);
  654. Show(rect.TopLeft());
  655. }
  656. void CToolTipEx::OnScaleimagestofitwindow()
  657. {
  658. CGetSetOptions::SetScaleImagesToDescWindow(!CGetSetOptions::GetScaleImagesToDescWindow());
  659. Invalidate();
  660. }
  661. void CToolTipEx::OnRButtonDown(UINT nFlags, CPoint point)
  662. {
  663. OnOptions();
  664. CWnd::OnRButtonDown(nFlags, point);
  665. }
  666. void CToolTipEx::OnSetFocus(CWnd* pOldWnd)
  667. {
  668. CWnd::OnSetFocus(pOldWnd);
  669. m_RichEdit.SetFocus();
  670. }