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

📄 suitabcontrol.pas

📁 SUIPack是一款为Delphi和C++Builder开发的所见即所得的界面增强VCL组件
💻 PAS
📖 第 1 页 / 共 3 页
字号:

    if (
        (Value < -1) or
        (Value > m_Tabs.Count -1)
    ) then
    begin
        Repaint();
        Exit;
    end;

    if m_UserChanging then
    begin
        bAllow := true;
        if Assigned(m_TabControl.m_OnChanging) then
            m_TabControl.m_OnChanging(m_TabControl, bAllow);
        if not bAllow then
            Exit;
    end;
    m_TabIndex := Value;
    m_AutoFit := true;
    Repaint();
    m_AutoFit := false;
    m_TabControl.TabActive(m_TabIndex);
    Repaint();
end;

procedure TsuiTabControlTopPanel.SetTabPosition(const Value: TsuiTabPosition);
begin
    if m_TabPosition = Value then
        Exit;
    m_TabPosition := Value;
    RoundPicture2(m_ActiveTab);
    RoundPicture2(m_InactiveTab);
    RoundPicture2(m_Line);
    Repaint();
end;

procedure TsuiTabControlTopPanel.SetTabs(const Value: TStrings);
begin
    m_Tabs.Assign(Value);
end;

procedure TsuiTabControlTopPanel.SetUIStyle(const Value: TsuiUIStyle);
var
    BtnBitmap : TBitmap;
    OutUIStyle : TsuiUIStyle;
begin
    m_UIStyle := Value;

    BtnBitmap := TBitmap.Create();

    if UsingFileTheme(m_FileTheme, m_UIStyle, OutUIStyle) then
    begin
        m_FileTheme.GetBitmap2(SKIN2_TABCONTROL, m_ActiveTab, 2, 1);
        m_FileTheme.GetBitmap2(SKIN2_TABCONTROL, m_InactiveTab, 2, 2);
        m_Line.Assign(m_FileTheme.GetBitmap(SKIN2_TABCONTROLLINE));
        if m_FileTheme.GetBitmap(SKIN2_SCROLLBUTTON) = nil then
            GetInsideThemeBitmap(SUI_THEME_DEFAULT, SUI_THEME_SCROLLBUTTON_IMAGE, BtnBitmap, 4, 1)
        else
            m_FileTheme.GetBitmap2(SKIN2_SCROLLBUTTON, BtnBitmap, 4, 1);
        m_ActiveTabFontColor := m_FileTheme.GetColor(SKIN2_TABCONTROLACTIVEFONTCOLOR);
        m_InactiveTabFontColor := m_FileTheme.GetColor(SKIN2_TABCONTROLINACTIVEFONTCOLOR);
    end
    else
    begin
        GetInsideThemeBitmap(OutUIStyle, SUI_THEME_TABCONTROL_TAB_IMAGE, m_ActiveTab, 2, 1);
        GetInsideThemeBitmap(OutUIStyle, SUI_THEME_TABCONTROL_TAB_IMAGE, m_InactiveTab, 2, 2);
        GetInsideThemeBitmap(OutUIStyle, SUI_THEME_TABCONTROL_BAR_IMAGE, m_Line);
        GetInsideThemeBitmap(OutUIStyle, SUI_THEME_SCROLLBUTTON_IMAGE, BtnBitmap, 4, 1);
        m_ActiveTabFontColor := clBlack;
        m_InactiveTabFontColor := clBlack;
    end;

    if m_TabPosition = suiBottom then
    begin
        RoundPicture2(m_ActiveTab);
        RoundPicture2(m_InactiveTab);
        RoundPicture2(m_Line);
    end;

    Height := m_ActiveTab.Height + m_Line.Height;
    m_BtnSize.X := BtnBitmap.Width;
    m_BtnSize.Y := BtnBitmap.Height;

    BtnBitmap.Free();
    Repaint();
end;

procedure TsuiTabControlTopPanel.WMERASEBKGND(var Msg: TMessage);
begin
    // do nothing
end;

function TsuiTab.GetLeftMargin: Integer;
begin
    Result := m_TopPanel.LeftMargin;
end;

function TsuiTab.GetTabIndex: Integer;
begin
    Result := m_TopPanel.TabIndex;
end;

function TsuiTab.GetTabs: TStrings;
begin
    Result := m_TopPanel.Tabs;
end;

procedure TsuiTab.Paint;
var
    R : TRect;
begin
    Canvas.Brush.Color := Color;
    if m_TabPosition = suiTop then
        R := Rect(ClientRect.Left, m_TopPanel.Height, ClientRect.Right, ClientRect.Bottom)
    else
        R := Rect(ClientRect.Left, 0, ClientRect.Right, ClientRect.Bottom - m_TopPanel.Height);
    Canvas.FillRect(R);
    Canvas.Pen.Color := m_BorderColor;
    if m_TabPosition = suiTop then
    begin
        Canvas.MoveTo(0, R.Top - 1);
        Canvas.LineTo(0, R.Bottom - 1);
        Canvas.LineTo(R.Right - 1, R.Bottom - 1);
        Canvas.LineTo(R.Right - 1, R.Top - 1);
    end
    else
    begin
        Canvas.MoveTo(R.Right - 1, R.Bottom - 1);
        Canvas.LineTo(R.Right - 1, R.Top);
        Canvas.LineTo(0, R.Top);
        Canvas.LineTo(0, R.Bottom);
    end;
end;

procedure TsuiTab.SetBorderColor(const Value: TColor);
begin
    m_BorderColor := Value;

    BorderColorChanged();
    Repaint();
    m_TopPanel.Repaint();
end;

procedure TsuiTab.SetFont(const Value: TFont);
begin
    m_Font.Assign(Value);
    m_TopPanel.Repaint();
end;

procedure TsuiTab.SetLeftMargin(const Value: Integer);
begin
    m_TopPanel.LeftMargin := Value;
end;

procedure TsuiTab.SetTabIndex(const Value: Integer);
begin
    m_TopPanel.TabIndex := Value;
end;

procedure TsuiTab.SetTabs(const Value: TStrings);
begin
    m_TopPanel.Tabs := Value;
end;

procedure TsuiTab.SetUIStyle(const Value: TsuiUIStyle);
var
    OutUIStyle : TsuiUIStyle;
begin
    m_UIStyle := Value;
    m_TopPanel.FileTheme := m_FileTheme;
    m_TopPanel.UIStyle := m_UIStyle;
    m_TopPanel.Repaint();

    UpdateUIStyle(m_UIStyle, m_FileTheme);
    
    if UsingFileTheme(m_FileTheme, m_UIStyle, OutUIStyle) then
    begin
        m_TopPanel.Color := m_FileTheme.GetColor(SKIN2_FORMCOLOR);
        m_BorderColor := m_FileTheme.GetColor(SKIN2_CONTROLBORDERCOLOR);
        Color := m_FileTheme.GetColor(SKIN2_FORMCOLOR);
    end
    else
    begin
        m_TopPanel.Color := GetInsideThemeColor(OutUIStyle, SUI_THEME_CONTROL_BACKGROUND_COLOR);
        m_BorderColor := GetInsideThemeColor(OutUIStyle, SUI_THEME_CONTROL_BORDER_COLOR);
        if {$IFDEF RES_WINXP}m_UIStyle <> WinXP{$ELSE} True {$ENDIF} then
            Color := GetInsideThemeColor(OutUIStyle, SUI_THEME_CONTROL_BACKGROUND_COLOR)
        else
            Color := clWhite;
    end;

    Repaint();
end;

procedure TsuiTab.UpdateUIStyle(UIStyle: TsuiUIStyle; FileTheme : TsuiFileTheme);
begin
    ContainerApplyUIStyle(self, UIStyle, FileTheme);
end;

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

    m_TopPanel := CreateTopPanel();
    m_TopPanel.Parent := self;
    m_TopPanel.OnClick := TopPanelClick;
    m_TopPanel.OnDblClick := TopPanelDblClick;
    m_TabPosition := suiTop;

    m_Font := TFont.Create();
    m_PageDrawFocused := true;

    Caption := ' ';
    BevelInner := bvNone;
    BevelOuter := bvNone;
    BorderWidth := 0;
    Height := 80;

    UIStyle := GetSUIFormStyle(AOwner);
    m_TopPanel.SetBounds(0, 0, Width, m_TopPanel.Height);    
end;

destructor TsuiTab.Destroy;
begin
    m_Font.Free();
    m_Font := nil;

    m_TopPanel.Free();
    m_TopPanel := nil;

    inherited;
end;

procedure TsuiTabControlTopPanel.WMKillFocus(var Msg: TWMKillFocus);
begin
    inherited;

    Repaint();
end;

procedure TsuiTabControlTopPanel.WMSetFocus(var Msg: TWMSetFocus);
begin
    inherited;

    Repaint();
end;

{ TsuiTabControl }

function TsuiTabControl.CreateTopPanel: TsuiTabControlTopPanel;
begin
    Result := TsuiTabControlTopPanel.Create(self, self);
end;

procedure TsuiTab.TabActive(TabIndex : Integer);
begin
    if not (csLoading in ComponentState) then
    begin
        if Assigned(m_OnTabActive) then
            m_OnTabActive(self, TabIndex);
        if Assigned(m_OnChange) then
            m_OnChange(self);
    end;
end;

procedure TsuiTab.BorderColorChanged;
begin
    // do nothing
end;

procedure TsuiTab.CMCursorChanged(var Message: TMessage);
begin
    m_TopPanel.Cursor := Cursor;
    inherited;
end;

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

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

    if (
        (Operation = opRemove) and
        (AComponent = m_ImageList)
    )then
    begin
        m_ImageList := nil;
        m_TopPanel.Repaint();
    end;
end;

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

procedure TsuiTab.AlignControls(AControl: TControl; var Rect: TRect);
begin
    if m_TabPosition = suiTop then
    begin
        Rect.Left := Rect.Left + 3;
        Rect.Right := Rect.Right - 3;
        Rect.Bottom := Rect.Bottom - 3;
        Rect.Top := Rect.Top + m_TopPanel.Height + 3;
    end
    else
    begin
        Rect.Left := Rect.Left + 3;
        Rect.Right := Rect.Right - 3;
        Rect.Top := Rect.Top + 3;
        Rect.Bottom := Rect.Bottom - m_TopPanel.Height - 3;
    end;
    inherited AlignControls(AControl, Rect);
end;

procedure TsuiTab.Resize;
begin
    inherited;

    if m_TabPosition = suiTop then
        m_TopPanel.SetBounds(0, 0, Width, m_TopPanel.Height)
    else
    begin
        m_TopPanel.Top := Height - m_TopPanel.Height;
        m_TopPanel.Left := 0;
        m_TopPanel.Width := Width;
    end;
end;

procedure TsuiTab.WMERASEBKGND(var Message: TMessage);
begin
    // do nothing
end;

procedure TsuiTab.TopPanelClick(Sender: TObject);
begin
    if Assigned(OnClick) then
        OnClick(self);
end;

procedure TsuiTab.TopPanelDblClick(Sender: TObject);
begin
    if Assigned(OnDblClick) then
        OnDblClick(self);
end;

procedure TsuiTab.SetTabPosition(const Value: TsuiTabPosition);
begin
    if m_TabPosition = Value then
        Exit;
    m_TabPosition := Value;
    m_TopPanel.TabPosition := Value;
    m_TopPanel.RequestAlign();
    Realign();
end;

procedure TsuiTab.SetImageList(const Value: TCustomImageList);
begin
    m_ImageList := Value;
    m_TopPanel.Repaint();
end;

function TsuiTabControl.GetImageIndex(PageId: Integer): Integer;
begin
    result := PageId;
end;

procedure TsuiTab.SetPageDrawFocused(const Value: Boolean);
begin
    m_PageDrawFocused := Value;
    m_TopPanel.Repaint();
end;

end.

⌨️ 快捷键说明

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