< 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.


 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 float getInvScale() {
  85     HWND hWnd = ::GetDesktopWindow();
  86     HDC hDC = ::GetDC(hWnd);
  87     int dpi = ::GetDeviceCaps(hDC, LOGPIXELSY);
  88     ::ReleaseDC(hWnd, hDC);
  89     return dpi == 0.0f ? 1.0f : 96.0f / dpi;
  90 }
  91 
  92 int rescale(int y, float invScale){
  93     return invScale == 1.0f ? y : (int)round(y * invScale);
  94 }
  95 
  96 void AwtDesktopProperties::GetSystemProperties() {
  97     HDC dc = CreateDC(TEXT("DISPLAY"), NULL, NULL, NULL);
  98 
  99     if (dc != NULL) {
 100         try {
 101             SetFontProperty(dc, ANSI_FIXED_FONT, TEXT("win.ansiFixed.font"));
 102             SetFontProperty(dc, ANSI_VAR_FONT, TEXT("win.ansiVar.font"));
 103             SetFontProperty(dc, DEVICE_DEFAULT_FONT, TEXT("win.deviceDefault.font"));
 104             SetFontProperty(dc, DEFAULT_GUI_FONT, TEXT("win.defaultGUI.font"), getInvScale());
 105             SetFontProperty(dc, OEM_FIXED_FONT, TEXT("win.oemFixed.font"));
 106             SetFontProperty(dc, SYSTEM_FONT, TEXT("win.system.font"));
 107             SetFontProperty(dc, SYSTEM_FIXED_FONT, TEXT("win.systemFixed.font"));
 108         }
 109         catch (std::bad_alloc&) {
 110             DeleteDC(dc);
 111             throw;
 112         }
 113         DeleteDC(dc);
 114     }
 115 }
 116 
 117 
 118 // Does the actual lookup for shell dialog font (MS Shell Dlg).  fontName
 119 // contains the name to lookup (either MS Shell Dlg or MS Shell Dlg 2) and
 120 // handle contains a reference toe the registry entry to look in.
 121 // This will return NULL or a pointer to the resolved name.
 122 // Note that it uses malloc() and returns the pointer to allocated
 123 // memory, so remember to use free() when you are done with its
 124 // result.


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


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