customdrawn: Starts the drawing of TCDListView

git-svn-id: trunk@33439 -
This commit is contained in:
sekelsenmat 2011-11-09 15:55:40 +00:00
parent ad54b6620d
commit 8990e8afbb
3 changed files with 334 additions and 210 deletions

View File

@ -83,6 +83,10 @@ type
// TCDListView
procedure DrawListView(ADest: TCanvas; ADestPos: TPoint; ASize: TSize;
AState: TCDControlState; AStateEx: TCDListViewStateEx); override;
procedure DrawReportListView(ADest: TCanvas; ADestPos: TPoint; ASize: TSize;
AState: TCDControlState; AStateEx: TCDListViewStateEx); override;
procedure DrawReportListViewItem(ADest: TCanvas; ADestPos: TPoint; ASize: TSize;
ACurItem: TCDListItems; AState: TCDControlState; AStateEx: TCDListViewStateEx); override;
// TCDCustomTabControl
procedure DrawCTabControl(ADest: TCanvas; ADestPos: TPoint; ASize: TSize;
AState: TCDControlState; AStateEx: TCDCTabControlStateEx); override;
@ -136,6 +140,12 @@ begin
TCDTRACKBAR_RIGHT_SPACING: Result := 9;
TCDTRACKBAR_TOP_SPACING: Result := 5;
TCDTRACKBAR_FRAME_HEIGHT: Result := 17;
//
TCDLISTVIEW_COLUMN_LEFT_SPACING: Result := 10;
TCDLISTVIEW_COLUMN_RIGHT_SPACING: Result := 10;
TCDLISTVIEW_COLUMN_TEXT_LEFT_SPACING: Result := 5;
TCDLISTVIEW_LINE_TOP_SPACING: Result := 3;
TCDLISTVIEW_LINE_BOTTOM_SPACING: Result := 3;
else
Result := 0;
end;
@ -153,8 +163,8 @@ begin
case AMeasureID of
TCDCONTROL_CAPTION_WIDTH: Result := ADest.TextWidth(AStateEx.Caption);
TCDCONTROL_CAPTION_HEIGHT: Result := ADest.TextHeight('ŹÇ')+3;
TCDCTABCONTROL_TAB_HEIGHT: Result := ADest.TextHeight('ŹÇ')+10;
TCDCONTROL_CAPTION_HEIGHT: Result := ADest.TextHeight(cddTestStr)+3;
TCDCTABCONTROL_TAB_HEIGHT: Result := ADest.TextHeight(cddTestStr)+10;
TCDCTABCONTROL_TAB_WIDTH:
begin
lCaption := ATabsStateEx.Tabs.Strings[ATabsStateEx.CurTabIndex];
@ -627,6 +637,8 @@ begin
Size(ASize.cx-lSquareHeight-4, ASize.cy));
// Now the text
ADest.Brush.Style := bsClear;
ADest.Pen.Style := psClear;
ADest.Font.Assign(AStateEx.Font);
ADest.TextOut(lSquareHeight+5, 0, AStateEx.Caption);
end;
@ -758,7 +770,7 @@ var
lTextSize: TSize;
lCaption: String;
begin
FCaptionMiddle := ADest.TextHeight('ŹÇ') div 2;
FCaptionMiddle := ADest.TextHeight(cddTestStr) div 2;
if FCaptionMiddle = 0 then FCaptionMiddle := AStateEx.Font.Size div 2;
if FCaptionMiddle = 0 then FCaptionMiddle := 5;
@ -956,6 +968,101 @@ begin
DrawSunkenFrame(ADest, ADestPos, ASize);
// The contents depend on the view style
case AStateEx.ViewStyle of
vsReport: DrawReportListView(ADest, ADestPos, ASize, AState, AStateEx);
end;
end;
procedure TCDDrawerCommon.DrawReportListView(ADest: TCanvas; ADestPos: TPoint;
ASize: TSize; AState: TCDControlState; AStateEx: TCDListViewStateEx);
var
lColumn: TListColumn;
lWidth: TWidth;
i, j: Integer;
lCurPos: TPoint;
lItemSize: TSize;
lItemCount: Integer;
lCurItem: TCDListItems;
begin
lCurPos := Point(2, 2);
lItemCount := AStateEx.Items.GetItemCount();
// i is an column zero-based index
for i := AStateEx.FirstVisibleColumn to AStateEx.Columns.Count-1 do
begin
lColumn := AStateEx.Columns[i];
lCurPos.Y := 2;
// get the column width
if lColumn.AutoSize then
begin
lItemSize.cx := ADest.GetTextWidth(lColumn.Caption)
+ GetMeasures(TCDLISTVIEW_COLUMN_LEFT_SPACING)
+ GetMeasures(TCDLISTVIEW_COLUMN_RIGHT_SPACING);
if (lColumn.MinWidth > 0) and (lItemSize.cx < lColumn.MinWidth) then lItemSize.cx := lColumn.MinWidth
else if (lColumn.MaxWidth > 0) and (lItemSize.cx > lColumn.MaxWidth) then lItemSize.cx := lColumn.MaxWidth;
end
else lItemSize.cx := lColumn.Width;
// line height measure
lItemSize.cy := ADest.TextHeight(cddTestStr)
+ GetMeasures(TCDLISTVIEW_LINE_TOP_SPACING)
+ GetMeasures(TCDLISTVIEW_LINE_BOTTOM_SPACING);
// Draw the column header
if AStateEx.ShowColumnHeader then
begin
// Foreground
ADest.Brush.Style := bsSolid;
ADest.Brush.Color := Palette.BtnFace; // WIN2000_BTNFACE
ADest.Pen.Style := psClear;
ADest.FillRect(Bounds(lCurPos.X, lCurPos.Y, lItemSize.cx, lItemSize.cy));
// Frame
DrawRaisedFrame(ADest, lCurPos, lItemSize);
// The caption
ADest.Brush.Style := bsClear;
ADest.Pen.Style := psClear;
ADest.TextOut(
lCurPos.X+GetMeasures(TCDLISTVIEW_COLUMN_TEXT_LEFT_SPACING),
lCurPos.Y+GetMeasures(TCDLISTVIEW_LINE_TOP_SPACING),
lColumn.Caption);
Inc(lCurPos.Y, lItemSize.cy);
end;
// j is a zero-based index for lines, ignoring the header
// Draw all items until we get out of the visible area
for j := 0 to lItemCount-1 do
begin
lCurItem := nil;
if i = 0 then lCurItem := AStateEx.Items.GetItem(j)
else if AStateEx.Items.GetItem(j).GetItemCount >= i then
lCurItem := AStateEx.Items.GetItem(j).GetItem(i-1);
if lCurItem = nil then Continue;
// Draw the item
DrawReportListViewItem(ADest, lCurPos, lItemSize, lCurItem, AState, AStateEx);
Inc(lCurPos.Y, lItemSize.CY);
end;
Inc(lCurPos.X, lItemSize.CX);
end;
end;
procedure TCDDrawerCommon.DrawReportListViewItem(ADest: TCanvas;
ADestPos: TPoint; ASize: TSize; ACurItem: TCDListItems; AState: TCDControlState;
AStateEx: TCDListViewStateEx);
begin
ADest.Brush.Style := bsClear;
ADest.Pen.Style := psClear;
ADest.TextOut(
ADestPos.X+GetMeasures(TCDLISTVIEW_COLUMN_TEXT_LEFT_SPACING),
ADestPos.Y+GetMeasures(TCDLISTVIEW_LINE_TOP_SPACING),
ACurItem.Caption);
end;
procedure TCDDrawerCommon.DrawCTabControl(ADest: TCanvas; ADestPos: TPoint;

View File

@ -369,10 +369,12 @@ type
FIconOptions: TIconOptions;
FListItems: TCDListItems;
FProperties: TListViewProperties;
FShowColumnHeader: Boolean;
FViewStyle: TViewStyle;
function GetProperty(AIndex: Integer): Boolean;
procedure SetColumns(AValue: TListColumns);
procedure SetProperty(AIndex: Integer; AValue: Boolean);
procedure SetShowColumnHeader(AValue: Boolean);
procedure SetViewStyle(AValue: TViewStyle);
protected
{ // keyboard
@ -401,10 +403,11 @@ type
property Columns: TListColumns read FColumns write SetColumns;
//property GridLines: Boolean index Ord(lvpGridLines) read GetProperty write SetProperty default False;
property Items: TCDListItems read FListItems;
property ViewStyle: TViewStyle read FViewStyle default vsList;
property ShowColumnHeader: Boolean read FShowColumnHeader write SetShowColumnHeader default True;
property ViewStyle: TViewStyle read FViewStyle write SetViewStyle default vsList;
end;
{TCDTabControl}
{ TCDTabControl }
{ TCDCustomTabControl }
@ -524,187 +527,6 @@ implementation
resourcestring
sTABSHEET_DEFAULT_NAME = 'CTabSheet';
{ TCDListView }
function TCDListView.GetProperty(AIndex: Integer): Boolean;
begin
end;
procedure TCDListView.SetColumns(AValue: TListColumns);
begin
if FColumns=AValue then Exit;
FColumns:=AValue;
end;
procedure TCDListView.SetProperty(AIndex: Integer; AValue: Boolean);
begin
end;
procedure TCDListView.SetViewStyle(AValue: TViewStyle);
begin
if FViewStyle=AValue then Exit;
FViewStyle:=AValue;
end;
function TCDListView.GetControlId: TCDControlID;
begin
Result := cidListView;
end;
procedure TCDListView.CreateControlStateEx;
begin
FLVState := TCDListViewStateEx.Create;
FStateEx := FLVState;
end;
procedure TCDListView.PrepareControlStateEx;
begin
inherited PrepareControlStateEx;
FLVState.Items := FListItems;
FLVState.Columns := FColumns;
FLVState.ViewStyle := FViewStyle;
end;
constructor TCDListView.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
Width := 250;
Height := 150;
FColumns := TListColumns.Create(nil);
FListItems := TCDListItems.Create();
TabStop := True;
// FProperties: TListViewProperties;
// FViewStyle: TViewStyle;
PrepareCurrentDrawer();
end;
destructor TCDListView.Destroy;
begin
FColumns.Free;
FListItems.Free;
inherited Destroy;
end;
{ TCDProgressBar }
procedure TCDProgressBar.SetMax(AValue: integer);
begin
if FMax=AValue then Exit;
FMax:=AValue;
Invalidate;
end;
procedure TCDProgressBar.SetBarShowText(AValue: Boolean);
begin
if FBarShowText=AValue then Exit;
FBarShowText:=AValue;
Invalidate;
end;
procedure TCDProgressBar.SetMin(AValue: integer);
begin
if FMin=AValue then Exit;
FMin:=AValue;
Invalidate;
end;
procedure TCDProgressBar.SetOrientation(AValue: TProgressBarOrientation);
var
lOldWidth: Integer;
begin
if FOrientation=AValue then Exit;
FOrientation:=AValue;
Invalidate;
end;
procedure TCDProgressBar.SetPosition(AValue: integer);
begin
if FPosition=AValue then Exit;
FPosition:=AValue;
Invalidate;
end;
procedure TCDProgressBar.SetSmooth(AValue: Boolean);
begin
if FSmooth=AValue then Exit;
FSmooth:=AValue;
Invalidate;
end;
procedure TCDProgressBar.SetStyle(AValue: TProgressBarStyle);
begin
if FStyle=AValue then Exit;
FStyle:=AValue;
Invalidate;
end;
function TCDProgressBar.GetControlId: TCDControlID;
begin
Result := cidProgressBar;
end;
procedure TCDProgressBar.CreateControlStateEx;
begin
FPBState := TCDProgressBarStateEx.Create;
FStateEx := FPBState;
end;
procedure TCDProgressBar.PrepareControlStateEx;
begin
inherited PrepareControlStateEx;
if FMax <> FMin then FPBState.PercentPosition := (FPosition-FMin)/(FMax-FMin)
else FPBState.PercentPosition := 1.0;
FPBState.BarShowText := FBarShowText;
FPBState.Style := FStyle;
FPBState.Orientation := FOrientation;
FPBState.Smooth := FSmooth;
end;
constructor TCDProgressBar.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
Width := 100;
Height := 20;
FMax := 100;
TabStop := False;
PrepareCurrentDrawer();
end;
destructor TCDProgressBar.Destroy;
begin
inherited Destroy;
end;
{ TCDStaticText }
function TCDStaticText.GetControlId: TCDControlID;
begin
Result:=cidStaticText;
end;
procedure TCDStaticText.RealSetText(const Value: TCaption);
begin
inherited RealSetText(Value);
Invalidate;
end;
constructor TCDStaticText.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
Width := 70;
Height := 20;
TabStop := False;
ControlStyle := ControlStyle - [csAcceptsControls];
end;
destructor TCDStaticText.Destroy;
begin
inherited Destroy;
end;
{ TCDControl }
procedure TCDControl.CalculatePreferredSize(var PreferredWidth,
@ -1392,6 +1214,33 @@ begin
inherited Destroy;
end;
{ TCDStaticText }
function TCDStaticText.GetControlId: TCDControlID;
begin
Result:=cidStaticText;
end;
procedure TCDStaticText.RealSetText(const Value: TCaption);
begin
inherited RealSetText(Value);
Invalidate;
end;
constructor TCDStaticText.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
Width := 70;
Height := 20;
TabStop := False;
ControlStyle := ControlStyle - [csAcceptsControls];
end;
destructor TCDStaticText.Destroy;
begin
inherited Destroy;
end;
{ TCDTrackBar }
procedure TCDTrackBar.SetMax(Value: integer);
@ -1596,30 +1445,171 @@ begin
inherited Destroy;
end;
{procedure TCDTrackBar.Paint;
var
AImage: TLazIntfImage = nil;
ABmp: TBitmap = nil;
lCanvas: TFPImageCanvas = nil;
{ TCDProgressBar }
procedure TCDProgressBar.SetMax(AValue: integer);
begin
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, AImage, Self);
ABmp.LoadFromIntfImage(AImage);
Canvas.Draw(0, 0, ABmp);
finally
if lCanvas <> nil then
lCanvas.Free;
if AImage <> nil then
AImage.Free;
ABmp.Free;
end;
end;}
if FMax=AValue then Exit;
FMax:=AValue;
if not (csLoading in ComponentState) then Invalidate;
end;
procedure TCDProgressBar.SetBarShowText(AValue: Boolean);
begin
if FBarShowText=AValue then Exit;
FBarShowText:=AValue;
if not (csLoading in ComponentState) then Invalidate;
end;
procedure TCDProgressBar.SetMin(AValue: integer);
begin
if FMin=AValue then Exit;
FMin:=AValue;
if not (csLoading in ComponentState) then Invalidate;
end;
procedure TCDProgressBar.SetOrientation(AValue: TProgressBarOrientation);
var
lOldWidth: Integer;
begin
if FOrientation=AValue then Exit;
FOrientation:=AValue;
if not (csLoading in ComponentState) then Invalidate;
end;
procedure TCDProgressBar.SetPosition(AValue: integer);
begin
if FPosition=AValue then Exit;
FPosition:=AValue;
if not (csLoading in ComponentState) then Invalidate;
end;
procedure TCDProgressBar.SetSmooth(AValue: Boolean);
begin
if FSmooth=AValue then Exit;
FSmooth:=AValue;
if not (csLoading in ComponentState) then
Invalidate;
end;
procedure TCDProgressBar.SetStyle(AValue: TProgressBarStyle);
begin
if FStyle=AValue then Exit;
FStyle:=AValue;
if not (csLoading in ComponentState) then Invalidate;
end;
function TCDProgressBar.GetControlId: TCDControlID;
begin
Result := cidProgressBar;
end;
procedure TCDProgressBar.CreateControlStateEx;
begin
FPBState := TCDProgressBarStateEx.Create;
FStateEx := FPBState;
end;
procedure TCDProgressBar.PrepareControlStateEx;
begin
inherited PrepareControlStateEx;
if FMax <> FMin then FPBState.PercentPosition := (FPosition-FMin)/(FMax-FMin)
else FPBState.PercentPosition := 1.0;
FPBState.BarShowText := FBarShowText;
FPBState.Style := FStyle;
FPBState.Orientation := FOrientation;
FPBState.Smooth := FSmooth;
end;
constructor TCDProgressBar.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
Width := 100;
Height := 20;
FMax := 100;
TabStop := False;
PrepareCurrentDrawer();
end;
destructor TCDProgressBar.Destroy;
begin
inherited Destroy;
end;
{ TCDListView }
function TCDListView.GetProperty(AIndex: Integer): Boolean;
begin
end;
procedure TCDListView.SetColumns(AValue: TListColumns);
begin
if FColumns=AValue then Exit;
FColumns:=AValue;
if not (csLoading in ComponentState) then Invalidate;
end;
procedure TCDListView.SetProperty(AIndex: Integer; AValue: Boolean);
begin
end;
procedure TCDListView.SetShowColumnHeader(AValue: Boolean);
begin
if FShowColumnHeader=AValue then Exit;
FShowColumnHeader:=AValue;
if not (csLoading in ComponentState) then Invalidate;
end;
procedure TCDListView.SetViewStyle(AValue: TViewStyle);
begin
if FViewStyle=AValue then Exit;
FViewStyle:=AValue;
if not (csLoading in ComponentState) then Invalidate;
end;
function TCDListView.GetControlId: TCDControlID;
begin
Result := cidListView;
end;
procedure TCDListView.CreateControlStateEx;
begin
FLVState := TCDListViewStateEx.Create;
FStateEx := FLVState;
end;
procedure TCDListView.PrepareControlStateEx;
begin
inherited PrepareControlStateEx;
FLVState.Items := FListItems;
FLVState.Columns := FColumns;
FLVState.ViewStyle := FViewStyle;
FLVState.ShowColumnHeader := FShowColumnHeader;
end;
constructor TCDListView.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
Width := 250;
Height := 150;
FColumns := TListColumns.Create(nil);
FListItems := TCDListItems.Create();
TabStop := True;
FShowColumnHeader := True;
// FProperties: TListViewProperties;
// FViewStyle: TViewStyle;
PrepareCurrentDrawer();
end;
destructor TCDListView.Destroy;
begin
FColumns.Free;
FListItems.Free;
inherited Destroy;
end;
{ TCDTabSheet }

View File

@ -12,6 +12,8 @@ uses
const
CDDRAWSTYLE_COUNT = 19;
cddTestStr = 'ŹÇ'; // Used for testing text height
// Measures
TCDEDIT_LEFT_TEXT_SPACING = $400; // The space between the start of the text and the left end of the control
TCDEDIT_RIGHT_TEXT_SPACING = $401; // The space between the end of the text and the right end of the control
@ -28,6 +30,12 @@ const
TCDTRACKBAR_TOP_SPACING = $1002;
TCDTRACKBAR_FRAME_HEIGHT = $1003;
TCDLISTVIEW_COLUMN_LEFT_SPACING = $1200;
TCDLISTVIEW_COLUMN_RIGHT_SPACING = $1201;
TCDLISTVIEW_COLUMN_TEXT_LEFT_SPACING = $1202;
TCDLISTVIEW_LINE_TOP_SPACING = $1203;
TCDLISTVIEW_LINE_BOTTOM_SPACING = $1204;
// Measures Ex
TCDCONTROL_CAPTION_WIDTH = $100;
TCDCONTROL_CAPTION_HEIGHT = $101;
@ -75,7 +83,7 @@ type
csfOn,
csfOff,
csfPartiallyOn
{ // for TCDPageControl
{ // for TCDComboBox
csfDownArrow,
// for tool button
csfAutoRaise,
@ -149,6 +157,8 @@ type
constructor Create;
destructor Destroy; override;
function Add(ACaption: string; AImageIndex, AStateIndex: Integer): TCDListItems;
function GetItem(AIndex: Integer): TCDListItems;
function GetItemCount: Integer;
end;
TCDListViewStateEx = class(TCDControlStateEx)
@ -156,6 +166,9 @@ type
Columns: TListColumns; // just a reference, never free
Items: TCDListItems; // just a reference, never free
ViewStyle: TViewStyle;
FirstVisibleColumn: Integer; // 0-based index
FirstVisibleLine: Integer; // 0-based index, remember that the header is always visible or always invisible
ShowColumnHeader: Boolean;
end;
TCDCTabControlStateEx = class(TCDControlStateEx)
@ -278,6 +291,10 @@ type
// TCDListView
procedure DrawListView(ADest: TCanvas; ADestPos: TPoint; ASize: TSize;
AState: TCDControlState; AStateEx: TCDListViewStateEx); virtual; abstract;
procedure DrawReportListView(ADest: TCanvas; ADestPos: TPoint; ASize: TSize;
AState: TCDControlState; AStateEx: TCDListViewStateEx); virtual; abstract;
procedure DrawReportListViewItem(ADest: TCanvas; ADestPos: TPoint; ASize: TSize;
ACurItem: TCDListItems; AState: TCDControlState; AStateEx: TCDListViewStateEx); virtual; abstract;
// TCDCustomTabControl
procedure DrawCTabControl(ADest: TCanvas; ADestPos: TPoint; ASize: TSize;
AState: TCDControlState; AStateEx: TCDCTabControlStateEx); virtual; abstract;
@ -357,6 +374,16 @@ begin
Childs.Add(Pointer(Result));
end;
function TCDListItems.GetItem(AIndex: Integer): TCDListItems;
begin
Result := TCDListItems(Childs.Items[AIndex]);
end;
function TCDListItems.GetItemCount: Integer;
begin
Result := Childs.Count;
end;
{ TCDDrawer }
constructor TCDDrawer.Create;