143 if (parentWindowID != null) {
144 parentWindow = XToolkit.windowToXWindow(parentWindowID);
145 }
146 }
147
148 Long eventMask = (Long)params.get(EVENT_MASK);
149 if (eventMask != null) {
150 long mask = eventMask.longValue();
151 mask |= XConstants.SubstructureNotifyMask;
152 params.put(EVENT_MASK, mask);
153 }
154
155 screen = -1;
156 }
157
158 /**
159 * Called after window creation, descendants should override to initialize Window
160 * with class-specific values and perform post-initialization actions.
161 */
162 void postInit(XCreateWindowParams params) {
163 if (log.isLoggable(PlatformLogger.FINE)) {
164 log.fine("WM name is " + getWMName());
165 }
166 updateWMName();
167
168 // Set WM_CLIENT_LEADER property
169 initClientLeader();
170 }
171
172 /**
173 * Creates window using parameters <code>params</code>
174 * If params contain flag DELAYED doesn't do anything.
175 * Note: Descendants can call this method to create the window
176 * at the time different to instance construction.
177 */
178 protected final void init(XCreateWindowParams params) {
179 awtLock();
180 initialising = InitialiseState.INITIALISING;
181 awtUnlock();
182
183 try {
345 }
346
347 Boolean saveUnder = (Boolean)params.get(SAVE_UNDER);
348 if (saveUnder != null) {
349 xattr.set_save_under(saveUnder.booleanValue());
350 value_mask |= XConstants.CWSaveUnder;
351 }
352
353 Integer backingStore = (Integer)params.get(BACKING_STORE);
354 if (backingStore != null) {
355 xattr.set_backing_store(backingStore.intValue());
356 value_mask |= XConstants.CWBackingStore;
357 }
358
359 Integer bitGravity = (Integer)params.get(BIT_GRAVITY);
360 if (bitGravity != null) {
361 xattr.set_bit_gravity(bitGravity.intValue());
362 value_mask |= XConstants.CWBitGravity;
363 }
364
365 if (log.isLoggable(PlatformLogger.FINE)) {
366 log.fine("Creating window for " + this + " with the following attributes: \n" + params);
367 }
368 window = XlibWrapper.XCreateWindow(XToolkit.getDisplay(),
369 parentWindow.longValue(),
370 bounds.x, bounds.y, // location
371 bounds.width, bounds.height, // size
372 0, // border
373 depth.intValue(), // depth
374 visual_class.intValue(), // class
375 visual.longValue(), // visual
376 value_mask, // value mask
377 xattr.pData); // attributes
378
379 if (window == 0) {
380 throw new IllegalStateException("Couldn't create window because of wrong parameters. Run with NOISY_AWT to see details");
381 }
382 XToolkit.addToWinMap(window, this);
383 } finally {
384 xattr.dispose();
385 }
465 }
466 return wmHints;
467 }
468
469
470 /*
471 * Call this method under AWTLock.
472 * The lock should be acquired untill all operations with XSizeHints are completed.
473 */
474 public XSizeHints getHints() {
475 if (hints == null) {
476 long p_hints = XlibWrapper.XAllocSizeHints();
477 hints = new XSizeHints(p_hints);
478 // XlibWrapper.XGetWMNormalHints(XToolkit.getDisplay(), getWindow(), p_hints, XlibWrapper.larg1);
479 // TODO: Shouldn't we listen for WM updates on this property?
480 }
481 return hints;
482 }
483
484 public void setSizeHints(long flags, int x, int y, int width, int height) {
485 if (insLog.isLoggable(PlatformLogger.FINER)) {
486 insLog.finer("Setting hints, flags " + XlibWrapper.hintsToString(flags));
487 }
488 XToolkit.awtLock();
489 try {
490 XSizeHints hints = getHints();
491 // Note: if PPosition is not set in flags this means that
492 // we want to reset PPosition in hints. This is necessary
493 // for locationByPlatform functionality
494 if ((flags & XUtilConstants.PPosition) != 0) {
495 hints.set_x(x);
496 hints.set_y(y);
497 }
498 if ((flags & XUtilConstants.PSize) != 0) {
499 hints.set_width(width);
500 hints.set_height(height);
501 } else if ((hints.get_flags() & XUtilConstants.PSize) != 0) {
502 flags |= XUtilConstants.PSize;
503 }
504 if ((flags & XUtilConstants.PMinSize) != 0) {
505 hints.set_min_width(width);
528 } else if ((hints.get_flags() & XUtilConstants.PMaxSize) != 0) {
529 flags |= XUtilConstants.PMaxSize;
530 if (maxBounds != null) {
531 if (maxBounds.width != Integer.MAX_VALUE) {
532 hints.set_max_width(maxBounds.width);
533 } else {
534 hints.set_max_width(XToolkit.getDefaultScreenWidth());
535 }
536 if (maxBounds.height != Integer.MAX_VALUE) {
537 hints.set_max_height(maxBounds.height);
538 } else {
539 hints.set_max_height(XToolkit.getDefaultScreenHeight());
540 }
541 } else {
542 // Leave intact
543 }
544 }
545 flags |= XUtilConstants.PWinGravity;
546 hints.set_flags(flags);
547 hints.set_win_gravity((int)XConstants.NorthWestGravity);
548 if (insLog.isLoggable(PlatformLogger.FINER)) {
549 insLog.finer("Setting hints, resulted flags " + XlibWrapper.hintsToString(flags) +
550 ", values " + hints);
551 }
552 XlibWrapper.XSetWMNormalHints(XToolkit.getDisplay(), getWindow(), hints.pData);
553 } finally {
554 XToolkit.awtUnlock();
555 }
556 }
557
558 public boolean isMinSizeSet() {
559 XSizeHints hints = getHints();
560 long flags = hints.get_flags();
561 return ((flags & XUtilConstants.PMinSize) == XUtilConstants.PMinSize);
562 }
563
564 /**
565 * This lock object can be used to protect instance data from concurrent access
566 * by two threads. If both state lock and AWT lock are taken, AWT Lock should be taken first.
567 */
568 Object getStateLock() {
582
583 public Rectangle getBounds() {
584 return new Rectangle(x, y, width, height);
585 }
586 public Dimension getSize() {
587 return new Dimension(width, height);
588 }
589
590
591 public void toFront() {
592 XToolkit.awtLock();
593 try {
594 XlibWrapper.XRaiseWindow(XToolkit.getDisplay(), getWindow());
595 } finally {
596 XToolkit.awtUnlock();
597 }
598 }
599 public void xRequestFocus(long time) {
600 XToolkit.awtLock();
601 try {
602 if (focusLog.isLoggable(PlatformLogger.FINER)) {
603 focusLog.finer("XSetInputFocus on " + Long.toHexString(getWindow()) + " with time " + time);
604 }
605 XlibWrapper.XSetInputFocus2(XToolkit.getDisplay(), getWindow(), time);
606 } finally {
607 XToolkit.awtUnlock();
608 }
609 }
610 public void xRequestFocus() {
611 XToolkit.awtLock();
612 try {
613 if (focusLog.isLoggable(PlatformLogger.FINER)) {
614 focusLog.finer("XSetInputFocus on " + Long.toHexString(getWindow()));
615 }
616 XlibWrapper.XSetInputFocus(XToolkit.getDisplay(), getWindow());
617 } finally {
618 XToolkit.awtUnlock();
619 }
620 }
621
622 public static long xGetInputFocus() {
623 XToolkit.awtLock();
624 try {
625 return XlibWrapper.XGetInputFocus(XToolkit.getDisplay());
626 } finally {
627 XToolkit.awtUnlock();
628 }
629 }
630
631 public void xSetVisible(boolean visible) {
632 if (log.isLoggable(PlatformLogger.FINE)) {
633 log.fine("Setting visible on " + this + " to " + visible);
634 }
635 XToolkit.awtLock();
636 try {
637 this.visible = visible;
638 if (visible) {
639 XlibWrapper.XMapWindow(XToolkit.getDisplay(), getWindow());
640 }
641 else {
642 XlibWrapper.XUnmapWindow(XToolkit.getDisplay(), getWindow());
643 }
644 XlibWrapper.XFlush(XToolkit.getDisplay());
645 } finally {
646 XToolkit.awtUnlock();
647 }
648 }
649
650 boolean isMapped() {
651 return mapped;
652 }
699 XToolkit.awtUnlock();
700 }
701 }
702
703 long getScreen() {
704 if (screen == -1) { // Not initialized
705 screen = getScreenOfWindow(window);
706 }
707 return screen;
708 }
709
710 public void xSetBounds(Rectangle bounds) {
711 xSetBounds(bounds.x, bounds.y, bounds.width, bounds.height);
712 }
713
714 public void xSetBounds(int x, int y, int width, int height) {
715 if (getWindow() == 0) {
716 insLog.warning("Attempt to resize uncreated window");
717 throw new IllegalStateException("Attempt to resize uncreated window");
718 }
719 if (insLog.isLoggable(PlatformLogger.FINE)) {
720 insLog.fine("Setting bounds on " + this + " to (" + x + ", " + y + "), " + width + "x" + height);
721 }
722 width = Math.max(MIN_SIZE, width);
723 height = Math.max(MIN_SIZE, height);
724 XToolkit.awtLock();
725 try {
726 XlibWrapper.XMoveResizeWindow(XToolkit.getDisplay(), getWindow(), x,y,width,height);
727 } finally {
728 XToolkit.awtUnlock();
729 }
730 }
731
732 /**
733 * Translate coordinates from one window into another. Optimized
734 * for XAWT - uses cached data when possible. Preferable over
735 * pure XTranslateCoordinates.
736 * @return coordinates relative to dst, or null if error happened
737 */
738 static Point toOtherWindow(long src, long dst, int x, int y) {
739 Point rpt = new Point(0, 0);
817 try {
818 root = XlibWrapper.RootWindow(XToolkit.getDisplay(),
819 getScreenNumber());
820 } finally {
821 XToolkit.awtUnlock();
822 }
823 Point p = toOtherWindow(root, getContentWindow(), x, y);
824 if (p != null) {
825 return p;
826 } else {
827 return new Point(x, y);
828 }
829 }
830
831 /**
832 * We should always grab both keyboard and pointer to control event flow
833 * on popups. This also simplifies synthetic grab implementation.
834 * The active grab overrides activated automatic grab.
835 */
836 public boolean grabInput() {
837 if (grabLog.isLoggable(PlatformLogger.FINE)) {
838 grabLog.fine("Grab input on {0}", this);
839 }
840
841 XToolkit.awtLock();
842 try {
843 if (XAwtState.getGrabWindow() == this &&
844 XAwtState.isManualGrab())
845 {
846 grabLog.fine(" Already Grabbed");
847 return true;
848 }
849 //6273031: PIT. Choice drop down does not close once it is right clicked to show a popup menu
850 //remember previous window having grab and if it's not null ungrab it.
851 XBaseWindow prevGrabWindow = XAwtState.getGrabWindow();
852 final int eventMask = (int) (XConstants.ButtonPressMask | XConstants.ButtonReleaseMask
853 | XConstants.EnterWindowMask | XConstants.LeaveWindowMask | XConstants.PointerMotionMask
854 | XConstants.ButtonMotionMask);
855 final int ownerEvents = 1;
856
857
882 XAwtState.setGrabWindow(null);
883 grabLog.fine(" Grab Failure - keyboard");
884 return false;
885 }
886 }
887 if (prevGrabWindow != null) {
888 prevGrabWindow.ungrabInputImpl();
889 }
890 XAwtState.setGrabWindow(this);
891 grabLog.fine(" Grab - success");
892 return true;
893 } finally {
894 XToolkit.awtUnlock();
895 }
896 }
897
898 static void ungrabInput() {
899 XToolkit.awtLock();
900 try {
901 XBaseWindow grabWindow = XAwtState.getGrabWindow();
902 if (grabLog.isLoggable(PlatformLogger.FINE)) {
903 grabLog.fine("UnGrab input on {0}", grabWindow);
904 }
905 if (grabWindow != null) {
906 grabWindow.ungrabInputImpl();
907 if (!XToolkit.getSunAwtDisableGrab()) {
908 XlibWrapper.XUngrabPointer(XToolkit.getDisplay(), XConstants.CurrentTime);
909 XlibWrapper.XUngrabKeyboard(XToolkit.getDisplay(), XConstants.CurrentTime);
910 }
911 XAwtState.setGrabWindow(null);
912 // we need to call XFlush() here to force ungrab
913 // see 6384219 for details
914 XlibWrapper.XFlush(XToolkit.getDisplay());
915 }
916 } finally {
917 XToolkit.awtUnlock();
918 }
919 }
920
921 // called from ungrabInput, used in popup windows to hide theirselfs in ungrabbing
922 void ungrabInputImpl() {
926 if (XToolkit.isSecurityWarningEnabled() && XToolkit.isToolkitThread()) {
927 StackTraceElement stack[] = (new Throwable()).getStackTrace();
928 log.warning(stack[1] + ": Security violation: calling user code on toolkit thread");
929 }
930 }
931
932 public Set<Long> getChildren() {
933 synchronized (getStateLock()) {
934 return new HashSet<Long>(children);
935 }
936 }
937
938 // -------------- Event handling ----------------
939 public void handleMapNotifyEvent(XEvent xev) {
940 mapped = true;
941 }
942 public void handleUnmapNotifyEvent(XEvent xev) {
943 mapped = false;
944 }
945 public void handleReparentNotifyEvent(XEvent xev) {
946 if (eventLog.isLoggable(PlatformLogger.FINER)) {
947 XReparentEvent msg = xev.get_xreparent();
948 eventLog.finer(msg.toString());
949 }
950 }
951 public void handlePropertyNotify(XEvent xev) {
952 XPropertyEvent msg = xev.get_xproperty();
953 if (XPropertyCache.isCachingSupported()) {
954 XPropertyCache.clearCache(window, XAtom.get(msg.get_atom()));
955 }
956 if (eventLog.isLoggable(PlatformLogger.FINER)) {
957 eventLog.finer("{0}", msg);
958 }
959 }
960
961 public void handleDestroyNotify(XEvent xev) {
962 XAnyEvent xany = xev.get_xany();
963 if (xany.get_window() == getWindow()) {
964 XToolkit.removeFromWinMap(getWindow(), this);
965 if (XPropertyCache.isCachingSupported()) {
966 XPropertyCache.clearCache(getWindow());
967 }
968 }
969 if (xany.get_window() != getWindow()) {
970 synchronized (getStateLock()) {
971 children.remove(xany.get_window());
972 }
973 }
974 }
975
976 public void handleCreateNotify(XEvent xev) {
977 XAnyEvent xany = xev.get_xany();
978 if (xany.get_window() != getWindow()) {
979 synchronized (getStateLock()) {
980 children.add(xany.get_window());
981 }
982 }
983 }
984
985 public void handleClientMessage(XEvent xev) {
986 if (eventLog.isLoggable(PlatformLogger.FINER)) {
987 XClientMessageEvent msg = xev.get_xclient();
988 eventLog.finer(msg.toString());
989 }
990 }
991
992 public void handleVisibilityEvent(XEvent xev) {
993 }
994 public void handleKeyPress(XEvent xev) {
995 }
996 public void handleKeyRelease(XEvent xev) {
997 }
998 public void handleExposeEvent(XEvent xev) {
999 }
1000 /**
1001 * Activate automatic grab on first ButtonPress,
1002 * deactivate on full mouse release
1003 */
1004 public void handleButtonPressRelease(XEvent xev) {
1005 XButtonEvent xbe = xev.get_xbutton();
1006 /*
1022 // A click in a client area drops the actual focused window retaining.
1023 parent.setActualFocusedWindow(null);
1024 parent.requestWindowFocus(xbe.get_time(), true);
1025 }
1026 XAwtState.setAutoGrabWindow(this);
1027 }
1028 break;
1029 case XConstants.ButtonRelease:
1030 if (isFullRelease(buttonState, xbe.get_button())) {
1031 XAwtState.setAutoGrabWindow(null);
1032 }
1033 break;
1034 }
1035 }
1036 public void handleMotionNotify(XEvent xev) {
1037 }
1038 public void handleXCrossingEvent(XEvent xev) {
1039 }
1040 public void handleConfigureNotifyEvent(XEvent xev) {
1041 XConfigureEvent xe = xev.get_xconfigure();
1042 if (insLog.isLoggable(PlatformLogger.FINER)) {
1043 insLog.finer("Configure, {0}", xe);
1044 }
1045 x = xe.get_x();
1046 y = xe.get_y();
1047 width = xe.get_width();
1048 height = xe.get_height();
1049 }
1050 /**
1051 * Checks ButtonRelease released all Mouse buttons
1052 */
1053 static boolean isFullRelease(int buttonState, int button) {
1054 final int buttonsNumber = XToolkit.getNumberOfButtonsForMask();
1055
1056 if (button < 0 || button > buttonsNumber) {
1057 return buttonState == 0;
1058 } else {
1059 return buttonState == XlibUtil.getButtonMask(button);
1060 }
1061 }
1062
1075 return (target instanceof XWindowPeer);
1076 default:
1077 return false;
1078 }
1079 }
1080 /**
1081 * Dispatches event to the grab Window or event source window depending
1082 * on whether the grab is active and on the event type
1083 */
1084 static void dispatchToWindow(XEvent ev) {
1085 XBaseWindow target = XAwtState.getGrabWindow();
1086 if (target == null || !isGrabbedEvent(ev, target)) {
1087 target = XToolkit.windowToXWindow(ev.get_xany().get_window());
1088 }
1089 if (target != null && target.checkInitialised()) {
1090 target.dispatchEvent(ev);
1091 }
1092 }
1093
1094 public void dispatchEvent(XEvent xev) {
1095 if (eventLog.isLoggable(PlatformLogger.FINEST)) {
1096 eventLog.finest(xev.toString());
1097 }
1098 int type = xev.get_type();
1099
1100 if (isDisposed()) {
1101 return;
1102 }
1103
1104 switch (type)
1105 {
1106 case XConstants.VisibilityNotify:
1107 handleVisibilityEvent(xev);
1108 break;
1109 case XConstants.ClientMessage:
1110 handleClientMessage(xev);
1111 break;
1112 case XConstants.Expose :
1113 case XConstants.GraphicsExpose :
1114 handleExposeEvent(xev);
1115 break;
|
143 if (parentWindowID != null) {
144 parentWindow = XToolkit.windowToXWindow(parentWindowID);
145 }
146 }
147
148 Long eventMask = (Long)params.get(EVENT_MASK);
149 if (eventMask != null) {
150 long mask = eventMask.longValue();
151 mask |= XConstants.SubstructureNotifyMask;
152 params.put(EVENT_MASK, mask);
153 }
154
155 screen = -1;
156 }
157
158 /**
159 * Called after window creation, descendants should override to initialize Window
160 * with class-specific values and perform post-initialization actions.
161 */
162 void postInit(XCreateWindowParams params) {
163 if (log.isLoggable(PlatformLogger.Level.FINE)) {
164 log.fine("WM name is " + getWMName());
165 }
166 updateWMName();
167
168 // Set WM_CLIENT_LEADER property
169 initClientLeader();
170 }
171
172 /**
173 * Creates window using parameters <code>params</code>
174 * If params contain flag DELAYED doesn't do anything.
175 * Note: Descendants can call this method to create the window
176 * at the time different to instance construction.
177 */
178 protected final void init(XCreateWindowParams params) {
179 awtLock();
180 initialising = InitialiseState.INITIALISING;
181 awtUnlock();
182
183 try {
345 }
346
347 Boolean saveUnder = (Boolean)params.get(SAVE_UNDER);
348 if (saveUnder != null) {
349 xattr.set_save_under(saveUnder.booleanValue());
350 value_mask |= XConstants.CWSaveUnder;
351 }
352
353 Integer backingStore = (Integer)params.get(BACKING_STORE);
354 if (backingStore != null) {
355 xattr.set_backing_store(backingStore.intValue());
356 value_mask |= XConstants.CWBackingStore;
357 }
358
359 Integer bitGravity = (Integer)params.get(BIT_GRAVITY);
360 if (bitGravity != null) {
361 xattr.set_bit_gravity(bitGravity.intValue());
362 value_mask |= XConstants.CWBitGravity;
363 }
364
365 if (log.isLoggable(PlatformLogger.Level.FINE)) {
366 log.fine("Creating window for " + this + " with the following attributes: \n" + params);
367 }
368 window = XlibWrapper.XCreateWindow(XToolkit.getDisplay(),
369 parentWindow.longValue(),
370 bounds.x, bounds.y, // location
371 bounds.width, bounds.height, // size
372 0, // border
373 depth.intValue(), // depth
374 visual_class.intValue(), // class
375 visual.longValue(), // visual
376 value_mask, // value mask
377 xattr.pData); // attributes
378
379 if (window == 0) {
380 throw new IllegalStateException("Couldn't create window because of wrong parameters. Run with NOISY_AWT to see details");
381 }
382 XToolkit.addToWinMap(window, this);
383 } finally {
384 xattr.dispose();
385 }
465 }
466 return wmHints;
467 }
468
469
470 /*
471 * Call this method under AWTLock.
472 * The lock should be acquired untill all operations with XSizeHints are completed.
473 */
474 public XSizeHints getHints() {
475 if (hints == null) {
476 long p_hints = XlibWrapper.XAllocSizeHints();
477 hints = new XSizeHints(p_hints);
478 // XlibWrapper.XGetWMNormalHints(XToolkit.getDisplay(), getWindow(), p_hints, XlibWrapper.larg1);
479 // TODO: Shouldn't we listen for WM updates on this property?
480 }
481 return hints;
482 }
483
484 public void setSizeHints(long flags, int x, int y, int width, int height) {
485 if (insLog.isLoggable(PlatformLogger.Level.FINER)) {
486 insLog.finer("Setting hints, flags " + XlibWrapper.hintsToString(flags));
487 }
488 XToolkit.awtLock();
489 try {
490 XSizeHints hints = getHints();
491 // Note: if PPosition is not set in flags this means that
492 // we want to reset PPosition in hints. This is necessary
493 // for locationByPlatform functionality
494 if ((flags & XUtilConstants.PPosition) != 0) {
495 hints.set_x(x);
496 hints.set_y(y);
497 }
498 if ((flags & XUtilConstants.PSize) != 0) {
499 hints.set_width(width);
500 hints.set_height(height);
501 } else if ((hints.get_flags() & XUtilConstants.PSize) != 0) {
502 flags |= XUtilConstants.PSize;
503 }
504 if ((flags & XUtilConstants.PMinSize) != 0) {
505 hints.set_min_width(width);
528 } else if ((hints.get_flags() & XUtilConstants.PMaxSize) != 0) {
529 flags |= XUtilConstants.PMaxSize;
530 if (maxBounds != null) {
531 if (maxBounds.width != Integer.MAX_VALUE) {
532 hints.set_max_width(maxBounds.width);
533 } else {
534 hints.set_max_width(XToolkit.getDefaultScreenWidth());
535 }
536 if (maxBounds.height != Integer.MAX_VALUE) {
537 hints.set_max_height(maxBounds.height);
538 } else {
539 hints.set_max_height(XToolkit.getDefaultScreenHeight());
540 }
541 } else {
542 // Leave intact
543 }
544 }
545 flags |= XUtilConstants.PWinGravity;
546 hints.set_flags(flags);
547 hints.set_win_gravity((int)XConstants.NorthWestGravity);
548 if (insLog.isLoggable(PlatformLogger.Level.FINER)) {
549 insLog.finer("Setting hints, resulted flags " + XlibWrapper.hintsToString(flags) +
550 ", values " + hints);
551 }
552 XlibWrapper.XSetWMNormalHints(XToolkit.getDisplay(), getWindow(), hints.pData);
553 } finally {
554 XToolkit.awtUnlock();
555 }
556 }
557
558 public boolean isMinSizeSet() {
559 XSizeHints hints = getHints();
560 long flags = hints.get_flags();
561 return ((flags & XUtilConstants.PMinSize) == XUtilConstants.PMinSize);
562 }
563
564 /**
565 * This lock object can be used to protect instance data from concurrent access
566 * by two threads. If both state lock and AWT lock are taken, AWT Lock should be taken first.
567 */
568 Object getStateLock() {
582
583 public Rectangle getBounds() {
584 return new Rectangle(x, y, width, height);
585 }
586 public Dimension getSize() {
587 return new Dimension(width, height);
588 }
589
590
591 public void toFront() {
592 XToolkit.awtLock();
593 try {
594 XlibWrapper.XRaiseWindow(XToolkit.getDisplay(), getWindow());
595 } finally {
596 XToolkit.awtUnlock();
597 }
598 }
599 public void xRequestFocus(long time) {
600 XToolkit.awtLock();
601 try {
602 if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
603 focusLog.finer("XSetInputFocus on " + Long.toHexString(getWindow()) + " with time " + time);
604 }
605 XlibWrapper.XSetInputFocus2(XToolkit.getDisplay(), getWindow(), time);
606 } finally {
607 XToolkit.awtUnlock();
608 }
609 }
610 public void xRequestFocus() {
611 XToolkit.awtLock();
612 try {
613 if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
614 focusLog.finer("XSetInputFocus on " + Long.toHexString(getWindow()));
615 }
616 XlibWrapper.XSetInputFocus(XToolkit.getDisplay(), getWindow());
617 } finally {
618 XToolkit.awtUnlock();
619 }
620 }
621
622 public static long xGetInputFocus() {
623 XToolkit.awtLock();
624 try {
625 return XlibWrapper.XGetInputFocus(XToolkit.getDisplay());
626 } finally {
627 XToolkit.awtUnlock();
628 }
629 }
630
631 public void xSetVisible(boolean visible) {
632 if (log.isLoggable(PlatformLogger.Level.FINE)) {
633 log.fine("Setting visible on " + this + " to " + visible);
634 }
635 XToolkit.awtLock();
636 try {
637 this.visible = visible;
638 if (visible) {
639 XlibWrapper.XMapWindow(XToolkit.getDisplay(), getWindow());
640 }
641 else {
642 XlibWrapper.XUnmapWindow(XToolkit.getDisplay(), getWindow());
643 }
644 XlibWrapper.XFlush(XToolkit.getDisplay());
645 } finally {
646 XToolkit.awtUnlock();
647 }
648 }
649
650 boolean isMapped() {
651 return mapped;
652 }
699 XToolkit.awtUnlock();
700 }
701 }
702
703 long getScreen() {
704 if (screen == -1) { // Not initialized
705 screen = getScreenOfWindow(window);
706 }
707 return screen;
708 }
709
710 public void xSetBounds(Rectangle bounds) {
711 xSetBounds(bounds.x, bounds.y, bounds.width, bounds.height);
712 }
713
714 public void xSetBounds(int x, int y, int width, int height) {
715 if (getWindow() == 0) {
716 insLog.warning("Attempt to resize uncreated window");
717 throw new IllegalStateException("Attempt to resize uncreated window");
718 }
719 if (insLog.isLoggable(PlatformLogger.Level.FINE)) {
720 insLog.fine("Setting bounds on " + this + " to (" + x + ", " + y + "), " + width + "x" + height);
721 }
722 width = Math.max(MIN_SIZE, width);
723 height = Math.max(MIN_SIZE, height);
724 XToolkit.awtLock();
725 try {
726 XlibWrapper.XMoveResizeWindow(XToolkit.getDisplay(), getWindow(), x,y,width,height);
727 } finally {
728 XToolkit.awtUnlock();
729 }
730 }
731
732 /**
733 * Translate coordinates from one window into another. Optimized
734 * for XAWT - uses cached data when possible. Preferable over
735 * pure XTranslateCoordinates.
736 * @return coordinates relative to dst, or null if error happened
737 */
738 static Point toOtherWindow(long src, long dst, int x, int y) {
739 Point rpt = new Point(0, 0);
817 try {
818 root = XlibWrapper.RootWindow(XToolkit.getDisplay(),
819 getScreenNumber());
820 } finally {
821 XToolkit.awtUnlock();
822 }
823 Point p = toOtherWindow(root, getContentWindow(), x, y);
824 if (p != null) {
825 return p;
826 } else {
827 return new Point(x, y);
828 }
829 }
830
831 /**
832 * We should always grab both keyboard and pointer to control event flow
833 * on popups. This also simplifies synthetic grab implementation.
834 * The active grab overrides activated automatic grab.
835 */
836 public boolean grabInput() {
837 if (grabLog.isLoggable(PlatformLogger.Level.FINE)) {
838 grabLog.fine("Grab input on {0}", this);
839 }
840
841 XToolkit.awtLock();
842 try {
843 if (XAwtState.getGrabWindow() == this &&
844 XAwtState.isManualGrab())
845 {
846 grabLog.fine(" Already Grabbed");
847 return true;
848 }
849 //6273031: PIT. Choice drop down does not close once it is right clicked to show a popup menu
850 //remember previous window having grab and if it's not null ungrab it.
851 XBaseWindow prevGrabWindow = XAwtState.getGrabWindow();
852 final int eventMask = (int) (XConstants.ButtonPressMask | XConstants.ButtonReleaseMask
853 | XConstants.EnterWindowMask | XConstants.LeaveWindowMask | XConstants.PointerMotionMask
854 | XConstants.ButtonMotionMask);
855 final int ownerEvents = 1;
856
857
882 XAwtState.setGrabWindow(null);
883 grabLog.fine(" Grab Failure - keyboard");
884 return false;
885 }
886 }
887 if (prevGrabWindow != null) {
888 prevGrabWindow.ungrabInputImpl();
889 }
890 XAwtState.setGrabWindow(this);
891 grabLog.fine(" Grab - success");
892 return true;
893 } finally {
894 XToolkit.awtUnlock();
895 }
896 }
897
898 static void ungrabInput() {
899 XToolkit.awtLock();
900 try {
901 XBaseWindow grabWindow = XAwtState.getGrabWindow();
902 if (grabLog.isLoggable(PlatformLogger.Level.FINE)) {
903 grabLog.fine("UnGrab input on {0}", grabWindow);
904 }
905 if (grabWindow != null) {
906 grabWindow.ungrabInputImpl();
907 if (!XToolkit.getSunAwtDisableGrab()) {
908 XlibWrapper.XUngrabPointer(XToolkit.getDisplay(), XConstants.CurrentTime);
909 XlibWrapper.XUngrabKeyboard(XToolkit.getDisplay(), XConstants.CurrentTime);
910 }
911 XAwtState.setGrabWindow(null);
912 // we need to call XFlush() here to force ungrab
913 // see 6384219 for details
914 XlibWrapper.XFlush(XToolkit.getDisplay());
915 }
916 } finally {
917 XToolkit.awtUnlock();
918 }
919 }
920
921 // called from ungrabInput, used in popup windows to hide theirselfs in ungrabbing
922 void ungrabInputImpl() {
926 if (XToolkit.isSecurityWarningEnabled() && XToolkit.isToolkitThread()) {
927 StackTraceElement stack[] = (new Throwable()).getStackTrace();
928 log.warning(stack[1] + ": Security violation: calling user code on toolkit thread");
929 }
930 }
931
932 public Set<Long> getChildren() {
933 synchronized (getStateLock()) {
934 return new HashSet<Long>(children);
935 }
936 }
937
938 // -------------- Event handling ----------------
939 public void handleMapNotifyEvent(XEvent xev) {
940 mapped = true;
941 }
942 public void handleUnmapNotifyEvent(XEvent xev) {
943 mapped = false;
944 }
945 public void handleReparentNotifyEvent(XEvent xev) {
946 if (eventLog.isLoggable(PlatformLogger.Level.FINER)) {
947 XReparentEvent msg = xev.get_xreparent();
948 eventLog.finer(msg.toString());
949 }
950 }
951 public void handlePropertyNotify(XEvent xev) {
952 XPropertyEvent msg = xev.get_xproperty();
953 if (XPropertyCache.isCachingSupported()) {
954 XPropertyCache.clearCache(window, XAtom.get(msg.get_atom()));
955 }
956 if (eventLog.isLoggable(PlatformLogger.Level.FINER)) {
957 eventLog.finer("{0}", msg);
958 }
959 }
960
961 public void handleDestroyNotify(XEvent xev) {
962 XAnyEvent xany = xev.get_xany();
963 if (xany.get_window() == getWindow()) {
964 XToolkit.removeFromWinMap(getWindow(), this);
965 if (XPropertyCache.isCachingSupported()) {
966 XPropertyCache.clearCache(getWindow());
967 }
968 }
969 if (xany.get_window() != getWindow()) {
970 synchronized (getStateLock()) {
971 children.remove(xany.get_window());
972 }
973 }
974 }
975
976 public void handleCreateNotify(XEvent xev) {
977 XAnyEvent xany = xev.get_xany();
978 if (xany.get_window() != getWindow()) {
979 synchronized (getStateLock()) {
980 children.add(xany.get_window());
981 }
982 }
983 }
984
985 public void handleClientMessage(XEvent xev) {
986 if (eventLog.isLoggable(PlatformLogger.Level.FINER)) {
987 XClientMessageEvent msg = xev.get_xclient();
988 eventLog.finer(msg.toString());
989 }
990 }
991
992 public void handleVisibilityEvent(XEvent xev) {
993 }
994 public void handleKeyPress(XEvent xev) {
995 }
996 public void handleKeyRelease(XEvent xev) {
997 }
998 public void handleExposeEvent(XEvent xev) {
999 }
1000 /**
1001 * Activate automatic grab on first ButtonPress,
1002 * deactivate on full mouse release
1003 */
1004 public void handleButtonPressRelease(XEvent xev) {
1005 XButtonEvent xbe = xev.get_xbutton();
1006 /*
1022 // A click in a client area drops the actual focused window retaining.
1023 parent.setActualFocusedWindow(null);
1024 parent.requestWindowFocus(xbe.get_time(), true);
1025 }
1026 XAwtState.setAutoGrabWindow(this);
1027 }
1028 break;
1029 case XConstants.ButtonRelease:
1030 if (isFullRelease(buttonState, xbe.get_button())) {
1031 XAwtState.setAutoGrabWindow(null);
1032 }
1033 break;
1034 }
1035 }
1036 public void handleMotionNotify(XEvent xev) {
1037 }
1038 public void handleXCrossingEvent(XEvent xev) {
1039 }
1040 public void handleConfigureNotifyEvent(XEvent xev) {
1041 XConfigureEvent xe = xev.get_xconfigure();
1042 if (insLog.isLoggable(PlatformLogger.Level.FINER)) {
1043 insLog.finer("Configure, {0}", xe);
1044 }
1045 x = xe.get_x();
1046 y = xe.get_y();
1047 width = xe.get_width();
1048 height = xe.get_height();
1049 }
1050 /**
1051 * Checks ButtonRelease released all Mouse buttons
1052 */
1053 static boolean isFullRelease(int buttonState, int button) {
1054 final int buttonsNumber = XToolkit.getNumberOfButtonsForMask();
1055
1056 if (button < 0 || button > buttonsNumber) {
1057 return buttonState == 0;
1058 } else {
1059 return buttonState == XlibUtil.getButtonMask(button);
1060 }
1061 }
1062
1075 return (target instanceof XWindowPeer);
1076 default:
1077 return false;
1078 }
1079 }
1080 /**
1081 * Dispatches event to the grab Window or event source window depending
1082 * on whether the grab is active and on the event type
1083 */
1084 static void dispatchToWindow(XEvent ev) {
1085 XBaseWindow target = XAwtState.getGrabWindow();
1086 if (target == null || !isGrabbedEvent(ev, target)) {
1087 target = XToolkit.windowToXWindow(ev.get_xany().get_window());
1088 }
1089 if (target != null && target.checkInitialised()) {
1090 target.dispatchEvent(ev);
1091 }
1092 }
1093
1094 public void dispatchEvent(XEvent xev) {
1095 if (eventLog.isLoggable(PlatformLogger.Level.FINEST)) {
1096 eventLog.finest(xev.toString());
1097 }
1098 int type = xev.get_type();
1099
1100 if (isDisposed()) {
1101 return;
1102 }
1103
1104 switch (type)
1105 {
1106 case XConstants.VisibilityNotify:
1107 handleVisibilityEvent(xev);
1108 break;
1109 case XConstants.ClientMessage:
1110 handleClientMessage(xev);
1111 break;
1112 case XConstants.Expose :
1113 case XConstants.GraphicsExpose :
1114 handleExposeEvent(xev);
1115 break;
|