| View previous topic :: View next topic |
| Author |
Message |
punbho General User

Joined: 24 Feb 2009 Posts: 8
|
Posted: Thu Apr 02, 2009 9:08 pm Post subject: How to add event listener for Mouse drag event? |
|
|
I want to add mouse drag event listener in Draw or Impress. Can anyone tell me how to do that?
I am able to add MouseClickHandler but I am not able to figure out how to add Mouse drag event handler. |
|
| Back to top |
|
 |
SergeM Super User

Joined: 09 Sep 2003 Posts: 3211 Location: Troyes France
|
|
| Back to top |
|
 |
punbho General User

Joined: 24 Feb 2009 Posts: 8
|
Posted: Sat Apr 04, 2009 11:42 pm Post subject: |
|
|
| SergeM wrote: | | What language what OS ? |
Language - Open office Basic
OS - Linux |
|
| Back to top |
|
 |
punbho General User

Joined: 24 Feb 2009 Posts: 8
|
Posted: Sat Apr 04, 2009 11:47 pm Post subject: |
|
|
What I want is to implement a functionality similar to drawing a freeform line. When drawing a freeform line, a person drag a mouse to draw a freeform drawing. So for doing this, what I want is to handle the mouse drag event, and to find the coordinates of the points on which mouse is dragged and form a line passing through those points.
Please help me regarding this. |
|
| Back to top |
|
 |
ms777 Super User


Joined: 07 Feb 2004 Posts: 1355
|
|
| Back to top |
|
 |
ms777 Super User


Joined: 07 Feb 2004 Posts: 1355
|
Posted: Sun Apr 05, 2009 6:36 am Post subject: |
|
|
| ms777 wrote: | | To add a drag listener (in OO it is XMouseMotionListener) seems not to be possible due to a OO API design flaw... |
Ooops ... that seemed to be a little too quick: Put the following code into a draw doc and play around ...
Tested on XPSP3 with OO 2.4
Good luck,
ms777
| Code: | Global oSheetOutMML as Any
Global kRowSheetOutMML as Long
Global kLevelMML as Long
Sub Main
oCompWin = ThisComponent.CurrentController.Frame.ComponentWindow
oScrollPane = oCompWin.AccessibleContext.getAccessibleChild(0).AccessibleContext.getAccessibleChild(0)
oDoc = StarDesktop.LoadComponentFromUrl("private:factory/scalc","_default",0,Array())
oSheetOutMML = oDoc.sheets.getByIndex(0)
kRowSheetOutMML = 0
kLevelMML = 0
oMML = createUnoListener("MML_", "com.sun.star.awt.XMouseMotionListener")
addremoveMouseMotionListenerRecursively(true, oMML, oScrollPane)
wait(10000)
addremoveMouseMotionListenerRecursively(false, oMML, oScrollPane)
End Sub
sub MML_mouseDragged(e as com.sun.star.awt.MouseEvent)
if kLevelMML>0 then exit sub '
kLevelMML = kLevelMML + 1
logEvent("mouseDragged", e)
kLevelMML = kLevelMML - 1
end sub
sub MML_mouseMoved(e as com.sun.star.awt.MouseEvent)
end sub
sub MML_disposing( Source as com.sun.star.lang.EventObject)
end sub
sub logEvent(sText as String, e as com.sun.star.awt.MouseEvent)
oSheetOutMML.getCellByPosition(0, kRowSheetOutMML).String = sText
oSheetOutMML.getCellByPosition(1, kRowSheetOutMML).Value = e.X
oSheetOutMML.getCellByPosition(2, kRowSheetOutMML).Value = e.Y
oSheetOutMML.getCellByPosition(3, kRowSheetOutMML).Value = kLevelMML
kRowSheetOutMML = kRowSheetOutMML + 1
end sub
sub addremoveMouseMotionListenerRecursively( bAdd as Boolean, oMouseMotionListener as Any, oWin as Any)
if bAdd then
oWin.addMouseMotionListener(oMouseMotionListener)
else
oWin.removeMouseMotionListener(oMouseMotionListener)
endif
if HasUnoInterfaces(oWin, "com.sun.star.awt.XVclContainer") then
oWindows = oWin.Windows
for k=0 to UBound(oWindows)
call addremoveMouseMotionListenerRecursively( bAdd, oMouseMotionListener, oWindows(k))
next k
endif
end sub |
|
|
| Back to top |
|
 |
punbho General User

Joined: 24 Feb 2009 Posts: 8
|
Posted: Mon Apr 06, 2009 7:59 am Post subject: |
|
|
Hi ms777
Thanks for the code.
Can you explain to me some parts of the code like
| Code: | | oScrollPane = oCompWin.AccessibleContext.getAccessibleChild(0).AccessibleContext.getAccessibleChild(0) |
and the function
| Code: | | addremoveMouseMotionRecursively |
because i am not sure as to what the above mentioned code is doing.
Another question is can we do similar thing in the writer document? But the above code is only working is Draw or impress document. Is there a way to handle MouseMotion in writer? |
|
| Back to top |
|
 |
ms777 Super User


Joined: 07 Feb 2004 Posts: 1355
|
Posted: Mon Apr 06, 2009 2:14 pm Post subject: |
|
|
| punbho wrote: | Can you explain to me some parts of the code like
| Code: | | oScrollPane = oCompWin.AccessibleContext.getAccessibleChild(0).AccessibleContext.getAccessibleChild(0) |
... | See e.g. http://www.oooforum.org/forum/viewtopic.phtml?t=22845 , and browse the API doc for XAccessible and related interfaces
| punbho wrote: | Can you explain to me some parts of the code like
... | Code: | | addremoveMouseMotionRecursively |
| No - the subroutine titel says all
| punbho wrote: | | Another question is can we do similar thing in the writer document? ... Is there a way to handle MouseMotion in writer? | Yes, it should also work in writer. Writer has a different window structure, so you have to use sub AnalyzeCreateSxc from the above link to find out where to install the MouseMotionListener. The oScrollPane = ... line has to be modified.
Good luck,
ms777 |
|
| Back to top |
|
 |
|