improved focus debugging output

git-svn-id: trunk@3953 -
This commit is contained in:
mattias 2003-03-18 13:04:25 +00:00
parent 9c042310fa
commit 002ca709d8
3 changed files with 135 additions and 89 deletions

View File

@ -337,7 +337,7 @@ begin
end; end;
fReplaceAllClickedLast:=false; fReplaceAllClickedLast:=false;
TextToFindComboBox.SetFocus; ActiveControl:=TextToFindComboBox;
end; end;
destructor TLazFindReplaceDialog.Destroy; destructor TLazFindReplaceDialog.Destroy;
@ -376,7 +376,7 @@ procedure TLazFindReplaceDialog.OkButtonClick(Sender:TObject);
begin begin
if not CheckInput then exit; if not CheckInput then exit;
fReplaceAllClickedLast:=false; fReplaceAllClickedLast:=false;
TextToFindComboBox.SetFocus; ActiveControl:=TextToFindComboBox;
ModalResult:=mrOk; ModalResult:=mrOk;
end; end;
@ -384,13 +384,13 @@ procedure TLazFindReplaceDialog.ReplaceAllButtonClick(Sender:TObject);
begin begin
if not CheckInput then exit; if not CheckInput then exit;
fReplaceAllClickedLast:=true; fReplaceAllClickedLast:=true;
TextToFindComboBox.SetFocus; ActiveControl:=TextToFindComboBox;
ModalResult:=mrAll; ModalResult:=mrAll;
end; end;
procedure TLazFindReplaceDialog.CancelButtonClick(Sender:TObject); procedure TLazFindReplaceDialog.CancelButtonClick(Sender:TObject);
begin begin
TextToFindComboBox.SetFocus; ActiveControl:=TextToFindComboBox;
ModalResult:=mrCancel; ModalResult:=mrCancel;
end; end;

View File

@ -277,6 +277,7 @@ type
procedure SetMenu(Value : TMainMenu); procedure SetMenu(Value : TMainMenu);
procedure SetFormStyle(Value : TFormStyle); procedure SetFormStyle(Value : TFormStyle);
procedure SetIcon(AValue: TIcon); procedure SetIcon(AValue: TIcon);
procedure SetModalResult(const AValue: TModalResult);
procedure SetPosition(Value : TPosition); procedure SetPosition(Value : TPosition);
procedure SetVisible(Value: boolean); procedure SetVisible(Value: boolean);
procedure SetWindowFocus; procedure SetWindowFocus;
@ -349,10 +350,10 @@ type
function WantChildKey(Child : TControl; function WantChildKey(Child : TControl;
var Message : TLMessage): Boolean; virtual; var Message : TLMessage): Boolean; virtual;
procedure SetFocus; override; procedure SetFocus; override;
function SetFocusedControl(Control : TWinControl): Boolean ; Virtual; function SetFocusedControl(Control: TWinControl): Boolean ; Virtual;
procedure FocusControl(WinControl : TWinControl); procedure FocusControl(WinControl: TWinControl);
function ShowModal : Integer; function ShowModal : Integer;
property Active : Boolean read FActive; property Active: Boolean read FActive;
property BorderStyle : TFormBorderStyle property BorderStyle : TFormBorderStyle
read FBorderStyle write SetBorderStyle default bsSizeable; read FBorderStyle write SetBorderStyle default bsSizeable;
property Caption stored IsForm; property Caption stored IsForm;
@ -361,7 +362,7 @@ type
property FormState : TFormState read FFormState; property FormState : TFormState read FFormState;
property KeyPreview: Boolean read FKeyPreview write FKeyPreview; property KeyPreview: Boolean read FKeyPreview write FKeyPreview;
property Menu : TMainMenu read FMenu write SetMenu; property Menu : TMainMenu read FMenu write SetMenu;
property ModalResult : TModalResult read FModalResult write FModalResult; property ModalResult : TModalResult read FModalResult write SetModalResult;
property Visible write SetVisible default False; property Visible write SetVisible default False;
property WindowState: TWindowState read FWindowState write SetWindowState property WindowState: TWindowState read FWindowState write SetWindowState
default wsNormal; default wsNormal;

View File

@ -137,7 +137,6 @@ begin
if not WasActive then SetFocus; if not WasActive then SetFocus;
End; End;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
Method: TCustomForm.Notification Method: TCustomForm.Notification
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
@ -195,6 +194,15 @@ begin
FIcon.Assign(AValue); FIcon.Assign(AValue);
end; end;
{------------------------------------------------------------------------------
procedure TCustomForm.SetModalResult(const AValue: TModalResult);
------------------------------------------------------------------------------}
procedure TCustomForm.SetModalResult(const AValue: TModalResult);
begin
if FModalResult=AValue then exit;
FModalResult:=AValue;
end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
Method: TCustomForm.IsIconStored Method: TCustomForm.IsIconStored
Returns: if form icon should be stored in the stream Returns: if form icon should be stored in the stream
@ -222,16 +230,17 @@ end;
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
Procedure TCustomForm.SetFocus; Procedure TCustomForm.SetFocus;
Begin Begin
//writeln('[TCustomForm.SetFocus] A ',Classname); {$IFDEF VerboseFocus}
//if not(Visible and Enabled) then Exit; writeln('TCustomForm.SetFocus ',Name,':',ClassName);
{$ENDIF}
if not (Visible and Enabled and HandleAllocated) then Exit;
if HandleAllocated then if HandleAllocated then
CNSendMessage(LM_SETFOCUS,Self,nil); CNSendMessage(LM_SETFOCUS,Self,nil);
//writeln('[TCustomForm.SetFocus] END ',Classname);
end; end;
{------------------------------------------------------------------------------} {------------------------------------------------------------------------------
{ TCustomForm SetVisible } TCustomForm SetVisible
{------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
Procedure TCustomForm.SetVisible(Value : boolean); Procedure TCustomForm.SetVisible(Value : boolean);
Begin Begin
//writeln('[TCustomForm.SetVisible] START2 ',Name,':',ClassName,' ',Value,' ',(fsCreating in FFormState),' ',FormUpdating); //writeln('[TCustomForm.SetVisible] START2 ',Name,':',ClassName,' ',Value,' ',(fsCreating in FFormState),' ',FormUpdating);
@ -265,7 +274,10 @@ begin
' NewFocusControl=',NewFocusControl.Name,':',NewFocusControl.ClassName, ' NewFocusControl=',NewFocusControl.Name,':',NewFocusControl.ClassName,
' HndAlloc=',NewFocusControl.HandleAllocated); ' HndAlloc=',NewFocusControl.HandleAllocated);
{$ENDIF} {$ENDIF}
if not NewFocusControl.HandleAllocated then exit; if (not NewFocusControl.HandleAllocated)
or (not NewFocusControl.Visible)
or (not NewFocusControl.Enabled) then
exit;
LCLLinux.SetFocus(NewFocusControl.Handle); LCLLinux.SetFocus(NewFocusControl.Handle);
if GetFocus = NewFocusControl.Handle then if GetFocus = NewFocusControl.Handle then
NewFocusControl.Perform(CM_UIACTIVATE, 0, 0); NewFocusControl.Perform(CM_UIACTIVATE, 0, 0);
@ -283,7 +295,7 @@ const
SHOW_TEXT: array[Boolean] of string = ('Hide', 'Show'); SHOW_TEXT: array[Boolean] of string = ('Hide', 'Show');
begin begin
{$IFDEF VerboseFocus} {$IFDEF VerboseFocus}
write('TCustomForm.WMShowWindow A ',Name,':',ClassName,' fsShowing in FFormState=',fsShowing in FFormState,' Message.Show=',Message.Show); write('TCustomForm.WMShowWindow A ',Name,':',ClassName,' fsShowing=',fsShowing in FFormState,' Msg.Show=',Message.Show);
if FActiveControl<>nil then begin if FActiveControl<>nil then begin
write(' FActiveControl=',FActiveControl.Name,':',FActiveControl.ClassName,' HandleAllocated=',FActiveControl.HandleAllocated); write(' FActiveControl=',FActiveControl.Name,':',FActiveControl.ClassName,' HandleAllocated=',FActiveControl.HandleAllocated);
end else begin end else begin
@ -295,7 +307,8 @@ begin
Include(FFormState, fsShowing); Include(FFormState, fsShowing);
try try
if Message.Show then begin if Message.Show then begin
if (FActiveControl<>nil) and FActiveControl.HandleAllocated then begin if (FActiveControl<>nil) and FActiveControl.HandleAllocated
and (FActiveControl.Visible) and (FActiveControl.Enabled) then begin
{$IFDEF VerboseFocus} {$IFDEF VerboseFocus}
writeln('TCustomForm.WMShowWindow B ',FActiveControl.Name,':',FActiveControl.ClassName); writeln('TCustomForm.WMShowWindow B ',FActiveControl.Name,':',FActiveControl.ClassName);
{$ENDIF} {$ENDIF}
@ -320,11 +333,18 @@ end;
procedure TCustomForm.WMActivate(var Message : TLMActivate); procedure TCustomForm.WMActivate(var Message : TLMActivate);
begin begin
{$IFDEF VerboseFocus} {$IFDEF VerboseFocus}
writeln('TCustomForm.WMActivate ',Name,':',ClassName,' ',Message.Active); writeln('TCustomForm.WMActivate A ',Name,':',ClassName,' Msg.Active=',Message.Active);
{$ENDIF} {$ENDIF}
if (FormStyle <> fsMDIForm) or (csDesigning in ComponentState) then if (FormStyle <> fsMDIForm) or (csDesigning in ComponentState) then
SetActive(Message.Active {<> WA_INACTIVE}); SetActive(Message.Active {<> WA_INACTIVE});
FActive:=true; FActive:=true;
if (FActiveControl<>nil) and FActiveControl.HandleAllocated
and (FActiveControl.Visible) and (FActiveControl.Enabled) then begin
{$IFDEF VerboseFocus}
writeln('TCustomForm.WMActivate B ',FActiveControl.Name,':',FActiveControl.ClassName);
{$ENDIF}
LCLLinux.SetFocus(FActiveControl.Handle);
end;
Activate; Activate;
end; end;
@ -652,18 +672,20 @@ begin
FocusHandle := 0; FocusHandle := 0;
if FormStyle = fsMDIFORM if FormStyle = fsMDIFORM
then begin then begin
// ToDo
end end
else begin else begin
if (FActiveControl <> nil) and (FActiveControl <> Self) if (FActiveControl <> nil) and (FActiveControl <> Self)
and (FActiveControl.Visible) and (FActiveControl.Enabled)
then FocusHandle := FActiveControl.Handle; then FocusHandle := FActiveControl.Handle;
end; end;
if FocusHandle <> 0 TheMessage.Result:=0;
if FocusHandle <> 0
then begin then begin
//writeln('[TCustomForm.WndPRoc] A ',FActiveControl.ClassName); //writeln('[TCustomForm.WndPRoc] A ',FActiveControl.ClassName);
LCLLinux.SetFocus(FocusHandle); LCLLinux.SetFocus(FocusHandle);
Exit; Exit;
end; end;
TheMessage.Result:=0;
end; end;
end; end;
CM_EXIT: CM_EXIT:
@ -836,10 +858,10 @@ Procedure TCustomForm.SetActiveControl(AWinControl: TWinControl);
Begin Begin
if FActiveControl <> AWinControl then if FActiveControl <> AWinControl then
begin begin
if not ((AWinControl = nil) if not
or (AWinControl <> Self) ((AWinControl = nil)
and (GetParentForm(AWinControl) = Self) and ((csLoading in ComponentState) or (AWinControl <> Self) and (GetParentForm(AWinControl) = Self)
or AWinControl.CanFocus)) and ((csLoading in ComponentState) or AWinControl.CanFocus))
then then
RaiseGDBException(SCannotFocus); RaiseGDBException(SCannotFocus);
// EInvalidOperation.Create(SCannotFocus); // EInvalidOperation.Create(SCannotFocus);
@ -1059,22 +1081,21 @@ begin
Result := True; Result := True;
end; end;
{------------------------------------------------------------------------------} {------------------------------------------------------------------------------
{ TCustomForm Method SetFocusedControl } TCustomForm Method SetFocusedControl
{------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
function TCustomForm.SetFocusedControl(Control : TWinControl): Boolean; function TCustomForm.SetFocusedControl(Control : TWinControl): Boolean;
{var
FocusHandle: HWnd;
TempControl: TWinControl;}
begin begin
Result := True; Result := False;
// ToDo:
{ Result := False; // update FActiveControl
Inc(FocusCount);
if FDesigner = nil then if FDesigner = nil then
if Control <> Self then if Control <> Self then
FActiveControl := Control else FActiveControl := Control
else
FActiveControl := nil; FActiveControl := nil;
// update Screen object
Screen.FActiveControl := Control; Screen.FActiveControl := Control;
Screen.FActiveCustomForm := Self; Screen.FActiveCustomForm := Self;
Screen.FCustomForms.Remove(Self); Screen.FCustomForms.Remove(Self);
@ -1082,60 +1103,72 @@ begin
if Self is TForm then if Self is TForm then
begin begin
Screen.FActiveForm := TForm(Self); Screen.FActiveForm := TForm(Self);
Screen.FForms.Remove(Self); Screen.FFormList.Remove(Self);
Screen.FForms.Insert(0, Self); Screen.FFormList.Insert(0, Self);
end end
else Screen.FActiveForm := nil; else
if not (csFocusing in Control.ControlState) then Screen.FActiveForm := nil;
begin
Control.ControlState := Control.ControlState + [csFocusing]; {$IFDEF VerboseFocus}
try write('TCustomForm.SetFocusedControl Self=',Name,':',ClassName,' ');
if Screen.FFocusedForm <> Self then write(' Control=',Control.Name,':',Control.ClassName,' Control.HandleAllocated=',Control.HandleAllocated);
writeln();
{$ENDIF}
{
Inc(FocusCount);
// prevent looping
if (csFocusing in Control.ControlState) then exit;
Control.ControlState := Control.ControlState + [csFocusing];
try
if Screen.FFocusedForm <> Self then
begin
if Screen.FFocusedForm <> nil then
begin begin
if Screen.FFocusedForm <> nil then FocusHandle := Screen.FFocusedForm.Handle;
begin Screen.FFocusedForm := nil;
FocusHandle := Screen.FFocusedForm.Handle; if not SendFocusMessage(FocusHandle, CM_DEACTIVATE) then Exit;
Screen.FFocusedForm := nil;
if not SendFocusMessage(FocusHandle, CM_DEACTIVATE) then Exit;
end;
Screen.FFocusedForm := Self;
if not SendFocusMessage(Handle, CM_ACTIVATE) then Exit;
end; end;
if FFocusedControl = nil then FFocusedControl := Self; Screen.FFocusedForm := Self;
if FFocusedControl <> Control then if not SendFocusMessage(Handle, CM_ACTIVATE) then Exit;
begin
while (FFocusedControl <> nil) and not
FFocusedControl.ContainsControl(Control) do
begin
FocusHandle := FFocusedControl.Handle;
FFocusedControl := FFocusedControl.Parent;
if not SendFocusMessage(FocusHandle, CM_EXIT) then Exit;
end;
while FFocusedControl <> Control do
begin
TempControl := Control;
while TempControl.Parent <> FFocusedControl do
TempControl := TempControl.Parent;
FFocusedControl := TempControl;
if not SendFocusMessage(TempControl.Handle, CM_ENTER) then Exit;
end;
TempControl := Control.Parent;
while TempControl <> nil do
begin
if TempControl is TScrollingWinControl then
TScrollingWinControl(TempControl).AutoScrollInView(Control);
TempControl := TempControl.Parent;
end;
Perform(CM_FOCUSCHANGED, 0, Longint(Control));
if (FActiveOleControl <> nil) and (FActiveOleControl <> Control) then
FActiveOleControl.Perform(CM_UIDEACTIVATE, 0, 0);
end;
finally
Control.ControlState := Control.ControlState - [csFocusing];
end; end;
Screen.UpdateLastActive; if FFocusedWinControl = nil then FFocusedWinControl := Self;
Result := True; if FFocusedWinControl <> Control then
end;} begin
while (FFocusedWinControl <> nil) and not
FFocusedWinControl.ContainsControl(Control) do
begin
FocusHandle := FFocusedWinControl.Handle;
FFocusedWinControl := FFocusedWinControl.Parent;
if not SendFocusMessage(FocusHandle, CM_EXIT) then Exit;
end;
while FFocusedControl <> Control do
begin
TempControl := Control;
while TempControl.Parent <> FFocusedControl do
TempControl := TempControl.Parent;
FFocusedControl := TempControl;
if not SendFocusMessage(TempControl.Handle, CM_ENTER) then Exit;
end;
TempControl := Control.Parent;
while TempControl <> nil do
begin
if TempControl is TScrollingWinControl then
TScrollingWinControl(TempControl).AutoScrollInView(Control);
TempControl := TempControl.Parent;
end;
Perform(CM_FOCUSCHANGED, 0, Longint(Control));
if (FActiveOleControl <> nil) and (FActiveOleControl <> Control) then
FActiveOleControl.Perform(CM_UIDEACTIVATE, 0, 0);
end;
finally
Control.ControlState := Control.ControlState - [csFocusing];
end;
Screen.UpdateLastActive;
Result := True;
}
end; end;
{------------------------------------------------------------------------------} {------------------------------------------------------------------------------}
@ -1166,7 +1199,8 @@ begin
// activate focus if visible // activate focus if visible
if Visible then begin if Visible then begin
if (FActiveControl<>nil) and FActiveControl.HandleAllocated then begin if (FActiveControl<>nil) and FActiveControl.HandleAllocated
and FActiveControl.Visible and FActiveControl.Enabled then begin
{$IFDEF VerboseFocus} {$IFDEF VerboseFocus}
writeln('TCustomForm.CreateWnd A ',FActiveControl.Name,':',FActiveControl.ClassName); writeln('TCustomForm.CreateWnd A ',FActiveControl.Name,':',FActiveControl.ClassName);
{$ENDIF} {$ENDIF}
@ -1177,9 +1211,17 @@ begin
end; end;
procedure TCustomForm.Loaded; procedure TCustomForm.Loaded;
var
Control: TWinControl;
begin begin
inherited Loaded; inherited Loaded;
if FMenu<>nil then FMenu.HandleNeeded; if FMenu<>nil then FMenu.HandleNeeded;
if ActiveControl <> nil then
begin
Control := ActiveControl;
FActiveControl := nil;
if Control.CanFocus then SetActiveControl(Control);
end;
end; end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
@ -1250,7 +1292,7 @@ end;
{------------------------------------------------------------------------------} {------------------------------------------------------------------------------}
{ TCustomForm ShowModal } { TCustomForm ShowModal }
{------------------------------------------------------------------------------} {------------------------------------------------------------------------------}
Function TCustomForm.ShowModal : Integer; Function TCustomForm.ShowModal: Integer;
procedure RaiseShowModalImpossible; procedure RaiseShowModalImpossible;
begin begin
@ -1332,6 +1374,9 @@ end;
{ ============================================================================= { =============================================================================
$Log$ $Log$
Revision 1.91 2003/03/18 13:04:25 mattias
improved focus debugging output
Revision 1.90 2003/03/17 13:54:34 mattias Revision 1.90 2003/03/17 13:54:34 mattias
fixed setting activecontrol after createwnd fixed setting activecontrol after createwnd