Issue 76767

Summary: Mouse motion listener is never called for Draw frames
Product: Draw Reporter: gerard.deneux
Component: codeAssignee: AOO issues mailing list <issues>
Status: REOPENED --- QA Contact:
Severity: Trivial    
Priority: P3 CC: issues, ms777, pagalmes.lists
Version: OOo 2.2   
Target Milestone: AOO Later   
Hardware: PC   
OS: Linux, all   
Issue Type: DEFECT Latest Confirmation in: ---
Developer Difficulty: ---
Attachments:
Description Flags
component to test the mouse motion listener none

Description gerard.deneux 2007-04-27 17:17:55 UTC
a component that extend XMouseMotionListener register itself at a window but its
methods mouseMoved and mouseDragged are never called.
Comment 1 jsc 2007-04-30 07:35:18 UTC
jsc -> cd: one for the awt owner
Comment 2 gerard.deneux 2007-05-08 18:48:56 UTC
Created attachment 44948 [details]
component to test the mouse motion listener
Comment 3 gerard.deneux 2007-05-08 18:56:25 UTC
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.
Comment 4 carsten.driesner 2007-05-10 09:17:12 UTC
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.
Comment 5 gerard.deneux 2007-05-10 18:54:58 UTC
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
Comment 6 carsten.driesner 2007-05-11 06:59:54 UTC
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.
Comment 7 groucho266 2007-05-11 09:09:31 UTC
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.
Comment 8 patrickguimberteau 2007-05-22 16:50:04 UTC
Please listen the users !
Comment 9 gerard.deneux 2007-05-22 18:18:02 UTC
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)
Comment 10 groucho266 2007-10-30 13:55:27 UTC
Setting target.
Comment 11 Mechtilde 2008-11-07 12:24:35 UTC
close the WORKSFORME issue
Comment 12 pagalmes.lists 2008-11-07 17:08:39 UTC
-> metchilde: Why did you closed the issue?
Comment 13 ms7777 2009-04-05 15:38:37 UTC
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
Comment 14 Marcus 2017-05-20 11:31:30 UTC
Reset assigne to the default "issues@openoffice.apache.org".