ToolTipEx.cpp 19 KB

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