src/solaris/classes/sun/awt/X11/XFramePeer.java

Print this page




 192                         if (height != lastAppliedMenubarHeight) {
 193                             lastAppliedMenubarHeight = height;
 194                             heightChanged = true;
 195                         }
 196                     }
 197                     if (heightChanged) {
 198                         // To make frame contents be re-layout (copied from
 199                         // 'XDecoratedPeer.revalidate()'). These are not
 200                         // 'synchronized', because can recursively call client
 201                         // methods, which are not supposed to be called with locks
 202                         // acquired.
 203                         target.invalidate();
 204                         target.validate();
 205                     }
 206                 }
 207             }
 208         );
 209     }
 210 
 211     public void setMaximizedBounds(Rectangle b) {
 212         if (insLog.isLoggable(PlatformLogger.FINE)) insLog.fine("Setting maximized bounds to " + b);


 213         if (b == null) return;
 214         maxBounds = new Rectangle(b);
 215         XToolkit.awtLock();
 216         try {
 217             XSizeHints hints = getHints();
 218             hints.set_flags(hints.get_flags() | (int)XUtilConstants.PMaxSize);
 219             if (b.width != Integer.MAX_VALUE) {
 220                 hints.set_max_width(b.width);
 221             } else {
 222                 hints.set_max_width((int)XlibWrapper.DisplayWidth(XToolkit.getDisplay(), XlibWrapper.DefaultScreen(XToolkit.getDisplay())));
 223             }
 224             if (b.height != Integer.MAX_VALUE) {
 225                 hints.set_max_height(b.height);
 226             } else {
 227                 hints.set_max_height((int)XlibWrapper.DisplayHeight(XToolkit.getDisplay(), XlibWrapper.DefaultScreen(XToolkit.getDisplay())));
 228             }
 229             if (insLog.isLoggable(PlatformLogger.FINER)) insLog.finer("Setting hints, flags " + XlibWrapper.hintsToString(hints.get_flags()));


 230             XlibWrapper.XSetWMNormalHints(XToolkit.getDisplay(), window, hints.pData);
 231         } finally {
 232             XToolkit.awtUnlock();
 233         }
 234     }
 235 
 236     public int getState() {
 237         synchronized(getStateLock()) {
 238             return state;
 239         }
 240     }
 241 
 242     public void setState(int newState) {
 243         synchronized(getStateLock()) {
 244             if (!isShowing()) {
 245                 stateLog.finer("Frame is not showing");
 246                 state = newState;
 247                 return;
 248             }
 249         }
 250         changeState(newState);
 251     }
 252 
 253     void changeState(int newState) {
 254         int changed = state ^ newState;
 255         int changeIconic = changed & Frame.ICONIFIED;
 256         boolean iconic = (newState & Frame.ICONIFIED) != 0;
 257         stateLog.finer("Changing state, old state {0}, new state {1}(iconic {2})",
 258                        Integer.valueOf(state), Integer.valueOf(newState), Boolean.valueOf(iconic));
 259         if (changeIconic != 0 && iconic) {
 260             if (stateLog.isLoggable(PlatformLogger.FINER)) stateLog.finer("Iconifying shell " + getShell() + ", this " + this + ", screen " + getScreenNumber());


 261             XToolkit.awtLock();
 262             try {
 263                 int res = XlibWrapper.XIconifyWindow(XToolkit.getDisplay(), getShell(), getScreenNumber());
 264                 if (stateLog.isLoggable(PlatformLogger.FINER)) stateLog.finer("XIconifyWindow returned " + res);


 265             }
 266             finally {
 267                 XToolkit.awtUnlock();
 268             }
 269         }
 270         if ((changed & ~Frame.ICONIFIED) != 0) {
 271             setExtendedState(newState);
 272         }
 273         if (changeIconic != 0 && !iconic) {
 274             if (stateLog.isLoggable(PlatformLogger.FINER)) stateLog.finer("DeIconifying " + this);


 275             xSetVisible(true);
 276         }
 277     }
 278 
 279     void setExtendedState(int newState) {
 280         XWM.getWM().setExtendedState(this, newState);
 281     }
 282 
 283     public void handlePropertyNotify(XEvent xev) {
 284         super.handlePropertyNotify(xev);
 285         XPropertyEvent ev = xev.get_xproperty();
 286 
 287         log.finer("Property change {0}", ev);
 288         /*
 289          * Let's see if this is a window state protocol message, and
 290          * if it is - decode a new state in terms of java constants.
 291          */
 292         if (!XWM.getWM().isStateChange(this, ev)) {
 293             stateLog.finer("either not a state atom or state has not been changed");
 294             return;
 295         }
 296 
 297         final int newState = XWM.getWM().getState(this);
 298         int changed = state ^ newState;
 299         if (changed == 0) {

 300             stateLog.finer("State is the same: " + state);

 301             return;
 302         }
 303 
 304         int old_state = state;
 305         state = newState;
 306 
 307         // sync target with peer
 308         AWTAccessor.getFrameAccessor().setExtendedState((Frame)target, state);
 309 
 310         if ((changed & Frame.ICONIFIED) != 0) {
 311             if ((state & Frame.ICONIFIED) != 0) {
 312                 stateLog.finer("Iconified");
 313                 handleIconify();
 314             } else {
 315                 stateLog.finer("DeIconified");
 316                 content.purgeIconifiedExposeEvents();
 317                 handleDeiconify();
 318             }
 319         }
 320         handleStateChange(old_state, state);


 332     public void setVisible(boolean vis) {
 333         if (vis) {
 334             setupState(false);
 335         } else {
 336             if ((state & Frame.MAXIMIZED_BOTH) != 0) {
 337                 XWM.getWM().setExtendedState(this, state & ~Frame.MAXIMIZED_BOTH);
 338             }
 339         }
 340         super.setVisible(vis);
 341         if (vis && maxBounds != null) {
 342             setMaximizedBounds(maxBounds);
 343         }
 344     }
 345 
 346     void setInitialState(int wm_state) {
 347         XToolkit.awtLock();
 348         try {
 349             XWMHints hints = getWMHints();
 350             hints.set_flags((int)XUtilConstants.StateHint | hints.get_flags());
 351             hints.set_initial_state(wm_state);
 352             if (stateLog.isLoggable(PlatformLogger.FINE)) stateLog.fine("Setting initial WM state on " + this + " to " + wm_state);


 353             XlibWrapper.XSetWMHints(XToolkit.getDisplay(), getWindow(), hints.pData);
 354         }
 355         finally {
 356             XToolkit.awtUnlock();
 357         }
 358     }
 359 
 360     public void dispose() {
 361         if (menubarPeer != null) {
 362             menubarPeer.dispose();
 363         }
 364         super.dispose();
 365     }
 366 
 367     boolean isMaximized() {
 368         return (state & (Frame.MAXIMIZED_VERT  | Frame.MAXIMIZED_HORIZ)) != 0;
 369     }
 370 
 371 
 372 




 192                         if (height != lastAppliedMenubarHeight) {
 193                             lastAppliedMenubarHeight = height;
 194                             heightChanged = true;
 195                         }
 196                     }
 197                     if (heightChanged) {
 198                         // To make frame contents be re-layout (copied from
 199                         // 'XDecoratedPeer.revalidate()'). These are not
 200                         // 'synchronized', because can recursively call client
 201                         // methods, which are not supposed to be called with locks
 202                         // acquired.
 203                         target.invalidate();
 204                         target.validate();
 205                     }
 206                 }
 207             }
 208         );
 209     }
 210 
 211     public void setMaximizedBounds(Rectangle b) {
 212         if (insLog.isLoggable(PlatformLogger.FINE)) {
 213             insLog.fine("Setting maximized bounds to " + b);
 214         }
 215         if (b == null) return;
 216         maxBounds = new Rectangle(b);
 217         XToolkit.awtLock();
 218         try {
 219             XSizeHints hints = getHints();
 220             hints.set_flags(hints.get_flags() | (int)XUtilConstants.PMaxSize);
 221             if (b.width != Integer.MAX_VALUE) {
 222                 hints.set_max_width(b.width);
 223             } else {
 224                 hints.set_max_width((int)XlibWrapper.DisplayWidth(XToolkit.getDisplay(), XlibWrapper.DefaultScreen(XToolkit.getDisplay())));
 225             }
 226             if (b.height != Integer.MAX_VALUE) {
 227                 hints.set_max_height(b.height);
 228             } else {
 229                 hints.set_max_height((int)XlibWrapper.DisplayHeight(XToolkit.getDisplay(), XlibWrapper.DefaultScreen(XToolkit.getDisplay())));
 230             }
 231             if (insLog.isLoggable(PlatformLogger.FINER)) {
 232                 insLog.finer("Setting hints, flags " + XlibWrapper.hintsToString(hints.get_flags()));
 233             }
 234             XlibWrapper.XSetWMNormalHints(XToolkit.getDisplay(), window, hints.pData);
 235         } finally {
 236             XToolkit.awtUnlock();
 237         }
 238     }
 239 
 240     public int getState() {
 241         synchronized(getStateLock()) {
 242             return state;
 243         }
 244     }
 245 
 246     public void setState(int newState) {
 247         synchronized(getStateLock()) {
 248             if (!isShowing()) {
 249                 stateLog.finer("Frame is not showing");
 250                 state = newState;
 251                 return;
 252             }
 253         }
 254         changeState(newState);
 255     }
 256 
 257     void changeState(int newState) {
 258         int changed = state ^ newState;
 259         int changeIconic = changed & Frame.ICONIFIED;
 260         boolean iconic = (newState & Frame.ICONIFIED) != 0;
 261         stateLog.finer("Changing state, old state {0}, new state {1}(iconic {2})",
 262                        Integer.valueOf(state), Integer.valueOf(newState), Boolean.valueOf(iconic));
 263         if (changeIconic != 0 && iconic) {
 264             if (stateLog.isLoggable(PlatformLogger.FINER)) {
 265                 stateLog.finer("Iconifying shell " + getShell() + ", this " + this + ", screen " + getScreenNumber());
 266             }
 267             XToolkit.awtLock();
 268             try {
 269                 int res = XlibWrapper.XIconifyWindow(XToolkit.getDisplay(), getShell(), getScreenNumber());
 270                 if (stateLog.isLoggable(PlatformLogger.FINER)) {
 271                     stateLog.finer("XIconifyWindow returned " + res);
 272                 }
 273             }
 274             finally {
 275                 XToolkit.awtUnlock();
 276             }
 277         }
 278         if ((changed & ~Frame.ICONIFIED) != 0) {
 279             setExtendedState(newState);
 280         }
 281         if (changeIconic != 0 && !iconic) {
 282             if (stateLog.isLoggable(PlatformLogger.FINER)) {
 283                 stateLog.finer("DeIconifying " + this);
 284             }
 285             xSetVisible(true);
 286         }
 287     }
 288 
 289     void setExtendedState(int newState) {
 290         XWM.getWM().setExtendedState(this, newState);
 291     }
 292 
 293     public void handlePropertyNotify(XEvent xev) {
 294         super.handlePropertyNotify(xev);
 295         XPropertyEvent ev = xev.get_xproperty();
 296 
 297         log.finer("Property change {0}", ev);
 298         /*
 299          * Let's see if this is a window state protocol message, and
 300          * if it is - decode a new state in terms of java constants.
 301          */
 302         if (!XWM.getWM().isStateChange(this, ev)) {
 303             stateLog.finer("either not a state atom or state has not been changed");
 304             return;
 305         }
 306 
 307         final int newState = XWM.getWM().getState(this);
 308         int changed = state ^ newState;
 309         if (changed == 0) {
 310             if (stateLog.isLoggable(PlatformLogger.FINER)) {
 311                 stateLog.finer("State is the same: " + state);
 312             }
 313             return;
 314         }
 315 
 316         int old_state = state;
 317         state = newState;
 318 
 319         // sync target with peer
 320         AWTAccessor.getFrameAccessor().setExtendedState((Frame)target, state);
 321 
 322         if ((changed & Frame.ICONIFIED) != 0) {
 323             if ((state & Frame.ICONIFIED) != 0) {
 324                 stateLog.finer("Iconified");
 325                 handleIconify();
 326             } else {
 327                 stateLog.finer("DeIconified");
 328                 content.purgeIconifiedExposeEvents();
 329                 handleDeiconify();
 330             }
 331         }
 332         handleStateChange(old_state, state);


 344     public void setVisible(boolean vis) {
 345         if (vis) {
 346             setupState(false);
 347         } else {
 348             if ((state & Frame.MAXIMIZED_BOTH) != 0) {
 349                 XWM.getWM().setExtendedState(this, state & ~Frame.MAXIMIZED_BOTH);
 350             }
 351         }
 352         super.setVisible(vis);
 353         if (vis && maxBounds != null) {
 354             setMaximizedBounds(maxBounds);
 355         }
 356     }
 357 
 358     void setInitialState(int wm_state) {
 359         XToolkit.awtLock();
 360         try {
 361             XWMHints hints = getWMHints();
 362             hints.set_flags((int)XUtilConstants.StateHint | hints.get_flags());
 363             hints.set_initial_state(wm_state);
 364             if (stateLog.isLoggable(PlatformLogger.FINE)) {
 365                 stateLog.fine("Setting initial WM state on " + this + " to " + wm_state);
 366             }
 367             XlibWrapper.XSetWMHints(XToolkit.getDisplay(), getWindow(), hints.pData);
 368         }
 369         finally {
 370             XToolkit.awtUnlock();
 371         }
 372     }
 373 
 374     public void dispose() {
 375         if (menubarPeer != null) {
 376             menubarPeer.dispose();
 377         }
 378         super.dispose();
 379     }
 380 
 381     boolean isMaximized() {
 382         return (state & (Frame.MAXIMIZED_VERT  | Frame.MAXIMIZED_HORIZ)) != 0;
 383     }
 384 
 385 
 386