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