From b864dfc278b417aaa2980a6130aae2fcbdce6fc9 Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Mon, 19 Sep 2022 21:32:43 +0000 Subject: [PATCH] tvplanit: Move holiday detection event to TVpControlLink; deprecate that of TVpDayView etc. git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8492 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- .../tvplanit/examples/fulldemo/demomain.lfm | 46 +++++++-------- components/tvplanit/source/vpbaseds.pas | 58 ++++++++++++------- components/tvplanit/source/vpclock.pas | 1 - components/tvplanit/source/vpdayview.pas | 8 ++- components/tvplanit/source/vpganttview.pas | 20 ++++--- components/tvplanit/source/vpmonthview.pas | 7 ++- components/tvplanit/source/vpprtprvdlg.lfm | 5 +- components/tvplanit/source/vpprtprvdlg.pas | 3 +- components/tvplanit/source/vpweekview.pas | 7 ++- 9 files changed, 90 insertions(+), 65 deletions(-) diff --git a/components/tvplanit/examples/fulldemo/demomain.lfm b/components/tvplanit/examples/fulldemo/demomain.lfm index e4ab099c6..352ff34c4 100644 --- a/components/tvplanit/examples/fulldemo/demomain.lfm +++ b/components/tvplanit/examples/fulldemo/demomain.lfm @@ -94,7 +94,6 @@ object MainForm: TMainForm TodayAttributes.BorderPen.Color = clBlue TodayAttributes.BorderPen.Width = 3 WeekendAttributes.Font.Color = clBlack - OnHoliday = VpHoliday end object Splitter2: TSplitter Cursor = crVSplit @@ -174,7 +173,6 @@ object MainForm: TMainForm } GutterWidth = 5 WrapStyle = wsNoFlow - OnHoliday = VpHoliday end object DaySelectorPanel: TPanel Left = 0 @@ -298,7 +296,6 @@ object MainForm: TMainForm WeekStartsOn = dtMonday Align = alClient TabOrder = 2 - OnHoliday = VpHoliday end end object Tasks: TPage @@ -713,41 +710,41 @@ object MainForm: TMainForm DrawingStyle = dsCoolTab FolderCollection = < item - Version = 'v1.12' + Version = 'v1.0.7' Caption = 'Planner' Enabled = True FolderType = ftDefault ItemCollection = < item - Version = 'v1.12' + Version = 'v1.0.7' Caption = 'Events' IconIndex = 0 Name = 'NIEvents' Tag = 0 end item - Version = 'v1.12' + Version = 'v1.0.7' Caption = 'Month view' IconIndex = 5 Name = 'NIEventsByMonth' Tag = 0 end item - Version = 'v1.12' + Version = 'v1.0.7' Caption = 'Week view' IconIndex = 4 Name = 'NIEventsByWeek' Tag = 0 end item - Version = 'v1.12' + Version = 'v1.0.7' Caption = 'Day view' IconIndex = 3 Name = 'NIEventsByDay' Tag = 0 end item - Version = 'v1.12' + Version = 'v1.0.7' Caption = 'Tasks' Description = 'Show tasks' IconIndex = 1 @@ -755,7 +752,7 @@ object MainForm: TMainForm Tag = 0 end item - Version = 'v1.12' + Version = 'v1.0.7' Caption = 'Contacts' Description = 'Show address book' IconIndex = 2 @@ -767,20 +764,20 @@ object MainForm: TMainForm Tag = 0 end item - Version = 'v1.12' + Version = 'v1.0.7' Caption = 'Maintenance' Enabled = True FolderType = ftDefault ItemCollection = < item - Version = 'v1.12' + Version = 'v1.0.7' Caption = 'Resources' IconIndex = 7 Name = 'NIResources' Tag = 0 end item - Version = 'v1.12' + Version = 'v1.0.7' Caption = 'Settings' IconIndex = 8 Name = 'NISettings' @@ -817,12 +814,12 @@ object MainForm: TMainForm Printer.MarginUnits = imPercent Printer.PrintFormats = < item - Version = 'v1.12' + Version = 'v1.0.7' DayInc = 0 DayIncUnits = duDay Elements = < item - Version = 'v1.12' + Version = 'v1.0.7' Caption.Caption = 'Current week' Caption.Font.Style = [fsItalic] DayOffset = 0 @@ -837,12 +834,12 @@ object MainForm: TMainForm FormatName = 'Events of current week (dayview)' end item - Version = 'v1.12' + Version = 'v1.0.7' DayInc = 0 DayIncUnits = duWeek Elements = < item - Version = 'v1.12' + Version = 'v1.0.7' DayOffset = 0 DayOffsetUnits = duDay ElementName = 'WeekView' @@ -856,12 +853,12 @@ object MainForm: TMainForm FormatName = 'Events of current week (Week view)' end item - Version = 'v1.12' + Version = 'v1.0.7' DayInc = 0 DayIncUnits = duDay Elements = < item - Version = 'v1.12' + Version = 'v1.0.7' DayOffset = 0 DayOffsetUnits = duWeek ElementName = 'TaskList' @@ -875,12 +872,12 @@ object MainForm: TMainForm FormatName = 'Tasks of current week' end item - Version = 'v1.12' + Version = 'v1.0.7' DayInc = 0 DayIncUnits = duDay Elements = < item - Version = 'v1.12' + Version = 'v1.0.7' DayOffset = 0 DayOffsetUnits = duDay ElementName = 'TaskList' @@ -896,11 +893,12 @@ object MainForm: TMainForm end> Printer.RightMargin = 5 Printer.TopMargin = 5 + OnHoliday = VpHoliday Left = 312 Top = 200 end object VpResourceEditDialog1: TVpResourceEditDialog - Version = 'v1.12' + Version = 'v1.0.7' Options = [] Placement.Position = mpCenter Placement.Top = 10 @@ -1322,7 +1320,7 @@ object MainForm: TMainForm Top = 344 end object VpPrintPreviewDialog1: TVpPrintPreviewDialog - Version = 'v1.12' + Version = 'v1.0.7' ControlLink = VpControlLink1 EndDate = 42561.5151169907 MarginUnits = imPercent @@ -1337,7 +1335,7 @@ object MainForm: TMainForm Top = 432 end object VpPrintFormatEditDialog1: TVpPrintFormatEditDialog - Version = 'v1.12' + Version = 'v1.0.7' ControlLink = VpControlLink1 Options = [] Placement.Position = mpCenter diff --git a/components/tvplanit/source/vpbaseds.pas b/components/tvplanit/source/vpbaseds.pas index afea81993..7b6762c79 100644 --- a/components/tvplanit/source/vpbaseds.pas +++ b/components/tvplanit/source/vpbaseds.pas @@ -364,6 +364,7 @@ type {TVpLinkableControl} + TVpLinkableControl = class(TVpCustomControl) protected{private} FDataStore: TVpCustomDataStore; @@ -404,50 +405,55 @@ type property OnMouseWheel; end; + {TVpControlLink} + TVpControlLink = class(TVpComponent) private - FPrinter : TVpPrinter; - FDataStore : TVpCustomDataStore; - FOnGetVariable : TVpOnGetVariableEvent; - FOnNoLocalizationFile : TVpNoLocalizationFile; - FOnPageStart : TVpOnPageStartEvent; - FOnPageEnd : TVpOnPageEndEvent; - FLocalization : TVpLocalization; - FLocalizationFile : string; - FDefaultCountry : string; + FPrinter: TVpPrinter; + FDataStore: TVpCustomDataStore; + FLocalization: TVpLocalization; + FLocalizationFile: string; + FDefaultCountry: string; FCityStateZipFormat: String; + FOnGetVariable: TVpOnGetVariableEvent; + FOnHoliday: TVpHolidayEvent; + FOnNoLocalizationFile: TVpNoLocalizationFile; + FOnPageStart: TVpOnPageStartEvent; + FOnPageEnd: TVpOnPageEndEvent; protected{private} DependentList: TList; procedure ReleaseDependents; procedure SetCityStateZipFormat(const Value: String); - procedure SetDataStore (const Value : TVpCustomDataStore); - procedure SetDefaultCountry (const v : string); - procedure SetLocalizationFile (const v : string); - procedure SetPrinter (const v : TVpPrinter); + procedure SetDataStore(const Value: TVpCustomDataStore); + procedure SetDefaultCountry(const v: string); + procedure SetLocalizationFile(const v: string); + procedure SetPrinter(const v: TVpPrinter); public constructor Create(AOwner: TComponent); override; destructor Destroy; override; procedure Attach(Sender: TComponent); procedure Detach(Sender: TComponent); - function GetDependentList : TList; + function GetDependentList: TList; + function IsHoliday(ADate: TDate; out AHolidayName: String): Boolean; procedure LoadLocalizationInfo (const FileName : string); procedure Notify (Sender: TComponent; NotificationType: TVpNotificationType; const Value: Variant); procedure TriggerOnGetVariable (Sender : TObject; VarName: string; Found: Boolean; var Value: string; var Change: TVpChangeVar); procedure TriggerOnPageEnd (Sender: TObject; PageNum: Integer; ADate: TDateTime; LastPage: Boolean); procedure TriggerOnPageStart (Sender: TObject; PageNum: Integer; ADate: TDateTime); - property Localization : TVpLocalization read FLocalization write FLocalization; + property Localization: TVpLocalization read FLocalization write FLocalization; published property CityStateZipFormat: String read FCityStateZipFormat write SetCityStateZipFormat; // Use symbols @CITY, @STATE, @ZIP to define the order of these strings property DataStore: TVpCustomDataStore read FDataStore write SetDataStore; - property DefaultCountry : string read FDefaultCountry write SetDefaultCountry; - property LocalizationFile : string read FLocalizationFile write SetLocalizationFile; - property Printer : TVpPrinter read FPrinter write SetPrinter; - property OnGetVariable : TVpOnGetVariableEvent read FOnGetVariable write FOnGetVariable; - property OnNoLocalizationFile : TVpNoLocalizationFile read FOnNoLocalizationFile write FOnNoLocalizationFile; - property OnPageStart : TVpOnPageStartEvent read FOnPageStart write FOnPageStart; - property OnPageEnd : TVpOnPageEndEvent read FOnPageEnd write FOnPageEnd; + property DefaultCountry: string read FDefaultCountry write SetDefaultCountry; + property LocalizationFile: string read FLocalizationFile write SetLocalizationFile; + property Printer: TVpPrinter read FPrinter write SetPrinter; + property OnGetVariable: TVpOnGetVariableEvent read FOnGetVariable write FOnGetVariable; + property OnHoliday: TVpHolidayEvent read FOnHoliday write FOnHoliday; + property OnNoLocalizationFile: TVpNoLocalizationFile read FOnNoLocalizationFile write FOnNoLocalizationFile; + property OnPageStart: TVpOnPageStartEvent read FOnPageStart write FOnPageStart; + property OnPageEnd: TVpOnPageEndEvent read FOnPageEnd write FOnPageEnd; end; @@ -1596,6 +1602,14 @@ begin Result := DependentList; end; +function TVpControlLink.IsHoliday(ADate: TDate; out AHolidayName: String): Boolean; +begin + AHolidayName := ''; + if Assigned(FOnHoliday) then + FOnHoliday(Self, trunc(ADate), AHolidayName); + Result := AHolidayName <> ''; +end; + procedure TVpControlLink.LoadLocalizationInfo (const FileName : string); begin LocalizationFile := FileName; diff --git a/components/tvplanit/source/vpclock.pas b/components/tvplanit/source/vpclock.pas index d9e276ec6..05ab6961c 100644 --- a/components/tvplanit/source/vpclock.pas +++ b/components/tvplanit/source/vpclock.pas @@ -1464,7 +1464,6 @@ var Hour1, Minute1, Second1: Word; Hour2, Minute2, Second2: Word; MSecond: Word; - TimeStr: string; begin if FTime = Value then exit; diff --git a/components/tvplanit/source/vpdayview.pas b/components/tvplanit/source/vpdayview.pas index d7d586e02..28202ed60 100644 --- a/components/tvplanit/source/vpdayview.pas +++ b/components/tvplanit/source/vpdayview.pas @@ -527,7 +527,7 @@ type property OnBeforeDrawEvent: TVpOnDVBeforeDrawEvent read FOnBeforeDrawEvent write FOnBeforeDrawEvent; property OnDeletingEvent: TVpOnDeletingEvent read FOnDeletingEvent write FOnDeletingEvent; property OnDrawIcons: TVpOnDVDrawIcons read FOnDrawIcons Write FOnDrawIcons; - property OnHoliday: TVpHolidayEvent read FOnHoliday write FOnHoliday; + property OnHoliday: TVpHolidayEvent read FOnHoliday write FOnHoliday; deprecated 'Use TControlLink.OnHoliday instead'; property OnModifyEvent: TVpOnModifyEvent read FOnModifyEvent write FOnModifyEvent; property OnOwnerEditEvent: TVpEditEvent read FOwnerEditEvent write FOwnerEditEvent; property OnClick; @@ -1005,10 +1005,14 @@ end; function TVpDayView.IsHoliday(ADate: TDate; out AHolidayName: String): Boolean; begin + if Assigned(FOnHoliday) then AHolidayName := ''; if Assigned(FOnHoliday) then + begin FOnHoliday(Self, trunc(ADate), AHolidayName); - Result := AHolidayName <> ''; + Result := AHolidayName <> ''; + end else + Result := FControlLink.IsHoliday(ADate, AHolidayName); end; procedure TVpDayView.LinkHandler(Sender: TComponent; diff --git a/components/tvplanit/source/vpganttview.pas b/components/tvplanit/source/vpganttview.pas index aefe2c9a8..e20e01030 100644 --- a/components/tvplanit/source/vpganttview.pas +++ b/components/tvplanit/source/vpganttview.pas @@ -329,7 +329,7 @@ type // new events property OnAddEvent: TVpOnAddNewEvent read FOnAddEvent write FOnAddEvent; property OnDeletingEvent: TVpOnDeletingEvent read FOnDeletingEvent write FOnDeletingEvent; - property OnHoliday: TVpHolidayEvent read FOnHoliday write FOnHoliday; + property OnHoliday: TVpHolidayEvent read FOnHoliday write FOnHoliday; deprecated 'Use TControlLink.OnHoliday instead'; property OnModifyEvent: TVpOnModifyEvent read FOnModifyEvent write FOnModifyEvent; property OwnerEditEvent: TVpEditEvent read FOwnerEditEvent write FOwnerEditEvent; end; @@ -816,8 +816,7 @@ begin end; { Determines the date when the earliest event starts, and the date when the - latest event ends. - Stores them in the internal variables FFirstDate and FLastDate. } + latest event ends. } procedure TVpGanttView.GetEventDateRange(out AFirstDate, ALastDate: TDate); var i: Integer; @@ -826,18 +825,18 @@ var begin if (Datastore = nil) or (Datastore.Resource = nil) or (Datastore.Resource.Schedule.EventCount = 0) then begin - FFirstDate := NO_DATE; - FLastDate := NO_DATE; + AFirstDate := NO_DATE; + ALastDate := NO_DATE; end else begin event := Datastore.Resource.Schedule.GetEvent(0); - FFirstDate := DatePart(event.StartTime); - FLastDate := -99999; + AFirstDate := DatePart(event.StartTime); + ALastDate := -99999; for i := 0 to Datastore.Resource.Schedule.EventCount-1 do begin event := Datastore.Resource.Schedule.GetEvent(i); d := DatePart(event.EndTime); - if d > FLastDate then FLastDate := d; + if d > ALastDate then ALastDate := d; end; end; end; @@ -968,8 +967,11 @@ function TVpGanttView.IsHoliday(ADate: TDate; out AHolidayName: String): Boolean begin AHolidayName := ''; if Assigned(FOnHoliday) then + begin FOnHoliday(Self, ADate, AHolidayName); - Result := AHolidayName <> ''; + Result := AHolidayName <> ''; + end else + Result := FControlLink.IsHoliday(ADate, AHolidayName); end; procedure TVpGanttView.KeyDown(var Key: Word; Shift: TShiftState); diff --git a/components/tvplanit/source/vpmonthview.pas b/components/tvplanit/source/vpmonthview.pas index 22084168f..b1c39ad6f 100644 --- a/components/tvplanit/source/vpmonthview.pas +++ b/components/tvplanit/source/vpmonthview.pas @@ -371,7 +371,7 @@ type property OnAddEvent: TVpOnAddNewEvent read FOnAddEvent write FOnAddEvent; property OnEventClick: TVpOnEventClick read FOnEventClick write FOnEventClick; property OnEventDblClick: TVpOnEventClick read FOnEventDblClick write FOnEventDblClick; - property OnHoliday: TVpHolidayEvent read FOnHoliday write FOnHoliday; + property OnHoliday: TVpHolidayEvent read FOnHoliday write FOnHoliday; deprecated 'Use TControlLink.OnHoliday instead'; property OnModifyEvent: TVpOnModifyEvent read FOnModifyEvent write FOnModifyEvent; property OnOwnerEditEvent: TVpEditEvent read FOwnerEditEvent write FOwnerEditEvent; end; @@ -653,8 +653,11 @@ function TVpMonthView.IsHoliday(ADate: TDate; out AHolidayName: String): Boolean begin AHolidayName := ''; if Assigned(FOnHoliday) then + begin FOnHoliday(Self, ADate, AHolidayName); - Result := AHolidayName <> ''; + Result := AHolidayName <> ''; + end else + Result := FControlLink.IsHoliday(ADate, AHolidayName); end; procedure TVpMonthView.LinkHandler(Sender: TComponent; diff --git a/components/tvplanit/source/vpprtprvdlg.lfm b/components/tvplanit/source/vpprtprvdlg.lfm index 418e3b580..6868a649e 100644 --- a/components/tvplanit/source/vpprtprvdlg.lfm +++ b/components/tvplanit/source/vpprtprvdlg.lfm @@ -14,6 +14,7 @@ object frmPrintPreview: TfrmPrintPreview OnCreate = FormCreate OnKeyDown = FormKeyDown OnShow = FormShow + LCLVersion = '2.3.0.0' object Panel1: TPanel Left = 0 Height = 56 @@ -49,7 +50,7 @@ object frmPrintPreview: TfrmPrintPreview end object ToolButton3: TToolButton Left = 55 - Height = 25 + Height = 5 Top = 0 Caption = 'ToolButton3' ImageIndex = 2 @@ -85,7 +86,7 @@ object frmPrintPreview: TfrmPrintPreview end object ToolButton8: TToolButton Left = 152 - Height = 25 + Height = 5 Top = 0 Caption = 'ToolButton8' ImageIndex = 6 diff --git a/components/tvplanit/source/vpprtprvdlg.pas b/components/tvplanit/source/vpprtprvdlg.pas index 717b6ccb0..5619f7f6f 100644 --- a/components/tvplanit/source/vpprtprvdlg.pas +++ b/components/tvplanit/source/vpprtprvdlg.pas @@ -164,7 +164,8 @@ implementation {$ENDIF} uses - VpConst, VpPrtFmt; + VpConst, // needed for define VP_LCL_SCALING + VpPrtFmt; { TfrmPrintPreview } diff --git a/components/tvplanit/source/vpweekview.pas b/components/tvplanit/source/vpweekview.pas index 1d187590a..b6f814380 100644 --- a/components/tvplanit/source/vpweekview.pas +++ b/components/tvplanit/source/vpweekview.pas @@ -372,7 +372,7 @@ type property BeforeEdit: TVpBeforeEditEvent read FBeforeEdit write FBeforeEdit; property OnAddEvent: TVpOnAddNewEvent read FOnAddEvent write FOnAddEvent; property OnDeletingEvent: TVpOnDeletingEvent read FOnDeletingEvent write FOnDeletingEvent; - property OnHoliday: TVpHolidayEvent read FOnHoliday write FOnHoliday; + property OnHoliday: TVpHolidayEvent read FOnHoliday write FOnHoliday; deprecated 'Use TControlLink.OnHoliday instead'; property OnModifyEvent: TVpOnModifyEvent read FOnModifyEvent write FOnModifyEvent; property OnOwnerEditEvent: TVpEditEvent read FOwnerEditEvent write FOwnerEditEvent; end; @@ -779,8 +779,11 @@ function TVpWeekView.IsHoliday(ADate: TDate; out AHolidayName: String): Boolean; begin AHolidayName := ''; if Assigned(FOnHoliday) then + begin FOnHoliday(Self, ADate, AHolidayName); - Result := AHolidayName <> ''; + Result := AHolidayName <> ''; + end else + Result := FControlLink.IsHoliday(ADate, AHolidayName); end; procedure TVpWeekView.LinkHandler(Sender: TComponent;