Mouse motion listener

I’m trying to invoke MouseMotionListener in LO Draw, but no luck so far. Not sure if it’s even possible, but it definitely seems to be. If someone could help me out by pointing me in the right direction, I’d be very grateful. My code so far is as follows:

global listenerMouseMotionHandler as object

sub registerMouseMotionHandler()
dim oDoc as object: oDoc = thisComponent
dim oController as object: oController = oDoc.currentController
dim oComponentWindow as object: oComponentWindow = oController.componentWindow

listenerMouseMotionHandler = createUnoListener(“MouseMove_”, “com.sun.star.awt.XMouseMotionListener”)
oComponentWindow.addMouseMotionListener(listenerMouseMotionHandler)
end sub

sub unregisterMouseMotionHandler()
thisComponent.currentController.componentWindow.removeMouseMotionListener(listenerMouseMotionHandler)
end sub

function MouseMove_MouseDragged(oEvt) as boolean

end function

function MouseMove_MouseMoved(oEvt) as boolean
doSomething() ’ does not cause any response
end function

sub MouseMove_disposing(oEvt)
end sub

In my tests, sub-window 0 is always the drawing area, but, I’m not sure it always is. Python version:

import unohelper
from com.sun.star.awt import XMouseMotionListener

class EventsMouse(unohelper.Base, XMouseMotionListener):

    def mouseMoved(self, event):
        print(event.X, event.Y)
        return

    def mouseDragged(self, event):
        pass


def main():

    doc = XSCRIPTCONTEXT.getDocument()
    com_win = doc.CurrentController.Frame.ComponentWindow
    win = (com_win.AccessibleContext.getAccessibleChild(0)
            .AccessibleContext.getAccessibleChild(0)).Windows[0]
    win.addMouseMotionListener(EventsMouse())

    return

@elmau I wrote your subroutine in Basic, trying to utilize it for its Draw application, but it’s kicking me out the moment the mouse moves onto the drawing area. Which is a good sign, at least there is some sort of a reaction. But how do I look for a particular process which will work here.

I see you’re going two levels down into the subprocesses. How do you know what to look for in this case? This may be a silly question, but I’m not a professional programmer, yet very curious. :grinning:

Here is my code, based on yours:

global listenerMouseMotionHandler as object

sub registerMouseMotionHandler()
dim oDoc as object: oDoc = thisComponent
dim oController as object: oController = oDoc.currentController
dim oFrame as object: oFrame = oController.Frame
dim oComponentWindow as object: oComponentWindow = oFrame.componentWindow
dim o1 as object: o1= oComponentWindow.accessibleContext
dim o2 as object: o2 = o1.getAccessibleChild(0)
dim o3 as object: o3 = o2.accessibleContext
dim o4 as object: o4 = o3.getAccessibleChild(0)
dim o5 as object: o5 = o4.windows(0)

o5.addMouseMotionListener(listenerMouseMotionHandler)
end sub

function MouseMove_MouseDragged(oEvt) as boolean

end function

function MouseMove_MouseMoved(oEvt) as boolean
msgbox(“moved”)
end function

sub MouseMove_disposing(oEvt)
end sub

Just found my own answer:

https://bz.apache.org/ooo/show_bug.cgi?id=76767

2 Likes