mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-14 09:59:20 +02:00
fixed TRadioGroup.ItemIndex=-1
git-svn-id: trunk@3949 -
This commit is contained in:
parent
5a75290b61
commit
48e0c94e7a
@ -161,8 +161,9 @@ end;
|
|||||||
------------------------------------------------------------------------------}
|
------------------------------------------------------------------------------}
|
||||||
procedure TCustomCheckBox.ApplyChanges;
|
procedure TCustomCheckBox.ApplyChanges;
|
||||||
begin
|
begin
|
||||||
if HandleAllocated and (not (csLoading in ComponentState)) then
|
if HandleAllocated and (not (csLoading in ComponentState)) then begin
|
||||||
CNSendMessage(LM_SetValue,Self,@fState);
|
CNSendMessage(LM_SetValue,Self,@fState);
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCustomCheckBox.SetText(const Value: TCaption);
|
procedure TCustomCheckBox.SetText(const Value: TCaption);
|
||||||
@ -185,6 +186,9 @@ begin
|
|||||||
end;
|
end;
|
||||||
{
|
{
|
||||||
$Log$
|
$Log$
|
||||||
|
Revision 1.11 2003/03/17 20:50:30 mattias
|
||||||
|
fixed TRadioGroup.ItemIndex=-1
|
||||||
|
|
||||||
Revision 1.10 2003/03/09 17:44:12 mattias
|
Revision 1.10 2003/03/09 17:44:12 mattias
|
||||||
finshed Make Resourcestring dialog and implemented TToggleBox
|
finshed Make Resourcestring dialog and implemented TToggleBox
|
||||||
|
|
||||||
|
@ -82,8 +82,9 @@ end;
|
|||||||
------------------------------------------------------------------------------}
|
------------------------------------------------------------------------------}
|
||||||
destructor TCustomRadioGroup.Destroy;
|
destructor TCustomRadioGroup.Destroy;
|
||||||
begin
|
begin
|
||||||
FItems.Free;
|
FreeAndNil(FItems);
|
||||||
FButtonList.Free;
|
FreeAndNil(FButtonList);
|
||||||
|
FreeAndNil(FHiddenButton);
|
||||||
inherited Destroy;
|
inherited Destroy;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -118,6 +119,13 @@ begin
|
|||||||
Temp.OnClick := @Clicked;
|
Temp.OnClick := @Clicked;
|
||||||
FButtonList.Add(Temp);
|
FButtonList.Add(Temp);
|
||||||
end;
|
end;
|
||||||
|
if FHiddenButton=nil then begin
|
||||||
|
FHiddenButton:=TRadioButton.Create(nil);
|
||||||
|
with FHiddenButton do begin
|
||||||
|
Name:='HiddenRadioButton';
|
||||||
|
Visible:=false;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
//writeln('[TCustomRadioGroup.CreateWnd] C ',Name,':',ClassName,' FItems.Count=',FItems.Count,' HandleAllocated=',HandleAllocated);
|
//writeln('[TCustomRadioGroup.CreateWnd] C ',Name,':',ClassName,' FItems.Count=',FItems.Count,' HandleAllocated=',HandleAllocated);
|
||||||
if (FItemIndex>=FItems.Count) then FItemIndex:=FItems.Count-1;
|
if (FItemIndex>=FItems.Count) then FItemIndex:=FItems.Count-1;
|
||||||
@ -132,6 +140,12 @@ begin
|
|||||||
Temp.Caption := FItems[i];
|
Temp.Caption := FItems[i];
|
||||||
Temp.Parent := Self;
|
Temp.Parent := Self;
|
||||||
end;
|
end;
|
||||||
|
with FHiddenButton do begin
|
||||||
|
FHiddenButton.Visible:=false;
|
||||||
|
Parent:=Self;
|
||||||
|
FHiddenButton.CreateHandle;
|
||||||
|
end;
|
||||||
|
|
||||||
DoPositionButtons;
|
DoPositionButtons;
|
||||||
|
|
||||||
for i:=0 to FItems.Count-1 do begin
|
for i:=0 to FItems.Count-1 do begin
|
||||||
@ -139,6 +153,7 @@ begin
|
|||||||
Temp.Checked := (i = FItemIndex);
|
Temp.Checked := (i = FItemIndex);
|
||||||
Temp.Visible := true;
|
Temp.Visible := true;
|
||||||
end;
|
end;
|
||||||
|
FHiddenButton.Checked:=(fItemIndex=-1);
|
||||||
end;
|
end;
|
||||||
//writeln('[TCustomRadioGroup.CreateWnd] F ',Name,':',ClassName,' FItems.Count=',FItems.Count,' HandleAllocated=',HandleAllocated,' ItemIndex=',ItemIndex);
|
//writeln('[TCustomRadioGroup.CreateWnd] F ',Name,':',ClassName,' FItems.Count=',FItems.Count,' HandleAllocated=',HandleAllocated,' ItemIndex=',ItemIndex);
|
||||||
|
|
||||||
@ -203,7 +218,7 @@ end;
|
|||||||
|
|
||||||
Select one of the radiobuttons
|
Select one of the radiobuttons
|
||||||
------------------------------------------------------------------------------}
|
------------------------------------------------------------------------------}
|
||||||
procedure TCustomRadioGroup.SetItemIndex (Value : integer);
|
procedure TCustomRadioGroup.SetItemIndex(Value : integer);
|
||||||
begin
|
begin
|
||||||
if Value = FItemIndex then exit;
|
if Value = FItemIndex then exit;
|
||||||
if FReading then
|
if FReading then
|
||||||
@ -214,11 +229,17 @@ begin
|
|||||||
|
|
||||||
if (HandleAllocated) then
|
if (HandleAllocated) then
|
||||||
begin
|
begin
|
||||||
|
// the radiobuttons are grouped by the widget interface
|
||||||
|
// and some does not allow to uncheck all buttons in a group
|
||||||
|
// Therefore there is a hidden button
|
||||||
|
FItemIndex:=Value;
|
||||||
if (FItemIndex <> -1) then
|
if (FItemIndex <> -1) then
|
||||||
TRadioButton (FButtonList [FItemIndex]).Checked := false;
|
TRadioButton(FButtonList[FitemIndex]).Checked := true
|
||||||
FItemIndex := Value;
|
else
|
||||||
if (Value <> -1) then
|
FHiddenButton.Checked:=true;
|
||||||
TRadioButton (FButtonList [Value]).Checked := true;
|
// this has automatically unset the old button. But they do not recognize
|
||||||
|
// it. Update the states.
|
||||||
|
UpdateRadioButtonStates;
|
||||||
|
|
||||||
OwnerFormDesignerModified(Self);
|
OwnerFormDesignerModified(Self);
|
||||||
end
|
end
|
||||||
@ -235,22 +256,7 @@ end;
|
|||||||
Retrieve the index of the radiobutton currently selected.
|
Retrieve the index of the radiobutton currently selected.
|
||||||
------------------------------------------------------------------------------}
|
------------------------------------------------------------------------------}
|
||||||
function TCustomRadioGroup.GetItemIndex : integer;
|
function TCustomRadioGroup.GetItemIndex : integer;
|
||||||
var
|
|
||||||
i: integer;
|
|
||||||
begin
|
begin
|
||||||
if (HandleAllocated) then
|
|
||||||
begin
|
|
||||||
i := FButtonList.Count-1;
|
|
||||||
// This nasty little loop is neccessary because the group is not informed
|
|
||||||
// when a button is pressed
|
|
||||||
while (i>=0) do
|
|
||||||
begin // find the actice button
|
|
||||||
if TRadioButton (FButtonList [i]).Checked
|
|
||||||
then break;
|
|
||||||
dec (i);
|
|
||||||
end;
|
|
||||||
FItemIndex := i;
|
|
||||||
end;
|
|
||||||
Result := FItemIndex;
|
Result := FItemIndex;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -303,8 +309,8 @@ end;
|
|||||||
------------------------------------------------------------------------------}
|
------------------------------------------------------------------------------}
|
||||||
Procedure TCustomRadioGroup.Clicked(Sender : TObject);
|
Procedure TCustomRadioGroup.Clicked(Sender : TObject);
|
||||||
Begin
|
Begin
|
||||||
GetItemIndex;
|
|
||||||
if FCreatingWnd then exit;
|
if FCreatingWnd then exit;
|
||||||
|
UpdateRadioButtonStates;
|
||||||
if Assigned (FOnClick) then FOnClick(Self);
|
if Assigned (FOnClick) then FOnClick(Self);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -337,7 +343,7 @@ begin
|
|||||||
Temp.SetBounds(nextLeft,nextTop,rbWidth,vertDist);
|
Temp.SetBounds(nextLeft,nextTop,rbWidth,vertDist);
|
||||||
|
|
||||||
inc (i);
|
inc (i);
|
||||||
if (i MOD FColumns) = 0 then begin
|
if (i mod FColumns) = 0 then begin
|
||||||
inc(nextTop, vertDist);
|
inc(nextTop, vertDist);
|
||||||
nextLeft := 10;
|
nextLeft := 10;
|
||||||
end else begin
|
end else begin
|
||||||
@ -347,8 +353,24 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{------------------------------------------------------------------------------
|
||||||
|
procedure TCustomRadioGroup.UpdateRadioButtonStates;
|
||||||
|
------------------------------------------------------------------------------}
|
||||||
|
procedure TCustomRadioGroup.UpdateRadioButtonStates;
|
||||||
|
var
|
||||||
|
i: Integer;
|
||||||
|
begin
|
||||||
|
FItemIndex:=-1;
|
||||||
|
FHiddenButton.Checked;
|
||||||
|
for i:=0 to FButtonList.Count-1 do
|
||||||
|
if TRadioButton(FButtonList[i]).Checked then FItemIndex:=i;
|
||||||
|
end;
|
||||||
|
|
||||||
{
|
{
|
||||||
$Log$
|
$Log$
|
||||||
|
Revision 1.19 2003/03/17 20:50:30 mattias
|
||||||
|
fixed TRadioGroup.ItemIndex=-1
|
||||||
|
|
||||||
Revision 1.18 2003/03/17 09:41:52 mattias
|
Revision 1.18 2003/03/17 09:41:52 mattias
|
||||||
fixed TCustomRadioGroup.SetItemIndex
|
fixed TCustomRadioGroup.SetItemIndex
|
||||||
|
|
||||||
|
@ -53,6 +53,7 @@ constructor TRadioButton.Create(AnOwner : TComponent);
|
|||||||
begin
|
begin
|
||||||
inherited Create(AnOwner);
|
inherited Create(AnOwner);
|
||||||
fCompStyle := csRadioButton;
|
fCompStyle := csRadioButton;
|
||||||
|
fAutoGroup:=true;
|
||||||
AutoSize := True;
|
AutoSize := True;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -67,8 +68,37 @@ procedure TRadioButton.SetText(const Value: TCaption);
|
|||||||
begin
|
begin
|
||||||
if Text=Value then exit;
|
if Text=Value then exit;
|
||||||
Inherited SetText(Value);
|
Inherited SetText(Value);
|
||||||
RecreateWnd;
|
if not (csLoading in ComponentState) then begin
|
||||||
DoAutoSize;
|
RecreateWnd;
|
||||||
|
DoAutoSize;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
{------------------------------------------------------------------------------
|
||||||
|
function TRadioButton.GetAutoGroup: boolean;
|
||||||
|
------------------------------------------------------------------------------}
|
||||||
|
function TRadioButton.GetAutoGroup: boolean;
|
||||||
|
begin
|
||||||
|
Result:=fAutoGroup;
|
||||||
|
end;
|
||||||
|
|
||||||
|
{------------------------------------------------------------------------------
|
||||||
|
function TRadioButton.AutoGroupIsStored: boolean;
|
||||||
|
------------------------------------------------------------------------------}
|
||||||
|
function TRadioButton.AutoGroupIsStored: boolean;
|
||||||
|
begin
|
||||||
|
Result:=fAutoGroup;
|
||||||
|
end;
|
||||||
|
|
||||||
|
{------------------------------------------------------------------------------
|
||||||
|
procedure TRadioButton.SetAutoGroup(const AValue: boolean);
|
||||||
|
------------------------------------------------------------------------------}
|
||||||
|
procedure TRadioButton.SetAutoGroup(const AValue: boolean);
|
||||||
|
begin
|
||||||
|
if AValue=fAutoGroup then exit;
|
||||||
|
fAutoGroup:=AValue;
|
||||||
|
if (not HandleAllocated) or (csLoading in ComponentState) then exit;
|
||||||
|
SetRadioButtonGroupMode(Handle,fAutoGroup);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{------------------------------------------------------------------------------
|
{------------------------------------------------------------------------------
|
||||||
@ -106,6 +136,9 @@ end;
|
|||||||
|
|
||||||
{
|
{
|
||||||
$Log$
|
$Log$
|
||||||
|
Revision 1.12 2003/03/17 20:50:30 mattias
|
||||||
|
fixed TRadioGroup.ItemIndex=-1
|
||||||
|
|
||||||
Revision 1.11 2002/11/27 15:40:36 mattias
|
Revision 1.11 2002/11/27 15:40:36 mattias
|
||||||
fixed resize request
|
fixed resize request
|
||||||
|
|
||||||
|
@ -806,6 +806,11 @@ type
|
|||||||
{TRadioButton}
|
{TRadioButton}
|
||||||
|
|
||||||
TRadioButton = class(TCustomCheckBox)
|
TRadioButton = class(TCustomCheckBox)
|
||||||
|
private
|
||||||
|
fAutoGroup: boolean;
|
||||||
|
function AutoGroupIsStored: boolean;
|
||||||
|
function GetAutoGroup: boolean;
|
||||||
|
procedure SetAutoGroup(const AValue: boolean);
|
||||||
protected
|
protected
|
||||||
procedure DoAutoSize; override;
|
procedure DoAutoSize; override;
|
||||||
procedure SetText(const Value: TCaption); override;
|
procedure SetText(const Value: TCaption); override;
|
||||||
@ -813,6 +818,8 @@ type
|
|||||||
constructor Create (AnOwner: TComponent); override;
|
constructor Create (AnOwner: TComponent); override;
|
||||||
published
|
published
|
||||||
property Anchors;
|
property Anchors;
|
||||||
|
property AutoGroup: boolean read GetAutoGroup write SetAutoGroup
|
||||||
|
stored AutoGroupIsStored;
|
||||||
property AutoSize;
|
property AutoSize;
|
||||||
property AllowGrayed;
|
property AllowGrayed;
|
||||||
property Caption;
|
property Caption;
|
||||||
@ -1395,6 +1402,9 @@ end.
|
|||||||
{ =============================================================================
|
{ =============================================================================
|
||||||
|
|
||||||
$Log$
|
$Log$
|
||||||
|
Revision 1.81 2003/03/17 20:50:30 mattias
|
||||||
|
fixed TRadioGroup.ItemIndex=-1
|
||||||
|
|
||||||
Revision 1.80 2003/03/17 08:51:09 mattias
|
Revision 1.80 2003/03/17 08:51:09 mattias
|
||||||
added IsWindowVisible
|
added IsWindowVisible
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user