jvcllaz: Activate LCL scaling for TJvYearGrid. Publish Font property. Update demo project.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7285 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2020-01-14 09:49:13 +00:00
parent 9100c787d7
commit 7c25c573a5
3 changed files with 240 additions and 90 deletions

View File

@ -7,6 +7,7 @@ object MainForm: TMainForm
Caption = 'JvYearGrid Demo'
ClientHeight = 546
ClientWidth = 1310
OnActivate = FormActivate
OnCreate = FormCreate
LCLVersion = '2.1.0.0'
object JvYearGrid1: TJvYearGrid
@ -97,78 +98,74 @@ object MainForm: TMainForm
AnchorSideTop.Control = JvYearGrid1
AnchorSideTop.Side = asrBottom
Left = 0
Height = 97
Height = 89
Top = 264
Width = 730
Width = 905
AutoSize = True
BorderSpacing.Bottom = 16
BevelOuter = bvNone
ClientHeight = 97
ClientWidth = 730
ClientHeight = 89
ClientWidth = 905
ParentFont = False
TabOrder = 1
object EdLeftMargin: TSpinEdit
AnchorSideTop.Control = EdTopMargin
object edLeftMargin: TSpinEdit
AnchorSideTop.Control = edTopMargin
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = Label4
AnchorSideRight.Side = asrBottom
Left = 24
Height = 23
Top = 31
Top = 27
Width = 50
Anchors = [akTop, akRight]
BorderSpacing.Left = 16
BorderSpacing.Top = 4
OnChange = EdLeftMarginChange
ParentFont = False
TabOrder = 0
end
object EdRightMargin: TSpinEdit
AnchorSideLeft.Control = EdTopMargin
object edRightMargin: TSpinEdit
AnchorSideLeft.Control = edTopMargin
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = EdLeftMargin
Left = 144
AnchorSideTop.Control = edLeftMargin
Left = 136
Height = 23
Top = 31
Top = 27
Width = 50
BorderSpacing.Left = 4
OnChange = EdRightMarginChange
ParentFont = False
TabOrder = 1
end
object EdTopMargin: TSpinEdit
AnchorSideLeft.Control = EdLeftMargin
object edTopMargin: TSpinEdit
AnchorSideLeft.Control = edLeftMargin
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = Panel1
Left = 82
Height = 23
Top = 4
Width = 58
Top = 0
Width = 50
BorderSpacing.Left = 8
BorderSpacing.Top = 4
OnChange = EdTopMarginChange
ParentFont = False
TabOrder = 2
end
object EdBottomMargin: TSpinEdit
AnchorSideLeft.Control = EdTopMargin
AnchorSideTop.Control = EdLeftMargin
object edBottomMargin: TSpinEdit
AnchorSideLeft.Control = edTopMargin
AnchorSideTop.Control = edLeftMargin
AnchorSideTop.Side = asrBottom
Left = 82
Height = 23
Top = 58
Width = 58
Top = 54
Width = 50
BorderSpacing.Top = 4
OnChange = EdBottomMarginChange
ParentFont = False
TabOrder = 3
end
object cmbDayNamesAlignment: TComboBox
AnchorSideLeft.Control = Label1
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = EdTopMargin
Left = 414
AnchorSideTop.Control = edTopMargin
Left = 398
Height = 23
Top = 4
Top = 0
Width = 100
BorderSpacing.Left = 8
ItemHeight = 15
@ -187,9 +184,9 @@ object MainForm: TMainForm
AnchorSideTop.Side = asrCenter
AnchorSideRight.Control = Label2
AnchorSideRight.Side = asrBottom
Left = 250
Left = 234
Height = 15
Top = 8
Top = 4
Width = 156
Anchors = [akTop, akRight]
Caption = 'Day names alignment/format'
@ -197,17 +194,17 @@ object MainForm: TMainForm
ParentFont = False
end
object Label2: TLabel
AnchorSideLeft.Control = EdRightMargin
AnchorSideLeft.Control = edRightMargin
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = cmbMonthNamesAlignment
AnchorSideTop.Side = asrCenter
AnchorSideRight.Control = Label1
AnchorSideRight.Side = asrBottom
Left = 234
Left = 218
Height = 15
Top = 35
Top = 31
Width = 172
BorderSpacing.Left = 40
BorderSpacing.Left = 32
Caption = 'Month names alignment/format'
ParentColor = False
ParentFont = False
@ -218,9 +215,9 @@ object MainForm: TMainForm
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = cmbDayNamesAlignment
AnchorSideRight.Side = asrBottom
Left = 414
Left = 398
Height = 23
Top = 31
Top = 27
Width = 100
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Top = 4
@ -240,9 +237,9 @@ object MainForm: TMainForm
AnchorSideTop.Side = asrCenter
AnchorSideRight.Control = Label1
AnchorSideRight.Side = asrBottom
Left = 324
Left = 308
Height = 15
Top = 62
Top = 58
Width = 82
Anchors = [akTop, akRight]
Caption = 'Days alignment'
@ -255,13 +252,12 @@ object MainForm: TMainForm
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = cmbDayNamesAlignment
AnchorSideRight.Side = asrBottom
Left = 414
Left = 398
Height = 23
Top = 58
Top = 54
Width = 100
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Top = 4
BorderSpacing.Bottom = 16
ItemHeight = 15
Items.Strings = (
'taLeftJustify'
@ -273,17 +269,17 @@ object MainForm: TMainForm
Style = csDropDownList
TabOrder = 6
end
object CbFlat: TCheckBox
AnchorSideLeft.Control = lblYear
AnchorSideTop.Control = cmbMonthFormat
object cmbFlat: TCheckBox
AnchorSideLeft.Control = cmbMonthFormat
AnchorSideTop.Control = cmbDaysAlignment
AnchorSideTop.Side = asrCenter
Left = 648
Left = 506
Height = 19
Top = 33
Top = 56
Width = 39
BorderSpacing.Right = 16
Caption = 'Flat'
OnChange = CbFlatChange
OnChange = cmbFlatChange
ParentFont = False
TabOrder = 7
end
@ -291,9 +287,9 @@ object MainForm: TMainForm
AnchorSideLeft.Control = cmbDayNamesAlignment
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = cmbDayNamesAlignment
Left = 522
Left = 506
Height = 23
Top = 4
Top = 0
Width = 100
BorderSpacing.Left = 8
ItemHeight = 15
@ -311,9 +307,9 @@ object MainForm: TMainForm
AnchorSideLeft.Control = cmbDayNamesAlignment
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = cmbMonthNamesAlignment
Left = 522
Left = 506
Height = 23
Top = 31
Top = 27
Width = 100
BorderSpacing.Left = 8
ItemHeight = 15
@ -332,9 +328,9 @@ object MainForm: TMainForm
AnchorSideTop.Control = cmbDayFormat
AnchorSideBottom.Control = cmbDayFormat
AnchorSideBottom.Side = asrBottom
Left = 673
Left = 657
Height = 23
Top = 4
Top = 0
Width = 57
Anchors = [akTop, akLeft, akBottom]
BorderSpacing.Left = 3
@ -350,9 +346,9 @@ object MainForm: TMainForm
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = cmbDayFormat
AnchorSideTop.Side = asrCenter
Left = 648
Left = 632
Height = 15
Top = 8
Top = 4
Width = 22
BorderSpacing.Left = 26
Caption = 'Year'
@ -361,15 +357,88 @@ object MainForm: TMainForm
end
object Label4: TLabel
AnchorSideLeft.Control = Panel1
AnchorSideTop.Control = EdTopMargin
AnchorSideTop.Control = edTopMargin
AnchorSideTop.Side = asrCenter
Left = 8
Height = 15
Top = 8
Top = 4
Width = 66
BorderSpacing.Left = 8
Caption = 'Cell margins'
ParentColor = False
end
object btnFont: TButton
AnchorSideLeft.Control = lblYear
AnchorSideTop.Control = cmbDaysAlignment
AnchorSideTop.Side = asrCenter
AnchorSideRight.Control = udYear
AnchorSideRight.Side = asrBottom
Left = 632
Height = 25
Top = 53
Width = 82
Anchors = [akTop, akLeft, akRight]
AutoSize = True
Caption = 'Font...'
OnClick = btnFontClick
TabOrder = 11
end
object rgAutoSize: TCheckGroup
AnchorSideLeft.Control = udYear
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = edTopMargin
Left = 730
Height = 89
Top = 0
Width = 167
AutoFill = True
AutoSize = True
BorderSpacing.Left = 16
BorderSpacing.Right = 8
Caption = 'Auto size'
ChildSizing.LeftRightSpacing = 6
ChildSizing.TopBottomSpacing = 6
ChildSizing.EnlargeHorizontal = crsHomogenousChildResize
ChildSizing.EnlargeVertical = crsHomogenousChildResize
ChildSizing.ShrinkHorizontal = crsScaleChilds
ChildSizing.ShrinkVertical = crsScaleChilds
ChildSizing.Layout = cclLeftToRightThenTopToBottom
ChildSizing.ControlsPerLine = 2
ClientHeight = 69
ClientWidth = 163
Columns = 2
Items.Strings = (
'Grid'
'First column'
'First row'
'Columns'
'Rows'
)
OnItemClick = rgAutoSizeItemClick
TabOrder = 12
Data = {
050000000202020202
}
end
object cmbAutoSize: TCheckBox
AnchorSideTop.Control = rgAutoSize
AnchorSideRight.Control = rgAutoSize
AnchorSideRight.Side = asrBottom
Left = 877
Height = 19
Top = 0
Width = 20
Anchors = [akTop, akRight]
Checked = True
OnChange = cmbAutoSizeChange
State = cbChecked
TabOrder = 13
end
end
object FontDialog1: TFontDialog
MinFontSize = 0
MaxFontSize = 0
left = 568
top = 320
end
end

View File

@ -14,35 +14,40 @@ type
{ TMainForm }
TMainForm = class(TForm)
btnFont: TButton;
cmbAutoSize: TCheckBox;
cmbMonthFormat: TComboBox;
cmbDayNamesAlignment: TComboBox;
cmbDayFormat: TComboBox;
cmbMonthNamesAlignment: TComboBox;
cmbDaysAlignment: TComboBox;
CbFlat: TCheckBox;
cmbFlat: TCheckBox;
FontDialog1: TFontDialog;
JvYearGrid1: TJvYearGrid;
EdLeftMargin: TSpinEdit;
EdRightMargin: TSpinEdit;
EdTopMargin: TSpinEdit;
EdBottomMargin: TSpinEdit;
edLeftMargin: TSpinEdit;
edRightMargin: TSpinEdit;
edTopMargin: TSpinEdit;
edBottomMargin: TSpinEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
lblYear: TLabel;
Panel1: TPanel;
rgAutoSize: TCheckGroup;
udYear: TUpDown;
procedure btnFontClick(Sender: TObject);
procedure cmbAutoSizeChange(Sender: TObject);
procedure cmbDayFormatChange(Sender: TObject);
procedure cmbDayNamesAlignmentChange(Sender: TObject);
procedure cmbDaysAlignmentChange(Sender: TObject);
procedure CbFlatChange(Sender: TObject);
procedure cmbFlatChange(Sender: TObject);
procedure cmbMonthFormatChange(Sender: TObject);
procedure cmbMonthNamesAlignmentChange(Sender: TObject);
procedure EdBottomMarginChange(Sender: TObject);
procedure EdLeftMarginChange(Sender: TObject);
procedure EdRightMarginChange(Sender: TObject);
procedure EdTopMarginChange(Sender: TObject);
procedure edMarginChange(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure rgAutoSizeItemClick(Sender: TObject; Index: integer);
procedure udYearClick(Sender: TObject; Button: TUDBtnType);
private
@ -77,9 +82,22 @@ begin
JvYearGrid1.DaysAlignment := TAlignment(cmbDaysAlignment.ItemIndex);
end;
procedure TMainForm.CbFlatChange(Sender: TObject);
procedure TMainForm.btnFontClick(Sender: TObject);
begin
JvYearGrid1.Flat := CbFlat.Checked;
FontDialog1.Font.Assign(JvYearGrid1.Font);
if FontDialog1.Execute then
JvYearGrid1.Font.Assign(FontDialog1.Font);
end;
procedure TMainForm.cmbAutoSizeChange(Sender: TObject);
begin
JvYearGrid1.AutoSize := cmbAutoSize.Checked;
rgAutoSize.Enabled := JvYearGrid1.AutoSize;
end;
procedure TMainForm.cmbFlatChange(Sender: TObject);
begin
JvYearGrid1.Flat := cmbFlat.Checked;
end;
procedure TMainForm.cmbMonthFormatChange(Sender: TObject);
@ -92,35 +110,36 @@ begin
JvYearGrid1.MonthNamesAlignment := TAlignment(cmbMonthNamesAlignment.ItemIndex);
end;
procedure TMainForm.EdBottomMarginChange(Sender: TObject);
procedure TMainForm.edMarginChange(Sender: TObject);
begin
JvYearGrid1.CellMargins.Bottom := EdBottomMargin.Value;
if Sender = edLeftMargin then
JvYearGrid1.CellMargins.Left := edLeftMargin.Value;
if Sender = edRightMargin then
JvYearGrid1.CellMargins.Right := edRightMargin.Value;
if Sender = edTopMargin then
JvYearGrid1.CellMargins.Top := edTopMargin.Value;
if Sender = edBottomMargin then
JvYearGrid1.CellMargins.Bottom := edBottomMargin.Value;
end;
procedure TMainForm.EdLeftMarginChange(Sender: TObject);
procedure TMainForm.FormActivate(Sender: TObject);
begin
JvYearGrid1.CellMargins.Left := EdLeftMargin.Value;
end;
procedure TMainForm.EdRightMarginChange(Sender: TObject);
begin
JvYearGrid1.CellMargins.Right := EdRightMargin.Value;
end;
procedure TMainForm.EdTopMarginChange(Sender: TObject);
begin
JvYearGrid1.CellMargins.Top := EdTopMargin.Value;
// Doing this in the OnCreate event would mean that the scaled values are
// not ready, yet.
edLeftMargin.Value := JvYearGrid1.CellMargins.Left;
edRightMargin.Value := JvYearGrid1.CellMargins.Right;
edTopMargin.Value := JvYearGrid1.CellMargins.Top;
edBottomMargin.Value := JvYearGrid1.CellMargins.Bottom;
edLeftMargin.OnChange := @edMarginChange;
edRightMargin.OnChange := @edMarginChange;
edTopMargin.OnChange := @edMarginChange;
edBottomMargin.OnChange := @edMarginChange;
end;
procedure TMainForm.FormCreate(Sender: TObject);
begin
JvYearGrid1.Year := YearOf(Date);
EdLeftMargin.Value := JvYearGrid1.CellMargins.Left;
EdRightMargin.Value := JvYearGrid1.CellMargins.Right;
EdTopMargin.Value := JvYearGrid1.CellMargins.Top;
EdBottomMargin.Value := JvYearGrid1.CellMargins.Bottom;
cmbDayNamesAlignment.ItemIndex := ord(JvYearGrid1.DayNamesAlignment);
cmbMonthNamesAlignment.ItemIndex := ord(JvYearGrid1.MonthNamesAlignment);
cmbDaysAlignment.ItemIndex := ord(JvYearGrid1.DaysAlignment);
@ -130,7 +149,41 @@ begin
udYear.Position := JvYearGrid1.Year;
CbFlat.Checked := JvYearGrid1.Flat;
cmbFlat.Checked := JvYearGrid1.Flat;
cmbAutoSize.Checked := JvYearGrid1.AutoSize;
rgAutoSize.Checked[ord(aoGrid)] := aoGrid in JvYearGrid1.AutosizeOptions;
rgAutoSize.Checked[ord(aoFirstColumn)] := aoFirstColumn in JvYearGrid1.AutosizeOptions;
rgAutoSize.Checked[ord(aoFirstRow)] := aoFirstRow in JvYearGrid1.AutosizeOptions;
rgAutoSize.Checked[ord(aoColumns)] := aoColumns in JvYearGrid1.AutosizeOptions;
rgAutoSize.Checked[ord(aoRows)] := aoRows in JvYearGrid1.AutosizeOptions;
end;
procedure TMainForm.rgAutoSizeItemClick(Sender: TObject; Index: integer);
begin
if rgAutoSize.Checked[ord(aoGrid)] then
JvYearGrid1.AutoSizeOptions := JvYearGrid1.AutoSizeOptions + [aoGrid]
else
JvYearGrid1.AutoSizeOptions := JvYearGrid1.AutoSizeOptions - [aoGrid];
if rgAutoSize.Checked[ord(aoFirstColumn)] then
JvYearGrid1.AutoSizeOptions := JvYearGrid1.AutoSizeOptions + [aoFirstColumn]
else
JvYearGrid1.AutoSizeOptions := JvYearGrid1.AutoSizeOptions - [aoFirstColumn];
if rgAutoSize.Checked[ord(aoFirstRow)] then
JvYearGrid1.AutoSizeOptions := JvYearGrid1.AutoSizeOptions + [aoFirstRow]
else
JvYearGrid1.AutoSizeOptions := JvYearGrid1.AutoSizeOptions - [aoFirstRow];
if rgAutoSize.Checked[ord(aoColumns)] then
JvYearGrid1.AutoSizeOptions := JvYearGrid1.AutoSizeOptions + [aoColumns]
else
JvYearGrid1.AutoSizeOptions := JvYearGrid1.AutoSizeOptions - [aoColumns];
if rgAutoSize.Checked[ord(aoRows)] then
JvYearGrid1.AutoSizeOptions := JvYearGrid1.AutoSizeOptions + [aoRows]
else
JvYearGrid1.AutoSizeOptions := JvYearGrid1.AutoSizeOptions - [aoRows];
end;
procedure TMainForm.udYearClick(Sender: TObject; Button: TUDBtnType);

View File

@ -173,6 +173,7 @@ type
procedure DrawTextInCell(aCol, aRow: Integer; aRect: TRect; {%H-}aState: TGridDrawState); override;
function SelectCell(ACol, ARow: Integer): Boolean; override;
procedure DblClick; override;
procedure FontChanged(Sender: TObject); override;
procedure DoPrepareCanvas(aCol,aRow:Integer; {%H-}aState: TGridDrawState); override;
procedure SetAutoSize(Value: Boolean); override;
procedure UpdateAllSizes;
@ -189,6 +190,10 @@ type
procedure WriteGridYear({%H-}Writer: TWriter);
procedure DefineProperties(Filer: TFiler); override;
{ LCL scaling }
procedure DoAutoAdjustLayout(const AMode: TLayoutAdjustmentPolicy;
const AXProportion, AYProportion: Double); override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
@ -264,6 +269,7 @@ type
property BorderSpacing;
property BorderStyle;
property Flat read GetFlat write SetFlat default true;
property Font;
property ScrollBars;
property TitleStyle;
end;
@ -1003,6 +1009,13 @@ begin
mnuEditClick(nil);
end;
procedure TJvYearGrid.FontChanged(Sender: TObject);
begin
UpdateAllSizes;
AdjustBounds;
Invalidate;
end;
procedure TJvYearGrid.SetBorderColor(const Value: TColor);
begin
if Value <> FBorderColor then
@ -1291,6 +1304,7 @@ var
begin
if AutoSize then
begin
Canvas.Font.Assign(Font);
Canvas.Font.Style := [fsBold];
if aoFirstRow in AutoSizeOptions then
RowHeights[0] := GetHighestTextInRow(0) + CellMargins.Top + CellMargins.Bottom;
@ -1530,6 +1544,7 @@ begin
with Canvas do
begin
Font.Assign(Self.Font);
Font.Color := clBlack;
if (ACol = 0) and (ARow = 0) then
Font.Style := Font.Style + [fsBold]
@ -1614,4 +1629,17 @@ begin
end;
end;
procedure TJvYearGrid.DoAutoAdjustLayout(const AMode: TLayoutAdjustmentPolicy;
const AXProportion, AYProportion: Double);
begin
inherited;
if AMode in [lapAutoAdjustWithoutHorizontalScrolling, lapAutoAdjustForDPI] then
begin
FCellMargins.Left := round(FCellMargins.Left * AXProportion);
FCellMargins.Right := round(FCellMargins.Right * AXProportion);
FCellMargins.Top := round(FCellMargins.Top * AYProportion);
FCellMargins.Bottom := round(FCellMargins.Bottom * AYProportion);
end;
end;
end.