< prev index next >

src/windows/native/sun/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 #include "math.h"
  39 
  40 #if defined(_MSC_VER) && _MSC_VER >= 1800
  41 #  define ROUND_TO_INT(num)    ((int) round(num))
  42 #else
  43 #  define ROUND_TO_INT(num)    ((int) floor((num) + 0.5))
  44 #endif
  45 
  46 // WDesktopProperties fields
  47 jfieldID AwtDesktopProperties::pDataID = 0;
  48 jmethodID AwtDesktopProperties::setBooleanPropertyID = 0;
  49 jmethodID AwtDesktopProperties::setIntegerPropertyID = 0;
  50 jmethodID AwtDesktopProperties::setStringPropertyID = 0;
  51 jmethodID AwtDesktopProperties::setColorPropertyID = 0;
  52 jmethodID AwtDesktopProperties::setFontPropertyID = 0;
  53 jmethodID AwtDesktopProperties::setSoundPropertyID = 0;
  54 
  55 AwtDesktopProperties::AwtDesktopProperties(jobject self) {
  56     this->self = GetEnv()->NewGlobalRef(self);
  57     GetEnv()->SetLongField( self, AwtDesktopProperties::pDataID,
  58                             ptr_to_jlong(this) );
  59 }
  60 
  61 AwtDesktopProperties::~AwtDesktopProperties() {
  62     GetEnv()->DeleteGlobalRef(self);
  63 }
  64 
  65 //


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


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


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


< prev index next >