Merge from the pain train
[official-gcc.git] / libjava / gnu / java / awt / peer / gtk / GtkWindowPeer.java
blobeabe59140a6d66a43859876ab4f14cffb125a494
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., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 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 int getWidth ()
68 return awtComponent.getWidth();
71 int getHeight ()
73 return awtComponent.getHeight();
76 native void create (int type, boolean decorated, GtkWindowPeer parent);
78 void create (int type, boolean decorated)
80 GtkWindowPeer parent_peer = null;
81 Component parent = awtComponent.getParent();
83 if (parent != null)
84 parent_peer = (GtkWindowPeer) awtComponent.getParent().getPeer();
86 create (type, decorated, parent_peer);
89 void create ()
91 // Create a normal undecorated window.
92 create (GDK_WINDOW_TYPE_HINT_NORMAL, false);
95 void setParent ()
97 setVisible (awtComponent.isVisible ());
98 setEnabled (awtComponent.isEnabled ());
101 void setVisibleAndEnabled ()
105 native void connectSignals ();
107 public GtkWindowPeer (Window window)
109 super (window);
112 public native void toBack();
113 public native void toFront();
115 native void nativeSetBounds (int x, int y, int width, int height);
117 public void setBounds (int x, int y, int width, int height)
119 nativeSetBounds (x, y,
120 width - insets.left - insets.right,
121 height - insets.top - insets.bottom);
124 public void setTitle (String title)
126 gtkWindowSetTitle (title);
129 native void setSize (int width, int height);
131 public void setResizable (boolean resizable)
133 // Call setSize; otherwise when resizable is changed from true to
134 // false the window will shrink to the dimensions it had before it
135 // was resizable.
136 setSize (awtComponent.getWidth() - insets.left - insets.right,
137 awtComponent.getHeight() - insets.top - insets.bottom);
138 gtkWindowSetResizable (resizable);
141 native void setBoundsCallback (Window window,
142 int x, int y,
143 int width, int height);
145 protected void postInsetsChangedEvent (int top, int left,
146 int bottom, int right)
148 insets.top = top;
149 insets.left = left;
150 insets.bottom = bottom;
151 insets.right = right;
154 protected void postConfigureEvent (int x, int y, int width, int height)
156 int frame_x = x - insets.left;
157 int frame_y = y - insets.top;
158 int frame_width = width + insets.left + insets.right;
159 int frame_height = height + insets.top + insets.bottom;
161 if (frame_x != awtComponent.getX()
162 || frame_y != awtComponent.getY()
163 || frame_width != awtComponent.getWidth()
164 || frame_height != awtComponent.getHeight())
166 setBoundsCallback ((Window) awtComponent,
167 frame_x, frame_y, frame_width, frame_height);
169 awtComponent.validate();
173 native void nativeSetVisible (boolean b);
174 public void setVisible (boolean b)
176 // Prevent the window manager from automatically placing this
177 // window when it is shown.
178 if (b)
179 setBounds (awtComponent.getX(),
180 awtComponent.getY(),
181 awtComponent.getWidth(),
182 awtComponent.getHeight());
183 nativeSetVisible (b);
186 void postWindowEvent (int id, Window opposite, int newState)
188 if (id == WindowEvent.WINDOW_OPENED)
190 // Post a WINDOW_OPENED event the first time this window is shown.
191 if (!hasBeenShown)
193 q().postEvent (new WindowEvent ((Window) awtComponent, id,
194 opposite));
195 hasBeenShown = true;
198 else if (id == WindowEvent.WINDOW_STATE_CHANGED)
200 if (oldState != newState)
202 q().postEvent (new WindowEvent ((Window) awtComponent, id, opposite,
203 oldState, newState));
204 oldState = newState;
207 else
208 q().postEvent (new WindowEvent ((Window) awtComponent, id, opposite));