1
0

UpdateToolTip.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * UpdateToolTip.cpp
  3. * -----------------
  4. * Purpose: Implementation of the update tooltip in the main toolbar.
  5. * Notes : (currently none)
  6. * Authors: OpenMPT Devs
  7. * The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
  8. */
  9. #include "stdafx.h"
  10. #include "Mptrack.h"
  11. #include "Mainfrm.h"
  12. OPENMPT_NAMESPACE_BEGIN
  13. BEGIN_MESSAGE_MAP(UpdateToolTip, CToolTipCtrl)
  14. ON_WM_LBUTTONUP()
  15. ON_NOTIFY_REFLECT(TTN_POP, &UpdateToolTip::OnPop)
  16. ON_NOTIFY_REFLECT(TTN_SHOW, &UpdateToolTip::OnShow)
  17. ON_NOTIFY_REFLECT(TTN_LINKCLICK, &UpdateToolTip::OnLinkClick)
  18. END_MESSAGE_MAP()
  19. bool UpdateToolTip::ShowUpdate(CWnd &parent, const CString &newVersion, const CString &infoURL, const CRect rectClient, const CPoint ptScreen, const int buttonID)
  20. {
  21. if(m_hWnd)
  22. DestroyWindow();
  23. Create(&parent, TTS_NOPREFIX | TTS_BALLOON | TTS_CLOSE | TTS_NOFADE);
  24. m_infoURL = infoURL;
  25. CString message = MPT_CFORMAT("OpenMPT {} has been released.\n<a>Click here to see what's new.</a>")(newVersion);
  26. TOOLINFO ti{};
  27. ti.cbSize = TTTOOLINFO_V1_SIZE;
  28. ti.uFlags = TTF_TRACK | TTF_PARSELINKS;
  29. ti.hwnd = parent;
  30. ti.lpszText = message.GetBuffer();
  31. ti.uId = buttonID;
  32. ti.rect = rectClient;
  33. if(!SendMessage(TTM_ADDTOOL, 0, reinterpret_cast<LPARAM>(&ti)))
  34. return false;
  35. SetTitle(TTI_INFO, _T("Update Available"));
  36. SendMessage(TTM_TRACKPOSITION, 0, static_cast<LPARAM>(MAKELONG(ptScreen.x, ptScreen.y)));
  37. SendMessage(TTM_TRACKACTIVATE, TRUE, reinterpret_cast<LPARAM>(&ti));
  38. return true;
  39. }
  40. void UpdateToolTip::SetResult(PopAction action)
  41. {
  42. m_popAction = action;
  43. SendMessage(TTM_TRACKACTIVATE, FALSE, 0);
  44. if(action != PopAction::CloseButton)
  45. CMainFrame::GetMainFrame()->SendMessage(WM_MOD_UPDATENOTIFY, static_cast<WPARAM>(action));
  46. }
  47. void UpdateToolTip::OnLButtonUp(UINT nFlags, CPoint point)
  48. {
  49. CToolTipCtrl::OnLButtonUp(nFlags, point);
  50. if(m_popAction == PopAction::Undetermined)
  51. SetResult(PopAction::ClickBubble);
  52. }
  53. void UpdateToolTip::OnPop(NMHDR *pNMHDR, LRESULT *)
  54. {
  55. if(pNMHDR->idFrom == UINT_PTR(-1))
  56. SetResult(PopAction::CloseButton);
  57. }
  58. void UpdateToolTip::OnShow(NMHDR *, LRESULT *)
  59. {
  60. m_popAction = PopAction::Undetermined;
  61. }
  62. void UpdateToolTip::OnLinkClick(NMHDR *, LRESULT *)
  63. {
  64. CTrackApp::OpenURL(m_infoURL);
  65. SetResult(PopAction::ClickLink);
  66. }
  67. OPENMPT_NAMESPACE_END