author | darcy |
Thu, 13 Mar 2014 12:40:27 -0700 | |
changeset 23647 | 41d22f2dbeb5 |
parent 22584 | eed64ee05369 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
22584
eed64ee05369
8032733: Fix cast lint warnings in client libraries
darcy
parents:
21270
diff
changeset
|
2 |
* Copyright (c) 2003, 2014, Oracle and/or its affiliates. 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 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 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
package sun.awt.X11; |
|
26 |
||
27 |
import java.awt.Component; |
|
28 |
import java.awt.Rectangle; |
|
29 |
import java.awt.Insets; |
|
30 |
||
31 |
import java.awt.event.ComponentEvent; |
|
32 |
||
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
439
diff
changeset
|
33 |
import sun.util.logging.PlatformLogger; |
2 | 34 |
|
4371
dc9dcb8b0ae7
6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents:
4214
diff
changeset
|
35 |
import sun.awt.AWTAccessor; |
2 | 36 |
|
37 |
/** |
|
38 |
* This class implements window which serves as content window for decorated frames. |
|
39 |
* Its purpose to provide correct events dispatching for the complex |
|
40 |
* constructs such as decorated frames. |
|
115 | 41 |
* |
42 |
* It should always be located at (- left inset, - top inset) in the associated |
|
43 |
* decorated window. So coordinates in it would be the same as java coordinates. |
|
2 | 44 |
*/ |
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
115
diff
changeset
|
45 |
public final class XContentWindow extends XWindow { |
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
439
diff
changeset
|
46 |
private static PlatformLogger insLog = PlatformLogger.getLogger("sun.awt.X11.insets.XContentWindow"); |
2 | 47 |
|
115 | 48 |
static XContentWindow createContent(XDecoratedPeer parentFrame) { |
49 |
final WindowDimensions dims = parentFrame.getDimensions(); |
|
50 |
Rectangle rec = dims.getBounds(); |
|
51 |
// Fix for - set the location of the content window to the (-left inset, -top inset) |
|
52 |
Insets ins = dims.getInsets(); |
|
53 |
if (ins != null) { |
|
54 |
rec.x = -ins.left; |
|
55 |
rec.y = -ins.top; |
|
56 |
} else { |
|
57 |
rec.x = 0; |
|
58 |
rec.y = 0; |
|
59 |
} |
|
60 |
final XContentWindow cw = new XContentWindow(parentFrame, rec); |
|
61 |
cw.xSetVisible(true); |
|
62 |
return cw; |
|
63 |
} |
|
64 |
||
65 |
private final XDecoratedPeer parentFrame; |
|
2 | 66 |
|
67 |
// A list of expose events that come when the parentFrame is iconified |
|
115 | 68 |
private final java.util.List<SavedExposeEvent> iconifiedExposeEvents = |
69 |
new java.util.ArrayList<SavedExposeEvent>(); |
|
2 | 70 |
|
115 | 71 |
private XContentWindow(XDecoratedPeer parentFrame, Rectangle bounds) { |
2 | 72 |
super((Component)parentFrame.getTarget(), parentFrame.getShell(), bounds); |
73 |
this.parentFrame = parentFrame; |
|
74 |
} |
|
75 |
||
76 |
void preInit(XCreateWindowParams params) { |
|
77 |
super.preInit(params); |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
115
diff
changeset
|
78 |
params.putIfNull(BIT_GRAVITY, Integer.valueOf(XConstants.NorthWestGravity)); |
2 | 79 |
Long eventMask = (Long)params.get(EVENT_MASK); |
80 |
if (eventMask != null) { |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
115
diff
changeset
|
81 |
eventMask = eventMask & ~(XConstants.StructureNotifyMask); |
2 | 82 |
params.put(EVENT_MASK, eventMask); |
83 |
} |
|
84 |
} |
|
85 |
||
86 |
protected String getWMName() { |
|
87 |
return "Content window"; |
|
88 |
} |
|
89 |
protected boolean isEventDisabled(XEvent e) { |
|
90 |
switch (e.get_type()) { |
|
91 |
// Override parentFrame to receive MouseEnter/Exit |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
115
diff
changeset
|
92 |
case XConstants.EnterNotify: |
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
115
diff
changeset
|
93 |
case XConstants.LeaveNotify: |
2 | 94 |
return false; |
95 |
// We handle ConfigureNotify specifically in XDecoratedPeer |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
115
diff
changeset
|
96 |
case XConstants.ConfigureNotify: |
2 | 97 |
return true; |
98 |
// We don't want SHOWN/HIDDEN on content window since it will duplicate XDecoratedPeer |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
115
diff
changeset
|
99 |
case XConstants.MapNotify: |
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
115
diff
changeset
|
100 |
case XConstants.UnmapNotify: |
2 | 101 |
return true; |
102 |
default: |
|
103 |
return super.isEventDisabled(e) || parentFrame.isEventDisabled(e); |
|
104 |
} |
|
105 |
} |
|
106 |
||
107 |
// Coordinates are that of the shell |
|
108 |
void setContentBounds(WindowDimensions dims) { |
|
109 |
XToolkit.awtLock(); |
|
110 |
try { |
|
111 |
// Bounds of content window are of the same size as bounds of Java window and with |
|
112 |
// location as -(insets) |
|
113 |
Rectangle newBounds = dims.getBounds(); |
|
114 |
Insets in = dims.getInsets(); |
|
115 |
if (in != null) { |
|
116 |
newBounds.setLocation(-in.left, -in.top); |
|
117 |
} |
|
18178
ee71c923891d
8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents:
16839
diff
changeset
|
118 |
if (insLog.isLoggable(PlatformLogger.Level.FINE)) { |
16839
d0f2e97b7359
8010297: Missing isLoggable() checks in logging code
anthony
parents:
5506
diff
changeset
|
119 |
insLog.fine("Setting content bounds {0}, old bounds {1}", |
d0f2e97b7359
8010297: Missing isLoggable() checks in logging code
anthony
parents:
5506
diff
changeset
|
120 |
newBounds, getBounds()); |
d0f2e97b7359
8010297: Missing isLoggable() checks in logging code
anthony
parents:
5506
diff
changeset
|
121 |
} |
2 | 122 |
// Fix for 5023533: |
123 |
// Change in the size of the content window means, well, change of the size |
|
124 |
// Change in the location of the content window means change in insets |
|
125 |
boolean needHandleResize = !(newBounds.equals(getBounds())); |
|
126 |
reshape(newBounds); |
|
127 |
if (needHandleResize) { |
|
128 |
insLog.fine("Sending RESIZED"); |
|
129 |
handleResize(newBounds); |
|
130 |
} |
|
131 |
} finally { |
|
132 |
XToolkit.awtUnlock(); |
|
133 |
} |
|
134 |
validateSurface(); |
|
135 |
} |
|
136 |
||
137 |
// NOTE: This method may be called by privileged threads. |
|
138 |
// DO NOT INVOKE CLIENT CODE ON THIS THREAD! |
|
139 |
public void handleResize(Rectangle bounds) { |
|
22584
eed64ee05369
8032733: Fix cast lint warnings in client libraries
darcy
parents:
21270
diff
changeset
|
140 |
AWTAccessor.getComponentAccessor().setSize(target, bounds.width, bounds.height); |
2 | 141 |
postEvent(new ComponentEvent(target, ComponentEvent.COMPONENT_RESIZED)); |
142 |
} |
|
143 |
||
144 |
||
21270
8a0fc12b81a2
7090424: TestGlyphVectorLayout failed automately with java.lang.StackOverflowError
serb
parents:
18178
diff
changeset
|
145 |
public void postPaintEvent(Component target, int x, int y, int w, int h) { |
2 | 146 |
// TODO: ? |
147 |
// get rid of 'istanceof' by subclassing: |
|
148 |
// XContentWindow -> XFrameContentWindow |
|
149 |
||
150 |
// Expose event(s) that result from deiconification |
|
151 |
// come before a deicinofication notification. |
|
152 |
// We reorder these events by saving all expose events |
|
153 |
// that come when the frame is iconified. Then we |
|
154 |
// actually handle saved expose events on deiconification. |
|
155 |
||
156 |
if (parentFrame instanceof XFramePeer && |
|
157 |
(((XFramePeer)parentFrame).getState() & java.awt.Frame.ICONIFIED) != 0) { |
|
158 |
// Save expose events if the frame is iconified |
|
159 |
// in order to handle them on deiconification. |
|
160 |
iconifiedExposeEvents.add(new SavedExposeEvent(target, x, y, w, h)); |
|
161 |
} else { |
|
162 |
// Normal case: [it is not a frame or] the frame is not iconified. |
|
21270
8a0fc12b81a2
7090424: TestGlyphVectorLayout failed automately with java.lang.StackOverflowError
serb
parents:
18178
diff
changeset
|
163 |
super.postPaintEvent(target, x, y, w, h); |
2 | 164 |
} |
165 |
} |
|
166 |
||
167 |
void purgeIconifiedExposeEvents() { |
|
168 |
for (SavedExposeEvent evt : iconifiedExposeEvents) { |
|
21270
8a0fc12b81a2
7090424: TestGlyphVectorLayout failed automately with java.lang.StackOverflowError
serb
parents:
18178
diff
changeset
|
169 |
super.postPaintEvent(evt.target, evt.x, evt.y, evt.w, evt.h); |
2 | 170 |
} |
171 |
iconifiedExposeEvents.clear(); |
|
172 |
} |
|
173 |
||
174 |
private static class SavedExposeEvent { |
|
175 |
Component target; |
|
176 |
int x, y, w, h; |
|
177 |
SavedExposeEvent(Component target, int x, int y, int w, int h) { |
|
178 |
this.target = target; |
|
179 |
this.x = x; |
|
180 |
this.y = y; |
|
181 |
this.w = w; |
|
182 |
this.h = h; |
|
183 |
} |
|
184 |
} |
|
185 |
||
186 |
public String toString() { |
|
187 |
return getClass().getName() + "[" + getBounds() + "]"; |
|
188 |
} |
|
189 |
} |