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

📄 suiform.pas

📁 一套还不错的DELPHI皮肤控件!
💻 PAS
📖 第 1 页 / 共 5 页
字号:
    end;

    if (
        (Operation = opRemove) and
        (AComponent = m_TitleBar)
    ) then
    begin
        m_TitleBar := nil;
    end;

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

    if (
        (Operation = opRemove) and
        (AComponent = self)
    )then
    begin
        if m_Menu <> nil then
        begin
            if m_Menu is TsuiMainMenu then
                (m_Menu as TsuiMainMenu).Form := nil;
        end;

        m_Destroyed := true;
        if m_Form.HandleAllocated then
        begin
            SetWindowLong(m_Form.Handle, GWL_STYLE, GetWindowLong(m_Form.Handle, GWL_STYLE) or WS_CAPTION);
            SetWindowLong(m_Form.Handle, GWL_WNDPROC, LongInt(m_PrevParentWndProc));
            SetWindowLong(m_Form.ClientHandle, GWL_WNDPROC, LongInt(m_PrevClientWndProc));
            SetWindowPos(m_Form.Handle, 0, 0, 0, 0, 0, SWP_DRAWFRAME or SWP_NOMOVE or SWP_NOZORDER or SWP_NOSIZE or SWP_NOACTIVATE);
        end;
        if m_AppOnMsgAssigned and (Application <> nil) then
            Application.OnMessage := nil;
    end;
end;

procedure TsuiMDIForm.OnApplicationMessage(var Msg: TMsg;
  var Handled: Boolean);
var
    AMsg : TMessage;
begin
    if Msg.message = WM_KEYDOWN then
    begin
        AMsg.Msg := Msg.message;
        AMsg.WParam := Msg.wParam;
        AMsg.LParam := Msg.lParam;
        ProcessKeyPress(AMsg);
        Handled := Boolean(AMsg.Result);
    end;
end;

procedure TsuiMDIForm.OnControlButtonClick(Sender: TObject);
begin
    if not (Sender is TsuiToolBarSpeedButton) then
        Exit;
    case (Sender as TsuiToolBarSpeedButton).Tag of

    -1383 : // min
    begin
        ShowWindow(m_Form.ActiveMDIChild.Handle, SW_SHOWMINIMIZED);
        Application.ProcessMessages();
    end;

    -1382 : // restore
    begin
        m_Form.ActiveMDIChild.WindowState := wsNormal;
        Application.ProcessMessages();        
    end;

    -1381 : // close
    begin
        m_Form.ActiveMDIChild.Close();
        Application.ProcessMessages();
    end;

    end;
end;

procedure TsuiMDIForm.PaintBorder;
var
    R : TRect;
    ACanvas : TCanvas;
    Bmp : TBitmap;
    nLeft, nRight : Integer;
    Tmp : TBitmap;
begin
    if m_Destroyed then
        Exit;

    if (m_Form = nil) or (not m_Form.HandleAllocated) then
    begin
        inherited;
        Exit;
    end;
    if m_Form.BorderWidth <> 0 then
        m_Form.BorderWidth := 0;
    if (m_Form.WindowState = wsMinimized) and (not (csDesigning in ComponentState)) then
        Exit;

    ACanvas := TCanvas.Create();
    ACanvas.Handle := GetWindowDC(m_Form.Handle);

    ACanvas.Brush.Color := m_BorderColor;
    R := Rect(0, 0, m_BorderWidth, m_Form.Height);
    ACanvas.FillRect(R);
    R := Rect(0, m_Form.Height - m_BorderWidth, m_Form.Width, m_Form.Height);
    ACanvas.FillRect(R);
    R := Rect(m_Form.Width - m_BorderWidth, m_Form.Height, m_Form.Width, 0);
    ACanvas.FillRect(R);

    if m_BorderWidth < 4 then
    begin
        ACanvas.Brush.Color := MenuBarColor;
        R := Rect(m_BorderWidth, m_TitleBar.Height, 3, m_Form.Height - m_BorderWidth);
        ACanvas.FillRect(R);
        R := Rect(m_BorderWidth, m_Form.Height - 3, m_Form.Width - m_BorderWidth, m_Form.Height - m_BorderWidth);
        ACanvas.FillRect(R);
        R := Rect(m_Form.Width - 3, m_Form.Height - m_BorderWidth, m_Form.Width - m_BorderWidth, m_TitleBar.Height);
        ACanvas.FillRect(R);

        if (m_MenuBar <> nil) and (m_MenuBar.Visible) then
        begin
            ACanvas.Brush.Color := m_MenuBar.Color;
            R := Rect(m_BorderWidth, 3 + m_TitleBar.Height, 3, 3 + m_TitleBar.Height + m_MenuBar.Height);
            ACanvas.FillRect(R);
            R := Rect(m_Form.Width - 3, 3 + m_TitleBar.Height, m_Form.Width - m_BorderWidth, 3 + m_TitleBar.Height + m_MenuBar.Height);
            ACanvas.FillRect(R);
        end;
    end;

    if TitleBarVisible and m_TitleBar.CanPaint() and (m_BorderWidth < 4) then
    begin
        Tmp := TBitmap.Create();

        m_TitleBar.GetLeftImage(Bmp);
        Tmp.Width := 3 - m_BorderWidth;
        Tmp.Height := Bmp.Height;
        Tmp.Canvas.Draw(0, 0, Bmp);
        ACanvas.Draw(m_BorderWidth, 0, Tmp);

        m_TitleBar.GetRightImage(Bmp);
        if Bmp.Width < 3 then
            Tmp.Canvas.StretchDraw(Rect(0, 0, Tmp.Width, Tmp.Height), Bmp)
        else
            Tmp.Canvas.Draw(2 - Bmp.Width, 0, Bmp);
        ACanvas.Draw(m_Form.Width - 3, 0, Tmp);

        Tmp.Width := m_Form.Width - 5;
        Tmp.Height := 3;
        m_TitleBar.GetLeftImage(Bmp);
        Tmp.Canvas.Draw(-2, 0, Bmp);
        nLeft := Bmp.Width - 2;
        m_TitleBar.GetRightImage(Bmp);
        nRight := Tmp.Width - Bmp.Width + 3;
        Tmp.Canvas.Draw(nRight, 0, Bmp);
        m_TitleBar.GetCenterImage(Bmp);
        Tmp.Canvas.StretchDraw(Rect(nLeft, 0, nRight, Bmp.Height), Bmp);
        ACanvas.Draw(2, 0, Tmp);

        if (m_BorderWidth = 1) and (RoundCorner = 11) and not (csDesigning in ComponentState) then
        begin
            ACanvas.Pen.Color := m_BorderColor;
            ACanvas.Arc(m_Form.Width - RoundCorner * 2 + 1, -1, m_Form.Width + 1, RoundCorner * 2 - 1, m_Form.Width + 1, RoundCorner - 1, m_Form.Width - RoundCorner + 1, -1);
            ACanvas.Arc(-1, -1, RoundCorner * 2 - 1, RoundCorner * 2 - 1, RoundCorner - 1, -1, - 1, RoundCorner - 1);
        end;

        Tmp.Free();
    end
    else if not TitleBarVisible then
    begin
        ACanvas.Brush.Color := m_BorderColor;
        R := Rect(0, 0, m_Form.Width, 1);
        ACanvas.FillRect(R);
        ACanvas.Brush.Color := MenuBarColor;
        R := Rect(m_BorderWidth, 1, m_Form.Width - m_BorderWidth, 3);
        ACanvas.FillRect(R);
    end;    

    ReleaseDC(m_Form.Handle, ACanvas.Handle);
    ACanvas.Free();
end;

procedure TsuiMDIForm.ProcessKeyPress(var Msg: TMessage);
begin
    if m_Destroyed then
        Exit;

    if not Assigned(m_TopMenu) then
        Msg.Result := 0
    else if m_TopMenu.IsShortCut(TWMKEY(Msg)) then
        Msg.Result := 1
    else
        Msg.Result := 0;
end;

procedure TsuiMDIForm.SetBorderColor(const Value: TColor);
begin
    m_BorderColor := Value;
    if csDesigning in ComponentState then
        Exit;
    PaintBorder();
end;

procedure TsuiMDIForm.SetCaption(const Value: TCaption);
begin
    m_Form.Caption := Value;
    m_TitleBar.Caption := Value;
end;

procedure TsuiMDIForm.SetFileTheme(const Value: TsuiFileTheme);
begin
    if m_FileTheme = Value then
        Exit;
    m_FileTheme := Value;
    SetUIStyle(m_UIStyle);
end;

procedure TsuiMDIForm.SetMenu(const Value: TMainMenu);
begin
    if m_Menu <> nil then
    begin
        if m_Menu is TsuiMainMenu then
            (m_Menu as TsuiMainMenu).Form := nil;
    end;
    m_Menu := Value;
    UpdateMenu();
end;

procedure TsuiMDIForm.SetMenuBarColor(const Value: TColor);
begin
    m_MenuBarColor := Value;
    
    if (m_MenuBar = nil) then
        Exit;

    m_MenuBar.Color := Value;
end;

procedure TsuiMDIForm.SetUIStyle(const Value: TsuiUIStyle);
var
    OutUIStyle : TsuiUIStyle;
    i : Integer;
    Col : TColor;
begin
    m_UIStyle := Value;

    if UsingFileTheme(m_FileTheme, m_UIStyle, OutUIStyle) then
    begin
        BorderColor := m_FileTheme.GetColor(SUI_THEME_FORM_BORDER_COLOR);
        MenuBarColor := m_FileTheme.GetColor(SUI_THEME_FORM_BACKGROUND_COLOR);
        m_BorderWidth := m_FileTheme.GetInt(SUI_THEME_FORM_BORDERWIDTH_INT);
        Col := m_FileTheme.GetColor(SUI_THEME_CONTROL_FONT_COLOR);
        if Col = 131072 then
            MenuBarColor := $00AC5B3B
        else if Col = 196608 then
            MenuBarColor := $00996733;
        RoundCorner := m_FileTheme.GetInt(SUI_THEME_FORM_ROUNDCORNER_INT);            
    end
    else
    begin
        BorderColor := GetInsideThemeColor(OutUIStyle, SUI_THEME_FORM_BORDER_COLOR);
        MenuBarColor := GetInsideThemeColor(OutUIStyle, SUI_THEME_FORM_BACKGROUND_COLOR);
        m_BorderWidth := GetInsideThemeInt(OutUIStyle, SUI_THEME_FORM_BORDERWIDTH_INT);
        RoundCorner := GetInsideThemeInt(OutUIStyle, SUI_THEME_FORM_ROUNDCORNER_INT);
    end;

    if m_Menu <> nil then
    begin
        if m_Menu is TsuiMainMenu then
        begin
            (m_Menu as TsuiMainMenu).UIStyle := m_UIStyle;
            (m_Menu as TsuiMainMenu).FileTheme := m_FileTheme;
        end;
    end;

    if (m_TitleBar = nil) then
        Exit;

    m_TitleBar.FileTheme := m_FileTheme;
    m_TitleBar.UIStyle := m_UIStyle;

    if not (csDesigning in ComponentState) then
    for i := 1 to 3 do
        m_ControlBtns[i].Color := MenuBarColor;

    m_TitleBar.RoundCorner := 0;
    PaintBorder();
end;

procedure TsuiMDIForm.ShowControlButtons;
var
    i : Integer;
    Form : TsuiForm;
begin
    Form := GetActiveChildSUIForm();
    if Form = nil then
        Exit;

    for i := 0 to Form.TitleBarButtons.Count - 1 do
    begin
        if Form.TitleBarButtons.Items[i].ButtonType = suiMin then
            m_ControlBtns[3].Visible := true;
        if Form.TitleBarButtons.Items[i].ButtonType = suiMax then
            m_ControlBtns[2].Visible := true;
        if Form.TitleBarButtons.Items[i].ButtonType = suiClose then
            m_ControlBtns[1].Visible := true;
    end;
end;

procedure TsuiMDIForm.ShowMenuBar;
begin
    if (m_MenuBar = nil) then
        Exit;
    m_TopPanel.Visible := true;
end;

procedure TsuiMDIForm.Tile;
var
    i : Integer;
    nLeft, nTop, nWidth, nHeight : Integer;
    nCount : Integer;
begin
    nCount := 0;
    for i := m_Form.MDIChildCount - 1 downto 0 do
    begin
        if m_Form.MDIChildren[i].WindowState = wsMinimized then
            continue;
        Inc(nCount);
    end;

    if nCount = 0 then
        Exit;

    nHeight := m_Form.ClientHeight - m_MenuBar.Height - m_TitleBar.Height;
    if nCount < m_Form.MDIChildCount then
        Dec(nHeight, 25);

    if m_Form.TileMode = tbVertical	then
    begin
        nLeft := 0;
        nWidth := m_Form.ClientWidth div nCount;
        for i := m_Form.MDIChildCount - 1 downto 0 do
        begin
            if m_Form.MDIChildren[i].WindowState = wsMinimized then
                continue;
            m_Form.MDIChildren[i].SetBounds(nLeft, 0, nWidth, nHeight);
            Inc(nLeft, nWidth - 6);
        end;
    end
    else
    begin
        nTop := 0;
        nHeight := nHeight div nCount;
        nWidth := m_Form.ClientWidth - 4;
        for i := m_Form.MDIChildCount - 1 downto 0 do
        begin
            if m_Form.MDIChildren[i].WindowState = wsMinimized then
                continue;
            m_Form.MDIChildren[i].SetBounds(0, nTop, nWidth, nHeight - 2);
            Inc(nTop, nHeight - 2);
        end;
    end;
end;

procedure TsuiMDIForm.UpdateMenu();
var
    i : Integer;
    Button : TToolButton;
begin
{$IFDEF SUIPACK_D5}
    if csDesigning in ComponentState then
        Exit;
{$ENDIF}

    m_TopMenu := GetMainMenu();

    if m_TopMenu = nil then
    begin
        HideMenuBar();
        Exit;
    end;

    if m_TitleBar <> nil then
        m_TitleBar.Top := 0;

    m_TopPanel.Constraints.MinHeight:=m_MenuBar.Height;

    if m_TopMenu.Items.Count<m_MenuBar.ButtonCount then
    for i := m_TopMenu.Items.Count to m_MenuBar.ButtonCount - 1 do
       m_MenuBar.Buttons[0].Free();

    if m_TopMenu.Items.Count>m_MenuBar.ButtonCount then
    for i := m_MenuBar.ButtonCount to  m_TopMenu.Items.Count - 1 do
    begin
        Button := TToolButton.Create(self);
        Button.Parent := m_MenuBar;
        Button.Grouped := true;
        Button.AutoSize := true;
    end;

    for i := m_TopMenu.Items.Count - 1 downto 0 do
        m_MenuBar.Buttons[i].MenuItem := m_TopMenu.Items[i];
        
    ShowMenuBar();
    m_TopPanel.Constraints.MinHeight:=m_MenuBar.Height;
    m_TopPanel.Height := m_MenuBar.Height;
end;


function TsuiMDIForm.GetDrawAppIcon: Boolean;
begin
    Result := m_TitleBar.DrawAppIcon;
end;

procedure TsuiMDIForm.SetDrawAppIcon(const Value: Boolean);
begin
    m_TitleBar.DrawAppIcon := Value;
end;

function TsuiMDIForm.GetTitleBarCustom: Boolean;
begin
    Result := m_TitleBar.Custom;
end;

procedure TsuiMDIForm.SetTitleBarCustom(const Value: Boolean);
begin
    m_T

⌨️ 快捷键说明

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