summaryrefslogtreecommitdiff
path: root/src/gui/gui_radiobutton.pas
diff options
context:
space:
mode:
authorgraemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf>2008-02-22 07:01:00 +0000
committergraemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf>2008-02-22 07:01:00 +0000
commit17ccab892612ec12ff7950b5ade495c053a344a2 (patch)
treec4e53a6dc33e0af3ca4c2e9b911232ef60882d01 /src/gui/gui_radiobutton.pas
parentf6b712988e8fa39e6a03480e93b72f69de5ecbb2 (diff)
downloadfpGUI-17ccab892612ec12ff7950b5ade495c053a344a2.tar.xz
Applied patch from Vladimir which improves the tab handling in the RadioButtons.
Diffstat (limited to 'src/gui/gui_radiobutton.pas')
-rw-r--r--src/gui/gui_radiobutton.pas113
1 files changed, 65 insertions, 48 deletions
diff --git a/src/gui/gui_radiobutton.pas b/src/gui/gui_radiobutton.pas
index 1bb2533d..9c90908b 100644
--- a/src/gui/gui_radiobutton.pas
+++ b/src/gui/gui_radiobutton.pas
@@ -197,10 +197,8 @@ procedure TfpgRadioButton.HandleLMouseUp(x, y: integer; shiftstate: TShiftState)
begin
inherited HandleLMouseUp(x, y, shiftstate);
FIsPressed := False;
- if not Checked then
- begin
- Checked := not FChecked;
- end
+ if not FChecked then
+ Checked := true
else
RePaint;
end;
@@ -210,23 +208,25 @@ procedure TfpgRadioButton.HandleKeyPress(var keycode: word;
var
nbr: TfpgRadioButton;
begin
- if (keycode = keyUp) then
- begin
- consumed := True;
- nbr := FindNeighbor(fsdPrev);
- if nbr = Self then
- nbr := FindNeighbor(fsdLast);
- nbr.SetFocus;
- nbr.Checked := True;
- end else
- if (keycode = keyDown) then
- begin
- consumed := True;
- nbr := FindNeighbor(fsdNext);
- if nbr = Self then
- nbr := FindNeighbor(fsdFirst);
- nbr.SetFocus;
- nbr.Checked := True;
+ case keycode of
+ keyUp, keyLeft:
+ begin
+ consumed := True;
+ nbr := FindNeighbor(fsdPrev);
+ if nbr = Self then
+ nbr := FindNeighbor(fsdLast);
+ nbr.SetFocus;
+ nbr.Checked := True;
+ end;
+ keyDown, keyRight:
+ begin
+ consumed := True;
+ nbr := FindNeighbor(fsdNext);
+ if nbr = Self then
+ nbr := FindNeighbor(fsdFirst);
+ nbr.SetFocus;
+ nbr.Checked := True;
+ end;
end;
if consumed then
@@ -253,51 +253,68 @@ end;
function TfpgRadioButton.FindNeighbor(direction: TFocusSearchDirection): TfpgRadioButton;
var
i: integer;
- wg, bestwg: TfpgWidget;
- bestdsp, dsp: integer; // spacing delta
+ wg: TfpgWidget;
+ bestdtab: integer;
+ FoundIt: boolean;
begin
+ Result := Self;
if (Parent <> nil) then
begin
- case direction of
- fsdNext: bestdsp := High(integer); // or "-999999" like that in TfpgWidget.FindFocusWidget?
- fsdPrev: bestdsp := Low(integer); // or "999999"?
- end;
-
- bestwg := Self;
+ FoundIt := False;
+ if direction in [fsdLast, fsdPrev] then
+ bestdtab := Low(integer) // or "-999999" like that in TfpgWidget.FindFocusWidget?
+ else
+ bestdtab := High(integer); // or "999999"?
+
for i := 0 to Parent.ComponentCount-1 do
begin
wg := TfpgWidget(Parent.Components[i]);
- if (wg <> nil) and (wg <> self) and (wg is TfpgRadioButton) and
- (TfpgRadioButton(wg).GroupIndex = GroupIndex) then
+ if (wg <> nil) and (wg is TfpgRadioButton) and
+ wg.Visible and wg.Enabled and wg.Focusable and
+ (TfpgRadioButton(wg).GroupIndex = GroupIndex) then
begin
case direction of
+ fsdFirst:
+ if (wg.TabOrder < bestdtab) then
+ begin
+ Result := TfpgRadioButton(wg);
+ bestdtab := wg.TabOrder;
+ end;
+
+ fsdLast:
+ if (wg.TabOrder >= bestdtab) then
+ begin
+ Result := TfpgRadioButton(wg);
+ bestdtab := wg.TabOrder;
+ end;
+
fsdNext:
+ if wg = Self then
+ FoundIt := True
+ else
begin
- dsp := (wg.Top - Self.Top) + (wg.Left - Self.Left);
- if (dsp > 0) and (dsp < bestdsp) then
+ if ((wg.TabOrder > Self.TabOrder) and (wg.TabOrder < bestdtab)) or
+ ((wg.TabOrder = Self.TabOrder) and FoundIt) then
begin
- bestwg := wg;
- bestdsp := dsp;
+ Result := TfpgRadioButton(wg);
+ bestdtab := wg.TabOrder;
end;
end;
+
fsdPrev:
+ if wg = Self then
+ FoundIt := True
+ else
begin
- dsp := (wg.Top - Self.Top) + (wg.Left - Self.Left);
- if (dsp < 0) and (dsp > bestdsp) then
+ if ((wg.TabOrder < Self.TabOrder) and (wg.TabOrder >= bestdtab)) or
+ ((wg.TabOrder = Self.TabOrder) and not FoundIt) then
begin
- bestwg := wg;
- bestdsp := dsp;
+ Result := TfpgRadioButton(wg);
+ bestdtab := wg.TabOrder;
end;
end;
- fsdFirst:
- if (wg.Top < bestwg.Top) then
- bestwg := wg;
- fsdLast:
- if (wg.Top > bestwg.Top) then
- bestwg := wg;
- end;
- Result := TfpgRadioButton(bestwg);
- end;
+ end; { case }
+ end; { if }
end; { for }
end; { if }
end;