mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-10-01 14:49:56 +02:00
lcl: don't explicitly set ActiveControl in TCustomForm LM_SETFOCUS handler
git-svn-id: trunk@25311 -
This commit is contained in:
parent
244c234887
commit
c7ce02bc66
@ -796,7 +796,8 @@ end;
|
|||||||
{------------------------------------------------------------------------------
|
{------------------------------------------------------------------------------
|
||||||
Method: TCustomForm.DefocusControl
|
Method: TCustomForm.DefocusControl
|
||||||
Params: Control: the control which is to be defocused
|
Params: Control: the control which is to be defocused
|
||||||
Removing: is it to be defocused because it is being removed?
|
Removing: is it to be defocused because it is being removed
|
||||||
|
(destructed or changed parent).
|
||||||
Returns: nothing
|
Returns: nothing
|
||||||
|
|
||||||
Updates ActiveControl if it is to be defocused
|
Updates ActiveControl if it is to be defocused
|
||||||
@ -1229,8 +1230,9 @@ procedure TCustomForm.WndProc(var TheMessage : TLMessage);
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
var
|
var
|
||||||
FocusHandle : HWND;
|
NewActiveControl: TWinControl;
|
||||||
MenuItem : TMenuItem;
|
NewFocus: HWND;
|
||||||
|
MenuItem: TMenuItem;
|
||||||
begin
|
begin
|
||||||
//debugln(['TCustomForm.WndProc ',dbgsname(Self)]);
|
//debugln(['TCustomForm.WndProc ',dbgsname(Self)]);
|
||||||
with TheMessage do
|
with TheMessage do
|
||||||
@ -1240,16 +1242,19 @@ begin
|
|||||||
if (Msg = LM_SETFOCUS) and not (csDesigning in ComponentState) then
|
if (Msg = LM_SETFOCUS) and not (csDesigning in ComponentState) then
|
||||||
begin
|
begin
|
||||||
//DebugLn(['TCustomForm.WndProc ',DbgSName(Self),' FActiveControl=',DbgSName(FActiveControl)]);
|
//DebugLn(['TCustomForm.WndProc ',DbgSName(Self),' FActiveControl=',DbgSName(FActiveControl)]);
|
||||||
FocusHandle := 0;
|
NewActiveControl := nil;
|
||||||
|
NewFocus := 0;
|
||||||
|
|
||||||
if (ActiveControl = nil) and (not (csDesigning in ComponentState))
|
if (ActiveControl = nil) and (not (csDesigning in ComponentState)) and (Parent=nil) then
|
||||||
and (Parent=nil) then begin
|
begin
|
||||||
// automatically choose a control to focus
|
// automatically choose a control to focus
|
||||||
{$IFDEF VerboseFocus}
|
{$IFDEF VerboseFocus}
|
||||||
DebugLn('TCustomForm.WndProc ',DbgSName(Self),' Set ActiveControl := ',DbgSName(FindDefaultForActiveControl));
|
DebugLn('TCustomForm.WndProc ',DbgSName(Self),' Set ActiveControl := ',DbgSName(FindDefaultForActiveControl));
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
ActiveControl := FindDefaultForActiveControl;
|
NewActiveControl := FindDefaultForActiveControl;
|
||||||
end;
|
end
|
||||||
|
else
|
||||||
|
NewActiveControl := ActiveControl;
|
||||||
|
|
||||||
if FormStyle = fsMDIFORM then
|
if FormStyle = fsMDIFORM then
|
||||||
begin
|
begin
|
||||||
@ -1257,25 +1262,25 @@ begin
|
|||||||
end
|
end
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
if (FActiveControl <> nil) and (FActiveControl <> Self)
|
if (NewActiveControl <> nil) and (NewActiveControl <> Self) and
|
||||||
and FActiveControl.IsVisible and FActiveControl.Enabled
|
NewActiveControl.IsVisible and NewActiveControl.Enabled and
|
||||||
and ([csLoading,csDestroying]*ComponentState=[])
|
([csLoading,csDestroying]*NewActiveControl.ComponentState=[]) and
|
||||||
and not FActiveControl.ParentDestroyingHandle
|
not NewActiveControl.ParentDestroyingHandle then
|
||||||
then begin
|
begin
|
||||||
// get or create handle of FActiveControl
|
// get or create handle of FActiveControl
|
||||||
FocusHandle := FActiveControl.Handle;
|
NewFocus := NewActiveControl.Handle;
|
||||||
//debugln('TCustomForm.WndProc A ',DbgSName(Self),' FActiveControl=',DbgSName(FActiveControl),' FocusHandle=',dbgs(FocusHandle));
|
//debugln('TCustomForm.WndProc A ',DbgSName(Self),' FActiveControl=',DbgSName(FActiveControl),' FocusHandle=',dbgs(FocusHandle));
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
TheMessage.Result:=0;
|
TheMessage.Result := 0;
|
||||||
if FocusHandle <> 0
|
if NewFocus <> 0 then
|
||||||
then begin
|
begin
|
||||||
// redirect focus to child
|
// redirect focus to child
|
||||||
{$IFDEF VerboseFocus}
|
{$IFDEF VerboseFocus}
|
||||||
DebugLn('[TCustomForm.WndProc] ',Name,':',ClassName,' FActiveControl=',DbgSName(FActiveControl));
|
DebugLn('[TCustomForm.WndProc] ',Name,':',ClassName,' FActiveControl=',DbgSName(FActiveControl));
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
LCLIntf.SetFocus(FocusHandle);
|
LCLIntf.SetFocus(NewFocus);
|
||||||
if not ContainsForm(Self) then exit;
|
if not ContainsForm(Self) then exit;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
Loading…
Reference in New Issue
Block a user