You've already forked lazarus-ccr
tvplanit: Add holiday support to MonthView. Add holiday and weekend attributes to Monthview.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@5198 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -57,7 +57,7 @@ object MainForm: TMainForm
|
||||
Height = 528
|
||||
Top = 48
|
||||
Width = 834
|
||||
PageIndex = 4
|
||||
PageIndex = 0
|
||||
Align = alClient
|
||||
TabOrder = 1
|
||||
TabStop = True
|
||||
@ -93,17 +93,22 @@ object MainForm: TMainForm
|
||||
HeadAttributes.Font.Height = -13
|
||||
HeadAttributes.Font.Style = [fsItalic]
|
||||
HeadAttributes.Color = clBtnFace
|
||||
HolidayAttributes.Font.Color = clBlack
|
||||
HolidayAttributes.Color = 8421631
|
||||
LineColor = clGray
|
||||
TimeFormat = tf12Hour
|
||||
TodayAttributes.Color = clSkyBlue
|
||||
TodayAttributes.Font.Color = clBlue
|
||||
TodayAttributes.Color = 16761024
|
||||
TodayAttributes.BorderPen.Color = clBlue
|
||||
TodayAttributes.BorderPen.Width = 3
|
||||
OffDayColor = clSilver
|
||||
OffDayColor = 15263976
|
||||
SelectedDayColor = clRed
|
||||
ShowEvents = True
|
||||
ShowEventTime = False
|
||||
WeekendAttributes.Font.Color = clBlack
|
||||
WeekendAttributes.Color = 12632319
|
||||
WeekStartsOn = dtSunday
|
||||
OnHoliday = VpHoliday
|
||||
end
|
||||
object Splitter2: TSplitter
|
||||
Cursor = crVSplit
|
||||
|
@ -116,6 +116,8 @@ type
|
||||
procedure RbHideCompletedTasksChange(Sender: TObject);
|
||||
procedure VpBufDSDataStore1PlaySound(Sender: TObject;
|
||||
const AWavFile: String; AMode: TVpPlaySoundMode);
|
||||
procedure VpHoliday(Sender: TObject; ADate: TDateTime;
|
||||
var AHolidayName: String);
|
||||
procedure VpNavBar1ItemClick(Sender: TObject; Button: TMouseButton;
|
||||
Shift: TShiftState; Index: Integer);
|
||||
|
||||
@ -306,6 +308,39 @@ begin
|
||||
Result := dtSunday;
|
||||
end;
|
||||
|
||||
function Easter(AYear: integer): TDateTime;
|
||||
// Calculates the date of the Easter holiday
|
||||
var
|
||||
day, month: integer;
|
||||
a,b,c,d,e,m,n: integer;
|
||||
begin
|
||||
result := 0;
|
||||
case AYear div 100 of
|
||||
17 : begin m := 23; n := 3; end;
|
||||
18 : begin m := 23; n := 4; end;
|
||||
19,20 : begin m := 24; n := 5; end;
|
||||
21 : begin m := 24; n := 6; end;
|
||||
else
|
||||
raise Exception.Create('Easter date can only be calculated for years between 1700 and 2199');
|
||||
end;
|
||||
a := AYear mod 19;
|
||||
b := AYear mod 4;
|
||||
c := AYear mod 7;
|
||||
d := (19*a + m) mod 30;
|
||||
e := (2*b + 4*c + 6*d + n) mod 7;
|
||||
day := 22 + d + e;
|
||||
month := 3;
|
||||
if day > 31 then begin
|
||||
day := d + e - 9;
|
||||
month := 4;
|
||||
if (d = 28) and (e = 6) and (a > 10) then begin
|
||||
if day = 26 then day := 19;
|
||||
if day = 25 then day := 18;
|
||||
end;
|
||||
end;
|
||||
result := EncodeDate(AYear, month, day);
|
||||
end;
|
||||
|
||||
|
||||
{ TMainForm }
|
||||
|
||||
@ -1101,6 +1136,40 @@ begin
|
||||
sound.PlaySound(AWavFile, AMode);
|
||||
end;
|
||||
|
||||
procedure TMainForm.VpHoliday(Sender: TObject; ADate: TDateTime;
|
||||
var AHolidayName: String);
|
||||
var
|
||||
d,m,y: Word;
|
||||
tmp: Word;
|
||||
easterDate: TDate;
|
||||
begin
|
||||
DecodeDate(ADate, y,m,d);
|
||||
if (d=1) and (m=1) then
|
||||
AHolidayName := 'New Year'
|
||||
else
|
||||
if (d = 25) and (m = 12) then
|
||||
AHolidayName := 'Christmas'
|
||||
else
|
||||
if m = 9 then begin
|
||||
tmp := 1;
|
||||
while DayOfWeek(EncodeDate(y, m, tmp)) <> 2 do inc(tmp);
|
||||
if tmp = d then
|
||||
AHolidayName := 'Labor Day (U.S.)'; // 1st Monday in September
|
||||
end
|
||||
else begin
|
||||
// Holidays depending on the date of Easter.
|
||||
easterDate := Easter(y);
|
||||
if ADate = easterDate - 2 then
|
||||
AHolidayName := 'Good Friday'
|
||||
else
|
||||
if ADate = easterDate then
|
||||
AHolidayName := 'Easter'
|
||||
else
|
||||
if ADate = easterDate + 49 then
|
||||
AHolidayName := 'Whitsunday'
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TMainForm.ShowContacts;
|
||||
begin
|
||||
Notebook.PageIndex := 2;
|
||||
|
@ -100,6 +100,9 @@ type
|
||||
TVpPlaySoundEvent = procedure(Sender: TObject; const AWavFile: String;
|
||||
AMode: TVpPlaySoundMode) of object;
|
||||
|
||||
TVpHolidayEvent = procedure(Sender: TObject; ADate: TDateTime;
|
||||
var AHolidayName: String) of object;
|
||||
|
||||
{ XML exceptions }
|
||||
EXML = class(Exception);
|
||||
|
||||
|
@ -94,6 +94,10 @@ const
|
||||
strTRUE = 'true';
|
||||
strFALSE = 'false';
|
||||
|
||||
WEEKEND_COLOR = $C0C0FF;
|
||||
HOLIDAY_COLOR = $8080FF;
|
||||
TODAY_COLOR = $FFC0C0;
|
||||
OFF_COLOR = $C0C0C0;
|
||||
|
||||
{virtual key constants not already defined}
|
||||
VK_NONE = 0;
|
||||
|
@ -58,6 +58,23 @@ type
|
||||
|
||||
TVpOnEventClick = procedure(Sender: TObject; Event: TVpEvent) of object;
|
||||
|
||||
TVpMonthViewAttr = class(TPersistent)
|
||||
private
|
||||
FMonthView: TVpMonthView;
|
||||
FColor: TColor;
|
||||
FFont: TVpFont;
|
||||
procedure SetColor(AValue: TColor);
|
||||
procedure SetFont(AValue: TVpFont);
|
||||
public
|
||||
constructor Create(AOwner: TVpMonthView);
|
||||
destructor Destroy; override;
|
||||
property MonthView: TVpMonthView read FMonthVIew;
|
||||
published
|
||||
property Font: TVpFont read FFont write SetFont;
|
||||
property Color: TColor read FColor write SetColor;
|
||||
end;
|
||||
|
||||
(*
|
||||
TVpMvHeadAttr = class(TPersistent)
|
||||
protected{ private }
|
||||
FOwner: TVpMonthView;
|
||||
@ -89,16 +106,25 @@ type
|
||||
property Color: TColor read FColor write SetColor;
|
||||
property Font: TVpFont read FFont write SetFont;
|
||||
end;
|
||||
|
||||
TVpMvTodayAttr = class(TPersistent)
|
||||
*)
|
||||
TVpMvTodayAttr = class(TVpMonthViewAttr)
|
||||
protected
|
||||
FBorderPen: TPen;
|
||||
procedure SetBorderPen(Value: TPen);
|
||||
public
|
||||
constructor Create(AOwner: TVpMonthView);
|
||||
destructor Destroy; override;
|
||||
published
|
||||
property BorderPen: TPen read FBorderPen write SetBorderPen;
|
||||
end;
|
||||
(*
|
||||
TVpMvHolidayAttr = class(TPersistent)
|
||||
protected
|
||||
FMonthView: TVpMonthView;
|
||||
FFont: TVpFont;
|
||||
FColor: TColor;
|
||||
FBorderPen: TPen;
|
||||
procedure SetColor(Value: TColor);
|
||||
procedure SetFont(Value: TVpFont);
|
||||
procedure SetBorderPen(Value: TPen);
|
||||
public
|
||||
constructor Create(AOwner: TVpMonthView);
|
||||
destructor Destroy; override;
|
||||
@ -106,8 +132,8 @@ type
|
||||
published
|
||||
property Color: TColor read FColor write SetColor;
|
||||
property Font: TVpFont read FFont write FFont;
|
||||
property BorderPen: TPen read FBorderPen write SetBorderPen;
|
||||
end;
|
||||
*)
|
||||
|
||||
{ TVpMonthView }
|
||||
|
||||
@ -131,9 +157,17 @@ type
|
||||
FDateLabelFormat: string;
|
||||
FShowEventTime: Boolean;
|
||||
FTopLine: Integer;
|
||||
FDayHeadAttr: TVpMonthViewAttr;
|
||||
FHeadAttr: TVpMonthViewAttr;
|
||||
FHolidayAttr: TVpMonthViewAttr;
|
||||
FTodayAttr: TVpMvTodayAttr;
|
||||
FWeekendAttr: TVpMonthViewAttr;
|
||||
{
|
||||
FDayHeadAttr: TVpDayHeadAttr;
|
||||
FHeadAttr: TVpMvHeadAttr;
|
||||
FTodayAttr: TVpMvTodayAttr;
|
||||
FHolidayAttr: TVpMvHolidayAttr;
|
||||
FTodayAttr: TVpMvTodayAttr; }
|
||||
|
||||
FDayNumberFont: TVpFont;
|
||||
FEventFont: TVpFont;
|
||||
FTimeFormat: TVpTimeFormat;
|
||||
@ -148,6 +182,7 @@ type
|
||||
FOwnerDrawCells: TVpOwnerDrawDayEvent;
|
||||
FOnEventClick: TVpOnEventClick;
|
||||
FOnEventDblClick: TVpOnEventClick;
|
||||
FOnHoliday: TVpHolidayEvent;
|
||||
|
||||
{ internal variables }
|
||||
mvLoaded: Boolean;
|
||||
@ -178,42 +213,35 @@ type
|
||||
procedure SetWeekStartsOn(Value: TVpDayType);
|
||||
|
||||
{ internal methods }
|
||||
procedure mvHookUp;
|
||||
procedure mvPenChanged(Sender: TObject);
|
||||
// procedure mvFontChanged(Sender: TObject);
|
||||
|
||||
procedure Paint; override;
|
||||
procedure Loaded; override;
|
||||
procedure InitializeDefaultPopup;
|
||||
function GetDateAtCoord(APoint: TPoint): TDateTime;
|
||||
procedure mvPopulate;
|
||||
procedure mvSpinButtonClick(Sender: TObject; Button: TUDBtnType);
|
||||
procedure mvSetDateByCoord(APoint: TPoint);
|
||||
procedure mvHookUp;
|
||||
procedure mvPenChanged(Sender: TObject);
|
||||
function SelectEventAtCoord(Point: TPoint): Boolean;
|
||||
|
||||
procedure CreateParams(var Params: TCreateParams); override;
|
||||
procedure CreateWnd; override;
|
||||
{$IFNDEF LCL}
|
||||
procedure WMLButtonDown(var Msg: TWMLButtonDown); message WM_LBUTTONDOWN;
|
||||
procedure WMLButtonDblClick(var Msg: TWMLButtonDblClk);message WM_LBUTTONDBLCLK;
|
||||
{$ELSE}
|
||||
procedure WMLButtonDown(var Msg: TLMLButtonDown); message LM_LBUTTONDOWN;
|
||||
procedure WMLButtonDblClick(var Msg: TLMLButtonDblClk); message LM_LBUTTONDBLCLK;
|
||||
{$ENDIF}
|
||||
|
||||
{ - renamed from EditEventAtCoord and re-written}
|
||||
function SelectEventAtCoord(Point: TPoint): Boolean;
|
||||
procedure mvSetDateByCoord(APoint: TPoint);
|
||||
function GetDateAtCoord(APoint: TPoint): TDateTime;
|
||||
procedure Loaded; override;
|
||||
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
|
||||
procedure MouseMove(Shift: TShiftState; X,Y: Integer); override;
|
||||
procedure MouseEnter; override;
|
||||
procedure MouseLeave; override;
|
||||
procedure Paint; override;
|
||||
|
||||
{ message handlers }
|
||||
{$IFNDEF LCL}
|
||||
procedure WMLButtonDown(var Msg: TWMLButtonDown); message WM_LBUTTONDOWN;
|
||||
procedure WMLButtonDblClick(var Msg: TWMLButtonDblClk);message WM_LBUTTONDBLCLK;
|
||||
procedure WMSize(var Msg: TWMSize); message WM_SIZE;
|
||||
procedure WMSetFocus(var Msg: TWMSetFocus); message WM_SETFOCUS;
|
||||
procedure WMRButtonDown(var Msg: TWMRButtonDown); message WM_RBUTTONDOWN;
|
||||
procedure CMWantSpecialKey(var Msg: TCMWantSpecialKey);
|
||||
message CM_WANTSPECIALKEY;
|
||||
{$ELSE}
|
||||
procedure WMLButtonDown(var Msg: TLMLButtonDown); message LM_LBUTTONDOWN;
|
||||
procedure WMLButtonDblClick(var Msg: TLMLButtonDblClk); message LM_LBUTTONDBLCLK;
|
||||
procedure WMSize(var Msg: TLMSize); message LM_SIZE;
|
||||
procedure WMSetFocus(var Msg: TLMSetFocus); message LM_SETFOCUS;
|
||||
procedure WMRButtonDown(var Msg: TLMRButtonDown); message LM_RBUTTONDOWN;
|
||||
@ -224,6 +252,7 @@ type
|
||||
procedure HideHintWindow;
|
||||
|
||||
{ Popup menu }
|
||||
procedure InitializeDefaultPopup;
|
||||
procedure PopupToday(Sender: TObject);
|
||||
procedure PopupNextMonth(Sender: TObject);
|
||||
procedure PopupPrevMonth(Sender: TObject);
|
||||
@ -237,6 +266,7 @@ type
|
||||
AShowEventTime, AStartTimeOnly: Boolean): String;
|
||||
procedure LoadLanguage;
|
||||
procedure Invalidate; override;
|
||||
function IsHoliday(ADate: TDate; out AHolidayName: String): Boolean;
|
||||
procedure LinkHandler(Sender: TComponent;
|
||||
NotificationType: TVpNotificationType; const Value: Variant); override;
|
||||
function GetControlType: TVpItemType; override;
|
||||
@ -258,13 +288,17 @@ type
|
||||
property KBNavigation: Boolean read FKBNavigate write FKBNavigate;
|
||||
property Color: TColor read FColor write SetColor;
|
||||
property DateLabelFormat: string read FDateLabelFormat write SetDateLabelFormat;
|
||||
property DayHeadAttributes: TVpDayHeadAttr read FDayHeadAttr write FDayHeadAttr;
|
||||
property DayHeadAttributes: TVpMonthviewAttr read FDayHeadAttr write FDayHeadAttr;
|
||||
// property DayHeadAttributes: TVpDayHeadAttr read FDayHeadAttr write FDayHeadAttr;
|
||||
property DayNameStyle: TVpMVDayNameStyle read FDayNameStyle write SetDayNameStyle;
|
||||
property DayNumberFont: TVpFont read FDayNumberFont write SetDayNumberFont;
|
||||
property DrawingStyle: TVpDrawingStyle read FDrawingStyle write SetDrawingStyle stored True;
|
||||
property EventDayStyle: TFontStyles read FEventDayStyle write SetEventDayStyle;
|
||||
property EventFont: TVpFont read FEventFont write SetEventFont;
|
||||
property HeadAttributes: TVpMvHeadAttr read FHeadAttr write FHeadAttr;
|
||||
// property HeadAttributes: TVpMvHeadAttr read FHeadAttr write FHeadAttr;
|
||||
property HeadAttributes: TVpMonthViewAttr read FHeadAttr write FHeadAttr;
|
||||
property HolidayAttributes: TVpMonthViewAttr read FHolidayAttr write FHolidayAttr;
|
||||
// property HolidayAttributes: TVpMvHolidayAttr read FHolidayAttr write FHolidayAttr;
|
||||
property HintMode: TVpHintMode read FHintMode write FHintMode default hmPlannerHint;
|
||||
property LineColor: TColor read FLineColor write SetLineColor;
|
||||
property TimeFormat: TVpTimeFormat read FTimeFormat write SetTimeFormat;
|
||||
@ -277,10 +311,12 @@ type
|
||||
property SelectedDayColor: TColor read FSelectedDayColor write SetSelectedDayColor;
|
||||
property ShowEvents: Boolean read FShowEvents write SetShowEvents;
|
||||
property ShowEventTime: Boolean read FShowEventTime write SetShowEventTime;
|
||||
property WeekendAttributes: TVpMonthViewAttr read FWeekendAttr write FWeekendAttr;
|
||||
property WeekStartsOn: TVpDayType read FWeekStartsOn write SetWeekStartsOn;
|
||||
{events}
|
||||
property OnEventClick: TVpOnEventClick read FOnEventClick write FOnEventClick;
|
||||
property OnEventDblClick: TVpOnEventClick read FOnEventDblClick write FOnEventDblClick;
|
||||
property OnHoliday: TVpHolidayEvent read FOnHoliday write FOnHoliday;
|
||||
end;
|
||||
|
||||
|
||||
@ -293,85 +329,43 @@ uses
|
||||
SysUtils, LazUTF8, Dialogs, StrUtils,
|
||||
VpMonthViewPainter;
|
||||
|
||||
|
||||
(*****************************************************************************)
|
||||
{ TVpMvHeadAttr }
|
||||
|
||||
constructor TVpMvHeadAttr.Create(AOwner: TVpMonthView);
|
||||
{ TVpMonthViewAttr }
|
||||
(*****************************************************************************)
|
||||
constructor TVpMonthViewAttr.Create(AOwner: TVpMonthView);
|
||||
begin
|
||||
inherited Create;
|
||||
FOwner := AOwner;
|
||||
FMonthView := AOwner;
|
||||
FColor := clBtnFace;
|
||||
FFont := TVpFont.Create(AOwner);
|
||||
end;
|
||||
|
||||
destructor TVpMvHeadAttr.Destroy;
|
||||
destructor TVpMonthViewAttr.Destroy;
|
||||
begin
|
||||
FFont.Free;
|
||||
inherited;
|
||||
end;
|
||||
|
||||
procedure TVpMvHeadAttr.SetColor(const Value: TColor);
|
||||
procedure TVpMonthViewAttr.SetColor(AValue: TColor);
|
||||
begin
|
||||
if FColor <> Value then begin
|
||||
FColor := Value;
|
||||
FOwner.Invalidate;
|
||||
if FColor <> AValue then begin
|
||||
FColor := AValue;
|
||||
FMonthView.Invalidate;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TVpMvHeadAttr.SetFont(Value: TVpFont);
|
||||
procedure TVpMonthViewAttr.SetFont(AValue: TVpFont);
|
||||
begin
|
||||
FFont.Assign(Value);
|
||||
FFont.Assign(AValue);
|
||||
end;
|
||||
|
||||
|
||||
(*****************************************************************************)
|
||||
{ TVpContactHeadAttr }
|
||||
constructor TVpDayHeadAttr.Create(AOwner: TVpMonthView);
|
||||
begin
|
||||
inherited Create;
|
||||
FMonthView := AOwner;
|
||||
FFont := TVpFont.Create(AOwner);
|
||||
FFont.Assign(FMonthView.Font);
|
||||
FColor := clSilver;
|
||||
end;
|
||||
{=====}
|
||||
|
||||
destructor TVpDayHeadAttr.Destroy;
|
||||
begin
|
||||
FFont.Free;
|
||||
inherited;
|
||||
end;
|
||||
{=====}
|
||||
|
||||
procedure TVpDayHeadAttr.SetColor(Value: TColor);
|
||||
begin
|
||||
if Value <> FColor then begin
|
||||
FColor := Value;
|
||||
MonthView.Invalidate;
|
||||
end;
|
||||
end;
|
||||
{=====}
|
||||
|
||||
procedure TVpDayHeadAttr.SetFont(Value: TVpFont);
|
||||
begin
|
||||
if Value <> FFont then begin
|
||||
FFont.Assign(Value);
|
||||
MonthView.Invalidate;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
{ TVpMvTodayAttr }
|
||||
(*****************************************************************************)
|
||||
{ TVpMvTodayAttr }
|
||||
|
||||
constructor TVpMvTodayAttr.Create(AOwner: TVpMonthView);
|
||||
begin
|
||||
inherited Create;
|
||||
FMonthView := AOwner;
|
||||
FFont := TVpFont.Create(AOwner);
|
||||
FFont.Assign(FMonthView.Font);
|
||||
FColor := clSilver;
|
||||
inherited Create(AOwner);
|
||||
FBorderPen := TPen.Create;
|
||||
FBorderPen.Color := clRed;
|
||||
FBorderPen.Width := 3;
|
||||
@ -381,26 +375,9 @@ end;
|
||||
destructor TVpMvTodayAttr.Destroy;
|
||||
begin
|
||||
FBorderPen.Free;
|
||||
FFont.Free;
|
||||
inherited;
|
||||
end;
|
||||
|
||||
procedure TVpMvTodayAttr.SetColor(Value: TColor);
|
||||
begin
|
||||
if Value <> FColor then begin
|
||||
FColor := Value;
|
||||
MonthView.Invalidate;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TVpMvTodayAttr.SetFont(Value: TVpFont);
|
||||
begin
|
||||
if Value <> FFont then begin
|
||||
FFont.Assign(Value);
|
||||
MonthView.Invalidate;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TVpMvTodayAttr.SetBorderPen(Value: TPen);
|
||||
begin
|
||||
if Value <> FBorderPen then begin
|
||||
@ -411,20 +388,27 @@ end;
|
||||
|
||||
|
||||
(*****************************************************************************)
|
||||
{ TVpMonthView }
|
||||
|
||||
{ TVpMonthView }
|
||||
(*****************************************************************************)
|
||||
constructor TVpMonthView.Create(AOwner: TComponent);
|
||||
begin
|
||||
inherited;
|
||||
ControlStyle := [csCaptureMouse, csOpaque, csDoubleClicks];
|
||||
|
||||
{ Create internal classes and stuff }
|
||||
FHeadAttr := TVpMonthViewAttr.Create(self);
|
||||
FDayHeadAttr := TVpMonthViewAttr.Create(self);
|
||||
FHolidayAttr := TVpMonthViewAttr.Create(self);
|
||||
FWeekendAttr := TVpMonthviewAttr.Create(self);
|
||||
FTodayAttr := TVpMvTodayAttr.Create(Self);
|
||||
mvSpinButtons := TUpDown.Create(self);
|
||||
{
|
||||
FHeadAttr := TVpMvHeadAttr.Create(self);
|
||||
FDayHeadAttr := TVpDayHeadAttr.Create(self);
|
||||
FTodayAttr := TVpMvTodayAttr.Create(self);
|
||||
// mvEventList := TList.Create;
|
||||
FHolidayAttr := TvpMvHolidayAttr.Create(self);
|
||||
mvSpinButtons := TUpDown.Create(self);
|
||||
|
||||
}
|
||||
{ Set styles and initialize internal variables }
|
||||
{$IFDEF VERSION4}
|
||||
DoubleBuffered := true;
|
||||
@ -462,9 +446,19 @@ begin
|
||||
{ Assign default font to DayNumberFont and EventFont }
|
||||
FDayNumberFont := TVpFont.Create(AOwner);
|
||||
FDayNumberFont.Assign(Font);
|
||||
|
||||
FEventFont := TVpFont.Create(AOwner);
|
||||
FEventFont.Assign(Font);
|
||||
|
||||
FOffDayFontColor := clGray;
|
||||
FOffDayColor := OFF_COLOR;
|
||||
|
||||
FHolidayAttr.Font.Assign(FDayNumberFont);
|
||||
FHolidayAttr.Font.Color := clBlack;
|
||||
FHolidayAttr.Color := HOLIDAY_COLOR;
|
||||
|
||||
FWeekendAttr.Font.Assign(FHolidayAttr.Font);
|
||||
FWeekendAttr.Color := WEEKEND_COLOR;
|
||||
|
||||
SetLength(mvEventArray, MaxVisibleEvents);
|
||||
SetLength(mvMonthdayArray, 45);
|
||||
@ -485,12 +479,14 @@ destructor TVpMonthView.Destroy;
|
||||
begin
|
||||
FreeAndNil(FHintWindow);
|
||||
FHeadAttr.Free;
|
||||
FHolidayAttr.Free;
|
||||
FTodayAttr.Free;
|
||||
FDayHeadAttr.Free;
|
||||
FWeekendAttr.Free;
|
||||
FDayNumberFont.Free;
|
||||
FEventFont.Free;
|
||||
mvSpinButtons.Free;
|
||||
FDefaultPopup.Free;
|
||||
// mvSpinButtons.Free;
|
||||
// FDefaultPopup.Free;
|
||||
inherited;
|
||||
end;
|
||||
|
||||
@ -553,7 +549,14 @@ procedure TVpMonthView.Invalidate;
|
||||
begin
|
||||
inherited;
|
||||
end;
|
||||
{=====}
|
||||
|
||||
function TVpMonthView.IsHoliday(ADate: TDate; out AHolidayName: String): Boolean;
|
||||
begin
|
||||
AHolidayName := '';
|
||||
if Assigned(FOnHoliday) then
|
||||
FOnHoliday(Self, ADate, AHolidayName);
|
||||
Result := AHolidayName <> '';
|
||||
end;
|
||||
|
||||
procedure TVpMonthView.LinkHandler(Sender: TComponent;
|
||||
NotificationType: TVpNotificationType; const Value: Variant);
|
||||
@ -925,6 +928,8 @@ var
|
||||
event: TVpEvent;
|
||||
list: TList;
|
||||
R: TRect;
|
||||
holiday: String = '';
|
||||
todayDate: TDate;
|
||||
begin
|
||||
if FHintMode = hmPlannerHint then
|
||||
begin
|
||||
@ -934,26 +939,40 @@ begin
|
||||
exit;
|
||||
end;
|
||||
|
||||
// If the date is a holiday we put the holidayname at the top
|
||||
IsHoliday(ADate, holiday);
|
||||
|
||||
// Collect all events of this day and add them separated by line feeds to
|
||||
// the hint string (txt).
|
||||
txt := '';
|
||||
list := TList.Create;
|
||||
txt := '';
|
||||
try
|
||||
Datastore.Resource.Schedule.EventsByDate(ADate, List);
|
||||
for i:=0 to list.Count-1 do begin
|
||||
event := TVpEvent(list[i]);
|
||||
s := BuildEventString(event, true, false);
|
||||
txt := IfThen(txt = '', s, txt + LineEnding + s);
|
||||
txt := IfThen(txt = '', s, txt + LineEnding + s);
|
||||
end;
|
||||
finally
|
||||
list.Free;
|
||||
end;
|
||||
|
||||
// If we have any events then we put the current date at the top.
|
||||
if txt <> '' then begin
|
||||
txt := FormatDateTime('dddddd', ADate) + LineEnding + LineEnding + txt;
|
||||
if ADate = SysUtils.Date then
|
||||
txt := RSToday + LineEnding + txt;
|
||||
todayDate := SysUtils.Date();
|
||||
if (txt = '') and (holiday = '') and (ADate = todayDate) then
|
||||
txt := RSToday + LineEnding + FormatDateTime('ddddd', ADate)
|
||||
else
|
||||
if (txt <> '') or (holiday <> '') then begin
|
||||
if (txt = '') and (holiday <> '') then
|
||||
txt := FormatDateTime('ddddd', ADate) + LineEnding + holiday
|
||||
else begin
|
||||
txt := LineEnding + txt;
|
||||
if holiday <> '' then
|
||||
txt := holiday + LineEnding + txt;
|
||||
txt := FormatDateTime('ddddd', ADate) + LineEnding + txt;
|
||||
if ADate = todayDate then
|
||||
txt := RSToday + LineEnding + txt;
|
||||
end;
|
||||
end;
|
||||
|
||||
if (txt <> '') and not (csDesigning in ComponentState) then
|
||||
|
@ -30,6 +30,7 @@ type
|
||||
TodayFontColor: TColor;
|
||||
TodayAttrColor: TColor;
|
||||
DotDotDotColor: TColor;
|
||||
FCurrHoliday: String;
|
||||
|
||||
// protected variables of the original monthview needed only for painting
|
||||
mvEventTextHeight: Integer;
|
||||
@ -41,7 +42,7 @@ type
|
||||
protected
|
||||
procedure Clear;
|
||||
procedure DrawBorders;
|
||||
procedure DrawDayCell(ADate: TDate; ACol: Integer;
|
||||
procedure DrawDayCell(ADate: TDate; ACol, ARow: Integer;
|
||||
var AIndex, ADayNumber: Integer; var ATextRect: TRect);
|
||||
procedure DrawDayHead;
|
||||
procedure DrawDays;
|
||||
@ -113,7 +114,7 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TVpMonthViewPainter.DrawDayCell(ADate: TDate; ACol: Integer;
|
||||
procedure TVpMonthViewPainter.DrawDayCell(ADate: TDate; ACol, ARow: Integer;
|
||||
var AIndex, ADayNumber: Integer; var ATextRect: TRect);
|
||||
var
|
||||
tmpRect: TRect;
|
||||
@ -134,10 +135,18 @@ begin
|
||||
tmpRect.Bottom := RealBottom;
|
||||
end else
|
||||
tmpRect := ATextRect;
|
||||
if ARow = 0 then
|
||||
inc(tmpRect.Top);
|
||||
|
||||
if DisplayMonth <> M then begin
|
||||
if FCurrHoliday <> '' then begin
|
||||
RenderCanvas.Brush.Color := FMonthView.HolidayAttributes.Color;
|
||||
TPSFillRect(RenderCanvas, Angle, RenderIn, tmpRect);
|
||||
end else if DisplayMonth <> M then begin
|
||||
RenderCanvas.Brush.Color := RealOffDayColor;
|
||||
TPSFillRect(RenderCanvas, Angle, RenderIn, tmpRect);
|
||||
end else if DayOfWeek(ADate) in [1, 7] then begin
|
||||
RenderCanvas.Brush.Color := FMonthView.WeekendAttributes.Color;
|
||||
TPSFillRect(RenderCanvas, Angle, RenderIn, tmpRect);
|
||||
end else
|
||||
RenderCanvas.Brush.Color := RealColor;
|
||||
|
||||
@ -157,10 +166,10 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
{ Paint the day number }
|
||||
{ Prepare the day number as string}
|
||||
Str := FormatDateTime('d', ADate);
|
||||
|
||||
{ set the proper font and style }
|
||||
{ Set the proper font and style }
|
||||
if ADate = todayDate then
|
||||
RenderCanvas.Font.Assign(FMonthView.TodayAttributes.Font)
|
||||
else
|
||||
@ -204,6 +213,8 @@ begin
|
||||
RenderCanvas.Font.Style := FontStyle;
|
||||
if DisplayMonth <> M then
|
||||
RenderCanvas.Font.Color := FMonthView.OffDayFontColor;
|
||||
if FCurrHoliday <> '' then
|
||||
RenderCanvas.Font.Assign(FMonthView.HolidayAttributes.Font);
|
||||
|
||||
{ Calculate size of rect for the day number at the top of the TextRect. }
|
||||
if ACol = 6 then
|
||||
@ -433,6 +444,9 @@ begin
|
||||
for Col := 0 to 6 do begin
|
||||
ThisDate := Trunc(StartingDate + DayNumber);
|
||||
|
||||
{ Check and store if the this date is a holiday }
|
||||
FMonthView.IsHoliday(ThisDate, FCurrHoliday);
|
||||
|
||||
OldBrush.Assign(RenderCanvas.Brush);
|
||||
OldPen.Assign(RenderCanvas.Pen);
|
||||
OldFont.Assign(RenderCanvas.Font);
|
||||
@ -445,7 +459,7 @@ begin
|
||||
if Drawn then
|
||||
Continue;
|
||||
end else
|
||||
DrawDayCell(ThisDate, Col, I, DayNumber, TextRect);
|
||||
DrawDayCell(ThisDate, Col, Row, I, DayNumber, TextRect);
|
||||
finally
|
||||
RenderCanvas.Brush.Assign(OldBrush);
|
||||
RenderCanvas.Pen.Assign(OldPen);
|
||||
|
Reference in New Issue
Block a user