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)) log.fine("WM name is " + getWMName());
164 updateWMName();
165
166 // Set WM_CLIENT_LEADER property
167 initClientLeader();
168 }
169
170 /**
171 * Creates window using parameters <code>params</code>
172 * If params contain flag DELAYED doesn't do anything.
173 * Note: Descendants can call this method to create the window
174 * at the time different to instance construction.
175 */
176 protected final void init(XCreateWindowParams params) {
177 awtLock();
178 initialising = InitialiseState.INITIALISING;
179 awtUnlock();
180
181 try {
182 if (!Boolean.TRUE.equals(params.get(DELAYED))) {
183 preInit(params);
463 }
464 return wmHints;
465 }
466
467
468 /*
469 * Call this method under AWTLock.
470 * The lock should be acquired untill all operations with XSizeHints are completed.
471 */
472 public XSizeHints getHints() {
473 if (hints == null) {
474 long p_hints = XlibWrapper.XAllocSizeHints();
475 hints = new XSizeHints(p_hints);
476 // XlibWrapper.XGetWMNormalHints(XToolkit.getDisplay(), getWindow(), p_hints, XlibWrapper.larg1);
477 // TODO: Shouldn't we listen for WM updates on this property?
478 }
479 return hints;
480 }
481
482 public void setSizeHints(long flags, int x, int y, int width, int height) {
483 if (insLog.isLoggable(PlatformLogger.FINER)) insLog.finer("Setting hints, flags " + XlibWrapper.hintsToString(flags));
484 XToolkit.awtLock();
485 try {
486 XSizeHints hints = getHints();
487 // Note: if PPosition is not set in flags this means that
488 // we want to reset PPosition in hints. This is necessary
489 // for locationByPlatform functionality
490 if ((flags & XUtilConstants.PPosition) != 0) {
491 hints.set_x(x);
492 hints.set_y(y);
493 }
494 if ((flags & XUtilConstants.PSize) != 0) {
495 hints.set_width(width);
496 hints.set_height(height);
497 } else if ((hints.get_flags() & XUtilConstants.PSize) != 0) {
498 flags |= XUtilConstants.PSize;
499 }
500 if ((flags & XUtilConstants.PMinSize) != 0) {
501 hints.set_min_width(width);
502 hints.set_min_height(height);
503 } else if ((hints.get_flags() & XUtilConstants.PMinSize) != 0) {
524 } else if ((hints.get_flags() & XUtilConstants.PMaxSize) != 0) {
525 flags |= XUtilConstants.PMaxSize;
526 if (maxBounds != null) {
527 if (maxBounds.width != Integer.MAX_VALUE) {
528 hints.set_max_width(maxBounds.width);
529 } else {
530 hints.set_max_width(XToolkit.getDefaultScreenWidth());
531 }
532 if (maxBounds.height != Integer.MAX_VALUE) {
533 hints.set_max_height(maxBounds.height);
534 } else {
535 hints.set_max_height(XToolkit.getDefaultScreenHeight());
536 }
537 } else {
538 // Leave intact
539 }
540 }
541 flags |= XUtilConstants.PWinGravity;
542 hints.set_flags(flags);
543 hints.set_win_gravity((int)XConstants.NorthWestGravity);
544 if (insLog.isLoggable(PlatformLogger.FINER)) insLog.finer("Setting hints, resulted flags " + XlibWrapper.hintsToString(flags) +
545 ", values " + hints);
546 XlibWrapper.XSetWMNormalHints(XToolkit.getDisplay(), getWindow(), hints.pData);
547 } finally {
548 XToolkit.awtUnlock();
549 }
550 }
551
552 public boolean isMinSizeSet() {
553 XSizeHints hints = getHints();
554 long flags = hints.get_flags();
555 return ((flags & XUtilConstants.PMinSize) == XUtilConstants.PMinSize);
556 }
557
558 /**
559 * This lock object can be used to protect instance data from concurrent access
560 * by two threads. If both state lock and AWT lock are taken, AWT Lock should be taken first.
561 */
562 Object getStateLock() {
563 return state_lock;
564 }
565
576
577 public Rectangle getBounds() {
578 return new Rectangle(x, y, width, height);
579 }
580 public Dimension getSize() {
581 return new Dimension(width, height);
582 }
583
584
585 public void toFront() {
586 XToolkit.awtLock();
587 try {
588 XlibWrapper.XRaiseWindow(XToolkit.getDisplay(), getWindow());
589 } finally {
590 XToolkit.awtUnlock();
591 }
592 }
593 public void xRequestFocus(long time) {
594 XToolkit.awtLock();
595 try {
596 if (focusLog.isLoggable(PlatformLogger.FINER)) focusLog.finer("XSetInputFocus on " + Long.toHexString(getWindow()) + " with time " + time);
597 XlibWrapper.XSetInputFocus2(XToolkit.getDisplay(), getWindow(), time);
598 } finally {
599 XToolkit.awtUnlock();
600 }
601 }
602 public void xRequestFocus() {
603 XToolkit.awtLock();
604 try {
605 if (focusLog.isLoggable(PlatformLogger.FINER)) focusLog.finer("XSetInputFocus on " + Long.toHexString(getWindow()));
606 XlibWrapper.XSetInputFocus(XToolkit.getDisplay(), getWindow());
607 } finally {
608 XToolkit.awtUnlock();
609 }
610 }
611
612 public static long xGetInputFocus() {
613 XToolkit.awtLock();
614 try {
615 return XlibWrapper.XGetInputFocus(XToolkit.getDisplay());
616 } finally {
617 XToolkit.awtUnlock();
618 }
619 }
620
621 public void xSetVisible(boolean visible) {
622 if (log.isLoggable(PlatformLogger.FINE)) log.fine("Setting visible on " + this + " to " + visible);
623 XToolkit.awtLock();
624 try {
625 this.visible = visible;
626 if (visible) {
627 XlibWrapper.XMapWindow(XToolkit.getDisplay(), getWindow());
628 }
629 else {
630 XlibWrapper.XUnmapWindow(XToolkit.getDisplay(), getWindow());
631 }
632 XlibWrapper.XFlush(XToolkit.getDisplay());
633 } finally {
634 XToolkit.awtUnlock();
635 }
636 }
637
638 boolean isMapped() {
639 return mapped;
640 }
641
642 void updateWMName() {
687 XToolkit.awtUnlock();
688 }
689 }
690
691 long getScreen() {
692 if (screen == -1) { // Not initialized
693 screen = getScreenOfWindow(window);
694 }
695 return screen;
696 }
697
698 public void xSetBounds(Rectangle bounds) {
699 xSetBounds(bounds.x, bounds.y, bounds.width, bounds.height);
700 }
701
702 public void xSetBounds(int x, int y, int width, int height) {
703 if (getWindow() == 0) {
704 insLog.warning("Attempt to resize uncreated window");
705 throw new IllegalStateException("Attempt to resize uncreated window");
706 }
707 insLog.fine("Setting bounds on " + this + " to (" + x + ", " + y + "), " + width + "x" + height);
708 width = Math.max(MIN_SIZE, width);
709 height = Math.max(MIN_SIZE, height);
710 XToolkit.awtLock();
711 try {
712 XlibWrapper.XMoveResizeWindow(XToolkit.getDisplay(), getWindow(), x,y,width,height);
713 } finally {
714 XToolkit.awtUnlock();
715 }
716 }
717
718 /**
719 * Translate coordinates from one window into another. Optimized
720 * for XAWT - uses cached data when possible. Preferable over
721 * pure XTranslateCoordinates.
722 * @return coordinates relative to dst, or null if error happened
723 */
724 static Point toOtherWindow(long src, long dst, int x, int y) {
725 Point rpt = new Point(0, 0);
726
727 // Check if both windows belong to XAWT - then no X calls are necessary
1055 return (target instanceof XWindowPeer);
1056 default:
1057 return false;
1058 }
1059 }
1060 /**
1061 * Dispatches event to the grab Window or event source window depending
1062 * on whether the grab is active and on the event type
1063 */
1064 static void dispatchToWindow(XEvent ev) {
1065 XBaseWindow target = XAwtState.getGrabWindow();
1066 if (target == null || !isGrabbedEvent(ev, target)) {
1067 target = XToolkit.windowToXWindow(ev.get_xany().get_window());
1068 }
1069 if (target != null && target.checkInitialised()) {
1070 target.dispatchEvent(ev);
1071 }
1072 }
1073
1074 public void dispatchEvent(XEvent xev) {
1075 if (eventLog.isLoggable(PlatformLogger.FINEST)) eventLog.finest(xev.toString());
1076 int type = xev.get_type();
1077
1078 if (isDisposed()) {
1079 return;
1080 }
1081
1082 switch (type)
1083 {
1084 case XConstants.VisibilityNotify:
1085 handleVisibilityEvent(xev);
1086 break;
1087 case XConstants.ClientMessage:
1088 handleClientMessage(xev);
1089 break;
1090 case XConstants.Expose :
1091 case XConstants.GraphicsExpose :
1092 handleExposeEvent(xev);
1093 break;
1094 case XConstants.ButtonPress:
1095 case XConstants.ButtonRelease:
|
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 {
184 if (!Boolean.TRUE.equals(params.get(DELAYED))) {
185 preInit(params);
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);
506 hints.set_min_height(height);
507 } else if ((hints.get_flags() & XUtilConstants.PMinSize) != 0) {
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() {
569 return state_lock;
570 }
571
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 }
653
654 void updateWMName() {
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);
740
741 // Check if both windows belong to XAWT - then no X calls are necessary
1069 return (target instanceof XWindowPeer);
1070 default:
1071 return false;
1072 }
1073 }
1074 /**
1075 * Dispatches event to the grab Window or event source window depending
1076 * on whether the grab is active and on the event type
1077 */
1078 static void dispatchToWindow(XEvent ev) {
1079 XBaseWindow target = XAwtState.getGrabWindow();
1080 if (target == null || !isGrabbedEvent(ev, target)) {
1081 target = XToolkit.windowToXWindow(ev.get_xany().get_window());
1082 }
1083 if (target != null && target.checkInitialised()) {
1084 target.dispatchEvent(ev);
1085 }
1086 }
1087
1088 public void dispatchEvent(XEvent xev) {
1089 if (eventLog.isLoggable(PlatformLogger.FINEST)) {
1090 eventLog.finest(xev.toString());
1091 }
1092 int type = xev.get_type();
1093
1094 if (isDisposed()) {
1095 return;
1096 }
1097
1098 switch (type)
1099 {
1100 case XConstants.VisibilityNotify:
1101 handleVisibilityEvent(xev);
1102 break;
1103 case XConstants.ClientMessage:
1104 handleClientMessage(xev);
1105 break;
1106 case XConstants.Expose :
1107 case XConstants.GraphicsExpose :
1108 handleExposeEvent(xev);
1109 break;
1110 case XConstants.ButtonPress:
1111 case XConstants.ButtonRelease:
|