statusbar now uses invalidaterect

git-svn-id: trunk@3677 -
This commit is contained in:
mattias 2002-11-30 11:22:53 +00:00
parent 790ec25214
commit 5cf67aa3fc
4 changed files with 139 additions and 58 deletions

View File

@ -43,18 +43,18 @@ uses
CommCtrl, Buttons; CommCtrl, Buttons;
type type
{ TAlignment = Class(TWinControl)
public
constructor Create(AOwner : TComponent); override;
destructor Destroy; override;
end;
}
TStatusPanelStyle = (psText, psOwnerDraw); TStatusPanelStyle = (psText, psOwnerDraw);
TStatusPanelBevel = (pbNone, pbLowered, pbRaised); TStatusPanelBevel = (pbNone, pbLowered, pbRaised);
TStatusBar = class; //forward declaration 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) TStatusPanel = class(TCollectionItem)
private private
FText: string; FText: string;
@ -63,7 +63,6 @@ type
FBevel: TStatusPanelBevel; FBevel: TStatusPanelBevel;
FParentBiDiMode: Boolean; FParentBiDiMode: Boolean;
FStyle: TStatusPanelStyle; FStyle: TStatusPanelStyle;
//FUpdateNeeded: Boolean;
procedure SetAlignment(Value: TAlignment); procedure SetAlignment(Value: TAlignment);
procedure SetBevel(Value: TStatusPanelBevel); procedure SetBevel(Value: TStatusPanelBevel);
procedure SetStyle(Value: TStatusPanelStyle); procedure SetStyle(Value: TStatusPanelStyle);
@ -71,9 +70,11 @@ type
procedure SetWidth(Value: Integer); procedure SetWidth(Value: Integer);
protected protected
function GetDisplayName: string; override; function GetDisplayName: string; override;
procedure PanelChanged(const Parts: TPanelParts);
public public
constructor Create(aCollection: TCollection); override; constructor Create(aCollection: TCollection); override;
procedure Assign(Source: TPersistent); override; procedure Assign(Source: TPersistent); override;
function StatusBar: TStatusBar;
published published
property Alignment: TAlignment read FAlignment write SetAlignment; property Alignment: TAlignment read FAlignment write SetAlignment;
property Bevel: TStatusPanelBevel read FBevel write SetBevel default pbLowered; property Bevel: TStatusPanelBevel read FBevel write SetBevel default pbLowered;
@ -91,22 +92,23 @@ type
function GetOwner: TPersistent; override; function GetOwner: TPersistent; override;
procedure Update(Item: TCollectionItem); override; procedure Update(Item: TCollectionItem); override;
public public
constructor Create(StatusBar: TStatusBar); constructor Create(TheStatusBar: TStatusBar);
function Add: TStatusPanel; function Add: TStatusPanel;
property Items[Index: Integer]: TStatusPanel read GetItem write SetItem; default; property Items[Index: Integer]: TStatusPanel read GetItem write SetItem; default;
property StatusBar: TStatusBar read FStatusBar;
end; end;
{ TStatusBar }
TStatusBar = Class(TWinControl) TStatusBar = Class(TWinControl)
private private
FCanvas : TCanvas; FCanvas : TCanvas;
FPanels : TStatusPanels; FPanels : TStatusPanels;
FSimpleText : String; FSimpleText : String;
FSimplePanel : Boolean; FSimplePanel : Boolean;
//FContext : Integer;
//FMessage : Integer;
//FAlignmentWidget : TAlignment;
procedure SetPanels(Value: TStatusPanels); procedure SetPanels(Value: TStatusPanels);
procedure SetSimpleText(Value : String); procedure SetSimpleText(const Value : String);
procedure SetSimplePanel(Value : Boolean); procedure SetSimplePanel(Value : Boolean);
Procedure WMPaint(var Msg: TLMPaint); message LM_PAINT; Procedure WMPaint(var Msg: TLMPaint); message LM_PAINT;
Procedure DrawDivider(X : Integer); Procedure DrawDivider(X : Integer);
@ -114,6 +116,9 @@ type
public public
constructor Create(AOwner : TComponent); override; constructor Create(AOwner : TComponent); override;
destructor Destroy; override; destructor Destroy; override;
procedure InvalidatePanel(PanelIndex: integer; PanelParts: TPanelParts); virtual;
procedure GetPanelRect(PanelIndex: integer; var ARect: TRect);
public
property Canvas : TCanvas read FCanvas; property Canvas : TCanvas read FCanvas;
published published
property Panels: TStatusPanels read FPanels write SetPanels; property Panels: TStatusPanels read FPanels write SetPanels;
@ -1708,6 +1713,9 @@ end.
{ ============================================================================= { =============================================================================
$Log$ $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 Revision 1.60 2002/11/25 11:37:18 mattias
applied patch from Vasily applied patch from Vasily

View File

@ -31,29 +31,28 @@ begin
FCanvas := TControlCanvas.Create; FCanvas := TControlCanvas.Create;
TControlCanvas(FCanvas).Control := Self; TControlCanvas(FCanvas).Control := Self;
FSimplePanel := True; FSimplePanel := True;
// FSizeGrip := True;
end; end;
{------------------------------------------------------------------------------} {------------------------------------------------------------------------------}
{ TStatusBar SetSimpleText } { TStatusBar SetSimpleText }
{------------------------------------------------------------------------------} {------------------------------------------------------------------------------}
procedure TStatusBar.SetSimpleText(Value : String); procedure TStatusBar.SetSimpleText(const Value : String);
begin begin
if FSimpleText <> value then if FSimpleText <> value then
begin begin
FSimpleText := Value; FSimpleText := Value;
Invalidate; Invalidate;
end; end;
end; end;
Procedure TStatusBar.SetSimplePanel(Value : Boolean); Procedure TStatusBar.SetSimplePanel(Value : Boolean);
Begin Begin
if FSimplePanel <> Value then if FSimplePanel <> Value then
Begin Begin
FSimplePanel := Value; FSimplePanel := Value;
Invalidate; Invalidate;
end; end;
End; End;
procedure TStatusBar.SetPanels(Value: TStatusPanels); procedure TStatusBar.SetPanels(Value: TStatusPanels);
@ -68,17 +67,67 @@ end;
{------------------------------------------------------------------------------} {------------------------------------------------------------------------------}
destructor TStatusBar.Destroy; destructor TStatusBar.Destroy;
begin begin
FPanels.Free; FreeThenNil(FPanels);
FCanvas.Free; FreeThenNil(FCanvas);
inherited Destroy; inherited Destroy;
end; 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 ); Procedure TStatusBar.DrawBevel(xLeft, PanelNum : Integer );
var var
Colora,Colorb:TColor; LeftTopColor,RightBottomColor:TColor;
I, PL, PW : Longint; I, PL, PW : Longint;
Begin Begin
if PanelNum = Panels.Count-1 then begin if PanelNum = Panels.Count-1 then begin
@ -90,36 +139,37 @@ Begin
end end
else else
PW := Panels[PanelNum].Width; PW := Panels[PanelNum].Width;
if PW<=0 then exit;
Canvas.Brush.Color := Color; if (Panels[PanelNum].Bevel in [pbRaised,pbLowered]) then begin
Canvas.FillRect(Rect(XLeft, Top, XLeft + PW, Top + Height)); Canvas.Brush.Color := Color;
Canvas.FillRect(Rect(XLeft+1, Top+1, XLeft + PW-1, Top + Height - 1));
if Panels[PanelNum].Bevel = pbRaised then
begin if Panels[PanelNum].Bevel = pbRaised then
Colora:=clBtnHighlight; begin
Colorb:=clBtnShadow; LeftTopColor:=clBtnHighlight;
end; RightBottomColor:=clBtnShadow;
if Panels[PanelNum].Bevel = pbLowered then end else begin
begin LeftTopColor:=clBtnShadow;
Colora:=clBtnShadow; RightBottomColor:=clBtnHighlight;
Colorb:=clBtnHighlight; end;
end; With Canvas Do Begin
Pen.Width:=1;
Canvas.Pen.Width:=1; Pen.Color:=LeftTopColor;
if (Panels[PanelNum].Bevel = pbRaised) or (Panels[PanelNum].Bevel = pbLowered) then
With Canvas Do
Begin
Pen.Color:=Colora;
MoveTo(XLeft,Top+Height-1); MoveTo(XLeft,Top+Height-1);
LineTo(XLeft,Top); LineTo(XLeft,Top);
LineTo(XLeft+PW-1,Top); LineTo(XLeft+PW-1,Top);
Pen.Color:=Colorb; Pen.Color:=RightBottomColor;
LineTo(XLeft+PW-1,Top+Height-1); LineTo(XLeft+PW-1,Top+Height);
LIneTo(XLeft,Top+Height-1); MoveTo(XLeft+PW-1,Top+Height-1);
End; LineTo(XLeft,Top+Height-1);
End;
end else begin
Canvas.Brush.Color := Color;
Canvas.FillRect(Rect(XLeft, Top, XLeft + PW, Top + Height));
end;
End; End;
Procedure TStatusBar.DrawDivider(X : Integer); Procedure TStatusBar.DrawDivider(X : Integer);
Begin Begin
Canvas.Pen.Width:=1; Canvas.Pen.Width:=1;

View File

@ -37,6 +37,13 @@ begin
else inherited Assign(Source); else inherited Assign(Source);
end; end;
function TStatusPanel.StatusBar: TStatusBar;
begin
if (Collection is TStatusPanels) then
Result:=TStatusPanels(Collection).StatusBar
else
Result:=nil;
end;
function TStatusPanel.GetDisplayName: string; function TStatusPanel.GetDisplayName: string;
begin begin
@ -44,12 +51,22 @@ begin
if Result = '' then Result := inherited GetDisplayName; if Result = '' then Result := inherited GetDisplayName;
end; 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); procedure TStatusPanel.SetAlignment(Value: TAlignment);
begin begin
if FAlignment <> Value then if FAlignment <> Value then
begin begin
FAlignment := Value; FAlignment := Value;
Changed(False); Changed(False);
PanelChanged([ppText]);
end; end;
end; end;
@ -59,6 +76,7 @@ begin
begin begin
FBevel := Value; FBevel := Value;
Changed(False); Changed(False);
PanelChanged([ppBorder]);
end; end;
end; end;
@ -68,6 +86,7 @@ begin
begin begin
FStyle := Value; FStyle := Value;
Changed(False); Changed(False);
PanelChanged([ppBorder]);
end; end;
end; end;
@ -77,6 +96,7 @@ begin
begin begin
FText := Value; FText := Value;
Changed(False); Changed(False);
PanelChanged([ppText]);
end; end;
end; end;
@ -86,6 +106,7 @@ begin
begin begin
FWidth := Value; FWidth := Value;
Changed(True); Changed(True);
PanelChanged([ppWidth]);
end; end;
end; end;

View File

@ -17,10 +17,10 @@
} }
constructor TStatusPanels.Create(StatusBar: TStatusBar); constructor TStatusPanels.Create(TheStatusBar: TStatusBar);
begin begin
inherited Create(TStatusPanel); inherited Create(TStatusPanel);
FStatusBar := StatusBar; FStatusBar := TheStatusBar;
end; end;
function TStatusPanels.Add: TStatusPanel; function TStatusPanels.Add: TStatusPanel;
@ -45,7 +45,9 @@ end;
procedure TStatusPanels.Update(Item: TCollectionItem); procedure TStatusPanels.Update(Item: TCollectionItem);
begin begin
FStatusBar.Invalidate; // Don't invalidate the whole statusbar. There is an improved
// TStatusBar.InvalidatePanel.
//FStatusBar.Invalidate;
end; end;
// included by comctrls.pp // included by comctrls.pp