author | yan |
Mon, 06 Oct 2008 16:45:00 +0400 | |
changeset 1966 | 12a51fb0db0d |
parent 449 | 7820f232278d |
child 1977 | 3a9980ccb120 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
420
diff
changeset
|
2 |
* Copyright 2002-2008 Sun Microsystems, Inc. All Rights Reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Sun designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Sun in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or |
|
23 |
* have any questions. |
|
24 |
*/ |
|
25 |
package sun.awt.X11; |
|
26 |
||
27 |
import java.awt.*; |
|
28 |
||
29 |
import java.awt.event.ComponentEvent; |
|
30 |
import java.awt.event.InvocationEvent; |
|
31 |
import java.awt.event.WindowEvent; |
|
32 |
||
33 |
import java.util.logging.Level; |
|
34 |
import java.util.logging.Logger; |
|
35 |
||
36 |
import sun.awt.ComponentAccessor; |
|
37 |
import sun.awt.SunToolkit; |
|
38 |
||
129
f995b9c9c5fa
6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents:
118
diff
changeset
|
39 |
abstract class XDecoratedPeer extends XWindowPeer { |
2 | 40 |
private static final Logger log = Logger.getLogger("sun.awt.X11.XDecoratedPeer"); |
41 |
private static final Logger insLog = Logger.getLogger("sun.awt.X11.insets.XDecoratedPeer"); |
|
42 |
private static final Logger focusLog = Logger.getLogger("sun.awt.X11.focus.XDecoratedPeer"); |
|
449 | 43 |
private static final Logger iconLog = Logger.getLogger("sun.awt.X11.icon.XDecoratedPeer"); |
2 | 44 |
|
45 |
// Set to true when we get the first ConfigureNotify after being |
|
46 |
// reparented - indicates that WM has adopted the top-level. |
|
47 |
boolean configure_seen; |
|
48 |
boolean insets_corrected; |
|
49 |
||
50 |
XIconWindow iconWindow; |
|
51 |
WindowDimensions dimensions; |
|
52 |
XContentWindow content; |
|
53 |
Insets currentInsets; |
|
54 |
XFocusProxyWindow focusProxy; |
|
55 |
||
56 |
XDecoratedPeer(Window target) { |
|
57 |
super(target); |
|
58 |
} |
|
59 |
||
60 |
XDecoratedPeer(XCreateWindowParams params) { |
|
61 |
super(params); |
|
62 |
} |
|
63 |
||
64 |
public long getShell() { |
|
65 |
return window; |
|
66 |
} |
|
67 |
||
68 |
public long getContentWindow() { |
|
69 |
return (content == null) ? window : content.getWindow(); |
|
70 |
} |
|
71 |
||
72 |
void preInit(XCreateWindowParams params) { |
|
73 |
super.preInit(params); |
|
74 |
winAttr.initialFocus = true; |
|
75 |
||
449 | 76 |
currentInsets = new Insets(0,0,0,0); |
77 |
applyGuessedInsets(); |
|
2 | 78 |
|
79 |
Rectangle bounds = (Rectangle)params.get(BOUNDS); |
|
80 |
dimensions = new WindowDimensions(bounds, getRealInsets(), false); |
|
81 |
params.put(BOUNDS, dimensions.getClientRect()); |
|
82 |
insLog.log(Level.FINE, "Initial dimensions {0}", new Object[] { dimensions }); |
|
83 |
||
84 |
// Deny default processing of these events on the shell - proxy will take care of |
|
85 |
// them instead |
|
86 |
Long eventMask = (Long)params.get(EVENT_MASK); |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
420
diff
changeset
|
87 |
params.add(EVENT_MASK, Long.valueOf(eventMask.longValue() & ~(XConstants.FocusChangeMask | XConstants.KeyPressMask | XConstants.KeyReleaseMask))); |
2 | 88 |
} |
89 |
||
90 |
void postInit(XCreateWindowParams params) { |
|
91 |
super.postInit(params); |
|
92 |
// The lines that follow need to be in a postInit, so they |
|
93 |
// happen after the X window is created. |
|
94 |
initResizability(); |
|
95 |
updateSizeHints(dimensions); |
|
449 | 96 |
XWM.requestWMExtents(getWindow()); |
97 |
||
115 | 98 |
content = XContentWindow.createContent(this); |
449 | 99 |
|
2 | 100 |
if (warningWindow != null) { |
101 |
warningWindow.toFront(); |
|
102 |
} |
|
103 |
focusProxy = createFocusProxy(); |
|
104 |
} |
|
105 |
||
106 |
void setIconHints(java.util.List<XIconInfo> icons) { |
|
107 |
if (!XWM.getWM().setNetWMIcon(this, icons)) { |
|
108 |
if (icons.size() > 0) { |
|
109 |
if (iconWindow == null) { |
|
110 |
iconWindow = new XIconWindow(this); |
|
111 |
} |
|
112 |
iconWindow.setIconImages(icons); |
|
113 |
} |
|
114 |
} |
|
115 |
} |
|
116 |
||
117 |
public void updateMinimumSize() { |
|
118 |
super.updateMinimumSize(); |
|
119 |
updateMinSizeHints(); |
|
120 |
} |
|
121 |
||
122 |
private void updateMinSizeHints() { |
|
123 |
if (isResizable()) { |
|
124 |
Dimension minimumSize = getTargetMinimumSize(); |
|
125 |
if (minimumSize != null) { |
|
126 |
Insets insets = getRealInsets(); |
|
127 |
int minWidth = minimumSize.width - insets.left - insets.right; |
|
128 |
int minHeight = minimumSize.height - insets.top - insets.bottom; |
|
129 |
if (minWidth < 0) minWidth = 0; |
|
130 |
if (minHeight < 0) minHeight = 0; |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
420
diff
changeset
|
131 |
setSizeHints(XUtilConstants.PMinSize | (isLocationByPlatform()?0:(XUtilConstants.PPosition | XUtilConstants.USPosition)), |
2 | 132 |
getX(), getY(), minWidth, minHeight); |
133 |
if (isVisible()) { |
|
134 |
Rectangle bounds = getShellBounds(); |
|
135 |
int nw = (bounds.width < minWidth) ? minWidth : bounds.width; |
|
136 |
int nh = (bounds.height < minHeight) ? minHeight : bounds.height; |
|
137 |
if (nw != bounds.width || nh != bounds.height) { |
|
138 |
setShellSize(new Rectangle(0, 0, nw, nh)); |
|
139 |
} |
|
140 |
} |
|
141 |
} else { |
|
142 |
boolean isMinSizeSet = isMinSizeSet(); |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
420
diff
changeset
|
143 |
XWM.removeSizeHints(this, XUtilConstants.PMinSize); |
2 | 144 |
/* Some WMs need remap to redecorate the window */ |
145 |
if (isMinSizeSet && isShowing() && XWM.needRemap(this)) { |
|
146 |
/* |
|
147 |
* Do the re/mapping at the Xlib level. Since we essentially |
|
148 |
* work around a WM bug we don't want this hack to be exposed |
|
149 |
* to Intrinsics (i.e. don't mess with grabs, callbacks etc). |
|
150 |
*/ |
|
151 |
xSetVisible(false); |
|
152 |
XToolkit.XSync(); |
|
153 |
xSetVisible(true); |
|
154 |
} |
|
155 |
} |
|
156 |
} |
|
157 |
} |
|
158 |
||
159 |
XFocusProxyWindow createFocusProxy() { |
|
160 |
return new XFocusProxyWindow(this); |
|
161 |
} |
|
162 |
||
163 |
protected XAtomList getWMProtocols() { |
|
164 |
XAtomList protocols = super.getWMProtocols(); |
|
165 |
protocols.add(wm_delete_window); |
|
166 |
protocols.add(wm_take_focus); |
|
167 |
return protocols; |
|
168 |
} |
|
169 |
||
170 |
public Graphics getGraphics() { |
|
171 |
return getGraphics(content.surfaceData, |
|
172 |
ComponentAccessor.getForeground(target), |
|
173 |
ComponentAccessor.getBackground(target), |
|
174 |
ComponentAccessor.getFont_NoClientCode(target)); |
|
175 |
} |
|
176 |
||
177 |
public void setTitle(String title) { |
|
178 |
if (log.isLoggable(Level.FINE)) log.fine("Title is " + title); |
|
179 |
winAttr.title = title; |
|
180 |
updateWMName(); |
|
181 |
} |
|
182 |
||
183 |
protected String getWMName() { |
|
184 |
if (winAttr.title == null || winAttr.title.trim().equals("")) { |
|
185 |
return " "; |
|
186 |
} else { |
|
187 |
return winAttr.title; |
|
188 |
} |
|
189 |
} |
|
190 |
||
191 |
void updateWMName() { |
|
192 |
super.updateWMName(); |
|
193 |
String name = getWMName(); |
|
194 |
XToolkit.awtLock(); |
|
195 |
try { |
|
196 |
if (name == null || name.trim().equals("")) { |
|
197 |
name = "Java"; |
|
198 |
} |
|
199 |
XAtom iconNameAtom = XAtom.get(XAtom.XA_WM_ICON_NAME); |
|
200 |
iconNameAtom.setProperty(getWindow(), name); |
|
201 |
XAtom netIconNameAtom = XAtom.get("_NET_WM_ICON_NAME"); |
|
202 |
netIconNameAtom.setPropertyUTF8(getWindow(), name); |
|
203 |
} finally { |
|
204 |
XToolkit.awtUnlock(); |
|
205 |
} |
|
206 |
} |
|
207 |
||
208 |
// NOTE: This method may be called by privileged threads. |
|
209 |
// DO NOT INVOKE CLIENT CODE ON THIS THREAD! |
|
210 |
public void handleIconify() { |
|
211 |
postEvent(new WindowEvent((Window)target, WindowEvent.WINDOW_ICONIFIED)); |
|
212 |
} |
|
213 |
||
214 |
// NOTE: This method may be called by privileged threads. |
|
215 |
// DO NOT INVOKE CLIENT CODE ON THIS THREAD! |
|
216 |
public void handleDeiconify() { |
|
217 |
postEvent(new WindowEvent((Window)target, WindowEvent.WINDOW_DEICONIFIED)); |
|
218 |
} |
|
219 |
||
220 |
public void handleFocusEvent(XEvent xev) { |
|
221 |
super.handleFocusEvent(xev); |
|
222 |
XFocusChangeEvent xfe = xev.get_xfocus(); |
|
223 |
||
224 |
// If we somehow received focus events forward it instead to proxy |
|
225 |
// FIXME: Shouldn't we instead check for inferrior? |
|
226 |
focusLog.finer("Received focus event on shell: " + xfe); |
|
227 |
// focusProxy.xRequestFocus(); |
|
228 |
} |
|
229 |
||
230 |
/*************************************************************************************** |
|
231 |
* I N S E T S C O D E |
|
232 |
**************************************************************************************/ |
|
233 |
||
234 |
protected boolean isInitialReshape() { |
|
235 |
return false; |
|
236 |
} |
|
237 |
||
449 | 238 |
private static Insets difference(Insets i1, Insets i2) { |
2 | 239 |
return new Insets(i1.top-i2.top, i1.left - i2.left, i1.bottom-i2.bottom, i1.right-i2.right); |
240 |
} |
|
241 |
||
449 | 242 |
private static boolean isNull(Insets i) { |
2 | 243 |
return (i == null) || ((i.left | i.top | i.right | i.bottom) == 0); |
244 |
} |
|
449 | 245 |
|
246 |
private static Insets copy(Insets i) { |
|
2 | 247 |
return new Insets(i.top, i.left, i.bottom, i.right); |
248 |
} |
|
249 |
||
449 | 250 |
// insets which we get from WM (e.g from _NET_FRAME_EXTENTS) |
251 |
private Insets wm_set_insets; |
|
252 |
||
253 |
private Insets getWMSetInsets(XAtom changedAtom) { |
|
254 |
if (isEmbedded()) { |
|
255 |
return null; |
|
256 |
} |
|
257 |
||
258 |
if (wm_set_insets != null) { |
|
259 |
return wm_set_insets; |
|
260 |
} |
|
261 |
||
262 |
if (changedAtom == null) { |
|
263 |
wm_set_insets = XWM.getInsetsFromExtents(getWindow()); |
|
264 |
} else { |
|
265 |
wm_set_insets = XWM.getInsetsFromProp(getWindow(), changedAtom); |
|
266 |
} |
|
267 |
||
268 |
insLog.log(Level.FINER, "FRAME_EXTENTS: {0}", new Object[]{wm_set_insets}); |
|
269 |
||
270 |
if (wm_set_insets != null) { |
|
271 |
wm_set_insets = copy(wm_set_insets); |
|
272 |
} |
|
273 |
return wm_set_insets; |
|
274 |
} |
|
275 |
||
276 |
private void resetWMSetInsets() { |
|
277 |
wm_set_insets = null; |
|
278 |
} |
|
279 |
||
280 |
public void handlePropertyNotify(XEvent xev) { |
|
281 |
super.handlePropertyNotify(xev); |
|
282 |
||
283 |
XPropertyEvent ev = xev.get_xproperty(); |
|
284 |
if (ev.get_atom() == XWM.XA_KDE_NET_WM_FRAME_STRUT.getAtom() |
|
285 |
|| ev.get_atom() == XWM.XA_NET_FRAME_EXTENTS.getAtom()) |
|
286 |
{ |
|
287 |
getWMSetInsets(XAtom.get(ev.get_atom())); |
|
288 |
} |
|
289 |
} |
|
290 |
||
2 | 291 |
long reparent_serial = 0; |
292 |
||
293 |
public void handleReparentNotifyEvent(XEvent xev) { |
|
294 |
XReparentEvent xe = xev.get_xreparent(); |
|
295 |
if (insLog.isLoggable(Level.FINE)) insLog.fine(xe.toString()); |
|
296 |
reparent_serial = xe.get_serial(); |
|
297 |
XToolkit.awtLock(); |
|
298 |
try { |
|
299 |
long root = XlibWrapper.RootWindow(XToolkit.getDisplay(), getScreenNumber()); |
|
300 |
||
301 |
if (isEmbedded()) { |
|
302 |
setReparented(true); |
|
303 |
insets_corrected = true; |
|
304 |
return; |
|
305 |
} |
|
306 |
Component t = (Component)target; |
|
115 | 307 |
if (getDecorations() == XWindowAttributesData.AWT_DECOR_NONE) { |
2 | 308 |
setReparented(true); |
309 |
insets_corrected = true; |
|
310 |
reshape(dimensions, SET_SIZE, false); |
|
311 |
} else if (xe.get_parent() == root) { |
|
312 |
configure_seen = false; |
|
313 |
insets_corrected = false; |
|
314 |
||
315 |
/* |
|
316 |
* We can be repareted to root for two reasons: |
|
317 |
* . setVisible(false) |
|
318 |
* . WM exited |
|
319 |
*/ |
|
320 |
if (isVisible()) { /* WM exited */ |
|
321 |
/* Work around 4775545 */ |
|
322 |
XWM.getWM().unshadeKludge(this); |
|
323 |
insLog.fine("- WM exited"); |
|
324 |
} else { |
|
325 |
insLog.fine(" - reparent due to hide"); |
|
326 |
} |
|
327 |
} else { /* reparented to WM frame, figure out our insets */ |
|
328 |
setReparented(true); |
|
329 |
insets_corrected = false; |
|
330 |
||
331 |
// Check if we have insets provided by the WM |
|
332 |
Insets correctWM = getWMSetInsets(null); |
|
333 |
if (correctWM != null) { |
|
334 |
insLog.log(Level.FINER, "wm-provided insets {0}", new Object[]{correctWM}); |
|
335 |
// If these insets are equal to our current insets - no actions are necessary |
|
336 |
Insets dimInsets = dimensions.getInsets(); |
|
337 |
if (correctWM.equals(dimInsets)) { |
|
338 |
insLog.finer("Insets are the same as estimated - no additional reshapes necessary"); |
|
339 |
no_reparent_artifacts = true; |
|
340 |
insets_corrected = true; |
|
341 |
applyGuessedInsets(); |
|
342 |
return; |
|
343 |
} |
|
344 |
} else { |
|
345 |
correctWM = XWM.getWM().getInsets(this, xe.get_window(), xe.get_parent()); |
|
346 |
||
347 |
if (correctWM != null) { |
|
348 |
insLog.log(Level.FINER, "correctWM {0}", new Object[] {correctWM}); |
|
349 |
} else { |
|
350 |
insLog.log(Level.FINER, "correctWM insets are not available, waiting for configureNotify"); |
|
351 |
} |
|
352 |
} |
|
353 |
||
354 |
if (correctWM != null) { |
|
355 |
handleCorrectInsets(correctWM); |
|
356 |
} |
|
357 |
} |
|
358 |
} finally { |
|
359 |
XToolkit.awtUnlock(); |
|
360 |
} |
|
361 |
} |
|
362 |
||
363 |
protected void handleCorrectInsets(Insets correctWM) { |
|
364 |
XToolkit.awtLock(); |
|
365 |
try { |
|
366 |
/* |
|
367 |
* Ok, now see if we need adjust window size because |
|
368 |
* initial insets were wrong (most likely they were). |
|
369 |
*/ |
|
370 |
Insets correction = difference(correctWM, currentInsets); |
|
371 |
insLog.log(Level.FINEST, "Corrention {0}", new Object[] {correction}); |
|
372 |
if (!isNull(correction)) { |
|
449 | 373 |
currentInsets = copy(correctWM); |
2 | 374 |
applyGuessedInsets(); |
375 |
||
376 |
//Fix for 6318109: PIT: Min Size is not honored properly when a |
|
377 |
//smaller size is specified in setSize(), XToolkit |
|
378 |
//update minimum size hints |
|
379 |
updateMinSizeHints(); |
|
380 |
} |
|
381 |
if (insLog.isLoggable(Level.FINER)) insLog.finer("Dimensions before reparent: " + dimensions); |
|
382 |
||
383 |
dimensions.setInsets(getRealInsets()); |
|
384 |
insets_corrected = true; |
|
385 |
||
449 | 386 |
if (isMaximized() || isNull(correction)) { |
2 | 387 |
return; |
388 |
} |
|
389 |
||
449 | 390 |
/* |
391 |
* If this window has been sized by a pack() we need |
|
392 |
* to keep the interior geometry intact. Since pack() |
|
393 |
* computed width and height with wrong insets, we |
|
394 |
* must adjust the target dimensions appropriately. |
|
395 |
*/ |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
420
diff
changeset
|
396 |
if ((getHints().get_flags() & (XUtilConstants.USPosition | XUtilConstants.PPosition)) != 0) { |
2 | 397 |
reshape(dimensions, SET_BOUNDS, false); |
398 |
} else { |
|
399 |
reshape(dimensions, SET_SIZE, false); |
|
400 |
} |
|
401 |
} finally { |
|
402 |
XToolkit.awtUnlock(); |
|
403 |
} |
|
404 |
} |
|
405 |
||
406 |
public void handleMoved(WindowDimensions dims) { |
|
407 |
Point loc = dims.getLocation(); |
|
408 |
ComponentAccessor.setX((Component)target, loc.x); |
|
409 |
ComponentAccessor.setY((Component)target, loc.y); |
|
410 |
postEvent(new ComponentEvent(target, ComponentEvent.COMPONENT_MOVED)); |
|
411 |
} |
|
412 |
||
413 |
||
414 |
protected Insets guessInsets() { |
|
449 | 415 |
if (isEmbedded() || isTargetUndecorated()) { |
2 | 416 |
return new Insets(0, 0, 0, 0); |
417 |
} else { |
|
449 | 418 |
if (!isNull(currentInsets)) { |
2 | 419 |
/* insets were set on wdata by System Properties */ |
420 |
return copy(currentInsets); |
|
421 |
} else { |
|
422 |
Insets res = getWMSetInsets(null); |
|
423 |
if (res == null) { |
|
424 |
res = XWM.getWM().guessInsets(this); |
|
425 |
} |
|
426 |
return res; |
|
427 |
} |
|
428 |
} |
|
429 |
} |
|
430 |
||
431 |
private void applyGuessedInsets() { |
|
432 |
Insets guessed = guessInsets(); |
|
433 |
currentInsets = copy(guessed); |
|
434 |
} |
|
435 |
||
436 |
public void revalidate() { |
|
437 |
XToolkit.executeOnEventHandlerThread(target, new Runnable() { |
|
438 |
public void run() { |
|
439 |
target.invalidate(); |
|
440 |
target.validate(); |
|
441 |
} |
|
442 |
}); |
|
443 |
} |
|
444 |
||
445 |
Insets getRealInsets() { |
|
449 | 446 |
if (isNull(currentInsets)) { |
2 | 447 |
applyGuessedInsets(); |
448 |
} |
|
449 | 449 |
return currentInsets; |
2 | 450 |
} |
451 |
||
452 |
public Insets getInsets() { |
|
453 |
Insets in = copy(getRealInsets()); |
|
454 |
in.top += getMenuBarHeight() + getWarningWindowHeight(); |
|
449 | 455 |
if (insLog.isLoggable(Level.FINEST)) { |
456 |
insLog.log(Level.FINEST, "Get insets returns {0}", new Object[] {in}); |
|
457 |
} |
|
2 | 458 |
return in; |
459 |
} |
|
460 |
||
461 |
boolean gravityBug() { |
|
462 |
return XWM.configureGravityBuggy(); |
|
463 |
} |
|
464 |
||
465 |
// The height of area used to display current active input method |
|
466 |
int getInputMethodHeight() { |
|
467 |
return 0; |
|
468 |
} |
|
469 |
||
470 |
void updateSizeHints(WindowDimensions dims) { |
|
471 |
Rectangle rec = dims.getClientRect(); |
|
472 |
checkShellRect(rec); |
|
473 |
updateSizeHints(rec.x, rec.y, rec.width, rec.height); |
|
474 |
} |
|
475 |
||
476 |
void updateSizeHints() { |
|
477 |
updateSizeHints(dimensions); |
|
478 |
} |
|
479 |
||
480 |
// Coordinates are that of the target |
|
481 |
// Called only on Toolkit thread |
|
482 |
public void reshape(WindowDimensions newDimensions, int op, |
|
483 |
boolean userReshape) |
|
484 |
{ |
|
485 |
if (insLog.isLoggable(Level.FINE)) { |
|
486 |
insLog.fine("Reshaping " + this + " to " + newDimensions + " op " + op + " user reshape " + userReshape); |
|
487 |
} |
|
129
f995b9c9c5fa
6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents:
118
diff
changeset
|
488 |
if (userReshape) { |
f995b9c9c5fa
6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents:
118
diff
changeset
|
489 |
// We handle only userReshape == true cases. It means that |
f995b9c9c5fa
6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents:
118
diff
changeset
|
490 |
// if the window manager or any other part of the windowing |
f995b9c9c5fa
6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents:
118
diff
changeset
|
491 |
// system sets inappropriate size for this window, we can |
f995b9c9c5fa
6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents:
118
diff
changeset
|
492 |
// do nothing but accept it. |
f995b9c9c5fa
6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents:
118
diff
changeset
|
493 |
Rectangle reqBounds = newDimensions.getBounds(); |
f995b9c9c5fa
6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents:
118
diff
changeset
|
494 |
Rectangle newBounds = constrainBounds(reqBounds.x, reqBounds.y, reqBounds.width, reqBounds.height); |
f995b9c9c5fa
6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents:
118
diff
changeset
|
495 |
newDimensions = new WindowDimensions(newBounds, newDimensions.getInsets(), newDimensions.isClientSizeSet()); |
f995b9c9c5fa
6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents:
118
diff
changeset
|
496 |
} |
2 | 497 |
XToolkit.awtLock(); |
498 |
try { |
|
499 |
if (!isReparented() || !isVisible()) { |
|
500 |
insLog.log(Level.FINE, "- not reparented({0}) or not visible({1}), default reshape", |
|
501 |
new Object[] {Boolean.valueOf(isReparented()), Boolean.valueOf(visible)}); |
|
502 |
||
503 |
// Fix for 6323293. |
|
504 |
// This actually is needed to preserve compatibility with previous releases - |
|
505 |
// some of licensees are expecting componentMoved event on invisible one while |
|
506 |
// its location changes. |
|
507 |
Point oldLocation = getLocation(); |
|
508 |
||
509 |
Point newLocation = new Point(ComponentAccessor.getX((Component)target), |
|
510 |
ComponentAccessor.getY((Component)target)); |
|
511 |
||
512 |
if (!newLocation.equals(oldLocation)) { |
|
513 |
handleMoved(newDimensions); |
|
514 |
} |
|
515 |
||
516 |
dimensions = new WindowDimensions(newDimensions); |
|
517 |
updateSizeHints(dimensions); |
|
518 |
Rectangle client = dimensions.getClientRect(); |
|
519 |
checkShellRect(client); |
|
520 |
setShellBounds(client); |
|
521 |
if (content != null && |
|
522 |
!content.getSize().equals(newDimensions.getSize())) |
|
523 |
{ |
|
524 |
reconfigureContentWindow(newDimensions); |
|
525 |
} |
|
526 |
return; |
|
527 |
} |
|
528 |
||
529 |
int wm = XWM.getWMID(); |
|
530 |
updateChildrenSizes(); |
|
531 |
applyGuessedInsets(); |
|
532 |
||
533 |
Rectangle shellRect = newDimensions.getClientRect(); |
|
534 |
||
535 |
if (gravityBug()) { |
|
536 |
Insets in = newDimensions.getInsets(); |
|
537 |
shellRect.translate(in.left, in.top); |
|
538 |
} |
|
539 |
||
540 |
if ((op & NO_EMBEDDED_CHECK) == 0 && isEmbedded()) { |
|
541 |
shellRect.setLocation(0, 0); |
|
542 |
} |
|
543 |
||
544 |
checkShellRectSize(shellRect); |
|
545 |
if (!isEmbedded()) { |
|
546 |
checkShellRectPos(shellRect); |
|
547 |
} |
|
548 |
||
549 |
op = op & ~NO_EMBEDDED_CHECK; |
|
550 |
||
551 |
if (op == SET_LOCATION) { |
|
552 |
setShellPosition(shellRect); |
|
553 |
} else if (isResizable()) { |
|
554 |
if (op == SET_BOUNDS) { |
|
555 |
setShellBounds(shellRect); |
|
556 |
} else { |
|
557 |
setShellSize(shellRect); |
|
558 |
} |
|
559 |
} else { |
|
560 |
XWM.setShellNotResizable(this, newDimensions, shellRect, true); |
|
561 |
if (op == SET_BOUNDS) { |
|
562 |
setShellPosition(shellRect); |
|
563 |
} |
|
564 |
} |
|
565 |
||
566 |
reconfigureContentWindow(newDimensions); |
|
567 |
} finally { |
|
568 |
XToolkit.awtUnlock(); |
|
569 |
} |
|
570 |
} |
|
571 |
||
572 |
/** |
|
573 |
* @param x, y, width, heith - dimensions of the window with insets |
|
574 |
*/ |
|
575 |
private void reshape(int x, int y, int width, int height, int operation, |
|
576 |
boolean userReshape) |
|
577 |
{ |
|
578 |
Rectangle newRec; |
|
579 |
boolean setClient = false; |
|
580 |
WindowDimensions dims = new WindowDimensions(dimensions); |
|
581 |
switch (operation & (~NO_EMBEDDED_CHECK)) { |
|
582 |
case SET_LOCATION: |
|
583 |
// Set location always sets bounds location. However, until the window is mapped we |
|
584 |
// should use client coordinates |
|
585 |
dims.setLocation(x, y); |
|
586 |
break; |
|
587 |
case SET_SIZE: |
|
588 |
// Set size sets bounds size. However, until the window is mapped we |
|
589 |
// should use client coordinates |
|
590 |
dims.setSize(width, height); |
|
591 |
break; |
|
592 |
case SET_CLIENT_SIZE: { |
|
593 |
// Sets client rect size. Width and height contain insets. |
|
594 |
Insets in = currentInsets; |
|
595 |
width -= in.left+in.right; |
|
596 |
height -= in.top+in.bottom; |
|
597 |
dims.setClientSize(width, height); |
|
598 |
break; |
|
599 |
} |
|
600 |
case SET_BOUNDS: |
|
601 |
default: |
|
602 |
dims.setLocation(x, y); |
|
603 |
dims.setSize(width, height); |
|
604 |
break; |
|
605 |
} |
|
606 |
if (insLog.isLoggable(Level.FINE)) insLog.log(Level.FINE, "For the operation {0} new dimensions are {1}", |
|
607 |
new Object[] {operationToString(operation), dims}); |
|
608 |
||
609 |
reshape(dims, operation, userReshape); |
|
610 |
} |
|
611 |
||
129
f995b9c9c5fa
6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents:
118
diff
changeset
|
612 |
// This method gets overriden in XFramePeer & XDialogPeer. |
f995b9c9c5fa
6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents:
118
diff
changeset
|
613 |
abstract boolean isTargetUndecorated(); |
f995b9c9c5fa
6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents:
118
diff
changeset
|
614 |
|
f995b9c9c5fa
6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents:
118
diff
changeset
|
615 |
@Override |
f995b9c9c5fa
6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents:
118
diff
changeset
|
616 |
Rectangle constrainBounds(int x, int y, int width, int height) { |
f995b9c9c5fa
6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents:
118
diff
changeset
|
617 |
// We don't restrict the setBounds() operation if the code is trusted. |
f995b9c9c5fa
6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents:
118
diff
changeset
|
618 |
if (!hasWarningWindow()) { |
f995b9c9c5fa
6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents:
118
diff
changeset
|
619 |
return new Rectangle(x, y, width, height); |
f995b9c9c5fa
6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents:
118
diff
changeset
|
620 |
} |
f995b9c9c5fa
6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents:
118
diff
changeset
|
621 |
|
f995b9c9c5fa
6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents:
118
diff
changeset
|
622 |
// If it's undecorated or is not currently visible, |
f995b9c9c5fa
6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents:
118
diff
changeset
|
623 |
// apply the same constraints as for the Window. |
f995b9c9c5fa
6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents:
118
diff
changeset
|
624 |
if (!isVisible() || isTargetUndecorated()) { |
f995b9c9c5fa
6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents:
118
diff
changeset
|
625 |
return super.constrainBounds(x, y, width, height); |
f995b9c9c5fa
6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents:
118
diff
changeset
|
626 |
} |
f995b9c9c5fa
6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents:
118
diff
changeset
|
627 |
|
f995b9c9c5fa
6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents:
118
diff
changeset
|
628 |
// If it's visible & decorated, constraint the size only |
f995b9c9c5fa
6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents:
118
diff
changeset
|
629 |
int newX = x; |
f995b9c9c5fa
6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents:
118
diff
changeset
|
630 |
int newY = y; |
f995b9c9c5fa
6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents:
118
diff
changeset
|
631 |
int newW = width; |
f995b9c9c5fa
6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents:
118
diff
changeset
|
632 |
int newH = height; |
f995b9c9c5fa
6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents:
118
diff
changeset
|
633 |
|
f995b9c9c5fa
6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents:
118
diff
changeset
|
634 |
GraphicsConfiguration gc = ((Window)target).getGraphicsConfiguration(); |
f995b9c9c5fa
6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents:
118
diff
changeset
|
635 |
Rectangle sB = gc.getBounds(); |
f995b9c9c5fa
6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents:
118
diff
changeset
|
636 |
Insets sIn = ((Window)target).getToolkit().getScreenInsets(gc); |
f995b9c9c5fa
6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents:
118
diff
changeset
|
637 |
|
f995b9c9c5fa
6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents:
118
diff
changeset
|
638 |
Rectangle curBounds = getBounds(); |
f995b9c9c5fa
6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents:
118
diff
changeset
|
639 |
|
f995b9c9c5fa
6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents:
118
diff
changeset
|
640 |
int maxW = Math.max(sB.width - sIn.left - sIn.right, curBounds.width); |
f995b9c9c5fa
6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents:
118
diff
changeset
|
641 |
int maxH = Math.max(sB.height - sIn.top - sIn.bottom, curBounds.height); |
f995b9c9c5fa
6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents:
118
diff
changeset
|
642 |
|
f995b9c9c5fa
6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents:
118
diff
changeset
|
643 |
// First make sure the size is withing the visible part of the screen |
f995b9c9c5fa
6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents:
118
diff
changeset
|
644 |
if (newW > maxW) { |
f995b9c9c5fa
6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents:
118
diff
changeset
|
645 |
newW = maxW; |
f995b9c9c5fa
6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents:
118
diff
changeset
|
646 |
} |
f995b9c9c5fa
6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents:
118
diff
changeset
|
647 |
|
f995b9c9c5fa
6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents:
118
diff
changeset
|
648 |
if (newH > maxH) { |
f995b9c9c5fa
6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents:
118
diff
changeset
|
649 |
newH = maxH; |
f995b9c9c5fa
6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents:
118
diff
changeset
|
650 |
} |
f995b9c9c5fa
6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents:
118
diff
changeset
|
651 |
|
f995b9c9c5fa
6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents:
118
diff
changeset
|
652 |
return new Rectangle(newX, newY, newW, newH); |
f995b9c9c5fa
6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents:
118
diff
changeset
|
653 |
} |
f995b9c9c5fa
6589527: Window and Frame instances can hide their "Applet Warning"
anthony
parents:
118
diff
changeset
|
654 |
|
2 | 655 |
/** |
656 |
* @see java.awt.peer.ComponentPeer#setBounds |
|
657 |
*/ |
|
658 |
public void setBounds(int x, int y, int width, int height, int op) { |
|
659 |
// TODO: Rewrite with WindowDimensions |
|
660 |
reshape(x, y, width, height, op, true); |
|
661 |
validateSurface(); |
|
662 |
} |
|
663 |
||
664 |
// Coordinates are that of the shell |
|
665 |
void reconfigureContentWindow(WindowDimensions dims) { |
|
666 |
if (content == null) { |
|
667 |
insLog.fine("WARNING: Content window is null"); |
|
668 |
return; |
|
669 |
} |
|
670 |
content.setContentBounds(dims); |
|
671 |
} |
|
672 |
||
673 |
boolean no_reparent_artifacts = false; |
|
674 |
public void handleConfigureNotifyEvent(XEvent xev) { |
|
675 |
assert (SunToolkit.isAWTLockHeldByCurrentThread()); |
|
676 |
XConfigureEvent xe = xev.get_xconfigure(); |
|
677 |
insLog.log(Level.FINE, "Configure notify {0}", new Object[] {xe}); |
|
678 |
||
679 |
// XXX: should really only consider synthetic events, but |
|
680 |
if (isReparented()) { |
|
681 |
configure_seen = true; |
|
682 |
} |
|
683 |
||
684 |
if (!isMaximized() |
|
685 |
&& (xe.get_serial() == reparent_serial || xe.get_window() != getShell()) |
|
686 |
&& !no_reparent_artifacts) |
|
687 |
{ |
|
688 |
insLog.fine("- reparent artifact, skipping"); |
|
689 |
return; |
|
690 |
} |
|
691 |
no_reparent_artifacts = false; |
|
692 |
||
693 |
/** |
|
694 |
* When there is a WM we receive some CN before being visible and after. |
|
695 |
* We should skip all CN which are before being visible, because we assume |
|
696 |
* the gravity is in action while it is not yet. |
|
697 |
* |
|
698 |
* When there is no WM we receive CN only _before_ being visible. |
|
699 |
* We should process these CNs. |
|
700 |
*/ |
|
701 |
if (!isVisible() && XWM.getWMID() != XWM.NO_WM) { |
|
702 |
insLog.fine(" - not visible, skipping"); |
|
703 |
return; |
|
704 |
} |
|
705 |
||
706 |
/* |
|
707 |
* Some window managers configure before we are reparented and |
|
708 |
* the send event flag is set! ugh... (Enlighetenment for one, |
|
709 |
* possibly MWM as well). If we haven't been reparented yet |
|
710 |
* this is just the WM shuffling us into position. Ignore |
|
711 |
* it!!!! or we wind up in a bogus location. |
|
712 |
*/ |
|
713 |
int runningWM = XWM.getWMID(); |
|
714 |
if (insLog.isLoggable(Level.FINE)) { |
|
715 |
insLog.log(Level.FINE, "reparented={0}, visible={1}, WM={2}, decorations={3}", |
|
716 |
new Object[] {isReparented(), isVisible(), runningWM, getDecorations()}); |
|
717 |
} |
|
718 |
if (!isReparented() && isVisible() && runningWM != XWM.NO_WM |
|
719 |
&& !XWM.isNonReparentingWM() |
|
115 | 720 |
&& getDecorations() != XWindowAttributesData.AWT_DECOR_NONE) { |
2 | 721 |
insLog.fine("- visible but not reparented, skipping"); |
722 |
return; |
|
723 |
} |
|
724 |
//Last chance to correct insets |
|
115 | 725 |
if (!insets_corrected && getDecorations() != XWindowAttributesData.AWT_DECOR_NONE) { |
2 | 726 |
long parent = XlibUtil.getParentWindow(window); |
727 |
Insets correctWM = (parent != -1) ? XWM.getWM().getInsets(this, window, parent) : null; |
|
728 |
if (insLog.isLoggable(Level.FINER)) { |
|
729 |
if (correctWM != null) { |
|
730 |
insLog.finer("Configure notify - insets : " + correctWM); |
|
731 |
} else { |
|
732 |
insLog.finer("Configure notify - insets are still not available"); |
|
733 |
} |
|
734 |
} |
|
735 |
if (correctWM != null) { |
|
736 |
handleCorrectInsets(correctWM); |
|
737 |
} else { |
|
738 |
//Only one attempt to correct insets is made (to lower risk) |
|
739 |
//if insets are still not available we simply set the flag |
|
740 |
insets_corrected = true; |
|
741 |
} |
|
742 |
} |
|
743 |
||
744 |
updateChildrenSizes(); |
|
745 |
||
746 |
// Bounds of the window |
|
747 |
Rectangle targetBounds = new Rectangle(ComponentAccessor.getX((Component)target), |
|
748 |
ComponentAccessor.getY((Component)target), |
|
749 |
ComponentAccessor.getWidth((Component)target), |
|
750 |
ComponentAccessor.getHeight((Component)target)); |
|
751 |
||
752 |
Point newLocation = targetBounds.getLocation(); |
|
753 |
if (xe.get_send_event() || runningWM == XWM.NO_WM || XWM.isNonReparentingWM()) { |
|
754 |
// Location, Client size + insets |
|
755 |
newLocation = new Point(xe.get_x() - currentInsets.left, xe.get_y() - currentInsets.top); |
|
756 |
} else { |
|
757 |
// CDE/MWM/Metacity/Sawfish bug: if shell is resized using |
|
758 |
// top or left border, we don't receive synthetic |
|
759 |
// ConfigureNotify, only the one from X with zero |
|
760 |
// coordinates. This is the workaround to get real |
|
761 |
// location, 6261336 |
|
762 |
switch (XWM.getWMID()) { |
|
763 |
case XWM.CDE_WM: |
|
764 |
case XWM.MOTIF_WM: |
|
765 |
case XWM.METACITY_WM: |
|
766 |
case XWM.SAWFISH_WM: |
|
767 |
{ |
|
768 |
Point xlocation = queryXLocation(); |
|
769 |
if (log.isLoggable(Level.FINE)) log.log(Level.FINE, "New X location: {0}", new Object[]{xlocation}); |
|
770 |
if (xlocation != null) { |
|
771 |
newLocation = xlocation; |
|
772 |
} |
|
773 |
break; |
|
774 |
} |
|
775 |
default: |
|
776 |
break; |
|
777 |
} |
|
778 |
} |
|
779 |
||
780 |
WindowDimensions newDimensions = |
|
781 |
new WindowDimensions(newLocation, |
|
782 |
new Dimension(xe.get_width(), xe.get_height()), |
|
783 |
copy(currentInsets), |
|
784 |
true); |
|
785 |
||
786 |
insLog.log(Level.FINER, "Insets are {0}, new dimensions {1}", |
|
787 |
new Object[] {currentInsets, newDimensions}); |
|
788 |
||
789 |
checkIfOnNewScreen(newDimensions.getBounds()); |
|
790 |
||
791 |
Point oldLocation = getLocation(); |
|
792 |
dimensions = newDimensions; |
|
793 |
if (!newLocation.equals(oldLocation)) { |
|
794 |
handleMoved(newDimensions); |
|
795 |
} |
|
796 |
reconfigureContentWindow(newDimensions); |
|
797 |
updateChildrenSizes(); |
|
798 |
} |
|
799 |
||
800 |
private void checkShellRectSize(Rectangle shellRect) { |
|
801 |
if (shellRect.width < 0) { |
|
802 |
shellRect.width = 1; |
|
803 |
} |
|
804 |
if (shellRect.height < 0) { |
|
805 |
shellRect.height = 1; |
|
806 |
} |
|
807 |
} |
|
808 |
||
809 |
private void checkShellRectPos(Rectangle shellRect) { |
|
810 |
int wm = XWM.getWMID(); |
|
811 |
if (wm == XWM.MOTIF_WM || wm == XWM.CDE_WM) { |
|
812 |
if (shellRect.x == 0 && shellRect.y == 0) { |
|
813 |
shellRect.x = shellRect.y = 1; |
|
814 |
} |
|
815 |
} |
|
816 |
} |
|
817 |
||
818 |
private void checkShellRect(Rectangle shellRect) { |
|
819 |
checkShellRectSize(shellRect); |
|
820 |
checkShellRectPos(shellRect); |
|
821 |
} |
|
822 |
||
823 |
public void setShellBounds(Rectangle rec) { |
|
824 |
if (insLog.isLoggable(Level.FINE)) insLog.fine("Setting shell bounds on " + |
|
825 |
this + " to " + rec); |
|
826 |
XToolkit.awtLock(); |
|
827 |
try { |
|
828 |
updateSizeHints(rec.x, rec.y, rec.width, rec.height); |
|
829 |
XlibWrapper.XResizeWindow(XToolkit.getDisplay(), getShell(), rec.width, rec.height); |
|
830 |
XlibWrapper.XMoveWindow(XToolkit.getDisplay(), getShell(), rec.x, rec.y); |
|
831 |
} |
|
832 |
finally { |
|
833 |
XToolkit.awtUnlock(); |
|
834 |
} |
|
835 |
} |
|
836 |
public void setShellSize(Rectangle rec) { |
|
837 |
if (insLog.isLoggable(Level.FINE)) insLog.fine("Setting shell size on " + |
|
838 |
this + " to " + rec); |
|
839 |
XToolkit.awtLock(); |
|
840 |
try { |
|
841 |
updateSizeHints(rec.x, rec.y, rec.width, rec.height); |
|
842 |
XlibWrapper.XResizeWindow(XToolkit.getDisplay(), getShell(), rec.width, rec.height); |
|
843 |
} |
|
844 |
finally { |
|
845 |
XToolkit.awtUnlock(); |
|
846 |
} |
|
847 |
} |
|
848 |
public void setShellPosition(Rectangle rec) { |
|
849 |
if (insLog.isLoggable(Level.FINE)) insLog.fine("Setting shell position on " + |
|
850 |
this + " to " + rec); |
|
851 |
XToolkit.awtLock(); |
|
852 |
try { |
|
853 |
updateSizeHints(rec.x, rec.y, rec.width, rec.height); |
|
854 |
XlibWrapper.XMoveWindow(XToolkit.getDisplay(), getShell(), rec.x, rec.y); |
|
855 |
} |
|
856 |
finally { |
|
857 |
XToolkit.awtUnlock(); |
|
858 |
} |
|
859 |
} |
|
860 |
||
861 |
void initResizability() { |
|
862 |
setResizable(winAttr.initialResizability); |
|
863 |
} |
|
864 |
public void setResizable(boolean resizable) { |
|
865 |
int fs = winAttr.functions; |
|
866 |
if (!isResizable() && resizable) { |
|
449 | 867 |
currentInsets = new Insets(0, 0, 0, 0); |
2 | 868 |
resetWMSetInsets(); |
869 |
if (!isEmbedded()) { |
|
870 |
setReparented(false); |
|
871 |
} |
|
872 |
winAttr.isResizable = resizable; |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
420
diff
changeset
|
873 |
if ((fs & MWMConstants.MWM_FUNC_ALL) != 0) { |
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
420
diff
changeset
|
874 |
fs &= ~(MWMConstants.MWM_FUNC_RESIZE | MWMConstants.MWM_FUNC_MAXIMIZE); |
2 | 875 |
} else { |
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
420
diff
changeset
|
876 |
fs |= (MWMConstants.MWM_FUNC_RESIZE | MWMConstants.MWM_FUNC_MAXIMIZE); |
2 | 877 |
} |
878 |
winAttr.functions = fs; |
|
879 |
XWM.setShellResizable(this); |
|
880 |
} else if (isResizable() && !resizable) { |
|
449 | 881 |
currentInsets = new Insets(0, 0, 0, 0); |
2 | 882 |
resetWMSetInsets(); |
883 |
if (!isEmbedded()) { |
|
884 |
setReparented(false); |
|
885 |
} |
|
886 |
winAttr.isResizable = resizable; |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
420
diff
changeset
|
887 |
if ((fs & MWMConstants.MWM_FUNC_ALL) != 0) { |
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
420
diff
changeset
|
888 |
fs |= (MWMConstants.MWM_FUNC_RESIZE | MWMConstants.MWM_FUNC_MAXIMIZE); |
2 | 889 |
} else { |
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
420
diff
changeset
|
890 |
fs &= ~(MWMConstants.MWM_FUNC_RESIZE | MWMConstants.MWM_FUNC_MAXIMIZE); |
2 | 891 |
} |
892 |
winAttr.functions = fs; |
|
118
35b334a806ab
6522731: Location of the frame changes,when the frame is resized & non-resized.
dcherepanov
parents:
115
diff
changeset
|
893 |
XWM.setShellNotResizable(this, dimensions, dimensions.getBounds(), false); |
2 | 894 |
} |
895 |
} |
|
896 |
||
897 |
Rectangle getShellBounds() { |
|
898 |
return dimensions.getClientRect(); |
|
899 |
} |
|
900 |
||
901 |
public Rectangle getBounds() { |
|
902 |
return dimensions.getBounds(); |
|
903 |
} |
|
904 |
||
905 |
public Dimension getSize() { |
|
906 |
return dimensions.getSize(); |
|
907 |
} |
|
908 |
||
909 |
public int getX() { |
|
910 |
return dimensions.getLocation().x; |
|
911 |
} |
|
912 |
||
913 |
public int getY() { |
|
914 |
return dimensions.getLocation().y; |
|
915 |
} |
|
916 |
||
917 |
public Point getLocation() { |
|
918 |
return dimensions.getLocation(); |
|
919 |
} |
|
920 |
||
921 |
public int getAbsoluteX() { |
|
922 |
// NOTE: returning this peer's location which is shell location |
|
923 |
return dimensions.getScreenBounds().x; |
|
924 |
} |
|
925 |
||
926 |
public int getAbsoluteY() { |
|
927 |
// NOTE: returning this peer's location which is shell location |
|
928 |
return dimensions.getScreenBounds().y; |
|
929 |
} |
|
930 |
||
931 |
public int getWidth() { |
|
932 |
return getSize().width; |
|
933 |
} |
|
934 |
||
935 |
public int getHeight() { |
|
936 |
return getSize().height; |
|
937 |
} |
|
938 |
||
115 | 939 |
final public WindowDimensions getDimensions() { |
2 | 940 |
return dimensions; |
941 |
} |
|
942 |
||
943 |
public Point getLocationOnScreen() { |
|
944 |
XToolkit.awtLock(); |
|
945 |
try { |
|
946 |
if (configure_seen) { |
|
947 |
return toGlobal(0,0); |
|
948 |
} else { |
|
949 |
Point location = target.getLocation(); |
|
950 |
if (insLog.isLoggable(Level.FINE)) |
|
951 |
insLog.log(Level.FINE, "getLocationOnScreen {0} not reparented: {1} ", |
|
952 |
new Object[] {this, location}); |
|
953 |
return location; |
|
954 |
} |
|
955 |
} finally { |
|
956 |
XToolkit.awtUnlock(); |
|
957 |
} |
|
958 |
} |
|
959 |
||
960 |
||
961 |
/*************************************************************************************** |
|
962 |
* END OF I N S E T S C O D E |
|
963 |
**************************************************************************************/ |
|
964 |
||
965 |
protected boolean isEventDisabled(XEvent e) { |
|
966 |
switch (e.get_type()) { |
|
967 |
// Do not generate MOVED/RESIZED events since we generate them by ourselves |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
420
diff
changeset
|
968 |
case XConstants.ConfigureNotify: |
2 | 969 |
return true; |
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
420
diff
changeset
|
970 |
case XConstants.EnterNotify: |
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
420
diff
changeset
|
971 |
case XConstants.LeaveNotify: |
2 | 972 |
// Disable crossing event on outer borders of Frame so |
973 |
// we receive only one set of cross notifications(first set is from content window) |
|
974 |
return true; |
|
975 |
default: |
|
976 |
return super.isEventDisabled(e); |
|
977 |
} |
|
978 |
} |
|
979 |
||
980 |
int getDecorations() { |
|
981 |
return winAttr.decorations; |
|
982 |
} |
|
983 |
||
984 |
int getFunctions() { |
|
985 |
return winAttr.functions; |
|
986 |
} |
|
987 |
||
988 |
public void setVisible(boolean vis) { |
|
989 |
log.log(Level.FINER, "Setting {0} to visible {1}", new Object[] {this, Boolean.valueOf(vis)}); |
|
990 |
if (vis && !isVisible()) { |
|
991 |
XWM.setShellDecor(this); |
|
992 |
super.setVisible(vis); |
|
993 |
if (winAttr.isResizable) { |
|
994 |
//Fix for 4320050: Minimum size for java.awt.Frame is not being enforced. |
|
995 |
//We need to update frame's minimum size, not to reset it |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
420
diff
changeset
|
996 |
XWM.removeSizeHints(this, XUtilConstants.PMaxSize); |
2 | 997 |
updateMinimumSize(); |
998 |
} |
|
999 |
} else { |
|
1000 |
super.setVisible(vis); |
|
1001 |
} |
|
1002 |
} |
|
1003 |
||
1004 |
protected void suppressWmTakeFocus(boolean doSuppress) { |
|
1005 |
XAtomList protocols = getWMProtocols(); |
|
1006 |
if (doSuppress) { |
|
1007 |
protocols.remove(wm_take_focus); |
|
1008 |
} else { |
|
1009 |
protocols.add(wm_take_focus); |
|
1010 |
} |
|
1011 |
wm_protocols.setAtomListProperty(this, protocols); |
|
1012 |
} |
|
1013 |
||
1014 |
public void dispose() { |
|
1015 |
if (content != null) { |
|
1016 |
content.destroy(); |
|
1017 |
} |
|
1018 |
focusProxy.destroy(); |
|
1019 |
||
1020 |
if (iconWindow != null) { |
|
1021 |
iconWindow.destroy(); |
|
1022 |
} |
|
1023 |
||
1024 |
super.dispose(); |
|
1025 |
} |
|
1026 |
||
1027 |
public void handleClientMessage(XEvent xev) { |
|
1028 |
super.handleClientMessage(xev); |
|
1029 |
XClientMessageEvent cl = xev.get_xclient(); |
|
1030 |
if ((wm_protocols != null) && (cl.get_message_type() == wm_protocols.getAtom())) { |
|
1031 |
if (cl.get_data(0) == wm_delete_window.getAtom()) { |
|
1032 |
handleQuit(); |
|
1033 |
} else if (cl.get_data(0) == wm_take_focus.getAtom()) { |
|
1034 |
handleWmTakeFocus(cl); |
|
1035 |
} |
|
1036 |
} |
|
1037 |
} |
|
1038 |
||
1039 |
private void handleWmTakeFocus(XClientMessageEvent cl) { |
|
1040 |
focusLog.log(Level.FINE, "WM_TAKE_FOCUS on {0}", new Object[]{this}); |
|
1041 |
requestWindowFocus(cl.get_data(1), true); |
|
1042 |
} |
|
1043 |
||
1044 |
/** |
|
1045 |
* Requests focus to this decorated top-level by requesting X input focus |
|
1046 |
* to the shell window. |
|
1047 |
*/ |
|
1048 |
protected void requestXFocus(long time, boolean timeProvided) { |
|
1049 |
// We have proxied focus mechanism - instead of shell the focus is held |
|
1050 |
// by "proxy" - invisible mapped window. When we want to set X input focus to |
|
1051 |
// toplevel set it on proxy instead. |
|
1052 |
if (focusProxy == null) { |
|
1053 |
if (focusLog.isLoggable(Level.FINE)) focusLog.warning("Focus proxy is null for " + this); |
|
1054 |
} else { |
|
1055 |
if (focusLog.isLoggable(Level.FINE)) focusLog.fine("Requesting focus to proxy: " + focusProxy); |
|
1056 |
if (timeProvided) { |
|
1057 |
focusProxy.xRequestFocus(time); |
|
1058 |
} else { |
|
1059 |
focusProxy.xRequestFocus(); |
|
1060 |
} |
|
1061 |
} |
|
1062 |
} |
|
1063 |
||
1064 |
XFocusProxyWindow getFocusProxy() { |
|
1065 |
return focusProxy; |
|
1066 |
} |
|
1067 |
||
1068 |
public void handleQuit() { |
|
1069 |
postEvent(new WindowEvent((Window)target, WindowEvent.WINDOW_CLOSING)); |
|
1070 |
} |
|
1071 |
||
1072 |
final void dumpMe() { |
|
1073 |
System.err.println(">>> Peer: " + x + ", " + y + ", " + width + ", " + height); |
|
1074 |
} |
|
1075 |
||
1076 |
final void dumpTarget() { |
|
1077 |
int getWidth = ComponentAccessor.getWidth((Component)target); |
|
1078 |
int getHeight = ComponentAccessor.getHeight((Component)target); |
|
1079 |
int getTargetX = ComponentAccessor.getX((Component)target); |
|
1080 |
int getTargetY = ComponentAccessor.getY((Component)target); |
|
1081 |
System.err.println(">>> Target: " + getTargetX + ", " + getTargetY + ", " + getWidth + ", " + getHeight); |
|
1082 |
} |
|
1083 |
||
1084 |
final void dumpShell() { |
|
1085 |
dumpWindow("Shell", getShell()); |
|
1086 |
} |
|
1087 |
final void dumpContent() { |
|
1088 |
dumpWindow("Content", getContentWindow()); |
|
1089 |
} |
|
1090 |
final void dumpParent() { |
|
1091 |
long parent = XlibUtil.getParentWindow(getShell()); |
|
1092 |
if (parent != 0) |
|
1093 |
{ |
|
1094 |
dumpWindow("Parent", parent); |
|
1095 |
} |
|
1096 |
else |
|
1097 |
{ |
|
1098 |
System.err.println(">>> NO PARENT"); |
|
1099 |
} |
|
1100 |
} |
|
1101 |
||
1102 |
final void dumpWindow(String id, long window) { |
|
1103 |
XWindowAttributes pattr = new XWindowAttributes(); |
|
1104 |
try { |
|
1105 |
XToolkit.awtLock(); |
|
1106 |
try { |
|
1107 |
int status = |
|
1108 |
XlibWrapper.XGetWindowAttributes(XToolkit.getDisplay(), |
|
1109 |
window, pattr.pData); |
|
1110 |
} |
|
1111 |
finally { |
|
1112 |
XToolkit.awtUnlock(); |
|
1113 |
} |
|
1114 |
System.err.println(">>>> " + id + ": " + pattr.get_x() |
|
1115 |
+ ", " + pattr.get_y() + ", " + pattr.get_width() |
|
1116 |
+ ", " + pattr.get_height()); |
|
1117 |
} finally { |
|
1118 |
pattr.dispose(); |
|
1119 |
} |
|
1120 |
} |
|
1121 |
||
1122 |
final void dumpAll() { |
|
1123 |
dumpTarget(); |
|
1124 |
dumpMe(); |
|
1125 |
dumpParent(); |
|
1126 |
dumpShell(); |
|
1127 |
dumpContent(); |
|
1128 |
} |
|
1129 |
||
1130 |
boolean isMaximized() { |
|
1131 |
return false; |
|
1132 |
} |
|
1133 |
||
1134 |
boolean isOverrideRedirect() { |
|
1135 |
return false; |
|
1136 |
} |
|
1137 |
||
1138 |
public boolean requestWindowFocus(long time, boolean timeProvided) { |
|
1139 |
focusLog.fine("Request for decorated window focus"); |
|
1140 |
// If this is Frame or Dialog we can't assure focus request success - but we still can try |
|
1141 |
// If this is Window and its owner Frame is active we can be sure request succedded. |
|
1142 |
Window focusedWindow = XKeyboardFocusManagerPeer.getCurrentNativeFocusedWindow(); |
|
1143 |
Window activeWindow = XWindowPeer.getDecoratedOwner(focusedWindow); |
|
1144 |
||
1145 |
focusLog.log(Level.FINER, "Current window is: active={0}, focused={1}", |
|
442
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
1146 |
new Object[]{ Boolean.valueOf(target == activeWindow), |
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
1147 |
Boolean.valueOf(target == focusedWindow)}); |
2 | 1148 |
|
1149 |
XWindowPeer toFocus = this; |
|
1150 |
while (toFocus.nextTransientFor != null) { |
|
1151 |
toFocus = toFocus.nextTransientFor; |
|
1152 |
} |
|
442
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
1153 |
if (toFocus == null || !toFocus.focusAllowedFor()) { |
2 | 1154 |
// This might change when WM will have property to determine focus policy. |
1155 |
// Right now, because policy is unknown we can't be sure we succedded |
|
1156 |
return false; |
|
1157 |
} |
|
442
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
1158 |
if (this == toFocus) { |
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
1159 |
if (isWMStateNetHidden()) { |
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
1160 |
focusLog.fine("The window is unmapped, so rejecting the request"); |
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
1161 |
return false; |
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
1162 |
} |
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
1163 |
if (target == activeWindow && target != focusedWindow) { |
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
1164 |
// Happens when an owned window is currently focused |
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
1165 |
focusLog.fine("Focus is on child window - transfering it back to the owner"); |
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
1166 |
handleWindowFocusInSync(-1); |
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
1167 |
return true; |
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
1168 |
} |
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
1169 |
Window realNativeFocusedWindow = XWindowPeer.getNativeFocusedWindow(); |
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
1170 |
focusLog.finest("Real native focused window: " + realNativeFocusedWindow + |
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
1171 |
"\nKFM's focused window: " + focusedWindow); |
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
1172 |
|
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
1173 |
// See 6522725, 6613426. |
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
1174 |
if (target == realNativeFocusedWindow) { |
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
1175 |
focusLog.fine("The window is already natively focused."); |
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
1176 |
return true; |
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
1177 |
} |
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
1178 |
} |
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
1179 |
focusLog.fine("Requesting focus to " + (this == toFocus ? "this window" : toFocus)); |
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
1180 |
|
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
1181 |
if (timeProvided) { |
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
1182 |
toFocus.requestXFocus(time); |
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
1183 |
} else { |
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
1184 |
toFocus.requestXFocus(); |
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
1185 |
} |
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
1186 |
return (this == toFocus); |
2 | 1187 |
} |
1188 |
||
1189 |
XWindowPeer actualFocusedWindow = null; |
|
1190 |
void setActualFocusedWindow(XWindowPeer actualFocusedWindow) { |
|
1191 |
synchronized(getStateLock()) { |
|
1192 |
this.actualFocusedWindow = actualFocusedWindow; |
|
1193 |
} |
|
1194 |
} |
|
1195 |
||
1196 |
boolean requestWindowFocus(XWindowPeer actualFocusedWindow, |
|
1197 |
long time, boolean timeProvided) |
|
1198 |
{ |
|
1199 |
setActualFocusedWindow(actualFocusedWindow); |
|
1200 |
return requestWindowFocus(time, timeProvided); |
|
1201 |
} |
|
1202 |
public void handleWindowFocusIn(long serial) { |
|
1203 |
if (null == actualFocusedWindow) { |
|
1204 |
super.handleWindowFocusIn(serial); |
|
1205 |
} else { |
|
1206 |
/* |
|
1207 |
* Fix for 6314575. |
|
1208 |
* If this is a result of clicking on one of the Frame's component |
|
1209 |
* then 'actualFocusedWindow' shouldn't be focused. A decision of focusing |
|
1210 |
* it or not should be made after the appropriate Java mouse event (if any) |
|
1211 |
* is handled by the component where 'actualFocusedWindow' value may be reset. |
|
1212 |
* |
|
1213 |
* The fix is based on the empiric fact consisting in that the component |
|
1214 |
* receives native mouse event nearly at the same time the Frame receives |
|
1215 |
* WM_TAKE_FOCUS (when FocusIn is generated via XSetInputFocus call) but |
|
1216 |
* definetely before the Frame gets FocusIn event (when this method is called). |
|
1217 |
*/ |
|
1218 |
postEvent(new InvocationEvent(target, new Runnable() { |
|
1219 |
public void run() { |
|
1220 |
XWindowPeer fw = null; |
|
1221 |
synchronized (getStateLock()) { |
|
1222 |
fw = actualFocusedWindow; |
|
1223 |
actualFocusedWindow = null; |
|
1224 |
if (null == fw || !fw.isVisible() || !fw.isFocusableWindow()) { |
|
1225 |
fw = XDecoratedPeer.this; |
|
1226 |
} |
|
1227 |
} |
|
1228 |
fw.handleWindowFocusIn_Dispatch(); |
|
1229 |
} |
|
1230 |
})); |
|
1231 |
} |
|
1232 |
} |
|
1233 |
||
1234 |
public void handleWindowFocusOut(Window oppositeWindow, long serial) { |
|
1235 |
Window actualFocusedWindow = XKeyboardFocusManagerPeer.getCurrentNativeFocusedWindow(); |
|
1236 |
||
1237 |
// If the actual focused window is not this decorated window then retain it. |
|
1238 |
if (actualFocusedWindow != null && actualFocusedWindow != target) { |
|
1239 |
Window owner = XWindowPeer.getDecoratedOwner(actualFocusedWindow); |
|
1240 |
||
1241 |
if (owner != null && owner == target) { |
|
1242 |
setActualFocusedWindow((XWindowPeer) ComponentAccessor.getPeer(actualFocusedWindow)); |
|
1243 |
} |
|
1244 |
} |
|
1245 |
super.handleWindowFocusOut(oppositeWindow, serial); |
|
1246 |
} |
|
1247 |
||
1248 |
private Point queryXLocation() |
|
1249 |
{ |
|
1250 |
return XlibUtil.translateCoordinates( |
|
1251 |
getContentWindow(), |
|
1252 |
XlibWrapper.RootWindow(XToolkit.getDisplay(), getScreenNumber()), |
|
1253 |
new Point(0, 0)); |
|
1254 |
} |
|
1255 |
} |