CalLite: Some simplification of r6950.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@6952 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2019-05-26 20:34:04 +00:00
parent f6af85d7c6
commit ad9b3eb976

View File

@ -283,7 +283,6 @@ type
procedure Paint; override; procedure Paint; override;
procedure Resize; override; procedure Resize; override;
procedure UpdateBiDiMode; procedure UpdateBiDiMode;
procedure UpdateBuffer;
procedure UseDayName(ADayOfWeek: TDayOfWeek; const AValue: String); procedure UseDayName(ADayOfWeek: TDayOfWeek; const AValue: String);
procedure UseDayNames(const AValue: String); procedure UseDayNames(const AValue: String);
procedure UseDisplayTexts(const AValue: String); procedure UseDisplayTexts(const AValue: String);
@ -302,6 +301,7 @@ type
procedure AddSelectedDate(ADate: TDate); procedure AddSelectedDate(ADate: TDate);
procedure ClearSelectedDates; procedure ClearSelectedDates;
procedure Draw; // Use instead of Invalidate to recreate the buffer
function IsSelected(ADate: TDate): Boolean; function IsSelected(ADate: TDate): Boolean;
function SelectedDates: TCalDateArray; function SelectedDates: TCalDateArray;
@ -1408,8 +1408,7 @@ procedure TCalColors.SetColor(AIndex: Integer; AValue: TColor);
begin begin
if FColors[AIndex] = AValue then exit; if FColors[AIndex] = AValue then exit;
FColors[AIndex] := AValue; FColors[AIndex] := AValue;
FOwner.FBufferValid := false; FOwner.Draw;
FOwner.Invalidate;
end; end;
@ -1419,6 +1418,7 @@ constructor TCalendarLite.Create(anOwner: TComponent);
begin begin
inherited Create(anOwner); inherited Create(anOwner);
FFormatSettings := DefaultFormatSettings; FFormatSettings := DefaultFormatSettings;
FCalDrawer := TCalDrawer.Create(Self);
FSelDates := TCalDateList.Create; FSelDates := TCalDateList.Create;
FColors := TCalColors.Create(self); FColors := TCalColors.Create(self);
//Color := clWhite; //Color := clWhite;
@ -1441,7 +1441,6 @@ begin
SetDefaultDisplayTexts; SetDefaultDisplayTexts;
FCustomDisplayTexts := GetDisplayTexts; FCustomDisplayTexts := GetDisplayTexts;
FPopupMenu := TPopupMenu.Create(Self); FPopupMenu := TPopupMenu.Create(Self);
FCalDrawer := TCalDrawer.Create(Self);
FDblClickTimer := TTimer.Create(self); FDblClickTimer := TTimer.Create(self);
FDblClickTimer.Enabled := false; FDblClickTimer.Enabled := false;
FDblClickTimer.Interval := DBLCLICK_INTERVAL; FDblClickTimer.Interval := DBLCLICK_INTERVAL;
@ -1466,7 +1465,7 @@ end;
procedure TCalendarLite.AddSelectedDate(ADate: TDate); procedure TCalendarLite.AddSelectedDate(ADate: TDate);
begin begin
FSelDates.AddDate(ADate); FSelDates.AddDate(ADate);
Invalidate; Draw;
end; end;
procedure TCalendarLite.ChangeDateTo(ADate: TDate; ASelMode: TCalSelMode); procedure TCalendarLite.ChangeDateTo(ADate: TDate; ASelMode: TCalSelMode);
@ -1544,20 +1543,13 @@ begin
if MonthOf(FDate) <> oldMonth then if MonthOf(FDate) <> oldMonth then
MonthChange; MonthChange;
FBufferValid := false; Draw;
{
with FCalDrawer do begin
FCanvas.Brush.Color := Colors.BackgroundColor;
FCanvas.FillRect(FBoundsRect);
end;
}
Invalidate;
end; end;
procedure TCalendarLite.ClearSelectedDates; procedure TCalendarLite.ClearSelectedDates;
begin begin
FSelDates.Clear; FSelDates.Clear;
Invalidate; Draw;
end; end;
procedure TCalendarLite.DateChange; procedure TCalendarLite.DateChange;
@ -1589,6 +1581,15 @@ begin
end; end;
{$endif} {$endif}
{ Use this method to enforce a repaint of the calendar (instead of the standard
"Invalidate". This is because it marks the drawing buffer to be invalid
and enforces repainting of the buffer. }
procedure TCalendarLite.Draw;
begin
FBufferValid := false;
Invalidate;
end;
class function TCalendarLite.GetControlClassDefaultSize: TSize; class function TCalendarLite.GetControlClassDefaultSize: TSize;
begin begin
{$ifdef lcl_scaling} {$ifdef lcl_scaling}
@ -1671,8 +1672,7 @@ begin
mbLeft : FCalDrawer.LeftClick(FClickPoint, FClickShift); mbLeft : FCalDrawer.LeftClick(FClickPoint, FClickShift);
mbRight : FCalDrawer.RightClick; mbRight : FCalDrawer.RightClick;
end; end;
FBufferValid := false; Draw;
Invalidate;
end; end;
function TCalendarLite.IsSelected(ADate: TDate): Boolean; function TCalendarLite.IsSelected(ADate: TDate): Boolean;
@ -1777,48 +1777,14 @@ begin
end; end;
procedure TCalendarLite.Paint; procedure TCalendarLite.Paint;
var
r: TRect;
begin begin
if Assigned(FCalDrawer) then if Assigned(FCalDrawer) then
begin begin
if not FBufferValid then if not FBufferValid then begin
UpdateBuffer; FCalDrawer.Draw; // Re-draws the buffer
FBufferValid := true;
end;
Canvas.Draw(0, 0, FCalDrawer.Buffer); Canvas.Draw(0, 0, FCalDrawer.Buffer);
(*
if ParentFont then
begin
if (Parent.Font <> FCalDrawer.FCanvas.Font)
then FCalDrawer.FCanvas.Font := Parent.Font
else if (Canvas.Font.Color <> Colors.TextColor)
then FColors.TextColor := Canvas.Font.Color;
end;
case (BiDiMode = bdLeftToRight) of
False: if not FCalDrawer.FTextStyle.RightToLeft then
FCalDrawer.FTextStyle.RightToLeft := True;
True : if FCalDrawer.FTextStyle.RightToLeft then
FCalDrawer.FTextStyle.RightToLeft := False;
end;
if ParentColor then
Canvas.Brush.Color := Parent.Color
else
Canvas.Brush.Color:= Colors.BackGroundColor;
Canvas.FillRect(ClientRect);
if (coShowBorder in FOptions) then
begin
if (Canvas.Pen.Color <> FColors.BorderColor) then
Canvas.Pen.Color := FColors.BorderColor;
Canvas.Pen.Style := psSolid;
Canvas.Frame(ClientRect);
end;
r:= ClientRect;
if (coShowBorder in FOptions) then InflateRect(r, -1, -1);
FCalDrawer.FBoundsRect:= r;
FCalDrawer.Draw;
*)
end; end;
inherited Paint; inherited Paint;
@ -1827,14 +1793,8 @@ end;
procedure TCalendarLite.Resize; procedure TCalendarLite.Resize;
begin begin
FBufferValid := false; FBufferValid := false;
inherited;
end;
procedure TCalendarLite.UpdateBuffer;
begin
FCalDrawer.BoundsRect := ClientRect; FCalDrawer.BoundsRect := ClientRect;
FCalDrawer.Draw; inherited;
FBufferValid := true;
end; end;
procedure TCalendarLite.PopulateHolidayPopupMenu; procedure TCalendarLite.PopulateHolidayPopupMenu;
@ -1942,16 +1902,14 @@ procedure TCalendarLite.SetButtonHeight(const AValue: Integer);
begin begin
if FButtonHeight = AValue then exit; if FButtonHeight = AValue then exit;
FButtonHeight := AValue; FButtonHeight := AValue;
FBufferValid := false; Draw;
Invalidate;
end; end;
procedure TCalendarLite.SetButtonWidth(const AValue: Integer); procedure TCalendarLite.SetButtonWidth(const AValue: Integer);
begin begin
if FButtonWidth = AValue then exit; if FButtonWidth = AValue then exit;
FButtonWidth := AValue; FButtonWidth := AValue;
FBufferValid := false; Draw;
Invalidate;
end; end;
procedure TCalendarLite.SetCustomDayNames(const AValue: String); procedure TCalendarLite.SetCustomDayNames(const AValue: String);
@ -1987,9 +1945,7 @@ begin
DateChange; DateChange;
if MonthOf(FDate) <> oldMonth then if MonthOf(FDate) <> oldMonth then
MonthChange; MonthChange;
FBufferValid := false; Draw;
FBufferValid := false;
Invalidate;
end; end;
procedure TCalendarLite.SetDefaultDayNames; procedure TCalendarLite.SetDefaultDayNames;
@ -2049,7 +2005,7 @@ begin
finally finally
L.Free; L.Free;
end; end;
Invalidate; Draw;
end; end;
procedure TCalendarLite.SetLanguage(AValue : TLanguage); procedure TCalendarLite.SetLanguage(AValue : TLanguage);
@ -2120,7 +2076,7 @@ begin
end; end;
end; end;
Invalidate; Draw;
end; end;
function TCalendarLite.SelMode(Shift: TShiftState): TCalSelMode; function TCalendarLite.SelMode(Shift: TShiftState): TCalSelMode;
@ -2171,8 +2127,7 @@ procedure TCalendarLite.SetStartingDayOfWeek(AValue: TDayOfWeek);
begin begin
if FStartingDayOfWeek = AValue then Exit; if FStartingDayOfWeek = AValue then Exit;
FStartingDayOfWeek := AValue; FStartingDayOfWeek := AValue;
FBufferValid := false; Draw;
Invalidate;
end; end;
procedure TCalendarLite.SetOptions(AValue: TCalOptions); procedure TCalendarLite.SetOptions(AValue: TCalOptions);
@ -2185,16 +2140,14 @@ begin
end; end;
if Length(FCalDrawer.FRowPositions) <> LastRow+1 then if Length(FCalDrawer.FRowPositions) <> LastRow+1 then
SetLength(FCalDrawer.FRowPositions, LastRow+1); SetLength(FCalDrawer.FRowPositions, LastRow+1);
FBufferValid := false; Draw;
Invalidate;
end; end;
procedure TCalendarLite.SetWeekendDays(AValue: TDaysOfWeek); procedure TCalendarLite.SetWeekendDays(AValue: TDaysOfWeek);
begin begin
if FWeekendDays = AValue then Exit; if FWeekendDays = AValue then Exit;
FWeekendDays := AValue; FWeekendDays := AValue;
FBufferValid := false; Draw;
Invalidate;
end; end;
{ The DblClickTimer was triggered by a mouse-down event; its purpose is to { The DblClickTimer was triggered by a mouse-down event; its purpose is to