Minor edit fixes and fixes memory leaks in customdrawn

git-svn-id: trunk@33176 -
This commit is contained in:
sekelsenmat 2011-10-30 14:22:17 +00:00
parent 5c8ad97065
commit 4c6c91f237
3 changed files with 116 additions and 132 deletions

View File

@ -27,8 +27,8 @@ type
TCDEditDrawerWinCE = class(TCDEditDrawer) TCDEditDrawerWinCE = class(TCDEditDrawer)
public public
procedure DrawToIntfImage(ADest: TFPImageCanvas; CDEdit: TCDEdit); override; procedure DrawToIntfImage(ADest: TFPImageCanvas; CDControl: TCDControl); override;
procedure DrawToCanvas(ADest: TCanvas; CDEdit: TCDEdit); override; procedure DrawToCanvas(ADest: TCanvas; CDControl: TCDControl); override;
end; end;
{ TCDCheckBoxDrawerWinCE } { TCDCheckBoxDrawerWinCE }
@ -103,12 +103,12 @@ end;
{ TCDEditDrawerWinCE } { TCDEditDrawerWinCE }
procedure TCDEditDrawerWinCE.DrawToIntfImage(ADest: TFPImageCanvas; procedure TCDEditDrawerWinCE.DrawToIntfImage(ADest: TFPImageCanvas;
CDEdit: TCDEdit); CDControl: TCDControl);
begin begin
end; end;
procedure TCDEditDrawerWinCE.DrawToCanvas(ADest: TCanvas; CDEdit: TCDEdit); procedure TCDEditDrawerWinCE.DrawToCanvas(ADest: TCanvas; CDControl: TCDControl);
begin begin
end; end;

View File

@ -26,11 +26,14 @@ uses
// //
customdrawnutils; customdrawnutils;
const
CDDRAWSTYLE_COUNT = 12;
type type
TCDDrawStyle = ( TCDDrawStyle = (
// The default is given by the DefaultStyle global variable // The default is given by the DefaultStyle global variable
dsDefault, dsDefault = 0,
// Operating system styles // Operating system styles
dsWinCE, dsWin2000, dsWinXP, dsWinCE, dsWin2000, dsWinXP,
dsKDE, dsGNOME, dsMacOSX, dsKDE, dsGNOME, dsMacOSX,
@ -44,8 +47,6 @@ type
{ TCDControl } { TCDControl }
TCDControl = class(TCustomControl) TCDControl = class(TCustomControl)
private
FIsMouseOver: Boolean;
protected protected
FDrawStyle: TCDDrawStyle; FDrawStyle: TCDDrawStyle;
FCurrentDrawer: TCDControlDrawer; FCurrentDrawer: TCDControlDrawer;
@ -54,23 +55,26 @@ type
procedure PrepareCurrentDrawer(); virtual; procedure PrepareCurrentDrawer(); virtual;
procedure SetDrawStyle(const AValue: TCDDrawStyle); virtual; procedure SetDrawStyle(const AValue: TCDDrawStyle); virtual;
function GetClientRect: TRect; override; function GetClientRect: TRect; override;
procedure EraseBackground(DC: HDC); override;
// mouse // mouse
procedure MouseEnter; override; procedure MouseEnter; override;
procedure MouseLeave; override; procedure MouseLeave; override;
// //
property DrawStyle: TCDDrawStyle read FDrawStyle write SetDrawStyle; property DrawStyle: TCDDrawStyle read FDrawStyle write SetDrawStyle;
public public
property IsMouseOver: Boolean read FIsMouseOver write FIsMouseOver; // state information
IsMouseOver: Boolean;
//
procedure EraseBackground(DC: HDC); override;
procedure Paint; override;
end; end;
TCDControlClass = class of TCDControl; TCDControlClass = class of TCDControl;
TCDControlDrawer = class TCDControlDrawer = class
public public
function GetClientRect(AControl: TCDControl): TRect; virtual; abstract; function GetClientRect(AControl: TCDControl): TRect; virtual; abstract;
//procedure DrawToIntfImage(ADest: TFPImageCanvas; AControl: TCDControl); procedure DrawToIntfImage(ADest: TFPImageCanvas; AControl: TCDControl);
// virtual; abstract; virtual; abstract;
//procedure DrawToCanvas(ADest: TCanvas; AControl: TCDControl); virtual; abstract; procedure DrawToCanvas(ADest: TCanvas; AControl: TCDControl); virtual; abstract;
end; end;
// =================================== // ===================================
@ -187,7 +191,6 @@ type
public public
constructor Create(AOwner: TComponent); override; constructor Create(AOwner: TComponent); override;
destructor Destroy; override; destructor Destroy; override;
procedure EraseBackground(DC: HDC); override;
procedure Paint; override; procedure Paint; override;
published published
property Color; property Color;
@ -196,8 +199,6 @@ type
TCDEditDrawer = class(TCDControlDrawer) TCDEditDrawer = class(TCDControlDrawer)
public public
procedure DrawToIntfImage(ADest: TFPImageCanvas; CDEdit: TCDEdit); virtual; abstract;
procedure DrawToCanvas(ADest: TCanvas; CDEdit: TCDEdit); virtual; abstract;
end; end;
{@@ {@@
@ -722,14 +723,35 @@ begin
inherited Destroy; inherited Destroy;
end; end;
procedure TCDEdit.EraseBackground(DC: HDC);
begin
inherited EraseBackground(DC);
end;
procedure TCDEdit.Paint; procedure TCDEdit.Paint;
var
AImage: TLazIntfImage = nil;
ABmp: TBitmap = nil;
lCanvas: TFPImageCanvas = nil;
begin begin
inherited Paint; inherited Paint;
PrepareCurrentDrawer();
ABmp := TBitmap.Create;
try
ABmp.Width := Width;
ABmp.Height := Height;
AImage := ABmp.CreateIntfImage;
lCanvas := TFPImageCanvas.Create(AImage);
// First step of the drawing: FCL TFPCustomCanvas for fast pixel access
TCDEditDrawer(FCurrentDrawer).DrawToIntfImage(lCanvas, Self);
ABmp.LoadFromIntfImage(AImage);
// Second step of the drawing: LCL TCustomCanvas for easy font access
TCDEditDrawer(FCurrentDrawer).DrawToCanvas(ABmp.Canvas, Self);
Canvas.Draw(0, 0, ABmp);
finally
if lCanvas <> nil then
lCanvas.Free;
if AImage <> nil then
AImage.Free;
ABmp.Free;
end;
end; end;
{ TCDCheckBox } { TCDCheckBox }
@ -992,15 +1014,46 @@ begin
end; end;
procedure TCDControl.Paint;
var
AImage: TLazIntfImage = nil;
ABmp: TBitmap = nil;
lCanvas: TFPImageCanvas = nil;
begin
inherited Paint;
PrepareCurrentDrawer();
ABmp := TBitmap.Create;
try
ABmp.Width := Width;
ABmp.Height := Height;
AImage := ABmp.CreateIntfImage;
lCanvas := TFPImageCanvas.Create(AImage);
// First step of the drawing: FCL TFPCustomCanvas for fast pixel access
FCurrentDrawer.DrawToIntfImage(lCanvas, Self);
ABmp.LoadFromIntfImage(AImage);
// Second step of the drawing: LCL TCustomCanvas for easy font access
FCurrentDrawer.DrawToCanvas(ABmp.Canvas, Self);
Canvas.Draw(0, 0, ABmp);
finally
if lCanvas <> nil then
lCanvas.Free;
if AImage <> nil then
AImage.Free;
ABmp.Free;
end;
end;
procedure TCDControl.MouseEnter; procedure TCDControl.MouseEnter;
begin begin
FIsMouseOver := True; IsMouseOver := True;
inherited MouseEnter; inherited MouseEnter;
end; end;
procedure TCDControl.MouseLeave; procedure TCDControl.MouseLeave;
begin begin
FIsMouseOver := True; IsMouseOver := True;
inherited MouseLeave; inherited MouseLeave;
end; end;
@ -1672,5 +1725,46 @@ begin
Result := FTabIndex; Result := FTabIndex;
end; end;
var
i: Integer;
finalization
// Free all drawers
// Standard Tab
for i := 0 to CDDRAWSTYLE_COUNT-1 do
begin
RegisteredButtonDrawers[TCDDrawStyle(i)].Free;
RegisteredButtonDrawers[TCDDrawStyle(i)] := nil;
end;
for i := 0 to CDDRAWSTYLE_COUNT-1 do
begin
RegisteredEditDrawers[TCDDrawStyle(i)].Free;
RegisteredEditDrawers[TCDDrawStyle(i)] := nil;
end;
for i := 0 to CDDRAWSTYLE_COUNT-1 do
begin
RegisteredGroupBoxDrawers[TCDDrawStyle(i)].Free;
RegisteredGroupBoxDrawers[TCDDrawStyle(i)] := nil;
end;
for i := 0 to CDDRAWSTYLE_COUNT-1 do
begin
RegisteredCheckBoxDrawers[TCDDrawStyle(i)].Free;
RegisteredCheckBoxDrawers[TCDDrawStyle(i)] := nil;
end;
// Common Controls Tab
for i := 0 to CDDRAWSTYLE_COUNT-1 do
begin
RegisteredTrackBarDrawers[TCDDrawStyle(i)].Free;
RegisteredTrackBarDrawers[TCDDrawStyle(i)] := nil;
end;
for i := 0 to CDDRAWSTYLE_COUNT-1 do
begin
RegisteredListViewDrawers[TCDDrawStyle(i)].Free;
RegisteredListViewDrawers[TCDDrawStyle(i)] := nil;
end;
for i := 0 to CDDRAWSTYLE_COUNT-1 do
begin
RegisteredCustomTabControlDrawers[TCDDrawStyle(i)].Free;
RegisteredCustomTabControlDrawers[TCDDrawStyle(i)] := nil;
end;
end. end.

View File

@ -26,10 +26,6 @@ procedure DrawAndroidButton(Canvas: TCanvas; Color: TColor);
procedure DrawXPTaskbarButton(Canvas: TCanvas; Color: TColor); procedure DrawXPTaskbarButton(Canvas: TCanvas; Color: TColor);
procedure FPImgCloneRect(IntfImg1, IntfImg2: TLazIntfImage; lRect: TRect; Fast: boolean); procedure FPImgCloneRect(IntfImg1, IntfImg2: TLazIntfImage; lRect: TRect; Fast: boolean);
function GetUniqueName(const Name: string; PControl: TComponent): string; function GetUniqueName(const Name: string; PControl: TComponent): string;
procedure DrawTabHead(aDest: TFPCustomCanvas; aRect: TRect; HeadColor: TColor;
IsActive: boolean);
procedure DrawTabHeadMask(aDest: TFPCustomCanvas; aRect: TRect;
HeadColor: TColor; IsActive: boolean);
procedure DrawArrow(aDest: TFPCustomCanvas; aRect: TRect; R: boolean); procedure DrawArrow(aDest: TFPCustomCanvas; aRect: TRect; R: boolean);
procedure DrawCDButtonDown(Canvas: TCanvas; ABackgroundColor: TColor); procedure DrawCDButtonDown(Canvas: TCanvas; ABackgroundColor: TColor);
@ -78,112 +74,6 @@ begin
end; end;
end; end;
procedure DrawTabHead(aDest: TFPCustomCanvas; aRect: TRect; HeadColor: TColor;
IsActive: boolean);
var
lRect: TRect;
CC: TFPColor;
begin
lRect.Bottom := aRect.Bottom;
lRect.Right := aRect.Right;
lRect.Left := aRect.Left;
lRect.Top := aRect.Top + 3;
if not IsActive then
GradientFillRect(clWhite, HeadColor, aDest, lREct)
else
begin
aDest.Brush.FPColor := TColorToFPColor(ColorToRGB(HeadColor));
aDest.Pen.FPColor := aDest.Brush.FPColor;
aDest.Rectangle(lRect);
end;
aDest.Pen.FPColor := TColorToFPColor(ColorToRGB(clWhite));
aDest.Line(lRect.Left + 2, aRect.Top + 1, lRect.Right - 2, aRect.Top + 1);
aDest.Line(lRect.Left + 1, aRect.Top + 2, lRect.Right - 1, aRect.Top + 2);
ADest.Pen.FPColor := TColorToFPColor(ColorToRGB($009C9B91));
aDest.Line(lRect.Left, lRect.Top, lRect.Left, lRect.Bottom);
//aDest.Line(lRect.Left + 3, aRect.Top, lRect.Right - 3, aRect.Top);
aDest.Line(lRect.Left + 3, aRect.Top, lRect.Right - 2, aRect.Top);
aDest.Line(lRect.Right, lRect.Top, lRect.Right, lRect.Bottom);
if not IsActive then
aDest.Line(aRect.Left, aRect.Bottom - 1, aRect.Right, aRect.Bottom - 1);
//aDest.Line();
{ aDest.Colors[aRect.Left + 1, aRect.Top + 2] := aDest.Pen.FPColor;
aDest.Colors[aRect.Left + 2, aRect.Top + 1] := aDest.Pen.FPColor;
aDest.Colors[aRect.Right - 1, aRect.Top + 2] := aDest.Pen.FPColor;
aDest.Colors[aRect.Right - 2, aRect.Top + 1] := aDest.Pen.FPColor; }
if IsActive then
begin
aDest.Pen.FPColor := TColorToFPColor(ColorToRGB($003CC7FF));
aDest.Line(lRect.Left, aRect.Top + 2, lRect.Right, aRect.Top + 2);
aDest.Line(lRect.Left + 1, aRect.Top + 1, lRect.Right - 1, aRect.Top + 1);
aDest.Pen.FPColor := TColorToFPColor(ColorToRGB($001CA7DF));
aDest.Line(lRect.Left + 2, aRect.Top, lRect.Right - 2, aRect.Top);
CC := TColorToFPColor(ColorToRGB($001CA7DF));
aDest.Colors[aRect.Left + 1, aRect.Top + 1] := CC;
aDest.Colors[aRect.Left, aRect.Top + 2] := CC;
aDest.Colors[aRect.Left + 2, aRect.Top] := CC;
aDest.Colors[aRect.Right - 1, aRect.Top + 1] := CC;
aDest.Colors[aRect.Right, aRect.Top + 2] := CC;
aDest.Colors[aRect.Right - 2, aRect.Top] := CC;
{ CC := TColorToFPColor(ColorToRGB($005CE7FF));
aDest.Colors[aRect.Left, aRect.Top + 1] := CC;
aDest.Colors[aRect.Left + 1, aRect.Top] := CC;
aDest.Colors[aRect.Left + 2, aRect.Top + 1] := CC;
aDest.Colors[aRect.Left + 1, aRect.Top + 2] := CC;
aDest.Colors[aRect.Right, aRect.Top + 1] := CC;
aDest.Colors[aRect.Right - 1, aRect.Top] := CC;
aDest.Colors[aRect.Right - 1, aRect.Top + 2] := CC;
aDest.Colors[aRect.Right - 2, aRect.Top + 1] := CC; }
end
else
begin
CC := TColorToFPColor(ColorToRGB($00BCBBB1));
aDest.Colors[aRect.Left + 1, aRect.Top + 1] := CC;
aDest.Colors[aRect.Left, aRect.Top + 2] := CC;
aDest.Colors[aRect.Left + 2, aRect.Top] := CC;
aDest.Colors[aRect.Right - 1, aRect.Top + 1] := CC;
aDest.Colors[aRect.Right, aRect.Top + 2] := CC;
aDest.Colors[aRect.Right - 2, aRect.Top] := CC;
CC := TColorToFPColor(ColorToRGB($00DCDBD1));
aDest.Colors[aRect.Left, aRect.Top + 1] := CC;
aDest.Colors[aRect.Left + 1, aRect.Top] := CC;
aDest.Colors[aRect.Left + 2, aRect.Top + 1] := CC;
aDest.Colors[aRect.Left + 1, aRect.Top + 2] := CC;
aDest.Colors[aRect.Right, aRect.Top + 1] := CC;
aDest.Colors[aRect.Right - 1, aRect.Top] := CC;
aDest.Colors[aRect.Right - 1, aRect.Top + 2] := CC;
aDest.Colors[aRect.Right - 2, aRect.Top + 1] := CC;
end;
end;
procedure DrawTabHeadMask(aDest: TFPCustomCanvas; aRect: TRect;
HeadColor: TColor; IsActive: boolean);
var
lRect: TRect;
CC: TFPColor;
begin
lRect.Bottom := aRect.Bottom;
lRect.Right := aRect.Right;
lRect.Left := aRect.Left;
lRect.Top := aRect.Top + 3;
CC := TColorToFPColor(ColorToRGB(HeadColor));
aDest.Pen.FPColor := CC;
aDest.Brush.FPColor := CC;
aDest.Rectangle(lRect);
aDest.Line(lRect.Left, lRect.Top, lRect.Left, lRect.Bottom);
aDest.Line(lRect.Left + 3, aRect.Top, lRect.Right - 2, aRect.Top);
aDest.Line(lRect.Right, lRect.Top, lRect.Right, lRect.Bottom);
aDest.Line(aRect.Left, aRect.Bottom - 1, aRect.Right, aRect.Bottom - 1);
aDest.Line(lRect.Left + 1, lRect.Top - 1, lRect.Right, lRect.Top - 1);
aDest.Line(lRect.Left + 2, lRect.Top - 2, lRect.Right - 1, lRect.Top - 2);
aDest.Colors[aRect.Left + 1, aRect.Top + 1] := CC;
aDest.Colors[aRect.Left, aRect.Top + 2] := CC;
aDest.Colors[aRect.Left + 2, aRect.Top] := CC;
aDest.Colors[aRect.Right - 1, aRect.Top + 1] := CC;
aDest.Colors[aRect.Right, aRect.Top + 2] := CC;
aDest.Colors[aRect.Right - 2, aRect.Top] := CC;
end;
function GetUniqueName(const Name: string; PControl: TComponent): string; function GetUniqueName(const Name: string; PControl: TComponent): string;
var var
i: integer; i: integer;