comparison dwt/internal/win32/OS.d @ 188:03f179597782

Make WinXP themes work with windows resources
author Frank Benoit <benoit@tionex.de>
date Sat, 15 Mar 2008 00:33:19 +0100
parents 52c185ec49e8
children f804bcfb9e49
comparison
equal deleted inserted replaced
187:bcdc37794717 188:03f179597782
17 alias dwt.internal.win32.WINAPI WINAPI; 17 alias dwt.internal.win32.WINAPI WINAPI;
18 18
19 import dwt.internal.C; 19 import dwt.internal.C;
20 import dwt.internal.Library; 20 import dwt.internal.Library;
21 import tango.sys.SharedLib : SharedLib; 21 import tango.sys.SharedLib : SharedLib;
22 import tango.sys.Common : SysError;
22 static import tango.stdc.stdlib; 23 static import tango.stdc.stdlib;
23 24
24 import tango.stdc.string : memset; 25 import tango.stdc.string : memset;
25 import tango.stdc.stringz : toString16z; 26 import tango.stdc.stringz : toString16z;
26 import tango.text.convert.Utf : toString16; 27 import tango.text.convert.Utf : toString16;
165 public static const int VER_PLATFORM_WIN32_NT = 2; 166 public static const int VER_PLATFORM_WIN32_NT = 2;
166 public static const int VER_PLATFORM_WIN32_CE = 3; 167 public static const int VER_PLATFORM_WIN32_CE = 3;
167 168
168 /* Forward references */ 169 /* Forward references */
169 public static const int HEAP_ZERO_MEMORY = 0x8; 170 public static const int HEAP_ZERO_MEMORY = 0x8;
170 public static const int ACTCTX_FLAG_RESOURCE_NAME_VALID = 0x00000008; 171 public static const int ACTCTX_FLAG_RESOURCE_NAME_VALID = 0x00000008;
171 public static const int ACTCTX_FLAG_SET_PROCESS_DEFAULT = 0x00000010; 172 public static const int ACTCTX_FLAG_SET_PROCESS_DEFAULT = 0x00000010;
172 public static const int MANIFEST_RESOURCE_ID = 2; 173 public static const int ACTCTX_FLAG_APPLICATION_NAME_VALID = 0x00000020;
174 public static const int ACTCTX_FLAG_OVERRIDEMANIFEST_VALID = 0x00000100;
175 public static const TCHAR* MANIFEST_RESOURCE_ID = cast(TCHAR*)2;
173 public static const int SM_DBCSENABLED = 0x2A; 176 public static const int SM_DBCSENABLED = 0x2A;
174 public static const int SM_IMMENABLED = 0x52; 177 public static const int SM_IMMENABLED = 0x52;
175 public static const int LANG_KOREAN = 0x12; 178 public static const int LANG_KOREAN = 0x12;
176 public static const int MAX_PATH = 260; 179 public static const int MAX_PATH = 260;
177 180
246 } 249 }
247 WIN32_MAJOR = info.dwMajorVersion; 250 WIN32_MAJOR = info.dwMajorVersion;
248 WIN32_MINOR = info.dwMinorVersion; 251 WIN32_MINOR = info.dwMinorVersion;
249 WIN32_VERSION = VERSION (WIN32_MAJOR, WIN32_MINOR); 252 WIN32_VERSION = VERSION (WIN32_MAJOR, WIN32_MINOR);
250 253
254 if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (5, 1)) {
255 loadLib( Symbols_Kernel32, `Kernel32.dll` );
256 }
257
258 //PORTING_CHANGE: made by version
259 //IsUnicode = !IsWin32s && !IsWin95;
260
261 /* Load the manifest to force the XP Theme */
262 enableVisualStyles();
263
251 // when to load uxtheme 264 // when to load uxtheme
252 if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (5, 1)) { 265 if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (5, 1)) {
253 loadLib( Symbols_UxTheme, `UxTheme.dll` ); 266 loadLib( Symbols_UxTheme, `UxTheme.dll` );
254 } 267 }
255 if (OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (5, 1)) { 268 if (OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (5, 1)) {
259 loadLib( Symbols_User32, `User32.dll` ); 272 loadLib( Symbols_User32, `User32.dll` );
260 } 273 }
261 if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (4, 0)) { 274 if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (4, 0)) {
262 loadLib( Symbols_Imm32, `Imm32.dll` ); 275 loadLib( Symbols_Imm32, `Imm32.dll` );
263 } 276 }
264 if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (5, 1)) {
265 loadLib( Symbols_Kernel32, `Kernel32.dll` );
266 }
267
268 //PORTING_CHANGE: made by version
269 //IsUnicode = !IsWin32s && !IsWin95;
270
271 /* Load the manifest to force the XP Theme */
272
273 enableVisualStyles();
274 277
275 /* Make the process DPI aware for Windows Vista */ 278 /* Make the process DPI aware for Windows Vista */
276 if (OS.WIN32_VERSION >= OS.VERSION (6, 0)) OS.SetProcessDPIAware (); 279 if (OS.WIN32_VERSION >= OS.VERSION (6, 0)) OS.SetProcessDPIAware ();
277 280
278 /* Get the DBCS flag */ 281 /* Get the DBCS flag */
344 } 347 }
345 SHELL32_MAJOR = dvi.dwMajorVersion; 348 SHELL32_MAJOR = dvi.dwMajorVersion;
346 SHELL32_MINOR = dvi.dwMinorVersion; 349 SHELL32_MINOR = dvi.dwMinorVersion;
347 SHELL32_VERSION = VERSION (SHELL32_MAJOR, SHELL32_MINOR); 350 SHELL32_VERSION = VERSION (SHELL32_MAJOR, SHELL32_MINOR);
348 } 351 }
349 352
350 /************************************************************************** 353 /**************************************************************************
351 354
352 **************************************************************************/ 355 **************************************************************************/
353 356
354 public static void enableVisualStyles() 357 public static void enableVisualStyles() {
355 { 358 void printError( char[] msg ){
356 if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (5, 1)) { 359 char[] winMsg = SysError.lastMsg();
357 const char[] manifest = 360 char[2000] buf;
358 `<?xml version="1.0" encoding="UTF-8" standalone="yes"?> 361 Trace.formatln("{}: {}", msg, CodePage.from( winMsg, buf ) );
359 <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> 362 }
360 <assemblyIdentity 363 TCHAR[] buffer = new TCHAR[ MAX_PATH ];
361 version="1.0.0.0" 364 buffer[] = 0;
362 processorArchitecture="X86" 365 HANDLE hModule = OS.GetLibraryHandle ();
363 name="dwt" 366 while (OS.GetModuleFileName (hModule, buffer.ptr, buffer.length ) is buffer.length ) {
364 type="win32"/> 367 buffer.length = buffer.length + MAX_PATH;
365 <description>D Widget Toolkit</description> 368 buffer[] = 0;
366 <dependency> 369 }
367 <dependentAssembly> 370 auto hHeap = OS.GetProcessHeap ();
368 <assemblyIdentity type="win32" 371 int byteCount = buffer.length * TCHAR.sizeof;
369 name="Microsoft.Windows.Common-Controls" 372 TCHAR* pszText = cast(TCHAR*) OS.HeapAlloc (hHeap, HEAP_ZERO_MEMORY, byteCount);
370 version="6.0.0.0" processorArchitecture="X86" 373 OS.MoveMemory (pszText, buffer.ptr, byteCount);
371 publicKeyToken="6595b64144ccf1df" 374
372 language="*"/> 375 ACTCTX pActCtx;
373 </dependentAssembly> 376 pActCtx.cbSize = ACTCTX.sizeof;
374 </dependency> 377 pActCtx.dwFlags = 0
375 </assembly>`; 378 | ACTCTX_FLAG_RESOURCE_NAME_VALID
376 379 | ACTCTX_FLAG_SET_PROCESS_DEFAULT
377 scope temp = new tango.io.TempFile.TempFile(tango.io.TempFile.TempFile.Permanent); 380 ;
378 temp.write(manifest); 381 pActCtx.lpSource = pszText;
379 temp.detach(); 382 pActCtx.lpApplicationName = pszText;
380 383 pActCtx.lpResourceName = MANIFEST_RESOURCE_ID;
381 ACTCTX actctx; 384 HANDLE hActCtx = OS.CreateActCtx (&pActCtx);
382 actctx.cbSize = actctx.sizeof; 385 if (hActCtx is INVALID_HANDLE_VALUE){
383 actctx.dwFlags = 0; 386 printError("CreateActCtx failed" );
384 actctx.lpSource = StrToTCHARz( 0, temp.toString ); 387 }
385 388 else{
386 // Create the activation context 389 ULONG_PTR ulpActivationCookie;
387 HANDLE hActCtx = OS.CreateActCtx(&actctx); 390 if (!OS.ActivateActCtx(hActCtx, &ulpActivationCookie)){
388 391 printError("ActivateActCtx failed" );
389 // Did we fail creating the activation context?
390 if (hActCtx is INVALID_HANDLE_VALUE){
391 Trace.formatln("The Activation Context could not be created");
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 }
398 } 392 }
399
400 temp.path.remove();
401
402 /+
403 //if (System.getProperty (NO_MANIFEST) is null) {
404 TCHAR[] buffer = new TCHAR[ MAX_PATH ];
405 HANDLE hModule = OS.GetLibraryHandle ();
406 while (OS.GetModuleFileName (hModule, buffer.ptr, buffer.length ) is buffer.length ) {
407 buffer.length = buffer.length + MAX_PATH;
408 }
409 auto hHeap = OS.GetProcessHeap ();
410 int byteCount = buffer.length * TCHAR.sizeof;
411 TCHAR* pszText = cast(TCHAR*) OS.HeapAlloc (hHeap, HEAP_ZERO_MEMORY, byteCount);
412 OS.MoveMemory (pszText, buffer.ptr, byteCount);
413 ACTCTX pActCtx;
414 pActCtx.cbSize = ACTCTX.sizeof;
415 pActCtx.dwFlags = ACTCTX_FLAG_RESOURCE_NAME_VALID | ACTCTX_FLAG_SET_PROCESS_DEFAULT;
416 pActCtx.lpSource = pszText;
417 pActCtx.lpResourceName = cast(TCHAR*)MANIFEST_RESOURCE_ID;
418 HANDLE hActCtx = OS.CreateActCtx (&pActCtx);
419 if (pszText !is null) OS.HeapFree (hHeap, 0, pszText);
420 uint lpCookie;
421 OS.ActivateActCtx (hActCtx, &lpCookie);
422 /*
423 * NOTE: A single activation context is created and activated
424 * for the entire lifetime of the program. It is deactivated
425 * and released by Windows when the program exits.
426 */
427 //}
428 +/
429 } 393 }
430 } 394
431 395 if (pszText !is null){
396 OS.HeapFree (hHeap, 0, pszText);
397 }
398
399 /*
400 * NOTE: A single activation context is created and activated
401 * for the entire lifetime of the program. It is deactivated
402 * and released by Windows when the program exits.
403 */
404 }
405
432 /************************************************************************** 406 /**************************************************************************
433 407
434 **************************************************************************/ 408 **************************************************************************/
435 409
436 /* Flag used on WinCE */ 410 /* Flag used on WinCE */
437 411
438 static const int SYS_COLOR_INDEX_FLAG = OS.IsWinCE ? 0x40000000 : 0x0; 412 static const int SYS_COLOR_INDEX_FLAG = OS.IsWinCE ? 0x40000000 : 0x0;
439 413
440 /* 414 /*
441 * NOTE: There is a bug in JVM 1.2 where loading 415 * NOTE: There is a bug in JVM 1.2 where loading
442 * a class with a large number of constants causes 416 * a class with a large number of constants causes