You've already forked lazarus-ccr
Introducing a way to replace default LCL's calendar with some other calendar control
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@2818 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
103
components/ZVDateTimeCtrls/trunk/calendarcontrolwrapper.pas
Normal file
103
components/ZVDateTimeCtrls/trunk/calendarcontrolwrapper.pas
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
{
|
||||||
|
CalendarControlWrapper
|
||||||
|
- - - - - - - - - - - - - - - - -
|
||||||
|
Author: Zoran Vučenović
|
||||||
|
Зоран Вученовић
|
||||||
|
|
||||||
|
This unit is part of ZVDateTimeCtrls package for Lazarus.
|
||||||
|
|
||||||
|
By default, TZVDateTimePicker uses LCL's TCalendar to represent the
|
||||||
|
drop-down calendar, but you can use some other calendar control instead.
|
||||||
|
|
||||||
|
In order to use another calendar control, you should "wrap" that control with
|
||||||
|
a CalendarControlWrapper.
|
||||||
|
|
||||||
|
To be used by ZVDateTimePicker, the calendar control must at least provide
|
||||||
|
a way to determine whether the coordinates are on the date (when this control
|
||||||
|
gets clicked, we must decide if the date has just been chosen - then we should
|
||||||
|
respond by closing the drop-down form and setting the date from calendar to
|
||||||
|
ZVDateTimePicker - for example in LCL's TCalendar we will respond when the
|
||||||
|
calendar is clicked on date, but not when the user clicks in title area changing
|
||||||
|
months or years, then we let the user keep browsing the calendar).
|
||||||
|
|
||||||
|
When creating new wrapper, there are four abstract methods which need to be
|
||||||
|
overriden. Please see the coments in code below.
|
||||||
|
|
||||||
|
-----------------------------------------------------------
|
||||||
|
LICENCE
|
||||||
|
- - - -
|
||||||
|
Modified LGPL -- see the file COPYING.modifiedLGPL.
|
||||||
|
|
||||||
|
-----------------------------------------------------------
|
||||||
|
NO WARRANTY
|
||||||
|
- - - - - -
|
||||||
|
There is no warranty whatsoever.
|
||||||
|
|
||||||
|
-----------------------------------------------------------
|
||||||
|
BEST REGARDS TO LAZARUS COMMUNITY!
|
||||||
|
- - - - - - - - - - - - - - - - - -
|
||||||
|
I do hope the ZVDateTimeCtrls package will be useful.
|
||||||
|
}
|
||||||
|
unit CalendarControlWrapper;
|
||||||
|
|
||||||
|
{$mode objfpc}{$H+}
|
||||||
|
|
||||||
|
interface
|
||||||
|
|
||||||
|
uses
|
||||||
|
Controls;
|
||||||
|
|
||||||
|
type
|
||||||
|
|
||||||
|
{ TCalendarControlWrapper }
|
||||||
|
|
||||||
|
TCalendarControlWrapper = class
|
||||||
|
private
|
||||||
|
FCalendarControl: TControl;
|
||||||
|
public
|
||||||
|
{ There are four methods that derived classes should override: }
|
||||||
|
|
||||||
|
{ Should be overriden to just return the class of the calendar control. }
|
||||||
|
class function GetCalendarControlClass: TControlClass; virtual abstract;
|
||||||
|
|
||||||
|
{ Should be overriden to set the date in the calendar control. }
|
||||||
|
procedure SetDate(Date: TDate); virtual abstract;
|
||||||
|
|
||||||
|
{ Should be overriden to get the date from the calendar control. }
|
||||||
|
function GetDate: TDate; virtual abstract;
|
||||||
|
|
||||||
|
{ This function should return True if coordinates (X, Y) are on the date in
|
||||||
|
the calendar control (ZVDateTimePicker calls this function when the calendar
|
||||||
|
is clicked, to determine whether the drop-down calendar should return the
|
||||||
|
date or not). }
|
||||||
|
function AreCoordinatesOnDate(X, Y: Integer): Boolean; virtual abstract;
|
||||||
|
|
||||||
|
function GetCalendarControl: TControl;
|
||||||
|
constructor Create; virtual;
|
||||||
|
destructor Destroy; override;
|
||||||
|
end;
|
||||||
|
|
||||||
|
TCalendarControlWrapperClass = class of TCalendarControlWrapper;
|
||||||
|
|
||||||
|
implementation
|
||||||
|
|
||||||
|
{ TCalendarControlWrapper }
|
||||||
|
|
||||||
|
function TCalendarControlWrapper.GetCalendarControl: TControl;
|
||||||
|
begin
|
||||||
|
Result := FCalendarControl;
|
||||||
|
end;
|
||||||
|
|
||||||
|
constructor TCalendarControlWrapper.Create;
|
||||||
|
begin
|
||||||
|
FCalendarControl := GetCalendarControlClass.Create(nil);
|
||||||
|
end;
|
||||||
|
|
||||||
|
destructor TCalendarControlWrapper.Destroy;
|
||||||
|
begin
|
||||||
|
FCalendarControl.Free;
|
||||||
|
inherited Destroy;
|
||||||
|
end;
|
||||||
|
|
||||||
|
end.
|
||||||
|
|
@ -62,6 +62,7 @@ type
|
|||||||
constructor Create(AOwner: TComponent); override;
|
constructor Create(AOwner: TComponent); override;
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
property Field: TField read GetField;
|
property Field: TField read GetField;
|
||||||
|
property CalendarWrapperClass;
|
||||||
published
|
published
|
||||||
{ Published declarations }
|
{ Published declarations }
|
||||||
property DataField: string read GetDataField write SetDataField;
|
property DataField: string read GetDataField write SetDataField;
|
||||||
|
74
components/ZVDateTimeCtrls/trunk/lclcalendarwrapper.pas
Normal file
74
components/ZVDateTimeCtrls/trunk/lclcalendarwrapper.pas
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
{
|
||||||
|
LCLCalendarWrapper
|
||||||
|
- - - - - - - - - - - - - - - - -
|
||||||
|
Author: Zoran Vučenović
|
||||||
|
Зоран Вученовић
|
||||||
|
|
||||||
|
This unit is part of ZVDateTimeCtrls package for Lazarus.
|
||||||
|
|
||||||
|
TLCLCalendarWrapper is the default implementation of TCalendarControlWrapper
|
||||||
|
abstract class, used by ZVDateTimePicker. Wraps LCL's TCalendar.
|
||||||
|
|
||||||
|
-----------------------------------------------------------
|
||||||
|
LICENCE
|
||||||
|
- - - -
|
||||||
|
Modified LGPL -- see the file COPYING.modifiedLGPL.
|
||||||
|
|
||||||
|
-----------------------------------------------------------
|
||||||
|
NO WARRANTY
|
||||||
|
- - - - - -
|
||||||
|
There is no warranty whatsoever.
|
||||||
|
|
||||||
|
-----------------------------------------------------------
|
||||||
|
BEST REGARDS TO LAZARUS COMMUNITY!
|
||||||
|
- - - - - - - - - - - - - - - - - -
|
||||||
|
I do hope the ZVDateTimeCtrls package will be useful.
|
||||||
|
}
|
||||||
|
unit LCLCalendarWrapper;
|
||||||
|
|
||||||
|
{$mode objfpc}{$H+}
|
||||||
|
|
||||||
|
interface
|
||||||
|
|
||||||
|
uses
|
||||||
|
Classes, Controls, Calendar, CalendarControlWrapper;
|
||||||
|
|
||||||
|
type
|
||||||
|
|
||||||
|
{ TLCLCalendarWrapper }
|
||||||
|
|
||||||
|
TLCLCalendarWrapper = class(TCalendarControlWrapper)
|
||||||
|
public
|
||||||
|
class function GetCalendarControlClass: TControlClass; override;
|
||||||
|
procedure SetDate(Date: TDate); override;
|
||||||
|
function GetDate: TDate; override;
|
||||||
|
function AreCoordinatesOnDate(X, Y: Integer): Boolean; override;
|
||||||
|
end;
|
||||||
|
|
||||||
|
implementation
|
||||||
|
|
||||||
|
{ TLCLCalendarWrapper }
|
||||||
|
|
||||||
|
class function TLCLCalendarWrapper.GetCalendarControlClass: TControlClass;
|
||||||
|
begin
|
||||||
|
Result := TCalendar;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TLCLCalendarWrapper.SetDate(Date: TDate);
|
||||||
|
begin
|
||||||
|
TCalendar(GetCalendarControl).DateTime := Date;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TLCLCalendarWrapper.GetDate: TDate;
|
||||||
|
begin
|
||||||
|
Result := TCalendar(GetCalendarControl).DateTime;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TLCLCalendarWrapper.AreCoordinatesOnDate(X, Y: Integer): Boolean;
|
||||||
|
begin
|
||||||
|
Result :=
|
||||||
|
TCalendar(GetCalendarControl).HitTest(Point(X, Y)) in [cpDate, cpNoWhere];
|
||||||
|
end;
|
||||||
|
|
||||||
|
end.
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
<?xml version="1.0"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<CONFIG>
|
<CONFIG>
|
||||||
<Package Version="4">
|
<Package Version="4">
|
||||||
<PathDelim Value="\"/>
|
<PathDelim Value="\"/>
|
||||||
@ -27,7 +27,7 @@
|
|||||||
<Description Value="TZVDateTimePicker - the cross-platform control behaving much like VCL's TDateTimePicker. TDBZVDateTimePicker - the data-aware version of TZVDateTimePicker"/>
|
<Description Value="TZVDateTimePicker - the cross-platform control behaving much like VCL's TDateTimePicker. TDBZVDateTimePicker - the data-aware version of TZVDateTimePicker"/>
|
||||||
<License Value="Modified LGPL"/>
|
<License Value="Modified LGPL"/>
|
||||||
<Version Major="1" Minor="4" Release="1"/>
|
<Version Major="1" Minor="4" Release="1"/>
|
||||||
<Files Count="5">
|
<Files Count="7">
|
||||||
<Item1>
|
<Item1>
|
||||||
<Filename Value="zvdatetimepicker.pas"/>
|
<Filename Value="zvdatetimepicker.pas"/>
|
||||||
<UnitName Value="ZVDateTimePicker"/>
|
<UnitName Value="ZVDateTimePicker"/>
|
||||||
@ -49,6 +49,14 @@
|
|||||||
<Filename Value="zvdatetimectrls.lrs"/>
|
<Filename Value="zvdatetimectrls.lrs"/>
|
||||||
<Type Value="LRS"/>
|
<Type Value="LRS"/>
|
||||||
</Item5>
|
</Item5>
|
||||||
|
<Item6>
|
||||||
|
<Filename Value="calendarcontrolwrapper.pas"/>
|
||||||
|
<UnitName Value="CalendarControlWrapper"/>
|
||||||
|
</Item6>
|
||||||
|
<Item7>
|
||||||
|
<Filename Value="lclcalendarwrapper.pas"/>
|
||||||
|
<UnitName Value="lclcalendarwrapper"/>
|
||||||
|
</Item7>
|
||||||
</Files>
|
</Files>
|
||||||
<Type Value="RunAndDesignTime"/>
|
<Type Value="RunAndDesignTime"/>
|
||||||
<RequiredPkgs Count="3">
|
<RequiredPkgs Count="3">
|
||||||
|
@ -8,7 +8,8 @@ interface
|
|||||||
|
|
||||||
uses
|
uses
|
||||||
ZVDateTimePicker, DBZVDateTimePicker, ZVDateTimePickerPropEdit,
|
ZVDateTimePicker, DBZVDateTimePicker, ZVDateTimePickerPropEdit,
|
||||||
ZVDateTimeControlsReg, LazarusPackageIntf;
|
ZVDateTimeControlsReg, CalendarControlWrapper, LCLCalendarWrapper,
|
||||||
|
LazarusPackageIntf;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
|
@ -45,8 +45,8 @@ uses
|
|||||||
{$ifdef unix}
|
{$ifdef unix}
|
||||||
clocale, // needed to initialize default locale settings on Linux.
|
clocale, // needed to initialize default locale settings on Linux.
|
||||||
{$endif}
|
{$endif}
|
||||||
Classes, SysUtils, Controls, LCLType, Graphics, Math, StdCtrls,
|
Classes, SysUtils, Controls, LCLType, Graphics, Math, StdCtrls, Buttons,
|
||||||
Buttons, ExtCtrls, Forms, Calendar, ComCtrls, Types, LMessages
|
ExtCtrls, Forms, ComCtrls, Types, LMessages, CalendarControlWrapper
|
||||||
{$ifdef LCLGtk2}, LCLVersion{$endif}
|
{$ifdef LCLGtk2}, LCLVersion{$endif}
|
||||||
;
|
;
|
||||||
|
|
||||||
@ -72,6 +72,9 @@ const
|
|||||||
So, this will be the down limit: }
|
So, this will be the down limit: }
|
||||||
TheSmallestDate = TDateTime(-53780.0); // 1. okt. 1752.
|
TheSmallestDate = TDateTime(-53780.0); // 1. okt. 1752.
|
||||||
|
|
||||||
|
var
|
||||||
|
DefaultCalendarWrapperClass: TCalendarControlWrapperClass = nil;
|
||||||
|
|
||||||
type
|
type
|
||||||
TYMD = record
|
TYMD = record
|
||||||
Year, Month, Day: Word;
|
Year, Month, Day: Word;
|
||||||
@ -84,8 +87,8 @@ type
|
|||||||
{ Used by DateDisplayOrder property to determine the order to display date
|
{ Used by DateDisplayOrder property to determine the order to display date
|
||||||
parts -- d-m-y, m-d-y or y-m-d.
|
parts -- d-m-y, m-d-y or y-m-d.
|
||||||
When ddoTryDefault is set, the actual order is determined from
|
When ddoTryDefault is set, the actual order is determined from
|
||||||
ShortDateFormat global variable -- see coments above AdjustDateDisplayOrder
|
ShortDateFormat global variable -- see coments above
|
||||||
procedure }
|
AdjustEffectiveHideDateTimeParts procedure }
|
||||||
TDateDisplayOrder = (ddoDMY, ddoMDY, ddoYMD, ddoTryDefault);
|
TDateDisplayOrder = (ddoDMY, ddoMDY, ddoYMD, ddoTryDefault);
|
||||||
|
|
||||||
TTimeDisplay = (tdHM, // hour and minute
|
TTimeDisplay = (tdHM, // hour and minute
|
||||||
@ -103,7 +106,10 @@ type
|
|||||||
TTextPart = 1..8;
|
TTextPart = 1..8;
|
||||||
TDateTimePart = (dtpDay, dtpMonth, dtpYear, dtpHour, dtpMinute,
|
TDateTimePart = (dtpDay, dtpMonth, dtpYear, dtpHour, dtpMinute,
|
||||||
dtpSecond, dtpMiliSec, dtpAMPM);
|
dtpSecond, dtpMiliSec, dtpAMPM);
|
||||||
TDateTimeParts = set of dtpDay..dtpMiliSec;
|
TDateTimeParts = set of dtpDay..dtpMiliSec; // without AMPM,
|
||||||
|
// because this set type is used for HideDateTimeParts property,
|
||||||
|
// where hiding of AMPM part is tied to hiding of hour (and, of
|
||||||
|
// course, it makes a difference only when TimeFormat is set to tf12)
|
||||||
|
|
||||||
TArrowShape = (asClassicSmaller, asClassicLarger, asModernSmaller,
|
TArrowShape = (asClassicSmaller, asClassicLarger, asModernSmaller,
|
||||||
asModernLarger, asYetAnotherShape);
|
asModernLarger, asYetAnotherShape);
|
||||||
@ -116,6 +122,7 @@ type
|
|||||||
private
|
private
|
||||||
FAutoAdvance: Boolean;
|
FAutoAdvance: Boolean;
|
||||||
FAutoButtonSize: Boolean;
|
FAutoButtonSize: Boolean;
|
||||||
|
FCalendarWrapperClass: TCalendarControlWrapperClass;
|
||||||
FCascade: Boolean;
|
FCascade: Boolean;
|
||||||
FCenturyFrom, FEffectiveCenturyFrom: Word;
|
FCenturyFrom, FEffectiveCenturyFrom: Word;
|
||||||
FDateDisplayOrder: TDateDisplayOrder;
|
FDateDisplayOrder: TDateDisplayOrder;
|
||||||
@ -178,6 +185,7 @@ type
|
|||||||
function GetTime: TTime;
|
function GetTime: TTime;
|
||||||
procedure SetArrowShape(const AValue: TArrowShape);
|
procedure SetArrowShape(const AValue: TArrowShape);
|
||||||
procedure SetAutoButtonSize(AValue: Boolean);
|
procedure SetAutoButtonSize(AValue: Boolean);
|
||||||
|
procedure SetCalendarWrapperClass(AValue: TCalendarControlWrapperClass);
|
||||||
procedure SetCenturyFrom(const AValue: Word);
|
procedure SetCenturyFrom(const AValue: Word);
|
||||||
procedure SetChecked(const AValue: Boolean);
|
procedure SetChecked(const AValue: Boolean);
|
||||||
procedure CheckTextEnabled;
|
procedure CheckTextEnabled;
|
||||||
@ -360,6 +368,8 @@ type
|
|||||||
read FAutoAdvance write FAutoAdvance default False;
|
read FAutoAdvance write FAutoAdvance default False;
|
||||||
property HideDateTimeParts: TDateTimeParts
|
property HideDateTimeParts: TDateTimeParts
|
||||||
read FHideDateTimeParts write SetHideDateTimeParts;
|
read FHideDateTimeParts write SetHideDateTimeParts;
|
||||||
|
property CalendarWrapperClass: TCalendarControlWrapperClass
|
||||||
|
read FCalendarWrapperClass write SetCalendarWrapperClass;
|
||||||
|
|
||||||
public
|
public
|
||||||
constructor Create(AOwner: TComponent); override;
|
constructor Create(AOwner: TComponent); override;
|
||||||
@ -380,6 +390,7 @@ type
|
|||||||
TZVDateTimePicker = class(TCustomZVDateTimePicker)
|
TZVDateTimePicker = class(TCustomZVDateTimePicker)
|
||||||
public
|
public
|
||||||
property DateTime;
|
property DateTime;
|
||||||
|
property CalendarWrapperClass;
|
||||||
published
|
published
|
||||||
property ArrowShape;
|
property ArrowShape;
|
||||||
property ShowCheckBox;
|
property ShowCheckBox;
|
||||||
@ -455,7 +466,8 @@ function IsNullDate(DT: TDateTime): Boolean;
|
|||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
uses DateUtils;
|
uses
|
||||||
|
DateUtils, LCLCalendarWrapper;
|
||||||
|
|
||||||
function NumberOfDaysInMonth(const Month, Year: Word): Word;
|
function NumberOfDaysInMonth(const Month, Year: Word): Word;
|
||||||
begin
|
begin
|
||||||
@ -481,17 +493,6 @@ begin
|
|||||||
(DT > SysUtils.MaxDateTime) or (DT < SysUtils.MinDateTime);
|
(DT > SysUtils.MaxDateTime) or (DT < SysUtils.MinDateTime);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TCustomZVDateTimePicker }
|
|
||||||
|
|
||||||
procedure TCustomZVDateTimePicker.SetChecked(const AValue: Boolean);
|
|
||||||
begin
|
|
||||||
if Assigned(FCheckBox) then
|
|
||||||
FCheckBox.Checked := AValue;
|
|
||||||
|
|
||||||
CheckTextEnabled;
|
|
||||||
Invalidate;
|
|
||||||
end;
|
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
||||||
{ TDTCalendarForm }
|
{ TDTCalendarForm }
|
||||||
@ -499,7 +500,7 @@ type
|
|||||||
TDTCalendarForm = class(TForm)
|
TDTCalendarForm = class(TForm)
|
||||||
private
|
private
|
||||||
DTPicker: TCustomZVDateTimePicker;
|
DTPicker: TCustomZVDateTimePicker;
|
||||||
Cal: TCalendar;
|
Cal: TCalendarControlWrapper;
|
||||||
Shape: TShape;
|
Shape: TShape;
|
||||||
RememberedCalendarFormOrigin: TPoint;
|
RememberedCalendarFormOrigin: TPoint;
|
||||||
FClosing: Boolean;
|
FClosing: Boolean;
|
||||||
@ -530,8 +531,6 @@ type
|
|||||||
published
|
published
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TDTCalendarForm }
|
|
||||||
|
|
||||||
procedure TDTCalendarForm.SetClosingCalendarForm;
|
procedure TDTCalendarForm.SetClosingCalendarForm;
|
||||||
begin
|
begin
|
||||||
if not FClosing then begin
|
if not FClosing then begin
|
||||||
@ -546,8 +545,8 @@ end;
|
|||||||
procedure TDTCalendarForm.AdjustCalendarFormSize;
|
procedure TDTCalendarForm.AdjustCalendarFormSize;
|
||||||
begin
|
begin
|
||||||
if not FClosing then begin
|
if not FClosing then begin
|
||||||
ClientWidth := Cal.Width + 2;
|
ClientWidth := Cal.GetCalendarControl.Width + 2;
|
||||||
ClientHeight := Cal.Height + 2;
|
ClientHeight := Cal.GetCalendarControl.Height + 2;
|
||||||
|
|
||||||
Shape.SetBounds(0, 0, ClientWidth, ClientHeight);
|
Shape.SetBounds(0, 0, ClientWidth, ClientHeight);
|
||||||
|
|
||||||
@ -614,11 +613,11 @@ begin
|
|||||||
try
|
try
|
||||||
if DTPicker.DateIsNull then begin
|
if DTPicker.DateIsNull then begin
|
||||||
// we'll set the time to 0.0 (midnight):
|
// we'll set the time to 0.0 (midnight):
|
||||||
DTPicker.SetDateTime(Int(Cal.DateTime));
|
DTPicker.SetDateTime(Int(Cal.GetDate));
|
||||||
end else if not EqualDateTime(Int(DTPicker.DateTime),
|
end else if not EqualDateTime(Int(DTPicker.DateTime),
|
||||||
Int(Cal.DateTime)) then begin
|
Int(Cal.GetDate)) then begin
|
||||||
// we'll change the date, but keep the time:
|
// we'll change the date, but keep the time:
|
||||||
DTPicker.SetDateTime(ComposeDateTime(Cal.DateTime, DTPicker.DateTime));
|
DTPicker.SetDateTime(ComposeDateTime(Cal.GetDate, DTPicker.DateTime));
|
||||||
end;
|
end;
|
||||||
finally
|
finally
|
||||||
Dec(DTPicker.FUserChanging);
|
Dec(DTPicker.FUserChanging);
|
||||||
@ -658,7 +657,7 @@ end;
|
|||||||
procedure TDTCalendarForm.CalendarMouseUp(Sender: TObject;
|
procedure TDTCalendarForm.CalendarMouseUp(Sender: TObject;
|
||||||
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
|
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
|
||||||
begin
|
begin
|
||||||
if Cal.HitTest(Point(X, Y)) in [cpDate, cpNoWhere] then
|
if Cal.AreCoordinatesOnDate(X, Y) then
|
||||||
CloseCalendarForm(True);
|
CloseCalendarForm(True);
|
||||||
|
|
||||||
end;
|
end;
|
||||||
@ -707,10 +706,16 @@ begin
|
|||||||
inherited DoClose(CloseAction);
|
inherited DoClose(CloseAction);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
type
|
||||||
|
{ To be able to access TControl's protected members,
|
||||||
|
we derive our class TDTControl from TControl: }
|
||||||
|
TDTControl = class(TControl);
|
||||||
|
|
||||||
constructor TDTCalendarForm.CreateNewDTCalendarForm(AOwner: TComponent;
|
constructor TDTCalendarForm.CreateNewDTCalendarForm(AOwner: TComponent;
|
||||||
ADTPicker: TCustomZVDateTimePicker);
|
ADTPicker: TCustomZVDateTimePicker);
|
||||||
var
|
var
|
||||||
P: TPoint;
|
P: TPoint;
|
||||||
|
CalClass: TCalendarControlWrapperClass;
|
||||||
begin
|
begin
|
||||||
inherited CreateNew(AOwner);
|
inherited CreateNew(AOwner);
|
||||||
|
|
||||||
@ -723,21 +728,28 @@ begin
|
|||||||
if Assigned(DTPickersParentForm) then begin
|
if Assigned(DTPickersParentForm) then begin
|
||||||
DTPickersParentForm.AddHandlerOnVisibleChanged(@VisibleOfParentChanged);
|
DTPickersParentForm.AddHandlerOnVisibleChanged(@VisibleOfParentChanged);
|
||||||
DTPickersParentForm.FreeNotification(Self);
|
DTPickersParentForm.FreeNotification(Self);
|
||||||
end;
|
PopupParent := DTPickersParentForm;
|
||||||
|
PopupMode := pmExplicit;
|
||||||
|
end else
|
||||||
|
PopupMode := pmAuto;
|
||||||
|
|
||||||
P := Point(0, 0);
|
P := Point(0, 0);
|
||||||
|
|
||||||
Cal := TCalendar.Create(nil);
|
if ADTPicker.FCalendarWrapperClass = nil then begin
|
||||||
Cal.ParentBiDiMode := True;
|
if DefaultCalendarWrapperClass = nil then
|
||||||
Cal.AutoSize := True;
|
CalClass := TLCLCalendarWrapper
|
||||||
Cal.GetPreferredSize(P.x, P.y);
|
else
|
||||||
|
CalClass := DefaultCalendarWrapperClass;
|
||||||
|
end else
|
||||||
|
CalClass := ADTPicker.FCalendarWrapperClass;
|
||||||
|
|
||||||
Cal.Align := alNone;
|
Cal := CalClass.Create;
|
||||||
|
|
||||||
Cal.SetBounds(1, 1, P.x, P.y);
|
Cal.GetCalendarControl.ParentBiDiMode := True;
|
||||||
Cal.TabStop := True;
|
Cal.GetCalendarControl.AutoSize := True;
|
||||||
|
Cal.GetCalendarControl.GetPreferredSize(P.x, P.y);
|
||||||
PopupMode := pmAuto;
|
Cal.GetCalendarControl.Align := alNone;
|
||||||
|
Cal.GetCalendarControl.SetBounds(1, 1, P.x, P.y);
|
||||||
|
|
||||||
SetBounds(-8000, -8000, P.x + 2, P.y + 2);
|
SetBounds(-8000, -8000, P.x + 2, P.y + 2);
|
||||||
RememberedCalendarFormOrigin := Point(-8000, -8000);
|
RememberedCalendarFormOrigin := Point(-8000, -8000);
|
||||||
@ -749,23 +761,27 @@ begin
|
|||||||
Shape.Brush.Style := bsClear;
|
Shape.Brush.Style := bsClear;
|
||||||
|
|
||||||
if DTPicker.DateIsNull then
|
if DTPicker.DateIsNull then
|
||||||
Cal.DateTime := Max(DTPicker.MinDate, Min(SysUtils.Date, DTPicker.MaxDate))
|
Cal.SetDate(Max(DTPicker.MinDate, Min(SysUtils.Date, DTPicker.MaxDate)))
|
||||||
|
|
||||||
else if DTPicker.DateTime < DTPicker.MinDate then // These "out of bounds" values
|
else if DTPicker.DateTime < DTPicker.MinDate then // These "out of bounds" values
|
||||||
Cal.DateTime := DTPicker.MinDate // can happen when DateTime was set with
|
Cal.SetDate(DTPicker.MinDate) // can happen when DateTime was set with
|
||||||
else if DTPicker.DateTime > DTPicker.MaxDate then // "SetDateTimeJumpMinMax" protected
|
else if DTPicker.DateTime > DTPicker.MaxDate then // "SetDateTimeJumpMinMax" protected
|
||||||
Cal.DateTime := DTPicker.MaxDate // procedure (used in TDBZVDateTimePicker control).
|
Cal.SetDate(DTPicker.MaxDate) // procedure (used in TDBZVDateTimePicker control).
|
||||||
|
|
||||||
else
|
else
|
||||||
Cal.DateTime := DTPicker.DateTime;
|
Cal.SetDate(DTPicker.Date);
|
||||||
|
|
||||||
|
Cal.GetCalendarControl.OnResize := @CalendarResize;
|
||||||
|
TDTControl(Cal.GetCalendarControl).OnMouseUp := @CalendarMouseUp;
|
||||||
|
if Cal.GetCalendarControl is TWinControl then begin
|
||||||
|
TWinControl(Cal.GetCalendarControl).OnKeyDown := @CalendarKeyDown;
|
||||||
|
TWinControl(Cal.GetCalendarControl).TabStop := True;
|
||||||
|
TWinControl(Cal.GetCalendarControl).SetFocus;
|
||||||
|
end;
|
||||||
|
|
||||||
Cal.Parent := Self;
|
|
||||||
Shape.Parent := Self;
|
Shape.Parent := Self;
|
||||||
|
Cal.GetCalendarControl.Parent := Self;
|
||||||
Cal.OnResize := @CalendarResize;
|
Cal.GetCalendarControl.BringToFront;
|
||||||
Cal.OnMouseUp := @CalendarMouseUp;
|
|
||||||
Cal.OnKeyDown := @CalendarKeyDown;
|
|
||||||
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
destructor TDTCalendarForm.Destroy;
|
destructor TDTCalendarForm.Destroy;
|
||||||
@ -775,9 +791,10 @@ begin
|
|||||||
DTPickersParentForm.RemoveAllHandlersOfObject(Self);
|
DTPickersParentForm.RemoveAllHandlersOfObject(Self);
|
||||||
|
|
||||||
if Assigned(Cal) then begin
|
if Assigned(Cal) then begin
|
||||||
Cal.OnResize := nil;
|
Cal.GetCalendarControl.OnResize := nil;
|
||||||
Cal.OnMouseUp := nil;
|
TDTControl(Cal.GetCalendarControl).OnMouseUp := nil;
|
||||||
Cal.OnKeyDown := nil;
|
if Cal.GetCalendarControl is TWinControl then
|
||||||
|
TWinControl(Cal.GetCalendarControl).OnKeyDown := nil;
|
||||||
Cal.Free;
|
Cal.Free;
|
||||||
Cal := nil;
|
Cal := nil;
|
||||||
end;
|
end;
|
||||||
@ -795,6 +812,17 @@ begin
|
|||||||
inherited Destroy;
|
inherited Destroy;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{ TCustomZVDateTimePicker }
|
||||||
|
|
||||||
|
procedure TCustomZVDateTimePicker.SetChecked(const AValue: Boolean);
|
||||||
|
begin
|
||||||
|
if Assigned(FCheckBox) then
|
||||||
|
FCheckBox.Checked := AValue;
|
||||||
|
|
||||||
|
CheckTextEnabled;
|
||||||
|
Invalidate;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TCustomZVDateTimePicker.CheckTextEnabled;
|
procedure TCustomZVDateTimePicker.CheckTextEnabled;
|
||||||
begin
|
begin
|
||||||
FTextEnabled := Self.Enabled and GetChecked;
|
FTextEnabled := Self.Enabled and GetChecked;
|
||||||
@ -1728,13 +1756,11 @@ end;
|
|||||||
selection moves to left, otherwise to right. }
|
selection moves to left, otherwise to right. }
|
||||||
procedure TCustomZVDateTimePicker.MoveSelectionLR(const ToLeft: Boolean);
|
procedure TCustomZVDateTimePicker.MoveSelectionLR(const ToLeft: Boolean);
|
||||||
var
|
var
|
||||||
I: Integer;
|
I, SafetyTextPart: TTextPart;
|
||||||
begin
|
begin
|
||||||
UpdateIfUserChangedText;
|
UpdateIfUserChangedText;
|
||||||
|
|
||||||
if FSelectedTextPart < Low(TTextPart) then
|
SafetyTextPart := Low(TTextPart);
|
||||||
FSelectedTextPart := Low(TTextPart);
|
|
||||||
|
|
||||||
I := FSelectedTextPart;
|
I := FSelectedTextPart;
|
||||||
repeat
|
repeat
|
||||||
if ToLeft then begin
|
if ToLeft then begin
|
||||||
@ -1753,7 +1779,11 @@ begin
|
|||||||
in FEffectiveHideDateTimeParts) then
|
in FEffectiveHideDateTimeParts) then
|
||||||
FSelectedTextPart := I;
|
FSelectedTextPart := I;
|
||||||
|
|
||||||
until I = FSelectedTextPart;
|
{ Is it possible that all parts are hidden? Yes it is!
|
||||||
|
So we need to ensure that this doesn't loop forever.
|
||||||
|
When this insurance text part gets to high value, break }
|
||||||
|
Inc(SafetyTextPart);
|
||||||
|
until (I = FSelectedTextPart) or (SafetyTextPart >= High(TTextPart));
|
||||||
|
|
||||||
Invalidate;
|
Invalidate;
|
||||||
end;
|
end;
|
||||||
@ -3096,6 +3126,13 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TCustomZVDateTimePicker.SetCalendarWrapperClass(
|
||||||
|
AValue: TCalendarControlWrapperClass);
|
||||||
|
begin
|
||||||
|
if FCalendarWrapperClass = AValue then Exit;
|
||||||
|
FCalendarWrapperClass := AValue;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TCustomZVDateTimePicker.SetCenturyFrom(const AValue: Word);
|
procedure TCustomZVDateTimePicker.SetCenturyFrom(const AValue: Word);
|
||||||
begin
|
begin
|
||||||
if FCenturyFrom = AValue then Exit;
|
if FCenturyFrom = AValue then Exit;
|
||||||
@ -3495,6 +3532,7 @@ begin
|
|||||||
|
|
||||||
AdjustEffectiveDateDisplayOrder;
|
AdjustEffectiveDateDisplayOrder;
|
||||||
AdjustEffectiveHideDateTimeParts;
|
AdjustEffectiveHideDateTimeParts;
|
||||||
|
FCalendarWrapperClass := nil;
|
||||||
|
|
||||||
SetDateMode(dmComboBox);
|
SetDateMode(dmComboBox);
|
||||||
end;
|
end;
|
||||||
|
@ -247,6 +247,7 @@ begin
|
|||||||
DTP[I].DateSeparator := CallerZVDateTimePicker.DateSeparator;
|
DTP[I].DateSeparator := CallerZVDateTimePicker.DateSeparator;
|
||||||
DTP[I].TrailingSeparator := CallerZVDateTimePicker.TrailingSeparator;
|
DTP[I].TrailingSeparator := CallerZVDateTimePicker.TrailingSeparator;
|
||||||
DTP[I].AutoAdvance := CallerZVDateTimePicker.AutoAdvance;
|
DTP[I].AutoAdvance := CallerZVDateTimePicker.AutoAdvance;
|
||||||
|
DTP[I].CalendarWrapperClass := CallerZVDateTimePicker.CalendarWrapperClass;
|
||||||
end;
|
end;
|
||||||
ZVDateTimePicker1.TextForNullDate := CallerZVDateTimePicker.TextForNullDate;
|
ZVDateTimePicker1.TextForNullDate := CallerZVDateTimePicker.TextForNullDate;
|
||||||
ZVDateTimePicker1.TimeSeparator := CallerZVDateTimePicker.TimeSeparator;
|
ZVDateTimePicker1.TimeSeparator := CallerZVDateTimePicker.TimeSeparator;
|
||||||
|
Reference in New Issue
Block a user