TStringGrid/TDrawGrid Columns fixes, bugs #1359,#1367

git-svn-id: trunk@7988 -
This commit is contained in:
jesus 2005-10-27 18:54:35 +00:00
parent 7b07d9012d
commit 0235d8ac82
2 changed files with 55 additions and 69 deletions

View File

@ -1577,17 +1577,6 @@ procedure TCustomDbGrid.DefaultDrawCell(aCol, aRow: Integer; aRect: TRect;
else else
result := dsInactive; result := dsInactive;
end; end;
procedure FixRectangle;
begin
case Canvas.TextStyle.Alignment of
Classes.taLeftJustify: Inc(aRect.Left, 3);
Classes.taRightJustify: Dec(aRect.Right, 3);
end;
case Canvas.TextStyle.Layout of
tlTop: Inc(aRect.Top, 3);
tlBottom: Dec(aRect.Bottom, 3);
end;
end;
var var
S: string; S: string;
F: TField; F: TField;
@ -1599,10 +1588,8 @@ begin
dbgOut('>'); dbgOut('>');
{$endif} {$endif}
end else end else
if (aRow=0)and(ACol>=FixedCols) then begin if (aRow=0)and(ACol>=FixedCols) then
FixRectangle; DrawCellText(aCol,aRow,aRect,aState,GetColumnTitle(aCol));
Canvas.TextRect(ARect,ARect.Left,ARect.Top,GetColumnTitle(aCol));
end;
end else begin end else begin
F := GetFieldFromGridColumn(aCol); F := GetFieldFromGridColumn(aCol);
case ColumnEditorStyle(aCol, F) of case ColumnEditorStyle(aCol, F) of
@ -1616,8 +1603,7 @@ begin
S := '(blob)'; S := '(blob)';
end else end else
S := ''; S := '';
FixRectangle; DrawCellText(aCol,aRow,aRect,aState,S);
Canvas.TextRect(Arect,ARect.Left,ARect.Top, S);
end; end;
end; end;
end; end;
@ -2504,31 +2490,16 @@ procedure TCustomDbGrid.DefaultDrawColumnCell(const Rect: TRect;
else else
result := dsInactive; result := dsInactive;
end; end;
function FixRectangle: TRect;
begin
result := Rect;
case Canvas.TextStyle.Alignment of
Classes.taLeftJustify: Inc(Result.Left, 3);
Classes.taRightJustify: Dec(Result.Right, 3);
end;
case Canvas.TextStyle.Layout of
tlTop: Inc(Result.Top, 3);
tlBottom: Dec(Result.Bottom, 3);
end;
end;
var var
S: string; S: string;
F: TField; F: TField;
R: TRect;
begin begin
if gdFixed in State then begin if gdFixed in State then begin
if (DataCol=0)and FDrawingActiveRecord then if (DataCol=0)and FDrawingActiveRecord then
DrawArrow(Canvas, Rect, GetDataSetState) DrawArrow(Canvas, Rect, GetDataSetState)
else else
if (DataCol>=FixedCols) then begin if (DataCol>=FixedCols) then
R := FixRectangle(); DrawCellText(0{dummy}, DataCol{dummy}, Rect, State,GetColumnTitle(DataCol));
Canvas.TextRect(R,R.Left,R.Top,GetColumnTitle(DataCol));
end;
end else begin end else begin
F := GetFieldFromGridColumn(DataCol); F := GetFieldFromGridColumn(DataCol);
case ColumnEditorStyle(DataCol, F) of case ColumnEditorStyle(DataCol, F) of
@ -2542,8 +2513,7 @@ begin
S := '(blob)'; S := '(blob)';
end else end else
S := ''; S := '';
FixRectangle(); DrawCellText(0, DataCol, Rect, State, S);
Canvas.TextRect(rect,Rect.Left,Rect.Top, S);
end; end;
end; end;
end; end;

View File

@ -69,6 +69,7 @@ const
const const
DEFCOLWIDTH = 64; DEFCOLWIDTH = 64;
DEFROWHEIGHT= 20;
type type
EGridException = class(Exception); EGridException = class(Exception);
@ -675,7 +676,8 @@ type
procedure DrawBorder; procedure DrawBorder;
procedure DrawByRows; virtual; procedure DrawByRows; virtual;
procedure DrawCell(aCol,aRow:Integer; aRect:TRect; aState:TGridDrawState); virtual; procedure DrawCell(aCol,aRow:Integer; aRect:TRect; aState:TGridDrawState); virtual;
procedure DrawCellGrid(aCol,aRow: Integer; aRect: TRect; astate: TGridDrawState); virtual; procedure DrawCellGrid(aCol,aRow: Integer; aRect: TRect; aState: TGridDrawState); virtual;
procedure DrawCellText(aCol,aRow: Integer; aRect: TRect; aState: TGridDrawState; aText: String); virtual;
procedure DrawColRowMoving; procedure DrawColRowMoving;
procedure DrawEdges; procedure DrawEdges;
//procedure DrawFixedCells; virtual; //procedure DrawFixedCells; virtual;
@ -785,7 +787,7 @@ type
property Columns: TGridColumns read GetColumns write SetColumns stored IsColumnsStored; property Columns: TGridColumns read GetColumns write SetColumns stored IsColumnsStored;
property ColWidths[aCol: Integer]: Integer read GetColWidths write SetColWidths; property ColWidths[aCol: Integer]: Integer read GetColWidths write SetColWidths;
property DefaultColWidth: Integer read FDefColWidth write SetDefColWidth default DEFCOLWIDTH; property DefaultColWidth: Integer read FDefColWidth write SetDefColWidth default DEFCOLWIDTH;
property DefaultRowHeight: Integer read FDefRowHeight write SetDefRowHeight default 20; property DefaultRowHeight: Integer read FDefRowHeight write SetDefRowHeight default DEFROWHEIGHT;
property DefaultDrawing: Boolean read FDefaultDrawing write SetDefaultDrawing default True; property DefaultDrawing: Boolean read FDefaultDrawing write SetDefaultDrawing default True;
property DefaultTextStyle: TTextStyle read FDefaultTextStyle write FDefaultTextStyle; property DefaultTextStyle: TTextStyle read FDefaultTextStyle write FDefaultTextStyle;
property DragDx: Integer read FDragDx write FDragDx; property DragDx: Integer read FDragDx write FDragDx;
@ -2845,6 +2847,20 @@ begin
end; end;
end; end;
procedure TCustomGrid.DrawCellText(aCol, aRow: Integer; aRect: TRect;
aState: TGridDrawState; aText: String);
begin
case Canvas.TextStyle.Alignment of
Classes.taLeftJustify: Inc(aRect.Left, 3);
Classes.taRightJustify: Dec(aRect.Right, 3);
end;
case Canvas.TextStyle.Layout of
tlTop: Inc(aRect.Top, 3);
tlBottom: Dec(aRect.Bottom, 3);
end;
Canvas.TextRect(aRect,ARect.Left,ARect.Top, aText);
end;
procedure TCustomGrid.OnTitleFontChanged(Sender: TObject); procedure TCustomGrid.OnTitleFontChanged(Sender: TObject);
begin begin
if FColumns.Enabled then if FColumns.Enabled then
@ -3765,13 +3781,16 @@ begin
if csDestroying in ComponentState then if csDestroying in ComponentState then
exit; exit;
if AColumn=nil then if AColumn=nil then begin
if Columns.Enabled then begin if Columns.Enabled then begin
if FixedCols + Columns.VisibleCount <> ColCount then
InternalSetColCount( FixedCols + Columns.VisibleCount ) InternalSetColCount( FixedCols + Columns.VisibleCount )
else
VisualChange;
end else end else
if not (csloading in ComponentState) then if not (csloading in ComponentState) then
ColCount := FixedCols + 1 ColCount := FixedCols + 1
else begin end else begin
aCol := Columns.IndexOf(AColumn); aCol := Columns.IndexOf(AColumn);
if ACol>=0 then begin if ACol>=0 then begin
if aColumn.WidthChanged then if aColumn.WidthChanged then
@ -4108,7 +4127,6 @@ begin
end; end;
gsColSizing: gsColSizing:
begin begin
{.$ifdef UseXOR}
if FUseXORFeatures then begin if FUseXORFeatures then begin
if FPrevLine then if FPrevLine then
DrawXorVertLine(FPrevValue); DrawXorVertLine(FPrevValue);
@ -4116,12 +4134,10 @@ begin
FPrevValue := -1; FPrevValue := -1;
ResizeColumn(FSplitter.x, x-FSplitter.y); ResizeColumn(FSplitter.x, x-FSplitter.y);
end; end;
{.$endif}
HeaderSized( True, FSplitter.X); HeaderSized( True, FSplitter.X);
end; end;
gsRowSizing: gsRowSizing:
begin begin
{.$ifdef UseXOR}
if FUseXORFeatures then begin if FUseXORFeatures then begin
if FPrevLine then if FPrevLine then
DrawXorHorzLine(FPrevValue); DrawXorHorzLine(FPrevValue);
@ -4129,7 +4145,6 @@ begin
FPrevValue := -1; FPrevValue := -1;
ResizeRow(FSplitter.y, y-FSplitter.x); ResizeRow(FSplitter.y, y-FSplitter.x);
end; end;
{.$endif}
HeaderSized( False, FSplitter.Y); HeaderSized( False, FSplitter.Y);
end; end;
end; end;
@ -5588,7 +5603,7 @@ begin
RowCount:=Cfg.GetValue('grid/design/rowcount', 5); RowCount:=Cfg.GetValue('grid/design/rowcount', 5);
FixedCols:=Cfg.GetValue('grid/design/fixedcols', 1); FixedCols:=Cfg.GetValue('grid/design/fixedcols', 1);
FixedRows:=Cfg.GetValue('grid/design/fixedrows', 1); FixedRows:=Cfg.GetValue('grid/design/fixedrows', 1);
DefaultRowheight:=Cfg.GetValue('grid/design/defaultrowheight', 20); DefaultRowheight:=Cfg.GetValue('grid/design/defaultrowheight', DEFROWHEIGHT);
DefaultColWidth:=Cfg.getValue('grid/design/defaultcolwidth', DEFCOLWIDTH); DefaultColWidth:=Cfg.getValue('grid/design/defaultcolwidth', DEFCOLWIDTH);
Path:='grid/design/columns/'; Path:='grid/design/columns/';
@ -5696,8 +5711,8 @@ begin
FScrollbars:=ssAutoBoth; FScrollbars:=ssAutoBoth;
fGridState:=gsNormal; fGridState:=gsNormal;
fDefColWidth:=DEFCOLWIDTH; fDefColWidth:=DEFCOLWIDTH;
fDefRowHeight:=20;//18; fDefRowHeight:=DEFROWHEIGHT;
fGridLineColor:=clSilver;//clGray; fGridLineColor:=clSilver;
FGridLineStyle:=psSolid; FGridLineStyle:=psSolid;
fFocusColor:=clRed; fFocusColor:=clRed;
FFixedColor:=clBtnFace; FFixedColor:=clBtnFace;
@ -6188,14 +6203,24 @@ end;
procedure TCustomDrawGrid.DrawCell(aCol,aRow: Integer; aRect: TRect; procedure TCustomDrawGrid.DrawCell(aCol,aRow: Integer; aRect: TRect;
aState:TGridDrawState); aState:TGridDrawState);
var
OldDefaultDrawing: boolean;
begin begin
if Assigned(OnDrawCell) and not(CsDesigning in ComponentState) then begin if Assigned(OnDrawCell) and not(CsDesigning in ComponentState) then begin
PrepareCanvas(aCol, aRow, aState); PrepareCanvas(aCol, aRow, aState);
if DefaultDrawing then if DefaultDrawing then
Canvas.FillRect(aRect); Canvas.FillRect(aRect);
OnDrawCell(Self,aCol,aRow,aRect,aState) OnDrawCell(Self,aCol,aRow,aRect,aState)
end else end else begin
OldDefaultDrawing:=FDefaultDrawing;
FDefaultDrawing:=True;
try
PrepareCanvas(aCol, aRow, aState);
finally
FDefaultDrawing:=OldDefaultDrawing;
end;
DefaultDrawCell(aCol,aRow,aRect,aState); DefaultDrawCell(aCol,aRow,aRect,aState);
end;
inherited DrawCellGrid(aCol,aRow,aRect,aState); inherited DrawCellGrid(aCol,aRow,aRect,aState);
end; end;
@ -6368,18 +6393,18 @@ end;
procedure TCustomDrawGrid.DefaultDrawCell(aCol, aRow: Integer; var aRect: TRect; procedure TCustomDrawGrid.DefaultDrawCell(aCol, aRow: Integer; var aRect: TRect;
aState: TGridDrawState); aState: TGridDrawState);
var var
OldDefaultDrawing: boolean; C: TGridColumn;
begin begin
OldDefaultDrawing:=FDefaultDrawing;
FDefaultDrawing:=True;
try
PrepareCanvas(aCol, aRow, aState);
finally
FDefaultDrawing:=OldDefaultDrawing;
end;
if goColSpanning in Options then CalcCellExtent(acol, arow, aRect); if goColSpanning in Options then CalcCellExtent(acol, arow, aRect);
Canvas.FillRect(aRect); Canvas.FillRect(aRect);
if Columns.Enabled and (gdFixed in aState) and (aRow=0) then begin
// draw the column title if there is any
C := ColumnFromGridColumn(aCol);
if C<>nil then
DrawCellText(aCol,aRow,aRect,aState,C.Title.Caption);
end;
if (goFixedRowNumbering in Options) and (FixedCols >= 1) and (aCol = 0) then if (goFixedRowNumbering in Options) and (FixedCols >= 1) and (aCol = 0) then
Canvas.TextRect(aRect,ARect.Left+3,ARect.Top+3, IntTostr(aRow)); Canvas.TextRect(aRect,ARect.Left+3,ARect.Top+3, IntTostr(aRow));
end; end;
@ -6658,17 +6683,8 @@ procedure TCustomStringGrid.DrawCell(aCol, aRow: Integer; aRect: TRect;
aState: TGridDrawState); aState: TGridDrawState);
begin begin
inherited DrawCell(aCol, aRow, aRect, aState); inherited DrawCell(aCol, aRow, aRect, aState);
if DefaultDrawing then begin if DefaultDrawing then
case Canvas.TextStyle.Alignment of DrawCellText(aCol, aRow, aRect, aState, Cells[aCol,aRow]);
Classes.taLeftJustify: Inc(aRect.Left, 3);
Classes.taRightJustify: Dec(aRect.Right, 3);
end;
case Canvas.TextStyle.Layout of
tlTop: Inc(aRect.Top, 3);
tlBottom: Dec(aRect.Bottom, 3);
end;
Canvas.TextRect(aRect,ARect.Left,ARect.Top, Cells[aCol,aRow]);
end;
end; end;
function TCustomStringGrid.GetEditText(aCol, aRow: Integer): string; function TCustomStringGrid.GetEditText(aCol, aRow: Integer): string;