Mouse event handle for composed widget

Moderators: LCMark, LCfraser

Post Reply
Marken
Posts: 6
Joined: Thu Apr 10, 2014 3:34 am

Mouse event handle for composed widget

Post by Marken » Tue Aug 16, 2016 6:33 am

i wrote a composed widget which was placed a svgPath widget.
But the svgPath widget post mouseDown message with a string argument.

Code: Select all

post "mouseDown" with [the click button formatted as string]
Now I need to handle mouseDown message when use click on my widget. The problem is that the onMouseDown handlers have different signature.
for handling message from my own widget the handler must

Code: Select all

 public handler OnMouseDown(/* args */) returns nothing 
for handling message from child widget(svgPath) the handler must

Code: Select all

 public handler OnMouseDown(in pClickButton as String) returns nothing 
I can't have two OnMouseDown handler in one LCB. Have any idea?

Whole my test widget is below:

Code: Select all

widget com.livecode.marken.scriptdemo5
use com.livecode.engine
use com.livecode.canvas
use com.livecode.widget
use com.livecode.library.widgetutils

metadata title is "Script Demo5"
metadata author is "Marken"
metadata version is "1.0.0"
metadata preferredSize is "200,200"

private variable mInsideShape as Widget

public handler OnPaint()
  variable tPath as Path
	put rectangle path of my bounds into tPath
  paintBorder(tPath)
end handler

private handler paintBorder(in pPath as Path)
	set the stroke width of this canvas to 1
	set the dashes of this canvas to [10, 10]
	set the paint of this canvas to my border paint
	stroke pPath on this canvas
end handler

public handler OnCreate() returns nothing
	-- inside shape
	put a new widget "com.livecode.widget.svgpath" into mInsideShape
  set annotation "Name" of mInsideShape to "MyShape"
	set the rectangle of mInsideShape to rectangle [0,0,100,100]
	place mInsideShape
end handler


public handler OnMouseDown(/* args */) returns nothing
  log "Parent Widget Mouse Down"
end handler


public handler OnMouseDown(in pClickButton as String) returns nothing
  log "SVGPath Widget Mouse Down"
end handler

end widget

livecodeali
Livecode Staff Member
Livecode Staff Member
Posts: 119
Joined: Thu Apr 18, 2013 2:48 pm

Re: Mouse event handle for composed widget

Post by livecodeali » Tue Aug 16, 2016 1:38 pm

Hi Marken,
It is something of a tricky situation as the reason the SVG path widget posts that parameter is so that the mouseUp handler of the widget's script object has the click button parameter, whereas we don't pass that in LiveCode Builder since it is accessible through the click button syntax. As far as I can tell there is no easy way around this, except perhaps to copy the code for the SVG path widget and create your own widget with the posted parameter removed.

Once we have the events sorted out properly, I believe the idea will be for parent widgets to be able to attach child widget signals to arbitrary handlers.

Post Reply

Return to “LiveCode Builder”