Kbase P151868: 4GL/ABL: How to trap OpenOffice Word Document events?
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  25/05/2010 |
|
Status: Verified
GOAL:
4GL/ABL: How to trap OpenOffice Word Document events?
GOAL:
How to write 4GL/ABL triggers for OpenOffice Word Document events?
FACT(s) (Environment):
Windows
Progress 9.x
OpenEdge 10.x
OpenEdge Category: Language (4GL/ABL)
FIX:
Since OpenOffice does not present events in the usual manner we cannot use the ENABLE-EVENTS statement to trap its events. The easiest way to trap OpenOffice events is to write a DLL that receives events from the OpenOffice object and pass them back to Progress to use the ENABLE-EVENTS statement. The following sample DLLs are written in VB6 and contain the servers for the event listeners, only the disposing event is trapped at present but this VB code may be easily expanded.
Option Explicit
'create a Public Event Matching the OOoevent sub below
'so it gets passed back to calling program
'To fire this event, use RaiseEvent with the following syntax:
'RaiseEvent xxxxxx[(arg1, arg2, ... , argn)] in the
'corresponding Sub below
'Event can be trapped in calling prog by
'objEventListener:enable-events("OOoEvents").
'and creating int proc called OOoevents.xxxxx
Public Event disposing(source)
Public Event terminate(source)
Public Event notifyevent(eventname, source)
Private interfaces(0) As String
Public Property Get Bridge_ImplementedInterfaces() As Variant
Bridge_ImplementedInterfaces = interfaces
End Property
Private Sub Class_Initialize()
'interfaces(0) = "com.sun.star.lang.XEventListener" 'service level
interfaces(0) = "com.sun.star.document.XEventListener" 'document level
End Sub
'create a sub for each OOoevent to be trapped
Public Sub disposing(ByVal source As Object)
RaiseEvent disposing(source)
End Sub
'these two dont appear to work odd!
Public Sub terminate(ByVal source As Object)
RaiseEvent terminate(source)
End Sub
'if this worked would solve all problems
Public Sub notifyevent(ByVal eventname As String, ByVal source As Object)
RaiseEvent notifyevent(eventname, source)
End Sub
Change the interface(0) in class_initialize depending on what level you want to trap events at. or use array for multilevels!?. The service exposed is given by the name in in the project properties.
OOoEvent.dll -- listens to OpenOffice service level events ( highest level)
OOoDocumentEvent.dll -- listens to OpenOffice document level events.
copy the dlls to windows/system32 and register them.
In Progress we could then write:
def var ch-office as com-handle no-undo.
def var ch-document as com-handle no-undo.
def var OOeventlistener as com-handle no-undo.
Def var DocEventListener as com-handle no-undo.
/* create the event listener on the OO System dont have to just
if you want to trap events at service level ie whole of OO closing*/
create "OOoevent.Listener" OOEventListener.
OOEventListener:enable-events("OOoEvents").
/* after the creation of openoffice we attach it to the listener */
/* add our listener to office if we want to trap event */
ch-office:AddEventListener(OOEventListener).
/* create the event listener on the document */
create "OOoDocumentEvent.Listener" DocEventListener.
DocEventListener:enable-events("DocEvents").
G>/* and after openning the document we attach it to its listener */
ch-document = ch-application:loadComponentFromURL("private:factory/swriter",
"_blank",
0,
extraArgs).
/* add our listener to the document */
ch-document:AddEventListener(DocEventListener). /* fires dispose first if both are used */
/* dont forget to release the listener objects when you are finished
probably in main block on close of this-procedure! */
release object OOEventListener no-error.
release object DocEventListener no-error.
/* The events can now be trapped and processed in the usual way .*/
PROCEDURE DocEvents.Disposing : /* traps Document level disposing */
def input-output param pv-source as com-handle no-undo.
/* pv-source is handle to object causing event to fire not a lot of use
at present but never know maybe later! */
message Program-name(1) "Disposing From " string(pv-source)
view-as alert-box title 'Document Event'.
END PROCEDURE.
PROCEDURE OOoEvents.disposing : /* traps service (top) level disposing */
def input-output param pv-source as com-handle no-undo.
/* pv-source is handle to object causing event to fire not a lot of use
at present but never know maybe later! */
message Program-name(1) "Disposing From " string(pv-source)
view-as alert-box title 'Service Event'.
END PROCEDURE..