1*cdf0e10cSrcweir package embeddedobj.test; 2*cdf0e10cSrcweir 3*cdf0e10cSrcweir import java.awt.*; 4*cdf0e10cSrcweir import java.applet.*; 5*cdf0e10cSrcweir import java.awt.event.*; 6*cdf0e10cSrcweir import java.net.*; 7*cdf0e10cSrcweir import java.io.*; 8*cdf0e10cSrcweir import java.util.Vector; 9*cdf0e10cSrcweir 10*cdf0e10cSrcweir import javax.swing.JOptionPane; 11*cdf0e10cSrcweir import javax.swing.Timer; 12*cdf0e10cSrcweir 13*cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory; 14*cdf0e10cSrcweir import com.sun.star.lang.XSingleServiceFactory; 15*cdf0e10cSrcweir 16*cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 17*cdf0e10cSrcweir import com.sun.star.uno.XInterface; 18*cdf0e10cSrcweir import com.sun.star.uno.AnyConverter; 19*cdf0e10cSrcweir import com.sun.star.uno.Type; 20*cdf0e10cSrcweir import com.sun.star.uno.Any; 21*cdf0e10cSrcweir 22*cdf0e10cSrcweir import com.sun.star.lang.XComponent; 23*cdf0e10cSrcweir 24*cdf0e10cSrcweir import com.sun.star.util.XCloseable; 25*cdf0e10cSrcweir import com.sun.star.util.XURLTransformer; 26*cdf0e10cSrcweir import com.sun.star.util.URL; 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir import com.sun.star.beans.PropertyValue; 29*cdf0e10cSrcweir import com.sun.star.beans.NamedValue; 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir import com.sun.star.datatransfer.DataFlavor; 32*cdf0e10cSrcweir import com.sun.star.datatransfer.XTransferable; 33*cdf0e10cSrcweir 34*cdf0e10cSrcweir import com.sun.star.container.XNameAccess; 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir import com.sun.star.io.XStream; 37*cdf0e10cSrcweir import com.sun.star.io.XInputStream; 38*cdf0e10cSrcweir import com.sun.star.io.XOutputStream; 39*cdf0e10cSrcweir import com.sun.star.io.XTruncate; 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir import com.sun.star.awt.XWindow; 42*cdf0e10cSrcweir import com.sun.star.awt.XBitmap; 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir import com.sun.star.task.XJob; 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir import com.sun.star.embed.*; 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir 49*cdf0e10cSrcweir class ActionObject 50*cdf0e10cSrcweir { 51*cdf0e10cSrcweir public byte m_nID; 52*cdf0e10cSrcweir public String m_sParam; 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir public ActionObject() 55*cdf0e10cSrcweir { 56*cdf0e10cSrcweir m_nID = 0; 57*cdf0e10cSrcweir m_sParam = null; 58*cdf0e10cSrcweir } 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir public ActionObject( byte nID ) 61*cdf0e10cSrcweir { 62*cdf0e10cSrcweir m_nID = nID; 63*cdf0e10cSrcweir m_sParam = null; 64*cdf0e10cSrcweir } 65*cdf0e10cSrcweir 66*cdf0e10cSrcweir public ActionObject( byte nID, String sParam ) 67*cdf0e10cSrcweir { 68*cdf0e10cSrcweir m_nID = nID; 69*cdf0e10cSrcweir m_sParam = sParam; 70*cdf0e10cSrcweir } 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir public ActionObject( ActionObject aObject ) 73*cdf0e10cSrcweir { 74*cdf0e10cSrcweir m_nID = aObject.m_nID; 75*cdf0e10cSrcweir m_sParam = aObject.m_sParam; 76*cdf0e10cSrcweir } 77*cdf0e10cSrcweir }; 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir public class EmbedContApp extends Applet 80*cdf0e10cSrcweir implements MouseListener, XEmbeddedClient, ActionListener, XJob, XInplaceClient, XWindowSupplier 81*cdf0e10cSrcweir { 82*cdf0e10cSrcweir private XMultiServiceFactory m_xServiceFactory; 83*cdf0e10cSrcweir 84*cdf0e10cSrcweir private final boolean m_bStoreVisRepl = false; 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir private XJob m_xMainThreadExecutor; 87*cdf0e10cSrcweir private NamedValue[] m_pValuesForExecutor; 88*cdf0e10cSrcweir 89*cdf0e10cSrcweir private XEmbeddedObject m_xEmbedObj; 90*cdf0e10cSrcweir private XStorage m_xStorage; 91*cdf0e10cSrcweir private float m_nXScaling; 92*cdf0e10cSrcweir private float m_nYScaling; 93*cdf0e10cSrcweir private float m_nXPixelSize; 94*cdf0e10cSrcweir private float m_nYPixelSize; 95*cdf0e10cSrcweir 96*cdf0e10cSrcweir private Frame m_aFrame; 97*cdf0e10cSrcweir private Menu m_aFileMenu; 98*cdf0e10cSrcweir private Menu m_aObjectMenu; 99*cdf0e10cSrcweir private Toolkit m_aToolkit; 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir private Image m_aImage; 102*cdf0e10cSrcweir private Object m_oImageLock; 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir private boolean m_bOwnFile = false; 105*cdf0e10cSrcweir 106*cdf0e10cSrcweir private boolean m_bLinkObj = false; 107*cdf0e10cSrcweir private String m_aLinkURI; 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir private Object m_oActionsNumberLock; 110*cdf0e10cSrcweir private Vector m_aActionsList; 111*cdf0e10cSrcweir 112*cdf0e10cSrcweir private Timer m_aTimer; 113*cdf0e10cSrcweir private boolean m_bDestroyed = false; 114*cdf0e10cSrcweir 115*cdf0e10cSrcweir private Object m_oInHandlerLock; 116*cdf0e10cSrcweir private boolean m_bInHandler = false; 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir private XURLTransformer m_xTransformer; 119*cdf0e10cSrcweir 120*cdf0e10cSrcweir private NativeView m_aNativeView; 121*cdf0e10cSrcweir private XWindow m_xVCLWindow; 122*cdf0e10cSrcweir 123*cdf0e10cSrcweir private XBitmap m_xBitmap; 124*cdf0e10cSrcweir private BitmapPainter m_aBitmapPainter; 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir // Constants 127*cdf0e10cSrcweir private final byte DESTROY = 1; 128*cdf0e10cSrcweir private final byte ACTIVATE_OUTPLACE = 2; 129*cdf0e10cSrcweir private final byte NEW_DOCUMENT = 3; 130*cdf0e10cSrcweir private final byte SAVE_AS = 4; 131*cdf0e10cSrcweir private final byte OPEN_FILE = 5; 132*cdf0e10cSrcweir private final byte SAVE = 6; 133*cdf0e10cSrcweir private final byte NEW_OBJECT = 7; 134*cdf0e10cSrcweir private final byte OBJECT_FROM_FILE = 8; 135*cdf0e10cSrcweir private final byte LINK_FROM_FILE = 9; 136*cdf0e10cSrcweir private final byte CONVERT_LINK_TO_OBJECT = 10; 137*cdf0e10cSrcweir private final byte ACTIVATE_INPLACE = 11; 138*cdf0e10cSrcweir private final byte DEACTIVATE = 12; 139*cdf0e10cSrcweir 140*cdf0e10cSrcweir // Methods 141*cdf0e10cSrcweir public EmbedContApp( Frame aFrame, XMultiServiceFactory xServiceFactory ) 142*cdf0e10cSrcweir { 143*cdf0e10cSrcweir m_aFrame = aFrame; 144*cdf0e10cSrcweir m_xServiceFactory = xServiceFactory; 145*cdf0e10cSrcweir } 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir public void init() 148*cdf0e10cSrcweir { 149*cdf0e10cSrcweir resize( 800, 600 ); 150*cdf0e10cSrcweir setBackground( Color.gray ); 151*cdf0e10cSrcweir 152*cdf0e10cSrcweir m_aToolkit = Toolkit.getDefaultToolkit(); 153*cdf0e10cSrcweir 154*cdf0e10cSrcweir try { 155*cdf0e10cSrcweir Object oTransformer = m_xServiceFactory.createInstance( "com.sun.star.util.URLTransformer" ); 156*cdf0e10cSrcweir m_xTransformer = (XURLTransformer)UnoRuntime.queryInterface( XURLTransformer.class, oTransformer ); 157*cdf0e10cSrcweir } catch( Exception e ) { System.exit( 0 ); } 158*cdf0e10cSrcweir 159*cdf0e10cSrcweir m_oActionsNumberLock = new Object(); 160*cdf0e10cSrcweir m_aActionsList = new Vector(); 161*cdf0e10cSrcweir 162*cdf0e10cSrcweir m_oInHandlerLock = new Object(); 163*cdf0e10cSrcweir m_oImageLock = new Object(); 164*cdf0e10cSrcweir 165*cdf0e10cSrcweir try { 166*cdf0e10cSrcweir Object oJob = m_xServiceFactory.createInstance( "com.sun.star.comp.thread.MainThreadExecutor" ); 167*cdf0e10cSrcweir m_xMainThreadExecutor = (XJob)UnoRuntime.queryInterface( XJob.class, oJob ); 168*cdf0e10cSrcweir } catch( Exception e ) {} 169*cdf0e10cSrcweir 170*cdf0e10cSrcweir if ( m_xMainThreadExecutor == null ) 171*cdf0e10cSrcweir { 172*cdf0e10cSrcweir System.out.println( "Can't create MainThreadExecutor! The application is unusable!" ); 173*cdf0e10cSrcweir System.exit( 0 ); 174*cdf0e10cSrcweir } 175*cdf0e10cSrcweir 176*cdf0e10cSrcweir m_nXScaling = 1; 177*cdf0e10cSrcweir m_nYScaling = 1; 178*cdf0e10cSrcweir m_nXPixelSize = 1; 179*cdf0e10cSrcweir m_nYPixelSize = 1; 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir m_pValuesForExecutor = new NamedValue[1]; 182*cdf0e10cSrcweir m_pValuesForExecutor[0] = new NamedValue( "JobToExecute", (Object)this ); 183*cdf0e10cSrcweir 184*cdf0e10cSrcweir m_aTimer = new Timer( 100, this ); 185*cdf0e10cSrcweir m_aTimer.start(); 186*cdf0e10cSrcweir 187*cdf0e10cSrcweir // Get a menu bar. 188*cdf0e10cSrcweir MenuBar aMenuBar = m_aFrame.getMenuBar(); 189*cdf0e10cSrcweir if( aMenuBar == null ) 190*cdf0e10cSrcweir { 191*cdf0e10cSrcweir aMenuBar = new MenuBar(); 192*cdf0e10cSrcweir m_aFrame.setMenuBar( aMenuBar ); 193*cdf0e10cSrcweir } 194*cdf0e10cSrcweir 195*cdf0e10cSrcweir // Create menus for the menu bar. 196*cdf0e10cSrcweir 197*cdf0e10cSrcweir // File menu 198*cdf0e10cSrcweir m_aFileMenu = new Menu( "File", true ); 199*cdf0e10cSrcweir aMenuBar.add( m_aFileMenu ); 200*cdf0e10cSrcweir 201*cdf0e10cSrcweir MenuItem aItem = new NewMenuItem(); 202*cdf0e10cSrcweir m_aFileMenu.add( aItem ); 203*cdf0e10cSrcweir 204*cdf0e10cSrcweir aItem = new OpenFileMenuItem(); 205*cdf0e10cSrcweir m_aFileMenu.add( aItem ); 206*cdf0e10cSrcweir 207*cdf0e10cSrcweir aItem = new SaveMenuItem(); 208*cdf0e10cSrcweir m_aFileMenu.add( aItem ); 209*cdf0e10cSrcweir 210*cdf0e10cSrcweir aItem = new SaveAsMenuItem(); 211*cdf0e10cSrcweir m_aFileMenu.add( aItem ); 212*cdf0e10cSrcweir 213*cdf0e10cSrcweir // Object menu 214*cdf0e10cSrcweir m_aObjectMenu = new Menu( "Object", true ); 215*cdf0e10cSrcweir aMenuBar.add( m_aObjectMenu ); 216*cdf0e10cSrcweir 217*cdf0e10cSrcweir aItem = new NewObjectMenuItem(); 218*cdf0e10cSrcweir m_aObjectMenu.add( aItem ); 219*cdf0e10cSrcweir 220*cdf0e10cSrcweir aItem = new LoadObjectMenuItem(); 221*cdf0e10cSrcweir m_aObjectMenu.add( aItem ); 222*cdf0e10cSrcweir 223*cdf0e10cSrcweir aItem = new LinkObjectMenuItem(); 224*cdf0e10cSrcweir m_aObjectMenu.add( aItem ); 225*cdf0e10cSrcweir 226*cdf0e10cSrcweir aItem = new ConvertLinkToEmbedMenuItem(); 227*cdf0e10cSrcweir m_aObjectMenu.add( aItem ); 228*cdf0e10cSrcweir 229*cdf0e10cSrcweir // Activation menu 230*cdf0e10cSrcweir m_aObjectMenu = new Menu( "Activation", true ); 231*cdf0e10cSrcweir aMenuBar.add( m_aObjectMenu ); 232*cdf0e10cSrcweir 233*cdf0e10cSrcweir aItem = new ActivateOutplaceMenuItem(); 234*cdf0e10cSrcweir m_aObjectMenu.add( aItem ); 235*cdf0e10cSrcweir 236*cdf0e10cSrcweir aItem = new ActivateInplaceMenuItem(); 237*cdf0e10cSrcweir m_aObjectMenu.add( aItem ); 238*cdf0e10cSrcweir 239*cdf0e10cSrcweir aItem = new DeactivateMenuItem(); 240*cdf0e10cSrcweir m_aObjectMenu.add( aItem ); 241*cdf0e10cSrcweir 242*cdf0e10cSrcweir m_aNativeView = new NativeView(); 243*cdf0e10cSrcweir m_aNativeView.resize( 800, 600 ); 244*cdf0e10cSrcweir this.add( m_aNativeView ); 245*cdf0e10cSrcweir 246*cdf0e10cSrcweir // Handle mouse clicks in our window. 247*cdf0e10cSrcweir // addMouseListener( this ); 248*cdf0e10cSrcweir } 249*cdf0e10cSrcweir 250*cdf0e10cSrcweir public void actionPerformed( ActionEvent evt ) 251*cdf0e10cSrcweir { 252*cdf0e10cSrcweir synchronized( m_oInHandlerLock ) 253*cdf0e10cSrcweir { 254*cdf0e10cSrcweir if ( m_bInHandler ) 255*cdf0e10cSrcweir return; 256*cdf0e10cSrcweir m_bInHandler = true; 257*cdf0e10cSrcweir } 258*cdf0e10cSrcweir 259*cdf0e10cSrcweir synchronized( m_oActionsNumberLock ) 260*cdf0e10cSrcweir { 261*cdf0e10cSrcweir if ( m_aActionsList.size() > 0 ) 262*cdf0e10cSrcweir { 263*cdf0e10cSrcweir try { 264*cdf0e10cSrcweir m_xMainThreadExecutor.execute( m_pValuesForExecutor ); 265*cdf0e10cSrcweir } 266*cdf0e10cSrcweir catch( Exception e ) 267*cdf0e10cSrcweir { 268*cdf0e10cSrcweir System.out.println( "Exception in actionPerformed() : " + e ); 269*cdf0e10cSrcweir } 270*cdf0e10cSrcweir } 271*cdf0e10cSrcweir else 272*cdf0e10cSrcweir { 273*cdf0e10cSrcweir synchronized( m_oInHandlerLock ) 274*cdf0e10cSrcweir { 275*cdf0e10cSrcweir m_bInHandler = false; 276*cdf0e10cSrcweir } 277*cdf0e10cSrcweir } 278*cdf0e10cSrcweir } 279*cdf0e10cSrcweir } 280*cdf0e10cSrcweir 281*cdf0e10cSrcweir // XWindowSupplier 282*cdf0e10cSrcweir public XWindow getWindow() 283*cdf0e10cSrcweir { 284*cdf0e10cSrcweir return m_xVCLWindow; 285*cdf0e10cSrcweir } 286*cdf0e10cSrcweir 287*cdf0e10cSrcweir // XEmbeddedClient 288*cdf0e10cSrcweir public void saveObject() 289*cdf0e10cSrcweir throws com.sun.star.uno.Exception 290*cdf0e10cSrcweir { 291*cdf0e10cSrcweir if ( m_xEmbedObj != null ) 292*cdf0e10cSrcweir { 293*cdf0e10cSrcweir try { 294*cdf0e10cSrcweir XEmbedPersist xPersist = (XEmbedPersist)UnoRuntime.queryInterface( XEmbedPersist.class, m_xEmbedObj ); 295*cdf0e10cSrcweir if ( xPersist != null ) 296*cdf0e10cSrcweir { 297*cdf0e10cSrcweir xPersist.storeOwn(); 298*cdf0e10cSrcweir generateNewImage(); 299*cdf0e10cSrcweir } 300*cdf0e10cSrcweir else 301*cdf0e10cSrcweir JOptionPane.showMessageDialog( m_aFrame, "No XEmbedPersist!", "Error:", JOptionPane.ERROR_MESSAGE ); 302*cdf0e10cSrcweir } 303*cdf0e10cSrcweir catch( Exception e ) 304*cdf0e10cSrcweir { 305*cdf0e10cSrcweir JOptionPane.showMessageDialog( m_aFrame, e, "Exception in saveObject:", JOptionPane.ERROR_MESSAGE ); 306*cdf0e10cSrcweir } 307*cdf0e10cSrcweir } 308*cdf0e10cSrcweir 309*cdf0e10cSrcweir generateNewImage(); 310*cdf0e10cSrcweir repaint(); 311*cdf0e10cSrcweir } 312*cdf0e10cSrcweir 313*cdf0e10cSrcweir public void onShowWindow( boolean bVisible ) 314*cdf0e10cSrcweir { 315*cdf0e10cSrcweir // for now nothing to do 316*cdf0e10cSrcweir } 317*cdf0e10cSrcweir 318*cdf0e10cSrcweir // XInplaceClient 319*cdf0e10cSrcweir public boolean canInplaceActivate() 320*cdf0e10cSrcweir { 321*cdf0e10cSrcweir return true; 322*cdf0e10cSrcweir } 323*cdf0e10cSrcweir 324*cdf0e10cSrcweir public void onInplaceActivate() 325*cdf0e10cSrcweir { 326*cdf0e10cSrcweir // TODO 327*cdf0e10cSrcweir // prepare for inplace activation 328*cdf0e10cSrcweir 329*cdf0e10cSrcweir // REMOVE 330*cdf0e10cSrcweir // workaround for CLIPCHILDREN problem 331*cdf0e10cSrcweir if ( m_aBitmapPainter != null ) 332*cdf0e10cSrcweir m_aBitmapPainter.stopPainting(); 333*cdf0e10cSrcweir } 334*cdf0e10cSrcweir 335*cdf0e10cSrcweir public void onUIActivate() 336*cdf0e10cSrcweir { 337*cdf0e10cSrcweir // TODO 338*cdf0e10cSrcweir // prepare for UI activate 339*cdf0e10cSrcweir } 340*cdf0e10cSrcweir 341*cdf0e10cSrcweir public void onInplaceDeactivate() 342*cdf0e10cSrcweir { 343*cdf0e10cSrcweir // TODO 344*cdf0e10cSrcweir // inplace deactivation is done 345*cdf0e10cSrcweir 346*cdf0e10cSrcweir // REMOVE 347*cdf0e10cSrcweir // workaround for CLIPCHILDREN problem 348*cdf0e10cSrcweir if ( m_aBitmapPainter != null ) 349*cdf0e10cSrcweir m_aBitmapPainter.startPainting(); 350*cdf0e10cSrcweir } 351*cdf0e10cSrcweir 352*cdf0e10cSrcweir public void onUIDeactivate() 353*cdf0e10cSrcweir { 354*cdf0e10cSrcweir // TODO 355*cdf0e10cSrcweir // prepare for UI deactivate 356*cdf0e10cSrcweir } 357*cdf0e10cSrcweir 358*cdf0e10cSrcweir public XIPMainContainerWindow getTopmostWindow() 359*cdf0e10cSrcweir { 360*cdf0e10cSrcweir // TODO 361*cdf0e10cSrcweir // return an implementation of XIPMainContainerWindow 362*cdf0e10cSrcweir // mainly required for ui activation 363*cdf0e10cSrcweir // dummy implementation is enough for inplace activation 364*cdf0e10cSrcweir 365*cdf0e10cSrcweir return null; 366*cdf0e10cSrcweir } 367*cdf0e10cSrcweir 368*cdf0e10cSrcweir public XInplaceUIWindow getDocumentWindow() 369*cdf0e10cSrcweir { 370*cdf0e10cSrcweir // TODO 371*cdf0e10cSrcweir // return implementation of XInplaceUIWindow 372*cdf0e10cSrcweir // mainly required for ui activation 373*cdf0e10cSrcweir // dummy implementation is enough for inplace activation 374*cdf0e10cSrcweir 375*cdf0e10cSrcweir return null; 376*cdf0e10cSrcweir } 377*cdf0e10cSrcweir 378*cdf0e10cSrcweir public com.sun.star.awt.Rectangle getPosRect() 379*cdf0e10cSrcweir { 380*cdf0e10cSrcweir // provide position rectangle to the object 381*cdf0e10cSrcweir try { 382*cdf0e10cSrcweir // here object bitmap and scaling factor hold the size 383*cdf0e10cSrcweir com.sun.star.awt.Size aBitmapSize = m_xBitmap.getSize(); 384*cdf0e10cSrcweir com.sun.star.awt.Size aVisSize = new com.sun.star.awt.Size( 385*cdf0e10cSrcweir (int)( aBitmapSize.Width * m_nXScaling ), 386*cdf0e10cSrcweir (int)( aBitmapSize.Height * m_nYScaling ) ); 387*cdf0e10cSrcweir return new com.sun.star.awt.Rectangle( 10, 10, aVisSize.Width, aVisSize.Height ); 388*cdf0e10cSrcweir } 389*cdf0e10cSrcweir catch( Exception e ) 390*cdf0e10cSrcweir { 391*cdf0e10cSrcweir System.out.println( "Position rectangle generation failed!" ); 392*cdf0e10cSrcweir } 393*cdf0e10cSrcweir 394*cdf0e10cSrcweir return new com.sun.star.awt.Rectangle( 10, 10, 110, 110 ); 395*cdf0e10cSrcweir } 396*cdf0e10cSrcweir 397*cdf0e10cSrcweir public com.sun.star.awt.Rectangle getClipRect() 398*cdf0e10cSrcweir { 399*cdf0e10cSrcweir // provide clip rectangle to the object 400*cdf0e10cSrcweir // in this application position and clip rectangles are the same 401*cdf0e10cSrcweir 402*cdf0e10cSrcweir try { 403*cdf0e10cSrcweir // here object bitmap and scaling factor hold the size 404*cdf0e10cSrcweir com.sun.star.awt.Size aBitmapSize = m_xBitmap.getSize(); 405*cdf0e10cSrcweir com.sun.star.awt.Size aVisSize = new com.sun.star.awt.Size( 406*cdf0e10cSrcweir (int)( aBitmapSize.Width * m_nXScaling ), 407*cdf0e10cSrcweir (int)( aBitmapSize.Height * m_nYScaling ) ); 408*cdf0e10cSrcweir return new com.sun.star.awt.Rectangle( 10, 10, aVisSize.Width, aVisSize.Height ); 409*cdf0e10cSrcweir } 410*cdf0e10cSrcweir catch( Exception e ) 411*cdf0e10cSrcweir { 412*cdf0e10cSrcweir System.out.println( "Clip rectangle generation failed!" ); 413*cdf0e10cSrcweir } 414*cdf0e10cSrcweir 415*cdf0e10cSrcweir return new com.sun.star.awt.Rectangle( 10, 10, 110, 110 ); 416*cdf0e10cSrcweir } 417*cdf0e10cSrcweir 418*cdf0e10cSrcweir public void translateAccelerators( com.sun.star.awt.KeyEvent[] aKeys ) 419*cdf0e10cSrcweir { 420*cdf0e10cSrcweir // TODO 421*cdf0e10cSrcweir // an accelerator table for object 422*cdf0e10cSrcweir // ui activation related 423*cdf0e10cSrcweir } 424*cdf0e10cSrcweir 425*cdf0e10cSrcweir public void scrollObj( com.sun.star.awt.Size aOffset ) 426*cdf0e10cSrcweir { 427*cdf0e10cSrcweir // TODO 428*cdf0e10cSrcweir // scrolls the object to a specified offset 429*cdf0e10cSrcweir // not mandatory for the testing application :) 430*cdf0e10cSrcweir } 431*cdf0e10cSrcweir 432*cdf0e10cSrcweir public void onPosRectChange( com.sun.star.awt.Rectangle aPosRect ) 433*cdf0e10cSrcweir { 434*cdf0e10cSrcweir // object asks to change the position 435*cdf0e10cSrcweir if ( m_xEmbedObj != null ) 436*cdf0e10cSrcweir { 437*cdf0e10cSrcweir try { 438*cdf0e10cSrcweir int nState = m_xEmbedObj.getCurrentState(); 439*cdf0e10cSrcweir // such a position change make sence only when object is 440*cdf0e10cSrcweir // either inplace or ui active 441*cdf0e10cSrcweir if ( nState == EmbedStates.EMBED_INPLACE_ACTIVE 442*cdf0e10cSrcweir || nState == EmbedStates.EMBED_UI_ACTIVE ) 443*cdf0e10cSrcweir { 444*cdf0e10cSrcweir XInplaceObject xInplObj = (XInplaceObject)UnoRuntime.queryInterface( XInplaceObject.class, m_xEmbedObj ); 445*cdf0e10cSrcweir if ( xInplObj != null ) 446*cdf0e10cSrcweir { 447*cdf0e10cSrcweir xInplObj.setObjectRects( aPosRect, aPosRect ); // show the whole object 448*cdf0e10cSrcweir if ( m_aBitmapPainter != null ) 449*cdf0e10cSrcweir m_aBitmapPainter.setRect( aPosRect ); 450*cdf0e10cSrcweir } 451*cdf0e10cSrcweir else 452*cdf0e10cSrcweir System.out.println( "Why object that does not support inplace activation behave like inplace object?!" ); 453*cdf0e10cSrcweir } 454*cdf0e10cSrcweir else 455*cdf0e10cSrcweir System.out.println( "The object is not active but asks to change visual area!" ); 456*cdf0e10cSrcweir } catch( Exception e ) 457*cdf0e10cSrcweir { 458*cdf0e10cSrcweir System.out.println( "Exception is thrown in onPosRectChange: " + e ); 459*cdf0e10cSrcweir } 460*cdf0e10cSrcweir } 461*cdf0e10cSrcweir else 462*cdf0e10cSrcweir System.out.println( "Who asks to change visual area?!!" ); 463*cdf0e10cSrcweir } 464*cdf0e10cSrcweir 465*cdf0e10cSrcweir // XJob 466*cdf0e10cSrcweir public Object execute( NamedValue[] pValues ) 467*cdf0e10cSrcweir { 468*cdf0e10cSrcweir for( int nInd = 0; nInd < m_aActionsList.size(); nInd++ ) 469*cdf0e10cSrcweir { 470*cdf0e10cSrcweir ActionObject aAction = ( ActionObject ) m_aActionsList.get( nInd ); 471*cdf0e10cSrcweir if ( aAction != null ) 472*cdf0e10cSrcweir { 473*cdf0e10cSrcweir if ( aAction.m_nID == DESTROY ) 474*cdf0e10cSrcweir { 475*cdf0e10cSrcweir // free all resources 476*cdf0e10cSrcweir clearObjectAndStorage(); 477*cdf0e10cSrcweir m_bDestroyed = true; 478*cdf0e10cSrcweir } 479*cdf0e10cSrcweir else if ( aAction.m_nID == ACTIVATE_OUTPLACE ) 480*cdf0e10cSrcweir { 481*cdf0e10cSrcweir // activate object if exists and not active 482*cdf0e10cSrcweir if ( m_xEmbedObj != null ) 483*cdf0e10cSrcweir { 484*cdf0e10cSrcweir try { 485*cdf0e10cSrcweir m_xEmbedObj.changeState( EmbedStates.EMBED_ACTIVE ); 486*cdf0e10cSrcweir } 487*cdf0e10cSrcweir catch( Exception ex ) 488*cdf0e10cSrcweir { 489*cdf0e10cSrcweir System.out.println( "Exception on mouse click" + ex ); 490*cdf0e10cSrcweir } 491*cdf0e10cSrcweir } 492*cdf0e10cSrcweir } 493*cdf0e10cSrcweir else if ( aAction.m_nID == NEW_DOCUMENT ) 494*cdf0e10cSrcweir { 495*cdf0e10cSrcweir // clear everything 496*cdf0e10cSrcweir clearObjectAndStorage(); 497*cdf0e10cSrcweir 498*cdf0e10cSrcweir repaint(); 499*cdf0e10cSrcweir } 500*cdf0e10cSrcweir else if ( aAction.m_nID == SAVE_AS ) 501*cdf0e10cSrcweir { 502*cdf0e10cSrcweir // open SaveAs dialog and store 503*cdf0e10cSrcweir 504*cdf0e10cSrcweir if ( m_xStorage != null && m_xEmbedObj != null ) 505*cdf0e10cSrcweir { 506*cdf0e10cSrcweir try { 507*cdf0e10cSrcweir /* 508*cdf0e10cSrcweir if ( m_bLinkObj ) 509*cdf0e10cSrcweir storeLinkAsFileURI( aFileURI ); 510*cdf0e10cSrcweir else 511*cdf0e10cSrcweir */ 512*cdf0e10cSrcweir saveObjectAsFileURI( aAction.m_sParam ); 513*cdf0e10cSrcweir } 514*cdf0e10cSrcweir catch( Exception ex ) 515*cdf0e10cSrcweir { 516*cdf0e10cSrcweir System.out.println( "Exception in SaveAsMenuItem: " + ex ); 517*cdf0e10cSrcweir } 518*cdf0e10cSrcweir } 519*cdf0e10cSrcweir } 520*cdf0e10cSrcweir else if ( aAction.m_nID == OPEN_FILE ) 521*cdf0e10cSrcweir { 522*cdf0e10cSrcweir // clear everything 523*cdf0e10cSrcweir clearObjectAndStorage(); 524*cdf0e10cSrcweir 525*cdf0e10cSrcweir // load from specified file 526*cdf0e10cSrcweir loadFileURI( aAction.m_sParam ); 527*cdf0e10cSrcweir 528*cdf0e10cSrcweir if ( m_xEmbedObj != null ) 529*cdf0e10cSrcweir { 530*cdf0e10cSrcweir try { 531*cdf0e10cSrcweir m_xEmbedObj.setClientSite( this ); 532*cdf0e10cSrcweir } 533*cdf0e10cSrcweir catch( Exception ex ) 534*cdf0e10cSrcweir { 535*cdf0e10cSrcweir System.out.println( "Exception in OpenFileMenuItem: " + ex ); 536*cdf0e10cSrcweir } 537*cdf0e10cSrcweir } 538*cdf0e10cSrcweir 539*cdf0e10cSrcweir generateNewImage(); 540*cdf0e10cSrcweir repaint(); 541*cdf0e10cSrcweir } 542*cdf0e10cSrcweir else if ( aAction.m_nID == SAVE ) 543*cdf0e10cSrcweir { 544*cdf0e10cSrcweir if ( m_xStorage != null && m_xEmbedObj != null ) 545*cdf0e10cSrcweir { 546*cdf0e10cSrcweir // if has persistance store there 547*cdf0e10cSrcweir // if not it is and error, SaveAs had to be used 548*cdf0e10cSrcweir 549*cdf0e10cSrcweir if ( m_bOwnFile ) 550*cdf0e10cSrcweir { 551*cdf0e10cSrcweir if ( m_xStorage != null ) 552*cdf0e10cSrcweir { 553*cdf0e10cSrcweir try { 554*cdf0e10cSrcweir saveObject(); 555*cdf0e10cSrcweir 556*cdf0e10cSrcweir if ( m_bLinkObj ) 557*cdf0e10cSrcweir storeLinkToStorage(); 558*cdf0e10cSrcweir 559*cdf0e10cSrcweir XTransactedObject xTransact = (XTransactedObject)UnoRuntime.queryInterface( XTransactedObject.class, 560*cdf0e10cSrcweir m_xStorage ); 561*cdf0e10cSrcweir if ( xTransact != null ) 562*cdf0e10cSrcweir xTransact.commit(); 563*cdf0e10cSrcweir } 564*cdf0e10cSrcweir catch( Exception ex ) 565*cdf0e10cSrcweir { 566*cdf0e10cSrcweir System.out.println( "Exception during save operation in SaveMenuItem:" + ex ); 567*cdf0e10cSrcweir } 568*cdf0e10cSrcweir } 569*cdf0e10cSrcweir else 570*cdf0e10cSrcweir { 571*cdf0e10cSrcweir System.out.println( "No storage for owned file!" ); 572*cdf0e10cSrcweir } 573*cdf0e10cSrcweir } 574*cdf0e10cSrcweir else 575*cdf0e10cSrcweir { 576*cdf0e10cSrcweir System.out.println( "No owned file!" ); 577*cdf0e10cSrcweir } 578*cdf0e10cSrcweir } 579*cdf0e10cSrcweir } 580*cdf0e10cSrcweir else if ( aAction.m_nID == NEW_OBJECT ) 581*cdf0e10cSrcweir { 582*cdf0e10cSrcweir // remove current object an init a new one 583*cdf0e10cSrcweir clearObjectAndStorage(); 584*cdf0e10cSrcweir 585*cdf0e10cSrcweir if ( aAction.m_sParam != null ) 586*cdf0e10cSrcweir { 587*cdf0e10cSrcweir m_xStorage = createTempStorage(); 588*cdf0e10cSrcweir 589*cdf0e10cSrcweir if ( m_xStorage != null ) 590*cdf0e10cSrcweir m_xEmbedObj = createEmbedObject( aAction.m_sParam ); 591*cdf0e10cSrcweir else 592*cdf0e10cSrcweir System.out.println( "Can't create temporary storage!" ); 593*cdf0e10cSrcweir 594*cdf0e10cSrcweir if ( m_xEmbedObj != null ) 595*cdf0e10cSrcweir { 596*cdf0e10cSrcweir try { 597*cdf0e10cSrcweir m_xEmbedObj.setClientSite( this ); 598*cdf0e10cSrcweir } 599*cdf0e10cSrcweir catch( Exception ex ) 600*cdf0e10cSrcweir { 601*cdf0e10cSrcweir System.out.println( "Exception in NewObjectMenuItem:" + ex ); 602*cdf0e10cSrcweir } 603*cdf0e10cSrcweir } 604*cdf0e10cSrcweir } 605*cdf0e10cSrcweir 606*cdf0e10cSrcweir generateNewImage(); 607*cdf0e10cSrcweir repaint(); 608*cdf0e10cSrcweir } 609*cdf0e10cSrcweir else if ( aAction.m_nID == OBJECT_FROM_FILE ) 610*cdf0e10cSrcweir { 611*cdf0e10cSrcweir // first remove current object 612*cdf0e10cSrcweir clearObjectAndStorage(); 613*cdf0e10cSrcweir 614*cdf0e10cSrcweir // create object from specified file 615*cdf0e10cSrcweir m_xStorage = createTempStorage(); 616*cdf0e10cSrcweir 617*cdf0e10cSrcweir if ( m_xStorage != null ) 618*cdf0e10cSrcweir m_xEmbedObj = loadEmbedObject( aAction.m_sParam ); 619*cdf0e10cSrcweir 620*cdf0e10cSrcweir if ( m_xEmbedObj != null ) 621*cdf0e10cSrcweir { 622*cdf0e10cSrcweir try { 623*cdf0e10cSrcweir m_xEmbedObj.setClientSite( this ); 624*cdf0e10cSrcweir } 625*cdf0e10cSrcweir catch( Exception ex ) 626*cdf0e10cSrcweir { 627*cdf0e10cSrcweir System.out.println( "Exception in LoadObjectMenuItem: " + ex ); 628*cdf0e10cSrcweir } 629*cdf0e10cSrcweir } 630*cdf0e10cSrcweir 631*cdf0e10cSrcweir generateNewImage(); 632*cdf0e10cSrcweir repaint(); 633*cdf0e10cSrcweir } 634*cdf0e10cSrcweir else if ( aAction.m_nID == LINK_FROM_FILE ) 635*cdf0e10cSrcweir { 636*cdf0e10cSrcweir // first remove current object 637*cdf0e10cSrcweir clearObjectAndStorage(); 638*cdf0e10cSrcweir 639*cdf0e10cSrcweir m_xStorage = createTempStorage(); 640*cdf0e10cSrcweir 641*cdf0e10cSrcweir // create object from specified file 642*cdf0e10cSrcweir m_xEmbedObj = createLinkObject( aAction.m_sParam ); 643*cdf0e10cSrcweir 644*cdf0e10cSrcweir if ( m_xEmbedObj != null ) 645*cdf0e10cSrcweir { 646*cdf0e10cSrcweir m_aLinkURI = aAction.m_sParam; 647*cdf0e10cSrcweir m_bLinkObj = true; 648*cdf0e10cSrcweir 649*cdf0e10cSrcweir try { 650*cdf0e10cSrcweir m_xEmbedObj.setClientSite( this ); 651*cdf0e10cSrcweir } 652*cdf0e10cSrcweir catch( Exception ex ) 653*cdf0e10cSrcweir { 654*cdf0e10cSrcweir System.out.println( "Exception in LinkObjectMenuItem:" + ex ); 655*cdf0e10cSrcweir } 656*cdf0e10cSrcweir } 657*cdf0e10cSrcweir 658*cdf0e10cSrcweir generateNewImage(); 659*cdf0e10cSrcweir repaint(); 660*cdf0e10cSrcweir } 661*cdf0e10cSrcweir else if ( aAction.m_nID == CONVERT_LINK_TO_OBJECT ) 662*cdf0e10cSrcweir { 663*cdf0e10cSrcweir if ( !m_bLinkObj ) 664*cdf0e10cSrcweir { 665*cdf0e10cSrcweir System.out.println( "The object is not a link!" ); 666*cdf0e10cSrcweir continue; 667*cdf0e10cSrcweir } 668*cdf0e10cSrcweir 669*cdf0e10cSrcweir if ( m_xEmbedObj != null ) 670*cdf0e10cSrcweir { 671*cdf0e10cSrcweir if ( m_xStorage != null ) 672*cdf0e10cSrcweir { 673*cdf0e10cSrcweir try { 674*cdf0e10cSrcweir XNameAccess xNameAccess = (XNameAccess)UnoRuntime.queryInterface( XNameAccess.class, 675*cdf0e10cSrcweir m_xStorage ); 676*cdf0e10cSrcweir if ( xNameAccess != null && xNameAccess.hasByName( "LinkName" ) ) 677*cdf0e10cSrcweir m_xStorage.removeElement( "LinkName" ); 678*cdf0e10cSrcweir 679*cdf0e10cSrcweir XLinkageSupport xLinkage = (XLinkageSupport)UnoRuntime.queryInterface( XLinkageSupport.class, 680*cdf0e10cSrcweir m_xEmbedObj ); 681*cdf0e10cSrcweir if ( xLinkage != null ) 682*cdf0e10cSrcweir { 683*cdf0e10cSrcweir xLinkage.breakLink( m_xStorage, "EmbedSub" ); 684*cdf0e10cSrcweir m_bLinkObj = false; 685*cdf0e10cSrcweir m_aLinkURI = null; 686*cdf0e10cSrcweir } 687*cdf0e10cSrcweir else 688*cdf0e10cSrcweir System.out.println( "No XLinkageSupport in ConvertLink... !" ); 689*cdf0e10cSrcweir } 690*cdf0e10cSrcweir catch( Exception e1 ) 691*cdf0e10cSrcweir { 692*cdf0e10cSrcweir System.out.println( "Exception in ConvertLinkToEmbed:try 1 :" + e1 ); 693*cdf0e10cSrcweir } 694*cdf0e10cSrcweir } 695*cdf0e10cSrcweir } 696*cdf0e10cSrcweir } 697*cdf0e10cSrcweir else if ( aAction.m_nID == ACTIVATE_INPLACE ) 698*cdf0e10cSrcweir { 699*cdf0e10cSrcweir // activate object 700*cdf0e10cSrcweir if ( m_xEmbedObj != null ) 701*cdf0e10cSrcweir { 702*cdf0e10cSrcweir // in general it is better to check acceptable states 703*cdf0e10cSrcweir try { 704*cdf0e10cSrcweir m_xEmbedObj.changeState( EmbedStates.EMBED_INPLACE_ACTIVE ); 705*cdf0e10cSrcweir } 706*cdf0e10cSrcweir catch( Exception ex ) 707*cdf0e10cSrcweir { 708*cdf0e10cSrcweir System.out.println( "Exception on inplace activation " + ex ); 709*cdf0e10cSrcweir } 710*cdf0e10cSrcweir } 711*cdf0e10cSrcweir } 712*cdf0e10cSrcweir else if ( aAction.m_nID == DEACTIVATE ) 713*cdf0e10cSrcweir { 714*cdf0e10cSrcweir // activate object 715*cdf0e10cSrcweir 716*cdf0e10cSrcweir if ( m_xEmbedObj != null ) 717*cdf0e10cSrcweir { 718*cdf0e10cSrcweir int nOldState = -1; 719*cdf0e10cSrcweir try { 720*cdf0e10cSrcweir nOldState = m_xEmbedObj.getCurrentState(); 721*cdf0e10cSrcweir } catch( Exception e ) 722*cdf0e10cSrcweir {} 723*cdf0e10cSrcweir 724*cdf0e10cSrcweir if ( nOldState == EmbedStates.EMBED_ACTIVE 725*cdf0e10cSrcweir || nOldState == EmbedStates.EMBED_INPLACE_ACTIVE 726*cdf0e10cSrcweir || nOldState == EmbedStates.EMBED_UI_ACTIVE ) 727*cdf0e10cSrcweir { 728*cdf0e10cSrcweir try { 729*cdf0e10cSrcweir m_xEmbedObj.changeState( EmbedStates.EMBED_RUNNING ); 730*cdf0e10cSrcweir } 731*cdf0e10cSrcweir catch( Exception ex ) 732*cdf0e10cSrcweir { 733*cdf0e10cSrcweir System.out.println( "Exception on inplace activation " + ex ); 734*cdf0e10cSrcweir } 735*cdf0e10cSrcweir } 736*cdf0e10cSrcweir else 737*cdf0e10cSrcweir { 738*cdf0e10cSrcweir System.out.println( "Deactivation of nonactive object!" ); 739*cdf0e10cSrcweir } 740*cdf0e10cSrcweir } 741*cdf0e10cSrcweir } 742*cdf0e10cSrcweir else 743*cdf0e10cSrcweir { 744*cdf0e10cSrcweir System.out.println( "Unknoun action is requested: " + aAction.m_nID + "\n" ); 745*cdf0e10cSrcweir } 746*cdf0e10cSrcweir } 747*cdf0e10cSrcweir } 748*cdf0e10cSrcweir 749*cdf0e10cSrcweir m_aActionsList.clear(); 750*cdf0e10cSrcweir 751*cdf0e10cSrcweir synchronized( m_oInHandlerLock ) 752*cdf0e10cSrcweir { 753*cdf0e10cSrcweir m_bInHandler = false; 754*cdf0e10cSrcweir } 755*cdf0e10cSrcweir 756*cdf0e10cSrcweir return Any.VOID; 757*cdf0e10cSrcweir } 758*cdf0e10cSrcweir 759*cdf0e10cSrcweir public void actionRegister( byte nActionID, String sParam ) 760*cdf0e10cSrcweir { 761*cdf0e10cSrcweir synchronized( m_oActionsNumberLock ) 762*cdf0e10cSrcweir { 763*cdf0e10cSrcweir int nSize = m_aActionsList.size(); 764*cdf0e10cSrcweir if ( nSize < 199 ) 765*cdf0e10cSrcweir { 766*cdf0e10cSrcweir if ( nSize == 0 ) 767*cdf0e10cSrcweir m_aActionsList.add( new ActionObject( nActionID, sParam ) ); 768*cdf0e10cSrcweir else 769*cdf0e10cSrcweir { 770*cdf0e10cSrcweir ActionObject aAction = ( ActionObject ) m_aActionsList.get( nSize - 1 ); 771*cdf0e10cSrcweir if ( aAction != null && aAction.m_nID != DESTROY ) 772*cdf0e10cSrcweir m_aActionsList.add( new ActionObject( nActionID, sParam ) ); 773*cdf0e10cSrcweir } 774*cdf0e10cSrcweir } 775*cdf0e10cSrcweir } 776*cdf0e10cSrcweir } 777*cdf0e10cSrcweir 778*cdf0e10cSrcweir public void SaveAsOperation() 779*cdf0e10cSrcweir { 780*cdf0e10cSrcweir if ( m_xStorage != null && m_xEmbedObj != null ) 781*cdf0e10cSrcweir { 782*cdf0e10cSrcweir FileDialog aFileDialog = new FileDialog( m_aFrame, "SaveAs", FileDialog.SAVE ); 783*cdf0e10cSrcweir aFileDialog.show(); 784*cdf0e10cSrcweir if ( aFileDialog.getFile() != null ) 785*cdf0e10cSrcweir { 786*cdf0e10cSrcweir String aFileName = aFileDialog.getDirectory() + aFileDialog.getFile(); 787*cdf0e10cSrcweir File aFile = new File( aFileName ); 788*cdf0e10cSrcweir if ( aFile != null ) 789*cdf0e10cSrcweir { 790*cdf0e10cSrcweir // create object from specified file 791*cdf0e10cSrcweir String aFileURI = getValidURL( aFile.toURI().toASCIIString() ); 792*cdf0e10cSrcweir actionRegister( SAVE_AS, aFileURI ); 793*cdf0e10cSrcweir } 794*cdf0e10cSrcweir } 795*cdf0e10cSrcweir } 796*cdf0e10cSrcweir else 797*cdf0e10cSrcweir JOptionPane.showMessageDialog( m_aFrame, "No document is embedded!", "Error:", JOptionPane.ERROR_MESSAGE ); 798*cdf0e10cSrcweir 799*cdf0e10cSrcweir } 800*cdf0e10cSrcweir 801*cdf0e10cSrcweir public void destroy() 802*cdf0e10cSrcweir { 803*cdf0e10cSrcweir // redirect the call through the timer and call super.destroy(); 804*cdf0e10cSrcweir actionRegister( DESTROY, null ); 805*cdf0e10cSrcweir 806*cdf0e10cSrcweir for ( int i = 0; i < 3 && !m_bDestroyed; i++ ) 807*cdf0e10cSrcweir { 808*cdf0e10cSrcweir try { 809*cdf0e10cSrcweir Thread.sleep( 200 ); 810*cdf0e10cSrcweir } catch ( Exception e ) 811*cdf0e10cSrcweir {} 812*cdf0e10cSrcweir } 813*cdf0e10cSrcweir 814*cdf0e10cSrcweir if ( !m_bDestroyed ) 815*cdf0e10cSrcweir System.out.println( "The object application can not exit correctly!" ); 816*cdf0e10cSrcweir 817*cdf0e10cSrcweir m_aTimer.stop(); 818*cdf0e10cSrcweir 819*cdf0e10cSrcweir super.destroy(); 820*cdf0e10cSrcweir } 821*cdf0e10cSrcweir 822*cdf0e10cSrcweir public void update( Graphics g ) 823*cdf0e10cSrcweir { 824*cdf0e10cSrcweir paint( g ); 825*cdf0e10cSrcweir } 826*cdf0e10cSrcweir 827*cdf0e10cSrcweir public void paint( Graphics g ) 828*cdf0e10cSrcweir { 829*cdf0e10cSrcweir super.paint( g ); 830*cdf0e10cSrcweir 831*cdf0e10cSrcweir // m_aNativeView.paint( g ); 832*cdf0e10cSrcweir 833*cdf0e10cSrcweir createVclWindow(); 834*cdf0e10cSrcweir } 835*cdf0e10cSrcweir 836*cdf0e10cSrcweir public void createVclWindow() 837*cdf0e10cSrcweir { 838*cdf0e10cSrcweir synchronized( m_oImageLock ) 839*cdf0e10cSrcweir { 840*cdf0e10cSrcweir if ( m_xVCLWindow == null && m_xServiceFactory != null && m_xEmbedObj != null && m_xBitmap != null ) 841*cdf0e10cSrcweir { 842*cdf0e10cSrcweir java.awt.Rectangle aBounds = getBounds(); 843*cdf0e10cSrcweir m_xVCLWindow = WindowHelper.createWindow( m_xServiceFactory, m_aNativeView, aBounds ); 844*cdf0e10cSrcweir m_xVCLWindow.setVisible( true ); 845*cdf0e10cSrcweir 846*cdf0e10cSrcweir com.sun.star.awt.Size aBitmapSize = new com.sun.star.awt.Size( 200, 100 ); 847*cdf0e10cSrcweir 848*cdf0e10cSrcweir XVisualObject xVisObj = (XVisualObject)UnoRuntime.queryInterface( XVisualObject.class, m_xEmbedObj ); 849*cdf0e10cSrcweir try { 850*cdf0e10cSrcweir com.sun.star.awt.Size aVisSize = xVisObj.getVisAreaSize( Aspects.MSASPECT_CONTENT ); 851*cdf0e10cSrcweir m_nXPixelSize = aVisSize.Width / aBitmapSize.Width; 852*cdf0e10cSrcweir m_nYPixelSize = aVisSize.Height / aBitmapSize.Height; 853*cdf0e10cSrcweir } 854*cdf0e10cSrcweir catch( Exception e ) 855*cdf0e10cSrcweir { 856*cdf0e10cSrcweir } 857*cdf0e10cSrcweir 858*cdf0e10cSrcweir if ( m_xBitmap != null ) 859*cdf0e10cSrcweir aBitmapSize = m_xBitmap.getSize(); 860*cdf0e10cSrcweir 861*cdf0e10cSrcweir System.out.println( "The visual area is Width = " + aBitmapSize.Width + "; Height = " + aBitmapSize.Height ); 862*cdf0e10cSrcweir 863*cdf0e10cSrcweir com.sun.star.awt.Rectangle aRect = new com.sun.star.awt.Rectangle( 864*cdf0e10cSrcweir 10, 865*cdf0e10cSrcweir 10, 866*cdf0e10cSrcweir Math.min( (int)aBounds.getWidth() - 20, aBitmapSize.Width ), 867*cdf0e10cSrcweir Math.min( (int)aBounds.getHeight() - 20, aBitmapSize.Height ) ); 868*cdf0e10cSrcweir 869*cdf0e10cSrcweir m_aBitmapPainter = new BitmapPainter( m_xMainThreadExecutor, m_xVCLWindow, m_xBitmap, aRect ); 870*cdf0e10cSrcweir } 871*cdf0e10cSrcweir } 872*cdf0e10cSrcweir } 873*cdf0e10cSrcweir 874*cdf0e10cSrcweir public void generateNewImage() 875*cdf0e10cSrcweir { 876*cdf0e10cSrcweir if ( m_xEmbedObj != null ) 877*cdf0e10cSrcweir { 878*cdf0e10cSrcweir try { 879*cdf0e10cSrcweir int nOldState = m_xEmbedObj.getCurrentState(); 880*cdf0e10cSrcweir int nState = nOldState; 881*cdf0e10cSrcweir if ( nOldState == EmbedStates.EMBED_LOADED ) 882*cdf0e10cSrcweir { 883*cdf0e10cSrcweir m_xEmbedObj.changeState( EmbedStates.EMBED_RUNNING ); 884*cdf0e10cSrcweir nState = EmbedStates.EMBED_RUNNING; 885*cdf0e10cSrcweir } 886*cdf0e10cSrcweir 887*cdf0e10cSrcweir if ( nState == EmbedStates.EMBED_UI_ACTIVE || nState == EmbedStates.EMBED_INPLACE_ACTIVE 888*cdf0e10cSrcweir || nState == EmbedStates.EMBED_ACTIVE || nState == EmbedStates.EMBED_RUNNING ) 889*cdf0e10cSrcweir { 890*cdf0e10cSrcweir XComponentSupplier xCompProv = (XComponentSupplier)UnoRuntime.queryInterface( 891*cdf0e10cSrcweir XComponentSupplier.class, 892*cdf0e10cSrcweir m_xEmbedObj ); 893*cdf0e10cSrcweir if ( xCompProv != null ) 894*cdf0e10cSrcweir { 895*cdf0e10cSrcweir XCloseable xCloseable = xCompProv.getComponent(); 896*cdf0e10cSrcweir XTransferable xTransfer = (XTransferable)UnoRuntime.queryInterface( 897*cdf0e10cSrcweir XTransferable.class, 898*cdf0e10cSrcweir xCloseable ); 899*cdf0e10cSrcweir if ( xTransfer != null ) 900*cdf0e10cSrcweir { 901*cdf0e10cSrcweir DataFlavor aFlavor = new DataFlavor(); 902*cdf0e10cSrcweir aFlavor.MimeType = "application/x-openoffice;windows_formatname=\"Bitmap\""; 903*cdf0e10cSrcweir aFlavor.HumanPresentableName = "Bitmap"; 904*cdf0e10cSrcweir aFlavor.DataType = new Type( byte[].class ); 905*cdf0e10cSrcweir 906*cdf0e10cSrcweir Object aAny = xTransfer.getTransferData( aFlavor ); 907*cdf0e10cSrcweir if ( aAny != null && AnyConverter.isArray( aAny ) ) 908*cdf0e10cSrcweir { 909*cdf0e10cSrcweir synchronized( m_oImageLock ) 910*cdf0e10cSrcweir { 911*cdf0e10cSrcweir m_xBitmap = WindowHelper.getVCLBitmapFromBytes( m_xServiceFactory, aAny ); 912*cdf0e10cSrcweir if ( m_aBitmapPainter != null ) 913*cdf0e10cSrcweir { 914*cdf0e10cSrcweir m_aBitmapPainter.setBitmap( m_xBitmap ); 915*cdf0e10cSrcweir 916*cdf0e10cSrcweir if ( m_xBitmap != null ) 917*cdf0e10cSrcweir { 918*cdf0e10cSrcweir try { 919*cdf0e10cSrcweir com.sun.star.awt.Size aBitmapSize = m_xBitmap.getSize(); 920*cdf0e10cSrcweir com.sun.star.awt.Size aVisSize = new com.sun.star.awt.Size( 921*cdf0e10cSrcweir (int)( aBitmapSize.Width * m_nXScaling ), 922*cdf0e10cSrcweir (int)( aBitmapSize.Height * m_nYScaling ) ); 923*cdf0e10cSrcweir m_aBitmapPainter.setSize( aVisSize ); 924*cdf0e10cSrcweir } 925*cdf0e10cSrcweir catch( Exception e ) 926*cdf0e10cSrcweir { 927*cdf0e10cSrcweir } 928*cdf0e10cSrcweir } 929*cdf0e10cSrcweir } 930*cdf0e10cSrcweir } 931*cdf0e10cSrcweir } 932*cdf0e10cSrcweir } 933*cdf0e10cSrcweir else 934*cdf0e10cSrcweir System.out.println( "paint() : can not get XTransferable for the component!\n" ); 935*cdf0e10cSrcweir } 936*cdf0e10cSrcweir else 937*cdf0e10cSrcweir System.out.println( "paint() : XComponentSupplier is not implemented!\n" ); 938*cdf0e10cSrcweir } 939*cdf0e10cSrcweir } 940*cdf0e10cSrcweir catch( com.sun.star.uno.Exception e ) 941*cdf0e10cSrcweir { 942*cdf0e10cSrcweir // dialogs should not be used in paint() 943*cdf0e10cSrcweir System.out.println( "Exception in paint(): " + e ); 944*cdf0e10cSrcweir } 945*cdf0e10cSrcweir } 946*cdf0e10cSrcweir } 947*cdf0e10cSrcweir 948*cdf0e10cSrcweir public void mouseClicked( MouseEvent e ) 949*cdf0e10cSrcweir { 950*cdf0e10cSrcweir if( e.getModifiers() == InputEvent.BUTTON1_MASK ) 951*cdf0e10cSrcweir { 952*cdf0e10cSrcweir actionRegister( ACTIVATE_OUTPLACE, null ); 953*cdf0e10cSrcweir } 954*cdf0e10cSrcweir } 955*cdf0e10cSrcweir 956*cdf0e10cSrcweir public void mousePressed( MouseEvent e ){}; 957*cdf0e10cSrcweir public void mouseEntered( MouseEvent e ){}; 958*cdf0e10cSrcweir public void mouseExited( MouseEvent e ){}; 959*cdf0e10cSrcweir public void mouseReleased( MouseEvent e ){}; 960*cdf0e10cSrcweir 961*cdf0e10cSrcweir // classes 962*cdf0e10cSrcweir class NewMenuItem extends MenuItem implements ActionListener // Menu New 963*cdf0e10cSrcweir { 964*cdf0e10cSrcweir public NewMenuItem() 965*cdf0e10cSrcweir { 966*cdf0e10cSrcweir super( "New", new MenuShortcut( KeyEvent.VK_A )); 967*cdf0e10cSrcweir addActionListener( this ); 968*cdf0e10cSrcweir } 969*cdf0e10cSrcweir 970*cdf0e10cSrcweir public void actionPerformed( ActionEvent e ) 971*cdf0e10cSrcweir { 972*cdf0e10cSrcweir actionRegister( NEW_DOCUMENT, null ); 973*cdf0e10cSrcweir } 974*cdf0e10cSrcweir } 975*cdf0e10cSrcweir 976*cdf0e10cSrcweir class SaveAsMenuItem extends MenuItem implements ActionListener // Menu SaveAs... 977*cdf0e10cSrcweir { 978*cdf0e10cSrcweir public SaveAsMenuItem() 979*cdf0e10cSrcweir { 980*cdf0e10cSrcweir super( "SaveAs..." ); 981*cdf0e10cSrcweir addActionListener( this ); 982*cdf0e10cSrcweir } 983*cdf0e10cSrcweir 984*cdf0e10cSrcweir public void actionPerformed( ActionEvent e ) 985*cdf0e10cSrcweir { 986*cdf0e10cSrcweir // open SaveAs dialog and store 987*cdf0e10cSrcweir 988*cdf0e10cSrcweir SaveAsOperation(); 989*cdf0e10cSrcweir } 990*cdf0e10cSrcweir } 991*cdf0e10cSrcweir 992*cdf0e10cSrcweir class OpenFileMenuItem extends MenuItem implements ActionListener // Menu Open 993*cdf0e10cSrcweir { 994*cdf0e10cSrcweir public OpenFileMenuItem() 995*cdf0e10cSrcweir { 996*cdf0e10cSrcweir super( "Open", new MenuShortcut( KeyEvent.VK_C )); 997*cdf0e10cSrcweir addActionListener( this ); 998*cdf0e10cSrcweir } 999*cdf0e10cSrcweir 1000*cdf0e10cSrcweir public void actionPerformed( ActionEvent e ) 1001*cdf0e10cSrcweir { 1002*cdf0e10cSrcweir // open OpenFile dialog and load doc 1003*cdf0e10cSrcweir FileDialog aFileDialog = new FileDialog( m_aFrame, "Open" ); 1004*cdf0e10cSrcweir aFileDialog.show(); 1005*cdf0e10cSrcweir if ( aFileDialog.getFile() != null ) 1006*cdf0e10cSrcweir { 1007*cdf0e10cSrcweir String aFileName = aFileDialog.getDirectory() + aFileDialog.getFile(); 1008*cdf0e10cSrcweir File aFile = new File( aFileName ); 1009*cdf0e10cSrcweir if ( aFile != null ) 1010*cdf0e10cSrcweir { 1011*cdf0e10cSrcweir // create object from specified file 1012*cdf0e10cSrcweir String aFileURI = getValidURL( aFile.toURI().toASCIIString() ); 1013*cdf0e10cSrcweir actionRegister( OPEN_FILE, aFileURI ); 1014*cdf0e10cSrcweir } 1015*cdf0e10cSrcweir } 1016*cdf0e10cSrcweir } 1017*cdf0e10cSrcweir } 1018*cdf0e10cSrcweir 1019*cdf0e10cSrcweir class SaveMenuItem extends MenuItem implements ActionListener // Menu Save 1020*cdf0e10cSrcweir { 1021*cdf0e10cSrcweir public SaveMenuItem() 1022*cdf0e10cSrcweir { 1023*cdf0e10cSrcweir super( "Save", new MenuShortcut( KeyEvent.VK_D )); 1024*cdf0e10cSrcweir addActionListener( this ); 1025*cdf0e10cSrcweir } 1026*cdf0e10cSrcweir 1027*cdf0e10cSrcweir public void actionPerformed( ActionEvent e ) 1028*cdf0e10cSrcweir { 1029*cdf0e10cSrcweir // if has persistance store there 1030*cdf0e10cSrcweir // if not open SaveAs dialog and store 1031*cdf0e10cSrcweir if ( m_xStorage != null && m_xEmbedObj != null ) 1032*cdf0e10cSrcweir { 1033*cdf0e10cSrcweir if ( m_bOwnFile ) 1034*cdf0e10cSrcweir { 1035*cdf0e10cSrcweir if ( m_xStorage == null ) 1036*cdf0e10cSrcweir { 1037*cdf0e10cSrcweir JOptionPane.showMessageDialog( m_aFrame, 1038*cdf0e10cSrcweir "No storage for oned file!", 1039*cdf0e10cSrcweir "Error:", 1040*cdf0e10cSrcweir JOptionPane.ERROR_MESSAGE ); 1041*cdf0e10cSrcweir 1042*cdf0e10cSrcweir return; 1043*cdf0e10cSrcweir } 1044*cdf0e10cSrcweir 1045*cdf0e10cSrcweir actionRegister( SAVE, null ); 1046*cdf0e10cSrcweir } 1047*cdf0e10cSrcweir else 1048*cdf0e10cSrcweir { 1049*cdf0e10cSrcweir SaveAsOperation(); 1050*cdf0e10cSrcweir } 1051*cdf0e10cSrcweir } 1052*cdf0e10cSrcweir else 1053*cdf0e10cSrcweir JOptionPane.showMessageDialog( m_aFrame, "No document is embedded!", "Error:", JOptionPane.ERROR_MESSAGE ); 1054*cdf0e10cSrcweir } 1055*cdf0e10cSrcweir } 1056*cdf0e10cSrcweir 1057*cdf0e10cSrcweir class NewObjectMenuItem extends MenuItem implements ActionListener // Menu NewObject 1058*cdf0e10cSrcweir { 1059*cdf0e10cSrcweir public NewObjectMenuItem() 1060*cdf0e10cSrcweir { 1061*cdf0e10cSrcweir super( "Create", new MenuShortcut( KeyEvent.VK_N )); 1062*cdf0e10cSrcweir addActionListener( this ); 1063*cdf0e10cSrcweir } 1064*cdf0e10cSrcweir 1065*cdf0e10cSrcweir public void actionPerformed( ActionEvent e ) 1066*cdf0e10cSrcweir { 1067*cdf0e10cSrcweir Object[] possibleValues = { "com.sun.star.comp.Writer.TextDocument", 1068*cdf0e10cSrcweir "com.sun.star.comp.Writer.GlobalDocument", 1069*cdf0e10cSrcweir "com.sun.star.comp.Writer.WebDocument", 1070*cdf0e10cSrcweir "com.sun.star.comp.Calc.SpreadsheetDocument", 1071*cdf0e10cSrcweir "com.sun.star.comp.Draw.PresentationDocument", 1072*cdf0e10cSrcweir "com.sun.star.comp.Draw.DrawingDocument", 1073*cdf0e10cSrcweir "com.sun.star.comp.Math.FormulaDocument", 1074*cdf0e10cSrcweir "BitmapImage" }; 1075*cdf0e10cSrcweir 1076*cdf0e10cSrcweir String selectedValue = (String)JOptionPane.showInputDialog( null, "DocumentType", "Select", 1077*cdf0e10cSrcweir JOptionPane.INFORMATION_MESSAGE, null, 1078*cdf0e10cSrcweir possibleValues, possibleValues[0] ); 1079*cdf0e10cSrcweir 1080*cdf0e10cSrcweir actionRegister( NEW_OBJECT, selectedValue ); 1081*cdf0e10cSrcweir } 1082*cdf0e10cSrcweir } 1083*cdf0e10cSrcweir 1084*cdf0e10cSrcweir class LoadObjectMenuItem extends MenuItem implements ActionListener // Menu LoadObject 1085*cdf0e10cSrcweir { 1086*cdf0e10cSrcweir public LoadObjectMenuItem() 1087*cdf0e10cSrcweir { 1088*cdf0e10cSrcweir super( "Load from file", new MenuShortcut( KeyEvent.VK_L )); 1089*cdf0e10cSrcweir addActionListener( this ); 1090*cdf0e10cSrcweir } 1091*cdf0e10cSrcweir 1092*cdf0e10cSrcweir public void actionPerformed( ActionEvent e ) 1093*cdf0e10cSrcweir { 1094*cdf0e10cSrcweir // open OpenFile dialog and load doc 1095*cdf0e10cSrcweir FileDialog aFileDialog = new FileDialog( m_aFrame, "Select sources to use for object init" ); 1096*cdf0e10cSrcweir aFileDialog.show(); 1097*cdf0e10cSrcweir if ( aFileDialog.getFile() != null ) 1098*cdf0e10cSrcweir { 1099*cdf0e10cSrcweir String aFileName = aFileDialog.getDirectory() + aFileDialog.getFile(); 1100*cdf0e10cSrcweir File aFile = new File( aFileName ); 1101*cdf0e10cSrcweir if ( aFile != null ) 1102*cdf0e10cSrcweir { 1103*cdf0e10cSrcweir // create object from specified file 1104*cdf0e10cSrcweir String aFileURI = getValidURL( aFile.toURI().toASCIIString() ); 1105*cdf0e10cSrcweir actionRegister( OBJECT_FROM_FILE, aFileURI ); 1106*cdf0e10cSrcweir } 1107*cdf0e10cSrcweir } 1108*cdf0e10cSrcweir } 1109*cdf0e10cSrcweir } 1110*cdf0e10cSrcweir 1111*cdf0e10cSrcweir class LinkObjectMenuItem extends MenuItem implements ActionListener // Menu LinkObject 1112*cdf0e10cSrcweir { 1113*cdf0e10cSrcweir public LinkObjectMenuItem() 1114*cdf0e10cSrcweir { 1115*cdf0e10cSrcweir super( "Create link", new MenuShortcut( KeyEvent.VK_M )); 1116*cdf0e10cSrcweir addActionListener( this ); 1117*cdf0e10cSrcweir } 1118*cdf0e10cSrcweir 1119*cdf0e10cSrcweir public void actionPerformed( ActionEvent e ) 1120*cdf0e10cSrcweir { 1121*cdf0e10cSrcweir // open OpenFile dialog and load doc 1122*cdf0e10cSrcweir FileDialog aFileDialog = new FileDialog( m_aFrame, "Select sources to use for object init" ); 1123*cdf0e10cSrcweir aFileDialog.show(); 1124*cdf0e10cSrcweir if ( aFileDialog.getFile() != null ) 1125*cdf0e10cSrcweir { 1126*cdf0e10cSrcweir String aFileName = aFileDialog.getDirectory() + aFileDialog.getFile(); 1127*cdf0e10cSrcweir File aFile = new File( aFileName ); 1128*cdf0e10cSrcweir if ( aFile != null ) 1129*cdf0e10cSrcweir { 1130*cdf0e10cSrcweir // create object from specified file 1131*cdf0e10cSrcweir String aFileURI = getValidURL( aFile.toURI().toASCIIString() ); 1132*cdf0e10cSrcweir actionRegister( LINK_FROM_FILE, aFileURI ); 1133*cdf0e10cSrcweir } 1134*cdf0e10cSrcweir } 1135*cdf0e10cSrcweir } 1136*cdf0e10cSrcweir } 1137*cdf0e10cSrcweir 1138*cdf0e10cSrcweir class ConvertLinkToEmbedMenuItem extends MenuItem implements ActionListener // Menu LinkObject 1139*cdf0e10cSrcweir { 1140*cdf0e10cSrcweir public ConvertLinkToEmbedMenuItem() 1141*cdf0e10cSrcweir { 1142*cdf0e10cSrcweir super( "Convert link to embed", new MenuShortcut( KeyEvent.VK_M )); 1143*cdf0e10cSrcweir addActionListener( this ); 1144*cdf0e10cSrcweir } 1145*cdf0e10cSrcweir 1146*cdf0e10cSrcweir public void actionPerformed( ActionEvent e ) 1147*cdf0e10cSrcweir { 1148*cdf0e10cSrcweir actionRegister( CONVERT_LINK_TO_OBJECT, null ); 1149*cdf0e10cSrcweir } 1150*cdf0e10cSrcweir } 1151*cdf0e10cSrcweir 1152*cdf0e10cSrcweir class ActivateOutplaceMenuItem extends MenuItem implements ActionListener // Menu ActiveteOutplace 1153*cdf0e10cSrcweir { 1154*cdf0e10cSrcweir public ActivateOutplaceMenuItem() 1155*cdf0e10cSrcweir { 1156*cdf0e10cSrcweir super( "Activate outplace", new MenuShortcut( KeyEvent.VK_A )); 1157*cdf0e10cSrcweir addActionListener( this ); 1158*cdf0e10cSrcweir } 1159*cdf0e10cSrcweir 1160*cdf0e10cSrcweir public void actionPerformed( ActionEvent e ) 1161*cdf0e10cSrcweir { 1162*cdf0e10cSrcweir actionRegister( ACTIVATE_OUTPLACE, null ); 1163*cdf0e10cSrcweir } 1164*cdf0e10cSrcweir } 1165*cdf0e10cSrcweir 1166*cdf0e10cSrcweir class ActivateInplaceMenuItem extends MenuItem implements ActionListener // Menu ActivateInplace 1167*cdf0e10cSrcweir { 1168*cdf0e10cSrcweir public ActivateInplaceMenuItem() 1169*cdf0e10cSrcweir { 1170*cdf0e10cSrcweir super( "Activate inplace", new MenuShortcut( KeyEvent.VK_I )); 1171*cdf0e10cSrcweir addActionListener( this ); 1172*cdf0e10cSrcweir } 1173*cdf0e10cSrcweir 1174*cdf0e10cSrcweir public void actionPerformed( ActionEvent e ) 1175*cdf0e10cSrcweir { 1176*cdf0e10cSrcweir actionRegister( ACTIVATE_INPLACE, null ); 1177*cdf0e10cSrcweir } 1178*cdf0e10cSrcweir } 1179*cdf0e10cSrcweir 1180*cdf0e10cSrcweir class DeactivateMenuItem extends MenuItem implements ActionListener // Menu Deactivate 1181*cdf0e10cSrcweir { 1182*cdf0e10cSrcweir public DeactivateMenuItem() 1183*cdf0e10cSrcweir { 1184*cdf0e10cSrcweir super( "Deactivate", new MenuShortcut( KeyEvent.VK_D )); 1185*cdf0e10cSrcweir addActionListener( this ); 1186*cdf0e10cSrcweir } 1187*cdf0e10cSrcweir 1188*cdf0e10cSrcweir public void actionPerformed( ActionEvent e ) 1189*cdf0e10cSrcweir { 1190*cdf0e10cSrcweir actionRegister( DEACTIVATE, null ); 1191*cdf0e10cSrcweir } 1192*cdf0e10cSrcweir } 1193*cdf0e10cSrcweir 1194*cdf0e10cSrcweir // Helper methods 1195*cdf0e10cSrcweir public XEmbeddedObject createEmbedObject( String aServiceName ) 1196*cdf0e10cSrcweir { 1197*cdf0e10cSrcweir XEmbeddedObject xEmbObj = null; 1198*cdf0e10cSrcweir byte[] pClassID = new byte[16]; 1199*cdf0e10cSrcweir 1200*cdf0e10cSrcweir if ( aServiceName.equals( "com.sun.star.comp.Writer.TextDocument" ) ) 1201*cdf0e10cSrcweir { 1202*cdf0e10cSrcweir int[] pTempClassID = { 0x8B, 0xC6, 0xB1, 0x65, 0xB1, 0xB2, 0x4E, 0xDD, 1203*cdf0e10cSrcweir 0xAA, 0x47, 0xDA, 0xE2, 0xEE, 0x68, 0x9D, 0xD6 }; 1204*cdf0e10cSrcweir for ( int ind = 0; ind < 16; ind++ ) 1205*cdf0e10cSrcweir pClassID[ind] = (byte)pTempClassID[ind]; 1206*cdf0e10cSrcweir } 1207*cdf0e10cSrcweir else if ( aServiceName.equals( "com.sun.star.comp.Writer.GlobalDocument" ) ) 1208*cdf0e10cSrcweir { 1209*cdf0e10cSrcweir int[] pTempClassID = { 0xB2, 0x1A, 0x0A, 0x7C, 0xE4, 0x03, 0x41, 0xFE, 1210*cdf0e10cSrcweir 0x95, 0x62, 0xBD, 0x13, 0xEA, 0x6F, 0x15, 0xA0 }; 1211*cdf0e10cSrcweir for ( int ind = 0; ind < 16; ind++ ) 1212*cdf0e10cSrcweir pClassID[ind] = (byte)pTempClassID[ind]; 1213*cdf0e10cSrcweir } 1214*cdf0e10cSrcweir else if ( aServiceName.equals( "com.sun.star.comp.Writer.WebDocument" ) ) 1215*cdf0e10cSrcweir { 1216*cdf0e10cSrcweir int[] pTempClassID = { 0xA8, 0xBB, 0xA6, 0x0C, 0x7C, 0x60, 0x45, 0x50, 1217*cdf0e10cSrcweir 0x91, 0xCE, 0x39, 0xC3, 0x90, 0x3F, 0xAC, 0x5E }; 1218*cdf0e10cSrcweir for ( int ind = 0; ind < 16; ind++ ) 1219*cdf0e10cSrcweir pClassID[ind] = (byte)pTempClassID[ind]; 1220*cdf0e10cSrcweir } 1221*cdf0e10cSrcweir else if ( aServiceName.equals( "com.sun.star.comp.Calc.SpreadsheetDocument" ) ) 1222*cdf0e10cSrcweir { 1223*cdf0e10cSrcweir int[] pTempClassID = { 0x47, 0xBB, 0xB4, 0xCB, 0xCE, 0x4C, 0x4E, 0x80, 1224*cdf0e10cSrcweir 0xA5, 0x91, 0x42, 0xD9, 0xAE, 0x74, 0x95, 0x0F }; 1225*cdf0e10cSrcweir for ( int ind = 0; ind < 16; ind++ ) 1226*cdf0e10cSrcweir pClassID[ind] = (byte)pTempClassID[ind]; 1227*cdf0e10cSrcweir } 1228*cdf0e10cSrcweir else if ( aServiceName.equals( "com.sun.star.comp.Draw.PresentationDocument" ) ) 1229*cdf0e10cSrcweir { 1230*cdf0e10cSrcweir int[] pTempClassID = { 0x91, 0x76, 0xE4, 0x8A, 0x63, 0x7A, 0x4D, 0x1F, 1231*cdf0e10cSrcweir 0x80, 0x3B, 0x99, 0xD9, 0xBF, 0xAC, 0x10, 0x47 }; 1232*cdf0e10cSrcweir for ( int ind = 0; ind < 16; ind++ ) 1233*cdf0e10cSrcweir pClassID[ind] = (byte)pTempClassID[ind]; 1234*cdf0e10cSrcweir } 1235*cdf0e10cSrcweir else if ( aServiceName.equals( "com.sun.star.comp.Draw.DrawingDocument" ) ) 1236*cdf0e10cSrcweir { 1237*cdf0e10cSrcweir int[] pTempClassID = { 0x4B, 0xAB, 0x89, 0x70, 0x8A, 0x3B, 0x45, 0xB3, 1238*cdf0e10cSrcweir 0x99, 0x1C, 0xCB, 0xEE, 0xAC, 0x6B, 0xD5, 0xE3 }; 1239*cdf0e10cSrcweir for ( int ind = 0; ind < 16; ind++ ) 1240*cdf0e10cSrcweir pClassID[ind] = (byte)pTempClassID[ind]; 1241*cdf0e10cSrcweir } 1242*cdf0e10cSrcweir else if ( aServiceName.equals( "com.sun.star.comp.Math.FormulaDocument" ) ) 1243*cdf0e10cSrcweir { 1244*cdf0e10cSrcweir int[] pTempClassID = { 0x07, 0x8B, 0x7A, 0xBA, 0x54, 0xFC, 0x45, 0x7F, 1245*cdf0e10cSrcweir 0x85, 0x51, 0x61, 0x47, 0xE7, 0x76, 0xA9, 0x97 }; 1246*cdf0e10cSrcweir for ( int ind = 0; ind < 16; ind++ ) 1247*cdf0e10cSrcweir pClassID[ind] = (byte)pTempClassID[ind]; 1248*cdf0e10cSrcweir } 1249*cdf0e10cSrcweir else if ( aServiceName.equals( "BitmapImage" ) ) 1250*cdf0e10cSrcweir { 1251*cdf0e10cSrcweir int[] pTempClassID = { 0xD3, 0xE3, 0x4B, 0x21, 0x9D, 0x75, 0x10, 0x1A, 1252*cdf0e10cSrcweir 0x8C, 0x3D, 0x00, 0xAA, 0x00, 0x1A, 0x16, 0x52 }; 1253*cdf0e10cSrcweir for ( int ind = 0; ind < 16; ind++ ) 1254*cdf0e10cSrcweir pClassID[ind] = (byte)pTempClassID[ind]; 1255*cdf0e10cSrcweir } 1256*cdf0e10cSrcweir 1257*cdf0e10cSrcweir if ( pClassID != null ) 1258*cdf0e10cSrcweir { 1259*cdf0e10cSrcweir // create embedded object based on the class ID 1260*cdf0e10cSrcweir try { 1261*cdf0e10cSrcweir Object oEmbedCreator = m_xServiceFactory.createInstance( "com.sun.star.embed.EmbeddedObjectCreator" ); 1262*cdf0e10cSrcweir XEmbedObjectCreator xEmbedCreator = (XEmbedObjectCreator)UnoRuntime.queryInterface( 1263*cdf0e10cSrcweir XEmbedObjectCreator.class, 1264*cdf0e10cSrcweir oEmbedCreator ); 1265*cdf0e10cSrcweir if ( xEmbedCreator != null ) 1266*cdf0e10cSrcweir { 1267*cdf0e10cSrcweir Object oEmbObj = xEmbedCreator.createInstanceInitNew( pClassID, 1268*cdf0e10cSrcweir "Dummy name", 1269*cdf0e10cSrcweir m_xStorage, 1270*cdf0e10cSrcweir "EmbedSub", 1271*cdf0e10cSrcweir new PropertyValue[0] ); 1272*cdf0e10cSrcweir xEmbObj = (XEmbeddedObject)UnoRuntime.queryInterface( XEmbeddedObject.class, oEmbObj ); 1273*cdf0e10cSrcweir } 1274*cdf0e10cSrcweir else 1275*cdf0e10cSrcweir JOptionPane.showMessageDialog( m_aFrame, 1276*cdf0e10cSrcweir "Can't create EmbedCreator!", 1277*cdf0e10cSrcweir "Error:", 1278*cdf0e10cSrcweir JOptionPane.ERROR_MESSAGE ); 1279*cdf0e10cSrcweir } 1280*cdf0e10cSrcweir catch( Exception e ) 1281*cdf0e10cSrcweir { 1282*cdf0e10cSrcweir JOptionPane.showMessageDialog( m_aFrame, e, "Exception in createInstanceInitNew():", JOptionPane.ERROR_MESSAGE ); 1283*cdf0e10cSrcweir } 1284*cdf0e10cSrcweir } 1285*cdf0e10cSrcweir else 1286*cdf0e10cSrcweir JOptionPane.showMessageDialog( m_aFrame, "Can't retrieve class ID!", "Error:", JOptionPane.ERROR_MESSAGE ); 1287*cdf0e10cSrcweir 1288*cdf0e10cSrcweir return xEmbObj; 1289*cdf0e10cSrcweir } 1290*cdf0e10cSrcweir 1291*cdf0e10cSrcweir public XEmbeddedObject createLinkObject( String aLinkURL ) 1292*cdf0e10cSrcweir { 1293*cdf0e10cSrcweir XEmbeddedObject xEmbObj = null; 1294*cdf0e10cSrcweir 1295*cdf0e10cSrcweir try { 1296*cdf0e10cSrcweir Object oLinkCreator = m_xServiceFactory.createInstance( "com.sun.star.embed.EmbeddedObjectCreator" ); 1297*cdf0e10cSrcweir XLinkCreator xLinkCreator = (XLinkCreator)UnoRuntime.queryInterface( 1298*cdf0e10cSrcweir XLinkCreator.class, 1299*cdf0e10cSrcweir oLinkCreator ); 1300*cdf0e10cSrcweir if ( xLinkCreator != null ) 1301*cdf0e10cSrcweir { 1302*cdf0e10cSrcweir PropertyValue[] aMedDescr = { new PropertyValue(), new PropertyValue() }; 1303*cdf0e10cSrcweir aMedDescr[0].Name = "URL"; 1304*cdf0e10cSrcweir aMedDescr[0].Value = (Object) aLinkURL; 1305*cdf0e10cSrcweir aMedDescr[1].Name = "ReadOnly"; 1306*cdf0e10cSrcweir aMedDescr[1].Value = (Object) new Boolean( false ); 1307*cdf0e10cSrcweir Object oEmbObj = xLinkCreator.createInstanceLink( m_xStorage, "EmbedSub", aMedDescr, new PropertyValue[0] ); 1308*cdf0e10cSrcweir xEmbObj = (XEmbeddedObject)UnoRuntime.queryInterface( XEmbeddedObject.class, oEmbObj ); 1309*cdf0e10cSrcweir } 1310*cdf0e10cSrcweir else 1311*cdf0e10cSrcweir JOptionPane.showMessageDialog( m_aFrame, 1312*cdf0e10cSrcweir "Can't create LinkCreator!", 1313*cdf0e10cSrcweir "Error:", 1314*cdf0e10cSrcweir JOptionPane.ERROR_MESSAGE ); 1315*cdf0e10cSrcweir } 1316*cdf0e10cSrcweir catch( Exception e ) 1317*cdf0e10cSrcweir { 1318*cdf0e10cSrcweir JOptionPane.showMessageDialog( m_aFrame, e, "Exception in createLinkObject():", JOptionPane.ERROR_MESSAGE ); 1319*cdf0e10cSrcweir } 1320*cdf0e10cSrcweir 1321*cdf0e10cSrcweir 1322*cdf0e10cSrcweir return xEmbObj; 1323*cdf0e10cSrcweir } 1324*cdf0e10cSrcweir 1325*cdf0e10cSrcweir 1326*cdf0e10cSrcweir public XEmbeddedObject loadEmbedObject( String aFileURI ) 1327*cdf0e10cSrcweir { 1328*cdf0e10cSrcweir XEmbeddedObject xEmbObj = null; 1329*cdf0e10cSrcweir try { 1330*cdf0e10cSrcweir Object oEmbedCreator = m_xServiceFactory.createInstance( "com.sun.star.embed.EmbeddedObjectCreator" ); 1331*cdf0e10cSrcweir XEmbedObjectCreator xEmbedCreator = (XEmbedObjectCreator)UnoRuntime.queryInterface( 1332*cdf0e10cSrcweir XEmbedObjectCreator.class, 1333*cdf0e10cSrcweir oEmbedCreator ); 1334*cdf0e10cSrcweir if ( xEmbedCreator != null ) 1335*cdf0e10cSrcweir { 1336*cdf0e10cSrcweir PropertyValue[] aMedDescr = { new PropertyValue(), new PropertyValue() }; 1337*cdf0e10cSrcweir aMedDescr[0].Name = "URL"; 1338*cdf0e10cSrcweir aMedDescr[0].Value = (Object) aFileURI; 1339*cdf0e10cSrcweir aMedDescr[1].Name = "ReadOnly"; 1340*cdf0e10cSrcweir aMedDescr[1].Value = (Object) new Boolean( false ); 1341*cdf0e10cSrcweir Object oEmbObj = xEmbedCreator.createInstanceInitFromMediaDescriptor( m_xStorage, 1342*cdf0e10cSrcweir "EmbedSub", 1343*cdf0e10cSrcweir aMedDescr, 1344*cdf0e10cSrcweir new PropertyValue[0] ); 1345*cdf0e10cSrcweir xEmbObj = (XEmbeddedObject)UnoRuntime.queryInterface( XEmbeddedObject.class, oEmbObj ); 1346*cdf0e10cSrcweir } 1347*cdf0e10cSrcweir else 1348*cdf0e10cSrcweir JOptionPane.showMessageDialog( m_aFrame, 1349*cdf0e10cSrcweir "Can't create EmbedFactory!", 1350*cdf0e10cSrcweir "Error:", 1351*cdf0e10cSrcweir JOptionPane.ERROR_MESSAGE ); 1352*cdf0e10cSrcweir } 1353*cdf0e10cSrcweir catch( Exception e ) 1354*cdf0e10cSrcweir { 1355*cdf0e10cSrcweir JOptionPane.showMessageDialog( m_aFrame, e, "Exception in loadEmbedObject():", JOptionPane.ERROR_MESSAGE ); 1356*cdf0e10cSrcweir } 1357*cdf0e10cSrcweir 1358*cdf0e10cSrcweir return xEmbObj; 1359*cdf0e10cSrcweir } 1360*cdf0e10cSrcweir 1361*cdf0e10cSrcweir public void clearObjectAndStorage() 1362*cdf0e10cSrcweir { 1363*cdf0e10cSrcweir synchronized( m_oImageLock ) 1364*cdf0e10cSrcweir { 1365*cdf0e10cSrcweir m_aImage = null; 1366*cdf0e10cSrcweir } 1367*cdf0e10cSrcweir 1368*cdf0e10cSrcweir m_nXScaling = 1; 1369*cdf0e10cSrcweir m_nYScaling = 1; 1370*cdf0e10cSrcweir m_nXPixelSize = 1; 1371*cdf0e10cSrcweir m_nYPixelSize = 1; 1372*cdf0e10cSrcweir 1373*cdf0e10cSrcweir m_bOwnFile = false; 1374*cdf0e10cSrcweir 1375*cdf0e10cSrcweir m_aLinkURI = null; 1376*cdf0e10cSrcweir m_bLinkObj = false; 1377*cdf0e10cSrcweir 1378*cdf0e10cSrcweir if ( m_xEmbedObj != null ) 1379*cdf0e10cSrcweir { 1380*cdf0e10cSrcweir try { 1381*cdf0e10cSrcweir XCloseable xClose = (XCloseable)UnoRuntime.queryInterface( XCloseable.class, m_xEmbedObj ); 1382*cdf0e10cSrcweir if ( xClose != null ) 1383*cdf0e10cSrcweir xClose.close( true ); 1384*cdf0e10cSrcweir } 1385*cdf0e10cSrcweir catch ( Exception ex ) 1386*cdf0e10cSrcweir {} 1387*cdf0e10cSrcweir m_xEmbedObj = null; 1388*cdf0e10cSrcweir } 1389*cdf0e10cSrcweir 1390*cdf0e10cSrcweir if ( m_xStorage != null ) 1391*cdf0e10cSrcweir { 1392*cdf0e10cSrcweir try { 1393*cdf0e10cSrcweir XComponent xComponent = (XComponent)UnoRuntime.queryInterface( XComponent.class, m_xStorage ); 1394*cdf0e10cSrcweir if ( xComponent != null ) 1395*cdf0e10cSrcweir xComponent.dispose(); 1396*cdf0e10cSrcweir } 1397*cdf0e10cSrcweir catch ( Exception ex ) 1398*cdf0e10cSrcweir {} 1399*cdf0e10cSrcweir m_xStorage = null; 1400*cdf0e10cSrcweir } 1401*cdf0e10cSrcweir } 1402*cdf0e10cSrcweir 1403*cdf0e10cSrcweir public XStorage createTempStorage() 1404*cdf0e10cSrcweir { 1405*cdf0e10cSrcweir XStorage xTempStorage = null; 1406*cdf0e10cSrcweir 1407*cdf0e10cSrcweir try { 1408*cdf0e10cSrcweir Object oStorageFactory = m_xServiceFactory.createInstance( "com.sun.star.embed.StorageFactory" ); 1409*cdf0e10cSrcweir XSingleServiceFactory xStorageFactory = (XSingleServiceFactory)UnoRuntime.queryInterface( 1410*cdf0e10cSrcweir XSingleServiceFactory.class, 1411*cdf0e10cSrcweir oStorageFactory ); 1412*cdf0e10cSrcweir if ( xStorageFactory != null ) 1413*cdf0e10cSrcweir { 1414*cdf0e10cSrcweir Object oStorage = xStorageFactory.createInstance(); 1415*cdf0e10cSrcweir xTempStorage = (XStorage)UnoRuntime.queryInterface( XStorage.class, oStorage ); 1416*cdf0e10cSrcweir } 1417*cdf0e10cSrcweir else 1418*cdf0e10cSrcweir JOptionPane.showMessageDialog( m_aFrame, 1419*cdf0e10cSrcweir "Can't create StorageFactory!", 1420*cdf0e10cSrcweir "Error:", 1421*cdf0e10cSrcweir JOptionPane.ERROR_MESSAGE ); 1422*cdf0e10cSrcweir } 1423*cdf0e10cSrcweir catch( Exception e ) 1424*cdf0e10cSrcweir { 1425*cdf0e10cSrcweir JOptionPane.showMessageDialog( m_aFrame, e, "Exception in createTempStorage():", JOptionPane.ERROR_MESSAGE ); 1426*cdf0e10cSrcweir } 1427*cdf0e10cSrcweir 1428*cdf0e10cSrcweir return xTempStorage; 1429*cdf0e10cSrcweir } 1430*cdf0e10cSrcweir 1431*cdf0e10cSrcweir public void saveObjectAsFileURI( String aFileURI ) 1432*cdf0e10cSrcweir { 1433*cdf0e10cSrcweir try { 1434*cdf0e10cSrcweir Object oStorageFactory = m_xServiceFactory.createInstance( "com.sun.star.embed.StorageFactory" ); 1435*cdf0e10cSrcweir XSingleServiceFactory xStorageFactory = (XSingleServiceFactory)UnoRuntime.queryInterface( 1436*cdf0e10cSrcweir XSingleServiceFactory.class, 1437*cdf0e10cSrcweir oStorageFactory ); 1438*cdf0e10cSrcweir if ( xStorageFactory != null ) 1439*cdf0e10cSrcweir { 1440*cdf0e10cSrcweir XEmbedPersist xPersist = (XEmbedPersist)UnoRuntime.queryInterface( XEmbedPersist.class, m_xEmbedObj ); 1441*cdf0e10cSrcweir if ( xPersist != null ) 1442*cdf0e10cSrcweir { 1443*cdf0e10cSrcweir Object aArgs[] = new Object[2]; 1444*cdf0e10cSrcweir aArgs[0] = aFileURI; 1445*cdf0e10cSrcweir aArgs[1] = new Integer( ElementModes.ELEMENT_READWRITE ); 1446*cdf0e10cSrcweir 1447*cdf0e10cSrcweir Object oStorage = xStorageFactory.createInstanceWithArguments( aArgs ); 1448*cdf0e10cSrcweir XStorage xTargetStorage = (XStorage)UnoRuntime.queryInterface( XStorage.class, oStorage ); 1449*cdf0e10cSrcweir 1450*cdf0e10cSrcweir PropertyValue aProps[] = { new PropertyValue() }; 1451*cdf0e10cSrcweir aProps[0].Name = "StoreVisualReplacement"; 1452*cdf0e10cSrcweir aProps[0].Value = new Boolean( m_bStoreVisRepl ); 1453*cdf0e10cSrcweir 1454*cdf0e10cSrcweir xPersist.storeAsEntry( xTargetStorage, "EmbedSub", new PropertyValue[0], aProps ); 1455*cdf0e10cSrcweir xPersist.saveCompleted( true ); 1456*cdf0e10cSrcweir 1457*cdf0e10cSrcweir // the object must be already based on new storage 1458*cdf0e10cSrcweir XComponent xComponent = (XComponent)UnoRuntime.queryInterface( XComponent.class, m_xStorage ); 1459*cdf0e10cSrcweir xComponent.dispose(); 1460*cdf0e10cSrcweir 1461*cdf0e10cSrcweir m_xStorage = xTargetStorage; 1462*cdf0e10cSrcweir m_bOwnFile = true; 1463*cdf0e10cSrcweir 1464*cdf0e10cSrcweir XTransactedObject xTransact = (XTransactedObject)UnoRuntime.queryInterface( XTransactedObject.class, 1465*cdf0e10cSrcweir m_xStorage ); 1466*cdf0e10cSrcweir if ( xTransact != null ) 1467*cdf0e10cSrcweir xTransact.commit(); 1468*cdf0e10cSrcweir } 1469*cdf0e10cSrcweir else 1470*cdf0e10cSrcweir JOptionPane.showMessageDialog( m_aFrame, "No XEmbedPersist!", "Error:", JOptionPane.ERROR_MESSAGE ); 1471*cdf0e10cSrcweir } 1472*cdf0e10cSrcweir else 1473*cdf0e10cSrcweir JOptionPane.showMessageDialog( m_aFrame, 1474*cdf0e10cSrcweir "Can't create StorageFactory!", 1475*cdf0e10cSrcweir "Error:", 1476*cdf0e10cSrcweir JOptionPane.ERROR_MESSAGE ); 1477*cdf0e10cSrcweir } 1478*cdf0e10cSrcweir catch( Exception e ) 1479*cdf0e10cSrcweir { 1480*cdf0e10cSrcweir JOptionPane.showMessageDialog( m_aFrame, e, "Exception in saveStorageToFileURI():", JOptionPane.ERROR_MESSAGE ); 1481*cdf0e10cSrcweir } 1482*cdf0e10cSrcweir 1483*cdf0e10cSrcweir } 1484*cdf0e10cSrcweir 1485*cdf0e10cSrcweir public void loadFileURI( String aFileURI ) 1486*cdf0e10cSrcweir { 1487*cdf0e10cSrcweir try 1488*cdf0e10cSrcweir { 1489*cdf0e10cSrcweir Object oStorageFactory = m_xServiceFactory.createInstance( "com.sun.star.embed.StorageFactory" ); 1490*cdf0e10cSrcweir XSingleServiceFactory xStorageFactory = (XSingleServiceFactory)UnoRuntime.queryInterface( 1491*cdf0e10cSrcweir XSingleServiceFactory.class, 1492*cdf0e10cSrcweir oStorageFactory ); 1493*cdf0e10cSrcweir Object aArgs[] = new Object[2]; 1494*cdf0e10cSrcweir aArgs[0] = aFileURI; 1495*cdf0e10cSrcweir aArgs[1] = new Integer( ElementModes.ELEMENT_READWRITE ); 1496*cdf0e10cSrcweir 1497*cdf0e10cSrcweir Object oStorage = xStorageFactory.createInstanceWithArguments( aArgs ); 1498*cdf0e10cSrcweir XStorage xTargetStorage = (XStorage)UnoRuntime.queryInterface( XStorage.class, oStorage ); 1499*cdf0e10cSrcweir 1500*cdf0e10cSrcweir Object oEmbedCreator = m_xServiceFactory.createInstance( "com.sun.star.embed.EmbeddedObjectCreator" ); 1501*cdf0e10cSrcweir XEmbedObjectCreator xEmbedCreator = (XEmbedObjectCreator)UnoRuntime.queryInterface( 1502*cdf0e10cSrcweir XEmbedObjectCreator.class, 1503*cdf0e10cSrcweir oEmbedCreator ); 1504*cdf0e10cSrcweir 1505*cdf0e10cSrcweir XNameAccess xNameAccess = (XNameAccess)UnoRuntime.queryInterface( XNameAccess.class, 1506*cdf0e10cSrcweir xTargetStorage ); 1507*cdf0e10cSrcweir if ( xNameAccess == null ) 1508*cdf0e10cSrcweir { 1509*cdf0e10cSrcweir JOptionPane.showMessageDialog( m_aFrame, "No XNameAccess!", "Error:", JOptionPane.ERROR_MESSAGE ); 1510*cdf0e10cSrcweir return; 1511*cdf0e10cSrcweir } 1512*cdf0e10cSrcweir 1513*cdf0e10cSrcweir Object oEmbObj = null; 1514*cdf0e10cSrcweir if ( xNameAccess.hasByName( "LinkName" ) && xTargetStorage.isStreamElement( "LinkName" ) ) 1515*cdf0e10cSrcweir { 1516*cdf0e10cSrcweir /* 1517*cdf0e10cSrcweir // OOo links will not be tested until they have correct persistence 1518*cdf0e10cSrcweir XStream xLinkStream = xTargetStorage.openStreamElement( "LinkName", ElementModes.ELEMENT_READ ); 1519*cdf0e10cSrcweir if ( xLinkStream != null ) 1520*cdf0e10cSrcweir { 1521*cdf0e10cSrcweir XInputStream xInStream = xLinkStream.getInputStream(); 1522*cdf0e10cSrcweir if ( xInStream != null ) 1523*cdf0e10cSrcweir { 1524*cdf0e10cSrcweir byte[][] pBuff = new byte[1][0]; 1525*cdf0e10cSrcweir int nRead = xInStream.readBytes( pBuff, 1000 ); 1526*cdf0e10cSrcweir m_aLinkURI = new String( pBuff[0] ); 1527*cdf0e10cSrcweir xInStream.closeInput(); 1528*cdf0e10cSrcweir oEmbObj = xEmbedCreator.createInstanceLink( m_aLinkURI ); 1529*cdf0e10cSrcweir m_bLinkObj = true; 1530*cdf0e10cSrcweir } 1531*cdf0e10cSrcweir } 1532*cdf0e10cSrcweir */ 1533*cdf0e10cSrcweir } 1534*cdf0e10cSrcweir else 1535*cdf0e10cSrcweir oEmbObj = xEmbedCreator.createInstanceInitFromEntry( xTargetStorage, 1536*cdf0e10cSrcweir "EmbedSub", 1537*cdf0e10cSrcweir false, 1538*cdf0e10cSrcweir new PropertyValue[0] ); 1539*cdf0e10cSrcweir 1540*cdf0e10cSrcweir m_xEmbedObj = (XEmbeddedObject)UnoRuntime.queryInterface( XEmbeddedObject.class, oEmbObj ); 1541*cdf0e10cSrcweir 1542*cdf0e10cSrcweir if ( m_xEmbedObj != null ) 1543*cdf0e10cSrcweir { 1544*cdf0e10cSrcweir m_xStorage = xTargetStorage; 1545*cdf0e10cSrcweir m_bOwnFile = true; 1546*cdf0e10cSrcweir } 1547*cdf0e10cSrcweir else 1548*cdf0e10cSrcweir JOptionPane.showMessageDialog( m_aFrame, 1549*cdf0e10cSrcweir "Can't create EmbedObject from storage!", 1550*cdf0e10cSrcweir "Error:", 1551*cdf0e10cSrcweir JOptionPane.ERROR_MESSAGE ); 1552*cdf0e10cSrcweir } 1553*cdf0e10cSrcweir catch( Exception e ) 1554*cdf0e10cSrcweir { 1555*cdf0e10cSrcweir JOptionPane.showMessageDialog( m_aFrame, e, "Exception in loadFileURI():", JOptionPane.ERROR_MESSAGE ); 1556*cdf0e10cSrcweir } 1557*cdf0e10cSrcweir } 1558*cdf0e10cSrcweir 1559*cdf0e10cSrcweir public void storeLinkToStorage() 1560*cdf0e10cSrcweir { 1561*cdf0e10cSrcweir if ( m_xStorage != null && m_bLinkObj ) 1562*cdf0e10cSrcweir { 1563*cdf0e10cSrcweir try { 1564*cdf0e10cSrcweir XStream xLinkStream = m_xStorage.openStreamElement( "LinkName", ElementModes.ELEMENT_WRITE ); 1565*cdf0e10cSrcweir 1566*cdf0e10cSrcweir if ( xLinkStream != null ) 1567*cdf0e10cSrcweir { 1568*cdf0e10cSrcweir XOutputStream xLinkOutStream = xLinkStream.getOutputStream(); 1569*cdf0e10cSrcweir XTruncate xTruncate = (XTruncate) UnoRuntime.queryInterface( XTruncate.class, 1570*cdf0e10cSrcweir xLinkOutStream ); 1571*cdf0e10cSrcweir if ( xLinkOutStream != null && xTruncate != null ) 1572*cdf0e10cSrcweir { 1573*cdf0e10cSrcweir xTruncate.truncate(); 1574*cdf0e10cSrcweir 1575*cdf0e10cSrcweir char[] aLinkChar = m_aLinkURI.toCharArray(); 1576*cdf0e10cSrcweir byte[] aLinkBytes = new byte[ aLinkChar.length ]; 1577*cdf0e10cSrcweir for ( int ind = 0; ind < aLinkChar.length; ind++ ) 1578*cdf0e10cSrcweir aLinkBytes[ind] = (byte)aLinkChar[ind]; 1579*cdf0e10cSrcweir 1580*cdf0e10cSrcweir xLinkOutStream.writeBytes( aLinkBytes ); 1581*cdf0e10cSrcweir xLinkOutStream.closeOutput(); 1582*cdf0e10cSrcweir 1583*cdf0e10cSrcweir XComponent xComponent = (XComponent) UnoRuntime.queryInterface( XComponent.class, 1584*cdf0e10cSrcweir xLinkStream ); 1585*cdf0e10cSrcweir if ( xComponent != null ) 1586*cdf0e10cSrcweir xComponent.dispose(); 1587*cdf0e10cSrcweir } 1588*cdf0e10cSrcweir else 1589*cdf0e10cSrcweir JOptionPane.showMessageDialog( m_aFrame, 1590*cdf0e10cSrcweir "The substream can not be truncated or written!", 1591*cdf0e10cSrcweir "Error:", 1592*cdf0e10cSrcweir JOptionPane.ERROR_MESSAGE ); 1593*cdf0e10cSrcweir 1594*cdf0e10cSrcweir } 1595*cdf0e10cSrcweir else 1596*cdf0e10cSrcweir JOptionPane.showMessageDialog( m_aFrame, 1597*cdf0e10cSrcweir "Can't create/open substream!", 1598*cdf0e10cSrcweir "Error:", 1599*cdf0e10cSrcweir JOptionPane.ERROR_MESSAGE ); 1600*cdf0e10cSrcweir } 1601*cdf0e10cSrcweir catch( Exception e ) 1602*cdf0e10cSrcweir { 1603*cdf0e10cSrcweir JOptionPane.showMessageDialog( m_aFrame, 1604*cdf0e10cSrcweir e, 1605*cdf0e10cSrcweir "Exception in storeLinkToStorage:", 1606*cdf0e10cSrcweir JOptionPane.ERROR_MESSAGE ); 1607*cdf0e10cSrcweir 1608*cdf0e10cSrcweir } 1609*cdf0e10cSrcweir } 1610*cdf0e10cSrcweir } 1611*cdf0e10cSrcweir 1612*cdf0e10cSrcweir public void storeLinkAsFileURI( String aFileURI ) 1613*cdf0e10cSrcweir { 1614*cdf0e10cSrcweir try { 1615*cdf0e10cSrcweir Object oStorageFactory = m_xServiceFactory.createInstance( "com.sun.star.embed.StorageFactory" ); 1616*cdf0e10cSrcweir XSingleServiceFactory xStorageFactory = (XSingleServiceFactory)UnoRuntime.queryInterface( 1617*cdf0e10cSrcweir XSingleServiceFactory.class, 1618*cdf0e10cSrcweir oStorageFactory ); 1619*cdf0e10cSrcweir if ( xStorageFactory != null ) 1620*cdf0e10cSrcweir { 1621*cdf0e10cSrcweir Object aArgs[] = new Object[2]; 1622*cdf0e10cSrcweir aArgs[0] = aFileURI; 1623*cdf0e10cSrcweir aArgs[1] = new Integer( ElementModes.ELEMENT_READWRITE ); 1624*cdf0e10cSrcweir 1625*cdf0e10cSrcweir Object oStorage = xStorageFactory.createInstanceWithArguments( aArgs ); 1626*cdf0e10cSrcweir XStorage xTargetStorage = (XStorage)UnoRuntime.queryInterface( XStorage.class, oStorage ); 1627*cdf0e10cSrcweir 1628*cdf0e10cSrcweir XComponent xComponent = (XComponent)UnoRuntime.queryInterface( XComponent.class, m_xStorage ); 1629*cdf0e10cSrcweir xComponent.dispose(); 1630*cdf0e10cSrcweir 1631*cdf0e10cSrcweir m_xStorage = xTargetStorage; 1632*cdf0e10cSrcweir m_bOwnFile = true; 1633*cdf0e10cSrcweir 1634*cdf0e10cSrcweir storeLinkToStorage(); 1635*cdf0e10cSrcweir 1636*cdf0e10cSrcweir XTransactedObject xTransact = (XTransactedObject)UnoRuntime.queryInterface( XTransactedObject.class, 1637*cdf0e10cSrcweir m_xStorage ); 1638*cdf0e10cSrcweir if ( xTransact != null ) 1639*cdf0e10cSrcweir xTransact.commit(); 1640*cdf0e10cSrcweir } 1641*cdf0e10cSrcweir else 1642*cdf0e10cSrcweir JOptionPane.showMessageDialog( m_aFrame, 1643*cdf0e10cSrcweir "Can't create StorageFactory!", 1644*cdf0e10cSrcweir "Error:", 1645*cdf0e10cSrcweir JOptionPane.ERROR_MESSAGE ); 1646*cdf0e10cSrcweir } 1647*cdf0e10cSrcweir catch( Exception e ) 1648*cdf0e10cSrcweir { 1649*cdf0e10cSrcweir JOptionPane.showMessageDialog( m_aFrame, e, "Exception in saveStorageToFileURI():", JOptionPane.ERROR_MESSAGE ); 1650*cdf0e10cSrcweir } 1651*cdf0e10cSrcweir } 1652*cdf0e10cSrcweir 1653*cdf0e10cSrcweir public String getValidURL( String sFileURL ) 1654*cdf0e10cSrcweir { 1655*cdf0e10cSrcweir // m_xTransformer must be set! 1656*cdf0e10cSrcweir URL[] aURLs = { new URL() }; 1657*cdf0e10cSrcweir aURLs[0].Complete = sFileURL; 1658*cdf0e10cSrcweir 1659*cdf0e10cSrcweir try { 1660*cdf0e10cSrcweir if ( !m_xTransformer.parseSmart( aURLs, "" ) ) 1661*cdf0e10cSrcweir throw new Exception(); 1662*cdf0e10cSrcweir } 1663*cdf0e10cSrcweir catch( Exception e ) 1664*cdf0e10cSrcweir { 1665*cdf0e10cSrcweir JOptionPane.showMessageDialog( m_aFrame, e, "Exception in getValidURL():", JOptionPane.ERROR_MESSAGE ); 1666*cdf0e10cSrcweir } 1667*cdf0e10cSrcweir 1668*cdf0e10cSrcweir return aURLs[0].Complete; 1669*cdf0e10cSrcweir } 1670*cdf0e10cSrcweir 1671*cdf0e10cSrcweir public void disposeObject() 1672*cdf0e10cSrcweir { 1673*cdf0e10cSrcweir // TODO: 1674*cdf0e10cSrcweir // usage of object, storage and bitmap painter should be locked 1675*cdf0e10cSrcweir // but since possibility of rasecondition is very low 1676*cdf0e10cSrcweir // it is not really required for testing application 1677*cdf0e10cSrcweir 1678*cdf0e10cSrcweir clearObjectAndStorage(); 1679*cdf0e10cSrcweir 1680*cdf0e10cSrcweir if ( m_aBitmapPainter != null ) 1681*cdf0e10cSrcweir { 1682*cdf0e10cSrcweir m_aBitmapPainter.disconnectListener(); 1683*cdf0e10cSrcweir m_aBitmapPainter = null; 1684*cdf0e10cSrcweir } 1685*cdf0e10cSrcweir } 1686*cdf0e10cSrcweir } 1687*cdf0e10cSrcweir 1688