changeset 161:d6bf6a720cde

Minor cleanup and organization of Activation Context Code
author John Reimer <terminal.node@gmail.com>
date Sun, 17 Feb 2008 09:30:11 -0800
parents c290741fbb6b
children 619faee45ef6 07ed83d51a19
files dwt/internal/win32/OS.d
diffstat 1 files changed, 92 insertions(+), 69 deletions(-) [+]
line wrap: on
line diff
--- a/dwt/internal/win32/OS.d	Fri Feb 15 03:29:01 2008 +0100
+++ b/dwt/internal/win32/OS.d	Sun Feb 17 09:30:11 2008 -0800
@@ -154,7 +154,7 @@
     public static const int COMCTL32_MAJOR, COMCTL32_MINOR, COMCTL32_VERSION;
     public static const int SHELL32_MAJOR, SHELL32_MINOR, SHELL32_VERSION;
 
-    public static const char[] NO_MANIFEST = "org.eclipse.swt.internal.win32.OS.NO_MANIFEST";
+    public static const char[] NO_MANIFEST = "dwt.internal.win32.OS.NO_MANIFEST";
 
 
     /*
@@ -269,73 +269,9 @@
         //IsUnicode = !IsWin32s && !IsWin95;
 
         /* Load the manifest to force the XP Theme */
-        if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (5, 1)) {
-
-            const char[] manifest = `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
-<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
-    <assemblyIdentity version="1.0.0.0" processorArchitecture="X86" name="dwt" type="win32"/>
-    <description>D Widget Toolkit</description>
-    <dependency>
-        <dependentAssembly>
-            <assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="X86" publicKeyToken="6595b64144ccf1df" language="*"/>
-        </dependentAssembly>
-    </dependency>
-</assembly>`;
-
-            scope temp = new tango.io.TempFile.TempFile(tango.io.TempFile.TempFile.Permanent);
-            temp.write(manifest);
-            temp.detach();
-
-            ACTCTX actctx;
-            actctx.cbSize = actctx.sizeof;
-            actctx.lpSource = StrToTCHARz( 0, temp.toString );
-
-            // Create the activation context
-            HANDLE hActCtx = OS.CreateActCtx(&actctx);
-
-            // Did we fail creating the activation context?
-            if (hActCtx is INVALID_HANDLE_VALUE){
-                Trace.formatln("The Activation Context could not be created");
-                goto LActCtxError;
-            }
-
-            // Activate the context and make use of it
-            ULONG_PTR ulpActivationCookie;
-            if (!OS.ActivateActCtx(hActCtx, &ulpActivationCookie)){
-                Trace.formatln("The Activation Context failed to load");
-                goto LActCtxError;
-            }
-
-    LActCtxError:
-            temp.path.remove();
-
-/+         //if (System.getProperty (NO_MANIFEST) is null) {
-                TCHAR[] buffer = new TCHAR[ MAX_PATH ];
-                HANDLE hModule = OS.GetLibraryHandle ();
-                while (OS.GetModuleFileName (hModule, buffer.ptr, buffer.length ) is buffer.length ) {
-                    buffer.length = buffer.length + MAX_PATH;
-                }
-                auto hHeap = OS.GetProcessHeap ();
-                int byteCount = buffer.length * TCHAR.sizeof;
-                TCHAR* pszText = cast(TCHAR*) OS.HeapAlloc (hHeap, HEAP_ZERO_MEMORY, byteCount);
-                OS.MoveMemory (pszText, buffer.ptr, byteCount);
-                ACTCTX pActCtx;
-                pActCtx.cbSize = ACTCTX.sizeof;
-                pActCtx.dwFlags = ACTCTX_FLAG_RESOURCE_NAME_VALID | ACTCTX_FLAG_SET_PROCESS_DEFAULT;
-                pActCtx.lpSource = pszText;
-                pActCtx.lpResourceName = cast(TCHAR*)MANIFEST_RESOURCE_ID;
-                HANDLE hActCtx = OS.CreateActCtx (&pActCtx);
-                if (pszText !is null) OS.HeapFree (hHeap, 0, pszText);
-                uint lpCookie;
-                OS.ActivateActCtx (hActCtx, &lpCookie);
-                /*
-                * NOTE:  A single activation context is created and activated
-                * for the entire lifetime of the program.  It is deactivated
-                * and released by Windows when the program exits.
-                */
-        //}
-+/
-        }
+        
+        enableVisualStyles();
+
         /* Make the process DPI aware for Windows Vista */
         if (OS.WIN32_VERSION >= OS.VERSION (6, 0)) OS.SetProcessDPIAware ();
 
@@ -410,8 +346,95 @@
         SHELL32_MINOR = dvi.dwMinorVersion;
         SHELL32_VERSION = VERSION (SHELL32_MAJOR, SHELL32_MINOR);
     }
-
+    
+    /**************************************************************************
+    
+    **************************************************************************/
+    
+    public static void enableVisualStyles()
+    {
+        if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (5, 1)) {
+            const char[] manifest = 
+            `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+            <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
+                <assemblyIdentity 
+                    version="1.0.0.0" 
+                    processorArchitecture="X86" 
+                    name="dwt" 
+                    type="win32"/>
+                <description>D Widget Toolkit</description>
+                <dependency>
+                    <dependentAssembly>
+                        <assemblyIdentity type="win32" 
+                            name="Microsoft.Windows.Common-Controls" 
+                            version="6.0.0.0" processorArchitecture="X86" 
+                            publicKeyToken="6595b64144ccf1df" 
+                            language="*"/>
+                    </dependentAssembly>
+                </dependency>
+            </assembly>`;
+
+            scope temp = new tango.io.TempFile.TempFile(tango.io.TempFile.TempFile.Permanent);
+            temp.write(manifest);
+            temp.detach();
+
+            ACTCTX actctx;
+            actctx.cbSize = actctx.sizeof;
+            actctx.dwFlags = 0;
+            actctx.lpSource = StrToTCHARz( 0, temp.toString );
+
+            // Create the activation context
+            HANDLE hActCtx = OS.CreateActCtx(&actctx);
+
+            // Did we fail creating the activation context?
+            if (hActCtx is INVALID_HANDLE_VALUE){
+                Trace.formatln("The Activation Context could not be created");
+            } else {
+                // Activate the context and make use of it
+                ULONG_PTR ulpActivationCookie;
+                if (!OS.ActivateActCtx(hActCtx, &ulpActivationCookie)){
+                    Trace.formatln("The Activation Context failed to load");
+                }
+            }
+
+            temp.path.remove();
+
+/+         
+            //if (System.getProperty (NO_MANIFEST) is null) {
+                TCHAR[] buffer = new TCHAR[ MAX_PATH ];
+                HANDLE hModule = OS.GetLibraryHandle ();
+                while (OS.GetModuleFileName (hModule, buffer.ptr, buffer.length ) is buffer.length ) {
+                    buffer.length = buffer.length + MAX_PATH;
+                }
+                auto hHeap = OS.GetProcessHeap ();
+                int byteCount = buffer.length * TCHAR.sizeof;
+                TCHAR* pszText = cast(TCHAR*) OS.HeapAlloc (hHeap, HEAP_ZERO_MEMORY, byteCount);
+                OS.MoveMemory (pszText, buffer.ptr, byteCount);
+                ACTCTX pActCtx;
+                pActCtx.cbSize = ACTCTX.sizeof;
+                pActCtx.dwFlags = ACTCTX_FLAG_RESOURCE_NAME_VALID | ACTCTX_FLAG_SET_PROCESS_DEFAULT;
+                pActCtx.lpSource = pszText;
+                pActCtx.lpResourceName = cast(TCHAR*)MANIFEST_RESOURCE_ID;
+                HANDLE hActCtx = OS.CreateActCtx (&pActCtx);
+                if (pszText !is null) OS.HeapFree (hHeap, 0, pszText);
+                uint lpCookie;
+                OS.ActivateActCtx (hActCtx, &lpCookie);
+                /*
+                * NOTE:  A single activation context is created and activated
+                * for the entire lifetime of the program.  It is deactivated
+                * and released by Windows when the program exits.
+                */
+        //}
++/
+        }
+    }
+    
+    /**************************************************************************
+    
+    **************************************************************************/
+         
     /* Flag used on WinCE */
+    
     static const int SYS_COLOR_INDEX_FLAG = OS.IsWinCE ? 0x40000000 : 0x0;
 
     /*