From 20d28e80a5c861a9d5f449ea911ab75b4f37ad0d Mon Sep 17 00:00:00 2001 From: Jef Date: Tue, 24 Sep 2024 14:54:57 +0200 Subject: Initial community commit --- .../openmpt-trunk/mptrack/UpdateToolTip.cpp | 90 ++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 Src/external_dependencies/openmpt-trunk/mptrack/UpdateToolTip.cpp (limited to 'Src/external_dependencies/openmpt-trunk/mptrack/UpdateToolTip.cpp') diff --git a/Src/external_dependencies/openmpt-trunk/mptrack/UpdateToolTip.cpp b/Src/external_dependencies/openmpt-trunk/mptrack/UpdateToolTip.cpp new file mode 100644 index 00000000..2045f40e --- /dev/null +++ b/Src/external_dependencies/openmpt-trunk/mptrack/UpdateToolTip.cpp @@ -0,0 +1,90 @@ +/* + * UpdateToolTip.cpp + * ----------------- + * Purpose: Implementation of the update tooltip in the main toolbar. + * Notes : (currently none) + * Authors: OpenMPT Devs + * The OpenMPT source code is released under the BSD license. Read LICENSE for more details. + */ + + +#include "stdafx.h" +#include "Mptrack.h" +#include "Mainfrm.h" + + +OPENMPT_NAMESPACE_BEGIN + + +BEGIN_MESSAGE_MAP(UpdateToolTip, CToolTipCtrl) + ON_WM_LBUTTONUP() + ON_NOTIFY_REFLECT(TTN_POP, &UpdateToolTip::OnPop) + ON_NOTIFY_REFLECT(TTN_SHOW, &UpdateToolTip::OnShow) + ON_NOTIFY_REFLECT(TTN_LINKCLICK, &UpdateToolTip::OnLinkClick) +END_MESSAGE_MAP() + + +bool UpdateToolTip::ShowUpdate(CWnd &parent, const CString &newVersion, const CString &infoURL, const CRect rectClient, const CPoint ptScreen, const int buttonID) +{ + if(m_hWnd) + DestroyWindow(); + Create(&parent, TTS_NOPREFIX | TTS_BALLOON | TTS_CLOSE | TTS_NOFADE); + + m_infoURL = infoURL; + + CString message = MPT_CFORMAT("OpenMPT {} has been released.\nClick here to see what's new.")(newVersion); + TOOLINFO ti{}; + ti.cbSize = TTTOOLINFO_V1_SIZE; + ti.uFlags = TTF_TRACK | TTF_PARSELINKS; + ti.hwnd = parent; + ti.lpszText = message.GetBuffer(); + ti.uId = buttonID; + ti.rect = rectClient; + if(!SendMessage(TTM_ADDTOOL, 0, reinterpret_cast(&ti))) + return false; + + SetTitle(TTI_INFO, _T("Update Available")); + SendMessage(TTM_TRACKPOSITION, 0, static_cast(MAKELONG(ptScreen.x, ptScreen.y))); + SendMessage(TTM_TRACKACTIVATE, TRUE, reinterpret_cast(&ti)); + return true; +} + + +void UpdateToolTip::SetResult(PopAction action) +{ + m_popAction = action; + SendMessage(TTM_TRACKACTIVATE, FALSE, 0); + if(action != PopAction::CloseButton) + CMainFrame::GetMainFrame()->SendMessage(WM_MOD_UPDATENOTIFY, static_cast(action)); +} + + +void UpdateToolTip::OnLButtonUp(UINT nFlags, CPoint point) +{ + CToolTipCtrl::OnLButtonUp(nFlags, point); + if(m_popAction == PopAction::Undetermined) + SetResult(PopAction::ClickBubble); +} + + +void UpdateToolTip::OnPop(NMHDR *pNMHDR, LRESULT *) +{ + if(pNMHDR->idFrom == UINT_PTR(-1)) + SetResult(PopAction::CloseButton); +} + + +void UpdateToolTip::OnShow(NMHDR *, LRESULT *) +{ + m_popAction = PopAction::Undetermined; +} + + +void UpdateToolTip::OnLinkClick(NMHDR *, LRESULT *) +{ + CTrackApp::OpenURL(m_infoURL); + SetResult(PopAction::ClickLink); +} + + +OPENMPT_NAMESPACE_END -- cgit