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