ToolTipEx.cpp 38 KB

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