58 super(params);
59 }
60
61 void preInit(XCreateWindowParams params) {
62 super.preInit(params);
63 Frame target = (Frame)(this.target);
64 // set the window attributes for this Frame
65 winAttr.initialState = target.getExtendedState();
66 state = 0;
67 undecorated = Boolean.valueOf(target.isUndecorated());
68 winAttr.nativeDecor = !target.isUndecorated();
69 if (winAttr.nativeDecor) {
70 winAttr.decorations = winAttr.AWT_DECOR_ALL;
71 } else {
72 winAttr.decorations = winAttr.AWT_DECOR_NONE;
73 }
74 winAttr.functions = MWMConstants.MWM_FUNC_ALL;
75 winAttr.isResizable = true; // target.isResizable();
76 winAttr.title = target.getTitle();
77 winAttr.initialResizability = target.isResizable();
78 if (log.isLoggable(PlatformLogger.FINE)) {
79 log.fine("Frame''s initial attributes: decor {0}, resizable {1}, undecorated {2}, initial state {3}",
80 Integer.valueOf(winAttr.decorations), Boolean.valueOf(winAttr.initialResizability),
81 Boolean.valueOf(!winAttr.nativeDecor), Integer.valueOf(winAttr.initialState));
82 }
83 }
84
85 void postInit(XCreateWindowParams params) {
86 super.postInit(params);
87 setupState(true);
88 }
89
90 @Override
91 boolean isTargetUndecorated() {
92 if (undecorated != null) {
93 return undecorated.booleanValue();
94 } else {
95 return ((Frame)target).isUndecorated();
96 }
97 }
98
192 if (height != lastAppliedMenubarHeight) {
193 lastAppliedMenubarHeight = height;
194 heightChanged = true;
195 }
196 }
197 if (heightChanged) {
198 // To make frame contents be re-layout (copied from
199 // 'XDecoratedPeer.revalidate()'). These are not
200 // 'synchronized', because can recursively call client
201 // methods, which are not supposed to be called with locks
202 // acquired.
203 target.invalidate();
204 target.validate();
205 }
206 }
207 }
208 );
209 }
210
211 public void setMaximizedBounds(Rectangle b) {
212 if (insLog.isLoggable(PlatformLogger.FINE)) {
213 insLog.fine("Setting maximized bounds to " + b);
214 }
215 if (b == null) return;
216 maxBounds = new Rectangle(b);
217 XToolkit.awtLock();
218 try {
219 XSizeHints hints = getHints();
220 hints.set_flags(hints.get_flags() | (int)XUtilConstants.PMaxSize);
221 if (b.width != Integer.MAX_VALUE) {
222 hints.set_max_width(b.width);
223 } else {
224 hints.set_max_width((int)XlibWrapper.DisplayWidth(XToolkit.getDisplay(), XlibWrapper.DefaultScreen(XToolkit.getDisplay())));
225 }
226 if (b.height != Integer.MAX_VALUE) {
227 hints.set_max_height(b.height);
228 } else {
229 hints.set_max_height((int)XlibWrapper.DisplayHeight(XToolkit.getDisplay(), XlibWrapper.DefaultScreen(XToolkit.getDisplay())));
230 }
231 if (insLog.isLoggable(PlatformLogger.FINER)) {
232 insLog.finer("Setting hints, flags " + XlibWrapper.hintsToString(hints.get_flags()));
233 }
234 XlibWrapper.XSetWMNormalHints(XToolkit.getDisplay(), window, hints.pData);
235 } finally {
236 XToolkit.awtUnlock();
237 }
238 }
239
240 public int getState() {
241 synchronized(getStateLock()) {
242 return state;
243 }
244 }
245
246 public void setState(int newState) {
247 synchronized(getStateLock()) {
248 if (!isShowing()) {
249 stateLog.finer("Frame is not showing");
250 state = newState;
251 return;
252 }
253 }
254 changeState(newState);
255 }
256
257 void changeState(int newState) {
258 int changed = state ^ newState;
259 int changeIconic = changed & Frame.ICONIFIED;
260 boolean iconic = (newState & Frame.ICONIFIED) != 0;
261 if (stateLog.isLoggable(PlatformLogger.FINER)) {
262 stateLog.finer("Changing state, old state {0}, new state {1}(iconic {2})",
263 Integer.valueOf(state), Integer.valueOf(newState), Boolean.valueOf(iconic));
264 }
265 if (changeIconic != 0 && iconic) {
266 if (stateLog.isLoggable(PlatformLogger.FINER)) {
267 stateLog.finer("Iconifying shell " + getShell() + ", this " + this + ", screen " + getScreenNumber());
268 }
269 XToolkit.awtLock();
270 try {
271 int res = XlibWrapper.XIconifyWindow(XToolkit.getDisplay(), getShell(), getScreenNumber());
272 if (stateLog.isLoggable(PlatformLogger.FINER)) {
273 stateLog.finer("XIconifyWindow returned " + res);
274 }
275 }
276 finally {
277 XToolkit.awtUnlock();
278 }
279 }
280 if ((changed & ~Frame.ICONIFIED) != 0) {
281 setExtendedState(newState);
282 }
283 if (changeIconic != 0 && !iconic) {
284 if (stateLog.isLoggable(PlatformLogger.FINER)) {
285 stateLog.finer("DeIconifying " + this);
286 }
287 xSetVisible(true);
288 }
289 }
290
291 void setExtendedState(int newState) {
292 XWM.getWM().setExtendedState(this, newState);
293 }
294
295 public void handlePropertyNotify(XEvent xev) {
296 super.handlePropertyNotify(xev);
297 XPropertyEvent ev = xev.get_xproperty();
298
299 if (log.isLoggable(PlatformLogger.FINER)) {
300 log.finer("Property change {0}", ev);
301 }
302 /*
303 * Let's see if this is a window state protocol message, and
304 * if it is - decode a new state in terms of java constants.
305 */
306 if (!XWM.getWM().isStateChange(this, ev)) {
307 stateLog.finer("either not a state atom or state has not been changed");
308 return;
309 }
310
311 final int newState = XWM.getWM().getState(this);
312 int changed = state ^ newState;
313 if (changed == 0) {
314 if (stateLog.isLoggable(PlatformLogger.FINER)) {
315 stateLog.finer("State is the same: " + state);
316 }
317 return;
318 }
319
320 int old_state = state;
321 state = newState;
322
323 // sync target with peer
324 AWTAccessor.getFrameAccessor().setExtendedState((Frame)target, state);
325
326 if ((changed & Frame.ICONIFIED) != 0) {
327 if ((state & Frame.ICONIFIED) != 0) {
328 stateLog.finer("Iconified");
329 handleIconify();
330 } else {
331 stateLog.finer("DeIconified");
332 content.purgeIconifiedExposeEvents();
333 handleDeiconify();
334 }
348 public void setVisible(boolean vis) {
349 if (vis) {
350 setupState(false);
351 } else {
352 if ((state & Frame.MAXIMIZED_BOTH) != 0) {
353 XWM.getWM().setExtendedState(this, state & ~Frame.MAXIMIZED_BOTH);
354 }
355 }
356 super.setVisible(vis);
357 if (vis && maxBounds != null) {
358 setMaximizedBounds(maxBounds);
359 }
360 }
361
362 void setInitialState(int wm_state) {
363 XToolkit.awtLock();
364 try {
365 XWMHints hints = getWMHints();
366 hints.set_flags((int)XUtilConstants.StateHint | hints.get_flags());
367 hints.set_initial_state(wm_state);
368 if (stateLog.isLoggable(PlatformLogger.FINE)) {
369 stateLog.fine("Setting initial WM state on " + this + " to " + wm_state);
370 }
371 XlibWrapper.XSetWMHints(XToolkit.getDisplay(), getWindow(), hints.pData);
372 }
373 finally {
374 XToolkit.awtUnlock();
375 }
376 }
377
378 public void dispose() {
379 if (menubarPeer != null) {
380 menubarPeer.dispose();
381 }
382 super.dispose();
383 }
384
385 boolean isMaximized() {
386 return (state & (Frame.MAXIMIZED_VERT | Frame.MAXIMIZED_HORIZ)) != 0;
387 }
388
|
58 super(params);
59 }
60
61 void preInit(XCreateWindowParams params) {
62 super.preInit(params);
63 Frame target = (Frame)(this.target);
64 // set the window attributes for this Frame
65 winAttr.initialState = target.getExtendedState();
66 state = 0;
67 undecorated = Boolean.valueOf(target.isUndecorated());
68 winAttr.nativeDecor = !target.isUndecorated();
69 if (winAttr.nativeDecor) {
70 winAttr.decorations = winAttr.AWT_DECOR_ALL;
71 } else {
72 winAttr.decorations = winAttr.AWT_DECOR_NONE;
73 }
74 winAttr.functions = MWMConstants.MWM_FUNC_ALL;
75 winAttr.isResizable = true; // target.isResizable();
76 winAttr.title = target.getTitle();
77 winAttr.initialResizability = target.isResizable();
78 if (log.isLoggable(PlatformLogger.Level.FINE)) {
79 log.fine("Frame''s initial attributes: decor {0}, resizable {1}, undecorated {2}, initial state {3}",
80 Integer.valueOf(winAttr.decorations), Boolean.valueOf(winAttr.initialResizability),
81 Boolean.valueOf(!winAttr.nativeDecor), Integer.valueOf(winAttr.initialState));
82 }
83 }
84
85 void postInit(XCreateWindowParams params) {
86 super.postInit(params);
87 setupState(true);
88 }
89
90 @Override
91 boolean isTargetUndecorated() {
92 if (undecorated != null) {
93 return undecorated.booleanValue();
94 } else {
95 return ((Frame)target).isUndecorated();
96 }
97 }
98
192 if (height != lastAppliedMenubarHeight) {
193 lastAppliedMenubarHeight = height;
194 heightChanged = true;
195 }
196 }
197 if (heightChanged) {
198 // To make frame contents be re-layout (copied from
199 // 'XDecoratedPeer.revalidate()'). These are not
200 // 'synchronized', because can recursively call client
201 // methods, which are not supposed to be called with locks
202 // acquired.
203 target.invalidate();
204 target.validate();
205 }
206 }
207 }
208 );
209 }
210
211 public void setMaximizedBounds(Rectangle b) {
212 if (insLog.isLoggable(PlatformLogger.Level.FINE)) {
213 insLog.fine("Setting maximized bounds to " + b);
214 }
215 if (b == null) return;
216 maxBounds = new Rectangle(b);
217 XToolkit.awtLock();
218 try {
219 XSizeHints hints = getHints();
220 hints.set_flags(hints.get_flags() | (int)XUtilConstants.PMaxSize);
221 if (b.width != Integer.MAX_VALUE) {
222 hints.set_max_width(b.width);
223 } else {
224 hints.set_max_width((int)XlibWrapper.DisplayWidth(XToolkit.getDisplay(), XlibWrapper.DefaultScreen(XToolkit.getDisplay())));
225 }
226 if (b.height != Integer.MAX_VALUE) {
227 hints.set_max_height(b.height);
228 } else {
229 hints.set_max_height((int)XlibWrapper.DisplayHeight(XToolkit.getDisplay(), XlibWrapper.DefaultScreen(XToolkit.getDisplay())));
230 }
231 if (insLog.isLoggable(PlatformLogger.Level.FINER)) {
232 insLog.finer("Setting hints, flags " + XlibWrapper.hintsToString(hints.get_flags()));
233 }
234 XlibWrapper.XSetWMNormalHints(XToolkit.getDisplay(), window, hints.pData);
235 } finally {
236 XToolkit.awtUnlock();
237 }
238 }
239
240 public int getState() {
241 synchronized(getStateLock()) {
242 return state;
243 }
244 }
245
246 public void setState(int newState) {
247 synchronized(getStateLock()) {
248 if (!isShowing()) {
249 stateLog.finer("Frame is not showing");
250 state = newState;
251 return;
252 }
253 }
254 changeState(newState);
255 }
256
257 void changeState(int newState) {
258 int changed = state ^ newState;
259 int changeIconic = changed & Frame.ICONIFIED;
260 boolean iconic = (newState & Frame.ICONIFIED) != 0;
261 if (stateLog.isLoggable(PlatformLogger.Level.FINER)) {
262 stateLog.finer("Changing state, old state {0}, new state {1}(iconic {2})",
263 Integer.valueOf(state), Integer.valueOf(newState), Boolean.valueOf(iconic));
264 }
265 if (changeIconic != 0 && iconic) {
266 if (stateLog.isLoggable(PlatformLogger.Level.FINER)) {
267 stateLog.finer("Iconifying shell " + getShell() + ", this " + this + ", screen " + getScreenNumber());
268 }
269 XToolkit.awtLock();
270 try {
271 int res = XlibWrapper.XIconifyWindow(XToolkit.getDisplay(), getShell(), getScreenNumber());
272 if (stateLog.isLoggable(PlatformLogger.Level.FINER)) {
273 stateLog.finer("XIconifyWindow returned " + res);
274 }
275 }
276 finally {
277 XToolkit.awtUnlock();
278 }
279 }
280 if ((changed & ~Frame.ICONIFIED) != 0) {
281 setExtendedState(newState);
282 }
283 if (changeIconic != 0 && !iconic) {
284 if (stateLog.isLoggable(PlatformLogger.Level.FINER)) {
285 stateLog.finer("DeIconifying " + this);
286 }
287 xSetVisible(true);
288 }
289 }
290
291 void setExtendedState(int newState) {
292 XWM.getWM().setExtendedState(this, newState);
293 }
294
295 public void handlePropertyNotify(XEvent xev) {
296 super.handlePropertyNotify(xev);
297 XPropertyEvent ev = xev.get_xproperty();
298
299 if (log.isLoggable(PlatformLogger.Level.FINER)) {
300 log.finer("Property change {0}", ev);
301 }
302 /*
303 * Let's see if this is a window state protocol message, and
304 * if it is - decode a new state in terms of java constants.
305 */
306 if (!XWM.getWM().isStateChange(this, ev)) {
307 stateLog.finer("either not a state atom or state has not been changed");
308 return;
309 }
310
311 final int newState = XWM.getWM().getState(this);
312 int changed = state ^ newState;
313 if (changed == 0) {
314 if (stateLog.isLoggable(PlatformLogger.Level.FINER)) {
315 stateLog.finer("State is the same: " + state);
316 }
317 return;
318 }
319
320 int old_state = state;
321 state = newState;
322
323 // sync target with peer
324 AWTAccessor.getFrameAccessor().setExtendedState((Frame)target, state);
325
326 if ((changed & Frame.ICONIFIED) != 0) {
327 if ((state & Frame.ICONIFIED) != 0) {
328 stateLog.finer("Iconified");
329 handleIconify();
330 } else {
331 stateLog.finer("DeIconified");
332 content.purgeIconifiedExposeEvents();
333 handleDeiconify();
334 }
348 public void setVisible(boolean vis) {
349 if (vis) {
350 setupState(false);
351 } else {
352 if ((state & Frame.MAXIMIZED_BOTH) != 0) {
353 XWM.getWM().setExtendedState(this, state & ~Frame.MAXIMIZED_BOTH);
354 }
355 }
356 super.setVisible(vis);
357 if (vis && maxBounds != null) {
358 setMaximizedBounds(maxBounds);
359 }
360 }
361
362 void setInitialState(int wm_state) {
363 XToolkit.awtLock();
364 try {
365 XWMHints hints = getWMHints();
366 hints.set_flags((int)XUtilConstants.StateHint | hints.get_flags());
367 hints.set_initial_state(wm_state);
368 if (stateLog.isLoggable(PlatformLogger.Level.FINE)) {
369 stateLog.fine("Setting initial WM state on " + this + " to " + wm_state);
370 }
371 XlibWrapper.XSetWMHints(XToolkit.getDisplay(), getWindow(), hints.pData);
372 }
373 finally {
374 XToolkit.awtUnlock();
375 }
376 }
377
378 public void dispose() {
379 if (menubarPeer != null) {
380 menubarPeer.dispose();
381 }
382 super.dispose();
383 }
384
385 boolean isMaximized() {
386 return (state & (Frame.MAXIMIZED_VERT | Frame.MAXIMIZED_HORIZ)) != 0;
387 }
388
|