javauis/eswt_qt/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/widgets/Control.java
changeset 79 2f468c1958d0
parent 61 bf7ee68962da
equal deleted inserted replaced
76:4ad59aaee882 79:2f468c1958d0
    39 import org.eclipse.swt.internal.qt.SharedGCWrapper;
    39 import org.eclipse.swt.internal.qt.SharedGCWrapper;
    40 import org.eclipse.swt.internal.qt.WidgetConstant;
    40 import org.eclipse.swt.internal.qt.WidgetConstant;
    41 import org.eclipse.swt.internal.qt.WidgetState;
    41 import org.eclipse.swt.internal.qt.WidgetState;
    42 import org.eclipse.swt.internal.qt.graphics.NativeCommandBuffer;
    42 import org.eclipse.swt.internal.qt.graphics.NativeCommandBuffer;
    43 import org.eclipse.swt.internal.qt.graphics.GraphicsContext;
    43 import org.eclipse.swt.internal.qt.graphics.GraphicsContext;
       
    44 import org.eclipse.swt.internal.qt.graphics.WindowSurface;
    44 
    45 
    45 /**
    46 /**
    46  * Control is the abstract superclass of all windowed user interface classes.
    47  * Control is the abstract superclass of all windowed user interface classes.
    47  * <p>
    48  * <p>
    48  * <dl>
    49  * <dl>
    79     Vector/*<GraphicsContext>*/ bufferedGcs;
    80     Vector/*<GraphicsContext>*/ bufferedGcs;
    80     Vector/*<Buffer>*/ gcBuffers;
    81     Vector/*<Buffer>*/ gcBuffers;
    81 
    82 
    82     private byte isPainting;
    83     private byte isPainting;
    83     boolean bufferFlush;
    84     boolean bufferFlush;
       
    85     WindowSurface windowSurface;
    84 
    86 
    85 Control() {
    87 Control() {
    86 }
    88 }
    87 
    89 
    88 /**
    90 /**
   751     // respectively enables all child widgets unless they have been explicitly
   753     // respectively enables all child widgets unless they have been explicitly
   752     // disabled.
   754     // disabled.
   753     OS.QWidget_setEnabled(topHandle, enabled);
   755     OS.QWidget_setEnabled(topHandle, enabled);
   754 }
   756 }
   755 
   757 
       
   758 /*
       
   759  * Closes window surface session
       
   760  */
       
   761 void endWindowSurfaceSession() {
       
   762 	checkWidget();
       
   763 	windowSurface.endPaint();
       
   764 }
       
   765 
   756 Control findBackgroundControl () {
   766 Control findBackgroundControl () {
   757     if (background != null || backgroundImage != null) return this;
   767     if (background != null || backgroundImage != null) return this;
   758     return (state & WidgetState.PARENT_BACKGROUND) != 0 ? parent.findBackgroundControl () : null;
   768     return (state & WidgetState.PARENT_BACKGROUND) != 0 ? parent.findBackgroundControl () : null;
   759 }
   769 }
   760 
   770 
   817     if(handle != 0) {
   827     if(handle != 0) {
   818         OS.QWidget_setAttribute(handle, OS.QT_WA_NOMOUSEPROPAGATION, true);
   828         OS.QWidget_setAttribute(handle, OS.QT_WA_NOMOUSEPROPAGATION, true);
   819     }
   829     }
   820 }
   830 }
   821 
   831 
   822 void flushBuffers() {
   832 void flushBuffers(Object target) {
   823     if (bufferedGcs != null) {
   833     if (bufferedGcs != null) {
   824         for (int i = 0; i < bufferedGcs.size(); i++) {
   834         for (int i = 0; i < bufferedGcs.size(); i++) {
   825             GraphicsContext igc = (GraphicsContext)bufferedGcs.elementAt(i);
   835             GraphicsContext igc = (GraphicsContext)bufferedGcs.elementAt(i);
   826             NativeCommandBuffer buf = (NativeCommandBuffer)gcBuffers.elementAt(i);
   836             NativeCommandBuffer buf = (NativeCommandBuffer)gcBuffers.elementAt(i);
   827             igc.releaseTarget();
   837             igc.releaseTarget();
   828             igc.bindTarget(this);
   838             if(target instanceof WindowSurface) {
       
   839             	igc.bindTarget((WindowSurface)target);
       
   840             } else {
       
   841             	igc.bindTarget(this);
       
   842             }
   829             igc.render(buf);
   843             igc.render(buf);
   830             igc.releaseTarget();
   844             igc.releaseTarget();
   831             igc.bindTarget(buf, this);
   845             igc.bindTarget(buf, this);
   832         }
   846         }
   833     }
   847     }
  2051     if (widgetHandle != handle) {
  2065     if (widgetHandle != handle) {
  2052         return;
  2066         return;
  2053     }
  2067     }
  2054 
  2068 
  2055     // Render the buffers created outside the paint event, if any
  2069     // Render the buffers created outside the paint event, if any
  2056     flushBuffers();
  2070     flushBuffers(this);
  2057 
  2071 
  2058     // If this is only a buffer flush event then stop here
  2072     // If this is only a buffer flush event then stop here
  2059     if(bufferFlush) {
  2073     if(bufferFlush) {
  2060         bufferFlush = false;
  2074         bufferFlush = false;
  2061         return;
  2075         return;
  3255         if (isDisposed ()) return;
  3269         if (isDisposed ()) return;
  3256     }
  3270     }
  3257     if (fixFocus) fixFocus (control);
  3271     if (fixFocus) fixFocus (control);
  3258 }
  3272 }
  3259 
  3273 
       
  3274 /*
       
  3275  * Starts external access to the window behind this control, 
       
  3276  * by opening surface session and flushing any pending GC originated
       
  3277  * rendering to the window.
       
  3278  * 
       
  3279  * @param clip The invalid area to be converted to window coordinates
       
  3280  * @return the area to be painted in window coordinates
       
  3281  */
       
  3282 Rectangle startWindowSurfaceSession(Rectangle clip) {
       
  3283 	checkWidget();
       
  3284 	if (clip == null)
       
  3285         error(SWT.ERROR_NULL_ARGUMENT);
       
  3286 
       
  3287 	Shell s = getShell();
       
  3288     if(windowSurface == null) {
       
  3289         windowSurface = s.getWindowSurface();
       
  3290         if(windowSurface == null) {
       
  3291         	error(SWT.ERROR_NULL_ARGUMENT);
       
  3292         }
       
  3293     }
       
  3294     // this is supported only with children of Scrollable, 
       
  3295     // i.e. Canvas, Shell
       
  3296     if(this instanceof Scrollable) {
       
  3297         Rectangle caInWinCoords = toWindowSurface(((Scrollable)this).getClientArea());
       
  3298         windowSurface.beginPaint(caInWinCoords.x, caInWinCoords.y, caInWinCoords.width, caInWinCoords.height);
       
  3299         flushBuffers(windowSurface);
       
  3300         return toWindowSurface(clip);
       
  3301     } else {
       
  3302     	error(SWT.ERROR_NOT_IMPLEMENTED);
       
  3303     }
       
  3304     return null;
       
  3305 }
       
  3306 
  3260 /**
  3307 /**
  3261  * Returns a point which is the result of converting the argument, which is
  3308  * Returns a point which is the result of converting the argument, which is
  3262  * specified in display relative coordinates, to coordinates relative to the
  3309  * specified in display relative coordinates, to coordinates relative to the
  3263  * receiver.
  3310  * receiver.
  3264  * <p>
  3311  * <p>
  3368 public Point toDisplay(Point point) {
  3415 public Point toDisplay(Point point) {
  3369     checkWidget();
  3416     checkWidget();
  3370     if (point == null)
  3417     if (point == null)
  3371         error(SWT.ERROR_NULL_ARGUMENT);
  3418         error(SWT.ERROR_NULL_ARGUMENT);
  3372     return toDisplay(point.x, point.y);
  3419     return toDisplay(point.x, point.y);
       
  3420 }
       
  3421 
       
  3422 /*
       
  3423  * Converts given rectangle form the (this) Control coordinates 
       
  3424  * to window surface coordinates.
       
  3425  * 
       
  3426  * @param rect The rectangle to be converted, given in the coordinates of this Control 
       
  3427  */
       
  3428 Rectangle toWindowSurface(Rectangle rect) {
       
  3429 	// The window surface is the size of the client area of a shell.
       
  3430 	Shell s = getShell();
       
  3431 	Point wTopLeft = s.toControl(toDisplay(rect.x, rect.y));
       
  3432 	Point wBottomRight = s.toControl(toDisplay(rect.x+rect.width, rect.y+rect.height));
       
  3433 	
       
  3434     // trim for possible shell border
       
  3435     if ((getStyle() & SWT.BORDER) != 0){
       
  3436     	final int frameOffset = getBorderWidth();
       
  3437     	wTopLeft.x = wTopLeft.x + frameOffset; 
       
  3438         wTopLeft.y = wTopLeft.y + frameOffset; 
       
  3439     }
       
  3440     return new Rectangle(wTopLeft.x, wTopLeft.y, wBottomRight.x-wTopLeft.x, wBottomRight.y-wTopLeft.y);
  3373 }
  3441 }
  3374 
  3442 
  3375 /**
  3443 /**
  3376  * Based on the argument, perform one of the expected platform traversal action.
  3444  * Based on the argument, perform one of the expected platform traversal action.
  3377  * The argument should be one of the constants: <code>SWT.TRAVERSE_ESCAPE</code>
  3445  * The argument should be one of the constants: <code>SWT.TRAVERSE_ESCAPE</code>