-
Notifications
You must be signed in to change notification settings - Fork 1
/
VCL.ODPopCal.pas
1074 lines (976 loc) · 32.3 KB
/
VCL.ODPopCal.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
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
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{
Copyright (c) 1998-2015
Orbital Decisions:- My Power Station Technology (Pty) Ltd
P.O.Box 1080, Milnerton 7435, South Africa
components@mypowerstation.biz
http://www.orbital.co.za/text/prodlist.htm
Use at your own risk!
}
unit VCL.ODPopCal;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Buttons, ExtCtrls, VCL.ODCalend;
type
TODVCLCalendarForm = class(TForm)
Panel1: TPanel;
Panel2: TPanel;
OKBtn: TBitBtn;
CancelBtn: TBitBtn;
procedure btnClearClick(Sender: TObject);
procedure OKBtnClick(Sender: TObject);
private
FCalendar: TODVCLCalendar;
FOnDayDblClick: TODVCLDateEvent;
procedure Change(Sender: TObject);
public
constructor Create(AOwner: TComponent); override;
procedure DayDblClick(Sender: TObject; ADate: TDateTime);
property Calendar: TODVCLCalendar read FCalendar write FCalendar;
property OnDayDblClick: TODVCLDateEvent read FOnDayDblClick write FOnDayDblClick;
end;
TODVCLCalendarDialog = class(TComponent)
private
FForm: TODVCLCalendarForm;
FMonthNames: TODVCLMonthNames;
FHeaders: TODVCLCalendarHeaders;
FCaption, FDateFormat: string;
FDialogHeight, FDialogWidth: Integer;
FStartDate, FFinishDate: TDateTime;
FDisplayYear, FDisplayMonth{, FDisplayWeek}: Integer;
FDayColor, FTodayColor, FRangeColor, FWeekColor: TColor;
FTitleFont, FStartFont, FFinishFont, FDateFont: TFont;
FPrevYearGlyph, FNextYearGlyph, FPrevMonthGlyph, FNextMonthGlyph: TBitmap;
FAutoPage, FSingleDate, FShowStatus, FShowYearBtns, FStartOnMonday,
FPlain, FUseTime, FShowTimeBtns, FShowCurrent, FShowWeeks: Boolean;
FBevelEdge: TPanelBevel;
FOnChange: TNotifyEvent;
FOnDayDblClick: TODVCLDateEvent;
FOnStartClick, FOnFinishClick: TODVCLSelectDateEvent;
FOnSelectYear: TODVCLSelectYearEvent;
FOnSetupDay: TODVCLSetupDayEvent;
function GetAbout: string;
procedure SetAbout(Value: string);
function GetDisplayDate: TDateTime;
procedure SetDisplayDate(Value: TDateTime);
procedure SetDisplayYear(Value: Integer);
procedure SetDisplayMonth(Value: Integer);
// procedure SetDisplayWeek(Value: Integer);
procedure SetTitleFont(Value: TFont);
procedure SetStartFont(Value: TFont);
procedure SetFinishFont(Value: TFont);
procedure SetDateFont(Value: TFont);
procedure SetPrevYearGlyph(Value: TBitmap);
procedure SetNextYearGlyph(Value: TBitmap);
procedure SetPrevMonthGlyph(Value: TBitmap);
procedure SetNextMonthGlyph(Value: TBitmap);
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
function Execute: Boolean;
function DaysInMonth(AMonth, AYear: Integer): Integer;
function WeeksInYear(AYear: Integer): Integer;
function WeekToMonth(AWeek: Integer): Integer;
function MonthToWeek(AMonth: Integer): Integer;
property StartDate: TDateTime read FStartDate write FStartDate;
property FinishDate: TDateTime read FFinishDate write FFinishDate;
property DisplayDate: TDateTime read GetDisplayDate write SetDisplayDate;
published
property About: string read GetAbout write SetAbout stored False;
property Caption: string read FCaption write FCaption;
property DialogHeight: Integer read FDialogHeight write FDialogHeight default 250;
property DialogWidth: Integer read FDialogWidth write FDialogWidth default 240;
property DisplayYear: Integer read FDisplayYear write SetDisplayYear;
property DisplayMonth: Integer read FDisplayMonth write SetDisplayMonth;
// property DisplayWeek: Integer read FDisplayWeek write SetDisplayWeek;
property DayColor: TColor read FDayColor write FDayColor default clWindow;
property TodayColor: TColor read FTodayColor write FTodayColor default clBlue;
property RangeColor: TColor read FRangeColor write FRangeColor default clAqua;
property WeekColor: TColor read FWeekColor write FWeekColor default clWhite;
property TitleFont: TFont read FTitleFont write SetTitleFont;
property StartFont: TFont read FStartFont write SetStartFont;
property FinishFont: TFont read FFinishFont write SetFinishFont;
property DateFont: TFont read FDateFont write SetDateFont;
property PrevYearGlyph: TBitmap read FPrevYearGlyph write SetPrevYearGlyph;
property NextYearGlyph: TBitmap read FNextYearGlyph write SetNextYearGlyph;
property PrevMonthGlyph: TBitmap read FPrevMonthGlyph write SetPrevMonthGlyph;
property NextMonthGlyph: TBitmap read FNextMonthGlyph write SetNextMonthGlyph;
property DateFormat: string read FDateFormat write FDateFormat;
property MonthNames: TODVCLMonthNames read FMonthNames write FMonthNames;
property Headers: TODVCLCalendarHeaders read FHeaders write FHeaders;
property BevelEdge: TPanelBevel read FBevelEdge write FBevelEdge default bvRaised;
property SingleDate: Boolean read FSingleDate write FSingleDate default False;
property ShowCurrent: Boolean read FShowCurrent write FShowCurrent default True;
property ShowStatus: Boolean read FShowStatus write FShowStatus default True;
property ShowYearBtns: Boolean read FShowYearBtns write FShowYearBtns default True;
property ShowTimeBtns: Boolean read FShowTimeBtns write FShowTimeBtns default True;
property ShowWeeks: Boolean read FShowWeeks write FShowWeeks default True;
property AutoPage: Boolean read FAutoPage write FAutoPage default True;
property Plain: Boolean read FPlain write FPlain default False;
property StartOnMonday: Boolean read FStartOnMonday write FStartOnMonday default False;
property UseTime: Boolean read FUseTime write FUseTime default False;
property OnChange: TNotifyEvent read FOnChange write FOnChange;
property OnDayDblClick: TODVCLDateEvent read FOnDayDblClick write FOnDayDblClick;
property OnStartClick: TODVCLSelectDateEvent read FOnStartClick write FOnStartClick;
property OnFinishClick: TODVCLSelectDateEvent read FOnFinishClick write FOnFinishClick;
property OnSelectYear: TODVCLSelectYearEvent read FOnSelectYear write FOnSelectYear;
property OnSetupDay: TODVCLSetupDayEvent read FOnSetupDay write FOnSetupDay;
end;
TODVCLPopupButton = class(TSpeedButton)
private
procedure CMDesignHitTest(var Msg: TCMDesignHitTest); message CM_DESIGNHITTEST;
end;
TODVCLPopupCalendar = class(TCustomPanel)
private
FMonthNames: TODVCLMonthNames;
FHeaders: TODVCLCalendarHeaders;
FDateFormat, FSeperator, FPopupCaption, FTimeFormat: string;
FStartDate, FFinishDate: TDateTime;
FDisplayYear, FDisplayMonth{, FDisplayWeek}: Integer;
FDayColor, FTodayColor, FRangeColor, FWeekColor: TColor;
FTitleFont, FStartFont, FFinishFont, FDateFont: TFont;
FPrevYearGlyph, FNextYearGlyph, FPrevMonthGlyph, FNextMonthGlyph: TBitmap;
FAutoPage, FSingleDate, FShowStatus, FShowYearBtns, FStartOnMonday,
FPlain, FUseTime, FShowTimeBtns, FShowCurrent, FShowWeeks: Boolean;
FBevelEdge: TPanelBevel;
FPopupHeight, FPopupWidth: Integer;
FOnDayDblClick: TODVCLDateEvent;
FOnStartClick, FOnFinishClick: TODVCLSelectDateEvent;
FOnSelectYear: TODVCLSelectYearEvent;
FOnSetupDay: TODVCLSetupDayEvent;
FOnChange, FOnPopup: TNotifyEvent;
function GetAbout: string;
procedure SetAbout(Value: string);
function GetDisplayDate: TDateTime;
procedure SetDisplayDate(Value: TDateTime);
procedure SetDisplayYear(Value: Integer);
procedure SetDisplayMonth(Value: Integer);
// procedure SetDisplayWeek(Value: Integer);
procedure SetTitleFont(Value: TFont);
procedure SetStartFont(Value: TFont);
procedure SetFinishFont(Value: TFont);
procedure SetDateFont(Value: TFont);
function GetText: string;
function GetGlyph: TBitmap;
procedure SetGlyph(Value: TBitmap);
procedure SetPrevYearGlyph(Value: TBitmap);
procedure SetNextYearGlyph(Value: TBitmap);
procedure SetPrevMonthGlyph(Value: TBitmap);
procedure SetNextMonthGlyph(Value: TBitmap);
procedure SetStartDate(Value: TDateTime);
procedure SetFinishDate(Value: TDateTime);
procedure SetSingleDate(Value: Boolean);
procedure SetDateFormat(const Value: string);
procedure SetSeperator(const Value: string);
procedure SetUseTime(Value: Boolean);
procedure ReadStartDate(Reader: TReader);
procedure WriteStartDate(Writer: TWriter);
procedure ReadFinishDate(Reader: TReader);
procedure WriteFinishDate(Writer: TWriter);
protected
FForm: TODVCLCalendarForm;
FText: TEdit;
FLabel: TLabel;
FButton: TSpeedButton;
StoreDates: Boolean;
procedure SetEnabled(Value: Boolean);
procedure DefineProperties(Filer: TFiler); override;
procedure Resize; override;
procedure DoEnter; override;
procedure Change(Sender: TObject); virtual;
procedure StartClick(Sender: TObject; var ADate: TDateTime); virtual;
procedure FinishClick(Sender: TObject; var ADate: TDateTime); virtual;
procedure SelectYear(Sender: TObject; Year: Integer;
var YearStart, YearFinish: TDateTime); virtual;
procedure SetupDay(Sender: TObject; ADate: TDateTime;
var AColor: TColor; var AHint: string); virtual;
procedure SetText;
procedure ButtonClick(Sender: TObject); virtual;
procedure TextChange(Sender: TObject);
procedure SetOnMouseDown(Value: TMouseEvent);
procedure SetOnMouseUp(Value: TMouseEvent);
function GetOnMouseDown: TMouseEvent;
function GetOnMouseUp: TMouseEvent;
function GetEnabled: Boolean;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Loaded; override;
procedure Clear; // Added By AG 2000/07/11 - See proc for more info.
function DaysInMonth(AMonth, AYear: Integer): Integer;
function WeeksInYear(AYear: Integer): Integer;
function WeekToMonth(AWeek: Integer): Integer;
function MonthToWeek(AMonth: Integer): Integer;
property StartDate: TDateTime read FStartDate write SetStartDate;
property FinishDate: TDateTime read FFinishDate write SetFinishDate;
property DisplayDate: TDateTime read GetDisplayDate write SetDisplayDate;
property Text: string read GetText;
published
property About: string read GetAbout write SetAbout stored False;
property DateFormat: string read FDateFormat write SetDateFormat;
property Seperator: string read FSeperator write SetSeperator;
property PopupCaption: string read FPopupCaption write FPopupCaption;
property PopupHeight: Integer read FPopupHeight write FPopupHeight default 250;
property PopupWidth: Integer read FPopupWidth write FPopupWidth default 240;
property DisplayYear: Integer read FDisplayYear write SetDisplayYear;
property DisplayMonth: Integer read FDisplayMonth write SetDisplayMonth;
// property DisplayWeek: Integer read FDisplayWeek write SetDisplayWeek;
property DayColor: TColor read FDayColor write FDayColor default clWindow;
property TodayColor: TColor read FTodayColor write FTodayColor default clBlue;
property RangeColor: TColor read FRangeColor write FRangeColor default clAqua;
property WeekColor: TColor read FWeekColor write FWeekColor default clWhite;
property TitleFont: TFont read FTitleFont write SetTitleFont;
property StartFont: TFont read FStartFont write SetStartFont;
property FinishFont: TFont read FFinishFont write SetFinishFont;
property DateFont: TFont read FDateFont write SetDateFont;
property MonthNames: TODVCLMonthNames read FMonthNames write FMonthNames;
property Headers: TODVCLCalendarHeaders read FHeaders write FHeaders;
property BevelEdge: TPanelBevel read FBevelEdge write FBevelEdge default bvRaised;
property Plain: Boolean read FPlain write FPlain default False;
property SingleDate: Boolean read FSingleDate write SetSingleDate default False;
property ShowCurrent: Boolean read FShowCurrent write FShowCurrent default True;
property ShowStatus: Boolean read FShowStatus write FShowStatus default True;
property ShowYearBtns: Boolean read FShowYearBtns write FShowYearBtns default True;
property ShowTimeBtns: Boolean read FShowTimeBtns write FShowTimeBtns default True;
property ShowWeeks: Boolean read FShowWeeks write FShowWeeks default True;
property StartOnMonday: Boolean read FStartOnMonday write FStartOnMonday default False;
property AutoPage: Boolean read FAutoPage write FAutoPage default True;
property Enabled: Boolean read GetEnabled write SetEnabled default True;
property Glyph: TBitmap read GetGlyph write SetGlyph;
property PrevYearGlyph: TBitmap read FPrevYearGlyph write SetPrevYearGlyph;
property NextYearGlyph: TBitmap read FNextYearGlyph write SetNextYearGlyph;
property PrevMonthGlyph: TBitmap read FPrevMonthGlyph write SetPrevMonthGlyph;
property NextMonthGlyph: TBitmap read FNextMonthGlyph write SetNextMonthGlyph;
property UseTime: Boolean read FUseTime write SetUseTime default False;
property TimeFormat: string read FTimeFormat write FTimeFormat;
property Color;
property Font;
property ParentColor;
// property ParentCtl3D;
property ParentFont;
property ParentShowHint;
property ShowHint;
property TabOrder;
property TabStop;
property Visible;
property OnChange: TNotifyEvent read FOnChange write FOnChange;
property OnDayDblClick: TODVCLDateEvent read FOnDayDblClick write FOnDayDblClick;
property OnStartClick: TODVCLSelectDateEvent read FOnStartClick write FOnStartClick;
property OnFinishClick: TODVCLSelectDateEvent read FOnFinishClick write FOnFinishClick;
property OnSelectYear: TODVCLSelectYearEvent read FOnSelectYear write FOnSelectYear;
property OnSetupDay: TODVCLSetupDayEvent read FOnSetupDay write FOnSetupDay;
property OnPopup: TNotifyEvent read FOnPopup write FOnPopup;
property OnMouseDown: TMouseEvent read GetOnMouseDown write SetOnMouseDown; // AG 00/07/11
property OnMouseUp: TMouseEvent read GetOnMouseUp write SetOnMouseUp; // AG 00/07/11
property OnEnter;
property OnExit;
property OnResize;
end;
implementation
{$R *.DFM}
//TODVCLCalendarForm
constructor TODVCLCalendarForm.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FCalendar := TODVCLCalendar.Create(Self);
with FCalendar do
begin
Parent := Self;
Align := alClient;
OnChange := Change;
OnDayDblClick := DayDblClick;
end;
end;
procedure TODVCLCalendarForm.Change(Sender: TObject);
begin
OKBtn.Enabled := FCalendar.FinishDate > 0;
end;
procedure TODVCLCalendarForm.DayDblClick(Sender: TObject; ADate: TDateTime);
begin
if Assigned(FOnDayDblClick) then
FOnDayDblClick(Owner, ADate);
if FCalendar.SingleDate then
ModalResult := mrOK;
end;
procedure TODVCLCalendarForm.OKBtnClick(Sender: TObject);
begin
end;
//TODVCLCalendarDialog
constructor TODVCLCalendarDialog.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
if not (csDesigning in ComponentState) then
FForm := TODVCLCalendarForm.Create(Application);
FMonthNames := TODVCLMonthNames.Create;
FHeaders := TODVCLCalendarHeaders.Create;
FTitleFont := TFont.Create;
FStartFont := TFont.Create;
FFinishFont := TFont.Create;
FDateFont := TFont.Create;
FPrevYearGlyph := TBitmap.Create;
FNextYearGlyph := TBitmap.Create;
FPrevMonthGlyph := TBitmap.Create;
FNextMonthGlyph := TBitmap.Create;
FDialogHeight := 250;
FDialogWidth := 240;
FCaption := 'Select Date Range';
FDateFormat := 'dddd, mmm d, yyyy';
FDayColor := clWindow;
FTodayColor := clBlue;
FRangeColor := clAqua;
FWeekColor := clWhite;
FBevelEdge := bvRaised;
FShowStatus := True;
FShowCurrent := True;
FShowYearBtns := True;
FShowTimeBtns := True;
FShowWeeks := True;
FAutoPage := True;
SetDisplayDate(Date);
end;
destructor TODVCLCalendarDialog.Destroy;
begin
FHeaders.Free;
FMonthNames.Free;
FTitleFont.Free;
FStartFont.Free;
FFinishFont.Free;
FDateFont.Free;
FPrevYearGlyph.Free;
FNextYearGlyph.Free;
FPrevMonthGlyph.Free;
FNextMonthGlyph.Free;
inherited Destroy;
end;
function TODVCLCalendarDialog.Execute: Boolean;
begin
with FForm.Calendar do
begin
MonthNames.Assign(FMonthNames);
Headers.Assign(FHeaders);
OnStartClick := FOnStartClick;
OnFinishClick := FOnFinishClick;
OnSelectYear := FOnSelectYear;
OnSetupDay := FOnSetupDay;
DayColor := FDayColor;
TodayColor := FTodayColor;
RangeColor := FRangeColor;
WeekColor := FWeekColor;
TitleFont := FTitleFont;
StartFont := FStartFont;
FinishFont := FFinishFont;
DateFont := FDateFont;
PrevYearGlyph := FPrevYearGlyph;
NextYearGlyph := FNextYearGlyph;
PrevMonthGlyph := FPrevMonthGlyph;
NextMonthGlyph := FNextMonthGlyph;
BevelEdge := FBevelEdge;
Plain := FPlain;
SingleDate := FSingleDate;
ShowCurrent := FShowCurrent;
ShowStatus := FShowStatus;
ShowYearBtns := FShowYearBtns;
ShowTimeBtns := FShowTimeBtns;
ShowWeeks := FShowWeeks;
StartOnMonday := FStartOnMonday;
AutoPage := FAutoPage;
DateFormat := FDateFormat;
DisplayYear := FDisplayYear;
DisplayMonth := FDisplayMonth;
// DisplayWeek := FDisplayWeek;
UseTime := FUseTime;
if StartDate > 0 then
DisplayDate := StartDate
else if ShowCurrent then
DisplayDate := Date;
StartDate := FStartDate;
if not FSingleDate then
Finishdate := FFinishDate;
end;
with FForm do
begin
{ OnStartChange := FOnStartChange;
OnFinishChange := FOnFinishChange;}
OnChange := FOnChange;
OnDayDblClick := FOnDayDblClick;
Caption := FCaption;
Height := FDialogHeight;
Width := FDialogWidth;
Result := ShowModal = ID_OK;
if Result then
begin
FStartDate := Calendar.StartDate;
FFinishDate := Calendar.FinishDate;
end
else
begin
Calendar.StartDate := FStartDate;
Calendar.FinishDate := FFinishDate;
end;
end;
end;
function TODVCLCalendarDialog.DaysInMonth(AMonth, AYear: Integer): Integer;
begin
Result := FForm.Calendar.DaysInMonth(AMonth, AYear);
end;
function TODVCLCalendarDialog.WeeksInYear(AYear: Integer): Integer;
begin
Result := FForm.Calendar.WeeksInYear(AYear);
end;
function TODVCLCalendarDialog.WeekToMonth(AWeek: Integer): Integer;
begin
Result := FForm.Calendar.WeekToMonth(AWeek);
end;
function TODVCLCalendarDialog.MonthToWeek(AMonth: Integer): Integer;
begin
Result := FForm.Calendar.MonthToWeek(AMonth);
end;
function TODVCLCalendarDialog.GetDisplayDate: TDateTime;
begin
Result := EncodeDate(FDisplayYear, FDisplayMonth, 1);
end;
procedure TODVCLCalendarDialog.SetDisplayDate(Value: TDateTime);
var
yr, mo, dy: Word;
begin
DecodeDate(Value, yr, mo, dy);
FDisplayYear := yr;
FDisplayMonth := mo;
FShowCurrent := False;
end;
procedure TODVCLCalendarDialog.SetDisplayYear(Value: Integer);
begin
if Value < 1900 then FDisplayYear := 1900
else if Value > 2100 then FDisplayYear := 2100
else FDisplayYear := Value;
FShowCurrent := False;
end;
procedure TODVCLCalendarDialog.SetDisplayMonth(Value: Integer);
begin
if Value < 1 then FDisplayMonth := 1
else if Value > 12 then FDisplayMonth := 12
else FDisplayMonth := Value;
FShowCurrent := False;
end;
{
procedure TODVCLCalendarDialog.SetDisplayWeek(Value: Integer);
var
tw: Integer;
begin
tw := FCalendar.WeeksInYear(FDisplayYear);
if Value < 1 then Value := 1
else if Value > tw then Value := tw;
FDisplayMonth := FForm.Calendar.WeekToMonth(Value);
FShowCurrent := False;
end;
}
procedure TODVCLCalendarDialog.SetTitleFont(Value: TFont);
begin
FTitleFont.Assign(Value);
end;
procedure TODVCLCalendarDialog.SetStartFont(Value: TFont);
begin
FStartFont.Assign(Value);
end;
procedure TODVCLCalendarDialog.SetFinishFont(Value: TFont);
begin
FFinishFont.Assign(Value);
end;
procedure TODVCLCalendarDialog.SetDateFont(Value: TFont);
begin
FDateFont.Assign(Value);
end;
procedure TODVCLCalendarDialog.SetPrevYearGlyph(Value: TBitmap);
begin
FPrevYearGlyph.Assign(Value);
end;
procedure TODVCLCalendarDialog.SetNextYearGlyph(Value: TBitmap);
begin
FNextYearGlyph.Assign(Value);
end;
procedure TODVCLCalendarDialog.SetPrevMonthGlyph(Value: TBitmap);
begin
FPrevMonthGlyph.Assign(Value);
end;
procedure TODVCLCalendarDialog.SetNextMonthGlyph(Value: TBitmap);
begin
FNextMonthGlyph.Assign(Value);
end;
function TODVCLCalendarDialog.GetAbout: string;
begin
Result := 'Version ' + ODVCLCalendarVersion;
end;
procedure TODVCLCalendarDialog.SetAbout(Value: string);
begin
{do nothing}
end;
//TODVCLPopupButton
procedure TODVCLPopupButton.CMDesignHitTest(var Msg: TCMDesignHitTest);
begin
if Parent.CanFocus and
PtInRect(Rect(0, 0, Width, Height), SmallPointToPoint(Msg.Pos)) then
Msg.Result := 1;
end;
//TODVCLPopupCalendar
constructor TODVCLPopupCalendar.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
Width := 320;
Height := 21;
BevelOuter := bvNone;
BorderStyle := bsSingle;
Color := clWindow;
ControlStyle := ControlStyle - [csAcceptsControls];
FMonthNames := TODVCLMonthNames.Create;
FHeaders := TODVCLCalendarHeaders.Create;
FButton := TODVCLPopupButton.Create(Self);
with FButton do
begin
Parent := Self;
Font.Style := [fsBold];
Caption := '...';
GroupIndex := 1;
AllowAllUp := True;
Layout := blGlyphTop;
OnClick := ButtonClick;
end;
FText := TEdit.Create(Self);
with FText do
begin
Parent := Self;
AutoSize := False;
ReadOnly := True;
BorderStyle := bsNone;
Top := 1;
Left := 1;
Height := 16;
OnChange := TextChange;
end;
FLabel := TLabel.Create(Self);
with FLabel do
begin
Parent := Self;
Width := 1;
Color := clBtnFace;
end;
Resize;
if not (csDesigning in ComponentState) then
FForm := TODVCLCalendarForm.Create(Self);
FTitleFont := TFont.Create;
FStartFont := TFont.Create;
FFinishFont := TFont.Create;
FDateFont := TFont.Create;
FPrevYearGlyph := TBitmap.Create;
FNextYearGlyph := TBitmap.Create;
FPrevMonthGlyph := TBitmap.Create;
FNextMonthGlyph := TBitmap.Create;
FPopupHeight := 250;
FPopupWidth := 240;
FPopupCaption := 'Select Date Range';
FDateFormat := 'dddd, mmm d, yyyy';
FTimeFormat := 'hh:mm';
FSeperator := ' - ';
FDayColor := clWindow;
FTodayColor := clBlue;
FRangeColor := clAqua;
FWeekColor := clWhite;
FBevelEdge := bvRaised;
FShowCurrent := True;
FShowStatus := True;
FShowYearBtns := True;
FShowTimeBtns := True;
FShowWeeks := True;
FAutoPage := True;
SetDisplayDate(Date);
StoreDates := True;
end;
destructor TODVCLPopupCalendar.Destroy;
begin
FHeaders.Free;
FMonthNames.Free;
FTitleFont.Free;
FStartFont.Free;
FFinishFont.Free;
FDateFont.Free;
FPrevYearGlyph.Free;
FNextYearGlyph.Free;
FPrevMonthGlyph.Free;
FNextMonthGlyph.Free;
inherited Destroy;
end;
procedure TODVCLPopupCalendar.Loaded;
begin
inherited Loaded;
Resize;
if not FButton.Glyph.Empty then
SetGlyph(FButton.Glyph)
end;
procedure TODVCLPopupCalendar.Clear;
begin
// Added by Alan Givati - Clears FText EditBox and resets start+finish dates.
// This procedure used to be called ClearEdit
// ClearEdit only cleared the EditBox - the actual
// start and finish dates were not being reset.
FText.Text := '';
SetStartDate(0);
SetFinishDate(0);
SetDisplayDate(Date);
end;
function TODVCLPopupCalendar.DaysInMonth(AMonth, AYear: Integer): Integer;
begin
Result := FForm.Calendar.DaysInMonth(AMonth, AYear);
end;
function TODVCLPopupCalendar.WeeksInYear(AYear: Integer): Integer;
begin
Result := FForm.Calendar.WeeksInYear(AYear);
end;
function TODVCLPopupCalendar.WeekToMonth(AWeek: Integer): Integer;
begin
Result := FForm.Calendar.WeekToMonth(AWeek);
end;
function TODVCLPopupCalendar.MonthToWeek(AMonth: Integer): Integer;
begin
Result := FForm.Calendar.MonthToWeek(AMonth);
end;
procedure TODVCLPopupCalendar.DefineProperties(Filer: TFiler);
begin
inherited DefineProperties(Filer);
if StoreDates then
begin
Filer.DefineProperty('StartDate',
ReadStartDate, WriteStartDate, FStartDate > 0);
Filer.DefineProperty('FinishDate',
ReadFinishDate, WriteFinishDate, FFinishDate > 0);
end;
end;
procedure TODVCLPopupCalendar.ReadStartDate;
begin
SetStartDate(Reader.ReadFloat);
end;
procedure TODVCLPopupCalendar.WriteStartDate;
begin
Writer.WriteFloat(FStartDate);
end;
procedure TODVCLPopupCalendar.ReadFinishDate;
begin
SetFinishDate(Reader.ReadFloat);
end;
procedure TODVCLPopupCalendar.WriteFinishDate;
begin
Writer.WriteFloat(FFinishDate);
end;
procedure TODVCLPopupCalendar.ButtonClick(Sender: TObject);
begin
SetFocus;
if Assigned(FOnPopup) then FOnPopup(Self);
if FForm = nil then
FForm := TODVCLCalendarForm.Create(Application);
with FForm.Calendar do
begin
MonthNames.Assign(FMonthNames);
Headers.Assign(FHeaders);
OnStartClick := StartClick;
OnFinishClick := FinishClick;
// OnDayDblClick := FOnDayDblClick;
OnSelectYear := SelectYear;
OnSetupDay := SetupDay;
DisplayYear := FDisplayYear;
DisplayMonth := FDisplayMonth;
// DisplayWeek := FDisplayWeek;
DayColor := FDayColor;
TodayColor := FTodayColor;
RangeColor := FRangeColor;
WeekColor := FWeekColor;
TitleFont := FTitleFont;
StartFont := FStartFont;
FinishFont := FFinishFont;
DateFont := FDateFont;
PrevYearGlyph := FPrevYearGlyph;
NextYearGlyph := FNextYearGlyph;
PrevMonthGlyph := FPrevMonthGlyph;
NextMonthGlyph := FNextMonthGlyph;
BevelEdge := FBevelEdge;
Plain := FPlain;
SingleDate := FSingleDate;
ShowCurrent := FShowCurrent;
ShowStatus := FShowStatus;
ShowYearBtns := FShowYearBtns;
ShowTimeBtns := FShowTimeBtns;
ShowWeeks := FShowWeeks;
StartOnMonday := FStartOnMonday;
AutoPage := FAutoPage;
DateFormat := FDateFormat;
UseTime := FUseTime;
if FStartDate > 0 then
DisplayDate := FStartDate
else if ShowCurrent then
DisplayDate := Date;
StartDate := FStartDate;
if not FSingleDate then
FinishDate := FFinishDate;
end;
with FForm do
begin
Height := FPopupHeight;
Width := FPopupWidth;
Caption := FPopupCaption;
ShowHint := ShowHint;
OnDayDblClick := FOnDayDblClick;
end;
if FForm.ShowModal = ID_OK then
begin
if (FStartDate <> FForm.Calendar.StartDate) or
(FFinishDate <> FForm.Calendar.FinishDate) then
begin
FStartDate := FForm.Calendar.StartDate;
FFinishDate := FForm.Calendar.FinishDate;
SetText;
end;
end
else
begin
FForm.Calendar.StartDate := FStartDate;
FForm.Calendar.FinishDate := FFinishDate;
end;
if csDesigning in ComponentState then
begin
FForm.Free;
FForm := nil;
end;
FButton.Down := False;
end;
procedure TODVCLPopupCalendar.TextChange(Sender: TObject);
begin
if Assigned(FOnChange) then FOnChange(Self);
end;
procedure TODVCLPopupCalendar.Resize;
begin
inherited Resize;
FButton.Height := Height - 4;
FButton.Width := FButton.Height;
FButton.Left := Width - FButton.Width - 4;
FText.Top := (FButton.Height - FText.Height + 1) div 2;
FText.Width := Width - FButton.Width - 6;
FLabel.Height := FButton.Height;
FLabel.Left := FButton.Left - 1;
end;
procedure TODVCLPopupCalendar.DoEnter;
begin
inherited DoEnter;
FText.SetFocus;
end;
procedure TODVCLPopupCalendar.Change(Sender: TObject);
begin
if Assigned(FOnChange) then FOnChange(Self);
end;
procedure TODVCLPopupCalendar.StartClick(Sender: TObject; var ADate: TDateTime);
begin
if Assigned(FOnStartClick) then
FOnStartClick(Self, ADate);
end;
procedure TODVCLPopupCalendar.FinishClick(Sender: TObject; var ADate: TDateTime);
begin
if Assigned(FOnFinishClick) then
FOnFinishClick(Self, ADate);
end;
procedure TODVCLPopupCalendar.SelectYear(Sender: TObject; Year: Integer;
var YearStart, YearFinish: TDateTime);
begin
if Assigned(FOnSelectYear) then
FOnSelectYear(Self, Year, YearStart, YearFinish);
end;
procedure TODVCLPopupCalendar.SetupDay(Sender: TObject; ADate: TDateTime;
var AColor: TColor; var AHint: string);
begin
if Assigned(FOnSetupDay) then
FOnSetupDay(Self, ADate, AColor, AHint);
end;
function TODVCLPopupCalendar.GetText: string;
begin
Result := FText.Text;
end;
procedure TODVCLPopupCalendar.SetStartDate(Value: TDateTime);
begin
FStartDate := Value;
if FStartDate > FFinishDate then
FFinishDate := FStartDate;
SetText;
end;
procedure TODVCLPopupCalendar.SetFinishDate(Value: TDateTime);
begin
FFinishDate := Value;
if FFinishDate < FStartDate then
FStartDate := FFinishDate;
SetText;
end;
procedure TODVCLPopupCalendar.SetDateFormat(const Value: string);
begin
FDateFormat := Value;
if not (csLoading in ComponentState) then SetText;
end;
procedure TODVCLPopupCalendar.SetSeperator(const Value: string);
begin
FSeperator := Value;
if not (csLoading in ComponentState) then SetText;
end;
procedure TODVCLPopupCalendar.SetUseTime(Value: Boolean);
begin
FUseTime := Value;
SetText;
end;
procedure TODVCLPopupCalendar.SetText;
var
fs: string;
begin
if FUseTime then
fs := FDateFormat + ' ' + FTimeFormat
else
fs := FDateFormat;
if FStartDate = 0 then
FText.Text := ''
else if FSingleDate then
FText.Text := FormatDateTime(fs, FStartDate)
else
FText.Text := FormatDateTime(fs, FStartDate) +
FSeperator + FormatDateTime(fs, FFinishDate);
end;
procedure TODVCLPopupCalendar.SetSingleDate(Value: Boolean);
begin
FSingleDate := Value;
SetText;
end;
function TODVCLPopupCalendar.GetDisplayDate: TDateTime;
begin
Result := EncodeDate(FDisplayYear, FDisplayMonth, 1);
end;
procedure TODVCLPopupCalendar.SetDisplayDate(Value: TDateTime);
var
yr, mo, dy: Word;
begin
DecodeDate(Value, yr, mo, dy);
FDisplayYear := yr;
FDisplayMonth := mo;
FShowCurrent := False;
end;
procedure TODVCLPopupCalendar.SetDisplayYear(Value: Integer);
begin
if Value < 1900 then FDisplayYear := 1900
else if Value > 2100 then FDisplayYear := 2100
else FDisplayYear := Value;
FShowCurrent := False;
end;
procedure TODVCLPopupCalendar.SetDisplayMonth(Value: Integer);
begin
if Value < 1 then FDisplayMonth := 1
else if Value > 12 then FDisplayMonth := 12
else FDisplayMonth := Value;
FShowCurrent := False;
end;
{
procedure TODVCLPopupCalendar.SetDisplayWeek(Value: Integer);
var
tw: Integer;
begin
tw := FCalendar.WeeksInYear(FDisplayYear);
if Value < 1 then Value := 1
else if Value > tw then Value := tw;
FDisplayMonth := FForm.Calendar.WeekToMonth(Value);
FShowCurrent := False;
end;
}
procedure TODVCLPopupCalendar.SetTitleFont(Value: TFont);
begin
FTitleFont.Assign(Value);
end;
procedure TODVCLPopupCalendar.SetStartFont(Value: TFont);
begin
FStartFont.Assign(Value);
end;
procedure TODVCLPopupCalendar.SetFinishFont(Value: TFont);
begin
FFinishFont.Assign(Value);
end;
procedure TODVCLPopupCalendar.SetDateFont(Value: TFont);
begin
FDateFont.Assign(Value);
end;
function TODVCLPopupCalendar.GetGlyph: TBitmap;
begin
Result := FButton.Glyph;
end;
procedure TODVCLPopupCalendar.SetGlyph(Value: TBitmap);
begin
with FButton do
begin
Glyph.Assign(Value);
if Glyph.Empty then
begin
Caption := '...';
Margin := -1;
end
else
begin
Caption := '';
Margin := 0;
NumGlyphs := Glyph.Width div Glyph.Height;
end;
end;