From 7d36353fbd081d7797ef2544c6edca7390a02010 Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Thu, 27 Dec 2018 17:06:09 +0000 Subject: [PATCH] callight: Use copy of FormatSettings in calendar. git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@6773 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- components/callite/demo1/CalLiteTest.lpi | 9 +-- components/callite/demo2/testCalLite.lpi | 11 ++- components/callite/demo2/umaintestcallite.lfm | 21 +++--- components/callite/source/calendarlite.pas | 72 +++++++++++++------ 4 files changed, 71 insertions(+), 42 deletions(-) diff --git a/components/callite/demo1/CalLiteTest.lpi b/components/callite/demo1/CalLiteTest.lpi index 2671a64f8..ea653dbdd 100644 --- a/components/callite/demo1/CalLiteTest.lpi +++ b/components/callite/demo1/CalLiteTest.lpi @@ -1,7 +1,7 @@ - + @@ -20,9 +20,10 @@ - - - + + + + diff --git a/components/callite/demo2/testCalLite.lpi b/components/callite/demo2/testCalLite.lpi index 26ae4cae1..4057bf780 100644 --- a/components/callite/demo2/testCalLite.lpi +++ b/components/callite/demo2/testCalLite.lpi @@ -1,7 +1,7 @@ - + @@ -19,13 +19,12 @@ - - - - - + + + + diff --git a/components/callite/demo2/umaintestcallite.lfm b/components/callite/demo2/umaintestcallite.lfm index 0ecc04c6c..c88f7c5f4 100644 --- a/components/callite/demo2/umaintestcallite.lfm +++ b/components/callite/demo2/umaintestcallite.lfm @@ -12,29 +12,28 @@ object Form1: TForm1 LCLVersion = '2.1.0.0' object PSettings: TPanel Left = 0 - Height = 432 + Height = 448 Top = 0 Width = 753 Align = alTop - ClientHeight = 432 + ClientHeight = 448 ClientWidth = 753 TabOrder = 0 object cgOptions: TCheckGroup Left = 24 - Height = 384 + Height = 392 Top = 40 Width = 160 AutoFill = True Caption = 'Set calendar Options' ChildSizing.LeftRightSpacing = 6 - ChildSizing.TopBottomSpacing = 6 ChildSizing.EnlargeHorizontal = crsHomogenousChildResize ChildSizing.EnlargeVertical = crsHomogenousChildResize ChildSizing.ShrinkHorizontal = crsScaleChilds ChildSizing.ShrinkVertical = crsScaleChilds ChildSizing.Layout = cclLeftToRightThenTopToBottom ChildSizing.ControlsPerLine = 1 - ClientHeight = 364 + ClientHeight = 372 ClientWidth = 156 Items.Strings = ( 'coBoldDayNames' @@ -117,20 +116,19 @@ object Form1: TForm1 end object rgLanguage: TRadioGroup Left = 200 - Height = 208 + Height = 216 Top = 216 Width = 160 AutoFill = True Caption = 'Language to use' ChildSizing.LeftRightSpacing = 6 - ChildSizing.TopBottomSpacing = 6 ChildSizing.EnlargeHorizontal = crsHomogenousChildResize ChildSizing.EnlargeVertical = crsHomogenousChildResize ChildSizing.ShrinkHorizontal = crsScaleChilds ChildSizing.ShrinkVertical = crsScaleChilds ChildSizing.Layout = cclLeftToRightThenTopToBottom ChildSizing.ControlsPerLine = 1 - ClientHeight = 188 + ClientHeight = 196 ClientWidth = 156 ItemIndex = 0 Items.Strings = ( @@ -155,7 +153,6 @@ object Form1: TForm1 AutoFill = True Caption = 'Starting day of the week' ChildSizing.LeftRightSpacing = 6 - ChildSizing.TopBottomSpacing = 6 ChildSizing.EnlargeHorizontal = crsHomogenousChildResize ChildSizing.EnlargeVertical = crsHomogenousChildResize ChildSizing.ShrinkHorizontal = crsScaleChilds @@ -178,11 +175,11 @@ object Form1: TForm1 end object GroupBox1: TGroupBox Left = 376 - Height = 384 + Height = 392 Top = 40 Width = 160 Caption = 'Colors' - ClientHeight = 364 + ClientHeight = 372 ClientWidth = 156 TabOrder = 6 object CbArrowBorder: TColorButton @@ -491,7 +488,7 @@ object Form1: TForm1 end object SelDateListbox: TListBox Left = 560 - Height = 144 + Height = 152 Top = 280 Width = 168 Columns = 2 diff --git a/components/callite/source/calendarlite.pas b/components/callite/source/calendarlite.pas index bb4992080..f39355a04 100644 --- a/components/callite/source/calendarlite.pas +++ b/components/callite/source/calendarlite.pas @@ -245,9 +245,7 @@ type FCalDrawer: TCalDrawer; FColors: TCalColors; FDate: TDateTime; - FDayNames: TStringList; FDisplayTexts: TStringList; - FMonthNames: TStringList; FOnDateChange: TNotifyEvent; FOnMonthChange: TNotifyEvent; FOnGetDayText: TCalGetDayTextEvent; @@ -269,6 +267,7 @@ type FClickButton: TMouseButton; FLanguage: TLanguage; FDblClickTimer: TTimer; + FFormatSettings: TFormatSettings; function GetDayNames: String; function GetDisplayText(aTextIndex: TDisplayText): String; function GetDisplayTexts: String; @@ -932,7 +931,7 @@ begin s:= FOwner.GetDisplayText(dtToday); if (coShowTodayName in FOwner.Options) then s := Format('%s %s',[s, FOwner.GetDayName(TDayOfWeek(DayOfWeek(Date())))]); - AppendStr(s, ' ' + FormatDateTime(FOwner.GetDisplayText(dtTodayFormat), Date())); + AppendStr(s, ' ' + FormatDateTime(FOwner.GetDisplayText(dtTodayFormat), Date(), FOwner.FFormatSettings)); w1 := FCanvas.TextWidth('aaa'); w2 := FCanvas.TextWidth(' '); w3 := FCanvas.TextWidth(s); @@ -1287,6 +1286,7 @@ end; constructor TCalendarLite.Create(anOwner: TComponent); begin inherited Create(anOwner); + FFormatSettings := DefaultFormatSettings; FSelDates := TCalDateList.Create; FColors := TCalColors.Create(self); Color := clWhite; @@ -1297,8 +1297,6 @@ begin Constraints.MinWidth := ScaleY(DefMinWidth, DESIGNTIME_PPI); Canvas.Brush.Style := bsSolid; TabStop := true; - FDayNames := TStringList.Create; - FMonthNames := TStringList.Create; FDisplayTexts := TStringList.Create; FDisplayTexts.StrictDelimiter := True; FDisplayTexts.Delimiter := ','; @@ -1321,8 +1319,6 @@ end; destructor TCalendarLite.Destroy; begin FreeAndNil(FSelDates); - FreeAndNil(FDayNames); - FreeAndNil(FMonthNames); FreeAndNil(FDisplayTexts); FreeAndNil(FColors); SetLength(FCalDrawer.FRowPositions, 0); @@ -1448,14 +1444,22 @@ end; function TCalendarLite.GetDayName(ADayOfWeek: TDayOfWeek): String; begin - Result := SysToUTF8(DefaultFormatSettings.ShortDayNames[integer(ADayOfWeek)]); - if Pred(integer(ADayOfWeek)) < FDayNames.Count then - Result := FDayNames[Pred(integer(ADayOfWeek))]; + Result := FFormatSettings.ShortDayNames[integer(ADayOfWeek)]; end; function TCalendarLite.GetDayNames: String; +var + L: TStrings; + i: Integer; begin - Result := FDayNames.CommaText; + L := TStringList.Create; + try + for i:= 1 to 7 do + L.Add(FFormatSettings.ShortDayNames[i]); + Result := L.CommaText; + finally + L.Free; + end; end; function TCalendarLite.GetDisplayText(aTextIndex: TDisplayText): String; @@ -1470,14 +1474,22 @@ end; function TCalendarLite.GetMonthName(AMonth: Integer): String; begin - Result := SysToUTF8(DefaultFormatSettings.LongMonthNames[AMonth]); - if pred(AMonth) < FMonthnames.Count then - Result := FMonthNames[pred(AMonth)]; + Result := FFormatSettings.LongMonthNames[AMonth]; end; function TCalendarLite.GetMonthNames: String; +var + L: TStrings; + i: Integer; begin - Result := FMonthNames.CommaText; + L := TStringList.Create; + try + for i:=1 to 12 do + L.Add(FFormatSettings.ShortMonthNames[i]); + Result := L.CommaText; + finally + L.Free; + end; end; procedure TCalendarLite.HolidayMenuItemClicked(Sender: TObject); @@ -1766,9 +1778,19 @@ begin end; procedure TCalendarLite.SetDayNames(const AValue: String); +var + i: Integer; + L: TStrings; begin - FDayNames.CommaText := AValue; - Invalidate; + L := TStringList.Create; + try + L.CommaText := AValue; + for i := 1 to 7 do + FFormatSettings.ShortDayNames[i] := L[i-1]; + Invalidate; + finally + L.Free; + end; end; procedure TCalendarLite.SetDefaultDisplayTexts; @@ -1849,9 +1871,19 @@ begin end; procedure TCalendarLite.SetMonthNames(const AValue: String); +var + i: Integer; + L: TStrings; begin - FMonthNames.CommaText := AValue; - Invalidate; + L := TStringList.Create; + try + L.CommaText := AValue; + for i:= 1 to 12 do + FFormatSettings.ShortMonthNames[i] := L[i-1]; + Invalidate; + finally + L.Free; + end; end; procedure TCalendarLite.SetMultiSelect(AValue: Boolean); @@ -1910,7 +1942,7 @@ end; procedure TCalendarLite.ShowHintWindow(APoint: TPoint; ADate: TDate); var - txt: String; + txt: String = ''; y, m, d: Word; begin if Assigned(FOnHint) then begin