1ae15d43aSAndrew Rist /**************************************************************
2ae15d43aSAndrew Rist  *
3ae15d43aSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4ae15d43aSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5ae15d43aSAndrew Rist  * distributed with this work for additional information
6ae15d43aSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7ae15d43aSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8ae15d43aSAndrew Rist  * "License"); you may not use this file except in compliance
9ae15d43aSAndrew Rist  * with the License.  You may obtain a copy of the License at
10ae15d43aSAndrew Rist  *
11ae15d43aSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12ae15d43aSAndrew Rist  *
13ae15d43aSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14ae15d43aSAndrew Rist  * software distributed under the License is distributed on an
15ae15d43aSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16ae15d43aSAndrew Rist  * KIND, either express or implied.  See the License for the
17ae15d43aSAndrew Rist  * specific language governing permissions and limitations
18ae15d43aSAndrew Rist  * under the License.
19ae15d43aSAndrew Rist  *
20ae15d43aSAndrew Rist  *************************************************************/
21ae15d43aSAndrew Rist 
22cdf0e10cSrcweir package org.openoffice.examples.embedding;
23cdf0e10cSrcweir 
24cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
25cdf0e10cSrcweir import com.sun.star.uno.XComponentContext;
26cdf0e10cSrcweir import com.sun.star.lang.XMultiComponentFactory;
27cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory;
28cdf0e10cSrcweir import com.sun.star.uno.AnyConverter;
29cdf0e10cSrcweir import com.sun.star.lib.uno.helper.WeakBase;
30cdf0e10cSrcweir import com.sun.star.io.XStream;
31cdf0e10cSrcweir import com.sun.star.io.XOutputStream;
32cdf0e10cSrcweir import com.sun.star.io.XInputStream;
33cdf0e10cSrcweir import com.sun.star.io.XTruncate;
34cdf0e10cSrcweir import com.sun.star.beans.XPropertySet;
35cdf0e10cSrcweir import com.sun.star.lang.XComponent;
36cdf0e10cSrcweir import com.sun.star.document.EventObject;
37cdf0e10cSrcweir import com.sun.star.embed.VisualRepresentation;
38cdf0e10cSrcweir import com.sun.star.container.XNameAccess;
39cdf0e10cSrcweir 
40cdf0e10cSrcweir 
41cdf0e10cSrcweir import com.sun.star.embed.*;
42cdf0e10cSrcweir 
43cdf0e10cSrcweir import java.util.Vector;
44cdf0e10cSrcweir import java.awt.Dimension;
45cdf0e10cSrcweir import java.lang.Integer;
46cdf0e10cSrcweir import org.omg.CORBA.COMM_FAILURE;
47cdf0e10cSrcweir 
48cdf0e10cSrcweir import org.openoffice.examples.embedding.EditorFrame;
49cdf0e10cSrcweir 
50cdf0e10cSrcweir public final class OwnEmbeddedObject extends WeakBase
51cdf0e10cSrcweir    implements com.sun.star.embed.XEmbedPersist,
52cdf0e10cSrcweir               com.sun.star.embed.XEmbeddedObject
53cdf0e10cSrcweir {
54cdf0e10cSrcweir     protected final XComponentContext m_xContext;
55cdf0e10cSrcweir     protected final byte[] m_aClassID;
56cdf0e10cSrcweir 
57cdf0e10cSrcweir     protected boolean m_bDisposed = false;
58cdf0e10cSrcweir     protected int m_nObjectState = -1;
59cdf0e10cSrcweir 
60cdf0e10cSrcweir     protected com.sun.star.embed.XStorage m_xParentStorage;
61cdf0e10cSrcweir     protected com.sun.star.embed.XStorage m_xOwnStorage;
62cdf0e10cSrcweir     protected String m_aEntryName;
63cdf0e10cSrcweir 
64cdf0e10cSrcweir     protected com.sun.star.embed.XStorage m_xNewParentStorage;
65cdf0e10cSrcweir     protected com.sun.star.embed.XStorage m_xNewOwnStorage;
66cdf0e10cSrcweir     protected String m_aNewEntryName;
67cdf0e10cSrcweir     protected boolean m_bWaitSaveCompleted = false;
68cdf0e10cSrcweir 
69cdf0e10cSrcweir     protected EditorFrame m_aEditorFrame;
70cdf0e10cSrcweir 
71cdf0e10cSrcweir     protected Vector m_aListeners;
72cdf0e10cSrcweir 
73cdf0e10cSrcweir     com.sun.star.embed.VerbDescriptor[] m_pOwnVerbs;
74cdf0e10cSrcweir 
75cdf0e10cSrcweir     com.sun.star.embed.XEmbeddedClient m_xClient;
76cdf0e10cSrcweir 
77cdf0e10cSrcweir     Dimension m_aObjSize;
78cdf0e10cSrcweir 
79cdf0e10cSrcweir     // -------------------------------------------------------------
GetListeners()80cdf0e10cSrcweir     protected Vector GetListeners()
81cdf0e10cSrcweir     {
82cdf0e10cSrcweir         if ( m_aListeners == null )
83cdf0e10cSrcweir             m_aListeners = new Vector<Object>( 10, 10 );
84cdf0e10cSrcweir 
85cdf0e10cSrcweir         return m_aListeners;
86cdf0e10cSrcweir     }
87cdf0e10cSrcweir 
88cdf0e10cSrcweir     // -------------------------------------------------------------
UpdateSizeAndGetFromActive()89cdf0e10cSrcweir     protected Dimension UpdateSizeAndGetFromActive()
90cdf0e10cSrcweir     {
91cdf0e10cSrcweir         if ( m_nObjectState == com.sun.star.embed.EmbedStates.ACTIVE )
92cdf0e10cSrcweir             m_aObjSize = m_aEditorFrame.getAppSize();
93cdf0e10cSrcweir 
94cdf0e10cSrcweir         if ( m_aObjSize != null )
95cdf0e10cSrcweir             return m_aObjSize;
96cdf0e10cSrcweir         else
97cdf0e10cSrcweir             return new Dimension();
98cdf0e10cSrcweir     }
99cdf0e10cSrcweir 
100cdf0e10cSrcweir     // -------------------------------------------------------------
SwitchOwnPersistence( XStorage xParentStorage, XStorage xOwnStorage, String aEntryName )101cdf0e10cSrcweir     protected void SwitchOwnPersistence( XStorage xParentStorage, XStorage xOwnStorage, String aEntryName )
102cdf0e10cSrcweir     {
103cdf0e10cSrcweir         if ( xOwnStorage != m_xOwnStorage )
104cdf0e10cSrcweir         {
105cdf0e10cSrcweir             if ( m_xOwnStorage != null )
106cdf0e10cSrcweir                 m_xOwnStorage.dispose();
107cdf0e10cSrcweir             m_xParentStorage = xParentStorage;
108cdf0e10cSrcweir             m_xOwnStorage = xOwnStorage;
109cdf0e10cSrcweir             m_aEntryName = aEntryName;
110cdf0e10cSrcweir         }
111cdf0e10cSrcweir     }
112cdf0e10cSrcweir 
113cdf0e10cSrcweir     // -------------------------------------------------------------
SwitchOwnPersistence( XStorage xParentStorage, String aEntryName )114cdf0e10cSrcweir     protected void SwitchOwnPersistence( XStorage xParentStorage, String aEntryName ) throws com.sun.star.io.IOException
115cdf0e10cSrcweir     {
116cdf0e10cSrcweir         if ( xParentStorage != m_xParentStorage || !aEntryName.equals( m_aEntryName ) )
117cdf0e10cSrcweir         {
118cdf0e10cSrcweir             try
119cdf0e10cSrcweir             {
120cdf0e10cSrcweir                 XStorage xOwnStorage = xParentStorage.openStorageElement( aEntryName, com.sun.star.embed.ElementModes.READWRITE );
121cdf0e10cSrcweir                 SwitchOwnPersistence( xParentStorage, xOwnStorage, aEntryName );
122cdf0e10cSrcweir             }
123cdf0e10cSrcweir             catch( com.sun.star.uno.RuntimeException e )
124cdf0e10cSrcweir             {
125cdf0e10cSrcweir                 throw e;
126cdf0e10cSrcweir             }
127cdf0e10cSrcweir             catch( com.sun.star.io.IOException e )
128cdf0e10cSrcweir             {
129cdf0e10cSrcweir                 throw e;
130cdf0e10cSrcweir             }
131cdf0e10cSrcweir             catch( com.sun.star.uno.Exception e )
132cdf0e10cSrcweir             {
133cdf0e10cSrcweir                 throw new com.sun.star.io.IOException( "Error while switching object storage!" );
134cdf0e10cSrcweir             }
135cdf0e10cSrcweir         }
136cdf0e10cSrcweir     }
137cdf0e10cSrcweir 
138cdf0e10cSrcweir     // -------------------------------------------------------------
SaveDataToStorage( XStorage xStorage, String aString, Dimension aDimension )139cdf0e10cSrcweir     protected static void SaveDataToStorage( XStorage xStorage, String aString, Dimension aDimension ) throws com.sun.star.io.IOException
140cdf0e10cSrcweir     {
141cdf0e10cSrcweir         try
142cdf0e10cSrcweir         {
143cdf0e10cSrcweir             // save the text
144cdf0e10cSrcweir             XStream xStream = xStorage.openStreamElement( "content.txt", com.sun.star.embed.ElementModes.READWRITE );
145cdf0e10cSrcweir             XComponent xStreamComp = ( XComponent ) UnoRuntime.queryInterface( XComponent.class, xStream );
146cdf0e10cSrcweir             if ( xStreamComp == null )
147cdf0e10cSrcweir                 throw new com.sun.star.uno.RuntimeException();
148cdf0e10cSrcweir 
149cdf0e10cSrcweir             XOutputStream xOutStream = xStream.getOutputStream();
150cdf0e10cSrcweir             XTruncate xTruncate = ( XTruncate ) UnoRuntime.queryInterface( XTruncate.class, xOutStream );
151cdf0e10cSrcweir             if ( xTruncate == null )
152cdf0e10cSrcweir                 throw new com.sun.star.io.IOException();
153cdf0e10cSrcweir 
154cdf0e10cSrcweir             xTruncate.truncate();
155cdf0e10cSrcweir             xOutStream.writeBytes( aString.getBytes() );
156cdf0e10cSrcweir 
157cdf0e10cSrcweir             // save the size
158cdf0e10cSrcweir             xStream = xStorage.openStreamElement( "properties.txt", com.sun.star.embed.ElementModes.READWRITE );
159cdf0e10cSrcweir             xStreamComp = ( XComponent ) UnoRuntime.queryInterface( XComponent.class, xStream );
160cdf0e10cSrcweir             if ( xStreamComp == null )
161cdf0e10cSrcweir                 throw new com.sun.star.uno.RuntimeException();
162cdf0e10cSrcweir 
163cdf0e10cSrcweir             xOutStream = xStream.getOutputStream();
164cdf0e10cSrcweir             xTruncate = ( XTruncate ) UnoRuntime.queryInterface( XTruncate.class, xOutStream );
165cdf0e10cSrcweir             if ( xTruncate == null )
166cdf0e10cSrcweir                 throw new com.sun.star.io.IOException();
167cdf0e10cSrcweir 
168cdf0e10cSrcweir             xTruncate.truncate();
169cdf0e10cSrcweir             String aProps = Integer.toString( (int)aDimension.getWidth() ) + "|" + Integer.toString( (int)aDimension.getHeight() );
170cdf0e10cSrcweir             xOutStream.writeBytes( aProps.getBytes() );
171cdf0e10cSrcweir 
172cdf0e10cSrcweir             // set the media type
173cdf0e10cSrcweir             XPropertySet xPropSet = (XPropertySet)UnoRuntime.queryInterface( XPropertySet.class, xStorage );
174cdf0e10cSrcweir             if ( xPropSet == null )
175cdf0e10cSrcweir                 throw new com.sun.star.uno.RuntimeException();
176cdf0e10cSrcweir             xPropSet.setPropertyValue( "MediaType", "application/x-openoffice-embedded-69474366-FD6F-4806-8374-8EDD1B6E771D" );
177cdf0e10cSrcweir 
178cdf0e10cSrcweir             XTransactedObject xTransact = ( XTransactedObject ) UnoRuntime.queryInterface( XTransactedObject.class, xStorage );
179cdf0e10cSrcweir             if ( xTransact != null )
180cdf0e10cSrcweir                 xTransact.commit();
181cdf0e10cSrcweir 
182cdf0e10cSrcweir             xStreamComp.dispose();
183cdf0e10cSrcweir         }
184cdf0e10cSrcweir         catch( com.sun.star.uno.RuntimeException e )
185cdf0e10cSrcweir         {
186cdf0e10cSrcweir             throw e;
187cdf0e10cSrcweir         }
188cdf0e10cSrcweir         catch( com.sun.star.io.IOException e )
189cdf0e10cSrcweir         {
190cdf0e10cSrcweir             throw e;
191cdf0e10cSrcweir         }
192cdf0e10cSrcweir         catch( com.sun.star.uno.Exception e )
193cdf0e10cSrcweir         {
194cdf0e10cSrcweir             throw new com.sun.star.io.IOException( "Error while switching object storage!" );
195cdf0e10cSrcweir         }
196cdf0e10cSrcweir     }
197cdf0e10cSrcweir 
198cdf0e10cSrcweir     // -------------------------------------------------------------
PostEvent( String aEvEntryName )199cdf0e10cSrcweir     protected void PostEvent( String aEvEntryName )
200cdf0e10cSrcweir     {
201cdf0e10cSrcweir         if ( m_aListeners != null )
202cdf0e10cSrcweir         {
203cdf0e10cSrcweir             com.sun.star.document.EventObject aEventObject = new com.sun.star.document.EventObject( this, aEvEntryName );
204cdf0e10cSrcweir             for ( int nInd = 0; nInd < m_aListeners.size(); nInd++ )
205cdf0e10cSrcweir             {
206cdf0e10cSrcweir                 try
207cdf0e10cSrcweir                 {
208cdf0e10cSrcweir                     com.sun.star.document.XEventListener xListener = ( com.sun.star.document.XEventListener )
209cdf0e10cSrcweir                         UnoRuntime.queryInterface( com.sun.star.document.XEventListener.class, m_aListeners.get( nInd ) );
210cdf0e10cSrcweir 
211cdf0e10cSrcweir                     if ( xListener != null )
212cdf0e10cSrcweir                         xListener.notifyEvent( aEventObject );
213cdf0e10cSrcweir                 }
214cdf0e10cSrcweir                 catch( java.lang.Exception e )
215cdf0e10cSrcweir                 {
216cdf0e10cSrcweir                     m_aListeners.remove( nInd );
217cdf0e10cSrcweir                 }
218cdf0e10cSrcweir             }
219cdf0e10cSrcweir         }
220cdf0e10cSrcweir     }
221cdf0e10cSrcweir 
222cdf0e10cSrcweir     // -------------------------------------------------------------
StateChangeNotification( boolean bBeforeChange, int nOldState, int nNewState )223cdf0e10cSrcweir     protected void StateChangeNotification( boolean bBeforeChange, int nOldState, int nNewState )
224cdf0e10cSrcweir     {
225cdf0e10cSrcweir         if ( m_aListeners != null )
226cdf0e10cSrcweir         {
227cdf0e10cSrcweir             com.sun.star.lang.EventObject aEventObject = new com.sun.star.lang.EventObject( this );
228cdf0e10cSrcweir             for ( int nInd = 0; nInd < m_aListeners.size(); nInd++ )
229cdf0e10cSrcweir             {
230cdf0e10cSrcweir                 try
231cdf0e10cSrcweir                 {
232cdf0e10cSrcweir                     com.sun.star.embed.XStateChangeListener xListener = ( com.sun.star.embed.XStateChangeListener )
233cdf0e10cSrcweir                         UnoRuntime.queryInterface( com.sun.star.embed.XStateChangeListener.class, m_aListeners.get( nInd ) );
234cdf0e10cSrcweir 
235cdf0e10cSrcweir                     if ( xListener != null )
236cdf0e10cSrcweir                     {
237cdf0e10cSrcweir                         if ( bBeforeChange )
238cdf0e10cSrcweir                             xListener.changingState( aEventObject, nOldState, nNewState );
239cdf0e10cSrcweir                         else
240cdf0e10cSrcweir                             xListener.stateChanged( aEventObject, nOldState, nNewState );
241cdf0e10cSrcweir                     }
242cdf0e10cSrcweir                 }
243cdf0e10cSrcweir                 catch( java.lang.Exception e )
244cdf0e10cSrcweir                 {
245cdf0e10cSrcweir                     m_aListeners.remove( nInd );
246cdf0e10cSrcweir                 }
247cdf0e10cSrcweir             }
248cdf0e10cSrcweir         }
249cdf0e10cSrcweir     }
250cdf0e10cSrcweir 
251cdf0e10cSrcweir     // -------------------------------------------------------------
ReadStringFromStream( XStorage xStorage, String aStreamName )252cdf0e10cSrcweir     protected String ReadStringFromStream( XStorage xStorage, String aStreamName ) throws com.sun.star.io.IOException
253cdf0e10cSrcweir     {
254cdf0e10cSrcweir         if ( xStorage == null )
255cdf0e10cSrcweir             throw new com.sun.star.uno.RuntimeException();
256cdf0e10cSrcweir 
257cdf0e10cSrcweir         try
258cdf0e10cSrcweir         {
259cdf0e10cSrcweir             XStream xStream = xStorage.openStreamElement( aStreamName, com.sun.star.embed.ElementModes.READWRITE );
260cdf0e10cSrcweir             XComponent xStreamComp = ( XComponent ) UnoRuntime.queryInterface( XComponent.class, xStream );
261cdf0e10cSrcweir             if ( xStreamComp == null )
262cdf0e10cSrcweir                 throw new com.sun.star.uno.RuntimeException();
263cdf0e10cSrcweir 
264cdf0e10cSrcweir             XInputStream xInStream = xStream.getInputStream();
265cdf0e10cSrcweir             byte[][] aData = new byte[1][];
266cdf0e10cSrcweir             aData[0] = new byte[0];
267cdf0e10cSrcweir             String aResult = new String();
268cdf0e10cSrcweir 
269cdf0e10cSrcweir             int nLen = 0;
270cdf0e10cSrcweir             do
271cdf0e10cSrcweir             {
272cdf0e10cSrcweir                 nLen = xInStream.readBytes( aData, 10 );
273cdf0e10cSrcweir                 if ( aData.length == 0 || aData[0] == null )
274cdf0e10cSrcweir                     throw new com.sun.star.io.IOException();
275cdf0e10cSrcweir                 aResult += new String( aData[0] );
276cdf0e10cSrcweir             } while( nLen > 0 );
277cdf0e10cSrcweir 
278cdf0e10cSrcweir             xStreamComp.dispose();
279cdf0e10cSrcweir 
280cdf0e10cSrcweir             return aResult;
281cdf0e10cSrcweir         }
282cdf0e10cSrcweir         catch( com.sun.star.uno.RuntimeException e )
283cdf0e10cSrcweir         {
284cdf0e10cSrcweir             throw e;
285cdf0e10cSrcweir         }
286cdf0e10cSrcweir         catch( com.sun.star.io.IOException e )
287cdf0e10cSrcweir         {
288cdf0e10cSrcweir             throw e;
289cdf0e10cSrcweir         }
290cdf0e10cSrcweir         catch( com.sun.star.uno.Exception e )
291cdf0e10cSrcweir         {
292cdf0e10cSrcweir             throw new com.sun.star.io.IOException( "Error while reading one of object streams!" );
293cdf0e10cSrcweir         }
294cdf0e10cSrcweir     }
295cdf0e10cSrcweir 
296cdf0e10cSrcweir     // -------------------------------------------------------------
ReadSizeFromOwnStorage()297cdf0e10cSrcweir     protected void ReadSizeFromOwnStorage() throws com.sun.star.io.IOException
298cdf0e10cSrcweir     {
299cdf0e10cSrcweir         String aSize = ReadStringFromStream( m_xOwnStorage, "properties.txt" );
300cdf0e10cSrcweir 
301cdf0e10cSrcweir         int nSeparator = aSize.indexOf( '|' );
302cdf0e10cSrcweir         if ( nSeparator > 0 && nSeparator < aSize.length() - 1 )
303cdf0e10cSrcweir         {
304cdf0e10cSrcweir             int nWidth = Integer.parseInt( aSize.substring( 0, nSeparator ) );
305cdf0e10cSrcweir             int nHeight = Integer.parseInt( aSize.substring( nSeparator + 1, aSize.length() ) );
306cdf0e10cSrcweir             m_aObjSize = new Dimension( nWidth, nHeight );
307cdf0e10cSrcweir         }
308cdf0e10cSrcweir     }
309cdf0e10cSrcweir 
310cdf0e10cSrcweir     // -------------------------------------------------------------
OwnEmbeddedObject( XComponentContext context, byte[] aClassID )311cdf0e10cSrcweir     public OwnEmbeddedObject( XComponentContext context, byte[] aClassID )
312cdf0e10cSrcweir     {
313cdf0e10cSrcweir         m_xContext = context;
314cdf0e10cSrcweir         m_aClassID = aClassID;
315cdf0e10cSrcweir     };
316cdf0e10cSrcweir 
317cdf0e10cSrcweir     // -------------------------------------------------------------
CloseFrameRequest()318cdf0e10cSrcweir     public void CloseFrameRequest()
319cdf0e10cSrcweir     {
320cdf0e10cSrcweir         com.sun.star.embed.XEmbeddedClient xClient = m_xClient;
321cdf0e10cSrcweir         if ( xClient == null )
322cdf0e10cSrcweir             return;
323cdf0e10cSrcweir 
324cdf0e10cSrcweir         UpdateSizeAndGetFromActive();
325cdf0e10cSrcweir         StateChangeNotification( true, com.sun.star.embed.EmbedStates.ACTIVE, com.sun.star.embed.EmbedStates.RUNNING );
326cdf0e10cSrcweir 
327cdf0e10cSrcweir         try{
328cdf0e10cSrcweir             xClient.visibilityChanged( false );
329cdf0e10cSrcweir         } catch( com.sun.star.uno.Exception e ){}
330cdf0e10cSrcweir 
331cdf0e10cSrcweir         try{
332cdf0e10cSrcweir             xClient.saveObject();
333cdf0e10cSrcweir         } catch( com.sun.star.uno.Exception e ){}
334cdf0e10cSrcweir 
335cdf0e10cSrcweir         m_nObjectState = com.sun.star.embed.EmbedStates.RUNNING;
336cdf0e10cSrcweir         StateChangeNotification( false, com.sun.star.embed.EmbedStates.ACTIVE, m_nObjectState );
337cdf0e10cSrcweir 
338cdf0e10cSrcweir         PostEvent( "OnVisAreaChanged" );
339cdf0e10cSrcweir     }
340cdf0e10cSrcweir 
341cdf0e10cSrcweir     // com.sun.star.embed.XCommonEmbedPersist:
342cdf0e10cSrcweir     // -------------------------------------------------------------
storeOwn()343cdf0e10cSrcweir     public void storeOwn() throws com.sun.star.embed.WrongStateException, com.sun.star.io.IOException, com.sun.star.uno.Exception
344cdf0e10cSrcweir     {
345cdf0e10cSrcweir         if ( m_bDisposed )
346cdf0e10cSrcweir             throw new com.sun.star.lang.DisposedException();
347cdf0e10cSrcweir 
348cdf0e10cSrcweir         if ( m_nObjectState == -1 || m_bWaitSaveCompleted )
349cdf0e10cSrcweir             throw new com.sun.star.embed.WrongStateException();
350cdf0e10cSrcweir 
351cdf0e10cSrcweir         // nothing to do, if the object is in loaded state
352cdf0e10cSrcweir         if ( m_nObjectState == com.sun.star.embed.EmbedStates.LOADED )
353cdf0e10cSrcweir             return;
354cdf0e10cSrcweir 
355cdf0e10cSrcweir         if ( m_xOwnStorage == null )
356cdf0e10cSrcweir             throw new com.sun.star.io.IOException();
357cdf0e10cSrcweir 
358cdf0e10cSrcweir         PostEvent( "OnSave" );
359cdf0e10cSrcweir 
360cdf0e10cSrcweir         if ( m_aEditorFrame == null )
361cdf0e10cSrcweir             throw new com.sun.star.uno.RuntimeException();
362cdf0e10cSrcweir 
363cdf0e10cSrcweir         SaveDataToStorage( m_xOwnStorage, m_aEditorFrame.getText(), UpdateSizeAndGetFromActive() );
364cdf0e10cSrcweir 
365cdf0e10cSrcweir         PostEvent( "OnSaveDone" );
366cdf0e10cSrcweir     }
367cdf0e10cSrcweir 
368cdf0e10cSrcweir     // -------------------------------------------------------------
isReadonly()369cdf0e10cSrcweir     public boolean isReadonly() throws com.sun.star.embed.WrongStateException
370cdf0e10cSrcweir     {
371cdf0e10cSrcweir         return false;
372cdf0e10cSrcweir     }
373cdf0e10cSrcweir 
374cdf0e10cSrcweir     // -------------------------------------------------------------
reload(com.sun.star.beans.PropertyValue[] aMediaArgs, com.sun.star.beans.PropertyValue[] aObjectArgs)375cdf0e10cSrcweir     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
376cdf0e10cSrcweir     {
377cdf0e10cSrcweir         // not implemented currently
378cdf0e10cSrcweir         return;
379cdf0e10cSrcweir     }
380cdf0e10cSrcweir 
381cdf0e10cSrcweir     // com.sun.star.embed.XEmbedPersist:
382cdf0e10cSrcweir     // -------------------------------------------------------------
setPersistentEntry(com.sun.star.embed.XStorage xStorage, String aEntryName, int nEntryConnectionMode, com.sun.star.beans.PropertyValue[] aMediaArgs, com.sun.star.beans.PropertyValue[] aObjectArgs)383cdf0e10cSrcweir     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
384cdf0e10cSrcweir     {
385cdf0e10cSrcweir         if ( m_bDisposed )
386cdf0e10cSrcweir             throw new com.sun.star.lang.DisposedException();
387cdf0e10cSrcweir 
388cdf0e10cSrcweir         if ( xStorage == null || aEntryName.length() == 0 )
389cdf0e10cSrcweir             throw new com.sun.star.lang.IllegalArgumentException();
390cdf0e10cSrcweir 
391cdf0e10cSrcweir         if ( ( m_nObjectState != -1 || nEntryConnectionMode == com.sun.star.embed.EntryInitModes.NO_INIT )
392cdf0e10cSrcweir           && ( m_nObjectState == -1 || nEntryConnectionMode != com.sun.star.embed.EntryInitModes.NO_INIT ) )
393cdf0e10cSrcweir         {
394cdf0e10cSrcweir             // if the object is not loaded
395*a893be29SPedro Giffuni             // it can not get persistent representation without initialization
396cdf0e10cSrcweir 
397cdf0e10cSrcweir             // if the object is loaded
398*a893be29SPedro Giffuni             // it can switch persistent representation only without initialization
399cdf0e10cSrcweir 
400cdf0e10cSrcweir             throw new com.sun.star.embed.WrongStateException();
401cdf0e10cSrcweir         }
402cdf0e10cSrcweir 
403cdf0e10cSrcweir         if ( m_bWaitSaveCompleted )
404cdf0e10cSrcweir         {
405cdf0e10cSrcweir             if ( nEntryConnectionMode == com.sun.star.embed.EntryInitModes.NO_INIT )
406cdf0e10cSrcweir             {
407cdf0e10cSrcweir                 if ( m_xParentStorage == xStorage && m_aEntryName.equals( aEntryName ) )
408cdf0e10cSrcweir                     saveCompleted( false );
409cdf0e10cSrcweir                 else if ( m_xNewParentStorage == xStorage && m_aNewEntryName.equals( aEntryName ) )
410cdf0e10cSrcweir                     saveCompleted( true );
411cdf0e10cSrcweir                 else
412cdf0e10cSrcweir                     throw new com.sun.star.embed.WrongStateException();
413cdf0e10cSrcweir             }
414cdf0e10cSrcweir             else
415cdf0e10cSrcweir                 throw new com.sun.star.embed.WrongStateException();
416cdf0e10cSrcweir 
417cdf0e10cSrcweir             return;
418cdf0e10cSrcweir         }
419cdf0e10cSrcweir 
420cdf0e10cSrcweir         boolean bElExists = xStorage.hasByName( aEntryName );
421cdf0e10cSrcweir 
422cdf0e10cSrcweir         if ( nEntryConnectionMode == com.sun.star.embed.EntryInitModes.DEFAULT_INIT )
423cdf0e10cSrcweir         {
424cdf0e10cSrcweir             SwitchOwnPersistence( xStorage, aEntryName );
425cdf0e10cSrcweir             if ( bElExists )
426cdf0e10cSrcweir             {
427cdf0e10cSrcweir                 XPropertySet xPropSet = (XPropertySet)UnoRuntime.queryInterface( XPropertySet.class, m_xOwnStorage );
428cdf0e10cSrcweir                 if ( xPropSet == null )
429cdf0e10cSrcweir                     throw new com.sun.star.uno.RuntimeException();
430cdf0e10cSrcweir 
431cdf0e10cSrcweir                 String aMediaType = AnyConverter.toString( xPropSet.getPropertyValue( "MediaType" ) );
432cdf0e10cSrcweir                 if ( !aMediaType.equals( "application/x-openoffice-embedded-69474366-FD6F-4806-8374-8EDD1B6E771D" ) )
433cdf0e10cSrcweir                     throw new com.sun.star.lang.IllegalArgumentException();
434cdf0e10cSrcweir 
435cdf0e10cSrcweir                 m_nObjectState = com.sun.star.embed.EmbedStates.LOADED;
436cdf0e10cSrcweir             }
437cdf0e10cSrcweir             else
438cdf0e10cSrcweir             {
439cdf0e10cSrcweir                 m_aEditorFrame = new EditorFrame( m_aEntryName, this, 5, 20 );
440cdf0e10cSrcweir                 m_nObjectState = com.sun.star.embed.EmbedStates.RUNNING;
441cdf0e10cSrcweir                 m_aObjSize = m_aEditorFrame.getAppSize();
442cdf0e10cSrcweir             }
443cdf0e10cSrcweir         }
444cdf0e10cSrcweir         else if ( nEntryConnectionMode == com.sun.star.embed.EntryInitModes.TRUNCATE_INIT )
445cdf0e10cSrcweir         {
446cdf0e10cSrcweir             SwitchOwnPersistence( xStorage, aEntryName );
447cdf0e10cSrcweir             m_aEditorFrame = new EditorFrame( m_aEntryName, this, 5, 20 );
448cdf0e10cSrcweir             m_nObjectState = com.sun.star.embed.EmbedStates.RUNNING;
449cdf0e10cSrcweir             m_aObjSize = m_aEditorFrame.getAppSize();
450cdf0e10cSrcweir         }
451cdf0e10cSrcweir         else
452cdf0e10cSrcweir             throw new com.sun.star.lang.IllegalArgumentException();
453cdf0e10cSrcweir     }
454cdf0e10cSrcweir 
455cdf0e10cSrcweir     // -------------------------------------------------------------
storeToEntry(com.sun.star.embed.XStorage xStorage, String aEntryName, com.sun.star.beans.PropertyValue[] aMediaArgs, com.sun.star.beans.PropertyValue[] aObjectArgs)456cdf0e10cSrcweir     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
457cdf0e10cSrcweir     {
458cdf0e10cSrcweir         if ( m_bDisposed )
459cdf0e10cSrcweir             throw new com.sun.star.lang.DisposedException();
460cdf0e10cSrcweir 
461cdf0e10cSrcweir         if ( m_nObjectState == -1 || m_bWaitSaveCompleted )
462cdf0e10cSrcweir             throw new com.sun.star.embed.WrongStateException();
463cdf0e10cSrcweir 
464cdf0e10cSrcweir         if ( m_nObjectState == com.sun.star.embed.EmbedStates.LOADED )
465cdf0e10cSrcweir         {
466cdf0e10cSrcweir             m_xParentStorage.copyElementTo( m_aEntryName, xStorage, aEntryName );
467cdf0e10cSrcweir         }
468cdf0e10cSrcweir         else
469cdf0e10cSrcweir         {
470cdf0e10cSrcweir             com.sun.star.embed.XStorage xSubStorage =
471cdf0e10cSrcweir                 xStorage.openStorageElement( aEntryName,
472cdf0e10cSrcweir                             com.sun.star.embed.ElementModes.READWRITE | com.sun.star.embed.ElementModes.TRUNCATE );
473cdf0e10cSrcweir 
474cdf0e10cSrcweir             String aContents = m_aEditorFrame.getText();
475cdf0e10cSrcweir 
476cdf0e10cSrcweir             SaveDataToStorage( xSubStorage, m_aEditorFrame.getText(), UpdateSizeAndGetFromActive() );
477cdf0e10cSrcweir         }
478cdf0e10cSrcweir     }
479cdf0e10cSrcweir 
480cdf0e10cSrcweir     // -------------------------------------------------------------
storeAsEntry(com.sun.star.embed.XStorage xStorage, String aEntryName, com.sun.star.beans.PropertyValue[] aMediaArgs, com.sun.star.beans.PropertyValue[] aObjectArgs)481cdf0e10cSrcweir     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
482cdf0e10cSrcweir     {
483cdf0e10cSrcweir         if ( m_bDisposed )
484cdf0e10cSrcweir             throw new com.sun.star.lang.DisposedException();
485cdf0e10cSrcweir 
486cdf0e10cSrcweir         if ( m_nObjectState == -1 || m_bWaitSaveCompleted )
487cdf0e10cSrcweir             throw new com.sun.star.embed.WrongStateException();
488cdf0e10cSrcweir 
489cdf0e10cSrcweir         com.sun.star.embed.XStorage xSubStorage = null;
490cdf0e10cSrcweir 
491cdf0e10cSrcweir         if ( m_nObjectState == com.sun.star.embed.EmbedStates.LOADED )
492cdf0e10cSrcweir         {
493cdf0e10cSrcweir             xSubStorage =
494cdf0e10cSrcweir                 xStorage.openStorageElement( aEntryName,
495cdf0e10cSrcweir                             com.sun.star.embed.ElementModes.READWRITE | com.sun.star.embed.ElementModes.NOCREATE );
496cdf0e10cSrcweir 
497cdf0e10cSrcweir             m_xOwnStorage.copyToStorage( xSubStorage );
498cdf0e10cSrcweir         }
499cdf0e10cSrcweir         else
500cdf0e10cSrcweir         {
501cdf0e10cSrcweir             xSubStorage =
502cdf0e10cSrcweir                 xStorage.openStorageElement( aEntryName,
503cdf0e10cSrcweir                             com.sun.star.embed.ElementModes.READWRITE | com.sun.star.embed.ElementModes.TRUNCATE );
504cdf0e10cSrcweir 
505cdf0e10cSrcweir             SaveDataToStorage( xSubStorage, m_aEditorFrame.getText(), UpdateSizeAndGetFromActive() );
506cdf0e10cSrcweir         }
507cdf0e10cSrcweir 
508cdf0e10cSrcweir         m_bWaitSaveCompleted = true;
509cdf0e10cSrcweir         m_xNewOwnStorage = xSubStorage;
510cdf0e10cSrcweir         m_xNewParentStorage = xStorage;
511cdf0e10cSrcweir         m_aNewEntryName = aEntryName;
512cdf0e10cSrcweir 
513cdf0e10cSrcweir     }
514cdf0e10cSrcweir 
515cdf0e10cSrcweir     // -------------------------------------------------------------
saveCompleted(boolean bUseNew)516cdf0e10cSrcweir     public void saveCompleted(boolean bUseNew) throws com.sun.star.embed.WrongStateException, com.sun.star.uno.Exception
517cdf0e10cSrcweir     {
518cdf0e10cSrcweir         if ( m_bDisposed )
519cdf0e10cSrcweir             throw new com.sun.star.lang.DisposedException();
520cdf0e10cSrcweir 
521cdf0e10cSrcweir         if ( m_nObjectState == -1 )
522cdf0e10cSrcweir             throw new com.sun.star.embed.WrongStateException();
523cdf0e10cSrcweir 
524cdf0e10cSrcweir         // it is allowed to call saveCompleted( false ) for nonstored objects
525cdf0e10cSrcweir         if ( !m_bWaitSaveCompleted && !bUseNew )
526cdf0e10cSrcweir             return;
527cdf0e10cSrcweir 
528cdf0e10cSrcweir         if ( !m_bWaitSaveCompleted )
529cdf0e10cSrcweir             throw new com.sun.star.io.IOException();
530cdf0e10cSrcweir 
531cdf0e10cSrcweir         if ( bUseNew )
532cdf0e10cSrcweir         {
533cdf0e10cSrcweir             SwitchOwnPersistence( m_xNewParentStorage, m_xNewOwnStorage, m_aNewEntryName );
534cdf0e10cSrcweir             PostEvent( "OnSaveAsDone" );
535cdf0e10cSrcweir         }
536cdf0e10cSrcweir         else
537cdf0e10cSrcweir         {
538cdf0e10cSrcweir             try
539cdf0e10cSrcweir             {
540cdf0e10cSrcweir                 m_xNewOwnStorage.dispose();
541cdf0e10cSrcweir             }
542cdf0e10cSrcweir             catch( com.sun.star.uno.RuntimeException e )
543cdf0e10cSrcweir             {}
544cdf0e10cSrcweir         }
545cdf0e10cSrcweir 
546cdf0e10cSrcweir         m_xNewOwnStorage = null;
547cdf0e10cSrcweir         m_xNewParentStorage = null;
548cdf0e10cSrcweir         m_aNewEntryName = null;
549cdf0e10cSrcweir         m_bWaitSaveCompleted = false;
550cdf0e10cSrcweir     }
551cdf0e10cSrcweir 
552cdf0e10cSrcweir     // -------------------------------------------------------------
hasEntry()553cdf0e10cSrcweir     public boolean hasEntry() throws com.sun.star.embed.WrongStateException
554cdf0e10cSrcweir     {
555cdf0e10cSrcweir         if ( m_bDisposed )
556cdf0e10cSrcweir             throw new com.sun.star.lang.DisposedException();
557cdf0e10cSrcweir 
558cdf0e10cSrcweir         if ( m_bWaitSaveCompleted )
559cdf0e10cSrcweir             throw new com.sun.star.embed.WrongStateException();
560cdf0e10cSrcweir 
561cdf0e10cSrcweir         if ( m_xOwnStorage != null )
562cdf0e10cSrcweir             return true;
563cdf0e10cSrcweir 
564cdf0e10cSrcweir         return false;
565cdf0e10cSrcweir     }
566cdf0e10cSrcweir 
567cdf0e10cSrcweir     // -------------------------------------------------------------
getEntryName()568cdf0e10cSrcweir     public String getEntryName() throws com.sun.star.embed.WrongStateException
569cdf0e10cSrcweir     {
570cdf0e10cSrcweir         if ( m_bDisposed )
571cdf0e10cSrcweir             throw new com.sun.star.lang.DisposedException();
572cdf0e10cSrcweir 
573cdf0e10cSrcweir         if ( m_nObjectState == -1 || m_bWaitSaveCompleted )
574cdf0e10cSrcweir             throw new com.sun.star.embed.WrongStateException();
575cdf0e10cSrcweir 
576cdf0e10cSrcweir         return m_aEntryName;
577cdf0e10cSrcweir     }
578cdf0e10cSrcweir 
579cdf0e10cSrcweir     // com.sun.star.embed.XVisualObject:
580cdf0e10cSrcweir     // -------------------------------------------------------------
setVisualAreaSize(long nAspect, com.sun.star.awt.Size aSize)581cdf0e10cSrcweir     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
582cdf0e10cSrcweir     {
583cdf0e10cSrcweir         if ( m_bDisposed )
584cdf0e10cSrcweir             throw new com.sun.star.lang.DisposedException();
585cdf0e10cSrcweir 
586cdf0e10cSrcweir         if ( m_nObjectState == -1 )
587cdf0e10cSrcweir             throw new com.sun.star.embed.WrongStateException();
588cdf0e10cSrcweir 
589cdf0e10cSrcweir         if ( nAspect == com.sun.star.embed.Aspects.MSOLE_ICON )
590cdf0e10cSrcweir             // the ICON aspect should be handled by the container
591cdf0e10cSrcweir             throw new com.sun.star.embed.WrongStateException();
592cdf0e10cSrcweir 
593cdf0e10cSrcweir         if ( m_nObjectState == com.sun.star.embed.EmbedStates.LOADED )
594cdf0e10cSrcweir             changeState( com.sun.star.embed.EmbedStates.RUNNING );
595cdf0e10cSrcweir 
596cdf0e10cSrcweir         if ( m_aEditorFrame == null )
597cdf0e10cSrcweir             throw new com.sun.star.uno.RuntimeException();
598cdf0e10cSrcweir 
599cdf0e10cSrcweir         m_aObjSize.setSize( aSize.Width, aSize.Height );
600cdf0e10cSrcweir         m_aEditorFrame.setAppSize( m_aObjSize );
601cdf0e10cSrcweir     }
602cdf0e10cSrcweir 
603cdf0e10cSrcweir     // -------------------------------------------------------------
getVisualAreaSize(long nAspect)604cdf0e10cSrcweir     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
605cdf0e10cSrcweir     {
606cdf0e10cSrcweir         if ( m_bDisposed )
607cdf0e10cSrcweir             throw new com.sun.star.lang.DisposedException();
608cdf0e10cSrcweir 
609cdf0e10cSrcweir         if ( m_nObjectState == -1 )
610cdf0e10cSrcweir             throw new com.sun.star.embed.WrongStateException();
611cdf0e10cSrcweir 
612cdf0e10cSrcweir         if ( nAspect == com.sun.star.embed.Aspects.MSOLE_ICON )
613cdf0e10cSrcweir             // the ICON aspect should be handled by the container
614cdf0e10cSrcweir             throw new com.sun.star.embed.WrongStateException();
615cdf0e10cSrcweir 
616cdf0e10cSrcweir         if ( m_nObjectState == com.sun.star.embed.EmbedStates.LOADED )
617cdf0e10cSrcweir             changeState( com.sun.star.embed.EmbedStates.RUNNING );
618cdf0e10cSrcweir 
619cdf0e10cSrcweir         UpdateSizeAndGetFromActive();
620cdf0e10cSrcweir 
621cdf0e10cSrcweir         return new com.sun.star.awt.Size( (int)m_aObjSize.getWidth(), (int)m_aObjSize.getHeight() );
622cdf0e10cSrcweir     }
623cdf0e10cSrcweir 
624cdf0e10cSrcweir     // -------------------------------------------------------------
getPreferredVisualRepresentation(long nAspect)625cdf0e10cSrcweir     public VisualRepresentation getPreferredVisualRepresentation(long nAspect) throws com.sun.star.lang.IllegalArgumentException, com.sun.star.embed.WrongStateException, com.sun.star.uno.Exception
626cdf0e10cSrcweir     {
627cdf0e10cSrcweir         if ( m_bDisposed )
628cdf0e10cSrcweir             throw new com.sun.star.lang.DisposedException();
629cdf0e10cSrcweir 
630cdf0e10cSrcweir         if ( m_nObjectState == -1 )
631cdf0e10cSrcweir             throw new com.sun.star.embed.WrongStateException();
632cdf0e10cSrcweir 
633cdf0e10cSrcweir         if ( nAspect == com.sun.star.embed.Aspects.MSOLE_ICON )
634cdf0e10cSrcweir             // the ICON aspect should be handled by the container
635cdf0e10cSrcweir             throw new com.sun.star.embed.WrongStateException();
636cdf0e10cSrcweir 
637cdf0e10cSrcweir         if ( m_nObjectState == com.sun.star.embed.EmbedStates.LOADED )
638cdf0e10cSrcweir             changeState( com.sun.star.embed.EmbedStates.RUNNING );
639cdf0e10cSrcweir 
640cdf0e10cSrcweir         byte[] aData = m_aEditorFrame.getReplacementImage();
641cdf0e10cSrcweir         VisualRepresentation aVisRep = new VisualRepresentation();
642cdf0e10cSrcweir         aVisRep.Data = aData;
643cdf0e10cSrcweir         aVisRep.Flavor = new com.sun.star.datatransfer.DataFlavor( "image/png", "png", new com.sun.star.uno.Type( byte[].class ) );
644cdf0e10cSrcweir         return aVisRep;
645cdf0e10cSrcweir     }
646cdf0e10cSrcweir 
647cdf0e10cSrcweir     // -------------------------------------------------------------
getMapUnit(long nAspect)648cdf0e10cSrcweir     public int getMapUnit(long nAspect) throws com.sun.star.uno.Exception
649cdf0e10cSrcweir     {
650cdf0e10cSrcweir         if ( m_bDisposed )
651cdf0e10cSrcweir             throw new com.sun.star.lang.DisposedException();
652cdf0e10cSrcweir 
653cdf0e10cSrcweir         if ( m_nObjectState == -1 )
654cdf0e10cSrcweir             throw new com.sun.star.embed.WrongStateException();
655cdf0e10cSrcweir 
656cdf0e10cSrcweir         if ( nAspect == com.sun.star.embed.Aspects.MSOLE_ICON )
657cdf0e10cSrcweir             // the ICON aspect should be handled by the container
658cdf0e10cSrcweir             throw new com.sun.star.embed.WrongStateException();
659cdf0e10cSrcweir 
660cdf0e10cSrcweir         return com.sun.star.embed.EmbedMapUnits.PIXEL;
661cdf0e10cSrcweir     }
662cdf0e10cSrcweir 
663cdf0e10cSrcweir     // com.sun.star.embed.XClassifiedObject:
664cdf0e10cSrcweir     // -------------------------------------------------------------
getClassID()665cdf0e10cSrcweir     public byte[] getClassID()
666cdf0e10cSrcweir     {
667cdf0e10cSrcweir         if ( m_bDisposed )
668cdf0e10cSrcweir             throw new com.sun.star.lang.DisposedException();
669cdf0e10cSrcweir 
670cdf0e10cSrcweir         return m_aClassID;
671cdf0e10cSrcweir     }
672cdf0e10cSrcweir 
673cdf0e10cSrcweir     // -------------------------------------------------------------
getClassName()674cdf0e10cSrcweir     public String getClassName()
675cdf0e10cSrcweir     {
676cdf0e10cSrcweir         if ( m_bDisposed )
677cdf0e10cSrcweir             throw new com.sun.star.lang.DisposedException();
678cdf0e10cSrcweir 
679cdf0e10cSrcweir         return new String();
680cdf0e10cSrcweir     }
681cdf0e10cSrcweir 
682cdf0e10cSrcweir     // -------------------------------------------------------------
setClassInfo(byte[] aClassID, String sClassName)683cdf0e10cSrcweir     public void setClassInfo(byte[] aClassID, String sClassName) throws com.sun.star.lang.NoSupportException
684cdf0e10cSrcweir     {
685cdf0e10cSrcweir         throw new com.sun.star.lang.NoSupportException();
686cdf0e10cSrcweir     }
687cdf0e10cSrcweir 
688cdf0e10cSrcweir     // com.sun.star.embed.XComponentSupplier:
689cdf0e10cSrcweir     // -------------------------------------------------------------
getComponent()690cdf0e10cSrcweir     public com.sun.star.util.XCloseable getComponent()
691cdf0e10cSrcweir     {
692cdf0e10cSrcweir         if ( m_bDisposed )
693cdf0e10cSrcweir             throw new com.sun.star.lang.DisposedException();
694cdf0e10cSrcweir 
695cdf0e10cSrcweir         // allows no access to the component, this simple example just has no
696cdf0e10cSrcweir         return null;
697cdf0e10cSrcweir     }
698cdf0e10cSrcweir 
699cdf0e10cSrcweir     // com.sun.star.embed.XStateChangeBroadcaster:
700cdf0e10cSrcweir     // -------------------------------------------------------------
addStateChangeListener(com.sun.star.embed.XStateChangeListener xListener)701cdf0e10cSrcweir     public void addStateChangeListener(com.sun.star.embed.XStateChangeListener xListener)
702cdf0e10cSrcweir     {
703cdf0e10cSrcweir         if ( m_bDisposed )
704cdf0e10cSrcweir             return;
705cdf0e10cSrcweir 
706cdf0e10cSrcweir         GetListeners().add( xListener );
707cdf0e10cSrcweir     }
708cdf0e10cSrcweir 
709cdf0e10cSrcweir     // -------------------------------------------------------------
removeStateChangeListener(com.sun.star.embed.XStateChangeListener xListener)710cdf0e10cSrcweir     public void removeStateChangeListener(com.sun.star.embed.XStateChangeListener xListener)
711cdf0e10cSrcweir     {
712cdf0e10cSrcweir         if ( m_bDisposed )
713cdf0e10cSrcweir             return;
714cdf0e10cSrcweir 
715cdf0e10cSrcweir         if ( m_aListeners != null )
716cdf0e10cSrcweir             m_aListeners.remove( xListener );
717cdf0e10cSrcweir     }
718cdf0e10cSrcweir 
719cdf0e10cSrcweir     // com.sun.star.document.XEventBroadcaster:
720cdf0e10cSrcweir     // -------------------------------------------------------------
addEventListener(com.sun.star.document.XEventListener xListener)721cdf0e10cSrcweir     public void addEventListener(com.sun.star.document.XEventListener xListener)
722cdf0e10cSrcweir     {
723cdf0e10cSrcweir         if ( m_bDisposed )
724cdf0e10cSrcweir             return;
725cdf0e10cSrcweir 
726cdf0e10cSrcweir         GetListeners().add( xListener );
727cdf0e10cSrcweir     }
728cdf0e10cSrcweir 
729cdf0e10cSrcweir     // -------------------------------------------------------------
removeEventListener(com.sun.star.document.XEventListener xListener)730cdf0e10cSrcweir     public void removeEventListener(com.sun.star.document.XEventListener xListener)
731cdf0e10cSrcweir     {
732cdf0e10cSrcweir         if ( m_bDisposed )
733cdf0e10cSrcweir             return;
734cdf0e10cSrcweir 
735cdf0e10cSrcweir         if ( m_aListeners != null )
736cdf0e10cSrcweir             m_aListeners.remove( xListener );
737cdf0e10cSrcweir     }
738cdf0e10cSrcweir 
739cdf0e10cSrcweir     // com.sun.star.util.XCloseBroadcaster:
740cdf0e10cSrcweir     // -------------------------------------------------------------
addCloseListener(com.sun.star.util.XCloseListener xListener)741cdf0e10cSrcweir     public void addCloseListener(com.sun.star.util.XCloseListener xListener)
742cdf0e10cSrcweir     {
743cdf0e10cSrcweir         if ( m_bDisposed )
744cdf0e10cSrcweir             return;
745cdf0e10cSrcweir 
746cdf0e10cSrcweir         GetListeners().add( xListener );
747cdf0e10cSrcweir     }
748cdf0e10cSrcweir 
749cdf0e10cSrcweir     // -------------------------------------------------------------
removeCloseListener(com.sun.star.util.XCloseListener xListener)750cdf0e10cSrcweir     public void removeCloseListener(com.sun.star.util.XCloseListener xListener)
751cdf0e10cSrcweir     {
752cdf0e10cSrcweir         if ( m_bDisposed )
753cdf0e10cSrcweir             return;
754cdf0e10cSrcweir 
755cdf0e10cSrcweir         if ( m_aListeners != null )
756cdf0e10cSrcweir             m_aListeners.remove( xListener );
757cdf0e10cSrcweir     }
758cdf0e10cSrcweir 
759cdf0e10cSrcweir     // com.sun.star.util.XCloseable:
760cdf0e10cSrcweir     // -------------------------------------------------------------
close(boolean bDeliverOwnership)761cdf0e10cSrcweir     public void close(boolean bDeliverOwnership) throws com.sun.star.util.CloseVetoException
762cdf0e10cSrcweir     {
763cdf0e10cSrcweir         if ( m_bDisposed )
764cdf0e10cSrcweir             throw new com.sun.star.lang.DisposedException();
765cdf0e10cSrcweir 
766cdf0e10cSrcweir         com.sun.star.lang.EventObject aEventObject = new com.sun.star.lang.EventObject( this );
767cdf0e10cSrcweir 
768cdf0e10cSrcweir         if ( m_aListeners != null )
769cdf0e10cSrcweir         {
770cdf0e10cSrcweir             for ( int nInd = 0; nInd < m_aListeners.size(); nInd++ )
771cdf0e10cSrcweir             {
772cdf0e10cSrcweir                 try
773cdf0e10cSrcweir                 {
774cdf0e10cSrcweir                     com.sun.star.util.XCloseListener xListener = ( com.sun.star.util.XCloseListener )
775cdf0e10cSrcweir                         UnoRuntime.queryInterface( com.sun.star.document.XEventListener.class, m_aListeners.get( nInd ) );
776cdf0e10cSrcweir 
777cdf0e10cSrcweir                     if ( xListener != null )
778cdf0e10cSrcweir                         xListener.queryClosing( aEventObject, bDeliverOwnership );
779cdf0e10cSrcweir                 }
780cdf0e10cSrcweir                 catch( com.sun.star.util.CloseVetoException e )
781cdf0e10cSrcweir                 {
782cdf0e10cSrcweir                     throw e;
783cdf0e10cSrcweir                 }
784cdf0e10cSrcweir                 catch( java.lang.Exception e )
785cdf0e10cSrcweir                 {
786cdf0e10cSrcweir                     m_aListeners.remove( nInd );
787cdf0e10cSrcweir                 }
788cdf0e10cSrcweir             }
789cdf0e10cSrcweir 
790cdf0e10cSrcweir             m_bDisposed = true;
791cdf0e10cSrcweir 
792cdf0e10cSrcweir             for ( int nInd = 0; nInd < m_aListeners.size(); nInd++ )
793cdf0e10cSrcweir             {
794cdf0e10cSrcweir                 try
795cdf0e10cSrcweir                 {
796cdf0e10cSrcweir                     com.sun.star.util.XCloseListener xListener = ( com.sun.star.util.XCloseListener )
797cdf0e10cSrcweir                         UnoRuntime.queryInterface( com.sun.star.document.XEventListener.class, m_aListeners.get( nInd ) );
798cdf0e10cSrcweir 
799cdf0e10cSrcweir                     if ( xListener != null )
800cdf0e10cSrcweir                         xListener.notifyClosing( aEventObject );
801cdf0e10cSrcweir                 }
802cdf0e10cSrcweir                 catch( java.lang.Exception e )
803cdf0e10cSrcweir                 {
804cdf0e10cSrcweir                     m_aListeners.remove( nInd );
805cdf0e10cSrcweir                 }
806cdf0e10cSrcweir             }
807cdf0e10cSrcweir 
808cdf0e10cSrcweir             m_aListeners.clear();
809cdf0e10cSrcweir         }
810cdf0e10cSrcweir 
811cdf0e10cSrcweir         m_bDisposed = true;
812cdf0e10cSrcweir 
813cdf0e10cSrcweir         if ( m_aEditorFrame != null )
814cdf0e10cSrcweir         {
815cdf0e10cSrcweir             m_aEditorFrame.dispose();
816cdf0e10cSrcweir             m_aEditorFrame = null;
817cdf0e10cSrcweir         }
818cdf0e10cSrcweir 
819cdf0e10cSrcweir         if ( m_xOwnStorage != null )
820cdf0e10cSrcweir         {
821cdf0e10cSrcweir             try {
822cdf0e10cSrcweir                 m_xOwnStorage.dispose();
823cdf0e10cSrcweir             } catch( java.lang.Exception e ) {}
824cdf0e10cSrcweir             m_xOwnStorage = null;
825cdf0e10cSrcweir         }
826cdf0e10cSrcweir     }
827cdf0e10cSrcweir 
828cdf0e10cSrcweir     // com.sun.star.embed.XEmbeddedObject:
829cdf0e10cSrcweir     // -------------------------------------------------------------
changeState(int nNewState)830cdf0e10cSrcweir     public void changeState(int nNewState) throws com.sun.star.embed.UnreachableStateException, com.sun.star.embed.WrongStateException, com.sun.star.uno.Exception
831cdf0e10cSrcweir     {
832cdf0e10cSrcweir         if ( m_bDisposed )
833cdf0e10cSrcweir             throw new com.sun.star.lang.DisposedException();
834cdf0e10cSrcweir 
835cdf0e10cSrcweir         if ( m_nObjectState == -1 )
836cdf0e10cSrcweir             throw new com.sun.star.embed.WrongStateException();
837cdf0e10cSrcweir 
838cdf0e10cSrcweir         int nOldState = m_nObjectState;
839cdf0e10cSrcweir 
840cdf0e10cSrcweir         if ( nOldState == nNewState )
841cdf0e10cSrcweir         {
842cdf0e10cSrcweir             if ( nOldState == com.sun.star.embed.EmbedStates.ACTIVE )
843cdf0e10cSrcweir             {
844cdf0e10cSrcweir                 if ( m_aEditorFrame == null )
845cdf0e10cSrcweir                     throw new com.sun.star.uno.RuntimeException();
846cdf0e10cSrcweir                 m_aEditorFrame.toFront();
847cdf0e10cSrcweir             }
848cdf0e10cSrcweir 
849cdf0e10cSrcweir             return;
850cdf0e10cSrcweir         }
851cdf0e10cSrcweir 
852cdf0e10cSrcweir         if ( nNewState != com.sun.star.embed.EmbedStates.LOADED
853cdf0e10cSrcweir           && nNewState != com.sun.star.embed.EmbedStates.RUNNING
854cdf0e10cSrcweir           && nNewState != com.sun.star.embed.EmbedStates.ACTIVE )
855cdf0e10cSrcweir             throw new com.sun.star.embed.UnreachableStateException();
856cdf0e10cSrcweir 
857cdf0e10cSrcweir         StateChangeNotification( true, nOldState, nNewState );
858cdf0e10cSrcweir 
859cdf0e10cSrcweir         try
860cdf0e10cSrcweir         {
861cdf0e10cSrcweir             if ( nOldState == com.sun.star.embed.EmbedStates.LOADED )
862cdf0e10cSrcweir             {
863cdf0e10cSrcweir                 // switch to the RUNNING state first
864cdf0e10cSrcweir                 String aText = ReadStringFromStream( m_xOwnStorage, "content.txt" );
865cdf0e10cSrcweir 
866cdf0e10cSrcweir                 EditorFrame aEditorFrame = new EditorFrame( m_aEntryName, this, 5, 20 );
867cdf0e10cSrcweir                 aEditorFrame.setText( aText );
868cdf0e10cSrcweir 
869cdf0e10cSrcweir                 ReadSizeFromOwnStorage();
870cdf0e10cSrcweir 
871cdf0e10cSrcweir                 m_aEditorFrame = aEditorFrame;
872cdf0e10cSrcweir                 m_nObjectState = com.sun.star.embed.EmbedStates.RUNNING;
873cdf0e10cSrcweir 
874cdf0e10cSrcweir                 if ( nNewState == com.sun.star.embed.EmbedStates.ACTIVE )
875cdf0e10cSrcweir                 {
876cdf0e10cSrcweir                     if ( m_xClient == null )
877cdf0e10cSrcweir                         throw new com.sun.star.embed.WrongStateException();
878cdf0e10cSrcweir 
879cdf0e10cSrcweir                     m_aEditorFrame.show();
880cdf0e10cSrcweir                     m_aEditorFrame.toFront();
881cdf0e10cSrcweir 
882cdf0e10cSrcweir                     if ( m_aObjSize != null )
883cdf0e10cSrcweir                         aEditorFrame.setAppSize( m_aObjSize );
884cdf0e10cSrcweir 
885cdf0e10cSrcweir                     m_xClient.visibilityChanged( true );
886cdf0e10cSrcweir                     m_nObjectState = com.sun.star.embed.EmbedStates.ACTIVE;
887cdf0e10cSrcweir                 }
888cdf0e10cSrcweir             }
889cdf0e10cSrcweir             else if ( nOldState == com.sun.star.embed.EmbedStates.RUNNING )
890cdf0e10cSrcweir             {
891cdf0e10cSrcweir                 if ( nNewState == com.sun.star.embed.EmbedStates.LOADED )
892cdf0e10cSrcweir                 {
893cdf0e10cSrcweir                     EditorFrame aFrame = m_aEditorFrame;
894cdf0e10cSrcweir                     m_aEditorFrame = null;
895cdf0e10cSrcweir                     aFrame.dispose();
896cdf0e10cSrcweir                     m_nObjectState = nNewState;
897cdf0e10cSrcweir                 }
898cdf0e10cSrcweir                 else // nNewState == ACTIVE
899cdf0e10cSrcweir                 {
900cdf0e10cSrcweir                     if ( m_aEditorFrame == null )
901cdf0e10cSrcweir                         throw new com.sun.star.uno.RuntimeException();
902cdf0e10cSrcweir 
903cdf0e10cSrcweir                     if ( m_xClient == null )
904cdf0e10cSrcweir                         throw new com.sun.star.embed.WrongStateException();
905cdf0e10cSrcweir 
906cdf0e10cSrcweir                     m_aEditorFrame.show();
907cdf0e10cSrcweir                     m_aEditorFrame.toFront();
908cdf0e10cSrcweir 
909cdf0e10cSrcweir                     if ( m_aObjSize != null )
910cdf0e10cSrcweir                         m_aEditorFrame.setAppSize( m_aObjSize );
911cdf0e10cSrcweir 
912cdf0e10cSrcweir                     m_xClient.visibilityChanged( true );
913cdf0e10cSrcweir 
914cdf0e10cSrcweir                     m_nObjectState = nNewState;
915cdf0e10cSrcweir                 }
916cdf0e10cSrcweir             }
917cdf0e10cSrcweir             else // nOldState == ACTIVE
918cdf0e10cSrcweir             {
919cdf0e10cSrcweir                 UpdateSizeAndGetFromActive();
920cdf0e10cSrcweir                 if ( nNewState == com.sun.star.embed.EmbedStates.RUNNING )
921cdf0e10cSrcweir                 {
922cdf0e10cSrcweir                     m_aEditorFrame.hide();
923cdf0e10cSrcweir                     m_nObjectState = nNewState;
924cdf0e10cSrcweir                 }
925cdf0e10cSrcweir                 else // nNewState == LOADED
926cdf0e10cSrcweir                 {
927cdf0e10cSrcweir                     EditorFrame aFrame = m_aEditorFrame;
928cdf0e10cSrcweir                     m_aEditorFrame = null;
929cdf0e10cSrcweir                     aFrame.dispose();
930cdf0e10cSrcweir                     m_nObjectState = nNewState;
931cdf0e10cSrcweir                 }
932cdf0e10cSrcweir             }
933cdf0e10cSrcweir         }
934cdf0e10cSrcweir         catch( com.sun.star.uno.Exception e )
935cdf0e10cSrcweir         {
936cdf0e10cSrcweir             if ( nOldState != m_nObjectState )
937cdf0e10cSrcweir                 StateChangeNotification( false, nOldState, m_nObjectState );
938cdf0e10cSrcweir             throw e;
939cdf0e10cSrcweir         }
940cdf0e10cSrcweir 
941cdf0e10cSrcweir         StateChangeNotification( true, nOldState, nNewState );
942cdf0e10cSrcweir     }
943cdf0e10cSrcweir 
944cdf0e10cSrcweir     // -------------------------------------------------------------
getReachableStates()945cdf0e10cSrcweir     public int[] getReachableStates() throws com.sun.star.embed.NeedsRunningStateException, com.sun.star.embed.WrongStateException
946cdf0e10cSrcweir     {
947cdf0e10cSrcweir         if ( m_bDisposed )
948cdf0e10cSrcweir             throw new com.sun.star.lang.DisposedException();
949cdf0e10cSrcweir 
950cdf0e10cSrcweir         if ( m_nObjectState == -1 )
951cdf0e10cSrcweir             throw new com.sun.star.embed.WrongStateException();
952cdf0e10cSrcweir 
953cdf0e10cSrcweir         int[] pStates = new int[3];
954cdf0e10cSrcweir         pStates[0] = com.sun.star.embed.EmbedStates.LOADED;
955cdf0e10cSrcweir         pStates[1] = com.sun.star.embed.EmbedStates.RUNNING;
956cdf0e10cSrcweir         pStates[2] = com.sun.star.embed.EmbedStates.ACTIVE;
957cdf0e10cSrcweir 
958cdf0e10cSrcweir         return pStates;
959cdf0e10cSrcweir     }
960cdf0e10cSrcweir 
961cdf0e10cSrcweir     // -------------------------------------------------------------
getCurrentState()962cdf0e10cSrcweir     public int getCurrentState() throws com.sun.star.embed.WrongStateException
963cdf0e10cSrcweir     {
964cdf0e10cSrcweir         if ( m_bDisposed )
965cdf0e10cSrcweir             throw new com.sun.star.lang.DisposedException();
966cdf0e10cSrcweir 
967cdf0e10cSrcweir         if ( m_nObjectState == -1 )
968cdf0e10cSrcweir             throw new com.sun.star.embed.WrongStateException();
969cdf0e10cSrcweir 
970cdf0e10cSrcweir         return m_nObjectState;
971cdf0e10cSrcweir     }
972cdf0e10cSrcweir 
973cdf0e10cSrcweir     // -------------------------------------------------------------
doVerb(int nVerbID)974cdf0e10cSrcweir     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
975cdf0e10cSrcweir     {
976cdf0e10cSrcweir         if ( m_bDisposed )
977cdf0e10cSrcweir             throw new com.sun.star.lang.DisposedException();
978cdf0e10cSrcweir 
979cdf0e10cSrcweir         if ( m_nObjectState == -1 )
980cdf0e10cSrcweir             throw new com.sun.star.embed.WrongStateException();
981cdf0e10cSrcweir 
982cdf0e10cSrcweir         if ( nVerbID == com.sun.star.embed.EmbedVerbs.MS_OLEVERB_PRIMARY
983cdf0e10cSrcweir           || nVerbID == com.sun.star.embed.EmbedVerbs.MS_OLEVERB_SHOW
984cdf0e10cSrcweir           || nVerbID == com.sun.star.embed.EmbedVerbs.MS_OLEVERB_OPEN )
985cdf0e10cSrcweir             changeState( com.sun.star.embed.EmbedStates.ACTIVE );
986cdf0e10cSrcweir         else if ( nVerbID == com.sun.star.embed.EmbedVerbs.MS_OLEVERB_HIDE )
987cdf0e10cSrcweir             changeState( com.sun.star.embed.EmbedStates.RUNNING );
988cdf0e10cSrcweir     }
989cdf0e10cSrcweir 
990cdf0e10cSrcweir     // -------------------------------------------------------------
getSupportedVerbs()991cdf0e10cSrcweir     public com.sun.star.embed.VerbDescriptor[] getSupportedVerbs() throws com.sun.star.embed.NeedsRunningStateException, com.sun.star.embed.WrongStateException
992cdf0e10cSrcweir     {
993cdf0e10cSrcweir         if ( m_bDisposed )
994cdf0e10cSrcweir             throw new com.sun.star.lang.DisposedException();
995cdf0e10cSrcweir 
996cdf0e10cSrcweir         if ( m_nObjectState == -1 )
997cdf0e10cSrcweir             throw new com.sun.star.embed.WrongStateException();
998cdf0e10cSrcweir 
999cdf0e10cSrcweir         if ( m_pOwnVerbs == null )
1000cdf0e10cSrcweir         {
1001cdf0e10cSrcweir             try
1002cdf0e10cSrcweir             {
1003cdf0e10cSrcweir                 XMultiComponentFactory xFactory = m_xContext.getServiceManager();
1004cdf0e10cSrcweir                 Object obj = xFactory.createInstanceWithContext( "com.sun.star.configuration.ConfigurationProvider", m_xContext );
1005cdf0e10cSrcweir                 XMultiServiceFactory xConfProvider = (XMultiServiceFactory) UnoRuntime.queryInterface( XMultiServiceFactory.class, obj );
1006cdf0e10cSrcweir                 if ( xConfProvider == null )
1007cdf0e10cSrcweir                     throw new com.sun.star.uno.RuntimeException();
1008cdf0e10cSrcweir 
1009cdf0e10cSrcweir                 Object[] aArgs = new Object[1];
1010cdf0e10cSrcweir                 aArgs[0] = "/org.openoffice.Office.Embedding/Objects";
1011cdf0e10cSrcweir                 Object oSettings = xConfProvider.createInstanceWithArguments( "com.sun.star.configuration.ConfigurationAccess", aArgs );
1012cdf0e10cSrcweir                 XNameAccess xObjConfNA = ( XNameAccess ) UnoRuntime.queryInterface( XNameAccess.class, oSettings );
1013cdf0e10cSrcweir                 if ( xObjConfNA == null )
1014cdf0e10cSrcweir                     throw new com.sun.star.uno.RuntimeException();
1015cdf0e10cSrcweir 
1016cdf0e10cSrcweir                 Object oEmbObj = xObjConfNA.getByName( "69474366-FD6F-4806-8374-8EDD1B6E771D" );
1017cdf0e10cSrcweir                 XNameAccess xEmbObjNA = (XNameAccess) UnoRuntime.queryInterface( XNameAccess.class, oEmbObj );
1018cdf0e10cSrcweir                 if ( xEmbObjNA == null )
1019cdf0e10cSrcweir                     throw new com.sun.star.uno.RuntimeException();
1020cdf0e10cSrcweir 
1021cdf0e10cSrcweir                 String[] pVerbShortcuts = (String[]) AnyConverter.toArray( xEmbObjNA.getByName( "ObjectVerbs" ) );
1022cdf0e10cSrcweir                 if ( pVerbShortcuts != null && pVerbShortcuts.length != 0 )
1023cdf0e10cSrcweir                 {
1024cdf0e10cSrcweir                     com.sun.star.embed.VerbDescriptor[] pVerbs = new com.sun.star.embed.VerbDescriptor[pVerbShortcuts.length];
1025cdf0e10cSrcweir                        aArgs[0] = "/org.openoffice.Office.Embedding/Verbs";
1026cdf0e10cSrcweir                        Object oVerbs = xConfProvider.createInstanceWithArguments( "com.sun.star.configuration.ConfigurationAccess", aArgs );
1027cdf0e10cSrcweir                        XNameAccess xVerbsConfNA = ( XNameAccess ) UnoRuntime.queryInterface( XNameAccess.class, oVerbs );
1028cdf0e10cSrcweir                        if ( xVerbsConfNA == null )
1029cdf0e10cSrcweir                         throw new com.sun.star.uno.RuntimeException();
1030cdf0e10cSrcweir 
1031cdf0e10cSrcweir                     for ( int nInd = 0; nInd < pVerbShortcuts.length; nInd++ )
1032cdf0e10cSrcweir                     {
1033cdf0e10cSrcweir                         try
1034cdf0e10cSrcweir                         {
1035cdf0e10cSrcweir                             XNameAccess xVerbNA = (XNameAccess) UnoRuntime.queryInterface(
1036cdf0e10cSrcweir                                                                 XNameAccess.class,
1037cdf0e10cSrcweir                                                                 xVerbsConfNA.getByName( pVerbShortcuts[nInd] ) );
1038cdf0e10cSrcweir                             if ( xVerbNA != null )
1039cdf0e10cSrcweir                             {
1040cdf0e10cSrcweir                                 com.sun.star.embed.VerbDescriptor aVerb = new com.sun.star.embed.VerbDescriptor();
1041cdf0e10cSrcweir                                 aVerb.VerbID = AnyConverter.toInt( xVerbNA.getByName( "VerbID" ) );
1042cdf0e10cSrcweir                                 aVerb.VerbName = AnyConverter.toString( xVerbNA.getByName( "VerbUIName" ) );
1043cdf0e10cSrcweir                                 aVerb.VerbFlags = AnyConverter.toInt( xVerbNA.getByName( "VerbFlags" ) );
1044cdf0e10cSrcweir                                 aVerb.VerbAttributes = AnyConverter.toInt( xVerbNA.getByName( "VerbAttributes" ) );
1045cdf0e10cSrcweir                                 pVerbs[nInd] = aVerb;
1046cdf0e10cSrcweir                             }
1047cdf0e10cSrcweir                         }
1048cdf0e10cSrcweir                         catch( java.lang.Exception e )
1049cdf0e10cSrcweir                         {
1050cdf0e10cSrcweir                         }
1051cdf0e10cSrcweir 
1052cdf0e10cSrcweir                         if ( pVerbs[nInd] == null )
1053cdf0e10cSrcweir                         {
1054cdf0e10cSrcweir                             // let the error be visible
1055cdf0e10cSrcweir                             pVerbs[nInd] = new com.sun.star.embed.VerbDescriptor();
1056cdf0e10cSrcweir                             pVerbs[nInd].VerbID = com.sun.star.embed.EmbedVerbs.MS_OLEVERB_PRIMARY;
1057cdf0e10cSrcweir                             pVerbs[nInd].VerbName = "ERROR!";
1058cdf0e10cSrcweir                             pVerbs[nInd].VerbFlags = 0;
1059cdf0e10cSrcweir                             pVerbs[nInd].VerbAttributes = com.sun.star.embed.VerbAttributes.MS_VERBATTR_ONCONTAINERMENU;
1060cdf0e10cSrcweir                         }
1061cdf0e10cSrcweir                     }
1062cdf0e10cSrcweir 
1063cdf0e10cSrcweir                     m_pOwnVerbs = pVerbs;
1064cdf0e10cSrcweir                 }
1065cdf0e10cSrcweir             }
1066cdf0e10cSrcweir             catch( com.sun.star.uno.Exception e )
1067cdf0e10cSrcweir             {}
1068cdf0e10cSrcweir         }
1069cdf0e10cSrcweir 
1070cdf0e10cSrcweir         if ( m_pOwnVerbs != null )
1071cdf0e10cSrcweir             return m_pOwnVerbs;
1072cdf0e10cSrcweir 
1073cdf0e10cSrcweir         return new com.sun.star.embed.VerbDescriptor[0];
1074cdf0e10cSrcweir     }
1075cdf0e10cSrcweir 
1076cdf0e10cSrcweir     // -------------------------------------------------------------
setClientSite(com.sun.star.embed.XEmbeddedClient xClient)1077cdf0e10cSrcweir     public void setClientSite(com.sun.star.embed.XEmbeddedClient xClient) throws com.sun.star.embed.WrongStateException
1078cdf0e10cSrcweir     {
1079cdf0e10cSrcweir         if ( m_bDisposed )
1080cdf0e10cSrcweir             throw new com.sun.star.lang.DisposedException();
1081cdf0e10cSrcweir 
1082cdf0e10cSrcweir         if ( m_nObjectState == -1 )
1083cdf0e10cSrcweir             throw new com.sun.star.embed.WrongStateException();
1084cdf0e10cSrcweir 
1085cdf0e10cSrcweir         m_xClient = xClient;
1086cdf0e10cSrcweir     }
1087cdf0e10cSrcweir 
1088cdf0e10cSrcweir     // -------------------------------------------------------------
getClientSite()1089cdf0e10cSrcweir     public com.sun.star.embed.XEmbeddedClient getClientSite() throws com.sun.star.embed.WrongStateException
1090cdf0e10cSrcweir     {
1091cdf0e10cSrcweir         if ( m_bDisposed )
1092cdf0e10cSrcweir             throw new com.sun.star.lang.DisposedException();
1093cdf0e10cSrcweir 
1094cdf0e10cSrcweir         if ( m_nObjectState == -1 )
1095cdf0e10cSrcweir             throw new com.sun.star.embed.WrongStateException();
1096cdf0e10cSrcweir 
1097cdf0e10cSrcweir         return m_xClient;
1098cdf0e10cSrcweir     }
1099cdf0e10cSrcweir 
1100cdf0e10cSrcweir     // -------------------------------------------------------------
update()1101cdf0e10cSrcweir     public void update() throws com.sun.star.embed.WrongStateException, com.sun.star.uno.Exception
1102cdf0e10cSrcweir     {
1103cdf0e10cSrcweir         if ( m_bDisposed )
1104cdf0e10cSrcweir             throw new com.sun.star.lang.DisposedException();
1105cdf0e10cSrcweir 
1106cdf0e10cSrcweir         if ( m_nObjectState == -1 )
1107cdf0e10cSrcweir             throw new com.sun.star.embed.WrongStateException();
1108cdf0e10cSrcweir 
1109cdf0e10cSrcweir         // not implemented
1110cdf0e10cSrcweir     }
1111cdf0e10cSrcweir 
1112cdf0e10cSrcweir     // -------------------------------------------------------------
setUpdateMode(int nMode)1113cdf0e10cSrcweir     public void setUpdateMode(int nMode) throws com.sun.star.embed.WrongStateException
1114cdf0e10cSrcweir     {
1115cdf0e10cSrcweir         if ( m_bDisposed )
1116cdf0e10cSrcweir             throw new com.sun.star.lang.DisposedException();
1117cdf0e10cSrcweir 
1118cdf0e10cSrcweir         if ( m_nObjectState == -1 )
1119cdf0e10cSrcweir             throw new com.sun.star.embed.WrongStateException();
1120cdf0e10cSrcweir 
1121cdf0e10cSrcweir         // not implemented
1122cdf0e10cSrcweir     }
1123cdf0e10cSrcweir 
1124cdf0e10cSrcweir     // -------------------------------------------------------------
getStatus(long nAspect)1125cdf0e10cSrcweir     public long getStatus(long nAspect) throws com.sun.star.embed.WrongStateException
1126cdf0e10cSrcweir     {
1127cdf0e10cSrcweir         if ( m_bDisposed )
1128cdf0e10cSrcweir             throw new com.sun.star.lang.DisposedException();
1129cdf0e10cSrcweir 
1130cdf0e10cSrcweir         if ( m_nObjectState == -1 )
1131cdf0e10cSrcweir             throw new com.sun.star.embed.WrongStateException();
1132cdf0e10cSrcweir 
1133cdf0e10cSrcweir         return 0;
1134cdf0e10cSrcweir     }
1135cdf0e10cSrcweir 
1136cdf0e10cSrcweir     // -------------------------------------------------------------
setContainerName(String sName)1137cdf0e10cSrcweir     public void setContainerName(String sName)
1138cdf0e10cSrcweir     {
1139cdf0e10cSrcweir         if ( m_bDisposed )
1140cdf0e10cSrcweir             throw new com.sun.star.lang.DisposedException();
1141cdf0e10cSrcweir 
1142cdf0e10cSrcweir         // not implemented
1143cdf0e10cSrcweir     }
1144cdf0e10cSrcweir }
1145cdf0e10cSrcweir 
1146