Show
Ignore:
Timestamp:
05/17/08 11:34:28 (8 months ago)
Author:
Frank Benoit <benoit@tionex.de>
branch:
default
Message:

Update to SWT 3.4M7

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • dwt/graphics/GC.d

    r212 r213  
    7474public final class GC : Resource { 
    7575 
     76    alias Resource.init_ init_; 
     77 
    7678    /** 
    7779     * the handle to the OS device context 
     
    182184    this.device = data.device = device; 
    183185    init_ (drawable, data, hDC); 
    184     if (device.tracking) device.new_Object(this); 
     186    init_(); 
    185187} 
    186188 
     
    264266            } 
    265267            if (dashes !is null) { 
    266                 Gdip.Pen_SetDashPattern(pen, dashes, dashes.length); 
     268                Gdip.Pen_SetDashPattern(pen, dashes.ptr, dashes.length); 
    267269                Gdip.Pen_SetDashStyle(pen, Gdip.DashStyleCustom); 
    268270                Gdip.Pen_SetDashOffset(pen, dashOffset); 
     
    324326        } 
    325327        if ((state & FONT) !is 0) { 
    326             OS.SelectObject(handle, data.hFont); 
    327             auto font = createGdipFont(handle, data.hFont); 
     328            Font font = data.font; 
     329            OS.SelectObject(handle, font.handle); 
     330            auto gdipFont = createGdipFont(handle, font.handle); 
    328331            if (data.gdipFont !is null) Gdip.Font_delete(data.gdipFont); 
    329             data.gdipFont = font; 
     332            data.gdipFont = gdipFont; 
    330333        } 
    331334        if ((state & DRAW_OFFSET) !is 0) { 
    332335            data.gdipXOffset = data.gdipYOffset = 0; 
    333336            auto matrix = Gdip.Matrix_new(1, 0, 0, 1, 0, 0); 
    334             float[6] elements
     337            float[2] point; point[0]=1.0; point[1]=1.0
    335338            Gdip.Graphics_GetTransform(gdipGraphics, matrix); 
    336             Gdip.Matrix_GetElements(matrix, elements ); 
     339            Gdip.Matrix_TransformPoints(matrix, cast(Gdip.PointF*)point.ptr, 1); 
    337340            Gdip.Matrix_delete(matrix); 
    338             float scaling = elements[0]; 
     341            float scaling = point[0]; 
    339342            if (scaling < 0) scaling = -scaling; 
    340343            float penWidth = data.lineWidth * scaling; 
     
    342345                data.gdipXOffset = 0.5f / scaling; 
    343346            } 
    344             scaling = elements[3]; 
     347            scaling = point[1]; 
    345348            if (scaling < 0) scaling = -scaling; 
    346349            penWidth = data.lineWidth * scaling; 
     
    440443    } 
    441444    if ((state & FONT) !is 0) { 
    442         OS.SelectObject(handle, data.hFont); 
     445        Font font = data.font; 
     446        OS.SelectObject(handle, font.handle); 
    443447    } 
    444448} 
     
    628632 * </ul> 
    629633 */ 
    630 override public void dispose() { 
    631     if (handle is null) return; 
    632     if (data.device.isDisposed()) return; 
    633  
     634void destroy() { 
     635    bool gdip = data.gdipGraphics !is null; 
    634636    disposeGdip(); 
     637    if (gdip && (data.style & DWT.MIRRORED) !is 0) { 
     638        OS.SetLayout(handle, OS.GetLayout(handle) | OS.LAYOUT_RTL); 
     639    } 
    635640 
    636641    /* Select stock pen and brush objects and free resources */ 
     
    662667    * Dispose the HDC. 
    663668    */ 
    664     Device device = data.device; 
    665669    if (drawable !is null) drawable.internal_dispose_GC(handle, data); 
    666670    drawable = null; 
     
    668672    data.image = null; 
    669673    data.ps = null; 
    670     if (device.tracking) device.dispose_Object(this); 
    671     data.device = null; 
    672674    data = null; 
    673675} 
     
    817819    if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); 
    818820    if ((data.uiState & OS.UISF_HIDEFOCUS) !is 0) return; 
     821    data.focusDrawn = true; 
    819822    HDC hdc = handle; 
    820823    int state = 0; 
     
    838841        if (!Gdip.Matrix_IsIdentity(matrix)) { 
    839842            gotElements = true; 
    840             Gdip.Matrix_GetElements(matrix, lpXform); 
     843            Gdip.Matrix_GetElements(matrix, lpXform.ptr); 
    841844        } 
    842845        Gdip.Matrix_delete(matrix); 
    843846        hdc = Gdip.Graphics_GetHDC(gdipGraphics); 
    844847        state = OS.SaveDC(hdc); 
    845         OS.SetBkColor(hdc, data.background); 
    846         OS.SetTextColor(hdc, data.foreground); 
    847848        if (gotElements) { 
    848849            OS.SetGraphicsMode(hdc, OS.GM_ADVANCED); 
     
    854855        } 
    855856    } 
     857    OS.SetBkColor(hdc, 0xFFFFFF); 
     858    OS.SetTextColor(hdc, 0x000000); 
    856859    RECT rect; 
    857860    OS.SetRect(&rect, x, y, x + width, y + height); 
     
    860863        OS.RestoreDC(hdc, state); 
    861864        Gdip.Graphics_ReleaseHDC(gdipGraphics, hdc); 
     865    } else { 
     866        data.state &= ~(BACKGROUND_TEXT | FOREGROUND_TEXT); 
    862867    } 
    863868} 
     
    935940    if (data.gdipGraphics !is null) { 
    936941        //TODO - cache bitmap 
    937         int[] gdipImage = srcImage.createGdipImage(); 
     942        int /*long*/ [] gdipImage = srcImage.createGdipImage(); 
    938943        auto img = cast(Gdip.Image) gdipImage[0]; 
    939944        int imgWidth = Gdip.Image_GetWidth(img); 
     
    14271432    auto srcHdc = OS.CreateCompatibleDC(handle); 
    14281433    auto oldSrcBitmap = OS.SelectObject(srcHdc, srcColor); 
    1429     auto destHdc = handle, x = destX, y = destY; 
     1434    auto destHdc = handle; 
     1435    int x = destX, y = destY; 
    14301436    HDC tempHdc; 
    14311437    HBITMAP tempBitmap; 
     
    18071813    if (gdipGraphics !is null) { 
    18081814        Gdip.Graphics_TranslateTransform(gdipGraphics, data.gdipXOffset, data.gdipYOffset, Gdip.MatrixOrderPrepend); 
    1809         Gdip.Graphics_DrawPolygon(gdipGraphics, data.gdipPen, cast(Gdip.Point[])pointArray, pointArray.length/2); 
     1815        Gdip.Graphics_DrawPolygon(gdipGraphics, data.gdipPen, cast(Gdip.Point*)pointArray.ptr, pointArray.length/2); 
    18101816        Gdip.Graphics_TranslateTransform(gdipGraphics, -data.gdipXOffset, -data.gdipYOffset, Gdip.MatrixOrderPrepend); 
    18111817        return; 
     
    18521858    if (gdipGraphics !is null) { 
    18531859        Gdip.Graphics_TranslateTransform(gdipGraphics, data.gdipXOffset, data.gdipYOffset, Gdip.MatrixOrderPrepend); 
    1854         Gdip.Graphics_DrawLines(gdipGraphics, data.gdipPen, cast(Gdip.Point[])pointArray, pointArray.length / 2); 
     1860        Gdip.Graphics_DrawLines(gdipGraphics, data.gdipPen, cast(Gdip.Point*)pointArray.ptr, pointArray.length / 2); 
    18551861        Gdip.Graphics_TranslateTransform(gdipGraphics, -data.gdipXOffset, -data.gdipYOffset, Gdip.MatrixOrderPrepend); 
    18561862        return; 
     
    18991905    auto gdipGraphics = data.gdipGraphics; 
    19001906    if (gdipGraphics !is null) { 
     1907        if (width < 0) { 
     1908            x = x + width; 
     1909            width = -width; 
     1910        } 
     1911        if (height < 0) { 
     1912            y = y + height; 
     1913            height = -height; 
     1914        } 
    19011915        Gdip.Graphics_TranslateTransform(gdipGraphics, data.gdipXOffset, data.gdipYOffset, Gdip.MatrixOrderPrepend); 
    19021916        Gdip.Graphics_DrawRectangle(gdipGraphics, data.gdipPen, x, y, width, height); 
     
    20372051 
    20382052    Gdip.Graphics_TranslateTransform(gdipGraphics, data.gdipXOffset, data.gdipYOffset, Gdip.MatrixOrderPrepend); 
    2039     auto path = Gdip.GraphicsPath_new(Gdip.FillModeAlternate); 
    2040     if (path is null) DWT.error(DWT.ERROR_NO_HANDLES); 
    2041     if (nw > naw) { 
    2042         if (nh > nah) { 
    2043             Gdip.GraphicsPath_AddArc(path, nx + nw - naw, ny, naw, nah, 0, -90); 
    2044             Gdip.GraphicsPath_AddArc(path, nx, ny, naw, nah, -90, -90); 
    2045             Gdip.GraphicsPath_AddArc(path, nx, ny + nh - nah, naw, nah, -180, -90); 
    2046             Gdip.GraphicsPath_AddArc(path, nx + nw - naw, ny + nh - nah, naw, nah, -270, -90); 
     2053    if (naw is 0 || nah is 0) { 
     2054        Gdip.Graphics_DrawRectangle(gdipGraphics, data.gdipPen, x, y, width, height); 
     2055    } else { 
     2056        auto path = Gdip.GraphicsPath_new(Gdip.FillModeAlternate); 
     2057        if (path is null) DWT.error(DWT.ERROR_NO_HANDLES); 
     2058        if (nw > naw) { 
     2059            if (nh > nah) { 
     2060                Gdip.GraphicsPath_AddArc(path, nx + nw - naw, ny, naw, nah, 0, -90); 
     2061                Gdip.GraphicsPath_AddArc(path, nx, ny, naw, nah, -90, -90); 
     2062                Gdip.GraphicsPath_AddArc(path, nx, ny + nh - nah, naw, nah, -180, -90); 
     2063                Gdip.GraphicsPath_AddArc(path, nx + nw - naw, ny + nh - nah, naw, nah, -270, -90); 
     2064            } else { 
     2065                Gdip.GraphicsPath_AddArc(path, nx + nw - naw, ny, naw, nh, -270, -180); 
     2066                Gdip.GraphicsPath_AddArc(path, nx, ny, naw, nh, -90, -180); 
     2067            } 
    20472068        } else { 
    2048             Gdip.GraphicsPath_AddArc(path, nx + nw - naw, ny, naw, nh, -270, -180); 
    2049             Gdip.GraphicsPath_AddArc(path, nx, ny, naw, nh, -90, -180); 
    2050         } 
    2051     } else { 
    2052         if (nh > nah) { 
    2053             Gdip.GraphicsPath_AddArc(path, nx, ny, nw, nah, 0, -180); 
    2054             Gdip.GraphicsPath_AddArc(path, nx, ny + nh - nah, nw, nah, -180, -180); 
    2055         } else { 
    2056             Gdip.GraphicsPath_AddArc(path, nx, ny, nw, nh, 0, 360); 
    2057         } 
    2058     } 
    2059     Gdip.GraphicsPath_CloseFigure(path); 
    2060     Gdip.Graphics_DrawPath(gdipGraphics, pen, path); 
    2061     Gdip.GraphicsPath_delete(path); 
     2069            if (nh > nah) { 
     2070                Gdip.GraphicsPath_AddArc(path, nx, ny, nw, nah, 0, -180); 
     2071                Gdip.GraphicsPath_AddArc(path, nx, ny + nh - nah, nw, nah, -180, -180); 
     2072            } else { 
     2073                Gdip.GraphicsPath_AddArc(path, nx, ny, nw, nh, 0, 360); 
     2074            } 
     2075        } 
     2076        Gdip.GraphicsPath_CloseFigure(path); 
     2077        Gdip.Graphics_DrawPath(gdipGraphics, pen, path); 
     2078        Gdip.GraphicsPath_delete(path); 
     2079    } 
    20622080    Gdip.Graphics_TranslateTransform(gdipGraphics, -data.gdipXOffset, -data.gdipYOffset, Gdip.MatrixOrderPrepend); 
    20632081} 
     
    23172335        Gdip.StringFormat_SetFormatFlags(format, formatFlags); 
    23182336        float[] tabs = (flags & DWT.DRAW_TAB) !is 0 ? [ cast(float) measureSpace(data.gdipFont, format) * 8] : new float[1]; 
    2319         Gdip.StringFormat_SetTabStops(format, 0, tabs.length, tabs); 
     2337        Gdip.StringFormat_SetTabStops(format, 0, tabs.length, tabs.ptr); 
    23202338        int hotkeyPrefix = (flags & DWT.DRAW_MNEMONIC) !is 0 ? Gdip.HotkeyPrefixShow : Gdip.HotkeyPrefixNone; 
    23212339        if ((flags & DWT.DRAW_MNEMONIC) !is 0 && (data.uiState & OS.UISF_HIDEACCEL) !is 0) hotkeyPrefix = Gdip.HotkeyPrefixHide; 
     
    27692787    if (data.gdipGraphics !is null) { 
    27702788        int mode = OS.GetPolyFillMode(handle) is OS.WINDING ? Gdip.FillModeWinding : Gdip.FillModeAlternate; 
    2771         Gdip.Graphics_FillPolygon(data.gdipGraphics, data.gdipBrush, cast(Gdip.Point[])pointArray, pointArray.length / 2, mode); 
     2789        Gdip.Graphics_FillPolygon(data.gdipGraphics, data.gdipBrush, cast(Gdip.Point*)pointArray.ptr, pointArray.length / 2, mode); 
    27722790        return; 
    27732791    } 
     
    28042822    checkGC(FILL); 
    28052823    if (data.gdipGraphics !is null) { 
     2824        if (width < 0) { 
     2825            x = x + width; 
     2826            width = -width; 
     2827        } 
     2828        if (height < 0) { 
     2829            y = y + height; 
     2830            height = -height; 
     2831        } 
    28062832        Gdip.Graphics_FillRectangle(data.gdipGraphics, data.gdipBrush, x, y, width, height); 
    28072833        return; 
     
    28872913        nah = 0 - nah; 
    28882914 
    2889     auto path = Gdip.GraphicsPath_new(Gdip.FillModeAlternate); 
    2890     if (path is null) DWT.error(DWT.ERROR_NO_HANDLES); 
    2891     if (nw > naw) { 
    2892         if (nh > nah) { 
    2893             Gdip.GraphicsPath_AddArc(path, nx + nw - naw, ny, naw, nah, 0, -90); 
    2894             Gdip.GraphicsPath_AddArc(path, nx, ny, naw, nah, -90, -90); 
    2895             Gdip.GraphicsPath_AddArc(path, nx, ny + nh - nah, naw, nah, -180, -90); 
    2896             Gdip.GraphicsPath_AddArc(path, nx + nw - naw, ny + nh - nah, naw, nah, -270, -90); 
     2915    if (naw is 0 || nah is 0) { 
     2916        Gdip.Graphics_FillRectangle(data.gdipGraphics, data.gdipBrush, x, y, width, height); 
     2917    } else { 
     2918        auto path = Gdip.GraphicsPath_new(Gdip.FillModeAlternate); 
     2919        if (path is null) DWT.error(DWT.ERROR_NO_HANDLES); 
     2920        if (nw > naw) { 
     2921            if (nh > nah) { 
     2922                Gdip.GraphicsPath_AddArc(path, nx + nw - naw, ny, naw, nah, 0, -90); 
     2923                Gdip.GraphicsPath_AddArc(path, nx, ny, naw, nah, -90, -90); 
     2924                Gdip.GraphicsPath_AddArc(path, nx, ny + nh - nah, naw, nah, -180, -90); 
     2925                Gdip.GraphicsPath_AddArc(path, nx + nw - naw, ny + nh - nah, naw, nah, -270, -90); 
     2926            } else { 
     2927                Gdip.GraphicsPath_AddArc(path, nx + nw - naw, ny, naw, nh, -270, -180); 
     2928                Gdip.GraphicsPath_AddArc(path, nx, ny, naw, nh, -90, -180); 
     2929            } 
    28972930        } else { 
    2898             Gdip.GraphicsPath_AddArc(path, nx + nw - naw, ny, naw, nh, -270, -180); 
    2899             Gdip.GraphicsPath_AddArc(path, nx, ny, naw, nh, -90, -180); 
    2900         } 
    2901     } else { 
    2902         if (nh > nah) { 
    2903             Gdip.GraphicsPath_AddArc(path, nx, ny, nw, nah, 0, -180); 
    2904             Gdip.GraphicsPath_AddArc(path, nx, ny + nh - nah, nw, nah, -180, -180); 
    2905         } else { 
    2906             Gdip.GraphicsPath_AddArc(path, nx, ny, nw, nh, 0, 360); 
    2907         } 
    2908     } 
    2909     Gdip.GraphicsPath_CloseFigure(path); 
    2910     Gdip.Graphics_FillPath(gdipGraphics, brush, path); 
    2911     Gdip.GraphicsPath_delete(path); 
     2931            if (nh > nah) { 
     2932                Gdip.GraphicsPath_AddArc(path, nx, ny, nw, nah, 0, -180); 
     2933                Gdip.GraphicsPath_AddArc(path, nx, ny + nh - nah, nw, nah, -180, -180); 
     2934            } else { 
     2935                Gdip.GraphicsPath_AddArc(path, nx, ny, nw, nh, 0, 360); 
     2936            } 
     2937        } 
     2938        Gdip.GraphicsPath_CloseFigure(path); 
     2939        Gdip.Graphics_FillPath(gdipGraphics, brush, path); 
     2940        Gdip.GraphicsPath_delete(path); 
     2941    } 
    29122942} 
    29132943 
     
    32703300public Font getFont () { 
    32713301    if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); 
    3272     return Font.win32_new(data.device, data.hFont)
     3302    return data.font
    32733303} 
    32743304 
     
    36673697    if ((data.style & DWT.MIRRORED) !is 0) { 
    36683698        int width = 0; 
    3669         Image image = data.image; 
    3670         if (image !is null) { 
     3699        int technology = OS.GetDeviceCaps(handle, OS.TECHNOLOGY); 
     3700        if (technology is OS.DT_RASPRINTER) { 
     3701            width = OS.GetDeviceCaps(handle, OS.PHYSICALWIDTH); 
     3702        } else { 
     3703            Image image = data.image; 
     3704            if (image !is null) { 
    36713705            BITMAP bm; 
    36723706            OS.GetObject(image.handle, BITMAP.sizeof, &bm); 
    3673             width = bm.bmWidth; 
    3674         } else if (data.hwnd !is null) { 
    3675             RECT rect; 
    3676             OS.GetClientRect(data.hwnd, &rect); 
    3677             width = rect.right - rect.left; 
     3707                width = bm.bmWidth; 
     3708            } else { 
     3709                HWND hwnd; 
     3710                static if( OS.IsWinCE ){ 
     3711                    hwnd = data.hwnd; 
     3712                } 
     3713                else{ 
     3714                    hwnd = OS.WindowFromDC(handle); 
     3715                } 
     3716                if (hwnd !is null) { 
     3717                    RECT rect; 
     3718                    OS.GetClientRect(hwnd, &rect); 
     3719                    width = rect.right - rect.left; 
     3720                } else { 
     3721                    auto hBitmap = OS.GetCurrentObject(handle, OS.OBJ_BITMAP); 
     3722                    BITMAP bm; 
     3723                    OS.GetObject(hBitmap, BITMAP.sizeof, &bm); 
     3724                    width = bm.bmWidth; 
     3725                } 
     3726            } 
    36783727        } 
    36793728        POINT pt; 
     
    36983747    } 
    36993748    data.state &= ~(NULL_BRUSH | NULL_PEN); 
    3700     auto hFont = data.hFont; 
    3701     if (hFont !is null && hFont !is cast(HFONT)-1 ) { 
     3749    Font font = data.font; 
     3750    if (font !is null) { 
    37023751        data.state &= ~FONT; 
    37033752    } else { 
    3704         data.hFont = OS.GetCurrentObject(hDC, OS.OBJ_FONT); 
     3753        data.font = Font.win32_new(device, OS.GetCurrentObject(hDC, OS.OBJ_FONT)); 
    37053754    } 
    37063755    auto hPalette = data.device.hPalette; 
     
    37643813public bool isClipped() { 
    37653814    if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); 
     3815    auto gdipGraphics = data.gdipGraphics; 
     3816    if (gdipGraphics !is null) { 
     3817        auto rgn = Gdip.Region_new(); 
     3818        Gdip.Graphics_GetClip(data.gdipGraphics, rgn); 
     3819        bool isInfinite = Gdip.Region_IsInfinite(rgn, gdipGraphics) !is 0; 
     3820        Gdip.Region_delete(rgn); 
     3821        return !isInfinite; 
     3822    } 
    37663823    auto region = OS.CreateRectRgn(0, 0, 0, 0); 
    3767     auto result = OS.GetClipRgn(handle, region); 
     3824    int result = OS.GetClipRgn(handle, region); 
    37683825    OS.DeleteObject(region); 
    37693826    return result > 0; 
     
    40694126        int mode = OS.GetPolyFillMode(handle) is OS.WINDING ? Gdip.FillModeWinding : Gdip.FillModeAlternate; 
    40704127        Gdip.GraphicsPath_SetFillMode(path.handle, mode); 
    4071         Gdip.Graphics_SetClip(data.gdipGraphics, path.handle); 
     4128        Gdip.Graphics_SetClipPath(data.gdipGraphics, path.handle); 
    40724129    } 
    40734130} 
     
    41644221    if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); 
    41654222    if (font !is null && font.isDisposed()) DWT.error(DWT.ERROR_INVALID_ARGUMENT); 
    4166     data.hFont = font !is null ? font.handle : data.device.systemFont; 
     4223    data.font = font !is null ? font : data.device.systemFont; 
    41674224    data.state &= ~FONT; 
    41684225} 
     
    43284385        } 
    43294386    } 
    4330     int cap = attributes.join
     4387    int cap = attributes.cap
    43314388    if (cap !is data.lineCap) { 
    43324389        mask |= LINE_CAP; 
     
    48014858        Gdip.StringFormat_SetFormatFlags(format, formatFlags); 
    48024859        float[] tabs = (flags & DWT.DRAW_TAB) !is 0 ? [measureSpace(data.gdipFont, format) * 8] : new float[1]; 
    4803         Gdip.StringFormat_SetTabStops(format, 0, tabs.length, tabs); 
     4860        Gdip.StringFormat_SetTabStops(format, 0, tabs.length, tabs.ptr); 
    48044861        Gdip.StringFormat_SetHotkeyPrefix(format, (flags & DWT.DRAW_MNEMONIC) !is 0 ? Gdip.HotkeyPrefixShow : Gdip.HotkeyPrefixNone); 
    48054862        Gdip.Graphics_MeasureString(data.gdipGraphics, buffer, length_, data.gdipFont, pt, format, bounds); 
     
    48774934    GC gc = new GC(); 
    48784935    gc.device = data.device; 
     4936    data.style |= DWT.LEFT_TO_RIGHT; 
     4937    if (OS.WIN32_VERSION >= OS.VERSION (4, 10)) { 
     4938        int flags = OS.GetLayout (hDC); 
     4939        if ((flags & OS.LAYOUT_RTL) !is 0) { 
     4940            data.style |= DWT.RIGHT_TO_LEFT | DWT.MIRRORED; 
     4941        } 
     4942    } 
    48794943    gc.init_(null, data, hDC); 
    48804944    return gc;