1 package embeddedobj
.test
;
5 import java
.awt
.event
.*;
9 import com
.sun
.star
.awt
.XBitmap
;
10 import com
.sun
.star
.awt
.XWindow
;
11 import com
.sun
.star
.awt
.XWindowPeer
;
12 import com
.sun
.star
.awt
.XToolkit
;
13 import com
.sun
.star
.awt
.XSystemChildFactory
;
14 import com
.sun
.star
.awt
.WindowDescriptor
;
15 import com
.sun
.star
.awt
.WindowClass
;
16 import com
.sun
.star
.awt
.WindowAttribute
;
17 import com
.sun
.star
.awt
.VclWindowPeerAttribute
;
19 import com
.sun
.star
.uno
.UnoRuntime
;
20 import com
.sun
.star
.uno
.AnyConverter
;
21 import com
.sun
.star
.uno
.Any
;
23 import com
.sun
.star
.lang
.XMultiServiceFactory
;
24 import com
.sun
.star
.lang
.XSingleServiceFactory
;
28 public static XWindow
createWindow( XMultiServiceFactory xFactory
, NativeView aParent
, java
.awt
.Rectangle aBounds
)
30 XWindow xWindow
= null;
31 XToolkit xToolkit
= null;
33 // get access to toolkit of remote office to create the container window of new target frame
35 xToolkit
= (XToolkit
)UnoRuntime
.queryInterface( XToolkit
.class,
36 xFactory
.createInstance("com.sun.star.awt.Toolkit") );
43 XSystemChildFactory xChildFactory
= (XSystemChildFactory
)UnoRuntime
.queryInterface(
44 XSystemChildFactory
.class,
49 XWindowPeer xPeer
= null;
50 Integer nHandle
= aParent
.getHWND();
51 short nSystem
= (short)aParent
.getNativeWindowSystemType();
52 byte[] lProcID
= new byte[0];
55 xPeer = xChildFactory.createSystemChild((Object)nHandle, lProcID, nSystem);
62 JavaWindowPeerFake aWrapper
= new JavaWindowPeerFake(aParent
);
64 XWindowPeer xParentPeer
= (XWindowPeer
)UnoRuntime
.queryInterface(
68 WindowDescriptor aDescriptor
= new WindowDescriptor();
69 aDescriptor
.Type
= WindowClass
.TOP
;
70 aDescriptor
.WindowServiceName
= "workwindow";
71 aDescriptor
.ParentIndex
= 1;
72 aDescriptor
.Parent
= xParentPeer
;
73 aDescriptor
.Bounds
= new com
.sun
.star
.awt
.Rectangle( (int)aBounds
.getX(),
75 (int)aBounds
.getWidth(),
76 (int)aBounds
.getHeight() );
78 System
.out
.println( "The rectangle for vcl window is:\nx = " + (int)aBounds
.getX()
79 + "; y = " + (int)aBounds
.getY()
80 + "; width = " + (int)aBounds
.getWidth()
81 + "; height = " + (int)aBounds
.getHeight() );
83 if (nSystem
== com
.sun
.star
.lang
.SystemDependent
.SYSTEM_WIN32
)
84 aDescriptor
.WindowAttributes
= WindowAttribute
.SHOW
;
86 aDescriptor
.WindowAttributes
= WindowAttribute
.SYSTEMDEPENDENT
;
88 aDescriptor
.WindowAttributes
|= VclWindowPeerAttribute
.CLIPCHILDREN
;
90 xPeer
= xToolkit
.createWindow( aDescriptor
);
93 xWindow
= (XWindow
)UnoRuntime
.queryInterface( XWindow
.class, xPeer
);
94 if ( xWindow
!= null )
95 xWindow
.setPosSize( (int)aBounds
.getX(),
97 (int)aBounds
.getWidth(),
98 (int)aBounds
.getHeight(),
99 com
.sun
.star
.awt
.PosSize
.POSSIZE
);
101 catch( Exception ex1
)
103 System
.out
.println( "Exception on VCL window creation: " + ex1
);
110 public static XBitmap
getVCLBitmapFromBytes( XMultiServiceFactory xFactory
, Object aAny
)
112 if ( !AnyConverter
.isArray( aAny
) )
113 throw new com
.sun
.star
.uno
.RuntimeException();
115 Object
[] aArgs
= new Object
[1];
117 XBitmap xResult
= null;
120 XSingleServiceFactory xBitmapFactory
= (XSingleServiceFactory
)UnoRuntime
.queryInterface(
121 XSingleServiceFactory
.class,
122 xFactory
.createInstance( "com.sun.star.embed.BitmapCreator" ) );
124 xResult
= (XBitmap
)UnoRuntime
.queryInterface(
126 xBitmapFactory
.createInstanceWithArguments( aArgs
) );
130 System
.out
.println( "Could not create VCL bitmap based on sequence," );
131 System
.out
.println( "exception: " + e
);