ToolTipEx.cpp 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461
  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 "HyperLink.h"
  8. #include <Richedit.h>
  9. #ifdef _DEBUG
  10. #define new DEBUG_NEW
  11. #undef THIS_FILE
  12. static char THIS_FILE[] = __FILE__;
  13. #endif
  14. #define HIDE_WINDOW_TIMER 1
  15. #define SAVE_SIZE 2
  16. #define TIMER_BUTTON_UP 3
  17. #define TIMER_AUTO_MAX 4
  18. /////////////////////////////////////////////////////////////////////////////
  19. // CToolTipEx
  20. CToolTipEx::CToolTipEx(): m_dwTextStyle(DT_EXPANDTABS | DT_EXTERNALLEADING |
  21. DT_NOPREFIX | DT_WORDBREAK), m_rectMargin(2, 2, 3, 3),
  22. m_pNotifyWnd(NULL), m_clipId(0), m_clipRow(-1)
  23. {
  24. m_showPersistant = false;
  25. m_pToolTipActions = NULL;
  26. m_bMaxSetTimer = false;
  27. m_lDelayMaxSeconds = 2;
  28. }
  29. CToolTipEx::~CToolTipEx()
  30. {
  31. m_Font.DeleteObject();
  32. m_clipDataFont.DeleteObject();
  33. }
  34. BEGIN_MESSAGE_MAP(CToolTipEx, CWnd)
  35. //{{AFX_MSG_MAP(CToolTipEx)
  36. ON_WM_PAINT()
  37. ON_WM_SIZE()
  38. ON_WM_NCHITTEST()
  39. ON_WM_ACTIVATE()
  40. ON_WM_TIMER()
  41. ON_WM_NCLBUTTONDBLCLK()
  42. ON_WM_NCPAINT()
  43. ON_WM_NCCALCSIZE()
  44. ON_WM_NCLBUTTONDOWN()
  45. ON_WM_NCMOUSEMOVE()
  46. ON_WM_NCLBUTTONUP()
  47. ON_WM_ERASEBKGND()
  48. ON_COMMAND(ID_FIRST_REMEMBERWINDOWPOSITION, &CToolTipEx::OnRememberwindowposition)
  49. ON_COMMAND(ID_FIRST_SIZEWINDOWTOCONTENT, &CToolTipEx::OnSizewindowtocontent)
  50. ON_COMMAND(ID_FIRST_SCALEIMAGESTOFITWINDOW, &CToolTipEx::OnScaleimagestofitwindow)
  51. ON_COMMAND(2, OnOptions)
  52. ON_WM_RBUTTONDOWN()
  53. ON_WM_SETFOCUS()
  54. ON_COMMAND(ID_FIRST_HIDEDESCRIPTIONWINDOWONM, &CToolTipEx::OnFirstHidedescriptionwindowonm)
  55. ON_COMMAND(ID_FIRST_WRAPTEXT, &CToolTipEx::OnFirstWraptext)
  56. ON_WM_WINDOWPOSCHANGING()
  57. ON_COMMAND(ID_FIRST_ALWAYSONTOP, &CToolTipEx::OnFirstAlwaysontop)
  58. ON_NOTIFY(EN_MSGFILTER, 1, &CToolTipEx::OnEnMsgfilterRichedit21)
  59. ON_MESSAGE(WM_DPICHANGED, OnDpiChanged)
  60. ON_WM_MOVING()
  61. ON_WM_ENTERSIZEMOVE()
  62. ON_WM_HSCROLL()
  63. ON_MESSAGE(WM_REFRESH_FOOTER, OnRefreshFooter)
  64. END_MESSAGE_MAP()
  65. /////////////////////////////////////////////////////////////////////////////
  66. // CToolTipEx message handlers
  67. BOOL CToolTipEx::Create(CWnd *pParentWnd)
  68. {
  69. m_saveWindowLockout = true;
  70. // Get the class name and create the window
  71. CString szClassName = AfxRegisterWndClass(CS_CLASSDC | CS_SAVEBITS, LoadCursor(NULL, IDC_ARROW));
  72. // Create the window - just don't show it yet.
  73. if( !CWnd::CreateEx(0, szClassName, _T(""), WS_POPUP,
  74. 0, 0, 0, 0, pParentWnd->GetSafeHwnd(), 0, NULL))
  75. {
  76. return FALSE;
  77. }
  78. HICON b = (HICON)LoadImage(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDR_MAINFRAME), IMAGE_ICON, 64, 64, LR_SHARED);
  79. SetIcon(b, TRUE);
  80. //CString szClassName2 = AfxRegisterWndClass(CS_CLASSDC | CS_SAVEBITS, LoadCursor(NULL, IDC_ARROW));
  81. //BOOL b = m_imageViewer.Create(_T(""), szClassName2, WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL, CRect(0, 0, 0, 0), this, 3);
  82. m_imageViewer.Create(this);
  83. m_DittoWindow.DoCreate(this);
  84. m_DittoWindow.SetCaptionColors(g_Opt.m_Theme.CaptionLeft(), g_Opt.m_Theme.CaptionRight(), g_Opt.m_Theme.Border());
  85. m_DittoWindow.SetCaptionOn(this, CGetSetOptions::GetCaptionPos(), true, g_Opt.m_Theme.GetCaptionSize(), g_Opt.m_Theme.GetCaptionFontSize());
  86. m_DittoWindow.m_bDrawMaximize = false;
  87. m_DittoWindow.m_bDrawMinimize = false;
  88. m_DittoWindow.m_bDrawChevron = true;
  89. m_DittoWindow.m_sendWMClose = false;
  90. m_RichEdit.Create(_T(""), _T(""), WS_CHILD | WS_VISIBLE | WS_VSCROLL |
  91. WS_HSCROLL | ES_MULTILINE | ES_AUTOVSCROLL | ES_NOHIDESEL |
  92. ES_AUTOHSCROLL, CRect(10, 10, 100, 200), this, 1);
  93. m_RichEdit.SetReadOnly();
  94. m_RichEdit.SetBackgroundColor(FALSE, g_Opt.m_Theme.DescriptionWindowBG());
  95. m_RichEdit.SetEventMask(m_RichEdit.GetEventMask() | ENM_SELCHANGE | ENM_LINK | ENM_MOUSEEVENTS | ENM_SCROLLEVENTS);
  96. m_RichEdit.SetAutoURLDetect(TRUE);
  97. ApplyWordWrap();
  98. m_optionsButton.Create(NULL, WS_CHILD | BS_OWNERDRAW | WS_TABSTOP, CRect(0, 0, 0, 0), this, 2);
  99. m_optionsButton.LoadStdImageDPI(m_DittoWindow.m_dpi.GetDPI(), IDB_COG_16_16, IDB_COG_20_20, IDB_COG_24_24, cog_28, IDB_COG_32_32, _T("PNG"));
  100. m_optionsButton.SetToolTipText(theApp.m_Language.GetString(_T("DescriptionOptionsTooltip"), _T("Description Options")));
  101. m_optionsButton.ShowWindow(SW_SHOW);
  102. m_clipDataStatic.Create(_T("some text"), WS_CHILD | WS_VISIBLE | SS_SIMPLE, CRect(0, 0, 0, 0), this, 3);
  103. m_folderPathStatic.Create(_T("some text"), WS_CHILD | WS_VISIBLE | SS_SIMPLE, CRect(0, 0, 0, 0), this, 4);
  104. m_clipDataFont.CreateFont(-m_DittoWindow.m_dpi.Scale(11), 0, 0, 0, 400, 0, 0, 0, DEFAULT_CHARSET, 3, 2, 1, 34, _T("Segoe UI"));
  105. m_Font.CreateFont(-m_DittoWindow.m_dpi.Scale(13), 0, 0, 0, 400, 0, 0, 0, DEFAULT_CHARSET, 3, 2, 1, 34, _T("Segoe UI"));
  106. m_fontHeight = -13;
  107. m_clipDataStatic.SetFont(&m_clipDataFont);
  108. m_clipDataStatic.SetBkColor(g_Opt.m_Theme.DescriptionWindowBG());
  109. m_clipDataStatic.SetTextColor(RGB(80, 80, 80));
  110. m_folderPathStatic.SetFont(&m_clipDataFont);
  111. m_folderPathStatic.SetBkColor(g_Opt.m_Theme.DescriptionWindowBG());
  112. m_folderPathStatic.SetTextColor(RGB(80, 80, 80));
  113. m_saveWindowLockout = false;
  114. return TRUE;
  115. }
  116. BOOL CToolTipEx::Show(CPoint point)
  117. {
  118. if(m_imageViewer.m_pGdiplusBitmap)
  119. {
  120. int percent = (m_imageViewer.m_scale - 1.0) * 100.0;
  121. m_clipData = m_originalClipData + _T(" | ") + StrF(_T("%d x %d, %d%%"), m_imageViewer.m_pGdiplusBitmap->GetWidth(), m_imageViewer.m_pGdiplusBitmap->GetHeight(), percent);
  122. m_imageViewer.ShowWindow(SW_SHOW);
  123. m_RichEdit.ShowWindow(SW_HIDE);
  124. if (::IsWindow(m_browser.m_hWnd))
  125. {
  126. m_browser.ShowWindow(SW_HIDE);
  127. }
  128. }
  129. else if (m_html.GetLength() > 0)
  130. {
  131. if (::IsWindow(m_browser.m_hWnd))
  132. {
  133. m_browser.ShowWindow(SW_SHOW);
  134. }
  135. m_imageViewer.ShowWindow(SW_HIDE);
  136. m_RichEdit.ShowWindow(SW_HIDE);
  137. }
  138. else
  139. {
  140. m_RichEdit.ShowWindow(SW_SHOW);
  141. m_imageViewer.ShowWindow(SW_HIDE);
  142. if (::IsWindow(m_browser.m_hWnd))
  143. {
  144. m_browser.ShowWindow(SW_HIDE);
  145. }
  146. }
  147. CRect rect;
  148. if(CGetSetOptions::GetSizeDescWindowToContent() == FALSE)
  149. {
  150. rect.left = point.x;
  151. rect.top = point.y;
  152. CSize size;
  153. CGetSetOptions::GetDescWndSize(size);
  154. rect.right = rect.left + m_DittoWindow.m_dpi.Scale(size.cx);
  155. rect.bottom = rect.top + m_DittoWindow.m_dpi.Scale(size.cy);
  156. EnsureWindowVisible(&rect);
  157. }
  158. else
  159. {
  160. rect = GetBoundsRect();
  161. //account for the scroll bars
  162. rect.right += 20;
  163. rect.bottom += 20;
  164. if (m_imageViewer.m_pGdiplusBitmap)
  165. {
  166. int nWidth = m_imageViewer.m_pGdiplusBitmap->GetWidth() + ::GetSystemMetrics(SM_CXVSCROLL);
  167. int nHeight = m_imageViewer.m_pGdiplusBitmap->GetHeight() + ::GetSystemMetrics(SM_CYHSCROLL);
  168. rect.right = rect.left + nWidth;
  169. rect.bottom = rect.top + nHeight;
  170. }
  171. else if(m_csRTF != "")
  172. {
  173. //if showing rtf then increase the size because
  174. //rtf will probably draw bigger
  175. long lNewWidth = (long)rect.Width() + (long)(rect.Width() *1.5);
  176. rect.right = rect.left + lNewWidth;
  177. long lNewHeight = (long)rect.Height() + (long)(rect.Height() *1.5);
  178. rect.bottom = rect.top + lNewHeight;
  179. }
  180. //rect.right += CAPTION_BORDER * 2;
  181. //rect.bottom += CAPTION_BORDER * 2;
  182. ClientToScreen(rect);
  183. CRect cr(point, point);
  184. CRect rcScreen = MonitorRectFromRect(cr);
  185. //ensure that we don't go outside the screen
  186. if(point.x < 0)
  187. {
  188. point.x = 5;
  189. //m_reducedWindowSize = true;
  190. }
  191. if(point.y < 0)
  192. {
  193. point.y = 5;
  194. //m_reducedWindowSize = true;
  195. }
  196. rcScreen.DeflateRect(0, 0, 5, 5);
  197. long lWidth = rect.Width();
  198. long lHeight = rect.Height();
  199. rect.left = point.x;
  200. rect.top = point.y;
  201. rect.right = rect.left + lWidth;
  202. rect.bottom = rect.top + lHeight;
  203. if (rect.right > rcScreen.right)
  204. {
  205. rect.right = rcScreen.right;
  206. //m_reducedWindowSize = true;
  207. }
  208. if (rect.bottom > rcScreen.bottom)
  209. {
  210. rect.bottom = rcScreen.bottom;
  211. //m_reducedWindowSize = true;
  212. }
  213. }
  214. m_clipDataStatic.SetWindowText(m_clipData);
  215. m_folderPathStatic.SetWindowText(m_folderPath);
  216. if (m_DittoWindow.m_bMinimized)
  217. {
  218. //m_DittoWindow.MinMaxWindow(this, FORCE_MAX);
  219. m_DittoWindow.m_bMinimized = false;
  220. }
  221. m_saveWindowLockout = true;
  222. MoveWindow(rect);
  223. MoveControls();
  224. if (m_imageViewer.m_pGdiplusBitmap)
  225. {
  226. m_imageViewer.UpdateBitmapSize(true);
  227. }
  228. ShowWindow(SW_SHOWNA);
  229. //this->Invalidate();
  230. //this->UpdateWindow();
  231. m_saveWindowLockout = false;
  232. return TRUE;
  233. }
  234. void CToolTipEx::GetWindowRectEx(LPRECT lpRect)
  235. {
  236. if (m_DittoWindow.m_bMinimized)
  237. {
  238. *lpRect = m_DittoWindow.m_crFullSizeWindow;
  239. return;
  240. }
  241. CWnd::GetWindowRect(lpRect);
  242. }
  243. BOOL CToolTipEx::Hide()
  244. {
  245. delete m_imageViewer.m_pGdiplusBitmap;
  246. m_imageViewer.m_pGdiplusBitmap = NULL;
  247. SaveWindowSize();
  248. ShowWindow(SW_HIDE);
  249. if (m_browser.m_hWnd != NULL &&
  250. ::IsWindow(m_browser.m_hWnd))
  251. {
  252. m_browser.DestroyWindow();
  253. }
  254. m_csRTF = "";
  255. m_csText = "";
  256. m_html = "";
  257. m_clipId = 0;
  258. m_clipRow = -1;
  259. m_searchText = _T("");
  260. m_showPersistant = false;
  261. return TRUE;
  262. }
  263. void CToolTipEx::OnNcLButtonDblClk(UINT nHitTest, CPoint point)
  264. {
  265. // toggle ShowPersistent when we double click the caption
  266. if (nHitTest == HTCAPTION)
  267. {
  268. OnFirstAlwaysontop();
  269. }
  270. CWnd::OnNcLButtonDblClk(nHitTest, point);
  271. }
  272. void CToolTipEx::SaveWindowSize()
  273. {
  274. if (::IsWindowVisible(m_hWnd))
  275. {
  276. CRect rect;
  277. if (m_DittoWindow.m_bMinimized)
  278. {
  279. rect = m_DittoWindow.m_crFullSizeWindow;
  280. }
  281. else
  282. {
  283. this->GetWindowRect(&rect);
  284. }
  285. CSize s = rect.Size();
  286. CGetSetOptions::SetDescWndSize(CSize(m_DittoWindow.m_dpi.UnScale(s.cx), m_DittoWindow.m_dpi.UnScale(s.cy)));
  287. CGetSetOptions::SetDescWndPoint(rect.TopLeft());
  288. OutputDebugString(_T("Saving tooltip size"));
  289. }
  290. }
  291. void CToolTipEx::PostNcDestroy()
  292. {
  293. CWnd::PostNcDestroy();
  294. delete this;
  295. }
  296. BOOL CToolTipEx::PreTranslateMessage(MSG *pMsg)
  297. {
  298. m_DittoWindow.DoPreTranslateMessage(pMsg);
  299. switch (pMsg->message)
  300. {
  301. case WM_KEYDOWN:
  302. switch(pMsg->wParam)
  303. {
  304. case 'C':
  305. if(GetKeyState(VK_CONTROL) &0x8000)
  306. {
  307. m_RichEdit.Copy();
  308. return TRUE;
  309. }
  310. break;
  311. }
  312. break;
  313. case WM_RBUTTONDOWN:
  314. {
  315. auto f = GetFocus();
  316. if (f != NULL &&
  317. (m_RichEdit.m_hWnd == f->m_hWnd ||
  318. m_imageViewer.m_hWnd == f->m_hWnd))
  319. {
  320. OnOptions();
  321. return TRUE;
  322. }
  323. }
  324. break;
  325. case WM_LBUTTONUP:
  326. auto f = GetFocus();
  327. if (f != NULL &&
  328. m_RichEdit.m_hWnd != f->m_hWnd &&
  329. m_optionsButton.m_hWnd != f->m_hWnd)
  330. {
  331. auto p = GetParent();
  332. if (p != NULL)
  333. {
  334. p->SetFocus();
  335. }
  336. }
  337. break;
  338. }
  339. if (m_pToolTipActions != NULL)
  340. {
  341. CAccel a;
  342. if (m_pToolTipActions->OnMsg(pMsg, a))
  343. {
  344. switch (a.Cmd)
  345. {
  346. case ActionEnums::CLOSEWINDOW:
  347. /*if (this->m_showPersistant &&
  348. m_DittoWindow.m_bMinimized == false)
  349. {
  350. m_DittoWindow.MinMaxWindow(this, FORCE_MIN);
  351. theApp.m_activeWnd.ReleaseFocus();
  352. return TRUE;
  353. }*/
  354. break;
  355. }
  356. }
  357. }
  358. return CWnd::PreTranslateMessage(pMsg);
  359. }
  360. BOOL CToolTipEx::OnMsg(MSG *pMsg)
  361. {
  362. if(FALSE == IsWindowVisible())
  363. {
  364. return FALSE;
  365. }
  366. switch(pMsg->message)
  367. {
  368. case WM_WINDOWPOSCHANGING:
  369. case WM_LBUTTONDOWN:
  370. {
  371. if (m_showPersistant == false)
  372. {
  373. if (CGetSetOptions::GetMouseClickHidesDescription())
  374. {
  375. if (!IsCursorInToolTip())
  376. {
  377. Hide();
  378. }
  379. }
  380. }
  381. }
  382. break;
  383. case WM_KEYDOWN:
  384. {
  385. WPARAM vk = pMsg->wParam;
  386. if(vk == 'C')
  387. {
  388. if (GetKeyState(VK_CONTROL) & 0x8000)
  389. {
  390. if (::IsWindow(m_browser.m_hWnd))
  391. {
  392. m_browser.Copy();
  393. return TRUE;
  394. }
  395. }
  396. }
  397. if(vk == VK_TAB)
  398. {
  399. m_RichEdit.SetFocus();
  400. return TRUE;
  401. }
  402. else if (vk == VK_CONTROL || vk == VK_SHIFT)
  403. {
  404. return FALSE;
  405. }
  406. else if (vk == VK_UP)
  407. {
  408. return FALSE;
  409. }
  410. else if (vk == VK_DOWN)
  411. {
  412. return FALSE;
  413. }
  414. else if (vk == VK_NEXT)
  415. {
  416. return FALSE;
  417. }
  418. else if (vk == VK_PRIOR)
  419. {
  420. return FALSE;
  421. }
  422. else if (vk == VK_DELETE)
  423. {
  424. return FALSE;
  425. }
  426. if (m_pToolTipActions != NULL)
  427. {
  428. if (m_pToolTipActions->ContainsKey((int)vk))
  429. {
  430. return FALSE;
  431. }
  432. }
  433. if (m_showPersistant == false)
  434. {
  435. Hide();
  436. }
  437. break;
  438. }
  439. case WM_LBUTTONDBLCLK:
  440. case WM_RBUTTONDBLCLK:
  441. case WM_MBUTTONDOWN:
  442. case WM_MBUTTONDBLCLK:
  443. case WM_NCLBUTTONDOWN:
  444. case WM_NCLBUTTONDBLCLK:
  445. case WM_NCRBUTTONDOWN:
  446. case WM_NCRBUTTONDBLCLK:
  447. case WM_NCMBUTTONDOWN:
  448. case WM_NCMBUTTONDBLCLK:
  449. {
  450. if (m_showPersistant == false)
  451. {
  452. Hide();
  453. }
  454. break;
  455. }
  456. case WM_MOUSEWHEEL:
  457. case WM_MOUSEHWHEEL:
  458. {
  459. if (m_imageViewer.m_pGdiplusBitmap)
  460. {
  461. m_imageViewer.PostMessageW(pMsg->message, pMsg->wParam, pMsg->lParam);
  462. return TRUE;
  463. }
  464. else
  465. {
  466. m_RichEdit.PostMessageW(pMsg->message, pMsg->wParam, pMsg->lParam);
  467. return TRUE;
  468. }
  469. }
  470. break;
  471. }
  472. return FALSE;
  473. }
  474. CRect CToolTipEx::GetBoundsRect()
  475. {
  476. DWORD d = GetTickCount();
  477. CWindowDC dc(NULL);
  478. int nLineWidth = 0;
  479. CRect rect(0, 0, 0, 0);
  480. if(nLineWidth == 0)
  481. {
  482. // Count the number of lines of text
  483. int nStart = 0;
  484. INT nNumLines = 0;
  485. int longestLength = 0;
  486. CString longestString;
  487. do
  488. {
  489. nNumLines++;
  490. int newStart = m_csText.Find(_T("\n"), nStart);
  491. if (newStart < 0)
  492. {
  493. int length = m_csText.GetLength() - nStart;
  494. if (length > longestLength)
  495. {
  496. longestString = m_csText.Mid(nStart, length);
  497. longestLength = length;
  498. }
  499. break;
  500. }
  501. int length = newStart - nStart;
  502. if(length > longestLength)
  503. {
  504. longestString = m_csText.Mid(nStart, length);
  505. longestLength = length;
  506. }
  507. nStart = newStart + 1;
  508. }
  509. while(nStart >= 0 && nNumLines < 100);
  510. CFont *pOldFont = (CFont*)dc.SelectObject((CFont*)&m_Font);
  511. CSize size = dc.GetTextExtent(longestString);
  512. dc.SelectObject(pOldFont);
  513. rect.right = size.cx;
  514. rect.bottom = size.cy * nNumLines;
  515. }
  516. rect.bottom += m_rectMargin.top + m_rectMargin.bottom + GetSystemMetrics(SM_CYVSCROLL);
  517. rect.right += m_rectMargin.left + m_rectMargin.right + GetSystemMetrics(SM_CXVSCROLL);
  518. if(m_imageViewer.m_pGdiplusBitmap)
  519. {
  520. int nWidth = m_imageViewer.m_pGdiplusBitmap->GetWidth();
  521. int nHeight = m_imageViewer.m_pGdiplusBitmap->GetHeight();
  522. rect.bottom += nHeight;
  523. if((rect.left + nWidth) > rect.right)
  524. {
  525. rect.right = rect.left + nWidth;
  526. }
  527. }
  528. DWORD diff = GetTickCount() - d;
  529. if (diff > 10)
  530. {
  531. Log(StrF(_T("Size To Content: %d\n"), diff));
  532. }
  533. return rect;
  534. }
  535. CString CToolTipEx::GetFieldFromString(CString ref, int nIndex, TCHAR ch)
  536. {
  537. CString strReturn;
  538. LPCTSTR pstrStart = ref.LockBuffer();
  539. LPCTSTR pstrBuffer = pstrStart;
  540. int nCurrent = 0;
  541. int nStart = 0;
  542. int nEnd = 0;
  543. int nOldStart = 0;
  544. while(nCurrent <= nIndex && *pstrBuffer != _T('\0'))
  545. {
  546. if(*pstrBuffer == ch)
  547. {
  548. nOldStart = nStart;
  549. nStart = nEnd + 1;
  550. nCurrent++;
  551. }
  552. nEnd++;
  553. pstrBuffer++;
  554. }
  555. // May have reached the end of the string
  556. if(*pstrBuffer == _T('\0'))
  557. {
  558. nOldStart = nStart;
  559. nEnd++;
  560. }
  561. ref.UnlockBuffer();
  562. if(nCurrent < nIndex)
  563. {
  564. //TRACE1("Warning: GetStringField - Couldn't find field %d.\n", nIndex);
  565. return strReturn;
  566. }
  567. return ref.Mid(nOldStart, nEnd - nOldStart - 1);
  568. }
  569. BOOL CToolTipEx::SetLogFont(LPLOGFONT lpLogFont, BOOL bRedraw /*=TRUE*/)
  570. {
  571. ASSERT(lpLogFont);
  572. if(!lpLogFont)
  573. {
  574. return FALSE;
  575. }
  576. LOGFONT LogFont;
  577. // Store font as the global default
  578. memcpy(&LogFont, lpLogFont, sizeof(LOGFONT));
  579. m_fontHeight = lpLogFont->lfHeight;
  580. LogFont.lfHeight = m_DittoWindow.m_dpi.Scale(LogFont.lfHeight);
  581. // Create the actual font object
  582. m_Font.DeleteObject();
  583. m_Font.CreateFontIndirect(&LogFont);
  584. if(bRedraw && ::IsWindow(GetSafeHwnd()))
  585. {
  586. Invalidate();
  587. }
  588. return TRUE;
  589. }
  590. void CToolTipEx::SetGdiplusBitmap(Gdiplus::Bitmap *gdiplusBitmap)
  591. {
  592. delete m_imageViewer.m_pGdiplusBitmap;
  593. m_imageViewer.m_pGdiplusBitmap = NULL;
  594. m_imageViewer.m_pGdiplusBitmap = gdiplusBitmap;
  595. m_imageViewer.UpdateBitmapSize(true);
  596. Invalidate();
  597. }
  598. void CToolTipEx::OnSize(UINT nType, int cx, int cy)
  599. {
  600. CWnd::OnSize(nType, cx, cy);
  601. if(::IsWindow(m_RichEdit.GetSafeHwnd()) == FALSE)
  602. {
  603. return ;
  604. }
  605. MoveControls();
  606. }
  607. void CToolTipEx::MoveControls()
  608. {
  609. CRect cr;
  610. GetClientRect(cr);
  611. int bottom = m_DittoWindow.m_dpi.Scale(22);
  612. int optionsExtra = 0;
  613. if (m_folderPath != _T(""))
  614. {
  615. bottom += m_DittoWindow.m_dpi.Scale(17);
  616. optionsExtra += m_DittoWindow.m_dpi.Scale(10);
  617. m_folderPathStatic.ShowWindow(SW_SHOW);
  618. }
  619. else
  620. {
  621. m_folderPathStatic.ShowWindow(SW_HIDE);
  622. }
  623. cr.DeflateRect(0, 0, 0, bottom);
  624. m_RichEdit.MoveWindow(cr);
  625. m_imageViewer.MoveWindow(cr);
  626. if (::IsWindow(m_browser.m_hWnd))
  627. {
  628. m_browser.MoveWindow(cr);
  629. }
  630. m_optionsButton.MoveWindow(cr.left, cr.bottom + m_DittoWindow.m_dpi.Scale(3) + optionsExtra, m_DittoWindow.m_dpi.Scale(17), m_DittoWindow.m_dpi.Scale(17));
  631. m_clipDataStatic.MoveWindow(cr.left + m_DittoWindow.m_dpi.Scale(19), cr.bottom + m_DittoWindow.m_dpi.Scale(4), cr.Width() - cr.left + m_DittoWindow.m_dpi.Scale(19), m_DittoWindow.m_dpi.Scale(20));
  632. m_folderPathStatic.MoveWindow(cr.left + m_DittoWindow.m_dpi.Scale(19), cr.bottom + m_DittoWindow.m_dpi.Scale(20), cr.Width() - cr.left + m_DittoWindow.m_dpi.Scale(19), m_DittoWindow.m_dpi.Scale(20));
  633. this->Invalidate();
  634. if (m_saveWindowLockout == false)
  635. {
  636. SetTimer(SAVE_SIZE, 250, NULL);
  637. }
  638. }
  639. BOOL CToolTipEx::IsCursorInToolTip()
  640. {
  641. CRect cr;
  642. GetWindowRect(cr);
  643. CPoint cursorPos;
  644. GetCursorPos(&cursorPos);
  645. return cr.PtInRect(cursorPos);
  646. }
  647. void CToolTipEx::SetHtmlText(const CString &html)
  648. {
  649. if (html.GetLength() > 0 &&
  650. ::IsWindow(m_browser.m_hWnd) == FALSE)
  651. {
  652. m_browser.Create(WS_CHILD | WS_VISIBLE, CRect(10, 10, 100, 200), this, 2);
  653. }
  654. if (::IsWindow(m_browser.m_hWnd))
  655. {
  656. int pos = html.Find(_T("<html"));
  657. if (pos >= 0)
  658. {
  659. m_html = html.Mid(pos);
  660. }
  661. else
  662. {
  663. int pos = html.Find(_T("<HTML"));
  664. if (pos >= 0)
  665. {
  666. m_html = html.Mid(pos);
  667. }
  668. else
  669. {
  670. m_html = html;
  671. }
  672. }
  673. COLORREF c = g_Opt.m_Theme.DescriptionWindowBG();
  674. DWORD dwR = GetRValue(c);
  675. DWORD dwG = GetGValue(c);
  676. DWORD dwB = GetBValue(c);
  677. CString colorHex;
  678. colorHex.Format(_T("#%02X%02X%02X"), dwR, dwG, dwB);
  679. m_html.Replace(_T("<body>"), StrF(_T("<body bgcolor=\"%s\">"), colorHex));
  680. m_browser.PutSilent(true);
  681. m_browser.Clear();
  682. m_browser.Write(m_html);
  683. }
  684. }
  685. void CToolTipEx::SetRTFText(const CStringA &rtf)
  686. {
  687. m_RichEdit.SetRTF(rtf);
  688. m_csRTF = rtf;
  689. m_RichEdit.SetSel(0, 0);
  690. HighlightSearchText();
  691. }
  692. //void CToolTipEx::SetRTFText(const CString &csRTF)
  693. //{
  694. // m_RichEdit.SetRTF(csRTF);
  695. // m_csRTF = csRTF;
  696. //}
  697. void CToolTipEx::SetToolTipText(const CString &csText)
  698. {
  699. m_csText = csText;
  700. m_RichEdit.SetFont(&m_Font);
  701. m_RichEdit.SetText(csText);
  702. m_RichEdit.SetSel(0, 0);
  703. CHARFORMAT cfNew;
  704. cfNew.cbSize = sizeof(CHARFORMAT);
  705. cfNew.dwMask = CFM_COLOR;
  706. cfNew.dwEffects = CFM_COLOR;
  707. cfNew.dwEffects &= ~CFE_AUTOCOLOR;
  708. cfNew.crTextColor = g_Opt.m_Theme.DescriptionWindowText();
  709. m_RichEdit.SetDefaultCharFormat(cfNew);
  710. HighlightSearchText();
  711. }
  712. void CToolTipEx::HighlightSearchText()
  713. {
  714. if (m_searchText.GetLength() <= 0)
  715. return;
  716. FINDTEXTEX ft;
  717. long n = -1;
  718. ft.lpstrText = m_searchText;
  719. ft.chrg.cpMin = 0;
  720. ft.chrg.cpMax = -1;
  721. CHARFORMAT cf;
  722. cf.cbSize = sizeof(cf);
  723. cf.dwMask = CFM_COLOR;
  724. cf.dwEffects = CFE_BOLD | ~CFE_AUTOCOLOR;
  725. cf.crTextColor = RGB(255, 0, 0);
  726. m_RichEdit.SetRedraw(0);
  727. auto mask = m_RichEdit.GetEventMask();
  728. m_RichEdit.SetEventMask(0);
  729. do
  730. {
  731. ft.chrg.cpMin = n+1;
  732. n = m_RichEdit.FindText(FR_DOWN, &ft);
  733. if (n != -1)
  734. {
  735. m_RichEdit.SetSel(ft.chrgText);
  736. m_RichEdit.SetSelectionCharFormat(cf);
  737. }
  738. } while (n != -1);
  739. m_RichEdit.SetSel(0, 0);
  740. m_RichEdit.SetEventMask(mask);
  741. m_RichEdit.SetRedraw(1);
  742. m_RichEdit.UpdateWindow();
  743. }
  744. void CToolTipEx::DoSearch()
  745. {
  746. if (m_searchText.GetLength() <= 0)
  747. return;
  748. FINDTEXTEX ft;
  749. long n = -1;
  750. ft.lpstrText = m_searchText;
  751. long start;
  752. long end;
  753. m_RichEdit.GetSel(start, end);
  754. ft.chrg.cpMin = end;
  755. ft.chrg.cpMax = -1;
  756. int searchDirection = FR_DOWN;
  757. if (GetKeyState(VK_SHIFT) & 0x8000)
  758. {
  759. searchDirection = 0;
  760. ft.chrg.cpMin = start;
  761. }
  762. n = m_RichEdit.FindText(searchDirection, &ft);
  763. if (n != -1)
  764. {
  765. m_RichEdit.SetSel(ft.chrgText);
  766. }
  767. else
  768. {
  769. if (searchDirection == 0)
  770. {
  771. ft.chrg.cpMin = m_RichEdit.GetTextLength();
  772. }
  773. else
  774. {
  775. ft.chrg.cpMin = 0;
  776. }
  777. ft.chrg.cpMax = -1;
  778. n = m_RichEdit.FindText(searchDirection, &ft);
  779. if (n != -1)
  780. {
  781. m_RichEdit.SetSel(ft.chrgText);
  782. }
  783. }
  784. }
  785. void CToolTipEx::OnActivate(UINT nState, CWnd *pWndOther, BOOL bMinimized)
  786. {
  787. CWnd::OnActivate(nState, pWndOther, bMinimized);
  788. if (nState == WA_INACTIVE)
  789. {
  790. if(m_pNotifyWnd)
  791. {
  792. m_pNotifyWnd->PostMessage(NM_INACTIVE_TOOLTIPWND, 0, 0);
  793. }
  794. }
  795. }
  796. void CToolTipEx::OnTimer(UINT_PTR nIDEvent)
  797. {
  798. switch(nIDEvent)
  799. {
  800. case HIDE_WINDOW_TIMER:
  801. Hide();
  802. PostMessage(WM_DESTROY, 0, 0);
  803. break;
  804. case SAVE_SIZE:
  805. SaveWindowSize();
  806. KillTimer(SAVE_SIZE);
  807. break;
  808. case TIMER_BUTTON_UP:
  809. {
  810. if ((GetKeyState(VK_LBUTTON) & 0x100) == 0)
  811. {
  812. m_DittoWindow.DoNcLButtonUp(this, 0, CPoint(0, 0));
  813. KillTimer(TIMER_BUTTON_UP);
  814. auto f = GetFocus();
  815. if (f != NULL &&
  816. m_RichEdit.m_hWnd != f->m_hWnd)
  817. {
  818. auto p = GetParent();
  819. if (p != NULL)
  820. {
  821. p->SetFocus();
  822. }
  823. }
  824. }
  825. break;
  826. }
  827. case TIMER_AUTO_MAX:
  828. {
  829. if (m_DittoWindow.m_bMinimized)
  830. {
  831. CPoint cp;
  832. GetCursorPos(&cp);
  833. UINT nHitTest = (UINT)OnNcHitTest(cp);
  834. ScreenToClient(&cp);
  835. if (nHitTest == HTCAPTION)
  836. {
  837. if (m_DittoWindow.m_crCloseBT.PtInRect(cp) == false)
  838. {
  839. if (m_DittoWindow.m_crMinimizeBT.PtInRect(cp) == false)
  840. {
  841. m_DittoWindow.MinMaxWindow(this, FORCE_MAX);
  842. }
  843. }
  844. }
  845. }
  846. KillTimer(TIMER_AUTO_MAX);
  847. m_bMaxSetTimer = false;
  848. }
  849. }
  850. CWnd::OnTimer(nIDEvent);
  851. }
  852. void CToolTipEx::OnNcPaint()
  853. {
  854. m_DittoWindow.DoNcPaint(this);
  855. }
  856. void CToolTipEx::OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS FAR* lpncsp)
  857. {
  858. CWnd::OnNcCalcSize(bCalcValidRects, lpncsp);
  859. m_DittoWindow.DoNcCalcSize(bCalcValidRects, lpncsp);
  860. }
  861. HITTEST_RET CToolTipEx::OnNcHitTest(CPoint point)
  862. {
  863. UINT Ret = m_DittoWindow.DoNcHitTest(this, point);
  864. if(Ret == -1)
  865. return CWnd::OnNcHitTest(point);
  866. return Ret;
  867. }
  868. void CToolTipEx::OnNcLButtonDown(UINT nHitTest, CPoint point)
  869. {
  870. int buttonPressed = m_DittoWindow.DoNcLButtonDown(this, nHitTest, point);
  871. SetTimer(TIMER_BUTTON_UP, 100, NULL);
  872. CWnd::OnNcLButtonDown(nHitTest, point);
  873. }
  874. void CToolTipEx::OnNcLButtonUp(UINT nHitTest, CPoint point)
  875. {
  876. long lRet = m_DittoWindow.DoNcLButtonUp(this, nHitTest, point);
  877. switch(lRet)
  878. {
  879. case BUTTON_CLOSE:
  880. Hide();
  881. break;
  882. case BUTTON_CHEVRON:
  883. m_DittoWindow.MinMaxWindow(this, SWAP_MIN_MAX);
  884. OnNcPaint();
  885. break;
  886. }
  887. KillTimer(TIMER_BUTTON_UP);
  888. auto f = GetFocus();
  889. if (f != NULL &&
  890. m_RichEdit.m_hWnd != f->m_hWnd)
  891. {
  892. auto p = GetParent();
  893. if (p != NULL)
  894. {
  895. p->SetFocus();
  896. }
  897. }
  898. CWnd::OnNcLButtonUp(nHitTest, point);
  899. }
  900. void CToolTipEx::OnNcMouseMove(UINT nHitTest, CPoint point)
  901. {
  902. m_DittoWindow.DoNcMouseMove(this, nHitTest, point);
  903. if ((m_bMaxSetTimer == false) && m_DittoWindow.m_bMinimized)
  904. {
  905. COleDateTimeSpan sp = COleDateTime::GetCurrentTime() - m_DittoWindow.m_TimeMinimized;
  906. if (sp.GetTotalSeconds() >= m_lDelayMaxSeconds)
  907. {
  908. SetTimer(TIMER_AUTO_MAX, CGetSetOptions::GetTimeBeforeExpandWindow(), NULL);
  909. m_bMaxSetTimer = true;
  910. }
  911. }
  912. CWnd::OnNcMouseMove(nHitTest, point);
  913. }
  914. void CToolTipEx::OnOptions()
  915. {
  916. POINT pp;
  917. CMenu cmPopUp;
  918. CMenu *cmSubMenu = NULL;
  919. GetCursorPos(&pp);
  920. if(cmPopUp.LoadMenu(IDR_DESC_OPTIONS_MENU) != 0)
  921. {
  922. cmSubMenu = cmPopUp.GetSubMenu(0);
  923. if(!cmSubMenu)
  924. {
  925. return ;
  926. }
  927. GetCursorPos(&pp);
  928. //theApp.m_Language.UpdateRightClickMenu(cmSubMenu);
  929. if(CGetSetOptions::GetRememberDescPos())
  930. cmSubMenu->CheckMenuItem(ID_FIRST_REMEMBERWINDOWPOSITION, MF_CHECKED);
  931. if(CGetSetOptions::GetSizeDescWindowToContent())
  932. cmSubMenu->CheckMenuItem(ID_FIRST_SIZEWINDOWTOCONTENT, MF_CHECKED);
  933. if(CGetSetOptions::GetScaleImagesToDescWindow())
  934. cmSubMenu->CheckMenuItem(ID_FIRST_SCALEIMAGESTOFITWINDOW, MF_CHECKED);
  935. if (CGetSetOptions::GetMouseClickHidesDescription())
  936. cmSubMenu->CheckMenuItem(ID_FIRST_HIDEDESCRIPTIONWINDOWONM, MF_CHECKED);
  937. if (CGetSetOptions::GetWrapDescriptionText())
  938. cmSubMenu->CheckMenuItem(ID_FIRST_WRAPTEXT, MF_CHECKED);
  939. if (m_showPersistant)
  940. cmSubMenu->CheckMenuItem(ID_FIRST_ALWAYSONTOP, MF_CHECKED);
  941. UpdateMenuShortCut(cmSubMenu, ID_FIRST_WRAPTEXT, ActionEnums::TOGGLE_DESCRIPTION_WORD_WRAP);
  942. UpdateMenuShortCut(cmSubMenu, ID_FIRST_ALWAYSONTOP, ActionEnums::TOGGLESHOWPERSISTANT);
  943. cmSubMenu->TrackPopupMenu(TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RIGHTBUTTON, pp.x, pp.y, this, NULL);
  944. }
  945. }
  946. void CToolTipEx::UpdateMenuShortCut(CMenu *subMenu, int id, DWORD action)
  947. {
  948. if (m_pToolTipActions != NULL)
  949. {
  950. CString cs;
  951. subMenu->GetMenuString(id, cs, MF_BYCOMMAND);
  952. CString shortcutText = m_pToolTipActions->GetCmdKeyText(action);
  953. if (shortcutText != _T("") &&
  954. cs.Find("\t" + shortcutText) < 0)
  955. {
  956. cs += "\t";
  957. cs += shortcutText;
  958. subMenu->ModifyMenu(id, MF_BYCOMMAND, id, cs);
  959. }
  960. }
  961. }
  962. void CToolTipEx::OnRememberwindowposition()
  963. {
  964. CGetSetOptions::SetRememberDescPos(!CGetSetOptions::GetRememberDescPos());
  965. }
  966. void CToolTipEx::OnSizewindowtocontent()
  967. {
  968. CGetSetOptions::SetSizeDescWindowToContent(!CGetSetOptions::GetSizeDescWindowToContent());
  969. CRect rect;
  970. this->GetWindowRect(&rect);
  971. Show(rect.TopLeft());
  972. }
  973. void CToolTipEx::OnScaleimagestofitwindow()
  974. {
  975. CGetSetOptions::SetScaleImagesToDescWindow(!CGetSetOptions::GetScaleImagesToDescWindow());
  976. m_imageViewer.UpdateBitmapSize(true);
  977. Invalidate();
  978. }
  979. void CToolTipEx::OnRButtonDown(UINT nFlags, CPoint point)
  980. {
  981. OnOptions();
  982. CWnd::OnRButtonDown(nFlags, point);
  983. }
  984. void CToolTipEx::OnSetFocus(CWnd* pOldWnd)
  985. {
  986. CWnd::OnSetFocus(pOldWnd);
  987. if (m_RichEdit.IsWindowVisible())
  988. {
  989. m_RichEdit.SetFocus();
  990. }
  991. }
  992. void CToolTipEx::OnPaint()
  993. {
  994. CPaintDC dc(this); // device context for painting
  995. CRect rect;
  996. GetClientRect(rect);
  997. CBrush Brush, *pOldBrush;
  998. Brush.CreateSolidBrush(g_Opt.m_Theme.DescriptionWindowBG());
  999. pOldBrush = dc.SelectObject(&Brush);
  1000. dc.FillRect(&rect, &Brush);
  1001. // Cleanup
  1002. dc.SelectObject(pOldBrush);
  1003. }
  1004. void CToolTipEx::OnFirstHidedescriptionwindowonm()
  1005. {
  1006. CGetSetOptions::SetMouseClickHidesDescription(!CGetSetOptions::GetMouseClickHidesDescription());
  1007. }
  1008. bool CToolTipEx::ToggleWordWrap()
  1009. {
  1010. bool didWordWrap = false;
  1011. if (m_RichEdit.IsWindowVisible())
  1012. {
  1013. OnFirstWraptext();
  1014. didWordWrap = true;
  1015. }
  1016. return didWordWrap;
  1017. }
  1018. void CToolTipEx::OnFirstWraptext()
  1019. {
  1020. CGetSetOptions::SetWrapDescriptionText(!CGetSetOptions::GetWrapDescriptionText());
  1021. ApplyWordWrap();
  1022. }
  1023. void CToolTipEx::ApplyWordWrap()
  1024. {
  1025. if (CGetSetOptions::GetWrapDescriptionText())
  1026. {
  1027. m_RichEdit.SetTargetDevice(NULL, 0);
  1028. }
  1029. else
  1030. {
  1031. m_RichEdit.SetTargetDevice(NULL, 1);
  1032. }
  1033. }
  1034. void CToolTipEx::HideWindowInXMilliSeconds(long lms)
  1035. {
  1036. SetTimer(HIDE_WINDOW_TIMER, lms, NULL);
  1037. }
  1038. void CToolTipEx::OnWindowPosChanging(WINDOWPOS* lpwndpos)
  1039. {
  1040. CWnd::OnWindowPosChanging(lpwndpos);
  1041. //m_DittoWindow.SnapToEdge(this, lpwndpos);
  1042. }
  1043. void CToolTipEx::OnFirstAlwaysontop()
  1044. {
  1045. m_showPersistant = !m_showPersistant;
  1046. if (m_showPersistant)
  1047. {
  1048. m_DittoWindow.m_customWindowTitle = _T("[Always on top]");
  1049. m_DittoWindow.m_useCustomWindowTitle = true;
  1050. ::SetWindowPos(m_hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_SHOWWINDOW | SWP_NOACTIVATE);
  1051. }
  1052. else
  1053. {
  1054. m_DittoWindow.m_customWindowTitle = _T("");
  1055. m_DittoWindow.m_useCustomWindowTitle = true;
  1056. }
  1057. ::SetWindowPos(m_hWnd, NULL, 0, 0, 0, 0, SWP_DRAWFRAME | SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
  1058. }
  1059. BOOL CToolTipEx::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
  1060. {
  1061. CString cs;
  1062. cs.Format(_T("On Notify: %d\r\n"), ((LPNMHDR)lParam)->code);
  1063. OutputDebugString(cs);
  1064. switch (((LPNMHDR)lParam)->code)
  1065. {
  1066. case EN_LINK:
  1067. {
  1068. ENLINK *enLinkInfo = (ENLINK *)lParam; // pointer to a ENLINK structure
  1069. if (enLinkInfo->msg == WM_LBUTTONUP)
  1070. {
  1071. CString s;
  1072. m_RichEdit.GetTextRange(enLinkInfo->chrg.cpMin, enLinkInfo->chrg.cpMax, s);
  1073. if (s == m_mouseDownOnLink)
  1074. {
  1075. CHyperLink::GotoURL(s, SW_SHOW);
  1076. }
  1077. m_mouseDownOnLink = _T("");
  1078. }
  1079. if (enLinkInfo->msg == WM_LBUTTONDOWN)
  1080. {
  1081. m_RichEdit.GetTextRange(enLinkInfo->chrg.cpMin, enLinkInfo->chrg.cpMax, m_mouseDownOnLink);
  1082. }
  1083. }
  1084. break;
  1085. case SimpleBrowser::NotificationType::BeforeNavigate2:
  1086. {
  1087. SimpleBrowser::Notification * not = (SimpleBrowser::Notification *)lParam;
  1088. if (not != NULL)
  1089. {
  1090. if (not->URL.Find(_T("http")) >= 0)
  1091. {
  1092. CHyperLink::GotoURL(not->URL, SW_SHOW);
  1093. *pResult = TRUE;
  1094. //return TRUE;
  1095. }
  1096. }
  1097. }
  1098. break;
  1099. case 5:
  1100. int x = 0;
  1101. break;
  1102. }
  1103. return CWnd::OnNotify(wParam, lParam, pResult);
  1104. }
  1105. void CToolTipEx::OnEnMsgfilterRichedit21(NMHDR *pNMHDR, LRESULT *pResult)
  1106. {
  1107. MSGFILTER *pMsgFilter = reinterpret_cast<MSGFILTER *>(pNMHDR);
  1108. if (pMsgFilter != NULL)
  1109. {
  1110. switch (pMsgFilter->msg)
  1111. {
  1112. //handle click on the rich text control when it doesn't have focus
  1113. //set focus so the first click is handled by the rich text control
  1114. case WM_MOUSEACTIVATE:
  1115. m_RichEdit.SetFocus();
  1116. break;
  1117. case WM_MOUSEHWHEEL:
  1118. int delta = GET_WHEEL_DELTA_WPARAM(pMsgFilter->wParam);
  1119. if (delta < 0)
  1120. {
  1121. m_RichEdit.SendMessage(WM_HSCROLL, SB_LINERIGHT, NULL);
  1122. }
  1123. else
  1124. {
  1125. m_RichEdit.SendMessage(WM_HSCROLL, SB_LINELEFT, NULL);
  1126. }
  1127. break;
  1128. }
  1129. }
  1130. *pResult = 0;
  1131. }
  1132. LRESULT CToolTipEx::OnDpiChanged(WPARAM wParam, LPARAM lParam)
  1133. {
  1134. int dpi = HIWORD(wParam);
  1135. m_DittoWindow.OnDpiChanged(this, dpi);
  1136. RECT* const prcNewWindow = (RECT*)lParam;
  1137. SetWindowPos(NULL,
  1138. prcNewWindow->left,
  1139. prcNewWindow->top,
  1140. prcNewWindow->right - prcNewWindow->left,
  1141. prcNewWindow->bottom - prcNewWindow->top,
  1142. SWP_NOZORDER | SWP_NOACTIVATE);
  1143. log(StrF(_T("CQPasteWnd::OnDpiChanged dpi: %d width: %d, height: %d"), dpi, (prcNewWindow->right - prcNewWindow->left), (prcNewWindow->bottom - prcNewWindow->top)));
  1144. m_optionsButton.Reset();
  1145. m_optionsButton.LoadStdImageDPI(m_DittoWindow.m_dpi.GetDPI(), IDB_COG_16_16, IDB_COG_20_20, IDB_COG_24_24, cog_28, IDB_COG_32_32, _T("PNG"));
  1146. m_clipDataFont.Detach();
  1147. m_clipDataFont.CreateFont(-m_DittoWindow.m_dpi.Scale(8), 0, 0, 0, 400, 0, 0, 0, DEFAULT_CHARSET, 3, 2, 1, 34, _T("Segoe UI"));
  1148. m_clipDataStatic.SetFont(&m_clipDataFont);
  1149. m_clipDataStatic.SetBkColor(g_Opt.m_Theme.DescriptionWindowBG());
  1150. m_clipDataStatic.SetTextColor(RGB(80, 80, 80));
  1151. m_folderPathStatic.SetFont(&m_clipDataFont);
  1152. m_folderPathStatic.SetBkColor(g_Opt.m_Theme.DescriptionWindowBG());
  1153. m_folderPathStatic.SetTextColor(RGB(80, 80, 80));
  1154. LOGFONT lf;
  1155. m_Font.GetLogFont(&lf);
  1156. lf.lfHeight = m_DittoWindow.m_dpi.Scale(m_fontHeight);
  1157. // Create the actual font object
  1158. m_Font.DeleteObject();
  1159. m_Font.CreateFontIndirect(&lf);
  1160. m_RichEdit.SetFont(&m_Font);
  1161. this->MoveControls();
  1162. this->Invalidate();
  1163. this->UpdateWindow();
  1164. return TRUE;
  1165. }
  1166. void CToolTipEx::OnMoving(UINT fwSide, LPRECT pRect)
  1167. {
  1168. CWnd::OnMoving(fwSide, pRect);
  1169. m_snap.OnSnapMoving(m_hWnd, pRect);
  1170. // TODO: Add your message handler code here
  1171. }
  1172. void CToolTipEx::OnEnterSizeMove()
  1173. {
  1174. m_snap.OnSnapEnterSizeMove(m_hWnd);
  1175. CWnd::OnEnterSizeMove();
  1176. }
  1177. void CToolTipEx::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
  1178. {
  1179. int x = 9;
  1180. //m_scrollHelper.OnHScroll(nSBCode, nPos, pScrollBar);
  1181. }
  1182. LRESULT CToolTipEx::OnRefreshFooter(WPARAM wParam, LPARAM lParam)
  1183. {
  1184. m_clipData = m_originalClipData;
  1185. if (m_imageViewer.m_pGdiplusBitmap)
  1186. {
  1187. int percent = ((m_imageViewer.m_scale) * 100.0) + .5;
  1188. m_clipData = m_originalClipData + _T(" | ") + StrF(_T("%d x %d, %d%%"), m_imageViewer.m_pGdiplusBitmap->GetWidth(), m_imageViewer.m_pGdiplusBitmap->GetHeight(), percent);
  1189. }
  1190. m_clipDataStatic.SetWindowText(m_clipData);
  1191. m_clipDataStatic.Invalidate();
  1192. this->Invalidate();
  1193. return TRUE;
  1194. }