1 /*
2 * Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved.
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. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
151 }
152 public long getSite(int x, int y) {
153 assert XToolkit.isAWTLockHeldByCurrentThread();
154
155 Iterator<Long> iter = sites.iterator();
156 while (iter.hasNext()) {
157 Long l = iter.next();
158 long window = l.longValue();
159
160 Point p = XBaseWindow.toOtherWindow(getRoot(), window, x, y);
161
162 if (p == null) {
163 continue;
164 }
165
166 int dest_x = p.x;
167 int dest_y = p.y;
168 if (dest_x >= 0 && dest_y >= 0) {
169 XWindowAttributes wattr = new XWindowAttributes();
170 try {
171 XToolkit.WITH_XERROR_HANDLER(XErrorHandler.IgnoreBadWindowHandler.getInstance());
172 int status = XlibWrapper.XGetWindowAttributes(XToolkit.getDisplay(),
173 window, wattr.pData);
174 XToolkit.RESTORE_XERROR_HANDLER();
175
176 if (status == 0 ||
177 (XToolkit.saved_error != null &&
178 XToolkit.saved_error.get_error_code() != XConstants.Success)) {
179 continue;
180 }
181
182 if (wattr.get_map_state() != XConstants.IsUnmapped
183 && dest_x < wattr.get_width()
184 && dest_y < wattr.get_height()) {
185 return window;
186 }
187 } finally {
188 wattr.dispose();
189 }
190 }
191 }
192 return 0;
193 }
194 }
195
196 private final HashMap<Long, EmbeddedDropSiteEntry> embeddedDropSiteRegistry =
197 new HashMap<Long, EmbeddedDropSiteEntry>();
198
205 List<XDropTargetProtocol> embedderProtocols = new ArrayList();
206
207 while (dropTargetProtocols.hasNext()) {
208 XDropTargetProtocol dropTargetProtocol =
209 (XDropTargetProtocol)dropTargetProtocols.next();
210 if (dropTargetProtocol.isProtocolSupported(embedder)) {
211 embedderProtocols.add(dropTargetProtocol);
212 }
213 }
214
215 embedderProtocols = Collections.unmodifiableList(embedderProtocols);
216
217 /* Grab server, since we are working with the window that belongs to
218 another client. */
219 XlibWrapper.XGrabServer(XToolkit.getDisplay());
220 try {
221 long root = 0;
222 long event_mask = 0;
223 XWindowAttributes wattr = new XWindowAttributes();
224 try {
225 XToolkit.WITH_XERROR_HANDLER(XErrorHandler.IgnoreBadWindowHandler.getInstance());
226 int status = XlibWrapper.XGetWindowAttributes(XToolkit.getDisplay(),
227 embedder, wattr.pData);
228 XToolkit.RESTORE_XERROR_HANDLER();
229
230 if (status == 0 ||
231 (XToolkit.saved_error != null &&
232 XToolkit.saved_error.get_error_code() != XConstants.Success)) {
233 throw new XException("XGetWindowAttributes failed");
234 }
235
236 event_mask = wattr.get_your_event_mask();
237 root = wattr.get_root();
238 } finally {
239 wattr.dispose();
240 }
241
242 if ((event_mask & XConstants.PropertyChangeMask) == 0) {
243 XToolkit.WITH_XERROR_HANDLER(XErrorHandler.IgnoreBadWindowHandler.getInstance());
244 XlibWrapper.XSelectInput(XToolkit.getDisplay(), embedder,
245 event_mask | XConstants.PropertyChangeMask);
246 XToolkit.RESTORE_XERROR_HANDLER();
247
248 if (XToolkit.saved_error != null &&
249 XToolkit.saved_error.get_error_code() != XConstants.Success) {
250 throw new XException("XSelectInput failed");
251 }
252 }
253
254 return new EmbeddedDropSiteEntry(root, event_mask, embedderProtocols);
255 } finally {
256 XlibWrapper.XUngrabServer(XToolkit.getDisplay());
257 }
258 }
259
260 private static final boolean XEMBED_PROTOCOLS = true;
261 private static final boolean NON_XEMBED_PROTOCOLS = false;
262
263 private void registerProtocols(long embedder, boolean protocols,
264 List<XDropTargetProtocol> supportedProtocols) {
265 Iterator dropTargetProtocols = null;
266
267 /*
268 * By default, we register a drop site that supports all dnd
269 * protocols. This approach is not appropriate in plugin
377 EmbeddedDropSiteEntry entry) {
378 assert XToolkit.isAWTLockHeldByCurrentThread();
379
380 Iterator dropTargetProtocols =
381 XDragAndDropProtocols.getDropTargetProtocols();
382
383 /* Grab server, since we are working with the window that belongs to
384 another client. */
385 XlibWrapper.XGrabServer(XToolkit.getDisplay());
386 try {
387 while (dropTargetProtocols.hasNext()) {
388 XDropTargetProtocol dropTargetProtocol =
389 (XDropTargetProtocol)dropTargetProtocols.next();
390 dropTargetProtocol.unregisterEmbedderDropSite(embedder);
391 }
392
393 long event_mask = entry.getEventMask();
394
395 /* Restore the original event mask for the embedder. */
396 if ((event_mask & XConstants.PropertyChangeMask) == 0) {
397 XToolkit.WITH_XERROR_HANDLER(XErrorHandler.IgnoreBadWindowHandler.getInstance());
398 XlibWrapper.XSelectInput(XToolkit.getDisplay(), embedder,
399 event_mask);
400 XToolkit.RESTORE_XERROR_HANDLER();
401
402 if (XToolkit.saved_error != null &&
403 XToolkit.saved_error.get_error_code() != XConstants.Success) {
404 throw new XException("XSelectInput failed");
405 }
406 }
407 } finally {
408 XlibWrapper.XUngrabServer(XToolkit.getDisplay());
409 }
410 }
411
412 private void registerEmbeddedDropSite(long toplevel, long window) {
413 XBaseWindow xBaseWindow = XToolkit.windowToXWindow(window);
414 boolean isXEmbedClient =
415 (xBaseWindow instanceof XEmbeddedFramePeer) &&
416 ((XEmbeddedFramePeer)xBaseWindow).isXEmbedActive();
417
418 XEmbedCanvasPeer peer = null;
419 {
420 XBaseWindow xbaseWindow = XToolkit.windowToXWindow(toplevel);
421 if (xbaseWindow != null) {
422 if (xbaseWindow instanceof XEmbedCanvasPeer) {
423 peer = (XEmbedCanvasPeer)xbaseWindow;
|
1 /*
2 * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
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. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
151 }
152 public long getSite(int x, int y) {
153 assert XToolkit.isAWTLockHeldByCurrentThread();
154
155 Iterator<Long> iter = sites.iterator();
156 while (iter.hasNext()) {
157 Long l = iter.next();
158 long window = l.longValue();
159
160 Point p = XBaseWindow.toOtherWindow(getRoot(), window, x, y);
161
162 if (p == null) {
163 continue;
164 }
165
166 int dest_x = p.x;
167 int dest_y = p.y;
168 if (dest_x >= 0 && dest_y >= 0) {
169 XWindowAttributes wattr = new XWindowAttributes();
170 try {
171 XErrorHandlerUtil.WITH_XERROR_HANDLER(XErrorHandler.IgnoreBadWindowHandler.getInstance());
172 int status = XlibWrapper.XGetWindowAttributes(XToolkit.getDisplay(),
173 window, wattr.pData);
174 XErrorHandlerUtil.RESTORE_XERROR_HANDLER();
175
176 if ((status == 0) ||
177 ((XErrorHandlerUtil.saved_error != null) &&
178 (XErrorHandlerUtil.saved_error.get_error_code() != XConstants.Success))) {
179 continue;
180 }
181
182 if (wattr.get_map_state() != XConstants.IsUnmapped
183 && dest_x < wattr.get_width()
184 && dest_y < wattr.get_height()) {
185 return window;
186 }
187 } finally {
188 wattr.dispose();
189 }
190 }
191 }
192 return 0;
193 }
194 }
195
196 private final HashMap<Long, EmbeddedDropSiteEntry> embeddedDropSiteRegistry =
197 new HashMap<Long, EmbeddedDropSiteEntry>();
198
205 List<XDropTargetProtocol> embedderProtocols = new ArrayList();
206
207 while (dropTargetProtocols.hasNext()) {
208 XDropTargetProtocol dropTargetProtocol =
209 (XDropTargetProtocol)dropTargetProtocols.next();
210 if (dropTargetProtocol.isProtocolSupported(embedder)) {
211 embedderProtocols.add(dropTargetProtocol);
212 }
213 }
214
215 embedderProtocols = Collections.unmodifiableList(embedderProtocols);
216
217 /* Grab server, since we are working with the window that belongs to
218 another client. */
219 XlibWrapper.XGrabServer(XToolkit.getDisplay());
220 try {
221 long root = 0;
222 long event_mask = 0;
223 XWindowAttributes wattr = new XWindowAttributes();
224 try {
225 XErrorHandlerUtil.WITH_XERROR_HANDLER(XErrorHandler.IgnoreBadWindowHandler.getInstance());
226 int status = XlibWrapper.XGetWindowAttributes(XToolkit.getDisplay(),
227 embedder, wattr.pData);
228 XErrorHandlerUtil.RESTORE_XERROR_HANDLER();
229
230 if ((status == 0) ||
231 ((XErrorHandlerUtil.saved_error != null) &&
232 (XErrorHandlerUtil.saved_error.get_error_code() != XConstants.Success))) {
233 throw new XException("XGetWindowAttributes failed");
234 }
235
236 event_mask = wattr.get_your_event_mask();
237 root = wattr.get_root();
238 } finally {
239 wattr.dispose();
240 }
241
242 if ((event_mask & XConstants.PropertyChangeMask) == 0) {
243 XErrorHandlerUtil.WITH_XERROR_HANDLER(XErrorHandler.IgnoreBadWindowHandler.getInstance());
244 XlibWrapper.XSelectInput(XToolkit.getDisplay(), embedder,
245 event_mask | XConstants.PropertyChangeMask);
246 XErrorHandlerUtil.RESTORE_XERROR_HANDLER();
247
248 if ((XErrorHandlerUtil.saved_error != null) &&
249 (XErrorHandlerUtil.saved_error.get_error_code() != XConstants.Success)) {
250 throw new XException("XSelectInput failed");
251 }
252 }
253
254 return new EmbeddedDropSiteEntry(root, event_mask, embedderProtocols);
255 } finally {
256 XlibWrapper.XUngrabServer(XToolkit.getDisplay());
257 }
258 }
259
260 private static final boolean XEMBED_PROTOCOLS = true;
261 private static final boolean NON_XEMBED_PROTOCOLS = false;
262
263 private void registerProtocols(long embedder, boolean protocols,
264 List<XDropTargetProtocol> supportedProtocols) {
265 Iterator dropTargetProtocols = null;
266
267 /*
268 * By default, we register a drop site that supports all dnd
269 * protocols. This approach is not appropriate in plugin
377 EmbeddedDropSiteEntry entry) {
378 assert XToolkit.isAWTLockHeldByCurrentThread();
379
380 Iterator dropTargetProtocols =
381 XDragAndDropProtocols.getDropTargetProtocols();
382
383 /* Grab server, since we are working with the window that belongs to
384 another client. */
385 XlibWrapper.XGrabServer(XToolkit.getDisplay());
386 try {
387 while (dropTargetProtocols.hasNext()) {
388 XDropTargetProtocol dropTargetProtocol =
389 (XDropTargetProtocol)dropTargetProtocols.next();
390 dropTargetProtocol.unregisterEmbedderDropSite(embedder);
391 }
392
393 long event_mask = entry.getEventMask();
394
395 /* Restore the original event mask for the embedder. */
396 if ((event_mask & XConstants.PropertyChangeMask) == 0) {
397 XErrorHandlerUtil.WITH_XERROR_HANDLER(XErrorHandler.IgnoreBadWindowHandler.getInstance());
398 XlibWrapper.XSelectInput(XToolkit.getDisplay(), embedder,
399 event_mask);
400 XErrorHandlerUtil.RESTORE_XERROR_HANDLER();
401
402 if ((XErrorHandlerUtil.saved_error != null) &&
403 (XErrorHandlerUtil.saved_error.get_error_code() != XConstants.Success)) {
404 throw new XException("XSelectInput failed");
405 }
406 }
407 } finally {
408 XlibWrapper.XUngrabServer(XToolkit.getDisplay());
409 }
410 }
411
412 private void registerEmbeddedDropSite(long toplevel, long window) {
413 XBaseWindow xBaseWindow = XToolkit.windowToXWindow(window);
414 boolean isXEmbedClient =
415 (xBaseWindow instanceof XEmbeddedFramePeer) &&
416 ((XEmbeddedFramePeer)xBaseWindow).isXEmbedActive();
417
418 XEmbedCanvasPeer peer = null;
419 {
420 XBaseWindow xbaseWindow = XToolkit.windowToXWindow(toplevel);
421 if (xbaseWindow != null) {
422 if (xbaseWindow instanceof XEmbedCanvasPeer) {
423 peer = (XEmbedCanvasPeer)xbaseWindow;
|