C++ Builder OLE document preview

Java, C++, C#, Delphi... - Using the UNO bridges
Post Reply
SteelRat
Posts: 4
Joined: Fri Oct 29, 2010 2:53 pm

C++ Builder OLE document preview

Post by SteelRat »

Hi all :)
There is a task, given to me, to preview OpenOffice documents (only Presentations and Documents) in the program. I develope this program in C++ Builder and using TOleContainer, where I placed OpenOffice document with help of TOleContainer1->CreateObjectFromFile(filename, false);. This document loads in container, but it doesn't render :( , instead of document I see only it's name (and if I install MS Office I see nice preview, but I need OpenOffice)... But if I activate this element, new OpenOffice window opens and I can view\edit document.

Can anyone help me to make possibility to display first page preview of the existing OpenOffice document? It will be great if it will be done with TOleContainer...

OS: WinXP SP3, IDE: RAD Studio 2010.
Attachments
It's document preview of file "file.doc" in TOleContainer
It's document preview of file "file.doc" in TOleContainer
document_preview.png (6.75 KiB) Viewed 9668 times
OpenOffice 3.2.1 on Windows Seven
rudolfo
Volunteer
Posts: 1488
Joined: Wed Mar 19, 2008 11:34 am
Location: Germany

Re: C++ Builder OLE document preview

Post by rudolfo »

Let me think about this ... You say you use:

Code: Select all

TOleContainer1->CreateObjectFromFile(filename, false);
So filename (in your screenshot "file.doc") is the thing you specify. But you never mention anywhere in your code something like getenv("ProgramFiles") "swriter.exe", right?
Not sure about the internals in Delphi or C++ Builder but I think you can't influence how an OLE document should be viewed in your application. If you use "CreateObjectFromFile" the OLE Configuration (aka the Windows Registry with its CLSIDs) will resolve the file extension and choose the application that is associated with this extension. For .doc this may be Wordpad, OpenOffice Writer or MS Word.
Can you run your app on a different computer? See if it will behave differently there.
Also check the C++ Builder docs on the second parameter ... maybe you need "false", to manually change the default behaviour.
OpenOffice 3.1.1 (2.4.3 until October 2009) and LibreOffice 3.3.2 on Windows 2000, AOO 3.4.1 on Windows 7
There are several macro languages in OOo, but none of them is called Visual Basic or VB(A)! Please call it OOo Basic, Star Basic or simply Basic.
SteelRat
Posts: 4
Joined: Fri Oct 29, 2010 2:53 pm

Re: C++ Builder OLE document preview

Post by SteelRat »

rudolfo wrote:Let me think about this ... You say you use:

Code: Select all

TOleContainer1->CreateObjectFromFile(filename, false);
So filename (in your screenshot "file.doc") is the thing you specify. But you never mention anywhere in your code something like getenv("ProgramFiles") "swriter.exe", right?
The url for file is correct, because, when I activate TOleContainer - this file opens in separate OpenOffice window
rudolfo wrote:Not sure about the internals in Delphi or C++ Builder but I think you can't influence how an OLE document should be viewed in your application. If you use "CreateObjectFromFile" the OLE Configuration (aka the Windows Registry with its CLSIDs) will resolve the file extension and choose the application that is associated with this extension. For .doc this may be Wordpad, OpenOffice Writer or MS Word.
Can you run your app on a different computer? See if it will behave differently there.
This file format is associated with OpenOffice Writer, because of my answer above + I opened this file myself with Windows Explorer and OpenOffice Writer was opened.
rudolfo wrote:Also check the C++ Builder docs on the second parameter ... maybe you need "false", to manually change the default behaviour.
Second parameter is "Display file icon instead of file preview?", so if I will choose "true", then I will see only file icon, but I need Preview of the document.
OpenOffice 3.2.1 on Windows Seven
rudolfo
Volunteer
Posts: 1488
Joined: Wed Mar 19, 2008 11:34 am
Location: Germany

Re: C++ Builder OLE document preview

Post by rudolfo »

Sorry, if the following sounds rude but I have to say it: You have a debugging problem here, not a problem with OpenOffice. Debugging means not mainly to use a debugger, but rather to reconsider your context:
  • What are my starting conditions?
  • What do I expect to see?
  • What assumptions have I made?
  • Which changes can I make to my starting conditions to see different results.
You double clicked on the file file.doc in WIndows Explorer and it opened in OpenOffice. Good. We both would conclude that the file associations in the Registry are correct then. But if file associations are the only parameter for OLE behaviour, and I think we aggree on this, why should it then be different in your C++ Builder application?! This seems to be a contradiction.
Okay, it is a contradiction, but it can't be solved by "But it must be"s. My suggestion to test this on a different computer was one way to get some evidence about the starting conditions. Maybe not practicle for you.
If you change the starting conditions to have .doc files associated with MS Word you say that the TOleContainer works as expected. Instead of changing the file associations you could also change the file: Use a .odt file instead of one with the .doc extension. Yes, I know your application is supposed to open .doc files, but it can tell you something and help you to identify the problem.
Another question: If you say with the second parameter as "True" you see the icon displayed ... which icon is this? The MS Word icon or the Sun Writer Icon?

I guess you will rarely come across C++ Builder or Delphi developers here, so I hope this more general hints from a Borland agnostic can help you.
OpenOffice 3.1.1 (2.4.3 until October 2009) and LibreOffice 3.3.2 on Windows 2000, AOO 3.4.1 on Windows 7
There are several macro languages in OOo, but none of them is called Visual Basic or VB(A)! Please call it OOo Basic, Star Basic or simply Basic.
SteelRat
Posts: 4
Joined: Fri Oct 29, 2010 2:53 pm

Re: C++ Builder OLE document preview

Post by SteelRat »

rudolfo wrote:My suggestion to test this on a different computer was one way to get some evidence about the starting conditions. Maybe not practicle for you.
If you change the starting conditions to have .doc files associated with MS Word you say that the TOleContainer works as expected. Instead of changing the file associations you could also change the file: Use a .odt file instead of one with the .doc extension. Yes, I know your application is supposed to open .doc files, but it can tell you something and help you to identify the problem.
Another question: If you say with the second parameter as "True" you see the icon displayed ... which icon is this? The MS Word icon or the Sun Writer Icon?

I guess you will rarely come across C++ Builder or Delphi developers here, so I hope this more general hints from a Borland agnostic can help you.
I tried to launch my program on XP SP3 and Seven, but nothing changed...
I tried to view .odt file, but the same problem arose...

When I change TOleContainer property to view Icon, when I insert basic object in TOleContainer in C++ Builder - I see Sun Writer Icon, but when during program work I insert file with

Code: Select all

TOleContainer1->CreateObjectFromFile(filename, true);
I did't see icon for any file, and even filetype in TOleContainer doesn't display properly in .doc files (it shows "?????????"), but in .odt files it properly shows "OpenOffice.org".

P.S. When you choose Icon view you must see File Icon + File Type under the icon.
OpenOffice 3.2.1 on Windows Seven
rudolfo
Volunteer
Posts: 1488
Joined: Wed Mar 19, 2008 11:34 am
Location: Germany

Re: C++ Builder OLE document preview

Post by rudolfo »

That's weird! Keeping in mind that with MS Word registered as default app for .doc files the OLE functionality is properly working it makes me think that the problem must be somewhere in the OLE configuration with OpenOffice...
Can you use another OLE application and try to embed a .ods file there? Embedding a .ods Document als OLE object into a MS Word document should basically work. It shows the content on my system although the formatting is garbage because the attempt to insert something on a single Word A4 page that is based on Writer pages that are also A4 will have a scaling problem.
This would proof that you can actually use OLE embedding with Writer .ods files.
If this is not working on your system I would expect some issue with the user profile. Maybe Writer is started in a user context where it has not yet created a user profile ... in that case it will be stuck in the first-start wizard.
I would still say that you could identify such a situation with the task manager. Check which processes are running before you start your Delphi application (ideally no OOo related at all, turn of the quicklauncher if needed) and then again when your app renders the OLE area.

And there is always the chance that this is a bug in the OLE implementation of OpenOffice. Maybe there is something specific with TOleContainer and OpenOffice OLE that is not going smoothly.
OpenOffice 3.1.1 (2.4.3 until October 2009) and LibreOffice 3.3.2 on Windows 2000, AOO 3.4.1 on Windows 7
There are several macro languages in OOo, but none of them is called Visual Basic or VB(A)! Please call it OOo Basic, Star Basic or simply Basic.
SteelRat
Posts: 4
Joined: Fri Oct 29, 2010 2:53 pm

Re: C++ Builder OLE document preview

Post by SteelRat »

rudolfo, I tried to add .odt object in MS Word 2010. When I choose "Create Object from File" and choose file and "OK" button, I get warning with such context: "This object was created in this program: opendocument. This program isn't installed on your computer, or doesn't answer. To edit this object - install opendocument or make sure that all dialog windows in opendocument is closed". I have made sure that all windows of OpenOffice is closed with help of Task Manager, but MS Word didn't want to open this document type. But when I have checked "Link" checkbox in dialog of "Create Object from File", then file embed sucesfully.
I tried to do the same with C++ Builder using

Code: Select all

CreateLinkToFile(filename, false)
, and when I choose .odt file - it sucesfully embed in TOleContainer and I can view it content. But when I choose .doc file, I see only file name as on screenshot in topic header.

P.S. when I choose file for TOleContainer and check "Link" box before compilation of program - after compilation - I see the context of this .doc file!!! :bravo: But when I dynamically change file to another .doc file with CreateLinkToFile - I see only file name :(
OpenOffice 3.2.1 on Windows Seven
rudolfo
Volunteer
Posts: 1488
Joined: Wed Mar 19, 2008 11:34 am
Location: Germany

Re: C++ Builder OLE document preview

Post by rudolfo »

Seems like I won't be able to help you any further. All I know about C++ Builder and Delphi is that the interesing GUI objects all start with T-Something. I remember from earlier times that .doc files did not use standard/basic file association scheme in the registry, but had also some CLSID and DDE keys. Maybe the way how OpenOffice associates the .doc file with itself is not appropriate for "OLE Objects from file"? Might be different (better) for systems where MS Word was never installed.

At least I have done another test with Word 2000 and OOo Writer 3.1.1: I can embed the .odt files in my word document also directly not linked to the file. If I double click on the object or right-click and choose edit I have the OOo Menu and toolbar inside Ms-Word (and I had another OOo Base window open at the same time in the background):
file.odt embedded in Ms Word
file.odt embedded in Ms Word
Surely that's only a proof of concept and not something that anybody would use in a real world context. Seems like my OLE configuration is more what OpenOffice expects to see then yours. Or the OLE implementation in MS Word 2000 works better with OOo than the one in Word 2010 ??
OpenOffice 3.1.1 (2.4.3 until October 2009) and LibreOffice 3.3.2 on Windows 2000, AOO 3.4.1 on Windows 7
There are several macro languages in OOo, but none of them is called Visual Basic or VB(A)! Please call it OOo Basic, Star Basic or simply Basic.
Post Reply