annotate src/windows/native/sun/windows/awt_DesktopProperties.cpp @ 7441:cf14f699f36c

8009071: Improve shape handling Reviewed-by: art, mschoene
author anthony
date Thu, 18 Apr 2013 13:52:38 +0100
parents 1785f8335f4d
children 8b1f1c2a400f
rev   line source
duke@0 1 /*
VKARNAUK@5837 2 * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
duke@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@0 4 *
duke@0 5 * This code is free software; you can redistribute it and/or modify it
duke@0 6 * under the terms of the GNU General Public License version 2 only, as
ohair@2362 7 * published by the Free Software Foundation. Oracle designates this
duke@0 8 * particular file as subject to the "Classpath" exception as provided
ohair@2362 9 * by Oracle in the LICENSE file that accompanied this code.
duke@0 10 *
duke@0 11 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@0 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@0 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@0 14 * version 2 for more details (a copy is included in the LICENSE file that
duke@0 15 * accompanied this code).
duke@0 16 *
duke@0 17 * You should have received a copy of the GNU General Public License version
duke@0 18 * 2 along with this work; if not, write to the Free Software Foundation,
duke@0 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@0 20 *
ohair@2362 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@2362 22 * or visit www.oracle.com if you need additional information or have any
ohair@2362 23 * questions.
duke@0 24 */
duke@0 25
art@862 26 #include "awt.h"
duke@0 27 #include "mmsystem.h"
duke@0 28 #include "jlong.h"
duke@0 29 #include "awt_DesktopProperties.h"
art@862 30 #include "awt_Toolkit.h"
duke@0 31 #include "sun_awt_windows_WDesktopProperties.h"
duke@0 32 #include "java_awt_Font.h"
duke@0 33 #include "awtmsg.h"
art@862 34 #include "zmouse.h"
art@862 35 #include <shellapi.h>
art@862 36 #include <shlobj.h>
duke@0 37
duke@0 38 // WDesktopProperties fields
duke@0 39 jfieldID AwtDesktopProperties::pDataID = 0;
duke@0 40 jmethodID AwtDesktopProperties::setBooleanPropertyID = 0;
duke@0 41 jmethodID AwtDesktopProperties::setIntegerPropertyID = 0;
duke@0 42 jmethodID AwtDesktopProperties::setStringPropertyID = 0;
duke@0 43 jmethodID AwtDesktopProperties::setColorPropertyID = 0;
duke@0 44 jmethodID AwtDesktopProperties::setFontPropertyID = 0;
duke@0 45 jmethodID AwtDesktopProperties::setSoundPropertyID = 0;
duke@0 46
duke@0 47 AwtDesktopProperties::AwtDesktopProperties(jobject self) {
duke@0 48 this->self = GetEnv()->NewGlobalRef(self);
duke@0 49 GetEnv()->SetLongField( self, AwtDesktopProperties::pDataID,
duke@0 50 ptr_to_jlong(this) );
duke@0 51 }
duke@0 52
duke@0 53 AwtDesktopProperties::~AwtDesktopProperties() {
duke@0 54 GetEnv()->DeleteGlobalRef(self);
duke@0 55 }
duke@0 56
duke@0 57 //
duke@0 58 // Reads Windows parameters and sets the corresponding values
duke@0 59 // in WDesktopProperties
duke@0 60 //
duke@0 61 void AwtDesktopProperties::GetWindowsParameters() {
duke@0 62 if (GetEnv()->EnsureLocalCapacity(MAX_PROPERTIES) < 0) {
duke@0 63 DASSERT(0);
duke@0 64 return;
duke@0 65 }
duke@0 66 // this number defines the set of properties available, it is incremented
duke@0 67 // whenever more properties are added (in a public release of course)
duke@0 68 // for example, version 1 defines the properties available in Java SDK version 1.3.
duke@0 69 SetIntegerProperty( TEXT("win.properties.version"), AWT_DESKTOP_PROPERTIES_VERSION);
duke@0 70 GetNonClientParameters();
duke@0 71 GetIconParameters();
duke@0 72 GetColorParameters();
VKARNAUK@5837 73 GetCaretParameters();
duke@0 74 GetOtherParameters();
duke@0 75 GetSoundEvents();
duke@0 76 GetSystemProperties();
duke@0 77 if (IS_WINXP) {
duke@0 78 GetXPStyleProperties();
duke@0 79 }
duke@0 80 }
duke@0 81
duke@0 82 void AwtDesktopProperties::GetSystemProperties() {
duke@0 83 HDC dc = CreateDC(TEXT("DISPLAY"), NULL, NULL, NULL);
duke@0 84
duke@0 85 if (dc != NULL) {
duke@0 86 SetFontProperty(dc, ANSI_FIXED_FONT, TEXT("win.ansiFixed.font"));
duke@0 87 SetFontProperty(dc, ANSI_VAR_FONT, TEXT("win.ansiVar.font"));
duke@0 88 SetFontProperty(dc, DEVICE_DEFAULT_FONT, TEXT("win.deviceDefault.font"));
duke@0 89 SetFontProperty(dc, DEFAULT_GUI_FONT, TEXT("win.defaultGUI.font"));
duke@0 90 SetFontProperty(dc, OEM_FIXED_FONT, TEXT("win.oemFixed.font"));
duke@0 91 SetFontProperty(dc, SYSTEM_FONT, TEXT("win.system.font"));
duke@0 92 SetFontProperty(dc, SYSTEM_FIXED_FONT, TEXT("win.systemFixed.font"));
duke@0 93 DeleteDC(dc);
duke@0 94 }
duke@0 95 }
duke@0 96
duke@0 97
duke@0 98 // Does the actual lookup for shell dialog font (MS Shell Dlg). fontName
duke@0 99 // contains the name to lookup (either MS Shell Dlg or MS Shell Dlg 2) and
duke@0 100 // handle contains a reference toe the registry entry to look in.
duke@0 101 // This will return NULL or a pointer to the resolved name.
duke@0 102 // Note that it uses malloc() and returns the pointer to allocated
duke@0 103 // memory, so remember to use free() when you are done with its
duke@0 104 // result.
duke@0 105 static LPTSTR resolveShellDialogFont(LPTSTR fontName, HKEY handle) {
duke@0 106 DWORD valueType, valueSize;
duke@0 107 if (RegQueryValueEx((HKEY)handle, fontName, NULL,
duke@0 108 &valueType, NULL, &valueSize) != 0) {
duke@0 109 // Couldn't find it
duke@0 110 return NULL;
duke@0 111 }
duke@0 112 if (valueType != REG_SZ) {
duke@0 113 // Not the expected type
duke@0 114 return NULL;
duke@0 115 }
duke@0 116 LPTSTR buffer = (LPTSTR)safe_Malloc(valueSize);
duke@0 117 if (RegQueryValueEx((HKEY)handle, fontName, NULL,
duke@0 118 &valueType, (unsigned char *)buffer, &valueSize) != 0) {
duke@0 119 // Error fetching
duke@0 120 free(buffer);
duke@0 121 return NULL;
duke@0 122 }
duke@0 123 return buffer;
duke@0 124 }
duke@0 125
duke@0 126 // Determines what the font MS Shell Dlg maps to.
duke@0 127 // Note that it uses malloc() and returns the pointer to allocated
duke@0 128 // memory, so remember to use free() when you are done with its
duke@0 129 // result.
duke@0 130 static LPTSTR resolveShellDialogFont() {
duke@0 131 LPTSTR subKey = TEXT("Software\\Microsoft\\Windows NT\\CurrentVersion\\FontSubstitutes");
duke@0 132
duke@0 133 HKEY handle;
duke@0 134 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, subKey, 0, KEY_READ, &handle) != 0) {
duke@0 135 return NULL;
duke@0 136 }
duke@0 137 // Prefer MS Shell Dlg 2.
duke@0 138 LPTSTR font = resolveShellDialogFont(TEXT("MS Shell Dlg 2"), handle);
duke@0 139 if (font == NULL) {
duke@0 140 font = resolveShellDialogFont(TEXT("MS Shell Dlg"), handle);
duke@0 141 }
duke@0 142 RegCloseKey(handle);
duke@0 143 return font;
duke@0 144 }
duke@0 145
duke@0 146 // Local function for getting values from the Windows registry
duke@0 147 // Note that it uses malloc() and returns the pointer to allocated
duke@0 148 // memory, so remember to use free() when you are done with its
duke@0 149 // result.
duke@0 150 static LPTSTR getWindowsPropFromReg(LPTSTR subKey, LPTSTR valueName, DWORD *valueType) {
duke@0 151 HKEY handle;
duke@0 152 if (RegOpenKeyEx(HKEY_CURRENT_USER, subKey, 0, KEY_READ, &handle) != 0) {
duke@0 153 return NULL;
duke@0 154 }
duke@0 155 // valueSize is in bytes, while valueChar is in characters.
duke@0 156 DWORD valueSize, valueChar;
duke@0 157 if (RegQueryValueEx((HKEY)handle, valueName, NULL,
duke@0 158 valueType, NULL, &valueSize) != 0) {
duke@0 159 RegCloseKey(handle);
duke@0 160 return NULL;
duke@0 161 }
duke@0 162 LPTSTR buffer = (LPTSTR)safe_Malloc(valueSize);
duke@0 163 if (RegQueryValueEx((HKEY)handle, valueName, NULL,
duke@0 164 valueType, (unsigned char *)buffer, &valueSize) != 0) {
duke@0 165 free(buffer);
duke@0 166 RegCloseKey(handle);
duke@0 167 return NULL;
duke@0 168 }
duke@0 169 RegCloseKey(handle);
duke@0 170
duke@0 171 if (*valueType == REG_EXPAND_SZ) {
duke@0 172 // Pending: buffer must be null-terminated at this point
duke@0 173 valueChar = ExpandEnvironmentStrings(buffer, NULL, 0);
anthony@7441 174 LPTSTR buffer2 = (LPTSTR)SAFE_SIZE_ARRAY_ALLOC(safe_Malloc, valueChar, sizeof(TCHAR));
duke@0 175 ExpandEnvironmentStrings(buffer, buffer2, valueChar);
duke@0 176 free(buffer);
duke@0 177 return buffer2;
duke@0 178 } else if (*valueType == REG_SZ) {
duke@0 179 return buffer;
duke@0 180 } else if (*valueType == REG_DWORD) {
duke@0 181 return buffer;
duke@0 182 } else {
duke@0 183 free(buffer);
duke@0 184 return NULL;
duke@0 185 }
duke@0 186 }
duke@0 187
duke@0 188 static LPTSTR getXPStylePropFromReg(LPTSTR valueName) {
duke@0 189 DWORD valueType;
duke@0 190 return getWindowsPropFromReg(TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\ThemeManager"),
duke@0 191 valueName, &valueType);
duke@0 192 }
duke@0 193
duke@0 194
duke@0 195 // Used in AwtMenuItem to determine the color of top menus,
duke@0 196 // since they depend on XP style. ThemeActive property is
duke@0 197 // '1' for XP Style, '0' for Windows classic style.
duke@0 198 BOOL AwtDesktopProperties::IsXPStyle() {
duke@0 199 LPTSTR style = getXPStylePropFromReg(TEXT("ThemeActive"));
duke@0 200 BOOL result = (style != NULL && *style == _T('1'));
duke@0 201 free(style);
duke@0 202 return result;
duke@0 203 }
duke@0 204
duke@0 205 void AwtDesktopProperties::GetXPStyleProperties() {
duke@0 206 LPTSTR value;
duke@0 207
duke@0 208 value = getXPStylePropFromReg(TEXT("ThemeActive"));
duke@0 209 SetBooleanProperty(TEXT("win.xpstyle.themeActive"), (value != NULL && *value == _T('1')));
duke@0 210 if (value != NULL) {
duke@0 211 free(value);
duke@0 212 }
duke@0 213 value = getXPStylePropFromReg(TEXT("DllName"));
duke@0 214 if (value != NULL) {
duke@0 215 SetStringProperty(TEXT("win.xpstyle.dllName"), value);
duke@0 216 free(value);
duke@0 217 }
duke@0 218 value = getXPStylePropFromReg(TEXT("SizeName"));
duke@0 219 if (value != NULL) {
duke@0 220 SetStringProperty(TEXT("win.xpstyle.sizeName"), value);
duke@0 221 free(value);
duke@0 222 }
duke@0 223 value = getXPStylePropFromReg(TEXT("ColorName"));
duke@0 224 if (value != NULL) {
duke@0 225 SetStringProperty(TEXT("win.xpstyle.colorName"), value);
duke@0 226 free(value);
duke@0 227 }
duke@0 228 }
duke@0 229
duke@0 230
duke@0 231 void AwtDesktopProperties::GetNonClientParameters() {
duke@0 232 //
duke@0 233 // general window properties
duke@0 234 //
duke@0 235 NONCLIENTMETRICS ncmetrics;
duke@0 236
prr@2324 237 // Fix for 6944516: specify correct size for ncmetrics on WIN2K/XP
prr@2324 238 // Microsoft recommend to subtract the size of 'iPaddedBorderWidth' field
prr@2324 239 // when running on XP. However this can't be referenced at compile time
prr@2324 240 // with the older SDK, so there use 'lfMessageFont' plus its size.
prr@2324 241 if (!IS_WINVISTA) {
art@2859 242 #if defined(_MSC_VER) && (_MSC_VER >= 1600)
prr@2324 243 ncmetrics.cbSize = offsetof(NONCLIENTMETRICS, iPaddedBorderWidth);
prr@2324 244 #else
prr@2324 245 ncmetrics.cbSize = offsetof(NONCLIENTMETRICS,lfMessageFont) + sizeof(LOGFONT);
prr@2324 246 #endif
prr@2324 247 } else {
prr@2324 248 ncmetrics.cbSize = sizeof(ncmetrics);
prr@2324 249 }
duke@0 250 VERIFY( SystemParametersInfo(SPI_GETNONCLIENTMETRICS, ncmetrics.cbSize, &ncmetrics, FALSE) );
duke@0 251
duke@0 252 SetFontProperty( TEXT("win.frame.captionFont"), ncmetrics.lfCaptionFont );
duke@0 253 SetIntegerProperty( TEXT("win.frame.captionHeight"), ncmetrics.iCaptionHeight );
duke@0 254 SetIntegerProperty( TEXT("win.frame.captionButtonWidth"), ncmetrics.iCaptionWidth );
duke@0 255 SetIntegerProperty( TEXT("win.frame.captionButtonHeight"), ncmetrics.iCaptionHeight );
duke@0 256 SetFontProperty( TEXT("win.frame.smallCaptionFont"), ncmetrics.lfSmCaptionFont );
duke@0 257 SetIntegerProperty( TEXT("win.frame.smallCaptionHeight"), ncmetrics.iSmCaptionHeight );
duke@0 258 SetIntegerProperty( TEXT("win.frame.smallCaptionButtonWidth"), ncmetrics.iSmCaptionWidth );
duke@0 259 SetIntegerProperty( TEXT("win.frame.smallCaptionButtonHeight"), ncmetrics.iSmCaptionHeight );
duke@0 260 SetIntegerProperty( TEXT("win.frame.sizingBorderWidth"), ncmetrics.iBorderWidth );
duke@0 261
duke@0 262 // menu properties
duke@0 263 SetFontProperty( TEXT("win.menu.font"), ncmetrics.lfMenuFont );
duke@0 264 SetIntegerProperty( TEXT("win.menu.height"), ncmetrics.iMenuHeight );
duke@0 265 SetIntegerProperty( TEXT("win.menu.buttonWidth"), ncmetrics.iMenuWidth );
duke@0 266
duke@0 267 // scrollbar properties
duke@0 268 SetIntegerProperty( TEXT("win.scrollbar.width"), ncmetrics.iScrollWidth );
duke@0 269 SetIntegerProperty( TEXT("win.scrollbar.height"), ncmetrics.iScrollHeight );
duke@0 270
duke@0 271 // status bar and tooltip properties
duke@0 272 SetFontProperty( TEXT("win.status.font"), ncmetrics.lfStatusFont );
duke@0 273 SetFontProperty( TEXT("win.tooltip.font"), ncmetrics.lfStatusFont );
duke@0 274
duke@0 275 // message box properties
duke@0 276 SetFontProperty( TEXT("win.messagebox.font"), ncmetrics.lfMessageFont );
duke@0 277 }
duke@0 278
duke@0 279 void AwtDesktopProperties::GetIconParameters() {
duke@0 280 //
duke@0 281 // icon properties
duke@0 282 //
duke@0 283 ICONMETRICS iconmetrics;
duke@0 284
duke@0 285 iconmetrics.cbSize = sizeof(iconmetrics);
duke@0 286 VERIFY( SystemParametersInfo(SPI_GETICONMETRICS, iconmetrics.cbSize, &iconmetrics, FALSE) );
duke@0 287
duke@0 288 SetIntegerProperty(TEXT("win.icon.hspacing"), iconmetrics.iHorzSpacing);
duke@0 289 SetIntegerProperty(TEXT("win.icon.vspacing"), iconmetrics.iVertSpacing);
duke@0 290 SetBooleanProperty(TEXT("win.icon.titleWrappingOn"), iconmetrics.iTitleWrap != 0);
duke@0 291 SetFontProperty(TEXT("win.icon.font"), iconmetrics.lfFont);
duke@0 292 }
duke@0 293 /*
duke@0 294 Windows settings for these are also in the registry
duke@0 295 They exist as system wide HKLM: HKEY_LOCAL_MACHINE and
duke@0 296 HKCU: HKEY_CURRENT_USER.
duke@0 297 HKCU\Control Panel\Desktop\FontSmoothing : "0=OFF", "2=ON"
duke@0 298 HKCU\Control Panel\Desktop\FontSmoothingType: 1=Standard, 2=LCD
duke@0 299 HKCU\Control Panel\Desktop\FontSmoothingGamma: 1000->2200
duke@0 300 HKCU\Control Panel\Desktop\FontSmoothingOrientation: 0=BGR, 1=RGB
duke@0 301
duke@0 302 SystemParametersInfo supplies the first three of these but does not
duke@0 303 however expose the Orientation. That has to come from the registry.
duke@0 304
duke@0 305 We go to some small lengths in here to not make queries we don't need.
duke@0 306 Eg if we previously were using standard font smoothing and we still are
duke@0 307 then its unlikely that any change in gamma will have occurred except
duke@0 308 by a program which changed it, and even if it did, we don't need to pick
duke@0 309 it up until someone turns on the LCD option.
duke@0 310 To do: this loop is called once per top-level window so an app with
duke@0 311 N windows will get notified N times. It would save us a small amount of
duke@0 312 redundant work if I could identify the message as being one already processed
duke@0 313 for another window.
duke@0 314 Also presumably a repaint that specifies only a partially damaged window
duke@0 315 isn't one that needs this checking.
duke@0 316 */
duke@0 317
duke@0 318 #define FONTSMOOTHING_OFF 0
duke@0 319 #define FONTSMOOTHING_ON 1
duke@0 320 #define FONTSMOOTHING_STANDARD 1
duke@0 321 #define FONTSMOOTHING_LCD 2
duke@0 322 #define LCD_RGB_ORDER 1
duke@0 323 #define LCD_BGR_ORDER 0
duke@0 324
duke@0 325
duke@0 326 int GetLCDSubPixelOrder() {
duke@0 327 LONG order=99;
duke@0 328 LONG bufferSize = 4;
duke@0 329 HKEY hkeyDesktop;
duke@0 330 static LPCTSTR DESKTOPKEY = TEXT("Control Panel\\Desktop");
duke@0 331 LONG ret = RegOpenKeyEx(HKEY_CURRENT_USER,
duke@0 332 DESKTOPKEY, 0L, KEY_READ, &hkeyDesktop);
duke@0 333 if (ret != ERROR_SUCCESS) {
duke@0 334 return LCD_RGB_ORDER;
duke@0 335 }
duke@0 336 ret = RegQueryValueEx(hkeyDesktop, TEXT("FontSmoothingOrientation"),
duke@0 337 NULL, NULL, (LPBYTE)&order, (LPDWORD)&bufferSize);
duke@0 338 RegCloseKey(hkeyDesktop);
duke@0 339 if (ret != ERROR_SUCCESS) {
duke@0 340 return LCD_RGB_ORDER;
duke@0 341 } else {
duke@0 342 return (int)order;
duke@0 343 }
duke@0 344 }
duke@0 345
duke@0 346 void CheckFontSmoothingSettings(HWND hWnd) {
duke@0 347 static BOOL firstTime = TRUE;
duke@0 348 static BOOL lastFontSmoothing = FALSE;
duke@0 349 static UINT lastFontSmoothingType = FONTSMOOTHING_ON;
duke@0 350 static UINT lastFontSmoothingContrast = 1400;
duke@0 351 static UINT lastSubpixelOrder = LCD_RGB_ORDER;
duke@0 352
duke@0 353 /* If we are called with a window handle it is because there is a
duke@0 354 * message to repaint at least some part of the window which typically
duke@0 355 * is not because of the desktop font settings change. Much more likely
duke@0 356 * its a normal repaint event. If it is because of the rare settings
duke@0 357 * change in that case the update region will be the entire window.
duke@0 358 * Try to as cheaply as possible determine if this is not a call
duke@0 359 * to repaint the whole window by assuming that all such calls will
duke@0 360 * have an update region whose origin is 0,0. Only in that case will
duke@0 361 * we take the hit of checking the settings.
duke@0 362 * Thus we avoid taking the hit of the other calls for most partial
duke@0 363 * expose events, which will never be the result of changes to desktop
duke@0 364 * font settings.
duke@0 365 */
duke@0 366 if (hWnd != NULL) {
duke@0 367 RECT r;
duke@0 368 if (!::GetUpdateRect(hWnd, &r, FALSE) || r.top != 0 || r.left != 0) {
duke@0 369 return;
duke@0 370 }
duke@0 371 }
duke@0 372
duke@0 373 BOOL fontSmoothing = FALSE, settingsChanged;
duke@0 374 UINT fontSmoothingType=0, fontSmoothingContrast=0, subPixelOrder;
duke@0 375
duke@0 376 if (firstTime) {
duke@0 377 SystemParametersInfo(SPI_GETFONTSMOOTHING, 0, &fontSmoothing, 0);
duke@0 378 if (IS_WINXP) {
duke@0 379 SystemParametersInfo(SPI_GETFONTSMOOTHINGTYPE, 0,
duke@0 380 &fontSmoothingType, 0);
duke@0 381 SystemParametersInfo(SPI_GETFONTSMOOTHINGCONTRAST, 0,
duke@0 382 &fontSmoothingContrast, 0);
duke@0 383 }
duke@0 384 lastFontSmoothing = fontSmoothing;
duke@0 385 lastFontSmoothingType = fontSmoothingType;
duke@0 386 lastFontSmoothingContrast = fontSmoothingContrast;
duke@0 387 firstTime = FALSE;
duke@0 388 return;
duke@0 389 } else {
duke@0 390 SystemParametersInfo(SPI_GETFONTSMOOTHING, 0, &fontSmoothing, 0);
duke@0 391 settingsChanged = fontSmoothing != lastFontSmoothing;
duke@0 392 if (!settingsChanged && fontSmoothing == FONTSMOOTHING_OFF) {
duke@0 393 /* no need to check the other settings in this case. */
duke@0 394 return;
duke@0 395 }
duke@0 396 if (IS_WINXP) {
duke@0 397 SystemParametersInfo(SPI_GETFONTSMOOTHINGTYPE, 0,
duke@0 398 &fontSmoothingType, 0);
duke@0 399 settingsChanged |= fontSmoothingType != lastFontSmoothingType;
duke@0 400 if (!settingsChanged &&
duke@0 401 fontSmoothingType == FONTSMOOTHING_STANDARD) {
duke@0 402 /* No need to check any LCD specific settings */
duke@0 403 return;
duke@0 404 } else {
duke@0 405 SystemParametersInfo(SPI_GETFONTSMOOTHINGCONTRAST, 0,
duke@0 406 &fontSmoothingContrast, 0);
duke@0 407 settingsChanged |=
duke@0 408 fontSmoothingContrast != lastFontSmoothingContrast;
duke@0 409 if (fontSmoothingType == FONTSMOOTHING_LCD) {
duke@0 410 // Order is a registry entry so more expensive to check.x
duke@0 411 subPixelOrder = GetLCDSubPixelOrder();
duke@0 412 settingsChanged |= subPixelOrder != lastSubpixelOrder;
duke@0 413 }
duke@0 414 }
duke@0 415 } else {
duke@0 416 if (settingsChanged && fontSmoothing == FONTSMOOTHING_ON) {
duke@0 417 fontSmoothingType = FONTSMOOTHING_STANDARD;
duke@0 418 }
duke@0 419 }
duke@0 420 }
duke@0 421 if (settingsChanged) {
duke@0 422 /* Some of these values may not have been queried, but it shouldn't
duke@0 423 * matter as what's important is to track changes in values we are
duke@0 424 * actually using. The up-call we make here will cause the actual
duke@0 425 * values for everything to get queried and set into the desktop
duke@0 426 * properties.
duke@0 427 */
duke@0 428 lastFontSmoothing = fontSmoothing;
duke@0 429 lastFontSmoothingType = fontSmoothingType;
duke@0 430 lastFontSmoothingContrast = fontSmoothingContrast;
duke@0 431 lastSubpixelOrder = subPixelOrder;
duke@0 432
duke@0 433 jobject peer = AwtToolkit::GetInstance().GetPeer();
duke@0 434 if (peer != NULL) {
duke@0 435 AwtToolkit::GetEnv()->CallVoidMethod(peer,
duke@0 436 AwtToolkit::windowsSettingChangeMID);
duke@0 437 }
duke@0 438 }
duke@0 439 }
duke@0 440
duke@0 441 void AwtDesktopProperties::GetColorParameters() {
duke@0 442
art@862 443 SetColorProperty(TEXT("win.frame.activeCaptionGradientColor"),
art@862 444 GetSysColor(COLOR_GRADIENTACTIVECAPTION));
art@862 445 SetColorProperty(TEXT("win.frame.inactiveCaptionGradientColor"),
art@862 446 GetSysColor(COLOR_GRADIENTINACTIVECAPTION));
art@862 447 SetColorProperty(TEXT("win.item.hotTrackedColor"),
art@862 448 GetSysColor(COLOR_HOTLIGHT));
duke@0 449 SetColorProperty(TEXT("win.3d.darkShadowColor"), GetSysColor(COLOR_3DDKSHADOW));
duke@0 450 SetColorProperty(TEXT("win.3d.backgroundColor"), GetSysColor(COLOR_3DFACE));
duke@0 451 SetColorProperty(TEXT("win.3d.highlightColor"), GetSysColor(COLOR_3DHIGHLIGHT));
duke@0 452 SetColorProperty(TEXT("win.3d.lightColor"), GetSysColor(COLOR_3DLIGHT));
duke@0 453 SetColorProperty(TEXT("win.3d.shadowColor"), GetSysColor(COLOR_3DSHADOW));
duke@0 454 SetColorProperty(TEXT("win.button.textColor"), GetSysColor(COLOR_BTNTEXT));
duke@0 455 SetColorProperty(TEXT("win.desktop.backgroundColor"), GetSysColor(COLOR_DESKTOP));
duke@0 456 SetColorProperty(TEXT("win.frame.activeCaptionColor"), GetSysColor(COLOR_ACTIVECAPTION));
duke@0 457 SetColorProperty(TEXT("win.frame.activeBorderColor"), GetSysColor(COLOR_ACTIVEBORDER));
duke@0 458
duke@0 459 // ?? ?? ??
duke@0 460 SetColorProperty(TEXT("win.frame.color"), GetSysColor(COLOR_WINDOWFRAME)); // ?? WHAT THE HECK DOES THIS MEAN ??
duke@0 461 // ?? ?? ??
duke@0 462
duke@0 463 SetColorProperty(TEXT("win.frame.backgroundColor"), GetSysColor(COLOR_WINDOW));
duke@0 464 SetColorProperty(TEXT("win.frame.captionTextColor"), GetSysColor(COLOR_CAPTIONTEXT));
duke@0 465 SetColorProperty(TEXT("win.frame.inactiveBorderColor"), GetSysColor(COLOR_INACTIVEBORDER));
duke@0 466 SetColorProperty(TEXT("win.frame.inactiveCaptionColor"), GetSysColor(COLOR_INACTIVECAPTION));
duke@0 467 SetColorProperty(TEXT("win.frame.inactiveCaptionTextColor"), GetSysColor(COLOR_INACTIVECAPTIONTEXT));
duke@0 468 SetColorProperty(TEXT("win.frame.textColor"), GetSysColor(COLOR_WINDOWTEXT));
duke@0 469 SetColorProperty(TEXT("win.item.highlightColor"), GetSysColor(COLOR_HIGHLIGHT));
duke@0 470 SetColorProperty(TEXT("win.item.highlightTextColor"), GetSysColor(COLOR_HIGHLIGHTTEXT));
duke@0 471 SetColorProperty(TEXT("win.mdi.backgroundColor"), GetSysColor(COLOR_APPWORKSPACE));
duke@0 472 SetColorProperty(TEXT("win.menu.backgroundColor"), GetSysColor(COLOR_MENU));
duke@0 473 SetColorProperty(TEXT("win.menu.textColor"), GetSysColor(COLOR_MENUTEXT));
duke@0 474 // COLOR_MENUBAR is only defined on WindowsXP. Our binaries are
duke@0 475 // built on NT, hence the below ifdef.
duke@0 476 #ifndef COLOR_MENUBAR
duke@0 477 #define COLOR_MENUBAR 30
duke@0 478 #endif
duke@0 479 SetColorProperty(TEXT("win.menubar.backgroundColor"),
duke@0 480 GetSysColor(IS_WINXP ? COLOR_MENUBAR : COLOR_MENU));
duke@0 481 SetColorProperty(TEXT("win.scrollbar.backgroundColor"), GetSysColor(COLOR_SCROLLBAR));
duke@0 482 SetColorProperty(TEXT("win.text.grayedTextColor"), GetSysColor(COLOR_GRAYTEXT));
duke@0 483 SetColorProperty(TEXT("win.tooltip.backgroundColor"), GetSysColor(COLOR_INFOBK));
duke@0 484 SetColorProperty(TEXT("win.tooltip.textColor"), GetSysColor(COLOR_INFOTEXT));
duke@0 485 }
duke@0 486
duke@0 487 void AwtDesktopProperties::GetOtherParameters() {
duke@0 488 // TODO BEGIN: On NT4, some setttings don't trigger WM_SETTINGCHANGE --
duke@0 489 // check whether this has been fixed on Windows 2000 and Windows 98
duke@0 490 // ECH 10/6/2000 seems to be fixed on NT4 SP5, but not on 98
duke@0 491 SetBooleanProperty(TEXT("win.frame.fullWindowDragsOn"), GetBooleanParameter(SPI_GETDRAGFULLWINDOWS));
duke@0 492 SetBooleanProperty(TEXT("win.text.fontSmoothingOn"), GetBooleanParameter(SPI_GETFONTSMOOTHING));
duke@0 493 // TODO END
duke@0 494
duke@0 495 if (IS_WINXP) {
duke@0 496 SetIntegerProperty(TEXT("win.text.fontSmoothingType"),
duke@0 497 GetIntegerParameter(SPI_GETFONTSMOOTHINGTYPE));
duke@0 498 SetIntegerProperty(TEXT("win.text.fontSmoothingContrast"),
duke@0 499 GetIntegerParameter(SPI_GETFONTSMOOTHINGCONTRAST));
duke@0 500 SetIntegerProperty(TEXT("win.text.fontSmoothingOrientation"),
duke@0 501 GetLCDSubPixelOrder());
duke@0 502 }
duke@0 503
duke@0 504 int cxdrag = GetSystemMetrics(SM_CXDRAG);
duke@0 505 int cydrag = GetSystemMetrics(SM_CYDRAG);
duke@0 506 SetIntegerProperty(TEXT("win.drag.width"), cxdrag);
duke@0 507 SetIntegerProperty(TEXT("win.drag.height"), cydrag);
duke@0 508 SetIntegerProperty(TEXT("DnD.gestureMotionThreshold"), max(cxdrag, cydrag)/2);
dav@2773 509 SetIntegerProperty(TEXT("awt.mouse.numButtons"), AwtToolkit::GetNumberOfButtons());
dav@2773 510
duke@0 511 SetIntegerProperty(TEXT("awt.multiClickInterval"), GetDoubleClickTime());
duke@0 512
duke@0 513 // BEGIN cross-platform properties
duke@0 514 // Note that these are cross-platform properties, but are being stuck into
duke@0 515 // WDesktopProperties. WToolkit.lazilyLoadDesktopProperty() can find them,
duke@0 516 // but if a Toolkit subclass uses the desktopProperties
duke@0 517 // member, these properties won't be there. -bchristi, echawkes
duke@0 518 // This property is called "win.frame.fullWindowDragsOn" above
duke@0 519 // This is one of the properties that don't trigger WM_SETTINGCHANGE
duke@0 520 SetBooleanProperty(TEXT("awt.dynamicLayoutSupported"), GetBooleanParameter(SPI_GETDRAGFULLWINDOWS));
art@862 521 SetBooleanProperty(TEXT("awt.wheelMousePresent"),
art@862 522 ::GetSystemMetrics(SM_MOUSEWHEELPRESENT));
duke@0 523
duke@0 524 // END cross-platform properties
duke@0 525
art@862 526 //DWORD menuShowDelay;
art@862 527 //SystemParametersInfo(SPI_GETMENUSHOWDELAY, 0, &menuShowDelay, 0);
art@862 528 // SetIntegerProperty(TEXT("win.menu.showDelay"), menuShowDelay);
art@862 529 SetBooleanProperty(TEXT("win.frame.captionGradientsOn"), GetBooleanParameter(SPI_GETGRADIENTCAPTIONS));
art@862 530 SetBooleanProperty(TEXT("win.item.hotTrackingOn"), GetBooleanParameter(SPI_GETHOTTRACKING));
duke@0 531
art@862 532 SetBooleanProperty(TEXT("win.menu.keyboardCuesOn"), GetBooleanParameter(SPI_GETKEYBOARDCUES));
duke@0 533
duke@0 534 // High contrast accessibility property
duke@0 535 HIGHCONTRAST contrast;
duke@0 536 contrast.cbSize = sizeof(HIGHCONTRAST);
duke@0 537 if (SystemParametersInfo(SPI_GETHIGHCONTRAST, sizeof(HIGHCONTRAST),
duke@0 538 &contrast, 0) != 0 &&
duke@0 539 (contrast.dwFlags & HCF_HIGHCONTRASTON) == HCF_HIGHCONTRASTON) {
duke@0 540 SetBooleanProperty(TEXT("win.highContrast.on"), TRUE);
duke@0 541 }
duke@0 542 else {
duke@0 543 SetBooleanProperty(TEXT("win.highContrast.on"), FALSE);
duke@0 544 }
duke@0 545
art@862 546 SHELLFLAGSTATE sfs;
art@862 547 ::SHGetSettings(&sfs, SSF_SHOWALLOBJECTS | SSF_SHOWATTRIBCOL);
art@862 548 if (sfs.fShowAllObjects) {
art@862 549 SetBooleanProperty(TEXT("awt.file.showHiddenFiles"), TRUE);
art@862 550 }
art@862 551 else {
art@862 552 SetBooleanProperty(TEXT("awt.file.showHiddenFiles"), FALSE);
art@862 553 }
art@862 554 if (sfs.fShowAttribCol) {
art@862 555 SetBooleanProperty(TEXT("awt.file.showAttribCol"), TRUE);
art@862 556 }
art@862 557 else {
art@862 558 SetBooleanProperty(TEXT("awt.file.showAttribCol"), FALSE);
duke@0 559 }
duke@0 560
duke@0 561 LPTSTR value;
duke@0 562 DWORD valueType;
duke@0 563
duke@0 564 // Shell Icon BPP - only honored on platforms before XP
duke@0 565 value = getWindowsPropFromReg(TEXT("Control Panel\\Desktop\\WindowMetrics"),
duke@0 566 TEXT("Shell Icon BPP"), &valueType);
duke@0 567 if (value != NULL) {
duke@0 568 if (valueType == REG_SZ) {
duke@0 569 SetStringProperty(TEXT("win.icon.shellIconBPP"), value);
duke@0 570 }
duke@0 571 free(value);
duke@0 572 }
duke@0 573
duke@0 574
duke@0 575 // The following registry settings control the file chooser places bar
duke@0 576 // under the Windows L&F. These settings are not present by default, but
duke@0 577 // can be enabled using the TweakUI tool from Microsoft. For more info,
duke@0 578 // see http://msdn.microsoft.com/msdnmag/issues/1100/Registry/
duke@0 579
duke@0 580 // NoPlacesBar is a REG_DWORD, with values 0 or 1
duke@0 581 value = getWindowsPropFromReg(TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\comdlg32"),
duke@0 582 TEXT("NoPlacesBar"), &valueType);
duke@0 583 if (value != NULL) {
duke@0 584 if (valueType == REG_DWORD) {
duke@0 585 SetBooleanProperty(TEXT("win.comdlg.noPlacesBar"), (BOOL)((int)*value != 0));
duke@0 586 }
duke@0 587 free(value);
duke@0 588 }
duke@0 589
duke@0 590 LPTSTR valueName = TEXT("PlaceN");
anthony@7441 591 LPTSTR valueNameBuf = (LPTSTR)SAFE_SIZE_ARRAY_ALLOC(safe_Malloc, (lstrlen(valueName) + 1), sizeof(TCHAR));
duke@0 592 lstrcpy(valueNameBuf, valueName);
duke@0 593
duke@0 594 LPTSTR propKey = TEXT("win.comdlg.placesBarPlaceN");
anthony@7441 595 LPTSTR propKeyBuf = (LPTSTR)SAFE_SIZE_ARRAY_ALLOC(safe_Malloc, (lstrlen(propKey) + 1), sizeof(TCHAR));
duke@0 596 lstrcpy(propKeyBuf, propKey);
duke@0 597
duke@0 598 int i = 0;
duke@0 599 do {
duke@0 600 valueNameBuf[5] = _T('0' + i++);
duke@0 601 propKeyBuf[25] = valueNameBuf[5];
duke@0 602
duke@0 603 LPTSTR key = TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\comdlg32\\PlacesBar");
duke@0 604 if ((value = getWindowsPropFromReg(key, valueNameBuf, &valueType)) != NULL) {
duke@0 605 if (valueType == REG_DWORD) {
duke@0 606 // Value is a CSIDL
duke@0 607 SetIntegerProperty(propKeyBuf, (int)*value);
duke@0 608 } else {
duke@0 609 // Value is a path
duke@0 610 SetStringProperty(propKeyBuf, value);
duke@0 611 }
duke@0 612 free(value);
duke@0 613 }
duke@0 614 } while (value != NULL);
duke@0 615
duke@0 616 free(valueNameBuf);
duke@0 617 free(propKeyBuf);
duke@0 618 }
duke@0 619
duke@0 620 void AwtDesktopProperties::GetSoundEvents() {
duke@0 621 /////
duke@0 622 SetSoundProperty(TEXT("win.sound.default"), TEXT(".Default"));
duke@0 623 SetSoundProperty(TEXT("win.sound.close"), TEXT("Close"));
duke@0 624 SetSoundProperty(TEXT("win.sound.maximize"), TEXT("Maximize"));
duke@0 625 SetSoundProperty(TEXT("win.sound.minimize"), TEXT("Minimize"));
duke@0 626 SetSoundProperty(TEXT("win.sound.menuCommand"), TEXT("MenuCommand"));
duke@0 627 SetSoundProperty(TEXT("win.sound.menuPopup"), TEXT("MenuPopup"));
duke@0 628 SetSoundProperty(TEXT("win.sound.open"), TEXT("Open"));
duke@0 629 SetSoundProperty(TEXT("win.sound.restoreDown"), TEXT("RestoreDown"));
duke@0 630 SetSoundProperty(TEXT("win.sound.restoreUp"), TEXT("RestoreUp"));
duke@0 631 /////
duke@0 632 SetSoundProperty(TEXT("win.sound.asterisk"), TEXT("SystemAsterisk"));
duke@0 633 SetSoundProperty(TEXT("win.sound.exclamation"), TEXT("SystemExclamation"));
duke@0 634 SetSoundProperty(TEXT("win.sound.exit"), TEXT("SystemExit"));
duke@0 635 SetSoundProperty(TEXT("win.sound.hand"), TEXT("SystemHand"));
duke@0 636 SetSoundProperty(TEXT("win.sound.question"), TEXT("SystemQuestion"));
duke@0 637 SetSoundProperty(TEXT("win.sound.start"), TEXT("SystemStart"));
duke@0 638 }
duke@0 639
VKARNAUK@5837 640 void AwtDesktopProperties::GetCaretParameters() {
VKARNAUK@5837 641 SetIntegerProperty(TEXT("win.caret.width"), GetIntegerParameter(SPI_GETCARETWIDTH));
VKARNAUK@5837 642 }
VKARNAUK@5837 643
duke@0 644 BOOL AwtDesktopProperties::GetBooleanParameter(UINT spi) {
duke@0 645 BOOL flag;
duke@0 646 SystemParametersInfo(spi, 0, &flag, 0);
duke@0 647 DASSERT(flag == TRUE || flag == FALSE); // should be simple boolean value
duke@0 648 return flag;
duke@0 649 }
duke@0 650
duke@0 651 UINT AwtDesktopProperties::GetIntegerParameter(UINT spi) {
duke@0 652 UINT retValue;
duke@0 653 SystemParametersInfo(spi, 0, &retValue, 0);
duke@0 654 return retValue;
duke@0 655 }
duke@0 656
duke@0 657 void AwtDesktopProperties::SetStringProperty(LPCTSTR propName, LPTSTR value) {
dav@3292 658 jstring key = JNU_NewStringPlatform(GetEnv(), propName);
duke@0 659 GetEnv()->CallVoidMethod(self,
duke@0 660 AwtDesktopProperties::setStringPropertyID,
duke@0 661 key, JNU_NewStringPlatform(GetEnv(), value));
duke@0 662 GetEnv()->DeleteLocalRef(key);
duke@0 663 }
duke@0 664
duke@0 665 void AwtDesktopProperties::SetIntegerProperty(LPCTSTR propName, int value) {
dav@3292 666 jstring key = JNU_NewStringPlatform(GetEnv(), propName);
duke@0 667 GetEnv()->CallVoidMethod(self,
duke@0 668 AwtDesktopProperties::setIntegerPropertyID,
duke@0 669 key, (jint)value);
duke@0 670 GetEnv()->DeleteLocalRef(key);
duke@0 671 }
duke@0 672
duke@0 673 void AwtDesktopProperties::SetBooleanProperty(LPCTSTR propName, BOOL value) {
dav@3292 674 jstring key = JNU_NewStringPlatform(GetEnv(), propName);
duke@0 675 GetEnv()->CallVoidMethod(self,
duke@0 676 AwtDesktopProperties::setBooleanPropertyID,
duke@0 677 key, value ? JNI_TRUE : JNI_FALSE);
duke@0 678 GetEnv()->DeleteLocalRef(key);
duke@0 679 }
duke@0 680
duke@0 681 void AwtDesktopProperties::SetColorProperty(LPCTSTR propName, DWORD value) {
dav@3292 682 jstring key = JNU_NewStringPlatform(GetEnv(), propName);
duke@0 683 GetEnv()->CallVoidMethod(self,
duke@0 684 AwtDesktopProperties::setColorPropertyID,
duke@0 685 key, GetRValue(value), GetGValue(value),
duke@0 686 GetBValue(value));
duke@0 687 GetEnv()->DeleteLocalRef(key);
duke@0 688 }
duke@0 689
duke@0 690 void AwtDesktopProperties::SetFontProperty(HDC dc, int fontID,
duke@0 691 LPCTSTR propName) {
duke@0 692 HGDIOBJ font = GetStockObject(fontID);
duke@0 693 if (font != NULL && SelectObject(dc, font) != NULL) {
duke@0 694 int length = GetTextFace(dc, 0, NULL);
duke@0 695
duke@0 696 if (length > 0) {
duke@0 697 LPTSTR face = new TCHAR[length];
duke@0 698
duke@0 699 if (GetTextFace(dc, length, face) > 0) {
duke@0 700 TEXTMETRIC metrics;
duke@0 701
duke@0 702 if (GetTextMetrics(dc, &metrics) > 0) {
duke@0 703 jstring fontName = NULL;
duke@0 704 if (!wcscmp(face, L"MS Shell Dlg")) {
duke@0 705 // MS Shell Dlg is an indirect font name, find the
duke@0 706 // real face name from the registry.
duke@0 707 LPTSTR shellDialogFace = resolveShellDialogFont();
duke@0 708 if (shellDialogFace != NULL) {
duke@0 709 fontName = JNU_NewStringPlatform(GetEnv(),
duke@0 710 shellDialogFace);
duke@0 711 free(shellDialogFace);
duke@0 712 }
duke@0 713 else {
duke@0 714 // Couldn't determine mapping for MS Shell Dlg,
duke@0 715 // fall back to Microsoft Sans Serif
duke@0 716 fontName = JNU_NewStringPlatform(GetEnv(),
duke@0 717 L"Microsoft Sans Serif");
duke@0 718 }
duke@0 719 }
duke@0 720 else {
duke@0 721 fontName = JNU_NewStringPlatform(GetEnv(), face);
duke@0 722 }
duke@0 723 jint pointSize = metrics.tmHeight -
duke@0 724 metrics.tmInternalLeading;
duke@0 725 jint style = java_awt_Font_PLAIN;
duke@0 726
duke@0 727 if (metrics.tmWeight >= FW_BOLD) {
duke@0 728 style = java_awt_Font_BOLD;
duke@0 729 }
duke@0 730 if (metrics.tmItalic ) {
duke@0 731 style |= java_awt_Font_ITALIC;
duke@0 732 }
duke@0 733
dav@3292 734 jstring key = JNU_NewStringPlatform(GetEnv(), propName);
duke@0 735 GetEnv()->CallVoidMethod(self,
duke@0 736 AwtDesktopProperties::setFontPropertyID,
duke@0 737 key, fontName, style, pointSize);
duke@0 738 GetEnv()->DeleteLocalRef(fontName);
duke@0 739 GetEnv()->DeleteLocalRef(key);
duke@0 740 }
duke@0 741 }
duke@0 742 delete[] face;
duke@0 743 }
duke@0 744 }
duke@0 745 }
duke@0 746
duke@0 747 void AwtDesktopProperties::SetFontProperty(LPCTSTR propName, const LOGFONT & font) {
duke@0 748 jstring fontName;
duke@0 749 jint pointSize;
duke@0 750 jint style;
duke@0 751
dav@3292 752 fontName = JNU_NewStringPlatform(GetEnv(), font.lfFaceName);
duke@0 753
duke@0 754 #if 0
duke@0 755 HDC hdc;
duke@0 756 int pixelsPerInch = GetDeviceCaps(hdc, LOGPIXELSY);
duke@0 757 // convert font size specified in pixels to font size in points
duke@0 758 hdc = GetDC(NULL);
duke@0 759 pointSize = (-font.lfHeight)*72/pixelsPerInch;
duke@0 760 ReleaseDC(NULL, hdc);
duke@0 761 #endif
duke@0 762 // Java uses point sizes, but assumes 1 pixel = 1 point
duke@0 763 pointSize = -font.lfHeight;
duke@0 764
duke@0 765 // convert Windows font style to Java style
duke@0 766 style = java_awt_Font_PLAIN;
duke@0 767 DTRACE_PRINTLN1("weight=%d", font.lfWeight);
duke@0 768 if ( font.lfWeight >= FW_BOLD ) {
duke@0 769 style = java_awt_Font_BOLD;
duke@0 770 }
duke@0 771 if ( font.lfItalic ) {
duke@0 772 style |= java_awt_Font_ITALIC;
duke@0 773 }
duke@0 774
dav@3292 775 jstring key = JNU_NewStringPlatform(GetEnv(), propName);
duke@0 776 GetEnv()->CallVoidMethod(self, AwtDesktopProperties::setFontPropertyID,
duke@0 777 key, fontName, style, pointSize);
duke@0 778
duke@0 779 GetEnv()->DeleteLocalRef(fontName);
duke@0 780 GetEnv()->DeleteLocalRef(key);
duke@0 781 }
duke@0 782
duke@0 783 void AwtDesktopProperties::SetSoundProperty(LPCTSTR propName, LPCTSTR winEventName) {
dav@3292 784 jstring key = JNU_NewStringPlatform(GetEnv(), propName);
dav@3292 785 jstring event = JNU_NewStringPlatform(GetEnv(), winEventName);
duke@0 786 GetEnv()->CallVoidMethod(self,
duke@0 787 AwtDesktopProperties::setSoundPropertyID,
duke@0 788 key, event);
duke@0 789
duke@0 790 GetEnv()->DeleteLocalRef(key);
duke@0 791 GetEnv()->DeleteLocalRef(event);
duke@0 792 }
duke@0 793
duke@0 794 void AwtDesktopProperties::PlayWindowsSound(LPCTSTR event) {
duke@0 795 // stop any currently playing sounds
art@862 796 ::PlaySound(NULL, NULL, SND_PURGE);
duke@0 797 // play the sound for the given event name
art@862 798 ::PlaySound(event, NULL, SND_ASYNC|SND_ALIAS|SND_NODEFAULT);
duke@0 799 }
duke@0 800
duke@0 801 ///////////////////////////////////////////////////////////////////////////////////////////////////
duke@0 802
duke@0 803 static AwtDesktopProperties * GetCppThis(JNIEnv *env, jobject self) {
duke@0 804 jlong longProps = env->GetLongField(self, AwtDesktopProperties::pDataID);
duke@0 805 AwtDesktopProperties * props =
duke@0 806 (AwtDesktopProperties *)jlong_to_ptr(longProps);
duke@0 807 DASSERT( !IsBadReadPtr(props, sizeof(*props)) );
duke@0 808 return props;
duke@0 809 }
duke@0 810
duke@0 811 JNIEXPORT void JNICALL
duke@0 812 Java_sun_awt_windows_WDesktopProperties_initIDs(JNIEnv *env, jclass cls) {
duke@0 813 TRY;
duke@0 814
duke@0 815 AwtDesktopProperties::pDataID = env->GetFieldID(cls, "pData", "J");
duke@0 816 DASSERT(AwtDesktopProperties::pDataID != 0);
duke@0 817
duke@0 818 AwtDesktopProperties::setBooleanPropertyID = env->GetMethodID(cls, "setBooleanProperty", "(Ljava/lang/String;Z)V");
duke@0 819 DASSERT(AwtDesktopProperties::setBooleanPropertyID != 0);
duke@0 820
duke@0 821 AwtDesktopProperties::setIntegerPropertyID = env->GetMethodID(cls, "setIntegerProperty", "(Ljava/lang/String;I)V");
duke@0 822 DASSERT(AwtDesktopProperties::setIntegerPropertyID != 0);
duke@0 823
duke@0 824 AwtDesktopProperties::setStringPropertyID = env->GetMethodID(cls, "setStringProperty", "(Ljava/lang/String;Ljava/lang/String;)V");
duke@0 825 DASSERT(AwtDesktopProperties::setStringPropertyID != 0);
duke@0 826
duke@0 827 AwtDesktopProperties::setColorPropertyID = env->GetMethodID(cls, "setColorProperty", "(Ljava/lang/String;III)V");
duke@0 828 DASSERT(AwtDesktopProperties::setColorPropertyID != 0);
duke@0 829
duke@0 830 AwtDesktopProperties::setFontPropertyID = env->GetMethodID(cls, "setFontProperty", "(Ljava/lang/String;Ljava/lang/String;II)V");
duke@0 831 DASSERT(AwtDesktopProperties::setFontPropertyID != 0);
duke@0 832
duke@0 833 AwtDesktopProperties::setSoundPropertyID = env->GetMethodID(cls, "setSoundProperty", "(Ljava/lang/String;Ljava/lang/String;)V");
duke@0 834 DASSERT(AwtDesktopProperties::setSoundPropertyID != 0);
duke@0 835
duke@0 836 CATCH_BAD_ALLOC;
duke@0 837 }
duke@0 838
duke@0 839 JNIEXPORT void JNICALL
duke@0 840 Java_sun_awt_windows_WDesktopProperties_init(JNIEnv *env, jobject self) {
duke@0 841 TRY;
duke@0 842
duke@0 843 new AwtDesktopProperties(self);
duke@0 844
duke@0 845 CATCH_BAD_ALLOC;
duke@0 846 }
duke@0 847
duke@0 848 JNIEXPORT void JNICALL
duke@0 849 Java_sun_awt_windows_WDesktopProperties_getWindowsParameters(JNIEnv *env, jobject self) {
duke@0 850 TRY;
duke@0 851
duke@0 852 GetCppThis(env, self)->GetWindowsParameters();
duke@0 853
duke@0 854 CATCH_BAD_ALLOC;
duke@0 855 }
duke@0 856
duke@0 857 JNIEXPORT void JNICALL
duke@0 858 Java_sun_awt_windows_WDesktopProperties_playWindowsSound(JNIEnv *env, jobject self, jstring event) {
duke@0 859 TRY;
duke@0 860
duke@0 861 LPCTSTR winEventName;
duke@0 862 winEventName = JNU_GetStringPlatformChars(env, event, NULL);
duke@0 863 if ( winEventName == NULL ) {
duke@0 864 return;
duke@0 865 }
duke@0 866 GetCppThis(env, self)->PlayWindowsSound(winEventName);
duke@0 867 JNU_ReleaseStringPlatformChars(env, event, winEventName);
duke@0 868
duke@0 869 CATCH_BAD_ALLOC;
duke@0 870 }