diff --git a/components/customdrawn/customdrawn_wince.pas b/components/customdrawn/customdrawn_wince.pas index fcd65e8379..437c461b7d 100644 --- a/components/customdrawn/customdrawn_wince.pas +++ b/components/customdrawn/customdrawn_wince.pas @@ -27,8 +27,8 @@ type TCDEditDrawerWinCE = class(TCDEditDrawer) public - procedure DrawToIntfImage(ADest: TFPImageCanvas; CDEdit: TCDEdit); override; - procedure DrawToCanvas(ADest: TCanvas; CDEdit: TCDEdit); override; + procedure DrawToIntfImage(ADest: TFPImageCanvas; CDControl: TCDControl); override; + procedure DrawToCanvas(ADest: TCanvas; CDControl: TCDControl); override; end; { TCDCheckBoxDrawerWinCE } @@ -103,12 +103,12 @@ end; { TCDEditDrawerWinCE } procedure TCDEditDrawerWinCE.DrawToIntfImage(ADest: TFPImageCanvas; - CDEdit: TCDEdit); + CDControl: TCDControl); begin end; -procedure TCDEditDrawerWinCE.DrawToCanvas(ADest: TCanvas; CDEdit: TCDEdit); +procedure TCDEditDrawerWinCE.DrawToCanvas(ADest: TCanvas; CDControl: TCDControl); begin end; diff --git a/components/customdrawn/customdrawncontrols.pas b/components/customdrawn/customdrawncontrols.pas index 6208709f87..e4d3f09d36 100644 --- a/components/customdrawn/customdrawncontrols.pas +++ b/components/customdrawn/customdrawncontrols.pas @@ -26,11 +26,14 @@ uses // customdrawnutils; +const + CDDRAWSTYLE_COUNT = 12; + type TCDDrawStyle = ( // The default is given by the DefaultStyle global variable - dsDefault, + dsDefault = 0, // Operating system styles dsWinCE, dsWin2000, dsWinXP, dsKDE, dsGNOME, dsMacOSX, @@ -44,8 +47,6 @@ type { TCDControl } TCDControl = class(TCustomControl) - private - FIsMouseOver: Boolean; protected FDrawStyle: TCDDrawStyle; FCurrentDrawer: TCDControlDrawer; @@ -54,23 +55,26 @@ type procedure PrepareCurrentDrawer(); virtual; procedure SetDrawStyle(const AValue: TCDDrawStyle); virtual; function GetClientRect: TRect; override; - procedure EraseBackground(DC: HDC); override; // mouse procedure MouseEnter; override; procedure MouseLeave; override; // property DrawStyle: TCDDrawStyle read FDrawStyle write SetDrawStyle; public - property IsMouseOver: Boolean read FIsMouseOver write FIsMouseOver; + // state information + IsMouseOver: Boolean; + // + procedure EraseBackground(DC: HDC); override; + procedure Paint; override; end; TCDControlClass = class of TCDControl; TCDControlDrawer = class public function GetClientRect(AControl: TCDControl): TRect; virtual; abstract; - //procedure DrawToIntfImage(ADest: TFPImageCanvas; AControl: TCDControl); - // virtual; abstract; - //procedure DrawToCanvas(ADest: TCanvas; AControl: TCDControl); virtual; abstract; + procedure DrawToIntfImage(ADest: TFPImageCanvas; AControl: TCDControl); + virtual; abstract; + procedure DrawToCanvas(ADest: TCanvas; AControl: TCDControl); virtual; abstract; end; // =================================== @@ -187,7 +191,6 @@ type public constructor Create(AOwner: TComponent); override; destructor Destroy; override; - procedure EraseBackground(DC: HDC); override; procedure Paint; override; published property Color; @@ -196,8 +199,6 @@ type TCDEditDrawer = class(TCDControlDrawer) public - procedure DrawToIntfImage(ADest: TFPImageCanvas; CDEdit: TCDEdit); virtual; abstract; - procedure DrawToCanvas(ADest: TCanvas; CDEdit: TCDEdit); virtual; abstract; end; {@@ @@ -722,14 +723,35 @@ begin inherited Destroy; end; -procedure TCDEdit.EraseBackground(DC: HDC); -begin - inherited EraseBackground(DC); -end; - procedure TCDEdit.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 + 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; { TCDCheckBox } @@ -992,15 +1014,46 @@ begin 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; begin - FIsMouseOver := True; + IsMouseOver := True; inherited MouseEnter; end; procedure TCDControl.MouseLeave; begin - FIsMouseOver := True; + IsMouseOver := True; inherited MouseLeave; end; @@ -1672,5 +1725,46 @@ begin Result := FTabIndex; 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. diff --git a/components/customdrawn/customdrawnutils.pas b/components/customdrawn/customdrawnutils.pas index 958945185a..2c62312bf5 100644 --- a/components/customdrawn/customdrawnutils.pas +++ b/components/customdrawn/customdrawnutils.pas @@ -26,10 +26,6 @@ procedure DrawAndroidButton(Canvas: TCanvas; Color: TColor); procedure DrawXPTaskbarButton(Canvas: TCanvas; Color: TColor); procedure FPImgCloneRect(IntfImg1, IntfImg2: TLazIntfImage; lRect: TRect; Fast: boolean); 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 DrawCDButtonDown(Canvas: TCanvas; ABackgroundColor: TColor); @@ -78,112 +74,6 @@ begin 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; var i: integer;