SlumberMan wrote:
> Hi, All
> I try to use com::sun::star::frame::XStorable interface in a cpp source
> file, which is written by myself.
> I add the line "using namespace com::sun::star::frame;" at top and try
> to invoke a reference of XStorable by the following line:
> Reference < XStorable > xSave ( xComponent, UNO_QUERY );
> But the compiler says that, error: ‘XStorable’ was not declared in this
> scope.
You didn't mention that you included <com/sun/star/frame/XStorable.hpp>
in your file. Perhaps you forgot to do that?
> There's only example code in Java in Developer's Guide book and OOo Wiki.
> Could anybody give me some hint about how to save a document which is
> opened by XComponentLoader::loadComponentFromURL() in cpp language.
>From the top of my head, without having compiled it and whithout writing
down the complete code for creating the desktop object and without any
handling of exceptions:
#include <rtl/ustring.hxx>
#include <com/sun/star/uno/Reference.hxx>
#include <com/sun/star/uno/Sequence.hxx>
#include <com/sun/star/lang/XComponent.hpp>
#include <com/sun/star/frame/XComponentLoader.hpp>
#include <com/sun/star/frame/XStorable.hpp>
#include <com/sun/star/beans/PropertyValue.hpp>
using namespace com::sun::star;
// add code to create Desktoo object
uno::Reference < frame::XDesktop > xDesktop;
// properties for loading might be added here
uno::Sequence < beans::PropertyValue > aProps;
// example file name
::rtl::OUString aFileName =
:rtl::OUString::createFromAscii("file:///home/user/myfile.odt");
// create new window
::rtl::OUString aTargetFrame = rtl::OUString::createFromAscii("_blank");
uno::Reference < frame::XStorable >
xStor( xDesktop->loadComponentFromURL( aFileName, aTargetFrame, 0,
aProps ), uno::UNO_QUERY );
// more properties for storing might be added here
uno::Sequence < beans::PropertyValue > aStoreProps(1);
aStoreProps[0].Name = ::rtl::OUString::createFromAscii("Overwrite");
aStoreProps[0].Value <<= sal_True;
// example file name for storing
::rtl::OUString aFileName =
:rtl::OUString::createFromAscii("file:///home/user/mynewfile.odt");
xStorable->storeToURL( aNewFile, aStoreProps );
Some of the includes may be superfluous as they might be nested into
others anyway. Please watch that runtime library headers are included as
"hxx", while API headers have the extension "hpp".
I recommend to send questions like this to the "dev" or "d...@api" list
in future.
Regards,
Mathias
--
Mathias Bauer (mba) - Project Lead OpenOffice.org Writer
OpenOffice.org Engineering at Sun: http://blogs.sun.com/GullFOSS
Please don't reply to "[email protected]".
I use it for the OOo lists and only rarely read other mails sent to it.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]