From fe385f8a664ea8c71b3a358fead1f178e3b4a651 Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Sun, 18 Dec 2022 18:52:00 +0000 Subject: [PATCH] CalLite: Fix compilation with FPC 3.3.1. This is a code-breaking change in applications which rely on TDayOfWeek beginning at 1. Issue #39048. git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8656 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- components/callite/demo1/main.lfm | 2 +- components/callite/demo1/main.pas | 3 +- components/callite/demo2/umaintestcallite.lfm | 47 +++++++++++++------ components/callite/demo2/umaintestcallite.pp | 7 +-- components/callite/demo3/main.lpi | 4 +- components/callite/source/calendarlite.pas | 30 ++++++------ 6 files changed, 58 insertions(+), 35 deletions(-) diff --git a/components/callite/demo1/main.lfm b/components/callite/demo1/main.lfm index e96bf790a..7c1457b67 100644 --- a/components/callite/demo1/main.lfm +++ b/components/callite/demo1/main.lfm @@ -9,5 +9,5 @@ object Form1: TForm1 KeyPreview = True OnCreate = FormCreate Position = poScreenCenter - LCLVersion = '1.7' + LCLVersion = '2.3.0.0' end diff --git a/components/callite/demo1/main.pas b/components/callite/demo1/main.pas index 957718dd4..58204512d 100644 --- a/components/callite/demo1/main.pas +++ b/components/callite/demo1/main.pas @@ -42,7 +42,8 @@ begin Height := self.Height - 2*Top; Date := Now(); DisplayTexts := '"Today is",dd/mm/yyyy,"Holidays during","There are no holidays set for"'; - WeekendDays := [dowSaturday]; + WeekendDays := [dowSaturday, dowSunday]; + StartingDayOfWeek := dowMonday; Anchors := [akLeft, akTop, akRight, akBottom]; end; end; diff --git a/components/callite/demo2/umaintestcallite.lfm b/components/callite/demo2/umaintestcallite.lfm index e70d005f1..0ece5f4a4 100644 --- a/components/callite/demo2/umaintestcallite.lfm +++ b/components/callite/demo2/umaintestcallite.lfm @@ -9,7 +9,7 @@ object Form1: TForm1 Color = clWindow Font.CharSet = ANSI_CHARSET OnCreate = FormCreate - LCLVersion = '2.1.0.0' + LCLVersion = '2.3.0.0' object PSettings: TPanel Left = 0 Height = 432 @@ -61,7 +61,7 @@ object Form1: TForm1 Left = 560 Height = 19 Top = 112 - Width = 169 + Width = 167 Caption = 'Ignore OnGetHolidays event' OnChange = cbUseHolidaysChange TabOrder = 1 @@ -72,6 +72,7 @@ object Form1: TForm1 Top = 8 Width = 318 Caption = 'Various calendar property settings can be changed below:' + Color = clDefault Font.CharSet = ANSI_CHARSET Font.Style = [fsBold] ParentColor = False @@ -83,6 +84,7 @@ object Form1: TForm1 Top = 52 Width = 32 Caption = 'Width' + Color = clDefault ParentColor = False end object seWidth: TSpinEdit @@ -113,6 +115,7 @@ object Form1: TForm1 Top = 81 Width = 36 Caption = 'Height' + Color = clDefault ParentColor = False end object rgLanguage: TRadioGroup @@ -208,6 +211,7 @@ object Form1: TForm1 Top = 13 Width = 67 Caption = 'ArrowBorder' + Color = clDefault ParentColor = False end object Label3: TLabel @@ -216,6 +220,7 @@ object Form1: TForm1 Top = 37 Width = 32 Caption = 'Arrow' + Color = clDefault ParentColor = False end object CbBackground: TColorButton @@ -246,6 +251,7 @@ object Form1: TForm1 Top = 61 Width = 64 Caption = 'Background' + Color = clDefault ParentColor = False end object Label5: TLabel @@ -254,6 +260,7 @@ object Form1: TForm1 Top = 85 Width = 35 Caption = 'Border' + Color = clDefault ParentColor = False end object CbDayLine: TColorButton @@ -284,6 +291,7 @@ object Form1: TForm1 Top = 109 Width = 42 Caption = 'Day line' + Color = clDefault ParentColor = False end object Label7: TLabel @@ -292,6 +300,7 @@ object Form1: TForm1 Top = 133 Width = 46 Caption = 'Holidays' + Color = clDefault ParentColor = False end object CbPastMonth: TColorButton @@ -322,6 +331,7 @@ object Form1: TForm1 Top = 157 Width = 89 Caption = 'Past/next month' + Color = clDefault ParentColor = False end object Label9: TLabel @@ -330,6 +340,7 @@ object Form1: TForm1 Top = 181 Width = 70 Caption = 'Selected date' + Color = clDefault ParentColor = False end object CbText: TColorButton @@ -360,6 +371,7 @@ object Form1: TForm1 Top = 205 Width = 21 Caption = 'Text' + Color = clDefault ParentColor = False end object Label11: TLabel @@ -368,6 +380,7 @@ object Form1: TForm1 Top = 229 Width = 65 Caption = 'Today frame' + Color = clDefault ParentColor = False end object CbTopRow: TColorButton @@ -398,6 +411,7 @@ object Form1: TForm1 Top = 253 Width = 42 Caption = 'Top row' + Color = clDefault ParentColor = False end object Label13: TLabel @@ -406,6 +420,7 @@ object Form1: TForm1 Top = 277 Width = 65 Caption = 'Top row text' + Color = clDefault ParentColor = False end object CbWeekend: TColorButton @@ -425,6 +440,7 @@ object Form1: TForm1 Top = 301 Width = 49 Caption = 'Weekend' + Color = clDefault ParentColor = False end end @@ -432,7 +448,7 @@ object Form1: TForm1 Left = 560 Height = 19 Top = 184 - Width = 144 + Width = 142 Caption = 'Override font of 1st day' OnChange = CbPrepareCanvasChange TabOrder = 7 @@ -450,7 +466,7 @@ object Form1: TForm1 Left = 560 Height = 19 Top = 208 - Width = 161 + Width = 159 Caption = 'Owner draw (icon, Nov 11)' OnChange = CbDrawCellChange TabOrder = 9 @@ -459,7 +475,7 @@ object Form1: TForm1 Left = 560 Height = 19 Top = 136 - Width = 152 + Width = 150 Caption = 'Add holiday name to cell' OnChange = CbAddHolidayNameToCellChange TabOrder = 10 @@ -468,7 +484,7 @@ object Form1: TForm1 Left = 560 Height = 19 Top = 232 - Width = 92 + Width = 90 Caption = 'CbShowHints' Checked = True OnChange = CbShowHintsChange @@ -479,7 +495,7 @@ object Form1: TForm1 Left = 560 Height = 19 Top = 256 - Width = 81 + Width = 79 Caption = 'Multi select' OnChange = CbMultiSelectChange TabOrder = 12 @@ -497,7 +513,7 @@ object Form1: TForm1 Left = 560 Height = 19 Top = 160 - Width = 153 + Width = 151 Caption = 'Use built-in popup menu' Checked = True OnChange = CbUseBuiltinPopupChange @@ -510,6 +526,7 @@ object Form1: TForm1 Top = 52 Width = 66 Caption = 'Buttonwidth' + Color = clDefault ParentColor = False end object seButtonWidth: TSpinEdit @@ -528,6 +545,7 @@ object Form1: TForm1 Top = 81 Width = 70 Caption = 'Buttonheight' + Color = clDefault ParentColor = False end object seButtonHeight: TSpinEdit @@ -634,18 +652,19 @@ object Form1: TForm1 Top = 408 Width = 34 Caption = 'Label1' + Color = clDefault ParentColor = False end end object FontDialog: TFontDialog MinFontSize = 0 MaxFontSize = 0 - left = 408 - top = 416 + Left = 408 + Top = 416 end object ImageList1: TImageList - left = 336 - top = 432 + Left = 336 + Top = 432 Bitmap = { 4C7A010000001000000010000000330200000000000078DA9D92DF6B526118C7 BDCAABEEFA13BC09BAE82FD85DD445D045C56E828211A3CB8C42486ACD1A04B5 @@ -669,8 +688,8 @@ object Form1: TForm1 } end object PopupMenu1: TPopupMenu - left = 117 - top = 465 + Left = 117 + Top = 465 object MenuItem1: TMenuItem Caption = 'Dummy item' end diff --git a/components/callite/demo2/umaintestcallite.pp b/components/callite/demo2/umaintestcallite.pp index b6a6fe941..8efbe79a3 100644 --- a/components/callite/demo2/umaintestcallite.pp +++ b/components/callite/demo2/umaintestcallite.pp @@ -177,7 +177,7 @@ begin if (opt in demoCal.Options) then cgOptions.Checked[integer(opt)] := True; seHeight.Value := demoCal.Height; seWidth.Value := demoCal.Width; - rgStartingDOW.ItemIndex := integer(demoCal.StartingDayOfWeek)-1; + rgStartingDOW.ItemIndex := ord(demoCal.StartingDayOfWeek); copyCal:= TCalendarLite.Create(Self); copyCal.Parent := Self; @@ -225,7 +225,7 @@ end; procedure TForm1.rgStartingDOWClick(Sender: TObject); begin - demoCal.StartingDayOfWeek := TDayOfWeek(rgStartingDOW.ItemIndex + 1); + demoCal.StartingDayOfWeek := TDayOfWeek(rgStartingDOW.ItemIndex); end; procedure TForm1.sbResetButtonHeightClick(Sender: TObject); @@ -344,7 +344,8 @@ end; procedure TForm1.CbPrepareCanvasChange(Sender: TObject); begin if CbPrepareCanvas.Checked then - demoCal.OnPrepareCanvas := @PrepareCanvas else + demoCal.OnPrepareCanvas := @PrepareCanvas + else demoCal.OnPrepareCanvas := nil; demoCal.Invalidate; end; diff --git a/components/callite/demo3/main.lpi b/components/callite/demo3/main.lpi index 894adca24..cfae4eeb7 100644 --- a/components/callite/demo3/main.lpi +++ b/components/callite/demo3/main.lpi @@ -15,7 +15,6 @@ - @@ -61,6 +60,9 @@ + + + diff --git a/components/callite/source/calendarlite.pas b/components/callite/source/calendarlite.pas index cce30a319..90ddd749e 100644 --- a/components/callite/source/calendarlite.pas +++ b/components/callite/source/calendarlite.pas @@ -61,12 +61,12 @@ type TArrowhead = (ahSingle, ahDouble); TArrowPoints = array[1..3] of TPoint; - TDayOfWeek = (dowSunday=1, dowMonday=2, dowTuesday=3, dowWednesday=4, - dowThursday=5, dowFriday=6, dowSaturday=7); + TDayOfWeek = (dowSunday, dowMonday, dowTuesday, dowWednesday, + dowThursday, dowFriday, dowSaturday); TDaysOfWeek = set of TDayOfWeek; - TDisplayText = (dtToday=0, dtTodayFormat=1, dtHolidaysDuring=2, - dtNoHolidaysDuring=3, dtTodayFormatLong=4, dtCaptionFormat=5); + TDisplayText = (dtToday, dtTodayFormat, dtHolidaysDuring, + dtNoHolidaysDuring, dtTodayFormatLong, dtCaptionFormat); THolidays = DWord; TGetHolidaysEvent = procedure (Sender: TObject; AMonth, AYear: Integer; @@ -884,7 +884,7 @@ var continueDrawing: Boolean; begin todayDate := Date; - dow := DayOfWeek(FOwner.FDate); + dow := DayOfWeek(FOwner.FDate) - 1; // DayOfWeek is 1-based, dow is 0-based ! c := dow - integer(FOwner.FStartingDayOfWeek); if (c < 0) then Inc(c, 7); startCol := Succ(c); @@ -931,7 +931,7 @@ begin end else { Special case: override weekend } if (coShowWeekend in FOwner.Options) and - (TDayOfWeek(DayOfWeek(dt)) in FOwner.FWeekendDays) then + (TDayOfWeek(DayOfWeek(dt) - 1) in FOwner.FWeekendDays) then begin FCanvas.Font.Color := FOwner.Colors.WeekendColor; if coBoldWeekend in FOwner.Options then @@ -1021,11 +1021,11 @@ begin FCanvas.Font.Style := FCanvas.Font.Style + [fsBold] else FCanvas.Font.Style := FCanvas.Font.Style - [fsBold]; - map := Integer(FOwner.FStartingDayOfWeek); + map := Integer(FOwner.FStartingDayOfWeek) + 1; for c:= Low(TWeekNameArray) to High(TWeekNameArray) do begin if (map > High(TWeekNameArray)) then map := Low(TWeekNameArray); - lbls[c] := FOwner.GetDayName(TDayOfWeek(map)); + lbls[c] := FOwner.GetDayName(TDayOfWeek(map - 1)); inc(map); end; for c:= Low(FColPositions) to High(FColPositions) do @@ -1069,7 +1069,7 @@ begin s:= FOwner.GetDisplayText(dtToday); if pos('%s', s) = 0 then begin if (coShowTodayName in FOwner.Options) then - s := Format('%s %s',[s, FOwner.GetDayName(TDayOfWeek(DayOfWeek(Date())))]); + s := Format('%s %s',[s, FOwner.GetDayName(TDayOfWeek(DayOfWeek(Date())-1))]); AppendStr(s, ' ' + FormatDateTime(FOwner.GetDisplayText(dtTodayFormat), Date(), FOwner.FFormatSettings)); end else begin if coShowTodayName in FOwner.Options then @@ -1637,7 +1637,7 @@ end; function TCalendarLite.GetDayName(ADayOfWeek: TDayOfWeek): String; begin - Result := FFormatSettings.ShortDayNames[integer(ADayOfWeek)]; + Result := FFormatSettings.ShortDayNames[integer(ADayOfWeek) + 1]; end; function TCalendarLite.GetDayNames: String; @@ -2216,7 +2216,7 @@ var d: Integer; begin if AValue = '' then exit; - d := ord(ADayOfWeek); + d := ord(ADayOfWeek) + 1; // TDayOfWeek is 0-based, FormatSettings.DayNames are 1-based. p := pos('|', AValue); if p > 0 then begin FFormatSettings.LongDayNames[d] := Trim(Copy(AValue, 1, p-1)); @@ -2230,15 +2230,15 @@ end; procedure TCalendarLite.UseDayNames(const AValue: String); var L: TStrings; - i, d: Integer; + i, dow: Integer; begin L := TStringList.Create; try L.CommaText := AValue; for i:=0 to L.Count-1 do begin - d := succ(i); - if d <= 7 then - UseDayName(TDayOfWeek(d), L[i]); + dow := i; + if dow < 7 then + UseDayName(TDayOfWeek(dow), L[i]); end; finally L.Free;