ToolTipEx.cpp 21 KB

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