197 * FOCUS STUFF 198 *************************************************/ 199 200 /** 201 * Keeps the track of focused state of the _NATIVE_ window 202 */ 203 boolean bHasFocus = false; 204 205 /** 206 * Descendants should use this method to determine whether or not native window 207 * has focus. 208 */ 209 final public boolean hasFocus() { 210 return bHasFocus; 211 } 212 213 /** 214 * Called when component receives focus 215 */ 216 public void focusGained(FocusEvent e) { 217 if (focusLog.isLoggable(PlatformLogger.FINE)) { 218 focusLog.fine("{0}", e); 219 } 220 bHasFocus = true; 221 } 222 223 /** 224 * Called when component loses focus 225 */ 226 public void focusLost(FocusEvent e) { 227 if (focusLog.isLoggable(PlatformLogger.FINE)) { 228 focusLog.fine("{0}", e); 229 } 230 bHasFocus = false; 231 } 232 233 public boolean isFocusable() { 234 /* should be implemented by other sub-classes */ 235 return false; 236 } 237 238 private static Class seClass; 239 private static Constructor seCtor; 240 241 final static AWTEvent wrapInSequenced(AWTEvent event) { 242 try { 243 if (seClass == null) { 244 seClass = Class.forName("java.awt.SequencedEvent"); 245 } 246 247 if (seCtor == null) { 281 CausedFocusEvent.Cause cause) 282 { 283 if (XKeyboardFocusManagerPeer. 284 processSynchronousLightweightTransfer(target, lightweightChild, temporary, 285 focusedWindowChangeAllowed, time)) 286 { 287 return true; 288 } 289 290 int result = XKeyboardFocusManagerPeer. 291 shouldNativelyFocusHeavyweight(target, lightweightChild, 292 temporary, focusedWindowChangeAllowed, 293 time, cause); 294 295 switch (result) { 296 case XKeyboardFocusManagerPeer.SNFH_FAILURE: 297 return false; 298 case XKeyboardFocusManagerPeer.SNFH_SUCCESS_PROCEED: 299 // Currently we just generate focus events like we deal with lightweight instead of calling 300 // XSetInputFocus on native window 301 if (focusLog.isLoggable(PlatformLogger.FINER)) { 302 focusLog.finer("Proceeding with request to " + 303 lightweightChild + " in " + target); 304 } 305 /** 306 * The problems with requests in non-focused window arise because shouldNativelyFocusHeavyweight 307 * checks that native window is focused while appropriate WINDOW_GAINED_FOCUS has not yet 308 * been processed - it is in EventQueue. Thus, SNFH allows native request and stores request record 309 * in requests list - and it breaks our requests sequence as first record on WGF should be the last 310 * focus owner which had focus before WLF. So, we should not add request record for such requests 311 * but store this component in mostRecent - and return true as before for compatibility. 312 */ 313 Window parentWindow = SunToolkit.getContainingWindow(target); 314 if (parentWindow == null) { 315 return rejectFocusRequestHelper("WARNING: Parent window is null"); 316 } 317 XWindowPeer wpeer = (XWindowPeer)parentWindow.getPeer(); 318 if (wpeer == null) { 319 return rejectFocusRequestHelper("WARNING: Parent window's peer is null"); 320 } 321 /* 322 * Passing null 'actualFocusedWindow' as we don't want to restore focus on it 323 * when a component inside a Frame is requesting focus. 324 * See 6314575 for details. 325 */ 326 boolean res = wpeer.requestWindowFocus(null); 327 328 if (focusLog.isLoggable(PlatformLogger.FINER)) { 329 focusLog.finer("Requested window focus: " + res); 330 } 331 // If parent window can be made focused and has been made focused(synchronously) 332 // then we can proceed with children, otherwise we retreat. 333 if (!(res && parentWindow.isFocused())) { 334 return rejectFocusRequestHelper("Waiting for asynchronous processing of the request"); 335 } 336 return XKeyboardFocusManagerPeer.deliverFocus(lightweightChild, 337 (Component)target, 338 temporary, 339 focusedWindowChangeAllowed, 340 time, cause); 341 // Motif compatibility code 342 case XKeyboardFocusManagerPeer.SNFH_SUCCESS_HANDLED: 343 // Either lightweight or excessive request - all events are generated. 344 return true; 345 } 346 return false; 347 } 348 349 private boolean rejectFocusRequestHelper(String logMsg) { 350 if (focusLog.isLoggable(PlatformLogger.FINER)) { 351 focusLog.finer(logMsg); 352 } 353 XKeyboardFocusManagerPeer.removeLastFocusRequest(target); 354 return false; 355 } 356 357 void handleJavaFocusEvent(AWTEvent e) { 358 if (focusLog.isLoggable(PlatformLogger.FINER)) { 359 focusLog.finer(e.toString()); 360 } 361 if (e.getID() == FocusEvent.FOCUS_GAINED) { 362 focusGained((FocusEvent)e); 363 } else { 364 focusLost((FocusEvent)e); 365 } 366 } 367 368 void handleJavaWindowFocusEvent(AWTEvent e) { 369 } 370 371 /************************************************* 372 * END OF FOCUS STUFF 373 *************************************************/ 374 375 376 377 public void setVisible(boolean b) { 378 xSetVisible(b); 379 } 380 381 public void hide() { 382 setVisible(false); 383 } 384 385 /** 386 * @see java.awt.peer.ComponentPeer 387 */ 388 public void setEnabled(final boolean value) { 389 if (enableLog.isLoggable(PlatformLogger.FINE)) { 390 enableLog.fine("{0}ing {1}", (value ? "Enabl" : "Disabl"), this); 391 } 392 boolean status = value; 393 // If any of our heavyweight ancestors are disable, we should be too 394 // See 6176875 for more information 395 final Container cp = SunToolkit.getNativeContainer(target); 396 if (cp != null) { 397 status &= ((XComponentPeer) cp.getPeer()).isEnabled(); 398 } 399 synchronized (getStateLock()) { 400 if (enabled == status) { 401 return; 402 } 403 enabled = status; 404 } 405 406 if (target instanceof Container) { 407 final Component[] list = ((Container) target).getComponents(); 408 for (final Component child : list) { 409 final ComponentPeer p = child.getPeer(); 450 this.y = y; 451 this.width = width; 452 this.height = height; 453 xSetBounds(x,y,width,height); 454 validateSurface(); 455 layout(); 456 } 457 458 public void reshape(int x, int y, int width, int height) { 459 setBounds(x, y, width, height, SET_BOUNDS); 460 } 461 462 public void coalescePaintEvent(PaintEvent e) { 463 Rectangle r = e.getUpdateRect(); 464 if (!(e instanceof IgnorePaintEvent)) { 465 paintArea.add(r, e.getID()); 466 } 467 if (true) { 468 switch(e.getID()) { 469 case PaintEvent.UPDATE: 470 if (log.isLoggable(PlatformLogger.FINER)) { 471 log.finer("XCP coalescePaintEvent : UPDATE : add : x = " + 472 r.x + ", y = " + r.y + ", width = " + r.width + ",height = " + r.height); 473 } 474 return; 475 case PaintEvent.PAINT: 476 if (log.isLoggable(PlatformLogger.FINER)) { 477 log.finer("XCP coalescePaintEvent : PAINT : add : x = " + 478 r.x + ", y = " + r.y + ", width = " + r.width + ",height = " + r.height); 479 } 480 return; 481 } 482 } 483 } 484 485 XWindowPeer getParentTopLevel() { 486 AWTAccessor.ComponentAccessor compAccessor = AWTAccessor.getComponentAccessor(); 487 Container parent = (target instanceof Container) ? ((Container)target) : (compAccessor.getParent(target)); 488 // Search for parent window 489 while (parent != null && !(parent instanceof Window)) { 490 parent = compAccessor.getParent(parent); 491 } 492 if (parent != null) { 493 return (XWindowPeer)compAccessor.getPeer(parent); 494 } else { 495 return null; 496 } 623 624 /* 625 * Draw a 3D rectangle using the Motif colors. 626 * "Normal" rectangles have shadows on the bottom. 627 * "Depressed" rectangles (such as pressed buttons) have shadows on the top, 628 * in which case true should be passed for topShadow. 629 */ 630 public void drawMotif3DRect(Graphics g, 631 int x, int y, int width, int height, 632 boolean topShadow) { 633 g.setColor(topShadow ? darkShadow : lightShadow); 634 g.drawLine(x, y, x+width, y); // top 635 g.drawLine(x, y+height, x, y); // left 636 637 g.setColor(topShadow ? lightShadow : darkShadow ); 638 g.drawLine(x+1, y+height, x+width, y+height); // bottom 639 g.drawLine(x+width, y+height, x+width, y+1); // right 640 } 641 642 public void setBackground(Color c) { 643 if (log.isLoggable(PlatformLogger.FINE)) { 644 log.fine("Set background to " + c); 645 } 646 synchronized (getStateLock()) { 647 background = c; 648 } 649 super.setBackground(c); 650 repaint(); 651 } 652 653 public void setForeground(Color c) { 654 if (log.isLoggable(PlatformLogger.FINE)) { 655 log.fine("Set foreground to " + c); 656 } 657 synchronized (getStateLock()) { 658 foreground = c; 659 } 660 repaint(); 661 } 662 663 /** 664 * Gets the font metrics for the specified font. 665 * @param font the font for which font metrics is to be 666 * obtained 667 * @return the font metrics for <code>font</code> 668 * @see #getFont 669 * @see #getPeer 670 * @see java.awt.peer.ComponentPeer#getFontMetrics(Font) 671 * @see Toolkit#getFontMetrics(Font) 672 * @since JDK1.0 673 */ 674 public FontMetrics getFontMetrics(Font font) { 675 if (fontLog.isLoggable(PlatformLogger.FINE)) { 676 fontLog.fine("Getting font metrics for " + font); 677 } 678 return sun.font.FontDesignMetrics.getMetrics(font); 679 } 680 681 public void setFont(Font f) { 682 synchronized (getStateLock()) { 683 if (f == null) { 684 f = XWindow.getDefaultFont(); 685 } 686 font = f; 687 } 688 // as it stands currently we dont need to do layout or repaint since 689 // layout is done in the Component upon setFont. 690 //layout(); 691 // target.repaint(); 692 //repaint()? 693 } 694 695 public Font getFont() { 1141 g.drawLine(v1, thickness-2, v1 + v2, thickness-2); 1142 } else { 1143 g.drawLine(2, v1 + v2, thickness-2, v1 + v2); 1144 g.drawLine(thickness-2, v1, thickness-2, v1 + v2); 1145 } 1146 } 1147 g.setColor(c); 1148 } 1149 1150 /** 1151 * The following multibuffering-related methods delegate to our 1152 * associated GraphicsConfig (X11 or GLX) to handle the appropriate 1153 * native windowing system specific actions. 1154 */ 1155 1156 private BufferCapabilities backBufferCaps; 1157 1158 public void createBuffers(int numBuffers, BufferCapabilities caps) 1159 throws AWTException 1160 { 1161 if (buffersLog.isLoggable(PlatformLogger.FINE)) { 1162 buffersLog.fine("createBuffers(" + numBuffers + ", " + caps + ")"); 1163 } 1164 // set the caps first, they're used when creating the bb 1165 backBufferCaps = caps; 1166 backBuffer = graphicsConfig.createBackBuffer(this, numBuffers, caps); 1167 xBackBuffer = graphicsConfig.createBackBufferImage(target, 1168 backBuffer); 1169 } 1170 1171 @Override 1172 public BufferCapabilities getBackBufferCaps() { 1173 return backBufferCaps; 1174 } 1175 1176 public void flip(int x1, int y1, int x2, int y2, 1177 BufferCapabilities.FlipContents flipAction) 1178 { 1179 if (buffersLog.isLoggable(PlatformLogger.FINE)) { 1180 buffersLog.fine("flip(" + flipAction + ")"); 1181 } 1182 if (backBuffer == 0) { 1183 throw new IllegalStateException("Buffers have not been created"); 1184 } 1185 graphicsConfig.flip(this, target, xBackBuffer, 1186 x1, y1, x2, y2, flipAction); 1187 } 1188 1189 public Image getBackBuffer() { 1190 if (buffersLog.isLoggable(PlatformLogger.FINE)) { 1191 buffersLog.fine("getBackBuffer()"); 1192 } 1193 if (backBuffer == 0) { 1194 throw new IllegalStateException("Buffers have not been created"); 1195 } 1196 return xBackBuffer; 1197 } 1198 1199 public void destroyBuffers() { 1200 if (buffersLog.isLoggable(PlatformLogger.FINE)) { 1201 buffersLog.fine("destroyBuffers()"); 1202 } 1203 graphicsConfig.destroyBackBuffer(backBuffer); 1204 backBuffer = 0; 1205 xBackBuffer = null; 1206 } 1207 1208 // End of multi-buffering 1209 1210 public void notifyTextComponentChange(boolean add){ 1211 Container parent = AWTAccessor.getComponentAccessor().getParent(target); 1212 while(!(parent == null || 1213 parent instanceof java.awt.Frame || 1214 parent instanceof java.awt.Dialog)) { 1215 parent = AWTAccessor.getComponentAccessor().getParent(parent); 1216 } 1217 1218 /* FIX ME - FIX ME need to implement InputMethods 1219 if (parent instanceof java.awt.Frame || 1220 parent instanceof java.awt.Dialog) { 1221 if (add) 1222 ((MInputMethodControl)parent.getPeer()).addTextComponent((MComponentPeer)this); 1223 else 1224 ((MInputMethodControl)parent.getPeer()).removeTextComponent((MComponentPeer)this); 1225 } 1226 */ 1227 } 1228 1229 /** 1230 * Returns true if this event is disabled and shouldn't be processed by window 1231 * Currently if target component is disabled the following event will be disabled on window: 1232 * ButtonPress, ButtonRelease, KeyPress, KeyRelease, EnterNotify, LeaveNotify, MotionNotify 1233 */ 1234 protected boolean isEventDisabled(XEvent e) { 1235 if (enableLog.isLoggable(PlatformLogger.FINEST)) { 1236 enableLog.finest("Component is {1}, checking for disabled event {0}", e, (isEnabled()?"enabled":"disable")); 1237 } 1238 if (!isEnabled()) { 1239 switch (e.get_type()) { 1240 case XConstants.ButtonPress: 1241 case XConstants.ButtonRelease: 1242 case XConstants.KeyPress: 1243 case XConstants.KeyRelease: 1244 case XConstants.EnterNotify: 1245 case XConstants.LeaveNotify: 1246 case XConstants.MotionNotify: 1247 if (enableLog.isLoggable(PlatformLogger.FINER)) { 1248 enableLog.finer("Event {0} is disable", e); 1249 } 1250 return true; 1251 } 1252 } 1253 switch(e.get_type()) { 1254 case XConstants.MapNotify: 1255 case XConstants.UnmapNotify: 1256 return true; 1257 } 1258 return super.isEventDisabled(e); 1259 } 1260 1261 Color getPeerBackground() { 1262 return background; 1263 } 1264 1265 Color getPeerForeground() { 1266 return foreground; 1267 } 1350 public void removeDropTarget(DropTarget dt) { 1351 Component comp = target; 1352 while(!(comp == null || comp instanceof Window)) { 1353 comp = comp.getParent(); 1354 } 1355 1356 if (comp instanceof Window) { 1357 XWindowPeer wpeer = (XWindowPeer)(comp.getPeer()); 1358 if (wpeer != null) { 1359 wpeer.removeDropTarget(); 1360 } 1361 } 1362 } 1363 1364 /** 1365 * Applies the shape to the X-window. 1366 * @since 1.7 1367 */ 1368 public void applyShape(Region shape) { 1369 if (XlibUtil.isShapingSupported()) { 1370 if (shapeLog.isLoggable(PlatformLogger.FINER)) { 1371 shapeLog.finer( 1372 "*** INFO: Setting shape: PEER: " + this 1373 + "; WINDOW: " + getWindow() 1374 + "; TARGET: " + target 1375 + "; SHAPE: " + shape); 1376 } 1377 XToolkit.awtLock(); 1378 try { 1379 if (shape != null) { 1380 XlibWrapper.SetRectangularShape( 1381 XToolkit.getDisplay(), 1382 getWindow(), 1383 shape.getLoX(), shape.getLoY(), 1384 shape.getHiX(), shape.getHiY(), 1385 (shape.isRectangular() ? null : shape) 1386 ); 1387 } else { 1388 XlibWrapper.SetRectangularShape( 1389 XToolkit.getDisplay(), 1390 getWindow(), 1391 0, 0, 1392 0, 0, 1393 null 1394 ); 1395 } 1396 } finally { 1397 XToolkit.awtUnlock(); 1398 } 1399 } else { 1400 if (shapeLog.isLoggable(PlatformLogger.FINER)) { 1401 shapeLog.finer("*** WARNING: Shaping is NOT supported!"); 1402 } 1403 } 1404 } 1405 1406 public boolean updateGraphicsData(GraphicsConfiguration gc) { 1407 int oldVisual = -1, newVisual = -1; 1408 1409 if (graphicsConfig != null) { 1410 oldVisual = graphicsConfig.getVisual(); 1411 } 1412 if (gc != null && gc instanceof X11GraphicsConfig) { 1413 newVisual = ((X11GraphicsConfig)gc).getVisual(); 1414 } 1415 1416 // If the new visual differs from the old one, the peer must be 1417 // recreated because X11 does not allow changing the visual on the fly. 1418 // So we even skip the initGraphicsConfiguration() call. 1419 // The initial assignment should happen though, hence the != -1 thing. 1420 if (oldVisual != -1 && oldVisual != newVisual) { | 197 * FOCUS STUFF 198 *************************************************/ 199 200 /** 201 * Keeps the track of focused state of the _NATIVE_ window 202 */ 203 boolean bHasFocus = false; 204 205 /** 206 * Descendants should use this method to determine whether or not native window 207 * has focus. 208 */ 209 final public boolean hasFocus() { 210 return bHasFocus; 211 } 212 213 /** 214 * Called when component receives focus 215 */ 216 public void focusGained(FocusEvent e) { 217 if (focusLog.isLoggable(PlatformLogger.Level.FINE)) { 218 focusLog.fine("{0}", e); 219 } 220 bHasFocus = true; 221 } 222 223 /** 224 * Called when component loses focus 225 */ 226 public void focusLost(FocusEvent e) { 227 if (focusLog.isLoggable(PlatformLogger.Level.FINE)) { 228 focusLog.fine("{0}", e); 229 } 230 bHasFocus = false; 231 } 232 233 public boolean isFocusable() { 234 /* should be implemented by other sub-classes */ 235 return false; 236 } 237 238 private static Class seClass; 239 private static Constructor seCtor; 240 241 final static AWTEvent wrapInSequenced(AWTEvent event) { 242 try { 243 if (seClass == null) { 244 seClass = Class.forName("java.awt.SequencedEvent"); 245 } 246 247 if (seCtor == null) { 281 CausedFocusEvent.Cause cause) 282 { 283 if (XKeyboardFocusManagerPeer. 284 processSynchronousLightweightTransfer(target, lightweightChild, temporary, 285 focusedWindowChangeAllowed, time)) 286 { 287 return true; 288 } 289 290 int result = XKeyboardFocusManagerPeer. 291 shouldNativelyFocusHeavyweight(target, lightweightChild, 292 temporary, focusedWindowChangeAllowed, 293 time, cause); 294 295 switch (result) { 296 case XKeyboardFocusManagerPeer.SNFH_FAILURE: 297 return false; 298 case XKeyboardFocusManagerPeer.SNFH_SUCCESS_PROCEED: 299 // Currently we just generate focus events like we deal with lightweight instead of calling 300 // XSetInputFocus on native window 301 if (focusLog.isLoggable(PlatformLogger.Level.FINER)) { 302 focusLog.finer("Proceeding with request to " + 303 lightweightChild + " in " + target); 304 } 305 /** 306 * The problems with requests in non-focused window arise because shouldNativelyFocusHeavyweight 307 * checks that native window is focused while appropriate WINDOW_GAINED_FOCUS has not yet 308 * been processed - it is in EventQueue. Thus, SNFH allows native request and stores request record 309 * in requests list - and it breaks our requests sequence as first record on WGF should be the last 310 * focus owner which had focus before WLF. So, we should not add request record for such requests 311 * but store this component in mostRecent - and return true as before for compatibility. 312 */ 313 Window parentWindow = SunToolkit.getContainingWindow(target); 314 if (parentWindow == null) { 315 return rejectFocusRequestHelper("WARNING: Parent window is null"); 316 } 317 XWindowPeer wpeer = (XWindowPeer)parentWindow.getPeer(); 318 if (wpeer == null) { 319 return rejectFocusRequestHelper("WARNING: Parent window's peer is null"); 320 } 321 /* 322 * Passing null 'actualFocusedWindow' as we don't want to restore focus on it 323 * when a component inside a Frame is requesting focus. 324 * See 6314575 for details. 325 */ 326 boolean res = wpeer.requestWindowFocus(null); 327 328 if (focusLog.isLoggable(PlatformLogger.Level.FINER)) { 329 focusLog.finer("Requested window focus: " + res); 330 } 331 // If parent window can be made focused and has been made focused(synchronously) 332 // then we can proceed with children, otherwise we retreat. 333 if (!(res && parentWindow.isFocused())) { 334 return rejectFocusRequestHelper("Waiting for asynchronous processing of the request"); 335 } 336 return XKeyboardFocusManagerPeer.deliverFocus(lightweightChild, 337 (Component)target, 338 temporary, 339 focusedWindowChangeAllowed, 340 time, cause); 341 // Motif compatibility code 342 case XKeyboardFocusManagerPeer.SNFH_SUCCESS_HANDLED: 343 // Either lightweight or excessive request - all events are generated. 344 return true; 345 } 346 return false; 347 } 348 349 private boolean rejectFocusRequestHelper(String logMsg) { 350 if (focusLog.isLoggable(PlatformLogger.Level.FINER)) { 351 focusLog.finer(logMsg); 352 } 353 XKeyboardFocusManagerPeer.removeLastFocusRequest(target); 354 return false; 355 } 356 357 void handleJavaFocusEvent(AWTEvent e) { 358 if (focusLog.isLoggable(PlatformLogger.Level.FINER)) { 359 focusLog.finer(e.toString()); 360 } 361 if (e.getID() == FocusEvent.FOCUS_GAINED) { 362 focusGained((FocusEvent)e); 363 } else { 364 focusLost((FocusEvent)e); 365 } 366 } 367 368 void handleJavaWindowFocusEvent(AWTEvent e) { 369 } 370 371 /************************************************* 372 * END OF FOCUS STUFF 373 *************************************************/ 374 375 376 377 public void setVisible(boolean b) { 378 xSetVisible(b); 379 } 380 381 public void hide() { 382 setVisible(false); 383 } 384 385 /** 386 * @see java.awt.peer.ComponentPeer 387 */ 388 public void setEnabled(final boolean value) { 389 if (enableLog.isLoggable(PlatformLogger.Level.FINE)) { 390 enableLog.fine("{0}ing {1}", (value ? "Enabl" : "Disabl"), this); 391 } 392 boolean status = value; 393 // If any of our heavyweight ancestors are disable, we should be too 394 // See 6176875 for more information 395 final Container cp = SunToolkit.getNativeContainer(target); 396 if (cp != null) { 397 status &= ((XComponentPeer) cp.getPeer()).isEnabled(); 398 } 399 synchronized (getStateLock()) { 400 if (enabled == status) { 401 return; 402 } 403 enabled = status; 404 } 405 406 if (target instanceof Container) { 407 final Component[] list = ((Container) target).getComponents(); 408 for (final Component child : list) { 409 final ComponentPeer p = child.getPeer(); 450 this.y = y; 451 this.width = width; 452 this.height = height; 453 xSetBounds(x,y,width,height); 454 validateSurface(); 455 layout(); 456 } 457 458 public void reshape(int x, int y, int width, int height) { 459 setBounds(x, y, width, height, SET_BOUNDS); 460 } 461 462 public void coalescePaintEvent(PaintEvent e) { 463 Rectangle r = e.getUpdateRect(); 464 if (!(e instanceof IgnorePaintEvent)) { 465 paintArea.add(r, e.getID()); 466 } 467 if (true) { 468 switch(e.getID()) { 469 case PaintEvent.UPDATE: 470 if (log.isLoggable(PlatformLogger.Level.FINER)) { 471 log.finer("XCP coalescePaintEvent : UPDATE : add : x = " + 472 r.x + ", y = " + r.y + ", width = " + r.width + ",height = " + r.height); 473 } 474 return; 475 case PaintEvent.PAINT: 476 if (log.isLoggable(PlatformLogger.Level.FINER)) { 477 log.finer("XCP coalescePaintEvent : PAINT : add : x = " + 478 r.x + ", y = " + r.y + ", width = " + r.width + ",height = " + r.height); 479 } 480 return; 481 } 482 } 483 } 484 485 XWindowPeer getParentTopLevel() { 486 AWTAccessor.ComponentAccessor compAccessor = AWTAccessor.getComponentAccessor(); 487 Container parent = (target instanceof Container) ? ((Container)target) : (compAccessor.getParent(target)); 488 // Search for parent window 489 while (parent != null && !(parent instanceof Window)) { 490 parent = compAccessor.getParent(parent); 491 } 492 if (parent != null) { 493 return (XWindowPeer)compAccessor.getPeer(parent); 494 } else { 495 return null; 496 } 623 624 /* 625 * Draw a 3D rectangle using the Motif colors. 626 * "Normal" rectangles have shadows on the bottom. 627 * "Depressed" rectangles (such as pressed buttons) have shadows on the top, 628 * in which case true should be passed for topShadow. 629 */ 630 public void drawMotif3DRect(Graphics g, 631 int x, int y, int width, int height, 632 boolean topShadow) { 633 g.setColor(topShadow ? darkShadow : lightShadow); 634 g.drawLine(x, y, x+width, y); // top 635 g.drawLine(x, y+height, x, y); // left 636 637 g.setColor(topShadow ? lightShadow : darkShadow ); 638 g.drawLine(x+1, y+height, x+width, y+height); // bottom 639 g.drawLine(x+width, y+height, x+width, y+1); // right 640 } 641 642 public void setBackground(Color c) { 643 if (log.isLoggable(PlatformLogger.Level.FINE)) { 644 log.fine("Set background to " + c); 645 } 646 synchronized (getStateLock()) { 647 background = c; 648 } 649 super.setBackground(c); 650 repaint(); 651 } 652 653 public void setForeground(Color c) { 654 if (log.isLoggable(PlatformLogger.Level.FINE)) { 655 log.fine("Set foreground to " + c); 656 } 657 synchronized (getStateLock()) { 658 foreground = c; 659 } 660 repaint(); 661 } 662 663 /** 664 * Gets the font metrics for the specified font. 665 * @param font the font for which font metrics is to be 666 * obtained 667 * @return the font metrics for <code>font</code> 668 * @see #getFont 669 * @see #getPeer 670 * @see java.awt.peer.ComponentPeer#getFontMetrics(Font) 671 * @see Toolkit#getFontMetrics(Font) 672 * @since JDK1.0 673 */ 674 public FontMetrics getFontMetrics(Font font) { 675 if (fontLog.isLoggable(PlatformLogger.Level.FINE)) { 676 fontLog.fine("Getting font metrics for " + font); 677 } 678 return sun.font.FontDesignMetrics.getMetrics(font); 679 } 680 681 public void setFont(Font f) { 682 synchronized (getStateLock()) { 683 if (f == null) { 684 f = XWindow.getDefaultFont(); 685 } 686 font = f; 687 } 688 // as it stands currently we dont need to do layout or repaint since 689 // layout is done in the Component upon setFont. 690 //layout(); 691 // target.repaint(); 692 //repaint()? 693 } 694 695 public Font getFont() { 1141 g.drawLine(v1, thickness-2, v1 + v2, thickness-2); 1142 } else { 1143 g.drawLine(2, v1 + v2, thickness-2, v1 + v2); 1144 g.drawLine(thickness-2, v1, thickness-2, v1 + v2); 1145 } 1146 } 1147 g.setColor(c); 1148 } 1149 1150 /** 1151 * The following multibuffering-related methods delegate to our 1152 * associated GraphicsConfig (X11 or GLX) to handle the appropriate 1153 * native windowing system specific actions. 1154 */ 1155 1156 private BufferCapabilities backBufferCaps; 1157 1158 public void createBuffers(int numBuffers, BufferCapabilities caps) 1159 throws AWTException 1160 { 1161 if (buffersLog.isLoggable(PlatformLogger.Level.FINE)) { 1162 buffersLog.fine("createBuffers(" + numBuffers + ", " + caps + ")"); 1163 } 1164 // set the caps first, they're used when creating the bb 1165 backBufferCaps = caps; 1166 backBuffer = graphicsConfig.createBackBuffer(this, numBuffers, caps); 1167 xBackBuffer = graphicsConfig.createBackBufferImage(target, 1168 backBuffer); 1169 } 1170 1171 @Override 1172 public BufferCapabilities getBackBufferCaps() { 1173 return backBufferCaps; 1174 } 1175 1176 public void flip(int x1, int y1, int x2, int y2, 1177 BufferCapabilities.FlipContents flipAction) 1178 { 1179 if (buffersLog.isLoggable(PlatformLogger.Level.FINE)) { 1180 buffersLog.fine("flip(" + flipAction + ")"); 1181 } 1182 if (backBuffer == 0) { 1183 throw new IllegalStateException("Buffers have not been created"); 1184 } 1185 graphicsConfig.flip(this, target, xBackBuffer, 1186 x1, y1, x2, y2, flipAction); 1187 } 1188 1189 public Image getBackBuffer() { 1190 if (buffersLog.isLoggable(PlatformLogger.Level.FINE)) { 1191 buffersLog.fine("getBackBuffer()"); 1192 } 1193 if (backBuffer == 0) { 1194 throw new IllegalStateException("Buffers have not been created"); 1195 } 1196 return xBackBuffer; 1197 } 1198 1199 public void destroyBuffers() { 1200 if (buffersLog.isLoggable(PlatformLogger.Level.FINE)) { 1201 buffersLog.fine("destroyBuffers()"); 1202 } 1203 graphicsConfig.destroyBackBuffer(backBuffer); 1204 backBuffer = 0; 1205 xBackBuffer = null; 1206 } 1207 1208 // End of multi-buffering 1209 1210 public void notifyTextComponentChange(boolean add){ 1211 Container parent = AWTAccessor.getComponentAccessor().getParent(target); 1212 while(!(parent == null || 1213 parent instanceof java.awt.Frame || 1214 parent instanceof java.awt.Dialog)) { 1215 parent = AWTAccessor.getComponentAccessor().getParent(parent); 1216 } 1217 1218 /* FIX ME - FIX ME need to implement InputMethods 1219 if (parent instanceof java.awt.Frame || 1220 parent instanceof java.awt.Dialog) { 1221 if (add) 1222 ((MInputMethodControl)parent.getPeer()).addTextComponent((MComponentPeer)this); 1223 else 1224 ((MInputMethodControl)parent.getPeer()).removeTextComponent((MComponentPeer)this); 1225 } 1226 */ 1227 } 1228 1229 /** 1230 * Returns true if this event is disabled and shouldn't be processed by window 1231 * Currently if target component is disabled the following event will be disabled on window: 1232 * ButtonPress, ButtonRelease, KeyPress, KeyRelease, EnterNotify, LeaveNotify, MotionNotify 1233 */ 1234 protected boolean isEventDisabled(XEvent e) { 1235 if (enableLog.isLoggable(PlatformLogger.Level.FINEST)) { 1236 enableLog.finest("Component is {1}, checking for disabled event {0}", e, (isEnabled()?"enabled":"disable")); 1237 } 1238 if (!isEnabled()) { 1239 switch (e.get_type()) { 1240 case XConstants.ButtonPress: 1241 case XConstants.ButtonRelease: 1242 case XConstants.KeyPress: 1243 case XConstants.KeyRelease: 1244 case XConstants.EnterNotify: 1245 case XConstants.LeaveNotify: 1246 case XConstants.MotionNotify: 1247 if (enableLog.isLoggable(PlatformLogger.Level.FINER)) { 1248 enableLog.finer("Event {0} is disable", e); 1249 } 1250 return true; 1251 } 1252 } 1253 switch(e.get_type()) { 1254 case XConstants.MapNotify: 1255 case XConstants.UnmapNotify: 1256 return true; 1257 } 1258 return super.isEventDisabled(e); 1259 } 1260 1261 Color getPeerBackground() { 1262 return background; 1263 } 1264 1265 Color getPeerForeground() { 1266 return foreground; 1267 } 1350 public void removeDropTarget(DropTarget dt) { 1351 Component comp = target; 1352 while(!(comp == null || comp instanceof Window)) { 1353 comp = comp.getParent(); 1354 } 1355 1356 if (comp instanceof Window) { 1357 XWindowPeer wpeer = (XWindowPeer)(comp.getPeer()); 1358 if (wpeer != null) { 1359 wpeer.removeDropTarget(); 1360 } 1361 } 1362 } 1363 1364 /** 1365 * Applies the shape to the X-window. 1366 * @since 1.7 1367 */ 1368 public void applyShape(Region shape) { 1369 if (XlibUtil.isShapingSupported()) { 1370 if (shapeLog.isLoggable(PlatformLogger.Level.FINER)) { 1371 shapeLog.finer( 1372 "*** INFO: Setting shape: PEER: " + this 1373 + "; WINDOW: " + getWindow() 1374 + "; TARGET: " + target 1375 + "; SHAPE: " + shape); 1376 } 1377 XToolkit.awtLock(); 1378 try { 1379 if (shape != null) { 1380 XlibWrapper.SetRectangularShape( 1381 XToolkit.getDisplay(), 1382 getWindow(), 1383 shape.getLoX(), shape.getLoY(), 1384 shape.getHiX(), shape.getHiY(), 1385 (shape.isRectangular() ? null : shape) 1386 ); 1387 } else { 1388 XlibWrapper.SetRectangularShape( 1389 XToolkit.getDisplay(), 1390 getWindow(), 1391 0, 0, 1392 0, 0, 1393 null 1394 ); 1395 } 1396 } finally { 1397 XToolkit.awtUnlock(); 1398 } 1399 } else { 1400 if (shapeLog.isLoggable(PlatformLogger.Level.FINER)) { 1401 shapeLog.finer("*** WARNING: Shaping is NOT supported!"); 1402 } 1403 } 1404 } 1405 1406 public boolean updateGraphicsData(GraphicsConfiguration gc) { 1407 int oldVisual = -1, newVisual = -1; 1408 1409 if (graphicsConfig != null) { 1410 oldVisual = graphicsConfig.getVisual(); 1411 } 1412 if (gc != null && gc instanceof X11GraphicsConfig) { 1413 newVisual = ((X11GraphicsConfig)gc).getVisual(); 1414 } 1415 1416 // If the new visual differs from the old one, the peer must be 1417 // recreated because X11 does not allow changing the visual on the fly. 1418 // So we even skip the initGraphicsConfiguration() call. 1419 // The initial assignment should happen though, hence the != -1 thing. 1420 if (oldVisual != -1 && oldVisual != newVisual) { |