2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package embeddedobj
.test
;
23 import java
.awt
.event
.*;
27 import com
.sun
.star
.awt
.XBitmap
;
28 import com
.sun
.star
.awt
.XWindow
;
29 import com
.sun
.star
.awt
.XWindowPeer
;
30 import com
.sun
.star
.awt
.XToolkit
;
31 import com
.sun
.star
.awt
.XSystemChildFactory
;
32 import com
.sun
.star
.awt
.WindowDescriptor
;
33 import com
.sun
.star
.awt
.WindowClass
;
34 import com
.sun
.star
.awt
.WindowAttribute
;
35 import com
.sun
.star
.awt
.VclWindowPeerAttribute
;
37 import com
.sun
.star
.uno
.UnoRuntime
;
38 import com
.sun
.star
.uno
.AnyConverter
;
39 import com
.sun
.star
.uno
.Any
;
41 import com
.sun
.star
.lang
.XMultiServiceFactory
;
42 import com
.sun
.star
.lang
.XSingleServiceFactory
;
46 public static XWindow
createWindow( XMultiServiceFactory xFactory
, NativeView aParent
, java
.awt
.Rectangle aBounds
)
48 XWindow xWindow
= null;
49 XToolkit xToolkit
= null;
51 // get access to toolkit of remote office to create the container window of new target frame
53 xToolkit
= (XToolkit
)UnoRuntime
.queryInterface( XToolkit
.class,
54 xFactory
.createInstance("com.sun.star.awt.Toolkit") );
61 XSystemChildFactory xChildFactory
= (XSystemChildFactory
)UnoRuntime
.queryInterface(
62 XSystemChildFactory
.class,
67 XWindowPeer xPeer
= null;
68 Integer nHandle
= aParent
.getHWND();
69 short nSystem
= (short)aParent
.getNativeWindowSystemType();
70 byte[] lProcID
= new byte[0];
73 xPeer = xChildFactory.createSystemChild((Object)nHandle, lProcID, nSystem);
80 JavaWindowPeerFake aWrapper
= new JavaWindowPeerFake(aParent
);
82 XWindowPeer xParentPeer
= (XWindowPeer
)UnoRuntime
.queryInterface(
86 WindowDescriptor aDescriptor
= new WindowDescriptor();
87 aDescriptor
.Type
= WindowClass
.TOP
;
88 aDescriptor
.WindowServiceName
= "workwindow";
89 aDescriptor
.ParentIndex
= 1;
90 aDescriptor
.Parent
= xParentPeer
;
91 aDescriptor
.Bounds
= new com
.sun
.star
.awt
.Rectangle( (int)aBounds
.getX(),
93 (int)aBounds
.getWidth(),
94 (int)aBounds
.getHeight() );
96 System
.out
.println( "The rectangle for vcl window is:\nx = " + (int)aBounds
.getX()
97 + "; y = " + (int)aBounds
.getY()
98 + "; width = " + (int)aBounds
.getWidth()
99 + "; height = " + (int)aBounds
.getHeight() );
101 if (nSystem
== com
.sun
.star
.lang
.SystemDependent
.SYSTEM_WIN32
)
102 aDescriptor
.WindowAttributes
= WindowAttribute
.SHOW
;
104 aDescriptor
.WindowAttributes
= WindowAttribute
.SYSTEMDEPENDENT
;
106 aDescriptor
.WindowAttributes
|= VclWindowPeerAttribute
.CLIPCHILDREN
;
108 xPeer
= xToolkit
.createWindow( aDescriptor
);
111 xWindow
= (XWindow
)UnoRuntime
.queryInterface( XWindow
.class, xPeer
);
112 if ( xWindow
!= null )
113 xWindow
.setPosSize( (int)aBounds
.getX(),
115 (int)aBounds
.getWidth(),
116 (int)aBounds
.getHeight(),
117 com
.sun
.star
.awt
.PosSize
.POSSIZE
);
119 catch( Exception ex1
)
121 System
.out
.println( "Exception on VCL window creation: " + ex1
);
128 public static XBitmap
getVCLBitmapFromBytes( XMultiServiceFactory xFactory
, Object aAny
)
130 if ( !AnyConverter
.isArray( aAny
) )
131 throw new com
.sun
.star
.uno
.RuntimeException();
133 Object
[] aArgs
= new Object
[1];
135 XBitmap xResult
= null;
138 XSingleServiceFactory xBitmapFactory
= (XSingleServiceFactory
)UnoRuntime
.queryInterface(
139 XSingleServiceFactory
.class,
140 xFactory
.createInstance( "com.sun.star.embed.BitmapCreator" ) );
142 xResult
= (XBitmap
)UnoRuntime
.queryInterface(
144 xBitmapFactory
.createInstanceWithArguments( aArgs
) );
148 System
.out
.println( "Could not create VCL bitmap based on sequence," );
149 System
.out
.println( "exception: " + e
);