From ed5640d8b587fbcfed7dd7967f3de04b37a76f26 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 11:06:44 +0200 Subject: Adding upstream version 4:7.4.7. Signed-off-by: Daniel Baumann --- .../EmbedDocument/EmbeddedObject/EditorFrame.java | 134 +++ .../EmbeddedObject/EmbeddedObject.odt | Bin 0 -> 9975 bytes .../EmbeddedObject/EmbeddedObject.xcu | 45 + .../java/EmbedDocument/EmbeddedObject/Makefile | 148 +++ .../EmbeddedObject/OwnEmbeddedObject.components | 8 + .../EmbeddedObject/OwnEmbeddedObject.java | 1123 ++++++++++++++++++++ .../EmbeddedObject/OwnEmbeddedObjectFactory.java | 106 ++ 7 files changed, 1564 insertions(+) create mode 100644 odk/examples/java/EmbedDocument/EmbeddedObject/EditorFrame.java create mode 100644 odk/examples/java/EmbedDocument/EmbeddedObject/EmbeddedObject.odt create mode 100644 odk/examples/java/EmbedDocument/EmbeddedObject/EmbeddedObject.xcu create mode 100644 odk/examples/java/EmbedDocument/EmbeddedObject/Makefile create mode 100644 odk/examples/java/EmbedDocument/EmbeddedObject/OwnEmbeddedObject.components create mode 100644 odk/examples/java/EmbedDocument/EmbeddedObject/OwnEmbeddedObject.java create mode 100644 odk/examples/java/EmbedDocument/EmbeddedObject/OwnEmbeddedObjectFactory.java (limited to 'odk/examples/java/EmbedDocument/EmbeddedObject') diff --git a/odk/examples/java/EmbedDocument/EmbeddedObject/EditorFrame.java b/odk/examples/java/EmbedDocument/EmbeddedObject/EditorFrame.java new file mode 100644 index 000000000..fb15106b7 --- /dev/null +++ b/odk/examples/java/EmbedDocument/EmbeddedObject/EditorFrame.java @@ -0,0 +1,134 @@ +/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +import java.awt.*; +import java.awt.event.*; +import java.awt.image.*; +import javax.swing.JTextArea; +import javax.swing.JFrame; +import java.io.*; +import javax.imageio.ImageIO; + +public class EditorFrame extends JFrame +{ + private final OwnEmbeddedObject m_aEmbObj; + private final JTextArea m_aTextArea; + private BufferedImage m_aBufImage; + + private final WindowListener m_aCloser = new WindowAdapter() + { + @Override + public void windowClosing( WindowEvent e ) + { + m_aBufImage = new BufferedImage( m_aTextArea.getWidth(), m_aTextArea.getHeight(), BufferedImage.TYPE_INT_RGB ); + Graphics2D aGr = m_aBufImage.createGraphics(); + m_aTextArea.paintAll( aGr ); + aGr.dispose(); + + hide(); + m_aEmbObj.CloseFrameRequest(); + } + }; + + public EditorFrame( String sName, OwnEmbeddedObject aEmbObj, int nWidth, int nHeight ) + { + super( sName ); + m_aEmbObj = aEmbObj; + addWindowListener( m_aCloser ); + m_aTextArea = new JTextArea( "", nWidth, nHeight ); + + add( "Center", m_aTextArea ); + pack(); + } + + public String getText() + { + return m_aTextArea.getText(); + } + + public void setText( String aText ) + { + m_aTextArea.setText( aText ); + } + + public Dimension getAppSize() + { + return m_aTextArea.getSize(); + } + + public void setAppSize( Dimension aSize ) + { + Dimension aOwnSize = getSize(); + Dimension aAppSize = m_aTextArea.getSize(); + Dimension aToSet = + new Dimension( (int)( aSize.getWidth() + aOwnSize.getWidth() - aAppSize.getWidth() ), + (int)(aSize.getHeight() + aOwnSize.getHeight() - aAppSize.getHeight() ) ); + + setSize( aToSet ); + validate(); + } + + public byte[] getReplacementImage() + { + Dimension aDim = m_aTextArea.getSize(); + BufferedImage aBufImage = null; + + if ( m_aBufImage != null ) + aBufImage = m_aBufImage; + else + { + try + { + int nWidth = (int)aDim.getWidth(); + int nHeight = (int)aDim.getHeight(); + aBufImage = new BufferedImage( nWidth, nHeight, BufferedImage.TYPE_INT_RGB ); + Graphics2D aGr = aBufImage.createGraphics(); + aGr.setBackground( Color.WHITE ); + aGr.clearRect( 0, 0, nWidth, nHeight ); + aGr.dispose(); + } + catch ( java.lang.Exception e ) + {} + } + + if ( aBufImage != null ) + { + try + { + File aTmpFile = File.createTempFile( "temp", ".png" ); + ImageIO.write( aBufImage, "png", aTmpFile ); + + int nLen = (int)aTmpFile.length(); + byte[] aResult = new byte[nLen]; + FileInputStream aTmpStream = new FileInputStream( aTmpFile ); + aTmpStream.read( aResult ); + aTmpStream.close(); + aTmpFile.delete(); + + return aResult; + } + catch ( java.lang.Exception e ) + {} + } + + return new byte[0]; + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/odk/examples/java/EmbedDocument/EmbeddedObject/EmbeddedObject.odt b/odk/examples/java/EmbedDocument/EmbeddedObject/EmbeddedObject.odt new file mode 100644 index 000000000..dde408bd3 Binary files /dev/null and b/odk/examples/java/EmbedDocument/EmbeddedObject/EmbeddedObject.odt differ diff --git a/odk/examples/java/EmbedDocument/EmbeddedObject/EmbeddedObject.xcu b/odk/examples/java/EmbedDocument/EmbeddedObject/EmbeddedObject.xcu new file mode 100644 index 000000000..ce7f3785b --- /dev/null +++ b/odk/examples/java/EmbedDocument/EmbeddedObject/EmbeddedObject.xcu @@ -0,0 +1,45 @@ + + + + + + + org.openoffice.examples.embedding.Factory69474366FD6F480683748EDD1B6E771D + + + PRIMARY SHOW OPEN HIDE + + + + + 69474366-FD6F-4806-8374-8EDD1B6E771D + + + + + + Example of a simple outplace text object + + + 69474366-FD6F-4806-8374-8EDD1B6E771D + + + + + diff --git a/odk/examples/java/EmbedDocument/EmbeddedObject/Makefile b/odk/examples/java/EmbedDocument/EmbeddedObject/Makefile new file mode 100644 index 000000000..b568c39c2 --- /dev/null +++ b/odk/examples/java/EmbedDocument/EmbeddedObject/Makefile @@ -0,0 +1,148 @@ +#************************************************************************* +# +# The Contents of this file are made available subject to the terms of +# the BSD license. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# 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. +# +#************************************************************************** + +PRJ=../../../.. +SETTINGS=$(PRJ)/settings + +include $(SETTINGS)/settings.mk +include $(SETTINGS)/std.mk + +# Define non-platform/compiler specific settings + +# we use the sample directory name for separating this example +# from others in the output directory +SAMPLE_NAME=EmbeddedObject +SAMPLE_CLASS_OUT=$(OUT_CLASS)/$(SAMPLE_NAME) +SAMPLE_GEN_OUT=$(OUT_MISC)/$(SAMPLE_NAME) + +COMP_NAME=OwnEmbeddedObject +COMP_CLASS_OUT=$(SAMPLE_CLASS_OUT)/$(COMP_NAME) +COMP_GEN_OUT=$(SAMPLE_GEN_OUT)/$(COMP_NAME) +COMP_PACKAGE=$(OUT_BIN)/$(COMP_NAME).$(UNOOXT_EXT) +COMP_PACKAGE_URL=$(subst \\,\,"$(COMP_PACKAGE_DIR)$(PS)$(COMP_NAME).$(UNOOXT_EXT)") +COMP_JAR_NAME=$(COMP_NAME).uno.jar +COMP_JAR=$(SAMPLE_CLASS_OUT)/$(COMP_JAR_NAME) +COMP_JAR_MANIFEST=$(COMP_GEN_OUT)/$(COMP_NAME).Manifest +COMP_UNOPKG_MANIFEST = $(COMP_GEN_OUT)/META-INF/manifest.xml +COMP_REGISTERFLAG=$(COMP_GEN_OUT)$(PS)java_$(COMP_NAME)_register_component.flag +COMP_COMPONENTS=$(COMP_NAME).components + +PACKAGE = + +COMP_JAVAFILES =\ + OwnEmbeddedObject.java\ + OwnEmbeddedObjectFactory.java\ + EditorFrame.java + +COMP_CLASSFILES = $(patsubst %.java,$(COMP_CLASS_OUT)/%.class,$(COMP_JAVAFILES)) + +SDK_CLASSPATH = $(subst $(EMPTYSTRING) $(PATH_SEPARATOR),$(PATH_SEPARATOR),$(CLASSPATH)\ + $(PATH_SEPARATOR)$(SAMPLE_CLASS_OUT)\ + $(PATH_SEPARATOR)$(COMP_CLASS_OUT)) + + +# Targets +.PHONY: ALL +ALL : $(COMP_NAME) + +include $(SETTINGS)/stdtarget.mk + +$(COMP_GEN_OUT)/%.Manifest : + -$(MKDIR) $(subst \\,\,$(subst /,$(PS),$(@D))) + @echo RegistrationClassName: $(subst /,.,$(PACKAGE)).$(COMP_NAME)Factory> $@ + +# component as well as application are dependent from the generated types +# rule for component class files +$(COMP_CLASS_OUT)/%.class : $(COMP_JAVAFILES) + -$(MKDIR) $(subst /,$(PS),$(@D)) + $(SDK_JAVAC) $(JAVAC_FLAGS) -classpath "$(SDK_CLASSPATH)" -d $(COMP_CLASS_OUT) $(COMP_JAVAFILES) + +# rule for component jar file +$(COMP_JAR) : $(COMP_JAR_MANIFEST) $(COMP_CLASSFILES) + -$(DEL) $(subst \\,\,$(subst /,$(PS),$@)) + -$(MKDIR) $(subst /,$(PS),$(@D)) + $(SDK_JAR) cvfm $@ $< -C $(COMP_CLASS_OUT) . + +# rule for component package manifest +$(COMP_GEN_OUT)/%/manifest.xml : + -$(MKDIR) $(subst /,$(PS),$(@D)) + @echo $(OSEP)?xml version="$(QM)1.0$(QM)" encoding="$(QM)UTF-8$(QM)"?$(CSEP) > $@ + @echo $(OSEP)manifest:manifest xmlns:manifest="$(QM)http://openoffice.org/2001/manifest$(QM)"$(CSEP) >> $@ + @echo $(SQM) $(SQM)$(OSEP)manifest:file-entry manifest:media-type="$(QM)application/vnd.sun.star.configuration-data$(QM)" >> $@ + @echo $(SQM) $(SQM)manifest:full-path="$(QM)$(SAMPLE_NAME).xcu$(QM)"/$(CSEP) >> $@ + @echo $(SQM) $(SQM)$(OSEP)manifest:file-entry manifest:media-type="$(QM)application/vnd.sun.star.uno-components$(QM)">> $@ + @echo $(SQM) $(SQM)manifest:full-path="$(QM)$(COMP_NAME).components$(QM)"/$(CSEP)>> $@ + @echo $(OSEP)/manifest:manifest$(CSEP) >> $@ + +# rule for component package file +$(COMP_PACKAGE) : $(COMP_JAR) $(COMP_UNOPKG_MANIFEST) $(COMP_NAME).components + -$(DEL) $(subst \\,\,$(subst /,$(PS),$@)) + -$(MKDIR) $(subst /,$(PS),$(@D)) + $(SDK_ZIP) $@ $(SAMPLE_NAME).xcu + $(SDK_ZIP) $@ -u $(COMP_NAME).components + cd $(subst /,$(PS),$(SAMPLE_CLASS_OUT)) && $(SDK_ZIP) -u $@ $(COMP_JAR_NAME) + cd $(subst /,$(PS),$(COMP_GEN_OUT)) && $(SDK_ZIP) -u $@ META-INF/manifest.xml + +$(COMP_REGISTERFLAG) : $(COMP_PACKAGE) +ifeq "$(SDK_AUTO_DEPLOYMENT)" "YES" + -$(DEL) $(subst \\,\,$(subst /,$(PS),$@)) + -$(MKDIR) $(subst \\,\,$(subst /,$(PS),$(@D))) + $(DEPLOYTOOL) $(COMP_PACKAGE_URL) + @echo flagged > $(subst /,$(PS),$@) +else + @echo -------------------------------------------------------------------------------- + @echo If you want to install your component automatically, please set the environment + @echo variable SDK_AUTO_DEPLOYMENT = YES. But note that auto deployment is only + @echo possible if no office instance is running. + @echo -------------------------------------------------------------------------------- +endif + +$(COMP_NAME) : $(COMP_REGISTERFLAG) + @echo ------ + @echo The $(COMP_NAME) component was installed if SDK_AUTO_DEPLOYMENT = YES. + @echo Load the "$(QM)$(SAMPLE_NAME).odt$(QM)" document to see how this component works. + @echo You can use this component inside your office installation, see the example + @echo description. + @echo - + @echo $(MAKE) $(SAMPLE_NAME).odt.load + @echo -------------------------------------------------------------------------------- + +$(SAMPLE_NAME).odt.load : $(COMP_REGISTERFLAG) + "$(OFFICE_PROGRAM_PATH)$(PS)soffice" $(basename $@) + +.PHONY: clean +clean : + -$(DELRECURSIVE) $(subst /,$(PS),$(SAMPLE_CLASS_OUT)) + -$(DELRECURSIVE) $(subst /,$(PS),$(SAMPLE_GEN_OUT)) + -$(DEL) $(subst \\,\,$(subst /,$(PS),$(COMP_PACKAGE_URL))) diff --git a/odk/examples/java/EmbedDocument/EmbeddedObject/OwnEmbeddedObject.components b/odk/examples/java/EmbedDocument/EmbeddedObject/OwnEmbeddedObject.components new file mode 100644 index 000000000..a77b099e0 --- /dev/null +++ b/odk/examples/java/EmbedDocument/EmbeddedObject/OwnEmbeddedObject.components @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/odk/examples/java/EmbedDocument/EmbeddedObject/OwnEmbeddedObject.java b/odk/examples/java/EmbedDocument/EmbeddedObject/OwnEmbeddedObject.java new file mode 100644 index 000000000..f2377dcbc --- /dev/null +++ b/odk/examples/java/EmbedDocument/EmbeddedObject/OwnEmbeddedObject.java @@ -0,0 +1,1123 @@ +/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +import java.awt.Dimension; +import java.util.ArrayList; + +import com.sun.star.beans.XPropertySet; +import com.sun.star.configuration.theDefaultProvider; +import com.sun.star.container.XNameAccess; +import com.sun.star.embed.VisualRepresentation; +import com.sun.star.embed.XStorage; +import com.sun.star.embed.XTransactedObject; +import com.sun.star.io.XInputStream; +import com.sun.star.io.XOutputStream; +import com.sun.star.io.XStream; +import com.sun.star.io.XTruncate; +import com.sun.star.lang.XComponent; +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.lib.uno.helper.WeakBase; +import com.sun.star.uno.AnyConverter; +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XComponentContext; + +public final class OwnEmbeddedObject extends WeakBase + implements com.sun.star.embed.XEmbedPersist, + com.sun.star.embed.XEmbeddedObject +{ + private final XComponentContext m_xContext; + private final byte[] m_aClassID; + + private boolean m_bDisposed = false; + private int m_nObjectState = -1; + + private com.sun.star.embed.XStorage m_xParentStorage; + private com.sun.star.embed.XStorage m_xOwnStorage; + private String m_aEntryName; + + private com.sun.star.embed.XStorage m_xNewParentStorage; + private com.sun.star.embed.XStorage m_xNewOwnStorage; + private String m_aNewEntryName; + private boolean m_bWaitSaveCompleted = false; + + private EditorFrame m_aEditorFrame; + + private ArrayList m_aListeners; + + private com.sun.star.embed.VerbDescriptor[] m_pOwnVerbs; + + private com.sun.star.embed.XEmbeddedClient m_xClient; + + private Dimension m_aObjSize; + + + private ArrayList GetListeners() + { + if ( m_aListeners == null ) + m_aListeners = new ArrayList(10); + + return m_aListeners; + } + + + private Dimension UpdateSizeAndGetFromActive() + { + if ( m_nObjectState == com.sun.star.embed.EmbedStates.ACTIVE ) + m_aObjSize = m_aEditorFrame.getAppSize(); + + if ( m_aObjSize != null ) + return m_aObjSize; + else + return new Dimension(); + } + + + private void SwitchOwnPersistence( XStorage xParentStorage, XStorage xOwnStorage, String aEntryName ) + { + if ( xOwnStorage != m_xOwnStorage ) + { + if ( m_xOwnStorage != null ) + m_xOwnStorage.dispose(); + m_xParentStorage = xParentStorage; + m_xOwnStorage = xOwnStorage; + m_aEntryName = aEntryName; + } + } + + + private void SwitchOwnPersistence( XStorage xParentStorage, String aEntryName ) throws com.sun.star.io.IOException + { + if ( xParentStorage != m_xParentStorage || !aEntryName.equals( m_aEntryName ) ) + { + try + { + XStorage xOwnStorage = xParentStorage.openStorageElement( aEntryName, com.sun.star.embed.ElementModes.READWRITE ); + SwitchOwnPersistence( xParentStorage, xOwnStorage, aEntryName ); + } + catch( com.sun.star.io.IOException e ) + { + throw e; + } + catch( com.sun.star.uno.Exception e ) + { + com.sun.star.io.IOException e2 = new com.sun.star.io.IOException( "Error while switching object storage!" ); + e2.initCause(e); + throw e2; + } + } + } + + + private static void SaveDataToStorage( XStorage xStorage, String aString, Dimension aDimension ) throws com.sun.star.io.IOException + { + try + { + // save the text + XStream xStream = xStorage.openStreamElement( "content.txt", com.sun.star.embed.ElementModes.READWRITE ); + XComponent xStreamComp = UnoRuntime.queryInterface( XComponent.class, xStream ); + if ( xStreamComp == null ) + throw new com.sun.star.uno.RuntimeException(); + + XOutputStream xOutStream = xStream.getOutputStream(); + XTruncate xTruncate = UnoRuntime.queryInterface( XTruncate.class, xOutStream ); + if ( xTruncate == null ) + throw new com.sun.star.io.IOException(); + + xTruncate.truncate(); + xOutStream.writeBytes( aString.getBytes() ); + + // save the size + xStream = xStorage.openStreamElement( "properties.txt", com.sun.star.embed.ElementModes.READWRITE ); + xStreamComp = UnoRuntime.queryInterface( XComponent.class, xStream ); + if ( xStreamComp == null ) + throw new com.sun.star.uno.RuntimeException(); + + xOutStream = xStream.getOutputStream(); + xTruncate = UnoRuntime.queryInterface( XTruncate.class, xOutStream ); + if ( xTruncate == null ) + throw new com.sun.star.io.IOException(); + + xTruncate.truncate(); + String aProps = Integer.toString( (int)aDimension.getWidth() ) + "|" + Integer.toString( (int)aDimension.getHeight() ); + xOutStream.writeBytes( aProps.getBytes() ); + + // set the media type + XPropertySet xPropSet = UnoRuntime.queryInterface( XPropertySet.class, xStorage ); + if ( xPropSet == null ) + throw new com.sun.star.uno.RuntimeException(); + xPropSet.setPropertyValue( "MediaType", "application/x-openoffice-embedded-69474366-FD6F-4806-8374-8EDD1B6E771D" ); + + XTransactedObject xTransact = UnoRuntime.queryInterface( XTransactedObject.class, xStorage ); + if ( xTransact != null ) + xTransact.commit(); + + xStreamComp.dispose(); + } + catch( com.sun.star.io.IOException e ) + { + throw e; + } + catch( com.sun.star.uno.Exception e ) + { + com.sun.star.io.IOException e2 = new com.sun.star.io.IOException( "Error while switching object storage!" ); + e2.initCause(e); + throw e2; + } + } + + + private void PostEvent( String aEvEntryName ) + { + if ( m_aListeners != null ) + { + com.sun.star.document.EventObject aEventObject = new com.sun.star.document.EventObject( this, aEvEntryName ); + for ( int nInd = 0; nInd < m_aListeners.size(); nInd++ ) + { + try + { + com.sun.star.document.XEventListener xListener = UnoRuntime.queryInterface( com.sun.star.document.XEventListener.class, m_aListeners.get( nInd ) ); + + if ( xListener != null ) + xListener.notifyEvent( aEventObject ); + } + catch( java.lang.Exception e ) + { + m_aListeners.remove( nInd ); + } + } + } + } + + + private void StateChangeNotification( boolean bBeforeChange, int nOldState, int nNewState ) + { + if ( m_aListeners != null ) + { + com.sun.star.lang.EventObject aEventObject = new com.sun.star.lang.EventObject( this ); + for ( int nInd = 0; nInd < m_aListeners.size(); nInd++ ) + { + try + { + com.sun.star.embed.XStateChangeListener xListener = UnoRuntime.queryInterface( com.sun.star.embed.XStateChangeListener.class, m_aListeners.get( nInd ) ); + + if ( xListener != null ) + { + if ( bBeforeChange ) + xListener.changingState( aEventObject, nOldState, nNewState ); + else + xListener.stateChanged( aEventObject, nOldState, nNewState ); + } + } + catch( java.lang.Exception e ) + { + m_aListeners.remove( nInd ); + } + } + } + } + + + private String ReadStringFromStream( XStorage xStorage, String aStreamName ) throws com.sun.star.io.IOException + { + if ( xStorage == null ) + throw new com.sun.star.uno.RuntimeException(); + + try + { + XStream xStream = xStorage.openStreamElement( aStreamName, com.sun.star.embed.ElementModes.READWRITE ); + XComponent xStreamComp = UnoRuntime.queryInterface( XComponent.class, xStream ); + if ( xStreamComp == null ) + throw new com.sun.star.uno.RuntimeException(); + + XInputStream xInStream = xStream.getInputStream(); + byte[][] aData = new byte[1][]; + aData[0] = new byte[0]; + String aResult = ""; + + int nLen = 0; + do + { + nLen = xInStream.readBytes( aData, 10 ); + if ( aData.length == 0 || aData[0] == null ) + throw new com.sun.star.io.IOException(); + aResult += new String( aData[0] ); + } while( nLen > 0 ); + + xStreamComp.dispose(); + + return aResult; + } + catch( com.sun.star.io.IOException e ) + { + throw e; + } + catch( com.sun.star.uno.Exception e ) + { + com.sun.star.io.IOException e2 = new com.sun.star.io.IOException( "Error while reading one of object streams!" ); + e2.initCause(e); + throw e2; + } + } + + + private void ReadSizeFromOwnStorage() throws com.sun.star.io.IOException + { + String aSize = ReadStringFromStream( m_xOwnStorage, "properties.txt" ); + + int nSeparator = aSize.indexOf( '|' ); + if ( nSeparator > 0 && nSeparator < aSize.length() - 1 ) + { + int nWidth = Integer.parseInt( aSize.substring( 0, nSeparator ) ); + int nHeight = Integer.parseInt( aSize.substring( nSeparator + 1, aSize.length() ) ); + m_aObjSize = new Dimension( nWidth, nHeight ); + } + } + + + public OwnEmbeddedObject( XComponentContext context, byte[] aClassID ) + { + m_xContext = context; + m_aClassID = aClassID; + } + + + public void CloseFrameRequest() + { + com.sun.star.embed.XEmbeddedClient xClient = m_xClient; + if ( xClient == null ) + return; + + UpdateSizeAndGetFromActive(); + StateChangeNotification( true, com.sun.star.embed.EmbedStates.ACTIVE, com.sun.star.embed.EmbedStates.RUNNING ); + + try{ + xClient.visibilityChanged( false ); + } catch( com.sun.star.uno.Exception e ){} + + try{ + xClient.saveObject(); + } catch( com.sun.star.uno.Exception e ){} + + m_nObjectState = com.sun.star.embed.EmbedStates.RUNNING; + StateChangeNotification( false, com.sun.star.embed.EmbedStates.ACTIVE, m_nObjectState ); + + PostEvent( "OnVisAreaChanged" ); + } + + // com.sun.star.embed.XCommonEmbedPersist: + + public void storeOwn() throws com.sun.star.embed.WrongStateException, com.sun.star.io.IOException, com.sun.star.uno.Exception + { + if ( m_bDisposed ) + throw new com.sun.star.lang.DisposedException(); + + if ( m_nObjectState == -1 || m_bWaitSaveCompleted ) + throw new com.sun.star.embed.WrongStateException(); + + // nothing to do, if the object is in loaded state + if ( m_nObjectState == com.sun.star.embed.EmbedStates.LOADED ) + return; + + if ( m_xOwnStorage == null ) + throw new com.sun.star.io.IOException(); + + PostEvent( "OnSave" ); + + if ( m_aEditorFrame == null ) + throw new com.sun.star.uno.RuntimeException(); + + SaveDataToStorage( m_xOwnStorage, m_aEditorFrame.getText(), UpdateSizeAndGetFromActive() ); + + PostEvent( "OnSaveDone" ); + } + + + public boolean isReadonly() throws com.sun.star.embed.WrongStateException + { + return false; + } + + + public void reload(com.sun.star.beans.PropertyValue[] aMediaArgs, com.sun.star.beans.PropertyValue[] aObjectArgs) throws com.sun.star.lang.IllegalArgumentException, com.sun.star.embed.WrongStateException, com.sun.star.io.IOException, com.sun.star.uno.Exception + { + // not implemented currently + } + + // com.sun.star.embed.XEmbedPersist: + + public void setPersistentEntry(com.sun.star.embed.XStorage xStorage, String aEntryName, int nEntryConnectionMode, com.sun.star.beans.PropertyValue[] aMediaArgs, com.sun.star.beans.PropertyValue[] aObjectArgs) throws com.sun.star.lang.IllegalArgumentException, com.sun.star.embed.WrongStateException, com.sun.star.io.IOException, com.sun.star.uno.Exception + { + if ( m_bDisposed ) + throw new com.sun.star.lang.DisposedException(); + + if ( xStorage == null || aEntryName.length() == 0 ) + throw new com.sun.star.lang.IllegalArgumentException(); + + if ( ( m_nObjectState != -1 || nEntryConnectionMode == com.sun.star.embed.EntryInitModes.NO_INIT ) + && ( m_nObjectState == -1 || nEntryConnectionMode != com.sun.star.embed.EntryInitModes.NO_INIT ) ) + { + // if the object is not loaded + // it can not get persistent representation without initialization + + // if the object is loaded + // it can switch persistent representation only without initialization + + throw new com.sun.star.embed.WrongStateException(); + } + + if ( m_bWaitSaveCompleted ) + { + if ( nEntryConnectionMode == com.sun.star.embed.EntryInitModes.NO_INIT ) + { + if ( m_xParentStorage == xStorage && m_aEntryName.equals( aEntryName ) ) + saveCompleted( false ); + else if ( m_xNewParentStorage == xStorage && m_aNewEntryName.equals( aEntryName ) ) + saveCompleted( true ); + else + throw new com.sun.star.embed.WrongStateException(); + } + else + throw new com.sun.star.embed.WrongStateException(); + + return; + } + + boolean bElExists = xStorage.hasByName( aEntryName ); + + if ( nEntryConnectionMode == com.sun.star.embed.EntryInitModes.DEFAULT_INIT ) + { + SwitchOwnPersistence( xStorage, aEntryName ); + if ( bElExists ) + { + XPropertySet xPropSet = UnoRuntime.queryInterface( XPropertySet.class, m_xOwnStorage ); + if ( xPropSet == null ) + throw new com.sun.star.uno.RuntimeException(); + + String aMediaType = AnyConverter.toString( xPropSet.getPropertyValue( "MediaType" ) ); + if ( !aMediaType.equals( "application/x-openoffice-embedded-69474366-FD6F-4806-8374-8EDD1B6E771D" ) ) + throw new com.sun.star.lang.IllegalArgumentException(); + + m_nObjectState = com.sun.star.embed.EmbedStates.LOADED; + } + else + { + m_aEditorFrame = new EditorFrame( m_aEntryName, this, 5, 20 ); + m_nObjectState = com.sun.star.embed.EmbedStates.RUNNING; + m_aObjSize = m_aEditorFrame.getAppSize(); + } + } + else if ( nEntryConnectionMode == com.sun.star.embed.EntryInitModes.TRUNCATE_INIT ) + { + SwitchOwnPersistence( xStorage, aEntryName ); + m_aEditorFrame = new EditorFrame( m_aEntryName, this, 5, 20 ); + m_nObjectState = com.sun.star.embed.EmbedStates.RUNNING; + m_aObjSize = m_aEditorFrame.getAppSize(); + } + else + throw new com.sun.star.lang.IllegalArgumentException(); + } + + + public void storeToEntry(com.sun.star.embed.XStorage xStorage, String aEntryName, com.sun.star.beans.PropertyValue[] aMediaArgs, com.sun.star.beans.PropertyValue[] aObjectArgs) throws com.sun.star.lang.IllegalArgumentException, com.sun.star.embed.WrongStateException, com.sun.star.io.IOException, com.sun.star.uno.Exception + { + if ( m_bDisposed ) + throw new com.sun.star.lang.DisposedException(); + + if ( m_nObjectState == -1 || m_bWaitSaveCompleted ) + throw new com.sun.star.embed.WrongStateException(); + + if ( m_nObjectState == com.sun.star.embed.EmbedStates.LOADED ) + { + m_xParentStorage.copyElementTo( m_aEntryName, xStorage, aEntryName ); + } + else + { + com.sun.star.embed.XStorage xSubStorage = + xStorage.openStorageElement( aEntryName, + com.sun.star.embed.ElementModes.READWRITE | com.sun.star.embed.ElementModes.TRUNCATE ); + + SaveDataToStorage( xSubStorage, m_aEditorFrame.getText(), UpdateSizeAndGetFromActive() ); + } + } + + + public void storeAsEntry(com.sun.star.embed.XStorage xStorage, String aEntryName, com.sun.star.beans.PropertyValue[] aMediaArgs, com.sun.star.beans.PropertyValue[] aObjectArgs) throws com.sun.star.lang.IllegalArgumentException, com.sun.star.embed.WrongStateException, com.sun.star.io.IOException, com.sun.star.uno.Exception + { + if ( m_bDisposed ) + throw new com.sun.star.lang.DisposedException(); + + if ( m_nObjectState == -1 || m_bWaitSaveCompleted ) + throw new com.sun.star.embed.WrongStateException(); + + com.sun.star.embed.XStorage xSubStorage = null; + + if ( m_nObjectState == com.sun.star.embed.EmbedStates.LOADED ) + { + xSubStorage = + xStorage.openStorageElement( aEntryName, + com.sun.star.embed.ElementModes.READWRITE | com.sun.star.embed.ElementModes.NOCREATE ); + + m_xOwnStorage.copyToStorage( xSubStorage ); + } + else + { + xSubStorage = + xStorage.openStorageElement( aEntryName, + com.sun.star.embed.ElementModes.READWRITE | com.sun.star.embed.ElementModes.TRUNCATE ); + + SaveDataToStorage( xSubStorage, m_aEditorFrame.getText(), UpdateSizeAndGetFromActive() ); + } + + m_bWaitSaveCompleted = true; + m_xNewOwnStorage = xSubStorage; + m_xNewParentStorage = xStorage; + m_aNewEntryName = aEntryName; + + } + + + public void saveCompleted(boolean bUseNew) throws com.sun.star.embed.WrongStateException, com.sun.star.uno.Exception + { + if ( m_bDisposed ) + throw new com.sun.star.lang.DisposedException(); + + if ( m_nObjectState == -1 ) + throw new com.sun.star.embed.WrongStateException(); + + // it is allowed to call saveCompleted( false ) for nonstored objects + if ( !m_bWaitSaveCompleted && !bUseNew ) + return; + + if ( !m_bWaitSaveCompleted ) + throw new com.sun.star.io.IOException(); + + if ( bUseNew ) + { + SwitchOwnPersistence( m_xNewParentStorage, m_xNewOwnStorage, m_aNewEntryName ); + PostEvent( "OnSaveAsDone" ); + } + else + { + try + { + m_xNewOwnStorage.dispose(); + } + catch( com.sun.star.uno.RuntimeException e ) + {} + } + + m_xNewOwnStorage = null; + m_xNewParentStorage = null; + m_aNewEntryName = null; + m_bWaitSaveCompleted = false; + } + + + public boolean hasEntry() throws com.sun.star.embed.WrongStateException + { + if ( m_bDisposed ) + throw new com.sun.star.lang.DisposedException(); + + if ( m_bWaitSaveCompleted ) + throw new com.sun.star.embed.WrongStateException(); + + if ( m_xOwnStorage != null ) + return true; + + return false; + } + + + public String getEntryName() throws com.sun.star.embed.WrongStateException + { + if ( m_bDisposed ) + throw new com.sun.star.lang.DisposedException(); + + if ( m_nObjectState == -1 || m_bWaitSaveCompleted ) + throw new com.sun.star.embed.WrongStateException(); + + return m_aEntryName; + } + + // com.sun.star.embed.XVisualObject: + + public void setVisualAreaSize(long nAspect, com.sun.star.awt.Size aSize) throws com.sun.star.lang.IllegalArgumentException, com.sun.star.embed.WrongStateException, com.sun.star.uno.Exception + { + if ( m_bDisposed ) + throw new com.sun.star.lang.DisposedException(); + + if ( m_nObjectState == -1 ) + throw new com.sun.star.embed.WrongStateException(); + + if ( nAspect == com.sun.star.embed.Aspects.MSOLE_ICON ) + // the ICON aspect should be handled by the container + throw new com.sun.star.embed.WrongStateException(); + + if ( m_nObjectState == com.sun.star.embed.EmbedStates.LOADED ) + changeState( com.sun.star.embed.EmbedStates.RUNNING ); + + if ( m_aEditorFrame == null ) + throw new com.sun.star.uno.RuntimeException(); + + m_aObjSize.setSize( aSize.Width, aSize.Height ); + m_aEditorFrame.setAppSize( m_aObjSize ); + } + + + public com.sun.star.awt.Size getVisualAreaSize(long nAspect) throws com.sun.star.lang.IllegalArgumentException, com.sun.star.embed.WrongStateException, com.sun.star.uno.Exception + { + if ( m_bDisposed ) + throw new com.sun.star.lang.DisposedException(); + + if ( m_nObjectState == -1 ) + throw new com.sun.star.embed.WrongStateException(); + + if ( nAspect == com.sun.star.embed.Aspects.MSOLE_ICON ) + // the ICON aspect should be handled by the container + throw new com.sun.star.embed.WrongStateException(); + + if ( m_nObjectState == com.sun.star.embed.EmbedStates.LOADED ) + changeState( com.sun.star.embed.EmbedStates.RUNNING ); + + UpdateSizeAndGetFromActive(); + + return new com.sun.star.awt.Size( (int)m_aObjSize.getWidth(), (int)m_aObjSize.getHeight() ); + } + + + public VisualRepresentation getPreferredVisualRepresentation(long nAspect) throws com.sun.star.lang.IllegalArgumentException, com.sun.star.embed.WrongStateException, com.sun.star.uno.Exception + { + if ( m_bDisposed ) + throw new com.sun.star.lang.DisposedException(); + + if ( m_nObjectState == -1 ) + throw new com.sun.star.embed.WrongStateException(); + + if ( nAspect == com.sun.star.embed.Aspects.MSOLE_ICON ) + // the ICON aspect should be handled by the container + throw new com.sun.star.embed.WrongStateException(); + + if ( m_nObjectState == com.sun.star.embed.EmbedStates.LOADED ) + changeState( com.sun.star.embed.EmbedStates.RUNNING ); + + byte[] aData = m_aEditorFrame.getReplacementImage(); + VisualRepresentation aVisRep = new VisualRepresentation(); + aVisRep.Data = aData; + aVisRep.Flavor = new com.sun.star.datatransfer.DataFlavor( "image/png", "png", new com.sun.star.uno.Type( byte[].class ) ); + return aVisRep; + } + + + public int getMapUnit(long nAspect) throws com.sun.star.uno.Exception + { + if ( m_bDisposed ) + throw new com.sun.star.lang.DisposedException(); + + if ( m_nObjectState == -1 ) + throw new com.sun.star.embed.WrongStateException(); + + if ( nAspect == com.sun.star.embed.Aspects.MSOLE_ICON ) + // the ICON aspect should be handled by the container + throw new com.sun.star.embed.WrongStateException(); + + return com.sun.star.embed.EmbedMapUnits.PIXEL; + } + + // com.sun.star.embed.XClassifiedObject: + + public byte[] getClassID() + { + if ( m_bDisposed ) + throw new com.sun.star.lang.DisposedException(); + + return m_aClassID; + } + + + public String getClassName() + { + if ( m_bDisposed ) + throw new com.sun.star.lang.DisposedException(); + + return ""; + } + + + public void setClassInfo(byte[] aClassID, String sClassName) throws com.sun.star.lang.NoSupportException + { + throw new com.sun.star.lang.NoSupportException(); + } + + // com.sun.star.embed.XComponentSupplier: + + public com.sun.star.util.XCloseable getComponent() + { + if ( m_bDisposed ) + throw new com.sun.star.lang.DisposedException(); + + // allows no access to the component, this simple example just has no + return null; + } + + // com.sun.star.embed.XStateChangeBroadcaster: + + public void addStateChangeListener(com.sun.star.embed.XStateChangeListener xListener) + { + if ( m_bDisposed ) + return; + + GetListeners().add( xListener ); + } + + + public void removeStateChangeListener(com.sun.star.embed.XStateChangeListener xListener) + { + if ( m_bDisposed ) + return; + + if ( m_aListeners != null ) + m_aListeners.remove( xListener ); + } + + // com.sun.star.document.XEventBroadcaster: + + public void addEventListener(com.sun.star.document.XEventListener xListener) + { + if ( m_bDisposed ) + return; + + GetListeners().add( xListener ); + } + + + public void removeEventListener(com.sun.star.document.XEventListener xListener) + { + if ( m_bDisposed ) + return; + + if ( m_aListeners != null ) + m_aListeners.remove( xListener ); + } + + // com.sun.star.util.XCloseBroadcaster: + + public void addCloseListener(com.sun.star.util.XCloseListener xListener) + { + if ( m_bDisposed ) + return; + + GetListeners().add( xListener ); + } + + + public void removeCloseListener(com.sun.star.util.XCloseListener xListener) + { + if ( m_bDisposed ) + return; + + if ( m_aListeners != null ) + m_aListeners.remove( xListener ); + } + + // com.sun.star.util.XCloseable: + + public void close(boolean bDeliverOwnership) throws com.sun.star.util.CloseVetoException + { + if ( m_bDisposed ) + throw new com.sun.star.lang.DisposedException(); + + com.sun.star.lang.EventObject aEventObject = new com.sun.star.lang.EventObject( this ); + + if ( m_aListeners != null ) + { + for ( int nInd = 0; nInd < m_aListeners.size(); nInd++ ) + { + try + { + com.sun.star.util.XCloseListener xListener = ( com.sun.star.util.XCloseListener ) + UnoRuntime.queryInterface( com.sun.star.document.XEventListener.class, m_aListeners.get( nInd ) ); + + if ( xListener != null ) + xListener.queryClosing( aEventObject, bDeliverOwnership ); + } + catch( com.sun.star.util.CloseVetoException e ) + { + throw e; + } + catch( java.lang.Exception e ) + { + m_aListeners.remove( nInd ); + } + } + + m_bDisposed = true; + + for ( int nInd = 0; nInd < m_aListeners.size(); nInd++ ) + { + try + { + com.sun.star.util.XCloseListener xListener = ( com.sun.star.util.XCloseListener ) + UnoRuntime.queryInterface( com.sun.star.document.XEventListener.class, m_aListeners.get( nInd ) ); + + if ( xListener != null ) + xListener.notifyClosing( aEventObject ); + } + catch( java.lang.Exception e ) + { + m_aListeners.remove( nInd ); + } + } + + m_aListeners.clear(); + } + + m_bDisposed = true; + + if ( m_aEditorFrame != null ) + { + m_aEditorFrame.dispose(); + m_aEditorFrame = null; + } + + if ( m_xOwnStorage != null ) + { + try { + m_xOwnStorage.dispose(); + } catch( java.lang.Exception e ) {} + m_xOwnStorage = null; + } + } + + // com.sun.star.embed.XEmbeddedObject: + + public void changeState(int nNewState) throws com.sun.star.embed.UnreachableStateException, com.sun.star.embed.WrongStateException, com.sun.star.uno.Exception + { + if ( m_bDisposed ) + throw new com.sun.star.lang.DisposedException(); + + if ( m_nObjectState == -1 ) + throw new com.sun.star.embed.WrongStateException(); + + int nOldState = m_nObjectState; + + if ( nOldState == nNewState ) + { + if ( nOldState == com.sun.star.embed.EmbedStates.ACTIVE ) + { + if ( m_aEditorFrame == null ) + throw new com.sun.star.uno.RuntimeException(); + m_aEditorFrame.toFront(); + } + + return; + } + + if ( nNewState != com.sun.star.embed.EmbedStates.LOADED + && nNewState != com.sun.star.embed.EmbedStates.RUNNING + && nNewState != com.sun.star.embed.EmbedStates.ACTIVE ) + throw new com.sun.star.embed.UnreachableStateException(); + + StateChangeNotification( true, nOldState, nNewState ); + + try + { + if ( nOldState == com.sun.star.embed.EmbedStates.LOADED ) + { + // switch to the RUNNING state first + String aText = ReadStringFromStream( m_xOwnStorage, "content.txt" ); + + EditorFrame aEditorFrame = new EditorFrame( m_aEntryName, this, 5, 20 ); + aEditorFrame.setText( aText ); + + ReadSizeFromOwnStorage(); + + m_aEditorFrame = aEditorFrame; + m_nObjectState = com.sun.star.embed.EmbedStates.RUNNING; + + if ( nNewState == com.sun.star.embed.EmbedStates.ACTIVE ) + { + if ( m_xClient == null ) + throw new com.sun.star.embed.WrongStateException(); + + m_aEditorFrame.show(); + m_aEditorFrame.toFront(); + + if ( m_aObjSize != null ) + aEditorFrame.setAppSize( m_aObjSize ); + + m_xClient.visibilityChanged( true ); + m_nObjectState = com.sun.star.embed.EmbedStates.ACTIVE; + } + } + else if ( nOldState == com.sun.star.embed.EmbedStates.RUNNING ) + { + if ( nNewState == com.sun.star.embed.EmbedStates.LOADED ) + { + EditorFrame aFrame = m_aEditorFrame; + m_aEditorFrame = null; + aFrame.dispose(); + m_nObjectState = nNewState; + } + else // nNewState == ACTIVE + { + if ( m_aEditorFrame == null ) + throw new com.sun.star.uno.RuntimeException(); + + if ( m_xClient == null ) + throw new com.sun.star.embed.WrongStateException(); + + m_aEditorFrame.show(); + m_aEditorFrame.toFront(); + + if ( m_aObjSize != null ) + m_aEditorFrame.setAppSize( m_aObjSize ); + + m_xClient.visibilityChanged( true ); + + m_nObjectState = nNewState; + } + } + else // nOldState == ACTIVE + { + UpdateSizeAndGetFromActive(); + if ( nNewState == com.sun.star.embed.EmbedStates.RUNNING ) + { + m_aEditorFrame.hide(); + m_nObjectState = nNewState; + } + else // nNewState == LOADED + { + EditorFrame aFrame = m_aEditorFrame; + m_aEditorFrame = null; + aFrame.dispose(); + m_nObjectState = nNewState; + } + } + } + catch( com.sun.star.uno.Exception e ) + { + if ( nOldState != m_nObjectState ) + StateChangeNotification( false, nOldState, m_nObjectState ); + throw e; + } + + StateChangeNotification( true, nOldState, nNewState ); + } + + + public int[] getReachableStates() throws com.sun.star.embed.NeedsRunningStateException, com.sun.star.embed.WrongStateException + { + if ( m_bDisposed ) + throw new com.sun.star.lang.DisposedException(); + + if ( m_nObjectState == -1 ) + throw new com.sun.star.embed.WrongStateException(); + + int[] pStates = new int[3]; + pStates[0] = com.sun.star.embed.EmbedStates.LOADED; + pStates[1] = com.sun.star.embed.EmbedStates.RUNNING; + pStates[2] = com.sun.star.embed.EmbedStates.ACTIVE; + + return pStates; + } + + + public int getCurrentState() throws com.sun.star.embed.WrongStateException + { + if ( m_bDisposed ) + throw new com.sun.star.lang.DisposedException(); + + if ( m_nObjectState == -1 ) + throw new com.sun.star.embed.WrongStateException(); + + return m_nObjectState; + } + + + public void doVerb(int nVerbID) throws com.sun.star.lang.IllegalArgumentException, com.sun.star.embed.WrongStateException, com.sun.star.embed.UnreachableStateException, com.sun.star.uno.Exception + { + if ( m_bDisposed ) + throw new com.sun.star.lang.DisposedException(); + + if ( m_nObjectState == -1 ) + throw new com.sun.star.embed.WrongStateException(); + + if ( nVerbID == com.sun.star.embed.EmbedVerbs.MS_OLEVERB_PRIMARY + || nVerbID == com.sun.star.embed.EmbedVerbs.MS_OLEVERB_SHOW + || nVerbID == com.sun.star.embed.EmbedVerbs.MS_OLEVERB_OPEN ) + changeState( com.sun.star.embed.EmbedStates.ACTIVE ); + else if ( nVerbID == com.sun.star.embed.EmbedVerbs.MS_OLEVERB_HIDE ) + changeState( com.sun.star.embed.EmbedStates.RUNNING ); + } + + + public com.sun.star.embed.VerbDescriptor[] getSupportedVerbs() throws com.sun.star.embed.NeedsRunningStateException, com.sun.star.embed.WrongStateException + { + if ( m_bDisposed ) + throw new com.sun.star.lang.DisposedException(); + + if ( m_nObjectState == -1 ) + throw new com.sun.star.embed.WrongStateException(); + + if ( m_pOwnVerbs == null ) + { + try + { + XMultiServiceFactory xConfProvider = theDefaultProvider.get(m_xContext); + if ( xConfProvider == null ) + throw new com.sun.star.uno.RuntimeException(); + + Object[] aArgs = new Object[1]; + aArgs[0] = "/org.openoffice.Office.Embedding/Objects"; + Object oSettings = xConfProvider.createInstanceWithArguments( "com.sun.star.configuration.ConfigurationAccess", aArgs ); + XNameAccess xObjConfNA = UnoRuntime.queryInterface( XNameAccess.class, oSettings ); + if ( xObjConfNA == null ) + throw new com.sun.star.uno.RuntimeException(); + + Object oEmbObj = xObjConfNA.getByName( "69474366-FD6F-4806-8374-8EDD1B6E771D" ); + XNameAccess xEmbObjNA = UnoRuntime.queryInterface( XNameAccess.class, oEmbObj ); + if ( xEmbObjNA == null ) + throw new com.sun.star.uno.RuntimeException(); + + String[] pVerbShortcuts = (String[]) AnyConverter.toArray( xEmbObjNA.getByName( "ObjectVerbs" ) ); + if ( pVerbShortcuts != null && pVerbShortcuts.length != 0 ) + { + com.sun.star.embed.VerbDescriptor[] pVerbs = new com.sun.star.embed.VerbDescriptor[pVerbShortcuts.length]; + aArgs[0] = "/org.openoffice.Office.Embedding/Verbs"; + Object oVerbs = xConfProvider.createInstanceWithArguments( "com.sun.star.configuration.ConfigurationAccess", aArgs ); + XNameAccess xVerbsConfNA = UnoRuntime.queryInterface( XNameAccess.class, oVerbs ); + if ( xVerbsConfNA == null ) + throw new com.sun.star.uno.RuntimeException(); + + for ( int nInd = 0; nInd < pVerbShortcuts.length; nInd++ ) + { + try + { + XNameAccess xVerbNA = UnoRuntime.queryInterface( + XNameAccess.class, + xVerbsConfNA.getByName( pVerbShortcuts[nInd] ) ); + if ( xVerbNA != null ) + { + com.sun.star.embed.VerbDescriptor aVerb = new com.sun.star.embed.VerbDescriptor(); + aVerb.VerbID = AnyConverter.toInt( xVerbNA.getByName( "VerbID" ) ); + aVerb.VerbName = AnyConverter.toString( xVerbNA.getByName( "VerbUIName" ) ); + aVerb.VerbFlags = AnyConverter.toInt( xVerbNA.getByName( "VerbFlags" ) ); + aVerb.VerbAttributes = AnyConverter.toInt( xVerbNA.getByName( "VerbAttributes" ) ); + pVerbs[nInd] = aVerb; + } + } + catch( java.lang.Exception e ) + { + } + + if ( pVerbs[nInd] == null ) + { + // let the error be visible + pVerbs[nInd] = new com.sun.star.embed.VerbDescriptor(); + pVerbs[nInd].VerbID = com.sun.star.embed.EmbedVerbs.MS_OLEVERB_PRIMARY; + pVerbs[nInd].VerbName = "ERROR!"; + pVerbs[nInd].VerbFlags = 0; + pVerbs[nInd].VerbAttributes = com.sun.star.embed.VerbAttributes.MS_VERBATTR_ONCONTAINERMENU; + } + } + + m_pOwnVerbs = pVerbs; + } + } + catch( com.sun.star.uno.Exception e ) + {} + } + + if ( m_pOwnVerbs != null ) + return m_pOwnVerbs; + + return new com.sun.star.embed.VerbDescriptor[0]; + } + + + public void setClientSite(com.sun.star.embed.XEmbeddedClient xClient) throws com.sun.star.embed.WrongStateException + { + if ( m_bDisposed ) + throw new com.sun.star.lang.DisposedException(); + + if ( m_nObjectState == -1 ) + throw new com.sun.star.embed.WrongStateException(); + + m_xClient = xClient; + } + + + public com.sun.star.embed.XEmbeddedClient getClientSite() throws com.sun.star.embed.WrongStateException + { + if ( m_bDisposed ) + throw new com.sun.star.lang.DisposedException(); + + if ( m_nObjectState == -1 ) + throw new com.sun.star.embed.WrongStateException(); + + return m_xClient; + } + + + public void update() throws com.sun.star.embed.WrongStateException, com.sun.star.uno.Exception + { + if ( m_bDisposed ) + throw new com.sun.star.lang.DisposedException(); + + if ( m_nObjectState == -1 ) + throw new com.sun.star.embed.WrongStateException(); + + // not implemented + } + + + public void setUpdateMode(int nMode) throws com.sun.star.embed.WrongStateException + { + if ( m_bDisposed ) + throw new com.sun.star.lang.DisposedException(); + + if ( m_nObjectState == -1 ) + throw new com.sun.star.embed.WrongStateException(); + + // not implemented + } + + + public long getStatus(long nAspect) throws com.sun.star.embed.WrongStateException + { + if ( m_bDisposed ) + throw new com.sun.star.lang.DisposedException(); + + if ( m_nObjectState == -1 ) + throw new com.sun.star.embed.WrongStateException(); + + return 0; + } + + + public void setContainerName(String sName) + { + if ( m_bDisposed ) + throw new com.sun.star.lang.DisposedException(); + + // not implemented + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/odk/examples/java/EmbedDocument/EmbeddedObject/OwnEmbeddedObjectFactory.java b/odk/examples/java/EmbedDocument/EmbeddedObject/OwnEmbeddedObjectFactory.java new file mode 100644 index 000000000..a4333a8fd --- /dev/null +++ b/odk/examples/java/EmbedDocument/EmbeddedObject/OwnEmbeddedObjectFactory.java @@ -0,0 +1,106 @@ +/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +import com.sun.star.uno.XComponentContext; +import com.sun.star.lib.uno.helper.Factory; +import com.sun.star.lang.XSingleComponentFactory; +import com.sun.star.lib.uno.helper.WeakBase; + +public final class OwnEmbeddedObjectFactory extends WeakBase + implements com.sun.star.lang.XServiceInfo, + com.sun.star.embed.XEmbedObjectFactory +{ + private final XComponentContext m_xContext; + private static final String m_implementationName = OwnEmbeddedObjectFactory.class.getName(); + private static final String[] m_serviceNames = { + "org.openoffice.examples.embedding.Factory69474366FD6F480683748EDD1B6E771D" }; + private static final byte[] m_classID = { 0x69, 0x47, 0x43, 0x66, (byte)0xFD, 0x6F, 0x48, 0x06, (byte)0x83, 0x74, (byte)0x8E, (byte)0xDD, 0x1B, 0x6E, 0x77, 0x1D }; + + + public OwnEmbeddedObjectFactory( XComponentContext context ) + { + m_xContext = context; + } + + public static XSingleComponentFactory __getComponentFactory( String sImplementationName ) { + XSingleComponentFactory xFactory = null; + + if ( sImplementationName.equals( m_implementationName ) ) + xFactory = Factory.createComponentFactory(OwnEmbeddedObjectFactory.class, m_serviceNames); + return xFactory; + } + + // com.sun.star.lang.XServiceInfo: + public String getImplementationName() { + return m_implementationName; + } + + public boolean supportsService( String sService ) { + int len = m_serviceNames.length; + + for( int i=0; i < len; i++) { + if (sService.equals(m_serviceNames[i])) + return true; + } + return false; + } + + public String[] getSupportedServiceNames() { + return m_serviceNames; + } + + // com.sun.star.embed.XEmbedObjectFactory: + public Object createInstanceUserInit(byte[] aClassID, String sClassName, com.sun.star.embed.XStorage xStorage, String sEntName, int nEntryConnectionMode, com.sun.star.beans.PropertyValue[] aArgs, com.sun.star.beans.PropertyValue[] aObjectArgs) throws com.sun.star.lang.IllegalArgumentException, com.sun.star.io.IOException, com.sun.star.uno.Exception + { + if ( xStorage == null || sEntName == null || sEntName.length() == 0 ) + throw new com.sun.star.lang.IllegalArgumentException(); + + if ( nEntryConnectionMode == com.sun.star.embed.EntryInitModes.DEFAULT_INIT ) + { + if ( aClassID != null && aClassID.length != 0 ) + { + if ( aClassID.length != m_classID.length ) + throw new com.sun.star.lang.IllegalArgumentException(); + + for ( int i = 0; i < aClassID.length; i++ ) + if ( aClassID[i] != m_classID[i] ) + throw new com.sun.star.lang.IllegalArgumentException(); + } + else if ( !xStorage.hasByName( sEntName ) ) + throw new com.sun.star.lang.IllegalArgumentException(); + } + else if ( nEntryConnectionMode == com.sun.star.embed.EntryInitModes.TRUNCATE_INIT ) + { + if ( aClassID.length != m_classID.length ) + throw new com.sun.star.lang.IllegalArgumentException(); + + for ( int i = 0; i < m_classID.length; i++ ) + if ( aClassID[i] != m_classID[i] ) + throw new com.sun.star.lang.IllegalArgumentException(); + } + + OwnEmbeddedObject aObject = new OwnEmbeddedObject( m_xContext, m_classID ); + aObject.setPersistentEntry( xStorage, sEntName, nEntryConnectionMode, aArgs, aObjectArgs ); + + return aObject; + } + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit v1.2.3