< prev index next >

src/java.desktop/windows/native/libawt/windows/awt_DesktopProperties.cpp

Print this page




  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 #include "awt.h"
  27 #include "mmsystem.h"
  28 #include "jlong.h"
  29 #include "awt_DesktopProperties.h"
  30 #include "awt_Toolkit.h"
  31 #include "sun_awt_windows_WDesktopProperties.h"
  32 #include "java_awt_Font.h"
  33 #include "awtmsg.h"
  34 #include "zmouse.h"
  35 #include <shellapi.h>
  36 #include <shlobj.h>
  37 


  38 // WDesktopProperties fields
  39 jfieldID AwtDesktopProperties::pDataID = 0;
  40 jmethodID AwtDesktopProperties::setBooleanPropertyID = 0;
  41 jmethodID AwtDesktopProperties::setIntegerPropertyID = 0;
  42 jmethodID AwtDesktopProperties::setStringPropertyID = 0;
  43 jmethodID AwtDesktopProperties::setColorPropertyID = 0;
  44 jmethodID AwtDesktopProperties::setFontPropertyID = 0;
  45 jmethodID AwtDesktopProperties::setSoundPropertyID = 0;
  46 
  47 AwtDesktopProperties::AwtDesktopProperties(jobject self) {
  48     this->self = GetEnv()->NewGlobalRef(self);
  49     GetEnv()->SetLongField( self, AwtDesktopProperties::pDataID,
  50                             ptr_to_jlong(this) );
  51 }
  52 
  53 AwtDesktopProperties::~AwtDesktopProperties() {
  54     GetEnv()->DeleteGlobalRef(self);
  55 }
  56 
  57 //


  62     if (GetEnv()->EnsureLocalCapacity(MAX_PROPERTIES) < 0) {
  63         DASSERT(0);
  64         return;
  65     }
  66     // this number defines the set of properties available, it is incremented
  67     // whenever more properties are added (in a public release of course)
  68     // for example, version 1 defines the properties available in Java SDK version 1.3.
  69     SetIntegerProperty( TEXT("win.properties.version"), AWT_DESKTOP_PROPERTIES_VERSION);
  70     GetNonClientParameters();
  71     GetIconParameters();
  72     GetColorParameters();
  73     GetCaretParameters();
  74     GetOtherParameters();
  75     GetSoundEvents();
  76     GetSystemProperties();
  77     if (IS_WINXP) {
  78         GetXPStyleProperties();
  79     }
  80 }
  81 














  82 void AwtDesktopProperties::GetSystemProperties() {
  83     HDC dc = CreateDC(TEXT("DISPLAY"), NULL, NULL, NULL);
  84 
  85     if (dc != NULL) {
  86         try {
  87             SetFontProperty(dc, ANSI_FIXED_FONT, TEXT("win.ansiFixed.font"));
  88             SetFontProperty(dc, ANSI_VAR_FONT, TEXT("win.ansiVar.font"));
  89             SetFontProperty(dc, DEVICE_DEFAULT_FONT, TEXT("win.deviceDefault.font"));
  90             SetFontProperty(dc, DEFAULT_GUI_FONT, TEXT("win.defaultGUI.font"));
  91             SetFontProperty(dc, OEM_FIXED_FONT, TEXT("win.oemFixed.font"));
  92             SetFontProperty(dc, SYSTEM_FONT, TEXT("win.system.font"));
  93             SetFontProperty(dc, SYSTEM_FIXED_FONT, TEXT("win.systemFixed.font"));



  94         }
  95         catch (std::bad_alloc&) {
  96             DeleteDC(dc);
  97             throw;
  98         }
  99         DeleteDC(dc);
 100     }
 101 }
 102 
 103 
 104 // Does the actual lookup for shell dialog font (MS Shell Dlg).  fontName
 105 // contains the name to lookup (either MS Shell Dlg or MS Shell Dlg 2) and
 106 // handle contains a reference toe the registry entry to look in.
 107 // This will return NULL or a pointer to the resolved name.
 108 // Note that it uses malloc() and returns the pointer to allocated
 109 // memory, so remember to use free() when you are done with its
 110 // result.
 111 static LPTSTR resolveShellDialogFont(LPTSTR fontName, HKEY handle) {
 112     DWORD valueType, valueSize;
 113     if (RegQueryValueEx((HKEY)handle, fontName, NULL,


 249     //
 250     // general window properties
 251     //
 252     NONCLIENTMETRICS    ncmetrics;
 253 
 254     // Fix for 6944516: specify correct size for ncmetrics on WIN2K/XP
 255     // Microsoft recommend to subtract the size of  'iPaddedBorderWidth' field
 256     // when running on XP. However this can't be referenced at compile time
 257     // with the older SDK, so there use 'lfMessageFont' plus its size.
 258     if (!IS_WINVISTA) {
 259 #if defined(_MSC_VER) && (_MSC_VER >= 1600)
 260         ncmetrics.cbSize = offsetof(NONCLIENTMETRICS, iPaddedBorderWidth);
 261 #else
 262         ncmetrics.cbSize = offsetof(NONCLIENTMETRICS,lfMessageFont) + sizeof(LOGFONT);
 263 #endif
 264     } else {
 265         ncmetrics.cbSize = sizeof(ncmetrics);
 266     }
 267     VERIFY( SystemParametersInfo(SPI_GETNONCLIENTMETRICS, ncmetrics.cbSize, &ncmetrics, FALSE) );
 268 
 269     SetFontProperty( TEXT("win.frame.captionFont"), ncmetrics.lfCaptionFont );
 270     SetIntegerProperty( TEXT("win.frame.captionHeight"), ncmetrics.iCaptionHeight );
 271     SetIntegerProperty( TEXT("win.frame.captionButtonWidth"), ncmetrics.iCaptionWidth );
 272     SetIntegerProperty( TEXT("win.frame.captionButtonHeight"), ncmetrics.iCaptionHeight );
 273     SetFontProperty( TEXT("win.frame.smallCaptionFont"), ncmetrics.lfSmCaptionFont );
 274     SetIntegerProperty( TEXT("win.frame.smallCaptionHeight"), ncmetrics.iSmCaptionHeight );
 275     SetIntegerProperty( TEXT("win.frame.smallCaptionButtonWidth"), ncmetrics.iSmCaptionWidth );
 276     SetIntegerProperty( TEXT("win.frame.smallCaptionButtonHeight"), ncmetrics.iSmCaptionHeight );
 277     SetIntegerProperty( TEXT("win.frame.sizingBorderWidth"), ncmetrics.iBorderWidth );




 278 
 279     // menu properties
 280     SetFontProperty( TEXT("win.menu.font"), ncmetrics.lfMenuFont );
 281     SetIntegerProperty( TEXT("win.menu.height"), ncmetrics.iMenuHeight );
 282     SetIntegerProperty( TEXT("win.menu.buttonWidth"), ncmetrics.iMenuWidth );
 283 
 284     // scrollbar properties
 285     SetIntegerProperty( TEXT("win.scrollbar.width"), ncmetrics.iScrollWidth );
 286     SetIntegerProperty( TEXT("win.scrollbar.height"), ncmetrics.iScrollHeight );
 287 
 288     // status bar and tooltip properties
 289     SetFontProperty( TEXT("win.status.font"), ncmetrics.lfStatusFont );
 290     SetFontProperty( TEXT("win.tooltip.font"), ncmetrics.lfStatusFont );
 291 
 292     // message box properties
 293     SetFontProperty( TEXT("win.messagebox.font"), ncmetrics.lfMessageFont );
 294 }
 295 
 296 void AwtDesktopProperties::GetIconParameters() {
 297     //
 298     // icon properties
 299     //
 300     ICONMETRICS iconmetrics;
 301 
 302     iconmetrics.cbSize = sizeof(iconmetrics);
 303     VERIFY( SystemParametersInfo(SPI_GETICONMETRICS, iconmetrics.cbSize, &iconmetrics, FALSE) );
 304 
 305     SetIntegerProperty(TEXT("win.icon.hspacing"), iconmetrics.iHorzSpacing);
 306     SetIntegerProperty(TEXT("win.icon.vspacing"), iconmetrics.iVertSpacing);



 307     SetBooleanProperty(TEXT("win.icon.titleWrappingOn"), iconmetrics.iTitleWrap != 0);
 308     SetFontProperty(TEXT("win.icon.font"), iconmetrics.lfFont);
 309 }
 310 /*
 311  Windows settings for these are also in the registry
 312  They exist as system wide HKLM: HKEY_LOCAL_MACHINE and
 313  HKCU: HKEY_CURRENT_USER.
 314  HKCU\Control Panel\Desktop\FontSmoothing :  "0=OFF",  "2=ON"
 315  HKCU\Control Panel\Desktop\FontSmoothingType: 1=Standard, 2=LCD
 316  HKCU\Control Panel\Desktop\FontSmoothingGamma: 1000->2200
 317  HKCU\Control Panel\Desktop\FontSmoothingOrientation: 0=BGR, 1=RGB
 318 
 319  SystemParametersInfo supplies the first three of these but does not
 320  however expose the Orientation. That has to come from the registry.
 321 
 322  We go to some small lengths in here to not make queries we don't need.
 323  Eg if we previously were using standard font smoothing and we still are
 324  then its unlikely that any change in gamma will have occurred except
 325  by a program which changed it, and even if it did, we don't need to pick
 326  it up until someone turns on the LCD option.
 327  To do: this loop is called once per top-level window so an app with
 328  N windows will get notified N times. It would save us a small amount of


 701 }
 702 
 703 void AwtDesktopProperties::SetStringProperty(LPCTSTR propName, LPTSTR value) {
 704     jstring key = JNU_NewStringPlatform(GetEnv(), propName);
 705     if (key == NULL) {
 706         throw std::bad_alloc();
 707     }
 708     jstring jValue = JNU_NewStringPlatform(GetEnv(), value);
 709     if (jValue == NULL) {
 710         GetEnv()->DeleteLocalRef(key);
 711         throw std::bad_alloc();
 712     }
 713     GetEnv()->CallVoidMethod(self,
 714                              AwtDesktopProperties::setStringPropertyID,
 715                              key, jValue);
 716     GetEnv()->DeleteLocalRef(jValue);
 717     GetEnv()->DeleteLocalRef(key);
 718 }
 719 
 720 void AwtDesktopProperties::SetIntegerProperty(LPCTSTR propName, int value) {

 721     jstring key = JNU_NewStringPlatform(GetEnv(), propName);
 722     if (key == NULL) {
 723         throw std::bad_alloc();
 724     }
 725     GetEnv()->CallVoidMethod(self,
 726                              AwtDesktopProperties::setIntegerPropertyID,
 727                              key, (jint)value);
 728     GetEnv()->DeleteLocalRef(key);
 729 }
 730 
 731 void AwtDesktopProperties::SetBooleanProperty(LPCTSTR propName, BOOL value) {
 732     jstring key = JNU_NewStringPlatform(GetEnv(), propName);
 733     if (key == NULL) {
 734         throw std::bad_alloc();
 735     }
 736     GetEnv()->CallVoidMethod(self,
 737                              AwtDesktopProperties::setBooleanPropertyID,
 738                              key, value ? JNI_TRUE : JNI_FALSE);
 739     GetEnv()->DeleteLocalRef(key);
 740 }
 741 
 742 void AwtDesktopProperties::SetColorProperty(LPCTSTR propName, DWORD value) {
 743     jstring key = JNU_NewStringPlatform(GetEnv(), propName);
 744     if (key == NULL) {
 745         throw std::bad_alloc();
 746     }
 747     GetEnv()->CallVoidMethod(self,
 748                              AwtDesktopProperties::setColorPropertyID,
 749                              key, GetRValue(value), GetGValue(value),
 750                              GetBValue(value));
 751     GetEnv()->DeleteLocalRef(key);
 752 }
 753 
 754 void AwtDesktopProperties::SetFontProperty(HDC dc, int fontID,
 755                                            LPCTSTR propName) {
 756     HGDIOBJ font = GetStockObject(fontID);
 757     if (font != NULL && SelectObject(dc, font) != NULL) {
 758         int length = GetTextFace(dc, 0, NULL);
 759 
 760         if (length > 0) {
 761             LPTSTR face = new TCHAR[length];
 762 
 763             if (GetTextFace(dc, length, face) > 0) {
 764                 TEXTMETRIC metrics;
 765 
 766                 if (GetTextMetrics(dc, &metrics) > 0) {
 767                     jstring fontName = NULL;
 768                     if (!wcscmp(face, L"MS Shell Dlg")) {
 769                         // MS Shell Dlg is an indirect font name, find the
 770                         // real face name from the registry.
 771                         LPTSTR shellDialogFace = resolveShellDialogFont();
 772                         if (shellDialogFace != NULL) {
 773                             fontName = JNU_NewStringPlatform(GetEnv(),
 774                                                              shellDialogFace);
 775                             free(shellDialogFace);
 776                         }
 777                         else {
 778                             // Couldn't determine mapping for MS Shell Dlg,
 779                             // fall back to Microsoft Sans Serif
 780                             fontName = JNU_NewStringPlatform(GetEnv(),
 781                                                     L"Microsoft Sans Serif");
 782                         }
 783                     }
 784                     else {
 785                         fontName = JNU_NewStringPlatform(GetEnv(), face);
 786                     }
 787                     if (fontName == NULL) {
 788                         delete[] face;
 789                         throw std::bad_alloc();
 790                     }
 791 
 792                     jint pointSize = metrics.tmHeight -
 793                                      metrics.tmInternalLeading;
 794                     jint style = java_awt_Font_PLAIN;
 795 
 796                     if (metrics.tmWeight >= FW_BOLD) {
 797                         style =  java_awt_Font_BOLD;
 798                     }
 799                     if (metrics.tmItalic ) {
 800                         style |= java_awt_Font_ITALIC;
 801                     }
 802 
 803                     jstring key = JNU_NewStringPlatform(GetEnv(), propName);
 804                     if (key == NULL) {
 805                         GetEnv()->DeleteLocalRef(fontName);
 806                         delete[] face;
 807                         throw std::bad_alloc();
 808                     }
 809                     GetEnv()->CallVoidMethod(self,
 810                               AwtDesktopProperties::setFontPropertyID,
 811                               key, fontName, style, pointSize);
 812                     GetEnv()->DeleteLocalRef(key);
 813                     GetEnv()->DeleteLocalRef(fontName);
 814                 }
 815             }
 816             delete[] face;
 817         }
 818     }
 819 }
 820 
 821 void AwtDesktopProperties::SetFontProperty(LPCTSTR propName, const LOGFONT & font) {

 822     jstring fontName;
 823     jint pointSize;
 824     jint style;
 825 
 826     fontName = JNU_NewStringPlatform(GetEnv(), font.lfFaceName);
 827     if (fontName == NULL) {
 828         throw std::bad_alloc();
 829     }
 830 #if 0
 831     HDC         hdc;
 832     int         pixelsPerInch = GetDeviceCaps(hdc, LOGPIXELSY);
 833     // convert font size specified in pixels to font size in points
 834     hdc = GetDC(NULL);
 835     pointSize = (-font.lfHeight)*72/pixelsPerInch;
 836     ReleaseDC(NULL, hdc);
 837 #endif
 838     // Java uses point sizes, but assumes 1 pixel = 1 point
 839     pointSize = -font.lfHeight;
 840 
 841     // convert Windows font style to Java style
 842     style = java_awt_Font_PLAIN;
 843     DTRACE_PRINTLN1("weight=%d", font.lfWeight);
 844     if ( font.lfWeight >= FW_BOLD ) {
 845         style =  java_awt_Font_BOLD;
 846     }
 847     if ( font.lfItalic ) {
 848         style |= java_awt_Font_ITALIC;
 849     }
 850 
 851     jstring key = JNU_NewStringPlatform(GetEnv(), propName);
 852     if (key == NULL) {
 853         GetEnv()->DeleteLocalRef(fontName);
 854         throw std::bad_alloc();
 855     }
 856     GetEnv()->CallVoidMethod(self, AwtDesktopProperties::setFontPropertyID,
 857                              key, fontName, style, pointSize);
 858     GetEnv()->DeleteLocalRef(key);
 859     GetEnv()->DeleteLocalRef(fontName);




  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 #include "awt.h"
  27 #include "mmsystem.h"
  28 #include "jlong.h"
  29 #include "awt_DesktopProperties.h"
  30 #include "awt_Toolkit.h"
  31 #include "sun_awt_windows_WDesktopProperties.h"
  32 #include "java_awt_Font.h"
  33 #include "awtmsg.h"
  34 #include "zmouse.h"
  35 #include <shellapi.h>
  36 #include <shlobj.h>
  37 
  38 #include "math.h"
  39 
  40 // WDesktopProperties fields
  41 jfieldID AwtDesktopProperties::pDataID = 0;
  42 jmethodID AwtDesktopProperties::setBooleanPropertyID = 0;
  43 jmethodID AwtDesktopProperties::setIntegerPropertyID = 0;
  44 jmethodID AwtDesktopProperties::setStringPropertyID = 0;
  45 jmethodID AwtDesktopProperties::setColorPropertyID = 0;
  46 jmethodID AwtDesktopProperties::setFontPropertyID = 0;
  47 jmethodID AwtDesktopProperties::setSoundPropertyID = 0;
  48 
  49 AwtDesktopProperties::AwtDesktopProperties(jobject self) {
  50     this->self = GetEnv()->NewGlobalRef(self);
  51     GetEnv()->SetLongField( self, AwtDesktopProperties::pDataID,
  52                             ptr_to_jlong(this) );
  53 }
  54 
  55 AwtDesktopProperties::~AwtDesktopProperties() {
  56     GetEnv()->DeleteGlobalRef(self);
  57 }
  58 
  59 //


  64     if (GetEnv()->EnsureLocalCapacity(MAX_PROPERTIES) < 0) {
  65         DASSERT(0);
  66         return;
  67     }
  68     // this number defines the set of properties available, it is incremented
  69     // whenever more properties are added (in a public release of course)
  70     // for example, version 1 defines the properties available in Java SDK version 1.3.
  71     SetIntegerProperty( TEXT("win.properties.version"), AWT_DESKTOP_PROPERTIES_VERSION);
  72     GetNonClientParameters();
  73     GetIconParameters();
  74     GetColorParameters();
  75     GetCaretParameters();
  76     GetOtherParameters();
  77     GetSoundEvents();
  78     GetSystemProperties();
  79     if (IS_WINXP) {
  80         GetXPStyleProperties();
  81     }
  82 }
  83 
  84 void getInvScale(float &invScaleX, float &invScaleY) {
  85     HWND hWnd = ::GetDesktopWindow();
  86     HDC hDC = ::GetDC(hWnd);
  87     int dpiX = ::GetDeviceCaps(hDC, LOGPIXELSX);
  88     int dpiY = ::GetDeviceCaps(hDC, LOGPIXELSY);
  89     ::ReleaseDC(hWnd, hDC);
  90     invScaleX = (dpiX == 0.0f) ? 1.0f : 96.0f / dpiX;
  91     invScaleY = (dpiY == 0.0f) ? 1.0f : 96.0f / dpiY;
  92 }
  93 
  94 int rescale(int value, float invScale){
  95     return invScale == 1.0f ? value : (int)round(value * invScale);
  96 }
  97 
  98 void AwtDesktopProperties::GetSystemProperties() {
  99     HDC dc = CreateDC(TEXT("DISPLAY"), NULL, NULL, NULL);
 100 
 101     if (dc != NULL) {
 102         try {
 103             float invScaleX;
 104             float invScaleY;
 105             getInvScale(invScaleX, invScaleY);
 106             SetFontProperty(dc, ANSI_FIXED_FONT, TEXT("win.ansiFixed.font"), 1.0f);
 107             SetFontProperty(dc, ANSI_VAR_FONT, TEXT("win.ansiVar.font"), 1.0f);
 108             SetFontProperty(dc, DEVICE_DEFAULT_FONT, TEXT("win.deviceDefault.font"), 1.0f);
 109             SetFontProperty(dc, DEFAULT_GUI_FONT, TEXT("win.defaultGUI.font"), invScaleY);
 110             SetFontProperty(dc, OEM_FIXED_FONT, TEXT("win.oemFixed.font"), 1.0f);
 111             SetFontProperty(dc, SYSTEM_FONT, TEXT("win.system.font"), 1.0f);
 112             SetFontProperty(dc, SYSTEM_FIXED_FONT, TEXT("win.systemFixed.font"), 1.0f);
 113         }
 114         catch (std::bad_alloc&) {
 115             DeleteDC(dc);
 116             throw;
 117         }
 118         DeleteDC(dc);
 119     }
 120 }
 121 
 122 
 123 // Does the actual lookup for shell dialog font (MS Shell Dlg).  fontName
 124 // contains the name to lookup (either MS Shell Dlg or MS Shell Dlg 2) and
 125 // handle contains a reference toe the registry entry to look in.
 126 // This will return NULL or a pointer to the resolved name.
 127 // Note that it uses malloc() and returns the pointer to allocated
 128 // memory, so remember to use free() when you are done with its
 129 // result.
 130 static LPTSTR resolveShellDialogFont(LPTSTR fontName, HKEY handle) {
 131     DWORD valueType, valueSize;
 132     if (RegQueryValueEx((HKEY)handle, fontName, NULL,


 268     //
 269     // general window properties
 270     //
 271     NONCLIENTMETRICS    ncmetrics;
 272 
 273     // Fix for 6944516: specify correct size for ncmetrics on WIN2K/XP
 274     // Microsoft recommend to subtract the size of  'iPaddedBorderWidth' field
 275     // when running on XP. However this can't be referenced at compile time
 276     // with the older SDK, so there use 'lfMessageFont' plus its size.
 277     if (!IS_WINVISTA) {
 278 #if defined(_MSC_VER) && (_MSC_VER >= 1600)
 279         ncmetrics.cbSize = offsetof(NONCLIENTMETRICS, iPaddedBorderWidth);
 280 #else
 281         ncmetrics.cbSize = offsetof(NONCLIENTMETRICS,lfMessageFont) + sizeof(LOGFONT);
 282 #endif
 283     } else {
 284         ncmetrics.cbSize = sizeof(ncmetrics);
 285     }
 286     VERIFY( SystemParametersInfo(SPI_GETNONCLIENTMETRICS, ncmetrics.cbSize, &ncmetrics, FALSE) );
 287 
 288     float invScaleX;
 289     float invScaleY;
 290     getInvScale(invScaleX, invScaleY);
 291 
 292     SetFontProperty(TEXT("win.frame.captionFont"), ncmetrics.lfCaptionFont, invScaleY);
 293     SetIntegerProperty(TEXT("win.frame.captionHeight"), rescale(ncmetrics.iCaptionHeight, invScaleY));
 294     SetIntegerProperty(TEXT("win.frame.captionButtonWidth"), rescale(ncmetrics.iCaptionWidth, invScaleX));
 295     SetIntegerProperty(TEXT("win.frame.captionButtonHeight"), rescale(ncmetrics.iCaptionHeight, invScaleY));
 296     SetFontProperty(TEXT("win.frame.smallCaptionFont"), ncmetrics.lfSmCaptionFont, invScaleY);
 297     SetIntegerProperty(TEXT("win.frame.smallCaptionHeight"), rescale(ncmetrics.iSmCaptionHeight, invScaleY));
 298     SetIntegerProperty(TEXT("win.frame.smallCaptionButtonWidth"), rescale(ncmetrics.iSmCaptionWidth, invScaleX));
 299     SetIntegerProperty(TEXT("win.frame.smallCaptionButtonHeight"), rescale(ncmetrics.iSmCaptionHeight, invScaleY));
 300     SetIntegerProperty(TEXT("win.frame.sizingBorderWidth"), rescale(ncmetrics.iBorderWidth, invScaleX));
 301 
 302     // menu properties
 303     SetFontProperty(TEXT("win.menu.font"), ncmetrics.lfMenuFont, invScaleY);
 304     SetIntegerProperty(TEXT("win.menu.height"), rescale(ncmetrics.iMenuHeight, invScaleY));
 305     SetIntegerProperty(TEXT("win.menu.buttonWidth"), rescale(ncmetrics.iMenuWidth, invScaleX));
 306 
 307     // scrollbar properties
 308     SetIntegerProperty(TEXT("win.scrollbar.width"), rescale(ncmetrics.iScrollWidth, invScaleX));
 309     SetIntegerProperty(TEXT("win.scrollbar.height"), rescale(ncmetrics.iScrollHeight, invScaleY));
 310 
 311     // status bar and tooltip properties
 312     SetFontProperty(TEXT("win.status.font"), ncmetrics.lfStatusFont, invScaleY);
 313     SetFontProperty(TEXT("win.tooltip.font"), ncmetrics.lfStatusFont, invScaleY);
 314 
 315     // message box properties
 316     SetFontProperty(TEXT("win.messagebox.font"), ncmetrics.lfMessageFont, invScaleY);
 317 }
 318 
 319 void AwtDesktopProperties::GetIconParameters() {
 320     //
 321     // icon properties
 322     //
 323     ICONMETRICS iconmetrics;
 324 
 325     iconmetrics.cbSize = sizeof(iconmetrics);
 326     VERIFY( SystemParametersInfo(SPI_GETICONMETRICS, iconmetrics.cbSize, &iconmetrics, FALSE) );
 327 
 328     float invScaleX;
 329     float invScaleY;
 330     getInvScale(invScaleX, invScaleY);
 331     SetIntegerProperty(TEXT("win.icon.hspacing"), rescale(iconmetrics.iHorzSpacing, invScaleX));
 332     SetIntegerProperty(TEXT("win.icon.vspacing"), rescale(iconmetrics.iVertSpacing, invScaleY));
 333     SetBooleanProperty(TEXT("win.icon.titleWrappingOn"), iconmetrics.iTitleWrap != 0);
 334     SetFontProperty(TEXT("win.icon.font"), iconmetrics.lfFont, invScaleY);
 335 }
 336 /*
 337  Windows settings for these are also in the registry
 338  They exist as system wide HKLM: HKEY_LOCAL_MACHINE and
 339  HKCU: HKEY_CURRENT_USER.
 340  HKCU\Control Panel\Desktop\FontSmoothing :  "0=OFF",  "2=ON"
 341  HKCU\Control Panel\Desktop\FontSmoothingType: 1=Standard, 2=LCD
 342  HKCU\Control Panel\Desktop\FontSmoothingGamma: 1000->2200
 343  HKCU\Control Panel\Desktop\FontSmoothingOrientation: 0=BGR, 1=RGB
 344 
 345  SystemParametersInfo supplies the first three of these but does not
 346  however expose the Orientation. That has to come from the registry.
 347 
 348  We go to some small lengths in here to not make queries we don't need.
 349  Eg if we previously were using standard font smoothing and we still are
 350  then its unlikely that any change in gamma will have occurred except
 351  by a program which changed it, and even if it did, we don't need to pick
 352  it up until someone turns on the LCD option.
 353  To do: this loop is called once per top-level window so an app with
 354  N windows will get notified N times. It would save us a small amount of


 727 }
 728 
 729 void AwtDesktopProperties::SetStringProperty(LPCTSTR propName, LPTSTR value) {
 730     jstring key = JNU_NewStringPlatform(GetEnv(), propName);
 731     if (key == NULL) {
 732         throw std::bad_alloc();
 733     }
 734     jstring jValue = JNU_NewStringPlatform(GetEnv(), value);
 735     if (jValue == NULL) {
 736         GetEnv()->DeleteLocalRef(key);
 737         throw std::bad_alloc();
 738     }
 739     GetEnv()->CallVoidMethod(self,
 740                              AwtDesktopProperties::setStringPropertyID,
 741                              key, jValue);
 742     GetEnv()->DeleteLocalRef(jValue);
 743     GetEnv()->DeleteLocalRef(key);
 744 }
 745 
 746 void AwtDesktopProperties::SetIntegerProperty(LPCTSTR propName, int value) {
 747 
 748     jstring key = JNU_NewStringPlatform(GetEnv(), propName);
 749     if (key == NULL) {
 750         throw std::bad_alloc();
 751     }
 752     GetEnv()->CallVoidMethod(self,
 753                              AwtDesktopProperties::setIntegerPropertyID,
 754                              key, (jint)value);
 755     GetEnv()->DeleteLocalRef(key);
 756 }
 757 
 758 void AwtDesktopProperties::SetBooleanProperty(LPCTSTR propName, BOOL value) {
 759     jstring key = JNU_NewStringPlatform(GetEnv(), propName);
 760     if (key == NULL) {
 761         throw std::bad_alloc();
 762     }
 763     GetEnv()->CallVoidMethod(self,
 764                              AwtDesktopProperties::setBooleanPropertyID,
 765                              key, value ? JNI_TRUE : JNI_FALSE);
 766     GetEnv()->DeleteLocalRef(key);
 767 }
 768 
 769 void AwtDesktopProperties::SetColorProperty(LPCTSTR propName, DWORD value) {
 770     jstring key = JNU_NewStringPlatform(GetEnv(), propName);
 771     if (key == NULL) {
 772         throw std::bad_alloc();
 773     }
 774     GetEnv()->CallVoidMethod(self,
 775                              AwtDesktopProperties::setColorPropertyID,
 776                              key, GetRValue(value), GetGValue(value),
 777                              GetBValue(value));
 778     GetEnv()->DeleteLocalRef(key);
 779 }
 780 
 781 void AwtDesktopProperties::SetFontProperty(HDC dc, int fontID,
 782     LPCTSTR propName, float invScale) {
 783         HGDIOBJ font = GetStockObject(fontID);
 784     if (font != NULL && SelectObject(dc, font) != NULL) {
 785         int length = GetTextFace(dc, 0, NULL);
 786 
 787         if (length > 0) {
 788             LPTSTR face = new TCHAR[length];
 789 
 790             if (GetTextFace(dc, length, face) > 0) {
 791                 TEXTMETRIC metrics;
 792 
 793                 if (GetTextMetrics(dc, &metrics) > 0) {
 794                     jstring fontName = NULL;
 795                     if (!wcscmp(face, L"MS Shell Dlg")) {
 796                         // MS Shell Dlg is an indirect font name, find the
 797                         // real face name from the registry.
 798                         LPTSTR shellDialogFace = resolveShellDialogFont();
 799                         if (shellDialogFace != NULL) {
 800                             fontName = JNU_NewStringPlatform(GetEnv(),
 801                                                              shellDialogFace);
 802                             free(shellDialogFace);
 803                         }
 804                         else {
 805                             // Couldn't determine mapping for MS Shell Dlg,
 806                             // fall back to Microsoft Sans Serif
 807                             fontName = JNU_NewStringPlatform(GetEnv(),
 808                                                     L"Microsoft Sans Serif");
 809                         }
 810                     }
 811                     else {
 812                         fontName = JNU_NewStringPlatform(GetEnv(), face);
 813                     }
 814                     if (fontName == NULL) {
 815                         delete[] face;
 816                         throw std::bad_alloc();
 817                     }
 818 
 819                     jint pointSize = rescale(metrics.tmHeight -
 820                                      metrics.tmInternalLeading, invScale);
 821                     jint style = java_awt_Font_PLAIN;
 822 
 823                     if (metrics.tmWeight >= FW_BOLD) {
 824                         style =  java_awt_Font_BOLD;
 825                     }
 826                     if (metrics.tmItalic ) {
 827                         style |= java_awt_Font_ITALIC;
 828                     }
 829 
 830                     jstring key = JNU_NewStringPlatform(GetEnv(), propName);
 831                     if (key == NULL) {
 832                         GetEnv()->DeleteLocalRef(fontName);
 833                         delete[] face;
 834                         throw std::bad_alloc();
 835                     }
 836                     GetEnv()->CallVoidMethod(self,
 837                               AwtDesktopProperties::setFontPropertyID,
 838                               key, fontName, style, pointSize);
 839                     GetEnv()->DeleteLocalRef(key);
 840                     GetEnv()->DeleteLocalRef(fontName);
 841                 }
 842             }
 843             delete[] face;
 844         }
 845     }
 846 }
 847 
 848 void AwtDesktopProperties::SetFontProperty(LPCTSTR propName, const LOGFONT & font,
 849     float invScale) {
 850     jstring fontName;
 851     jint pointSize;
 852     jint style;
 853 
 854     fontName = JNU_NewStringPlatform(GetEnv(), font.lfFaceName);
 855     if (fontName == NULL) {
 856         throw std::bad_alloc();
 857     }
 858 #if 0
 859     HDC         hdc;
 860     int         pixelsPerInch = GetDeviceCaps(hdc, LOGPIXELSY);
 861     // convert font size specified in pixels to font size in points
 862     hdc = GetDC(NULL);
 863     pointSize = (-font.lfHeight)*72/pixelsPerInch;
 864     ReleaseDC(NULL, hdc);
 865 #endif
 866     // Java uses point sizes, but assumes 1 pixel = 1 point
 867     pointSize = rescale(-font.lfHeight, invScale);
 868 
 869     // convert Windows font style to Java style
 870     style = java_awt_Font_PLAIN;
 871     DTRACE_PRINTLN1("weight=%d", font.lfWeight);
 872     if ( font.lfWeight >= FW_BOLD ) {
 873         style =  java_awt_Font_BOLD;
 874     }
 875     if ( font.lfItalic ) {
 876         style |= java_awt_Font_ITALIC;
 877     }
 878 
 879     jstring key = JNU_NewStringPlatform(GetEnv(), propName);
 880     if (key == NULL) {
 881         GetEnv()->DeleteLocalRef(fontName);
 882         throw std::bad_alloc();
 883     }
 884     GetEnv()->CallVoidMethod(self, AwtDesktopProperties::setFontPropertyID,
 885                              key, fontName, style, pointSize);
 886     GetEnv()->DeleteLocalRef(key);
 887     GetEnv()->DeleteLocalRef(fontName);


< prev index next >