diff dwt/widgets/Display.d @ 80:1801ddeb8f32

removed static ctors
author Frank Benoit <benoit@tionex.de>
date Wed, 06 Feb 2008 12:09:44 +0100
parents f824f1836871
children 43c42c637c9c
line wrap: on
line diff
--- a/dwt/widgets/Display.d	Wed Feb 06 11:08:01 2008 +0100
+++ b/dwt/widgets/Display.d	Wed Feb 06 12:09:44 2008 +0100
@@ -165,26 +165,38 @@
     HWND lastGetHwnd;
     Control [] controlTable;
     static const int GROW_SIZE = 1024;
-    static const int SWT_OBJECT_INDEX;
+    private static /+const+/ int SWT_OBJECT_INDEX;
     static const bool USE_PROPERTY = !OS.IsWinCE;
-    static this() {
-        static if (USE_PROPERTY) {
-            SWT_OBJECT_INDEX = OS.GlobalAddAtom (StrToTCHARz( "SWT_OBJECT_INDEX")); //$NON-NLS-1$
-        } else {
-            SWT_OBJECT_INDEX = 0;
+
+    private static bool static_this_completed = false;
+    private static void static_this() {
+        if( static_this_completed ){
+            return;
+        }
+        synchronized {
+            if( static_this_completed ){
+                return;
+            }
+            static if (USE_PROPERTY) {
+                SWT_OBJECT_INDEX = OS.GlobalAddAtom (StrToTCHARz("SWT_OBJECT_INDEX")); //$NON-NLS-1$
+            } else {
+                SWT_OBJECT_INDEX = 0;
+            }
+            static_this_StartupInfo ();
+            static_this_DeviceFinder ();
+            static_this_completed = true;
         }
     }
 
     /* Startup info */
-    static STARTUPINFO* lpStartupInfo;
-    static this() {
+    private static STARTUPINFO* lpStartupInfo;
+    private static void static_this_StartupInfo (){
         static if (!OS.IsWinCE) {
             lpStartupInfo = new STARTUPINFO ();
             lpStartupInfo.cb = STARTUPINFO.sizeof;
             OS.GetStartupInfo (lpStartupInfo);
         }
     }
-
     /* XP Themes */
     HTHEME hButtonTheme_, hEditTheme_, hExplorerBarTheme_, hScrollBarTheme_, hTabTheme_;
     static const wchar [] BUTTON = "BUTTON\0"w;
@@ -429,7 +441,7 @@
     * gets the current display. This code will
     * be removed in the future.
     */
-    static this () {
+    private static void static_this_DeviceFinder () {
         DeviceFinder = new class() Runnable {
             public void run () {
                 Device device = getCurrent ();
@@ -445,6 +457,7 @@
 * TEMPORARY CODE.
 */
 static void setDevice (Device device) {
+    static_this();
     CurrentDevice = device;
 }
 
@@ -477,6 +490,7 @@
  * @param data the device data
  */
 public this (DeviceData data) {
+    static_this();
     super (data);
     synchronizer = new Synchronizer (this);
     cursors = new Cursor [DWT.CURSOR_HAND + 1];
@@ -794,6 +808,7 @@
 }
 
 static HBITMAP create32bitDIB (Image image) {
+    static_this();
     int transparentPixel = -1, alpha = -1;
     HBITMAP hMask;
     HBITMAP hBitmap;
@@ -926,6 +941,7 @@
 }
 
 static HBITMAP create32bitDIB (HBITMAP hBitmap, int alpha, byte [] alphaData, int transparentPixel) {
+    static_this();
     BITMAP bm;
     OS.GetObject (hBitmap, BITMAP.sizeof, &bm);
     int imgWidth = bm.bmWidth;
@@ -1015,6 +1031,7 @@
 }
 
 static Image createIcon (Image image) {
+    static_this();
     Device device = image.getDevice ();
     ImageData data = image.getImageData ();
     if (data.alpha is -1 && data.alphaData is null) {
@@ -1062,6 +1079,7 @@
 }
 
 static HBITMAP createMaskFromAlpha (ImageData data, int destWidth, int destHeight) {
+    static_this();
     int srcWidth = data.width;
     int srcHeight = data.height;
     ImageData mask = ImageData.internal_new (srcWidth, srcHeight, 1,
@@ -1093,6 +1111,7 @@
 }
 
 static synchronized void deregister (Display display) {
+    static_this();
     for (int i=0; i<Displays.length; i++) {
         if (display is Displays [i]) Displays [i] = null;
     }
@@ -1331,6 +1350,7 @@
  * @return the display for the given thread
  */
 public static synchronized Display findDisplay (Thread thread) {
+    static_this();
     for (int i=0; i<Displays.length; i++) {
         Display display = Displays [i];
         if (display !is null && display.thread is thread) {
@@ -1390,6 +1410,7 @@
  * @return the current display
  */
 public static synchronized Display getCurrent () {
+    static_this();
     return findDisplay (Thread.getThis ());
 }
 
@@ -1548,6 +1569,7 @@
  * @return the default display
  */
 public static synchronized Display getDefault () {
+    static_this();
     if (Default is null) Default = new Display ();
     return Default;
 }
@@ -3368,6 +3390,7 @@
 }
 
 static synchronized void register (Display display) {
+    static_this();
     for (int i=0; i<Displays.length; i++) {
         if (Displays [i] is null) {
             Displays [i] = display;