You've already forked lazarus-ccr
tvplanit: Add "check/uncheck all" checkbox to header of the grid in the import preview form.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8399 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -2,68 +2,26 @@ object VpImportPreviewForm: TVpImportPreviewForm
|
|||||||
Left = 327
|
Left = 327
|
||||||
Height = 295
|
Height = 295
|
||||||
Top = 127
|
Top = 127
|
||||||
Width = 603
|
Width = 634
|
||||||
Caption = 'VpImportPreviewForm'
|
Caption = 'VpImportPreviewForm'
|
||||||
ClientHeight = 295
|
ClientHeight = 295
|
||||||
ClientWidth = 603
|
ClientWidth = 634
|
||||||
LCLVersion = '2.3.0.0'
|
|
||||||
object Grid: TDrawGrid
|
|
||||||
Left = 0
|
|
||||||
Height = 258
|
|
||||||
Top = 0
|
|
||||||
Width = 603
|
|
||||||
Align = alClient
|
|
||||||
AutoFillColumns = True
|
|
||||||
ColCount = 3
|
|
||||||
Columns = <
|
|
||||||
item
|
|
||||||
Alignment = taCenter
|
|
||||||
ButtonStyle = cbsCheckboxColumn
|
|
||||||
SizePriority = 0
|
|
||||||
Title.Caption = ''
|
|
||||||
Width = 33
|
|
||||||
end
|
|
||||||
item
|
|
||||||
ReadOnly = True
|
|
||||||
Title.Caption = 'Title'
|
|
||||||
Width = 410
|
|
||||||
end
|
|
||||||
item
|
|
||||||
ButtonStyle = cbsPickList
|
|
||||||
SizePriority = 0
|
|
||||||
Title.Caption = 'Title'
|
|
||||||
Width = 160
|
|
||||||
end>
|
|
||||||
ExtendedSelect = False
|
|
||||||
FixedCols = 0
|
|
||||||
Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goRangeSelect, goColSizing, goEditing, goSmoothScroll]
|
|
||||||
TabOrder = 0
|
|
||||||
OnDrawCell = GridDrawCell
|
|
||||||
OnGetCheckboxState = GridGetCheckboxState
|
|
||||||
OnPrepareCanvas = GridPrepareCanvas
|
|
||||||
OnSetCheckboxState = GridSetCheckboxState
|
|
||||||
ColWidths = (
|
|
||||||
33
|
|
||||||
410
|
|
||||||
160
|
|
||||||
)
|
|
||||||
end
|
|
||||||
object ButtonPanel: TPanel
|
object ButtonPanel: TPanel
|
||||||
Left = 6
|
Left = 6
|
||||||
Height = 25
|
Height = 25
|
||||||
Top = 264
|
Top = 264
|
||||||
Width = 591
|
Width = 622
|
||||||
Align = alBottom
|
Align = alBottom
|
||||||
AutoSize = True
|
AutoSize = True
|
||||||
BorderSpacing.Around = 6
|
BorderSpacing.Around = 6
|
||||||
BevelOuter = bvNone
|
BevelOuter = bvNone
|
||||||
ClientHeight = 25
|
ClientHeight = 25
|
||||||
ClientWidth = 591
|
ClientWidth = 622
|
||||||
TabOrder = 1
|
TabOrder = 0
|
||||||
object btnExecute: TButton
|
object btnExecute: TButton
|
||||||
AnchorSideTop.Control = ButtonPanel
|
AnchorSideTop.Control = ButtonPanel
|
||||||
AnchorSideRight.Control = btnCancel
|
AnchorSideRight.Control = btnCancel
|
||||||
Left = 375
|
Left = 406
|
||||||
Height = 25
|
Height = 25
|
||||||
Top = 0
|
Top = 0
|
||||||
Width = 141
|
Width = 141
|
||||||
@ -77,7 +35,7 @@ object VpImportPreviewForm: TVpImportPreviewForm
|
|||||||
AnchorSideTop.Control = ButtonPanel
|
AnchorSideTop.Control = ButtonPanel
|
||||||
AnchorSideRight.Control = ButtonPanel
|
AnchorSideRight.Control = ButtonPanel
|
||||||
AnchorSideRight.Side = asrBottom
|
AnchorSideRight.Side = asrBottom
|
||||||
Left = 516
|
Left = 547
|
||||||
Height = 25
|
Height = 25
|
||||||
Top = 0
|
Top = 0
|
||||||
Width = 75
|
Width = 75
|
||||||
|
@ -1,8 +1,5 @@
|
|||||||
{"version":1,"strings":[
|
{"version":1,"strings":[
|
||||||
{"hash":185343357,"name":"tvpimportpreviewform.caption","sourcebytes":[86,112,73,109,112,111,114,116,80,114,101,118,105,101,119,70,111,114,109],"value":"VpImportPreviewForm"},
|
{"hash":185343357,"name":"tvpimportpreviewform.caption","sourcebytes":[86,112,73,109,112,111,114,116,80,114,101,118,105,101,119,70,111,114,109],"value":"VpImportPreviewForm"},
|
||||||
{"hash":4294967295,"name":"tvpimportpreviewform.grid.columns[0].title.caption","sourcebytes":[],"value":""},
|
|
||||||
{"hash":5966629,"name":"tvpimportpreviewform.grid.columns[1].title.caption","sourcebytes":[84,105,116,108,101],"value":"Title"},
|
|
||||||
{"hash":5966629,"name":"tvpimportpreviewform.grid.columns[2].title.caption","sourcebytes":[84,105,116,108,101],"value":"Title"},
|
|
||||||
{"hash":202226323,"name":"tvpimportpreviewform.btnexecute.caption","sourcebytes":[73,109,112,111,114,116,32,99,104,101,99,107,101,100,32,105,116,101,109,115],"value":"Import checked items"},
|
{"hash":202226323,"name":"tvpimportpreviewform.btnexecute.caption","sourcebytes":[73,109,112,111,114,116,32,99,104,101,99,107,101,100,32,105,116,101,109,115],"value":"Import checked items"},
|
||||||
{"hash":77089212,"name":"tvpimportpreviewform.btncancel.caption","sourcebytes":[67,97,110,99,101,108],"value":"Cancel"}
|
{"hash":77089212,"name":"tvpimportpreviewform.btncancel.caption","sourcebytes":[67,97,110,99,101,108],"value":"Cancel"}
|
||||||
]}
|
]}
|
||||||
|
@ -9,12 +9,22 @@ uses
|
|||||||
Forms, Controls, Dialogs, Grids, ExtCtrls, StdCtrls, VpBaseDS;
|
Forms, Controls, Dialogs, Grids, ExtCtrls, StdCtrls, VpBaseDS;
|
||||||
|
|
||||||
type
|
type
|
||||||
|
{ TVpImportGrid }
|
||||||
|
|
||||||
|
TVpImportGrid = class(TDrawGrid)
|
||||||
|
protected
|
||||||
|
procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X,Y: Integer); override;
|
||||||
|
public
|
||||||
|
procedure DrawCellCheckboxBitmaps(const ACol, ARow: Integer; const ARect: TRect);
|
||||||
|
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
{ TVpImportPreviewForm }
|
{ TVpImportPreviewForm }
|
||||||
|
|
||||||
TVpImportPreviewForm = class(TForm)
|
TVpImportPreviewForm = class(TForm)
|
||||||
btnExecute: TButton;
|
btnExecute: TButton;
|
||||||
btnCancel: TButton;
|
btnCancel: TButton;
|
||||||
Grid: TDrawGrid;
|
|
||||||
ButtonPanel: TPanel;
|
ButtonPanel: TPanel;
|
||||||
procedure GridDrawCell(Sender: TObject; aCol, aRow: Integer; aRect: TRect;
|
procedure GridDrawCell(Sender: TObject; aCol, aRow: Integer; aRect: TRect;
|
||||||
{%H-}aState: TGridDrawState);
|
{%H-}aState: TGridDrawState);
|
||||||
@ -26,10 +36,13 @@ type
|
|||||||
const Value: TCheckboxState);
|
const Value: TCheckboxState);
|
||||||
private
|
private
|
||||||
FDatastore: TVpCustomDatastore;
|
FDatastore: TVpCustomDatastore;
|
||||||
|
FGrid: TVpImportGrid;
|
||||||
procedure SetDatastore(const AValue: TVpCustomDatastore);
|
procedure SetDatastore(const AValue: TVpCustomDatastore);
|
||||||
|
|
||||||
protected
|
protected
|
||||||
FItems: TFPList;
|
FItems: TFPList;
|
||||||
|
FCol0CheckState: TCheckboxState;
|
||||||
|
FLockCheckState: Integer;
|
||||||
procedure CalcRowHeights;
|
procedure CalcRowHeights;
|
||||||
function GetCellText({%H-}ACol, {%H-}ARow: Integer): String; virtual;
|
function GetCellText({%H-}ACol, {%H-}ARow: Integer): String; virtual;
|
||||||
procedure PrepareItems; virtual;
|
procedure PrepareItems; virtual;
|
||||||
@ -41,6 +54,7 @@ type
|
|||||||
function Execute: Boolean;
|
function Execute: Boolean;
|
||||||
function IsChecked({%H-}ARow: Integer): Boolean; virtual;
|
function IsChecked({%H-}ARow: Integer): Boolean; virtual;
|
||||||
property Datastore: TVpCustomDatastore read FDatastore write SetDatastore;
|
property Datastore: TVpCustomDatastore read FDatastore write SetDatastore;
|
||||||
|
property Grid: TVpImportGrid read FGrid;
|
||||||
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -52,14 +66,105 @@ implementation
|
|||||||
{$R *.lfm}
|
{$R *.lfm}
|
||||||
|
|
||||||
uses
|
uses
|
||||||
LCLIntf, LCLType;
|
LCLIntf, LCLType, Themes;
|
||||||
|
|
||||||
|
{ TVpImportGrid }
|
||||||
|
|
||||||
|
procedure TVpImportGrid.DrawCellCheckboxBitmaps(const ACol, ARow: Integer;
|
||||||
|
const ARect: TRect);
|
||||||
|
var
|
||||||
|
checkboxState: TCheckboxState;
|
||||||
|
begin
|
||||||
|
checkboxState := cbUnchecked;
|
||||||
|
GetCheckBoxState(ACol, ARow, checkboxState);
|
||||||
|
DrawGridCheckboxBitmaps(ACol, ARow, ARect, checkboxState);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TVpImportGrid.MouseUp(Button: TMouseButton; Shift: TShiftState;
|
||||||
|
X,Y: Integer);
|
||||||
|
var
|
||||||
|
cell: TPoint;
|
||||||
|
R: TRect;
|
||||||
|
lSize: TSize;
|
||||||
|
Details: TThemedElementDetails;
|
||||||
|
checkboxState: TCheckboxState;
|
||||||
|
begin
|
||||||
|
inherited;
|
||||||
|
cell := MouseToCell(Point(x,y));
|
||||||
|
if (cell.X = 0) and (cell.Y = 0) then
|
||||||
|
begin
|
||||||
|
R := CellRect(cell.X, cell.Y);
|
||||||
|
details := ThemeServices.GetElementDetails(tbCheckBoxCheckedNormal);
|
||||||
|
lSize := ThemeServices.GetDetailSize(Details);
|
||||||
|
lSize.cx := MulDiv(lSize.cx, Font.PixelsPerInch, Screen.PixelsPerInch);
|
||||||
|
lSize.cy := MulDiv(lSize.cy, Font.PixelsPerInch, Screen.PixelsPerInch);
|
||||||
|
OffsetRect(R, (R.Left+R.Right-lSize.CX) div 2, (R.Top+R.Bottom-lSize.CY) div 2);
|
||||||
|
R.Right := R.Left + lSize.CX;
|
||||||
|
R.Bottom := R.Top + lSize.CY;
|
||||||
|
if PtInRect(R, Point(x, y)) then
|
||||||
|
begin
|
||||||
|
checkboxState := cbGrayed;
|
||||||
|
GetCheckboxState(cell.x, cell.Y, checkboxState);
|
||||||
|
case checkboxState of
|
||||||
|
cbChecked:
|
||||||
|
SetCheckboxState(cell.X, cell.Y, cbUnchecked);
|
||||||
|
cbUnchecked,
|
||||||
|
cbGrayed:
|
||||||
|
SetCheckboxState(cell.X, cell.Y, cbChecked);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
InvalidateCell(cell.X, cell.Y);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
{ TVpImportPreviewForm }
|
{ TVpImportPreviewForm }
|
||||||
|
|
||||||
constructor TVpImportPreviewForm.Create(AOwner: TComponent);
|
constructor TVpImportPreviewForm.Create(AOwner: TComponent);
|
||||||
begin
|
begin
|
||||||
inherited;
|
inherited;
|
||||||
Grid.Options := Grid.Options + [goEditing, goRowSelect, goThumbTracking];
|
|
||||||
|
FCol0CheckState := cbChecked;
|
||||||
|
|
||||||
|
FGrid := TVpImportGrid.Create(self);
|
||||||
|
with FGrid do
|
||||||
|
begin
|
||||||
|
Align := alClient;
|
||||||
|
AutoFillColumns := true;
|
||||||
|
Columns.Clear;
|
||||||
|
with Columns.Add do
|
||||||
|
begin
|
||||||
|
Alignment := taCenter;
|
||||||
|
ButtonStyle := cbsCheckboxColumn;
|
||||||
|
SizePriority := 0;
|
||||||
|
Title.Caption := '';
|
||||||
|
Width := 10; //33;
|
||||||
|
end;
|
||||||
|
with Columns.Add do
|
||||||
|
begin
|
||||||
|
ReadOnly := true;
|
||||||
|
SizePriority := 2;
|
||||||
|
Title.Caption := '';
|
||||||
|
end;
|
||||||
|
with Columns.Add do
|
||||||
|
begin
|
||||||
|
ButtonStyle := cbsPickList;
|
||||||
|
SizePriority := 0;
|
||||||
|
Title.Caption := '';
|
||||||
|
Width := 160;
|
||||||
|
end;
|
||||||
|
ExtendedSelect := false;
|
||||||
|
FixedCols := 0;
|
||||||
|
Options := [goEditing, goRowSelect, goThumbTracking,
|
||||||
|
goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine,
|
||||||
|
goRangeSelect, goColSizing, goSmoothScroll];
|
||||||
|
OnDrawCell := @GridDrawCell;
|
||||||
|
OnGetCheckboxState := @GridGetCheckboxState;
|
||||||
|
OnPrepareCanvas := @GridPrepareCanvas;
|
||||||
|
OnSetCheckboxState := @GridSetCheckboxState;
|
||||||
|
Parent := self;
|
||||||
|
end;
|
||||||
|
|
||||||
FItems := TFPList.Create;
|
FItems := TFPList.Create;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -101,8 +206,24 @@ end;
|
|||||||
{ Marks the item in the specified row to be accepted for import.
|
{ Marks the item in the specified row to be accepted for import.
|
||||||
To be overridden by ancestors. }
|
To be overridden by ancestors. }
|
||||||
procedure TVpImportPreviewForm.CheckItem(ARow: Integer; AChecked: Boolean);
|
procedure TVpImportPreviewForm.CheckItem(ARow: Integer; AChecked: Boolean);
|
||||||
|
var
|
||||||
|
r: Integer;
|
||||||
|
allcheckstate, cbs: TCheckboxState;
|
||||||
begin
|
begin
|
||||||
//
|
if ARow > 0 then
|
||||||
|
begin
|
||||||
|
Grid.GetCheckboxState(0, 1, allcheckstate{%H-});
|
||||||
|
for r := 2 to Grid.RowCount-1 do
|
||||||
|
begin
|
||||||
|
Grid.GetCheckboxState(0, r, cbs{%H-});
|
||||||
|
if cbs <> allcheckstate then
|
||||||
|
begin
|
||||||
|
FCol0Checkstate := cbGrayed;
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
FCol0CheckState := allcheckstate;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TVpImportPreviewForm.Execute: Boolean;
|
function TVpImportPreviewForm.Execute: Boolean;
|
||||||
@ -124,14 +245,22 @@ var
|
|||||||
R: TRect;
|
R: TRect;
|
||||||
begin
|
begin
|
||||||
R := ARect;
|
R := ARect;
|
||||||
InflateRect(R, -varCellPadding, - varCellPadding);
|
if (ACol = 0) and (ARow = 0) then
|
||||||
s := GetCellText(ACol, ARow);
|
Grid.DrawCellCheckboxBitmaps(aCol, aRow, R)
|
||||||
Grid.Canvas.TextRect(R, R.Left, R.Top, s);
|
else
|
||||||
|
begin
|
||||||
|
InflateRect(R, -varCellPadding, - varCellPadding);
|
||||||
|
s := GetCellText(ACol, ARow);
|
||||||
|
Grid.Canvas.TextRect(R, R.Left, R.Top, s);
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TVpImportPreviewForm.GridGetCheckboxState(Sender: TObject; ACol,
|
procedure TVpImportPreviewForm.GridGetCheckboxState(Sender: TObject; ACol,
|
||||||
ARow: Integer; var Value: TCheckboxState);
|
ARow: Integer; var Value: TCheckboxState);
|
||||||
begin
|
begin
|
||||||
|
if (ARow = 0) and (ACol = 0) then
|
||||||
|
Value := FCol0CheckState
|
||||||
|
else
|
||||||
if ARow >= Grid.FixedRows then
|
if ARow >= Grid.FixedRows then
|
||||||
begin
|
begin
|
||||||
if IsChecked(ARow) then
|
if IsChecked(ARow) then
|
||||||
@ -157,9 +286,23 @@ end;
|
|||||||
|
|
||||||
procedure TVpImportPreviewForm.GridSetCheckboxState(Sender: TObject; ACol,
|
procedure TVpImportPreviewForm.GridSetCheckboxState(Sender: TObject; ACol,
|
||||||
ARow: Integer; const Value: TCheckboxState);
|
ARow: Integer; const Value: TCheckboxState);
|
||||||
|
var
|
||||||
|
r: Integer;
|
||||||
begin
|
begin
|
||||||
|
if (ARow = 0) and (ACol = 0) then
|
||||||
|
begin
|
||||||
|
FCol0CheckState := Value;
|
||||||
|
if Value <> cbGrayed then
|
||||||
|
for r := Grid.FixedRows to Grid.RowCount-1 do
|
||||||
|
CheckItem(r, Value = cbChecked);
|
||||||
|
Grid.Invalidate;
|
||||||
|
end
|
||||||
|
else
|
||||||
if ARow >= Grid.FixedRows then
|
if ARow >= Grid.FixedRows then
|
||||||
|
begin
|
||||||
CheckItem(ARow, Value = cbChecked);
|
CheckItem(ARow, Value = cbChecked);
|
||||||
|
Grid.Invalidate;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ Returns that the item in the given row should be included in the import process.
|
{ Returns that the item in the given row should be included in the import process.
|
||||||
|
@ -65,8 +65,10 @@ begin
|
|||||||
if ARow < Grid.FixedRows then
|
if ARow < Grid.FixedRows then
|
||||||
exit;
|
exit;
|
||||||
item := TVpICalEntry(FItems[ARow - Grid.FixedRows]);
|
item := TVpICalEntry(FItems[ARow - Grid.FixedRows]);
|
||||||
if item <> nil then
|
if item <> nil then begin
|
||||||
item.Checked := AChecked;
|
item.Checked := AChecked;
|
||||||
|
inherited;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TVpImportPreviewICalEventForm.GetCellText(ACol, ARow: Integer): String;
|
function TVpImportPreviewICalEventForm.GetCellText(ACol, ARow: Integer): String;
|
||||||
|
@ -66,7 +66,10 @@ begin
|
|||||||
exit;
|
exit;
|
||||||
item := TVpICalEntry(FItems[ARow - Grid.FixedRows]);
|
item := TVpICalEntry(FItems[ARow - Grid.FixedRows]);
|
||||||
if item <> nil then
|
if item <> nil then
|
||||||
item.Checked := AChecked;
|
begin
|
||||||
|
item.Checked := AChecked;
|
||||||
|
inherited;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TVpImportPreviewICalTaskForm.GetCellText(ACol, ARow: Integer): String;
|
function TVpImportPreviewICalTaskForm.GetCellText(ACol, ARow: Integer): String;
|
||||||
|
@ -61,7 +61,10 @@ begin
|
|||||||
exit;
|
exit;
|
||||||
card := TVpVCard(FItems[ARow - Grid.FixedRows]);
|
card := TVpVCard(FItems[ARow - Grid.FixedRows]);
|
||||||
if card <> nil then
|
if card <> nil then
|
||||||
|
begin
|
||||||
card.Checked := AChecked;
|
card.Checked := AChecked;
|
||||||
|
inherited;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TVpImportPreviewVCardForm.GetCellText(ACol, ARow: Integer): String;
|
function TVpImportPreviewVCardForm.GetCellText(ACol, ARow: Integer): String;
|
||||||
|
Reference in New Issue
Block a user