2004-10-07 Michael Koch <konqueror@gmx.de>
[official-gcc.git] / libjava / gnu / java / awt / peer / gtk / GtkWindowPeer.java
blob1bdac28f62884ac72001ff67a79affbead8f1db0
1 /* GtkWindowPeer.java -- Implements WindowPeer with GTK
2 Copyright (C) 1998, 1999, 2002 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.Dimension;
43 import java.awt.Frame;
44 import java.awt.Window;
45 import java.awt.event.WindowEvent;
46 import java.awt.peer.WindowPeer;
48 public class GtkWindowPeer extends GtkContainerPeer
49 implements WindowPeer
51 static protected final int GDK_WINDOW_TYPE_HINT_NORMAL = 0;
52 static protected final int GDK_WINDOW_TYPE_HINT_DIALOG = 1;
53 static protected final int GDK_WINDOW_TYPE_HINT_MENU = 2;
54 static protected final int GDK_WINDOW_TYPE_HINT_TOOLBAR = 3;
55 static protected final int GDK_WINDOW_TYPE_HINT_SPLASHSCREEN = 4;
56 static protected final int GDK_WINDOW_TYPE_HINT_UTILITY = 5;
57 static protected final int GDK_WINDOW_TYPE_HINT_DOCK = 6;
58 static protected final int GDK_WINDOW_TYPE_HINT_DESKTOP = 7;
60 private boolean hasBeenShown = false;
61 private int oldState = Frame.NORMAL;
63 native void gtkWindowSetTitle (String title);
64 native void gtkWindowSetResizable (boolean resizable);
65 native void gtkWindowSetModal (boolean modal);
67 native void create (int type, boolean decorated,
68 int width, int height,
69 GtkWindowPeer parent,
70 int[] insets);
72 void create (int type, boolean decorated)
74 GtkWindowPeer parent_peer = null;
75 Component parent = awtComponent.getParent();
76 int[] insets = new int [] { 0, 0, 0, 0 };
78 if (parent != null)
79 parent_peer = (GtkWindowPeer) awtComponent.getParent().getPeer();
81 create (type, decorated,
82 awtComponent.getWidth(),
83 awtComponent.getHeight(),
84 parent_peer,
85 insets);
87 this.insets.top = insets [0];
88 this.insets.left = insets [1];
89 this.insets.bottom = insets [2];
90 this.insets.right = insets [3];
93 void create ()
95 // Create a normal undecorated window.
96 create (GDK_WINDOW_TYPE_HINT_NORMAL, false);
99 void setParent ()
101 setVisible (awtComponent.isVisible ());
102 setEnabled (awtComponent.isEnabled ());
105 void setVisibleAndEnabled ()
109 native void connectJObject ();
110 native void connectSignals ();
112 public GtkWindowPeer (Window window)
114 super (window);
117 native public void toBack ();
118 native public void toFront ();
120 native void nativeSetBounds (int x, int y, int width, int height);
122 public void setBounds (int x, int y, int width, int height)
124 nativeSetBounds (x, y,
125 width - insets.left - insets.right,
126 height - insets.top - insets.bottom);
129 public void setTitle (String title)
131 gtkWindowSetTitle (title);
134 native void setSize (int width, int height);
136 public void setResizable (boolean resizable)
138 // Call setSize; otherwise when resizable is changed from true to
139 // false the window will shrink to the dimensions it had before it
140 // was resizable.
141 setSize (awtComponent.getWidth() - insets.left - insets.right,
142 awtComponent.getHeight() - insets.top - insets.bottom);
143 gtkWindowSetResizable (resizable);
146 native void setBoundsCallback (Window window,
147 int x, int y,
148 int width, int height);
150 protected void postInsetsChangedEvent (int top, int left,
151 int bottom, int right)
153 insets.top = top;
154 insets.left = left;
155 insets.bottom = bottom;
156 insets.right = right;
159 protected void postConfigureEvent (int x, int y, int width, int height)
161 int frame_x = x - insets.left;
162 int frame_y = y - insets.top;
163 int frame_width = width + insets.left + insets.right;
164 int frame_height = height + insets.top + insets.bottom;
166 if (frame_x != awtComponent.getX()
167 || frame_y != awtComponent.getY()
168 || frame_width != awtComponent.getWidth()
169 || frame_height != awtComponent.getHeight())
170 setBoundsCallback ((Window) awtComponent,
171 frame_x, frame_y, frame_width, frame_height);
173 awtComponent.validate();
176 native void nativeSetVisible (boolean b);
177 public void setVisible (boolean b)
179 // Prevent the window manager from automatically placing this
180 // window when it is shown.
181 if (b)
182 setBounds (awtComponent.getX(),
183 awtComponent.getY(),
184 awtComponent.getWidth(),
185 awtComponent.getHeight());
186 nativeSetVisible (b);
189 void postWindowEvent (int id, Window opposite, int newState)
191 if (id == WindowEvent.WINDOW_OPENED)
193 // Post a WINDOW_OPENED event the first time this window is shown.
194 if (!hasBeenShown)
196 q.postEvent (new WindowEvent ((Window) awtComponent, id,
197 opposite));
198 hasBeenShown = true;
201 else if (id == WindowEvent.WINDOW_STATE_CHANGED)
203 if (oldState != newState)
205 q.postEvent (new WindowEvent ((Window) awtComponent, id, opposite,
206 oldState, newState));
207 oldState = newState;
210 else
211 q.postEvent (new WindowEvent ((Window) awtComponent, id, opposite));