ToolTipEx.cpp 21 KB

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