Remove old autovect-branch by moving to "dead" directory.
[official-gcc.git] / old-autovect-branch / libjava / classpath / gnu / java / awt / peer / gtk / GtkWindowPeer.java
blob57fb87f37bfe837803d2ccfd0a1933e0a0d403c7
1 /* GtkWindowPeer.java -- Implements WindowPeer with GTK
2 Copyright (C) 1998, 1999, 2002, 2005 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 package gnu.java.awt.peer.gtk;
41 import java.awt.Component;
42 import java.awt.Frame;
43 import java.awt.Window;
44 import java.awt.event.WindowEvent;
45 import java.awt.peer.WindowPeer;
47 public class GtkWindowPeer extends GtkContainerPeer
48 implements WindowPeer
50 protected static final int GDK_WINDOW_TYPE_HINT_NORMAL = 0;
51 protected static final int GDK_WINDOW_TYPE_HINT_DIALOG = 1;
52 protected static final int GDK_WINDOW_TYPE_HINT_MENU = 2;
53 protected static final int GDK_WINDOW_TYPE_HINT_TOOLBAR = 3;
54 protected static final int GDK_WINDOW_TYPE_HINT_SPLASHSCREEN = 4;
55 protected static final int GDK_WINDOW_TYPE_HINT_UTILITY = 5;
56 protected static final int GDK_WINDOW_TYPE_HINT_DOCK = 6;
57 protected static final int GDK_WINDOW_TYPE_HINT_DESKTOP = 7;
59 private boolean hasBeenShown = false;
60 private int oldState = Frame.NORMAL;
62 native void gtkWindowSetTitle (String title);
63 native void gtkWindowSetResizable (boolean resizable);
64 native void gtkWindowSetModal (boolean modal);
66 native void realize ();
68 int getWidth ()
70 return awtComponent.getWidth();
73 int getHeight ()
75 return awtComponent.getHeight();
78 native void create (int type, boolean decorated, GtkWindowPeer parent);
80 void create (int type, boolean decorated)
82 Window window = (Window) awtComponent;
83 GtkWindowPeer parent_peer = null;
84 Component parent = awtComponent.getParent();
86 if (!window.isFocusableWindow())
87 type = GDK_WINDOW_TYPE_HINT_MENU;
89 if (parent != null)
90 parent_peer = (GtkWindowPeer) awtComponent.getParent().getPeer();
92 create (type, decorated, parent_peer);
95 void create ()
97 // Create a normal undecorated window.
98 create (GDK_WINDOW_TYPE_HINT_NORMAL, false);
101 void setParent ()
103 setVisible (awtComponent.isVisible ());
104 setEnabled (awtComponent.isEnabled ());
107 void setVisibleAndEnabled ()
111 public native void setVisibleNative (boolean b);
112 public native void setVisibleNativeUnlocked (boolean b);
114 native void connectSignals ();
116 public GtkWindowPeer (Window window)
118 super (window);
121 public native void toBack();
122 public native void toFront();
124 native void nativeSetBounds (int x, int y, int width, int height);
125 native void nativeSetBoundsUnlocked (int x, int y, int width, int height);
127 public void setBounds (int x, int y, int width, int height)
129 // prevent window_configure_cb -> awtComponent.setSize ->
130 // peer.setBounds -> nativeSetBounds self-deadlock on GDK lock.
131 if (Thread.currentThread() == GtkToolkit.mainThread)
132 return;
134 nativeSetBounds (x, y,
135 width - insets.left - insets.right,
136 height - insets.top - insets.bottom);
139 public void setBoundsUnlocked (int x, int y, int width, int height)
141 nativeSetBoundsUnlocked (x, y,
142 width - insets.left - insets.right,
143 height - insets.top - insets.bottom);
146 public void setTitle (String title)
148 gtkWindowSetTitle (title);
151 native void setSize (int width, int height);
153 public void setResizable (boolean resizable)
155 // Call setSize; otherwise when resizable is changed from true to
156 // false the window will shrink to the dimensions it had before it
157 // was resizable.
158 setSize (awtComponent.getWidth() - insets.left - insets.right,
159 awtComponent.getHeight() - insets.top - insets.bottom);
160 gtkWindowSetResizable (resizable);
163 protected void postInsetsChangedEvent (int top, int left,
164 int bottom, int right)
166 insets.top = top;
167 insets.left = left;
168 insets.bottom = bottom;
169 insets.right = right;
172 // called back by native side: window_configure_cb
173 // only called from GTK thread
174 protected void postConfigureEvent (int x, int y, int width, int height)
176 int frame_width = width + insets.left + insets.right;
177 int frame_height = height + insets.top + insets.bottom;
179 if (frame_width != awtComponent.getWidth()
180 || frame_height != awtComponent.getHeight())
181 awtComponent.setSize(frame_width, frame_height);
183 int frame_x = x - insets.left;
184 int frame_y = y - insets.top;
186 if (frame_x != awtComponent.getX()
187 || frame_y != awtComponent.getY())
189 // awtComponent.setLocation(frame_x, frame_y);
193 public void show ()
195 // Prevent the window manager from automatically placing this
196 // window when it is shown.
197 setBounds (awtComponent.getX(),
198 awtComponent.getY(),
199 awtComponent.getWidth(),
200 awtComponent.getHeight());
201 setVisible (true);
204 void postWindowEvent (int id, Window opposite, int newState)
206 if (id == WindowEvent.WINDOW_OPENED)
208 // Post a WINDOW_OPENED event the first time this window is shown.
209 if (!hasBeenShown)
211 q().postEvent (new WindowEvent ((Window) awtComponent, id,
212 opposite));
213 hasBeenShown = true;
216 else if (id == WindowEvent.WINDOW_STATE_CHANGED)
218 if (oldState != newState)
220 q().postEvent (new WindowEvent ((Window) awtComponent, id, opposite,
221 oldState, newState));
222 oldState = newState;
225 else
226 q().postEvent (new WindowEvent ((Window) awtComponent, id, opposite));
228 public void updateAlwaysOnTop()
230 // TODO Auto-generated method stub
233 public boolean requestWindowFocus()
235 // TODO Auto-generated method stub
236 return false;