Merge from mainline.
[official-gcc.git] / libjava / classpath / gnu / java / awt / peer / gtk / GtkFramePeer.java
blob6ec0b72982bde587d4c1185d2c0c165d3ce927bc
1 /* GtkFramePeer.java -- Implements FramePeer with GTK
2 Copyright (C) 1999, 2002, 2004, 2006 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.event.PaintEvent;
47 import java.awt.peer.FramePeer;
48 import java.awt.peer.MenuBarPeer;
50 public class GtkFramePeer extends GtkWindowPeer
51 implements FramePeer
53 private int menuBarHeight;
54 private MenuBarPeer menuBar;
55 native int getMenuBarHeight (MenuBarPeer bar);
56 native void setMenuBarWidthUnlocked (MenuBarPeer bar, int width);
57 native void setMenuBarWidth (MenuBarPeer bar, int width);
58 native void setMenuBarPeer (MenuBarPeer bar);
59 native void removeMenuBarPeer ();
60 native void gtkFixedSetVisible (boolean visible);
62 int getMenuBarHeight ()
64 return menuBar == null ? 0 : getMenuBarHeight (menuBar);
67 public void setMenuBar (MenuBar bar)
69 if (bar == null && menuBar != null)
71 // We're removing the menubar.
72 gtkFixedSetVisible (false);
73 menuBar = null;
74 removeMenuBarPeer ();
75 insets.top -= menuBarHeight;
76 menuBarHeight = 0;
77 // if component has already been validated, we need to revalidate.
78 // otherwise, it will be validated when it is shown.
79 if (awtComponent.isValid())
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 // if component has already been validated, we need to revalidate.
96 // otherwise, it will be validated when it is shown.
97 if (awtComponent.isValid())
98 awtComponent.validate ();
99 gtkFixedSetVisible (true);
101 else if (bar != null && menuBar != null)
103 // We're swapping the menubar.
104 gtkFixedSetVisible (false);
105 removeMenuBarPeer();
106 int oldHeight = menuBarHeight;
107 int menuBarWidth =
108 awtComponent.getWidth () - insets.left - insets.right;
109 menuBar = (MenuBarPeer) ((MenuBar) bar).getPeer ();
110 setMenuBarPeer (menuBar);
111 if (menuBarWidth > 0)
112 setMenuBarWidth (menuBar, menuBarWidth);
113 menuBarHeight = getMenuBarHeight ();
114 if (oldHeight != menuBarHeight)
116 insets.top += (menuBarHeight - oldHeight);
117 awtComponent.validate ();
119 gtkFixedSetVisible (true);
123 public void setBounds (int x, int y, int width, int height)
125 int menuBarWidth = width - insets.left - insets.right;
126 if (menuBar != null && menuBarWidth > 0)
127 setMenuBarWidth (menuBar, menuBarWidth);
129 super.setBounds(x, y, width, height + menuBarHeight);
132 public void setResizable (boolean resizable)
134 // Call setSize; otherwise when resizable is changed from true to
135 // false the frame will shrink to the dimensions it had before it
136 // was resizable.
137 setSize (awtComponent.getWidth() - insets.left - insets.right,
138 awtComponent.getHeight() - insets.top - insets.bottom
139 + menuBarHeight);
140 gtkWindowSetResizable (resizable);
143 protected void postInsetsChangedEvent (int top, int left,
144 int bottom, int right)
146 insets.top = top + menuBarHeight;
147 insets.left = left;
148 insets.bottom = bottom;
149 insets.right = right;
152 public GtkFramePeer (Frame frame)
154 super (frame);
157 void create ()
159 // Create a normal decorated window.
160 create (GDK_WINDOW_TYPE_HINT_NORMAL,
161 !((Frame) awtComponent).isUndecorated ());
163 Frame frame = (Frame) awtComponent;
165 setMenuBar (frame.getMenuBar ());
167 setTitle (frame.getTitle ());
168 gtkWindowSetResizable (frame.isResizable ());
169 setIconImage(frame.getIconImage());
172 native void nativeSetIconImage (GtkImage image);
174 public void setIconImage (Image image)
176 if (image != null)
178 if (image instanceof GtkImage)
179 nativeSetIconImage((GtkImage) image);
180 else
181 nativeSetIconImage(new GtkImage(image.getSource()));
185 protected void postConfigureEvent (int x, int y, int width, int height)
187 if (menuBar != null && width > 0)
188 setMenuBarWidthUnlocked (menuBar, width);
190 // Since insets.top already includes the MenuBar's height, we need
191 // to subtract the MenuBar's height from the top inset.
192 int frame_height = height - menuBarHeight;
194 // Likewise, since insets.top includes the MenuBar height, we need
195 // to add back the MenuBar height to the frame's y position. If
196 // no MenuBar exists in this frame, the MenuBar height will be 0.
197 int frame_y = y + menuBarHeight;
199 super.postConfigureEvent(x, frame_y, width, frame_height);
202 public int getState ()
204 return 0;
207 public void setState (int state)
212 public void setMaximizedBounds (Rectangle r)
216 public void setBoundsPrivate(int x, int y, int width, int height)
218 // TODO Auto-generated method stub
221 public void updateAlwaysOnTop()
223 // TODO Auto-generated method stub
226 public boolean requestWindowFocus()
228 // TODO Auto-generated method stub
229 return false;