You've already forked lazarus-ccr
jvcllaz: ReadOnly support in TJvYearGrid. YearGridEditForm contains a color box for color selection. Extended YearGrid demo.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8374 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -81,6 +81,7 @@ type
|
||||
FAutoSize: Boolean;
|
||||
FDayFormat: TJvDayFormat;
|
||||
FMonthFormat: TJvMonthFormat;
|
||||
FReadOnly: Boolean;
|
||||
FOnInfoChanging: TOnInfoChanging;
|
||||
FOnSelectDate: TOnSelectDate;
|
||||
FOnYearChanged: TOnYearChanged;
|
||||
@ -118,6 +119,7 @@ type
|
||||
procedure SetMonthFormat(const AValue: TJvMonthFormat);
|
||||
procedure SetMonthNamesAlignment(const Value: TAlignment);
|
||||
procedure SetOrientation(const Value: TJvYearGridOrientation);
|
||||
procedure SetReadOnly(const Value: Boolean);
|
||||
procedure SetWeekendColor(const AValue: TColor);
|
||||
procedure SetWeekendDays(const Value: TJvWeekDaySet);
|
||||
procedure SetYear(const Value: Integer);
|
||||
@ -233,6 +235,7 @@ type
|
||||
property WeekendColor: TColor read FWeekendColor write SetWeekendColor default JvDefaultWeekendColor;
|
||||
property Orientation: TJvYearGridOrientation read FOrientation write SetOrientation default yoHorizontal;
|
||||
property FirstDayOfWeek: TJvWeekDay read FFirstDayOfWeek write SetFirstDayOfWeek default wdMonday;
|
||||
property ReadOnly: Boolean read FReadOnly write SetReadOnly default false;
|
||||
|
||||
property Year: Integer read FYear write SetYear;
|
||||
property YearFile: string read FYearFile write FYearFile;
|
||||
@ -283,6 +286,7 @@ uses
|
||||
const
|
||||
TodayFontColor = clWhite;
|
||||
TodayBrushColor = clRed;
|
||||
READONLY_TAG = 2;
|
||||
|
||||
constructor TJvYearGrid.Create(AOwner: TComponent);
|
||||
var
|
||||
@ -487,7 +491,7 @@ begin
|
||||
DList.Clear;
|
||||
DList.Append(FYearData[DayIndex, MonthIndex].DisplayText);
|
||||
S := FYearData[DayIndex, MonthIndex].InfoText;
|
||||
S := StringReplace(S, Cr, '||', [rfReplaceAll]);
|
||||
S := StringReplace(S, LineEnding, '||', [rfReplaceAll]);
|
||||
DList.Append(S);
|
||||
DList.Append(ColorToString(FYearData[DayIndex, MonthIndex].DefaultColor));
|
||||
DList.Append(ColorToString(FYearData[DayIndex, MonthIndex].CustomColor));
|
||||
@ -532,7 +536,7 @@ begin
|
||||
Inc(Index);
|
||||
FYearData[DayIndex, MonthIndex].DisplayText := DList[0];
|
||||
S := DList[1];
|
||||
S := StringReplace(S, '||', Cr, [rfReplaceAll]);
|
||||
S := StringReplace(S, '||', LineEnding, [rfReplaceAll]);
|
||||
FYearData[DayIndex, MonthIndex].InfoText := S;
|
||||
FYearData[DayIndex, MonthIndex].DefaultColor := StringToColor(DList[2]);
|
||||
FYearData[DayIndex, MonthIndex].CustomColor := StringToColor(DList[3]);
|
||||
@ -718,8 +722,12 @@ procedure TJvYearGrid.mnuYearClick(Sender: TObject);
|
||||
var
|
||||
S: string;
|
||||
AYear: Word;
|
||||
n: Integer;
|
||||
begin
|
||||
n := cInputQueryEditSizePercents;
|
||||
cInputQueryEditSizePercents := 0;
|
||||
S := InputBox(RsYearGrid, RsEnterYear, IntToStr(Self.Year));
|
||||
cInputQueryEditSizePercents := n;
|
||||
try
|
||||
if S = '' then
|
||||
Exit;
|
||||
@ -736,6 +744,8 @@ procedure TJvYearGrid.mnuPasteClick(Sender: TObject);
|
||||
var
|
||||
S: string = '';
|
||||
begin
|
||||
if FReadOnly then
|
||||
exit;
|
||||
if GetCellData(S) then
|
||||
if Clipboard.HasFormat(CF_TEXT) then
|
||||
SetCellData(Clipboard.AsText);
|
||||
@ -745,6 +755,8 @@ procedure TJvYearGrid.mnuDeleteClick(Sender: TObject);
|
||||
var
|
||||
S: string = '';
|
||||
begin
|
||||
if FReadOnly then
|
||||
exit;
|
||||
if GetCellData(S) then
|
||||
SetCellData('');
|
||||
end;
|
||||
@ -846,6 +858,9 @@ var
|
||||
CanChange: Boolean;
|
||||
InfoText: string;
|
||||
begin
|
||||
if FReadOnly then
|
||||
exit;
|
||||
|
||||
lCol := Col;
|
||||
lRow := Row;
|
||||
if (lCol < 1) or (lRow < 1) then
|
||||
@ -858,6 +873,7 @@ begin
|
||||
InfoText := FYearData[lCol, lRow].InfoText;
|
||||
F.MemoText.Text := InfoText;
|
||||
F.Caption := 'Edit ' + DateToStr(CellToDate(lCol, lRow));
|
||||
F.ColorBox.Selected := FYearData[lCol, lRow].CustomColor;
|
||||
if F.ShowModal = mrOk then
|
||||
begin
|
||||
InfoText := F.MemoText.Text;
|
||||
@ -870,10 +886,10 @@ begin
|
||||
if InfoText = '' then
|
||||
FYearData[lCol, lRow].Custom := False
|
||||
else
|
||||
if not FYearData[lCol, lRow].Custom then
|
||||
// if not FYearData[lCol, lRow].Custom then
|
||||
begin
|
||||
FYearData[lCol, lRow].Custom := True;
|
||||
FYearData[lCol, lRow].CustomColor := RGB(206, 250, 253);
|
||||
FYearData[lCol, lRow].CustomColor := F.ColorBox.Selected;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
@ -886,7 +902,7 @@ procedure TJvYearGrid.mnuColorClick(Sender: TObject);
|
||||
var
|
||||
CD: TColorDialog;
|
||||
begin
|
||||
if (Col < 1) or (Row < 1) or (FYearData[Col, Row].DisplayText = '') then
|
||||
if (Col < 1) or (Row < 1) or (FYearData[Col, Row].DisplayText = '') or FReadOnly then
|
||||
Exit;
|
||||
CD := TColorDialog.Create(Application);
|
||||
{ -- not available in LCL:
|
||||
@ -903,7 +919,7 @@ end;
|
||||
|
||||
procedure TJvYearGrid.mnuNoColorClick(Sender: TObject);
|
||||
begin
|
||||
if (Col < 1) or (Row < 1) or (FYearData[Col, Row].DisplayText = '') then
|
||||
if (Col < 1) or (Row < 1) or (FYearData[Col, Row].DisplayText = '') or FReadOnly then
|
||||
Exit;
|
||||
FYearData[Col, Row].Custom := False;
|
||||
Invalidate;
|
||||
@ -915,10 +931,18 @@ var
|
||||
begin
|
||||
if (Col > 0) and (Row > 0) and (FYearData[Col, Row].DisplayText <> '') then
|
||||
for I := 0 to FGridPop.Items.Count - 1 do
|
||||
FGridPop.Items[I].Enabled := True
|
||||
begin
|
||||
FGridPop.Items[I].Enabled := True;
|
||||
if (FGridPop.Items[I].Tag AND READONLY_TAG <> 0) and FReadOnly then
|
||||
FGridPop.Items[I].Enabled := False;
|
||||
end
|
||||
else
|
||||
for I := 0 to FGridPop.Items.Count - 1 do
|
||||
begin
|
||||
FGridPop.Items[I].Enabled := (FGridPop.Items[I].Tag = 1);
|
||||
if (FGridPop.Items[I].Tag AND READONLY_TAG <> 0) and FReadOnly then
|
||||
FGridPop.Items[I].Enabled := False;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TJvYearGrid.Launch(AFile: string);
|
||||
@ -1467,6 +1491,15 @@ begin
|
||||
AdjustBounds;
|
||||
end;
|
||||
|
||||
procedure TJvYearGrid.SetReadOnly(const Value: Boolean);
|
||||
begin
|
||||
if Value <> FReadOnly then
|
||||
begin
|
||||
FReadOnly := Value;
|
||||
SetupGridPop(self);
|
||||
end;
|
||||
end;
|
||||
|
||||
function TJvYearGrid.IsCurrentYear: Boolean;
|
||||
begin
|
||||
Result := Year = FCurrentYear;
|
||||
|
@ -1,81 +1,79 @@
|
||||
object YearGridEditForm: TYearGridEditForm
|
||||
Left = 303
|
||||
Height = 367
|
||||
Height = 246
|
||||
Top = 154
|
||||
Width = 394
|
||||
BorderStyle = bsDialog
|
||||
Caption = 'YearGrid Edit'
|
||||
ClientHeight = 367
|
||||
ClientHeight = 246
|
||||
ClientWidth = 394
|
||||
Color = clBtnFace
|
||||
Font.Color = clWindowText
|
||||
OnCreate = FormCreate
|
||||
OnShow = FormShow
|
||||
Position = poScreenCenter
|
||||
LCLVersion = '1.9.0.0'
|
||||
object Panel1: TPanel
|
||||
Left = 0
|
||||
Height = 35
|
||||
Top = 332
|
||||
Width = 394
|
||||
Left = 6
|
||||
Height = 26
|
||||
Top = 214
|
||||
Width = 382
|
||||
Align = alBottom
|
||||
AutoSize = True
|
||||
ClientHeight = 35
|
||||
ClientWidth = 394
|
||||
TabOrder = 0
|
||||
BorderSpacing.Around = 6
|
||||
BevelOuter = bvNone
|
||||
ClientHeight = 26
|
||||
ClientWidth = 382
|
||||
TabOrder = 2
|
||||
object BtnOK: TBitBtn
|
||||
AnchorSideTop.Control = BitCancel
|
||||
AnchorSideTop.Side = asrCenter
|
||||
AnchorSideRight.Control = BitCancel
|
||||
AnchorSideBottom.Side = asrBottom
|
||||
Left = 241
|
||||
Left = 232
|
||||
Height = 26
|
||||
Top = 4
|
||||
Top = 0
|
||||
Width = 62
|
||||
Anchors = [akTop, akRight]
|
||||
AutoSize = True
|
||||
BorderSpacing.Left = 16
|
||||
BorderSpacing.Right = 4
|
||||
BorderSpacing.Right = 6
|
||||
Caption = 'OK'
|
||||
Default = True
|
||||
Kind = bkOK
|
||||
ModalResult = 1
|
||||
TabOrder = 0
|
||||
TabOrder = 2
|
||||
end
|
||||
object BitCancel: TBitBtn
|
||||
AnchorSideTop.Control = Panel1
|
||||
AnchorSideTop.Side = asrCenter
|
||||
AnchorSideRight.Control = Panel1
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 307
|
||||
Left = 300
|
||||
Height = 26
|
||||
Top = 4
|
||||
Top = 0
|
||||
Width = 82
|
||||
Anchors = [akTop, akRight]
|
||||
AutoSize = True
|
||||
BorderSpacing.Top = 4
|
||||
BorderSpacing.Right = 4
|
||||
BorderSpacing.Bottom = 4
|
||||
Cancel = True
|
||||
Caption = 'Cancel'
|
||||
Kind = bkCancel
|
||||
ModalResult = 2
|
||||
TabOrder = 1
|
||||
TabOrder = 3
|
||||
end
|
||||
object BtnLoad: TButton
|
||||
AnchorSideLeft.Control = Panel1
|
||||
AnchorSideTop.Control = BtnOK
|
||||
AnchorSideBottom.Control = BtnOK
|
||||
AnchorSideBottom.Side = asrBottom
|
||||
Left = 5
|
||||
Left = 0
|
||||
Height = 26
|
||||
Top = 4
|
||||
Top = 0
|
||||
Width = 61
|
||||
Anchors = [akTop, akLeft, akBottom]
|
||||
AutoSize = True
|
||||
BorderSpacing.Left = 4
|
||||
Caption = '&Load...'
|
||||
OnClick = BtnLoadClick
|
||||
TabOrder = 2
|
||||
TabOrder = 0
|
||||
end
|
||||
object BtnSave: TButton
|
||||
AnchorSideLeft.Control = BtnLoad
|
||||
@ -83,9 +81,9 @@ object YearGridEditForm: TYearGridEditForm
|
||||
AnchorSideTop.Control = BtnLoad
|
||||
AnchorSideBottom.Control = BtnLoad
|
||||
AnchorSideBottom.Side = asrBottom
|
||||
Left = 70
|
||||
Left = 65
|
||||
Height = 26
|
||||
Top = 4
|
||||
Top = 0
|
||||
Width = 59
|
||||
Anchors = [akTop, akLeft, akBottom]
|
||||
AutoSize = True
|
||||
@ -93,26 +91,68 @@ object YearGridEditForm: TYearGridEditForm
|
||||
BorderSpacing.Right = 16
|
||||
Caption = '&Save...'
|
||||
OnClick = BtnSaveClick
|
||||
TabOrder = 3
|
||||
TabOrder = 1
|
||||
end
|
||||
end
|
||||
object MemoText: TMemo
|
||||
Left = 0
|
||||
Height = 332
|
||||
Top = 0
|
||||
Width = 394
|
||||
Left = 6
|
||||
Height = 172
|
||||
Top = 36
|
||||
Width = 382
|
||||
Align = alClient
|
||||
BorderSpacing.Left = 6
|
||||
BorderSpacing.Right = 6
|
||||
TabOrder = 1
|
||||
end
|
||||
object Panel2: TPanel
|
||||
Left = 6
|
||||
Height = 24
|
||||
Top = 6
|
||||
Width = 382
|
||||
Align = alTop
|
||||
AutoSize = True
|
||||
BorderSpacing.Around = 6
|
||||
BevelOuter = bvNone
|
||||
ClientHeight = 24
|
||||
ClientWidth = 382
|
||||
TabOrder = 0
|
||||
object ColorBox: TColorBox
|
||||
AnchorSideLeft.Control = LblColor
|
||||
AnchorSideLeft.Side = asrBottom
|
||||
AnchorSideTop.Control = Panel2
|
||||
AnchorSideRight.Control = Panel2
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 37
|
||||
Height = 24
|
||||
Top = 0
|
||||
Width = 345
|
||||
Style = [cbStandardColors, cbExtendedColors, cbIncludeNone, cbIncludeDefault, cbPrettyNames, cbCustomColors]
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
BorderSpacing.Left = 8
|
||||
DropDownCount = 24
|
||||
ItemHeight = 16
|
||||
TabOrder = 0
|
||||
end
|
||||
object LblColor: TLabel
|
||||
AnchorSideLeft.Control = Panel2
|
||||
AnchorSideTop.Control = ColorBox
|
||||
AnchorSideTop.Side = asrCenter
|
||||
Left = 0
|
||||
Height = 15
|
||||
Top = 5
|
||||
Width = 29
|
||||
Caption = 'Color'
|
||||
end
|
||||
end
|
||||
object OpenDialog: TOpenDialog
|
||||
Filter = 'Text Files|*.txt|All Files|*.*'
|
||||
left = 88
|
||||
top = 104
|
||||
Left = 64
|
||||
Top = 80
|
||||
end
|
||||
object SaveDialog: TSaveDialog
|
||||
DefaultExt = '.txt'
|
||||
Filter = 'Text Files|*.txt|All Files|*.*'
|
||||
left = 120
|
||||
top = 104
|
||||
Left = 64
|
||||
Top = 136
|
||||
end
|
||||
end
|
||||
|
@ -30,13 +30,16 @@ unit JvYearGridEditForm;
|
||||
interface
|
||||
|
||||
uses
|
||||
SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Buttons, ExtCtrls;
|
||||
SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Buttons,
|
||||
ExtCtrls, ColorBox;
|
||||
|
||||
type
|
||||
|
||||
{ TYearGridEditForm }
|
||||
|
||||
TYearGridEditForm = class(TForm) //JvForm)
|
||||
ColorBox: TColorBox;
|
||||
LblColor: TLabel;
|
||||
Panel1: TPanel;
|
||||
BtnOK: TBitBtn;
|
||||
BitCancel: TBitBtn;
|
||||
@ -44,9 +47,11 @@ type
|
||||
BtnLoad: TButton;
|
||||
BtnSave: TButton;
|
||||
OpenDialog: TOpenDialog;
|
||||
Panel2: TPanel;
|
||||
SaveDialog: TSaveDialog;
|
||||
procedure BtnLoadClick(Sender: TObject);
|
||||
procedure BtnSaveClick(Sender: TObject);
|
||||
procedure FormCreate(Sender: TObject);
|
||||
procedure FormShow(Sender: TObject);
|
||||
public
|
||||
end;
|
||||
@ -56,6 +61,9 @@ implementation
|
||||
|
||||
{$R *.lfm}
|
||||
|
||||
const
|
||||
DEFAULT_COLOR = 206 + 250 shl 8 + 253 shl 16;
|
||||
|
||||
procedure TYearGridEditForm.BtnLoadClick(Sender: TObject);
|
||||
begin
|
||||
if OpenDialog.Execute then
|
||||
@ -70,10 +78,16 @@ begin
|
||||
MemoText.SetFocus;
|
||||
end;
|
||||
|
||||
procedure TYearGridEditForm.FormCreate(Sender: TObject);
|
||||
begin
|
||||
ColorBox.DefaultColorColor := DEFAULT_COLOR;
|
||||
ColorBox.Selected := DEFAULT_COLOR;
|
||||
end;
|
||||
|
||||
procedure TYearGridEditForm.FormShow(Sender: TObject);
|
||||
begin
|
||||
MemoText.SetFocus;
|
||||
end;
|
||||
|
||||
|
||||
end.
|
||||
|
||||
|
Reference in New Issue
Block a user