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