Markup/XAML: Does anybody know how to hook the Mou |
Post Reply |
Author | |
rvoith
Groupie Joined: 03 July 2003 Location: Norway Status: Offline Points: 40 |
Post Options
Thanks(0)
Posted: 26 November 2021 at 6:53am |
Has anybody hooked the mouse-button events? I see that Markup's XTPMarkupInputElement.h contain the following events static CXTPMarkupRoutedEvent* m_pMouseLeaveEvent; static CXTPMarkupRoutedEvent* m_pMouseEnterEvent; static CXTPMarkupRoutedEvent* m_pMouseLeftButtonUpEvent; static CXTPMarkupRoutedEvent* m_pMouseLeftButtonDownEvent; static CXTPMarkupRoutedEvent* m_pMouseRightButtonUpEvent; static CXTPMarkupRoutedEvent* m_pMouseRightButtonDownEvent; static CXTPMarkupRoutedEvent* m_pMouseMoveEvent; static CXTPMarkupRoutedEvent* m_pLostMouseCaptureEvent; I also see that the MarkupPad-sample contain handlers for the Markup tags like MouseEnter and MouseLeave in found DynamicMarkup.xaml. The markup looks like this in DynamicMarkup.xaml: <Border Grid.Column="4" Background="Magenta"><TextBlock MouseEnter="SetText1" MouseLeave="SetText2" Padding="4" Text="Column 5"/></Border> Note the "SetText1" and "SetText2". Further, in the MarkupPad-samples CMarkupPadView::CMarkupPadView(), you find the connection between the markup's SetText1 and SetText2 like: SetDelegate(L"SetText1", CreateMarkupClassDelegate(this, &CMarkupPadView::OnSetText1)); SetDelegate(L"SetText2", CreateMarkupClassDelegate(this, &CMarkupPadView::OnSetText2)); This allows MarkupPad's own implementation to hook into the Markup tag's *attribute values* of SetText1 and SetText2. Below you see the handler for SetText1: void CMarkupPadView::OnSetText1(CXTPMarkupObject* pSender, CXTPMarkupMouseEventArgs* /*pArgs*/) { ((CXTPMarkupTextBlock*)pSender)->SetText(L"New Text"); } The only challenge with this approach, is that the SetText1 now can be used in many Markup tag' attribute value, like for example: <Border Grid.Column="4" Background="Magenta"><TextBlock MouseRightButtonUp="SetText1" MouseLeftButtonUp="SetText2" Padding="4" Text="Column 5"/></Border> I would rather like to have a generic hook into the MouseLeft/RightButtonUp, and then for example check the Markup-tag's Tag-attribute. Has anybody done something along these lines? |
|
Best regards,
Bob Proud Programmer! |
|
cpede
Senior Member Joined: 13 August 2004 Location: Denmark Status: Offline Points: 668 |
Post Options
Thanks(0)
|
Maybe you can do something like this:
|
|
Product: Xtreme ToolkitPro (24.0.0)
Platform: Windows 10 (x64) Language: Visual Studio 2017 (C++) |
|
rvoith
Groupie Joined: 03 July 2003 Location: Norway Status: Offline Points: 40 |
Post Options
Thanks(0)
|
@cpede, thanks for answering!
Yes, that is along the lines I plan to check for the current tag, when my handler is called. However, my current main-challenge is to be able to set up the handler for the mouse-events at large. I imagine that I have to AddHandler or SetDelegate in my class somehow. My current class is based on CXTPMarkupStatic (which has a CXTPMarkupContext-member), and thus I imagined that I could use something like this in the constructor: GetMarkupContext()->AddHandler(CXTPMarkupInputElement::m_pMouseRightButtonUpEvent, CreateMarkupClassDelegate(this, &CMyStaticControl::OnMouseRightButtonUp)); This is in the hope that any right-click in my control, would trigger my handler (where I next-up can check the tag and do stuff along your lines). I imagine this would be similar to how the CMarkupPadView's constructor sets up the handler for the CXTPMarkupHyperlink::m_pClickEvent, like this; AddHandler(CXTPMarkupHyperlink::m_pClickEvent, CreateMarkupClassDelegate(this, &CMarkupPadView::OnHyperlinkClick)); |
|
Best regards,
Bob Proud Programmer! |
|
cpede
Senior Member Joined: 13 August 2004 Location: Denmark Status: Offline Points: 668 |
Post Options
Thanks(0)
|
OK I see.
What about standard MFC code and a HitTest, like this:
|
|
Product: Xtreme ToolkitPro (24.0.0)
Platform: Windows 10 (x64) Language: Visual Studio 2017 (C++) |
|
rvoith
Groupie Joined: 03 July 2003 Location: Norway Status: Offline Points: 40 |
Post Options
Thanks(0)
|
That is a great tip, which I might need to resolve to.
In CXTPMarkupContext's HandleMouseUpDown() something similar seem to be happening. The message == WM_RBUTTONUP is handled and an "routed event" seems to be triggered. Below you see the top of the method: BOOL CXTPMarkupContext::HandleMouseUpDown(UINT message, WPARAM /*wParam*/, LPARAM lParam) { CXTPMarkupInputElement* pMouseOver = m_pMouseOver; if (m_pMouseCapture) pMouseOver = m_pMouseCapture; if (!pMouseOver) return FALSE; CInputElementCollection listNewMouseOver; BuildInputList(pMouseOver, &listNewMouseOver); CXTPMarkupMouseButtonEventArgs* eMouseButtonEventArgs = new CXTPMarkupMouseButtonEventArgs( message == WM_LBUTTONDOWN || message == WM_LBUTTONDBLCLK ? CXTPMarkupInputElement::m_pMouseLeftButtonDownEvent : message == WM_LBUTTONUP ? CXTPMarkupInputElement::m_pMouseLeftButtonUpEvent : message == WM_RBUTTONDOWN ? CXTPMarkupInputElement::m_pMouseRightButtonDownEvent : message == WM_RBUTTONUP ? CXTPMarkupInputElement::m_pMouseRightButtonUpEvent : NULL); I was hoping that some of the CodeJock-samples could shred some light on how to use these mouse handllers in code. However, your tips might be the hack to get around this :-) |
|
Best regards,
Bob Proud Programmer! |
|
Post Reply | |
Tweet
|
Forum Jump | Forum Permissions You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |