diff --git a/lcl/controls.pp b/lcl/controls.pp index 5b7ba04d8c..526c0186a2 100644 --- a/lcl/controls.pp +++ b/lcl/controls.pp @@ -1023,6 +1023,7 @@ type Procedure CMDrag(var Message : TCMDrag); message CM_DRAG; procedure CMShowingChanged(var Message: TLMessage); message CM_SHOWINGCHANGED; procedure CMVisibleChanged(var TheMessage: TLMessage); message CM_VISIBLECHANGED; + function ContainsControl(Control: TControl): Boolean; procedure ControlsAligned; virtual; procedure DoSendBoundsToInterface; virtual; procedure RealizeBounds; virtual; @@ -1852,6 +1853,9 @@ end. { ============================================================================= $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 hint fixes: parentfont, font itself, showing/hiding + more diff --git a/lcl/forms.pp b/lcl/forms.pp index ecd825dcdf..20a04fbe51 100644 --- a/lcl/forms.pp +++ b/lcl/forms.pp @@ -431,6 +431,7 @@ type procedure ShowOnTop; function WantChildKey(Child : TControl; var Message : TLMessage): Boolean; virtual; + procedure DefocusControl(Control: TWinControl; Removing: Boolean); procedure SetFocus; override; function SetFocusedControl(Control: TWinControl): Boolean ; Virtual; procedure FocusControl(WinControl: TWinControl); diff --git a/lcl/include/customform.inc b/lcl/include/customform.inc index 7fbe41debb..5379160520 100644 --- a/lcl/include/customform.inc +++ b/lcl/include/customform.inc @@ -457,6 +457,20 @@ begin inherited WMSize(Message); 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 Params: none @@ -1453,6 +1467,9 @@ end; { ============================================================================= $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 attachmenutowindow cleanup diff --git a/lcl/include/wincontrol.inc b/lcl/include/wincontrol.inc index 5500a1da04..78554ddf3c 100644 --- a/lcl/include/wincontrol.inc +++ b/lcl/include/wincontrol.inc @@ -2045,7 +2045,7 @@ var Form: TCustomForm; begin Form := GetParentForm(Self); - if Form <> nil then ;//Form.DefocusControl(Self, Removing); + if Form <> nil then Form.DefocusControl(Self, Removing); end; {------------------------------------------------------------------------------} @@ -2155,6 +2155,19 @@ begin 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 ------------------------------------------------------------------------------} @@ -2279,6 +2292,9 @@ var Control: TControl; begin //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 DestroyHandle; //writeln('[TWinControl.Destroy] B ',Name,':',ClassName); @@ -3150,6 +3166,9 @@ end; { ============================================================================= $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 hint fixes: parentfont, font itself, showing/hiding + more