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: int getMenuBarHeight ()
61: {
62: return menuBar == null ? 0 : getMenuBarHeight (menuBar);
63: }
64:
65: public void setMenuBar (MenuBar bar)
66: {
67: if (bar == null && menuBar != null)
68: {
69:
70: gtkFixedSetVisible (false);
71: menuBar = null;
72: removeMenuBarPeer ();
73: insets.top -= menuBarHeight;
74: menuBarHeight = 0;
75:
76:
77: if (awtComponent.isValid())
78: awtComponent.validate ();
79: gtkFixedSetVisible (true);
80: }
81: else if (bar != null && menuBar == null)
82: {
83:
84: gtkFixedSetVisible (false);
85: menuBar = (MenuBarPeer) ((MenuBar) bar).getPeer();
86: setMenuBarPeer (menuBar);
87: int menuBarWidth =
88: awtComponent.getWidth () - insets.left - insets.right;
89: if (menuBarWidth > 0)
90: setMenuBarWidth (menuBar, menuBarWidth);
91: menuBarHeight = getMenuBarHeight ();
92: insets.top += menuBarHeight;
93:
94:
95: if (awtComponent.isValid())
96: awtComponent.validate ();
97: gtkFixedSetVisible (true);
98: }
99: else if (bar != null && menuBar != null)
100: {
101:
102: gtkFixedSetVisible (false);
103: removeMenuBarPeer();
104: int oldHeight = menuBarHeight;
105: int menuBarWidth =
106: awtComponent.getWidth () - insets.left - insets.right;
107: menuBar = (MenuBarPeer) ((MenuBar) bar).getPeer ();
108: setMenuBarPeer (menuBar);
109: if (menuBarWidth > 0)
110: setMenuBarWidth (menuBar, menuBarWidth);
111: menuBarHeight = getMenuBarHeight ();
112: if (oldHeight != menuBarHeight)
113: {
114: insets.top += (menuBarHeight - oldHeight);
115: awtComponent.validate ();
116: }
117: gtkFixedSetVisible (true);
118: }
119: }
120:
121: public void setBounds (int x, int y, int width, int height)
122: {
123: int menuBarWidth = width - insets.left - insets.right;
124: if (menuBar != null && menuBarWidth > 0)
125: setMenuBarWidth (menuBar, menuBarWidth);
126:
127: super.setBounds(x, y, width, height + menuBarHeight);
128: }
129:
130: public void setResizable (boolean resizable)
131: {
132:
133:
134:
135: setSize (awtComponent.getWidth() - insets.left - insets.right,
136: awtComponent.getHeight() - insets.top - insets.bottom
137: + menuBarHeight);
138: gtkWindowSetResizable (resizable);
139: }
140:
141: protected void postInsetsChangedEvent (int top, int left,
142: int bottom, int right)
143: {
144: insets.top = top + menuBarHeight;
145: insets.left = left;
146: insets.bottom = bottom;
147: insets.right = right;
148: }
149:
150: public GtkFramePeer (Frame frame)
151: {
152: super (frame);
153: }
154:
155: void create ()
156: {
157:
158: create (GDK_WINDOW_TYPE_HINT_NORMAL,
159: !((Frame) awtComponent).isUndecorated ());
160:
161: Frame frame = (Frame) awtComponent;
162:
163: setMenuBar (frame.getMenuBar ());
164:
165: setTitle (frame.getTitle ());
166: gtkWindowSetResizable (frame.isResizable ());
167: setIconImage(frame.getIconImage());
168: }
169:
170: native void nativeSetIconImage (GtkImage image);
171:
172: public void setIconImage (Image image)
173: {
174: if (image != null)
175: {
176: if (image instanceof GtkImage)
177: nativeSetIconImage((GtkImage) image);
178: else
179: nativeSetIconImage(new GtkImage(image.getSource()));
180: }
181: }
182:
183: protected void postConfigureEvent (int x, int y, int width, int height)
184: {
185: if (menuBar != null && width > 0)
186: setMenuBarWidthUnlocked (menuBar, width);
187:
188:
189:
190: int frame_height = height - menuBarHeight;
191:
192:
193:
194:
195: int frame_y = y + menuBarHeight;
196:
197: super.postConfigureEvent(x, frame_y, width, frame_height);
198: }
199:
200: public int getState ()
201: {
202: return 0;
203: }
204:
205: public void setState (int state)
206: {
207:
208: }
209:
210: public void setMaximizedBounds (Rectangle r)
211: {
212:
213: }
214: public void setBoundsPrivate(int x, int y, int width, int height)
215: {
216:
217:
218: }
219:
220: public boolean requestWindowFocus()
221: {
222:
223: return false;
224: }
225: }
226: