Chapter 12: Generic Document Methods


Overview

OpenOffice.org supports five primary document types: text, spreadsheet, drawing, math, and presentation. The different document types share a lot of common functionality and interfaces, such as accessing the document model, printing, and saving. This chapter shows you how to perform these common tasks across all of the document types.

The paradigm for each document type follows a similar pattern. The OpenOffice.org infrastructure is too large for a single individual to fully understand all of the pieces. If you learn the general paradigm, however, you'll know where to look for specific functionality.

Every document contains data that can be manipulated and printed. For example, the primary data in a Writer document is text, but it can also contain tables and graphics. The data model consists of this underlying data that can be manipulated independently of how it is displayed. To manipulate the data by means of a macro, you have to manipulate the data model directly. Although you can use the dispatcher to indirectly manipulate the data, the changes are still made directly to the model. A typical usage of the dispatcher is to paste the clipboard contents into the document (see Chapter 10, "UNO and the Dispatcher").

The data model contains a Controller object, which manipulates the visual presentation of the data. The controller doesn't change the data; it only controls how the document is presented. The controller interacts directly with the user interface to control the location of the displayed cursor, to control which page is displayed, and to select portions of the document. Use the controller to determine display- related information such as the current page or the currently selected text.

Tip  

OOo supports a mode called "headless," which has no startup screen, no default document, no user interface, and supports no user interaction. (To see a list of supported modes, run "soffice -?".) If OOo is started in headless mode, there is no display component. Therefore, a controller is not required and may not exist. If it's possible for your macro to run on OOo in headless mode, you must check the controller to see if it is null before using it.

OpenOffice.org has a general global service manager, which is used to create and obtain instances of general UNO services. A service manager accepts a string that identifies a type of object, and it returns an instance of that object. The global service manager is made available in OOo Basic through the function createUnoService(String). The global service manager returns general objects such as a dispatch helper or an object for simple file access.

 oDispatcher = createUnoService("com.sun.star.frame.DispatchHelper") oSimpleFileAccess = createUnoService("com.sun.star.ucb.SimpleFileAccess") 

Except for Math documents, every document type acts as a service manager, returning objects that are directly related to the document. For example, a Writer document is able to create a text table or text field that can be inserted into the document. In general, objects that were not created by a document cannot be inserted into the document. A Writer document is unable to return global objects, and the global service manager is unable to return objects that are then inserted into a document.

 REM Let the document create the text table. oTable = oDoc.createInstance( "com.sun.star.text.TextTable" ) oTable.initialize(3, 2) 'Three rows, two columns REM Now insert the text table at the end of the document. oDoc.Text.insertTextContent(oDoc.Text.getEnd(), oTable, False) 



OpenOffice.org Macros Explained
OpenOffice.org Macros Explained
ISBN: 1930919514
EAN: 2147483647
Year: 2004
Pages: 203

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net