diff --git a/lcl/comctrls.pp b/lcl/comctrls.pp index bf45a1e80f..3578fd2969 100644 --- a/lcl/comctrls.pp +++ b/lcl/comctrls.pp @@ -43,18 +43,18 @@ uses CommCtrl, Buttons; type - -{ TAlignment = Class(TWinControl) - public - constructor Create(AOwner : TComponent); override; - destructor Destroy; override; - end; - } TStatusPanelStyle = (psText, psOwnerDraw); TStatusPanelBevel = (pbNone, pbLowered, pbRaised); TStatusBar = class; //forward declaration + TPanelPart = ( + ppText, // for text and text alignment + ppBorder, // for bevel and style + ppWidth // for width + ); + TPanelParts = set of TPanelPart; + TStatusPanel = class(TCollectionItem) private FText: string; @@ -63,7 +63,6 @@ type FBevel: TStatusPanelBevel; FParentBiDiMode: Boolean; FStyle: TStatusPanelStyle; - //FUpdateNeeded: Boolean; procedure SetAlignment(Value: TAlignment); procedure SetBevel(Value: TStatusPanelBevel); procedure SetStyle(Value: TStatusPanelStyle); @@ -71,9 +70,11 @@ type procedure SetWidth(Value: Integer); protected function GetDisplayName: string; override; + procedure PanelChanged(const Parts: TPanelParts); public constructor Create(aCollection: TCollection); override; procedure Assign(Source: TPersistent); override; + function StatusBar: TStatusBar; published property Alignment: TAlignment read FAlignment write SetAlignment; property Bevel: TStatusPanelBevel read FBevel write SetBevel default pbLowered; @@ -91,22 +92,23 @@ type function GetOwner: TPersistent; override; procedure Update(Item: TCollectionItem); override; public - constructor Create(StatusBar: TStatusBar); + constructor Create(TheStatusBar: TStatusBar); function Add: TStatusPanel; property Items[Index: Integer]: TStatusPanel read GetItem write SetItem; default; + property StatusBar: TStatusBar read FStatusBar; end; + + + { TStatusBar } - TStatusBar = Class(TWinControl) + TStatusBar = Class(TWinControl) private FCanvas : TCanvas; FPanels : TStatusPanels; FSimpleText : String; FSimplePanel : Boolean; - //FContext : Integer; - //FMessage : Integer; - //FAlignmentWidget : TAlignment; procedure SetPanels(Value: TStatusPanels); - procedure SetSimpleText(Value : String); + procedure SetSimpleText(const Value : String); procedure SetSimplePanel(Value : Boolean); Procedure WMPaint(var Msg: TLMPaint); message LM_PAINT; Procedure DrawDivider(X : Integer); @@ -114,6 +116,9 @@ type public constructor Create(AOwner : TComponent); override; destructor Destroy; override; + procedure InvalidatePanel(PanelIndex: integer; PanelParts: TPanelParts); virtual; + procedure GetPanelRect(PanelIndex: integer; var ARect: TRect); + public property Canvas : TCanvas read FCanvas; published property Panels: TStatusPanels read FPanels write SetPanels; @@ -1708,6 +1713,9 @@ end. { ============================================================================= $Log$ + Revision 1.61 2002/11/30 11:22:53 mattias + statusbar now uses invalidaterect + Revision 1.60 2002/11/25 11:37:18 mattias applied patch from Vasily diff --git a/lcl/include/statusbar.inc b/lcl/include/statusbar.inc index 284c3d2953..1350423c58 100644 --- a/lcl/include/statusbar.inc +++ b/lcl/include/statusbar.inc @@ -31,29 +31,28 @@ begin FCanvas := TControlCanvas.Create; TControlCanvas(FCanvas).Control := Self; FSimplePanel := True; -// FSizeGrip := True; end; {------------------------------------------------------------------------------} { TStatusBar SetSimpleText } {------------------------------------------------------------------------------} -procedure TStatusBar.SetSimpleText(Value : String); +procedure TStatusBar.SetSimpleText(const Value : String); begin - if FSimpleText <> value then - begin - FSimpleText := Value; - Invalidate; - end; + if FSimpleText <> value then + begin + FSimpleText := Value; + Invalidate; + end; end; Procedure TStatusBar.SetSimplePanel(Value : Boolean); Begin if FSimplePanel <> Value then - Begin - FSimplePanel := Value; - Invalidate; - end; + Begin + FSimplePanel := Value; + Invalidate; + end; End; procedure TStatusBar.SetPanels(Value: TStatusPanels); @@ -68,17 +67,67 @@ end; {------------------------------------------------------------------------------} destructor TStatusBar.Destroy; begin - FPanels.Free; - FCanvas.Free; + FreeThenNil(FPanels); + FreeThenNil(FCanvas); inherited Destroy; end; -{------------------------------------------------------------------------------} -{ TStatusBar DrawBevel } -{------------------------------------------------------------------------------} +{------------------------------------------------------------------------------ + procedure TStatusBar.InvalidatePanel(PanelIndex: integer; + PanelParts: TPanelParts); +------------------------------------------------------------------------------} +procedure TStatusBar.InvalidatePanel(PanelIndex: integer; + PanelParts: TPanelParts); +var + PanelRect, TextRect: TRect; +begin + if (PanelParts=[]) or (not HandleAllocated) or (csLoading in ComponentState) + then exit; + if ppWidth in PanelParts then begin + Invalidate; + end else begin + GetPanelRect(PanelIndex,PanelRect); + if ppText in PanelParts then begin + TextRect:=PanelRect; + inc(TextRect.Left); + inc(TextRect.Top); + dec(TextRect.Right); + dec(TextRect.Bottom); + InvalidateRect(Handle,@TextRect,false); + end; + if ppBorder in PanelParts then begin + InvalidateFrame(Handle,@PanelRect,false,2); + end; + end; +end; + +{------------------------------------------------------------------------------ + procedure TStatusBar.GetPanelRect(PanelIndex: integer; var ARect: TRect); +------------------------------------------------------------------------------} +procedure TStatusBar.GetPanelRect(PanelIndex: integer; var ARect: TRect); +var + i: Integer; +begin + ARect.Left:=0; + ARect.Top:=0; + ARect.Bottom:=ClientHeight; + for i:=0 to PanelIndex-1 do + inc(ARect.Left,Panels[i].Width); + if PanelIndex = Panels.Count-1 then begin + ARect.Right:=ClientWidth-ARect.Left; + if ARect.Right<ARect.Left then + ARect.Right:=ARect.Left; + end + else + ARect.Right:=ARect.Left+Panels[PanelIndex].Width; +end; + +{------------------------------------------------------------------------------ + TStatusBar DrawBevel +------------------------------------------------------------------------------} Procedure TStatusBar.DrawBevel(xLeft, PanelNum : Integer ); var - Colora,Colorb:TColor; + LeftTopColor,RightBottomColor:TColor; I, PL, PW : Longint; Begin if PanelNum = Panels.Count-1 then begin @@ -90,36 +139,37 @@ Begin end else PW := Panels[PanelNum].Width; + if PW<=0 then exit; - Canvas.Brush.Color := Color; - Canvas.FillRect(Rect(XLeft, Top, XLeft + PW, Top + Height)); - - if Panels[PanelNum].Bevel = pbRaised then - begin - Colora:=clBtnHighlight; - Colorb:=clBtnShadow; - end; - if Panels[PanelNum].Bevel = pbLowered then - begin - Colora:=clBtnShadow; - Colorb:=clBtnHighlight; - end; - - Canvas.Pen.Width:=1; - if (Panels[PanelNum].Bevel = pbRaised) or (Panels[PanelNum].Bevel = pbLowered) then - With Canvas Do - Begin - Pen.Color:=Colora; + if (Panels[PanelNum].Bevel in [pbRaised,pbLowered]) then begin + Canvas.Brush.Color := Color; + Canvas.FillRect(Rect(XLeft+1, Top+1, XLeft + PW-1, Top + Height - 1)); + + if Panels[PanelNum].Bevel = pbRaised then + begin + LeftTopColor:=clBtnHighlight; + RightBottomColor:=clBtnShadow; + end else begin + LeftTopColor:=clBtnShadow; + RightBottomColor:=clBtnHighlight; + end; + With Canvas Do Begin + Pen.Width:=1; + Pen.Color:=LeftTopColor; MoveTo(XLeft,Top+Height-1); LineTo(XLeft,Top); LineTo(XLeft+PW-1,Top); - Pen.Color:=Colorb; - LineTo(XLeft+PW-1,Top+Height-1); - LIneTo(XLeft,Top+Height-1); - End; + Pen.Color:=RightBottomColor; + LineTo(XLeft+PW-1,Top+Height); + MoveTo(XLeft+PW-1,Top+Height-1); + LineTo(XLeft,Top+Height-1); + End; + end else begin + Canvas.Brush.Color := Color; + Canvas.FillRect(Rect(XLeft, Top, XLeft + PW, Top + Height)); + end; End; - Procedure TStatusBar.DrawDivider(X : Integer); Begin Canvas.Pen.Width:=1; diff --git a/lcl/include/statuspanel.inc b/lcl/include/statuspanel.inc index fa1b601d09..4795c89303 100644 --- a/lcl/include/statuspanel.inc +++ b/lcl/include/statuspanel.inc @@ -37,6 +37,13 @@ begin else inherited Assign(Source); end; +function TStatusPanel.StatusBar: TStatusBar; +begin + if (Collection is TStatusPanels) then + Result:=TStatusPanels(Collection).StatusBar + else + Result:=nil; +end; function TStatusPanel.GetDisplayName: string; begin @@ -44,12 +51,22 @@ begin if Result = '' then Result := inherited GetDisplayName; end; +procedure TStatusPanel.PanelChanged(const Parts: TPanelParts); +var + TheStatusBar: TStatusBar; +begin + TheStatusBar:=StatusBar; + if TheStatusBar=nil then exit; + TheStatusBar.InvalidatePanel(Index,Parts); +end; + procedure TStatusPanel.SetAlignment(Value: TAlignment); begin if FAlignment <> Value then begin FAlignment := Value; Changed(False); + PanelChanged([ppText]); end; end; @@ -59,6 +76,7 @@ begin begin FBevel := Value; Changed(False); + PanelChanged([ppBorder]); end; end; @@ -68,6 +86,7 @@ begin begin FStyle := Value; Changed(False); + PanelChanged([ppBorder]); end; end; @@ -77,6 +96,7 @@ begin begin FText := Value; Changed(False); + PanelChanged([ppText]); end; end; @@ -86,6 +106,7 @@ begin begin FWidth := Value; Changed(True); + PanelChanged([ppWidth]); end; end; diff --git a/lcl/include/statuspanels.inc b/lcl/include/statuspanels.inc index 648428ee3f..5a9e6faee7 100644 --- a/lcl/include/statuspanels.inc +++ b/lcl/include/statuspanels.inc @@ -17,10 +17,10 @@ } -constructor TStatusPanels.Create(StatusBar: TStatusBar); +constructor TStatusPanels.Create(TheStatusBar: TStatusBar); begin inherited Create(TStatusPanel); - FStatusBar := StatusBar; + FStatusBar := TheStatusBar; end; function TStatusPanels.Add: TStatusPanel; @@ -45,7 +45,9 @@ end; procedure TStatusPanels.Update(Item: TCollectionItem); begin - FStatusBar.Invalidate; + // Don't invalidate the whole statusbar. There is an improved + // TStatusBar.InvalidatePanel. + //FStatusBar.Invalidate; end; // included by comctrls.pp