1:
37:
38:
39: package ;
40:
41: import ;
42: import ;
43: import ;
44: import ;
45: import ;
46: import ;
47: import ;
48: import ;
49: import ;
50: import ;
51: import ;
52:
53: public class GtkWindowPeer extends GtkContainerPeer
54: implements WindowPeer
55: {
56: protected static final int GDK_WINDOW_TYPE_HINT_NORMAL = 0;
57: protected static final int GDK_WINDOW_TYPE_HINT_DIALOG = 1;
58: protected static final int GDK_WINDOW_TYPE_HINT_MENU = 2;
59: protected static final int GDK_WINDOW_TYPE_HINT_TOOLBAR = 3;
60: protected static final int GDK_WINDOW_TYPE_HINT_SPLASHSCREEN = 4;
61: protected static final int GDK_WINDOW_TYPE_HINT_UTILITY = 5;
62: protected static final int GDK_WINDOW_TYPE_HINT_DOCK = 6;
63: protected static final int GDK_WINDOW_TYPE_HINT_DESKTOP = 7;
64:
65: private boolean hasBeenShown = false;
66: private int oldState = Frame.NORMAL;
67:
68:
69: private int x, y, width, height;
70:
71: native void gtkWindowSetTitle (String title);
72: native void gtkWindowSetResizable (boolean resizable);
73: native void gtkWindowSetModal (boolean modal);
74: native void gtkWindowSetAlwaysOnTop ( boolean alwaysOnTop );
75: native boolean gtkWindowHasFocus();
76: native void realize ();
77:
78:
79: int getX ()
80: {
81: return x;
82: }
83:
84:
85: int getY ()
86: {
87: return y;
88: }
89:
90:
91: int getWidth ()
92: {
93: return width;
94: }
95:
96:
97: int getHeight ()
98: {
99: return height;
100: }
101:
102: native void create (int type, boolean decorated, GtkWindowPeer parent);
103:
104: void create (int type, boolean decorated)
105: {
106: Window window = (Window) awtComponent;
107: GtkWindowPeer parent_peer = null;
108: Component parent = awtComponent.getParent();
109: x = awtComponent.getX();
110: y = awtComponent.getY();
111: height = awtComponent.getHeight();
112: width = awtComponent.getWidth();
113:
114: if (!window.isFocusableWindow())
115: type = GDK_WINDOW_TYPE_HINT_MENU;
116:
117: if (parent != null)
118: parent_peer = (GtkWindowPeer) awtComponent.getParent().getPeer();
119:
120: create (type, decorated, parent_peer);
121: }
122:
123: void create ()
124: {
125:
126: create (GDK_WINDOW_TYPE_HINT_NORMAL, false);
127: }
128:
129: void setParent ()
130: {
131: setVisible (awtComponent.isVisible ());
132: setEnabled (awtComponent.isEnabled ());
133: }
134:
135: void setVisibleAndEnabled ()
136: {
137: }
138:
139: public native void setVisibleNative (boolean b);
140: public native void setVisibleNativeUnlocked (boolean b);
141:
142: native void connectSignals ();
143:
144: public GtkWindowPeer (Window window)
145: {
146: super (window);
147: }
148:
149: public native void toBack();
150: public native void toFront();
151:
152: native void nativeSetBounds (int x, int y, int width, int height);
153: native void nativeSetBoundsUnlocked (int x, int y, int width, int height);
154: native void nativeSetLocation (int x, int y);
155: native void nativeSetLocationUnlocked (int x, int y);
156:
157:
158: protected void setLocation (int x, int y)
159: {
160: nativeSetLocation (x, y);
161: }
162:
163: public void setBounds (int x, int y, int width, int height)
164: {
165: if (x != getX()
166: || y != getY()
167: || width != getWidth()
168: || height != getHeight())
169: {
170: this.x = x;
171: this.y = y;
172: this.width = width;
173: this.height = height;
174:
175: nativeSetBounds (x, y,
176: width - insets.left - insets.right,
177: height - insets.top - insets.bottom);
178: }
179: }
180:
181: public void setTitle (String title)
182: {
183: gtkWindowSetTitle (title);
184: }
185:
186:
187: protected native void setSize (int width, int height);
188:
189:
194: public void setResizable (boolean resizable)
195: {
196:
197:
198:
199: x = awtComponent.getX();
200: y = awtComponent.getY();
201: width = awtComponent.getWidth();
202: height = awtComponent.getHeight();
203: setSize (width - insets.left - insets.right,
204: height - insets.top - insets.bottom);
205: gtkWindowSetResizable (resizable);
206: }
207:
208: protected void postInsetsChangedEvent (int top, int left,
209: int bottom, int right)
210: {
211: insets.top = top;
212: insets.left = left;
213: insets.bottom = bottom;
214: insets.right = right;
215: }
216:
217:
218:
219: protected void postConfigureEvent (int x, int y, int width, int height)
220: {
221: int frame_width = width + insets.left + insets.right;
222: int frame_height = height + insets.top + insets.bottom;
223:
224: if (frame_width != getWidth()
225: || frame_height != getHeight())
226: {
227: this.width = frame_width;
228: this.height = frame_height;
229: q().postEvent(new ComponentEvent(awtComponent,
230: ComponentEvent.COMPONENT_RESIZED));
231: }
232:
233: int frame_x = x - insets.left;
234: int frame_y = y - insets.top;
235:
236: if (frame_x != getX()
237: || frame_y != getY())
238: {
239: this.x = frame_x;
240: this.y = frame_y;
241: q().postEvent(new ComponentEvent(awtComponent,
242: ComponentEvent.COMPONENT_MOVED));
243: }
244: }
245:
246: public void show ()
247: {
248: x = awtComponent.getX();
249: y = awtComponent.getY();
250: width = awtComponent.getWidth();
251: height = awtComponent.getHeight();
252: setLocation(x, y);
253: setVisible (true);
254: }
255:
256: void postWindowEvent (int id, Window opposite, int newState)
257: {
258: if (id == WindowEvent.WINDOW_OPENED)
259: {
260:
261: if (!hasBeenShown)
262: {
263: q().postEvent (new WindowEvent ((Window) awtComponent, id,
264: opposite));
265: hasBeenShown = true;
266: }
267: }
268: else if (id == WindowEvent.WINDOW_STATE_CHANGED)
269: {
270: if (oldState != newState)
271: {
272: q().postEvent (new WindowEvent ((Window) awtComponent, id, opposite,
273: oldState, newState));
274: oldState = newState;
275: }
276: }
277: else
278: q().postEvent (new WindowEvent ((Window) awtComponent, id, opposite));
279: }
280:
281:
284: public void updateAlwaysOnTop()
285: {
286: gtkWindowSetAlwaysOnTop( ((Window)awtComponent).isAlwaysOnTop() );
287: }
288:
289: protected void postExposeEvent (int x, int y, int width, int height)
290: {
291:
292:
293:
294:
295:
296: q().postEvent (new PaintEvent (awtComponent, PaintEvent.PAINT,
297: new Rectangle (x + insets.left,
298: y + insets.top,
299: width, height)));
300: }
301:
302: public boolean requestWindowFocus()
303: {
304:
305: return false;
306: }
307:
308: public boolean requestFocus (Component request, boolean temporary,
309: boolean allowWindowFocus, long time)
310: {
311: assert request == awtComponent || isLightweightDescendant(request);
312: boolean retval = false;
313: if (gtkWindowHasFocus())
314: {
315: KeyboardFocusManager kfm =
316: KeyboardFocusManager.getCurrentKeyboardFocusManager();
317: Component currentFocus = kfm.getFocusOwner();
318: if (currentFocus == request)
319:
320: retval = true;
321: else
322: {
323:
324:
325:
326:
327: postFocusEvent(FocusEvent.FOCUS_GAINED, temporary);
328: retval = true;
329: }
330: }
331: else
332: {
333: if (allowWindowFocus)
334: {
335: retval = requestWindowFocus();
336: }
337: }
338: return retval;
339: }
340:
341: public Graphics getGraphics ()
342: {
343: Graphics g = super.getGraphics ();
344:
345:
346:
347:
348:
349: g.translate (-insets.left, -insets.top);
350: return g;
351: }
352:
353: protected void updateComponent (PaintEvent event)
354: {
355:
356:
357: paintComponent(event);
358: }
359:
360: protected void postMouseEvent(int id, long when, int mods, int x, int y,
361: int clickCount, boolean popupTrigger)
362: {
363:
364:
365:
366:
367:
368: super.postMouseEvent (id, when, mods,
369: x + insets.left, y + insets.top,
370: clickCount, popupTrigger);
371: }
372:
373:
374:
375: public Rectangle getBounds()
376: {
377: return new Rectangle(x, y, width, height);
378: }
379: }