lcl: use correct method to restore Default and Cancel of TCustomButton (Loaded instead of SetParent), remove TButtonPanel.RestoreCancel workaround

git-svn-id: trunk@18460 -
This commit is contained in:
paul 2009-01-27 06:39:18 +00:00
parent e3f461ec5f
commit 5980abdcec
4 changed files with 20 additions and 35 deletions

View File

@ -61,7 +61,6 @@ type
FSpacing: TSpacingSize; FSpacing: TSpacingSize;
procedure CreateButton(AButton: TPanelButton); procedure CreateButton(AButton: TPanelButton);
procedure DoDefaultButton; procedure DoDefaultButton;
procedure DoRestoreCancel;
procedure DoShowButtons; procedure DoShowButtons;
procedure DoShowGlyphs; procedure DoShowGlyphs;
procedure SetButtonOrder(Value: TButtonOrder); procedure SetButtonOrder(Value: TButtonOrder);
@ -317,15 +316,6 @@ begin
end; end;
end; end;
procedure TCustomButtonPanel.DoRestoreCancel;
begin
if FButtons[pbCancel] = nil then Exit;
// to restore cancel button we need to do this hack
FButtons[pbCancel].Cancel := False;
FButtons[pbCancel].Cancel := True;
end;
procedure TCustomButtonPanel.SetDefaultButton(Value: TPanelButton); procedure TCustomButtonPanel.SetDefaultButton(Value: TPanelButton);
begin begin
if FDefaultButton = Value then if FDefaultButton = Value then
@ -359,7 +349,6 @@ procedure TCustomButtonPanel.Loaded;
begin begin
inherited Loaded; inherited Loaded;
DoRestoreCancel;
Realign; Realign;
end; end;

View File

@ -58,32 +58,11 @@ begin
inherited ControlKeyDown(Key, Shift); inherited ControlKeyDown(Key, Shift);
end; end;
procedure TCustomButton.ControlKeyUp(var Key: Word; Shift: TShiftState procedure TCustomButton.ControlKeyUp(var Key: Word; Shift: TShiftState);
);
begin begin
inherited ControlKeyUp(Key, Shift); inherited ControlKeyUp(Key, Shift);
end; end;
{------------------------------------------------------------------------------
procedure TCustomButton.SetParent(AParent: TWinControl);
------------------------------------------------------------------------------}
procedure TCustomButton.SetParent(AParent: TWinControl);
var
Form: TCustomForm;
begin
if Parent=AParent then exit;
inherited SetParent(AParent);
Form := GetParentForm(Self);
if Form <> nil then
begin
if FDefault then
Form.DefaultControl := Self;
if FCancel then
Form.CancelControl := Self;
end;
WSSetDefault;
end;
procedure TCustomButton.UpdateRolesForForm; procedure TCustomButton.UpdateRolesForForm;
var var
AForm: TCustomForm; AForm: TCustomForm;
@ -304,6 +283,23 @@ begin
inherited TextChanged; inherited TextChanged;
end; end;
procedure TCustomButton.Loaded;
var
Form: TCustomForm;
begin
inherited Loaded;
Form := GetParentForm(Self);
if Form <> nil then
begin
if FDefault then
Form.DefaultControl := Self;
if FCancel then
Form.CancelControl := Self;
end;
WSSetDefault;
end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
procedure TCustomButton.DoSendBtnDefault; procedure TCustomButton.DoSendBtnDefault;
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}

View File

@ -3144,7 +3144,7 @@ end;
TControl SetParentComponent TControl SetParentComponent
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
procedure TControl.SetParentComponent(NewParentComponent: TComponent); procedure TControl.SetParentComponent(NewParentComponent: TComponent);
Begin begin
if (NewParentComponent is TWinControl) then if (NewParentComponent is TWinControl) then
SetParent(TWinControl(NewParentComponent)); SetParent(TWinControl(NewParentComponent));
end; end;

View File

@ -1060,7 +1060,6 @@ type
procedure CreateWnd; override; procedure CreateWnd; override;
procedure ControlKeyDown(var Key: Word; Shift: TShiftState); override; procedure ControlKeyDown(var Key: Word; Shift: TShiftState); override;
procedure ControlKeyUp(var Key: Word; Shift: TShiftState); override; procedure ControlKeyUp(var Key: Word; Shift: TShiftState); override;
procedure SetParent(AParent: TWinControl); override;
function DialogChar(var Message: TLMKey): boolean; override; function DialogChar(var Message: TLMKey): boolean; override;
function ChildClassAllowed(ChildClass: TClass): boolean; override; function ChildClassAllowed(ChildClass: TClass): boolean; override;
class function GetControlClassDefaultSize: TPoint; override; class function GetControlClassDefaultSize: TPoint; override;
@ -1068,6 +1067,7 @@ type
procedure WSSetDefault; procedure WSSetDefault;
procedure WSSetText(const AText: String); override; procedure WSSetText(const AText: String); override;
procedure TextChanged; override; procedure TextChanged; override;
procedure Loaded; override;
public public
constructor Create(TheOwner: TComponent); override; constructor Create(TheOwner: TComponent); override;
procedure ExecuteDefaultAction; override; procedure ExecuteDefaultAction; override;