summaryrefslogtreecommitdiff
path: root/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment
diff options
context:
space:
mode:
Diffstat (limited to 'odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment')
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/CustomizeView.java304
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/Desk.java102
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/DocumentView.java436
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/FunctionHelper.java1066
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/IOnewayLink.java76
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/IShutdownListener.java53
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/Install.txt10
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/Interceptor.java678
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/JavaWindowPeerFake.java113
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/Makefile134
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/NativeView.java188
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/OfficeConnect.java211
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/OnewayExecutor.java246
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/StatusListener.java484
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/StatusView.java272
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/ViewContainer.java275
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/nativelib/unix/Makefile79
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/nativelib/unix/nativeview.c117
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/nativelib/unix/nativeview.h69
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/nativelib/windows/Makefile87
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/nativelib/windows/nativeview.c184
-rw-r--r--odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/nativelib/windows/nativeview.h69
22 files changed, 5253 insertions, 0 deletions
diff --git a/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/CustomizeView.java b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/CustomizeView.java
new file mode 100644
index 000000000000..1ba840286b95
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/CustomizeView.java
@@ -0,0 +1,304 @@
+/*************************************************************************
+ *
+ * $RCSfile: CustomizeView.java,v $
+ *
+ * $Revision: 1.4 $
+ *
+ * last change: $Author: rt $ $Date: 2005-01-31 16:37:25 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright (c) 2003 by Sun Microsystems, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+// __________ Imports __________
+
+import com.sun.star.uno.UnoRuntime;
+
+import java.awt.*;
+import javax.swing.*;
+import java.lang.String;
+import java.awt.event.*;
+import java.awt.*;
+
+// __________ Implementation __________
+
+/**
+ * Makes it possible to change some states of currently loaded
+ * document (e.g. enable/disable menubar, toolbar, objectbar)
+ *
+ * @author Andreas Schlüns
+ * @created 20.06.2002 09:28
+ */
+public class CustomizeView extends JPanel
+ implements IShutdownListener
+{
+ // ____________________
+ // const
+
+ /**
+ * These const URL's describe feature for toggling some properties of loaded document.
+ * Dispatch it with the corresponding parameter to the frame.
+ */
+ private static final String FEATUREURL_MENUBAR = "slot:6661" ;
+ private static final String FEATUREURL_TOOLBAR = "slot:5909" ;
+ private static final String FEATUREURL_OBJECTBAR = "slot:5905" ;
+
+ private static final String FEATUREPROP_MENUBAR = "MenuBarVisible" ;
+ private static final String FEATUREPROP_TOOLBAR = "ToolBarVisible" ;
+ private static final String FEATUREPROP_OBJECTBAR = "ObjectBarVisible" ;
+
+ private static final String ACTION_MENUBAR = "toogle_menu" ;
+ private static final String ACTION_TOOLBAR = "toogle_toolbar" ;
+ private static final String ACTION_OBJECTBAR = "toogle_objectbar" ;
+
+ private static final String MENUBAR_ON = "menubar on" ;
+ private static final String TOOLBAR_ON = "toolbar on" ;
+ private static final String OBJECTBAR_ON = "objectbar on" ;
+
+ private static final String MENUBAR_OFF = "menubar off" ;
+ private static final String TOOLBAR_OFF = "toolbar off" ;
+ private static final String OBJECTBAR_OFF = "objectbar off" ;
+
+ // ____________________
+ // member
+
+ /**
+ * @member m_cbMenuBar reference to checkbox for toggling menubar
+ * @member m_cbToolBar reference to checkbox for toggling toolbar
+ * @member m_cbObjectBar reference to checkbox for toggling objectbar
+ *
+ * @member m_aMenuBarListener listener for status events of the menu bar
+ * @member m_aToolBarListener listener for status events of the tool bar
+ * @member m_aObjectBarListener listener for status events of the object bar
+ */
+ private JCheckBox m_cbMenuBar ;
+ private JCheckBox m_cbToolBar ;
+ private JCheckBox m_cbObjectBar ;
+
+ private StatusListener m_aMenuBarListener ;
+ private StatusListener m_aToolBarListener ;
+ private StatusListener m_aObjectBarListener;
+
+ // ____________________
+
+ /**
+ * ctor
+ * Create view controls on startup and initialize it.
+ * We don't start listening here. see setFrame()!
+ */
+ CustomizeView()
+ {
+ this.setLayout(new GridLayout(3,0));
+
+ m_cbMenuBar = new JCheckBox(MENUBAR_OFF , false);
+ m_cbToolBar = new JCheckBox(TOOLBAR_OFF , false);
+ m_cbObjectBar = new JCheckBox(OBJECTBAR_OFF, false);
+
+ m_cbMenuBar.setEnabled (false);
+ m_cbToolBar.setEnabled (false);
+ m_cbObjectBar.setEnabled(false);
+
+ m_cbMenuBar.setActionCommand (ACTION_MENUBAR );
+ m_cbToolBar.setActionCommand (ACTION_TOOLBAR );
+ m_cbObjectBar.setActionCommand(ACTION_OBJECTBAR);
+
+ this.add(m_cbMenuBar );
+ this.add(m_cbToolBar );
+ this.add(m_cbObjectBar);
+ }
+
+ // ____________________
+
+ /**
+ * set new frame for this view
+ * We start listening for frame action/status and click events instandly.
+ * If an event occure we use it to synchronize our controls
+ * with states of a (my be) new document view of this frame.
+ *
+ * @param xFrame
+ * the reference to the frame, which provides the
+ * possibility to get the required status informations
+ *
+ * Attention: We don't accept new frames here.
+ * We get one after startup and work with him.
+ * That's it!
+ */
+ public void setFrame(com.sun.star.frame.XFrame xFrame)
+ {
+ if (xFrame==null)
+ return;
+
+ // be listener for click events
+ // They will toogle the UI controls.
+ ClickListener aMenuBarHandler = new ClickListener(FEATUREURL_MENUBAR ,FEATUREPROP_MENUBAR ,xFrame);
+ ClickListener aToolBarHandler = new ClickListener(FEATUREURL_TOOLBAR ,FEATUREPROP_TOOLBAR ,xFrame);
+ ClickListener aObjectBarHandler = new ClickListener(FEATUREURL_OBJECTBAR,FEATUREPROP_OBJECTBAR,xFrame);
+
+ m_cbMenuBar.addActionListener (aMenuBarHandler );
+ m_cbToolBar.addActionListener (aToolBarHandler );
+ m_cbObjectBar.addActionListener(aObjectBarHandler);
+
+ // be frame action listener
+ // The callback will update listener connections
+ // for status updates automaticly!
+ m_aMenuBarListener = new StatusListener(m_cbMenuBar ,MENUBAR_ON ,MENUBAR_OFF ,xFrame, FEATUREURL_MENUBAR );
+ m_aToolBarListener = new StatusListener(m_cbToolBar ,TOOLBAR_ON ,TOOLBAR_OFF ,xFrame, FEATUREURL_TOOLBAR );
+ m_aObjectBarListener = new StatusListener(m_cbObjectBar,OBJECTBAR_ON,OBJECTBAR_OFF,xFrame, FEATUREURL_OBJECTBAR);
+
+ m_aMenuBarListener.startListening();
+ m_aToolBarListener.startListening();
+ m_aObjectBarListener.startListening();
+ }
+
+ // ____________________
+
+ /**
+ * react for click events of the used check boxes
+ * We use our internal set dispatch objects to
+ * call it. This calls toogle the menu/object- or toolbar.
+ * Note: Because we are listener status events too - hopefully
+ * we get a notification, if toogling was successfully or not.
+ * We use this information to update our check boxes again.
+ * But such update doesn't force (hopefully) an action event. Otherwhise
+ * we can produce a never ending recursion!
+ *
+ * @param aEvent
+ * describes the used check box and his current state
+ * we can use to dispatch the right URL to the office
+ */
+ class ClickListener implements ActionListener,
+ com.sun.star.lang.XEventListener
+ {
+ /// URL, to toogle the requested UI item
+ String m_sURL;
+ /// name of the property which must be used in combination with the URL
+ String m_sProp;
+ /// we must use this frame to dispatch a request
+ com.sun.star.frame.XFrame m_xFrame;
+
+ //_____________________
+
+ /**
+ * ctor
+ * It initialize an instance of this clas only.
+ */
+ ClickListener( String sURL ,
+ String sProp ,
+ com.sun.star.frame.XFrame xFrame )
+ {
+ m_sURL = sURL ;
+ m_sProp = sProp ;
+ m_xFrame = xFrame;
+ }
+
+ //_____________________
+
+ /**
+ * callback for action events
+ * Such events occure if somehwere click the
+ * JCheckBox control on which we are registered.
+ * Such events doesn't occure if we set it programmaticly
+ * (e.g. if we get status events to -> see class StatusListener too)
+ *
+ * @param aEvent
+ * describes the check box and his state
+ * we can use to toogle the requested office
+ * ressource.
+ */
+ public void actionPerformed(ActionEvent aEvent)
+ {
+ synchronized(this)
+ {
+ if (m_xFrame==null)
+ return;
+ }
+
+ // define parameters for following dispatch
+ boolean bState = ((JCheckBox)aEvent.getSource()).isSelected();
+
+ // prepare the dispatch
+ com.sun.star.util.URL aURL = FunctionHelper.parseURL(m_sURL);
+ if (aURL==null)
+ return;
+
+ com.sun.star.beans.PropertyValue[] lProperties = new com.sun.star.beans.PropertyValue[1];
+ lProperties[0] = new com.sun.star.beans.PropertyValue();
+ lProperties[0].Name = m_sProp;
+ lProperties[0].Value = new Boolean(bState);
+
+ // execute (dispatch) it into the frame
+ if (m_xFrame==null)
+ return;
+ FunctionHelper.execute(m_xFrame,aURL,lProperties,null);
+ }
+
+ // ____________________
+
+ /**
+ * callback for disposing events
+ * Internaly we save a reference to an office frame.
+ * Of course he can die and inform us then. We should react
+ * and forget his reference.
+ *
+ * @param aEvent
+ * describes the source which fire this event
+ * Must be our internal saved frame. Otherwhise
+ * somewhere know us without a registration ...
+ */
+ public void disposing(com.sun.star.lang.EventObject aEvent)
+ {
+ synchronized(this)
+ {
+ m_xFrame = null;
+ }
+ }
+ }
+
+ // ____________________
+
+ /**
+ * If this java application shutdown - we must cancel all current existing
+ * listener connections. Otherwhise the office will run into some
+ * DisposedExceptions if it tries to use these forgotten listener references.
+ * And of course it can die doing that.
+ * We are registered at a central object to be informed if the VM will exit.
+ * So we can react.
+ */
+ public void shutdown()
+ {
+ m_aMenuBarListener.shutdown();
+ m_aToolBarListener.shutdown();
+ m_aObjectBarListener.shutdown();
+
+ m_aMenuBarListener = null;
+ m_aToolBarListener = null;
+ m_aObjectBarListener = null;
+ }
+}
diff --git a/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/Desk.java b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/Desk.java
new file mode 100644
index 000000000000..42f47be0c1cd
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/Desk.java
@@ -0,0 +1,102 @@
+/*************************************************************************
+ *
+ * $RCSfile: Desk.java,v $
+ *
+ * $Revision: 1.5 $
+ *
+ * last change: $Author: rt $ $Date: 2005-01-31 16:37:37 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright (c) 2003 by Sun Microsystems, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+// __________ Imports __________
+
+import com.sun.star.uno.UnoRuntime;
+
+import java.lang.String;
+
+// __________ Implementation __________
+
+/**
+ * TODO
+ *
+ * @author Andreas Schlüns
+ * @created 08.02.2002 14:05
+ */
+public class Desk
+{
+ // ____________________
+
+ /**
+ * main
+ * Establish connection to a remote office and starts the demo application.
+ * User can overwrite some of neccessary start options by using command line parameters.
+ *
+ * syntax: Desk [mode={inplace|outplace}] [file=<filename>]
+ *
+ * @param args command line arguments
+ * mode describe using mode of document view {inplace/outplace}
+ * default=inplace
+ * file name of first file which should be open
+ * default="private:factory/swriter" to open empty writer document
+ */
+ public static void main(String[] lArguments)
+ {
+ // Analyze command line parameters.
+ String sMode = new String("inplace");
+ String sFile = new String("private:factory/swriter");
+
+ for(int i=0; i<lArguments.length; ++i)
+ {
+ lArguments[i] = lArguments[i].toLowerCase();
+ if(lArguments[i].startsWith("mode=")==true)
+ sMode = lArguments[i].substring(5);
+ else
+ if(lArguments[i].startsWith("file=")==true)
+ sFile = lArguments[i].substring(5);
+ }
+
+ ViewContainer.mbInplace = (sMode.compareTo("inplace")==0);
+
+ // Connect to remote office.
+ OfficeConnect.createConnection();
+
+ // Create first document view.
+ // This one will register himself at the global
+ // ViewContainer. Further views will be open
+ // automaticly started from this first one.
+ DocumentView aView = new DocumentView();
+ aView.setVisible(true);
+ aView.createFrame();
+ aView.load(sFile);
+ }
+}
diff --git a/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/DocumentView.java b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/DocumentView.java
new file mode 100644
index 000000000000..e0c7b2578898
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/DocumentView.java
@@ -0,0 +1,436 @@
+/*************************************************************************
+ *
+ * $RCSfile: DocumentView.java,v $
+ *
+ * $Revision: 1.4 $
+ *
+ * last change: $Author: rt $ $Date: 2005-01-31 16:37:50 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright (c) 2003 by Sun Microsystems, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+// __________ Imports __________
+
+import com.sun.star.uno.UnoRuntime;
+
+import java.awt.*;
+import java.awt.event.*;
+import java.lang.*;
+import java.net.*;
+import javax.swing.*;
+import javax.swing.border.*;
+import java.awt.AWTEvent;
+import java.awt.event.WindowEvent;
+
+// __________ Implementation __________
+
+/**
+ * This implement a java frame wich contains
+ * an office document, shows some status informations
+ * about that, provides simple functionality on it
+ * (e.g. toggle menubar, save document) and
+ * react for different situations independent
+ * (e.g. closing the document from outside).
+ * Every instance of this class will be a member
+ * inside the global "ViewContainer" of this java
+ * demo application which holds all opened views alive.
+ *
+ * @author Andreas Schl&uuml;ns
+ * @created 06.03.2002 09:38
+ */
+public class DocumentView extends JFrame
+ implements com.sun.star.lang.XEventListener, // react for Frame::disposing()
+ IShutdownListener // react for System.exit()
+{
+ // ____________________
+
+ /**
+ * const
+ * These command strings are used to identify a received action
+ * of buttons on which we listen for action events.
+ */
+ public static final String COMMAND_OPEN = "open" ;
+ public static final String COMMAND_SAVE = "save" ;
+ public static final String COMMAND_EXPORT = "export" ;
+ public static final String COMMAND_EXIT = "exit" ;
+
+ // ____________________
+
+ /**
+ * @member mxFrame office frame which contains the document of this view
+ *
+ * @member maStatusView special panel wich show available status informations of currently loaded document
+ * @member maDocumentView use JNI mechanism to plug an office window into our own java UI container (used for inplace mode only!)
+ * @member maCustomizeView special panel makes it possible to toggle menubar/toolbar or objectbar of loaded document
+ * @member maInterceptor interceptor thread which intercept "new" menu of office frame to open new frames inside this java application
+ *
+ * @member msName unique name of this view (returned by the global ViewContainer during registration)
+ *
+ * @member mbOpen button to open documents
+ * @member mbSave button to save currently loaded document
+ * @member mbExport button to save currently loaded document in HTML format (if it is possible!)
+ * @member mbExit button to exit this demo
+ *
+ * @member maInterception we try to intercept the file->new menu to open new document inside this java application
+ */
+ private com.sun.star.frame.XFrame mxFrame ;
+
+ private StatusView maStatusView ;
+ private NativeView maDocumentView ;
+ private CustomizeView maCustomizeView ;
+ private Interceptor maInterceptor ;
+
+ private String msName ;
+
+ private JButton mbtOpen ;
+ private JButton mbtSave ;
+ private JButton mbtExport ;
+ private JButton mbtExit ;
+
+ private boolean mbDead ;
+
+ // ____________________
+
+ /**
+ * ctor
+ * Create view controls on startup and initialize it with default values.
+ */
+ DocumentView()
+ {
+ this.setSize( new Dimension(800,600) );
+
+ JPanel paMainPanel = (JPanel)this.getContentPane();
+
+ // create and add command buttons to a panel
+ // it will be a sub panel of later layouted UI
+ mbtOpen = new JButton("Open ..." );
+ mbtSave = new JButton("Save" );
+ mbtExport = new JButton("Save as HTML ...");
+ mbtExit = new JButton("Exit" );
+
+ mbtOpen.setEnabled (true );
+ mbtSave.setEnabled (false);
+ mbtExport.setEnabled(false);
+ mbtExit.setEnabled (true );
+
+ mbtOpen.setActionCommand (COMMAND_OPEN );
+ mbtSave.setActionCommand (COMMAND_SAVE );
+ mbtExport.setActionCommand(COMMAND_EXPORT);
+ mbtExit.setActionCommand (COMMAND_EXIT );
+
+ Reactor aListener = new Reactor();
+ mbtOpen.addActionListener (aListener);
+ mbtSave.addActionListener (aListener);
+ mbtExport.addActionListener(aListener);
+ mbtExit.addActionListener (aListener);
+
+ JPanel paCommands = new JPanel( new GridLayout(4,0) );
+ paCommands.add(mbtOpen);
+ paCommands.add(mbtSave);
+ paCommands.add(mbtExport);
+ paCommands.add(mbtExit);
+
+ // create view to show status informations of opened file
+ maStatusView = new StatusView();
+
+ // create view for toggle different bar's of document
+ maCustomizeView = new CustomizeView();
+
+ paCommands.setBorder ( new TitledBorder(BorderFactory.createEtchedBorder(),"Commands") );
+ maStatusView.setBorder ( new TitledBorder(BorderFactory.createEtchedBorder(),"Status Informations") );
+ maCustomizeView.setBorder( new TitledBorder(BorderFactory.createEtchedBorder(),"Customize Document View") );
+
+ // layout the whole UI
+ JPanel paTest = new JPanel(new GridLayout(3,0));
+ paTest.add(paCommands );
+ paTest.add(maStatusView );
+ paTest.add(maCustomizeView);
+ JScrollPane paScroll = new JScrollPane();
+ paScroll.getViewport().add(paTest,null);
+
+ if(ViewContainer.mbInplace==true)
+ {
+ // create view to show opened documents
+ // This special view is neccessary for inplace mode only!
+ maDocumentView = new NativeView();
+
+ JSplitPane paSplit = new JSplitPane();
+ paSplit.setOneTouchExpandable( true );
+
+ paSplit.setLeftComponent (maDocumentView);
+ paSplit.setRightComponent(paScroll );
+
+ paMainPanel.add(paSplit);
+ }
+ else
+ {
+ paMainPanel.add(paScroll);
+ }
+
+ // Register this new view on our global view container.
+ msName = FunctionHelper.getUniqueFrameName();
+ this.setTitle(msName);
+ ViewContainer.getGlobalContainer().addView(this);
+ ViewContainer.getGlobalContainer().addListener(this);
+ // be listener for closing the application
+ this.enableEvents(AWTEvent.WINDOW_EVENT_MASK);
+ }
+
+ // ____________________
+
+ /**
+ * Create the view frame for showing the office documents on demand.
+ * Dependend from given command line parameter we create
+ * an office XFrame and initialize it with a window. This
+ * window can be a pure toolkit window (means toolkit of office!)
+ * or a plugged java canvas - office window combination.
+ */
+ public void createFrame()
+ {
+ // create view frame (as a XFrame!) here
+ // Look for right view mode setted by user command line parameter.
+ // First try to get a new unambigous frame name from our global ViewContainer.
+ if(ViewContainer.mbInplace==true)
+ {
+ // inplace document view can't be initialized without a visible parent window hierarchy!
+ // So make shure that we are visible in every case!
+ this.setVisible(true);
+ mxFrame = FunctionHelper.createViewFrame(msName,maDocumentView);
+ }
+ else
+ mxFrame = FunctionHelper.createViewFrame(msName,null);
+
+ if(mxFrame!=null)
+ {
+ // start interception
+ maInterceptor = new Interceptor(mxFrame);
+ maInterceptor.startListening();
+
+ // start listening for status events and actualization
+ // of our status view
+ // (of course for our CustomizeView too)
+ maStatusView.setFrame (mxFrame);
+ maCustomizeView.setFrame(mxFrame);
+
+ // be listener for closing the remote target view frame
+ com.sun.star.lang.XComponent xBroadcaster = (com.sun.star.lang.XComponent)UnoRuntime.queryInterface(
+ com.sun.star.lang.XComponent.class,
+ mxFrame);
+
+ if(xBroadcaster!=null)
+ xBroadcaster.addEventListener(this);
+ }
+ }
+
+ // ____________________
+
+ /**
+ * Different ways to load any URL from outside (may be by the command line)
+ * into this document view or to save it.
+ */
+ public void load(String sURL)
+ {
+ load(sURL,new com.sun.star.beans.PropertyValue[0]);
+ }
+
+ // ____________________
+
+ public void load(String sURL, com.sun.star.beans.PropertyValue[] lArguments)
+ {
+ com.sun.star.lang.XComponent xDocument = FunctionHelper.loadDocument(mxFrame,sURL,lArguments);
+ if(xDocument!=null)
+ {
+ mbtSave.setEnabled (true);
+ mbtExport.setEnabled(true);
+ }
+ else
+ {
+ mbtSave.setEnabled (false);
+ mbtExport.setEnabled(false);
+ }
+ }
+
+ // ____________________
+
+ public void save()
+ {
+ com.sun.star.frame.XController xController = mxFrame.getController();
+ if (xController==null)
+ return;
+ com.sun.star.frame.XModel xDocument = xController.getModel();
+ if (xDocument==null)
+ return;
+ FunctionHelper.saveDocument(xDocument);
+ }
+
+ // ____________________
+
+ public void exportHTML(String sURL)
+ {
+ com.sun.star.frame.XController xController = mxFrame.getController();
+ if (xController==null)
+ return;
+ com.sun.star.frame.XModel xDocument = xController.getModel();
+ if (xDocument==null)
+ return;
+ FunctionHelper.saveAsHTML(xDocument,sURL);
+ }
+
+ // ____________________
+
+ /**
+ * Overridden so we can react for window closing of this view.
+ */
+ protected void processWindowEvent(WindowEvent aEvent)
+ {
+ if (aEvent.getID()!=WindowEvent.WINDOW_CLOSING)
+ {
+ super.processWindowEvent(aEvent);
+ }
+ else
+ if (FunctionHelper.closeFrame(mxFrame))
+ {
+ mxFrame = null;
+ shutdown();
+ super.processWindowEvent(aEvent);
+ }
+ }
+
+ // ____________________
+
+ /**
+ * Here we can react for System.exit() normaly.
+ * But we use it for disposing() or windowClosing() too.
+ */
+ public void shutdown()
+ {
+ if (mbDead)
+ return;
+ mbDead=true;
+
+ // force these sub view to release her remote
+ // refrences too!
+ maStatusView.shutdown();
+ maCustomizeView.shutdown();
+
+ maStatusView = null;
+ maCustomizeView = null;
+
+ // disable all interceptions
+ maInterceptor.shutdown();
+ maInterceptor = null;
+
+ // close the frame and his document
+ // Relaesing of our listener connections for disposing()
+ // will be forced automaticly then. Because the frame
+ // will call us back ...
+ if (mxFrame!=null)
+ FunctionHelper.closeFrame(mxFrame);
+
+ // deregister this view in the global container
+ // Normaly we should die afterwards by garbage collection ...
+ // In cease this was the last view - it force a system.exit().
+ // But then we are no longer a member of the global container
+ // of possible shutdown listener ... and this method should be
+ // called again.
+ ViewContainer.getGlobalContainer().removeView(this);
+ }
+
+ // ____________________
+
+ /**
+ * callback from our internal saved frame
+ * which wish to die. Its not neccessary to remove listener connections
+ * here. Because the broadcaster do it automaticly.
+ * We have to release all references to him only.
+ *
+ * @param aSource
+ * describe the broadcaster of this event
+ * Must be our internal saved frame.
+ */
+ public void disposing(com.sun.star.lang.EventObject aSource)
+ {
+ mxFrame = null;
+ }
+
+ // ____________________
+
+ /**
+ * This inner class is used to react for events of our own UI controls.
+ * So we can start different actions then.
+ */
+ private class Reactor implements ActionListener
+ {
+ // ____________________
+
+ /**
+ * This method react for pressed buttons or selected check boxes.
+ */
+ public void actionPerformed(ActionEvent aEvent)
+ {
+ String sCommand = aEvent.getActionCommand();
+ //-----------------------------
+ // open any file from disk
+ if( sCommand.compareTo(COMMAND_OPEN) == 0 )
+ {
+ String sURL = FunctionHelper.askUserForFileURL(DocumentView.this,true);
+ if(sURL!=null)
+ DocumentView.this.load(sURL);
+ }
+ else
+ //-----------------------------
+ // save current document
+ if( sCommand.compareTo(COMMAND_SAVE) == 0 )
+ {
+ DocumentView.this.save();
+ }
+ else
+ //-----------------------------
+ // export current document to html
+ if( sCommand.compareTo(COMMAND_EXPORT) == 0 )
+ {
+ String sURL = FunctionHelper.askUserForFileURL(DocumentView.this,false);
+ if(sURL!=null)
+ DocumentView.this.exportHTML(sURL);
+ }
+ else
+ //-----------------------------
+ // exit application
+ if( sCommand.compareTo(COMMAND_EXIT) == 0 )
+ {
+ // This will force deleting of this and
+ // all other currently opened views automaticly!
+ System.exit(0);
+ }
+ }
+ }
+}
diff --git a/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/FunctionHelper.java b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/FunctionHelper.java
new file mode 100644
index 000000000000..6f0454c79fba
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/FunctionHelper.java
@@ -0,0 +1,1066 @@
+/*************************************************************************
+ *
+ * $RCSfile: FunctionHelper.java,v $
+ *
+ * $Revision: 1.5 $
+ *
+ * last change: $Author: kz $ $Date: 2005-03-01 12:09:15 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright (c) 2003 by Sun Microsystems, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+// __________ Imports __________
+
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.uno.AnyConverter;
+
+import java.lang.*;
+import java.awt.*;
+import javax.swing.*;
+import java.io.*;
+import java.net.*;
+
+// __________ Implementation __________
+
+/**
+ * Is a collection of basic features.
+ * This helper shows different functionality of framework api
+ * in an example manner. You can use the follow ones:
+ * (1) parse URL's
+ * (2) create frames (inside/outside a java application)
+ * (3) dispatches (with[out] notifications)
+ * (4) loading/saving documents
+ * (5) convert documents to HTML (if possible)
+ * (6) close documents (and her frames) correctly
+ *
+ * There exist some other helper functionality too, which
+ * doesn't use or demonstrate the office api:
+ * (a) getting file names by using a file chosser
+ *
+ * @author Andreas Schl&uuml;ns
+ * @created 28.02.2002 15:31
+ */
+public class FunctionHelper
+{
+ // ____________________
+
+ /**
+ * This convert an URL (formated as a string) to a struct com.sun.star.util.URL.
+ * It use a special service to do that: the URLTransformer.
+ * Because some API calls need it and it's not allowed to set "Complete"
+ * part of the util struct only. The URL must be parsed.
+ *
+ * @param sURL
+ * URL for parsing in string notation
+ *
+ * @return [com.sun.star.util.URL]
+ * URL in UNO struct notation
+ */
+ public static com.sun.star.util.URL parseURL(String sURL)
+ {
+ com.sun.star.util.URL aURL = null;
+
+ if (sURL==null || sURL.equals(""))
+ {
+ System.out.println("wrong using of URL parser");
+ return null;
+ }
+
+ try
+ {
+ com.sun.star.uno.XComponentContext xOfficeCtx =
+ OfficeConnect.getOfficeContext();
+
+ // Create special service for parsing of given URL.
+ com.sun.star.util.XURLTransformer xParser =
+ (com.sun.star.util.XURLTransformer)UnoRuntime.queryInterface(
+ com.sun.star.util.XURLTransformer.class,
+ xOfficeCtx.getServiceManager().createInstanceWithContext(
+ "com.sun.star.util.URLTransformer", xOfficeCtx));
+
+ // Because it's an in/out parameter we must use an array of URL objects.
+ com.sun.star.util.URL[] aParseURL = new com.sun.star.util.URL[1];
+ aParseURL[0] = new com.sun.star.util.URL();
+ aParseURL[0].Complete = sURL;
+
+ // Parse the URL
+ xParser.parseStrict(aParseURL);
+
+ aURL = aParseURL[0];
+ }
+ catch(com.sun.star.uno.RuntimeException exRuntime)
+ {
+ // Any UNO method of this scope can throw this exception.
+ // Reset the return value only.
+ aURL = null;
+ }
+ catch(com.sun.star.uno.Exception exUno)
+ {
+ // "createInstance()" method of used service manager can throw it.
+ // Then it wasn't possible to get the URL transformer.
+ // Return default instead of realy parsed URL.
+ aURL = null;
+ }
+
+ return aURL;
+ }
+
+ // ____________________
+
+ /**
+ * create a new empty target frame
+ * Attention: Currently we must use special service com.sun.star.frame.Task instead of Frame.
+ * Because desktop environment accept this special frame type only as direct children.
+ * Note - This service will be deprecated and must be replaces by com.sun.star.frame.Frame in
+ * further versions. To feature prove we use both service names. If for new versions
+ * the deprecated one not exist we get an empty frame, we can try to use the new service.
+ *
+ * @param xSMGR
+ * we nee the remote service manager to create this task/frame service
+ *
+ * @return [com.sun.star.frame.XFrame]
+ * the new created frame reference in case of success or null otherwhise
+ */
+ private static com.sun.star.frame.XFrame impl_createEmptyFrame(
+ com.sun.star.uno.XComponentContext xCtx )
+ {
+ com.sun.star.frame.XFrame xFrame = null;
+
+ try{
+ xFrame = (com.sun.star.frame.XFrame)UnoRuntime.queryInterface(
+ com.sun.star.frame.XFrame.class,
+ xCtx.getServiceManager().createInstanceWithContext(
+ "com.sun.star.frame.Task", xCtx));
+ } catch(com.sun.star.uno.Exception ex1) {}
+
+ if (xFrame==null)
+ {
+ try{
+ xFrame = (com.sun.star.frame.XFrame)UnoRuntime.queryInterface(
+ com.sun.star.frame.XFrame.class,
+ xCtx.getServiceManager().createInstanceWithContext(
+ "com.sun.star.frame.Frame", xCtx));
+ } catch(com.sun.star.uno.Exception ex2) {}
+ }
+
+ return xFrame;
+ }
+
+ // ____________________
+
+ /**
+ * create a new window which can be used as container window of an office frame
+ * We know two modes for creation:
+ * - the office window will be a child of one of our java windows
+ * - the office will be a normal system window outside this java application
+ * This behaviour will be regulated by the second parameter of this operation.
+ * If a parentview is given the first mode will be activated - otherwhise
+ * the second one.
+ *
+ * Note: First mode (creation of a child window) can be reached by two different
+ * ways.
+ * - pack the required window handle of our java window inside an UNO object
+ * to transport it to the remote office toolkit and get a child office
+ * window.
+ * This is the old way. It's better to use the second one - but to be
+ * future prove this old one should be tried too.
+ * - it's possible to pass the native window handle directly to the toolkit.
+ * A special interface method was enabled to accept that.
+ *
+ * The right way to create an office window should be then:
+ * - try to use second creation mode (directly using of the window handle)
+ * - if it failed ... use the old way by packing the handle inside an object
+ *
+ * @param xSMGR
+ * we need a service manager to be able to create remote office
+ * services
+ *
+ * @param aParentView
+ * the java window as parent for the office window if an inplace office
+ * is required. If it is set to null the created office window will be
+ * a normal system window outside of our java application.
+ *
+ * @return [com.sun.star.awt.XWindow]
+ * The new created office window which can be used to set it as
+ * a ContainerWindow on an empty office frame.
+ */
+ private static com.sun.star.awt.XWindow impl_createWindow(
+ com.sun.star.uno.XComponentContext xCtx, NativeView aParentView )
+ {
+ com.sun.star.awt.XWindow xWindow = null;
+ com.sun.star.awt.XWindowPeer xPeer = null;
+ com.sun.star.awt.XToolkit xToolkit = null;
+
+ // get access to toolkit of remote office to create the container window of
+ // new target frame
+ try{
+ xToolkit = (com.sun.star.awt.XToolkit)UnoRuntime.queryInterface(
+ com.sun.star.awt.XToolkit.class,
+ xCtx.getServiceManager().createInstanceWithContext(
+ "com.sun.star.awt.Toolkit", xCtx));
+ }
+ catch(com.sun.star.uno.Exception ex)
+ {
+ return null;
+ }
+
+ // mode 1) create an external system window
+ if (aParentView==null)
+ {
+ // Describe the properties of the container window.
+ com.sun.star.awt.WindowDescriptor aDescriptor =
+ new com.sun.star.awt.WindowDescriptor();
+ aDescriptor.Type = com.sun.star.awt.WindowClass.TOP;
+ aDescriptor.WindowServiceName = "window";
+ aDescriptor.ParentIndex = -1;
+ aDescriptor.Parent = null;
+ aDescriptor.Bounds = new com.sun.star.awt.Rectangle(0,0,0,0);
+ aDescriptor.WindowAttributes = com.sun.star.awt.WindowAttribute.BORDER |
+ com.sun.star.awt.WindowAttribute.MOVEABLE |
+ com.sun.star.awt.WindowAttribute.SIZEABLE |
+ com.sun.star.awt.WindowAttribute.CLOSEABLE;
+
+ try{
+ xPeer = xToolkit.createWindow( aDescriptor );
+ } catch(com.sun.star.lang.IllegalArgumentException exIllegal) {}
+ }
+ // mode 2) create an internal office window as child of our given java
+ // parent window
+ else
+ {
+ // try new version of creation first: directly using of the window
+ // handle. The old implementation of the corresponding toolkit method
+ // requires a process ID. If this id isn't the right one a null object
+ // is returned. But normaly nobody outside the office knows this id.
+ // New version of this method ignore the id parameter and creation will
+ // work.
+ // Note: You must be shure if your window handle can be realy used by
+ // the remote office. Means if this java client and the remote office
+ // use the same display!
+ com.sun.star.awt.XSystemChildFactory xChildFactory =
+ (com.sun.star.awt.XSystemChildFactory)UnoRuntime.queryInterface(
+ com.sun.star.awt.XSystemChildFactory.class, xToolkit);
+
+ try
+ {
+ Integer nHandle = aParentView.getHWND();
+ short nSystem = (short)aParentView.getNativeWindowSystemType();
+ byte[] lProcID = new byte[0];
+
+ xPeer = xChildFactory.createSystemChild((Object)nHandle,
+ lProcID, nSystem);
+
+ if (xPeer==null)
+ {
+ // mode 3) OK - new version doesn't work. It requires the
+ // process id which we doesn't have.
+ // So we must use the old way to get the right window peer.
+ // Pack the handle inside a wrapper object.
+ JavaWindowPeerFake aWrapper = new
+ JavaWindowPeerFake(aParentView);
+
+ com.sun.star.awt.XWindowPeer xParentPeer =
+ (com.sun.star.awt.XWindowPeer)UnoRuntime.queryInterface(
+ com.sun.star.awt.XWindowPeer.class, aWrapper);
+
+ com.sun.star.awt.WindowDescriptor aDescriptor =
+ new com.sun.star.awt.WindowDescriptor();
+ aDescriptor.Type = com.sun.star.awt.WindowClass.TOP;
+ aDescriptor.WindowServiceName = "workwindow";
+ aDescriptor.ParentIndex = 1;
+ aDescriptor.Parent = xParentPeer;
+ aDescriptor.Bounds = new com.sun.star.awt.Rectangle(0,0,0,0);
+ if (nSystem == com.sun.star.lang.SystemDependent.SYSTEM_WIN32)
+ aDescriptor.WindowAttributes =
+ com.sun.star.awt.WindowAttribute.SHOW;
+ else
+ aDescriptor.WindowAttributes =
+ com.sun.star.awt.WindowAttribute.SYSTEMDEPENDENT;
+
+ try{
+ xPeer = xToolkit.createWindow( aDescriptor );
+ } catch(com.sun.star.lang.IllegalArgumentException exIllegal) {}
+ }
+ }
+ catch(java.lang.RuntimeException exJRun)
+ {
+ // This exception is thrown by the native JNI code if it try to get
+ // the systemw window handle. A possible reason can be an invisible
+ // java window. In this case it should be enough to set return
+ // values to null. All other ressources (which was created before)
+ // will be freed automaticly if scope wil be leaved.
+ System.out.println("May be the NativeView object wasn't realy visible at calling time of getNativeWindow()?");
+ xPeer = null;
+ xWindow = null;
+ }
+ }
+
+ // It doesn't matter which way was used to get the window peer.
+ // Cast it to the right return interface and return it.
+ xWindow = (com.sun.star.awt.XWindow)UnoRuntime.queryInterface(
+ com.sun.star.awt.XWindow.class,
+ xPeer);
+
+ return xWindow;
+ }
+
+ // ____________________
+
+ /**
+ * This method create a new empty child frame on desktop instance of remote office.
+ * It use a special JNI functionality to pass the office XWindow over a java window.
+ * This java window can be inserted into another java window container for complex layouting.
+ * If this parent java window isn't used, a top level system window will be created.
+ * The the resulting office frame isn't plugged into this java application.
+ *
+ * @param sName
+ * name to set it on the new created frame
+ *
+ * @param aParentView
+ * java window which should be used as parent window of new created office frame window
+ * May be set to null.
+ *
+ * @return [com.sun.star.frame.XFrame]
+ * reference to the new created frame for success or null if it failed
+ */
+ public static com.sun.star.frame.XFrame createViewFrame(String sName, NativeView aParentView)
+ {
+ com.sun.star.frame.XFrame xFrame = null;
+
+ try
+ {
+ com.sun.star.uno.XComponentContext xCtx =
+ OfficeConnect.getOfficeContext();
+
+ // create an empty office frame first
+ xFrame = impl_createEmptyFrame(xCtx);
+
+ // create an office window then
+ // Depending from the given parameter aParentView it will be a child or a top level
+ // system window. (see impl method for further informations)
+ // But before we call this helper - prepare the possible parent window: show it.
+ // JNI calls to get system window handle of java window can't work without that!
+ if (aParentView!=null)
+ aParentView.setVisible(true);
+ com.sun.star.awt.XWindow xWindow = impl_createWindow(xCtx, aParentView);
+
+ // pass the window the frame as his new container window.
+ // It's neccessary to do it first - before you call anything else there.
+ // Otherwhise the frame throws some exceptions for "uninitialized state".
+ xFrame.initialize( xWindow );
+
+ // Insert the new frame in desktop hierarchy.
+ // Use XFrames interface to do so. It provides access to the child frame container of that instance.
+ com.sun.star.frame.XFramesSupplier xTreeRoot = (com.sun.star.frame.XFramesSupplier)UnoRuntime.queryInterface(
+ com.sun.star.frame.XFramesSupplier.class,
+ xCtx.getServiceManager().createInstanceWithContext(
+ "com.sun.star.frame.Desktop", xCtx));
+ com.sun.star.frame.XFrames xChildContainer = xTreeRoot.getFrames();
+ xChildContainer.append(xFrame);
+
+ // Make some further initializations on frame and window.
+ xWindow.setVisible(true);
+ xFrame.setName(sName);
+ }
+ catch(com.sun.star.uno.RuntimeException exRuntime)
+ {
+ // Any UNO method of this scope can throw this exception.
+ // So the frame can be already created and he must be freed
+ // correctly. May be he was inserted into the desktop tree too ...
+ if(xFrame!=null)
+ {
+ // Try to dispose the frame. He should deregister himself at the desktop object
+ // and free all internal used ressources (e.g. the container window) automaticly.
+ // It's possible to do that here - because frame has no component inside yet.
+ // So nobody can disagree with that.
+ // After the dispose() call forget all references to this frame and let him die.
+ // If a new exception will occure ... no generell solution exist then.
+ // Nobody can guarantee if next call will work or not.
+ com.sun.star.lang.XComponent xComponent = (com.sun.star.lang.XComponent)UnoRuntime.queryInterface(
+ com.sun.star.lang.XComponent.class,
+ xFrame);
+ xComponent.dispose();
+ xComponent = null;
+ xFrame = null;
+ }
+ }
+ catch(com.sun.star.uno.Exception exUno)
+ {
+ // "createInstance()" method of used service manager can throw it.
+ // If it occured during creation of desktop service the frame already was created.
+ // Free it by decresing his refcount. Changes on the desktop tree couldn't exist.
+ // Without the desktop service that wasn't possible. So no further rollbacks must follow.
+ if(xFrame!=null)
+ {
+ com.sun.star.lang.XComponent xComponent = (com.sun.star.lang.XComponent)UnoRuntime.queryInterface(
+ com.sun.star.lang.XComponent.class,
+ xFrame);
+ xComponent.dispose();
+ xComponent = null;
+ xFrame = null;
+ }
+ }
+
+ return xFrame;
+ }
+
+ // ____________________
+
+ /**
+ * Dispatch an URL to given frame.
+ * Caller can register himself for following status events for dispatched
+ * URL too. But nobody guarantee that such notifications will occure.
+ * (see dispatchWithNotification() if you interest on that)
+ * The returned dispatch object should be hold alive by caller
+ * till he deosn't need it any longer. Otherwise the dispatcher can(!)
+ * die by decreasing his refcount.
+ *
+ * @param xFrame frame wich should be the target of this dispatch
+ * @param aURL full parsed and converted office URL for dispatch
+ * @param lProperties optional arguments for dispatch
+ * @param xListener optional listener which is registered automaticly for status events
+ * (Note: Deregistration is part of this listener himself!)
+ *
+ * @return [XDispatch] It's the used dispatch object and can be used for deregistration of an optional listener.
+ * Otherwhise caller can ignore it.
+ */
+ public static com.sun.star.frame.XDispatch execute(com.sun.star.frame.XFrame xFrame ,
+ com.sun.star.util.URL aURL ,
+ com.sun.star.beans.PropertyValue[] lProperties,
+ com.sun.star.frame.XStatusListener xListener )
+ {
+ com.sun.star.frame.XDispatch xDispatcher = null;
+
+ try
+ {
+ // Query the frame for right interface which provides access to all available dispatch objects.
+ com.sun.star.frame.XDispatchProvider xProvider = (com.sun.star.frame.XDispatchProvider)UnoRuntime.queryInterface(
+ com.sun.star.frame.XDispatchProvider.class,
+ xFrame);
+
+ // Ask himn for right dispatch object for given URL.
+ // Force given frame as target for following dispatch by using "".
+ // It means the same like "_self".
+ xDispatcher = xProvider.queryDispatch(aURL,"",0);
+
+ // Dispatch the URL into the frame.
+ if(xDispatcher!=null)
+ {
+ if(xListener!=null)
+ xDispatcher.addStatusListener(xListener,aURL);
+
+ xDispatcher.dispatch(aURL,lProperties);
+ }
+ }
+ catch(com.sun.star.uno.RuntimeException exUno)
+ {
+ // Any UNO method of this scope can throw this exception.
+ // But there will be nothing to do then - because
+ // we haven't changed anything inside the remote objects
+ // except method "addStatusListener().
+ // But in this case the source of this exception has to
+ // rollback all his operations. There is no chance to
+ // make anything right then.
+ // Reset the return value to a default - that's it.
+ exUno.printStackTrace();
+ xDispatcher = null;
+ }
+
+ return xDispatcher;
+ }
+
+ // ____________________
+
+ /**
+ * Dispatch an URL to given frame.
+ * Caller can register himself for following result events for dispatched
+ * URL too. Notifications are guaranteed (instead of dispatch())
+ * Returning of the dispatch object isn't neccessary.
+ * Nobody must hold it alive longer the dispatch needs.
+ *
+ * @param xFrame frame wich should be the target of this dispatch
+ * @param aURL full parsed and converted office URL for dispatch
+ * @param lProperties optional arguments for dispatch
+ * @param xListener optional listener which is registered automaticly for status events
+ * (Note: Deregistration is not supported. Dispatcher does it automaticly.)
+ */
+ public static void executeWithNotification(com.sun.star.frame.XFrame xFrame ,
+ com.sun.star.util.URL aURL ,
+ com.sun.star.beans.PropertyValue[] lProperties,
+ com.sun.star.frame.XDispatchResultListener xListener )
+ {
+ try
+ {
+ // Query the frame for right interface which provides access to all available dispatch objects.
+ com.sun.star.frame.XDispatchProvider xProvider = (com.sun.star.frame.XDispatchProvider)UnoRuntime.queryInterface(
+ com.sun.star.frame.XDispatchProvider.class,
+ xFrame);
+
+ // Ask himn for right dispatch object for given URL.
+ // Force THIS frame as target for following dispatch.
+ // Attention: The interface XNotifyingDispatch is an optional one!
+ com.sun.star.frame.XDispatch xDispatcher = xProvider.queryDispatch(aURL,"",0);
+ com.sun.star.frame.XNotifyingDispatch xNotifyingDispatcher = (com.sun.star.frame.XNotifyingDispatch)UnoRuntime.queryInterface(
+ com.sun.star.frame.XNotifyingDispatch.class,
+ xDispatcher);
+
+ // Dispatch the URL.
+ if(xNotifyingDispatcher!=null)
+ xNotifyingDispatcher.dispatchWithNotification(aURL,lProperties,xListener);
+ }
+ catch(com.sun.star.uno.RuntimeException exUno)
+ {
+ // Any UNO method of this scope can throw this exception.
+ // But there is nothing we can do then.
+ exUno.printStackTrace();
+ }
+ }
+
+ // ____________________
+
+ /**
+ * Load document specified by an URL into given frame synchronously.
+ * The result of this operation will be the loaded document for success
+ * or null if loading failed.
+ *
+ * @param xFrame frame wich should be the target of this load call
+ * @param sURL unparsed URL for loading
+ * @param lProperties optional arguments
+ *
+ * @return [XComponent] the loaded document for success or null if it's failed
+ */
+ public static com.sun.star.lang.XComponent loadDocument(
+ com.sun.star.frame.XFrame xFrame, String sURL,
+ com.sun.star.beans.PropertyValue[] lProperties)
+ {
+ com.sun.star.lang.XComponent xDocument = null;
+ String sOldName = null;
+
+ try
+ {
+ com.sun.star.uno.XComponentContext xCtx =
+ OfficeConnect.getOfficeContext();
+
+ // First prepare frame for loading
+ // We must adress it inside the frame tree without any complications.
+ // So we set an unambigous (we hope it) name and use it later.
+ // Don't forget to reset original name after that.
+ sOldName = xFrame.getName();
+ String sTarget = "odk_officedev_desk";
+ xFrame.setName(sTarget);
+
+ // Get access to the global component loader of the office
+ // for synchronous loading the document.
+ com.sun.star.frame.XComponentLoader xLoader =
+ (com.sun.star.frame.XComponentLoader)UnoRuntime.queryInterface(
+ com.sun.star.frame.XComponentLoader.class,
+ xCtx.getServiceManager().createInstanceWithContext(
+ "com.sun.star.frame.Desktop", xCtx));
+
+ // Load the document into the target frame by using his name and
+ // special search flags.
+ xDocument = xLoader.loadComponentFromURL(
+ sURL,
+ sTarget,
+ com.sun.star.frame.FrameSearchFlag.CHILDREN,
+ lProperties);
+
+ // dont forget to restore old frame name ...
+ xFrame.setName(sOldName);
+ }
+ catch(com.sun.star.io.IOException exIO)
+ {
+ // Can be thrown by "loadComponentFromURL()" call.
+ // The only thing we should do then is to reset changed frame name!
+ exIO.printStackTrace();
+ xDocument = null;
+ if(sOldName!=null)
+ xFrame.setName(sOldName);
+ }
+ catch(com.sun.star.lang.IllegalArgumentException exIllegal)
+ {
+ // Can be thrown by "loadComponentFromURL()" call.
+ // The only thing we should do then is to reset changed frame name!
+ exIllegal.printStackTrace();
+ xDocument = null;
+ if(sOldName!=null)
+ xFrame.setName(sOldName);
+ }
+ catch(com.sun.star.uno.RuntimeException exRuntime)
+ {
+ // Any UNO method of this scope can throw this exception.
+ // The only thing we can try(!) is to reset changed frame name.
+ exRuntime.printStackTrace();
+ xDocument = null;
+ if(sOldName!=null)
+ xFrame.setName(sOldName);
+ }
+ catch(com.sun.star.uno.Exception exUno)
+ {
+ // "createInstance()" method of used service manager can throw it.
+ // The only thing we should do then is to reset changed frame name!
+ exUno.printStackTrace();
+ xDocument = null;
+ if(sOldName!=null)
+ xFrame.setName(sOldName);
+ }
+
+ return xDocument;
+ }
+
+ // ____________________
+
+ /**
+ * Save currently loaded document of given frame.
+ *
+ * @param xDocument document for saving changes
+ */
+ public static void saveDocument(com.sun.star.lang.XComponent xDocument)
+ {
+ try
+ {
+ // Check for supported model functionality.
+ // Normaly the application documents (text, spreadsheet ...) do so
+ // but some other ones (e.g. db components) doesn't do that.
+ // They can't be save then.
+ com.sun.star.frame.XModel xModel = (com.sun.star.frame.XModel)UnoRuntime.queryInterface(
+ com.sun.star.frame.XModel.class,
+ xDocument);
+ if(xModel!=null)
+ {
+ // Check for modifications => break save process if there is nothing to do.
+ com.sun.star.util.XModifiable xModified = (com.sun.star.util.XModifiable)UnoRuntime.queryInterface(
+ com.sun.star.util.XModifiable.class,
+ xModel);
+ if(xModified.isModified()==true)
+ {
+ com.sun.star.frame.XStorable xStore = (com.sun.star.frame.XStorable)UnoRuntime.queryInterface(
+ com.sun.star.frame.XStorable.class,
+ xModel);
+
+ xStore.store();
+ }
+ }
+ }
+ catch(com.sun.star.io.IOException exIO)
+ {
+ // Can be thrown by "store()" call.
+ // But there is nothing we can do then.
+ exIO.printStackTrace();
+ }
+ catch(com.sun.star.uno.RuntimeException exUno)
+ {
+ // Any UNO method of this scope can throw this exception.
+ // But there is nothing we can do then.
+ exUno.printStackTrace();
+ }
+ }
+
+ // ____________________
+
+ /**
+ * It try to export given document in HTML format.
+ * Current document will be converted to HTML and moved to new place on disk.
+ * A "new" file will be created by given URL (may be overwritten
+ * if it already exist). Right filter will be used automaticly if factory of
+ * this document support it. If no valid filter can be found for export,
+ * nothing will be done here.
+ *
+ * @param xDocument document which should be exported
+ * @param sURL target URL for converted document
+ */
+ public static void saveAsHTML(com.sun.star.lang.XComponent xDocument,
+ String sURL )
+ {
+ try
+ {
+ // First detect factory of this document.
+ // Ask for the supported service name of this document.
+ // If information is available it can be used to find out wich
+ // filter exist for HTML export. Normaly this filter should be searched
+ // inside the filter configuration but this little demo doesn't do so.
+ // (see service com.sun.star.document.FilterFactory for further
+ // informations too)
+ // Well known filter names are used directly. They must exist in current
+ // office installation. Otherwise this code will fail. But to prevent
+ // this code against missing filters it check for existing state of it.
+ com.sun.star.lang.XServiceInfo xInfo = (com.sun.star.lang.XServiceInfo)
+ UnoRuntime.queryInterface(com.sun.star.lang.XServiceInfo.class,
+ xDocument);
+
+ if(xInfo!=null)
+ {
+ // Find out possible filter name.
+ String sFilter = null;
+ if(xInfo.supportsService("com.sun.star.text.TextDocument")==true)
+ sFilter = new String("HTML (StarWriter)");
+ else
+ if(xInfo.supportsService("com.sun.star.text.WebDocument")==true)
+ sFilter = new String("HTML");
+ else
+ if(xInfo.supportsService("com.sun.star.sheet.SpreadsheetDocument")==true)
+ sFilter = new String("HTML (StarCalc)");
+
+ // Check for existing state of this filter.
+ if(sFilter!=null)
+ {
+ com.sun.star.uno.XComponentContext xCtx =
+ OfficeConnect.getOfficeContext();
+
+ com.sun.star.container.XNameAccess xFilterContainer =
+ (com.sun.star.container.XNameAccess)
+ UnoRuntime.queryInterface(
+ com.sun.star.container.XNameAccess.class,
+ xCtx.getServiceManager().createInstanceWithContext(
+ "com.sun.star.document.FilterFactory", xCtx));
+
+ if(xFilterContainer.hasByName(sFilter)==false)
+ sFilter=null;
+ }
+
+ // Use this filter for export.
+ if(sFilter!=null)
+ {
+ // Export can be forced by saving the document and using a
+ // special filter name which can write needed format. Build
+ // neccessary argument list now.
+ // Use special flag "Overwrite" too, to prevent operation
+ // against possible exceptions, if file already exist.
+ com.sun.star.beans.PropertyValue[] lProperties =
+ new com.sun.star.beans.PropertyValue[2];
+ lProperties[0] = new com.sun.star.beans.PropertyValue();
+ lProperties[0].Name = "FilterName";
+ lProperties[0].Value = sFilter;
+ lProperties[1] = new com.sun.star.beans.PropertyValue();
+ lProperties[1].Name = "Overwrite";
+ lProperties[1].Value = Boolean.TRUE;
+
+ com.sun.star.frame.XStorable xStore =
+ (com.sun.star.frame.XStorable)UnoRuntime.queryInterface(
+ com.sun.star.frame.XStorable.class, xDocument);
+
+ xStore.storeAsURL(sURL,lProperties);
+ }
+ }
+ }
+ catch(com.sun.star.io.IOException exIO)
+ {
+ // Can be thrown by "store()" call.
+ // Do nothing then. Saving failed - that's it.
+ exIO.printStackTrace();
+ }
+ catch(com.sun.star.uno.RuntimeException exRuntime)
+ {
+ // Can be thrown by any uno call.
+ // Do nothing here. Saving failed - that's it.
+ exRuntime.printStackTrace();
+ }
+ catch(com.sun.star.uno.Exception exUno)
+ {
+ // Can be thrown by "createInstance()" call of service manager.
+ // Do nothing here. Saving failed - that's it.
+ exUno.printStackTrace();
+ }
+ }
+
+ // ____________________
+
+ /**
+ * Try to close the document without any saving of modifications.
+ * We can try it only! Controller and/or model of this document
+ * can disagree with that. But mostly they doesn't do so.
+ *
+ * @param xDocument document which should be clcosed
+ */
+ public static void closeDocument(com.sun.star.lang.XComponent xDocument)
+ {
+ try
+ {
+ // Check supported functionality of the document (model or controller).
+ com.sun.star.frame.XModel xModel =
+ (com.sun.star.frame.XModel)UnoRuntime.queryInterface(
+ com.sun.star.frame.XModel.class, xDocument);
+
+ if(xModel!=null)
+ {
+ // It's a full featured office document.
+ // Reset the modify state of it and close it.
+ // Note: Model can disgree by throwing a veto exception.
+ com.sun.star.util.XModifiable xModify =
+ (com.sun.star.util.XModifiable)UnoRuntime.queryInterface(
+ com.sun.star.util.XModifiable.class, xModel);
+
+ xModify.setModified(false);
+ xDocument.dispose();
+ }
+ else
+ {
+ // It's a document which supports a controller .. or may by a pure
+ // window only. If it's at least a controller - we can try to
+ // suspend him. But - he can disagree with that!
+ com.sun.star.frame.XController xController =
+ (com.sun.star.frame.XController)UnoRuntime.queryInterface(
+ com.sun.star.frame.XController.class, xDocument);
+
+ if(xController!=null)
+ {
+ if(xController.suspend(true)==true)
+ {
+ // Note: Don't dispose the controller - destroy the frame
+ // to make it right!
+ com.sun.star.frame.XFrame xFrame = xController.getFrame();
+ xFrame.dispose();
+ }
+ }
+ }
+ }
+ catch(com.sun.star.beans.PropertyVetoException exVeto)
+ {
+ // Can be thrown by "setModified()" call on model.
+ // He disagree with our request.
+ // But there is nothing to do then. Following "dispose()" call wasn't
+ // never called (because we catch it before). Closing failed -that's it.
+ exVeto.printStackTrace();
+ }
+ catch(com.sun.star.lang.DisposedException exDisposed)
+ {
+ // If an UNO object was already disposed before - he throw this special
+ // runtime exception. Of course every UNO call must be look for that -
+ // but it's a question of error handling.
+ // For demonstration this exception is handled here.
+ exDisposed.printStackTrace();
+ }
+ catch(com.sun.star.uno.RuntimeException exRuntime)
+ {
+ // Every uno call can throw that.
+ // Do nothing - closing failed - that's it.
+ exRuntime.printStackTrace();
+ }
+ }
+
+ // ____________________
+
+ /**
+ * Try to close the frame instead of the document.
+ * It shows the possible interface to do so.
+ *
+ * @param xFrame
+ * frame which should be clcosed
+ *
+ * @return <TRUE/> in case frame could be closed
+ * <FALSE/> otherwise
+ */
+ public static boolean closeFrame(com.sun.star.frame.XFrame xFrame)
+ {
+ boolean bClosed = false;
+
+ try
+ {
+ // first try the new way: use new interface XCloseable
+ // It replace the deprecated XTask::close() and should be preferred ...
+ // if it can be queried.
+ com.sun.star.util.XCloseable xCloseable =
+ (com.sun.star.util.XCloseable)UnoRuntime.queryInterface(
+ com.sun.star.util.XCloseable.class, xFrame);
+ if (xCloseable!=null)
+ {
+ // We deliver the owner ship of this frame not to the (possible)
+ // source which throw a CloseVetoException. We whishto have it
+ // under our own control.
+ try
+ {
+ xCloseable.close(false);
+ bClosed = true;
+ }
+ catch( com.sun.star.util.CloseVetoException exVeto )
+ {
+ bClosed = false;
+ }
+ }
+ else
+ {
+ // OK: the new way isn't possible. Try the old one.
+ com.sun.star.frame.XTask xTask = (com.sun.star.frame.XTask)
+ UnoRuntime.queryInterface(com.sun.star.frame.XTask.class,
+ xFrame);
+ if (xTask!=null)
+ {
+ // return value doesn't interest here. Because
+ // we forget this task ...
+ bClosed = xTask.close();
+ }
+ }
+ }
+ catch (com.sun.star.lang.DisposedException exDisposed)
+ {
+ // Of course - this task can be already dead - means disposed.
+ // But for us it's not important. Because we tried to close it too.
+ // And "already disposed" or "closed" should be the same ...
+ bClosed = true;
+ }
+
+ return bClosed;
+ }
+
+ // ____________________
+
+ /**
+ * Try to find an unique frame name, which isn't currently used inside
+ * remote office instance. Because we create top level frames
+ * only, it's enough to check the names of existing child frames on the
+ * desktop only.
+ *
+ * @return [String]
+ * should represent an unique frame name, which currently isn't
+ * used inside the remote office frame tree
+ * (Couldn't guaranteed for a real multithreaded environment.
+ * But we try it ...)
+ */
+ private static final String BASEFRAMENAME = "Desk View ";
+
+ public static String getUniqueFrameName()
+ {
+ String sName = null;
+
+ com.sun.star.uno.XComponentContext xCtx = OfficeConnect.getOfficeContext();
+
+ try
+ {
+ com.sun.star.frame.XFramesSupplier xSupplier =
+ (com.sun.star.frame.XFramesSupplier)UnoRuntime.queryInterface(
+ com.sun.star.frame.XFramesSupplier.class,
+ xCtx.getServiceManager().createInstanceWithContext(
+ "com.sun.star.frame.Desktop", xCtx));
+
+ com.sun.star.container.XIndexAccess xContainer =
+ (com.sun.star.container.XIndexAccess)UnoRuntime.queryInterface(
+ com.sun.star.container.XIndexAccess.class,
+ xSupplier.getFrames());
+
+ int nCount = xContainer.getCount();
+ for (int i=0; i<nCount; ++i )
+ {
+ com.sun.star.frame.XFrame xFrame = (com.sun.star.frame.XFrame)AnyConverter.toObject(new com.sun.star.uno.Type(com.sun.star.frame.XFrame.class), xContainer.getByIndex(i));
+ sName = new String(BASEFRAMENAME+mnViewCount);
+ while(sName.compareTo(xFrame.getName())==0)
+ {
+ ++mnViewCount;
+ sName = new String(BASEFRAMENAME+mnViewCount);
+ }
+ }
+ }
+ catch(com.sun.star.uno.Exception exCreateFailed)
+ {
+ sName = new String(BASEFRAMENAME);
+ }
+
+ if (sName==null)
+ {
+ System.out.println("invalid name!");
+ sName = new String(BASEFRAMENAME);
+ }
+
+ return sName;
+ }
+
+ // ____________________
+
+ /**
+ * helper to get a file URL selected by user
+ * This method doesn't show any API concepts ...
+ * but is neccessary rof this demo application.
+ *
+ * @param aParent parent window of this dialog
+ * @param bOpen If it is set to true =>
+ * dialog is opend in "file open" mode -
+ * otherwise in "file save" mode.
+ */
+ public static String askUserForFileURL(Component aParent,boolean bOpen)
+ {
+ String sFileURL = null;
+ int nDecision = JFileChooser.CANCEL_OPTION;
+ JFileChooser aChooser = null;
+
+ // set last visited directory on new file chosser
+ // (if this information is available)
+ if( maLastDir==null )
+ aChooser = new JFileChooser();
+ else
+ aChooser = new JFileChooser(maLastDir);
+
+ // decide between file open/save dialog
+ if( bOpen==true )
+ nDecision = aChooser.showOpenDialog(aParent);
+ else
+ nDecision = aChooser.showSaveDialog(aParent);
+
+ // react for "OK" result only
+ if(nDecision == JFileChooser.APPROVE_OPTION)
+ {
+ // save current directory as last visited one
+ maLastDir = aChooser.getCurrentDirectory();
+ // get file URL from the dialog
+ try
+ {
+ sFileURL = aChooser.getSelectedFile().toURL().toExternalForm();
+ }
+ catch( MalformedURLException ex )
+ {
+ ex.printStackTrace();
+ sFileURL = null;
+ }
+ // problem of java: file URL's are coded with 1 slash instead of 3 ones!
+ // => correct this problem first, otherwise office can't use these URL's
+ if(
+ ( sFileURL !=null ) &&
+ ( sFileURL.startsWith("file:/") ==true ) &&
+ ( sFileURL.startsWith("file://")==false )
+ )
+ {
+ StringBuffer sWorkBuffer = new StringBuffer(sFileURL);
+ sWorkBuffer.insert(6,"//");
+ sFileURL = sWorkBuffer.toString();
+ }
+ }
+
+ return sFileURL;
+ }
+
+ // ____________________
+
+ /**
+ * @member maLastDir save the last visited directory of used file open/save dialog
+ * @member mnViewCount we try to set unique names on every frame we create (that's why we must count it)
+ */
+ private static File maLastDir = null;
+ private static int mnViewCount = 0 ;
+}
diff --git a/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/IOnewayLink.java b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/IOnewayLink.java
new file mode 100644
index 000000000000..d3fce206b3bb
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/IOnewayLink.java
@@ -0,0 +1,76 @@
+/*************************************************************************
+ *
+ * $RCSfile: IOnewayLink.java,v $
+ *
+ * $Revision: 1.4 $
+ *
+ * last change: $Author: rt $ $Date: 2005-01-31 16:38:16 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright (c) 2003 by Sun Microsystems, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import java.util.Vector;
+
+// __________ Implementation __________
+
+/**
+ * We need a generic interface to forward any oneway uno interface method
+ * by using threads to the original object. Reason:
+ * It's not allowed to call synchronoues back to the office if a java object
+ * was called in a oneway declared interface method. Then it must be
+ * executed asynchronoues. To do so - a thread can be created which use this
+ * interface. It get the object, which whis to be called back and the type and
+ * parameter of the original request.
+ *
+ * @author Andreas Schl&uuml;ns
+ * @created 17.07.2002 08:09
+ */
+public interface IOnewayLink
+{
+ // _______________________________
+
+ /**
+ * @param nRequest
+ * The two user of this callback can define an unique number,
+ * which identify the type of original interface method. So the called
+ * interface object can decide, which action will be neccessary.
+ *
+ * @param lParams
+ * If the original method used parameters, they will be coded here in
+ * a generic way. Only the called interface object know (it depends
+ * from the original request - see nRequest too), how this list must
+ * be interpreted.
+ * Note: Atomic types (e.g. int, long) will be transported as objects
+ * too (Integer, Long)!
+ */
+ public abstract void execOneway( int nRequest, Vector lParams );
+}
diff --git a/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/IShutdownListener.java b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/IShutdownListener.java
new file mode 100644
index 000000000000..71bd0b4b3cff
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/IShutdownListener.java
@@ -0,0 +1,53 @@
+/*************************************************************************
+ *
+ * $RCSfile: IShutdownListener.java,v $
+ *
+ * $Revision: 1.4 $
+ *
+ * last change: $Author: rt $ $Date: 2005-01-31 16:38:31 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright (c) 2003 by Sun Microsystems, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+// __________ Implementation __________
+
+/**
+ * Listener interface to get information about application shutdown
+ * if java virtual machine dies.
+ *
+ * @author Andreas Schl&uuml;ns
+ * @created 03.05.2002 13:51
+ */
+public interface IShutdownListener
+{
+ public abstract void shutdown();
+}
diff --git a/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/Install.txt b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/Install.txt
new file mode 100644
index 000000000000..fc7c95afbb98
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/Install.txt
@@ -0,0 +1,10 @@
+(1) goto "./nativelib/<platform>" directory and build it
+(2) build this directory
+(3) expand your class path to include all jar files of an office installation
+ (means all files in path "<officeinst>/program/classes")
+(4) goto "api/<platform>/class"
+(5) copy from an existing java installation the runtime library "jawt" (e.g. jawt.dll for windows)
+ into this directory
+(6) copy "api/<platform>/bin/nativelib.dll" (for windows) to "api/<platform>/class"
+(7) start an office : "soffice -accept=socket,host=localhost,port=2083;urp;"
+(8) goto "api/<platform>/class" and start java applet: "java -jar desktop.jar"
diff --git a/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/Interceptor.java b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/Interceptor.java
new file mode 100644
index 000000000000..5865c65c2463
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/Interceptor.java
@@ -0,0 +1,678 @@
+/*************************************************************************
+ *
+ * $RCSfile: Interceptor.java,v $
+ *
+ * $Revision: 1.4 $
+ *
+ * last change: $Author: rt $ $Date: 2005-01-31 16:38:44 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright (c) 2003 by Sun Microsystems, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+// __________ Imports __________
+
+import com.sun.star.uno.UnoRuntime;
+
+import java.lang.*;
+import javax.swing.*;
+import java.util.Vector;
+
+// __________ Implementation __________
+
+/**
+ * This class can be used to intercept dispatched URL's
+ * on any frame used in this demo application.
+ * It intercept all URL's wich try to create a new empty frame.
+ * (e.g. "private:factory/swriter")
+ * Nobody can guarantee that this interception will be realy used -
+ * because another interceptor (registered at a later time then this one!)
+ * will be called before this one.
+ * Implementation is executed inside a new thread to prevent application
+ * against possible deadlocks. This deadlocks can occure if
+ * synchronous/asynchronous ... normal ones and oneway calls are mixed.
+ * Notifications of listener will be oneway mostly - her reactions can
+ * be synchronous then. => deadlocks are possible
+ *
+ * @author Andreas Schl&uuml;ns
+ * @created 06.03.2002 09:38
+ */
+public class Interceptor implements com.sun.star.frame.XFrameActionListener,
+ com.sun.star.frame.XDispatchProviderInterceptor,
+ com.sun.star.frame.XDispatchProvider,
+ com.sun.star.frame.XDispatch,
+ com.sun.star.frame.XInterceptorInfo,
+ IShutdownListener,
+ IOnewayLink
+{
+ // ____________________
+
+ /**
+ * const
+ * All these URL's are intercepted by this implementation.
+ */
+ private static final String[] INTERCEPTED_URLS = { "private:factory/*" ,
+ ".uno:SaveAs" ,
+ "slot:5300" ,
+ ".uno:Quit" };
+
+ // ____________________
+
+ /**
+ * @member m_xMaster use this interceptor if he doesn't handle queried dispatch request
+ * @member m_xSlave we can forward all unhandled requests to this slave interceptor
+ * @member m_xFrame intercepted frame
+ * @member m_bDead there exist more then one way to finish an object of this class - we must know it sometimes
+ */
+ private com.sun.star.frame.XDispatchProvider m_xMaster ;
+ private com.sun.star.frame.XDispatchProvider m_xSlave ;
+ private com.sun.star.frame.XFrame m_xFrame ;
+ private boolean m_bIsActionListener ;
+ private boolean m_bIsRegistered ;
+ private boolean m_bDead ;
+
+ // ____________________
+
+ /**
+ * ctor
+ * Initialize the new interceptor. Given frame reference can be used to
+ * register this interceptor on it automaticly later.
+ *
+ * @seealso startListening()
+ *
+ * @param xFrame
+ * this interceptor will register himself at this frame to intercept dispatched URLs
+ */
+ Interceptor(/*IN*/ com.sun.star.frame.XFrame xFrame)
+ {
+ m_xFrame = xFrame ;
+ m_xSlave = null ;
+ m_xMaster = null ;
+ m_bIsRegistered = false ;
+ m_bIsActionListener = false ;
+ m_bDead = false ;
+ }
+
+ //_____________________
+
+ /**
+ * start working as frame action listener realy.
+ * We will be frame action listener here. In case
+ * we get a frame action which indicates, that we should
+ * update our interception. Because such using of an interecptor
+ * isn't guaranteed - in case a newer one was registered ...
+ */
+ public void startListening()
+ {
+ com.sun.star.frame.XFrame xFrame = null;
+ synchronized(this)
+ {
+ if (m_bDead)
+ return;
+ if (m_xFrame==null)
+ return;
+ if (m_bIsActionListener==true)
+ return;
+ xFrame = m_xFrame;
+ }
+ m_xFrame.addFrameActionListener(this);
+ synchronized(this)
+ {
+ m_bIsActionListener=true;
+ }
+ }
+
+ //_____________________
+
+ /**
+ * In case we got an oneway listener callback - we had to use the office
+ * asynchronous then. This method is the callback from the started thread
+ * (started inside the original oneway method). We found all parameters of
+ * the original request packed inside a vector. Here we unpack it and
+ * call the right internal helper method, which implements the right
+ * funtionality.
+ *
+ * @seealso frameAction()
+ * @seealso dispatch()
+ *
+ * @param nRequest
+ * indicates, which was the original request (identifies the
+ * original called method)
+ *
+ * @param lParams
+ * the vector with all packed parameters of the original request
+ */
+ public void execOneway(/*IN*/ int nRequest,/*IN*/ Vector lParams )
+ {
+ synchronized(this)
+ {
+ if (m_bDead)
+ return;
+ }
+
+ // was it frameAction()?
+ if (nRequest==OnewayExecutor.REQUEST_FRAMEACTION)
+ {
+ com.sun.star.frame.FrameActionEvent[] lOutAction = new com.sun.star.frame.FrameActionEvent[1];
+ Vector[] lInParams = new Vector[1];
+ lInParams[0] = lParams;
+
+ OnewayExecutor.codeFrameAction( OnewayExecutor.DECODE_PARAMS ,
+ lInParams ,
+ lOutAction );
+ impl_frameAction(lOutAction[0]);
+ }
+ else
+ // was it dispatch()?
+ if (nRequest==OnewayExecutor.REQUEST_DISPATCH)
+ {
+ com.sun.star.util.URL[] lOutURL = new com.sun.star.util.URL[1];
+ com.sun.star.beans.PropertyValue[][] lOutProps = new com.sun.star.beans.PropertyValue[1][];
+ Vector[] lInParams = new Vector[1];
+ lInParams[0] = lParams;
+
+ OnewayExecutor.codeDispatch( OnewayExecutor.DECODE_PARAMS ,
+ lInParams ,
+ lOutURL ,
+ lOutProps );
+ impl_dispatch(lOutURL[0],lOutProps[0]);
+ }
+ }
+
+ // ____________________
+
+ /**
+ * call back for frame action events
+ * We use it to update our interception. Because if a new component was loaded into
+ * the frame or another interceptor was registered, we should refresh our connection
+ * to the frame. Otherwhise we can't guarantee full functionality here.
+ *
+ * Note: Don't react synchronous in an asynchronous listener callback. So use a thread
+ * here to update anything.
+ *
+ * @seealso impl_frameAction()
+ *
+ * @param aEvent
+ * describes the action
+ */
+ public /*ONEWAY*/ void frameAction(/*IN*/ com.sun.star.frame.FrameActionEvent aEvent)
+ {
+ synchronized(this)
+ {
+ if (m_bDead)
+ return;
+ }
+
+ boolean bHandle = false;
+ switch(aEvent.Action.getValue())
+ {
+ case com.sun.star.frame.FrameAction.COMPONENT_ATTACHED_value : bHandle=true; break;
+ case com.sun.star.frame.FrameAction.COMPONENT_DETACHING_value : bHandle=true; break;
+ case com.sun.star.frame.FrameAction.COMPONENT_REATTACHED_value : bHandle=true; break;
+ // Don't react for CONTEXT_CHANGED here. Ok it indicates, that may another interceptor
+ // was registered at the frame ... but if we register ourself there - we get a context
+ // changed too :-( Best way to produce a never ending recursion ...
+ // May be that somewhere find a safe mechanism to detect own produced frame action events
+ // and ignore it.
+ case com.sun.star.frame.FrameAction.CONTEXT_CHANGED_value :
+ System.out.println("Time to update interception ... but may it will start a recursion. So I let it :-(");
+ bHandle=false;
+ break;
+ }
+
+ // ignore some events
+ if (! bHandle)
+ return;
+
+ // pack the event and start thread - which call us back later
+ Vector[] lOutParams = new Vector[1];
+ com.sun.star.frame.FrameActionEvent[] lInAction = new com.sun.star.frame.FrameActionEvent[1];
+ lInAction[0] = aEvent;
+
+ OnewayExecutor.codeFrameAction( OnewayExecutor.ENCODE_PARAMS ,
+ lOutParams ,
+ lInAction );
+ OnewayExecutor aExecutor = new OnewayExecutor( (IOnewayLink)this ,
+ OnewayExecutor.REQUEST_FRAMEACTION ,
+ lOutParams[0] );
+ aExecutor.start();
+ }
+
+ // ____________________
+
+ /**
+ * Indicates using of us as an interceptor.
+ * Now we have to react for the requests, we are registered.
+ * That means: load new empty documents - triggered by the new menu of the office.
+ * Because it's oneway - use thread for loading!
+ *
+ * @seealso impl_dispatch()
+ *
+ * @param aURL
+ * describes the document, which should be loaded
+ *
+ * @param lArguments
+ * optional parameters for loading
+ */
+ public /*ONEWAY*/ void dispatch(/*IN*/ com.sun.star.util.URL aURL,/*IN*/ com.sun.star.beans.PropertyValue[] lArguments)
+ {
+ synchronized(this)
+ {
+ if (m_bDead)
+ return;
+ }
+
+ Vector[] lOutParams = new Vector[1];
+ com.sun.star.util.URL[] lInURL = new com.sun.star.util.URL[1];
+ com.sun.star.beans.PropertyValue[][] lInArguments = new com.sun.star.beans.PropertyValue[1][];
+ lInURL[0] = aURL ;
+ lInArguments[0] = lArguments;
+
+ OnewayExecutor.codeDispatch( OnewayExecutor.ENCODE_PARAMS ,
+ lOutParams ,
+ lInURL ,
+ lInArguments );
+ OnewayExecutor aExecutor = new OnewayExecutor( (IOnewayLink)this ,
+ OnewayExecutor.REQUEST_DISPATCH ,
+ lOutParams[0] );
+ aExecutor.start();
+ }
+
+
+ //_____________________
+
+ /**
+ * Internal call back for frame action events, triggered by the used
+ * OnewayExecutor thread we started in frameAction().
+ * We use it to update our interception on the internal saved frame.
+ *
+ * @param aEvent
+ * describes the action
+ */
+ public void impl_frameAction(/*IN*/ com.sun.star.frame.FrameActionEvent aEvent)
+ {
+ synchronized(this)
+ {
+ if (m_bDead)
+ return;
+ }
+
+ // deregistration will be done everytime ...
+ // But may it's not neccessary to establish a new registration!
+ // Don't look for ignoring actions - it was done already inside original frameAction() call!
+ boolean bRegister = false;
+
+ // analyze the event and decide which reaction is usefull
+ switch(aEvent.Action.getValue())
+ {
+ case com.sun.star.frame.FrameAction.COMPONENT_ATTACHED_value : bRegister = true ; break;
+ case com.sun.star.frame.FrameAction.COMPONENT_REATTACHED_value : bRegister = true ; break;
+ case com.sun.star.frame.FrameAction.COMPONENT_DETACHING_value : bRegister = false; break;
+ }
+
+ com.sun.star.frame.XFrame xFrame = null ;
+ boolean bIsRegistered = false;
+ synchronized(this)
+ {
+ bIsRegistered = m_bIsRegistered;
+ m_bIsRegistered = false;
+ xFrame = m_xFrame;
+ }
+
+ com.sun.star.frame.XDispatchProviderInterception xRegistration = (com.sun.star.frame.XDispatchProviderInterception)UnoRuntime.queryInterface(
+ com.sun.star.frame.XDispatchProviderInterception.class,
+ xFrame);
+
+ if(xRegistration==null)
+ return;
+
+ if (bIsRegistered)
+ xRegistration.releaseDispatchProviderInterceptor(this);
+
+ if (! bRegister)
+ return;
+
+ xRegistration.registerDispatchProviderInterceptor(this);
+ synchronized(this)
+ {
+ m_bIsRegistered = true;
+ }
+ }
+
+ // ____________________
+
+ /**
+ * Implementation of interface XDispatchProviderInterceptor
+ * These functions are used to build a list of interceptor objects
+ * connected in both ways.
+ * Searching for a right interceptor is made by forwarding any request
+ * from toppest master to lowest slave of this hierarchy.
+ * If an interceptor whish to handle the request he can break that
+ * and return himself as a dispatcher.
+ */
+ public com.sun.star.frame.XDispatchProvider getSlaveDispatchProvider()
+ {
+ synchronized(this)
+ {
+ return m_xSlave;
+ }
+ }
+
+ // ____________________
+
+ public void setSlaveDispatchProvider(com.sun.star.frame.XDispatchProvider xSlave)
+ {
+ synchronized(this)
+ {
+ m_xSlave = xSlave;
+ }
+ }
+
+ // ____________________
+
+ public com.sun.star.frame.XDispatchProvider getMasterDispatchProvider()
+ {
+ synchronized(this)
+ {
+ return m_xMaster;
+ }
+ }
+
+ // ____________________
+
+ public void setMasterDispatchProvider(com.sun.star.frame.XDispatchProvider xMaster)
+ {
+ synchronized(this)
+ {
+ m_xMaster = xMaster;
+ }
+ }
+
+ // ____________________
+
+ /**
+ * Implementation of interface XDispatchProvider
+ * These functions are called from our master if he willn't handle the outstanding request.
+ * Given parameter should be checked if they are right for us. If it's true, the returned
+ * dispatcher should be this implementation himself; otherwise call should be forwarded
+ * to the slave.
+ *
+ * @param aURL
+ * describes the request, which should be handled
+ *
+ * @param sTarget
+ * specifies the target frame for this request
+ *
+ * @param nSearchFlags
+ * optional search flags, if sTarget isn't a special one
+ *
+ * @return [XDispatch]
+ * a dispatch object, which can handle the given URL
+ * May be NULL!
+ */
+ public com.sun.star.frame.XDispatch queryDispatch(/*IN*/ com.sun.star.util.URL aURL,/*IN*/ String sTarget,/*IN*/ int nSearchFlags)
+ {
+ synchronized(this)
+ {
+ if (m_bDead)
+ return null;
+ }
+
+ // intercept loading empty documents into new created frames
+ if(
+ (sTarget.compareTo ("_blank" ) == 0 ) &&
+ (aURL.Complete.startsWith("private:factory") == true)
+ )
+ {
+ System.out.println("intercept private:factory");
+ return this;
+ }
+
+ // intercept opening the SaveAs dialog
+ if (aURL.Complete.startsWith(".uno:SaveAs") == true)
+ {
+ System.out.println("intercept SaveAs by returning null!");
+ return null;
+ }
+
+ // intercept "File->Exit" inside the menu
+ if (
+ (aURL.Complete.startsWith("slot:5300") == true) ||
+ (aURL.Complete.startsWith(".uno:Quit") == true)
+ )
+ {
+ System.out.println("intercept File->Exit");
+ return this;
+ }
+
+ synchronized(this)
+ {
+ if (m_xSlave!=null)
+ return m_xSlave.queryDispatch(aURL, sTarget, nSearchFlags);
+ }
+
+ return null;
+ }
+
+ // ____________________
+
+ public com.sun.star.frame.XDispatch[] queryDispatches(/*IN*/ com.sun.star.frame.DispatchDescriptor[] lDescriptor)
+ {
+ synchronized(this)
+ {
+ if (m_bDead)
+ return null;
+ }
+ // Resolve any request seperatly by using own "dispatch()" method.
+ // Note: Don't pack return list if "null" objects occure!
+ int nCount = lDescriptor.length;
+ com.sun.star.frame.XDispatch[] lDispatcher = new com.sun.star.frame.XDispatch[nCount];
+ for(int i=0; i<nCount; ++i)
+ {
+ lDispatcher[i] = queryDispatch(lDescriptor[i].FeatureURL ,
+ lDescriptor[i].FrameName ,
+ lDescriptor[i].SearchFlags);
+ }
+ return lDispatcher;
+ }
+
+ // ____________________
+
+ /**
+ * This method is called if this interceptor "wins the request".
+ * We intercepted creation of new frames and loading of empty documents.
+ * Do it now.
+ *
+ * @param aURL
+ * describes the document
+ *
+ * @param lArguments
+ * optional arguments for loading
+ */
+ public void impl_dispatch(/*IN*/ com.sun.star.util.URL aURL,/*IN*/ com.sun.star.beans.PropertyValue[] lArguments)
+ {
+ synchronized(this)
+ {
+ if (m_bDead)
+ return;
+ }
+
+ if (
+ (aURL.Complete.startsWith("slot:5300") == true) ||
+ (aURL.Complete.startsWith(".uno:Quit") == true)
+ )
+ {
+ System.exit(0);
+ }
+ else
+ if (aURL.Complete.startsWith("private:factory") == true)
+ {
+ // Create view frame for showing loaded documents on demand.
+ // The visible state is neccessary for JNI functionality to get the HWND and plug office
+ // inside a java window hierarchy!
+ DocumentView aNewView = new DocumentView();
+ aNewView.setVisible(true);
+ aNewView.createFrame();
+ aNewView.load(aURL.Complete,lArguments);
+ }
+ }
+
+ // ____________________
+
+ /**
+ * Notification of status listener isn't guaranteed (instead of listener on XNotifyingDispatch interface).
+ * So this interceptor doesn't support that realy ...
+ */
+ public /*ONEWAY*/ void addStatusListener(/*IN*/ com.sun.star.frame.XStatusListener xListener,/*IN*/ com.sun.star.util.URL aURL)
+ {
+/* if (aURL.Complete.startsWith(".uno:SaveAs")==true)
+ {
+ com.sun.star.frame.FeatureStateEvent aEvent = new com.sun.star.frame.FeatureStateEvent(
+ this,
+ aURL,
+ "",
+ false,
+ false,
+ null);
+ if (xListener!=null)
+ {
+ System.out.println("interceptor disable SavAs by listener notify");
+ xListener.statusChanged(aEvent);
+ }
+ }*/
+ }
+
+ // ____________________
+
+ public /*ONEWAY*/ void removeStatusListener(/*IN*/ com.sun.star.frame.XStatusListener xListener,/*IN*/ com.sun.star.util.URL aURL)
+ {
+ }
+
+ // ____________________
+
+ /**
+ * Implements (optional!) optimization for interceptor mechanism.
+ * Any interceptor which provides this special interface is called automaticly
+ * at registration time on this method. Returned URL's will be used to
+ * call this interceptor directly without calling his masters before, IF(!)
+ * following rules will be true:
+ * (1) every master supports this optional interface too
+ * (2) nobody of these masters whish to intercept same URL then this one
+ * This interceptor whish to intercept creation of new documents.
+ */
+ public String[] getInterceptedURLs()
+ {
+ return INTERCEPTED_URLS;
+ }
+
+ // ____________________
+
+ /**
+ * This class listen on the intercepted frame to free all used ressources on closing.
+ * We forget the reference to the frame only here. Deregistration
+ * isn't neccessary here - because this frame dies and wish to forgoten.
+ *
+ * @param aSource
+ * must be our internal saved frame, on which we listen for frame action events
+ */
+ public /*ONEAY*/ void disposing(/*IN*/ com.sun.star.lang.EventObject aSource)
+ {
+ synchronized(this)
+ {
+ if (m_bDead)
+ return;
+ if (m_xFrame!=null && UnoRuntime.areSame(aSource.Source,m_xFrame))
+ {
+ m_bIsActionListener = false;
+ m_xFrame = null ;
+ }
+ }
+ shutdown();
+ }
+
+ // ____________________
+
+ /**
+ * If this java application shutdown - we must cancel all current existing
+ * listener connections. Otherwhise the office will run into some
+ * DisposedExceptions if it tries to use these forgotten listener references.
+ * And of course it can die doing that.
+ * We are registered at a central object to be informed if the VM will exit.
+ * So we can react.
+ */
+ public void shutdown()
+ {
+ com.sun.star.frame.XFrame xFrame = null ;
+ boolean bIsRegistered = false;
+ boolean bIsActionListener = false;
+ synchronized(this)
+ {
+ // don't react a second time here!
+ if (m_bDead)
+ return;
+ m_bDead = true;
+
+ bIsRegistered = m_bIsRegistered;
+ m_bIsRegistered = false;
+
+ bIsActionListener = m_bIsActionListener;
+ m_bIsActionListener = false;
+
+ xFrame = m_xFrame;
+ m_xFrame = null;
+ }
+
+ // it's a good idead to cancel listening for frame action events
+ // before(!) we deregister us as an interceptor.
+ // Because registration and deregistratio nof interceptor objects
+ // will force sending of frame action events ...!
+ if (bIsActionListener)
+ xFrame.removeFrameActionListener(this);
+
+ if (bIsRegistered)
+ {
+ com.sun.star.frame.XDispatchProviderInterception xRegistration = (com.sun.star.frame.XDispatchProviderInterception)UnoRuntime.queryInterface(
+ com.sun.star.frame.XDispatchProviderInterception.class,
+ xFrame);
+
+ if(xRegistration!=null)
+ xRegistration.releaseDispatchProviderInterceptor(this);
+ }
+
+ xFrame = null;
+
+ synchronized(this)
+ {
+ m_xMaster = null;
+ m_xSlave = null;
+ }
+ }
+}
diff --git a/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/JavaWindowPeerFake.java b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/JavaWindowPeerFake.java
new file mode 100644
index 000000000000..bbaa451f3d67
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/JavaWindowPeerFake.java
@@ -0,0 +1,113 @@
+/*************************************************************************
+ *
+ * $RCSfile: JavaWindowPeerFake.java,v $
+ *
+ * $Revision: 1.4 $
+ *
+ * last change: $Author: rt $ $Date: 2005-01-31 16:38:57 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright (c) 2003 by Sun Microsystems, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import java.awt.*;
+
+
+/** <p>Class to pass the system window handle to the OpenOffice.org toolkit.</p>
+ */
+class JavaWindowPeerFake implements com.sun.star.awt.XSystemDependentWindowPeer,
+ com.sun.star.awt.XWindowPeer
+{
+ NativeView maView;
+
+ public JavaWindowPeerFake(NativeView aNative)
+ {
+ maView = aNative;
+ }
+
+ // ____________________
+ /**
+ * Implementation of XSystemDependentWindowPeer (that's all we really need).
+ * This method is called back from the Office toolkit to retrieve the system data.
+ */
+ public java.lang.Object getWindowHandle(byte[] aProcessId, short aSystem)
+ throws com.sun.star.uno.RuntimeException
+ {
+ Object aReturn = null;
+ if(aSystem==maView.maSystem)
+ aReturn = (Object)maView.maHandle;
+ return aReturn;
+ }
+
+ /** not really neaded.
+ */
+ public com.sun.star.awt.XToolkit getToolkit()
+ throws com.sun.star.uno.RuntimeException
+ {
+ return null;
+ }
+
+ public void setPointer(com.sun.star.awt.XPointer xPointer)
+ throws com.sun.star.uno.RuntimeException
+ {
+ }
+
+ public void setBackground(int nColor)
+ throws com.sun.star.uno.RuntimeException
+ {
+ }
+
+ public void invalidate(short nFlags)
+ throws com.sun.star.uno.RuntimeException
+ {
+ }
+
+ public void invalidateRect(com.sun.star.awt.Rectangle aRect,short nFlags)
+ throws com.sun.star.uno.RuntimeException
+ {
+ }
+
+ public void dispose()
+ throws com.sun.star.uno.RuntimeException
+ {
+ }
+
+ public void addEventListener(com.sun.star.lang.XEventListener xListener)
+ throws com.sun.star.uno.RuntimeException
+ {
+ }
+
+ public void removeEventListener(com.sun.star.lang.XEventListener xListener)
+ throws com.sun.star.uno.RuntimeException
+ {
+ }
+}
+
diff --git a/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/Makefile b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/Makefile
new file mode 100644
index 000000000000..5faa381b140a
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/Makefile
@@ -0,0 +1,134 @@
+#*************************************************************************
+#
+# $RCSfile: Makefile,v $
+#
+# $Revision: 1.6 $
+#
+# last change: $Author: rt $ $Date: 2005-03-29 12:11:20 $
+#
+# The Contents of this file are made available subject to the terms of
+# the BSD license.
+#
+# Copyright (c) 2003 by Sun Microsystems, Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+# 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+# contributors may be used to endorse or promote products derived
+# from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+#**************************************************************************
+
+# Builds the OfficeDevDestopEnvironment example of the Developers Guide.
+
+PRJ=../../../..
+SETTINGS=$(PRJ)/settings
+
+include $(SETTINGS)/settings.mk
+include $(SETTINGS)/std.mk
+include $(SETTINGS)/dk.mk
+
+# Define non-platform/compiler specific settings
+EXAMPLE_NAME=OfficeDevDesktopEnv
+OUT_APP_CLASS = $(OUT_CLASS)/$(EXAMPLE_NAME)
+
+APP1_NAME=DesktopExample
+APP1_JAR=$(OUT_APP_CLASS)/$(APP1_NAME).jar
+
+APP1_JAVAFILES = \
+ CustomizeView.java \
+ Desk.java \
+ DocumentView.java \
+ FunctionHelper.java \
+ Interceptor.java \
+ IOnewayLink.java \
+ IShutdownListener.java \
+ JavaWindowPeerFake.java \
+ NativeView.java \
+ OfficeConnect.java \
+ OnewayExecutor.java \
+ StatusListener.java \
+ StatusView.java \
+ ViewContainer.java
+
+APP1_CLASSFILES = $(patsubst %.java,$(OUT_APP_CLASS)/%.class,$(APP1_JAVAFILES))
+APP1_CLASSNAMES = $(patsubst %.java,%.class,$(APP1_JAVAFILES)) \
+ CustomizeView$(QUOTE)$$ClickListener.class \
+ DocumentView$(QUOTE)$$1.class \
+ DocumentView$(QUOTE)$$Reactor.class
+
+
+SDK_CLASSPATH = $(subst $(EMPTYSTRING) $(PATH_SEPARATOR),$(PATH_SEPARATOR),$(CLASSPATH)\
+ $(PATH_SEPARATOR)$(OUT_APP_CLASS))
+
+ifeq "$(OS)" "WIN"
+SUBDIR= nativelib/windows
+else
+SUBDIR= nativelib/unix
+endif
+
+# Targets
+.PHONY: ALL
+ALL : $(SUBDIR) \
+ $(EXAMPLE_NAME)
+
+include $(SETTINGS)/stdtarget.mk
+
+.PHONY : $(SUBDIR)
+$(SUBDIR) :
+ $(MAKE) -C $@
+
+$(APP1_CLASSFILES) : $(APP1_JAVAFILES)
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(SDK_JAVAC) $(JAVAC_FLAGS) -classpath "$(SDK_CLASSPATH)" -d $(OUT_APP_CLASS) $(APP1_JAVAFILES)
+
+$(OUT_APP_CLASS)/$(APP1_NAME).mf :
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ @echo Main-Class: com.sun.star.lib.loader.Loader> $@
+ $(ECHOLINE)>> $@
+ @echo Name: com/sun/star/lib/loader/Loader.class>> $@
+ @echo Application-Class: Desk>> $@
+
+$(APP1_JAR) : $(OUT_APP_CLASS)/$(APP1_NAME).mf $(APP1_CLASSFILES)
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ +cd $(subst /,$(PS),$(OUT_APP_CLASS)) && $(SDK_JAR) cvfm $(@F) $(basename $(@F)).mf $(APP1_CLASSNAMES)
+ +$(SDK_JAR) uvf $@ $(SDK_JAVA_UNO_BOOTSTRAP_FILES)
+
+$(EXAMPLE_NAME) : $(APP1_JAR)
+ @echo --------------------------------------------------------------------------------
+ @echo Please use the following command to execute the example!
+ @echo -
+ @echo $(MAKE) DesktopExample.run
+ @echo ------
+ @echo If you want to run the $(JAR1_JAR) file please set your
+ @echo CLASSPATH = $(SDK_CLASSPATH)
+ @echo Start the example with jar -jar $(JAR1_JAR)
+ @echo --------------------------------------------------------------------------------
+
+%.run: $(OUT_APP_CLASS)/%.jar
+ $(SDK_JAVA) -Dcom.sun.star.lib.loader.unopath="$(OFFICE_PROGRAM_PATH)" -jar $<
+
+.PHONY: clean
+clean :
+ $(MAKE) -C $(SUBDIR) clean
+ -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_APP_CLASS))
diff --git a/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/NativeView.java b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/NativeView.java
new file mode 100644
index 000000000000..b9853f9037d5
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/NativeView.java
@@ -0,0 +1,188 @@
+/*************************************************************************
+ *
+ * $RCSfile: NativeView.java,v $
+ *
+ * $Revision: 1.4 $
+ *
+ * last change: $Author: rt $ $Date: 2005-01-31 16:39:23 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright (c) 2003 by Sun Microsystems, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+// __________ Imports __________
+
+import java.awt.*;
+import java.lang.*;
+import java.awt.event.*;
+
+// __________ Implementation __________
+
+/**
+ * Class to pass the system window handle to the OpenOffice.org toolkit.
+ * It use special JNI methods to get the system handle of used java window.
+ *
+ * Attention!
+ * Use JNI functions on already visible canvas objects only!
+ * Otherwise they can make some trouble.
+ *
+ * @author Andreas Schl&uuml;ns
+ * @created 22.02.2002 08:47
+ */
+
+public class NativeView extends java.awt.Canvas
+{
+ // ____________________
+
+ /**
+ * ctor
+ * Does nothing realy.
+ * We can use our JNI mechanism for an already visible
+ * canvas only. So we overload the method for showing ("setVisible()")
+ * and make our intialization there. BUt we try to show an empty clean
+ * window till there.
+ */
+ public NativeView()
+ {
+ maHandle = null;
+ maSystem = 0;
+ this.setBackground(Color.white);
+ }
+
+ // ____________________
+
+ /**
+ * Overload this method to make neccessary initializations here.
+ * (e.g. get the window handle and neccessary system informations)
+ *
+ * Why here?
+ * Because the handle seams to be available for already visible windows
+ * only. So it's the best place to get it. Special helper method
+ * can be called more then ones - but call native code one times only
+ * and safe the handle and the system type on our members maHandle/maSystem!
+ */
+ public void setVisible(boolean bState)
+ {
+ getHWND();
+ }
+
+ // ____________________
+
+ /**
+ * to guarantee right resize handling inside a swing container
+ * (e.g. JSplitPane) we must provide some informations about our
+ * prefered/minimum and maximum size.
+ */
+ public Dimension getPreferredSize()
+ {
+ return new Dimension(500,300);
+ }
+
+ public Dimension getMaximumSize()
+ {
+ return new Dimension(1024,768);
+ }
+
+ public Dimension getMinimumSize()
+ {
+ return new Dimension(100,100);
+ }
+
+ // ____________________
+
+ /**
+ * overload paint routine to show provide against
+ * repaint errors if no office view is realy plugged
+ * into this canvas.
+ * If handle is present - we shouldn't paint anything further.
+ * May the remote window is already plugged. In such case we
+ * shouldn't paint it over.
+ */
+ public void paint(Graphics aGraphic)
+ {
+ if(maHandle==null)
+ {
+ Dimension aSize = getSize();
+ aGraphic.clearRect(0,0,aSize.width,aSize.height);
+ }
+ }
+
+ // ____________________
+
+ /**
+ * JNI interface of this class
+ * These two methods are implemented by using JNI mechanismen.
+ * The will be used to get the platform dependent window handle
+ * of a java awt canvas. This handle can be used to create an office
+ * window as direct child of it. So it's possible to plug Office
+ * windows in a java UI container.
+ *
+ * Note:
+ * Native code for windows register special function pointer to handle
+ * window messages ... But if it doesn't check for an already registered
+ * instance of this handler it will do it twice and produce a stack overflow
+ * because such method call herself in a never ending loop ...
+ * So we try to use the JNI code one times only and safe already getted
+ * informations inside this class.
+ */
+ public native int getNativeWindowSystemType();
+ private native long getNativeWindow(); // private! => use getHWND() with cache mechanism!
+
+ public Integer getHWND()
+ {
+ if(maHandle==null)
+ {
+ maHandle = new Integer((int)getNativeWindow());
+ maSystem = getNativeWindowSystemType();
+ }
+ return maHandle;
+ }
+
+ // ____________________
+
+ /**
+ * for using of the JNI methods it's neccessary to load
+ * system library which exports it.
+ */
+ static
+ {
+ System.loadLibrary("nativeview");
+ }
+
+ // ____________________
+
+ /**
+ * @member maHandle system window handle
+ * @member maSystem info about currently used platform
+ */
+ public Integer maHandle ;
+ public int maSystem ;
+}
diff --git a/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/OfficeConnect.java b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/OfficeConnect.java
new file mode 100644
index 000000000000..76007310dc89
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/OfficeConnect.java
@@ -0,0 +1,211 @@
+/*************************************************************************
+ *
+ * $RCSfile: OfficeConnect.java,v $
+ *
+ * $Revision: 1.4 $
+ *
+ * last change: $Author: rt $ $Date: 2005-01-31 16:39:37 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright (c) 2003 by Sun Microsystems, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+// __________ Imports __________
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.uno.Any;
+
+import java.lang.String;
+
+
+// __________ Implementation __________
+
+/**
+ * support ONE singleton uno connection to an running office installation!
+ * Can be used to open/use/close connection to uno environment of an office. If
+ * necessary a new office instance is started.
+ * ctor isn't available from outside. You should call static function
+ * "getConnection()" to open or use internal set connection which is created one
+ * times only.
+ *
+ * @author Andreas Schl&uuml;ns
+ * @created 7. Februar 2002
+ * @modified 05.02.2002 12:10
+ */
+public class OfficeConnect
+{
+ // ____________________
+
+ /**
+ * At first call we create static connection object and open connection to an
+ * office - anew offic einstance is started if necessary
+ * Then - and for all further requests we return these static connection member.
+ */
+ public static synchronized void createConnection()
+ {
+ if (maConnection == null)
+ maConnection = new OfficeConnect();
+ }
+
+ // ____________________
+
+ /**
+ * close connection to remote office if it exist
+ */
+ public static synchronized void disconnect()
+ {
+ if(maConnection!=null)
+ {
+ mxServiceManager=null;
+ mxOfficeContext=null;
+ maConnection=null;
+ }
+ }
+
+ // ____________________
+
+ /**
+ * ctor
+ * We try to open the connection in our ctor ... transparently for user.
+ * After it was successfully you will find an internal set member
+ * m_xRemoteContext wich means remote component context of the connected office.
+ * The context can be used to get the remote service manager from the office.
+ * We made it private to support singleton pattern of these implementation.
+ * see getConnection() for further informations
+ */
+ private OfficeConnect()
+ {
+ try
+ {
+ // get the remote office context. If necessary a new office
+ // process is started
+ mxOfficeContext = com.sun.star.comp.helper.Bootstrap.bootstrap();
+ System.out.println("Connected to a running office ...");
+ mxServiceManager = mxOfficeContext.getServiceManager();
+ }
+ catch (java.lang.Exception ex)
+ {
+ System.err.println("connection failed" + ex);
+ ex.printStackTrace(System.out);
+ System.exit(1);
+
+ }
+ }
+
+ // ____________________
+
+ /**
+ * create uno components inside remote office process
+ * After connection of these proccess to a running office we have access to
+ * remote service manager of it.
+ * So we can use it to create all existing services. Use this method to create
+ * components by name and get her interface. Casting of it to right target
+ * interface is part of your implementation.
+ *
+ * @param aType describe class type of created service
+ * Returned object can be casted directly to this one.
+ * Uno query was done by this method automaticly.
+ * @param sServiceSpecifier name of service which should be created
+ * @return the new created service object
+ */
+ public static synchronized Object createRemoteInstance(
+ Class aType, String sServiceSpecifier)
+ {
+ Object aResult = null;
+ try
+ {
+ aResult = UnoRuntime.queryInterface(aType,
+ mxServiceManager.createInstanceWithContext(
+ sServiceSpecifier, mxOfficeContext));
+ }
+ catch (com.sun.star.uno.Exception ex)
+ {
+ System.err.println("Couldn't create Service of type "
+ + sServiceSpecifier + ": " + ex);
+ System.exit(0);
+ }
+ return aResult;
+ }
+
+ // ____________________
+
+ /**
+ * same as "createRemoteInstance()" but supports additional parameter for
+ * initializing created object
+ *
+ * @param lArguments optional arguments
+ * They are used to initialize new created service.
+ * @param aType Description of Parameter
+ * @param sServiceSpecifier Description of Parameter
+ * @return the new create service object
+ */
+ public static synchronized Object createRemoteInstanceWithArguments(
+ Class aType, String sServiceSpecifier, Any[] lArguments)
+ {
+ Object aResult = null;
+ try
+ {
+ aResult = UnoRuntime.queryInterface(aType,
+ mxServiceManager.createInstanceWithArgumentsAndContext(
+ sServiceSpecifier, lArguments, mxOfficeContext));
+ }
+ catch (com.sun.star.uno.Exception ex)
+ {
+ System.err.println("Couldn't create Service of type "
+ + sServiceSpecifier + ": " + ex);
+ System.exit(0);
+ }
+ return aResult;
+ }
+
+ // ____________________
+
+ /**
+ * returns remote component context of the connected office
+ */
+ public static synchronized com.sun.star.uno.XComponentContext getOfficeContext()
+ {
+ return mxOfficeContext;
+ }
+
+ // ____________________
+
+ /**
+ * member
+ */
+ // singleton connection instance
+ private static OfficeConnect maConnection;
+
+ // reference to the office component context
+ private static com.sun.star.uno.XComponentContext mxOfficeContext;
+ // reference to remote service manager of singleton connection object
+ private static com.sun.star.lang.XMultiComponentFactory mxServiceManager;
+}
+
diff --git a/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/OnewayExecutor.java b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/OnewayExecutor.java
new file mode 100644
index 000000000000..7bef81f5f7fd
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/OnewayExecutor.java
@@ -0,0 +1,246 @@
+/*************************************************************************
+ *
+ * $RCSfile: OnewayExecutor.java,v $
+ *
+ * $Revision: 1.4 $
+ *
+ * last change: $Author: rt $ $Date: 2005-01-31 16:39:52 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright (c) 2003 by Sun Microsystems, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import java.util.Vector;
+
+// __________ Implementation __________
+
+/**
+ * It's not allowed to call synchronoues back inside an oneway interface call.
+ * (see IOnewayLink too). So we start a thread (implemented by this class), which
+ * gets all neccessary parameters from the original called object and
+ * call it back later inside his run() method. So the execution of such oneway call
+ * will be asynchronous. It works in a generic way and can be used or any type
+ * of oneway request. Because the source and the target of this call-link knows,
+ * which method was used and which parameters must be handled.
+ *
+ * @author Andreas Schl&uuml;ns
+ * @created 17.07.2002 08:18
+ */
+class OnewayExecutor extends Thread
+{
+ // _______________________________
+
+ /**
+ * const
+ * We define some request for some well known oneway interface
+ * calls here too. So they mustn't be declared more then ones.
+ * Of course it's not necessary to use it ... but why not :-)
+ */
+
+ public static final int REQUEST_FRAMEACTION = 1 ;
+ public static final int REQUEST_STATUSCHANGED = 2 ;
+ public static final int REQUEST_ADDSTATUSLISTENER = 3 ;
+ public static final int REQUEST_REMOVESTATUSLISTENER = 4 ;
+ public static final int REQUEST_DISPATCH = 5 ;
+
+ public static final boolean ENCODE_PARAMS = true ;
+ public static final boolean DECODE_PARAMS = false ;
+
+ // _______________________________
+
+ /**
+ * @member m_rLink the object, which wish to be called back by this thread
+ * @member m_nRequest describes the type of the original request (means the
+ * called oneyway method)
+ * @member m_lParams list of parameters of the original request
+ */
+ private IOnewayLink m_rLink ;
+ private int m_nRequest ;
+ private Vector m_lParams ;
+
+ // _______________________________
+
+ /**
+ * ctor
+ * It's initialize this thread with all neccessary parameters.
+ * It gets the object, which wish to be called back and the type
+ * and parameters of the original request.
+ *
+ * @param nRequest
+ * The two user of this callback can define an unique number,
+ * which identify the type of original interface method.
+ * So the called interface object can decide, which action will be
+ * neccessary.
+ *
+ * @param lParams
+ * If the original method used parameters, they will be coded here in
+ * a generic way. Only the called interface object know (it depends
+ * from the original request - see nRequest too), how this list must
+ * be interpreted.
+ * Note: Atomic types (e.g. int, long) will be transported as objects
+ * too (Integer, Long)!
+ */
+ public OnewayExecutor( IOnewayLink rLink ,
+ int nRequest ,
+ Vector lParams )
+ {
+ m_rLink = rLink ;
+ m_nRequest = nRequest;
+ m_lParams = lParams ;
+
+ if (m_rLink==null)
+ System.out.println("ctor ... m_rLink == null");
+ if (m_lParams==null)
+ System.out.println("ctor ... m_lParams == null");
+ }
+
+ // _______________________________
+
+ /**
+ * implements the thread function
+ * Here we call the internal set link object back and
+ * give him all neccessary parameters.
+ * After that we die by ouerself ...
+ */
+ public void run()
+ {
+ if (m_rLink==null)
+ System.out.println("run ... m_rLink == null");
+ if (m_lParams==null)
+ System.out.println("run ... m_lParams == null");
+
+ if (m_rLink!=null)
+ m_rLink.execOneway( m_nRequest, m_lParams );
+ }
+
+ // _______________________________
+
+ /**
+ * static helper!
+ * To make convertion of the generic parameter list to the original
+ * one easier - you can use this helper methods. They know how suchlist
+ * must be coded. It's not a must to use it - but you can ...
+ */
+ public static void codeFrameAction(
+ boolean bEncode, Vector[] lParams,
+ com.sun.star.frame.FrameActionEvent[] aAction)
+ {
+ if (bEncode)
+ {
+ lParams[0] = new Vector(1);
+ lParams[0].add( (Object)(aAction[0]) );
+ }
+ else
+ {
+ aAction[0] = (com.sun.star.frame.FrameActionEvent)
+ (lParams[0].elementAt(0));
+ }
+ }
+
+ // _______________________________
+
+ public static void codeStatusChanged(
+ boolean bEncode, Vector[] lParams,
+ com.sun.star.frame.FeatureStateEvent[] aStatus)
+ {
+ if (bEncode)
+ {
+ lParams[0] = new Vector(1);
+ lParams[0].add( (Object)aStatus[0] );
+ }
+ else
+ {
+ aStatus[0] = (com.sun.star.frame.FeatureStateEvent)
+ (lParams[0].elementAt(0));
+ }
+ }
+
+ // _______________________________
+
+ public static void codeAddOrRemoveStatusListener(
+ boolean bEncode, Vector[] lParams,
+ com.sun.star.frame.XStatusListener[] xListener,
+ com.sun.star.util.URL[] aURL)
+ {
+ if (bEncode)
+ {
+ lParams[0] = new Vector(2);
+ lParams[0].add( (Object)xListener[0] );
+ lParams[0].add( (Object)aURL[0] );
+ }
+ else
+ {
+ xListener[0] = (com.sun.star.frame.XStatusListener)
+ (lParams[0].elementAt(0));
+ aURL[0] = (com.sun.star.util.URL)(lParams[0].elementAt(1));
+ }
+ }
+
+ // _______________________________
+
+ public static void codeDispatch(
+ boolean bEncode, Vector[] lParams,
+ com.sun.star.util.URL[] aURL,
+ com.sun.star.beans.PropertyValue[][] lArgs)
+ {
+ if (bEncode)
+ {
+ int nLength = lArgs.length+1;
+ int nPos = 0;
+ lParams[0] = new Vector(nLength);
+
+ lParams[0].add( (Object)aURL[0] );
+ --nLength;
+
+ while (nLength>0)
+ {
+ lParams[0].add( (Object)lArgs[0][nPos] );
+ --nLength;
+ ++nPos ;
+ }
+ }
+ else
+ {
+ int nLength = lParams[0].size()-1;
+ int nPos = 0;
+
+ lArgs[0] = new com.sun.star.beans.PropertyValue[nLength];
+ aURL[0] = (com.sun.star.util.URL)(lParams[0].elementAt(0));
+
+ while (nPos<nLength)
+ {
+ lArgs[0][nPos] = (com.sun.star.beans.PropertyValue)
+ (lParams[0].elementAt(nPos+1));
+ ++nPos;
+ }
+ }
+ }
+}
diff --git a/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/StatusListener.java b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/StatusListener.java
new file mode 100644
index 000000000000..bf43756226e5
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/StatusListener.java
@@ -0,0 +1,484 @@
+/*************************************************************************
+ *
+ * $RCSfile: StatusListener.java,v $
+ *
+ * $Revision: 1.4 $
+ *
+ * last change: $Author: rt $ $Date: 2005-01-31 16:40:05 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright (c) 2003 by Sun Microsystems, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+// __________ Imports __________
+
+import com.sun.star.uno.UnoRuntime;
+
+import java.lang.String;
+import java.awt.Component;
+import javax.swing.JCheckBox;
+import javax.swing.JLabel;
+import java.util.Vector;
+
+// __________ Implementation __________
+
+/**
+ * reacts for status events we listen for
+ * We listen for status events to update our UI.
+ * To know which event must be used for which UI control
+ * we use a special class to do that. Otherwhise we have
+ * to guess it ...
+ *
+ * Further we are frame action listener too.
+ * So we can update our status listener connections and
+ * internal holded dispatch object automaticly.
+ *
+ * Another reason for such extra class for listening:
+ * Most listener callbacks are asynchronoues [oneay] requests.
+ * And it's not allowed to call back synchronously there.
+ * So we must start threads for updating something internaly.
+ *
+ * @author Andreas Schl&uuml;ns
+ * @created 15.07.2002 12:36
+ */
+class StatusListener implements com.sun.star.frame.XStatusListener,
+ com.sun.star.frame.XFrameActionListener,
+ IShutdownListener,
+ IOnewayLink
+{
+ //_____________________
+
+ /**
+ * @member m_rControl reference to the UI control, which should be updated
+ * @member m_sTrueText this text will be shown at the used UI control as description for an enabled status
+ * @member m_sFalseText this text will be shown at the used UI control as description for an disabled status
+ * @member m_xDispatch if we listen for status events, we must hold the dispatch object alive!
+ * @member m_xFrame reference to the frame, which can provide new dispatch objects if it's neccessary to update it
+ * @member m_aURL and of course we must be registered for a special URL
+ * @member m_bIsActionListener indicates if we are currently registered as a listener for frame action events or not
+ * @member m_bIsStatusListener indicates if we are currently registered as a listener for status events or not
+ * @member m_bDead there exist more then one way to finish an object of this class - we must know it sometimes
+ */
+ private Component m_rControl ;
+ private String m_sTrueText ;
+ private String m_sFalseText ;
+ private com.sun.star.frame.XDispatch m_xDispatch ;
+ private com.sun.star.frame.XFrame m_xFrame ;
+ private com.sun.star.util.URL m_aURL ;
+ private boolean m_bIsActionListener;
+ private boolean m_bIsStatusListener;
+ private boolean m_bDead ;
+
+ //_____________________
+
+ /**
+ * ctor
+ * It initialize an instance of this class only.
+ * We sett all neccessary informations on our internal member - that's it
+ */
+ StatusListener( /*IN*/ Component rControl ,
+ /*IN*/ String sTrueText ,
+ /*IN*/ String sFalseText ,
+ /*IN*/ com.sun.star.frame.XFrame xFrame ,
+ /*IN*/ String sURL )
+ {
+ m_rControl = rControl ;
+ m_sTrueText = sTrueText ;
+ m_sFalseText = sFalseText ;
+ m_xFrame = xFrame ;
+ m_bIsStatusListener = false ;
+ m_bIsActionListener = false ;
+ m_bDead = false ;
+ // to be perform - we parse the given URL one times only
+ // and use it till we die ...
+ m_aURL = FunctionHelper.parseURL(sURL);
+ }
+
+ //_____________________
+
+ /**
+ * start working as frame action listener realy.
+ * In case we get such frame action, it indicates that we should
+ * update our internal saved dispatch object on which we listen
+ * for status events. So we can do it automaticly. The outside code
+ * mustn't check such things. We can work with one frame,
+ * till it die. It doesn't matter if he will be used for different
+ * load/save or any other requests. We will be up to date everytime.
+ */
+ public void startListening()
+ {
+ com.sun.star.frame.XFrame xFrame = null;
+ synchronized(this)
+ {
+ if (m_bDead)
+ return;
+ if (m_xFrame==null)
+ return;
+ if (m_bIsActionListener==true)
+ return;
+ xFrame = m_xFrame;
+ }
+ xFrame.addFrameActionListener(this);
+ synchronized(this)
+ {
+ m_bIsActionListener=true;
+ }
+ }
+
+ //_____________________
+
+ /**
+ * In case we got an oneway listener callback - we had to use the office
+ * asynchronous then. This method is the callback from the started thread
+ * (started inside the original oneway method). We found all parameters of
+ * the original request packed inside a vector. Here we unpack it and
+ * call the right internal helper method, which implements the right
+ * funtionality.
+ *
+ * @seealso frameAction()
+ * @seealso statusChanged()
+ *
+ * @param nRequest
+ * indicates, which was the original request (identifies the
+ * original called method)
+ *
+ * @param lParams
+ * the vector with all packed parameters of the original request
+ */
+ public void execOneway(/*IN*/ int nRequest,/*IN*/ Vector lParams )
+ {
+ synchronized(this)
+ {
+ if (m_bDead)
+ return;
+ }
+ // was it frameAction()?
+ if (nRequest==OnewayExecutor.REQUEST_FRAMEACTION)
+ {
+ com.sun.star.frame.FrameActionEvent[] lOutAction = new com.sun.star.frame.FrameActionEvent[1];
+ Vector[] lInParams = new Vector[1];
+ lInParams[0] = lParams;
+
+ OnewayExecutor.codeFrameAction( OnewayExecutor.DECODE_PARAMS ,
+ lInParams ,
+ lOutAction );
+ impl_frameAction(lOutAction[0]);
+ }
+ }
+
+ //_____________________
+
+ /**
+ * This is the callback method for such frame action events, we listen for.
+ * Because it's a oneway method we start a thread as reaction. This thread call
+ * us back and we can do neccessary things there.
+ * But we shouldn't start such action - if it's not realy neccessary.
+ * So we check before, if we are intereested on this event realy.
+ *
+ * @see impl_frameAction()
+ *
+ * @param aEvent
+ * describes the action, which triggered this event
+ */
+ public /*ONEWAY*/ void frameAction(/*IN*/ com.sun.star.frame.FrameActionEvent aEvent)
+ {
+ synchronized(this)
+ {
+ if (m_bDead)
+ return;
+ }
+ boolean bHandle = false;
+ switch(aEvent.Action.getValue())
+ {
+ case com.sun.star.frame.FrameAction.COMPONENT_ATTACHED_value : bHandle=true; break;
+ case com.sun.star.frame.FrameAction.COMPONENT_DETACHING_value : bHandle=true; break;
+ case com.sun.star.frame.FrameAction.COMPONENT_REATTACHED_value : bHandle=true; break;
+ case com.sun.star.frame.FrameAction.CONTEXT_CHANGED_value : bHandle=true; break;
+ }
+
+ if (! bHandle)
+ return;
+
+ Vector[] lOutParams = new Vector[1];
+ com.sun.star.frame.FrameActionEvent[] lInAction = new com.sun.star.frame.FrameActionEvent[1];
+ lInAction[0] = aEvent;
+
+ OnewayExecutor.codeFrameAction( OnewayExecutor.ENCODE_PARAMS ,
+ lOutParams ,
+ lInAction );
+ OnewayExecutor aExecutor = new OnewayExecutor( (IOnewayLink)this ,
+ OnewayExecutor.REQUEST_FRAMEACTION ,
+ lOutParams[0] );
+ aExecutor.start();
+ }
+
+ //_____________________
+
+ /**
+ * This is the callback method for the status we listen for an wish to show it
+ * on our UI control. Of yourse it's a oneway method ... but we doesn't call back
+ * to the office synchronously here. We update our UI only. So we don't leave this
+ * java process. In such case it's not neccessary to use threads to decouple it.
+ * Do it here and now ...
+ *
+ * @param aEvent
+ * describes the status, we can use to update our UI control
+ */
+ public /*ONEWAY*/ void statusChanged(/*IN*/ com.sun.star.frame.FeatureStateEvent aEvent)
+ {
+ synchronized(this)
+ {
+ if (m_bDead)
+ return;
+
+ // enable/dsiable th control.
+ // Means: If the feature isn't available currently - we can't show an status realy here.
+ // Then we should colorize it gray ...
+ m_rControl.setEnabled(aEvent.IsEnabled);
+
+ // Only if status is enabled we can look for his value!
+ if (aEvent.IsEnabled)
+ {
+ // look for the right type ofthe UI control
+ // Following actions depend on it.
+
+ //.............................................................
+ // it's a check box
+ if (m_rControl instanceof JCheckBox)
+ {
+ JCheckBox aBox = (JCheckBox)m_rControl;
+
+ // State must be a boolean value too. Otherwhise must
+ // ignore this event.
+ if ( ! (aEvent.State instanceof Boolean ) )
+ return;
+
+ boolean bState = ((Boolean)(aEvent.State)).booleanValue();
+ aBox.setSelected(bState);
+ if (bState)
+ aBox.setText(m_sTrueText);
+ else
+ aBox.setText(m_sFalseText);
+ }
+ else
+ //.............................................................
+ // it's a label
+ if (m_rControl instanceof JLabel)
+ {
+ JLabel aLabel = (JLabel)m_rControl;
+
+ // Detect type of state value
+ // and set it on internal well known UI control
+ // But do it only, if value realy change.
+ if(aEvent.State instanceof String)
+ {
+ String sState = (String)aEvent.State;
+ aLabel.setText(sState);
+ }
+ else
+ if(aEvent.State instanceof Boolean)
+ {
+ boolean bState = ((Boolean)aEvent.State).booleanValue();
+ if (bState)
+ aLabel.setText(m_sTrueText);
+ else
+ aLabel.setText(m_sFalseText);
+ }
+ else
+ if(aEvent.State instanceof Float)
+ {
+ String sState = ((Float)aEvent.State).toString();
+ aLabel.setText(sState);
+ }
+ }
+ }
+ }
+ }
+
+ //_____________________
+
+ /**
+ * Internal call back for frame action events, triggered by the used
+ * OnewayExecutor thread we started in frameAction().
+ * We use it to update internal saved dispatch object and the corresponding
+ * listener connection for status events.
+ *
+ * @param aEvent
+ * describes the action
+ */
+ public void impl_frameAction(/*IN*/ com.sun.star.frame.FrameActionEvent aEvent)
+ {
+ synchronized(this)
+ {
+ if (m_bDead)
+ return;
+ }
+ // Don't look for ignoring actions - it was done already inside original frameAction() call!
+ // deregistration as status listener will be done here everytime - but registration only, if neccessary!
+ boolean bRegister = false;
+ switch(aEvent.Action.getValue())
+ {
+ case com.sun.star.frame.FrameAction.COMPONENT_ATTACHED_value : bRegister=true ; break;
+ case com.sun.star.frame.FrameAction.COMPONENT_DETACHING_value : bRegister=false; break;
+ case com.sun.star.frame.FrameAction.COMPONENT_REATTACHED_value : bRegister=true ; break;
+ case com.sun.star.frame.FrameAction.CONTEXT_CHANGED_value : bRegister=true ; break;
+ }
+
+ boolean bIsStatusListener = false;
+ com.sun.star.frame.XFrame xFrame = null ;
+ com.sun.star.frame.XDispatch xDispatch = null ;
+ com.sun.star.util.URL aURL = null ;
+ synchronized(this)
+ {
+ bIsStatusListener = m_bIsStatusListener;
+ m_bIsStatusListener = false;
+
+ xDispatch = m_xDispatch;
+ m_xDispatch = null;
+
+ aURL = m_aURL;
+ xFrame = m_xFrame;
+ }
+
+ if (bIsStatusListener)
+ xDispatch.removeStatusListener(this,aURL);
+ xDispatch = null;
+
+ if (! bRegister)
+ return;
+
+ com.sun.star.frame.XDispatchProvider xProvider = (com.sun.star.frame.XDispatchProvider)UnoRuntime.queryInterface(
+ com.sun.star.frame.XDispatchProvider.class,
+ xFrame);
+
+ if (xProvider==null)
+ return;
+
+ xDispatch = xProvider.queryDispatch(aURL,"",0);
+
+ if (xDispatch==null)
+ return;
+
+ xDispatch.addStatusListener(this,aURL);
+ synchronized(this)
+ {
+ m_xDispatch = xDispatch;
+ m_bIsStatusListener = true;
+ }
+ }
+
+ // ____________________
+
+ /**
+ * callback for disposing events
+ * Our dispatch or frame object inform us about his following dead ...
+ * So we must forget his reference. But it's not neccessary to
+ * remove listener connections here. Because the broadcaster
+ * forget us automaticly. The only thing we have to do: release
+ * his reference and let him die!
+ *
+ * @param aEvent
+ * describes the source which fire this event
+ * Must be our internal saved dispatch or frame. Otherwhise
+ * somewhere know us without a registration ...
+ */
+ public /*ONEWAY*/ void disposing(/*IN*/ com.sun.star.lang.EventObject aEvent)
+ {
+ synchronized(this)
+ {
+ if (m_bDead)
+ return;
+ if (m_xFrame!=null && UnoRuntime.areSame(aEvent.Source,m_xFrame))
+ {
+ m_bIsActionListener = false;
+ m_xFrame = null ;
+ }
+ else
+ if (m_xDispatch!=null && UnoRuntime.areSame(aEvent.Source,m_xDispatch))
+ {
+ m_bIsStatusListener = false;
+ m_xDispatch = null ;
+ m_aURL = null ;
+ }
+ }
+ shutdown();
+ }
+
+ // ____________________
+
+ /**
+ * If this java application shutdown - we must cancel all current existing
+ * listener connections. Otherwhise the office will run into some
+ * DisposedExceptions if it tries to use these forgotten listener references.
+ * And of course it can die doing that.
+ * We are registered at a central object to be informed if the VM will exit.
+ * So we can react.
+ */
+ public void shutdown()
+ {
+ boolean bIsActionListener = false;
+ boolean bIsStatusListener = false;
+ com.sun.star.frame.XFrame xFrame = null ;
+ com.sun.star.frame.XDispatch xDispatch = null ;
+ com.sun.star.util.URL aURL = null ;
+ synchronized(this)
+ {
+ // don't react a second time here!
+ if (m_bDead)
+ return;
+ m_bDead = true;
+
+ bIsActionListener = m_bIsActionListener;
+ m_bIsActionListener = false;
+
+ bIsStatusListener = m_bIsStatusListener;
+ m_bIsStatusListener = false;
+
+ xFrame = m_xFrame;
+ m_xFrame = null;
+
+ xDispatch = m_xDispatch;
+ m_xDispatch = null;
+
+ aURL = m_aURL;
+ m_aURL = null;
+ }
+
+ if (bIsStatusListener)
+ xDispatch.removeStatusListener(this,aURL);
+ xDispatch = null ;
+ aURL = null ;
+
+ if (bIsActionListener)
+ xFrame.removeFrameActionListener(this);
+ xFrame = null ;
+ }
+}
diff --git a/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/StatusView.java b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/StatusView.java
new file mode 100644
index 000000000000..01b1dcbebeae
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/StatusView.java
@@ -0,0 +1,272 @@
+/*************************************************************************
+ *
+ * $RCSfile: StatusView.java,v $
+ *
+ * $Revision: 1.4 $
+ *
+ * last change: $Author: rt $ $Date: 2005-01-31 16:40:19 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright (c) 2003 by Sun Microsystems, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+// __________ Imports __________
+
+import com.sun.star.uno.UnoRuntime;
+
+import java.awt.*;
+import javax.swing.*;
+import java.lang.String;
+
+// __________ Implementation __________
+
+/**
+ * Implement a view to show status informations
+ * of currently loaded document of a document view.
+ * It use seperate listener threads to get this informations
+ * and actualize it automaticly if frame broadcast changes of
+ * his contained document.
+ * Threads are neccessary to prevent this view against deadlocks.
+ * These deadlocks can occure if a listener will be notified
+ * by the office in an "oneway" method and try to call back
+ * to the office by using a synchronous method.
+ * UNO must guarantee order of all these calls ... and if
+ * the source of arrived event holds a mutex and our synchronous
+ * call needs this mutex too => a deadlock occure.
+ * Why? UNO had created a new thread for our synchronous call
+ * inside the office process and so exist different threads
+ * for this constallation.
+ *
+ * @author Andreas Schl&uuml;ns
+ * @created 20.06.2002 15:08
+ */
+public class StatusView extends JPanel
+ implements IShutdownListener
+{
+ // ____________________
+
+ /**
+ * const
+ * These URL's describe available feature states.
+ */
+ public static final String FEATUREURL_FONT = "slot:10007";
+ public static final String FEATUREURL_SIZE = "slot:10015";
+ public static final String FEATUREURL_BOLD = "slot:10009";
+ public static final String FEATUREURL_ITALIC = "slot:10008";
+ public static final String FEATUREURL_UNDERLINE = "slot:10014";
+
+ // ____________________
+
+ /**
+ * const
+ * These values are used to show current state of showed feature.
+ */
+ public static final String FONT_OFF = "unknown" ;
+ public static final String SIZE_OFF = "0.0" ;
+ public static final String BOLD_OFF = "-" ;
+ public static final String ITALIC_OFF = "-" ;
+ public static final String UNDERLINE_OFF = "-" ;
+
+ public static final String FONT_ON = "" ;
+ public static final String SIZE_ON = "" ;
+ public static final String BOLD_ON = "X" ;
+ public static final String ITALIC_ON = "X" ;
+ public static final String UNDERLINE_ON = "X" ;
+
+ // ____________________
+
+ /**
+ * @member mlaFontValue shows status of font name
+ * @member mlaSizeValue shows status of font size
+ * @member mlaBoldValue shows status of font style bold
+ * @member mlaUnderlineValue shows status of font style underline
+ * @member mlaItalicValue shows status of font style italic
+ *
+ * @member maFontListener threadsafe(!) helper to listen for status event which describe font name
+ * @member maSizeListener threadsafe(!) helper to listen for status event which describe font size
+ * @member maBoldListener threadsafe(!) helper to listen for status event which describe font style bold
+ * @member maUnderlineListener threadsafe(!) helper to listen for status event which describe font style underline
+ * @member maItalicListener threadsafe(!) helper to listen for status event which describe font style italic
+ */
+ private JLabel m_laFontValue ;
+ private JLabel m_laSizeValue ;
+ private JLabel m_laBoldValue ;
+ private JLabel m_laUnderlineValue ;
+ private JLabel m_laItalicValue ;
+
+ private StatusListener m_aFontListener ;
+ private StatusListener m_aSizeListener ;
+ private StatusListener m_aBoldListener ;
+ private StatusListener m_aUnderlineListener ;
+ private StatusListener m_aItalicListener ;
+
+ // ____________________
+
+ /**
+ * ctor
+ * Create view controls on startup and initialize it with default values.
+ * Filling of view items can be done by special set-methods.
+ * We don't start listening here! see setFrame() for that ...
+ */
+ StatusView()
+ {
+ this.setLayout(new GridBagLayout());
+
+ GridBagConstraints aConstraint = new GridBagConstraints();
+ aConstraint.anchor = GridBagConstraints.NORTHWEST;
+ aConstraint.insets = new Insets(2,2,2,2);
+ aConstraint.gridy = 0;
+ aConstraint.gridx = 0;
+
+ JLabel laFont = new JLabel("Font" );
+ JLabel laSize = new JLabel("Size" );
+ JLabel laBold = new JLabel("Bold" );
+ JLabel laUnderline = new JLabel("Underline");
+ JLabel laItalic = new JLabel("Italic" );
+
+ m_laFontValue = new JLabel();
+ m_laSizeValue = new JLabel();
+ m_laBoldValue = new JLabel();
+ m_laUnderlineValue = new JLabel();
+ m_laItalicValue = new JLabel();
+
+ aConstraint.gridx = 0;
+ this.add( laFont, aConstraint );
+ aConstraint.gridx = 1;
+ this.add( m_laFontValue, aConstraint );
+
+ ++aConstraint.gridy;
+
+ aConstraint.gridx = 0;
+ this.add( laSize, aConstraint );
+ aConstraint.gridx = 1;
+ this.add( m_laSizeValue, aConstraint );
+
+ ++aConstraint.gridy;
+
+ aConstraint.gridx = 0;
+ this.add( laSize, aConstraint );
+ aConstraint.gridx = 1;
+ this.add( m_laSizeValue, aConstraint );
+
+ ++aConstraint.gridy;
+
+ aConstraint.gridx = 0;
+ this.add( laBold, aConstraint );
+ aConstraint.gridx = 1;
+ this.add( m_laBoldValue, aConstraint );
+
+ ++aConstraint.gridy;
+
+ aConstraint.gridx = 0;
+ this.add( laUnderline, aConstraint );
+ aConstraint.gridx = 1;
+ this.add( m_laUnderlineValue, aConstraint );
+
+ ++aConstraint.gridy;
+
+ aConstraint.gridx = 0;
+ this.add( laItalic, aConstraint );
+ aConstraint.gridx = 1;
+ this.add( m_laItalicValue, aConstraint );
+
+ m_laFontValue.setEnabled (false);
+ m_laSizeValue.setEnabled (false);
+ m_laBoldValue.setEnabled (false);
+ m_laItalicValue.setEnabled (false);
+ m_laUnderlineValue.setEnabled(false);
+
+ m_laFontValue.setText (FONT_OFF );
+ m_laSizeValue.setText (SIZE_OFF );
+ m_laBoldValue.setText (BOLD_OFF );
+ m_laItalicValue.setText (ITALIC_OFF );
+ m_laUnderlineValue.setText(UNDERLINE_OFF);
+ }
+
+ // ____________________
+
+ /**
+ * Set new frame for this view and start listening for events imedatly.
+ * We create one status listener for every control we whish to update.
+ * And because the environment of the frame can be changed - these
+ * listener refresh himself internaly for frame action events too.
+ * So we register it as such frame action listener only here.
+ * Rest is done automaticly ...
+ *
+ * @param xFrame
+ * will be used as source of possible status events
+ */
+ public void setFrame(com.sun.star.frame.XFrame xFrame)
+ {
+ if (xFrame==null)
+ return;
+
+ // create some listener on given frame for available status events
+ // Created listener instances will register herself on this frame and
+ // show her received informations automaticly on setted UI controls.
+ m_aFontListener = new StatusListener(m_laFontValue ,FONT_ON ,FONT_OFF ,xFrame, FEATUREURL_FONT );
+ m_aSizeListener = new StatusListener(m_laSizeValue ,SIZE_ON ,SIZE_OFF ,xFrame, FEATUREURL_SIZE );
+ m_aBoldListener = new StatusListener(m_laBoldValue ,BOLD_ON ,BOLD_OFF ,xFrame, FEATUREURL_BOLD );
+ m_aItalicListener = new StatusListener(m_laItalicValue ,ITALIC_ON ,ITALIC_OFF ,xFrame, FEATUREURL_ITALIC );
+ m_aUnderlineListener = new StatusListener(m_laUnderlineValue,UNDERLINE_ON,UNDERLINE_OFF,xFrame, FEATUREURL_UNDERLINE);
+
+ m_aFontListener.startListening();
+ m_aSizeListener.startListening();
+ m_aBoldListener.startListening();
+ m_aItalicListener.startListening();
+ m_aUnderlineListener.startListening();
+ }
+
+ // ____________________
+
+ /**
+ * If this java application shutdown - we must cancel all current existing
+ * listener connections. Otherwhise the office will run into some
+ * DisposedExceptions if it tries to use these forgotten listener references.
+ * And of course it can die doing that.
+ * We are registered at a central object to be informed if the VM will exit.
+ * So we can react.
+ */
+ public void shutdown()
+ {
+ m_aFontListener.shutdown();
+ m_aSizeListener.shutdown();
+ m_aBoldListener.shutdown();
+ m_aItalicListener.shutdown();
+ m_aUnderlineListener.shutdown();
+
+ m_aFontListener = null;
+ m_aSizeListener = null;
+ m_aBoldListener = null;
+ m_aItalicListener = null;
+ m_aUnderlineListener = null;
+ }
+}
diff --git a/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/ViewContainer.java b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/ViewContainer.java
new file mode 100644
index 000000000000..a2ff9886516d
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/ViewContainer.java
@@ -0,0 +1,275 @@
+/*************************************************************************
+ *
+ * $RCSfile: ViewContainer.java,v $
+ *
+ * $Revision: 1.4 $
+ *
+ * last change: $Author: rt $ $Date: 2005-01-31 16:40:33 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright (c) 2003 by Sun Microsystems, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+// __________ Imports __________
+
+import com.sun.star.uno.UnoRuntime;
+
+import java.lang.*;
+import java.util.*;
+
+// __________ Implementation __________
+
+/**
+ * It's implement a static container which hold
+ * all opened documents and her views alive.
+ * It's possible to register/deregister such views,
+ * to get information about these and it provides
+ * some global functionality - like termination of
+ * this demo application.
+ *
+ * @author Andreas Schl&uuml;ns
+ * @created 01.03.2002 08:42
+ */
+public class ViewContainer extends Thread
+{
+ // ____________________
+
+ /**
+ * provides a singleton view container
+ * Neccessary for terminate(9 functionality to be able
+ * to call Runtime.runFinilization().
+ *
+ * @return a reference to the singleton ViewContainer instance
+ */
+ public static synchronized ViewContainer getGlobalContainer()
+ {
+ if (maSingleton==null)
+ maSingleton=new ViewContainer();
+ return maSingleton;
+ }
+
+ // ____________________
+
+ /**
+ * ctor
+ * It's private - because nobody should create any instance
+ * expect the only global one, which wil be created by ourself!
+ */
+ private ViewContainer()
+ {
+ mlViews = new Vector();
+ mlListener = new Vector();
+ mbShutdownActive = false ;
+ Runtime.getRuntime().addShutdownHook(this);
+ }
+
+ // ____________________
+
+ /**
+ * This register a new view inside this global container
+ * (if it doesnt already exist).
+ *
+ * @param aView view which whish to be registered inside this container
+ */
+ public void addView(Object aView)
+ {
+ synchronized(mlViews)
+ {
+ if(mlViews.contains(aView)==false)
+ mlViews.add(aView);
+ }
+ }
+
+ // ____________________
+
+ /**
+ * This deregister a view from this global container.
+ * Normaly it should be the last reference to the view
+ * and her finalize() method should be called.
+ * If last view will be closed here - we terminate these
+ * java application too. Because there is no further
+ * visible frame anymore.
+ *
+ * @param aView
+ * view object which wish to be deregistered
+ */
+ public void removeView(Object aView)
+ {
+ int nViewCount = 0;
+ synchronized(mlViews)
+ {
+ if(mlViews.contains(aView)==true)
+ mlViews.remove(aView);
+
+ nViewCount = mlViews.size();
+
+ if (nViewCount<1)
+ mlViews = null;
+ }
+ // If this view is a registered shutdown listener on this view container
+ // too, we must call his interface and forget him as possible listener.
+ // It's neccessary to guarantee his dead ...
+ boolean bShutdownView = false;
+ synchronized(mlListener)
+ {
+ bShutdownView = mlListener.contains(aView);
+ if (bShutdownView==true)
+ mlListener.remove(aView);
+ }
+ if (bShutdownView==true)
+ ((IShutdownListener)aView).shutdown();
+
+ // We use a system.exit() to finish the whole application.
+ // And further we have registered THIS instance as a possible shutdown
+ // hook at the runtime class. So our run() method will be called.
+ // Teh our view container should be empty - but
+ // our listener container can include some references.
+ // These objects wich to be informed then and release e.g. some
+ // remote references.
+ if (nViewCount<1)
+ {
+ boolean bNeccessary = false;
+ synchronized(this)
+ {
+ bNeccessary = ! mbShutdownActive;
+ }
+ if (bNeccessary==true)
+ {
+ System.out.println("call exit(0)!");
+ System.exit(0);
+ }
+ }
+ }
+
+ // ____________________
+
+ /**
+ * add/remove listener for possibe shutdown events
+ */
+ public void addListener( IShutdownListener rListener )
+ {
+ synchronized(mlListener)
+ {
+ if ( ! mlListener.contains(rListener) )
+ mlListener.add(rListener);
+ }
+ }
+
+ // ____________________
+
+ public void removeListener( IShutdownListener rListener )
+ {
+ synchronized(mlListener)
+ {
+ if ( mlListener.contains(rListener) )
+ mlListener.remove(rListener);
+ }
+ }
+
+ // ____________________
+
+ /**
+ * Is called from current runtime system of the java machine
+ * on shutdown. We inform all current registered listener and
+ * views. They should deinitialize her internal things then.
+ */
+ public void run()
+ {
+ synchronized(this)
+ {
+ if (mbShutdownActive)
+ return;
+ mbShutdownActive=true;
+ }
+
+ while( true )
+ {
+ IShutdownListener aListener = null;
+ synchronized(mlListener)
+ {
+ try{
+ aListener = (IShutdownListener)mlListener.firstElement();
+ } catch(java.util.NoSuchElementException exEmpty) {}
+ }
+ if (aListener==null)
+ break;
+
+ aListener.shutdown();
+ // May this listener has dergeistered himself.
+ // But if not we must do it for him. Our own
+ // method "removeListener()" ignore requests for
+ // already gone listener objects.
+ removeListener(aListener);
+ }
+
+ if (mlViews!=null)
+ {
+ synchronized(mlViews)
+ {
+ mlViews.clear();
+ mlViews = null;
+ }
+ }
+
+ if (mlListener!=null)
+ {
+ synchronized(mlListener)
+ {
+ mlListener.clear();
+ mlListener = null;
+ }
+ }
+ }
+
+ // ____________________
+
+ /**
+ * @const BASICNAME it's used to create uinque names for all regieterd views
+ */
+ private static final String BASICNAME = "Document View ";
+
+ // ____________________
+
+ /**
+ * @member mbInplace indicates using of inplace office frames instead of outplace ones
+ * @member maSingleton singleton instance of this view container
+ * @member mlViews list of all currently registered document views
+ * @member mlListener list of all currently registered shutdown listener
+ * @member mbShutdownActive if this shutdown hook already was started it's not a good idea to
+ * call System.exit() again for other conditions.
+ * We supress it by using this variable!
+ */
+ public static boolean mbInplace = false ;
+ private static ViewContainer maSingleton = null ;
+ private Vector mlViews ;
+ private Vector mlListener ;
+ private boolean mbShutdownActive ;
+}
diff --git a/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/nativelib/unix/Makefile b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/nativelib/unix/Makefile
new file mode 100644
index 000000000000..09726249c34b
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/nativelib/unix/Makefile
@@ -0,0 +1,79 @@
+#*************************************************************************
+#
+# $RCSfile: Makefile,v $
+#
+# $Revision: 1.5 $
+#
+# last change: $Author: rt $ $Date: 2005-01-31 16:40:47 $
+#
+# The Contents of this file are made available subject to the terms of
+# the BSD license.
+#
+# Copyright (c) 2003 by Sun Microsystems, Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+# 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+# contributors may be used to endorse or promote products derived
+# from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+#**************************************************************************
+
+# Builds the OfficeDevDesktopEnvironment native library of the Developers Guide.
+
+PRJ=../../../../../..
+SETTINGS=$(PRJ)/settings
+
+include $(SETTINGS)/settings.mk
+include $(SETTINGS)/std.mk
+include $(SETTINGS)/dk.mk
+
+# Define non-platform/compiler specific settings
+SHL_NAME=nativeview
+SHL_LIBRARY=$(SHAREDLIB_OUT)/$(SHAREDLIB_PRE)$(SHL_NAME).$(SHAREDLIB_EXT)
+
+OUT_SHL_SLO=$(OUT_SLO)/nativeview
+
+CFILES = nativeview.c
+
+SLOFILES = $(patsubst %.c,$(OUT_SHL_SLO)/%.$(OBJ_EXT),$(CFILES))
+
+
+# Targets
+.PHONY: ALL
+ALL : $(SHL_LIBRARY)
+
+include $(SETTINGS)/stdtarget.mk
+
+$(OUT_SHL_SLO)/%.$(OBJ_EXT) : %.c
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(CC) $(CC_FLAGS) $(CC_INCLUDES) $(SDK_JAVA_INCLUDES) $(CC_DEFINES) $(CC_OUTPUT_SWITCH)$(subst /,$(PS),$@) $<
+
+$(SHAREDLIB_OUT)/$(SHAREDLIB_PRE)$(SHL_NAME).$(SHAREDLIB_EXT) : $(SLOFILES)
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(LINK) $(LIBRARY_LINK_FLAGS) $(LINK_LIBS) $(LINK_JAVA_LIBS) -o $@ $< \
+ -ljawt $(CPPUHELPERLIB) $(CPPULIB) $(SALLIB) $(STLPORTLIB) $(STDC++LIB)
+
+.PHONY: clean
+clean :
+ -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_SHL_SLO))
+ -$(DEL) $(subst /,$(PS),$(SHAREDLIB_OUT))$(PS)*$(SHL_NAME)*.*
diff --git a/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/nativelib/unix/nativeview.c b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/nativelib/unix/nativeview.c
new file mode 100644
index 000000000000..ba06d3fb2231
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/nativelib/unix/nativeview.c
@@ -0,0 +1,117 @@
+/*************************************************************************
+ *
+ * $RCSfile: nativeview.c,v $
+ *
+ * $Revision: 1.4 $
+ *
+ * last change: $Author: rt $ $Date: 2005-01-31 16:41:12 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright (c) 2003 by Sun Microsystems, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <X11/Intrinsic.h>
+
+#include "jawt.h"
+#include "jawt_md.h"
+#include "nativeview.h"
+
+#define MY_ASSERT(X,S) if (!X) { fprintf(stderr,S); return 0L;}
+
+#define SYSTEM_WIN32 1
+#define SYSTEM_WIN16 2
+#define SYSTEM_JAVA 3
+#define SYSTEM_OS2 4
+#define SYSTEM_MAC 5
+#define SYSTEM_XWINDOW 6
+
+/*****************************************************************************/
+/*
+ * Class: NativeView
+ * Method: getNativeWindowSystemType
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_NativeView_getNativeWindowSystemType
+ (JNIEnv * env, jobject obj_this)
+{
+ return (SYSTEM_XWINDOW);
+}
+
+/*****************************************************************************/
+/*
+ * Class: NativeView
+ * Method: getNativeWindow
+ * Signature: ()J
+ */
+JNIEXPORT jlong JNICALL Java_NativeView_getNativeWindow
+ (JNIEnv * env, jobject obj_this)
+{
+ jboolean result ;
+ jint lock ;
+ JAWT awt ;
+ JAWT_DrawingSurface* ds ;
+ JAWT_DrawingSurfaceInfo* dsi ;
+ JAWT_X11DrawingSurfaceInfo* dsi_x11 ;
+ Drawable drawable;
+ Display* display ;
+
+ /* Get the AWT */
+ awt.version = JAWT_VERSION_1_3;
+ result = JAWT_GetAWT(env, &awt);
+ MY_ASSERT(result != JNI_FALSE,"wrong jawt version");
+
+ /* Get the drawing surface */
+ if ((ds = awt.GetDrawingSurface(env, obj_this)) == NULL)
+ return 0L;
+
+ /* Lock the drawing surface */
+ lock = ds->Lock(ds);
+ MY_ASSERT((lock & JAWT_LOCK_ERROR)==0,"can't lock the drawing surface");
+
+ /* Get the drawing surface info */
+ dsi = ds->GetDrawingSurfaceInfo(ds);
+
+ /* Get the platform-specific drawing info */
+ dsi_x11 = (JAWT_X11DrawingSurfaceInfo*)dsi->platformInfo;
+ drawable = dsi_x11->drawable;
+ display = dsi_x11->display;
+
+ /* Free the drawing surface info */
+ ds->FreeDrawingSurfaceInfo(dsi);
+ /* Unlock the drawing surface */
+ ds->Unlock(ds);
+ /* Free the drawing surface */
+ awt.FreeDrawingSurface(ds);
+
+ return ((jlong)drawable);
+}
diff --git a/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/nativelib/unix/nativeview.h b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/nativelib/unix/nativeview.h
new file mode 100644
index 000000000000..9cd5f2e7d69b
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/nativelib/unix/nativeview.h
@@ -0,0 +1,69 @@
+/*************************************************************************
+ *
+ * $RCSfile: nativeview.h,v $
+ *
+ * $Revision: 1.4 $
+ *
+ * last change: $Author: rt $ $Date: 2005-01-31 16:41:26 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright (c) 2003 by Sun Microsystems, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+/* DO NOT EDIT THIS FILE - it is machine generated */
+#include <jni.h>
+/* Header for class org_openoffice_OpenOffice */
+
+#ifndef _Included_NativeView
+#define _Included_NativeView
+#ifdef __cplusplus
+extern "C" {
+#endif
+/*
+ * Class: org_openoffice_OpenOffice
+ * Method: getNativeWindowSystemType
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_NativeView_getNativeWindowSystemType
+ (JNIEnv *, jobject);
+
+/*
+ * Class: org_openoffice_OpenOffice
+ * Method: getNativeWindow
+ * Signature: ()J
+ */
+JNIEXPORT jlong JNICALL Java_NativeView_getNativeWindow
+ (JNIEnv *, jobject);
+
+#ifdef __cplusplus
+}
+#endif
+#endif
diff --git a/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/nativelib/windows/Makefile b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/nativelib/windows/Makefile
new file mode 100644
index 000000000000..7a0f16e6a687
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/nativelib/windows/Makefile
@@ -0,0 +1,87 @@
+#*************************************************************************
+#
+# $RCSfile: Makefile,v $
+#
+# $Revision: 1.4 $
+#
+# last change: $Author: rt $ $Date: 2004-05-18 13:25:26 $
+#
+# The Contents of this file are made available subject to the terms of
+# the BSD license.
+#
+# Copyright (c) 2003 by Sun Microsystems, Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+# 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+# contributors may be used to endorse or promote products derived
+# from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+#**************************************************************************
+
+# Builds the OfficeDevDesktopEnvironment native library of the Developers Guide.
+
+PRJ=../../../../../..
+SETTINGS=$(PRJ)/settings
+
+include $(SETTINGS)/settings.mk
+include $(SETTINGS)/std.mk
+include $(SETTINGS)/dk.mk
+
+# Define non-platform/compiler specific settings
+SHL_NAME=nativeview
+SHL_LIBRARY=$(SHAREDLIB_OUT)/$(SHAREDLIB_PRE)$(SHL_NAME).$(SHAREDLIB_EXT)
+
+OUT_SHL_SLO=$(OUT_SLO)/nativeview
+OUT_SHL_MISC=$(OUT_MISC)/nativeview
+
+CFILES = nativeview.c
+
+SLOFILES = $(patsubst %.c,$(OUT_SHL_SLO)/%.$(OBJ_EXT),$(CFILES))
+
+# Targets
+.PHONY: ALL
+ALL : \
+ $(SHL_LIBRARY)
+
+include $(SETTINGS)/stdtarget.mk
+
+$(OUT_SHL_SLO)/%.$(OBJ_EXT) : %.c
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(CC) $(CC_FLAGS) $(CC_INCLUDES) $(SDK_JAVA_INCLUDES) $(CC_DEFINES) $(CC_OUTPUT_SWITCH)$(subst /,$(PS),$@) $<
+
+$(OUT_SHL_MISC)/%.def : exports.dxp
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ @echo EXPORTS > $(OUT_SHL_MISC)/$(SHL_NAME).def
+ $(CAT) exports.dxp >> $(OUT_SHL_MISC)/$(SHL_NAME).def
+
+$(SHAREDLIB_OUT)/$(SHAREDLIB_PRE)$(SHL_NAME).$(SHAREDLIB_EXT) : $(SLOFILES) $(OUT_SHL_MISC)/$(SHL_NAME).def
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(LINK) $(LIBRARY_LINK_FLAGS) /OUT:$@ /MAP:$(OUT_SHL_MISC)/$(SHL_NAME).map \
+ /DEF:$(OUT_SHL_MISC)/$(SHL_NAME).def $(LINK_JAVA_LIBS) \
+ $(SLOFILES) jawt.lib msvcrt.lib kernel32.lib user32.lib
+
+.PHONY: clean
+clean :
+ -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_SHL_SLO))
+ -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_SHL_MISC))
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$(SHAREDLIB_OUT))$(PS)*$(SHL_NAME)*.*)
diff --git a/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/nativelib/windows/nativeview.c b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/nativelib/windows/nativeview.c
new file mode 100644
index 000000000000..dafce5419b47
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/nativelib/windows/nativeview.c
@@ -0,0 +1,184 @@
+/*************************************************************************
+ *
+ * $RCSfile: nativeview.c,v $
+ *
+ * $Revision: 1.4 $
+ *
+ * last change: $Author: rt $ $Date: 2005-01-31 16:42:03 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright (c) 2003 by Sun Microsystems, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+#include <windows.h>
+
+#include "jawt.h"
+#include "jawt_md.h"
+#include "NativeView.h"
+
+#define MY_ASSERT(X,S) if (!X) { fprintf(stderr,"%s\n",S); return 0L;}
+
+#define SYSTEM_WIN32 1
+#define SYSTEM_WIN16 2
+#define SYSTEM_JAVA 3
+#define SYSTEM_OS2 4
+#define SYSTEM_MAC 5
+#define SYSTEM_XWINDOW 6
+
+// property name to register own window procedure on hwnd
+#define OLD_PROC_KEY "oldwindowproc"
+// signature of this window procedure
+static LRESULT APIENTRY NativeViewWndProc( HWND , UINT , WPARAM , LPARAM );
+
+/*****************************************************************************
+ *
+ * Class : NativeView
+ * Method : getNativeWindowSystemType
+ * Signature : ()I
+ * Description: returns an identifier for the current operating system
+ */
+JNIEXPORT jint JNICALL Java_NativeView_getNativeWindowSystemType
+ (JNIEnv * env, jobject obj_this)
+{
+ return (SYSTEM_WIN32);
+}
+
+/*****************************************************************************
+ *
+ * Class : NativeView
+ * Method : getNativeWindow
+ * Signature : ()J
+ * Description: returns the native systemw window handle of this object
+ */
+JNIEXPORT jlong JNICALL Java_NativeView_getNativeWindow
+ (JNIEnv * env, jobject obj_this)
+{
+ jboolean result ;
+ jint lock ;
+ JAWT awt ;
+ JAWT_DrawingSurface* ds ;
+ JAWT_DrawingSurfaceInfo* dsi ;
+ JAWT_Win32DrawingSurfaceInfo* dsi_win ;
+ HDC hdc ;
+ HWND hWnd ;
+ LONG hFuncPtr;
+
+ /* Get the AWT */
+ awt.version = JAWT_VERSION_1_3;
+ result = JAWT_GetAWT(env, &awt);
+ MY_ASSERT(result!=JNI_FALSE,"wrong jawt version");
+
+ /* Get the drawing surface */
+ if ((ds = awt.GetDrawingSurface(env, obj_this)) == NULL)
+ return 0L;
+
+ /* Lock the drawing surface */
+ lock = ds->Lock(ds);
+ MY_ASSERT((lock & JAWT_LOCK_ERROR)==0,"can't lock the drawing surface");
+
+ /* Get the drawing surface info */
+ dsi = ds->GetDrawingSurfaceInfo(ds);
+
+ /* Get the platform-specific drawing info */
+ dsi_win = (JAWT_Win32DrawingSurfaceInfo*)dsi->platformInfo;
+ hdc = dsi_win->hdc;
+ hWnd = dsi_win->hwnd;
+
+ /* Free the drawing surface info */
+ ds->FreeDrawingSurfaceInfo(dsi);
+ /* Unlock the drawing surface */
+ ds->Unlock(ds);
+ /* Free the drawing surface */
+ awt.FreeDrawingSurface(ds);
+
+ /* Register own window procedure
+ Do it one times only! Otherwhise
+ multiple instances will be registered
+ and calls on such construct produce
+ a stack overflow.
+ */
+ if (GetProp( hWnd, OLD_PROC_KEY )==0)
+ {
+ hFuncPtr = SetWindowLong( hWnd, GWL_WNDPROC, (DWORD)NativeViewWndProc );
+ SetProp( hWnd, OLD_PROC_KEY, (HANDLE)hFuncPtr );
+ }
+
+ return ((jlong)hWnd);
+}
+
+/*****************************************************************************
+ *
+ * Class : -
+ * Method : NativeViewWndProc
+ * Signature : -
+ * Description: registered window handler to intercept window messages between
+ * java and office process
+ */
+static LRESULT APIENTRY NativeViewWndProc(
+ HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
+{
+ HANDLE hFuncPtr;
+
+ /* resize new created child window to fill out the java window complete */
+ if (uMsg==WM_PARENTNOTIFY)
+ {
+ if (wParam == WM_CREATE)
+ {
+ RECT rect;
+ HWND hChild = (HWND) lParam;
+
+ GetClientRect(hWnd, &rect);
+
+ SetWindowPos(hChild,
+ NULL,
+ rect.left,
+ rect.top,
+ rect.right - rect.left,
+ rect.bottom - rect.top,
+ SWP_NOZORDER);
+ }
+ }
+ /* handle normal resize events */
+ else if(uMsg==WM_SIZE)
+ {
+ WORD newHeight = HIWORD(lParam);
+ WORD newWidth = LOWORD(lParam);
+ HWND hChild = GetWindow(hWnd, GW_CHILD);
+
+ if (hChild != NULL)
+ SetWindowPos(hChild, NULL, 0, 0, newWidth, newHeight, SWP_NOZORDER);
+ }
+
+ /* forward request to original handler which is intercepted by this window procedure */
+ hFuncPtr = GetProp(hWnd, OLD_PROC_KEY);
+ MY_ASSERT(hFuncPtr,"lost original window proc handler");
+ return CallWindowProc( hFuncPtr, hWnd, uMsg, wParam, lParam);
+}
diff --git a/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/nativelib/windows/nativeview.h b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/nativelib/windows/nativeview.h
new file mode 100644
index 000000000000..1da98ba3158e
--- /dev/null
+++ b/odk/examples/DevelopersGuide/OfficeDev/DesktopEnvironment/nativelib/windows/nativeview.h
@@ -0,0 +1,69 @@
+/*************************************************************************
+ *
+ * $RCSfile: nativeview.h,v $
+ *
+ * $Revision: 1.4 $
+ *
+ * last change: $Author: rt $ $Date: 2005-01-31 16:42:16 $
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright (c) 2003 by Sun Microsystems, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+/* DO NOT EDIT THIS FILE - it is machine generated */
+#include <jni.h>
+/* Header for class org_openoffice_OpenOffice */
+
+#ifndef _Included_NativeView
+#define _Included_NativeView
+#ifdef __cplusplus
+extern "C" {
+#endif
+/*
+ * Class: org_openoffice_OpenOffice
+ * Method: getNativeWindowSystemType
+ * Signature: ()I
+ */
+JNIEXPORT jint JNICALL Java_NativeView_getNativeWindowSystemType
+ (JNIEnv *, jobject);
+
+/*
+ * Class: org_openoffice_OpenOffice
+ * Method: getNativeWindow
+ * Signature: ()J
+ */
+JNIEXPORT jlong JNICALL Java_NativeView_getNativeWindow
+ (JNIEnv *, jobject);
+
+#ifdef __cplusplus
+}
+#endif
+#endif