LibreOffice (Draw) Macro - Select draw object with mouse

asked 2020-10-07 11:35:22 +0200

Vijay Tripathi gravatar image

N00b at LO macros and LO Basic. Was working on a macro but couldn't figure out the following: 1) How to send a prompt message to the status bar. Is it even possible? 2) How to "Await" for a mouse click to select a shape within in the current frame 3) Do I really need to add mouse click listeners? Shouldn't they be on by default as any document needs mouse click when the document is loaded?

Below is my code (help taken from Andrew Pitonyak's reference). However, it doesn't await for any input and I always get the "Couldn't get the mouse click" message (as programmed in the if statement).

REM  *****  BASIC  *****

Global vLine_selection_listener
Global vLine_selection_broadcast

Sub MyMacroMain

    Dim oEventObject as New com.sun.star.awt.MouseEvent

    StartListeningToMouseClickEvents

    Line_selection_select(oEventObject)

    StopListeningToMouseClickEvents

End Sub

Sub StartListeningToMouseClickEvents

    vLine_selection_broadcast = ThisComponent.getCurrentController

    vLine_selection_listener = CreateUnoListener("Line_selection_", "com.sun.star.awt.XMouseClickHandler")

    vLine_selection_broadcast.addMouseClickHandler(vLine_selection_listener)
End Sub

Sub StopListeningToMouseClickEvents
    vLine_selection_broadcast.removeMouseClickHandler(vLine_selection_listener)
End Sub

Sub Line_selection_select(vEvent)
    Dim vCurrentSelection As Object
    vCurrentSelection = vEvent.source

    If vEvent.Buttons AND com.sun.star.awt.MouseButton.LEFT Then
        Msg = Msg & "LEFT "
    Else
        Msg = "Couldn't get the mouse click"
    End If

    MsgBox Msg

End Sub

Sub Line_selection_disposing(vEvent)
    'disposing listener
End Sub
edit retag flag offensive close merge delete