fix bug in RxDBGrid - tnx haword from freepascal.ru

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@2310 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
alexs75
2012-02-23 04:46:16 +00:00
parent db4f915436
commit 6c209927e9

View File

@ -50,6 +50,11 @@ const
VK_END, VK_SPACE, VK_MULTIPLY]; VK_END, VK_SPACE, VK_MULTIPLY];
type type
//forward declarations
TRxDBGrid = class;
TRxColumn = class;
TRxQuickSearchNotifyEvent = procedure(Sender: TObject; Field: TField; TRxQuickSearchNotifyEvent = procedure(Sender: TObject; Field: TField;
var AValue: string) of object; var AValue: string) of object;
@ -139,7 +144,31 @@ type
default; default;
end; end;
TRxColumn = class; { TRxDBGridFooterOptions }
TRxDBGridFooterOptions = class(TPersistent)
private
FActive: boolean;
FColor: TColor;
FOwner: TRxDBGrid;
FRowCount: integer;
FStyle: TTitleStyle;
procedure SetActive(AValue: boolean);
procedure SetColor(AValue: TColor);
procedure SetRowCount(AValue: integer);
procedure SetStyle(AValue: TTitleStyle);
protected
procedure AssignTo(Dest: TPersistent); override;
public
constructor Create(Owner: TRxDBGrid);
destructor Destroy; override;
published
property Active: boolean read FActive write SetActive default false;
property Color: TColor read FColor write SetColor default clWindow;
property RowCount: integer read FRowCount write SetRowCount default 0;
property Style: TTitleStyle read FStyle write SetStyle default tsLazarus;
end;
{ TRxDBGridSortEngine } { TRxDBGridSortEngine }
TRxSortEngineOption = (seoCaseInsensitiveSort); TRxSortEngineOption = (seoCaseInsensitiveSort);
@ -327,10 +356,11 @@ type
{ TRxDBGrid } { TRxDBGrid }
TRxDBGrid = class(TCustomDBGrid) TRxDBGrid = class(TCustomDBGrid)
private private
FFooterOptions: TRxDBGridFooterOptions;
FSortingNow:Boolean; FSortingNow:Boolean;
FInProcessCalc: integer; FInProcessCalc: integer;
FAllowedOperations: TRxDBGridAllowedOperations; FAllowedOperations: TRxDBGridAllowedOperations;
FFooterColor: TColor; //FFooterColor: TColor;
FFooterRowCount: integer; FFooterRowCount: integer;
FKeyStrokes: TRxDBGridKeyStrokes; FKeyStrokes: TRxDBGridKeyStrokes;
FOnGetCellProps: TGetCellPropsEvent; FOnGetCellProps: TGetCellPropsEvent;
@ -382,12 +412,15 @@ type
procedure DoCreateJMenu; procedure DoCreateJMenu;
function GetColumns: TRxDbGridColumns; function GetColumns: TRxDbGridColumns;
function GetFooterColor: TColor;
function GetFooterRowCount: integer;
function GetPropertyStorage: TCustomPropertyStorage; function GetPropertyStorage: TCustomPropertyStorage;
function GetTitleButtons: boolean; function GetTitleButtons: boolean;
function IsColumnsStored: boolean; function IsColumnsStored: boolean;
procedure SetAutoSort(const AValue: boolean); procedure SetAutoSort(const AValue: boolean);
procedure SetColumns(const AValue: TRxDbGridColumns); procedure SetColumns(const AValue: TRxDbGridColumns);
procedure SetFooterColor(const AValue: TColor); procedure SetFooterColor(const AValue: TColor);
procedure SetFooterOptions(AValue: TRxDBGridFooterOptions);
procedure SetFooterRowCount(const AValue: integer); procedure SetFooterRowCount(const AValue: integer);
procedure SetKeyStrokes(const AValue: TRxDBGridKeyStrokes); procedure SetKeyStrokes(const AValue: TRxDBGridKeyStrokes);
procedure SetOptionsRx(const AValue: TOptionsRx); procedure SetOptionsRx(const AValue: TOptionsRx);
@ -513,6 +546,7 @@ type
property Columns: TRxDbGridColumns property Columns: TRxDbGridColumns
read GetColumns write SetColumns stored IsColumnsStored; read GetColumns write SetColumns stored IsColumnsStored;
property KeyStrokes: TRxDBGridKeyStrokes read FKeyStrokes write SetKeyStrokes; property KeyStrokes: TRxDBGridKeyStrokes read FKeyStrokes write SetKeyStrokes;
property FooterOptions:TRxDBGridFooterOptions read FFooterOptions write SetFooterOptions;
//storage //storage
property PropertyStorage: TCustomPropertyStorage property PropertyStorage: TCustomPropertyStorage
@ -522,10 +556,13 @@ type
read FAllowedOperations write FAllowedOperations default read FAllowedOperations write FAllowedOperations default
[aoInsert, aoUpdate, aoDelete, aoAppend]; [aoInsert, aoUpdate, aoDelete, aoAppend];
property OptionsRx: TOptionsRx read FOptionsRx write SetOptionsRx; property OptionsRx: TOptionsRx read FOptionsRx write SetOptionsRx;
property FooterColor: TColor read FFooterColor write SetFooterColor default clWindow; // property FooterColor: TColor read FFooterColor write SetFooterColor default clWindow;
property FooterRowCount: integer read FFooterRowCount property FooterColor: TColor read GetFooterColor write SetFooterColor default clWindow; deprecated;
write SetFooterRowCount default 0; // property FooterRowCount: integer read FFooterRowCount write SetFooterRowCount default 0;
property FooterRowCount: integer read GetFooterRowCount write SetFooterRowCount default 0; deprecated;
property OnFiltred: TNotifyEvent read FOnFiltred write FOnFiltred; property OnFiltred: TNotifyEvent read FOnFiltred write FOnFiltred;
//from DBGrid //from DBGrid
property Align; property Align;
property AlternateColor; property AlternateColor;
@ -700,6 +737,64 @@ type
procedure EditingDone; override; procedure EditingDone; override;
end; end;
{ TRxDBGridFooterOptions }
procedure TRxDBGridFooterOptions.SetActive(AValue: boolean);
begin
if FActive=AValue then Exit;
FActive:=AValue;
end;
procedure TRxDBGridFooterOptions.SetColor(AValue: TColor);
begin
if FColor=AValue then Exit;
FColor:=AValue;
FOwner.Invalidate;
end;
procedure TRxDBGridFooterOptions.SetRowCount(AValue: integer);
begin
if FRowCount=AValue then Exit;
FRowCount:=AValue;
FOwner.VisualChange;
end;
procedure TRxDBGridFooterOptions.SetStyle(AValue: TTitleStyle);
begin
if FStyle=AValue then Exit;
FStyle:=AValue;
end;
procedure TRxDBGridFooterOptions.AssignTo(Dest: TPersistent);
var
FO:TRxDBGridFooterOptions absolute Dest;
begin
if Dest is TRxDBGridFooterOptions then
begin
FO.Active:=Active;
FO.Color:=Color;
FO.RowCount:=RowCount;
FO.Style:=Style;
end
else
inherited AssignTo(Dest);
end;
constructor TRxDBGridFooterOptions.Create(Owner: TRxDBGrid);
begin
inherited Create;
FOwner:=Owner;
FColor := clWindow;
FRowCount := 0;
FStyle := tsLazarus;
end;
destructor TRxDBGridFooterOptions.Destroy;
begin
inherited Destroy;
end;
{ TRxDBGridDateEditor } { TRxDBGridDateEditor }
@ -1152,6 +1247,16 @@ begin
Result := TRxDbGridColumns(TCustomDrawGrid(Self).Columns); Result := TRxDbGridColumns(TCustomDrawGrid(Self).Columns);
end; end;
function TRxDBGrid.GetFooterColor: TColor;
begin
Result:=FFooterOptions.FColor;
end;
function TRxDBGrid.GetFooterRowCount: integer;
begin
Result:=FFooterOptions.RowCount;
end;
function TRxDBGrid.GetDrawFullLine: boolean; function TRxDBGrid.GetDrawFullLine: boolean;
begin begin
Result := FDrawFullLine; Result := FDrawFullLine;
@ -1212,19 +1317,26 @@ end;
procedure TRxDBGrid.SetFooterColor(const AValue: TColor); procedure TRxDBGrid.SetFooterColor(const AValue: TColor);
begin begin
if FFooterColor = AValue then { if FFooterColor = AValue then
exit; exit;
FFooterColor := AValue; FFooterOptions.FColor := AValue;
Invalidate; Invalidate;}
FFooterOptions.Color := AValue;
end;
procedure TRxDBGrid.SetFooterOptions(AValue: TRxDBGridFooterOptions);
begin
FFooterOptions.AssignTo(AValue);
end; end;
procedure TRxDBGrid.SetFooterRowCount(const AValue: integer); procedure TRxDBGrid.SetFooterRowCount(const AValue: integer);
begin begin
if FFooterRowCount = AValue then { if FFooterRowCount = AValue then
exit; exit;
FFooterRowCount := AValue; FFooterRowCount := AValue;
VisualChange; VisualChange;
// Invalidate; // Invalidate;}
FFooterOptions.RowCount:=AValue;
end; end;
procedure TRxDBGrid.SetKeyStrokes(const AValue: TRxDBGridKeyStrokes); procedure TRxDBGrid.SetKeyStrokes(const AValue: TRxDBGridKeyStrokes);
@ -1516,7 +1628,7 @@ begin
DrawThemedCell(aCol, aRow, aRect, aState) DrawThemedCell(aCol, aRow, aRect, aState)
else else
begin begin
// Canvas.FillRect(aRect); Canvas.FillRect(aRect);
DrawCellGrid(aCol, aRow, aRect, aState); DrawCellGrid(aCol, aRow, aRect, aState);
end; end;
@ -1887,14 +1999,34 @@ var
TxS: TTextStyle; TxS: TTextStyle;
begin begin
if (dgIndicator in Options) and (aCol = 0) then { if (dgIndicator in Options) and (aCol = 0) then
begin begin
Canvas.FillRect(aRect); Canvas.FillRect(aRect);
DrawCellGrid(aCol, aRow, aRect, aState); DrawCellGrid(aCol, aRow, aRect, aState);
exit; exit;
end; end;
DrawCellGrid(aCol, aRow, aRect, aState);}
if (dgIndicator in Options) and (aCol = 0) then
begin
if (TitleStyle = tsNative) then
DrawThemedCell(aCol, aRow, aRect, aState)
else
begin
Canvas.FillRect(aRect);
DrawCellGrid(aCol, aRow, aRect, aState); DrawCellGrid(aCol, aRow, aRect, aState);
end;
exit;
end;
if (TitleStyle = tsNative) then
DrawThemedCell(aCol, aRow, aRect, aState)
else
begin
Canvas.FillRect(aRect);
DrawCellGrid(aCol, aRow, aRect, aState);
end;
Inc(aRect.Left, 1); Inc(aRect.Left, 1);
Dec(aRect.Right, 1); Dec(aRect.Right, 1);
Inc(aRect.Top, 1); Inc(aRect.Top, 1);
@ -1904,14 +2036,21 @@ begin
begin begin
bg := Canvas.Brush.Color; bg := Canvas.Brush.Color;
al := Canvas.TextStyle.Alignment; al := Canvas.TextStyle.Alignment;
ft := Canvas.Font; // ft := Canvas.Font;
ft:=TFont.Create;
ft.Assign(Canvas.Font);
TxS := Canvas.TextStyle; TxS := Canvas.TextStyle;
MyCol := Columns.RealIndex(aCol - 1); MyCol := Columns.RealIndex(aCol - 1);
with TRxColumn(Columns[MyCol]).Filter do with TRxColumn(Columns[MyCol]).Filter do
begin begin
// Canvas.Brush.Color := Color;
// Canvas.FillRect(aRect);
if (TitleStyle <> tsNative) then
begin
Canvas.Brush.Color := Color; Canvas.Brush.Color := Color;
Canvas.FillRect(aRect); Canvas.FillRect(aRect);
end;
if Value <> '' then if Value <> '' then
begin begin
@ -1937,7 +2076,9 @@ begin
end; end;
end; end;
Canvas.Font := ft; // Canvas.Font := ft;
Canvas.Font.Assign(ft);
ft.Free;
Canvas.Brush.Color := bg; Canvas.Brush.Color := bg;
// Canvas.TextStyle.Alignment := al; // Canvas.TextStyle.Alignment := al;
TxS.Alignment := al; TxS.Alignment := al;
@ -2101,6 +2242,8 @@ begin
DataSource.DataSet.OnPostError := @ErrorPo; DataSource.DataSet.OnPostError := @ErrorPo;
end; end;
CalcStatTotals; CalcStatTotals;
if rdgFilter in OptionsRx then
OnFilter(nil);
end end
else else
begin begin
@ -2116,7 +2259,9 @@ begin
F_EventOnDeleteError := nil; F_EventOnDeleteError := nil;
DataSource.DataSet.OnPostError := F_EventOnPostError; DataSource.DataSet.OnPostError := F_EventOnPostError;
F_EventOnPostError := nil; F_EventOnPostError := nil;
OptionsRx := OptionsRx - [rdgFilter]; // OptionsRx := OptionsRx - [rdgFilter];
if rdgFilter in OptionsRx then
OnFilter(nil);
end; end;
F_LastFilter.Clear; F_LastFilter.Clear;
end; end;
@ -2154,7 +2299,7 @@ begin
R.Top := TotalYOffs; R.Top := TotalYOffs;
R.Bottom := TotalYOffs + DefaultRowHeight * FooterRowCount + 2; R.Bottom := TotalYOffs + DefaultRowHeight * FooterRowCount + 2;
Canvas.Brush.Color := FFooterColor; Canvas.Brush.Color := FFooterOptions.FColor;
if (Columns.Count > 0) then if (Columns.Count > 0) then
begin begin
TxS := Canvas.TextStyle; TxS := Canvas.TextStyle;
@ -2198,7 +2343,11 @@ begin
for i := 0 to FixedCols - 1 do for i := 0 to FixedCols - 1 do
begin begin
ColRowToOffset(True, True, i, R.Left, R.Right); ColRowToOffset(True, True, i, R.Left, R.Right);
if FFooterOptions.FStyle = tsNative then
DrawThemedCell(i, 0, R, [gdFixed])
else
DrawCellGrid(i, 0, R, [gdFixed]); DrawCellGrid(i, 0, R, [gdFixed]);
if ((R.Left < ClipArea.Right) and (R.Right > ClipArea.Left)) then if ((R.Left < ClipArea.Right) and (R.Right > ClipArea.Left)) then
DrawCell(i, 0, R, [gdFixed]); DrawCell(i, 0, R, [gdFixed]);
end; end;
@ -3055,6 +3204,8 @@ begin
C.Filter.ValueList.Add(C.Filter.EmptyValue); C.Filter.ValueList.Add(C.Filter.EmptyValue);
end; end;
if DatalinkActive then
begin
DataSource.DataSet.DisableControls; DataSource.DataSet.DisableControls;
DataSource.DataSet.Filtered := True; DataSource.DataSet.Filtered := True;
DataSource.DataSet.First; DataSource.DataSet.First;
@ -3071,6 +3222,7 @@ begin
DataSource.DataSet.First; DataSource.DataSet.First;
DataSource.DataSet.EnableControls; DataSource.DataSet.EnableControls;
end; end;
end;
procedure TRxDBGrid.OnFilterClose(Sender: TObject); procedure TRxDBGrid.OnFilterClose(Sender: TObject);
var var
@ -3178,7 +3330,7 @@ begin
FAllowedOperations := [aoInsert, aoUpdate, aoDelete, aoAppend]; FAllowedOperations := [aoInsert, aoUpdate, aoDelete, aoAppend];
//FFooterColor:=clWindow; //FFooterColor:=clWindow;
FFooterColor := clYellow; //FFooterColor := clYellow;
FFooterRowCount := 0; FFooterRowCount := 0;
FFilterListEditor := TFilterListCellEditor.Create(nil); FFilterListEditor := TFilterListCellEditor.Create(nil);
@ -3202,6 +3354,8 @@ begin
FRxDbGridDateEditor.Name := 'RxDbGridDateEditor'; FRxDbGridDateEditor.Name := 'RxDbGridDateEditor';
FRxDbGridDateEditor.Visible := False; FRxDbGridDateEditor.Visible := False;
FFooterOptions:=TRxDBGridFooterOptions.Create(Self);
UpdateJMenuKeys; UpdateJMenuKeys;
end; end;
@ -3209,6 +3363,8 @@ destructor TRxDBGrid.Destroy;
begin begin
CleanDSEvent; CleanDSEvent;
FreeAndNil(FFooterOptions);
FreeAndNil(FRxDbGridLookupComboEditor); FreeAndNil(FRxDbGridLookupComboEditor);
FreeAndNil(FRxDbGridDateEditor); FreeAndNil(FRxDbGridDateEditor);
FreeAndNil(FMarkerDown); FreeAndNil(FMarkerDown);
@ -3886,7 +4042,7 @@ begin
// FColor := clSkyBlue; // FColor := clSkyBlue;
FEmptyFont.Style := [fsItalic]; FEmptyFont.Style := [fsItalic];
FEmptyValue := sRxDBGridEmptiFilter; FEmptyValue := sRxDBGridEmptiFilter;
FFont.Style := [fsItalic]; //FFont.Style := [fsItalic];
end; end;
destructor TRxColumnFilter.Destroy; destructor TRxColumnFilter.Destroy;