| View previous topic :: View next topic |
| Author |
Message |
oopit General User

Joined: 22 Mar 2005 Posts: 7
|
Posted: Sun Jun 12, 2005 3:16 am Post subject: Invoking documentcompare (Diff-Viewer) via UNO/C++ |
|
|
Hi,
I have the code below to invoke a view of the differences of two documents
via UNO. This code works, but onlz about 60% of the time.
Often, only the First Document is opened and the second is not loaded an the compare function is not invoked. When i don't use that strange CompareEventListener(),
the success rate is down to somwthing like 40%.
Anyone has a sound solution/idea to fix that issue?
Thanks,
/ pit
| Code: |
class CompareEventListener : public cppu::WeakImplHelper1<com::sun::star::document::XEventListener>
{
public:
CompareEventListener()
{
}
virtual ~CompareEventListener()
{
}
void notifyEvent(const com::sun::star::document::EventObject &evt)
throw (com::sun::star::uno::RuntimeException)
{
EE("CompareEventListener:notifyEvent: %s\n", OU2Ascii(evt.EventName));
}
void disposing(const com::sun::star::lang::EventObject& evt)
throw (com::sun::star::uno::RuntimeException)
{
EE("CompareEventListener:disposing\n");
}
};
// function snippet that actually invokes comparison functionality:
Reference<XDesktop> desk(m_servicefactory->createInstance(Ascii2OU("com.sun.star.frame.Desktop")), UNO_QUERY);
Reference<XComponentLoader> loader(desk, UNO_QUERY);
// load first document
Sequence<PropertyValue> loadproperties(3);
loadproperties[0].Name = Ascii2OU("Hidden");
loadproperties[0].Value <<= sal_False;
loadproperties[1].Name = Ascii2OU("Silent");
loadproperties[1].Value <<= sal_True;
loadproperties[2].Name = Ascii2OU("ReadOnly"); // neccessary!
loadproperties[2].Value <<= sal_False;
Reference<XComponent> comp = loader->loadComponentFromURL(Ascii2OU(doc1url), Ascii2OU("_blank"), 0, loadproperties);
// event listener
Reference<com::sun::star::document::XEventBroadcaster> xeb(comp, UNO_QUERY);
xeb->addEventListener(static_cast<com::sun::star::document::XEventListener *>(new CompareEventListener));
// prepare call
Sequence<PropertyValue> compprops(2);
compprops[0].Name = OUString(RTL_CONSTASCII_USTRINGPARAM("URL"));
compprops[0].Value <<= Ascii2OU(doc2url);
compprops[1].Name = OUString(RTL_CONSTASCII_USTRINGPARAM("CompareDocuments"));
compprops[1].Value <<= sal_True;
// dispatch call
Reference<XDispatchHelper> disphlp(m_servicefactory->createInstance(
Ascii2OU("com.sun.star.frame.DispatchHelper")), UNO_QUERY);
Reference<XDispatchProvider> currentframe(desk->getCurrentFrame(), UNO_QUERY);
disphlp->executeDispatch(currentframe,
Ascii2OU(".uno:CompareDocuments"),
Ascii2OU(""), 0, compprops);
|
|
|
| Back to top |
|
 |
SergeM Super User

Joined: 09 Sep 2003 Posts: 3211 Location: Troyes France
|
|
| Back to top |
|
 |
oopit General User

Joined: 22 Mar 2005 Posts: 7
|
Posted: Wed Jun 15, 2005 5:27 am Post subject: |
|
|
the 2. document is loaded after
// prepare call
-----
compprops[0].Name = OUString(RTL_CONSTASCII_USTRINGPARAM("URL"));
compprops[0].Value <<= Ascii2OU(doc2url);
-----
where doc2url is something like file:///path/to/file.sxw
As stated, it works, but not always, which is the strange thing i want fixed. |
|
| Back to top |
|
 |
SergeM Super User

Joined: 09 Sep 2003 Posts: 3211 Location: Troyes France
|
Posted: Wed Jun 15, 2005 10:38 am Post subject: |
|
|
I can beter explain what i want to say with the shematic above. Your program is like :
| Code: |
+--------+
| loader |
+--------+
|
loadComponentFromURL
|
V
+--------+
| comp |
+--------+
|
UNO_QUERY
|
V
+-------+
| xeb |
+-------+
|
addEventListener
|
V
|
With your program only comp know where is the first document you first load. And it will be never used again. Then I don't see the link between both documents to compare. How is your program knowing the first document ? Perhaps it works only when it is the default document ! Or perhaps you don't give us the entire code ? _________________ Linux & Windows OOo3.0
UNO & C++ : WIKI
http://wiki.services.openoffice.org/wiki/Using_Cpp_with_the_OOo_SDK
In French
http://wiki.services.openoffice.org/wiki/Documentation/FR/Cpp_Guide |
|
| Back to top |
|
 |
oopit General User

Joined: 22 Mar 2005 Posts: 7
|
Posted: Thu Jun 23, 2005 2:04 am Post subject: |
|
|
that event listener think is just pure specualtion, it could be the cause of the problem,
because i thought the dispatch won't succeed if the 1st document is not loaded fully.
but the issue seems more random, somehow.
functionality basically is, that the first document is simply loaded with
'loadComponentFromURL' then the ".uno:CompareDocuments" with a parameter containing the 2nd document is dispatched against the current frame. |
|
| Back to top |
|
 |
|