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/Image.d

    r212 r213  
    8989public final class Image : Resource, Drawable { 
    9090 
     91    alias Resource.init_ init_; 
     92 
    9193    /** 
    9294     * specifies whether the receiver is a bitmap or an icon 
     
    157159 * Prevents uninitialized instances from being created outside the package. 
    158160 */ 
    159 this () { 
     161this (Device device) { 
     162    super(device); 
    160163} 
    161164 
     
    191194 */ 
    192195public this(Device device, int width, int height) { 
    193     if (device is null) device = Device.getDevice(); 
    194     if (device is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 
    195     init_(device, width, height); 
    196     if (device.tracking) device.new_Object(this); 
     196    super(device); 
     197    init_(width, height); 
     198    init_(); 
    197199} 
    198200 
     
    229231 */ 
    230232public this(Device device, Image srcImage, int flag) { 
    231     if (device is null) device = Device.getDevice(); 
    232     if (device is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 
    233     this.device = device; 
     233    super(device); 
     234    device = this.device; 
    234235    if (srcImage is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 
    235236    if (srcImage.isDisposed()) DWT.error(DWT.ERROR_INVALID_ARGUMENT); 
    236237    Rectangle rect = srcImage.getBounds(); 
     238    this.type = srcImage.type; 
    237239    switch (flag) { 
    238240        case DWT.IMAGE_COPY: { 
    239             this.type = srcImage.type; 
    240241            switch (type) { 
    241242                case DWT.BITMAP: 
     
    270271                case DWT.ICON: 
    271272                    static if (OS.IsWinCE) { 
    272                         init_(device, srcImage.data); 
     273                        init_(srcImage.data); 
    273274                    } else { 
    274275                        handle = OS.CopyImage(srcImage.handle, OS.IMAGE_ICON, rect.width, rect.height, 0); 
     
    279280                    DWT.error(DWT.ERROR_INVALID_IMAGE); 
    280281            } 
    281             if (device.tracking) device.new_Object(this); 
    282             return; 
     282            break; 
    283283        } 
    284284        case DWT.IMAGE_DISABLE: { 
     
    338338                } 
    339339            } 
    340             init_ (device, newData); 
    341             if (device.tracking) device.new_Object(this); 
    342             return; 
     340            init_ (newData); 
     341            break; 
    343342        } 
    344343        case DWT.IMAGE_GRAY: { 
     
    403402                } 
    404403            } 
    405             init_ (device, newData); 
    406             if (device.tracking) device.new_Object(this); 
    407             return; 
     404            init_ (newData); 
     405            break; 
    408406        } 
    409407        default: 
    410408            DWT.error(DWT.ERROR_INVALID_ARGUMENT); 
    411409    } 
     410    init_(); 
    412411} 
    413412 
     
    443442 */ 
    444443public this(Device device, Rectangle bounds) { 
    445     if (device is null) device = Device.getDevice(); 
    446     if (device is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 
     444    super(device); 
    447445    if (bounds is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 
    448     init_(device, bounds.width, bounds.height); 
    449     if (device.tracking) device.new_Object(this); 
     446    init_(bounds.width, bounds.height); 
     447    init_(); 
    450448} 
    451449 
     
    469467 */ 
    470468public this(Device device, ImageData data) { 
    471     if (device is null) device = Device.getDevice(); 
    472     if (device is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 
    473     init_(device, data); 
    474     if (device.tracking) device.new_Object(this); 
     469    super(device); 
     470    init_(data); 
     471    init_(); 
    475472} 
    476473 
     
    501498 */ 
    502499public this(Device device, ImageData source, ImageData mask) { 
    503     if (device is null) device = Device.getDevice(); 
    504     if (device is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 
     500    super(device); 
    505501    if (source is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 
    506502    if (mask is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 
     
    509505    } 
    510506    mask = ImageData.convertMask(mask); 
    511     init_(device, this, source, mask); 
    512     if (device.tracking) device.new_Object(this); 
     507    init_(this.device, this, source, mask); 
     508    init_(); 
    513509} 
    514510 
     
    562558 */ 
    563559public this (Device device, InputStream stream) { 
    564     if (device is null) device = Device.getDevice(); 
    565     if (device is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 
    566     init_(device, new ImageData(stream)); 
    567     if (device.tracking) device.new_Object(this); 
     560    super(device); 
     561    init_(new ImageData(stream)); 
     562    init_(); 
    568563} 
    569564 
     
    596591 */ 
    597592public this (Device device, String filename) { 
    598     if (device is null) device = Device.getDevice(); 
    599     if (device is null) DWT.error(DWT.ERROR_NULL_ARGUMENT)
     593    super(device); 
     594    device = this.device
    600595    if (filename is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 
    601     this.device = device; 
     596    bool gdip = true; 
    602597    try { 
    603598        device.checkGDIP(); 
     599    } catch (DWTException e) { 
     600        gdip = false; 
     601    } 
     602    /* 
     603    * Bug in GDI+.  For some reason, Bitmap.LockBits() segment faults 
     604    * when loading GIF files in 64-bit Windows.  The fix is to not use 
     605    * GDI+ image loading in this case. 
     606    */ 
     607    if (gdip && (void*).sizeof is 8 && filename.toLowerCase().endsWith(".gif")) gdip = false; 
     608    if (gdip) { 
    604609        int length = filename.length; 
    605610        char[] chars = new char[length+1]; 
     
    742747                                img.transparentPixel = transparentPixel; 
    743748                                img.alphaData = alphaData; 
    744                                 init_(device, img); 
     749                                init_(img); 
    745750                            } 
    746751                        } 
     
    754759            } 
    755760        } 
    756     } catch (DWTException e) {} 
    757     init_(device, new ImageData(filename)); 
    758     if(device.tracking) device.new_Object(this); 
     761    } 
     762    init_(new ImageData(filename)); 
     763    init_(); 
    759764} 
    760765 
     
    854859        } 
    855860    } 
    856     int pBits; 
     861    void* pBits; 
    857862    HBITMAP hDib = OS.CreateDIBSection(null, cast(BITMAPINFO*)bmi.ptr, OS.DIB_RGB_COLORS, &pBits, null, 0); 
    858863    if (hDib is null) DWT.error(DWT.ERROR_NO_HANDLES); 
     
    878883// function has them stored in the int array. 
    879884 
    880 int[] createGdipImage() { 
     885int /*long*/ [] createGdipImage() { 
    881886    switch (type) { 
    882887        case DWT.BITMAP: { 
     
    9971002            Gdip.Bitmap img; 
    9981003            ubyte* pixels; 
    999             if (imgWidth > imgHeight) { 
     1004            /* 
     1005            * Bug in GDI+.  Bitmap_new() segments fault if the image width 
     1006            * is greater than the image height. 
     1007            * 
     1008            * Note that it also fails to generated an appropriate alpha 
     1009            * channel when the icon depth is 32. 
     1010            */ 
     1011            if (imgWidth > imgHeight || bm.bmBitsPixel is 32) { 
    10001012                auto hDC = device.internal_new_GC(null); 
    10011013                auto srcHdc = OS.CreateCompatibleDC(hDC); 
     
    10141026                OS.DeleteObject(memDib); 
    10151027                OS.SelectObject(srcHdc, iconInfo.hbmMask); 
    1016                 for (int y = 0, dp = 0; y < imgHeight; ++y) { 
     1028                for (int y = 0, dp = 3; y < imgHeight; ++y) { 
    10171029                    for (int x = 0; x < imgWidth; ++x) { 
    1018                         if (OS.GetPixel(srcHdc, x, y) !is 0) { 
    1019                             srcData[dp + 3] = cast(ubyte)0; 
    1020                         } else { 
    1021                             srcData[dp + 3] = cast(ubyte)0xFF; 
     1030                        if (srcData[dp] is 0) { 
     1031                            if (OS.GetPixel(srcHdc, x, y) !is 0) { 
     1032                            srcData[dp] = cast(ubyte)0; 
     1033                            } else { 
     1034                            srcData[dp] = cast(ubyte)0xFF; 
     1035                            } 
    10221036                        } 
    10231037                        dp += 4; 
     
    10441058} 
    10451059 
    1046 /** 
    1047  * Disposes of the operating system resources associated with 
    1048  * the image. Applications must dispose of all images which 
    1049  * they allocate. 
    1050  */ 
    1051 override public void dispose () { 
    1052     if (handle is null) return; 
    1053     if (device.isDisposed()) return; 
     1060void destroy () { 
    10541061    if (memGC !is null) memGC.dispose(); 
    10551062    if (type is DWT.ICON) { 
     
    10611068    handle = null; 
    10621069    memGC = null; 
    1063     if (device.tracking) device.dispose_Object(this); 
    1064     device = null; 
    10651070} 
    10661071 
     
    15801585} 
    15811586 
    1582 void init_(Device device, int width, int height) { 
     1587void init_(int width, int height) { 
    15831588    if (width <= 0 || height <= 0) { 
    15841589        DWT.error (DWT.ERROR_INVALID_ARGUMENT); 
    15851590    } 
    1586     this.device = device; 
    15871591    type = DWT.BITMAP; 
    15881592    auto hDC = device.internal_new_GC(null); 
     
    16451649    } 
    16461650 
    1647     int[1] pBits; 
    1648     return OS.CreateDIBSection(null, cast(BITMAPINFO*)bmi.ptr, OS.DIB_RGB_COLORS, pBits.ptr, null, 0); 
     1651    void* pBits; 
     1652    return OS.CreateDIBSection(null, cast(BITMAPINFO*)bmi.ptr, OS.DIB_RGB_COLORS, &pBits, null, 0); 
    16491653} 
    16501654 
     
    16671671 
    16681672static int[] init_(Device device, Image image, ImageData i) { 
    1669     if (image !is null) image.device = device; 
    16701673 
    16711674    /* 
     
    18341837    OS.MoveMemory(pBits, data.ptr, data.length); 
    18351838 
    1836     int[] result = null; 
     1839    int /*long*/ [] result = null; 
    18371840    if (i.getTransparencyType() is DWT.TRANSPARENCY_MASK) { 
    18381841        /* Get the HDC for the device */ 
     
    19701973    return init_(device, image, imageData); 
    19711974} 
    1972 void init_(Device device, ImageData i) { 
     1975void init_(ImageData i) { 
    19731976    if (i is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 
    19741977    init_(device, this, i); 
     
    20142017        data.device = device; 
    20152018        data.image = this; 
    2016         data.hFont = device.systemFont; 
     2019        data.font = device.systemFont; 
    20172020    } 
    20182021    return imageDC; 
     
    21452148 */ 
    21462149public static Image win32_new(Device device, int type, HGDIOBJ handle) { 
    2147     if (device is null) device = Device.getDevice(); 
    2148     Image image = new Image(); 
     2150    Image image = new Image(device); 
    21492151    image.type = type; 
    21502152    image.handle = handle; 
    2151     image.device = device; 
    21522153    return image; 
    21532154}