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;
|
||||
|
Reference in New Issue
Block a user