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