Dead
[official-gcc.git] / gomp-20050608-branch / libjava / classpath / gnu / java / awt / peer / gtk / GtkFramePeer.java
blob99cca0cffa7dbcc3940897b0bc4c3cd0f23f376d
1 /* GtkFramePeer.java -- Implements FramePeer with GTK
2 Copyright (C) 1999, 2002, 2004 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.Frame;
42 import java.awt.Graphics;
43 import java.awt.Image;
44 import java.awt.MenuBar;
45 import java.awt.Rectangle;
46 import java.awt.Window;
47 import java.awt.event.ComponentEvent;
48 import java.awt.event.PaintEvent;
49 import java.awt.image.ColorModel;
50 import java.awt.peer.FramePeer;
51 import java.awt.peer.MenuBarPeer;
53 public class GtkFramePeer extends GtkWindowPeer
54 implements FramePeer
56 private int menuBarHeight;
57 private MenuBarPeer menuBar;
58 native int getMenuBarHeight (MenuBarPeer bar);
59 native void setMenuBarWidthUnlocked (MenuBarPeer bar, int width);
60 native void setMenuBarWidth (MenuBarPeer bar, int width);
61 native void setMenuBarPeer (MenuBarPeer bar);
62 native void removeMenuBarPeer ();
63 native void gtkFixedSetVisible (boolean visible);
65 int getMenuBarHeight ()
67 return menuBar == null ? 0 : getMenuBarHeight (menuBar);
70 public void setMenuBar (MenuBar bar)
72 if (bar == null && menuBar != null)
74 // We're removing the menubar.
75 gtkFixedSetVisible (false);
76 menuBar = null;
77 removeMenuBarPeer ();
78 insets.top -= menuBarHeight;
79 menuBarHeight = 0;
80 awtComponent.validate ();
81 gtkFixedSetVisible (true);
83 else if (bar != null && menuBar == null)
85 // We're adding a menubar where there was no menubar before.
86 gtkFixedSetVisible (false);
87 menuBar = (MenuBarPeer) ((MenuBar) bar).getPeer();
88 setMenuBarPeer (menuBar);
89 int menuBarWidth =
90 awtComponent.getWidth () - insets.left - insets.right;
91 if (menuBarWidth > 0)
92 setMenuBarWidth (menuBar, menuBarWidth);
93 menuBarHeight = getMenuBarHeight ();
94 insets.top += menuBarHeight;
95 awtComponent.validate ();
96 gtkFixedSetVisible (true);
98 else if (bar != null && menuBar != null)
100 // We're swapping the menubar.
101 gtkFixedSetVisible (false);
102 removeMenuBarPeer();
103 int oldHeight = menuBarHeight;
104 int menuBarWidth =
105 awtComponent.getWidth () - insets.left - insets.right;
106 menuBar = (MenuBarPeer) ((MenuBar) bar).getPeer ();
107 setMenuBarPeer (menuBar);
108 if (menuBarWidth > 0)
109 setMenuBarWidth (menuBar, menuBarWidth);
110 menuBarHeight = getMenuBarHeight ();
111 if (oldHeight != menuBarHeight)
113 insets.top += (menuBarHeight - oldHeight);
114 awtComponent.validate ();
116 gtkFixedSetVisible (true);
120 public void setBounds (int x, int y, int width, int height)
122 // prevent window_configure_cb -> awtComponent.setSize ->
123 // peer.setBounds -> nativeSetBounds self-deadlock on GDK lock.
124 if (Thread.currentThread() == GtkToolkit.mainThread)
126 int menuBarWidth = width - insets.left - insets.right;
127 if (menuBar != null && menuBarWidth > 0)
128 setMenuBarWidthUnlocked (menuBar, menuBarWidth);
130 return;
133 int menuBarWidth = width - insets.left - insets.right;
134 if (menuBar != null && menuBarWidth > 0)
135 setMenuBarWidth (menuBar, menuBarWidth);
137 nativeSetBounds (x, y,
138 width - insets.left - insets.right,
139 height - insets.top - insets.bottom
140 + menuBarHeight);
143 public void setResizable (boolean resizable)
145 // Call setSize; otherwise when resizable is changed from true to
146 // false the frame will shrink to the dimensions it had before it
147 // was resizable.
148 setSize (awtComponent.getWidth() - insets.left - insets.right,
149 awtComponent.getHeight() - insets.top - insets.bottom
150 + menuBarHeight);
151 gtkWindowSetResizable (resizable);
154 protected void postInsetsChangedEvent (int top, int left,
155 int bottom, int right)
157 insets.top = top + menuBarHeight;
158 insets.left = left;
159 insets.bottom = bottom;
160 insets.right = right;
163 public GtkFramePeer (Frame frame)
165 super (frame);
168 void create ()
170 // Create a normal decorated window.
171 create (GDK_WINDOW_TYPE_HINT_NORMAL,
172 !((Frame) awtComponent).isUndecorated ());
174 Frame frame = (Frame) awtComponent;
176 setMenuBar (frame.getMenuBar ());
178 setTitle (frame.getTitle ());
179 gtkWindowSetResizable (frame.isResizable ());
180 setIconImage(frame.getIconImage());
183 native void nativeSetIconImage (GtkImage image);
185 public void setIconImage (Image image)
187 if (image != null)
189 if (image instanceof GtkImage)
190 nativeSetIconImage((GtkImage) image);
191 else
192 nativeSetIconImage(new GtkImage(image.getSource()));
196 public Graphics getGraphics ()
198 Graphics g;
199 if (GtkToolkit.useGraphics2D ())
200 g = new GdkGraphics2D (this);
201 else
202 g = new GdkGraphics (this);
203 g.translate (-insets.left, -insets.top);
204 return g;
207 protected void postConfigureEvent (int x, int y, int width, int height)
209 int frame_width = width + insets.left + insets.right;
210 // Since insets.top already includes the MenuBar's height, we need
211 // to subtract the MenuBar's height from the top inset.
212 int frame_height = height + insets.top + insets.bottom - menuBarHeight;
214 if (frame_width != awtComponent.getWidth()
215 || frame_height != awtComponent.getHeight())
216 awtComponent.setSize(frame_width, frame_height);
218 int frame_x = x - insets.left;
219 // Likewise, since insets.top includes the MenuBar height, we need
220 // to add back the MenuBar height to the frame's y position. If
221 // no MenuBar exists in this frame, the MenuBar height will be 0.
222 int frame_y = y - insets.top + menuBarHeight;
224 if (frame_x != awtComponent.getX()
225 || frame_y != awtComponent.getY())
227 // awtComponent.setLocation(frame_x, frame_y);
231 protected void postMouseEvent(int id, long when, int mods, int x, int y,
232 int clickCount, boolean popupTrigger)
234 super.postMouseEvent (id, when, mods,
235 x + insets.left, y + insets.top,
236 clickCount, popupTrigger);
239 protected void postExposeEvent (int x, int y, int width, int height)
241 if (!isInRepaint)
242 q().postEvent (new PaintEvent (awtComponent, PaintEvent.PAINT,
243 new Rectangle (x + insets.left,
244 y + insets.top,
245 width, height)));
248 public int getState ()
250 return 0;
253 public void setState (int state)
258 public void setMaximizedBounds (Rectangle r)
262 public void setBoundsPrivate(int x, int y, int width, int height)
264 // TODO Auto-generated method stub
267 public void updateAlwaysOnTop()
269 // TODO Auto-generated method stub
272 public boolean requestWindowFocus()
274 // TODO Auto-generated method stub
275 return false;