Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / wpf / src / Framework / System / Windows / SystemFonts.cs / 1 / SystemFonts.cs
using System; using System.Collections; using System.ComponentModel; using System.Runtime.InteropServices; using System.Windows.Media; using System.Security; using System.Windows.Controls.Primitives; using Microsoft.Win32; using MS.Win32; using MS.Internal; namespace System.Windows { ////// Contains properties that are queries into the system's various settings. /// public static class SystemFonts { #region Fonts ////// Maps to SPI_GETICONTITLELOGFONT /// public static double IconFontSize { get { return ConvertFontHeight(SystemParameters.IconMetrics.lfFont.lfHeight); } } ////// Maps to SPI_GETICONTITLELOGFONT /// public static FontFamily IconFontFamily { get { if (_iconFontFamily == null) { _iconFontFamily = new FontFamily(SystemParameters.IconMetrics.lfFont.lfFaceName); } return _iconFontFamily; } } ////// Maps to SPI_GETICONTITLELOGFONT /// public static FontStyle IconFontStyle { get { return (SystemParameters.IconMetrics.lfFont.lfItalic != 0) ? FontStyles.Italic : FontStyles.Normal; } } ////// Maps to SPI_GETICONTITLELOGFONT /// public static FontWeight IconFontWeight { get { return FontWeight.FromOpenTypeWeight(SystemParameters.IconMetrics.lfFont.lfWeight); } } ////// Maps to SPI_GETICONTITLELOGFONT /// public static TextDecorationCollection IconFontTextDecorations { get { if (_iconFontTextDecorations == null) { _iconFontTextDecorations = new TextDecorationCollection(); if (SystemParameters.IconMetrics.lfFont.lfUnderline != 0) { CopyTextDecorationCollection(TextDecorations.Underline, _iconFontTextDecorations); } if (SystemParameters.IconMetrics.lfFont.lfStrikeOut != 0) { CopyTextDecorationCollection(TextDecorations.Strikethrough, _iconFontTextDecorations); } _iconFontTextDecorations.Freeze(); } return _iconFontTextDecorations; } } ////// Maps to SPI_NONCLIENTMETRICS /// public static double CaptionFontSize { get { return ConvertFontHeight(SystemParameters.NonClientMetrics.lfCaptionFont.lfHeight); } } ////// Maps to SPI_NONCLIENTMETRICS /// public static FontFamily CaptionFontFamily { get { if (_captionFontFamily == null) { _captionFontFamily = new FontFamily(SystemParameters.NonClientMetrics.lfCaptionFont.lfFaceName); } return _captionFontFamily; } } ////// Maps to SPI_NONCLIENTMETRICS /// public static FontStyle CaptionFontStyle { get { return (SystemParameters.NonClientMetrics.lfCaptionFont.lfItalic != 0) ? FontStyles.Italic : FontStyles.Normal; } } ////// Maps to SPI_NONCLIENTMETRICS /// public static FontWeight CaptionFontWeight { get { return FontWeight.FromOpenTypeWeight(SystemParameters.NonClientMetrics.lfCaptionFont.lfWeight); } } ////// Maps to SPI_NONCLIENTMETRICS /// public static TextDecorationCollection CaptionFontTextDecorations { get { if (_captionFontTextDecorations == null) { _captionFontTextDecorations = new TextDecorationCollection(); if (SystemParameters.NonClientMetrics.lfCaptionFont.lfUnderline != 0) { CopyTextDecorationCollection(TextDecorations.Underline, _captionFontTextDecorations); } if (SystemParameters.NonClientMetrics.lfCaptionFont.lfStrikeOut != 0) { CopyTextDecorationCollection(TextDecorations.Strikethrough, _captionFontTextDecorations); } _captionFontTextDecorations.Freeze(); } return _captionFontTextDecorations; } } ////// Maps to SPI_NONCLIENTMETRICS /// public static double SmallCaptionFontSize { get { return ConvertFontHeight(SystemParameters.NonClientMetrics.lfSmCaptionFont.lfHeight); } } ////// Maps to SPI_NONCLIENTMETRICS /// public static FontFamily SmallCaptionFontFamily { get { if (_smallCaptionFontFamily == null) { _smallCaptionFontFamily = new FontFamily(SystemParameters.NonClientMetrics.lfSmCaptionFont.lfFaceName); } return _smallCaptionFontFamily; } } ////// Maps to SPI_NONCLIENTMETRICS /// public static FontStyle SmallCaptionFontStyle { get { return (SystemParameters.NonClientMetrics.lfSmCaptionFont.lfItalic != 0) ? FontStyles.Italic : FontStyles.Normal; } } ////// Maps to SPI_NONCLIENTMETRICS /// public static FontWeight SmallCaptionFontWeight { get { return FontWeight.FromOpenTypeWeight(SystemParameters.NonClientMetrics.lfSmCaptionFont.lfWeight); } } ////// Maps to SPI_NONCLIENTMETRICS /// public static TextDecorationCollection SmallCaptionFontTextDecorations { get { if (_smallCaptionFontTextDecorations == null) { _smallCaptionFontTextDecorations = new TextDecorationCollection(); if (SystemParameters.NonClientMetrics.lfSmCaptionFont.lfUnderline != 0) { CopyTextDecorationCollection(TextDecorations.Underline, _smallCaptionFontTextDecorations); } if (SystemParameters.NonClientMetrics.lfSmCaptionFont.lfStrikeOut != 0) { CopyTextDecorationCollection(TextDecorations.Strikethrough, _smallCaptionFontTextDecorations); } _smallCaptionFontTextDecorations.Freeze(); } return _smallCaptionFontTextDecorations; } } ////// Maps to SPI_NONCLIENTMETRICS /// public static double MenuFontSize { get { return ConvertFontHeight(SystemParameters.NonClientMetrics.lfMenuFont.lfHeight); } } ////// Maps to SPI_NONCLIENTMETRICS /// public static FontFamily MenuFontFamily { get { if (_menuFontFamily == null) { _menuFontFamily = new FontFamily(SystemParameters.NonClientMetrics.lfMenuFont.lfFaceName); } return _menuFontFamily; } } ////// Maps to SPI_NONCLIENTMETRICS /// public static FontStyle MenuFontStyle { get { return (SystemParameters.NonClientMetrics.lfMenuFont.lfItalic != 0) ? FontStyles.Italic : FontStyles.Normal; } } ////// Maps to SPI_NONCLIENTMETRICS /// public static FontWeight MenuFontWeight { get { return FontWeight.FromOpenTypeWeight(SystemParameters.NonClientMetrics.lfMenuFont.lfWeight); } } ////// Maps to SPI_NONCLIENTMETRICS /// public static TextDecorationCollection MenuFontTextDecorations { get { if (_menuFontTextDecorations == null) { _menuFontTextDecorations = new TextDecorationCollection(); if (SystemParameters.NonClientMetrics.lfMenuFont.lfUnderline != 0) { CopyTextDecorationCollection(TextDecorations.Underline, _menuFontTextDecorations); } if (SystemParameters.NonClientMetrics.lfMenuFont.lfStrikeOut != 0) { CopyTextDecorationCollection(TextDecorations.Strikethrough, _menuFontTextDecorations); } _menuFontTextDecorations.Freeze(); } return _menuFontTextDecorations; } } ////// Maps to SPI_NONCLIENTMETRICS /// public static double StatusFontSize { get { return ConvertFontHeight(SystemParameters.NonClientMetrics.lfStatusFont.lfHeight); } } ////// Maps to SPI_NONCLIENTMETRICS /// public static FontFamily StatusFontFamily { get { if (_statusFontFamily == null) { _statusFontFamily = new FontFamily(SystemParameters.NonClientMetrics.lfStatusFont.lfFaceName); } return _statusFontFamily; } } ////// Maps to SPI_NONCLIENTMETRICS /// public static FontStyle StatusFontStyle { get { return (SystemParameters.NonClientMetrics.lfStatusFont.lfItalic != 0) ? FontStyles.Italic : FontStyles.Normal; } } ////// Maps to SPI_NONCLIENTMETRICS /// public static FontWeight StatusFontWeight { get { return FontWeight.FromOpenTypeWeight(SystemParameters.NonClientMetrics.lfStatusFont.lfWeight); } } ////// Maps to SPI_NONCLIENTMETRICS /// public static TextDecorationCollection StatusFontTextDecorations { get { if (_statusFontTextDecorations == null) { _statusFontTextDecorations = new TextDecorationCollection(); if (SystemParameters.NonClientMetrics.lfStatusFont.lfUnderline!= 0) { CopyTextDecorationCollection(TextDecorations.Underline, _statusFontTextDecorations); } if (SystemParameters.NonClientMetrics.lfStatusFont.lfStrikeOut != 0) { CopyTextDecorationCollection(TextDecorations.Strikethrough, _statusFontTextDecorations); } _statusFontTextDecorations.Freeze(); } return _statusFontTextDecorations; } } ////// Maps to SPI_NONCLIENTMETRICS /// public static double MessageFontSize { get { return ConvertFontHeight(SystemParameters.NonClientMetrics.lfMessageFont.lfHeight); } } ////// Maps to SPI_NONCLIENTMETRICS /// public static FontFamily MessageFontFamily { get { if (_messageFontFamily == null) { _messageFontFamily = new FontFamily(SystemParameters.NonClientMetrics.lfMessageFont.lfFaceName); } return _messageFontFamily; } } ////// Maps to SPI_NONCLIENTMETRICS /// public static FontStyle MessageFontStyle { get { return (SystemParameters.NonClientMetrics.lfMessageFont.lfItalic != 0) ? FontStyles.Italic : FontStyles.Normal; } } ////// Maps to SPI_NONCLIENTMETRICS /// public static FontWeight MessageFontWeight { get { return FontWeight.FromOpenTypeWeight(SystemParameters.NonClientMetrics.lfMessageFont.lfWeight); } } ////// Maps to SPI_NONCLIENTMETRICS /// public static TextDecorationCollection MessageFontTextDecorations { get { if (_messageFontTextDecorations == null) { _messageFontTextDecorations = new TextDecorationCollection(); if (SystemParameters.NonClientMetrics.lfMessageFont.lfUnderline != 0) { CopyTextDecorationCollection(TextDecorations.Underline, _messageFontTextDecorations); } if (SystemParameters.NonClientMetrics.lfMessageFont.lfStrikeOut != 0) { CopyTextDecorationCollection(TextDecorations.Strikethrough, _messageFontTextDecorations); } _messageFontTextDecorations.Freeze(); } return _messageFontTextDecorations; } } private static void CopyTextDecorationCollection(TextDecorationCollection from, TextDecorationCollection to) { int count = from.Count; for (int i = 0; i < count; ++i) { to.Add(from[i]); } } #endregion [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] private static SystemResourceKey CreateInstance(SystemResourceKeyID KeyId) { return new SystemResourceKey(KeyId); } #region Keys ////// IconFontSize System Resource Key /// public static ResourceKey IconFontSizeKey { get { if (_cacheIconFontSize == null) { _cacheIconFontSize = CreateInstance(SystemResourceKeyID.IconFontSize); } return _cacheIconFontSize; } } ////// IconFontFamily System Resource Key /// public static ResourceKey IconFontFamilyKey { get { if (_cacheIconFontFamily == null) { _cacheIconFontFamily = CreateInstance(SystemResourceKeyID.IconFontFamily); } return _cacheIconFontFamily; } } ////// IconFontStyle System Resource Key /// public static ResourceKey IconFontStyleKey { get { if (_cacheIconFontStyle == null) { _cacheIconFontStyle = CreateInstance(SystemResourceKeyID.IconFontStyle); } return _cacheIconFontStyle; } } ////// IconFontWeight System Resource Key /// public static ResourceKey IconFontWeightKey { get { if (_cacheIconFontWeight == null) { _cacheIconFontWeight = CreateInstance(SystemResourceKeyID.IconFontWeight); } return _cacheIconFontWeight; } } ////// IconFontTextDecorations System Resource Key /// public static ResourceKey IconFontTextDecorationsKey { get { if (_cacheIconFontTextDecorations == null) { _cacheIconFontTextDecorations = CreateInstance(SystemResourceKeyID.IconFontTextDecorations); } return _cacheIconFontTextDecorations; } } ////// CaptionFontSize System Resource Key /// public static ResourceKey CaptionFontSizeKey { get { if (_cacheCaptionFontSize == null) { _cacheCaptionFontSize = CreateInstance(SystemResourceKeyID.CaptionFontSize); } return _cacheCaptionFontSize; } } ////// CaptionFontFamily System Resource Key /// public static ResourceKey CaptionFontFamilyKey { get { if (_cacheCaptionFontFamily == null) { _cacheCaptionFontFamily = CreateInstance(SystemResourceKeyID.CaptionFontFamily); } return _cacheCaptionFontFamily; } } ////// CaptionFontStyle System Resource Key /// public static ResourceKey CaptionFontStyleKey { get { if (_cacheCaptionFontStyle == null) { _cacheCaptionFontStyle = CreateInstance(SystemResourceKeyID.CaptionFontStyle); } return _cacheCaptionFontStyle; } } ////// CaptionFontWeight System Resource Key /// public static ResourceKey CaptionFontWeightKey { get { if (_cacheCaptionFontWeight == null) { _cacheCaptionFontWeight = CreateInstance(SystemResourceKeyID.CaptionFontWeight); } return _cacheCaptionFontWeight; } } ////// CaptionFontTextDecorations System Resource Key /// public static ResourceKey CaptionFontTextDecorationsKey { get { if (_cacheCaptionFontTextDecorations == null) { _cacheCaptionFontTextDecorations = CreateInstance(SystemResourceKeyID.CaptionFontTextDecorations); } return _cacheCaptionFontTextDecorations; } } ////// SmallCaptionFontSize System Resource Key /// public static ResourceKey SmallCaptionFontSizeKey { get { if (_cacheSmallCaptionFontSize == null) { _cacheSmallCaptionFontSize = CreateInstance(SystemResourceKeyID.SmallCaptionFontSize); } return _cacheSmallCaptionFontSize; } } ////// SmallCaptionFontFamily System Resource Key /// public static ResourceKey SmallCaptionFontFamilyKey { get { if (_cacheSmallCaptionFontFamily == null) { _cacheSmallCaptionFontFamily = CreateInstance(SystemResourceKeyID.SmallCaptionFontFamily); } return _cacheSmallCaptionFontFamily; } } ////// SmallCaptionFontStyle System Resource Key /// public static ResourceKey SmallCaptionFontStyleKey { get { if (_cacheSmallCaptionFontStyle == null) { _cacheSmallCaptionFontStyle = CreateInstance(SystemResourceKeyID.SmallCaptionFontStyle); } return _cacheSmallCaptionFontStyle; } } ////// SmallCaptionFontWeight System Resource Key /// public static ResourceKey SmallCaptionFontWeightKey { get { if (_cacheSmallCaptionFontWeight == null) { _cacheSmallCaptionFontWeight = CreateInstance(SystemResourceKeyID.SmallCaptionFontWeight); } return _cacheSmallCaptionFontWeight; } } ////// SmallCaptionFontTextDecorations System Resource Key /// public static ResourceKey SmallCaptionFontTextDecorationsKey { get { if (_cacheSmallCaptionFontTextDecorations == null) { _cacheSmallCaptionFontTextDecorations = CreateInstance(SystemResourceKeyID.SmallCaptionFontTextDecorations); } return _cacheSmallCaptionFontTextDecorations; } } ////// MenuFontSize System Resource Key /// public static ResourceKey MenuFontSizeKey { get { if (_cacheMenuFontSize == null) { _cacheMenuFontSize = CreateInstance(SystemResourceKeyID.MenuFontSize); } return _cacheMenuFontSize; } } ////// MenuFontFamily System Resource Key /// public static ResourceKey MenuFontFamilyKey { get { if (_cacheMenuFontFamily == null) { _cacheMenuFontFamily = CreateInstance(SystemResourceKeyID.MenuFontFamily); } return _cacheMenuFontFamily; } } ////// MenuFontStyle System Resource Key /// public static ResourceKey MenuFontStyleKey { get { if (_cacheMenuFontStyle == null) { _cacheMenuFontStyle = CreateInstance(SystemResourceKeyID.MenuFontStyle); } return _cacheMenuFontStyle; } } ////// MenuFontWeight System Resource Key /// public static ResourceKey MenuFontWeightKey { get { if (_cacheMenuFontWeight == null) { _cacheMenuFontWeight = CreateInstance(SystemResourceKeyID.MenuFontWeight); } return _cacheMenuFontWeight; } } ////// MenuFontTextDecorations System Resource Key /// public static ResourceKey MenuFontTextDecorationsKey { get { if (_cacheMenuFontTextDecorations == null) { _cacheMenuFontTextDecorations = CreateInstance(SystemResourceKeyID.MenuFontTextDecorations); } return _cacheMenuFontTextDecorations; } } ////// StatusFontSize System Resource Key /// public static ResourceKey StatusFontSizeKey { get { if (_cacheStatusFontSize == null) { _cacheStatusFontSize = CreateInstance(SystemResourceKeyID.StatusFontSize); } return _cacheStatusFontSize; } } ////// StatusFontFamily System Resource Key /// public static ResourceKey StatusFontFamilyKey { get { if (_cacheStatusFontFamily == null) { _cacheStatusFontFamily = CreateInstance(SystemResourceKeyID.StatusFontFamily); } return _cacheStatusFontFamily; } } ////// StatusFontStyle System Resource Key /// public static ResourceKey StatusFontStyleKey { get { if (_cacheStatusFontStyle == null) { _cacheStatusFontStyle = CreateInstance(SystemResourceKeyID.StatusFontStyle); } return _cacheStatusFontStyle; } } ////// StatusFontWeight System Resource Key /// public static ResourceKey StatusFontWeightKey { get { if (_cacheStatusFontWeight == null) { _cacheStatusFontWeight = CreateInstance(SystemResourceKeyID.StatusFontWeight); } return _cacheStatusFontWeight; } } ////// StatusFontTextDecorations System Resource Key /// public static ResourceKey StatusFontTextDecorationsKey { get { if (_cacheStatusFontTextDecorations == null) { _cacheStatusFontTextDecorations = CreateInstance(SystemResourceKeyID.StatusFontTextDecorations); } return _cacheStatusFontTextDecorations; } } ////// MessageFontSize System Resource Key /// public static ResourceKey MessageFontSizeKey { get { if (_cacheMessageFontSize == null) { _cacheMessageFontSize = CreateInstance(SystemResourceKeyID.MessageFontSize); } return _cacheMessageFontSize; } } ////// MessageFontFamily System Resource Key /// public static ResourceKey MessageFontFamilyKey { get { if (_cacheMessageFontFamily == null) { _cacheMessageFontFamily = CreateInstance(SystemResourceKeyID.MessageFontFamily); } return _cacheMessageFontFamily; } } ////// MessageFontStyle System Resource Key /// public static ResourceKey MessageFontStyleKey { get { if (_cacheMessageFontStyle == null) { _cacheMessageFontStyle = CreateInstance(SystemResourceKeyID.MessageFontStyle); } return _cacheMessageFontStyle; } } ////// MessageFontWeight System Resource Key /// public static ResourceKey MessageFontWeightKey { get { if (_cacheMessageFontWeight == null) { _cacheMessageFontWeight = CreateInstance(SystemResourceKeyID.MessageFontWeight); } return _cacheMessageFontWeight; } } ////// MessageFontTextDecorations System Resource Key /// public static ResourceKey MessageFontTextDecorationsKey { get { if (_cacheMessageFontTextDecorations == null) { _cacheMessageFontTextDecorations = CreateInstance(SystemResourceKeyID.MessageFontTextDecorations); } return _cacheMessageFontTextDecorations; } } #endregion #region Implementation private static double ConvertFontHeight(int height) { int dpi = SystemParameters.Dpi; if (dpi != 0) { return (double)(Math.Abs(height) * 96 / dpi); } else { // Could not get the DPI to convert the size, using the hardcoded fallback value return FallbackFontSize; } } private const double FallbackFontSize = 11.0; // To use if unable to get the system size internal static void InvalidateIconMetrics() { _iconFontTextDecorations = null; _iconFontFamily = null; } internal static void InvalidateNonClientMetrics() { _messageFontTextDecorations = null; _statusFontTextDecorations = null; _menuFontTextDecorations = null; _smallCaptionFontTextDecorations = null; _captionFontTextDecorations = null; _messageFontFamily = null; _statusFontFamily = null; _menuFontFamily = null; _smallCaptionFontFamily = null; _captionFontFamily = null; } private static TextDecorationCollection _iconFontTextDecorations; private static TextDecorationCollection _messageFontTextDecorations; private static TextDecorationCollection _statusFontTextDecorations; private static TextDecorationCollection _menuFontTextDecorations; private static TextDecorationCollection _smallCaptionFontTextDecorations; private static TextDecorationCollection _captionFontTextDecorations; private static FontFamily _iconFontFamily; private static FontFamily _messageFontFamily; private static FontFamily _statusFontFamily; private static FontFamily _menuFontFamily; private static FontFamily _smallCaptionFontFamily; private static FontFamily _captionFontFamily; private static SystemResourceKey _cacheIconFontSize; private static SystemResourceKey _cacheIconFontFamily; private static SystemResourceKey _cacheIconFontStyle; private static SystemResourceKey _cacheIconFontWeight; private static SystemResourceKey _cacheIconFontTextDecorations; private static SystemResourceKey _cacheCaptionFontSize; private static SystemResourceKey _cacheCaptionFontFamily; private static SystemResourceKey _cacheCaptionFontStyle; private static SystemResourceKey _cacheCaptionFontWeight; private static SystemResourceKey _cacheCaptionFontTextDecorations; private static SystemResourceKey _cacheSmallCaptionFontSize; private static SystemResourceKey _cacheSmallCaptionFontFamily; private static SystemResourceKey _cacheSmallCaptionFontStyle; private static SystemResourceKey _cacheSmallCaptionFontWeight; private static SystemResourceKey _cacheSmallCaptionFontTextDecorations; private static SystemResourceKey _cacheMenuFontSize; private static SystemResourceKey _cacheMenuFontFamily; private static SystemResourceKey _cacheMenuFontStyle; private static SystemResourceKey _cacheMenuFontWeight; private static SystemResourceKey _cacheMenuFontTextDecorations; private static SystemResourceKey _cacheStatusFontSize; private static SystemResourceKey _cacheStatusFontFamily; private static SystemResourceKey _cacheStatusFontStyle; private static SystemResourceKey _cacheStatusFontWeight; private static SystemResourceKey _cacheStatusFontTextDecorations; private static SystemResourceKey _cacheMessageFontSize; private static SystemResourceKey _cacheMessageFontFamily; private static SystemResourceKey _cacheMessageFontStyle; private static SystemResourceKey _cacheMessageFontWeight; private static SystemResourceKey _cacheMessageFontTextDecorations; #endregion } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. using System; using System.Collections; using System.ComponentModel; using System.Runtime.InteropServices; using System.Windows.Media; using System.Security; using System.Windows.Controls.Primitives; using Microsoft.Win32; using MS.Win32; using MS.Internal; namespace System.Windows { ////// Contains properties that are queries into the system's various settings. /// public static class SystemFonts { #region Fonts ////// Maps to SPI_GETICONTITLELOGFONT /// public static double IconFontSize { get { return ConvertFontHeight(SystemParameters.IconMetrics.lfFont.lfHeight); } } ////// Maps to SPI_GETICONTITLELOGFONT /// public static FontFamily IconFontFamily { get { if (_iconFontFamily == null) { _iconFontFamily = new FontFamily(SystemParameters.IconMetrics.lfFont.lfFaceName); } return _iconFontFamily; } } ////// Maps to SPI_GETICONTITLELOGFONT /// public static FontStyle IconFontStyle { get { return (SystemParameters.IconMetrics.lfFont.lfItalic != 0) ? FontStyles.Italic : FontStyles.Normal; } } ////// Maps to SPI_GETICONTITLELOGFONT /// public static FontWeight IconFontWeight { get { return FontWeight.FromOpenTypeWeight(SystemParameters.IconMetrics.lfFont.lfWeight); } } ////// Maps to SPI_GETICONTITLELOGFONT /// public static TextDecorationCollection IconFontTextDecorations { get { if (_iconFontTextDecorations == null) { _iconFontTextDecorations = new TextDecorationCollection(); if (SystemParameters.IconMetrics.lfFont.lfUnderline != 0) { CopyTextDecorationCollection(TextDecorations.Underline, _iconFontTextDecorations); } if (SystemParameters.IconMetrics.lfFont.lfStrikeOut != 0) { CopyTextDecorationCollection(TextDecorations.Strikethrough, _iconFontTextDecorations); } _iconFontTextDecorations.Freeze(); } return _iconFontTextDecorations; } } ////// Maps to SPI_NONCLIENTMETRICS /// public static double CaptionFontSize { get { return ConvertFontHeight(SystemParameters.NonClientMetrics.lfCaptionFont.lfHeight); } } ////// Maps to SPI_NONCLIENTMETRICS /// public static FontFamily CaptionFontFamily { get { if (_captionFontFamily == null) { _captionFontFamily = new FontFamily(SystemParameters.NonClientMetrics.lfCaptionFont.lfFaceName); } return _captionFontFamily; } } ////// Maps to SPI_NONCLIENTMETRICS /// public static FontStyle CaptionFontStyle { get { return (SystemParameters.NonClientMetrics.lfCaptionFont.lfItalic != 0) ? FontStyles.Italic : FontStyles.Normal; } } ////// Maps to SPI_NONCLIENTMETRICS /// public static FontWeight CaptionFontWeight { get { return FontWeight.FromOpenTypeWeight(SystemParameters.NonClientMetrics.lfCaptionFont.lfWeight); } } ////// Maps to SPI_NONCLIENTMETRICS /// public static TextDecorationCollection CaptionFontTextDecorations { get { if (_captionFontTextDecorations == null) { _captionFontTextDecorations = new TextDecorationCollection(); if (SystemParameters.NonClientMetrics.lfCaptionFont.lfUnderline != 0) { CopyTextDecorationCollection(TextDecorations.Underline, _captionFontTextDecorations); } if (SystemParameters.NonClientMetrics.lfCaptionFont.lfStrikeOut != 0) { CopyTextDecorationCollection(TextDecorations.Strikethrough, _captionFontTextDecorations); } _captionFontTextDecorations.Freeze(); } return _captionFontTextDecorations; } } ////// Maps to SPI_NONCLIENTMETRICS /// public static double SmallCaptionFontSize { get { return ConvertFontHeight(SystemParameters.NonClientMetrics.lfSmCaptionFont.lfHeight); } } ////// Maps to SPI_NONCLIENTMETRICS /// public static FontFamily SmallCaptionFontFamily { get { if (_smallCaptionFontFamily == null) { _smallCaptionFontFamily = new FontFamily(SystemParameters.NonClientMetrics.lfSmCaptionFont.lfFaceName); } return _smallCaptionFontFamily; } } ////// Maps to SPI_NONCLIENTMETRICS /// public static FontStyle SmallCaptionFontStyle { get { return (SystemParameters.NonClientMetrics.lfSmCaptionFont.lfItalic != 0) ? FontStyles.Italic : FontStyles.Normal; } } ////// Maps to SPI_NONCLIENTMETRICS /// public static FontWeight SmallCaptionFontWeight { get { return FontWeight.FromOpenTypeWeight(SystemParameters.NonClientMetrics.lfSmCaptionFont.lfWeight); } } ////// Maps to SPI_NONCLIENTMETRICS /// public static TextDecorationCollection SmallCaptionFontTextDecorations { get { if (_smallCaptionFontTextDecorations == null) { _smallCaptionFontTextDecorations = new TextDecorationCollection(); if (SystemParameters.NonClientMetrics.lfSmCaptionFont.lfUnderline != 0) { CopyTextDecorationCollection(TextDecorations.Underline, _smallCaptionFontTextDecorations); } if (SystemParameters.NonClientMetrics.lfSmCaptionFont.lfStrikeOut != 0) { CopyTextDecorationCollection(TextDecorations.Strikethrough, _smallCaptionFontTextDecorations); } _smallCaptionFontTextDecorations.Freeze(); } return _smallCaptionFontTextDecorations; } } ////// Maps to SPI_NONCLIENTMETRICS /// public static double MenuFontSize { get { return ConvertFontHeight(SystemParameters.NonClientMetrics.lfMenuFont.lfHeight); } } ////// Maps to SPI_NONCLIENTMETRICS /// public static FontFamily MenuFontFamily { get { if (_menuFontFamily == null) { _menuFontFamily = new FontFamily(SystemParameters.NonClientMetrics.lfMenuFont.lfFaceName); } return _menuFontFamily; } } ////// Maps to SPI_NONCLIENTMETRICS /// public static FontStyle MenuFontStyle { get { return (SystemParameters.NonClientMetrics.lfMenuFont.lfItalic != 0) ? FontStyles.Italic : FontStyles.Normal; } } ////// Maps to SPI_NONCLIENTMETRICS /// public static FontWeight MenuFontWeight { get { return FontWeight.FromOpenTypeWeight(SystemParameters.NonClientMetrics.lfMenuFont.lfWeight); } } ////// Maps to SPI_NONCLIENTMETRICS /// public static TextDecorationCollection MenuFontTextDecorations { get { if (_menuFontTextDecorations == null) { _menuFontTextDecorations = new TextDecorationCollection(); if (SystemParameters.NonClientMetrics.lfMenuFont.lfUnderline != 0) { CopyTextDecorationCollection(TextDecorations.Underline, _menuFontTextDecorations); } if (SystemParameters.NonClientMetrics.lfMenuFont.lfStrikeOut != 0) { CopyTextDecorationCollection(TextDecorations.Strikethrough, _menuFontTextDecorations); } _menuFontTextDecorations.Freeze(); } return _menuFontTextDecorations; } } ////// Maps to SPI_NONCLIENTMETRICS /// public static double StatusFontSize { get { return ConvertFontHeight(SystemParameters.NonClientMetrics.lfStatusFont.lfHeight); } } ////// Maps to SPI_NONCLIENTMETRICS /// public static FontFamily StatusFontFamily { get { if (_statusFontFamily == null) { _statusFontFamily = new FontFamily(SystemParameters.NonClientMetrics.lfStatusFont.lfFaceName); } return _statusFontFamily; } } ////// Maps to SPI_NONCLIENTMETRICS /// public static FontStyle StatusFontStyle { get { return (SystemParameters.NonClientMetrics.lfStatusFont.lfItalic != 0) ? FontStyles.Italic : FontStyles.Normal; } } ////// Maps to SPI_NONCLIENTMETRICS /// public static FontWeight StatusFontWeight { get { return FontWeight.FromOpenTypeWeight(SystemParameters.NonClientMetrics.lfStatusFont.lfWeight); } } ////// Maps to SPI_NONCLIENTMETRICS /// public static TextDecorationCollection StatusFontTextDecorations { get { if (_statusFontTextDecorations == null) { _statusFontTextDecorations = new TextDecorationCollection(); if (SystemParameters.NonClientMetrics.lfStatusFont.lfUnderline!= 0) { CopyTextDecorationCollection(TextDecorations.Underline, _statusFontTextDecorations); } if (SystemParameters.NonClientMetrics.lfStatusFont.lfStrikeOut != 0) { CopyTextDecorationCollection(TextDecorations.Strikethrough, _statusFontTextDecorations); } _statusFontTextDecorations.Freeze(); } return _statusFontTextDecorations; } } ////// Maps to SPI_NONCLIENTMETRICS /// public static double MessageFontSize { get { return ConvertFontHeight(SystemParameters.NonClientMetrics.lfMessageFont.lfHeight); } } ////// Maps to SPI_NONCLIENTMETRICS /// public static FontFamily MessageFontFamily { get { if (_messageFontFamily == null) { _messageFontFamily = new FontFamily(SystemParameters.NonClientMetrics.lfMessageFont.lfFaceName); } return _messageFontFamily; } } ////// Maps to SPI_NONCLIENTMETRICS /// public static FontStyle MessageFontStyle { get { return (SystemParameters.NonClientMetrics.lfMessageFont.lfItalic != 0) ? FontStyles.Italic : FontStyles.Normal; } } ////// Maps to SPI_NONCLIENTMETRICS /// public static FontWeight MessageFontWeight { get { return FontWeight.FromOpenTypeWeight(SystemParameters.NonClientMetrics.lfMessageFont.lfWeight); } } ////// Maps to SPI_NONCLIENTMETRICS /// public static TextDecorationCollection MessageFontTextDecorations { get { if (_messageFontTextDecorations == null) { _messageFontTextDecorations = new TextDecorationCollection(); if (SystemParameters.NonClientMetrics.lfMessageFont.lfUnderline != 0) { CopyTextDecorationCollection(TextDecorations.Underline, _messageFontTextDecorations); } if (SystemParameters.NonClientMetrics.lfMessageFont.lfStrikeOut != 0) { CopyTextDecorationCollection(TextDecorations.Strikethrough, _messageFontTextDecorations); } _messageFontTextDecorations.Freeze(); } return _messageFontTextDecorations; } } private static void CopyTextDecorationCollection(TextDecorationCollection from, TextDecorationCollection to) { int count = from.Count; for (int i = 0; i < count; ++i) { to.Add(from[i]); } } #endregion [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)] private static SystemResourceKey CreateInstance(SystemResourceKeyID KeyId) { return new SystemResourceKey(KeyId); } #region Keys ////// IconFontSize System Resource Key /// public static ResourceKey IconFontSizeKey { get { if (_cacheIconFontSize == null) { _cacheIconFontSize = CreateInstance(SystemResourceKeyID.IconFontSize); } return _cacheIconFontSize; } } ////// IconFontFamily System Resource Key /// public static ResourceKey IconFontFamilyKey { get { if (_cacheIconFontFamily == null) { _cacheIconFontFamily = CreateInstance(SystemResourceKeyID.IconFontFamily); } return _cacheIconFontFamily; } } ////// IconFontStyle System Resource Key /// public static ResourceKey IconFontStyleKey { get { if (_cacheIconFontStyle == null) { _cacheIconFontStyle = CreateInstance(SystemResourceKeyID.IconFontStyle); } return _cacheIconFontStyle; } } ////// IconFontWeight System Resource Key /// public static ResourceKey IconFontWeightKey { get { if (_cacheIconFontWeight == null) { _cacheIconFontWeight = CreateInstance(SystemResourceKeyID.IconFontWeight); } return _cacheIconFontWeight; } } ////// IconFontTextDecorations System Resource Key /// public static ResourceKey IconFontTextDecorationsKey { get { if (_cacheIconFontTextDecorations == null) { _cacheIconFontTextDecorations = CreateInstance(SystemResourceKeyID.IconFontTextDecorations); } return _cacheIconFontTextDecorations; } } ////// CaptionFontSize System Resource Key /// public static ResourceKey CaptionFontSizeKey { get { if (_cacheCaptionFontSize == null) { _cacheCaptionFontSize = CreateInstance(SystemResourceKeyID.CaptionFontSize); } return _cacheCaptionFontSize; } } ////// CaptionFontFamily System Resource Key /// public static ResourceKey CaptionFontFamilyKey { get { if (_cacheCaptionFontFamily == null) { _cacheCaptionFontFamily = CreateInstance(SystemResourceKeyID.CaptionFontFamily); } return _cacheCaptionFontFamily; } } ////// CaptionFontStyle System Resource Key /// public static ResourceKey CaptionFontStyleKey { get { if (_cacheCaptionFontStyle == null) { _cacheCaptionFontStyle = CreateInstance(SystemResourceKeyID.CaptionFontStyle); } return _cacheCaptionFontStyle; } } ////// CaptionFontWeight System Resource Key /// public static ResourceKey CaptionFontWeightKey { get { if (_cacheCaptionFontWeight == null) { _cacheCaptionFontWeight = CreateInstance(SystemResourceKeyID.CaptionFontWeight); } return _cacheCaptionFontWeight; } } ////// CaptionFontTextDecorations System Resource Key /// public static ResourceKey CaptionFontTextDecorationsKey { get { if (_cacheCaptionFontTextDecorations == null) { _cacheCaptionFontTextDecorations = CreateInstance(SystemResourceKeyID.CaptionFontTextDecorations); } return _cacheCaptionFontTextDecorations; } } ////// SmallCaptionFontSize System Resource Key /// public static ResourceKey SmallCaptionFontSizeKey { get { if (_cacheSmallCaptionFontSize == null) { _cacheSmallCaptionFontSize = CreateInstance(SystemResourceKeyID.SmallCaptionFontSize); } return _cacheSmallCaptionFontSize; } } ////// SmallCaptionFontFamily System Resource Key /// public static ResourceKey SmallCaptionFontFamilyKey { get { if (_cacheSmallCaptionFontFamily == null) { _cacheSmallCaptionFontFamily = CreateInstance(SystemResourceKeyID.SmallCaptionFontFamily); } return _cacheSmallCaptionFontFamily; } } ////// SmallCaptionFontStyle System Resource Key /// public static ResourceKey SmallCaptionFontStyleKey { get { if (_cacheSmallCaptionFontStyle == null) { _cacheSmallCaptionFontStyle = CreateInstance(SystemResourceKeyID.SmallCaptionFontStyle); } return _cacheSmallCaptionFontStyle; } } ////// SmallCaptionFontWeight System Resource Key /// public static ResourceKey SmallCaptionFontWeightKey { get { if (_cacheSmallCaptionFontWeight == null) { _cacheSmallCaptionFontWeight = CreateInstance(SystemResourceKeyID.SmallCaptionFontWeight); } return _cacheSmallCaptionFontWeight; } } ////// SmallCaptionFontTextDecorations System Resource Key /// public static ResourceKey SmallCaptionFontTextDecorationsKey { get { if (_cacheSmallCaptionFontTextDecorations == null) { _cacheSmallCaptionFontTextDecorations = CreateInstance(SystemResourceKeyID.SmallCaptionFontTextDecorations); } return _cacheSmallCaptionFontTextDecorations; } } ////// MenuFontSize System Resource Key /// public static ResourceKey MenuFontSizeKey { get { if (_cacheMenuFontSize == null) { _cacheMenuFontSize = CreateInstance(SystemResourceKeyID.MenuFontSize); } return _cacheMenuFontSize; } } ////// MenuFontFamily System Resource Key /// public static ResourceKey MenuFontFamilyKey { get { if (_cacheMenuFontFamily == null) { _cacheMenuFontFamily = CreateInstance(SystemResourceKeyID.MenuFontFamily); } return _cacheMenuFontFamily; } } ////// MenuFontStyle System Resource Key /// public static ResourceKey MenuFontStyleKey { get { if (_cacheMenuFontStyle == null) { _cacheMenuFontStyle = CreateInstance(SystemResourceKeyID.MenuFontStyle); } return _cacheMenuFontStyle; } } ////// MenuFontWeight System Resource Key /// public static ResourceKey MenuFontWeightKey { get { if (_cacheMenuFontWeight == null) { _cacheMenuFontWeight = CreateInstance(SystemResourceKeyID.MenuFontWeight); } return _cacheMenuFontWeight; } } ////// MenuFontTextDecorations System Resource Key /// public static ResourceKey MenuFontTextDecorationsKey { get { if (_cacheMenuFontTextDecorations == null) { _cacheMenuFontTextDecorations = CreateInstance(SystemResourceKeyID.MenuFontTextDecorations); } return _cacheMenuFontTextDecorations; } } ////// StatusFontSize System Resource Key /// public static ResourceKey StatusFontSizeKey { get { if (_cacheStatusFontSize == null) { _cacheStatusFontSize = CreateInstance(SystemResourceKeyID.StatusFontSize); } return _cacheStatusFontSize; } } ////// StatusFontFamily System Resource Key /// public static ResourceKey StatusFontFamilyKey { get { if (_cacheStatusFontFamily == null) { _cacheStatusFontFamily = CreateInstance(SystemResourceKeyID.StatusFontFamily); } return _cacheStatusFontFamily; } } ////// StatusFontStyle System Resource Key /// public static ResourceKey StatusFontStyleKey { get { if (_cacheStatusFontStyle == null) { _cacheStatusFontStyle = CreateInstance(SystemResourceKeyID.StatusFontStyle); } return _cacheStatusFontStyle; } } ////// StatusFontWeight System Resource Key /// public static ResourceKey StatusFontWeightKey { get { if (_cacheStatusFontWeight == null) { _cacheStatusFontWeight = CreateInstance(SystemResourceKeyID.StatusFontWeight); } return _cacheStatusFontWeight; } } ////// StatusFontTextDecorations System Resource Key /// public static ResourceKey StatusFontTextDecorationsKey { get { if (_cacheStatusFontTextDecorations == null) { _cacheStatusFontTextDecorations = CreateInstance(SystemResourceKeyID.StatusFontTextDecorations); } return _cacheStatusFontTextDecorations; } } ////// MessageFontSize System Resource Key /// public static ResourceKey MessageFontSizeKey { get { if (_cacheMessageFontSize == null) { _cacheMessageFontSize = CreateInstance(SystemResourceKeyID.MessageFontSize); } return _cacheMessageFontSize; } } ////// MessageFontFamily System Resource Key /// public static ResourceKey MessageFontFamilyKey { get { if (_cacheMessageFontFamily == null) { _cacheMessageFontFamily = CreateInstance(SystemResourceKeyID.MessageFontFamily); } return _cacheMessageFontFamily; } } ////// MessageFontStyle System Resource Key /// public static ResourceKey MessageFontStyleKey { get { if (_cacheMessageFontStyle == null) { _cacheMessageFontStyle = CreateInstance(SystemResourceKeyID.MessageFontStyle); } return _cacheMessageFontStyle; } } ////// MessageFontWeight System Resource Key /// public static ResourceKey MessageFontWeightKey { get { if (_cacheMessageFontWeight == null) { _cacheMessageFontWeight = CreateInstance(SystemResourceKeyID.MessageFontWeight); } return _cacheMessageFontWeight; } } ////// MessageFontTextDecorations System Resource Key /// public static ResourceKey MessageFontTextDecorationsKey { get { if (_cacheMessageFontTextDecorations == null) { _cacheMessageFontTextDecorations = CreateInstance(SystemResourceKeyID.MessageFontTextDecorations); } return _cacheMessageFontTextDecorations; } } #endregion #region Implementation private static double ConvertFontHeight(int height) { int dpi = SystemParameters.Dpi; if (dpi != 0) { return (double)(Math.Abs(height) * 96 / dpi); } else { // Could not get the DPI to convert the size, using the hardcoded fallback value return FallbackFontSize; } } private const double FallbackFontSize = 11.0; // To use if unable to get the system size internal static void InvalidateIconMetrics() { _iconFontTextDecorations = null; _iconFontFamily = null; } internal static void InvalidateNonClientMetrics() { _messageFontTextDecorations = null; _statusFontTextDecorations = null; _menuFontTextDecorations = null; _smallCaptionFontTextDecorations = null; _captionFontTextDecorations = null; _messageFontFamily = null; _statusFontFamily = null; _menuFontFamily = null; _smallCaptionFontFamily = null; _captionFontFamily = null; } private static TextDecorationCollection _iconFontTextDecorations; private static TextDecorationCollection _messageFontTextDecorations; private static TextDecorationCollection _statusFontTextDecorations; private static TextDecorationCollection _menuFontTextDecorations; private static TextDecorationCollection _smallCaptionFontTextDecorations; private static TextDecorationCollection _captionFontTextDecorations; private static FontFamily _iconFontFamily; private static FontFamily _messageFontFamily; private static FontFamily _statusFontFamily; private static FontFamily _menuFontFamily; private static FontFamily _smallCaptionFontFamily; private static FontFamily _captionFontFamily; private static SystemResourceKey _cacheIconFontSize; private static SystemResourceKey _cacheIconFontFamily; private static SystemResourceKey _cacheIconFontStyle; private static SystemResourceKey _cacheIconFontWeight; private static SystemResourceKey _cacheIconFontTextDecorations; private static SystemResourceKey _cacheCaptionFontSize; private static SystemResourceKey _cacheCaptionFontFamily; private static SystemResourceKey _cacheCaptionFontStyle; private static SystemResourceKey _cacheCaptionFontWeight; private static SystemResourceKey _cacheCaptionFontTextDecorations; private static SystemResourceKey _cacheSmallCaptionFontSize; private static SystemResourceKey _cacheSmallCaptionFontFamily; private static SystemResourceKey _cacheSmallCaptionFontStyle; private static SystemResourceKey _cacheSmallCaptionFontWeight; private static SystemResourceKey _cacheSmallCaptionFontTextDecorations; private static SystemResourceKey _cacheMenuFontSize; private static SystemResourceKey _cacheMenuFontFamily; private static SystemResourceKey _cacheMenuFontStyle; private static SystemResourceKey _cacheMenuFontWeight; private static SystemResourceKey _cacheMenuFontTextDecorations; private static SystemResourceKey _cacheStatusFontSize; private static SystemResourceKey _cacheStatusFontFamily; private static SystemResourceKey _cacheStatusFontStyle; private static SystemResourceKey _cacheStatusFontWeight; private static SystemResourceKey _cacheStatusFontTextDecorations; private static SystemResourceKey _cacheMessageFontSize; private static SystemResourceKey _cacheMessageFontFamily; private static SystemResourceKey _cacheMessageFontStyle; private static SystemResourceKey _cacheMessageFontWeight; private static SystemResourceKey _cacheMessageFontTextDecorations; #endregion } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- DefaultTraceListener.cs
- TimelineCollection.cs
- GraphicsState.cs
- OpCodes.cs
- OutputScopeManager.cs
- TdsRecordBufferSetter.cs
- CriticalHandle.cs
- AnimatedTypeHelpers.cs
- WebOperationContext.cs
- XmlSchemaSequence.cs
- GlyphTypeface.cs
- RemotingException.cs
- RemoteWebConfigurationHostServer.cs
- MetaTable.cs
- SecureStringHasher.cs
- TokenBasedSet.cs
- FormViewUpdatedEventArgs.cs
- SafeReversePInvokeHandle.cs
- RoutedEventHandlerInfo.cs
- _ListenerRequestStream.cs
- TextServicesCompartmentEventSink.cs
- XmlDataContract.cs
- Int32EqualityComparer.cs
- IdentityValidationException.cs
- CollaborationHelperFunctions.cs
- ModelItemKeyValuePair.cs
- WebZone.cs
- _NetRes.cs
- ComponentResourceManager.cs
- XsdDateTime.cs
- ExtensibleClassFactory.cs
- OutputCacheSettings.cs
- AdRotator.cs
- MemberRestriction.cs
- BypassElement.cs
- AsymmetricKeyExchangeDeformatter.cs
- FormatControl.cs
- ConfigurationStrings.cs
- TextViewBase.cs
- LowerCaseStringConverter.cs
- ObjectStateEntry.cs
- PassportAuthenticationEventArgs.cs
- HostedImpersonationContext.cs
- CompilerCollection.cs
- CodeExpressionCollection.cs
- IriParsingElement.cs
- JournalEntry.cs
- CatalogPart.cs
- UInt32Converter.cs
- WebZone.cs
- RoleGroup.cs
- SelectionItemProviderWrapper.cs
- COMException.cs
- DocumentViewerBaseAutomationPeer.cs
- HMACRIPEMD160.cs
- TaskFactory.cs
- ControlPaint.cs
- FileIOPermission.cs
- RangeValidator.cs
- SafeTimerHandle.cs
- GlobalizationSection.cs
- StructuredTypeInfo.cs
- XmlChoiceIdentifierAttribute.cs
- CodeArgumentReferenceExpression.cs
- xamlnodes.cs
- PropertyMetadata.cs
- SQLByte.cs
- TouchPoint.cs
- WSSecurityXXX2005.cs
- SqlClientPermission.cs
- DoubleLinkListEnumerator.cs
- Stylesheet.cs
- Point3DCollection.cs
- ExpressionWriter.cs
- ColumnCollection.cs
- TextDecoration.cs
- WebPartZoneBase.cs
- DataRelationCollection.cs
- DirectoryNotFoundException.cs
- ResourceReferenceKeyNotFoundException.cs
- StickyNoteAnnotations.cs
- CustomError.cs
- AppDomainManager.cs
- XmlSortKey.cs
- XmlNavigatorStack.cs
- ConsoleKeyInfo.cs
- SqlXmlStorage.cs
- ConnectionsZoneAutoFormat.cs
- GlyphInfoList.cs
- IisTraceWebEventProvider.cs
- XmlIlGenerator.cs
- InlineObject.cs
- DateBoldEvent.cs
- ButtonDesigner.cs
- Condition.cs
- IBuiltInEvidence.cs
- ScriptMethodAttribute.cs
- mactripleDES.cs
- SecureEnvironment.cs
- IItemContainerGenerator.cs