CalLite: Flag days in Finland: what changed
Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.
Title: CalLite: Flag days in Finland
| Old | New | Line | |
|---|---|---|---|
| 1 | + |  [[CalLite|TCalendarLite]] is a lightweight calendar component. This demo shows how CalLite can be used to display flag days in Finland in the calendar as small icons | |
| 2 | + | ||
| 3 | + | ## unit uFinlandFlagDays | |
| 4 | + | ||
| 5 | + | ``` pascal | |
| 6 | + | unit uFinlandFlagDays; | |
| 7 | + | ||
| 8 | + | {$mode objfpc}{$H+} | |
| 9 | + | ||
| 10 | + | interface | |
| 11 | + | ||
| 12 | + | uses | |
| 13 | + | Classes, SysUtils, CalendarLite, DateUtils; | |
| 14 | + | ||
| 15 | + | procedure CalendarGetFlagDaysInFinland( AMonth, AYear: Integer; | |
| 16 | + | var Holidays: THolidays); | |
| 17 | + | ||
| 18 | + | implementation | |
| 19 | + | const | |
| 20 | + | SATURDAY = 6; | |
| 21 | + | SUNDAY = 7; | |
| 22 | + | FEBRUARY = 2; | |
| 23 | + | MARCH = 3; | |
| 24 | + | APRIL = 4; | |
| 25 | + | MAY = 5; | |
| 26 | + | JUNE = 6; | |
| 27 | + | JULY = 7; | |
| 28 | + | OCTOBER = 10; | |
| 29 | + | NOVEMBER = 11; | |
| 30 | + | DECEMBER = 12; | |
| 31 | + | ||
| 32 | + | function MothersDay(year:integer):integer; | |
| 33 | + | var | |
| 34 | + | day : integer; | |
| 35 | + | a_date : TDateTime; | |
| 36 | + | begin | |
| 37 | + | day := 7; | |
| 38 | + | repeat | |
| 39 | + | inc(day); | |
| 40 | + | a_date := EncodeDate(year, MAY, day); | |
| 41 | + | until DayOfTheWeek( a_date ) = SUNDAY; | |
| 42 | + | result := day; | |
| 43 | + | end; | |
| 44 | + | ||
| 45 | + | function FathersDay(year:integer):integer; | |
| 46 | + | var | |
| 47 | + | day : integer; | |
| 48 | + | a_date : TDateTime; | |
| 49 | + | begin | |
| 50 | + | day := 7; | |
| 51 | + | repeat | |
| 52 | + | inc(day); | |
| 53 | + | a_date := EncodeDate(year, NOVEMBER, day); | |
| 54 | + | until DayOfTheWeek( a_date ) = SUNDAY; | |
| 55 | + | result := day; | |
| 56 | + | end; | |
| 57 | + | ||
| 58 | + | function MidsummerDay(year:integer):integer; | |
| 59 | + | var | |
| 60 | + | day : integer; | |
| 61 | + | a_date : TDateTime; | |
| 62 | + | begin | |
| 63 | + | day := 20-1; | |
| 64 | + | repeat | |
| 65 | + | inc(day); | |
| 66 | + | a_date := EncodeDate(year, JUNE, day); | |
| 67 | + | until DayOfTheWeek( a_date ) = SATURDAY; | |
| 68 | + | result := day; | |
| 69 | + | end; | |
| 70 | + | ||
| 71 | + | function MemorialDayWarDead(year:integer):integer; //memorial day for the war dead | |
| 72 | + | var | |
| 73 | + | day : integer; | |
| 74 | + | a_date : TDateTime; | |
| 75 | + | begin | |
| 76 | + | day := MothersDay(year); | |
| 77 | + | repeat | |
| 78 | + | inc(day); | |
| 79 | + | a_date := EncodeDate(year, MAY, day); | |
| 80 | + | until DayOfTheWeek( a_date ) = SUNDAY; | |
| 81 | + | result := day; | |
| 82 | + | end; | |
| 83 | + | ||
| 84 | + | procedure CalendarGetFlagDaysInFinland( AMonth, AYear: Integer; | |
| 85 | + | var Holidays: THolidays); | |
| 86 | + | begin | |
| 87 | + | ClearHolidays(Holidays); | |
| 88 | + | begin | |
| 89 | + | case AMonth of | |
| 90 | + | FEBRUARY: begin | |
| 91 | + | AddHoliday( 5, Holidays);//Birthday of the national poet JL Runeberg | |
| 92 | + | AddHoliday(28, Holidays);//Day of Kalevala | |
| 93 | + | end; | |
| 94 | + | MARCH: AddHoliday(19, Holidays);// Birthday of novelist and playwright | |
| 95 | + | // Minna Canth, Day of Equality | |
| 96 | + | APRIL: begin | |
| 97 | + | AddHoliday( 9, Holidays);// The day Mikael Agricola, also celebrated | |
| 98 | + | // as the Day of the Finnish language | |
| 99 | + | AddHoliday(27, Holidays);// National War Veterans' Day | |
| 100 | + | end; | |
| 101 | + | MAY: begin | |
| 102 | + | AddHoliday( 1, Holidays);// 1 May, Vappu, the Day of Finnish Labour | |
| 103 | + | AddHoliday( 9, Holidays);// Europe Day | |
| 104 | + | AddHoliday(12, Holidays);// Day of the Finnish Identity, birthday | |
| 105 | + | // of the statesman J V Snellman | |
| 106 | + | AddHoliday(MothersDay(AYear), Holidays); // Mother's Day | |
| 107 | + | AddHoliday(MemorialDayWarDead(AYear), Holidays);//Memorial day for | |
| 108 | + | //the war dead | |
| 109 | + | end; | |
| 110 | + | JUNE: begin | |
| 111 | + | AddHoliday( 4, Holidays);// Flag Day of the Finnish Defence Forces | |
| 112 | + | AddHoliday(MidsummerDay(AYear), Holidays);// Midsummer Day | |
| 113 | + | end; | |
| 114 | + | JULY: AddHoliday( 6, Holidays);// Birthday of the poet Eino Leino | |
| 115 | + | OCTOBER: begin | |
| 116 | + | AddHoliday(10, Holidays);// Birthday of the National writer | |
| 117 | + | // Aleksis Kivi, also celebrated as the | |
| 118 | + | // Day of Finnish literature | |
| 119 | + | AddHoliday(24, Holidays);// Day of the United Nations | |
| 120 | + | end; | |
| 121 | + | NOVEMBER: begin | |
| 122 | + | AddHoliday( 6, Holidays);// Finnish Swedish Heritage Day | |
| 123 | + | AddHoliday(FathersDay(AYear), Holidays);//Father's Day | |
| 124 | + | end; | |
| 125 | + | DECEMBER: begin | |
| 126 | + | AddHoliday( 6, Holidays);// Independence Day | |
| 127 | + | AddHoliday( 8, Holidays);// Birthday of the composer Jean Sibelius | |
| 128 | + | // also celebrated as the Day of Finnish | |
| 129 | + | // music | |
| 130 | + | end; | |
| 131 | + | end; | |
| 132 | + | end; | |
| 133 | + | end; | |
| 134 | + | ||
| 135 | + | end. | |
| 136 | + | ``` | |
| 137 | + | ||
| 138 | + | ## unit unitFinlandFlagDays | |
| 139 | + | ||
| 140 | + | ``` pascal | |
| 141 | + | unit unitFinlandFlagDays; | |
| 142 | + | ||
| 143 | + | {$mode objfpc}{$H+} | |
| 144 | + | ||
| 145 | + | interface | |
| 146 | + | ||
| 147 | + | uses | |
| 148 | + | Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, CalendarLite, | |
| 149 | + | Types, lcltype, uFinlandFlagDays; | |
| 150 | + | ||
| 151 | + | type | |
| 152 | + | ||
| 153 | + | { TForm1 } | |
| 154 | + | ||
| 155 | + | TForm1 = class(TForm) | |
| 156 | + | CalendarLite1: TCalendarLite; | |
| 157 | + | procedure CalendarLite1DrawCell(Sender: TObject; ACanvas: TCanvas; AYear, | |
| 158 | + | AMonth, ADay: Word; AState: TCalCellStates; var ARect: TRect; | |
| 159 | + | var AContinueDrawing: Boolean); | |
| 160 | + | procedure FormCreate(Sender: TObject); | |
| 161 | + | private | |
| 162 | + | ||
| 163 | + | public | |
| 164 | + | ||
| 165 | + | end; | |
| 166 | + | ||
| 167 | + | var | |
| 168 | + | Form1: TForm1; | |
| 169 | + | ||
| 170 | + | implementation | |
| 171 | + | ||
| 172 | + | procedure FlagOfFinland(var Bitmap: TBitmap); | |
| 173 | + | const | |
| 174 | + | FFH = 11; // FinlandFlagHeight | |
| 175 | + | FFCH1 = 4; // FinlandFlagCrossH1 | |
| 176 | + | FFCH2 = 7; // FinlandFlagCrossH2 | |
| 177 | + | FFW = 18; // FinlandFlagWidth | |
| 178 | + | FFCW1 = 5; // FinlandFlagCrossW1 | |
| 179 | + | FFCW2 = 8; // FinlandFlagCrossW2 | |
| 180 | + | begin | |
| 181 | + | Bitmap.Canvas.Pen.Color := clWhite; | |
| 182 | + | Bitmap.Canvas.Brush.Style:=bsSolid; | |
| 183 | + | Bitmap.Canvas.Brush.Color:= clWhite; | |
| 184 | + | Bitmap.Canvas.FillRect(0, 0, Bitmap.Width, Bitmap.Height); | |
| 185 | + | Bitmap.Canvas.Brush.Color:=RGBToColor(0, 47, 108) ; | |
| 186 | + | Bitmap.Canvas.FillRect(0,MulDiv(Bitmap.Height,FFCH1,FFH), | |
| 187 | + | Bitmap.Width,MulDiv(Bitmap.Height,FFCH2,FFH)); | |
| 188 | + | Bitmap.Canvas.FillRect(MulDiv(Bitmap.Width,FFCW1,FFW), | |
| 189 | + | 0,MulDiv(Bitmap.Width,FFCW2,FFW),Bitmap.Height); | |
| 190 | + | end; | |
| 191 | + | ||
| 192 | + | {$R *.lfm} | |
| 193 | + | ||
| 194 | + | { TForm1 } | |
| 195 | + | ||
| 196 | + | procedure TForm1.CalendarLite1DrawCell(Sender: TObject; ACanvas: TCanvas; | |
| 197 | + | AYear, AMonth, ADay: Word; AState: TCalCellStates; var ARect: TRect; | |
| 198 | + | var AContinueDrawing: Boolean); | |
| 199 | + | ||
| 200 | + | var | |
| 201 | + | Bitmap: TBitmap; | |
| 202 | + | Flagdays: THolidays; | |
| 203 | + | begin | |
| 204 | + | CalendarGetFlagDaysInFinland(AMonth,AYear,Flagdays); | |
| 205 | + | if IsHoliday(aDay,Flagdays) and not (csOtherMonth in AState) then begin | |
| 206 | + | Bitmap := TBitmap.Create; | |
| 207 | + | try | |
| 208 | + | // Initializes the Bitmap Size | |
| 209 | + | Bitmap.Height := 11; | |
| 210 | + | Bitmap.Width := 18; | |
| 211 | + | FlagOfFinland(Bitmap); | |
| 212 | + | ACanvas.Draw(ARect.Left, (ARect.Top + ARect.Bottom - Bitmap.Height) div 2, | |
| 213 | + | Bitmap); | |
| 214 | + | inc(ARect.Left, Bitmap.Width + 2); | |
| 215 | + | // Not changing AContinueDrawing from its default value (true) means | |
| 216 | + | // that the day text is drawn by the built-in procedure into | |
| 217 | + | // the reduced rectangle | |
| 218 | + | finally | |
| 219 | + | Bitmap.Free; | |
| 220 | + | end; | |
| 221 | + | end; | |
| 222 | + | end; | |
| 223 | + | ||
| 224 | + | procedure TForm1.FormCreate(Sender: TObject); | |
| 225 | + | begin | |
| 226 | + | CalendarLite1.Languages := lgFinnish; | |
| 227 | + | CalendarLite1.StartingDayOfWeek := dowMonday; | |
| 228 | + | CalendarLite1.Date:=now; | |
| 229 | + | end; | |
| 230 | + | ||
| 231 | + | end. | |
| 232 | + | ``` | |
| 233 | + | ||
| 234 | + | ## unitFinlandFlagDays.lfm | |
| 235 | + | ||
| 236 | + | ``` pascal | |
| 237 | + | object Form1: TForm1 | |
| 238 | + | Left = 543 | |
| 239 | + | Height = 278 | |
| 240 | + | Top = 159 | |
| 241 | + | Width = 426 | |
| 242 | + | Caption = 'Flag days in Finland' | |
| 243 | + | ClientHeight = 278 | |
| 244 | + | ClientWidth = 426 | |
| 245 | + | OnCreate = FormCreate | |
| 246 | + | LCLVersion = '1.8.0.5' | |
| 247 | + | object CalendarLite1: TCalendarLite | |
| 248 | + | Left = 72 | |
| 249 | + | Height = 200 | |
| 250 | + | Top = 56 | |
| 251 | + | Width = 274 | |
| 252 | + | Constraints.MinHeight = 120 | |
| 253 | + | Constraints.MinWidth = 120 | |
| 254 | + | ParentColor = False | |
| 255 | + | TabOrder = 0 | |
| 256 | + | TabStop = True | |
| 257 | + | Colors.TodayFrameColor = clGray | |
| 258 | + | Date = 42993 | |
| 259 | + | DayNames = 'Su,Ma,Ti,ke,To,Pe,La' | |
| 260 | + | DisplayTexts = '"Tänään on",dd.mm.yyyy,Lomapäivät,"Lomapäiviä ei ole asetettu"' | |
| 261 | + | MonthNames = 'Tammikuu,Helmikuu,Maaliskuu,Huhtikuu,Toukokuu,Kesäkuu,Heinäkuu,Elokuu,Syyskuu,Lokakuu,Marraskuu,Joulukuu' | |
| 262 | + | MultiSelect = False | |
| 263 | + | StartingDayOfWeek = dowMonday | |
| 264 | + | WeekendDays = [dowSunday, dowSaturday] | |
| 265 | + | Languages = lgFinnish | |
| 266 | + | OnDrawCell = CalendarLite1DrawCell | |
| 267 | + | end | |
| 268 | + | end | |
| 269 | + | ``` | |
| 270 | + | ||
| 271 | + | ## program flagdays_project | |
| 272 | + | ||
| 273 | + | ``` pascal | |
| 274 | + | program flagdays_project; | |
| 275 | + | ||
| 276 | + | {$mode objfpc}{$H+} | |
| 277 | + | ||
| 278 | + | uses | |
| 279 | + | {$IFDEF UNIX}{$IFDEF UseCThreads} | |
| 280 | + | cthreads, | |
| 281 | + | {$ENDIF}{$ENDIF} | |
| 282 | + | Interfaces, // this includes the LCL widgetset | |
| 283 | + | Forms, unitFinlandFlagDays, uFinlandFlagDays | |
| 284 | + | { you can add units after this }; | |
| 285 | + | ||
| 286 | + | {$R *.res} | |
| 287 | + | ||
| 288 | + | begin | |
| 289 | + | RequireDerivedFormResource:=True; | |
| 290 | + | Application.Initialize; | |
| 291 | + | Application.CreateForm(TForm1, Form1); | |
| 292 | + | Application.Run; | |
| 293 | + | end. | |
| 294 | + | ``` | |
| 295 | + | ||
| 296 | + | --- | |
| 297 | + | *From the Free Pascal wiki, page "CalLite: Flag days in Finland", as it stood on 2019-10-24 after a change by Djzepi, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).* |
