public ThemeClass(ThemeFile parent, string name, string appName, string className) { Parent = parent; Name = name; AppName = appName; ClassName = className; }
private ThemeBitmap LoadReferencedImage(ThemeFile themeFile, int resRef) { ResInfoHandle resInfo = themeFile.Theme.FindResource("IMAGE", resRef); if (resInfo.IsInvalid) { return(null); } return(new ThemeBitmap(resRef, themeFile.Theme, resInfo)); }
private void ReadProperties(ThemeFile themeFile, string type, string name) { ResInfoHandle rh = themeFile.Theme.FindResourceEx(type, name, 0); var data = themeFile.Theme.LoadResourceAccessor(rh); bool globals = false; ThemeClass cls = null; int recordCount = 0; int currClass = -1; for (long offset = 0; offset < data.Capacity;) { var recordOffset = offset; var recordId = recordCount++; var record = data.Read <VSRecord>(ref offset); if (cls == null || record.Class != currClass) { string fullName = themeFile.ClassNames[record.Class]; string className = fullName; ParseClassName(ref className, out string appName); globals = className == "globals"; cls = themeFile.AddClass(fullName, appName, className); currClass = record.Class; } if (LoadRecordValue(themeFile, record, data, offset, out var value)) { } var prop = cls.AddProperty( recordId, recordOffset, record.Part, record.State, record.Type, record.SymbolVal, value, globals); if (record.ResId == 0) { offset += record.ByteLength; } DataExtensions.AlignTo(ref offset, 8); } }
public ThemeFile LoadTheme() { var themeFile = new ThemeFile(filePath, neutralModule, muiModule); themeFile.Version = GetVersion(); var classNames = ReadClassMap(); var vmap = ReadVariantMap(); var bcmap = ReadBaseClassMap(); themeFile.VariantMap = vmap; themeFile.ClassNames = classNames; UxThemeExNativeMethods.UxOpenThemeFile(filePath, isHighContrast, out var themeFileHandle).ThrowIfFailed(); themeFile.NativeThemeFile = themeFileHandle; ReadProperties(themeFile, "RMAP", "RMAP"); ReadProperties(themeFile, "VARIANT", vmap.Name); foreach (var @class in themeFile.Classes) { AddKnownPartsAndStates(@class); } var classMap = themeFile.Classes.ToDictionary(x => x.Name); var classNames2 = themeFile.ClassNames.Skip(4).ToList(); foreach (var entry in bcmap.Map) { var className = classNames2[entry.Key]; var baseClassName = classNames2[entry.Value]; if (classMap.TryGetValue(className, out ThemeClass @class) && classMap.TryGetValue(baseClassName, out ThemeClass baseClass)) { @class.BaseClass = baseClass; } } themeFile.Sort(); return(themeFile); }
private bool LoadRecordValue( ThemeFile theme, VSRecord record, UnmanagedMemoryAccessor data, long offset, out object value) { TPID id = GetThemePrimitiveId(record.SymbolVal, record.Type); if (id == TPID.Invalid) { value = null; return(false); } if (record.ResId == 0) { var payload = new byte[record.ByteLength]; data.ReadArray(offset, payload, 0, payload.Length); switch (id) { case TPID.STRING: value = data.ReadZString(offset); return(true); case TPID.ENUM: value = GetEnum(data.ReadInt32(offset), (TMT)record.SymbolVal); return(true); case TPID.BOOL: value = data.ReadInt32(offset) == 1; return(true); case TPID.INT: value = data.ReadInt32(offset); return(true); case TPID.COLOR: value = ColorUtils.ColorFromCOLORREF(data.ReadInt32(offset)); return(true); case TPID.MARGINS: value = data.Read <MARGINS>(offset); return(true); case TPID.SIZE: value = data.ReadInt32(offset); return(true); case TPID.POSITION: value = data.Read <POINT>(offset); return(true); case TPID.RECT: value = data.Read <RECT>(offset); return(true); case TPID.HIGHCONTRASTCOLORTYPE: value = (HIGHCONTRASTCOLOR)data.ReadInt32(offset); return(true); case TPID.SIMPLIFIEDIMAGETYPE: if (record.SymbolVal == (int)TMT.HCSIMPLIFIEDIMAGE) { value = data.ReadArray <HCIMAGEPROPERTIES>(offset, record.ByteLength); } else { value = data.ReadArray <IMAGEPROPERTIES>(offset, record.ByteLength); } return(true); case TPID.INTLIST: int length = data.ReadInt32(offset); if (length <= 1) { value = new IntList(new int[0]); return(true); } int dim = data.ReadInt32(offset + 4); Debug.Assert(length - 1 == dim * dim); var intList = new int[length - 1]; data.ReadArray(offset + 8, intList, 0, intList.Length); value = new IntList(intList); return(true); default: Console.WriteLine($"Unprocessed resource property type {id}"); value = null; return(false); } } else { value = null; switch (id) { case TPID.BITMAPIMAGE1: case TPID.BITMAPIMAGE2: case TPID.BITMAPIMAGE3: case TPID.BITMAPIMAGE4: case TPID.BITMAPIMAGE5: case TPID.BITMAPIMAGE6: case TPID.BITMAPIMAGE7: case TPID.STOCKBITMAPIMAGE: case TPID.GLYPHIMAGE: case TPID.COMPOSEDIMAGETYPE: return(LoadImageFileRes(theme.Theme, record.ResId, out value)); // TPID_ATLASIMAGE // TPID_ATLASINPUTIMAGE // TPID_ENUM case TPID.STRING: return(LoadStringRes(theme.MUI, record.ResId, out value)); // TPID_INT case TPID.BOOL: return(LoadBoolRes(theme.MUI, record.ResId, out value)); // TPID_COLOR // TPID_MARGINS case TPID.FILENAME: if (IsImageFile((TMT)record.SymbolVal)) { return(LoadImageFileRes(theme.Theme, record.ResId, out value)); } return(LoadStringRes(theme.MUI, record.ResId, out value)); // TPID_SIZE // TPID_POSITION case TPID.RECT: return(LoadRectRes(theme.MUI, record.ResId, out value)); case TPID.FONT: return(LoadFontRes(theme.MUI, record.ResId, out value)); case TPID.DISKSTREAM: value = "DISKSTREAM(" + record.ResId + ", len=" + record.ByteLength + ")"; //var window = new Form(); //window.ShowDialog(); //var th = StyleNativeMethods.OpenThemeData( // window.Handle, "LISTVIEW"); //IntPtr stream; //uint streamLen; //HResult hr = StyleNativeMethods.GetThemeStream( // th, (int)header.Part, (int)header.State, (int)header.Property, // out stream, out streamLen, tf.hTheme); //th.Dispose(); //GC.KeepAlive(window); return(true); default: Console.WriteLine($"Unprocessed MUI resource property type {id}"); return(false); } } }