Add property Cascade (patch by teejaydub - #22989)

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@2598 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
zoran-vucenovic
2012-12-07 14:56:48 +00:00
parent e4379b1df0
commit 97df6a8d20
2 changed files with 133 additions and 78 deletions

View File

@ -108,6 +108,7 @@ type
accidentally added in first release. } accidentally added in first release. }
property DateMode; property DateMode;
property UseDefaultSeparators; property UseDefaultSeparators;
property Cascade;
//events: //events:
property OnChange; property OnChange;
property OnCheckBoxChange; property OnCheckBoxChange;

View File

@ -115,6 +115,7 @@ type
TCustomZVDateTimePicker = class(TCustomControl) TCustomZVDateTimePicker = class(TCustomControl)
private private
FCascade: Boolean;
FCenturyFrom, FEffectiveCenturyFrom: Word; FCenturyFrom, FEffectiveCenturyFrom: Word;
FDateDisplayOrder: TDateDisplayOrder; FDateDisplayOrder: TDateDisplayOrder;
FKind: TDateTimeKind; FKind: TDateTimeKind;
@ -341,6 +342,7 @@ type
property Time: TTime read GetTime write SetTime; property Time: TTime read GetTime write SetTime;
property Date: TDate read GetDate write SetDate; property Date: TDate read GetDate write SetDate;
property DateMode: TDTDateMode read FDateMode write SetDateMode; property DateMode: TDTDateMode read FDateMode write SetDateMode;
property Cascade: Boolean read FCascade write FCascade default False;
public public
constructor Create(AOwner: TComponent); override; constructor Create(AOwner: TComponent); override;
@ -401,6 +403,7 @@ type
property Date; property Date;
property Time; property Time;
property UseDefaultSeparators; property UseDefaultSeparators;
property Cascade;
// events: // events:
property OnChange; property OnChange;
property OnCheckBoxChange; property OnCheckBoxChange;
@ -430,6 +433,8 @@ function IsNullDate(DT: TDateTime): Boolean;
implementation implementation
uses DateUtils;
function NumberOfDaysInMonth(const Month, Year: Word): Word; function NumberOfDaysInMonth(const Month, Year: Word): Word;
begin begin
Result := 0; Result := 0;
@ -2059,6 +2064,9 @@ var
N: Word; N: Word;
begin begin
SelectMonth; SelectMonth;
if Cascade then
SetDateTime(IncMonth(DateTime))
else begin
YMD := GetYYYYMMDD(True); YMD := GetYYYYMMDD(True);
if YMD.Month >= 12 then if YMD.Month >= 12 then
@ -2072,6 +2080,7 @@ begin
SetYYYYMMDD(YMD); SetYYYYMMDD(YMD);
end; end;
end;
procedure TCustomZVDateTimePicker.IncreaseYear; procedure TCustomZVDateTimePicker.IncreaseYear;
var var
@ -2092,6 +2101,9 @@ var
YMD: TYMD; YMD: TYMD;
begin begin
SelectDay; SelectDay;
if Cascade then
SetDateTime(IncDay(DateTime))
else begin
YMD := GetYYYYMMDD(True); YMD := GetYYYYMMDD(True);
if YMD.Day >= NumberOfDaysInMonth(YMD.Month, YMD.Year) then if YMD.Day >= NumberOfDaysInMonth(YMD.Month, YMD.Year) then
@ -2101,6 +2113,7 @@ begin
SetYYYYMMDD(YMD); SetYYYYMMDD(YMD);
end; end;
end;
procedure TCustomZVDateTimePicker.DecreaseMonth; procedure TCustomZVDateTimePicker.DecreaseMonth;
var var
@ -2108,6 +2121,9 @@ var
N: Word; N: Word;
begin begin
SelectMonth; SelectMonth;
if Cascade then
SetDateTime(IncMonth(DateTime, -1))
else begin
YMD := GetYYYYMMDD(True); YMD := GetYYYYMMDD(True);
if YMD.Month <= 1 then if YMD.Month <= 1 then
@ -2121,6 +2137,7 @@ begin
SetYYYYMMDD(YMD); SetYYYYMMDD(YMD);
end; end;
end;
procedure TCustomZVDateTimePicker.DecreaseYear; procedure TCustomZVDateTimePicker.DecreaseYear;
var var
@ -2139,6 +2156,9 @@ var
YMD: TYMD; YMD: TYMD;
begin begin
SelectDay; SelectDay;
if Cascade then
SetDateTime(IncDay(DateTime, -1))
else begin
YMD := GetYYYYMMDD(True); YMD := GetYYYYMMDD(True);
if YMD.Day <= 1 then if YMD.Day <= 1 then
@ -2148,12 +2168,16 @@ begin
SetYYYYMMDD(YMD); SetYYYYMMDD(YMD);
end; end;
end;
procedure TCustomZVDateTimePicker.IncreaseHour; procedure TCustomZVDateTimePicker.IncreaseHour;
var var
HMSMs: THMSMs; HMSMs: THMSMs;
begin begin
SelectHour; SelectHour;
if Cascade then
SetDateTime(IncHour(DateTime))
else begin
HMSMs := GetHMSMs(True); HMSMs := GetHMSMs(True);
if HMSMs.Hour >= 23 then if HMSMs.Hour >= 23 then
@ -2163,12 +2187,16 @@ begin
SetHMSMs(HMSMs); SetHMSMs(HMSMs);
end; end;
end;
procedure TCustomZVDateTimePicker.IncreaseMinute; procedure TCustomZVDateTimePicker.IncreaseMinute;
var var
HMSMs: THMSMs; HMSMs: THMSMs;
begin begin
SelectMinute; SelectMinute;
if Cascade then
SetDateTime(IncMinute(DateTime))
else begin
HMSMs := GetHMSMs(True); HMSMs := GetHMSMs(True);
if HMSMs.Minute >= 59 then if HMSMs.Minute >= 59 then
@ -2178,12 +2206,16 @@ begin
SetHMSMs(HMSMs); SetHMSMs(HMSMs);
end; end;
end;
procedure TCustomZVDateTimePicker.IncreaseSecond; procedure TCustomZVDateTimePicker.IncreaseSecond;
var var
HMSMs: THMSMs; HMSMs: THMSMs;
begin begin
SelectSecond; SelectSecond;
if Cascade then
SetDateTime(IncSecond(DateTime))
else begin
HMSMs := GetHMSMs(True); HMSMs := GetHMSMs(True);
if HMSMs.Second >= 59 then if HMSMs.Second >= 59 then
@ -2193,12 +2225,16 @@ begin
SetHMSMs(HMSMs); SetHMSMs(HMSMs);
end; end;
end;
procedure TCustomZVDateTimePicker.IncreaseMiliSec; procedure TCustomZVDateTimePicker.IncreaseMiliSec;
var var
HMSMs: THMSMs; HMSMs: THMSMs;
begin begin
SelectMiliSec; SelectMiliSec;
if Cascade then
SetDateTime(IncMilliSecond(DateTime))
else begin
HMSMs := GetHMSMs(True); HMSMs := GetHMSMs(True);
if HMSMs.MiliSec >= 999 then if HMSMs.MiliSec >= 999 then
@ -2208,12 +2244,16 @@ begin
SetHMSMs(HMSMs); SetHMSMs(HMSMs);
end; end;
end;
procedure TCustomZVDateTimePicker.DecreaseHour; procedure TCustomZVDateTimePicker.DecreaseHour;
var var
HMSMs: THMSMs; HMSMs: THMSMs;
begin begin
SelectHour; SelectHour;
if Cascade then
SetDateTime(IncHour(DateTime, -1))
else begin
HMSMs := GetHMSMs(True); HMSMs := GetHMSMs(True);
if HMSMs.Hour <= 0 then if HMSMs.Hour <= 0 then
@ -2223,12 +2263,16 @@ begin
SetHMSMs(HMSMs); SetHMSMs(HMSMs);
end; end;
end;
procedure TCustomZVDateTimePicker.DecreaseMinute; procedure TCustomZVDateTimePicker.DecreaseMinute;
var var
HMSMs: THMSMs; HMSMs: THMSMs;
begin begin
SelectMinute; SelectMinute;
if Cascade then
SetDateTime(IncMinute(DateTime, -1))
else begin
HMSMs := GetHMSMs(True); HMSMs := GetHMSMs(True);
if HMSMs.Minute <= 0 then if HMSMs.Minute <= 0 then
@ -2238,12 +2282,16 @@ begin
SetHMSMs(HMSMs); SetHMSMs(HMSMs);
end; end;
end;
procedure TCustomZVDateTimePicker.DecreaseSecond; procedure TCustomZVDateTimePicker.DecreaseSecond;
var var
HMSMs: THMSMs; HMSMs: THMSMs;
begin begin
SelectSecond; SelectSecond;
if Cascade then
SetDateTime(IncSecond(DateTime, -1))
else begin
HMSMs := GetHMSMs(True); HMSMs := GetHMSMs(True);
if HMSMs.Second <= 0 then if HMSMs.Second <= 0 then
@ -2253,12 +2301,16 @@ begin
SetHMSMs(HMSMs); SetHMSMs(HMSMs);
end; end;
end;
procedure TCustomZVDateTimePicker.DecreaseMiliSec; procedure TCustomZVDateTimePicker.DecreaseMiliSec;
var var
HMSMs: THMSMs; HMSMs: THMSMs;
begin begin
SelectMiliSec; SelectMiliSec;
if Cascade then
SetDateTime(IncMilliSecond(DateTime, -1))
else begin
HMSMs := GetHMSMs(True); HMSMs := GetHMSMs(True);
if HMSMs.MiliSec <= 0 then if HMSMs.MiliSec <= 0 then
@ -2268,6 +2320,7 @@ begin
SetHMSMs(HMSMs); SetHMSMs(HMSMs);
end; end;
end;
procedure TCustomZVDateTimePicker.ChangeAMPM; procedure TCustomZVDateTimePicker.ChangeAMPM;
var var
@ -3253,6 +3306,7 @@ begin
FTextEnabled := True; FTextEnabled := True;
FCalendarForm := nil; FCalendarForm := nil;
FDoNotArrangeControls := True; FDoNotArrangeControls := True;
FCascade := False;
AdjustEffectiveDateDisplayOrder; AdjustEffectiveDateDisplayOrder;