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

📄 suigrid.pas

📁 SUIPack是一款为Delphi和C++Builder开发的所见即所得的界面增强VCL组件
💻 PAS
📖 第 1 页 / 共 3 页
字号:
        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 TsuiCustomDrawGrid.SetSelectedColor(const Value: TColor);
begin
    m_SelectedColor := Value;
    Repaint();
end;

procedure TsuiCustomDrawGrid.SetUIStyle(const Value: TsuiUIStyle);
var
    OutUIStyle : TsuiUIStyle;
begin
    m_UIStyle := Value;
    if UsingFileTheme(m_FileTheme, m_UIStyle, OutUIStyle) then
    begin
        BorderColor := m_FileTheme.GetColor(SKIN2_CONTROLBORDERCOLOR);
        FixedColor := m_FileTheme.GetColor(SKIN2_SELECTEDMENUCOLOR);
        Color := m_FileTheme.GetColor(SKIN2_CONTROLCOLOR);
        FixedFontColor := m_FileTheme.GetColor(SKIN2_MENUITEMFONTCOLOR);
        Font.Color := m_FileTheme.GetColor(SKIN2_CONTROLFONTCOLOR);
    end
    else
    begin
        BorderColor := GetInsideThemeColor(OutUIStyle, SUI_THEME_CONTROL_BORDER_COLOR);
        FixedColor := GetInsideThemeColor(OutUIStyle, SUI_THEME_MENU_SELECTED_BACKGROUND_COLOR);
        Color := GetInsideThemeColor(OutUIStyle, SUI_THEME_CONTROL_BACKGROUND_COLOR);
        FixedFontColor := GetInsideThemeColor(OutUIStyle, SUI_THEME_MENU_SELECTED_FONT_COLOR);
        Font.Color := GetInsideThemeColor(OutUIStyle, SUI_THEME_MENU_FONT_COLOR);
	if (Font.Color = clWhite) then
	    Font.Color := clBlack;
    end;

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

procedure TsuiCustomDrawGrid.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 TsuiCustomDrawGrid.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 TsuiCustomDrawGrid.UpdateScrollBars;
var
    info : tagScrollInfo;
    barinfo : tagScrollBarInfo;
    L2R : Boolean;
begin
    if m_UserChanging then
        Exit;
    L2R := ((BidiMode = bdLeftToRight) or (BidiMode = bdRightToLeftReadingOnly)) or (not SysLocale.MiddleEast);
    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.Visible := 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.Visible := 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;
        if L2R then
            m_HScrollBar.Position := info.nPos
        else
            m_HScrollBar.Position := m_HScrollBar.Max - 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.Visible := false;
            m_VScrollBar.SliderVisible := false;
        end
        else
        begin
            m_VScrollBar.LineButton := abs(barinfo.xyThumbBottom - barinfo.xyThumbTop);
            m_VScrollBar.Visible := 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 TsuiCustomDrawGrid.UpdateScrollBarsPos;
var
    L2R : Boolean;
begin
    UpdateScrollBars();
    L2R := ((BidiMode = bdLeftToRight) or (BidiMode = bdRightToLeftReadingOnly)) or (not SysLocale.MiddleEast);
    if m_HScrollBar <> nil then
    begin
        if Height < m_HScrollBar.Height then
            m_HScrollBar.Visible := false
        else
            m_HScrollBar.Visible := true;
        if L2R then
        begin
            m_HScrollBar.Left := Left + 1;
            m_HScrollBar.Top := Top + Height - m_HScrollBar.Height - 1;
            if (m_VScrollBar <> nil) and m_VScrollBar.Visible then
                m_HScrollBar.Width := Width - 1 - m_VScrollBar.Width
            else
                m_HScrollBar.Width := Width - 2
        end
        else
        begin
            m_HScrollBar.Top := Top + Height - m_HScrollBar.Height - 1;
            if (m_VScrollBar <> nil) and m_VScrollBar.Visible then
            begin
                m_HScrollBar.Left := Left + m_VScrollBar.Width + 1;
                m_HScrollBar.Width := Width - 1 - m_VScrollBar.Width
            end
            else
            begin
                m_HScrollBar.Left := Left + 1;
                m_HScrollBar.Width := Width - 1;
            end;
        end;
    end;

    if m_VScrollBar <> nil then
    begin
        if Width < m_VScrollBar.Width then
            m_VScrollBar.Visible := false
        else
            m_VScrollBar.Visible := true;
        if L2R then
        begin
            m_VScrollBar.Left := Left + Width - m_VScrollBar.Width - 1;
            m_VScrollBar.Top := Top + 1;
            if (m_HScrollBar <> nil) and m_HScrollBar.Visible then
                m_VScrollBar.Height := Height - 1 - m_HScrollBar.Height
            else
                m_VScrollBar.Height := Height - 1;
        end
        else
        begin
            m_VScrollBar.Left := Left + 1;
            m_VScrollBar.Top := Top + 1;
            if (m_HScrollBar <> nil) and m_HScrollBar.Visible then
                m_VScrollBar.Height := Height - 1 - m_HScrollBar.Height
            else
                m_VScrollBar.Height := Height - 1;
        end;
    end;

    UpdateScrollBars();    
end;

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

procedure TsuiCustomDrawGrid.WMCut(var Message: TMessage);
begin
    inherited;
    UpdateScrollBars();
end;

procedure TsuiCustomDrawGrid.WMEARSEBKGND(var Msg: TMessage);
begin
    Paint();
end;

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

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

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

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

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

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

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

procedure TsuiCustomDrawGrid.WMPaste(var Message: TMessage);
begin
    inherited;
    UpdateScrollBars();
end;

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

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

procedure TsuiCustomDrawGrid.WMUndo(var Message: TMessage);
begin
    inherited;
    UpdateScrollBars();
end;

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

{ TsuiStringGrid }

procedure TsuiStringGrid.CMBIDIMODECHANGED(var Msg: TMessage);
var
    L2R : Boolean;
    info : tagScrollInfo;    
begin
    inherited;
    
    L2R := ((BidiMode = bdLeftToRight) or (BidiMode = bdRightToLeftReadingOnly)) or (not SysLocale.MiddleEast);
    if (not L2R) and (m_HScrollBar <> nil) then
    begin
        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 := m_HScrollBar.Max - info.nPos
    end;
end;

procedure TsuiStringGrid.CMEnabledChanged(var Msg: TMessage);
begin
    inherited;
    UpdateScrollBars();
end;

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

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

    ControlStyle := ControlStyle + [csOpaque];
    BorderStyle := bsNone;
    BorderWidth := 1;
    UIStyle := GetSUIFormStyle(AOwner);
    FocusedColor := clLime;
    SelectedColor := clYellow;
    ParentCtl3D := false;
    m_MouseDown := false;
    inherited Ctl3D := false;
end;

procedure TsuiStringGrid.DrawCell(ACol, ARow: Integer; ARect: TRect;
  AState: TGridDrawState);
var
    R : TRect;
begin
    if not DefaultDrawing then
    begin
        inherited;
        exit;
    end;

    R := ARect;

    try
        if gdFixed in AState then
            Exit;

        if gdSelected in AState then
        begin
            Canvas.Brush.Color := m_SelectedColor;
        end;

        if gdFocused in AState then
        begin
            Canvas.Brush.Color := m_FocusedColor;
        end;

        if AState = [] then
            Canvas.Brush.Color := Color;

        Canvas.FillRect(R);

    finally

        if gdFixed in AState then
        begin
            Canvas.Font.Color := m_FixedFontColor;
            Canvas.TextRect(ARect, ARect.Left + 2, ARect.Top + 2, Cells[ACol, ARow]);
        end;

        inherited;
    end;
end;

function TsuiStringGrid.GetBGColor: TColor;
begin
    Result := Color;
end;

function TsuiStringGrid.GetCtl3D: Boolean;
begin
    Result := false;
end;

function TsuiStringGrid.GetFixedBGColor: TColor;
begin
    Result := FixedColor;

⌨️ 快捷键说明

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