XTextFieldPeer(TextField target) { super(target); text = target.getText(); xtext = new XAWTTextField(text, this, target.getParent()); xtext.getDocument().addDocumentListener(xtext); xtext.setCursor(target.getCursor()); XToolkit.specialPeerMap.put(xtext, this); initTextField(); setText(target.getText()); if (target.echoCharIsSet()) { setEchoChar(target.getEchoChar()); } else setEchoChar((char) 0); int start = target.getSelectionStart(); int end = target.getSelectionEnd(); // Fix for 5100200 // Restoring Motif behaviour // Since the end position of the selected text can be greater than the length of the text, // so we should set caret to max position of the text setCaretPosition(Math.min(end, text.length())); if (end > start) { // Should be called after setText() and setCaretPosition() select(start, end); } setEditable(target.isEditable()); // After this line we should not change the component's text firstChangeSkipped = true; AWTAccessor.getComponentAccessor().setPeer(xtext, this); }
/* * Retrieves the owner of the peer. * Note: this method returns the owner which can be activated, (i.e. the instance * of Frame or Dialog may be returned). */ static LWWindowPeer getOwnerFrameDialog(LWWindowPeer peer) { Window owner = (peer != null ? peer.getTarget().getOwner() : null); while (owner != null && !(owner instanceof Frame || owner instanceof Dialog)) { owner = owner.getOwner(); } return owner == null ? null : (LWWindowPeer) AWTAccessor.getComponentAccessor().getPeer(owner); }
@SuppressWarnings("deprecation") public CPlatformWindow convertJComponentToTarget(final JRootPane p) { Component root = SwingUtilities.getRoot(p); final ComponentAccessor acc = AWTAccessor.getComponentAccessor(); if (root == null || acc.getPeer(root) == null) return null; return (CPlatformWindow) ((LWWindowPeer) acc.getPeer(root)).getPlatformWindow(); }
public void addClient() { client = new Canvas() { public void paint(Graphics g) { super.paint(g); } }; client.setBackground(new Color(30, 220, 40)); clientCont.add(client); clientCont.validate(); final ComponentAccessor acc = AWTAccessor.getComponentAccessor(); WindowIDProvider pid = (WindowIDProvider) acc.getPeer(client); log.fine("Added XEmbed server(Canvas) with X window ID " + pid.getWindow()); Rectangle toFocusBounds = toFocus.getBounds(); toFocusBounds.setLocation(toFocus.getLocationOnScreen()); f.validate(); // KDE doesn't accept clicks on title as activation - click below title Rectangle fbounds = f.getBounds(); fbounds.y += f.getInsets().top; fbounds.height -= f.getInsets().top; Process proc = startClient( new Rectangle[] { fbounds, dummy.getBounds(), toFocusBounds, new Rectangle(b_modal.getLocationOnScreen(), b_modal.getSize()), new Rectangle(10, 130, 20, 20) }, pid.getWindow()); new ClientWatcher(client, proc, clientCont).start(); }
void initTextField() { setVisible(target.isVisible()); setBounds(x, y, width, height, SET_BOUNDS); AWTAccessor.ComponentAccessor compAccessor = AWTAccessor.getComponentAccessor(); foreground = compAccessor.getForeground(target); if (foreground == null) foreground = SystemColor.textText; setForeground(foreground); background = compAccessor.getBackground(target); if (background == null) { if (((TextField) target).isEditable()) background = SystemColor.text; else background = SystemColor.control; } setBackground(background); if (!target.isBackgroundSet()) { // This is a way to set the background color of the TextArea // without calling setBackground - go through accessor compAccessor.setBackground(target, background); } if (!target.isForegroundSet()) { target.setForeground(SystemColor.textText); } setFont(font); }
public LWWindowPeer( Window target, PlatformComponent platformComponent, PlatformWindow platformWindow, PeerType peerType) { super(target, platformComponent); this.platformWindow = platformWindow; this.peerType = peerType; Window owner = target.getOwner(); LWWindowPeer ownerPeer = owner == null ? null : (LWWindowPeer) AWTAccessor.getComponentAccessor().getPeer(owner); PlatformWindow ownerDelegate = (ownerPeer != null) ? ownerPeer.getPlatformWindow() : null; // The delegate.initialize() needs a non-null GC on X11. GraphicsConfiguration gc = getTarget().getGraphicsConfiguration(); synchronized (getStateLock()) { // graphicsConfig should be updated according to the real window // bounds when the window is shown, see 4868278 this.graphicsConfig = gc; } if (!target.isFontSet()) { target.setFont(DEFAULT_FONT); } if (!target.isBackgroundSet()) { target.setBackground(SystemColor.window); } else { // first we check if user provided alpha for background. This is // similar to what Apple's Java do. // Since JDK7 we should rely on setOpacity() only. // this.opacity = c.getAlpha(); } if (!target.isForegroundSet()) { target.setForeground(SystemColor.windowText); // we should not call setForeground because it will call a repaint // which the peer may not be ready to do yet. } platformWindow.initialize(target, this, ownerDelegate); // Init warning window(for applets) SecurityWarningWindow warn = null; if (target.getWarningString() != null) { // accessSystemTray permission allows to display TrayIcon, TrayIcon tooltip // and TrayIcon balloon windows without a warning window. if (!AWTAccessor.getWindowAccessor().isTrayIconWindow(target)) { LWToolkit toolkit = (LWToolkit) Toolkit.getDefaultToolkit(); warn = toolkit.createSecurityWarning(target, this); } } warningWindow = warn; }
@Override public void blockWindows(List<Window> windows) { // TODO: LWX will probably need some collectJavaToplevels to speed this up for (Window w : windows) { WindowPeer wp = (WindowPeer) AWTAccessor.getComponentAccessor().getPeer(w); if (wp != null) { wp.setModalBlocked((Dialog) getTarget(), true); } } }
@Override public void repositionSecurityWarning() { if (warningWindow != null) { AWTAccessor.ComponentAccessor compAccessor = AWTAccessor.getComponentAccessor(); Window target = getTarget(); int x = compAccessor.getX(target); int y = compAccessor.getY(target); int width = compAccessor.getWidth(target); int height = compAccessor.getHeight(target); warningWindow.reposition(x, y, width, height); } }
XAWTTextField(String text, XComponentPeer xwin, Container parent) { super(text); this.xwin = xwin; setDoubleBuffered(true); setFocusable(false); AWTAccessor.getComponentAccessor().setParent(this, parent); setBackground(xwin.getPeerBackground()); setForeground(xwin.getPeerForeground()); setFont(xwin.getPeerFont()); setCaretPosition(0); addActionListener(this); addNotify(); }
@Override public void setModalBlocked(Dialog blocker, boolean blocked) { synchronized (getPeerTreeLock()) { ComponentPeer peer = AWTAccessor.getComponentAccessor().getPeer(blocker); if (blocked && (peer instanceof LWWindowPeer)) { this.blocker = (LWWindowPeer) peer; } else { this.blocker = null; } } platformWindow.setModalBlocked(blocked); }
@Override // PlatformWindow public void toFront() { final long nsWindowPtr = getNSWindowPtr(); LWCToolkit lwcToolkit = (LWCToolkit) Toolkit.getDefaultToolkit(); Window w = DefaultKeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow(); final ComponentAccessor acc = AWTAccessor.getComponentAccessor(); if (w != null && acc.getPeer(w) != null && ((LWWindowPeer) acc.getPeer(w)).getPeerType() == LWWindowPeer.PeerType.EMBEDDED_FRAME && !lwcToolkit.isApplicationActive()) { lwcToolkit.activateApplicationIgnoringOtherApps(); } updateFocusabilityForAutoRequestFocus(false); nativePushNSWindowToFront(nsWindowPtr); updateFocusabilityForAutoRequestFocus(true); }
/** * Sets a specified <code>Component</code> to be the glass pane for this root pane. The glass pane * should normally be a lightweight, transparent component, because it will be made visible when * ever the root pane needs to grab input events. * * <p>The new glass pane's visibility is changed to match that of the current glass pane. An * implication of this is that care must be taken when you want to replace the glass pane and make * it visible. Either of the following will work: * * <pre> * root.setGlassPane(newGlassPane); * newGlassPane.setVisible(true); * </pre> * * or: * * <pre> * root.getGlassPane().setVisible(true); * root.setGlassPane(newGlassPane); * </pre> * * @param glass the <code>Component</code> to use as the glass pane for this <code>JRootPane * </code> * @exception NullPointerException if the <code>glass</code> parameter is <code>null</code> */ public void setGlassPane(Component glass) { if (glass == null) { throw new NullPointerException("glassPane cannot be set to null."); } AWTAccessor.getComponentAccessor().setMixingCutoutShape(glass, new Rectangle()); boolean visible = false; if (glassPane != null && glassPane.getParent() == this) { this.remove(glassPane); visible = glassPane.isVisible(); } glass.setVisible(visible); glassPane = glass; this.add(glassPane, 0); if (visible) { repaint(); } }
public void updateGC() { int scrn = getScreenImOn(); if (screenLog.isLoggable(PlatformLogger.Level.FINER)) { log.finer("Screen number: " + scrn); } // get current GD Win32GraphicsDevice oldDev = (Win32GraphicsDevice) winGraphicsConfig.getDevice(); Win32GraphicsDevice newDev; GraphicsDevice devs[] = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices(); // Occasionally during device addition/removal getScreenImOn can return // a non-existing screen number. Use the default device in this case. if (scrn >= devs.length) { newDev = (Win32GraphicsDevice) GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(); } else { newDev = (Win32GraphicsDevice) devs[scrn]; } // Set winGraphicsConfig to the default GC for the monitor this Window // is now mostly on. winGraphicsConfig = (Win32GraphicsConfig) newDev.getDefaultConfiguration(); if (screenLog.isLoggable(PlatformLogger.Level.FINE)) { if (winGraphicsConfig == null) { screenLog.fine("Assertion (winGraphicsConfig != null) failed"); } } // if on a different display, take off old GD and put on new GD if (oldDev != newDev) { oldDev.removeDisplayChangedListener(this); newDev.addDisplayChangedListener(this); } AWTAccessor.getComponentAccessor() .setGraphicsConfiguration((Component) target, winGraphicsConfig); }
protected void startDrag(Transferable transferable, long[] formats, Map formatMap) { Component component = getTrigger().getComponent(); Component c = null; XWindowPeer wpeer = null; for (c = component; c != null && !(c instanceof Window); c = AWTAccessor.getComponentAccessor().getParent(c)) ; if (c instanceof Window) { wpeer = (XWindowPeer) c.getPeer(); } if (wpeer == null) { throw new InvalidDnDOperationException("Cannot find top-level for the drag source component"); } long xcursor = 0; long rootWindow = 0; long dragWindow = 0; long timeStamp = 0; /* Retrieve the X cursor for the drag operation. */ { Cursor cursor = getCursor(); if (cursor != null) { xcursor = XGlobalCursorManager.getCursor(cursor); } } XToolkit.awtLock(); try { if (proxyModeSourceWindow != 0) { throw new InvalidDnDOperationException("Proxy drag in progress"); } if (dndInProgress) { throw new InvalidDnDOperationException("Drag in progress"); } /* Determine the root window for the drag operation. */ { long screen = XlibWrapper.XScreenNumberOfScreen(wpeer.getScreen()); rootWindow = XlibWrapper.RootWindow(XToolkit.getDisplay(), screen); } dragWindow = XWindow.getXAWTRootWindow().getWindow(); timeStamp = XToolkit.getCurrentServerTime(); int dropActions = getDragSourceContext().getSourceActions(); Iterator dragProtocols = XDragAndDropProtocols.getDragSourceProtocols(); while (dragProtocols.hasNext()) { XDragSourceProtocol dragProtocol = (XDragSourceProtocol) dragProtocols.next(); try { dragProtocol.initializeDrag( dropActions, transferable, formatMap, formats); } catch (XException xe) { throw (InvalidDnDOperationException) new InvalidDnDOperationException().initCause(xe); } } /* Install X grabs. */ { int status; XWindowAttributes wattr = new XWindowAttributes(); try { status = XlibWrapper.XGetWindowAttributes(XToolkit.getDisplay(), rootWindow, wattr.pData); if (status == 0) { throw new InvalidDnDOperationException("XGetWindowAttributes failed"); } rootEventMask = wattr.get_your_event_mask(); XlibWrapper.XSelectInput( XToolkit.getDisplay(), rootWindow, rootEventMask | ROOT_EVENT_MASK); } finally { wattr.dispose(); } XBaseWindow.ungrabInput(); status = XlibWrapper.XGrabPointer( XToolkit.getDisplay(), rootWindow, 0, GRAB_EVENT_MASK, XConstants.GrabModeAsync, XConstants.GrabModeAsync, XConstants.None, xcursor, timeStamp); if (status != XConstants.GrabSuccess) { cleanup(timeStamp); throwGrabFailureException("Cannot grab pointer", status); return; } status = XlibWrapper.XGrabKeyboard( XToolkit.getDisplay(), rootWindow, 0, XConstants.GrabModeAsync, XConstants.GrabModeAsync, timeStamp); if (status != XConstants.GrabSuccess) { cleanup(timeStamp); throwGrabFailureException("Cannot grab keyboard", status); return; } } /* Update the global state. */ dndInProgress = true; dragInProgress = true; dragRootWindow = rootWindow; sourceActions = dropActions; sourceFormats = formats; } finally { XToolkit.awtUnlock(); } /* This implementation doesn't use native context */ setNativeContext(0); SunDropTargetContextPeer.setCurrentJVMLocalSourceTransferable(transferable); }
@Override // PlatformWindow public void setVisible(boolean visible) { final long nsWindowPtr = getNSWindowPtr(); // Configure stuff updateIconImages(); updateFocusabilityForAutoRequestFocus(false); boolean wasMaximized = isMaximized(); if (visible && target.isLocationByPlatform()) { nativeSetNSWindowLocationByPlatform(getNSWindowPtr()); } // Actually show or hide the window LWWindowPeer blocker = (peer == null) ? null : peer.getBlocker(); if (blocker == null || !visible) { // If it ain't blocked, or is being hidden, go regular way if (visible) { CWrapper.NSWindow.makeFirstResponder(nsWindowPtr, contentView.getAWTView()); boolean isPopup = (target.getType() == Window.Type.POPUP); if (isPopup) { // Popups in applets don't activate applet's process CWrapper.NSWindow.orderFrontRegardless(nsWindowPtr); } else { CWrapper.NSWindow.orderFront(nsWindowPtr); } boolean isKeyWindow = CWrapper.NSWindow.isKeyWindow(nsWindowPtr); if (!isKeyWindow) { CWrapper.NSWindow.makeKeyWindow(nsWindowPtr); } } else { // immediately hide the window CWrapper.NSWindow.orderOut(nsWindowPtr); // process the close CWrapper.NSWindow.close(nsWindowPtr); } } else { // otherwise, put it in a proper z-order CWrapper.NSWindow.orderWindow( nsWindowPtr, CWrapper.NSWindow.NSWindowBelow, ((CPlatformWindow) blocker.getPlatformWindow()).getNSWindowPtr()); } this.visible = visible; // Manage the extended state when showing if (visible) { // Apply the extended state as expected in shared code if (target instanceof Frame) { if (!wasMaximized && isMaximized()) { // setVisible could have changed the native maximized state deliverZoom(true); } else { int frameState = ((Frame) target).getExtendedState(); if ((frameState & Frame.ICONIFIED) != 0) { // Treat all state bit masks with ICONIFIED bit as ICONIFIED state. frameState = Frame.ICONIFIED; } switch (frameState) { case Frame.ICONIFIED: CWrapper.NSWindow.miniaturize(nsWindowPtr); break; case Frame.MAXIMIZED_BOTH: maximize(); break; default: // NORMAL unmaximize(); // in case it was maximized, otherwise this is a no-op break; } } } } nativeSynthesizeMouseEnteredExitedEvents(); // Configure stuff #2 updateFocusabilityForAutoRequestFocus(true); // Manage parent-child relationship when showing final ComponentAccessor acc = AWTAccessor.getComponentAccessor(); if (visible) { // Order myself above my parent if (owner != null && owner.isVisible()) { CWrapper.NSWindow.orderWindow( nsWindowPtr, CWrapper.NSWindow.NSWindowAbove, owner.getNSWindowPtr()); applyWindowLevel(target); } // Order my own children above myself for (Window w : target.getOwnedWindows()) { final Object p = acc.getPeer(w); if (p instanceof LWWindowPeer) { CPlatformWindow pw = (CPlatformWindow) ((LWWindowPeer) p).getPlatformWindow(); if (pw != null && pw.isVisible()) { CWrapper.NSWindow.orderWindow( pw.getNSWindowPtr(), CWrapper.NSWindow.NSWindowAbove, nsWindowPtr); pw.applyWindowLevel(w); } } } } // Deal with the blocker of the window being shown if (blocker != null && visible) { // Make sure the blocker is above its siblings ((CPlatformWindow) blocker.getPlatformWindow()).orderAboveSiblings(); } }
/* * Requests platform to set native focus on a frame/dialog. * In case of a simple window, triggers appropriate java focus change. */ public boolean requestWindowFocus(CausedFocusEvent.Cause cause) { if (focusLog.isLoggable(PlatformLogger.Level.FINE)) { focusLog.fine("requesting native focus to " + this); } if (!focusAllowedFor()) { focusLog.fine("focus is not allowed"); return false; } // if (platformWindow.rejectFocusRequest(cause)) { // return false; // } AppContext targetAppContext = AWTAccessor.getComponentAccessor().getAppContext(getTarget()); KeyboardFocusManager kfm = AWTAccessor.getKeyboardFocusManagerAccessor() .getCurrentKeyboardFocusManager(targetAppContext); Window currentActive = kfm.getActiveWindow(); Window opposite = LWKeyboardFocusManagerPeer.getInstance().getCurrentFocusedWindow(); // Make the owner active window. if (isSimpleWindow()) { focusLog.fine("This is a Simple Window."); LWWindowPeer owner = getOwnerFrameDialog(this); // If owner is not natively active, request native // activation on it w/o sending events up to java. if (owner != null && !owner.platformWindow.isActive()) { if (focusLog.isLoggable(PlatformLogger.Level.FINE)) { focusLog.fine("requesting native focus to the owner " + owner); } LWWindowPeer currentActivePeer = currentActive == null ? null : (LWWindowPeer) AWTAccessor.getComponentAccessor().getPeer(currentActive); // Ensure the opposite is natively active and suppress sending events. if (currentActivePeer != null && currentActivePeer.platformWindow.isActive()) { if (focusLog.isLoggable(PlatformLogger.Level.FINE)) { focusLog.fine("the opposite is " + currentActivePeer); } currentActivePeer.skipNextFocusChange = true; } owner.skipNextFocusChange = true; owner.platformWindow.requestWindowFocus(); } // DKFM will synthesize all the focus/activation events correctly. changeFocusedWindow(true, opposite); focusLog.fine("DKFM will synthesize all the focus/activation events correctly"); return true; // In case the toplevel is active but not focused, change focus directly, // as requesting native focus on it will not have effect. } else if (getTarget() == currentActive && !getTarget().hasFocus()) { changeFocusedWindow(true, opposite); focusLog.fine("toplevel is active but not focused, change focus directly"); return true; } focusLog.fine("platformWindow.requestWindowFocus()"); return platformWindow.requestWindowFocus(); }
// NOTE: This method may be called by privileged threads. // DO NOT INVOKE CLIENT CODE ON THIS THREAD! public void handleResize(Rectangle bounds) { AWTAccessor.getComponentAccessor().setSize((Component) target, bounds.width, bounds.height); postEvent(new ComponentEvent(target, ComponentEvent.COMPONENT_RESIZED)); }
@Override void handleJavaKeyEvent(KeyEvent e) { AWTAccessor.getComponentAccessor().processEvent(xtext, e); }