1 /*************************************************************************
3 * $RCSfile: NativeView.java,v $
7 * last change: $Author: rt $ $Date: 2005-01-31 16:39:23 $
9 * The Contents of this file are made available subject to the terms of
12 * Copyright (c) 2003 by Sun Microsystems, Inc.
13 * All rights reserved.
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions
18 * 1. Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in the
22 * documentation and/or other materials provided with the distribution.
23 * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
24 * contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
30 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
31 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
32 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
33 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
34 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
35 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
36 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
37 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 *************************************************************************/
41 // __________ Imports __________
45 import java
.awt
.event
.*;
47 // __________ Implementation __________
50 * Class to pass the system window handle to the OpenOffice.org toolkit.
51 * It use special JNI methods to get the system handle of used java window.
54 * Use JNI functions on already visible canvas objects only!
55 * Otherwise they can make some trouble.
57 * @author Andreas Schlüns
58 * @created 22.02.2002 08:47
61 public class NativeView
extends java
.awt
.Canvas
63 // ____________________
68 * We can use our JNI mechanism for an already visible
69 * canvas only. So we overload the method for showing ("setVisible()")
70 * and make our intialization there. BUt we try to show an empty clean
77 this.setBackground(Color
.white
);
80 // ____________________
83 * Overload this method to make neccessary initializations here.
84 * (e.g. get the window handle and neccessary system informations)
87 * Because the handle seams to be available for already visible windows
88 * only. So it's the best place to get it. Special helper method
89 * can be called more then ones - but call native code one times only
90 * and safe the handle and the system type on our members maHandle/maSystem!
92 public void setVisible(boolean bState
)
97 // ____________________
100 * to guarantee right resize handling inside a swing container
101 * (e.g. JSplitPane) we must provide some informations about our
102 * prefered/minimum and maximum size.
104 public Dimension
getPreferredSize()
106 return new Dimension(500,300);
109 public Dimension
getMaximumSize()
111 return new Dimension(1024,768);
114 public Dimension
getMinimumSize()
116 return new Dimension(100,100);
119 // ____________________
122 * overload paint routine to show provide against
123 * repaint errors if no office view is realy plugged
125 * If handle is present - we shouldn't paint anything further.
126 * May the remote window is already plugged. In such case we
127 * shouldn't paint it over.
129 public void paint(Graphics aGraphic
)
133 Dimension aSize
= getSize();
134 aGraphic
.clearRect(0,0,aSize
.width
,aSize
.height
);
138 // ____________________
141 * JNI interface of this class
142 * These two methods are implemented by using JNI mechanismen.
143 * The will be used to get the platform dependent window handle
144 * of a java awt canvas. This handle can be used to create an office
145 * window as direct child of it. So it's possible to plug Office
146 * windows in a java UI container.
149 * Native code for windows register special function pointer to handle
150 * window messages ... But if it doesn't check for an already registered
151 * instance of this handler it will do it twice and produce a stack overflow
152 * because such method call herself in a never ending loop ...
153 * So we try to use the JNI code one times only and safe already getted
154 * informations inside this class.
156 public native int getNativeWindowSystemType();
157 private native long getNativeWindow(); // private! => use getHWND() with cache mechanism!
159 public Integer
getHWND()
163 maHandle
= new Integer((int)getNativeWindow());
164 maSystem
= getNativeWindowSystemType();
169 // ____________________
172 * for using of the JNI methods it's neccessary to load
173 * system library which exports it.
177 System
.loadLibrary("nativeview");
180 // ____________________
183 * @member maHandle system window handle
184 * @member maSystem info about currently used platform
186 public Integer maHandle
;
187 public int maSystem
;