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

📄 suicombobox.pas

📁 suipack ver5控件 suipack ver5控件 suipack ver5控件 suipack ver5控件 suipack ver5控件
💻 PAS
📖 第 1 页 / 共 2 页
字号:
procedure TsuiDriveComboBox.CBNCloseUp(var Msg: TWMCommand);
begin
    if Msg.NotifyCode = CBN_CLOSEUP then
        CloseUp()
    else
        inherited;
end;
{$ENDIF}

procedure TsuiDriveComboBox.CloseUp;
begin
    if Parent <> nil then
        Parent.Repaint();
end;


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

    ControlStyle := ControlStyle + [csOpaque];
    BorderWidth := 0;
    ItemHeight := 15;

    UIStyle := GetSUIFormStyle(AOwner);
end;

procedure TsuiDriveComboBox.DrawArrow(const ACanvas: TCanvas; X,
  Y: Integer);
begin
    if not Enabled then
    begin
        ACanvas.Brush.Color := clWhite;
        ACanvas.Pen.Color := clWhite;
        ACanvas.Polygon([Point(X + 1, Y + 1), Point(X + 7, Y + 1), Point(X + 4, Y + 4)]);
        ACanvas.Brush.Color := clGray;
        ACanvas.Pen.Color := clGray;
    end
    else
    begin
        ACanvas.Brush.Color := m_ArrowColor;
        ACanvas.Pen.Color := m_ArrowColor;
    end;

    ACanvas.Polygon([Point(X, Y), Point(X + 6, Y), Point(X + 3, Y + 3)]);
end;

procedure TsuiDriveComboBox.DrawButton;
var
    R, ListRect : TRect;
    X, Y : Integer;
    Btn : graphics.TBitmap;
    pcbi : tagCOMBOBOXINFO;
    C: TControlCanvas;
    DesktopCanvas : TCanvas;
begin
    pcbi.cbSize := SizeOf(pcbi);
    if not SUIGetComboBoxInfo(Handle, pcbi) then
        Exit;

    // draw border
    C := TControlCanvas.Create;

    C.Control := Self;
    with C do
    begin
        C.Brush.Color := m_BorderColor;
        R := ClientRect;
        FrameRect(R);
        C.Brush.Color := Color;
        InflateRect(R, -1, -1);
        FrameRect(R);
        GetWindowRect(pcbi.hwndList, ListRect);
        if DroppedDown then
        begin
            DesktopCanvas := TCanvas.Create();
            DesktopCanvas.Handle := GetWindowDC(0);
            DesktopCanvas.Brush.Color := m_BorderColor;
            DesktopCanvas.FrameRect(ListRect);
            ReleaseDC(0, DesktopCanvas.Handle);
            DesktopCanvas.Free();
        end
    end;

    // Draw button
    R := pcbi.rcButton;
    if {$IFDEF RES_MACOS} (m_UIStyle = MacOS) {$ELSE} false {$ENDIF} or
        {$IFDEF RES_WINXP} (m_UIStyle = WinXP) {$ELSE} false {$ENDIF} then
    begin
        Btn := graphics.TBitmap.Create();
{$IFDEF RES_MACOS}
        if m_UIStyle = MacOS then
            Btn.LoadFromResourceName(hInstance, 'MACOS_COMBOBOX_BUTTON')
        else
{$ENDIF}        
            Btn.LoadFromResourceName(hInstance, 'WINXP_COMBOBOX_BUTTON');
        C.StretchDraw(R, Btn);
        Btn.Free();
    end
    else
    begin
        C.Brush.Color := m_ButtonColor;
        C.FillRect(R);
        C.Pen.Color := m_BorderColor;
        if (BidiMode = bdRightToLeft) and SysLocale.MiddleEast then
        begin
            C.MoveTo(R.Right, R.Top - 1);
            C.LineTo(R.Right, R.Bottom + 1);
        end
        else
        begin
            C.MoveTo(R.Left, R.Top - 1);
            C.LineTo(R.Left, R.Bottom + 1);
        end;
    end;

    X := (R.Right - R.Left) div 2 + R.Left - 3;
    Y := (R.Bottom - R.Top) div 2;
    if {$IFDEF RES_WINXP} m_UIStyle <> WinXP {$ELSE} True {$ENDIF} then
        DrawArrow(C, X, Y);

    C.Free;
end;

function TsuiDriveComboBox.GetDroppedDown: Boolean;
begin
    Result := LongBool(SendMessage(Handle, CB_GETDROPPEDSTATE, 0, 0));
end;

procedure TsuiDriveComboBox.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 TsuiDriveComboBox.SetArrowColor(const Value: TColor);
begin
    m_ArrowColor := Value;
    Repaint();
end;

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

procedure TsuiDriveComboBox.SetButtonColor(const Value: TColor);
begin
    m_ButtonColor := Value;
    Repaint();
end;

procedure TsuiDriveComboBox.SetDroppedDown(const Value: Boolean);
var
    R: TRect;
begin
    SendMessage(Handle, CB_SHOWDROPDOWN, Longint(Value), 0);
    R := ClientRect;
    InvalidateRect(Handle, @R, True);
end;

procedure TsuiDriveComboBox.SetEnabled(Value: Boolean);
begin
    inherited;
    Repaint();
end;

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

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

    m_ArrowColor := clBlack;
    if UsingFileTheme(m_FileTheme, m_UIStyle, OutUIStyle) then
    begin
        m_BorderColor := m_FileTheme.GetColor(SUI_THEME_CONTROL_BORDER_COLOR);
        m_ButtonColor := m_FileTheme.GetColor(SUI_THEME_FORM_BACKGROUND_COLOR);
    end
    else
    begin
        m_BorderColor := GetInsideThemeColor(OutUIStyle, SUI_THEME_CONTROL_BORDER_COLOR);
        m_ButtonColor := GetInsideThemeColor(OutUIStyle, SUI_THEME_FORM_BACKGROUND_COLOR);
    end;

    Repaint();
end;

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

    DrawButton();
end;

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

    DrawButton();
end;

{ TsuiFilterComboBox }

{$IFDEF SUIPACK_D5}
procedure TsuiFilterComboBox.CBNCloseUp(var Msg: TWMCommand);
begin
    if Msg.NotifyCode = CBN_CLOSEUP then
        CloseUp()
    else
        inherited;
end;
{$ENDIF}

procedure TsuiFilterComboBox.CloseUp;
begin
    if Parent <> nil then
        Parent.Repaint();
end;


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

    ControlStyle := ControlStyle + [csOpaque];
    BorderWidth := 0;
    ItemHeight := 15;

    UIStyle := GetSUIFormStyle(AOwner);
end;

procedure TsuiFilterComboBox.DrawArrow(const ACanvas: TCanvas; X,
  Y: Integer);
begin
    if not Enabled then
    begin
        ACanvas.Brush.Color := clWhite;
        ACanvas.Pen.Color := clWhite;
        ACanvas.Polygon([Point(X + 1, Y + 1), Point(X + 7, Y + 1), Point(X + 4, Y + 4)]);
        ACanvas.Brush.Color := clGray;
        ACanvas.Pen.Color := clGray;
    end
    else
    begin
        ACanvas.Brush.Color := m_ArrowColor;
        ACanvas.Pen.Color := m_ArrowColor;
    end;

    ACanvas.Polygon([Point(X, Y), Point(X + 6, Y), Point(X + 3, Y + 3)]);
end;

procedure TsuiFilterComboBox.DrawButton;
var
    R, ListRect : TRect;
    X, Y : Integer;
    Btn : graphics.TBitmap;
    pcbi : tagCOMBOBOXINFO;
    C: TControlCanvas;
    DesktopCanvas : TCanvas;
begin
    pcbi.cbSize := SizeOf(pcbi);
    if not SUIGetComboBoxInfo(Handle, pcbi) then
        Exit;

    // draw border
    C := TControlCanvas.Create;

    C.Control := Self;
    with C do
    begin
        C.Brush.Color := m_BorderColor;
        R := ClientRect;
        FrameRect(R);
        C.Brush.Color := Color;
        InflateRect(R, -1, -1);
        FrameRect(R);
        GetWindowRect(pcbi.hwndList, ListRect);
        if DroppedDown then
        begin
            DesktopCanvas := TCanvas.Create();
            DesktopCanvas.Handle := GetWindowDC(0);
            DesktopCanvas.Brush.Color := m_BorderColor;
            DesktopCanvas.FrameRect(ListRect);
            ReleaseDC(0, DesktopCanvas.Handle);
            DesktopCanvas.Free();
        end
    end;

    // Draw button
    R := pcbi.rcButton;
    if {$IFDEF RES_MACOS} (m_UIStyle = MacOS) {$ELSE} false {$ENDIF} or
        {$IFDEF RES_WINXP} (m_UIStyle = WinXP) {$ELSE} false {$ENDIF} then
    begin
        Btn := graphics.TBitmap.Create();
{$IFDEF RES_MACOS}
        if m_UIStyle = MacOS then
            Btn.LoadFromResourceName(hInstance, 'MACOS_COMBOBOX_BUTTON')
        else
{$ENDIF}        
            Btn.LoadFromResourceName(hInstance, 'WINXP_COMBOBOX_BUTTON');
        C.StretchDraw(R, Btn);
        Btn.Free();
    end
    else
    begin
        C.Brush.Color := m_ButtonColor;
        C.FillRect(R);
        C.Pen.Color := m_BorderColor;
        if (BidiMode = bdRightToLeft) and SysLocale.MiddleEast then
        begin
            C.MoveTo(R.Right, R.Top - 1);
            C.LineTo(R.Right, R.Bottom + 1);
        end
        else
        begin
            C.MoveTo(R.Left, R.Top - 1);
            C.LineTo(R.Left, R.Bottom + 1);
        end;
    end;

    X := (R.Right - R.Left) div 2 + R.Left - 3;
    Y := (R.Bottom - R.Top) div 2;
    if {$IFDEF RES_WINXP} m_UIStyle <> WinXP {$ELSE} True {$ENDIF} then
        DrawArrow(C, X, Y);

    C.Free;
end;

function TsuiFilterComboBox.GetDroppedDown: Boolean;
begin
    Result := LongBool(SendMessage(Handle, CB_GETDROPPEDSTATE, 0, 0));
end;

procedure TsuiFilterComboBox.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 TsuiFilterComboBox.SetArrowColor(const Value: TColor);
begin
    m_ArrowColor := Value;
    Repaint();
end;

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

procedure TsuiFilterComboBox.SetButtonColor(const Value: TColor);
begin
    m_ButtonColor := Value;
    Repaint();
end;

procedure TsuiFilterComboBox.SetDroppedDown(const Value: Boolean);
var
    R: TRect;
begin
    SendMessage(Handle, CB_SHOWDROPDOWN, Longint(Value), 0);
    R := ClientRect;
    InvalidateRect(Handle, @R, True);
end;

procedure TsuiFilterComboBox.SetEnabled(Value: Boolean);
begin
    inherited;
    Repaint();
end;

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

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

    m_ArrowColor := clBlack;
    if UsingFileTheme(m_FileTheme, m_UIStyle, OutUIStyle) then
    begin
        m_BorderColor := m_FileTheme.GetColor(SUI_THEME_CONTROL_BORDER_COLOR);
        m_ButtonColor := m_FileTheme.GetColor(SUI_THEME_FORM_BACKGROUND_COLOR);
    end
    else
    begin
        m_BorderColor := GetInsideThemeColor(OutUIStyle, SUI_THEME_CONTROL_BORDER_COLOR);
        m_ButtonColor := GetInsideThemeColor(OutUIStyle, SUI_THEME_FORM_BACKGROUND_COLOR);
    end;

    Repaint();
end;

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

    DrawButton();
end;

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

    DrawButton();
end;

end.

⌨️ 快捷键说明

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