cxradiogroup.pas
来自「胜天进销存源码,国产优秀的进销存」· PAS 代码 · 共 2,138 行 · 第 1/5 页
PAS
2,138 行
function TcxCustomRadioGroupButton.GetControl: TWinControl;
begin
Result := Self;
end;
function TcxCustomRadioGroupButton.GetControlContainer: TcxContainer;
begin
Result := RadioGroup;
end;
procedure TcxCustomRadioGroupButton.InternalSetChecked(AValue: Boolean);
begin
if FInternalSettingChecked then
Exit;
FInternalSettingChecked := True;
try
Checked := AValue;
finally
FInternalSettingChecked := False;
end;
end;
function TcxCustomRadioGroupButton.GetRadioGroup: TcxCustomRadioGroup;
begin
Result := TcxCustomRadioGroup(Owner);
end;
procedure TcxCustomRadioGroupButton.WMGetDlgCode(var Message: TWMGetDlgCode);
begin
inherited;
if RadioGroup.TabsNeeded and (GetKeyState(VK_CONTROL) >= 0) then
Message.Result := Message.Result or DLGC_WANTTAB;
if RadioGroup.IsInplace then
Message.Result := Message.Result or DLGC_WANTARROWS;
end;
procedure TcxCustomRadioGroupButton.WMKillFocus(var Message: TWMKillFocus);
begin
inherited;
if not(csDestroying in ComponentState) and (Message.FocusedWnd <> RadioGroup.Handle) then
RadioGroup.FocusChanged;
end;
procedure TcxCustomRadioGroupButton.WMSetFocus(var Message: TWMSetFocus);
begin
inherited;
if not(csDestroying in ComponentState) and (Message.FocusedWnd <> RadioGroup.Handle) then
RadioGroup.FocusChanged;
end;
procedure TcxCustomRadioGroupButton.CNCommand(var Message: TWMCommand);
begin
if FIsClickLocked then
Exit;
FIsClickLocked := True;
try
try
with RadioGroup do
if ((Message.NotifyCode = BN_CLICKED) or (Message.NotifyCode = BN_DOUBLECLICKED)) and
(Checked or CanModify and DoEditing) then
inherited;
except
Application.HandleException(Self);
end;
finally
FIsClickLocked := False;
end;
end;
{ TcxCustomRadioGroup }
procedure TcxCustomRadioGroup.Activate(var AEditData: TcxCustomEditData);
var
ACheckedButtonIndex: Integer;
begin
inherited Activate(AEditData);
if InternalButtons.Count = 0 then
Exit;
ACheckedButtonIndex := ItemIndex;
if ACheckedButtonIndex = -1 then
ACheckedButtonIndex := 0;
if Buttons[ACheckedButtonIndex].CanFocus then
Buttons[ACheckedButtonIndex].SetFocus;
end;
procedure TcxCustomRadioGroup.Clear;
begin
ItemIndex := -1;
end;
procedure TcxCustomRadioGroup.FlipChildren(AllLevels: Boolean);
begin
end;
class function TcxCustomRadioGroup.GetPropertiesClass: TcxCustomEditPropertiesClass;
begin
Result := TcxCustomRadioGroupProperties;
end;
procedure TcxCustomRadioGroup.GetTabOrderList(List: TList);
var
I: Integer;
begin
inherited GetTabOrderList(List);
List.Remove(Self);
if (TabStop or Focused) and (ItemIndex <> -1) then
for I := 0 to InternalButtons.Count - 1 do
if Buttons[I].Enabled then
List.Add(Buttons[I]);
end;
procedure TcxCustomRadioGroup.PrepareEditValue(const ADisplayValue: TcxEditValue;
out EditValue: TcxEditValue; AEditFocused: Boolean);
begin
if ADisplayValue = -1 then
EditValue := ActiveProperties.DefaultValue
else
begin
EditValue := ActiveProperties.Items[ADisplayValue].Value;
if VarIsNull(EditValue) then
EditValue := ActiveProperties.Items[ADisplayValue].Caption;
end;
end;
procedure TcxCustomRadioGroup.SetFocus;
var
ACheckedIndex: Integer;
begin
ACheckedIndex := GetCheckedIndex;
if (ACheckedIndex <> -1) and Buttons[ACheckedIndex].CanFocus then
Buttons[ACheckedIndex].SetFocus
else
inherited SetFocus;
end;
procedure TcxCustomRadioGroup.CursorChanged;
var
I: Integer;
begin
inherited CursorChanged;
for I := 0 to InternalButtons.Count - 1 do
Buttons[I].Cursor := Cursor;
end;
function TcxCustomRadioGroup.GetButtonDC(AButtonIndex: Integer): THandle;
begin
Result := Buttons[AButtonIndex].Canvas.Handle;
end;
procedure TcxCustomRadioGroup.Initialize;
begin
inherited Initialize;
{$IFDEF DELPHI7}
ControlStyle := ControlStyle * [csParentBackground];
{$ELSE}
ControlStyle := [];
{$ENDIF}
ControlStyle := ControlStyle + [csCaptureMouse, csClickEvents, csSetCaption,
csDoubleClicks, csReplicatable];
FLoadedItemIndex := -1;
Width := 185;
Height := 105;
end;
procedure TcxCustomRadioGroup.InternalSetEditValue(const Value: TcxEditValue;
AValidateEditValue: Boolean);
begin
SetInternalValues(Value, AValidateEditValue, False);
end;
function TcxCustomRadioGroup.IsContainerFocused: Boolean;
var
AIsButtonFocused: Boolean;
I: Integer;
begin
AIsButtonFocused := False;
for I := 0 to ActiveProperties.Items.Count - 1 do
if Buttons[I].Focused then
begin
AIsButtonFocused := True;
Break;
end;
if AIsButtonFocused then
Result := False
else
Result := inherited Focused;
end;
function TcxCustomRadioGroup.IsDBEditPaintCopyDrawing: Boolean;
begin
Result := not FSkinsPaintCopy and inherited IsDBEditPaintCopyDrawing;
end;
function TcxCustomRadioGroup.IsInternalControl(AControl: TControl): Boolean;
var
I: Integer;
begin
Result := AControl <> nil;
if Result then
begin
Result := inherited IsInternalControl(AControl);
if not Result then
for I := 0 to InternalButtons.Count - 1 do
if AControl = InternalButtons[I] then
begin
Result := True;
Exit;
end;
end;
end;
procedure TcxCustomRadioGroup.SetDragMode(Value: TDragMode);
var
I: Integer;
begin
inherited SetDragMode(Value);
for I := 0 to InternalButtons.Count - 1 do
Buttons[I].DragMode := Value;
end;
procedure TcxCustomRadioGroup.SetInternalValues(const AEditValue: TcxEditValue;
AValidateEditValue, AFromButtonChecked: Boolean);
procedure FocusButton(AIndex: Integer);
begin
if Focused and (GetFocus <> Handle) then
Buttons[AIndex].SetFocus;
end;
procedure SetButtonCheck(AItemIndex: Integer);
begin
if AFromButtonChecked then
FocusButton(AItemIndex)
else
begin
if AItemIndex < 0 then
Buttons[ItemIndex].InternalSetChecked(False)
else
begin
Buttons[AItemIndex].InternalSetChecked(True);
FocusButton(AItemIndex);
end;
if IsLoading or IsDesigning then
FLoadedItemIndex := AItemIndex;
end;
end;
var
AItemIndex: Integer;
begin
LockChangeEvents(True);
try
inherited InternalSetEditValue(AEditValue, AValidateEditValue);
AItemIndex := ActiveProperties.GetRadioGroupItemIndex(AEditValue);
if AFromButtonChecked or (GetCheckedIndex <> AItemIndex) then
begin
SetButtonCheck(AItemIndex);
DoClick;
DoChange;
end
else
if not KeyboardAction then
EditModified := False;
finally
LockChangeEvents(False);
end;
ShortRefreshContainer(False);
end;
procedure TcxCustomRadioGroup.SynchronizeButtonsStyle;
const
AButtonLookAndFeelKinds: array [TcxEditButtonStyle] of TcxLookAndFeelKind =
(lfStandard, lfStandard, lfFlat, lfStandard, lfStandard,
lfUltraFlat, lfOffice11);
var
I: Integer;
begin
inherited SynchronizeButtonsStyle;
if Length(ViewInfo.ButtonsInfo) > 0 then
for I := 0 to InternalButtons.Count - 1 do
begin
Buttons[I].LookAndFeel.Kind := AButtonLookAndFeelKinds[ViewInfo.ButtonsInfo[0].Data.Style];
if not Buttons[I].Enabled then
Buttons[I].Font.Color := StyleDisabled.GetVisibleFont.Color;
Buttons[I].Transparent := Transparent; // Repaint buttons
end;
end;
procedure TcxCustomRadioGroup.Resize;
begin
inherited Resize;
if IsDesigning and IsNativeBackground then
InvalidateRect(GetControlRect(Self), True);
end;
procedure TcxCustomRadioGroup.ParentBackgroundChanged;
var
I: Integer;
begin
for I := 0 to InternalButtons.Count - 1 do
Buttons[I].ParentBackground := ParentBackground;
end;
procedure TcxCustomRadioGroup.SetDragKind(Value: TDragKind);
var
I: Integer;
begin
inherited SetDragKind(Value);
for I := 0 to InternalButtons.Count - 1 do
Buttons[I].DragKind := Value;
end;
procedure TcxCustomRadioGroup.ArrangeButtons;
var
AButtonViewInfo: TcxGroupBoxButtonViewInfo;
I: Integer;
begin
inherited ArrangeButtons;
for I := 0 to InternalButtons.Count - 1 do
begin
AButtonViewInfo := TcxGroupBoxButtonViewInfo(ViewInfo.ButtonsInfo[I]);
Buttons[I].FColumn := AButtonViewInfo.Column;
Buttons[I].FRow := AButtonViewInfo.Row;
end;
end;
function TcxCustomRadioGroup.GetButtonInstance: TWinControl;
begin
Result := TcxCustomRadioGroupButton.Create(Self);
end;
procedure TcxCustomRadioGroup.UpdateButtons;
var
I: Integer;
AItemIndex: Integer;
begin
AItemIndex := ItemIndex;
inherited UpdateButtons;
if IsLoading then
Exit;
if GetCheckedIndex <> AItemIndex then
ItemIndex := AItemIndex;
for I := 0 to InternalButtons.Count - 1 do
begin
Buttons[I].Caption := ActiveProperties.Items[I].Caption;
Buttons[I].WordWrap := ActiveProperties.WordWrap;
end;
end;
procedure TcxCustomRadioGroup.AfterLoading;
begin
LockChangeEvents(True);
LockClick(True);
try
if not IsDBEdit then
FEditValue := ActiveProperties.DefaultValue;
ItemIndex := FLoadedItemIndex;
finally
LockClick(False);
LockChangeEvents(False, False);
end;
UpdateButtons;
end;
function TcxCustomRadioGroup.IsLoading: Boolean;
begin
Result := [csReading, csLoading, csUpdating] * ComponentState <> [];
end;
procedure TcxCustomRadioGroup.Loaded;
begin
inherited;
AfterLoading;
end;
procedure TcxCustomRadioGroup.Updated;
begin
inherited;
AfterLoading;
end;
procedure TcxCustomRadioGroup.GetChildren(Proc: TGetChildProc; Root: TComponent);
begin
end;
procedure TcxCustomRadioGroup.ButtonChecked(AButton: TcxCustomRadioGroupButton);
var
AEditValue: TcxEditValue;
begin
LockChangeEvents(True);
try
KeyboardAction := Focused;
try
if not IsLoading then
begin
PrepareEditValue(InternalButtons.IndexOf(AButton), AEditValue, InternalFocused);
SetInternalValues(AEditValue, True, True);
end;
finally
KeyboardAction := False;
end;
if Focused and ActiveProperties.ImmediatePost and CanPostEditValue and ValidateEdit(True) then
InternalPostEditValue;
finally
LockChangeEvents(False);
end;
end;
function TcxCustomRadioGroup.GetCheckedIndex: Integer;
var
I: Integer;
begin
Result := -1;
for I := 0 to InternalButtons.Count - 1 do
if Buttons[I].Checked then
begin
Result := I;
Break;
end;
end;
function TcxCustomRadioGroup.GetButton(Index: Integer): TcxCustomRadioGroupButton;
begin
Resu
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?