1:
37:
38:
39: package ;
40:
41: import ;
42: import ;
43: import ;
44: import ;
45: import ;
46: import ;
47:
48: public class GtkFramePeer extends GtkWindowPeer
49: implements FramePeer
50: {
51: private int menuBarHeight;
52: private MenuBarPeer menuBar;
53: native int getMenuBarHeight (MenuBarPeer bar);
54: native void setMenuBarWidthUnlocked (MenuBarPeer bar, int width);
55: native void setMenuBarWidth (MenuBarPeer bar, int width);
56: native void setMenuBarPeer (MenuBarPeer bar);
57: native void removeMenuBarPeer ();
58: native void gtkFixedSetVisible (boolean visible);
59:
60: private native void maximize();
61: private native void unmaximize();
62: private native void iconify();
63: private native void deiconify();
64:
65: int getMenuBarHeight ()
66: {
67: return menuBar == null ? 0 : getMenuBarHeight (menuBar);
68: }
69:
70: public void setMenuBar (MenuBar bar)
71: {
72: if (bar == null && menuBar != null)
73: {
74:
75: gtkFixedSetVisible (false);
76: menuBar = null;
77: removeMenuBarPeer ();
78: insets.top -= menuBarHeight;
79: menuBarHeight = 0;
80:
81:
82: if (awtComponent.isValid())
83: awtComponent.validate ();
84: gtkFixedSetVisible (true);
85: }
86: else if (bar != null && menuBar == null)
87: {
88:
89: gtkFixedSetVisible (false);
90: menuBar = (MenuBarPeer) bar.getPeer();
91: setMenuBarPeer (menuBar);
92: int menuBarWidth =
93: awtComponent.getWidth () - insets.left - insets.right;
94: if (menuBarWidth > 0)
95: setMenuBarWidth (menuBar, menuBarWidth);
96: menuBarHeight = getMenuBarHeight ();
97: insets.top += menuBarHeight;
98:
99:
100: if (awtComponent.isValid())
101: awtComponent.validate ();
102: gtkFixedSetVisible (true);
103: }
104: else if (bar != null && menuBar != null)
105: {
106:
107: gtkFixedSetVisible (false);
108: removeMenuBarPeer();
109: int oldHeight = menuBarHeight;
110: int menuBarWidth =
111: awtComponent.getWidth () - insets.left - insets.right;
112: menuBar = (MenuBarPeer) bar.getPeer ();
113: setMenuBarPeer (menuBar);
114: if (menuBarWidth > 0)
115: setMenuBarWidth (menuBar, menuBarWidth);
116: menuBarHeight = getMenuBarHeight ();
117: if (oldHeight != menuBarHeight)
118: {
119: insets.top += (menuBarHeight - oldHeight);
120: awtComponent.validate ();
121: }
122: gtkFixedSetVisible (true);
123: }
124: }
125:
126: public void setBounds (int x, int y, int width, int height)
127: {
128: int menuBarWidth = width - insets.left - insets.right;
129: if (menuBar != null && menuBarWidth > 0)
130: setMenuBarWidth (menuBar, menuBarWidth);
131:
132: super.setBounds(x, y, width, height + menuBarHeight);
133: }
134:
135: public void setResizable (boolean resizable)
136: {
137:
138:
139:
140: setSize (awtComponent.getWidth() - insets.left - insets.right,
141: awtComponent.getHeight() - insets.top - insets.bottom
142: + menuBarHeight);
143: gtkWindowSetResizable (resizable);
144: }
145:
146: protected void postInsetsChangedEvent (int top, int left,
147: int bottom, int right)
148: {
149: insets.top = top + menuBarHeight;
150: insets.left = left;
151: insets.bottom = bottom;
152: insets.right = right;
153: }
154:
155: public GtkFramePeer (Frame frame)
156: {
157: super (frame);
158: }
159:
160: void create ()
161: {
162:
163: create (GDK_WINDOW_TYPE_HINT_NORMAL,
164: !((Frame) awtComponent).isUndecorated ());
165:
166: Frame frame = (Frame) awtComponent;
167:
168: setMenuBar (frame.getMenuBar ());
169:
170: setTitle (frame.getTitle ());
171: gtkWindowSetResizable (frame.isResizable ());
172: setIconImage(frame.getIconImage());
173: }
174:
175: native void nativeSetIconImage (GtkImage image);
176:
177: public void setIconImage (Image image)
178: {
179: if (image != null)
180: {
181: GtkImage gtkImage;
182: if (image instanceof GtkImage)
183: gtkImage = (GtkImage) image;
184: else
185: gtkImage = new GtkImage(image.getSource());
186:
187: if (gtkImage.isLoaded && ! gtkImage.errorLoading)
188: nativeSetIconImage(gtkImage);
189: }
190: }
191:
192: protected void postConfigureEvent (int x, int y, int width, int height)
193: {
194: if (menuBar != null && width > 0)
195: setMenuBarWidthUnlocked (menuBar, width);
196:
197:
198:
199: int frame_height = height - menuBarHeight;
200:
201:
202:
203:
204: int frame_y = y + menuBarHeight;
205:
206: super.postConfigureEvent(x, frame_y, width, frame_height);
207: }
208:
209: public int getState ()
210: {
211: return windowState;
212: }
213:
214: public void setState (int state)
215: {
216: switch (state)
217: {
218: case Frame.NORMAL:
219: if ((windowState & Frame.ICONIFIED) != 0)
220: deiconify();
221: if ((windowState & Frame.MAXIMIZED_BOTH) != 0)
222: unmaximize();
223: break;
224: case Frame.ICONIFIED:
225: iconify();
226: break;
227: case Frame.MAXIMIZED_BOTH:
228: maximize();
229: }
230: }
231:
232: public void setMaximizedBounds (Rectangle r)
233: {
234:
235: }
236: public void setBoundsPrivate(int x, int y, int width, int height)
237: {
238:
239:
240: }
241:
242: public boolean requestWindowFocus()
243: {
244:
245: return false;
246: }
247:
248: public Rectangle getBoundsPrivate()
249: {
250:
251: throw new InternalError("Not yet implemented");
252: }
253:
254: }