Apply XMouseMotionHandler to the sheet

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
tagetes
Posts: 4
Joined: Wed Mar 13, 2013 6:29 am

Apply XMouseMotionHandler to the sheet

Post by tagetes »

Good day.
I want to prohibit the use drag & drop tool on a sheet of Calc. I think “:: com :: sun :: star :: awt :: XMouseMotionHandler“ is suitable for this. But I don't know how to take advantage of. Help apply XMouseMotionHandler to the sheet . Fix my code.

Code: Select all

Global oDocView_m As Object
Global oMouseMotionHandler As Object

Sub RegisterMouseMotionHandler
     oDocView_m = ThisComponent.CurrentController.Frame.ContainerWindow
     oMouseMotionHandler = createUnoListener("MyApp_", "com.sun.star.awt.XMouseMotionHandler")
     oDocView_m.addMouseMotionListener(oMouseMotionHandler)
     msgbox "RegisterMouseMotionHandler!"
End Sub

Sub UnregisterMouseMotionHandler
     on error resume next
     oDocView_m.removeMouseMotionListener(oMouseMotionHandler)
     on error goto 0
End Sub

Function MyApp_mouseDragged(oEvt) As Boolean
     msgbox "mouseDragged!"
     MyApp_mouseDragged = False
End Function

Function MyApp_mouseMoved(oEvt) As Boolean
     msgbox "mouseMoved!"
     MyApp_mouseMoved = False
End Function
Why don't I see the message "mouseDragged!" and "mouseMoved!" ?
OpenOffice 2.3 / OpenOffice 3.0 / OpenOffice 3.2 on Win 7 / Win XP / Win 98
mcmurchy1917
Posts: 23
Joined: Fri Feb 22, 2013 2:15 pm

Re: Apply XMouseMotionHandler to the sheet

Post by mcmurchy1917 »

Try this

Global oDocView_m As Object
Global oMouseMotionHandler As Object

Sub RegisterMouseMotionHandler

oDocView_m = ThisComponent.CurrentController.Frame.ComponentWindow
oMouseMotionHandler = createUnoListener("MyApp_", "com.sun.star.awt.XMouseMotionListener")
msgbox "RegisterMouseMotionHandler!"

addremoveMouseMotionListenerRecursively(true, oMouseMotionHandler, oDocView_m)

End Sub

Sub UnregisterMouseMotionHandler
on error resume next
addremoveMouseMotionListenerRecursively(false, oMouseMotionHandler, oDocView_m)
on error goto 0
End Sub

Function MyApp_mouseDragged(oEvt) As Boolean
msgbox "mouseDragged!"
MyApp_mouseDragged = False
End Function

Function MyApp_mouseMoved(oEvt) As Boolean
msgbox "mouseMoved!"
MyApp_mouseMoved = False
End Function


sub addremoveMouseMotionListenerRecursively( bAdd as Boolean, oMouseMotionListener as object, oWin as object)

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
Slackware user
Post Reply