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

📄 suidbctrls.pas

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

procedure TsuiDBMemo.OnHScrollBarChange(Sender: TObject);
begin
    if m_SelfChanging then
        Exit;
    m_UserChanging := true;
    SendMessage(Handle, WM_HSCROLL, MakeWParam(SB_THUMBPOSITION, m_HScrollBar.Position), 0);
    Invalidate;
    m_UserChanging := false;
end;

procedure TsuiDBMemo.OnVScrollBarChange(Sender: TObject);
begin
    if m_SelfChanging then
        Exit;
    m_UserChanging := true;
    SendMessage(Handle, WM_VSCROLL, MakeWParam(SB_THUMBPOSITION, m_VScrollBar.Position), 0);
    Invalidate;
    m_UserChanging := false;
end;

procedure TsuiDBMemo.SetHScrollBar(const Value: TsuiScrollBar);
begin
    if m_HScrollBar = Value then
        Exit;
    if m_HScrollBar <> nil then
    begin
        m_HScrollBar.OnChange := nil;
        m_HScrollBar.LineButton := 0;
        m_HScrollBar.Max := 100;
        m_HScrollBar.Enabled := true;
    end;

    m_HScrollBar := Value;
    if m_HScrollBar = nil then
    begin
        UpdateInnerScrollBars();
        Exit;
    end;
    m_HScrollBar.Orientation := suiHorizontal;
    m_HScrollBar.OnChange := OnHScrollBarChange;
    m_HScrollBar.BringToFront();
    UpdateInnerScrollBars();

    UpdateScrollBarsPos();
end;

procedure TsuiDBMemo.SetVScrollBar(const Value: TsuiScrollBar);
begin
    if m_VScrollBar = Value then
        Exit;
    if m_VScrollBar <> nil then
    begin
        m_VScrollBar.OnChange := nil;
        m_VScrollBar.LineButton := 0;
        m_VScrollBar.Max := 100;
        m_VScrollBar.Enabled := true;
    end;

    m_VScrollBar := Value;
    if m_VScrollBar = nil then
    begin
        UpdateInnerScrollBars();
        Exit;
    end;
    m_VScrollBar.Orientation := suiVertical;
    m_VScrollBar.OnChange := OnVScrollBArChange;
    m_VScrollBar.BringToFront();
    UpdateInnerScrollBars();

    UpdateScrollBarsPos();
end;

procedure TsuiDBMemo.UpdateInnerScrollBars;
begin
    if (m_VScrollBar <> nil) and (m_HScrollBar <> nil) then
        ScrollBars := ssBoth
    else if (m_VScrollBar <> nil) and (m_HScrollBar = nil) then
        ScrollBars := ssVertical
    else if (m_HScrollBar <> nil) and (m_VScrollBar = nil) then
        ScrollBars := ssHorizontal
    else
        ScrollBars := ssNone;
end;

procedure TsuiDBMemo.UpdateScrollBars;
var
    info : tagScrollInfo;
    barinfo : tagScrollBarInfo;
begin
    if m_UserChanging then
        Exit;
    m_SelfChanging := true;
    if m_HScrollBar <> nil then
    begin
        barinfo.cbSize := SizeOf(barinfo);
        if not SUIGetScrollBarInfo(Handle, Integer(OBJID_HSCROLL), barinfo) then
        begin
            m_HScrollBar.Visible := false;
        end
        else if (barinfo.rgstate[0] = STATE_SYSTEM_INVISIBLE) or
           (barinfo.rgstate[0] = STATE_SYSTEM_UNAVAILABLE) or
           (not Enabled) then
        begin
            m_HScrollBar.LineButton := 0;
            m_HScrollBar.Enabled := false;
            m_HScrollBar.SliderVisible := false;
        end
        else
        begin
            m_HScrollBar.LineButton := abs(barinfo.xyThumbBottom - barinfo.xyThumbTop);
            m_HScrollBar.SmallChange := 3 * m_HScrollBar.PageSize;
            m_HScrollBar.Enabled := true;
            m_HScrollBar.SliderVisible := true;
        end;
        info.cbSize := SizeOf(info);
        info.fMask := SIF_ALL;
        GetScrollInfo(Handle, SB_HORZ, info);
        m_HScrollBar.Max := info.nMax - Integer(info.nPage) + 1;
        m_HScrollBar.Min := info.nMin;
        m_HScrollBar.Position := info.nPos;
    end;

    if m_VScrollBar <> nil then
    begin
        barinfo.cbSize := SizeOf(barinfo);
        if not SUIGetScrollBarInfo(Handle, Integer(OBJID_VSCROLL), barinfo) then
        begin
            m_VScrollBar.Visible := false;
        end
        else if (barinfo.rgstate[0] = STATE_SYSTEM_INVISIBLE) or
           (barinfo.rgstate[0] = STATE_SYSTEM_UNAVAILABLE) or
           (not Enabled) then
        begin
            m_VScrollBar.LineButton := 0;
            m_VScrollBar.Enabled := false;
            m_VScrollBar.SliderVisible := false;
        end
        else
        begin
            m_VScrollBar.LineButton := abs(barinfo.xyThumbBottom - barinfo.xyThumbTop);
            m_VScrollBar.Enabled := true;
            m_VScrollBar.SliderVisible := true;
        end;
        info.cbSize := SizeOf(info);
        info.fMask := SIF_ALL;
        GetScrollInfo(Handle, SB_VERT, info);
        m_VScrollBar.Max := info.nMax - Integer(info.nPage) + 1;
        m_VScrollBar.Min := info.nMin;
        m_VScrollBar.Position := info.nPos;
    end;
    m_SelfChanging := false;
end;

procedure TsuiDBMemo.UpdateScrollBarsPos;
var
    L2R : Boolean;
begin
    L2R := ((BidiMode = bdLeftToRight) or (BidiMode = bdRightToLeftReadingOnly)) or (not SysLocale.MiddleEast);

    if m_HScrollBar <> nil then
    begin
        if L2R then
        begin
            m_HScrollBar.Left := Left + 1;
            m_HScrollBar.Top := Top + Height - m_HScrollBar.Height - 2;
            if m_VScrollBar <> nil then
                m_HScrollBar.Width := Width - 2 - m_VScrollBar.Width
            else
                m_HScrollBar.Width := Width - 2
        end
        else
        begin
            m_HScrollBar.Top := Top + Height - m_HScrollBar.Height - 2;
            if m_VScrollBar <> nil then
            begin
                m_HScrollBar.Left := Left + m_VScrollBar.Width + 1;
                m_HScrollBar.Width := Width - 2 - m_VScrollBar.Width
            end
            else
            begin
                m_HScrollBar.Left := Left + 1;
                m_HScrollBar.Width := Width - 2;
            end;
        end;
    end;

    if m_VScrollBar <> nil then
    begin
        if L2R then
        begin
            m_VScrollBar.Left := Left + Width - m_VScrollBar.Width - 2;
            m_VScrollBar.Top := Top + 1;
            if m_HScrollBar <> nil then
                m_VScrollBar.Height := Height - 2 - m_HScrollBar.Height
            else
                m_VScrollBar.Height := Height - 2;
        end
        else
        begin
            m_VScrollBar.Left := Left + 2;
            m_VScrollBar.Top := Top + 1;
            if m_HScrollBar <> nil then
                m_VScrollBar.Height := Height - 2 - m_HScrollBar.Height
            else
                m_VScrollBar.Height := Height - 2;
        end;
    end;

    UpdateScrollBars();    
end;

procedure TsuiDBMemo.WMClear(var Message: TMessage);
begin
    inherited;
    UpdateScrollBars();
end;

procedure TsuiDBMemo.WMKeyDown(var Message: TWMKeyDown);
begin
    inherited;
    UpdateScrollBars();
end;

procedure TsuiDBMemo.WMLBUTTONDOWN(var Message: TMessage);
begin
    inherited;
    m_MouseDown := true;
    UpdateScrollBars();
end;

procedure TsuiDBMemo.WMMOUSEWHEEL(var Message: TMessage);
begin
    inherited;
    UpdateScrollBars();
end;

procedure TsuiDBMemo.WMMOVE(var Msg: TMessage);
begin
    inherited;
    UpdateScrollBarsPos();
end;

procedure TsuiDBMemo.WMSetText(var Message: TWMSetText);
begin
    inherited;
    UpdateScrollBars();
end;

procedure TsuiDBMemo.WMSIZE(var Msg: TMessage);
begin
    inherited;
    UpdateScrollBarsPos();
end;

procedure TsuiDBMemo.WMHSCROLL(var Message: TWMHScroll);
begin
    inherited;
    if m_UserChanging then
        Exit;

    UpdateScrollBars();
end;

procedure TsuiDBMemo.WMLButtonUp(var Message: TMessage);
begin
    inherited;
    m_MouseDown := false;
end;

procedure TsuiDBMemo.WMMOUSEMOVE(var Message: TMessage);
begin
    inherited;
    if m_MouseDown then UpdateScrollBars();
end;

procedure TsuiDBMemo.WMVSCROLL(var Message: TWMVScroll);
begin
    inherited;
    if m_UserChanging then
        Exit;

    UpdateScrollBars();
end;

procedure TsuiDBMemo.SetFileTheme(const Value: TsuiFileTheme);
begin
    m_FileTheme := Value;
    if m_VScrollBar <> nil then
        m_VScrollBar.FileTheme := Value;
    if m_HScrollBar <> nil then
        m_HScrollBar.FileTheme := Value;
    SetUIStyle(m_UIStyle);
end;

procedure TsuiDBMemo.SetUIStyle(const Value: TsuiUIStyle);
var
    OutUIStyle : TsuiUIStyle;
begin
    m_UIStyle := Value;

    if UsingFileTheme(m_FileTheme, m_UIStyle, OutUIStyle) then
        m_BorderColor := m_FileTheme.GetColor(SKIN2_CONTROLBORDERCOLOR)
    else
        m_BorderColor := GetInsideThemeColor(OutUIStyle, SUI_THEME_CONTROL_BORDER_COLOR);

    if m_VScrollBar <> nil then
        m_VScrollBar.UIStyle := OutUIStyle;
    if m_HScrollBar <> nil then
        m_HScrollBar.UIStyle := OutUIStyle;    
    Repaint();
end;

procedure TsuiDBMemo.CMVisibleChanged(var Msg: TMessage);
begin
    inherited;

    if not Visible then
    begin
        if m_VScrollBar <> nil then
            m_VScrollBar.Visible := Visible;
        if m_HScrollBar <> nil then
            m_HScrollBar.Visible := Visible;
    end
    else
        UpdateScrollBarsPos();
end;

{ TsuiDBImage }

constructor TsuiDBImage.Create(AOwner: TComponent);
begin
    inherited Create(AOwner);
    BorderWidth := 2;

    UIStyle := GetSUIFormStyle(AOwner);
end;

procedure TsuiDBImage.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;

procedure TsuiDBImage.SetBorderColor(const Value: TColor);
begin
    m_BorderColor := Value;
    Repaint();
end;

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

procedure TsuiDBImage.SetUIStyle(const Value: TsuiUIStyle);
var
    OutUIStyle : TsuiUIStyle;
begin
    m_UIStyle := Value;
    if UsingFileTheme(m_FileTheme, m_UIStyle, OutUIStyle) then
        m_BorderColor := m_FileTheme.GetColor(SKIN2_CONTROLBORDERCOLOR)
    else
        m_BorderColor := GetInsideThemeColor(OutUIStyle, SUI_THEME_CONTROL_BORDER_COLOR);
    Repaint();
end;

procedure TsuiDBImage.WMEARSEBKGND(var Msg: TMessage);
begin
    inherited;

    DrawControlBorder(self, m_BorderColor, Color);
end;

procedure TsuiDBImage.WMPAINT(var Msg: TMessage);
begin
    inherited;

    DrawControlBorder(self, m_BorderColor, Color);
end;

{ TsuiDBListBox }

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

    ControlStyle := ControlStyle + [csOpaque];
    BorderStyle := bsNone;
    BorderWidth := 2;
    m_SelfChanging := false;
    m_MouseDown := false;

    UIStyle := GetSUIFormStyle(AOwner);
end;

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

    if AComponent = nil then
        Exit;

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

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

⌨️ 快捷键说明

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