win32: rewrite focusing while pages switching (bug #0012959)

git-svn-id: trunk@18233 -
This commit is contained in:
paul 2009-01-10 12:55:04 +00:00
parent 11f5a2759a
commit f7eda562c6

View File

@ -226,36 +226,27 @@ end;
procedure NotebookFocusNewControl(const ANotebook: TCustomNotebook; NewIndex: integer); procedure NotebookFocusNewControl(const ANotebook: TCustomNotebook; NewIndex: integer);
var var
Page: TCustomPage; Page: TCustomPage;
ControlList: TFPList; AWinControl: TWinControl;
lWinControl: TWinControl; ParentForm: TCustomForm;
I: integer;
FocusSet: Boolean;
begin begin
{ see if currently focused control is within notebook } { see if currently focused control is within notebook }
if not IsNotebookGroupFocused(ANotebook) then exit; if not IsNotebookGroupFocused(ANotebook) then exit;
{ focus was/is within notebook, pick a new control to focus } { focus was/is within notebook, pick a new control to focus }
Page := ANotebook.CustomPage(NewIndex); Page := ANotebook.CustomPage(NewIndex);
ControlList := TFPList.Create; ParentForm := GetParentForm(ANotebook);
try if ParentForm <> nil then
Page.GetTabOrderList(ControlList); begin
I := 0; if ANotebook.ContainsControl(ParentForm.ActiveControl) and (ParentForm.ActiveControl <> ANotebook) then
FocusSet := False;
while I < ControlList.Count do
begin begin
lWinControl := TWinControl(ControlList[I]); AWinControl := nil;
if lWinControl.TabStop and lWinControl.Enabled and lWinControl.CanFocus then if Page.CanFocus then
begin AWinControl := TCustomPageAccess(Page).FindNextControl(nil, True, True, False);
lWinControl.SetFocus; // if nothing to focus then focus notebook then we can traverse pages by keys
FocusSet := True; if AWinControl = nil then
break; AWinControl := ANotebook;
end; AWinControl.SetFocus;
Inc(I);
end; end;
if not FocusSet then
Page.SetFocus;
finally
ControlList.Free;
end; end;
end; end;