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

removed static ctors
author Frank Benoit <benoit@tionex.de>
date Wed, 06 Feb 2008 12:09:44 +0100
parents 205350493476
children 6f75fdfa1bcd
line wrap: on
line diff
--- a/dwt/widgets/ProgressBar.d	Wed Feb 06 11:08:01 2008 +0100
+++ b/dwt/widgets/ProgressBar.d	Wed Feb 06 12:09:44 2008 +0100
@@ -48,40 +48,51 @@
     static const int DELAY = 100;
     static const int TIMER_ID = 100;
     static const int MINIMUM_WIDTH = 100;
-    static const WNDPROC ProgressBarProc;
+    private static /+const+/ WNDPROC ProgressBarProc;
     static const TCHAR[] ProgressBarClass = OS.PROGRESS_CLASS;
-    static this() {
-        WNDCLASS lpWndClass;
-        OS.GetClassInfo (null, ProgressBarClass.ptr, &lpWndClass);
-        ProgressBarProc = lpWndClass.lpfnWndProc;
-        /*
-        * Feature in Windows.  The progress bar window class
-        * does not include CS_DBLCLKS.  This mean that these
-        * controls will not get double click messages such as
-        * WM_LBUTTONDBLCLK.  The fix is to register a new
-        * window class with CS_DBLCLKS.
-        *
-        * NOTE:  Screen readers look for the exact class name
-        * of the control in order to provide the correct kind
-        * of assistance.  Therefore, it is critical that the
-        * new window class have the same name.  It is possible
-        * to register a local window class with the same name
-        * as a global class.  Since bits that affect the class
-        * are being changed, it is possible that other native
-        * code, other than DWT, could create a control with
-        * this class name, and fail unexpectedly.
-        */
-        auto hInstance = OS.GetModuleHandle (null);
-        auto hHeap = OS.GetProcessHeap ();
-        lpWndClass.hInstance = hInstance;
-        lpWndClass.style &= ~OS.CS_GLOBALCLASS;
-        lpWndClass.style |= OS.CS_DBLCLKS;
-        int byteCount = (ProgressBarClass.length+1) * TCHAR.sizeof;
-        TCHAR* lpszClassName = cast(TCHAR*) OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount);
-        OS.MoveMemory (lpszClassName, ProgressBarClass.ptr, byteCount);
-        lpWndClass.lpszClassName = lpszClassName;
-        OS.RegisterClass (&lpWndClass);
-        OS.HeapFree (hHeap, 0, lpszClassName);
+
+    private static bool static_this_completed = false;
+    private static void static_this() {
+        if( static_this_completed ){
+            return;
+        }
+        synchronized {
+            if( static_this_completed ){
+                return;
+            }
+            WNDCLASS lpWndClass;
+            OS.GetClassInfo (null, ProgressBarClass.ptr, &lpWndClass);
+            ProgressBarProc = lpWndClass.lpfnWndProc;
+            /*
+            * Feature in Windows.  The progress bar window class
+            * does not include CS_DBLCLKS.  This mean that these
+            * controls will not get double click messages such as
+            * WM_LBUTTONDBLCLK.  The fix is to register a new
+            * window class with CS_DBLCLKS.
+            *
+            * NOTE:  Screen readers look for the exact class name
+            * of the control in order to provide the correct kind
+            * of assistance.  Therefore, it is critical that the
+            * new window class have the same name.  It is possible
+            * to register a local window class with the same name
+            * as a global class.  Since bits that affect the class
+            * are being changed, it is possible that other native
+            * code, other than DWT, could create a control with
+            * this class name, and fail unexpectedly.
+            */
+            auto hInstance = OS.GetModuleHandle (null);
+            auto hHeap = OS.GetProcessHeap ();
+            lpWndClass.hInstance = hInstance;
+            lpWndClass.style &= ~OS.CS_GLOBALCLASS;
+            lpWndClass.style |= OS.CS_DBLCLKS;
+            int byteCount = (ProgressBarClass.length+1) * TCHAR.sizeof;
+            TCHAR* lpszClassName = cast(TCHAR*) OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount);
+            OS.MoveMemory (lpszClassName, ProgressBarClass.ptr, byteCount);
+            lpWndClass.lpszClassName = lpszClassName;
+            OS.RegisterClass (&lpWndClass);
+            OS.HeapFree (hHeap, 0, lpszClassName);
+            static_this_completed = true;
+        }
     }
 
 /**
@@ -115,6 +126,7 @@
  * @see Widget#getStyle
  */
 public this (Composite parent, int style) {
+    static_this();
     super (parent, checkStyle (style));
 }