⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 suimgr.pas

📁 SUIPack是一款为Delphi和C++Builder开发的所见即所得的界面增强VCL组件
💻 PAS
📖 第 1 页 / 共 2 页
字号:
////////////////////////////////////////////////////////////////////////////////
//
//
//  FileName    :   SUIMgr.pas
//  Creator     :   Shen Min
//  Date        :   2003-02-26
//  Comment     :
//
//  Copyright (c) 2002-2006 Sunisoft
//  http://www.sunisoft.com
//  Email: support@sunisoft.com
//
////////////////////////////////////////////////////////////////////////////////

unit SUIMgr;

interface

{$I SUIPack.inc}

uses Windows, Classes, Controls, SysUtils, Forms, TypInfo, Graphics, Dialogs,
     SUIThemes, SUI2Define;

type
    // --------- TsuiFileTheme --------------------
    TsuiFileTheme = class(TComponent)
    private
        m_Mgr : TsuiFileThemeMgr;
        m_ThemeFile : String;
        m_CanUse : Boolean;
        m_Password : String;

        procedure SetThemeFile(const Value: String);
        procedure SetCanUse(const Value: Boolean);
        procedure SetPassword(const Value: String);

    public
        constructor Create(AOwner: TComponent); override;
        destructor Destroy(); override;

        function CanUse() : Boolean;

        function GetBitmap(const Index : Tsk2SkinBitmapElement) : TBitmap; 
        procedure GetBitmap2(const Index : Tsk2SkinBitmapElement; const Buf : TBitmap; SpitCount, SpitIndex : Integer);
        function GetInt(const Index : Tsk2IntElement) : Integer;
        function GetColor(const Index : Tsk2SkinColorElement) : TColor;
        function GetBool(const Index : Tsk2BoolElement) : Boolean;

    published
        property ThemeFile : String read m_ThemeFile write SetThemeFile;
        property Password : String read m_Password write SetPassword;
        property Ready : Boolean read m_CanUse write SetCanUse;

    end;

    TsuiBuiltInFileTheme = class(TsuiFileTheme)
    private
        m_OldThemeFile : String;
        
        procedure SetThemeFile2(const Value: String);
        procedure ReadSkinData(Stream: TStream);
        procedure WriteSkinData(Stream : TStream);

    protected
        procedure DefineProperties(Filer: TFiler); override;

    published
        property ThemeFile : String read m_OldThemeFile write SetThemeFile2;
    end;

    // --------- TsuiThemeManager -----------------
    TsuiThemeMgrCompList = class(TStringList)
    end;

    TsuiThemeManager = class(TComponent)
    private
        m_UIStyle : TsuiUIStyle;
        m_FileTheme : TsuiFileTheme;
        m_List : TsuiThemeMgrCompList;
        m_OnUIStyleChanged : TNotifyEvent;

        procedure SetUIStyle(const Value: TsuiUIStyle);
        procedure UpdateAll();

        procedure SetList(const Value: TsuiThemeMgrCompList);
        procedure SetFileTheme(const Value: TsuiFileTheme);

    protected
        procedure Notification(AComponent: TComponent; Operation: TOperation); override;

    public
        constructor Create(AOwner: TComponent); override;
        destructor Destroy(); override;

        procedure UpdateTheme();
        
    published
        property UIStyle : TsuiUIStyle read m_UIStyle write SetUIStyle;
        property FileTheme : TsuiFileTheme read m_FileTheme write SetFileTheme;
        property CompList : TsuiThemeMgrCompList read m_List write SetList;

        property OnUIStyleChanged : TNotifyEvent read m_OnUIStyleChanged write m_OnUIStyleChanged;
    end;

    procedure ThemeManagerEdit(AComp : TsuiThemeManager);
    procedure FileThemeEdit(AComp : TsuiFileTheme);
    procedure BuiltInFileThemeEdit(AComp : TsuiBuiltInFileTheme);

    function UsingFileTheme(
        const FileTheme : TsuiFileTheme;
        const UIStyle : TsuiUIStyle;
        out SuggUIStyle : TsuiUIStyle
    ) : Boolean;


implementation

uses SUIForm, frmThemeMgr, SUIPublic;

procedure ThemeManagerEdit(AComp : TsuiThemeManager);
var
    frmMgr: TfrmMgr;
    Form : TWinControl;
    i : Integer;
    nIndex : Integer;
    Comp : TComponent;
begin
    if not (AComp.Owner is TForm) and not (AComp.Owner is TCustomFrame) then
        Exit;
    Form := (AComp.Owner as TWinControl);
    frmMgr := TfrmMgr.Create(nil);

    for i := 0 to Form.ComponentCount - 1 do
    begin
        Comp := Form.Components[i];
        if (
            (Copy(Comp.ClassName, 1, 4) = 'Tsui') and
            (IsHasProperty(Comp, 'UIStyle')) and
            (IsHasProperty(Comp, 'FileTheme')) and
            not (Comp is TsuiThemeManager)
        ) then
        begin
            nIndex := frmMgr.List.Items.AddObject(Comp.Name, Comp);
            if AComp.m_List.IndexOf(Comp.Name) = -1 then
                frmMgr.List.Checked[nIndex] := false
            else
                frmMgr.List.Checked[nIndex] := true;
        end
    end;

    if frmMgr.ShowModal() = mrOK then
    begin
        AComp.m_List.Clear();
        for i := 0 to frmMgr.List.Items.Count - 1 do
        begin
            if frmMgr.List.Checked[i] then
                AComp.m_List.Add(frmMgr.List.Items[i]);
        end;
    end;
    frmMgr.Free();

    AComp.UpdateAll();
end;

procedure FileThemeEdit(AComp : TsuiFileTheme);
var
    OpenDialog: TOpenDialog;
begin
    OpenDialog := TOpenDialog.Create(Application);
    OpenDialog.Filter := 'Sunisoft Skin File(*.ssk)|*.ssk';
    if OpenDialog.Execute() then
        AComp.ThemeFile := OpenDialog.FileName;
    OpenDialog.Free();
end;

procedure BuiltInFileThemeEdit(AComp : TsuiBuiltInFileTheme);
var
    OpenDialog: TOpenDialog;
begin
    OpenDialog := TOpenDialog.Create(Application);
    OpenDialog.Filter := 'Sunisoft Skin File(*.ssk)|*.ssk';
    if OpenDialog.Execute() then
        AComp.ThemeFile := OpenDialog.FileName;
    OpenDialog.Free();
end;

{ TsuiThemeManager }

constructor TsuiThemeManager.Create(AOwner: TComponent);
begin
    inherited;

    m_List := TsuiThemeMgrCompList.Create();
    UIStyle := SUI_THEME_DEFAULT;
end;

destructor TsuiThemeManager.Destroy;
begin
    m_List.Free();
    m_List := nil;

    inherited;
end;

procedure TsuiThemeManager.Notification(AComponent: TComponent;
  Operation: TOperation);
var
    nIndex : Integer;
begin
    inherited;

    if AComponent = nil then
        Exit;

    if (Operation = opRemove) and (AComponent <> self) then
    begin
        nIndex := m_List.IndexOf(AComponent.Name);
        if nIndex <> -1 then
            m_List.Delete(nIndex);
    end;

    if (
        (Operation = opRemove) and
        (AComponent = m_FileTheme)
    )then
    begin
        m_FileTheme := nil;
        m_UIStyle := SUI_THEME_DEFAULT;
    end;
end;

procedure TsuiThemeManager.SetFileTheme(const Value: TsuiFileTheme);
begin
    m_FileTheme := Value;
    SetUIStyle(m_UIStyle);    
end;

procedure TsuiThemeManager.SetList(const Value: TsuiThemeMgrCompList);
begin
    m_List.Assign(Value);
end;

procedure TsuiThemeManager.SetUIStyle(const Value: TsuiUIStyle);
var
    NeedUpdate : Boolean;
begin
    if m_UIStyle = Value then
        NeedUpdate := false
    else
        NeedUpdate := true;
    m_UIStyle := Value;
    UpdateAll();
    if NeedUpdate then
        if Assigned(m_OnUIStyleChanged) then
            m_OnUIStyleChanged(self);
end;

procedure TsuiThemeManager.UpdateAll;
var
    i : Integer;
    Comp : TComponent;
    Form : TWinControl;
begin
    if not (Owner is TForm) and not (Owner is TCustomFrame) then
        Exit;
    Form := Owner as TWinControl;

    for i := 0 to m_List.Count - 1 do
    begin
        Comp := Form.FindComponent(m_List[i]);
        if Comp = nil then
            continue;
        SetOrdProp(Comp, 'UIStyle', Ord(UIStyle));
        SetObjectProp(Comp, 'FileTheme', m_FileTheme);        
    end;
end;

procedure TsuiThemeManager.UpdateTheme;
begin
    UpdateAll();
end;

{ TsuiFileTheme }

function TsuiFileTheme.CanUse: Boolean;
begin
    Result := m_CanUse;
end;

constructor TsuiFileTheme.Create(AOwner: TComponent);
begin
    inherited;

    m_Mgr := TsuiFileThemeMgr.Create();
    m_CanUse := false;
end;

destructor TsuiFileTheme.Destroy;
begin
    m_Mgr.Free();
    m_Mgr := nil;

    inherited;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -