ToolTipEx.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845
  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. ShowWindow(SW_HIDE);
  169. m_csRTF = "";
  170. m_csText = "";
  171. m_clipId = 0;
  172. m_searchText = _T("");
  173. CRect rect;
  174. this->GetWindowRect(&rect);
  175. CGetSetOptions::SetDescWndSize(rect.Size());
  176. CGetSetOptions::SetDescWndPoint(rect.TopLeft());
  177. return TRUE;
  178. }
  179. void CToolTipEx::OnPaint()
  180. {
  181. CPaintDC dc(this); // device context for painting
  182. CRect rect;
  183. GetClientRect(rect);
  184. // Draw Text
  185. // dc.SetBkMode(TRANSPARENT);
  186. // rect.DeflateRect(m_rectMargin);
  187. CBrush Brush, *pOldBrush;
  188. Brush.CreateSolidBrush(GetSysColor(COLOR_INFOBK));
  189. pOldBrush = dc.SelectObject(&Brush);
  190. CFont *pOldFont = dc.SelectObject(&m_Font);
  191. dc.FillRect(&rect, &Brush);
  192. if(m_pBitmap)
  193. {
  194. CDC MemDc;
  195. MemDc.CreateCompatibleDC(&dc);
  196. CBitmap *oldBitmap = MemDc.SelectObject(m_pBitmap);
  197. int nWidth = CBitmapHelper::GetCBitmapWidth(*m_pBitmap);
  198. int nHeight = CBitmapHelper::GetCBitmapHeight(*m_pBitmap);
  199. if(CGetSetOptions::GetScaleImagesToDescWindow())
  200. {
  201. dc.StretchBlt(rect.left, rect.top, rect.Width(), rect.Height(), &MemDc, 0, 0, nWidth, nHeight, SRCCOPY);
  202. //OutputDebugString(StrF(_T("scaling image, window size %d/%d, image %d/%d\n"), min(nWidth, rect.Width()), min(nHeight, rect.Height()), nWidth, nHeight));
  203. }
  204. else
  205. {
  206. dc.BitBlt(rect.left, rect.top, nWidth, nHeight, &MemDc, 0, 0, SRCCOPY);
  207. }
  208. //dc.StretchBlt(rect.left, rect.top, rect.Width(), rect.Height(), &MemDc, 0, 0, nWidth, nHeight, SRCCOPY);
  209. MemDc.SelectObject(oldBitmap);
  210. rect.top += nHeight;
  211. }
  212. //dc.DrawText(m_csText, rect, m_dwTextStyle);
  213. // Cleanup
  214. // dc.SelectObject(pOldBrush);
  215. // dc.SelectObject(pOldFont);
  216. }
  217. void CToolTipEx::PostNcDestroy()
  218. {
  219. CWnd::PostNcDestroy();
  220. delete this;
  221. }
  222. BOOL CToolTipEx::PreTranslateMessage(MSG *pMsg)
  223. {
  224. m_DittoWindow.DoPreTranslateMessage(pMsg);
  225. switch(pMsg->message)
  226. {
  227. case WM_KEYDOWN:
  228. switch(pMsg->wParam)
  229. {
  230. case VK_ESCAPE:
  231. Hide();
  232. return TRUE;
  233. case 'C':
  234. if(GetKeyState(VK_CONTROL) &0x8000)
  235. {
  236. m_RichEdit.Copy();
  237. }
  238. break;
  239. case VK_F3:
  240. {
  241. DoSearch();
  242. }
  243. break;
  244. }
  245. break;
  246. case WM_RBUTTONDOWN:
  247. {
  248. if (m_RichEdit.m_hWnd == GetFocus()->m_hWnd)
  249. {
  250. OnOptions();
  251. return TRUE;
  252. }
  253. }
  254. break;
  255. }
  256. return CWnd::PreTranslateMessage(pMsg);
  257. }
  258. BOOL CToolTipEx::OnMsg(MSG *pMsg)
  259. {
  260. if(FALSE == IsWindowVisible())
  261. {
  262. return FALSE;
  263. }
  264. switch(pMsg->message)
  265. {
  266. case WM_WINDOWPOSCHANGING:
  267. case WM_LBUTTONDOWN:
  268. {
  269. if(!IsCursorInToolTip())
  270. {
  271. Hide();
  272. }
  273. break;
  274. }
  275. case WM_KEYDOWN:
  276. {
  277. WPARAM vk = pMsg->wParam;
  278. if(vk == VK_ESCAPE)
  279. {
  280. Hide();
  281. return TRUE;
  282. }
  283. else if(vk == VK_TAB)
  284. {
  285. m_RichEdit.SetFocus();
  286. return TRUE;
  287. }
  288. else if(vk == 'N')
  289. {
  290. return FALSE;
  291. }
  292. else if (vk == 'P')
  293. {
  294. return FALSE;
  295. }
  296. else if(vk == VK_F3)
  297. {
  298. DoSearch();
  299. return TRUE;
  300. }
  301. else if(vk == VK_SHIFT)
  302. {
  303. return FALSE;
  304. }
  305. Hide();
  306. break;
  307. }
  308. case WM_LBUTTONDBLCLK:
  309. case WM_RBUTTONDBLCLK:
  310. case WM_MBUTTONDOWN:
  311. case WM_MBUTTONDBLCLK:
  312. case WM_NCLBUTTONDOWN:
  313. case WM_NCLBUTTONDBLCLK:
  314. case WM_NCRBUTTONDOWN:
  315. case WM_NCRBUTTONDBLCLK:
  316. case WM_NCMBUTTONDOWN:
  317. case WM_NCMBUTTONDBLCLK:
  318. {
  319. Hide();
  320. break;
  321. }
  322. }
  323. return FALSE;
  324. }
  325. CRect CToolTipEx::GetBoundsRect()
  326. {
  327. CWindowDC dc(NULL);
  328. CFont *pOldFont = (CFont*)dc.SelectObject((CFont*) &m_Font);
  329. int nLineWidth = 0;
  330. if(nLineWidth == 0)
  331. {
  332. // Count the number of lines of text
  333. int nStart = 0, nNumLines = 0;
  334. CString strTextCopy = m_csText;
  335. do
  336. {
  337. nStart = strTextCopy.Find(_T("\n"));
  338. // skip found character
  339. if(nStart >= 0)
  340. {
  341. strTextCopy = strTextCopy.Mid(nStart + 1);
  342. }
  343. nNumLines++;
  344. }
  345. while(nStart >= 0);
  346. // Find the widest line
  347. for(int i = 0; i < nNumLines; i++)
  348. {
  349. CString strLine = GetFieldFromString(m_csText, i, _T('\n')) + _T(
  350. " ");
  351. nLineWidth = max(nLineWidth, dc.GetTextExtent(strLine).cx);
  352. }
  353. }
  354. CRect rect(0, 0, max(0, nLineWidth), 0);
  355. dc.DrawText(m_csText, rect, DT_CALCRECT | m_dwTextStyle);
  356. dc.SelectObject(pOldFont);
  357. rect.bottom += m_rectMargin.top + m_rectMargin.bottom;
  358. rect.right += m_rectMargin.left + m_rectMargin.right + 2;
  359. if(m_pBitmap)
  360. {
  361. int nWidth = CBitmapHelper::GetCBitmapWidth(*m_pBitmap);
  362. int nHeight = CBitmapHelper::GetCBitmapHeight(*m_pBitmap);
  363. rect.bottom += nHeight;
  364. if((rect.left + nWidth) > rect.right)
  365. {
  366. rect.right = rect.left + nWidth;
  367. }
  368. }
  369. return rect;
  370. }
  371. CString CToolTipEx::GetFieldFromString(CString ref, int nIndex, TCHAR ch)
  372. {
  373. CString strReturn;
  374. LPCTSTR pstrStart = ref.LockBuffer();
  375. LPCTSTR pstrBuffer = pstrStart;
  376. int nCurrent = 0;
  377. int nStart = 0;
  378. int nEnd = 0;
  379. int nOldStart = 0;
  380. while(nCurrent <= nIndex && *pstrBuffer != _T('\0'))
  381. {
  382. if(*pstrBuffer == ch)
  383. {
  384. nOldStart = nStart;
  385. nStart = nEnd + 1;
  386. nCurrent++;
  387. }
  388. nEnd++;
  389. pstrBuffer++;
  390. }
  391. // May have reached the end of the string
  392. if(*pstrBuffer == _T('\0'))
  393. {
  394. nOldStart = nStart;
  395. nEnd++;
  396. }
  397. ref.UnlockBuffer();
  398. if(nCurrent < nIndex)
  399. {
  400. //TRACE1("Warning: GetStringField - Couldn't find field %d.\n", nIndex);
  401. return strReturn;
  402. }
  403. return ref.Mid(nOldStart, nEnd - nOldStart - 1);
  404. }
  405. LPLOGFONT CToolTipEx::GetSystemToolTipFont()
  406. {
  407. static LOGFONT LogFont;
  408. NONCLIENTMETRICS ncm;
  409. ncm.cbSize = sizeof(NONCLIENTMETRICS);
  410. if(!SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS),
  411. &ncm, 0))
  412. {
  413. return FALSE;
  414. }
  415. memcpy(&LogFont, &(ncm.lfStatusFont), sizeof(LOGFONT));
  416. return &LogFont;
  417. }
  418. BOOL CToolTipEx::SetLogFont(LPLOGFONT lpLogFont, BOOL bRedraw /*=TRUE*/)
  419. {
  420. ASSERT(lpLogFont);
  421. if(!lpLogFont)
  422. {
  423. return FALSE;
  424. }
  425. LOGFONT LogFont;
  426. // Store font as the global default
  427. memcpy(&LogFont, lpLogFont, sizeof(LOGFONT));
  428. // Create the actual font object
  429. m_Font.DeleteObject();
  430. m_Font.CreateFontIndirect(&LogFont);
  431. if(bRedraw && ::IsWindow(GetSafeHwnd()))
  432. {
  433. Invalidate();
  434. }
  435. return TRUE;
  436. }
  437. void CToolTipEx::SetBitmap(CBitmap *pBitmap)
  438. {
  439. DELETE_BITMAP
  440. m_pBitmap = pBitmap;
  441. if (m_pBitmap != NULL)
  442. {
  443. int nWidth = CBitmapHelper::GetCBitmapWidth(*m_pBitmap);
  444. int nHeight = CBitmapHelper::GetCBitmapHeight(*m_pBitmap);
  445. Invalidate();
  446. }
  447. }
  448. void CToolTipEx::OnSize(UINT nType, int cx, int cy)
  449. {
  450. CWnd::OnSize(nType, cx, cy);
  451. if(::IsWindow(m_RichEdit.GetSafeHwnd()) == FALSE)
  452. {
  453. return ;
  454. }
  455. CRect cr;
  456. GetClientRect(cr);
  457. cr.DeflateRect(0, 0, 0, theApp.m_metrics.ScaleY(21));
  458. m_RichEdit.MoveWindow(cr);
  459. m_optionsButton.MoveWindow(cr.left, cr.bottom + theApp.m_metrics.ScaleY(2), theApp.m_metrics.ScaleX(17), theApp.m_metrics.ScaleY(17));
  460. this->Invalidate();
  461. m_DittoWindow.DoSetRegion(this);
  462. }
  463. BOOL CToolTipEx::IsCursorInToolTip()
  464. {
  465. CRect cr;
  466. GetWindowRect(cr);
  467. CPoint cursorPos;
  468. GetCursorPos(&cursorPos);
  469. return cr.PtInRect(cursorPos);
  470. }
  471. void CToolTipEx::SetRTFText(const char *pRTF)
  472. {
  473. m_RichEdit.SetRTF(pRTF);
  474. m_csRTF = pRTF;
  475. m_RichEdit.SetSel(0, 0);
  476. HighlightSearchText();
  477. }
  478. //void CToolTipEx::SetRTFText(const CString &csRTF)
  479. //{
  480. // m_RichEdit.SetRTF(csRTF);
  481. // m_csRTF = csRTF;
  482. //}
  483. void CToolTipEx::SetToolTipText(const CString &csText)
  484. {
  485. m_csText = csText;
  486. m_RichEdit.SetFont(&m_Font);
  487. m_RichEdit.SetText(csText);
  488. m_RichEdit.SetSel(0, 0);
  489. HighlightSearchText();
  490. }
  491. void CToolTipEx::HighlightSearchText()
  492. {
  493. if (m_searchText.GetLength() <= 0)
  494. return;
  495. FINDTEXTEX ft;
  496. long n = -1;
  497. ft.lpstrText = m_searchText;
  498. ft.chrg.cpMin = 0;
  499. ft.chrg.cpMax = -1;
  500. CHARFORMAT cf;
  501. cf.cbSize = sizeof(cf);
  502. cf.dwMask = CFM_COLOR;
  503. cf.dwEffects = CFE_BOLD | ~CFE_AUTOCOLOR;
  504. cf.crTextColor = RGB(255, 0, 0);
  505. do
  506. {
  507. ft.chrg.cpMin = n+1;
  508. n = m_RichEdit.FindText(FR_DOWN, &ft);
  509. if (n != -1)
  510. {
  511. m_RichEdit.SetSel(ft.chrgText);
  512. m_RichEdit.SetSelectionCharFormat(cf);
  513. }
  514. } while (n != -1);
  515. m_RichEdit.SetSel(0, 0);
  516. }
  517. void CToolTipEx::DoSearch()
  518. {
  519. if (m_searchText.GetLength() <= 0)
  520. return;
  521. FINDTEXTEX ft;
  522. long n = -1;
  523. ft.lpstrText = m_searchText;
  524. long start;
  525. long end;
  526. m_RichEdit.GetSel(start, end);
  527. ft.chrg.cpMin = end;
  528. ft.chrg.cpMax = -1;
  529. int searchDirection = FR_DOWN;
  530. if (GetKeyState(VK_SHIFT) & 0x8000)
  531. {
  532. searchDirection = 0;
  533. ft.chrg.cpMin = start;
  534. }
  535. n = m_RichEdit.FindText(searchDirection, &ft);
  536. if (n != -1)
  537. {
  538. m_RichEdit.SetSel(ft.chrgText);
  539. }
  540. else
  541. {
  542. if (searchDirection == 0)
  543. {
  544. ft.chrg.cpMin = m_RichEdit.GetTextLength();
  545. }
  546. else
  547. {
  548. ft.chrg.cpMin = 0;
  549. }
  550. ft.chrg.cpMax = -1;
  551. n = m_RichEdit.FindText(searchDirection, &ft);
  552. if (n != -1)
  553. {
  554. m_RichEdit.SetSel(ft.chrgText);
  555. }
  556. }
  557. }
  558. void CToolTipEx::OnActivate(UINT nState, CWnd *pWndOther, BOOL bMinimized)
  559. {
  560. CWnd::OnActivate(nState, pWndOther, bMinimized);
  561. if(nState == WA_INACTIVE)
  562. {
  563. Hide();
  564. if(m_pNotifyWnd)
  565. {
  566. m_pNotifyWnd->PostMessage(NM_INACTIVE_TOOLTIPWND, 0, 0);
  567. }
  568. }
  569. }
  570. void CToolTipEx::OnTimer(UINT_PTR nIDEvent)
  571. {
  572. switch(nIDEvent)
  573. {
  574. case HIDE_WINDOW_TIMER:
  575. Hide();
  576. PostMessage(WM_DESTROY, 0, 0);
  577. break;
  578. }
  579. CWnd::OnTimer(nIDEvent);
  580. }
  581. void CToolTipEx::OnNcPaint()
  582. {
  583. m_DittoWindow.DoNcPaint(this);
  584. }
  585. void CToolTipEx::OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS FAR* lpncsp)
  586. {
  587. CWnd::OnNcCalcSize(bCalcValidRects, lpncsp);
  588. m_DittoWindow.DoNcCalcSize(bCalcValidRects, lpncsp);
  589. }
  590. HITTEST_RET CToolTipEx::OnNcHitTest(CPoint point)
  591. {
  592. UINT Ret = m_DittoWindow.DoNcHitTest(this, point);
  593. if(Ret == -1)
  594. return CWnd::OnNcHitTest(point);
  595. return Ret;
  596. }
  597. void CToolTipEx::OnNcLButtonDown(UINT nHitTest, CPoint point)
  598. {
  599. m_DittoWindow.DoNcLButtonDown(this, nHitTest, point);
  600. CWnd::OnNcLButtonDown(nHitTest, point);
  601. }
  602. void CToolTipEx::OnNcLButtonUp(UINT nHitTest, CPoint point)
  603. {
  604. long lRet = m_DittoWindow.DoNcLButtonUp(this, nHitTest, point);
  605. switch(lRet)
  606. {
  607. case BUTTON_CLOSE:
  608. Hide();
  609. break;
  610. }
  611. CWnd::OnNcLButtonUp(nHitTest, point);
  612. }
  613. void CToolTipEx::OnNcMouseMove(UINT nHitTest, CPoint point)
  614. {
  615. m_DittoWindow.DoNcMouseMove(this, nHitTest, point);
  616. CWnd::OnNcMouseMove(nHitTest, point);
  617. }
  618. void CToolTipEx::OnOptions()
  619. {
  620. POINT pp;
  621. CMenu cmPopUp;
  622. CMenu *cmSubMenu = NULL;
  623. GetCursorPos(&pp);
  624. if(cmPopUp.LoadMenu(IDR_DESC_OPTIONS_MENU) != 0)
  625. {
  626. cmSubMenu = cmPopUp.GetSubMenu(0);
  627. if(!cmSubMenu)
  628. {
  629. return ;
  630. }
  631. GetCursorPos(&pp);
  632. if(CGetSetOptions::GetRememberDescPos())
  633. cmSubMenu->CheckMenuItem(ID_FIRST_REMEMBERWINDOWPOSITION, MF_CHECKED);
  634. if(CGetSetOptions::GetSizeDescWindowToContent())
  635. cmSubMenu->CheckMenuItem(ID_FIRST_SIZEWINDOWTOCONTENT, MF_CHECKED);
  636. if(CGetSetOptions::GetScaleImagesToDescWindow())
  637. cmSubMenu->CheckMenuItem(ID_FIRST_SCALEIMAGESTOFITWINDOW, MF_CHECKED);
  638. //theApp.m_Language.UpdateRightClickMenu(cmSubMenu);
  639. cmSubMenu->TrackPopupMenu(TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RIGHTBUTTON, pp.x, pp.y, this, NULL);
  640. }
  641. }
  642. void CToolTipEx::OnRememberwindowposition()
  643. {
  644. CGetSetOptions::SetRememberDescPos(!CGetSetOptions::GetRememberDescPos());
  645. }
  646. void CToolTipEx::OnSizewindowtocontent()
  647. {
  648. CGetSetOptions::SetSizeDescWindowToContent(!CGetSetOptions::GetSizeDescWindowToContent());
  649. CRect rect;
  650. this->GetWindowRect(&rect);
  651. Show(rect.TopLeft());
  652. }
  653. void CToolTipEx::OnScaleimagestofitwindow()
  654. {
  655. CGetSetOptions::SetScaleImagesToDescWindow(!CGetSetOptions::GetScaleImagesToDescWindow());
  656. Invalidate();
  657. }
  658. void CToolTipEx::OnRButtonDown(UINT nFlags, CPoint point)
  659. {
  660. OnOptions();
  661. CWnd::OnRButtonDown(nFlags, point);
  662. }
  663. void CToolTipEx::OnSetFocus(CWnd* pOldWnd)
  664. {
  665. CWnd::OnSetFocus(pOldWnd);
  666. m_RichEdit.SetFocus();
  667. }