cxcheckgroup.pas
来自「胜天进销存源码,国产优秀的进销存」· PAS 代码 · 共 1,310 行 · 第 1/3 页
PAS
1,310 行
Result := CheckGroup.IsButtonNativeStyle;
end;
function TcxCheckGroupButton.IsTransparent: Boolean;
begin
Result := CheckGroup.IsTransparent;
end;
procedure TcxCheckGroupButton.KeyDown(var Key: Word; Shift: TShiftState);
procedure FocusNearestItem(ADown: Boolean);
var
AIndex, I, ADelta: Integer;
begin
with CheckGroup do
begin
AIndex := InternalButtons.IndexOf(Self);
ADelta := Integer(ADown) - Integer(not ADown);
I := AIndex;
repeat
I := I + ADelta;
if I = InternalButtons.Count then
I := 0
else
if I < 0 then
I := InternalButtons.Count - 1;
if Buttons[I].Enabled then
Break;
until I = AIndex;
if I <> AIndex then
Buttons[I].SetFocus;
end;
end;
var
APrevKeyDownEvent: TKeyEvent;
begin
_TcxContainerAccess.KeyDown(CheckGroup, Key, Shift);
if Key = 0 then
Exit;
if not CheckGroup.IsInplace then
if Key in [VK_UP, VK_LEFT] then
FocusNearestItem(False)
else
if Key in [VK_DOWN, VK_RIGHT] then
FocusNearestItem(True);
APrevKeyDownEvent := OnKeyDown;
OnKeyDown := nil;
inherited KeyDown(Key, Shift);
OnKeyDown := APrevKeyDownEvent;
end;
procedure TcxCheckGroupButton.LookAndFeelChanged(Sender: TcxLookAndFeel;
AChangedValues: TcxLookAndFeelValues);
begin
inherited LookAndFeelChanged(Sender, AChangedValues);
CheckTransparentBorder;
end;
procedure TcxCheckGroupButton.WndProc(var Message: TMessage);
begin
with Message do
if ((Msg = WM_LBUTTONDOWN) or (Msg = WM_LBUTTONDBLCLK)) and
(CheckGroup.DragMode = dmAutomatic) and not(csDesigning in CheckGroup.ComponentState) then
begin
_TcxContainerAccess.BeginAutoDrag(CheckGroup);
Exit;
end;
inherited WndProc(Message);
end;
function TcxCheckGroupButton.GetControl: TWinControl;
begin
Result := Self;
end;
function TcxCheckGroupButton.GetControlContainer: TcxContainer;
begin
Result := CheckGroup;
end;
procedure TcxCheckGroupButton.CheckTransparentBorder;
begin
if Style.LookAndFeel.SkinPainter <> nil then
ViewInfo.Transparent := True;
if not CheckGroup.IsInplace then
Style.TransparentBorder := IsNativeStyle;
end;
function TcxCheckGroupButton.GetCheckGroup: TcxCustomCheckGroup;
begin
Result := TcxCustomCheckGroup(Owner);
end;
{ TcxCustomCheckGroup }
procedure TcxCustomCheckGroup.Activate(var AEditData: TcxCustomEditData);
begin
FFocusedItemIndex := 0;
inherited Activate(AEditData);
end;
class function TcxCustomCheckGroup.GetPropertiesClass: TcxCustomEditPropertiesClass;
begin
Result := TcxCustomCheckGroupProperties;
end;
procedure TcxCustomCheckGroup.GetTabOrderList(List: TList);
var
AFocusedItemIndex: Integer;
begin
inherited GetTabOrderList(List);
List.Remove(Self);
if Focused then
AFocusedItemIndex := GetFocusedButtonIndex
else
AFocusedItemIndex := GetFirstEnabledItemIndex(FFocusedItemIndex);
if (AFocusedItemIndex <> -1) and TabStop then
List.Add(InternalButtons[AFocusedItemIndex]);
end;
procedure TcxCustomCheckGroup.SetFocus;
begin
inherited SetFocus;
FFocusedItemIndex := GetFirstEnabledItemIndex(FFocusedItemIndex);
if FFocusedItemIndex <> -1 then
TWinControl(InternalButtons[FFocusedItemIndex]).SetFocus;
end;
procedure TcxCustomCheckGroup.ArrangeButtons;
var
AButtonViewInfo: TcxGroupBoxButtonViewInfo;
I: Integer;
begin
inherited ArrangeButtons;
for I := 0 to InternalButtons.Count - 1 do
with Buttons[I] do
begin
AButtonViewInfo := TcxGroupBoxButtonViewInfo(Self.ViewInfo.ButtonsInfo[I]);
FColumn := AButtonViewInfo.Column;
FRow := AButtonViewInfo.Row;
end;
end;
function TcxCustomCheckGroup.GetButtonDC(AButtonIndex: Integer): THandle;
begin
Result := Buttons[AButtonIndex].Canvas.Handle;
end;
function TcxCustomCheckGroup.GetButtonInstance: TWinControl;
begin
Result := TcxCheckGroupButton.Create(Self, IsInplace);
end;
procedure TcxCustomCheckGroup.Initialize;
begin
inherited Initialize;
ControlStyle := ControlStyle - [csAcceptsControls];
FFocusedItemIndex := -1;
InternalEditValue := 0;
end;
procedure TcxCustomCheckGroup.InternalSetEditValue(const Value: TcxEditValue; AValidateEditValue: Boolean);
begin
inherited InternalSetEditValue(Value, AValidateEditValue);
SynchronizeModifiedAfterEnter;
end;
procedure TcxCustomCheckGroup.InternalValidateDisplayValue(const ADisplayValue: TcxEditValue);
var
APrevEditValue: TcxEditValue;
I: Integer;
begin
APrevEditValue := FEditValue;
SetLength(CheckStates, InternalButtons.Count);
for I := 0 to High(CheckStates) do
CheckStates[I] := Buttons[I].State;
with ActiveProperties do
CalculateEditValueByCheckStates(GetStandaloneEventSender(Self), FEditValue);
if not InternalVarEqualsExact(APrevEditValue, FEditValue) then
DoEditValueChanged;
end;
function TcxCustomCheckGroup.IsEditValueStored: Boolean;
begin
Result := (ActiveProperties.EditValueFormat = cvfInteger) and (EditValue <> 0) or
(ActiveProperties.EditValueFormat <> cvfInteger) and (VarToStr(EditValue) <> '');
end;
procedure TcxCustomCheckGroup.ParentBackgroundChanged;
var
I: Integer;
begin
for I := 0 to InternalButtons.Count - 1 do
Buttons[I].ParentBackground := ParentBackground;
end;
procedure TcxCustomCheckGroup.PropertiesChanged(Sender: TObject);
begin
inherited PropertiesChanged(Sender);
InternalValidateDisplayValue(Null);
DataBinding.UpdateDisplayValue;
end;
procedure TcxCustomCheckGroup.SynchronizeButtonsStyle;
var
AButton: TcxCheckGroupButton;
ADisabledTextColor: TColor;
I: Integer;
begin
inherited SynchronizeButtonsStyle;
ADisabledTextColor := LookAndFeelPainter.DefaultEditorTextColor(True);
if ADisabledTextColor = clDefault then
ADisabledTextColor := StyleDisabled.GetVisibleFont.Color;
for I := 0 to InternalButtons.Count - 1 do
begin
AButton := Buttons[I];
AButton.Style.BorderStyle := ActiveStyle.BorderStyle;
if not AButton.Enabled then
begin
AButton.StyleDisabled.Color := ActiveStyle.Color;
AButton.StyleDisabled.TextColor := ADisabledTextColor;
end;
AButton.Transparent := Transparent; // to repaint button
end;
end;
procedure TcxCustomCheckGroup.SynchronizeDisplayValue;
var
I: Integer;
begin
if ActiveProperties.Items.ItemChanged then
Exit;
with ActiveProperties do
CalculateCheckStatesByEditValue(GetStandaloneEventSender(Self), EditValue);
if not ActiveProperties.AllowGrayed and Focused then
for I := 0 to High(CheckStates) do
if CheckStates[I] = cbsGrayed then
CheckStates[I] := cbsUnchecked;
FButtonStatesChanging := True;
try
for I := 0 to InternalButtons.Count - 1 do
Buttons[I].State := CheckStates[I];
finally
FButtonStatesChanging := False;
end;
end;
procedure TcxCustomCheckGroup.SynchronizeModifiedAfterEnter;
function NeedSynchronize: Boolean;
begin
Result := not ModifiedAfterEnter or ActiveProperties.ImmediatePost;
end;
var
I: Integer;
begin
if NeedSynchronize then
for I := 0 to InternalButtons.Count - 1 do
Buttons[I].ModifiedAfterEnter := False;
end;
procedure TcxCustomCheckGroup.UpdateButtons;
const
ALookAndFeelKindMap: array [TcxEditButtonStyle] of TcxLookAndFeelKind =
(lfStandard, lfStandard, lfFlat, lfStandard, lfStandard,
lfUltraFlat, lfOffice11);
var
AButton: TcxCheckGroupButton;
I: Integer;
begin
inherited UpdateButtons;
if FFocusedItemIndex >= InternalButtons.Count then
FFocusedItemIndex := -1;
for I := 0 to InternalButtons.Count - 1 do
begin
AButton := Buttons[I];
AButton.Properties.BeginUpdate;
try
AButton.Properties.Alignment := ActiveProperties.ItemAlignment;
AButton.Properties.AllowGrayed := ActiveProperties.AllowGrayed;
AButton.Caption := ActiveProperties.Items[I].Caption;
AButton.Properties.MultiLine := ActiveProperties.WordWrap;
AButton.Properties.GlyphCount := ActiveProperties.GlyphCount;
AButton.Properties.ReadOnly := ActiveProperties.ReadOnly and
DataBinding.IsDataAvailable;
if Length(ViewInfo.ButtonsInfo) > 0 then
AButton.LookAndFeel.Kind := ALookAndFeelKindMap[ViewInfo.ButtonsInfo[0].Data.Style];
finally
AButton.Properties.EndUpdate;
AButton.OnEditing := DoButtonEditing;
AButton.OnFocusChanged := DoButtonFocusChanged;
AButton.Properties.OnChange := DoButtonChange;
end;
end;
// SynchronizeDisplayValue;
end;
function TcxCustomCheckGroup.WantNavigationKeys: Boolean;
begin
Result := not IsInplace;
end;
function TcxCustomCheckGroup.GetFirstEnabledItemIndex(AStartIndex: Integer): Integer;
var
I: Integer;
begin
Result := -1;
if AStartIndex = -1 then
AStartIndex := 0;
for I := 0 to InternalButtons.Count - 1 do
if TWinControl(InternalButtons[(I + AStartIndex) mod InternalButtons.Count]).CanFocus then
begin
Result := (I + AStartIndex) mod InternalButtons.Count;
Break;
end;
end;
procedure TcxCustomCheckGroup.DoButtonChange(Sender: TObject);
begin
if FButtonStatesChanging then
Exit;
LockChangeEvents(True);
try
InternalValidateDisplayValue(Null);
ChangeHandler(Self);
if ActiveProperties.ImmediatePost and CanPostEditValue and ValidateEdit(True) then
begin
InternalPostEditValue;
SynchronizeModifiedAfterEnter;
end;
finally
LockChangeEvents(False);
end;
end;
procedure TcxCustomCheckGroup.DoButtonEditing(Sender: TObject; var CanEdit: Boolean);
begin
CanEdit := DoEditing;
end;
procedure TcxCustomCheckGroup.DoButtonFocusChanged(Sender: TObject);
begin
FocusChanged;
end;
function TcxCustomCheckGroup.GetActiveProperties: TcxCustomCheckGroupProperties;
begin
Result := TcxCustomCheckGroupProperties(InternalGetActiveProperties);
end;
function TcxCustomCheckGroup.GetButton(Index: Integer): TcxCheckGroupButton;
begin
Result := TcxCheckGroupButton(InternalButtons[Index]);
end;
function TcxCustomCheckGroup.GetProperties: TcxCustomCheckGroupProperties;
begin
Result := TcxCustomCheckGroupProperties(FProperties);
end;
function TcxCustomCheckGroup.GetState(Index: Integer): TcxCheckBoxState;
begin
Result := Buttons[Index].State;
end;
procedure TcxCustomCheckGroup.SetProperties(Value: TcxCustomCheckGroupProperties);
begin
FProperties.Assign(Value);
end;
procedure TcxCustomCheckGroup.SetState(Index: Integer; Value: TcxCheckBoxState);
begin
Buttons[Index].State := Value;
end;
{ TcxCheckGroup }
class function TcxCheckGroup.GetPropertiesClass: TcxCustomEditPropertiesClass;
begin
Result := TcxCheckGroupProperties;
end;
function TcxCheckGroup.GetActiveProperties: TcxCheckGroupProperties;
begin
Result := TcxCheckGroupProperties(InternalGetActiveProperties);
end;
function TcxCheckGroup.GetProperties: TcxCheckGroupProperties;
begin
Result := TcxCheckGroupProperties(FProperties);
end;
procedure TcxCheckGroup.SetProperties(Value: TcxCheckGroupProperties);
begin
FProperties.Assign(Value);
end;
{ TcxFilterCheckGroupHelper }
class function TcxFilterCheckGroupHelper.GetEditValueFormat(
AEditProperties: TcxCustomEditProperties): TcxCheckStatesValueFormat;
begin
Result := TcxCustomCheckGroupProperties(AEditProperties).EditValueFormat;
end;
class function TcxFilterCheckGroupHelper.GetItems(
AEditProperties: TcxCustomEditProperties): IcxCheckItems;
begin
Result := TcxCustomCheckGroupProperties(AEditProperties).Items;
end;
class procedure TcxFilterCheckGroupHelper.InitializeItems(AProperties,
AEditProperties: TcxCustomEditProperties);
begin
inherited InitializeItems(AProperties, AEditProperties);
TcxCustomCheckComboBoxProperties(AProperties).Glyph :=
TcxCustomCheckGroupProperties(AEditProperties).Glyph;
TcxCustomCheckComboBoxProperties(AProperties).GlyphCount :=
TcxCustomCheckGroupProperties(AEditProperties).GlyphCount;
end;
initialization
GetRegisteredEditProperties.Register(TcxCheckGroupProperties,
scxSEditRepositoryCheckGroupItem);
FilterEditsController.Register(TcxCheckGroupProperties,
TcxFilterCheckGroupHelper);
finalization
FilterEditsController.Unregister(TcxCheckGroupProperties,
TcxFilterCheckGroupHelper);
GetRegisteredEditProperties.Unregister(TcxCheckGroupProperties);
end.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?