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

    r212 r213  
    1818import dwt.internal.win32.OS; 
    1919 
     20import dwt.graphics.Cursor; 
     21import dwt.graphics.GC; 
     22import dwt.graphics.Image; 
     23import dwt.graphics.Path; 
     24import dwt.graphics.Pattern; 
     25import dwt.graphics.Region; 
     26import dwt.graphics.TextLayout; 
     27import dwt.graphics.Transform; 
    2028import dwt.graphics.Drawable; 
    2129import dwt.graphics.DeviceData; 
     
    2836import dwt.dwthelper.Runnable; 
    2937import dwt.dwthelper.System; 
     38 
    3039import dwt.dwthelper.utils; 
    3140import tango.core.Exception; 
     41import tango.util.Convert; 
     42import tango.io.Stdout; 
    3243 
    3344/** 
     
    5061    Exception [] errors; 
    5162    Object [] objects; 
     63    Object trackingLock; 
    5264 
    5365    /** 
     
    6577 
    6678    /* System Font */ 
    67     HFONT systemFont; 
     79    Font systemFont; 
    6880 
    6981    /* Font Enumeration */ 
     
    7587    /* Scripts */ 
    7688    SCRIPT_PROPERTIES*[] scripts; 
     89    LOGFONT* [] logFontsCache; 
    7790 
    7891    /* Advanced Graphics */ 
     
    135148 */ 
    136149public this(DeviceData data) { 
    137     synchronized (this.classinfo) { 
     150    synchronized (Device.classinfo) { 
    138151        debug_ = DEBUG; 
    139152        tracking = DEBUG; 
     
    142155            tracking = data.tracking; 
    143156        } 
    144         create (data); 
    145         init_ (); 
    146157        if (tracking) { 
    147158            errors = new Exception [128]; 
    148159            objects = new Object [128]; 
    149         } 
    150  
    151         /* Initialize the system font slot */ 
    152         systemFont = getSystemFont().handle
     160            trackingLock = new Object (); 
     161        } 
     162        create (data); 
     163        init_ ()
    153164        gdipToken = 0; 
    154165    } 
     
    180191void checkGDIP() { 
    181192    if (gdipToken) return; 
    182     static if (OS.IsWinCE) DWT.error(DWT.ERROR_NOT_IMPLEMENTED)
    183     int oldErrorMode = OS.SetErrorMode (OS.SEM_FAILCRITICALERRORS); 
     193    int oldErrorMode = 0
     194    static if (!OS.IsWinCE) oldErrorMode = OS.SetErrorMode (OS.SEM_FAILCRITICALERRORS); 
    184195    try { 
    185196        ULONG_PTR token; 
     
    192203        DWT.error (DWT.ERROR_NO_GRAPHICS_LIBRARY, t, " [GDI+ is required]"); //$NON-NLS-1$ 
    193204    } finally { 
    194         OS.SetErrorMode (oldErrorMode); 
     205        if (!OS.IsWinCE) OS.SetErrorMode (oldErrorMode); 
    195206    } 
    196207} 
     
    273284 */ 
    274285public void dispose () { 
    275     if (isDisposed()) return; 
    276     checkDevice (); 
    277     release (); 
    278     destroy (); 
    279     disposed = true; 
    280     if (tracking) { 
    281         objects = null; 
    282         errors = null; 
     286    synchronized (Device.classinfo) { 
     287        if (isDisposed()) return; 
     288        checkDevice (); 
     289        release (); 
     290        destroy (); 
     291        disposed = true; 
     292        if (tracking) { 
     293            synchronized (trackingLock) { 
     294                printErrors (); 
     295                objects = null; 
     296                errors = null; 
     297                trackingLock = null; 
     298            } 
     299        } 
    283300    } 
    284301} 
    285302 
    286303void dispose_Object (Object object) { 
    287     for (int i=0; i<objects.length; i++) { 
    288         if (objects [i] is object) { 
    289             objects [i] = null; 
    290             errors [i] = null; 
    291             return; 
     304    synchronized (trackingLock) { 
     305        for (int i=0; i<objects.length; i++) { 
     306            if (objects [i] is object) { 
     307                objects [i] = null; 
     308                errors [i] = null; 
     309                return; 
     310            } 
    292311        } 
    293312    } 
     
    370389    data.debug_ = debug_; 
    371390    data.tracking = tracking; 
    372     int count = 0, length = 0; 
    373     if (tracking) length = objects.length; 
    374     for (int i=0; i<length; i++) { 
    375         if (objects [i] !is null) count++; 
    376     } 
    377     int index = 0; 
    378     data.objects = new Object [count]; 
    379     data.errors = new Exception [count]; 
    380     for (int i=0; i<length; i++) { 
    381         if (objects [i] !is null) { 
    382             data.objects [index] = objects [i]; 
    383             data.errors [index] = errors [i]; 
    384             index++; 
    385         } 
     391    if (tracking) { 
     392        synchronized (trackingLock) { 
     393            int count = 0, length = objects.length; 
     394            for (int i=0; i<length; i++) { 
     395                if (objects [i] !is null) count++; 
     396            } 
     397            int index = 0; 
     398            data.objects = new Object [count]; 
     399            data.errors = new Exception [count]; 
     400            for (int i=0; i<length; i++) { 
     401                if (objects [i] !is null) { 
     402                    data.objects [index] = objects [i]; 
     403                    data.errors [index] = errors [i]; 
     404                    index++; 
     405                } 
     406            } 
     407        } 
     408    } else { 
     409        data.objects = new Object [0]; 
     410        data.errors = new Exception [0]; 
    386411    } 
    387412    return data; 
     
    661686    } 
    662687 
     688    /* Initialize the system font slot */ 
     689    systemFont = getSystemFont(); 
     690 
    663691    /* Initialize scripts list */ 
    664692    static if (!OS.IsWinCE) { 
     
    773801 */ 
    774802public bool isDisposed () { 
    775     return disposed; 
     803    synchronized (Device.classinfo) { 
     804        return disposed; 
     805    } 
    776806} 
    777807 
     
    803833 
    804834void new_Object (Object object) { 
    805     for (int i=0; i<objects.length; i++) { 
    806         if (objects [i] is null) { 
    807             objects [i] = object; 
    808             errors [i] = new Exception ( "" ); 
    809             return; 
    810         } 
    811     } 
    812     Object [] newObjects = new Object [objects.length + 128]; 
    813     System.arraycopy (objects, 0, newObjects, 0, objects.length); 
    814     newObjects [objects.length] = object; 
    815     objects = newObjects; 
    816     Exception [] newErrors = new Exception [errors.length + 128]; 
    817     System.arraycopy (errors, 0, newErrors, 0, errors.length); 
    818     newErrors [errors.length] = new Exception (""); 
    819     errors = newErrors; 
     835    synchronized (trackingLock) { 
     836        for (int i=0; i<objects.length; i++) { 
     837            if (objects [i] is null) { 
     838                objects [i] = object; 
     839                errors [i] = new Exception ( "" ); 
     840                return; 
     841            } 
     842        } 
     843        Object [] newObjects = new Object [objects.length + 128]; 
     844        System.arraycopy (objects, 0, newObjects, 0, objects.length); 
     845        newObjects [objects.length] = object; 
     846        objects = newObjects; 
     847        Exception [] newErrors = new Exception [errors.length + 128]; 
     848        System.arraycopy (errors, 0, newErrors, 0, errors.length); 
     849        newErrors [errors.length] = new Exception (""); 
     850        errors = newErrors; 
     851    } 
     852
     853 
     854void printErrors () { 
     855    if (!DEBUG) return; 
     856    if (tracking) { 
     857        synchronized (trackingLock) { 
     858            if (objects is null || errors is null) return; 
     859            int objectCount = 0; 
     860            int colors = 0, cursors = 0, fonts = 0, gcs = 0, images = 0; 
     861            int paths = 0, patterns = 0, regions = 0, textLayouts = 0, transforms = 0; 
     862            for (int i=0; i<objects.length; i++) { 
     863                Object object = objects [i]; 
     864                if (object !is null) { 
     865                    objectCount++; 
     866                    if (null !is cast(Color)object ) colors++; 
     867                    if (null !is cast(Cursor)object ) cursors++; 
     868                    if (null !is cast(Font)object ) fonts++; 
     869                    if (null !is cast(GC)object ) gcs++; 
     870                    if (null !is cast(Image)object ) images++; 
     871                    if (null !is cast(Path)object ) paths++; 
     872                    if (null !is cast(Pattern)object ) patterns++; 
     873                    if (null !is cast(Region)object ) regions++; 
     874                    if (null !is cast(TextLayout)object ) textLayouts++; 
     875                    if (null !is cast(Transform)object ) transforms++; 
     876                } 
     877            } 
     878            if (objectCount !is 0) { 
     879                String string = "Summary: "; 
     880                if (colors !is 0) string ~= to!(String)(colors) ~ " Color(s), "; 
     881                if (cursors !is 0) string ~= to!(String)(cursors) ~ " Cursor(s), "; 
     882                if (fonts !is 0) string ~= to!(String)(fonts) ~ " Font(s), "; 
     883                if (gcs !is 0) string ~= to!(String)(gcs) ~ " GC(s), "; 
     884                if (images !is 0) string ~= to!(String)(images) ~ " Image(s), "; 
     885                if (paths !is 0) string ~= to!(String)(paths) ~ " Path(s), "; 
     886                if (patterns !is 0) string ~= to!(String)(patterns) ~ " Pattern(s), "; 
     887                if (regions !is 0) string ~= to!(String)(regions) ~ " Region(s), "; 
     888                if (textLayouts !is 0) string ~= to!(String)(textLayouts) ~ " TextLayout(s), "; 
     889                if (transforms !is 0) string ~= to!(String)(transforms) ~ " Transforms(s), "; 
     890                if (string.length !is 0) { 
     891                    string = string.substring (0, string.length - 2); 
     892                    Stderr.formatln ( "{}", string); 
     893                } 
     894                for (int i=0; i<errors.length; i++) { 
     895                    if (errors [i] !is null) ExceptionPrintStackTrace( errors [i], Stderr); 
     896                } 
     897            } 
     898        } 
     899    } 
    820900} 
    821901 
     
    849929    gdipToken = 0; // TODO: assignment of 0 might not be valid for token 
    850930    scripts = null; 
     931    logFontsCache = null; 
    851932    if (hPalette !is null) OS.DeleteObject (hPalette); 
    852933    hPalette = null;