358: 359: 360: 361: 362: 363: 364: 365: 366: 367: 368: 369: 370: 371: 372: 373: 374: 375: 376: 377: 378: 379: 380: 381: 382: 383: 384: 385: 386: 387: 388: 389: 390: 391: 392: 393: 394: 395: 396: 397: 398: 399: 400: 401: 402: 403: 404: 405: 406: 407: 408: 409: 410: 411: 412: 413: 414: 415: 416: 417: 418: 419: 420: 421: 422: 423: 424: 425: 426: 427: 428: 429: 430: 431: 432: 433: 434: 435: 436: 437: 438: 439: 440: 441: 442: 443: 444: 445: 446: 447: 448: 449: 450: 451: 452: 453: 454: 455: 456: 457: 458: 459: 460: 461: 462: 463: 464: 465: 466: 467: 468: 469: 470: 471: 472: 473: 474: 475: 476: 477: 478: 479: 480: 481: 482: 483: 484: 485: 486: 487: 488: 489: 490: 491: 492: 493: 494: 495: 496: 497: 498: 499: 500: 501: 502: 503: 504: 505: 506: 507: 508: 509: 510: 511: 512: 513: 514: 515: 516: 517: 518: 519: 520: 521: 522: 523: 524: 525: 526: 527: 528: 529: 530: 531: 532: 533: 534: 535: 536: 537: 538: 539: 540: 541: 542: 543: 544: 545: 546: 547: 548: 549: 550: 551: 552: 553: 554: 555: 556: 557: 558: 559: 560: 561: 562: 563: 564: 565: 566: 567: 568: 569: 570: 571: 572: 573: 574: 575: 576: 577: 578: 579: 580: 581: 582: 583: 584: 585: 586: 587: 588: 589: 590: 591:
| { ... } {$IFDEF WINCONTROL}
Procedure TDSCalendar.Repaint; {$ELSE}
Procedure TDSCalendar.Paint; {$ENDIF} Var D, M, Y: Word; FirstDay: Word; CurrentDay: Word; I, J: Integer; W: Integer; MonthOver: Boolean; MonthNotStarted: Boolean; WeekNr: Word; Canv: TCanvas; MaxDay: Integer; CanvasHandle, DoubleBufferCanvas: THandle; Procedure DrawColumnItem(Column, Row: Integer; Number: Integer; AlternativeText: String = ''; DontAddToCoords: Boolean = False); Var Text: String; OldNumber: Integer; _x, _y: Integer; NewAbsoluteDate: TDateTime; Begin OldNumber := Number; If AlternativeText = '' Then Begin If (MonthOver) And Not (Column = 0) Then Dec(Number, DaysInAMonth(Y, M)); If (MonthNotStarted) And Not (Column = 0) Then Begin If M = 1 Then Begin Inc(Number, DaysInAMonth(Y - 1, 12) - (FirstDay - 1)); NewAbsoluteDate := EncodeDate(Y - 1, 12, Number); End Else Begin Inc(Number, DaysInAMonth(Y, M - 1) - (FirstDay - 1)); NewAbsoluteDate := EncodeDate(Y, M - 1, Number); End; End; Text := IntToStr(Number) End Else Text := AlternativeText; With Canv Do Begin _x := BorderWidth + Trunc((Column + 1) * (W / 8)) - Trunc((W / 8) / 2) - TextWidth(Text) Div 2; _y := BorderWidth + FTitleFont.Size + FHeadlineOffset + FRowHeight * Row; If (((CurrentDay >= SelStartDay) And (CurrentDay <= SelEndDay)) Or ((CurrentDay = D) And (FHighlightDate))) And ((Column <> 0) And (Row <> 0)) Then Brush.Color := FSelectionBackgroundColor Else Brush.Color := FBackgroundColor; If ((MonthOver) Or (MonthNotStarted)) And Not (Column = 0) Then Font.Color := FOutOfMonthColor; TextOut(_x, _y, Text); End; If (AlternativeText = '') And Not (DontAddToCoords) Then Begin SetLength(FDayCoords, Length(FDayCoords) + 1); With FDayCoords[High(FDayCoords)] Do Begin Day := Number; If Not MonthNotStarted Then NewAbsoluteDate := StartOfTheMonth(FDate) + OldNumber - 1; Date := NewAbsoluteDate; Coords.Left := _x; Coords.Top := _y; Coords.Right := _x + Canv.TextWidth(Text); Coords.Bottom := _y + Canv.TextHeight(Text); End; End; End;
Begin If FUseDoubleBuffer Then Begin If DoubleBuffer = Nil Then Exit; DoubleBuffer.Width := Width; DoubleBuffer.Height := Height; End; If (FUseDoubleBuffer) And (DoubleBuffer <> Nil) Then Canv := DoubleBuffer.Canvas Else Begin {$IFDEF WINCONTROL} Canv := FCanvas; {$ELSE} Canv := Canvas; {$ENDIF} End; With Canv Do Begin MonthNotStarted := False; MonthOver := False; Brush.Color := FBackgroundColor; Pen.Color := FBorderColor; Rectangle(0, 0, Width, Height); W := Width - 2 * BorderWidth; Brush.Style := bsClear; Font := FFont; DecodeDate(FDate, Y, M, D); Font := FTitleFont; TextOut(Width Div 2 - TextWidth(LongMonthNames[M] + ' ' + FloatToStr(Y)) Div 2, BorderWidth, LongMonthNames[M] + ' ' + FloatToStr(Y)); Font := FFont; Font.Style := FHeadlineStyle; For I := 0 To 7 Do Begin Case I Of 0: Begin Font.Color := FWeekColor; DrawColumnItem(I, 0, 0, 'W'); Continue; End; 7: Begin Font.Color := FSundayColor; DrawColumnItem(I, 0, 0, ShortDayNames[1]); End; Else Begin Font.Color := FFont.Color; DrawColumnItem(I, 0, 0, ShortDayNames[I + 1]); End; End; End; Font := FFont; FirstDay := DayOfTheWeek(EncodeDate(Y, M, 1)); CurrentDay := 0; J := 0; Brush.Color := FBackgroundColor; Brush.Style := bsSolid; MaxDay := DaysInAMonth(Y, M); If FForceSixthWeekDraw Then Inc(MaxDay, 7); While (CurrentDay < MaxDay) And (J <= 5) Do Begin Inc(J); Font := FFont; Font.Color := FWeekColor; Brush.Color := FBackgroundColor; WeekNr := WeekOfTheYear(StartOfTheMonth(EncodeDate(Y, M, D)) + CurrentDay + 1); DrawColumnItem(0, J, WeekNr, '', True); If J <> 1 Then FirstDay := 1; MonthNotStarted := True; For I := 1 To FirstDay - 1 Do DrawColumnItem(I, J, I); MonthNotStarted := False; For I := FirstDay To 7 Do Begin Inc(CurrentDay); Font := FFont; If Not FIgnoreHolidays Then If CurrentDay In FFixedHolidays[M] Then Font.Color := FHolidayColor; If CurrentDay > DaysInAMonth(Y, M) Then MonthOver := True; If (CurrentDay = D) And FDayBold And Not (MonthOver) Then Font.Style := Font.Style + [fsBold]; If I = 7 Then Begin If Not MonthOver Then Font.Color := FSundayColor; End; DrawColumnItem(I, J, CurrentDay) End; End; End; If (FUseDoubleBuffer) And (DoubleBuffer <> Nil) Then Begin CanvasHandle := GetDC(Handle); Try DoubleBufferCanvas := DoubleBuffer.Canvas.Handle; BitBlt(CanvasHandle, 0, 0, Width, Height, DoubleBufferCanvas, 0, 0, SRCCOPY); Finally ReleaseDC(Handle, CanvasHandle); End; End; End; |