From 2f268b9eca4616ffe7f90fdc5c0247223a71b707 Mon Sep 17 00:00:00 2001 From: mattias Date: Sat, 17 Aug 2002 23:41:31 +0000 Subject: [PATCH] fixed TUpDown and added handler lists for TControl git-svn-id: trunk@2610 - --- lcl/buttons.pp | 4 ++ lcl/include/control.inc | 82 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 85 insertions(+), 1 deletion(-) diff --git a/lcl/buttons.pp b/lcl/buttons.pp index 55598f4f08..4d7c0c2cf2 100644 --- a/lcl/buttons.pp +++ b/lcl/buttons.pp @@ -109,6 +109,7 @@ type property OnMouseDown; property OnMouseMove; property OnMouseUp; + property OnResize; end; @@ -301,6 +302,9 @@ end. { ============================================================================= $Log$ + Revision 1.43 2003/06/13 12:53:51 mattias + fixed TUpDown and added handler lists for TControl + Revision 1.42 2003/05/03 09:53:33 mattias fixed popupmenu for component palette diff --git a/lcl/include/control.inc b/lcl/include/control.inc index 9b6d9b9a96..21d0b62a0c 100644 --- a/lcl/include/control.inc +++ b/lcl/include/control.inc @@ -129,7 +129,8 @@ var OldTop: Integer; OldWidth: Integer; OldHeight: Integer; - + CurBounds: TRect; + function UpdatePosSizeChanged: boolean; begin SizeChanged:= (FWidth <> OldWidth) or (FHeight <> OldHeight); @@ -229,6 +230,11 @@ begin // notify user about resize if (not (csLoading in ComponentState)) then begin Resize; + CurBounds:=BoundsRect; + if not CompareRect(@FLastDoChangeBounds,@CurBounds) then begin + FLastDoChangeBounds:=CurBounds; + DoOnChangeBounds; + end; SendMoveSizeMessages(SizeChanged,PosChanged); end; end; @@ -501,10 +507,32 @@ end; {------------------------------------------------------------------------------ procedure TControl.DoOnResize; + + Call events ------------------------------------------------------------------------------} procedure TControl.DoOnResize; +var + i: Integer; begin if Assigned(FOnResize) then FOnResize(Self); + i:=FControlHandlers[chtOnResize].Count; + while FControlHandlers[chtOnResize].NextDownIndex(i) do + TNotifyEvent(FControlHandlers[chtOnResize][i])(Self); +end; + +{------------------------------------------------------------------------------ + procedure TControl.DoOnResize; + + Call events +------------------------------------------------------------------------------} +procedure TControl.DoOnChangeBounds; +var + i: Integer; +begin + if Assigned(FOnChangeBounds) then FOnChangeBounds(Self); + i:=FControlHandlers[chtOnChangeBounds].Count; + while FControlHandlers[chtOnChangeBounds].NextDownIndex(i) do + TNotifyEvent(FControlHandlers[chtOnChangeBounds][i])(Self); end; {------------------------------------------------------------------------------ @@ -913,6 +941,20 @@ begin end; +procedure TControl.AddControlHandler(HandlerType: TControlHandlerType; + AMethod: TMethod; AsLast: boolean); +begin + if FControlHandlers[HandlerType]=nil then + FControlHandlers[HandlerType]:=TMethodList.Create; + FControlHandlers[HandlerType].Add(AMethod); +end; + +procedure TControl.RemoveControlHandler(HandlerType: TControlHandlerType; + AMethod: TMethod); +begin + FControlHandlers[HandlerType].Remove(AMethod); +end; + {------------------------------------------------------------------------------ TControl GetClientRect ------------------------------------------------------------------------------} @@ -2012,6 +2054,37 @@ begin and not (csReadingState in ControlState); end; +procedure TControl.AddHandlerOnResize(OnResizeEvent: TNotifyEvent; + AsLast: boolean); +begin + AddControlHandler(chtOnResize,TMethod(OnResizeEvent),AsLast); +end; + +procedure TControl.RemoveHandlerOnResize(OnResizeEvent: TNotifyEvent); +begin + RemoveControlHandler(chtOnResize,TMethod(OnResizeEvent)); +end; + +procedure TControl.AddHandlerOnChangeBounds(OnChangeBoundsEvent: TNotifyEvent; + AsLast: boolean); +begin + AddControlHandler(chtOnChangeBounds,TMethod(OnChangeBoundsEvent),AsLast); +end; + +procedure TControl.RemoveHandlerOnChangeBounds(OnChangeBoundsEvent: TNotifyEvent + ); +begin + RemoveControlHandler(chtOnChangeBounds,TMethod(OnChangeBoundsEvent)); +end; + +procedure TControl.RemoveAllControlHandlersOfObject(AnObject: TObject); +var + HandlerType: TControlHandlerType; +begin + for HandlerType:=Low(TControlHandlerType) to High(TControlHandlerType) do + FControlHandlers[HandlerType].RemoveAllMethodsOfObject(AnObject); +end; + {------------------------------------------------------------------------------ TControl.SetZOrderPosition ------------------------------------------------------------------------------} @@ -2103,6 +2176,8 @@ end; Destructor for the class. ------------------------------------------------------------------------------} destructor TControl.Destroy; +var + HandlerType: TControlHandlerType; begin //writeln('[TControl.Destroy] A ',Name,':',ClassName); Application.ControlDestroyed(Self); @@ -2112,6 +2187,8 @@ begin //writeln('[TControl.Destroy] B ',Name,':',ClassName); inherited Destroy; //writeln('[TControl.Destroy] END ',Name,':',ClassName); + for HandlerType:=Low(TControlHandlerType) to High(TControlHandlerType) do + FreeThenNil(FControlHandlers[HandlerType]); end; {------------------------------------------------------------------------------ @@ -2311,6 +2388,9 @@ end; { ============================================================================= $Log$ + Revision 1.133 2003/06/13 12:53:52 mattias + fixed TUpDown and added handler lists for TControl + Revision 1.132 2003/06/12 18:55:44 mattias improved designer to recognize auto child moves