📄 sskinmanager.pas
字号:
PackedData: TMemoryStream;
constructor Create(Collection: TCollection); override;
destructor Destroy; override;
procedure LoadSkin(sf : TMemIniFile);
procedure LoadFromIni(gd : TsSkinGenerals; sf: TMemIniFile);
published
property Name : string read FName write SetName;
property GeneralData : TsSkinGenerals read FGeneralData write SetGeneralData;
property Images : TsSkinImages read FImages write SetImages;
property Patterns : TsSkinPatterns read FPatterns write SetPatterns;
property MasterBitmap : TBitmap read FMasterBitmap write FMasterBitmap;
property Shadow1Color : TColor read FShadow1Color write FShadow1Color;
property Shadow1Offset : integer read FShadow1Offset write FShadow1Offset;
property Shadow1Blur : integer read FShadow1Blur write FShadow1Blur default -1;
property Shadow1Transparency : integer read FShadow1Transparency write FShadow1Transparency;
property BorderColor : TColor read FBorderColor write FBorderColor default clFuchsia;
property Version : real read FVersion write FVersion;
property Author : string read FAuthor write FAuthor;
property Description : string read FDescription write FDescription;
end;
TsStoredSkins = class(TCollection)
private
FOwner: TsSkinManager;
function GetItem(Index: Integer): TsStoredSkin;
procedure SetItem(Index: Integer; Value: TsStoredSkin);
protected
function GetOwner: TPersistent; override;
public
procedure Assign(Source: TPersistent); override;
constructor Create(AOwner: TsSkinManager);
destructor Destroy; override;
property Items[Index: Integer]: TsStoredSkin read GetItem write SetItem; default;
function IndexOf(const SkinName : string) : integer;
end;
{$ENDIF} // NOTFORHELP
ThirdPartyList = class(TPersistent)
private
FThirdEdits : string;
FThirdButtons : string;
FThirdBitBtns : string;
FThirdCheckBoxes : string;
FThirdGroupBoxes : string;
FThirdListViews : string;
FThirdPanels : string;
FThirdGrids : string;
FThirdTreeViews : string;
FThirdComboBoxes : string;
FThirdWWEdits : string;
FThirdVirtualTrees : string;
FThirdGridEh : string;
function GetString(const Index: Integer): string;
procedure SetString(const Index: Integer; const Value: string);
published
property ThirdEdits : string index ord(tpEdit ) read GetString write SetString stored True;
property ThirdButtons : string index ord(tpButton ) read GetString write SetString stored True;
property ThirdBitBtns : string index ord(tpBitBtn ) read GetString write SetString stored True;
property ThirdCheckBoxes : string index ord(tpCheckBox ) read GetString write SetString stored True;
property ThirdGroupBoxes : string index ord(tpGroupBox ) read GetString write SetString stored True;
property ThirdListViews : string index ord(tpListView ) read GetString write SetString stored True;
property ThirdPanels : string index ord(tpPanel ) read GetString write SetString stored True;
property ThirdGrids : string index ord(tpGrid ) read GetString write SetString stored True;
property ThirdTreeViews : string index ord(tpTreeView ) read GetString write SetString stored True;
property ThirdComboBoxes : string index ord(tpComboBox ) read GetString write SetString stored True;
property ThirdWWEdits : string index ord(tpWWEdit ) read GetString write SetString stored True;
property ThirdVirtualTrees : string index ord(tpVirtualTree) read GetString write SetString stored True;
property ThirdGridEh : string index ord(tpGridEh ) read GetString write SetString stored True;
end;
TacSkinningRule = (srStdForms, srStdDialogs, srThirdParty);
TacSkinningRules = set of TacSkinningRule;
TsSkinManager = class(TComponent)
private
{$IFNDEF NOTFORHELP}
FGroupIndex: integer;
FSkinName: TsSkinName;
FSkinDirectory: TsDirectory;
FActive: boolean;
FBuiltInSkins: TsStoredSkins;
FSkinableMenus: TsSkinableMenus;
FOnAfterChange: TNotifyEvent;
FOnBeforeChange: TNotifyEvent;
FSkinnedPopups: boolean;
FCommonSections: TStringList;
FIsDefault: boolean;
FOnGetPopupLineData: TacGetExtraLineData;
FMenuSupport: TacMenuSupport;
FAnimEffects: TacAnimEffects;
FActiveControl: hwnd;
GlobalHookInstalled : boolean;
FSkinningRules: TacSkinningRules;
FThirdParty: ThirdPartyList;
procedure SetSkinName(const Value: TsSkinName);
procedure SetSkinDirectory(const Value: string);
procedure SetActive(const Value: boolean);
procedure SetBuiltInSkins(const Value: TsStoredSkins);
procedure SetSkinnedPopups(const Value: boolean);
function GetVersion: string;
procedure SetVersion(const Value: string);
function GetSkinInfo: TacSkinInfo;
procedure SetSkinInfo(const Value: TacSkinInfo);
procedure SetHueOffset(const Value: integer);
procedure SetSaturation(const Value: integer);
procedure SetIsDefault(const Value: boolean);
function GetIsDefault: boolean;
function MainWindowHook(var Message: TMessage): boolean;
procedure SetActiveControl(const Value: hwnd);
protected
procedure SendNewSkin;
procedure SendRemoveSkin;
procedure LoadAllMasks;
procedure LoadAllPatterns;
procedure FreeBitmaps;
procedure FreeJpegs;
{$ENDIF} // NOTFORHELP
public
SkinData : TsSkinData;
{$IFNDEF NOTFORHELP}
ma : TsMaskArray;
pa : TsPatternArray;
gd : TsGeneralDataArray;
ConstData : TConstantSkinData;
MasterBitmap : TBitmap;
SkinIsPacked : boolean;
FHueOffset: integer;
FSaturation: integer;
ThirdLists : array of TStringList;
procedure InitConstantIndexes;
procedure LoadAllGeneralData;
procedure SetCommonSections(const Value: TStringList);
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure AfterConstruction; override;
procedure Loaded; override;
procedure SaveToIni(Index : integer; sf : TMemIniFile);
procedure ReloadSkin;
procedure ReloadPackedSkin;
procedure InstallHook;
procedure UnInstallHook;
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
procedure UpdateSkinSection(const SectionName : string);
property GroupIndex : integer read FGroupIndex write FGroupIndex;
property SkinableMenus : TsSkinableMenus read FSkinableMenus write FSkinableMenus;
property ActiveControl : hwnd read FActiveControl write SetActiveControl;
procedure RepaintForms;
function MaskSize(MaskIndex : integer) : TSize;
function GetSkinIndex(const SkinSection : string) : integer;
function GetMaskIndex(SkinIndex : integer; const SkinSection, mask : string) : integer; overload;
function GetMaskIndex(const SkinSection, mask : string) : integer; overload;
function GetTextureIndex(SkinIndex : integer; const SkinSection, PropName : string) : integer;
function GetPatternIndex(SkinIndex : integer; const SkinSection, pattern : string) : integer;
{$ENDIF} // NOTFORHELP
function GetFullSkinDirectory : string;
function GetSkinNames(sl: TStrings; SkinType : TacSkinTypes = stAllSkins) : string;
function GetExternalSkinNames(sl: TStrings; SkinType : TacSkinTypes = stAllSkins) : string;
procedure GetSkinSections(sl: TStrings);
procedure ExtractInternalSkin(const NameOfSkin, DestDir : string);
procedure ExtractByIndex(Index : integer; const DestDir : string);
procedure UpdateSkin;
function GetGlobalColor : TColor;
function GetGlobalFontColor : TColor;
function GetActiveEditColor : TColor;
function GetActiveEditFontColor : TColor;
function GetHighLightColor : TColor;
function GetHighLightFontColor : TColor;
{$IFNDEF NOTFORHELP}
function MaskWidthTop(MaskIndex : integer) : integer;
function MaskWidthLeft(MaskIndex : integer) : integer;
function MaskWidthBottom(MaskIndex : integer) : integer;
function MaskWidthRight(MaskIndex : integer) : integer;
function IsValidImgIndex(ImageIndex : integer) : boolean;
function IsValidSkinIndex(SkinIndex : integer) : boolean;
{$ENDIF} // NOTFORHELP
published
property SkinnedPopups : boolean read FSkinnedPopups write SetSkinnedPopups default True;
property AnimEffects : TacAnimEffects read FAnimEffects write FAnimEffects;
property IsDefault : boolean read GetIsDefault write SetIsDefault default True;
property Active : boolean read FActive write SetActive default True;
property CommonSections : TStringList read FCommonSections write SetCommonSections;
property Saturation : integer read FSaturation write SetSaturation default 0;
property HueOffset : integer read FHueOffset write SetHueOffset default 0;
property InternalSkins : TsStoredSkins read FBuiltInSkins write SetBuiltInSkins;
property MenuSupport : TacMenuSupport read FMenuSupport write FMenuSupport;
property SkinDirectory : TsDirectory read FSkinDirectory write SetSkinDirectory;
property SkinName : TsSkinName read FSkinName write SetSkinName;
property SkinInfo : TacSkinInfo read GetSkinInfo write SetSkinInfo;
property SkinningRules : TacSkinningRules read FSkinningRules write FSkinningRules default [srStdForms, srStdDialogs, srThirdParty];
property ThirdParty : ThirdPartyList read FThirdParty write FThirdParty;
property Version : string read GetVersion write SetVersion stored False;
property OnAfterChange : TNotifyEvent read FOnAfterChange write FOnAfterChange;
property OnBeforeChange : TNotifyEvent read FOnBeforeChange write FOnBeforeChange;
property OnGetMenuExtraLineData : TacGetExtraLineData read FOnGetPopupLineData write FOnGetPopupLineData;
end;
{$IFNDEF NOTFORHELP}
var
DefaultManager : TsSkinManager;
SkinFile : TMemIniFile;
OSVersionInfo: TOSVersionInfo;
IsNT : boolean;
sc : TacSkinConvertor;
UnPackedFirst : boolean = False;
function ChangeImageInSkin(const SkinSection, PropName, FileName : string; sm : TsSkinManager) : boolean;
procedure ChangeSkinSaturation(sManager : TsSkinManager; Value : integer);
procedure ChangeSkinHue(sManager : TsSkinManager; Value : integer);
procedure ChangeSkinBrightness(sManager : TsSkinManager; Value : integer);
procedure LoadThirdNames(sm : TsSkinManager; Overwrite : boolean = False);
procedure UpdateThirdNames(sm : TsSkinManager);
{$ENDIF} // NOTFORHELP
implementation
uses sMessages, acntUtils, sStoreUtils, sVclUtils, sCommonData,
sSkinProps, acDials, FileCtrl, sGraphUtils, sGradient{$IFDEF DEVEX}, cxLookAndFeels, acLFPainter{$ENDIF};
{$IFDEF DEVEX}
var
OldRootLookAndFeel : TcxLookAndFeelKind;
{$ENDIF}
function ChangeImageInSkin(const SkinSection, PropName, FileName : string; sm : TsSkinManager) : boolean;
var
i, l : integer;
s : string;
begin
with sm do begin
Result := False;
if not SkinData.Active then Exit;
if (SkinSection = '') or (PropName='') or not FileExists(FileName) then Exit;
s := UpperCase(PropName);
// If property is Background texture
if (s = s_PatternFile) or ( s = s_HotPatternFile) then begin
// If loaded file is Bitmap
if pos('.BMP', UpperCase(FileName)) > 0 then begin
l := Length(ma);
// ma - is array of records with image description
if l > 0 then begin
// search of the required image in the massive
for i := 0 to l - 1 do begin
if (UpperCase(ma[i].PropertyName) = s) and (UpperCase(ma[i].ClassName) = UpperCase(skinSection)) then begin
// If found then we must define new Bmp
if ma[i].Bmp = nil then ma[i].Bmp := TBitmap.Create;
ma[i].Bmp.LoadFromFile(FileName);
// To exit
Result := True;
Break;
end;
end;
end;
// If not found we must to add new image
if not Result then begin
l := Length(ma) + 1;
SetLength(ma, l);
ma[l - 1].PropertyName := '';
ma[l - 1].ClassName := '';
try
ma[l - 1].Bmp := TBitmap.Create;
ma[l - 1].Bmp.LoadFromFile(FileName);
finally
ma[l - 1].PropertyName := s;
ma[l - 1].ClassName := UpperCase(skinSection);
ma[l - 1].Manager := sm;
ma[l - 1].R := Rect(0, 0, ma[l - 1].Bmp.Width, ma[l - 1].Bmp.Height);
ma[l - 1].ImageCount := 1;
ma[l - 1].ImgType := itisaTexture;
end;
if ma[l - 1].Bmp.Width < 1 then begin
FreeAndNil(ma[l - 1].Bmp);
SetLength(ma, l - 1);
end;
l := Length(pa);
if l > 0 then for i := 0 to l - 1 do if (pa[i].PropertyName = s) and (pa[i].ClassName = UpperCase(skinSection)) then begin
FreeAndNil(pa[i].Img);
l := Length(pa) - 1;
if l <> i then begin
pa[i].Img := pa[l].Img ;
pa[i].ClassName := pa[l].ClassName ;
pa[i].PropertyName := pa[l].PropertyName;
end;
SetLength(pa, l);
Break;
end;
Result := True;
end;
end
// If loaded image is Jpeg, then working with massive of JPegs
else begin
l := Length(pa);
if l > 0 then for i := 0 to l - 1 do if (pa[i].PropertyName = s) and (pa[i].ClassName = UpperCase(skinSection)) then begin
if not Assigned(pa[i].Img) then pa[i].Img := TJpegImage.Create;
pa[i].Img.LoadFromFile(FileName);
Result := True;
Break;
end;
if not Result then begin
l := Length(pa) + 1;
SetLength(pa, l);
try
pa[l - 1].Img := TJpegImage.Create;
pa[l - 1].Img.LoadFromFile(FileName);
finally
pa[l - 1].PropertyName := s;
pa[l - 1].ClassName := UpperCase(SkinSection);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -