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

📄 suiform.pas

📁 suipack ver5控件 suipack ver5控件 suipack ver5控件 suipack ver5控件 suipack ver5控件
💻 PAS
📖 第 1 页 / 共 5 页
字号:
////////////////////////////////////////////////////////////////////////////////
//
//
//  FileName    :   SUIForm.pas
//  Creator     :   Shen Min
//  Date        :   2002-05-21 V1-V3
//                  2003-06-19 V4
//                  2004-07-02 V5
//  Comment     :
//
//  Copyright (c) 2002-2004 Sunisoft
//  http://www.sunisoft.com
//  Email: support@sunisoft.com
//
////////////////////////////////////////////////////////////////////////////////

unit SUIForm;

interface

{$I SUIPack.inc}

uses Windows, Messages, SysUtils, Classes, Controls, ExtCtrls, Graphics, Forms,
     ComCtrls, Menus, Dialogs, Buttons, AppEvnts, Math,
     SUITitleBar, SUIThemes, SUIMgr, SUIButton, SUIScrollBar, frmMSNPop;

type
    TsuiForm = class;
    TsuiMDIForm = class;
    TsuiMenuBar = class(TToolBar)
    private
        m_Form : TsuiForm;
        m_MDIForm : TsuiMDIForm;

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

    end;

    TsuiForm = class(TCustomPanel)
    private
        m_TitleBar : TsuiTitleBar;
        m_MenuBar : TsuiMenuBar;
        m_Menu : TMainMenu;
        m_OldWndProc : TWndMethod;
        m_BorderBuf : TBitmap;
        m_BottomBorderWidth : Integer;
        m_OldBorderStyle : TFormBorderStyle;        

        m_Form : TForm;
        m_Color : TColor;
        m_Panel : TCustomPanel;
        m_Width : Integer;
        m_UIStyle : TsuiUIStyle;
        m_FileTheme : TsuiFileTheme;        
        m_MenuBarColor : TColor;
        m_MenuBarHeight : Integer;
        m_UIStyleAutoUpdateSub : Boolean;
        m_Destroyed : Boolean;
        m_AppEvent : TApplicationEvents; 

        m_FormInitRect : TRect;
        m_FormInitMax : Boolean;

        procedure NewParentWndProc(var Msg: TMessage);
        procedure ProcessKeyPress(var Msg : TMessage);
        procedure WMERASEBKGND(var Msg : TMessage); message WM_ERASEBKGND;
        procedure SetButtons(const Value : TsuiTitleBarButtons);
        function GetButtons() : TsuiTitleBarButtons;

        function GetOnBtnClick() : TsuiTitleBarButtonClickEvent;
        procedure SetOnBtnClick(const Value : TsuiTitleBarButtonClickEvent);
        function GetOnHelpBtnClick() : TsuiTitleBarButtonClickEvent;
        procedure SetOnHelpBtnClick(const Value : TsuiTitleBarButtonClickEvent);

        function GetFont() : TFont;
        procedure SetFont(const Value : TFont);
        function GetCaption() : TCaption;
        procedure SetCaption(const Value : TCaption);

        procedure SetMenu(const Value : TMainMenu);
        procedure SetMenuBarColor(const Value : TColor);
        function GetSections: TsuiTitleBarSections;
        procedure SetSections(const Value: TsuiTitleBarSections);
        procedure SetColor(const Value: TColor);
        function GetDrawAppIcon: Boolean;
        procedure SetDrawAppIcon(const Value: Boolean);
        procedure SetMenuBarHeight(const Value: Integer);
        procedure SetTitleBarVisible(const Value: Boolean);
        function GetTitleBarVisible: Boolean;
        function GetMDIChild: Boolean;
        function GetRoundCorner: Integer;
        procedure SetRoundCorner(const Value: Integer);
        function GetRoundCornerBottom: Integer;
        procedure SetRoundCornerBottom(const Value: Integer);
        procedure SetFileTheme(const Value: TsuiFileTheme);

        procedure DrawButton(Sender: TToolBar; Button: TToolButton; State: TCustomDrawState; var DefaultDraw: Boolean);
        procedure DrawMenuBar(Sender: TToolBar; const ARect: TRect; var DefaultDraw: Boolean);

        procedure OnApplicationMessage(var Msg: TMsg; var Handled: Boolean);
        function GetTitleBarHeight: Integer;
        function GetTitleBarCustom: Boolean;
        procedure SetTitleBarCustom(const Value: Boolean);
        function GetVersion: String;
        procedure SetVersion(const Value: String);

        procedure RegionWindow();

    protected
        procedure SetPanel(const Value : TCustomPanel);
        procedure SetBorderWidth(const Value : Integer);
        procedure SetUIStyle(const Value : TsuiUIStyle);
        procedure Notification(AComponent: TComponent; Operation: TOperation); override;
        procedure PaintFormBorder();
        procedure Paint(); override;
        procedure Resize(); override;

        procedure CreateMenuBar();
        procedure DestroyMenuBar();

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

        procedure UpdateMenu();
        procedure UpdateTopMenu();
        procedure RepaintMenuBar();
        
        property MDIChild : Boolean read GetMDIChild;
        property TitleBarHeight : Integer read GetTitleBarHeight;
        procedure ReAssign;        
        
    published
        property TitleBarCustom : Boolean read GetTitleBarCustom write SetTitleBarCustom;
        property FileTheme : TsuiFileTheme read m_FileTheme write SetFileTheme;
        property UIStyle : TsuiUIStyle read m_UIStyle write SetUIStyle;
        property UIStyleAutoUpdateSub : Boolean read m_UIStyleAutoUpdateSub write m_UIStyleAutoUpdateSub;
        property BorderColor : TColor read m_Color write SetColor;
        property BorderWidth : Integer read m_Width write SetBorderWidth;
        property TitleBarVisible : Boolean read GetTitleBarVisible write SetTitleBarVisible default True;
        property BiDiMode;
        property Color;
        property Caption : TCaption read GetCaption write SetCaption;
        property FormPanel : TCustomPanel read m_Panel write SetPanel;
        property TitleBarButtons : TsuiTitleBarButtons read GetButtons write SetButtons;
        property TitleBarSections : TsuiTitleBarSections read GetSections write SetSections;
        property TitleBarDrawAppIcon : Boolean read GetDrawAppIcon write SetDrawAppIcon;
        property Font : TFont read GetFont write SetFont;
        property Menu : TMainMenu read m_Menu write SetMenu;
        property MenuBarColor : TColor read m_MenuBarColor write SetMenuBarColor;
        property MenuBarHeight : Integer read m_MenuBarHeight write SetMenuBarHeight;
        property RoundCorner : Integer read GetRoundCorner write SetRoundCorner;
        property RoundCornerBottom : Integer read GetRoundCornerBottom write SetRoundCornerBottom;
        property PopupMenu;
        property Version : String read GetVersion write SetVersion;

        property OnTitleBarCustomBtnsClick : TsuiTitleBarButtonClickEvent read GetOnBtnClick write SetOnBtnClick;
        property OnTitleBarHelpBtnClick : TsuiTitleBarButtonClickEvent read GetOnHelpBtnClick write SetOnHelpBtnClick;
        property OnMouseDown;
    	property OnMouseMove;
        property OnClick;
        property OnMouseUp;

    end;

    TsuiMDIForm = class(TComponent)
    private
        m_Form : TForm;
        m_OldWndProc : TWndMethod; 
        m_PrevClientWndProc: Pointer;
        m_TopPanel : TPanel;
        m_TitleBar : TsuiTitleBar;
        m_MenuBar : TsuiMenuBar;
        m_ControlBtns : array [1..3] of TsuiToolBarSpeedButton;
        m_DrawChildCaptions : Boolean;
        m_DrawChildMenus : Boolean;
        m_Destroyed : Boolean;
        m_BorderBuf : TBitmap;
        m_BottomBorderWidth : Integer;        

        m_Menu : TMainMenu;
        m_TopMenu : TMainMenu;
        m_UIStyle : TsuiUIStyle;
        m_FileTheme : TsuiFileTheme;
        m_MenuBarColor : TColor;
        m_BorderColor : TColor;
        m_BorderWidth : Integer;
        m_RoundCorner : Integer;
        m_RoundCornerBottom : Integer;
        m_AppEvent : TApplicationEvents;

        procedure NewParentWndProc(var Msg: TMessage);
        procedure NewClientWndProc(var Msg : TMessage);
        procedure ProcessKeyPress(var Msg : TMessage);
        procedure OnControlButtonClick(Sender : TObject);
        procedure OnApplicationMessage(var Msg: TMsg; var Handled: Boolean);
        procedure OnTopPanelResize(Sender : TObject);
        procedure SetMenu(const Value: TMainMenu);
        procedure SetMenuBarColor(const Value : TColor);
        procedure SetUIStyle(const Value : TsuiUIStyle);
        procedure SetFileTheme(const Value: TsuiFileTheme);
        procedure SetBorderColor(const Value: TColor);
        function GetCaption: TCaption;
        procedure SetCaption(const Value: TCaption);

        procedure PaintBorder();
        function GetActiveChildSUIForm() : TsuiForm;

        procedure CreateMenuBar();
        procedure DestroyMenuBar();
        procedure ShowMenuBar();
        procedure HideMenuBar();
        procedure ShowControlButtons();
        procedure HideControlButtons();
        function GetMainMenu() : TMainMenu;

        procedure SetDrawAppIcon(const Value: Boolean);
        function GetDrawAppIcon: Boolean;
        function GetTitleBarCustom: Boolean;
        procedure SetTitleBarCustom(const Value: Boolean);
        procedure SetTitleBarVisible(const Value: Boolean);
        function GetTitleBarVisible: Boolean;
        function GetSections: TsuiTitleBarSections;
        procedure SetSections(const Value: TsuiTitleBarSections);
        procedure SetButtons(const Value : TsuiTitleBarButtons);
        function GetButtons() : TsuiTitleBarButtons;

        procedure DrawButton(Sender: TToolBar; Button: TToolButton; State: TCustomDrawState; var DefaultDraw: Boolean);
        procedure DrawMenuBar(Sender: TToolBar; const ARect: TRect; var DefaultDraw: Boolean);
        procedure SetRoundCorner(const Value: Integer);
        procedure SetRoundCornerBottom(const Value: Integer);

        procedure RegionWindow();

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

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

        procedure UpdateMenu();
        procedure Cascade();
        procedure Tile();

        function GetTitleBarHeight: integer;

    published
        property UIStyle : TsuiUIStyle read m_UIStyle write SetUIStyle;
        property FileTheme : TsuiFileTheme read m_FileTheme write SetFileTheme;
        property Menu : TMainMenu read m_Menu write SetMenu;
        property MenuBarColor : TColor read m_MenuBarColor write SetMenuBarColor;
        property BorderColor : TColor read m_BorderColor write SetBorderColor;
        property Caption : TCaption read GetCaption write SetCaption;
        property TitleBarDrawAppIcon : Boolean read GetDrawAppIcon write SetDrawAppIcon default False;
        property TitleBarCustom : Boolean read GetTitleBarCustom write SetTitleBarCustom default False;
        property TitleBarVisible : Boolean read GetTitleBarVisible write SetTitleBarVisible default True;
        property TitleBarButtons : TsuiTitleBarButtons read GetButtons write SetButtons;
        property TitleBarSections : TsuiTitleBarSections read GetSections write SetSections;
        property TitleBarDrawChildCaptions : Boolean read m_DrawChildCaptions write m_DrawChildCaptions default True;
        property TitleBarDrawChildMenus : Boolean read m_DrawChildMenus write m_DrawChildMenus default True;
        property RoundCorner : Integer read m_RoundCorner write SetRoundCorner;
        property RoundCornerBottom : Integer read m_RoundCornerBottom write SetRoundCornerBottom;
    end;

    TsuiMSNPopForm = class(TComponent)
    private
        m_Form : TfrmMSNPopForm;
        m_AnimateTime : Integer;
        m_StayTime : Integer;
        m_X : Integer;
        m_Y : Integer;
        m_AutoPosition : Boolean;
        m_ClickHide : Boolean;
        m_Title : TCaption;
        m_Text : String;
        m_TextFont : TFont;
        m_TitleFont : TFont;
        m_OnTitleClick : TNotifyEvent;
        m_OnClick : TNotifyEvent;
        m_OnClose : TNotifyEvent;
        m_OnShow : TNotifyEvent;

        procedure InternalOnTitleClick(Sender : TObject);
        procedure InternalOnClick(Sender : TObject);
        procedure InternalOnClose(Sender : TObject);
        procedure SetTextFont(const Value: TFont);
        procedure SetTitleFont(const Value: TFont);

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

        procedure Popup();
        procedure Close();

    published
        property AnimateTime : Integer read m_AnimateTime write m_AnimateTime;
        property StayTime : Integer read m_StayTime write m_StayTime;
        property PositionX : Integer read m_X write m_X;
        property PositionY : Integer read m_Y write m_Y;
        property AutoPosition : Boolean read m_AutoPosition write m_AutoPosition;
        property ClickHide : Boolean read m_ClickHide write m_ClickHide;
        property Title : TCaption read m_Title write m_Title;
        property MessageText : String read m_Text write m_Text;

        property TitleFont : TFont read m_TitleFont write SetTitleFont;
        property MessageFont : TFont read m_TextFont write SetTextFont;

        property OnTitleClick : TNotifyEvent read m_OnTitleClick write m_OnTitleClick;
        property OnClick : TNotifyEvent read m_OnClick write m_OnClick;
        property OnClose : TNotifyEvent read m_OnClose write m_OnClose;
        property OnShow : TNotifyEvent read m_OnShow write m_OnShow;
    end;


implementation

uses SUIResDef, SUIPublic, SUIImagePanel, SUIMainMenu, SUIMenu, SUIProgressBar;

{ TsuiForm }

constructor TsuiForm.Create(AOwner: TComponent);
var
    i : Integer;
    c : Integer;
begin
    inherited;

    if not (AOwner is TForm) then
        Exit;

    m_Form := AOwner as TForm;
    c := 0;
    for i := 0 to m_Form.ControlCount - 1 do
    begin
        if m_Form.Controls[i] is TsuiForm then
            Inc(c);
    end;
    if c >= 1 then
        Exit;

    m_Destroyed := false;

    m_Form.Constraints.MinHeight := 50;
    m_Form.Constraints.MinWidth := 125;
    Constraints.MinHeight := 50;
    Constraints.MinWidth := 125;

    m_Form.BorderWidth := 0;
    m_FormInitRect := Classes.Rect(m_Form.Left, m_Form.Top, m_Form.Width + m_Form.Left, m_Form.Height + m_Form.Top);
    m_FormInitMax := (m_Form.WindowState = wsMaximized);

    m_TitleBar := TsuiTitleBar.Create(self);
    m_TitleBar.Parent := self;

    m_MenuBar := nil;
    m_MenuBarColor := Color;
    m_MenuBarHeight := 22;

    UIStyle := SUI_THEME_DEFAULT;
    m_UIStyleAutoUpdateSub := false;

    BevelOuter := bvNone;
    BevelInner := bvNone;
    BorderStyle := bsNone;
    Align := alClient;
    Caption := m_Form.Caption;
    TitleBarVisible := true;
    inherited Caption := ' ';

    for i := 0 to m_Form.ControlCount - 1 do
    begin
        if m_Form.Controls[i] is TsuiForm then
            raise Exception.Create('Sorry, You can create only one TsuiForm component in one form!');
    end;

    m_Form.Scaled := false;

    m_OldBorderStyle := m_Form.BorderStyle;
    case m_Form.BorderStyle of
    bsNone, bsSingle, bsToolWindow: m_Form.BorderStyle := bsDialog;
    end;

    SetWindowLong(m_Form.Handle, GWL_STYLE, GetWindowLong(m_Form.Handle, GWL_STYLE) and (not WS_CAPTION));

    m_Form.AutoScroll := false;

    m_OldWndProc := m_Form.WindowProc;
    m_Form.WindowProc := NewParentWndProc;

    m_AppEvent := TApplicationEvents.Create(nil);
    m_AppEvent.OnMessage := OnApplicationMessage;

    SetWindowPos(m_Form.Handle, 0, 0, 0, 0, 0, SWP_DRAWFRAME or SWP_NOMOVE or SWP_NOZORDER or SWP_NOSIZE or SWP_NOACTIVATE);
end;

procedure TsuiForm.CreateMenuBar;
begin
    if m_MenuBar <> nil then
        Exit;
    if m_Form.FormStyle = fsMDIChild then
        Exit;
    m_MenuBar := TsuiMenuBar.Create(self);
    m_MenuBar.m_Form := self;
    m_MenuBar.Parent := self;
    m_MenuBar.Flat := true;
    m_MenuBar.EdgeBorders := [];
    m_MenuBar.ShowCaptions := true;
    m_MenuBar.Height := m_MenuBarHeight;
    m_MenuBar.Color := m_MenuBarColor;
    if not (csDesigning in ComponentState) then
        m_MenuBar.OnCustomDrawButton := DrawButton;
    m_MenuBar.OnCustomDraw := DrawMenuBar;
    m_MenuBar.Wrapable := true;
    m_MenuBar.AutoSize := true;
    m_TitleBar.Top := 0;
end;

destructor TsuiForm.Destroy;
begin
    m_Destroyed := true;
    m_AppEvent.Free();
    m_AppEvent := nil;

    if m_MenuBar <> nil then
    begin

⌨️ 快捷键说明

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