OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

How to add event listener for Mouse drag event?

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
punbho
General User
General User


Joined: 24 Feb 2009
Posts: 8

PostPosted: Thu Apr 02, 2009 9:08 pm    Post subject: How to add event listener for Mouse drag event? Reply with quote

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
View user's profile Send private message
SergeM
Super User
Super User


Joined: 09 Sep 2003
Posts: 3211
Location: Troyes France

PostPosted: Fri Apr 03, 2009 9:10 am    Post subject: Reply with quote

What language what OS ?
_________________
Linux & Windows OOo3.0
UNO & C++ : WIKI
http://wiki.services.openoffice.org/wiki/Using_Cpp_with_the_OOo_SDK
In French
http://wiki.services.openoffice.org/wiki/Documentation/FR/Cpp_Guide
Back to top
View user's profile Send private message Visit poster's website
punbho
General User
General User


Joined: 24 Feb 2009
Posts: 8

PostPosted: Sat Apr 04, 2009 11:42 pm    Post subject: Reply with quote

SergeM wrote:
What language what OS ?

Language - Open office Basic
OS - Linux
Back to top
View user's profile Send private message
punbho
General User
General User


Joined: 24 Feb 2009
Posts: 8

PostPosted: Sat Apr 04, 2009 11:47 pm    Post subject: Reply with quote

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
View user's profile Send private message
ms777
Super User
Super User


Joined: 07 Feb 2004
Posts: 1355

PostPosted: Sun Apr 05, 2009 6:09 am    Post subject: Reply with quote

To add a drag listener (in OO it is XMouseMotionListener) seems not to be possible due to a OO API design flaw. See http://www.oooforum.org/forum/viewtopic.phtml?t=7270 , and http://qa.openoffice.org/issues/show_bug.cgi?id=76767

Good luck,

ms777
Back to top
View user's profile Send private message
ms777
Super User
Super User


Joined: 07 Feb 2004
Posts: 1355

PostPosted: Sun Apr 05, 2009 6:36 am    Post subject: Reply with quote

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
View user's profile Send private message
punbho
General User
General User


Joined: 24 Feb 2009
Posts: 8

PostPosted: Mon Apr 06, 2009 7:59 am    Post subject: Reply with quote

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
View user's profile Send private message
ms777
Super User
Super User


Joined: 07 Feb 2004
Posts: 1355

PostPosted: Mon Apr 06, 2009 2:14 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group