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

📄 suititlebar.pas

📁 SUIPack是一款为Delphi和C++Builder开发的所见即所得的界面增强VCL组件
💻 PAS
📖 第 1 页 / 共 4 页
字号:
                    WorkAreaRect := GetWorkAreaRect();
                    Dec(WorkAreaRect.Bottom);
                    Dec(WorkAreaRect.Top, 2);
                    Dec(WorkAreaRect.Left, 2);
                    Inc(WorkAreaRect.Right, 2);
                    PlaceControl(ParentForm, WorkAreaRect);
                end;
            end;
            ProcessMaxBtn();
        end;

        suiMin :
        begin
            if (Application <> nil) and (ParentForm = Application.MainForm) then
                SendMessage(Application.MainForm.Handle, WM_SYSCOMMAND, SC_MINIMIZE, 0)
            else
            begin
                //ShowWindow(ParentForm.Handle, SW_SHOWMINIMIZED);
                ParentForm.WindowState := wsMinimized;
            end;
        end;

        suiClose :
        begin
            ParentForm.Close();
        end;

        suiControlBox :
        begin
            if Assigned(m_ControlBoxMenu) then
            begin
                if ((Collection as TsuiTitleBarButtons).m_TitleBar.BidiMode = bdRightToLeft) and SysLocale.MiddleEast then
                    Point.X := 176
                else
                    Point.X := 0;
                Point.Y := (Collection as TsuiTitleBarButtons).m_TitleBar.Height;
                Point := (Collection as TsuiTitleBarButtons).m_TitleBar.ClientToScreen(Point);
                if Point.X < 0 then
                    Point.X := 0;
                m_ControlBoxMenu.Popup(Point.X, Point.Y);
            end;
        end;

        suiCustom :
        begin

        end;
    end; // case
end;

procedure TsuiTitleBarButton.ProcessMaxBtn;

    procedure InMAX(FileTheme : TsuiFileTheme);
    var
        OutUIStyle : TsuiUIStyle;
    begin
        if UsingFileTheme(FileTheme, m_UIStyle, OutUIStyle) then
        begin
            FileTheme.GetBitmap2(SKIN2_TITLEBUTTONS, PicNormal.Bitmap, 18, 10);
            FileTheme.GetBitmap2(SKIN2_TITLEBUTTONS, PicMouseOn.Bitmap, 18, 11);
            FileTheme.GetBitmap2(SKIN2_TITLEBUTTONS, PicMouseDown.Bitmap, 18, 12);
        end
        else
        begin
            GetInsideThemeBitmap(OutUIStyle, SUI_THEME_TITLEBAR_BUTTON_IMAGE, PicNormal.Bitmap, 18, 10);
            GetInsideThemeBitmap(OutUIStyle, SUI_THEME_TITLEBAR_BUTTON_IMAGE, PicMouseOn.Bitmap, 18, 11);
            GetInsideThemeBitmap(OutUIStyle, SUI_THEME_TITLEBAR_BUTTON_IMAGE, PicMouseDown.Bitmap, 18, 12);
        end;
    end;

    procedure InNormal(FileTheme : TsuiFileTheme);
    var
        OutUIStyle : TsuiUIStyle;
    begin
        if UsingFileTheme(FileTheme, m_UIStyle, OutUIStyle) then
        begin
            FileTheme.GetBitmap2(SKIN2_TITLEBUTTONS, PicNormal.Bitmap, 18, 7);
            FileTheme.GetBitmap2(SKIN2_TITLEBUTTONS, PicMouseOn.Bitmap, 18, 8);
            FileTheme.GetBitmap2(SKIN2_TITLEBUTTONS, PicMouseDown.Bitmap, 18, 9);
        end
        else
        begin
            GetInsideThemeBitmap(OutUIStyle, SUI_THEME_TITLEBAR_BUTTON_IMAGE, PicNormal.Bitmap, 18, 7);
            GetInsideThemeBitmap(OutUIStyle, SUI_THEME_TITLEBAR_BUTTON_IMAGE, PicMouseOn.Bitmap, 18, 8);
            GetInsideThemeBitmap(OutUIStyle, SUI_THEME_TITLEBAR_BUTTON_IMAGE, PicMouseDown.Bitmap, 18, 9);
        end;
    end;

var
    ParentForm : TCustomForm;
begin
    if ButtonType <> suiMax then
        Exit;

    if (Collection as TsuiTitleBarButtons).m_TitleBar.Custom then
        Exit;

    ParentForm := GetParentForm((Collection as TsuiTitleBarButtons).m_TitleBar);
    if ParentForm = nil then
    begin
        InNormal((Collection as TsuiTitleBarButtons).m_TitleBar.FileTheme);
        Exit;
    end;

    if ParentForm.WindowState = wsMaximized then
        InMax((Collection as TsuiTitleBarButtons).m_TitleBar.FileTheme)
    else
        InNormal((Collection as TsuiTitleBarButtons).m_TitleBar.FileTheme);
end;

procedure TsuiTitleBarButton.SetButtonType(const Value: TsuiTitleBarBtnType);
var
    i : Integer;
begin
    if Value = suiControlBox then
    begin
        for i := 0 to (Collection as TsuiTitleBarButtons).Count - 1 do
        begin
            if (Collection as TsuiTitleBarButtons).Items[i].ButtonType = suiControlBox then
            begin
                MessageDlg('Sorry, only one button''s ButtonType property can be "suiControlBox"', mtError, [mbOK], 0);
                Exit;
            end;
        end;
    end;

    m_ButtonType := Value;
    UpdateUIStyle();

    (Collection as TsuiTitleBarButtons).m_TitleBar.Repaint();
end;

procedure TsuiTitleBarButton.SetPicMouseDown(const Value: TPicture);
begin
    m_PicMouseDown.Assign(Value);

    (Collection as TsuiTitleBarButtons).m_TitleBar.Repaint();
end;

procedure TsuiTitleBarButton.SetPicMouseOn(const Value: TPicture);
begin
    m_PicMouseOn.Assign(Value);

    (Collection as TsuiTitleBarButtons).m_TitleBar.Repaint();
end;

procedure TsuiTitleBarButton.SetPicNormal(const Value: TPicture);
begin
    m_PicNormal.Assign(Value);

    (Collection as TsuiTitleBarButtons).m_TitleBar.Repaint();
end;

procedure TsuiTitleBarButton.SetTop(const Value: Integer);
begin
    m_Top := Value;

    (Collection as TsuiTitleBarButtons).m_TitleBar.Repaint();
end;

procedure TsuiTitleBarButton.SetTransparent(const Value: Boolean);
begin
    m_Transparent := Value;

    (Collection as TsuiTitleBarButtons).m_TitleBar.Repaint();
end;

procedure TsuiTitleBarButton.SetUIStyle(const Value: TsuiUIStyle);
begin
    m_UIStyle := Value;

    UpdateUIStyle();
end;

procedure TsuiTitleBarButton.SetVisible(const Value: Boolean);
begin
    m_Visible := Value;
    (Collection as TsuiTitleBarButtons).m_TitleBar.Repaint();
end;

procedure TsuiTitleBarButton.UpdateFileTheme;
var
    nNormal : Integer;
    nMouseOn : Integer;
    nMouseDown : Integer;
    FileTheme : TsuiFileTheme;
begin
    FileTheme := (Collection as TsuiTitleBarButtons).m_TitleBar.FileTheme;
    Transparent := FileTheme.GetBool(SKIN2_TITLEBTNTRANS);

    case m_ButtonType of

    suiMax :
    begin
        nNormal := 7;
        nMouseOn := 8;
        nMouseDown := 9;
    end;

    suiMin :
    begin
        nNormal := 13;
        nMouseOn := 14;
        nMouseDown := 15;
    end;

    suiClose :
    begin
        nNormal := 16;
        nMouseOn := 17;
        nMouseDown := 18;
    end;

    suiHelp :
    begin
        nNormal := 4;
        nMouseOn := 5;
        nMouseDown := 6;
    end;

    suiControlBox :
    begin
        nNormal := 1;
        nMouseOn := 2;
        nMouseDown := 3;
    end;

    else Exit;

    end; // case

    FileTheme.GetBitmap2(SKIN2_TITLEBUTTONS, PicNormal.Bitmap, 18, nNormal);
    FileTheme.GetBitmap2(SKIN2_TITLEBUTTONS, PicMouseOn.Bitmap, 18, nMouseOn);
    FileTheme.GetBitmap2(SKIN2_TITLEBUTTONS, PicMouseDown.Bitmap, 18, nMouseDown);

    Top := FileTheme.GetInt(SKIN2_TITLEBARBUTTONPOSY);
end;

procedure TsuiTitleBarButton.UpdateInsideTheme(UIStyle : TsuiUIStyle);
var
    nNormal : Integer;
    nMouseOn : Integer;
    nMouseDown : Integer;
begin
    Transparent := GetInsideThemeBool(UIStyle, SUI_THEME_TITLEBAR_BUTTON_TRANSPARENT_BOOL);

    case m_ButtonType of

    suiMax :
    begin
        nNormal := 7;
        nMouseOn := 8;
        nMouseDown := 9;
    end;

    suiMin :
    begin
        nNormal := 13;
        nMouseOn := 14;
        nMouseDown := 15;
    end;

    suiClose :
    begin
        nNormal := 16;
        nMouseOn := 17;
        nMouseDown := 18;
    end;

    suiHelp :
    begin
        nNormal := 4;
        nMouseOn := 5;
        nMouseDown := 6;
    end;

    suiControlBox :
    begin
        nNormal := 1;
        nMouseOn := 2;
        nMouseDown := 3;
    end;

    else Exit;

    end; // case

    GetInsideThemeBitmap(UIStyle, SUI_THEME_TITLEBAR_BUTTON_IMAGE, PicNormal.Bitmap, 18, nNormal);
    GetInsideThemeBitmap(UIStyle, SUI_THEME_TITLEBAR_BUTTON_IMAGE, PicMouseOn.Bitmap, 18, nMouseOn);
    GetInsideThemeBitmap(UIStyle, SUI_THEME_TITLEBAR_BUTTON_IMAGE, PicMouseDown.Bitmap, 18, nMouseDown);

    Top := GetInsideThemeInt(UIStyle, SUI_THEME_TITLEBAR_BUTTON_TOP_INT);
end;

procedure TsuiTitleBarButton.UpdateUIStyle;
var
    OutUIStyle : TsuiUIStyle;
begin
    if UsingFileTheme((Collection as TsuiTitleBarButtons).m_TitleBar.FileTheme, m_UIStyle, OutUIStyle) then
        UpdateFileTheme()
    else
        UpdateInsideTheme(OutUIStyle);

    if m_ButtonType = suiMax then
        ProcessMaxBtn();
end;

procedure TsuiTitleBar.CMFONTCHANGED(var Msg: TMessage);
begin
    Repaint();
end;

procedure TsuiTitleBar.SetRoundCorner(const Value: Integer);
begin
    m_RoundCorner := Value;
end;

procedure TsuiTitleBar.WMNCLBUTTONDOWN(var Msg: TMessage);
begin
    Msg.Result := SendMessage(GetParentForm(Self).Handle, Msg.Msg, Msg.WParam, Msg.LParam);
end;

procedure TsuiTitleBar.WMNCLBUTTONUP(var Msg: TMessage);
begin
    Msg.Result := SendMessage(GetParentForm(Self).Handle, Msg.Msg, Msg.WParam, Msg.LParam);
end;

procedure TsuiTitleBar.WMNCMOUSEMOVE(var Msg: TMessage);
begin
    Msg.Result := SendMessage(GetParentForm(Self).Handle, Msg.Msg, Msg.WParam, Msg.LParam);
end;

procedure TsuiTitleBar.SetFileTheme(const Value: TsuiFileTheme);
begin
    m_FileTheme := Value;
    m_SelfChanging := true;
    SetUIStyle(m_UIStyle);
    m_SelfChanging := false;
end;

procedure TsuiTitleBar.UpdateFileTheme;
var
    Sec : TsuiTitleBarSection;
    Form : TCustomForm;
begin
    m_FiveSec := m_FileTheme.GetBool(SKIN2_TITLEFIVESECT);
    m_TransColor := m_FileTheme.GetColor(SKIN2_TRANSCOLOR);

    Sec := Sections.Add();
    Sec.Picture.Bitmap.Assign(m_FileTheme.GetBitmap(SKIN2_TITLEBAR1));
    Sec.AutoSize := true;

    Sec := Sections.Add();
    Sec.Picture.Bitmap.Assign(m_FileTheme.GetBitmap(SKIN2_TITLEBAR2));

    if m_FiveSec then
        Sec.CapSec := true
    else
        Sec.Align := suiClient;

    Sec := Sections.Add();
    Sec.Picture.Bitmap.Assign(m_FileTheme.GetBitmap(SKIN2_TITLEBAR3));
    Sec.AutoSize := true;
    if not m_FiveSec then
        Sec.Align := suiRight;

    if m_FiveSec then
    begin
        Sec := Sections.Add();
        Sec.Picture.Bitmap.Assign(m_FileTheme.GetBitmap(SKIN2_TITLEBAR4));
        Sec.Align := suiClient;
        Sec := Sections.Add();
        Sec.Picture.Bitmap.Assign(m_FileTheme.GetBitmap(SKIN2_TITLEBAR5));
        Sec.AutoSize := true;
        Sec.Align := suiRight;
    end;

    LeftBtnXOffset := m_FileTheme.GetInt(SKIN2_TITLEBARICONPOSX);
    RightBtnXOffset := m_FileTheme.GetInt(SKIN2_TITLEBARBUTTONPOSX);
    m_FileTheme.GetBitmap(SKIN2_TITLEBUTTONS).PixelFormat := pf24Bit;
    m_BtnHeight := m_FileTheme.GetBitmap(SKIN2_TITLEBUTTONS).Height;
    m_BtnTop := m_FileTheme.GetInt(SKIN2_TITLEBARBUTTONPOSY);
    m_IconTop := m_FileTheme.GetInt(SKIN2_TITLEBARICONPOSY);
    m_CapTop := m_FileTheme.GetInt(SKIN2_TITLEBARCAPTIONTOP);
    m_FormColor := m_FileTheme.GetColor(SKIN2_FORMCOLOR);
    if Inform() then
    begin
        Dec(m_BtnTop, 3);
        Dec(m_IconTop, 3);
    end;

    Form := GetParentForm(self);
    if Form <> nil then
    begin
        if m_FiveSec then
        begin
            Form.Constraints.MinWidth := m_FileTheme.GetBitmap(SKIN2_TITLEBAR1).Width +
                m_FileTheme.GetBitmap(SKIN2_TITLEBAR3).Width + 16 +
                Max(m_FileTheme.GetBitmap(SKIN2_TITLEBAR5).Width,
                m_FileTheme.GetBitmap(SKIN2_TITLEBUTTONS).Width div 18 * m_Buttons.Count + m_FileTheme.GetInt(SKIN2_TITLEBARBUTTONPOSX));
        end
        else
        begin
            Form.Constraints.MinWidth := m_FileTheme.GetBitmap(SKIN2_TITLEBAR1).Width +
                Max(m_FileTheme.GetBitmap(SKIN2_TITLEBAR3).Width,
                    m_FileTheme.GetBitmap(SKIN2_TITLEBUTTONS).Width div 18 * m_Buttons.Count + m_FileTheme.GetInt(SKIN2_TITLEBARBUTTONPOSX));
        end;
    end;
end;

procedure TsuiTitleBar.UpdateInsideTheme(UIStyle : TsuiUIStyle);
var
    Sec : TsuiTitleBarSection;
    Form : TCustomForm;
    TempBmp : TBitmap;
begin
    Sec := Sections.Add();
    GetInsideThemeBitmap(UIStyle, SUI_THEME_TITLEBAR_LEFT_IMAGE, Sec.Picture.Bitmap);
    Sec.AutoSize := true;

    Sec := Sections.Add();
    GetInsideThemeBitmap(UIStyle, SUI_THEME_TITLEBAR_RIGHT_IMAGE, Sec.Picture.Bitmap);
    Sec.AutoSize := true;
    Sec.Align := suiRight;

    Sec := Sections.Add();
    GetInsideThemeBitmap(UIStyle, SUI_THEME_TITLEBAR_CLIENT_IMAGE, Sec.Picture.Bitmap);
    Sec.Align := suiClient;

    LeftBtnXOffset := GetInsideThemeInt(UIStyle, SUI_THEME_TITLEBAR_BUTTON_LEFTOFFSET_INT);
    RightBtnXOffset := GetInsideThemeInt(UIStyle, SUI_THEME_TITLEBAR_BUTTON_RIGHTOFFSET_INT);
    m_BorderColor := GetInsideThemeColor(UIStyle, SUI_THEME_FORM_BORDER_COLOR);
    TempBmp := TBitmap.Create();
    GetInsideThemeBitmap(UIStyle, SUI_THEME_TITLEBAR_BUTTON_IMAGE, TempBmp);
    m_BtnHeight := TempBmp.Height;
    TempBmp.Free();
    m_BtnTop := GetInsideThemeInt(UIStyle, SUI_THEME_TITLEBAR_BUTTON_TOP_INT);
    if Inform() then
        Dec(m_BtnTop, 3);
    m_IconTop := m_BtnTop;

    Form := GetParentForm(self);
    if Form <> nil then
    begin
        Form.Constraints.MinWidth := GetInsideThemeInt(UIStyle, SUI_THEME_FORM_MINWIDTH_INT);
        Form.Constraints.MinHeight := 50;
    end;

    m_RoundCorner := GetInsideThemeInt(UIStyle, SUI_THEME_FORM_ROUNDCORNER_INT);
    m_RoundCornerBottom := 0;
end;

procedure TsuiTitleBar.Notification(AComponent: TComponent;
  Operation: TOperation);
begin
    inherited;

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

end.

⌨️ 快捷键说明

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