Apache OpenOffice (AOO) Bugzilla – Issue 76767
Mouse motion listener is never called for Draw frames
Last modified: 2017-05-20 11:31:30 UTC
a component that extend XMouseMotionListener register itself at a window but its methods mouseMoved and mouseDragged are never called.
jsc -> cd: one for the awt owner
Created attachment 44948 [details] component to test the mouse motion listener
The testcomp.zip is an extension for OO.o 2.2 to test MouseMotionListener, KeyHandler, MouseClickHandler. The two last listener work but not the former. The extension is written in python.
cd: I am sorry but it works for me. Please look at the following Basic example which uses the mouse motion listener interface. It works without any problem on my system OpenOffice.org 2.2. Sub Main Dim oWindowProps as new com.sun.star.awt.WindowDescriptor Dim aRectangle as new com.sun.star.awt.Rectangle oToolkit = createUnoService( "com.sun.star.awt.Toolkit" ) oDesktop = createUnoService( "com.sun.star.frame.Desktop" ) oListener = createUnoListener( "on_", "com.sun.star.awt.XMouseMotionListener" ) oFrame = oDesktop.getCurrentFrame() aRectangle.X = 100 aRectangle.Y = 100 aRectangle.Width = 300 aRectangle.Height = 200 oWindowProps.Type = WINDOW_SIMPLE oWindowProps.WindowServiceName = "window" oWindowProps.Parent = oFrame.getContainerWindow() oWindowProps.ParentIndex = -1 oWindowProps.Bounds = aRectangle oWindowProps.WindowAttributes = com.sun.star.awt.WindowAttribute.SHOW + com.sun.star.awt.WindowAttribute.BORDER oWindow = oToolkit.createWindow( oWindowProps ) oWindow.addMouseMotionListener( oListener ) End Sub Sub on_mouseDragged( oEvent ) msgbox "mouseDragged" End Sub Sub on_mouseMoved( oEvent ) msgbox "mouseMoved" End Sub Please check your code again, there must be a problem with it.
Of course it works because you created a window from scratch, but I'd like to use a window of Draw. The following piece of code does not work with Draw. The methods mouseMoved and mouseDragged are never called. Did try my code ? From the menu Tools -> Manage extension add the zip file attached and then open a new draw file, you will see a new menu title "TestComp". try: import uno, unohelper from com.sun.star.task import XJob import traceback from com.sun.star.awt import XMouseMotionListener, XKeyHandler, XMouseClickHandler except ImportError: print "probleme d'import" #=================================== # a class to test listener # une classe pour tester un listener #=================================== class CompJob(unohelper.Base, XJob, XMouseMotionListener, XKeyHandler, XMouseClickHandler): """Test de listener Test of listener""" def __init__(self, ctx): self.ctx = ctx self.smgr = self.ctx.ServiceManager # get the central desktop object self.desktop = self.smgr.createInstanceWithContext( "com.sun.star.frame.Desktop",self.ctx) ## ********************* ## this method is called from an other one trigged by a command from menu ## ********************* def execute(self, aArgs): # access the current draw document if self.desktop.ActiveFrame.ActiveFrame: self.COMPONENTWINDOW = self.desktop.ActiveFrame.ActiveFrame.ComponentWindow self.CONTROLLER = self.desktop.ActiveFrame.ActiveFrame.Controller else: self.COMPONENTWINDOW = self.desktop.ActiveFrame.ComponentWindow self.CONTROLLER = self.desktop.ActiveFrame.Controller self.CONTROLLER.addKeyHandler(self) self.COMPONENTWINDOW.addMouseMotionListener(self) self.CONTROLLER.addMouseClickHandler(self) return aArgs #********************* # test of mouse motion #********************* def mouseMoved(self, aMouseEvent): print "mouse motion" return # ********************************** def mouseDragged(self, aMouseEvent): print "mouse dragged" return # ********************************** def mousePressed(self, aMouseEvent): print "mouse pressed" return True # ********************************** def mouseReleased(self, aMouseEvent): print "mouse released" return True # ********************************** def keyPressed(self, aKeyEvent): print "key pressed" return True # ********************************** def keyReleased(self, aKeyEvent): print "key released, bye !" self.CONTROLLER.removeKeyHandler(self) self.COMPONENTWINDOW.removeMouseMotionListener(self) self.CONTROLLER.removeMouseClickHandler(self) return True # XEventListener def disposing(self, eventObject): return # pythonloader looks for a static g_ImplementationHelper variable g_ImplementationHelper = unohelper.ImplementationHelper() g_ImplementationHelper.addImplementation(CompJob, # UNO object class "org.openoffice.comp.pyuno.deneux.CompJob", # implemenation name ("org.openoffice.comp.pyuno.CompJob",),) # list of implemented services
cd->denger68: Please use a correct summary for your problem. The mousemotion listener is called for windows. For your special problem it doesn't work and it cannot work. The component window from a frame is just a container for the application modules. They create other windows which overlaps the whole client area of the component window. Therefore you doesn't get mouse motion events. I changed the title to a more reflect the real problem better and set the component to Draw. cd->af: Hi Andre, I think you have a new API for these kind of things. Could you please help denger68 to get mouse motion events.
af->denger68: Like CD already said, Draw and Impress place another window into the component window that is obtained from the controller. Inside this are placed the scroll bars and the actual view window (with maybe another window in between somewhere). To get access to the content window of the view in one of the panes please have a look at the http://wiki.services.openoffice.org/wiki/Drawing_framework wiki page and especially the 'Accessing a Resource' section.
Please listen the users !
Finally I found a way to set the mouse motion listener to the right window as follow : # access the current draw document if desktop.ActiveFrame.ActiveFrame: CONTROLLER = self.desktop.ActiveFrame.ActiveFrame.Controller else: CONTROLLER = self.desktop.ActiveFrame.Controller # find the window document and scroll bars self.scrollbars = [] for i in range(CONTROLLER.Frame.ComponentWindow.AccessibleContext.AccessibleChildCount): aChild = CONTROLLER.Frame.ComponentWindow.AccessibleContext.getAccessibleChild(i) if aChild.AccessibleContext.AccessibleRole == SCROLL_PANE: for j in range(aChild.AccessibleContext.AccessibleChildCount): aSubChild = aChild.AccessibleContext.getAccessibleChild(j) if aSubChild.AccessibleContext.AccessibleRole == DOCUMENT: aLocation = aSubChild.Location aSize = aSubChild.Size if aSubChild.AccessibleContext.AccessibleRole == SCROLL_BAR: self.scrollbars.append(aSubChild) for w in aChild.Windows: nWidth, nHeight = (aLocation.X-w.PosSize.X) / 2 + aSize.Width, (aLocation.Y-w.PosSize.Y) / 2 + aSize.Height if w.AccessibleContext.AccessibleRole == PANEL and nWidth == w.PosSize.Width and nHeight == w.PosSize.Height: self.aEnv['COMPONENTWINDOW'] = w So I get the window and I hope it will work under all context (not sure for now)
Setting target.
close the WORKSFORME issue
-> metchilde: Why did you closed the issue?
The following OO Basic code (tested on XP SP3, OO 2.4) gives a hint how to implement the mouse motion listener in draw: 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
Reset assigne to the default "issues@openoffice.apache.org".