Changeset 11

Show
Ignore:
Timestamp:
05/02/04 12:49:53 (4 years ago)
Author:
brad
Message:

Andy Friesen's changes to the 0.1 branch. Mostly graphics, internal, widgets, and it compiles.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/0.1/src/dwt/graphics/all.d

    r3 r11  
    33module dwt.graphics.all; 
    44 
    5  
     5/* 
    66import dwt.graphics.device; 
    77import dwt.graphics.devicedata; 
     
    1010import dwt.graphics.rectangle; 
    1111 
     12*/ 
  • branches/0.1/src/dwt/graphics/color.d

    r3 r11  
    1212private import dwt.graphics.device; 
    1313private import dwt.internal.win32.os; 
     14private import std.string; 
    1415 
    1516 
     
    1718 * Instances of this class manage the operating system resources that 
    1819 * implement DWT's RGB color model. To create a color you can either 
    19  * specify the individual color components as integers in the range  
    20  * 0 to 255 or provide an instance of an <code>RGB</code>.  
    21  * <p> 
    22  * Application code must explicitly invoke the <code>Color.dispose()</code>  
     20 * specify the individual color components as integers in the range 
     21 * 0 to 255 or provide an instance of an <code>RGB</code>. 
     22 * <p> 
     23 * Application code must explicitly invoke the <code>Color.dispose()</code> 
    2324 * method to release the operating system resources managed by each instance 
    2425 * when those instances are no longer required. 
     
    3031 
    3132public final class Color { 
    32      
     33 
    3334    /** 
    34      * the handle to the OS color resource  
     35     * the handle to the OS color resource 
    3536     * (Warning: This field is platform dependent) 
    3637     */ 
    3738    public int handle; 
    38      
     39 
    3940    /** 
    4041     * the device where this color was created 
     
    4748this(){} 
    4849 
    49 /**      
     50/** 
    5051 * Constructs a new instance of this class given a device and the 
    5152 * desired red, green and blue values expressed as ints in the range 
     
    5354 * color devices, the color instance created by this call may not have 
    5455 * the same RGB values as the ones specified by the arguments. The 
    55  * RGB values on the returned instance will be the color values of  
     56 * RGB values on the returned instance will be the color values of 
    5657 * the operating system color. 
    5758 * <p> 
    58  * You must dispose the color when it is no longer required.  
     59 * You must dispose the color when it is no longer required. 
    5960 * </p> 
    6061 * 
     
    7879} 
    7980 
    80 /**      
     81/** 
    8182 * Constructs a new instance of this class given a device and an 
    8283 * <code>RGB</code> describing the desired red, green and blue values. 
     
    8687 * values of the operating system color. 
    8788 * <p> 
    88  * You must dispose the color when it is no longer required.  
     89 * You must dispose the color when it is no longer required. 
    8990 * </p> 
    9091 * 
     
    103104    if (device == null) device = Device.getDevice(); 
    104105    if (device == null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 
    105     if (rgb == null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 
    106106    init(device, rgb.red, rgb.green, rgb.blue); 
    107107    if (device.tracking) device.new_Object(this); 
     
    204204public RGB getRGB () { 
    205205    if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); 
    206     return new RGB(handle & 0xFF, (handle & 0xFF00) >> 8, (handle & 0xFF0000) >> 16); 
    207 } 
    208  
    209 /** 
    210  * Returns an integer hash code for the receiver. Any two  
    211  * objects which return <code>true</code> when passed to  
     206    return RGB(handle & 0xFF, (handle & 0xFF00) >> 8, (handle & 0xFF0000) >> 16); 
     207} 
     208 
     209/** 
     210 * Returns an integer hash code for the receiver. Any two 
     211 * objects which return <code>true</code> when passed to 
    212212 * <code>equals</code> must return the same value for this 
    213213 * method. 
     
    222222 
    223223/** 
    224  * Allocates the operating system resources associated  
     224 * Allocates the operating system resources associated 
    225225 * with the receiver. 
    226226 * 
     
    242242    this.device = device; 
    243243    handle = 0x02000000 | (red & 0xFF) | ((green & 0xFF) << 8) | ((blue & 0xFF) << 16); 
    244      
     244 
    245245    /* If this is not a palette-based device, return */ 
    246246    int hPal = device.hPalette; 
    247247    if (hPal == 0) return; 
    248      
     248 
    249249    int[] colorRefCount = device.colorRefCount; 
    250250    /* Add this color to the default palette now */ 
     
    276276    } else { 
    277277        /* Found a free entry */ 
    278         entry = new byte[] [ cast(byte)(red & 0xFF), cast(byte)(green & 0xFF), cast(byte)(blue & 0xFF), 0 ]; 
     278        entry = new byte[3];// [ cast(byte)(red & 0xFF), cast(byte)(green & 0xFF), cast(byte)(blue & 0xFF), 0 ]; 
     279                entry[0] = red & 0xff; 
     280                entry[1] = green & 0xff; 
     281                entry[2] = blue & 0xff; 
    279282        OS.SetPaletteEntries(hPal, index, 1, entry); 
    280283    } 
     
    304307public char[] toString () { 
    305308    if (isDisposed()) return "Color {*DISPOSED*}"; //$NON-NLS-1$ 
    306     return "Color {" + getRed() + ", " + getGreen() + ", " + getBlue() + "}"; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ 
    307 } 
    308  
    309 /**      
     309    return "Color {" ~ .toString(getRed()) ~ ", " ~ .toString(getGreen()) ~ ", " ~ .toString(getBlue()) ~ "}"; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ 
     310} 
     311 
     312/** 
    310313 * Invokes platform specific functionality to allocate a new color. 
    311314 * <p> 
  • branches/0.1/src/dwt/graphics/device.d

    r3 r11  
    99+/ 
    1010 
    11 private import dwt.dwt; 
    12  
    13 private import dwt.graphics.color; 
    14 private import dwt.graphics.drawable; 
    15 private import dwt.graphics.devicedata; 
    16 private import dwt.graphics.font; 
    17 private import dwt.graphics.fontdata; 
    18 private import dwt.graphics.gcdata; 
    19 private import dwt.graphics.rectangle; 
    20 private import dwt.graphics.point; 
    21  
    22 private import dwt.internal.compatibility; 
    23  
    24 private import dwt.internal.win32.os; 
    25 private import dwt.internal.win32.logfont; 
    26 private import dwt.internal.win32.logfonta; 
    27 private import dwt.internal.win32.logfontw; 
    28 private import dwt.internal.win32.textmetric; 
    29 private import dwt.internal.win32.textmetrica; 
    30 private import dwt.internal.win32.textmetricw; 
    31  
    32 private import dwt.util.runnable; 
    33  
     11private 
     12
     13    import dwt.dwt; 
     14 
     15    import dwt.graphics.color; 
     16    import dwt.graphics.drawable; 
     17    import dwt.graphics.devicedata; 
     18    import dwt.graphics.font; 
     19    import dwt.graphics.fontdata; 
     20    import dwt.graphics.forward; 
     21    import dwt.graphics.rectangle; 
     22    import dwt.graphics.point; 
     23 
     24    import dwt.internal.compatibility; 
     25 
     26    import dwt.internal.win32.os; 
     27    import dwt.internal.win32.logfont; 
     28    import dwt.internal.win32.textmetric; 
     29    import dwt.internal.win32.tchar; 
     30 
     31    import dwt.util.runnable; 
     32
    3433 
    3534/** 
     
    4241/+ TODO:  this was an abstract class, but I was having difficulties 
    4342    with no implementations allowed  +/ 
    44      
    45 public class Device : Drawable { 
    46  
    47   
     43 
     44public class Device : DeviceBase { 
     45 
     46 
    4847    /* Debugging */ 
    4948//  debug { 
    50         public static bit DBUG
     49        public const bit DBUG = true
    5150        bit dbug = DBUG; 
    5251        bit tracking = DBUG; 
     
    5453        Object[] objects; 
    5554//  } 
    56      
    57  
    58     /* Palette  
     55 
     56 
     57    /* Palette 
    5958    * (Warning: This field is platform dependent) 
    6059    */ 
    61     public int hPalette = 0; 
     60    /* 
     61        // Moved into DeviceBase for the time being. 
     62        public int hPalette = 0; 
    6263    int[] colorRefCount; 
    63      
    64     /* System Font */ 
     64 
     65    // System Font 
    6566    int systemFont; 
    6667 
    67     /* Font Enumeration */ 
     68    // Font Enumeration 
    6869    int nFonts = 256; 
    69     LOGFONT[] logFonts; 
     70    LOGFONT*[] logFonts; 
    7071 
    7172    bit disposed; 
    72  
    73 /+   
     73        */ 
     74 
     75 
    7476    /* 
    7577    * TEMPORARY CODE. When a graphics object is 
     
    8688    protected static Device CurrentDevice; 
    8789    protected static Runnable DeviceFinder; 
     90/+ 
    8891    static { 
    8992        try { 
    9093            Class.forName ("org.eclipse.swt.widgets.Display"); 
    9194        } catch (Throwable e) {} 
    92          
    93  
    94  
    95     } 
     95    } 
     96+/ 
    9697 
    9798/* 
     
    105106} 
    106107 
    107 +/ 
    108      
     108 
    109109/** 
    110110 * Constructs a new instance of this class. 
    111111 * <p> 
    112  * You must dispose the device when it is no longer required.  
     112 * You must dispose the device when it is no longer required. 
    113113 * </p> 
    114114 * 
     
    120120 */ 
    121121 
    122 this() {}  
    123   
     122this() {} 
     123 
    124124 
    125125// TODO:  not working when class was abstract due to no implementations 
     
    138138    /* Initialize the system font slot */ 
    139139    systemFont = getSystemFont().handle; 
    140      
     140 
    141141} 
    142142 
     
    195195} 
    196196 
    197 int computePoints(LOGFONT logFont) { 
     197int computePoints(LOGFONT* logFont) { 
    198198    int hDC = internal_new_GC (null); 
    199199    int logPixelsY = OS.GetDeviceCaps(hDC, OS.LOGPIXELSY); 
    200     int pixels = 0;  
     200    int pixels = 0; 
    201201    if (logFont.lfHeight > 0) { 
    202202        /* 
     
    210210        int hFont = OS.CreateFontIndirect(logFont); 
    211211        int oldFont = OS.SelectObject(hDC, hFont); 
    212         TEXTMETRIC lptm = OS.IsUnicode ? (TEXTMETRIC)new TEXTMETRICW() : new TEXTMETRICA(); 
     212        TEXTMETRIC* lptm = OS.IsUnicode 
     213                    ? cast(TEXTMETRIC*)new TEXTMETRICW() 
     214                    : cast(TEXTMETRIC*)new TEXTMETRICA(); 
    213215        OS.GetTextMetrics(hDC, lptm); 
    214216        OS.SelectObject(hDC, oldFont); 
     
    281283    bit scalable = lParam == 1; 
    282284    if (isScalable == scalable) { 
     285        // DWT's Java heritage is responsible for this particular weirdness. 
     286 
    283287        /* Add the log font to the list of log fonts */ 
    284         if (nFonts == logFonts.length) { 
    285             LOGFONT[] newLogFonts = new LOGFONT[logFonts.length + 128]; 
    286 //          System.arraycopy (logFonts, 0, newLogFonts, 0, nFonts); 
    287             newLogFonts = logFonts.dup; 
    288             logFonts = newLogFonts; 
    289         } 
    290         LOGFONT logFont = logFonts[nFonts]; 
    291         if (logFont == null) logFont = OS.IsUnicode ? (LOGFONT)new LOGFONTW () : new LOGFONTA (); 
    292         OS.MoveMemory (logFont, lpelfe, LOGFONT.sizeof); 
    293         logFonts [nFonts++] = logFont; 
     288        if (nFonts == logFonts.length) 
     289            logFonts.length = logFonts.length + 128; 
     290 
     291        LOGFONT* logFont = logFonts[nFonts]; 
     292        if (logFont === null) 
     293            logFont = OS.IsUnicode 
     294                ? cast(LOGFONT*)new LOGFONTW () 
     295                : cast(LOGFONT*)new LOGFONTA (); 
     296 
     297        // FIXME? LOGFONT is smaller than LOGFONTW and LOGFONTA 
     298        // the string at the end isn't copied! 
     299        *logFont = *cast(LOGFONT*)lpelfe; 
     300 
     301        logFonts ~= logFont; 
     302        nFonts++; 
    294303    } 
    295304    return 1; 
     
    353362 * Returns a rectangle which describes the area of the 
    354363 * receiver which is capable of displaying data. 
    355  *  
     364 * 
    356365 * @return the client area 
    357366 * 
     
    369378 * Returns the bit depth of the screen, which is the number of 
    370379 * bits it takes to represent the number of unique colors that 
    371  * the screen is currently capable of displaying. This number  
     380 * the screen is currently capable of displaying. This number 
    372381 * will typically be one of 1, 8, 15, 16, 24 or 32. 
    373382 * 
     
    420429 * </ul> 
    421430 */ 
    422 public FontData[] getFontList(char[] faceName, bit scalable) { 
     431public FontData[] getFontList(wchar[] faceName, bit scalable) { 
    423432    checkDevice (); 
    424      
     433 
    425434/+ 
    426435    /* Create the callback */ 
     
    428437    int lpEnumFontFamProc = callback.getAddress (); 
    429438+/ 
    430          
     439 
    431440    /* Initialize the instance variables */ 
    432     logFonts = new LOGFONT[nFonts]; 
     441    logFonts = new LOGFONT*[nFonts]; 
    433442    for (int i=0; i<logFonts.length; i++) { 
    434         logFonts [i] = OS.IsUnicode ? (LOGFONT) new LOGFONTW () : new LOGFONTA (); 
     443        logFonts [i] = OS.IsUnicode 
     444            ? cast(LOGFONT*) new LOGFONTW () 
     445            : cast(LOGFONT*) new LOGFONTA (); 
    435446    } 
    436447    nFonts = 0; 
     
    439450    int offset = 0; 
    440451    int hDC = internal_new_GC (null); 
    441     if (faceName == null) {     
     452    if (faceName == null) { 
    442453        /* The user did not specify a face name, so they want all versions of all available face names */ 
    443          
     454 
    444455// TODO: in D - this involves dwt.internal.callback above, if we're going to use that. 
    445456//      OS.EnumFontFamilies (hDC, null, lpEnumFontFamProc, scalable ? 1 : 0); 
    446          
     457 
    447458        /** 
    448459         * For bitmapped fonts, EnumFontFamilies only enumerates once for each font, regardless 
     
    452463        offset = nFonts; 
    453464        for (int i=0; i<offset; i++) { 
    454             LOGFONT lf = logFonts [i]; 
    455              
     465            LOGFONT* lf = logFonts [i]; 
     466 
    456467/+ TODO: in D 
    457468            /** 
     
    487498    FontData[] result = new FontData[count]; 
    488499    for (int i=0; i<count; i++) { 
    489         LOGFONT logFont = logFonts [i+offset]; 
     500        LOGFONT* logFont = logFonts [i+offset]; 
    490501        result [i] = FontData.win32_new (logFont, computePoints(logFont)); 
    491502    } 
    492      
     503 
    493504    /* Clean up */ 
    494505// TODO: using this?    callback.dispose (); 
     
    591602 * call the <code>super</code> implementation. 
    592603 * </p> 
    593  *  
     604 * 
    594605 * @see #create 
    595606 */ 
     
    606617    int bits = OS.GetDeviceCaps (hDC, OS.BITSPIXEL); 
    607618    int planes = OS.GetDeviceCaps (hDC, OS.PLANES); 
    608      
     619 
    609620    bits *= planes; 
    610621    if ((rc & OS.RC_PALETTE) == 0 || bits != 8) { 
     
    612623        return; 
    613624    } 
    614      
     625 
    615626    int numReserved = OS.GetDeviceCaps (hDC, OS.NUMRESERVED); 
    616627    int numEntries = OS.GetDeviceCaps (hDC, OS.SIZEPALETTE); 
     
    632643    /* 4 bytes header + 4 bytes per entry * numEntries entries */ 
    633644    byte [] logPalette = new byte [4 + 4 * numEntries]; 
    634      
     645 
    635646    /* 2 bytes = special header */ 
    636647    logPalette [0] = 0x00; 
    637648    logPalette [1] = 0x03; 
    638      
     649 
    639650    /* 2 bytes = number of colors, LSB first */ 
    640651    logPalette [2] = 0; 
    641652    logPalette [3] = 1; 
    642653 
    643     /*  
     654    /* 
    644655    * Create a palette which contains the system entries 
    645656    * as they are located in the system palette.  The 
     
    653664    /* Copy all entries from the system palette */ 
    654665//  System.arraycopy (lppe, 0, logPalette, 4, 4 * numEntries); 
    655      
     666 
    656667    /* Lock the indices corresponding to the system entries */ 
    657668    for (int i = 0; i < numReserved / 2; i++) { 
     
    668679 
    669680 
    670 /**      
     681/** 
    671682 * Invokes platform specific functionality to allocate a new GC handle. 
    672683 * <p> 
     
    678689 * </p> 
    679690 * 
    680  * @param data the platform specific GC data  
     691 * @param data the platform specific GC data 
    681692 * @return the platform specific GC handle 
    682693 */ 
    683 public int internal_new_GC (GCData data) {
    684  
    685 /**      
     694public int internal_new_GC (GCData data) { return 0;
     695 
     696/** 
    686697 * Invokes platform specific functionality to dispose a GC handle. 
    687698 * <p> 
     
    694705 * 
    695706 * @param handle the platform specific GC handle 
    696  * @param data the platform specific GC data  
     707 * @param data the platform specific GC data 
    697708 */ 
    698709public void internal_dispose_GC (int hDC, GCData data) {} 
     
    718729        if (objects [i] == null) { 
    719730            objects [i] = object; 
    720             errors [i] = new Error (); 
     731            errors [i] = new Error ("Java doesn't require a string here but D does -- andy"); 
    721732            return; 
    722733        } 
     
    728739    Error [] newErrors = new Error [errors.length + 128]; 
    729740// TODO:    System.arraycopy (errors, 0, newErrors, 0, errors.length); 
    730     newErrors [errors.length] = new Error (); 
     741    newErrors [errors.length] = new Error ("Same here"); 
    731742    errors = newErrors; 
    732743} 
  • branches/0.1/src/dwt/graphics/drawable.d

    r3 r11  
    1  
     1/+ 
    22 
    33module dwt.graphics.drawable; 
     
    88public interface Drawable { 
    99 
    10 /**      
     10/** 
    1111 * Invokes platform specific functionality to allocate a new GC handle. 
    1212 * <p> 
     
    1818 * </p> 
    1919 * 
    20  * @param data the platform specific GC data  
     20 * @param data the platform specific GC data 
    2121 * @return the platform specific GC handle 
    2222 */ 
     
    2525 
    2626 
    27 /**      
     27/** 
    2828 * Invokes platform specific functionality to dispose a GC handle. 
    2929 * <p> 
     
    3636 * 
    3737 * @param handle the platform specific GC handle 
    38  * @param data the platform specific GC data  
     38 * @param data the platform specific GC data 
    3939 */ 
    4040 
    4141public void internal_dispose_GC (int handle, GCData data); 
    4242} 
     43+/ 
  • branches/0.1/src/dwt/graphics/font.d

    r3 r11  
    1313private import dwt.internal.win32.os; 
    1414private import dwt.internal.win32.logfont; 
    15  
     15private import std.string; 
    1616 
    1717 
     
    2222 * or a <code>FontData</code> object which encapsulates this data. 
    2323 * <p> 
    24  * Application code must explicitly invoke the <code>Font.dispose()</code>  
     24 * Application code must explicitly invoke the <code>Font.dispose()</code> 
    2525 * method to release the operating system resources managed by each instance 
    2626 * when those instances are no longer required. 
     
    3131 
    3232public final class Font { 
    33      
     33 
    3434    /** 
    3535     * the handle to the OS font resource 
     
    3737     */ 
    3838    public int handle; 
    39      
     39 
    4040    /** 
    4141     * the device where this font was created 
    4242     */ 
    4343    Device device; 
    44      
     44 
    4545/** 
    4646 * Prevents uninitialized instances from being created outside the package. 
     
    4848this() {} 
    4949 
    50 /**      
     50/** 
    5151 * Constructs a new font given a device and font data 
    5252 * which describes the desired font's appearance. 
    5353 * <p> 
    54  * You must dispose the font when it is no longer required.  
     54 * You must dispose the font when it is no longer required. 
    5555 * </p> 
    5656 * 
    5757 * @param device the device to create the font on 
    5858 * @param fd the FontData that describes the desired font (must not be null) 
    59  *  
     59 * 
    6060 * @exception IllegalArgumentException <ul> 
    6161 *    <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li> 
     
    7070    if (device == null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 
    7171    init(device, fd); 
    72     if (device.tracking) device.new_Object(this);   
    73 } 
    74  
    75 /**      
     72    if (device.tracking) device.new_Object(this); 
     73} 
     74 
     75/** 
    7676 * Constructs a new font given a device and an array 
    7777 * of font data which describes the desired font's 
    7878 * appearance. 
    7979 * <p> 
    80  * You must dispose the font when it is no longer required.  
     80 * You must dispose the font when it is no longer required. 
    8181 * </p> 
    8282 * 
    8383 * @param device the device to create the font on 
    8484 * @param fds the array of FontData that describes the desired font (must not be null) 
    85  *  
     85 * 
    8686 * @exception IllegalArgumentException <ul> 
    8787 *    <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li> 
     
    9393 *    <li>ERROR_NO_HANDLES - if a font could not be created from the given font data</li> 
    9494 * </ul> 
    95  *  
     95 * 
    9696 * @since 2.1 
    9797 */ 
     
    102102    if (fds.length == 0) DWT.error(DWT.ERROR_INVALID_ARGUMENT); 
    103103    init(device, fds[0]); 
    104     if (device.tracking) device.new_Object(this);   
    105 } 
    106  
    107 /**      
     104    if (device.tracking) device.new_Object(this); 
     105} 
     106 
     107/** 
    108108 * Constructs a new font given a device, a font name, 
    109109 * the height of the desired font in points, and a font 
    110110 * style. 
    111111 * <p> 
    112  * You must dispose the font when it is no longer required.  
     112 * You must dispose the font when it is no longer required. 
    113113 * </p> 
    114114 * 
     
    117117 * @param height the font height in points 
    118118 * @param style a bit or combination of NORMAL, BOLD, ITALIC 
    119  *  
     119 * 
    120120 * @exception IllegalArgumentException <ul> 
    121121 *    <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li> 
     
    127127 * </ul> 
    128128 */ 
    129 public this(Device device, char[] name, int height, int style) { 
     129public this(Device device, wchar[] name, int height, int style) { 
    130130    if (device == null) device = Device.getDevice(); 
    131131    if (device == null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 
    132132    if (name == null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 
    133133    init(device, new FontData (name, height, style)); 
    134     if (device.tracking) device.new_Object(this);   
     134    if (device.tracking) device.new_Object(this); 
    135135} 
    136136 
     
    168168/** 
    169169 * Returns an array of <code>FontData</code>s representing the receiver. 
    170  * On Windows, only one FontData will be returned per font. On X however,  
    171  * a <code>Font</code> object <em>may</em> be composed of multiple X  
     170 * On Windows, only one FontData will be returned per font. On X however, 
     171 * a <code>Font</code> object <em>may</em> be composed of multiple X 
    172172 * fonts. To support this case, we return an array of font data objects. 
    173173 * 
     
    180180public FontData[] getFontData() { 
    181181    if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); 
    182     LOGFONT logFont = OS.IsUnicode ? (LOGFONT)new LOGFONTW() : new LOGFONTA(); 
     182    LOGFONT* logFont = OS.IsUnicode 
     183            ? cast(LOGFONT*)new LOGFONTW() 
     184            : cast(LOGFONT*)new LOGFONTA(); 
    183185    OS.GetObject(handle, LOGFONT.sizeof, logFont); 
    184     return new FontData[] [FontData.win32_new(logFont, device.computePoints(logFont))]; 
    185 
    186  
    187 /** 
    188  * Returns an integer hash code for the receiver. Any two  
    189  * objects which return <code>true</code> when passed to  
     186 
     187        FontData[] result; 
     188        result ~= FontData.win32_new(logFont, device.computePoints(logFont)); 
     189    return result; 
     190
     191 
     192/** 
     193 * Returns an integer hash code for the receiver. Any two 
     194 * objects which return <code>true</code> when passed to 
    190195 * <code>equals</code> must return the same value for this 
    191196 * method. 
     
    202207    if (fd == null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 
    203208    this.device = device; 
    204     LOGFONT logFont = fd.data; 
     209    LOGFONT* logFont = fd.data; 
    205210    int lfHeight = logFont.lfHeight; 
    206211    logFont.lfHeight = device.computePixels(fd.height); 
     
    232237public char[] toString () { 
    233238    if (isDisposed()) return "Font {*DISPOSED*}"; 
    234     return "Font {" + handle + "}"; 
    235 } 
    236  
    237 /**      
     239    return "Font {" ~ .toString(handle) ~ "}"; 
     240} 
     241 
     242/** 
    238243 * Invokes platform specific functionality to allocate a new font. 
    239244 * <p> 
  • branches/0.1/src/dwt/graphics/fontdata.d

    r3 r11  
    33module dwt.graphics.fontdata; 
    44 
    5 /+  
     5/+ 
    66import org.eclipse.swt.internal.*; 
    77import org.eclipse.swt.internal.win32.*; 
     
    1212 
    1313private import dwt.internal.win32.logfont; 
    14 private import dwt.internal.win32.logfonta; 
    15 private import dwt.internal.win32.logfontw; 
    1614private import dwt.internal.win32.os; 
    17  
     15private import dwt.internal.win32.tchar; 
     16private import dwt.internal.callback; 
     17private import dwt.util.string; 
     18private import std.string; 
    1819 
    1920 
     
    4546 
    4647public final class FontData { 
    47      
     48 
    4849    /** 
    4950     * A Win32 LOGFONT struct 
    5051     * (Warning: This field is platform dependent) 
    5152     */ 
    52     public LOGFONT data; 
    53      
     53    public LOGFONT* data; 
     54 
    5455    /** 
    5556     * The height of the font data in points 
     
    5758     */ 
    5859    public int height; 
    59      
     60 
    6061    /** 
    6162     * The locales of the font 
    6263     * (Warning: These fields are platform dependent) 
    6364     */ 
    64     char[] lang, country, variant; 
    65      
    66 /**      
     65    wchar[] lang, country, variant; 
     66 
     67/** 
    6768 * Constructs a new un-initialized font data. 
    6869 */ 
    6970public this() { 
    70     data = OS.IsUnicode ? (LOGFONT)new LOGFONTW() : new LOGFONTA(); 
     71    data = OS.IsUnicode 
     72            ? cast(LOGFONT*)new LOGFONTW() 
     73            : cast(LOGFONT*)new LOGFONTA(); 
    7174    // We set the charset field so that 
    7275    // wildcard searching will work properly 
     
    7982 * Constructs a new font data given the Windows <code>LOGFONT</code> 
    8083 * that it should represent. 
    81  *  
     84 * 
    8285 * @param data the <code>LOGFONT</code> for the result 
    8386 */ 
    84 this(LOGFONT data, int height) { 
     87this(LOGFONT* data, int height) { 
    8588    this.data = data; 
    8689    this.height = height; 
     
    9396 * <p> 
    9497 * Note that the representation varies between platforms, 
    95  * and a FontData can only be created from a string that was  
     98 * and a FontData can only be created from a string that was 
    9699 * generated on the same platform. 
    97100 * </p> 
     
    106109 * @see #toString 
    107110 */ 
    108 public this(char[] string) { 
    109     if (string == null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 
    110     int start = 0; 
    111     int end = string.indexOf('|'); 
    112     if (end == -1) DWT.error(DWT.ERROR_INVALID_ARGUMENT); 
    113     char[] version1 = string.substring(start, end); 
    114     try { 
    115         if (Integer.parseInt(version1) != 1) DWT.error(DWT.ERROR_INVALID_ARGUMENT);  
    116     } catch (NumberFormatException e) { 
    117         DWT.error(DWT.ERROR_INVALID_ARGUMENT); 
    118     } 
    119      
    120     start = end + 1; 
    121     end = string.indexOf('|', start); 
    122     if (end == -1) DWT.error(DWT.ERROR_INVALID_ARGUMENT); 
    123     char[] name = string.substring(start, end); 
    124      
    125     start = end + 1; 
    126     end = string.indexOf('|', start); 
    127     if (end == -1) DWT.error(DWT.ERROR_INVALID_ARGUMENT); 
     111public this(wchar[] string) { 
     112    wchar[][] str = Strings!(wchar).split(string, "|"); 
     113 
     114    if (string === null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 
     115    int pos = 0; 
     116    if (pos >= str.length) DWT.error(DWT.ERROR_INVALID_ARGUMENT); 
     117    wchar[] version1 = str[pos++]; 
     118    //try { 
     119        if (Strings!(wchar).toInt(version1) != 1) DWT.error(DWT.ERROR_INVALID_ARGUMENT); 
     120    //} catch (NumberFormatException e) { 
     121    //  DWT.error(DWT.ERROR_INVALID_ARGUMENT); 
     122    //} 
     123 
     124    if (pos >= str.length) DWT.error(DWT.ERROR_INVALID_ARGUMENT); 
     125    wchar[] name = str[pos++]; 
     126 
     127    if (pos >= str.length) DWT.error(DWT.ERROR_INVALID_ARGUMENT); 
    128128    int height = 0; 
    129     try { 
    130         height = Integer.parseInt(string.substring(start, end)); 
    131     } catch (NumberFormatException e) { 
    132         DWT.error(DWT.ERROR_INVALID_ARGUMENT); 
    133     } 
    134      
    135     start = end + 1; 
    136     end = string.indexOf('|', start); 
    137     if (end == -1) DWT.error(DWT.ERROR_INVALID_ARGUMENT); 
     129    //try { 
     130        height = Strings!(wchar).toInt(str[pos++]); 
     131    //} catch (NumberFormatException e) { 
     132    //  DWT.error(DWT.ERROR_INVALID_ARGUMENT); 
     133    //} 
     134 
     135    if (pos >= str.length) DWT.error(DWT.ERROR_INVALID_ARGUMENT); 
    138136    int style = 0; 
    139     try { 
    140         style = Integer.parseInt(string.substring(start, end)); 
    141     } catch (NumberFormatException e) { 
    142       DWT.error(DWT.ERROR_INVALID_ARGUMENT); 
    143    
    144  
    145     start = end + 1; 
    146     end = string.indexOf('|', start); 
    147     data = OS.IsUnicode ? (LOGFONT)new LOGFONTW() : new LOGFONTA(); 
     137    //try { 
     138        style = Strings!(wchar).toInt(str[pos++]); 
     139    //} catch (NumberFormatException e) { 
     140    //    DWT.error(DWT.ERROR_INVALID_ARGUMENT); 
     141    //
     142 
     143    data = OS.IsUnicode 
     144       ? cast(LOGFONT*)new LOGFONTW() 
     145       : cast(LOGFONT*)new LOGFONTA(); 
    148146    data.lfCharSet = OS.DEFAULT_CHARSET; 
    149147    setName(name); 
    150148    setHeight(height); 
    151149    setStyle(style); 
    152     if (end == -1) return; 
    153     char[] platform = string.substring(start, end); 
    154  
    155     start = end + 1; 
    156     end = string.indexOf('|', start); 
    157     if (end == -1) return; 
    158     char[] version2 = string.substring(start, end); 
    159  
    160     if (platform.equals("WINDOWS") && version2.equals("1")) { 
    161         LOGFONT newData = OS.IsUnicode ? (LOGFONT)new LOGFONTW() : new LOGFONTA(); 
    162         try { 
    163             start = end + 1; 
    164             end = string.indexOf('|', start); 
    165             if (end == -1) return; 
    166             newData.lfHeight = Integer.parseInt(string.substring(start, end)); 
    167             start = end + 1; 
    168             end = string.indexOf('|', start); 
    169             if (end == -1) return; 
    170             newData.lfWidth = Integer.parseInt(string.substring(start, end)); 
    171             start = end + 1; 
    172             end = string.indexOf('|', start); 
    173             if (end == -1) return; 
    174             newData.lfEscapement = Integer.parseInt(string.substring(start, end)); 
    175             start = end + 1; 
    176             end = string.indexOf('|', start); 
    177             if (end == -1) return; 
    178             newData.lfOrientation = Integer.parseInt(string.substring(start, end)); 
    179             start = end + 1; 
    180             end = string.indexOf('|', start); 
    181             if (end == -1) return; 
    182             newData.lfWeight = Integer.parseInt(string.substring(start, end)); 
    183             start = end + 1; 
    184             end = string.indexOf('|', start); 
    185             if (end == -1) return; 
    186             newData.lfItalic = Byte.parseByte(string.substring(start, end)); 
    187             start = end + 1; 
    188             end = string.indexOf('|', start); 
    189             if (end == -1) return; 
    190             newData.lfUnderline = Byte.parseByte(string.substring(start, end)); 
    191             start = end + 1; 
    192             end = string.indexOf('|', start); 
    193             if (end == -1) return; 
    194             newData.lfStrikeOut = Byte.parseByte(string.substring(start, end)); 
    195             start = end + 1; 
    196             end = string.indexOf('|', start); 
    197             if (end == -1) return; 
    198             newData.lfCharSet = Byte.parseByte(string.substring(start, end)); 
    199             start = end + 1; 
    200             end = string.indexOf('|', start); 
    201             if (end == -1) return; 
    202             newData.lfOutPrecision = Byte.parseByte(string.substring(start, end)); 
    203             start = end + 1; 
    204             end = string.indexOf('|', start); 
    205             if (end == -1) return; 
    206             newData.lfClipPrecision = Byte.parseByte(string.substring(start, end)); 
    207             start = end + 1; 
    208             end = string.indexOf('|', start); 
    209             if (end == -1) return; 
    210             newData.lfQuality = Byte.parseByte(string.substring(start, end)); 
    211             start = end + 1; 
    212             end = string.indexOf('|', start); 
    213             if (end == -1) return; 
    214             newData.lfPitchAndFamily = Byte.parseByte(string.substring(start, end)); 
    215             start = end + 1; 
    216         } catch (NumberFormatException e) { 
     150    if (pos >= str.length) DWT.error(DWT.ERROR_INVALID_ARGUMENT); 
     151    wchar[] platform = str[pos++]; 
     152 
     153    if (pos >= str.length) return; 
     154    wchar[] version2 = str[pos++]; 
     155 
     156    if (platform == "WINDOWS" && version2 == "1") { 
     157        LOGFONT* newData = OS.IsUnicode 
     158            ? cast(LOGFONT*)new LOGFONTW() 
     159            : cast(LOGFONT*)new LOGFONTA(); 
     160        //try { 
     161            if (pos >= str.length) return; 
     162            newData.lfHeight = Strings!(wchar).toInt(str[pos++]); 
     163 
     164            if (pos >= str.length) return; 
     165            newData.lfWidth = Strings!(wchar).toInt(str[pos++]); 
     166 
     167            if (pos >= str.length) return; 
     168            newData.lfEscapement = Strings!(wchar).toInt(str[pos++]); 
     169 
     170            if (pos >= str.length) return; 
     171        &