fix defocus control when destroying it

git-svn-id: trunk@4943 -
This commit is contained in:
micha 2003-12-23 16:50:45 +00:00
parent 8a4aa2f26c
commit d67aaa19bf
4 changed files with 42 additions and 1 deletions

View File

@ -1023,6 +1023,7 @@ type
Procedure CMDrag(var Message : TCMDrag); message CM_DRAG; Procedure CMDrag(var Message : TCMDrag); message CM_DRAG;
procedure CMShowingChanged(var Message: TLMessage); message CM_SHOWINGCHANGED; procedure CMShowingChanged(var Message: TLMessage); message CM_SHOWINGCHANGED;
procedure CMVisibleChanged(var TheMessage: TLMessage); message CM_VISIBLECHANGED; procedure CMVisibleChanged(var TheMessage: TLMessage); message CM_VISIBLECHANGED;
function ContainsControl(Control: TControl): Boolean;
procedure ControlsAligned; virtual; procedure ControlsAligned; virtual;
procedure DoSendBoundsToInterface; virtual; procedure DoSendBoundsToInterface; virtual;
procedure RealizeBounds; virtual; procedure RealizeBounds; virtual;
@ -1852,6 +1853,9 @@ end.
{ ============================================================================= { =============================================================================
$Log$ $Log$
Revision 1.160 2003/12/23 16:50:45 micha
fix defocus control when destroying it
Revision 1.159 2003/12/14 19:18:03 micha Revision 1.159 2003/12/14 19:18:03 micha
hint fixes: parentfont, font itself, showing/hiding + more hint fixes: parentfont, font itself, showing/hiding + more

View File

@ -431,6 +431,7 @@ type
procedure ShowOnTop; procedure ShowOnTop;
function WantChildKey(Child : TControl; function WantChildKey(Child : TControl;
var Message : TLMessage): Boolean; virtual; var Message : TLMessage): Boolean; virtual;
procedure DefocusControl(Control: TWinControl; Removing: Boolean);
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);

View File

@ -457,6 +457,20 @@ begin
inherited WMSize(Message); inherited WMSize(Message);
End; End;
{------------------------------------------------------------------------------
Method: TCustomForm.DefocusControl
Params: Control: the control which is to be defocused
Removing: is it to be defocused because it is being removed?
Returns: nothing
Updates ActiveControl if it is to be defocused
------------------------------------------------------------------------------}
procedure TCustomForm.DefocusControl(Control: TWinControl; Removing: Boolean);
begin
if Control.ContainsControl(FActiveControl) then
ActiveControl := nil;
end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
Method: TCustomForm.DoCreate Method: TCustomForm.DoCreate
Params: none Params: none
@ -1453,6 +1467,9 @@ end;
{ ============================================================================= { =============================================================================
$Log$ $Log$
Revision 1.122 2003/12/23 16:50:45 micha
fix defocus control when destroying it
Revision 1.121 2003/12/18 08:50:13 micha Revision 1.121 2003/12/18 08:50:13 micha
attachmenutowindow cleanup attachmenutowindow cleanup

View File

@ -2045,7 +2045,7 @@ var
Form: TCustomForm; Form: TCustomForm;
begin begin
Form := GetParentForm(Self); Form := GetParentForm(Self);
if Form <> nil then ;//Form.DefocusControl(Self, Removing); if Form <> nil then Form.DefocusControl(Self, Removing);
end; end;
{------------------------------------------------------------------------------} {------------------------------------------------------------------------------}
@ -2155,6 +2155,19 @@ begin
end; end;
End; End;
{------------------------------------------------------------------------------
Method: TWinControl.ContainsControl
Params: Control: the control to be checked
Returns: Self is a (super)parent of Control
Checks if Control is a child of Self
------------------------------------------------------------------------------}
function TWinControl.ContainsControl(Control: TControl): Boolean;
begin
while (Control <> nil) and (Control <> Self) do Control := Control.Parent;
Result := Control = Self;
end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
TWinControl GetBrush TWinControl GetBrush
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
@ -2279,6 +2292,9 @@ var
Control: TControl; Control: TControl;
begin begin
//writeln('[TWinControl.Destroy] A ',Name,':',ClassName); //writeln('[TWinControl.Destroy] A ',Name,':',ClassName);
// prevent parent to try to focus a to be destroyed control
if Parent <> nil then
RemoveFocus(true);
if HandleAllocated then if HandleAllocated then
DestroyHandle; DestroyHandle;
//writeln('[TWinControl.Destroy] B ',Name,':',ClassName); //writeln('[TWinControl.Destroy] B ',Name,':',ClassName);
@ -3150,6 +3166,9 @@ end;
{ ============================================================================= { =============================================================================
$Log$ $Log$
Revision 1.182 2003/12/23 16:50:45 micha
fix defocus control when destroying it
Revision 1.181 2003/12/14 19:18:04 micha Revision 1.181 2003/12/14 19:18:04 micha
hint fixes: parentfont, font itself, showing/hiding + more hint fixes: parentfont, font itself, showing/hiding + more