ToolTipEx.cpp 19 KB

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