Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Toolkit Pro
  New Posts New Posts RSS Feed - Markup/XAML: Does anybody know how to hook the Mou
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Markup/XAML: Does anybody know how to hook the Mou

 Post Reply Post Reply
Author
Message
rvoith View Drop Down
Groupie
Groupie
Avatar

Joined: 03 July 2003
Location: Norway
Status: Offline
Points: 40
Post Options Post Options   Thanks (0) Thanks(0)   Quote rvoith Quote  Post ReplyReply Direct Link To This Post Topic: Markup/XAML: Does anybody know how to hook the Mou
    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!
Back to Top
cpede View Drop Down
Senior Member
Senior Member


Joined: 13 August 2004
Location: Denmark
Status: Offline
Points: 645
Post Options Post Options   Thanks (0) Thanks(0)   Quote cpede Quote  Post ReplyReply Direct Link To This Post Posted: 29 November 2021 at 6:26am
Maybe you can do something like this:

CXTPMarkupString* pTag = MARKUP_STATICCAST(CXTPMarkupString, (CXTPMarkupHyperlink*)pSender)->GetTag());

CString sTag(*pTag);
if (sTag.Compare(_T("Tag1"))==0) //do smomething
else if (sTag.Compare(_T("Tag2"))==0) //do smomething
else if (sTag.Compare(_T("Tag3"))==0) //do smomething

pArgs->SetHandled();
Product: Xtreme ToolkitPro (20.3.0)
Platform: Windows 10 (x64)
Language: Visual Studio 2017 (C++)
Back to Top
rvoith View Drop Down
Groupie
Groupie
Avatar

Joined: 03 July 2003
Location: Norway
Status: Offline
Points: 40
Post Options Post Options   Thanks (0) Thanks(0)   Quote rvoith Quote  Post ReplyReply Direct Link To This Post Posted: 29 November 2021 at 7:39am
@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!
Back to Top
cpede View Drop Down
Senior Member
Senior Member


Joined: 13 August 2004
Location: Denmark
Status: Offline
Points: 645
Post Options Post Options   Thanks (0) Thanks(0)   Quote cpede Quote  Post ReplyReply Direct Link To This Post Posted: 29 November 2021 at 8:03am
OK I see.

What about standard MFC code and a HitTest, like this:

BEGIN_MESSAGE_MAP(CMyMarkup, CXTPMarkupStatic)
ON_WM_RBUTTONDOWN()
END_MESSAGE_MAP()


void CMyMarkup::OnRButtonDown(UINT nFlags, CPoint point)
{
CXTPMarkupInputElement* pObject = m_pUIElement->InputHitTest(point);
CString sTag = ((CXTPMarkupObject*)pObject)->GetTagName();

__super::OnRButtonDown(nFlags, point);
}

Product: Xtreme ToolkitPro (20.3.0)
Platform: Windows 10 (x64)
Language: Visual Studio 2017 (C++)
Back to Top
rvoith View Drop Down
Groupie
Groupie
Avatar

Joined: 03 July 2003
Location: Norway
Status: Offline
Points: 40
Post Options Post Options   Thanks (0) Thanks(0)   Quote rvoith Quote  Post ReplyReply Direct Link To This Post Posted: 29 November 2021 at 8:21am
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!
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.156 seconds.