Created
December 22, 2013 02:28
-
-
Save SLaks/8077754 to your computer and use it in GitHub Desktop.
Trying to create a design-time ResourceDictionary of VS theme colors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections; | |
using System.Runtime.CompilerServices; | |
using System.Runtime.InteropServices; | |
using Microsoft.Internal.VisualStudio.PlatformUI; | |
using Microsoft.Internal.VisualStudio.Shell.Interop; | |
using Microsoft.VisualStudio; | |
using Microsoft.VisualStudio.Platform.WindowManagement; | |
using Microsoft.VisualStudio.PlatformUI; | |
using Microsoft.VisualStudio.Shell; | |
using Microsoft.VisualStudio.Shell.Interop; | |
namespace SLaks.Rebracer.Notifications { | |
public class DesignerThemeDictionary : DeferredResourceDictionaryBase { | |
public DesignerThemeDictionary() { | |
dynamic colorThemeService =(ColorThemeService) Activator.CreateInstance(typeof(ColorThemeService)); | |
dynamic currentTheme = colorThemeService.Themes[0]; | |
foreach (ColorName colorName in colorThemeService.ColorNames) { | |
IVsColorEntry vsColorEntry = currentTheme[colorName]; | |
if (vsColorEntry != null) { | |
if (vsColorEntry.BackgroundType != 0) { | |
ThemeResourceKey themeResourceKey = new ThemeResourceKey(vsColorEntry.ColorName.Category, vsColorEntry.ColorName.Name, ThemeResourceKeyType.BackgroundBrush); | |
ThemeResourceKey themeResourceKey2 = new ThemeResourceKey(vsColorEntry.ColorName.Category, vsColorEntry.ColorName.Name, ThemeResourceKeyType.BackgroundColor); | |
Add(themeResourceKey, themeResourceKey); | |
Add(themeResourceKey2, themeResourceKey2); | |
int num = VsColorFromName(colorName); | |
if (num != 0) { | |
Add(VsColors.GetColorKey(num), themeResourceKey2); | |
Add(VsBrushes.GetBrushKey(num), themeResourceKey); | |
} | |
} | |
if (vsColorEntry.ForegroundType != 0) { | |
ThemeResourceKey foregroundKey = new ThemeResourceKey(vsColorEntry.ColorName.Category, vsColorEntry.ColorName.Name, ThemeResourceKeyType.ForegroundBrush); | |
ThemeResourceKey backgroundKey = new ThemeResourceKey(vsColorEntry.ColorName.Category, vsColorEntry.ColorName.Name, ThemeResourceKeyType.ForegroundColor); | |
Add(foregroundKey, foregroundKey); | |
Add(backgroundKey, backgroundKey); | |
} | |
} | |
} | |
} | |
// Microsoft.VisualStudio.Platform.WindowManagement.ColorNameTranslator | |
static int VsColorFromName(ColorName colorName) { | |
int result; | |
if (colorName.Category == EnvironmentColors.Category && VsColors.TryGetColorIDFromBaseKey(colorName.Name, out result)) { | |
return result; | |
} | |
return 0; | |
} | |
public static uint GetColorValue(ThemeResourceKey key) { | |
uint retVal; | |
var shell = (IVsUIShell2)ServiceProvider.GlobalProvider.GetService(typeof(SVsUIShell)); | |
ErrorHandler.ThrowOnFailure(shell.GetVSSysColorEx(VsColors.GetColorID(key), out retVal)); | |
return retVal; | |
} | |
protected override uint GetRgbaColorValue(ThemeResourceKey key) { | |
return GetColorValue(key); | |
} | |
} | |
} | |
namespace Microsoft.Internal.VisualStudio.Shell.Interop { | |
[CompilerGenerated, Guid("0D915B59-2ED7-472A-9DE8-9161737EA1C5"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), TypeIdentifier] | |
[ComImport] | |
public interface SVsColorThemeService { | |
} | |
[CompilerGenerated, Guid("EAB552CF-7858-4F05-8435-62DB6DF60684"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), TypeIdentifier] | |
[ComImport] | |
public interface IVsColorThemeService { | |
IVsColorThemes Themes { | |
[return: MarshalAs(UnmanagedType.Interface)] | |
get; | |
} | |
IVsColorNames ColorNames { | |
[return: MarshalAs(UnmanagedType.Interface)] | |
get; | |
} | |
IVsColorTheme CurrentTheme { | |
[return: MarshalAs(UnmanagedType.Interface)] | |
get; | |
} | |
void NotifyExternalThemeChanged(); | |
uint GetCurrentVsColorValue([In] int vsSysColor); | |
uint GetCurrentColorValue([In] ref Guid rguidColorCategory, [MarshalAs(UnmanagedType.LPWStr)] [In] string pszColorName, [In] uint dwColorType); | |
uint GetCurrentEncodedColor([In] ref Guid rguidColorCategory, [MarshalAs(UnmanagedType.LPWStr)] [In] string pszColorName, [In] uint dwColorType); | |
} | |
[CompilerGenerated, Guid("98192AFE-75B9-4347-82EC-FF312C1995D8"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), TypeIdentifier] | |
[ComImport] | |
public interface IVsColorThemes { | |
IVsColorTheme this[[In] int index] { | |
[return: MarshalAs(UnmanagedType.Interface)] | |
get; | |
} | |
int Count { get; } | |
[return: MarshalAs(UnmanagedType.Interface)] | |
IVsColorTheme GetThemeFromId([In] Guid ThemeId); | |
[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalType = "System.Runtime.InteropServices.CustomMarshalers.EnumeratorToEnumVariantMarshaler")] | |
IEnumerator GetEnumerator(); | |
} | |
[CompilerGenerated, Guid("92144F7A-61DE-439B-AA66-13BE7CDEC857"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), TypeIdentifier] | |
[ComImport] | |
public interface IVsColorNames { | |
ColorName this[[In] int index] { get; } | |
int Count { get; } | |
ColorName GetNameFromVsColor([In] int vsSysColor); | |
[return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalType = "System.Runtime.InteropServices.CustomMarshalers.EnumeratorToEnumVariantMarshaler")] | |
IEnumerator GetEnumerator(); | |
} | |
[CompilerGenerated, Guid("413D8344-C0DB-4949-9DBC-69C12BADB6AC"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), TypeIdentifier] | |
[ComImport] | |
public interface IVsColorTheme { | |
IVsColorEntry this[[In] ColorName Name] { | |
[return: MarshalAs(UnmanagedType.Interface)] | |
get; | |
} | |
Guid ThemeId { get; } | |
string Name { | |
[return: MarshalAs(UnmanagedType.BStr)] | |
get; | |
} | |
bool IsUserVisible { get; } | |
void Apply(); | |
} | |
[CompilerGenerated, Guid("BBE70639-7AD9-4365-AE36-9877AF2F973B"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), TypeIdentifier] | |
[ComImport] | |
public interface IVsColorEntry { | |
ColorName ColorName { get; } | |
byte BackgroundType { get; } | |
byte ForegroundType { get; } | |
uint Background { get; } | |
uint Foreground { get; } | |
uint BackgroundSource { get; } | |
uint ForegroundSource { get; } | |
} | |
[CompilerGenerated, TypeIdentifier("EF2A7BE1-84AF-4E47-A2CF-056DF55F3B7A", "Microsoft.Internal.VisualStudio.Shell.Interop.ColorName")] | |
[StructLayout(LayoutKind.Sequential, Pack = 8)] | |
public struct ColorName { | |
public Guid Category; | |
[MarshalAs(UnmanagedType.BStr)] | |
public string Name; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment