Ask Your Question
0

How do we import the listener events of LibreOffice writer in Visual Basic 6?

asked 2017-11-01 19:24:42 +0200

this post is marked as community wiki

This post is a wiki. Anyone with karma >75 is welcome to improve it.

I am trying to implement a listener event in Visual Basic 6 for LibreOffice Writer. I was referred to the following code from https://wiki.openoffice.org/wiki/Docu....

set xContext = objServiceManager.getPropertyValue( "DefaultContext" )
set xCoreReflection = xContext.getValueByName( "/singletons/com.sun.star.reflection.theCoreReflection" )
set xClass = xCoreReflection.forName( "com.sun.star.document.XEventBroadcaster" )
set xMethod = xClass.getMethod( "addEventListener" )

dim invokeargs(0)
invokeargs(0) = myListener

set value = objServiceManager.Bridge_GetValueObject()
call value.InitInOutParam("[]any", invokeargs)
call xMethod.invoke( objDocument, value )

I am not able to understand the implementation of the listener event from this code.

Can I get example code to implement listener events for LibreOffice Writer in Visual Basic 6?

edit retag flag offensive close merge delete

Comments

This was originally asked at https://stackoverflow.com/questions/4....

Jim K gravatar imageJim K ( 2017-11-02 17:35:37 +0200 )edit

1 Answer

Sort by » oldest newest most voted
0

answered 2017-11-02 19:46:19 +0200

Jim K gravatar image

updated 2017-11-02 19:49:53 +0200

Here is more complete _VB.NET_ code. Probably won't work in _VB6_ though.

Imports unoidl.com.sun.star.container
Imports unoidl.com.sun.star.lang

Module Module1
    Sub Main()
        Dim oSM
        Dim oDesk, oDoc As Object
        Dim arg(-1)
        oSM = CreateObject("com.sun.star.ServiceManager")
        oDesk = oSM.createInstance("com.sun.star.frame.Desktop")
        oDoc = oDesk.loadComponentFromURL("private:factory/swriter", "_blank", 0, arg)
        oDoc.getText().setString("Hello!")
        Dim xContainer As XContainer =  REM # TODO: Get object you want to listen to
        Dim myListener As MyListener = New MyListener()
        xContainer.addContainerListener(myListener)
    End Sub
    Class MyListener
        Implements XContainerListener
        Sub disposing(oEvent As EventObject) Implements XEventListener.disposing
            MsgBox("disposing")
        End Sub
        Sub XContainerListener_elementInserted([Event] As ContainerEvent) Implements XContainerListener.elementInserted
            MsgBox("elementInserted")
        End Sub
        Sub XContainerListener_elementRemoved([Event] As ContainerEvent) Implements XContainerListener.elementRemoved
            MsgBox("elementRemoved")
        End Sub
        Sub XContainerListener_elementReplaced([Event] As ContainerEvent) Implements XContainerListener.elementReplaced
            MsgBox("elementReplaced")
        End Sub
    End Class
End Module
edit flag offensive delete link more

Comments

Hi Jim,

Please let me know how to get object and assign for container.

Dim xContainer As XContainer = REM # TODO: Get object you want to listen to

Also provide me some example code (C# or VB.NET) to raise onSave event for libreoffice document.

Thanks

Muru gravatar imageMuru ( 2017-11-10 06:21:13 +0200 )edit

@Muru: Please ask this as a separate question, and I will give an answer for C# (which I prefer instead of _VB.NET_). Since this will be your first question on this site, have a look at my suggested list at https://ask.libreoffice.org/en/questi.... Especially be sure not to check the community wiki box. Then if your question is good enough, I'll upvote it to give you some reputation points, and you'll get points if you mark the answer as correct.

Jim K gravatar imageJim K ( 2017-11-10 20:53:47 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2017-11-01 19:24:42 +0200

Seen: 276 times

Last updated: Nov 02 '17