summaryrefslogtreecommitdiffstats
path: root/embeddedobj/test/Container1/WindowHelper.java
blob: 66de646ddb577e055b8954cfff410796ac49990a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

package embeddedobj.test;

import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import java.net.*;
import java.io.*;

import com.sun.star.awt.XBitmap;
import com.sun.star.awt.XWindow;
import com.sun.star.awt.XWindowPeer;
import com.sun.star.awt.XToolkit;
import com.sun.star.awt.XSystemChildFactory;
import com.sun.star.awt.WindowDescriptor;
import com.sun.star.awt.WindowClass;
import com.sun.star.awt.WindowAttribute;
import com.sun.star.awt.VclWindowPeerAttribute;

import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.AnyConverter;
import com.sun.star.uno.Any;

import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.lang.XSingleServiceFactory;

class WindowHelper {

    public static XWindow createWindow( XMultiServiceFactory xFactory, NativeView aParent, java.awt.Rectangle aBounds )
    {
        XWindow  xWindow = null;
        XToolkit    xToolkit = null;

        // get access to toolkit of remote office to create the container window of new target frame
        try{
            xToolkit = (XToolkit)UnoRuntime.queryInterface( XToolkit.class,
                                                            xFactory.createInstance("com.sun.star.awt.Toolkit") );
        }
        catch( Exception ex )
        {
            return null;
        }

        XSystemChildFactory xChildFactory = (XSystemChildFactory)UnoRuntime.queryInterface(
                XSystemChildFactory.class,
                xToolkit);

        try
        {
            XWindowPeer xPeer = null;
            Integer nHandle = aParent.getHWND();
            short   nSystem = (short)aParent.getNativeWindowSystemType();
            byte[]  lProcID = new byte[0];
/*
            try {
                xPeer = xChildFactory.createSystemChild((Object)nHandle, lProcID, nSystem);
            }
            catch( Exception e )
            {}
*/
            if (xPeer==null)
            {
                JavaWindowPeerFake aWrapper = new JavaWindowPeerFake(aParent);

                XWindowPeer xParentPeer = (XWindowPeer)UnoRuntime.queryInterface(
                        XWindowPeer.class,
                        aWrapper);

                WindowDescriptor aDescriptor = new WindowDescriptor();
                aDescriptor.Type = WindowClass.TOP;
                aDescriptor.WindowServiceName = "workwindow";
                aDescriptor.ParentIndex = 1;
                aDescriptor.Parent = xParentPeer;
                aDescriptor.Bounds = new com.sun.star.awt.Rectangle( (int)aBounds.getX(),
                                                                     (int)aBounds.getY(),
                                                                     (int)aBounds.getWidth(),
                                                                     (int)aBounds.getHeight() );

                System.out.println( "The rectangle for vcl window is:\nx = " + (int)aBounds.getX()
                                                                + "; y = " + (int)aBounds.getY()
                                                                + "; width = " + (int)aBounds.getWidth()
                                                                + "; height = " + (int)aBounds.getHeight() );

                if (nSystem == com.sun.star.lang.SystemDependent.SYSTEM_WIN32)
                    aDescriptor.WindowAttributes = WindowAttribute.SHOW;
                else
                    aDescriptor.WindowAttributes = WindowAttribute.SYSTEMDEPENDENT;

                aDescriptor.WindowAttributes |= VclWindowPeerAttribute.CLIPCHILDREN;

                xPeer = xToolkit.createWindow( aDescriptor );
            }

            xWindow = (XWindow)UnoRuntime.queryInterface( XWindow.class, xPeer);
            if ( xWindow != null )
                xWindow.setPosSize( (int)aBounds.getX(),
                                    (int)aBounds.getY(),
                                    (int)aBounds.getWidth(),
                                    (int)aBounds.getHeight(),
                                    com.sun.star.awt.PosSize.POSSIZE );
        }
        catch( Exception ex1 )
        {
            System.out.println( "Exception on VCL window creation: " + ex1 );
            xWindow = null;
        }

        return xWindow;
    }

    public static XBitmap getVCLBitmapFromBytes( XMultiServiceFactory xFactory, Object aAny )
    {
        if ( !AnyConverter.isArray( aAny ) )
            throw new com.sun.star.uno.RuntimeException();

        Object[] aArgs = new Object[1];
        aArgs[0] = aAny;
        XBitmap xResult = null;

        try {
            XSingleServiceFactory xBitmapFactory = (XSingleServiceFactory)UnoRuntime.queryInterface(
                    XSingleServiceFactory.class,
                    xFactory.createInstance( "com.sun.star.embed.BitmapCreator" ) );

            xResult = (XBitmap)UnoRuntime.queryInterface(
                    XBitmap.class,
                    xBitmapFactory.createInstanceWithArguments( aArgs ) );
        }
        catch( Exception e )
        {
            System.out.println( "Could not create VCL bitmap based on sequence," );
            System.out.println( "exception: " + e );
        }

        return xResult;
    }
};