ToolTipEx.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856
  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_UP)
  300. {
  301. return FALSE;
  302. }
  303. else if (vk == VK_DOWN)
  304. {
  305. return FALSE;
  306. }
  307. else if(vk == VK_F3)
  308. {
  309. DoSearch();
  310. return TRUE;
  311. }
  312. else if(vk == VK_SHIFT)
  313. {
  314. return FALSE;
  315. }
  316. Hide();
  317. break;
  318. }
  319. case WM_LBUTTONDBLCLK:
  320. case WM_RBUTTONDBLCLK:
  321. case WM_MBUTTONDOWN:
  322. case WM_MBUTTONDBLCLK:
  323. case WM_NCLBUTTONDOWN:
  324. case WM_NCLBUTTONDBLCLK:
  325. case WM_NCRBUTTONDOWN:
  326. case WM_NCRBUTTONDBLCLK:
  327. case WM_NCMBUTTONDOWN:
  328. case WM_NCMBUTTONDBLCLK:
  329. {
  330. Hide();
  331. break;
  332. }
  333. }
  334. return FALSE;
  335. }
  336. CRect CToolTipEx::GetBoundsRect()
  337. {
  338. CWindowDC dc(NULL);
  339. CFont *pOldFont = (CFont*)dc.SelectObject((CFont*) &m_Font);
  340. int nLineWidth = 0;
  341. if(nLineWidth == 0)
  342. {
  343. // Count the number of lines of text
  344. int nStart = 0, nNumLines = 0;
  345. CString strTextCopy = m_csText;
  346. do
  347. {
  348. nStart = strTextCopy.Find(_T("\n"));
  349. // skip found character
  350. if(nStart >= 0)
  351. {
  352. strTextCopy = strTextCopy.Mid(nStart + 1);
  353. }
  354. nNumLines++;
  355. }
  356. while(nStart >= 0);
  357. // Find the widest line
  358. for(int i = 0; i < nNumLines; i++)
  359. {
  360. CString strLine = GetFieldFromString(m_csText, i, _T('\n')) + _T(
  361. " ");
  362. nLineWidth = max(nLineWidth, dc.GetTextExtent(strLine).cx);
  363. }
  364. }
  365. CRect rect(0, 0, max(0, nLineWidth), 0);
  366. dc.DrawText(m_csText, rect, DT_CALCRECT | m_dwTextStyle);
  367. dc.SelectObject(pOldFont);
  368. rect.bottom += m_rectMargin.top + m_rectMargin.bottom;
  369. rect.right += m_rectMargin.left + m_rectMargin.right + 2;
  370. if(m_pBitmap)
  371. {
  372. int nWidth = CBitmapHelper::GetCBitmapWidth(*m_pBitmap);
  373. int nHeight = CBitmapHelper::GetCBitmapHeight(*m_pBitmap);
  374. rect.bottom += nHeight;
  375. if((rect.left + nWidth) > rect.right)
  376. {
  377. rect.right = rect.left + nWidth;
  378. }
  379. }
  380. return rect;
  381. }
  382. CString CToolTipEx::GetFieldFromString(CString ref, int nIndex, TCHAR ch)
  383. {
  384. CString strReturn;
  385. LPCTSTR pstrStart = ref.LockBuffer();
  386. LPCTSTR pstrBuffer = pstrStart;
  387. int nCurrent = 0;
  388. int nStart = 0;
  389. int nEnd = 0;
  390. int nOldStart = 0;
  391. while(nCurrent <= nIndex && *pstrBuffer != _T('\0'))
  392. {
  393. if(*pstrBuffer == ch)
  394. {
  395. nOldStart = nStart;
  396. nStart = nEnd + 1;
  397. nCurrent++;
  398. }
  399. nEnd++;
  400. pstrBuffer++;
  401. }
  402. // May have reached the end of the string
  403. if(*pstrBuffer == _T('\0'))
  404. {
  405. nOldStart = nStart;
  406. nEnd++;
  407. }
  408. ref.UnlockBuffer();
  409. if(nCurrent < nIndex)
  410. {
  411. //TRACE1("Warning: GetStringField - Couldn't find field %d.\n", nIndex);
  412. return strReturn;
  413. }
  414. return ref.Mid(nOldStart, nEnd - nOldStart - 1);
  415. }
  416. LPLOGFONT CToolTipEx::GetSystemToolTipFont()
  417. {
  418. static LOGFONT LogFont;
  419. NONCLIENTMETRICS ncm;
  420. ncm.cbSize = sizeof(NONCLIENTMETRICS);
  421. if(!SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS),
  422. &ncm, 0))
  423. {
  424. return FALSE;
  425. }
  426. memcpy(&LogFont, &(ncm.lfStatusFont), sizeof(LOGFONT));
  427. return &LogFont;
  428. }
  429. BOOL CToolTipEx::SetLogFont(LPLOGFONT lpLogFont, BOOL bRedraw /*=TRUE*/)
  430. {
  431. ASSERT(lpLogFont);
  432. if(!lpLogFont)
  433. {
  434. return FALSE;
  435. }
  436. LOGFONT LogFont;
  437. // Store font as the global default
  438. memcpy(&LogFont, lpLogFont, sizeof(LOGFONT));
  439. // Create the actual font object
  440. m_Font.DeleteObject();
  441. m_Font.CreateFontIndirect(&LogFont);
  442. if(bRedraw && ::IsWindow(GetSafeHwnd()))
  443. {
  444. Invalidate();
  445. }
  446. return TRUE;
  447. }
  448. void CToolTipEx::SetBitmap(CBitmap *pBitmap)
  449. {
  450. DELETE_BITMAP
  451. m_pBitmap = pBitmap;
  452. if (m_pBitmap != NULL)
  453. {
  454. int nWidth = CBitmapHelper::GetCBitmapWidth(*m_pBitmap);
  455. int nHeight = CBitmapHelper::GetCBitmapHeight(*m_pBitmap);
  456. Invalidate();
  457. }
  458. }
  459. void CToolTipEx::OnSize(UINT nType, int cx, int cy)
  460. {
  461. CWnd::OnSize(nType, cx, cy);
  462. if(::IsWindow(m_RichEdit.GetSafeHwnd()) == FALSE)
  463. {
  464. return ;
  465. }
  466. CRect cr;
  467. GetClientRect(cr);
  468. cr.DeflateRect(0, 0, 0, theApp.m_metrics.ScaleY(21));
  469. m_RichEdit.MoveWindow(cr);
  470. m_optionsButton.MoveWindow(cr.left, cr.bottom + theApp.m_metrics.ScaleY(2), theApp.m_metrics.ScaleX(17), theApp.m_metrics.ScaleY(17));
  471. this->Invalidate();
  472. m_DittoWindow.DoSetRegion(this);
  473. }
  474. BOOL CToolTipEx::IsCursorInToolTip()
  475. {
  476. CRect cr;
  477. GetWindowRect(cr);
  478. CPoint cursorPos;
  479. GetCursorPos(&cursorPos);
  480. return cr.PtInRect(cursorPos);
  481. }
  482. void CToolTipEx::SetRTFText(const char *pRTF)
  483. {
  484. m_RichEdit.SetRTF(pRTF);
  485. m_csRTF = pRTF;
  486. m_RichEdit.SetSel(0, 0);
  487. HighlightSearchText();
  488. }
  489. //void CToolTipEx::SetRTFText(const CString &csRTF)
  490. //{
  491. // m_RichEdit.SetRTF(csRTF);
  492. // m_csRTF = csRTF;
  493. //}
  494. void CToolTipEx::SetToolTipText(const CString &csText)
  495. {
  496. m_csText = csText;
  497. m_RichEdit.SetFont(&m_Font);
  498. m_RichEdit.SetText(csText);
  499. m_RichEdit.SetSel(0, 0);
  500. HighlightSearchText();
  501. }
  502. void CToolTipEx::HighlightSearchText()
  503. {
  504. if (m_searchText.GetLength() <= 0)
  505. return;
  506. FINDTEXTEX ft;
  507. long n = -1;
  508. ft.lpstrText = m_searchText;
  509. ft.chrg.cpMin = 0;
  510. ft.chrg.cpMax = -1;
  511. CHARFORMAT cf;
  512. cf.cbSize = sizeof(cf);
  513. cf.dwMask = CFM_COLOR;
  514. cf.dwEffects = CFE_BOLD | ~CFE_AUTOCOLOR;
  515. cf.crTextColor = RGB(255, 0, 0);
  516. do
  517. {
  518. ft.chrg.cpMin = n+1;
  519. n = m_RichEdit.FindText(FR_DOWN, &ft);
  520. if (n != -1)
  521. {
  522. m_RichEdit.SetSel(ft.chrgText);
  523. m_RichEdit.SetSelectionCharFormat(cf);
  524. }
  525. } while (n != -1);
  526. m_RichEdit.SetSel(0, 0);
  527. }
  528. void CToolTipEx::DoSearch()
  529. {
  530. if (m_searchText.GetLength() <= 0)
  531. return;
  532. FINDTEXTEX ft;
  533. long n = -1;
  534. ft.lpstrText = m_searchText;
  535. long start;
  536. long end;
  537. m_RichEdit.GetSel(start, end);
  538. ft.chrg.cpMin = end;
  539. ft.chrg.cpMax = -1;
  540. int searchDirection = FR_DOWN;
  541. if (GetKeyState(VK_SHIFT) & 0x8000)
  542. {
  543. searchDirection = 0;
  544. ft.chrg.cpMin = start;
  545. }
  546. n = m_RichEdit.FindText(searchDirection, &ft);
  547. if (n != -1)
  548. {
  549. m_RichEdit.SetSel(ft.chrgText);
  550. }
  551. else
  552. {
  553. if (searchDirection == 0)
  554. {
  555. ft.chrg.cpMin = m_RichEdit.GetTextLength();
  556. }
  557. else
  558. {
  559. ft.chrg.cpMin = 0;
  560. }
  561. ft.chrg.cpMax = -1;
  562. n = m_RichEdit.FindText(searchDirection, &ft);
  563. if (n != -1)
  564. {
  565. m_RichEdit.SetSel(ft.chrgText);
  566. }
  567. }
  568. }
  569. void CToolTipEx::OnActivate(UINT nState, CWnd *pWndOther, BOOL bMinimized)
  570. {
  571. CWnd::OnActivate(nState, pWndOther, bMinimized);
  572. if(nState == WA_INACTIVE)
  573. {
  574. Hide();
  575. if(m_pNotifyWnd)
  576. {
  577. m_pNotifyWnd->PostMessage(NM_INACTIVE_TOOLTIPWND, 0, 0);
  578. }
  579. }
  580. }
  581. void CToolTipEx::OnTimer(UINT_PTR nIDEvent)
  582. {
  583. switch(nIDEvent)
  584. {
  585. case HIDE_WINDOW_TIMER:
  586. Hide();
  587. PostMessage(WM_DESTROY, 0, 0);
  588. break;
  589. }
  590. CWnd::OnTimer(nIDEvent);
  591. }
  592. void CToolTipEx::OnNcPaint()
  593. {
  594. m_DittoWindow.DoNcPaint(this);
  595. }
  596. void CToolTipEx::OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS FAR* lpncsp)
  597. {
  598. CWnd::OnNcCalcSize(bCalcValidRects, lpncsp);
  599. m_DittoWindow.DoNcCalcSize(bCalcValidRects, lpncsp);
  600. }
  601. HITTEST_RET CToolTipEx::OnNcHitTest(CPoint point)
  602. {
  603. UINT Ret = m_DittoWindow.DoNcHitTest(this, point);
  604. if(Ret == -1)
  605. return CWnd::OnNcHitTest(point);
  606. return Ret;
  607. }
  608. void CToolTipEx::OnNcLButtonDown(UINT nHitTest, CPoint point)
  609. {
  610. m_DittoWindow.DoNcLButtonDown(this, nHitTest, point);
  611. CWnd::OnNcLButtonDown(nHitTest, point);
  612. }
  613. void CToolTipEx::OnNcLButtonUp(UINT nHitTest, CPoint point)
  614. {
  615. long lRet = m_DittoWindow.DoNcLButtonUp(this, nHitTest, point);
  616. switch(lRet)
  617. {
  618. case BUTTON_CLOSE:
  619. Hide();
  620. break;
  621. }
  622. CWnd::OnNcLButtonUp(nHitTest, point);
  623. }
  624. void CToolTipEx::OnNcMouseMove(UINT nHitTest, CPoint point)
  625. {
  626. m_DittoWindow.DoNcMouseMove(this, nHitTest, point);
  627. CWnd::OnNcMouseMove(nHitTest, point);
  628. }
  629. void CToolTipEx::OnOptions()
  630. {
  631. POINT pp;
  632. CMenu cmPopUp;
  633. CMenu *cmSubMenu = NULL;
  634. GetCursorPos(&pp);
  635. if(cmPopUp.LoadMenu(IDR_DESC_OPTIONS_MENU) != 0)
  636. {
  637. cmSubMenu = cmPopUp.GetSubMenu(0);
  638. if(!cmSubMenu)
  639. {
  640. return ;
  641. }
  642. GetCursorPos(&pp);
  643. if(CGetSetOptions::GetRememberDescPos())
  644. cmSubMenu->CheckMenuItem(ID_FIRST_REMEMBERWINDOWPOSITION, MF_CHECKED);
  645. if(CGetSetOptions::GetSizeDescWindowToContent())
  646. cmSubMenu->CheckMenuItem(ID_FIRST_SIZEWINDOWTOCONTENT, MF_CHECKED);
  647. if(CGetSetOptions::GetScaleImagesToDescWindow())
  648. cmSubMenu->CheckMenuItem(ID_FIRST_SCALEIMAGESTOFITWINDOW, MF_CHECKED);
  649. //theApp.m_Language.UpdateRightClickMenu(cmSubMenu);
  650. cmSubMenu->TrackPopupMenu(TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RIGHTBUTTON, pp.x, pp.y, this, NULL);
  651. }
  652. }
  653. void CToolTipEx::OnRememberwindowposition()
  654. {
  655. CGetSetOptions::SetRememberDescPos(!CGetSetOptions::GetRememberDescPos());
  656. }
  657. void CToolTipEx::OnSizewindowtocontent()
  658. {
  659. CGetSetOptions::SetSizeDescWindowToContent(!CGetSetOptions::GetSizeDescWindowToContent());
  660. CRect rect;
  661. this->GetWindowRect(&rect);
  662. Show(rect.TopLeft());
  663. }
  664. void CToolTipEx::OnScaleimagestofitwindow()
  665. {
  666. CGetSetOptions::SetScaleImagesToDescWindow(!CGetSetOptions::GetScaleImagesToDescWindow());
  667. Invalidate();
  668. }
  669. void CToolTipEx::OnRButtonDown(UINT nFlags, CPoint point)
  670. {
  671. OnOptions();
  672. CWnd::OnRButtonDown(nFlags, point);
  673. }
  674. void CToolTipEx::OnSetFocus(CWnd* pOldWnd)
  675. {
  676. CWnd::OnSetFocus(pOldWnd);
  677. m_RichEdit.SetFocus();
  678. }