cxcheckcombobox.pas
来自「胜天进销存源码,国产优秀的进销存」· PAS 代码 · 共 1,557 行 · 第 1/4 页
PAS
1,557 行
property StyleDisabled;
property StyleFocused;
property StyleHot;
property TabOrder;
property TabStop;
property Value; // deprecated
property Visible;
{$IFDEF DELPHI5}
property OnContextPopup;
{$ENDIF}
property OnDragDrop;
property OnDragOver;
property OnEditing;
property OnEndDock;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMouseDown;
property OnMouseEnter;
property OnMouseLeave;
property OnMouseMove;
property OnMouseUp;
property OnStartDock;
property OnStartDrag;
end;
{ TcxFilterChecksHelper }
TcxFilterChecksHelper = class(TcxFilterComboBoxHelper)
protected
class function GetEditValueFormat(
AEditProperties: TcxCustomEditProperties): TcxCheckStatesValueFormat; virtual;
class function GetItems(
AEditProperties: TcxCustomEditProperties): IcxCheckItems; virtual;
class procedure InitializeItems(AProperties,
AEditProperties: TcxCustomEditProperties); virtual;
public
class function GetFilterEditClass: TcxCustomEditClass; override;
class function GetSupportedFilterOperators(
AProperties: TcxCustomEditProperties; AValueTypeClass: TcxValueTypeClass;
AExtendedSet: Boolean = False): TcxFilterControlOperators; override;
class procedure InitializeProperties(AProperties,
AEditProperties: TcxCustomEditProperties; AHasButtons: Boolean); override;
end;
{ TcxFilterCheckComboBoxHelper }
TcxFilterCheckComboBoxHelper = class(TcxFilterChecksHelper)
protected
class function GetEditValueFormat(
AEditProperties: TcxCustomEditProperties): TcxCheckStatesValueFormat; override;
class function GetItems(
AEditProperties: TcxCustomEditProperties): IcxCheckItems; override;
end;
const
cxCheckComboValuesDelimiter = ';';
implementation
uses
dxThemeManager;
{ TcxCheckComboBoxItem }
procedure TcxCheckComboBoxItem.Assign(Source: TPersistent);
begin
if Source is TcxCheckComboBoxItem then
ShortDescription := TcxCheckComboBoxItem(Source).ShortDescription;
inherited Assign(Source);
end;
function TcxCheckComboBoxItem.GetDisplayDescription: string;
begin
if ShortDescription <> '' then
Result := ShortDescription
else
Result := Description;
end;
function TcxCheckComboBoxItem.GetDescription: TCaption;
begin
Result := Caption;
end;
procedure TcxCheckComboBoxItem.SetDescription(const Value: TCaption);
begin
Caption := Value;
end;
procedure TcxCheckComboBoxItem.SetShortDescription(const Value: TCaption);
begin
if Value <> FShortDescription then
begin
FShortDescription := Value;
DoChanged(Collection, copChanged);
end;
end;
{ TcxCheckComboBoxItems }
function TcxCheckComboBoxItems.GetItems(Index: Integer): TcxCheckComboBoxItem;
begin
Result := TcxCheckComboBoxItem(inherited Items[Index]);
end;
procedure TcxCheckComboBoxItems.SetItems(Index: Integer;const Value: TcxCheckComboBoxItem);
begin
inherited Items[Index] := Value;
end;
function TcxCheckComboBoxItems.Add: TcxCheckComboBoxItem;
begin
Result := TcxCheckComboBoxItem(inherited Add);
end;
function TcxCheckComboBoxItems.AddCheckItem(const ADescription: TCaption;
const AShortDescription: TCaption = ''): TcxCheckComboBoxItem;
begin
Result := Add;
Result.Description := ADescription;
Result.ShortDescription := AShortDescription;
end;
{ TcxCustomCheckComboBoxViewData }
procedure TcxCustomCheckComboBoxViewData.Calculate(ACanvas: TcxCanvas;
const ABounds: TRect; const P: TPoint; Button: TcxMouseButton;
Shift: TShiftState; AViewInfo: TcxCustomEditViewInfo; AIsMouseEvent: Boolean);
begin
if IsRectEmpty(ABounds) then
begin
inherited;
Exit;
end;
inherited Calculate(ACanvas, ABounds, P, Button, Shift, AViewInfo, AIsMouseEvent);
if (ABounds.Right = MaxInt) or (ABounds.Bottom = MaxInt) then Exit;
end;
function TcxCustomCheckComboBoxViewData.GetProperties: TcxCustomCheckComboBoxProperties;
begin
Result := TcxCustomCheckComboBoxProperties(FProperties);
end;
function TcxCustomCheckComboBoxViewData.InternalEditValueToDisplayText(
AEditValue: TcxEditValue): string;
var
ASender: TObject;
begin
if IsInplace then
ASender := nil
else
ASender := Edit;
Properties.CalculateCheckStatesByEditValue(ASender, AEditValue, CheckStates);
Result := Properties.CalculateDisplayValueByCheckStates(CheckStates);
Properties.DisplayValueToDisplayText(Result);
end;
function TcxCustomCheckComboBoxViewData.IsComboBoxStyle: Boolean;
begin
Result := True;
end;
{ TcxCustomCheckComboBoxListBox }
constructor TcxCustomCheckComboBoxListBox.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FCapturedCheckIndex := -1;
FHotCheckIndex := -1;
FInternalUpdate := False;
FPressedCheckIndex := -1;
Style := lbOwnerDrawFixed;
end;
destructor TcxCustomCheckComboBoxListBox.Destroy;
begin
EndMouseTracking(Self);
inherited Destroy;
end;
function TcxCustomCheckComboBoxListBox.GetItemHeight(AIndex: Integer = -1): Integer;
begin
if Edit.ActiveProperties.ItemHeight > 0 then
Result := Edit.ActiveProperties.ItemHeight
else
Result := inherited GetItemHeight(AIndex);
if Result < FCheckSize.cy + 2 then
Result := FCheckSize.cy + 2;
end;
function TcxCustomCheckComboBoxListBox.GetItemWidth(AIndex: Integer): Integer;
begin
Result := inherited GetItemWidth(AIndex);
Inc(Result, ItemHeight);
end;
procedure TcxCustomCheckComboBoxListBox.MouseTrackingMouseLeave;
begin
InternalMouseMove([], -1, -1);
EndMouseTracking(Self);
end;
procedure TcxCustomCheckComboBoxListBox.CheckHotTrack;
var
P: TPoint;
begin
P := ScreenToClient(InternalGetCursorPos);
InternalMouseMove(InternalGetShiftState, P.X, P.Y);
end;
function TcxCustomCheckComboBoxListBox.DoMouseWheel(Shift: TShiftState;
WheelDelta: Integer; MousePos: TPoint): Boolean;
begin
Result := inherited DoMouseWheel(Shift, WheelDelta, MousePos);
CheckHotTrack;
end;
procedure TcxCustomCheckComboBoxListBox.DrawItem(Index: Integer; Rect: TRect;
State: TOwnerDrawState);
function GetCheckState(AIsItemEnabled: Boolean): TcxEditCheckState;
begin
if not AIsItemEnabled then
Result := ecsDisabled
else
if FHotCheckIndex = Index then
Result := ecsHot
else
if FPressedCheckIndex = Index then
Result := ecsPressed
else
Result := ecsNormal;
end;
function GetCheckBorderStyle(ACheckState: TcxEditCheckState): TcxEditCheckBoxBorderStyle;
begin
if not Edit.FNativeStyle and (Edit.FCheckBorderStyle = ebsFlat) and
(ACheckState in [ecsHot, ecsPressed]) then
Result := ebs3D
else
Result := Edit.FCheckBorderStyle;
end;
var
ACheckState: TcxEditCheckState;
AFlags: Longint;
AText: string;
ATextRect : TRect;
begin
if DoDrawItem(Index, Rect, State) then
Exit;
with Edit.ActiveProperties do
begin
Canvas.FillRect(Rect);
FCheckPaintHelper.Glyph := Glyph;
FCheckPaintHelper.GlyphCount := GlyphCount;
ATextRect := FCheckPaintHelper.CalcTextRect(Rect, Edit.FStates[Index]);
AText := GetItem(Index);
AFlags := DrawTextBiDiModeFlags(DT_SINGLELINE or DT_LEFT or DT_VCENTER or DT_NOPREFIX);
if not Items[Index].Enabled then
Canvas.Font.Color := Edit.StyleDisabled.TextColor;
cxDrawText(Canvas.Handle, AText, ATextRect, AFlags);
if Rect.Top >= 0 then
begin
ACheckState := GetCheckState(Items[Index].Enabled);
SaveCanvasParametersForFocusRect;
DrawEditCheck(Canvas, GetCheckRect(Rect, True), Edit.FStates[Index],
ACheckState, Glyph, GlyphCount, GetCheckBorderStyle(ACheckState),
Edit.FNativeStyle, clBtnText, Color, False, False, False, False,
Edit.Style.LookAndFeel.SkinPainter);
RestoreCanvasParametersForFocusRect;
end;
end;
end;
procedure TcxCustomCheckComboBoxListBox.FullRepaint;
var
R: TRect;
begin
if HandleAllocated then
begin
R := GetControlRect(Self);
InvalidateRect(Handle, @R, True);
end;
end;
function TcxCustomCheckComboBoxListBox.GetCheckAt(X, Y: Integer): Integer;
begin
Result := ItemAtPos(Point(X, Y), True);
end;
function TcxCustomCheckComboBoxListBox.GetCheckRect(const R: TRect; AReturnFullRect: Boolean): TRect;
begin
// ToDo RightToLeftAlignment
with R do
begin
Result.Top := (Bottom - Top - FCheckSize.cy) div 2;
Result.Left := Result.Top;
Inc(Result.Top, Top);
Result.Bottom := Result.Top + FCheckSize.cy;
if Result.Left < 1 then
Result.Left := 1;
Result.Right := Result.Left + FCheckSize.cx;
end;
if AReturnFullRect then
InflateRect(Result, FCheckBorderOffset, FCheckBorderOffset);
end;
procedure TcxCustomCheckComboBoxListBox.InternalMouseMove(Shift: TShiftState; X, Y: Integer);
var
ANewHotCheckIndex, ANewPressedCheckIndex: Integer;
begin
ANewHotCheckIndex := FHotCheckIndex;
ANewPressedCheckIndex := FPressedCheckIndex;
if FCapturedCheckIndex <> -1 then
begin
ANewHotCheckIndex := -1;
if GetCheckAt(X, Y) = FCapturedCheckIndex then
ANewPressedCheckIndex := FCapturedCheckIndex
else
ANewPressedCheckIndex := -1;
end;
if (GetCaptureControl <> Self) and (Shift = []) then
ANewHotCheckIndex := GetCheckAt(X, Y);
SynchronizeCheckStates(ANewHotCheckIndex, ANewPressedCheckIndex);
end;
procedure TcxCustomCheckComboBoxListBox.InvalidateCheck(Index: Integer);
var
R: TRect;
begin
R := ItemRect(Index);
R := GetCheckRect(R, False);
InvalidateRect(Handle, @R, False);
end;
procedure TcxCustomCheckComboBoxListBox.KeyPress(var Key: Char);
begin
if (ItemIndex <> -1) and Assigned(Edit) then
begin
if (Key = Char(VK_SPACE)) then
begin
if not (Edit.ActiveProperties.Items[ItemIndex].Enabled) then Exit;
FInternalUpdate := True;
UpdateItemState(ItemIndex);
FInternalUpdate := False;
Key := #0;
end;
end
else
inherited KeyPress(Key);
end;
procedure TcxCustomCheckComboBoxListBox.LookAndFeelChanged(Sender: TcxLookAndFeel;
AChangedValues: TcxLookAndFeelValues);
begin
inherited LookAndFeelChanged(Sender, AChangedValues);
RecreateWindow;
end;
procedure TcxCustomCheckComboBoxListBox.MouseDown(Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
ANewPressedCheckIndex: Integer;
begin
inherited MouseDown(Button, Shift, X, Y);
if Button = mbLeft then
begin
ANewPressedCheckIndex := GetCheckAt(X, Y);
FCapturedCheckIndex := ANewPressedCheckIndex;
end
else
ANewPressedCheckIndex := -1;
SynchronizeCheckStates(-1, ANewPressedCheckIndex);
end;
procedure TcxCustomCheckComboBoxListBox.MouseMove(Shift: TShiftState; X, Y: Integer);
var
APopupMouseMoveLocked: Boolean;
begin
APopupMouseMoveLocked := Edit.PopupMouseMoveLocked;
inherited MouseMove(Shift, X, Y);
if not APopupMouseMoveLocked then
begin
InternalMouseMove(Shift, X, Y);
BeginMouseTracking(Self, GetControlRect(Self), Self);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?