Difference between revisions of "Writer/API/Overview"
SergeMoutou (talk | contribs) |
SergeMoutou (talk | contribs) |
||
| Line 1: | Line 1: | ||
| + | |||
| + | |||
| + | In this chapter, we use again the starting code described in [[UNO_automation_with_a_binary_%28executable%29#Preparing_a_new_Code_as_a_starting_Point|previous chapter]]. It consists of a subprogram “ooConnect()” and a main(). Starting with this code consists in adding new code in the main() where « add code here » is quoted in red. We give for the third time the main program : | ||
| + | <code>[cpp] | ||
| + | //Listing 1 Our starting Code | ||
| + | // C++ | ||
| + | // adapted for OOoWriter | ||
| + | int main( ) { | ||
| + | //retrieve an instance of the remote service manager | ||
| + | Reference< XMultiServiceFactory > rOfficeServiceManager; | ||
| + | rOfficeServiceManager = ooConnect(); | ||
| + | if( rOfficeServiceManager.is() ){ | ||
| + | printf( "Connected sucessfully to the office\n" ); | ||
| + | } | ||
| + | |||
| + | //get the desktop service using createInstance returns an XInterface type | ||
| + | Reference< XInterface > Desktop = rOfficeServiceManager->createInstance( | ||
| + | OUString::createFromAscii( "com.sun.star.frame.Desktop" )); | ||
| + | |||
| + | //query for the XComponentLoader interface | ||
| + | Reference< XComponentLoader > rComponentLoader (Desktop, UNO_QUERY); | ||
| + | if( rComponentLoader.is() ){ | ||
| + | printf( "XComponentloader successfully instanciated\n" ); | ||
| + | } | ||
| + | |||
| + | //get an instance of the OOowriter document | ||
| + | Reference< XComponent > xWriterComponent = rComponentLoader->loadComponentFromURL( | ||
| + | OUString::createFromAscii("private:factory/swriter"), | ||
| + | OUString::createFromAscii("_blank"), | ||
| + | 0, | ||
| + | Sequence < ::com::sun::star::beans::PropertyValue >()); | ||
| + | // add code here | ||
| + | return 0; | ||
| + | } | ||
| + | </code> | ||
| + | We remember the reader that for the examples below we use the “<OpenOffice.org1.1_SDK>/examples/DevelopersGuide/ProfUNO/CppBinding” example. Our code is put in “office_connect.cxx” file. If needed, comments in the code indicate what to add into the makefile and into the source code. The function ooConnect() is also used and not presented here : we have already studied such a function, so it should be quite familiar to us by now. If not, have a look in [UNO_automation_with_a_binary_%28executable|previous chapter]]. | ||
Revision as of 19:03, 23 May 2006
In this chapter, we use again the starting code described in previous chapter. It consists of a subprogram “ooConnect()” and a main(). Starting with this code consists in adding new code in the main() where « add code here » is quoted in red. We give for the third time the main program :
[cpp]
//Listing 1 Our starting Code
// C++
// adapted for OOoWriter
int main( ) {
//retrieve an instance of the remote service manager
Reference< XMultiServiceFactory > rOfficeServiceManager;
rOfficeServiceManager = ooConnect();
if( rOfficeServiceManager.is() ){
printf( "Connected sucessfully to the office\n" );
}
//get the desktop service using createInstance returns an XInterface type
Reference< XInterface > Desktop = rOfficeServiceManager->createInstance(
OUString::createFromAscii( "com.sun.star.frame.Desktop" ));
//query for the XComponentLoader interface
Reference< XComponentLoader > rComponentLoader (Desktop, UNO_QUERY);
if( rComponentLoader.is() ){
printf( "XComponentloader successfully instanciated\n" );
}
//get an instance of the OOowriter document
Reference< XComponent > xWriterComponent = rComponentLoader->loadComponentFromURL(
OUString::createFromAscii("private:factory/swriter"),
OUString::createFromAscii("_blank"),
0,
Sequence < ::com::sun::star::beans::PropertyValue >());
// add code here
return 0;
}
We remember the reader that for the examples below we use the “<OpenOffice.org1.1_SDK>/examples/DevelopersGuide/ProfUNO/CppBinding” example. Our code is put in “office_connect.cxx” file. If needed, comments in the code indicate what to add into the makefile and into the source code. The function ooConnect() is also used and not presented here : we have already studied such a function, so it should be quite familiar to us by now. If not, have a look in [UNO_automation_with_a_binary_%28executable|previous chapter]].
See also
- Using C++ with OOo SDK : Main Page
- Programming OOoWriter (Chapter 8 from UNO/C++ document)
- Using OOoBasic
- Writing a Program to Control OpenOffice.org, by Franco Pingiori — Part 1 and Part 2, Linux Journal
- Text cursor