Changeset 161:d6bf6a720cde

Show
Ignore:
Timestamp:
02/17/08 12:30:11 (10 months ago)
Author:
John Reimer <terminal.node@gmail.com>
Children:

162:619faee45ef6 165:07ed83d51a19

branch:
default
Message:

Minor cleanup and organization of Activation Context Code

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • dwt/internal/win32/OS.d

    r143 r161  
    155155    public static const int SHELL32_MAJOR, SHELL32_MINOR, SHELL32_VERSION; 
    156156 
    157     public static const char[] NO_MANIFEST = "org.eclipse.swt.internal.win32.OS.NO_MANIFEST"; 
     157    public static const char[] NO_MANIFEST = "dwt.internal.win32.OS.NO_MANIFEST"; 
    158158 
    159159 
     
    270270 
    271271        /* Load the manifest to force the XP Theme */ 
     272         
     273        enableVisualStyles(); 
     274 
     275        /* Make the process DPI aware for Windows Vista */ 
     276        if (OS.WIN32_VERSION >= OS.VERSION (6, 0)) OS.SetProcessDPIAware (); 
     277 
     278        /* Get the DBCS flag */ 
     279        BOOL dbcsEnabled = OS.GetSystemMetrics (SM_DBCSENABLED) !is 0; 
     280        BOOL immEnabled = OS.GetSystemMetrics (SM_IMMENABLED) !is 0; 
     281        IsDBLocale = dbcsEnabled || immEnabled; 
     282 
     283        /* 
     284        * Bug in Windows.  On Korean Windows XP when the Text 
     285        * Services Framework support for legacy applications 
     286        * is enabled, certain legacy calls segment fault. 
     287        * For example, when ImmSetCompositionWindow() is used 
     288        * to move the composition window outside of the client 
     289        * area, Windows crashes.  The fix is to disable legacy 
     290        * support. 
     291        * 
     292        * Note: The bug is fixed in Service Pack 2. 
     293        */ 
     294        if (!OS.IsWinCE && OS.WIN32_VERSION is OS.VERSION (5, 1)) { 
     295            short langID = OS.GetSystemDefaultUILanguage (); 
     296            short primaryLang = OS.PRIMARYLANGID (langID); 
     297            if (primaryLang is LANG_KOREAN) { 
     298                OSVERSIONINFOEX infoex; 
     299                infoex.dwOSVersionInfoSize = OSVERSIONINFOEX.sizeof; 
     300                GetVersionEx (cast(OSVERSIONINFO*) &infoex ); 
     301                if (infoex.wServicePackMajor < 2) { 
     302                    OS.ImmDisableTextFrameService (0); 
     303                } 
     304            } 
     305        } 
     306 
     307        /* Get the COMCTL32.DLL version */ 
     308        DLLVERSIONINFO dvi; 
     309        dvi.cbSize = DLLVERSIONINFO.sizeof; 
     310        dvi.dwMajorVersion = 4; 
     311        dvi.dwMinorVersion = 0; 
     312        //PORTING_CHANGE: comctl is loaded automatically 
     313        //TCHAR lpLibFileName = new TCHAR (0, "comctl32.dll", true); //$NON-NLS-1$ 
     314        //int /*long*/ hModule = OS.LoadLibrary (lpLibFileName); 
     315        if (auto lib = SharedLib.load( `comctl32.dll`) ) { 
     316            char[] name = "DllGetVersion\0"; //$NON-NLS-1$ 
     317            void* DllGetVersion = lib.getSymbol(name.ptr); 
     318            if (DllGetVersion !is null){ 
     319                alias extern(Windows) void function(DLLVERSIONINFO*) TDllVersion; 
     320                TDllVersion f = cast( TDllVersion )DllGetVersion; 
     321                f(&dvi); 
     322            } 
     323            lib.unload(); 
     324        } 
     325        COMCTL32_MAJOR = dvi.dwMajorVersion; 
     326        COMCTL32_MINOR = dvi.dwMinorVersion; 
     327        COMCTL32_VERSION = VERSION (COMCTL32_MAJOR, COMCTL32_MINOR); 
     328 
     329        /* Get the Shell32.DLL version */ 
     330        dvi = DLLVERSIONINFO.init; 
     331        dvi.cbSize = DLLVERSIONINFO.sizeof; 
     332        dvi.dwMajorVersion = 4; 
     333        //TCHAR lpLibFileName = new TCHAR (0, "Shell32.dll", true); //$NON-NLS-1$ 
     334        //int /*long*/ hModule = OS.LoadLibrary (lpLibFileName); 
     335        if ( auto lib = SharedLib.load( `Shell32.dll`)) { 
     336            char[] name = "DllGetVersion\0"; //$NON-NLS-1$ 
     337            void* DllGetVersion = lib.getSymbol(name.ptr); 
     338            if (DllGetVersion !is null){ 
     339                alias extern(Windows) void function(DLLVERSIONINFO*) TDllVersion; 
     340                TDllVersion f = cast( TDllVersion )DllGetVersion; 
     341                f(&dvi); 
     342            } 
     343            lib.unload(); 
     344        } 
     345        SHELL32_MAJOR = dvi.dwMajorVersion; 
     346        SHELL32_MINOR = dvi.dwMinorVersion; 
     347        SHELL32_VERSION = VERSION (SHELL32_MAJOR, SHELL32_MINOR); 
     348    } 
     349     
     350    /************************************************************************** 
     351     
     352    **************************************************************************/ 
     353     
     354    public static void enableVisualStyles() 
     355    { 
    272356        if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (5, 1)) { 
    273  
    274             const char[] manifest = `<?xml version="1.0" encoding="UTF-8" standalone="yes"?> 
    275 <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> 
    276     <assemblyIdentity version="1.0.0.0" processorArchitecture="X86" name="dwt" type="win32"/> 
    277     <description>D Widget Toolkit</description> 
    278     <dependency> 
    279         <dependentAssembly> 
    280             <assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="X86" publicKeyToken="6595b64144ccf1df" language="*"/> 
    281         </dependentAssembly> 
    282     </dependency> 
    283 </assembly>`; 
     357            const char[] manifest =  
     358            `<?xml version="1.0" encoding="UTF-8" standalone="yes"?> 
     359            <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> 
     360                <assemblyIdentity  
     361                    version="1.0.0.0"  
     362                    processorArchitecture="X86"  
     363                    name="dwt"  
     364                    type="win32"/> 
     365                <description>D Widget Toolkit</description> 
     366                <dependency> 
     367                    <dependentAssembly> 
     368                        <assemblyIdentity type="win32"  
     369                            name="Microsoft.Windows.Common-Controls"  
     370                            version="6.0.0.0" processorArchitecture="X86"  
     371                            publicKeyToken="6595b64144ccf1df"  
     372                            language="*"/> 
     373                    </dependentAssembly> 
     374                </dependency> 
     375            </assembly>`; 
    284376 
    285377            scope temp = new tango.io.TempFile.TempFile(tango.io.TempFile.TempFile.Permanent); 
     
    289381            ACTCTX actctx; 
    290382            actctx.cbSize = actctx.sizeof; 
     383            actctx.dwFlags = 0; 
    291384            actctx.lpSource = StrToTCHARz( 0, temp.toString ); 
    292385 
     
    297390            if (hActCtx is INVALID_HANDLE_VALUE){ 
    298391                Trace.formatln("The Activation Context could not be created"); 
    299                 goto LActCtxError; 
     392            } else { 
     393                // Activate the context and make use of it 
     394                ULONG_PTR ulpActivationCookie; 
     395                if (!OS.ActivateActCtx(hActCtx, &ulpActivationCookie)){ 
     396                    Trace.formatln("The Activation Context failed to load"); 
     397                } 
    300398            } 
    301399 
    302             // Activate the context and make use of it 
    303             ULONG_PTR ulpActivationCookie; 
    304             if (!OS.ActivateActCtx(hActCtx, &ulpActivationCookie)){ 
    305                 Trace.formatln("The Activation Context failed to load"); 
    306                 goto LActCtxError; 
    307             } 
    308  
    309     LActCtxError: 
    310400            temp.path.remove(); 
    311401 
    312 /+         //if (System.getProperty (NO_MANIFEST) is null) { 
     402/+          
     403            //if (System.getProperty (NO_MANIFEST) is null) { 
    313404                TCHAR[] buffer = new TCHAR[ MAX_PATH ]; 
    314405                HANDLE hModule = OS.GetLibraryHandle (); 
     
    337428+/ 
    338429        } 
    339         /* Make the process DPI aware for Windows Vista */ 
    340         if (OS.WIN32_VERSION >= OS.VERSION (6, 0)) OS.SetProcessDPIAware (); 
    341  
    342         /* Get the DBCS flag */ 
    343         BOOL dbcsEnabled = OS.GetSystemMetrics (SM_DBCSENABLED) !is 0; 
    344         BOOL immEnabled = OS.GetSystemMetrics (SM_IMMENABLED) !is 0; 
    345         IsDBLocale = dbcsEnabled || immEnabled; 
    346  
    347         /* 
    348         * Bug in Windows.  On Korean Windows XP when the Text 
    349         * Services Framework support for legacy applications 
    350         * is enabled, certain legacy calls segment fault. 
    351         * For example, when ImmSetCompositionWindow() is used 
    352         * to move the composition window outside of the client 
    353         * area, Windows crashes.  The fix is to disable legacy 
    354         * support. 
    355         * 
    356         * Note: The bug is fixed in Service Pack 2. 
    357         */ 
    358         if (!OS.IsWinCE && OS.WIN32_VERSION is OS.VERSION (5, 1)) { 
    359             short langID = OS.GetSystemDefaultUILanguage (); 
    360             short primaryLang = OS.PRIMARYLANGID (langID); 
    361             if (primaryLang is LANG_KOREAN) { 
    362                 OSVERSIONINFOEX infoex; 
    363                 infoex.dwOSVersionInfoSize = OSVERSIONINFOEX.sizeof; 
    364                 GetVersionEx (cast(OSVERSIONINFO*) &infoex ); 
    365                 if (infoex.wServicePackMajor < 2) { 
    366                     OS.ImmDisableTextFrameService (0); 
    367                 } 
    368             } 
    369         } 
    370  
    371         /* Get the COMCTL32.DLL version */ 
    372         DLLVERSIONINFO dvi; 
    373         dvi.cbSize = DLLVERSIONINFO.sizeof; 
    374         dvi.dwMajorVersion = 4; 
    375         dvi.dwMinorVersion = 0; 
    376         //PORTING_CHANGE: comctl is loaded automatically 
    377         //TCHAR lpLibFileName = new TCHAR (0, "comctl32.dll", true); //$NON-NLS-1$ 
    378         //int /*long*/ hModule = OS.LoadLibrary (lpLibFileName); 
    379         if (auto lib = SharedLib.load( `comctl32.dll`) ) { 
    380             char[] name = "DllGetVersion\0"; //$NON-NLS-1$ 
    381             void* DllGetVersion = lib.getSymbol(name.ptr); 
    382             if (DllGetVersion !is null){ 
    383                 alias extern(Windows) void function(DLLVERSIONINFO*) TDllVersion; 
    384                 TDllVersion f = cast( TDllVersion )DllGetVersion; 
    385                 f(&dvi); 
    386             } 
    387             lib.unload(); 
    388         } 
    389         COMCTL32_MAJOR = dvi.dwMajorVersion; 
    390         COMCTL32_MINOR = dvi.dwMinorVersion; 
    391         COMCTL32_VERSION = VERSION (COMCTL32_MAJOR, COMCTL32_MINOR); 
    392  
    393         /* Get the Shell32.DLL version */ 
    394         dvi = DLLVERSIONINFO.init; 
    395         dvi.cbSize = DLLVERSIONINFO.sizeof; 
    396         dvi.dwMajorVersion = 4; 
    397         //TCHAR lpLibFileName = new TCHAR (0, "Shell32.dll", true); //$NON-NLS-1$ 
    398         //int /*long*/ hModule = OS.LoadLibrary (lpLibFileName); 
    399         if ( auto lib = SharedLib.load( `Shell32.dll`)) { 
    400             char[] name = "DllGetVersion\0"; //$NON-NLS-1$ 
    401             void* DllGetVersion = lib.getSymbol(name.ptr); 
    402             if (DllGetVersion !is null){ 
    403                 alias extern(Windows) void function(DLLVERSIONINFO*) TDllVersion; 
    404                 TDllVersion f = cast( TDllVersion )DllGetVersion; 
    405                 f(&dvi); 
    406             } 
    407             lib.unload(); 
    408         } 
    409         SHELL32_MAJOR = dvi.dwMajorVersion; 
    410         SHELL32_MINOR = dvi.dwMinorVersion; 
    411         SHELL32_VERSION = VERSION (SHELL32_MAJOR, SHELL32_MINOR); 
    412     } 
    413  
     430    } 
     431     
     432    /************************************************************************** 
     433     
     434    **************************************************************************/ 
     435          
    414436    /* Flag used on WinCE */ 
     437     
    415438    static const int SYS_COLOR_INDEX_FLAG = OS.IsWinCE ? 0x40000000 : 0x0; 
    416439