mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-16 04:59:20 +02:00
LCL, fixes for dbgrid indicator problems, issues #14139,#14160
git-svn-id: trunk@20912 -
This commit is contained in:
parent
643e154806
commit
731b768329
@ -359,8 +359,6 @@ type
|
|||||||
procedure InvalidateSizes;
|
procedure InvalidateSizes;
|
||||||
procedure ColRowMoved(IsColumn: Boolean; FromIndex,ToIndex: Integer); override;
|
procedure ColRowMoved(IsColumn: Boolean; FromIndex,ToIndex: Integer); override;
|
||||||
function ColumnEditorStyle(aCol: Integer; F: TField): TColumnButtonStyle;
|
function ColumnEditorStyle(aCol: Integer; F: TField): TColumnButtonStyle;
|
||||||
function ColumnFromGridColumn(Column: Integer): TGridColumn; override;
|
|
||||||
function ColumnIndexFromGridColumn(Column: Integer): Integer; override;
|
|
||||||
function CreateColumns: TGridColumns; override;
|
function CreateColumns: TGridColumns; override;
|
||||||
procedure CreateWnd; override;
|
procedure CreateWnd; override;
|
||||||
procedure DefineProperties(Filer: TFiler); override;
|
procedure DefineProperties(Filer: TFiler); override;
|
||||||
@ -383,7 +381,7 @@ type
|
|||||||
function EditorCanAcceptKey(const ch: TUTF8Char): boolean; override;
|
function EditorCanAcceptKey(const ch: TUTF8Char): boolean; override;
|
||||||
function EditorIsReadOnly: boolean; override;
|
function EditorIsReadOnly: boolean; override;
|
||||||
procedure EndLayout;
|
procedure EndLayout;
|
||||||
function FieldIndexFromGridColumn(Column: Integer): Integer;
|
function FieldIndexFromGridColumn(AGridCol: Integer): Integer;
|
||||||
function FirstGridColumn: Integer; override;
|
function FirstGridColumn: Integer; override;
|
||||||
function GetBufferCount: integer;
|
function GetBufferCount: integer;
|
||||||
function GetDefaultColumnAlignment(Column: Integer): TAlignment; override;
|
function GetDefaultColumnAlignment(Column: Integer): TAlignment; override;
|
||||||
@ -719,10 +717,16 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCustomDBGrid.EmptyGrid;
|
procedure TCustomDBGrid.EmptyGrid;
|
||||||
|
var
|
||||||
|
OldFixedCols: Integer;
|
||||||
begin
|
begin
|
||||||
ColCount := FixedCols + 1;
|
OldFixedCols := FixedCols;
|
||||||
|
Clear;
|
||||||
|
ColCount := OldFixedCols + 1;
|
||||||
RowCount := 2;
|
RowCount := 2;
|
||||||
|
FixedCols := OldFixedCols;
|
||||||
FixedRows := 1;
|
FixedRows := 1;
|
||||||
|
if dgIndicator in Options then
|
||||||
ColWidths[0]:=12;
|
ColWidths[0]:=12;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -918,10 +922,12 @@ end;
|
|||||||
procedure TCustomDBGrid.SetOptions(const AValue: TDBGridOptions);
|
procedure TCustomDBGrid.SetOptions(const AValue: TDBGridOptions);
|
||||||
var
|
var
|
||||||
OldOptions: TGridOptions;
|
OldOptions: TGridOptions;
|
||||||
|
ChangedOptions: TDbGridOptions;
|
||||||
MultiSel: boolean;
|
MultiSel: boolean;
|
||||||
begin
|
begin
|
||||||
if FOptions<>AValue then begin
|
if FOptions<>AValue then begin
|
||||||
MultiSel := dgMultiSelect in FOptions;
|
MultiSel := dgMultiSelect in FOptions;
|
||||||
|
ChangedOptions := (FOptions-AValue) + (AValue-FOptions);
|
||||||
FOptions:=AValue;
|
FOptions:=AValue;
|
||||||
OldOptions := inherited Options;
|
OldOptions := inherited Options;
|
||||||
|
|
||||||
@ -980,6 +986,14 @@ begin
|
|||||||
else
|
else
|
||||||
Exclude(OldOptions, goHeaderPushedLook);
|
Exclude(OldOptions, goHeaderPushedLook);
|
||||||
|
|
||||||
|
if (dgIndicator in ChangedOptions) then begin
|
||||||
|
if (dgIndicator in FOptions) then
|
||||||
|
FixedCols := FixedCols + 1
|
||||||
|
else
|
||||||
|
FixedCols := FixedCols - 1;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
inherited Options := OldOptions;
|
inherited Options := OldOptions;
|
||||||
|
|
||||||
if MultiSel and not (dgMultiSelect in FOptions) then begin
|
if MultiSel and not (dgMultiSelect in FOptions) then begin
|
||||||
@ -1237,27 +1251,6 @@ begin
|
|||||||
Result := 0;
|
Result := 0;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TCustomDBGrid.ColumnIndexFromGridColumn(Column: Integer): Integer;
|
|
||||||
begin
|
|
||||||
if (Column < FixedCols) then
|
|
||||||
Result := Column-FirstGridColumn
|
|
||||||
else
|
|
||||||
Result := Columns.RealIndex(Column - FirstGridColumn);
|
|
||||||
end;
|
|
||||||
|
|
||||||
function TCustomDBGrid.ColumnFromGridColumn(Column: Integer): TGridColumn;
|
|
||||||
var ColIndex: Integer;
|
|
||||||
begin
|
|
||||||
if (Column < FixedCols) then
|
|
||||||
ColIndex := Column-FirstGridColumn
|
|
||||||
else
|
|
||||||
ColIndex := Columns.RealIndex(Column - FirstGridColumn);
|
|
||||||
if (ColIndex >= 0) then
|
|
||||||
Result := Columns[ColIndex]
|
|
||||||
else
|
|
||||||
Result := nil;
|
|
||||||
end;
|
|
||||||
|
|
||||||
// obtain the field either from a Db column or directly from dataset fields
|
// obtain the field either from a Db column or directly from dataset fields
|
||||||
function TCustomDBGrid.GetFieldFromGridColumn(Column: Integer): TField;
|
function TCustomDBGrid.GetFieldFromGridColumn(Column: Integer): TField;
|
||||||
var
|
var
|
||||||
@ -1288,33 +1281,27 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
// obtain the visible field index corresponding to the grid column index
|
// obtain the visible field index corresponding to the grid column index
|
||||||
function TCustomDBGrid.FieldIndexFromGridColumn(Column: Integer): Integer;
|
function TCustomDBGrid.FieldIndexFromGridColumn(AGridCol: Integer): Integer;
|
||||||
var
|
var
|
||||||
i, iCol: Integer;
|
i: Integer;
|
||||||
|
Column: TColumn;
|
||||||
begin
|
begin
|
||||||
column := column - FirstGridColumn;
|
|
||||||
i := 0;
|
|
||||||
iCol := 0;
|
|
||||||
result := -1;
|
result := -1;
|
||||||
if FDataLink.Active then begin
|
if not FDatalink.Active then
|
||||||
if (Column < FixedCols) then begin
|
exit;
|
||||||
//Fixed visible columns
|
|
||||||
for iCol:=0 to FDataLink.DataSet.FieldCount-1 do begin
|
if Columns.Enabled then begin
|
||||||
if FDataLink.Fields[iCol].Visible then begin
|
Column := TColumn(ColumnFromGridColumn(AGridCol));
|
||||||
Inc(i);
|
if (Column<>nil) and (Column.Field<>nil) and Column.Field.Visible then
|
||||||
if (i = Column) then begin
|
Result := FDatalink.Dataset.Fields.IndexOf(Column.Field)
|
||||||
Result := i;
|
|
||||||
Break;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
end else begin
|
end else begin
|
||||||
//Normal columns
|
AGridCol := AGridCol - FirstGridColumn;
|
||||||
while (i < FDataLink.DataSet.FieldCount) and (Column >= 0) do begin
|
i := 0;
|
||||||
if FDataLink.Fields[i].Visible then begin
|
while (AGridCol>=0) and (i<FDatalink.DataSet.FieldCount) do begin
|
||||||
Dec(Column);
|
if FDatalink.Fields[i].Visible then begin
|
||||||
if (Column < 0) then begin
|
Dec(AGridCol);
|
||||||
result := i;
|
if AGridCol<0 then begin
|
||||||
|
Result := i;
|
||||||
break;
|
break;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
@ -1322,7 +1309,6 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
|
||||||
|
|
||||||
function TCustomDBGrid.GetBufferCount: integer;
|
function TCustomDBGrid.GetBufferCount: integer;
|
||||||
begin
|
begin
|
||||||
@ -2592,13 +2578,13 @@ procedure TCustomDBGrid.DrawFixedText(aCol, aRow: Integer; aRect: TRect;
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
if (ACol=0) and FDrawingActiveRecord then begin
|
if (ACol=0) and (dgIndicator in Options) and FDrawingActiveRecord then begin
|
||||||
DrawIndicator(Canvas, aRect, GetDataSetState, FDrawingMultiSelRecord);
|
DrawIndicator(Canvas, aRect, GetDataSetState, FDrawingMultiSelRecord);
|
||||||
{$ifdef dbgGridPaint}
|
{$ifdef dbgGridPaint}
|
||||||
dbgOut('>');
|
dbgOut('>');
|
||||||
{$endif}
|
{$endif}
|
||||||
end else
|
end else
|
||||||
if (ACol=0) and FDrawingMultiSelRecord then
|
if (ACol=0) and (dgIndicator in Options) and FDrawingMultiSelRecord then
|
||||||
DrawIndicator(Canvas, aRect, dsCurValue{dummy}, True)
|
DrawIndicator(Canvas, aRect, dsCurValue{dummy}, True)
|
||||||
else
|
else
|
||||||
DrawColumnText(aCol, aRow, aRect, aState);
|
DrawColumnText(aCol, aRow, aRect, aState);
|
||||||
@ -2619,7 +2605,8 @@ begin
|
|||||||
if ((gdFixed in aState) and (aCol < FixedCols)) then
|
if ((gdFixed in aState) and (aCol < FixedCols)) then
|
||||||
begin
|
begin
|
||||||
F := GetFieldFromGridColumn(aCol);
|
F := GetFieldFromGridColumn(aCol);
|
||||||
DrawCellText(aCol, aRow, aRect, aState, F.DisplayText);
|
if F<>nil then
|
||||||
|
DrawCellText(aCol, aRow, aRect, aState, F.DisplayText)
|
||||||
end;//End if (gdFixed in aState)
|
end;//End if (gdFixed in aState)
|
||||||
end;//End if (aRow = 0)
|
end;//End if (aRow = 0)
|
||||||
end;//End if ((gdFixed in aState) and (aCol >= FirstGridColumn))
|
end;//End if ((gdFixed in aState) and (aCol >= FirstGridColumn))
|
||||||
|
@ -793,8 +793,8 @@ type
|
|||||||
procedure ColRowMoved(IsColumn: Boolean; FromIndex,ToIndex: Integer); dynamic;
|
procedure ColRowMoved(IsColumn: Boolean; FromIndex,ToIndex: Integer); dynamic;
|
||||||
function ColRowToOffset(IsCol, Relative: Boolean; Index:Integer;
|
function ColRowToOffset(IsCol, Relative: Boolean; Index:Integer;
|
||||||
var StartPos, EndPos: Integer): Boolean;
|
var StartPos, EndPos: Integer): Boolean;
|
||||||
function ColumnIndexFromGridColumn(Column: Integer): Integer; dynamic;
|
function ColumnIndexFromGridColumn(Column: Integer): Integer;
|
||||||
function ColumnFromGridColumn(Column: Integer): TGridColumn; dynamic;
|
function ColumnFromGridColumn(Column: Integer): TGridColumn;
|
||||||
procedure ColumnsChanged(aColumn: TGridColumn);
|
procedure ColumnsChanged(aColumn: TGridColumn);
|
||||||
procedure ColWidthsChanged; dynamic;
|
procedure ColWidthsChanged; dynamic;
|
||||||
function CreateColumns: TGridColumns; virtual;
|
function CreateColumns: TGridColumns; virtual;
|
||||||
@ -2289,6 +2289,7 @@ begin
|
|||||||
if C<>nil then begin
|
if C<>nil then begin
|
||||||
OldWidth := C.Width;
|
OldWidth := C.Width;
|
||||||
C.Width := AValue;
|
C.Width := AValue;
|
||||||
|
SetRawColWidths(ACol, AValue);
|
||||||
if OldWidth<>C.Width then
|
if OldWidth<>C.Width then
|
||||||
EditorWidthChanged(aCol, C.Width);
|
EditorWidthChanged(aCol, C.Width);
|
||||||
end;
|
end;
|
||||||
@ -3163,7 +3164,7 @@ end;
|
|||||||
procedure TCustomGrid.DrawColumnText(aCol, aRow: Integer; aRect: TRect;
|
procedure TCustomGrid.DrawColumnText(aCol, aRow: Integer; aRect: TRect;
|
||||||
aState: TGridDrawState);
|
aState: TGridDrawState);
|
||||||
begin
|
begin
|
||||||
if (gdFixed in aState) and (aRow=0) and (aCol>=FixedCols) then begin
|
if (gdFixed in aState) and (aRow=0) and (aCol>=FirstGridColumn) then begin
|
||||||
DrawColumnTitleImage(aRect, aCol);
|
DrawColumnTitleImage(aRect, aCol);
|
||||||
DrawCellText(aCol,aRow,aRect,aState,GetColumnTitle(aCol));
|
DrawCellText(aCol,aRow,aRect,aState,GetColumnTitle(aCol));
|
||||||
end;
|
end;
|
||||||
@ -4697,14 +4698,17 @@ end;
|
|||||||
|
|
||||||
function TCustomGrid.ColumnIndexFromGridColumn(Column: Integer): Integer;
|
function TCustomGrid.ColumnIndexFromGridColumn(Column: Integer): Integer;
|
||||||
begin
|
begin
|
||||||
Result := Columns.RealIndex( Column - FixedCols );
|
if Columns.Enabled and (Column>=FirstGridColumn) then
|
||||||
|
result := Columns.RealIndex(Column - FirstGridColumn)
|
||||||
|
else
|
||||||
|
result := -1;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TCustomGrid.ColumnFromGridColumn(Column: Integer): TGridColumn;
|
function TCustomGrid.ColumnFromGridColumn(Column: Integer): TGridColumn;
|
||||||
var
|
var
|
||||||
ColIndex: Integer;
|
ColIndex: Integer;
|
||||||
begin
|
begin
|
||||||
ColIndex := Columns.RealIndex( Column - FixedCols );
|
ColIndex := ColumnIndexFromGridColumn(Column);
|
||||||
if ColIndex>=0 then
|
if ColIndex>=0 then
|
||||||
result := Columns[ColIndex]
|
result := Columns[ColIndex]
|
||||||
else
|
else
|
||||||
@ -6193,7 +6197,7 @@ begin
|
|||||||
Result:=(goEditing in options);
|
Result:=(goEditing in options);
|
||||||
if Result and (ACol>=0) and (ACol<FColumns.Count) then begin
|
if Result and (ACol>=0) and (ACol<FColumns.Count) then begin
|
||||||
C:=ColumnFromGridColumn(ACol);
|
C:=ColumnFromGridColumn(ACol);
|
||||||
Result:=not C.ReadOnly;
|
Result:=(C<>nil) and (not C.ReadOnly);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user