1:
37:
38:
39: package ;
40:
41: import ;
42: import ;
43: import ;
44: import ;
45: import ;
46:
47: public class GtkWindowPeer extends GtkContainerPeer
48: implements WindowPeer
49: {
50: protected static final int GDK_WINDOW_TYPE_HINT_NORMAL = 0;
51: protected static final int GDK_WINDOW_TYPE_HINT_DIALOG = 1;
52: protected static final int GDK_WINDOW_TYPE_HINT_MENU = 2;
53: protected static final int GDK_WINDOW_TYPE_HINT_TOOLBAR = 3;
54: protected static final int GDK_WINDOW_TYPE_HINT_SPLASHSCREEN = 4;
55: protected static final int GDK_WINDOW_TYPE_HINT_UTILITY = 5;
56: protected static final int GDK_WINDOW_TYPE_HINT_DOCK = 6;
57: protected static final int GDK_WINDOW_TYPE_HINT_DESKTOP = 7;
58:
59: private boolean hasBeenShown = false;
60: private int oldState = Frame.NORMAL;
61:
62: native void gtkWindowSetTitle (String title);
63: native void gtkWindowSetResizable (boolean resizable);
64: native void gtkWindowSetModal (boolean modal);
65:
66: native void realize ();
67:
68: int getWidth ()
69: {
70: return awtComponent.getWidth();
71: }
72:
73: int getHeight ()
74: {
75: return awtComponent.getHeight();
76: }
77:
78: native void create (int type, boolean decorated, GtkWindowPeer parent);
79:
80: void create (int type, boolean decorated)
81: {
82: Window window = (Window) awtComponent;
83: GtkWindowPeer parent_peer = null;
84: Component parent = awtComponent.getParent();
85:
86: if (!window.isFocusableWindow())
87: type = GDK_WINDOW_TYPE_HINT_MENU;
88:
89: if (parent != null)
90: parent_peer = (GtkWindowPeer) awtComponent.getParent().getPeer();
91:
92: create (type, decorated, parent_peer);
93: }
94:
95: void create ()
96: {
97:
98: create (GDK_WINDOW_TYPE_HINT_NORMAL, false);
99: }
100:
101: void setParent ()
102: {
103: setVisible (awtComponent.isVisible ());
104: setEnabled (awtComponent.isEnabled ());
105: }
106:
107: void setVisibleAndEnabled ()
108: {
109: }
110:
111: public native void setVisibleNative (boolean b);
112: public native void setVisibleNativeUnlocked (boolean b);
113:
114: native void connectSignals ();
115:
116: public GtkWindowPeer (Window window)
117: {
118: super (window);
119: }
120:
121: public native void toBack();
122: public native void toFront();
123:
124: native void nativeSetBounds (int x, int y, int width, int height);
125: native void nativeSetBoundsUnlocked (int x, int y, int width, int height);
126:
127: public void setBounds (int x, int y, int width, int height)
128: {
129:
130:
131: if (Thread.currentThread() == GtkToolkit.mainThread)
132: return;
133:
134: nativeSetBounds (x, y,
135: width - insets.left - insets.right,
136: height - insets.top - insets.bottom);
137: }
138:
139: public void setBoundsUnlocked (int x, int y, int width, int height)
140: {
141: nativeSetBoundsUnlocked (x, y,
142: width - insets.left - insets.right,
143: height - insets.top - insets.bottom);
144: }
145:
146: public void setTitle (String title)
147: {
148: gtkWindowSetTitle (title);
149: }
150:
151: native void setSize (int width, int height);
152:
153: public void setResizable (boolean resizable)
154: {
155:
156:
157:
158: setSize (awtComponent.getWidth() - insets.left - insets.right,
159: awtComponent.getHeight() - insets.top - insets.bottom);
160: gtkWindowSetResizable (resizable);
161: }
162:
163: protected void postInsetsChangedEvent (int top, int left,
164: int bottom, int right)
165: {
166: insets.top = top;
167: insets.left = left;
168: insets.bottom = bottom;
169: insets.right = right;
170: }
171:
172:
173:
174: protected void postConfigureEvent (int x, int y, int width, int height)
175: {
176: int frame_width = width + insets.left + insets.right;
177: int frame_height = height + insets.top + insets.bottom;
178:
179: if (frame_width != awtComponent.getWidth()
180: || frame_height != awtComponent.getHeight())
181: awtComponent.setSize(frame_width, frame_height);
182:
183: int frame_x = x - insets.left;
184: int frame_y = y - insets.top;
185:
186: if (frame_x != awtComponent.getX()
187: || frame_y != awtComponent.getY())
188: {
189:
190: }
191: }
192:
193: public void show ()
194: {
195:
196:
197: setBounds (awtComponent.getX(),
198: awtComponent.getY(),
199: awtComponent.getWidth(),
200: awtComponent.getHeight());
201: setVisible (true);
202: }
203:
204: void postWindowEvent (int id, Window opposite, int newState)
205: {
206: if (id == WindowEvent.WINDOW_OPENED)
207: {
208:
209: if (!hasBeenShown)
210: {
211: q().postEvent (new WindowEvent ((Window) awtComponent, id,
212: opposite));
213: hasBeenShown = true;
214: }
215: }
216: else if (id == WindowEvent.WINDOW_STATE_CHANGED)
217: {
218: if (oldState != newState)
219: {
220: q().postEvent (new WindowEvent ((Window) awtComponent, id, opposite,
221: oldState, newState));
222: oldState = newState;
223: }
224: }
225: else
226: q().postEvent (new WindowEvent ((Window) awtComponent, id, opposite));
227: }
228: public void updateAlwaysOnTop()
229: {
230:
231:
232: }
233: public boolean requestWindowFocus()
234: {
235:
236: return false;
237: }
238: }