ToolTipEx.cpp 25 KB

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