cxradiogroup.pas
来自「胜天进销存源码,国产优秀的进销存」· PAS 代码 · 共 2,138 行 · 第 1/5 页
PAS
2,138 行
procedure TcxCustomRadioGroupViewData.CalculateButtonNativeState(AViewInfo: TcxCustomEditViewInfo;
AButtonViewInfo: TcxGroupBoxButtonViewInfo);
const
AButtonStateMap: array [Boolean, TcxEditButtonState] of Integer = (
(RBS_UNCHECKEDDISABLED, RBS_UNCHECKEDNORMAL, RBS_UNCHECKEDPRESSED, RBS_UNCHECKEDHOT),
(RBS_CHECKEDDISABLED, RBS_CHECKEDNORMAL, RBS_CHECKEDPRESSED, RBS_CHECKEDHOT)
);
var
ATheme: TdxTheme;
begin
with AButtonViewInfo do
begin
if not Data.NativeStyle then
Exit;
Data.NativePart := BP_RADIOBUTTON;
Data.NativeState := AButtonStateMap[Index = TcxCustomRadioGroupViewInfo(AViewInfo).ItemIndex, Data.State];
ATheme := OpenTheme(totButton);
Data.BackgroundPartiallyTransparent := IsThemeBackgroundPartiallyTransparent(ATheme,
Data.NativePart, Data.NativeState);
end;
end;
function TcxCustomRadioGroupViewData.GetProperties: TcxCustomRadioGroupProperties;
begin
Result := TcxCustomRadioGroupProperties(FProperties);
end;
{ TcxRadioGroupItem }
constructor TcxRadioGroupItem.Create(Collection: TCollection);
begin
FValue := Null;
inherited Create(Collection);
end;
procedure TcxRadioGroupItem.Assign(Source: TPersistent);
begin
if Source is TcxRadioGroupItem then
Value := TcxRadioGroupItem(Source).Value;
inherited Assign(Source);
end;
function TcxRadioGroupItem.IsValueStored: Boolean;
begin
Result := not VarIsNull(FValue);
end;
procedure TcxRadioGroupItem.SetValue(const Value: TcxEditValue);
begin
if not InternalVarEqualsExact(Value, FValue) then
begin
FValue := Value;
if Assigned(Collection) then
TcxRadioGroupItems(Collection).InternalNotify(Self, -1, copChanged);
end;
end;
{ TcxRadioGroupItems }
function TcxRadioGroupItems.Add: TcxRadioGroupItem;
begin
Result := TcxRadioGroupItem(inherited Add);
end;
function TcxRadioGroupItems.GetItem(Index: Integer): TcxRadioGroupItem;
begin
Result := TcxRadioGroupItem(inherited Items[Index]);
end;
procedure TcxRadioGroupItems.SetItem(Index: Integer; Value: TcxRadioGroupItem);
begin
inherited Items[Index] := Value;
end;
{ TcxCustomRadioGroupProperties }
constructor TcxCustomRadioGroupProperties.Create(AOwner: TPersistent);
begin
inherited Create(AOwner);
FDefaultCaption := cxGetResourceString(@cxSRadioGroupDefaultCaption);
FDefaultValue := Null;
end;
procedure TcxCustomRadioGroupProperties.Assign(Source: TPersistent);
begin
if Source is TcxCustomRadioGroupProperties then
begin
BeginUpdate;
try
inherited Assign(Source);
with Source as TcxCustomRadioGroupProperties do
begin
Self.DefaultCaption := DefaultCaption;
Self.DefaultValue := DefaultValue;
Self.WordWrap := WordWrap;
end;
finally
EndUpdate;
end
end
else
inherited Assign(Source);
end;
function TcxCustomRadioGroupProperties.CanCompareEditValue: Boolean;
begin
Result := True;
end;
function TcxCustomRadioGroupProperties.CompareDisplayValues(
const AEditValue1, AEditValue2: TcxEditValue): Boolean;
begin
Result := GetRadioGroupItemIndex(AEditValue1) = GetRadioGroupItemIndex(AEditValue2);
end;
class function TcxCustomRadioGroupProperties.GetContainerClass: TcxContainerClass;
begin
Result := TcxRadioGroup;
end;
function TcxCustomRadioGroupProperties.GetDisplayText(const AEditValue: TcxEditValue;
AFullText: Boolean = False; AIsInplace: Boolean = True): WideString;
var
AItemIndex: Integer;
begin
AItemIndex := GetRadioGroupItemIndex(AEditValue);
if AItemIndex = -1 then
Result := FDefaultCaption
else
Result := Items[AItemIndex].Caption;
end;
function TcxCustomRadioGroupProperties.GetRadioGroupItemIndex(
const AEditValue: TcxEditValue): Integer;
var
I: Integer;
AIsNull: Boolean;
AItem: TcxRadioGroupItem;
begin
Result := -1;
for I := 0 to Items.Count - 1 do
begin
AItem := Items[I];
AIsNull := VarIsNull(AItem.Value);
if AIsNull and InternalCompareString(AItem.Caption, VarToStr(AEditValue), True) or
not AIsNull and VarEqualsExact(AEditValue, AItem.Value) then
begin
Result := I;
Break;
end;
end;
end;
function TcxCustomRadioGroupProperties.GetSupportedOperations: TcxEditSupportedOperations;
begin
Result := inherited GetSupportedOperations + [esoHorzAlignment, esoSortingByDisplayText];
end;
class function TcxCustomRadioGroupProperties.GetViewInfoClass: TcxContainerViewInfoClass;
begin
Result := TcxCustomRadioGroupViewInfo;
end;
function TcxCustomRadioGroupProperties.IsResetEditClass: Boolean;
begin
Result := True;
end;
procedure TcxCustomRadioGroupProperties.PrepareDisplayValue(const AEditValue:
TcxEditValue; var DisplayValue: TcxEditValue; AEditFocused: Boolean);
begin
DisplayValue := GetRadioGroupItemIndex(AEditValue);
end;
function TcxCustomRadioGroupProperties.CreateItems: TcxButtonGroupItems;
begin
Result := TcxRadioGroupItems.Create(Self, TcxRadioGroupItem);
end;
function TcxCustomRadioGroupProperties.GetColumnCount: Integer;
begin
Result := Columns;
if Result > Items.Count then
Result := Items.Count;
if Result = 0 then
Result := 1;
end;
class function TcxCustomRadioGroupProperties.GetViewDataClass: TcxCustomEditViewDataClass;
begin
Result := TcxCustomRadioGroupViewData;
end;
function TcxCustomRadioGroupProperties.HasDisplayValue: Boolean;
begin
Result := True;
end;
function TcxCustomRadioGroupProperties.GetItems: TcxRadioGroupItems;
begin
Result := TcxRadioGroupItems(inherited Items);
end;
function TcxCustomRadioGroupProperties.IsDefaultCaptionStored: Boolean;
begin
Result := not InternalCompareString(FDefaultCaption,
cxGetResourceString(@cxSRadioGroupDefaultCaption), True);
end;
function TcxCustomRadioGroupProperties.IsDefaultValueStored: Boolean;
begin
Result := not VarIsNull(FDefaultValue);
end;
procedure TcxCustomRadioGroupProperties.SetDefaultValue(const Value: TcxEditValue);
begin
if not InternalVarEqualsExact(Value, FDefaultValue) then
begin
FDefaultValue := Value;
Changed;
end;
end;
procedure TcxCustomRadioGroupProperties.SetItems(Value: TcxRadioGroupItems);
begin
inherited Items.Assign(Value);
end;
{ TcxCustomRadioGroupButton }
constructor TcxCustomRadioGroupButton.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
with TcxCustomRadioGroup(AOwner) do
begin
InternalButtons.Add(Self);
Self.LookAndFeel.MasterLookAndFeel := Style.LookAndFeel;
end;
end;
destructor TcxCustomRadioGroupButton.Destroy;
begin
RadioGroup.InternalButtons.Remove(Self);
inherited Destroy;
end;
function TcxCustomRadioGroupButton.ExecuteAction(Action: TBasicAction): Boolean;
begin
Result := inherited ExecuteAction(Action) or
RadioGroup.DataBinding.ExecuteAction(Action);
end;
function TcxCustomRadioGroupButton.UpdateAction(Action: TBasicAction): Boolean;
begin
Result := inherited UpdateAction(Action) or
RadioGroup.DataBinding.UpdateAction(Action);
end;
{$IFDEF DELPHI5}
function TcxCustomRadioGroupButton.CanFocus: Boolean;
begin
Result := RadioGroup.CanFocusEx;
end;
{$ENDIF}
procedure TcxCustomRadioGroupButton.DefaultHandler(var Message);
begin
if not RadioGroup.InnerControlDefaultHandler(TMessage(Message)) then
inherited DefaultHandler(Message);
end;
procedure TcxCustomRadioGroupButton.Click;
begin
inherited Click;
with RadioGroup do
if not IsLoading then
RadioGroup.Click;
end;
procedure TcxCustomRadioGroupButton.CorrectTextRect(var R: TRect; ANativeStyle: Boolean);
begin
inherited CorrectTextRect(R, ANativeStyle);
end;
procedure TcxCustomRadioGroupButton.DoEnter;
begin
with RadioGroup do
begin
ShortRefreshContainer(False);
if not Checked and not IsInplace and not FFocusingByMouse and DoEditing then
Checked := True;
end;
end;
procedure TcxCustomRadioGroupButton.DoExit;
begin
inherited DoExit;
RadioGroup.ShortRefreshContainer(False);
end;
procedure TcxCustomRadioGroupButton.DrawBackground;
var
APrevWindowOrg: TPoint;
begin
if RadioGroup.ViewInfo.IsCustomBackground then
begin
OffsetWindowOrgEx(Canvas.Handle, Left, Top, APrevWindowOrg);
try
RadioGroup.ViewInfo.DrawBackground(Canvas);
finally
SetWindowOrgEx(Canvas.Handle, APrevWindowOrg.X, APrevWindowOrg.Y, nil);
end;
end
else
if not IsTransparentBackground then
inherited DrawBackground;
end;
function TcxCustomRadioGroupButton.IsInplace: Boolean;
begin
Result := RadioGroup.IsInplace;
end;
function TcxCustomRadioGroupButton.IsNativeBackground: Boolean;
begin
Result := RadioGroup.IsNativeBackground;
end;
function TcxCustomRadioGroupButton.IsNativeStyle: Boolean;
begin
Result := RadioGroup.IsButtonNativeStyle;
end;
function TcxCustomRadioGroupButton.IsTransparent: Boolean;
begin
Result := RadioGroup.IsTransparent;
end;
function TcxCustomRadioGroupButton.IsTransparentBackground: Boolean;
begin
Result := inherited IsTransparentBackground or RadioGroup.ViewInfo.IsCustomBackground;
end;
procedure TcxCustomRadioGroupButton.KeyPress(var Key: Char);
begin
inherited KeyPress(Key);
if ((Key = #8) or (Key = ' ')) and not RadioGroup.CanModify then
Key := #0;
end;
procedure TcxCustomRadioGroupButton.Paint(ADrawOnlyFocusedState: Boolean);
procedure SetSkinsPaintCopy(AValue: Boolean);
begin
if RadioGroup <> nil then
RadioGroup.SkinsPaintCopy := AValue;
end;
function DrawByPainter(APainter: TcxCustomLookAndFeelPainterClass): Boolean;
var
ABitmap: TcxBitmap;
ARadioButtonSize: TSize;
begin
Result := APainter <> nil;
if Result then
begin
with ClientRect do
ABitmap := TcxBitmap.CreateSize(Right - Left, Bottom - Top);
ABitmap.PixelFormat := pf32bit;
try
SetSkinsPaintCopy(True);
try
cxDrawTransparentControlBackground(Self, ABitmap.cxCanvas, ClientRect);
finally
SetSkinsPaintCopy(False);
end;
ARadioButtonSize := APainter.RadioButtonSize;
FButtonRect := GetRadioButtonRect(ARadioButtonSize, IsNativeStyle);
with FButtonRect do
APainter.DrawRadioButton(ABitmap.cxCanvas, Left, Top, AButtonStateMap[State],
Checked, Focused, clNone, csDesigning in ComponentState);
DrawCaption(ABitmap.cxCanvas, IsNativeStyle);
Canvas.Draw(0, 0, ABitmap);
finally
ABitmap.Free;
end;
end;
end;
begin
if not DrawByPainter(LookAndFeel.SkinPainter) then
inherited Paint(ADrawOnlyFocusedState);
end;
procedure TcxCustomRadioGroupButton.SetChecked(Value: Boolean);
begin
if Value = Checked then
Exit;
ClicksDisabled := True;
try
inherited SetChecked(Value);
finally
ClicksDisabled := False;
end;
if Value and not FInternalSettingChecked then
RadioGroup.ButtonChecked(Self);
end;
procedure TcxCustomRadioGroupButton.WndProc(var Message: TMessage);
begin
if RadioGroup.InnerControlMenuHandler(Message) then
Exit;
if ((Message.Msg = WM_LBUTTONDOWN) or (Message.Msg = WM_LBUTTONDBLCLK)) and
(RadioGroup.DragMode = dmAutomatic) and not RadioGroup.IsDesigning then
RadioGroup.BeginAutoDrag
else
begin
if Message.Msg = WM_LBUTTONDOWN then
FFocusingByMouse := True;
inherited WndProc(Message);
if Message.Msg = WM_LBUTTONDOWN then
FFocusingByMouse := False;
end;
end;
// IcxContainerInnerControl
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?