/// <include file='doc\StyleBuilderSite.uex' path='docs/doc[@for="StyleBuilderSite.GetUIFont"]/*' /> /// <devdoc> /// </devdoc> public Font GetUIFont() { Font uiFont = null; if (site != null) { try { IUIHostLocale uiService = (IUIHostLocale)QueryService(typeof(IUIHostLocale)); _LOGFONTW lfUnicode = new _LOGFONTW(); uiService.GetDialogFont(lfUnicode); NativeMethods.LOGFONT lfAuto = lfUnicode.ToLOGFONT_Internal(); uiFont = Font.FromLogFont(lfAuto); } catch (Exception e) { Debug.Fail(e.ToString()); } } if (uiFont == null) { try { // this is what VS returns... uiFont = new Font("Tahoma", 11, FontStyle.Regular, GraphicsUnit.World); } catch { uiFont = Control.DefaultFont; } } return(uiFont); }
//========================================================================================== // Constructors //========================================================================================== /// <summary> /// Initializes a new instance of the <see cref="PackageContext"/> class. /// </summary> /// <param name="serviceProvider"> /// The <see cref="ServiceProvider"/> instance to use for getting services from the environment. /// </param> public PackageContext(ServiceProvider serviceProvider) { Tracer.VerifyNonNullArgument(serviceProvider, "serviceProvider"); this.serviceProvider = serviceProvider; // Get an IUIHostLocale instance and Visual Studio's locale IUIHostLocale hostLocale = this.GetService(typeof(SUIHostLocale)) as IUIHostLocale; Tracer.Assert(hostLocale != null, "Cannot get Visual Studio's locale. Defaulting to current thread's locale."); int lcid = Thread.CurrentThread.CurrentUICulture.LCID; if (hostLocale != null) { uint lcidUnsigned; int hr = hostLocale.GetUILocale(out lcidUnsigned); if (NativeMethods.Succeeded(hr)) { lcid = (int)lcidUnsigned; } else { Tracer.Fail("Cannot get Visual Studio's locale. Defaulting to current thread's locale."); } } // Initialize our helpers this.managedResources = this.CreateManagedResourceManager(); this.nativeResources = new NativeResourceManager(lcid); this.settings = this.CreatePackageSettings(this.ServiceProvider); }
/// <include file='doc\DesignerPackage.uex' path='docs/doc[@for="DesignerPackage.SetSite"]/*' /> /// <devdoc> /// Overrides SetSite to create our editor factory. /// </devdoc> public override void SetSite(object site) { base.SetSite(site); // Now initialize our editor factory // editorFactory = new DesignerEditorFactory(site); // Initialize this thread's culture info with that of the shell's LCID // IUIHostLocale loc = (IUIHostLocale)GetService(typeof(IUIHostLocale)); Debug.Assert(loc != null, "Unable to get IUIHostLocale, defaulting CLR designer to current thread LCID"); if (loc != null) { Thread.CurrentThread.CurrentUICulture = new CultureInfo(loc.GetUILocale()); } SystemEvents.DisplaySettingsChanged += new EventHandler(this.OnSystemSettingChanged); SystemEvents.InstalledFontsChanged += new EventHandler(this.OnSystemSettingChanged); SystemEvents.UserPreferenceChanged += new UserPreferenceChangedEventHandler(this.OnUserPreferenceChanged); // Initialize the ShellLicenseManagerService so it can listen to solution events. // GetService(typeof(ILicenseManagerService)); Debug.Assert(licenseManagerService != null, "No license manager service available"); // Wake up the toolbox service so it registers as a data provider // GetService(typeof(IToolboxService)); }
/// <summary> /// Gets the font provided by the VS environment for dialog UI. /// </summary> /// <returns>Dialog font, or null if it is not available.</returns> public static Font GetDialogFont() { IUIHostLocale uiHostLocale = WixHelperMethods.GetServiceNoThrow <IUIHostLocale, IUIHostLocale>(WixPackage.Instance); if (uiHostLocale != null) { UIDLGLOGFONT[] pLOGFONT = new UIDLGLOGFONT[1]; if (uiHostLocale.GetDialogFont(pLOGFONT) == 0) { return(Font.FromLogFont(pLOGFONT[0])); } } return(null); }
Font GetVSFont() { IUIHostLocale hostLocale = _serviceProvider.GetService(typeof(IUIHostLocale)) as IUIHostLocale; if (hostLocale != null) { UIDLGLOGFONT[] dlgFont = new UIDLGLOGFONT[] { new UIDLGLOGFONT() }; hostLocale.GetDialogFont(dlgFont); return(Font.FromLogFont(dlgFont[0])); } else { return(base.Font); } }
public static uint GetProviderLocale(ServiceProvider provider) { CultureInfo ci = CultureInfo.CurrentCulture; uint lcid = (uint)ci.LCID; if (provider != null) { try { IUIHostLocale locale = (IUIHostLocale)provider.QueryService(VsConstants.SID_SUIHostLocale, typeof(IUIHostLocale)); locale.GetUILocale(out lcid); } catch (Exception) { } } return(lcid); }
/// <summary> /// This is used to get the current dialog font for use in property pages, etc. /// </summary> /// <returns>The current dialog font or a Segoe UI 9pt font if it is not available</returns> public static Font GetDialogFont() { IUIHostLocale host = GetServiceFromPackage <IUIHostLocale, IUIHostLocale>(false); if (host != null) { UIDLGLOGFONT[] pLOGFONT = new UIDLGLOGFONT[1]; if (host.GetDialogFont(pLOGFONT) == 0) { return(Font.FromLogFont(pLOGFONT[0])); } } return(new Font("Segoe UI", 9.0f)); }
public override object this[object key] { get { if (key is string) { string strKey = (string)key; if (strKey.Equals("HighlightColor")) { if (shellLightColor == SystemColors.Info) { IVsUIShell vsUIShell = (IVsUIShell)owner.GetService(typeof(IVsUIShell)); if (vsUIShell != null) { int vscolor = vsUIShell.GetVSSysColor(__VSSYSCOLOR.VSCOLOR_LIGHT); shellLightColor = ColorTranslator.FromWin32(vscolor); } else { shellLightColor = SystemColors.Info; } } return(shellLightColor); } else if (strKey.Equals("DialogFont")) { Font shellFont; // Get the default font from the shell. IUIHostLocale locale = (IUIHostLocale)owner.GetService(typeof(IUIHostLocale)); if (locale == null) { shellFont = Control.DefaultFont; } else { shellFont = DesignerPackage.GetFontFromShell(locale); } return(shellFont); } } throw new NotImplementedException("Does not support this key: " + key.ToString()); } set { throw new NotImplementedException("This collection does not support adding values"); } }
/// <summary> /// Initializes a new instance of the <see cref="SnippetDirectories"/> class. /// </summary> private SnippetDirectories() { var version = SnippetDesignerPackage.Instance.VSVersion; IUIHostLocale localeHost = (IUIHostLocale)SnippetDesignerPackage.Instance.GetService(typeof(IUIHostLocale)); uint lcid = (uint)CultureInfo.CurrentCulture.LCID; localeHost.GetUILocale(out lcid); registryPathReplacements.Add("%InstallRoot%", GetInstallRoot(version)); registryPathReplacements.Add("%LCID%", lcid.ToString()); registryPathReplacements.Add("%MyDocs%", RegistryLocations.GetVisualStudioUserDataPath(version)); replaceRegex = new Regex("(%InstallRoot%)|(%LCID%)|(%MyDocs%)", RegexOptions.Compiled); GetUserSnippetDirectories(); GetSnippetDirectoriesFromRegistry(Registry.LocalMachine, false, version); GetSnippetDirectoriesFromRegistry(Registry.CurrentUser, true, version); }
/// <summary> /// Gets the font provided by the VS environment for dialog UI. /// </summary> /// <returns>Dialog font, or null if it is not available.</returns> public static Font GetDialogFont() { IUIHostLocale uiHostLocale = XHelperMethods.GetServiceNoThrow <IUIHostLocale, IUIHostLocale>(AsyncProjectPackage.Instance); ThreadHelper.ThrowIfNotOnUIThread(); if (uiHostLocale != null) { UIDLGLOGFONT[] pLOGFONT = new UIDLGLOGFONT[1]; if (uiHostLocale.GetDialogFont(pLOGFONT) == 0) { return(Font.FromLogFont(pLOGFONT[0])); } } return(null); }
public static string Build(Dictionary <string, string[]> attributes) { StringBuilder sb = new StringBuilder(); sb.Append(HelpUrlPrefix); uint lcid; IUIHostLocale loc = (IUIHostLocale)ServiceProvider.GlobalProvider.GetService(typeof(IUIHostLocale)); if (loc != null && ErrorHandler.Succeeded(loc.GetUILocale(out lcid))) { var cultureInfo = new CultureInfo((int)lcid); sb.Append(cultureInfo.Name); } else { sb.Append("EN-US"); } if (attributes.ContainsKey("keyword")) { foreach (var keyword in attributes["keyword"]) { AppendUrlParameter(sb, "&k=k({0})", keyword); } } if (attributes.ContainsKey("TargetFrameworkMoniker")) { AppendUrlParameter(sb, ";k(TargetFrameworkMoniker-{0})", attributes["TargetFrameworkMoniker"][0]); } if (attributes.ContainsKey("DevLang")) { AppendUrlParameter(sb, ";k(DevLang-{0})", attributes["DevLang"][0]); } sb.Append(HelpUrlSuffix); return(sb.ToString()); }
/// <summary> /// Returns the current VS font from the provider /// </summary> /// <param name="provider">An IServiceProvider that contains IUIHostLocale</param> /// <returns>The current VS font</returns> internal static Font GetVsFont(IServiceProvider provider) { if (provider != null) { IUIHostLocale service = (IUIHostLocale)provider.GetService(typeof(IUIHostLocale)); UIDLGLOGFONT[] dlgFont = new UIDLGLOGFONT[1]; if (service != null && 0 == service.GetDialogFont(dlgFont)) { try { return(Font.FromLogFont(dlgFont[0])); } catch (ArgumentException) { // This can happen if a non-TrueType font is set as the system Icon font. // Eat the exception and use the system dialog font. } } } return(SystemFonts.DialogFont); }
internal static Font GetFontFromShell(IUIHostLocale locale) { _LOGFONTW font = new _LOGFONTW(); locale.GetDialogFont(font); NativeMethods.LOGFONT lfAuto = font.ToLOGFONT_Internal(); Font shellFont = null; if (lfAuto != null) { try { shellFont = Font.FromLogFont(lfAuto); } catch (ArgumentException) { } } if (shellFont == null) { shellFont = Control.DefaultFont; } return(shellFont); }
// so we can control recreates, etc internal Control GetOuterWindow() { if (holderWindow == null) { holderWindow = new HolderWindow(this, GetWindow()); Font font = null; IUIService uisvc = (IUIService)GetService(typeof(IUIService)); if (uisvc != null) { font = (Font)uisvc.Styles["DialogFont"]; } else { IUIHostLocale locale = (IUIHostLocale)GetService(typeof(IUIHostLocale)); if (locale != null) { font = DesignerPackage.GetFontFromShell(locale); } } holderWindow.Font = (font == null ? Control.DefaultFont : font); } return(holderWindow); }