UNO/C++
By
Serge Moutou
Last Modified

Thank You
I am unable to write such a document alone. My inspiration comes from the OooForum (http://www.oooforum.org/) where I find peoples who can spend a while to help others. In particularly, I have received or will receive advices from
Andrew Pitonyak
Christian Junker (Cybb20 in the OOoForum )
Niall Dorgan (redrgreen in the OOoForum )
It is difficult to do something without using Danny Brewer's code or package and advices.
I know also that I will inspire myself from a Bernard Marcelly's French document on UNO and OooBasic : " API (presque) sans peine "(see http://fr.openoffice.org/Documentation/How-to/indexht.html)
In Sophie Gautier's French document : “Dans la jungle de l’API OpenOffice.org”, I have found drawings for interfaces and services more colored than UML (see http://fr.openoffice.org/Documentation/How-to/indexht.html)
Daniel Bölzle's documentation (http://udk.openoffice.org/cpp/man/component_tutorial.html ) was also helpfull.
Disclaimer
The material in this document carries no guarantee of applicability, accuracy, or safety. Use the information and macros in this document at your own risk. In the unlikely event that they cause the loss of some or all of your data and/or computer hardware, that neither I, nor any of the contributors, will be held responsible.
Credentials
I studied physics in the 1970s. By this time, the university owns only one IBM 1130 for teaching and searching. I receive only 15 hours of Fortran programming during the 6 years I spend here. We have done only one program, and I never knew if it worked... As you can see, all that I know of software is self-learned. Consequently this document cannot be perfect. I don't know many aspects of software development very well. Perhaps software engineers will be shocked by great faults. If that's the case, please e-mail me.
Public Documentation License Notice
The contents of this Documentation are subject to the Public Documentation License Version 1.0 (the "License"); you may only use this Documentation if you comply with the terms of this License.
A copy of the License is available at http://www.openoffice.org/licenses/pdl.pdf
The Original Documentation and latest version is available at http://perso.wanadoo.fr/moutou/index.html#OOoDoclink
|
Contribution |
Contributor |
Contact |
Copyright |
|---|---|---|---|
|
Original author |
Serge Moutou |
2004 |
|
|
Reformatting and language |
Andrew Pitonyak |
2004 |
|
|
Reformatting and language |
Christian Junker |
2004 |
|
|
Help on event listener |
Emmanuel GUY |
|
2004 |
|
Help on Run Time Dialog Box |
GAP ( INDIA ) |
gap82 in OOoForum |
2005 |
|
Reformatting and language |
Aditya Kumar Pandey |
adipan in OOoForum |
2005 |
|
VC++.NET tutorial |
LarsB |
LarsB in OOoForum |
2005 |
|
bookmarks |
Robert MEAILLE |
foster06 in OOoForum |
2005 |
|
improving VC++.NET tutorial |
François Rossignol |
_francois_ in OOoForum |
2005 |
|
Add-in chapter |
Eric Ehlers |
|
2005 |
Table of Contents
1.1 How to read this document ? 6
1.2 What about the code 6
1.3 Why C++ and not OOoBasic? 6
2 How to install the SDK and compile the C++ examples 8
2.1 Installation under LINUX 8
2.2 Installation under Windows 9
2.3 OpenOffice with Visual Studio .NET Steps 9
2.4 Installing with the free MS Visual C++ Toolkit 2003 12
2.5 The Development Tools of the SDK 13
2.6 One Cpp Example 13
3.1 Our starting Example : Simple Binaries (Executable) 15
3.2 Types 16
3.3 Sequences 18
3.4 Strings 19
3.4.1 OUString and OString 20
3.4.2 File Path 22
3.4.3 SDK Example 23
3.4.4 Sequence of Strings 23
3.5 Any 24
3.6 Files 25
3.7 Threads 26
3.8 Make Dependency of the previous Examples 29
3.9 To go further : the Enumeration Type Problem 31
4 OpenOffice.org's UNO/ automation with a binary (executable) 33
4.1 Introduction : starting from a SDK example 33
4.2 The make dependency 38
4.3 Preparing a new Code as a starting Point 39
4.4 To find and to save the Document 40
4.4.1 Loading an existing File 41
4.4.2 Create a new Document 42
4.4.3 The default opened Document 42
4.4.4 Save the Document 44
4.5 My first Container enumeration with Desktop 45
4.5.1 XEnumeration Interface 45
4.5.2 Using a XIndexAcess interface 47
4.5.3 Using a XNameAccess interface 47
4.5.4 What is not clear for me (and then need Help) 47
4.6 Chapter Summary 47
5.1 To find the Sheet 49
5.1.1 An existing Sheet 49
5.1.2 Create, rename, copy and delete a Sheet 51
5.1.3 Retrieve or change the currently focused Sheet 54
5.2 How to obtain the Cell 57
5.3 What can we do with a Cell ? 58
5.3.1 Numerical Value in a Cell 58
5.3.2 Formula in a Cell 59
5.3.3 String in a Cell 59
5.3.4 What is the Content Type of a Cell ? 59
5.3.5 Computing the Formula 60
5.3.6 Formating a Cell 61
5.3.7 Cell Annotations 61
5.4 Cell Range 62
5.4.1 Retrieve the absolute X and Y Positions of a Cell 63
5.4.2 Retrieve the absolute Address of the Cell Range 63
5.4.3 Getting a Cell range with a Selection 64
5.4.4 To show a Cell Range as selected 64
5.5 Ready to translate the Developpers Guide into C++ 64
5.5.1 The Compute Function Example 65
5.5.2 A second Example : adding a Name to a Cell (or Cell Range) 66
5.5.3 A third Example 67
5.5.4 An Example from OooForum: opening a Password protected Document 68
5.6 Event Listener 69
5.6.1 First Event Listener 69
5.6.2 A second Event Listener 71
5.7 Chart 71
6.1 Finding the drawing Page 72
6.1.1 An existing Page 72
6.1.2 Create, rename, copy and remove a Slide 73
6.1.3 Setting the Focus on a Page 75
6.1.4 Property of a Page 75
6.2 Drawing with Draw 77
6.2.1 Inserting a Shape 77
6.2.2 Writing Text in a Shape 78
6.2.3 Giving a Name to the Shape 78
6.3 Graphics and OOoDraw 79
6.3.1 Inserting a bitmap 79
6.3.2 Changing the Size of a Picture 80
6.3.3 Inserting many Pictures 80
6.3.4 Finding a Picture with its Name 80
7 Shapes 81
7.1 Shape's Properties 82
7.1.1 Background Colors and Shape Colors 82
7.1.2 Shape and Shadow 84
7.1.3 Shape's Rotation and sharing 85
7.1.4 Line Style 85
7.2 Drawing Shapes 88
7.2.1 Polyline Shape 88
7.2.2 Bezier Shape 90
7.2.3 Connectors and glues points 92
8 OOoWriter 94
8.1 Using the Dispatcher and recording Macros 94
8.1.1 Introduction 95
8.1.2 Dispatcher and Internationalization 97
8.2 Creating, opening a Writer Document 98
8.3 Managing Text 98
8.3.1 Finding the Text 98
8.3.2 Writing any Text in the Document 99
8.3.3 Managing Text with XTextRange Interface 99
8.3.4 The XTextCursor Interface 100
8.3.5 The insertString Method 103
8.4 Accessing the Cursor Properties 104
8.5 Accessing a Bookmark 105
8.6 Tables in a Writer Document 106
8.7 Translate Java Code into C++ (Page Properties) 109
8.8 Translate Java Code into C++ (inserting an Image) 110
9.1 Playing with Window Toolkit AWT 111
9.1.1 DannyB's Explanations 111
9.1.2 The MessageBox Windows 111
9.1.3 A very simple Window 114
9.1.4 The file picker dialog 115
9.1.5 Save as Dialog 117
9.1.6 Run Time Dialog Box (with GAP's help (From INDIA )) 119
9.1.7 Complete Translation of a Java example 122
9.1.8 Control Edit example 126
9.1.9 List Box example 129
9.1.10 Adding a second Event Listener (List Box) 133
9.1.11 Radio Button 134
9.2 Executing an OOoBasic macro from C++ 137
9.2.1 A first example 137
9.2.2 XRay and C++ 138
10.1 Services and Interfaces 140
10.1.1 Introduction 140
10.1.2 Danny Brewer's rules 142
10.2 IDL specification 142
10.2.1 Specifying an interface 143
10.2.2 Specifying a service 143
10.2.3 Specifying a module 143
10.2.4 Further with IDL 144
10.3 Gathering UNO information with IDL files 145
10.3.1 Danny Brewer 's Point of View 145
10.3.2 A concrete example 146
10.4 IDL and C++ 148
10.4.1 Getting an interface in C++ 148
10.4.2 Mapping for Modules and Interfaces 150
10.5 Core reflection service and its Interfaces 151
10.5.1 The XIdlReflection interface 151
10.5.2 The XIntrospection Interface 155
10.5.2.1 Obtaining methods information 156
10.5.2.2 Obtaining all the interfaces 158
10.5.2.3 Obtaining all the properties 159
10.5.2.4 Putting all together 159
10.6 Using Java Inspector 165
10.7 Translating OOoBasic programs into C++ 168
11 UNO registry and bootstrapping 171
11.1 Why UNO registry ? 171
11.2 How to use UNO registeries 173
11.3 The Bootstrap 173
11.3.1 C++ UNO bootstrapping via defaultBootstrap_InitialComponentContext() 173
11.3.2 C++ UNO bootstrapping via Bootstrap_InitialComponentContext() 177
11.4 Playing with regview 179
11.5 How can we registry in C++ ? 179
11.6 How do we see the registeries in OOoBasic ? 181
12.1 Desktop Helper 184
12.1.1 The GAP's Helper 184
12.1.2 Simple Desktop Helper 186
12.1.3 Desktop Helper with message box 188
12.2 OOoDraw Helper 189
12.3 Reflection Helper 191
12.3.1 Presentation 191
12.3.2 Application 196
12.3.3 Printing out Reflection's Results in a Dialog 197
12.4 Helper's Compilation and Utilisation 203
12.4.1 The #include method 203
12.4.2 The object file method 203
12.4.3 The dynamic library uno.so / uno.dll method 206
13 Constructing Components 209
13.1 Danny Brewer's Terminology 209
13.2 Make dependency of a Component 210
13.3 First Example : accessing a Counter from OOoBasic 212
13.3.1 A very simple Counter 212
13.3.2 Making the Counter registerable 214
13.3.2.1 Rule 1 214
13.3.2.2 Rule 2 215
13.3.2.3 Rule 3 (provisional rule) 215
13.3.3 The Counter Example 216
13.3.4 Modifying the simple Counter to see registry at Work 218
13.3.5 Using an Helper to construct the scriptable Counter 222
13.3.5.1 Rule 3 222
13.3.6 A Counter with Attribute 226
13.3.7 Constructing the Counter without Helper 227
13.4 Using UNO Binary 227
13.5 A second example 228
13.5.1 The CppComponent Example (see Developer's Guide) 228
13.5.2 Simplifying the CppComponent Example 229
13.5.3 Explanations 232
13.6 Component as humble Add-in 233
14 Add-in : adding OooCalc functions 235
14.1 Introduction 235
14.1.1 Starting from official documentation 235
14.1.2 The corresponding Services 236
14.2 My first Add-In 239
14.3 Utilities 244
14.3.1 Transforming sequence of sequence into array 244
14.3.2 Transforming an Array into Sequence of Sequence 245
14.3.3 Eric Ehlers's utilities 246
14.4 Interfacing the GSL (GNU Scientific Library) 247
14.4.1 First step 247
14.4.2 Second step 247
14.4.3 Third Step 248
14.4.4 Step Four 248
15 Appendix : The makefile 250
15.1 Makefile structure 250
15.2 Lifetime example: compilation part 250
15.2.1 A shorter Makefile 251
15.2.2 Header file generation 252
15.2.2.1 The Lifetime example 252
15.2.2.2 A more sophisticated example 253
15.2.3 Compiling with gcc 254
15.2.3.1 A two step compilation example 254
15.2.3.2 A three step compilation example 255
15.2.3.3 A four step compilation example 255
15.3 Use of pkgchk 256
15.4 The two last parts 257
15.5 Conclusion : your own makefile 257
15.5.1 Linux Makefile 257
15.5.2 Windows Makefile 258