Difference between revisions of "Documentation/DevGuide/Drawings/Handling Drawing Document Files"

From Apache OpenOffice Wiki
Jump to: navigation, search
m (1 revision(s))
m
 
(4 intermediate revisions by 2 users not shown)
Line 5: Line 5:
 
|NextPage=Documentation/DevGuide/Drawings/Saving Drawing Documents
 
|NextPage=Documentation/DevGuide/Drawings/Saving Drawing Documents
 
}}
 
}}
{{DISPLAYTITLE:Handling Drawing Document Files}}
+
{{Documentation/DevGuideLanguages|Documentation/DevGuide/Drawings/{{SUBPAGENAME}}}}
 +
{{DISPLAYTITLE:Handling Drawing Document Files}}
 
=== Creating and Loading Drawing Documents ===
 
=== Creating and Loading Drawing Documents ===
  
If a document in {{PRODUCTNAME}} is required, begin by getting the <idl>com.sun.star.frame.Desktop</idl> service from the service manager. The desktop handles all document components in {{PRODUCTNAME}} among other things. It is discussed thoroughly in the chapter [[Documentation/DevGuide/OfficeDev/Office Development|Office Development]]. Office documents are often called components because they support the <idl>com.sun.star.lang.XComponent</idl> interface. An <code>XComponent</code> is a UNO object that can be disposed explicitly and broadcast an event to other UNO objects when this happens.
+
If a document in {{AOo}} is required, begin by getting the <idl>com.sun.star.frame.Desktop</idl> service from the service manager. The desktop handles all document components in {{AOo}} among other things. It is discussed thoroughly in the chapter [[Documentation/DevGuide/OfficeDev/Office Development|Office Development]]. Office documents are often called components because they support the <idl>com.sun.star.lang.XComponent</idl> interface. An <code>XComponent</code> is a UNO object that can be disposed explicitly and broadcast an event to other UNO objects when this happens.
  
 
The Desktop loads new and existing components from a URL. The desktop has a <idl>com.sun.star.frame.XComponentLoader</idl> interface that has one single method to load and instantiate components from a URL into a frame:
 
The Desktop loads new and existing components from a URL. The desktop has a <idl>com.sun.star.frame.XComponentLoader</idl> interface that has one single method to load and instantiate components from a URL into a frame:
 
+
<syntaxhighlight lang="java">
 
   com::sun::star::lang::XComponent loadComponentFromURL( [in] string aURL,  
 
   com::sun::star::lang::XComponent loadComponentFromURL( [in] string aURL,  
 
                                       [in] string aTargetFrameName,  
 
                                       [in] string aTargetFrameName,  
 
                                       [in] long nSearchFlags,  
 
                                       [in] long nSearchFlags,  
                                       [in] sequence< com::sun::star::beans::PropertyValue > aArgs )
+
                                       [in] sequence< com::sun::star::beans::PropertyValue > aArgs )</syntaxhighlight>
  
 
The parameters in our context are the URL that describes the resource to be loaded, and the load arguments. For the target frame pass in "<code>_blank</code>" and set the search flags to 0. In most cases, you will not want to reuse an existing frame.
 
The parameters in our context are the URL that describes the resource to be loaded, and the load arguments. For the target frame pass in "<code>_blank</code>" and set the search flags to 0. In most cases, you will not want to reuse an existing frame.
Line 25: Line 26:
 
The introductory example shows how to load a drawing document. This snippet loads a new drawing document in hidden mode:
 
The introductory example shows how to load a drawing document. This snippet loads a new drawing document in hidden mode:
  
  <code>// the method getRemoteServiceManager is described in the chapter First Steps
+
<syntaxhighlight lang="java">// the method getRemoteServiceManager is described in the chapter First Steps
 
   mxRemoteServiceManager = this.getRemoteServiceManager();
 
   mxRemoteServiceManager = this.getRemoteServiceManager();
 
    
 
    
Line 49: Line 50:
 
   // load
 
   // load
 
   com.sun.star.lang.XComponent xComponentLoader.loadComponentFromURL(
 
   com.sun.star.lang.XComponent xComponentLoader.loadComponentFromURL(
       "private:factory/sdraw", "_blank", 0, loadProps);  
+
       "private:factory/sdraw", "_blank", 0, loadProps);
 +
</syntaxhighlight>
  
 
{{PDL1}}
 
{{PDL1}}
[[Category: Drawing Documents and Presentation Documents]]
+
 
 +
[[Category:Documentation/Developer's Guide/Drawing Documents and Presentation Documents]]

Latest revision as of 14:06, 20 December 2020



Creating and Loading Drawing Documents

If a document in Apache OpenOffice is required, begin by getting the com.sun.star.frame.Desktop service from the service manager. The desktop handles all document components in Apache OpenOffice among other things. It is discussed thoroughly in the chapter Office Development. Office documents are often called components because they support the com.sun.star.lang.XComponent interface. An XComponent is a UNO object that can be disposed explicitly and broadcast an event to other UNO objects when this happens.

The Desktop loads new and existing components from a URL. The desktop has a com.sun.star.frame.XComponentLoader interface that has one single method to load and instantiate components from a URL into a frame:

  com::sun::star::lang::XComponent loadComponentFromURL( [in] string aURL, 
                                       [in] string aTargetFrameName, 
                                       [in] long nSearchFlags, 
                                       [in] sequence< com::sun::star::beans::PropertyValue > aArgs )

The parameters in our context are the URL that describes the resource to be loaded, and the load arguments. For the target frame pass in "_blank" and set the search flags to 0. In most cases, you will not want to reuse an existing frame.

The URL can be a file: URL, an http: URL, an ftp: URL or a private: URL. The correct URL format is located in the load URL box at the function bar of OpenOffice.org. For new Draw documents, a special URL scheme is used. The scheme is "private:", followed by "factory" as the hostname and the resource is "sdraw" for OpenOffice.org Draw documents. Thus, for a new Draw document, use "private:factory/sdraw".

The load arguments are described in com.sun.star.document.MediaDescriptor. The properties AsTemplate and Hidden are boolean values and used for programming. If AsTemplate is true, the loader creates a new untitled document from the given URL. If it is false, template files are loaded for editing. If Hidden is true, the document is loaded in the background. This is useful to generate a document in the background without letting the user observe what is happening. For instance, use it to generate a document and print it out without previewing. Refer to Office Development or other available options.

The introductory example shows how to load a drawing document. This snippet loads a new drawing document in hidden mode:

// the method getRemoteServiceManager is described in the chapter First Steps
  mxRemoteServiceManager = this.getRemoteServiceManager();
 
  // retrieve the Desktop object, we need its XComponentLoader
  Object desktop = mxRemoteServiceManager.createInstanceWithContext(
      "com.sun.star.frame.Desktop", mxRemoteContext);
 
  // query the XComponentLoader interface from the Desktop service
  XComponentLoader xComponentLoader = (XComponentLoader)UnoRuntime.queryInterface(
      XComponentLoader.class, desktop);
 
  // define load properties according to com.sun.star.document.MediaDescriptor
  // the boolean property Hidden tells the office to open a file in hidden mode
  PropertyValue[] loadProps = new PropertyValue[1];
  loadProps[0] = new PropertyValue();
  loadProps[0].Name = "Hidden";
  loadProps[0].Value = new Boolean(true); 
 
  /* or simply create an empty array of com.sun.star.beans.PropertyValue structs:
     PropertyValue[] loadProps = new PropertyValue[0]
   */
 
  // load
  com.sun.star.lang.XComponent xComponentLoader.loadComponentFromURL(
      "private:factory/sdraw", "_blank", 0, loadProps);
Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages