CalLite: Add keyboard support. Some refactoring.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@5314 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
parent
f83799d4a3
commit
1d40bd7687
@ -1,58 +1,13 @@
|
|||||||
object Form1: TForm1
|
object Form1: TForm1
|
||||||
Left = 400
|
Left = 400
|
||||||
Height = 272
|
Height = 227
|
||||||
Top = 115
|
Top = 115
|
||||||
Width = 256
|
Width = 256
|
||||||
Caption = 'Form1'
|
Caption = 'Form1'
|
||||||
ClientHeight = 272
|
|
||||||
ClientWidth = 256
|
|
||||||
Font.Height = -13
|
Font.Height = -13
|
||||||
Font.Name = 'Tahoma'
|
Font.Name = 'Tahoma'
|
||||||
KeyPreview = True
|
KeyPreview = True
|
||||||
OnCreate = FormCreate
|
OnCreate = FormCreate
|
||||||
OnResize = FormResize
|
|
||||||
Position = poScreenCenter
|
Position = poScreenCenter
|
||||||
LCLVersion = '1.6.0.4'
|
LCLVersion = '1.7'
|
||||||
object edtYear: TEdit
|
|
||||||
Left = 122
|
|
||||||
Height = 18
|
|
||||||
Top = 15
|
|
||||||
Width = 38
|
|
||||||
Alignment = taCenter
|
|
||||||
AutoSize = False
|
|
||||||
BorderStyle = bsNone
|
|
||||||
OnKeyDown = edtYearKeyDown
|
|
||||||
ParentColor = True
|
|
||||||
TabOrder = 1
|
|
||||||
Text = 'Year'
|
|
||||||
end
|
|
||||||
object edtMonth: TEdit
|
|
||||||
AnchorSideLeft.Side = asrBottom
|
|
||||||
AnchorSideTop.Control = edtYear
|
|
||||||
AnchorSideRight.Control = edtYear
|
|
||||||
Left = 84
|
|
||||||
Height = 18
|
|
||||||
Top = 15
|
|
||||||
Width = 38
|
|
||||||
Alignment = taCenter
|
|
||||||
Anchors = [akTop, akRight]
|
|
||||||
AutoSize = False
|
|
||||||
BorderStyle = bsNone
|
|
||||||
OnKeyDown = edtMonthKeyDown
|
|
||||||
ParentColor = True
|
|
||||||
TabOrder = 0
|
|
||||||
Text = 'Month'
|
|
||||||
end
|
|
||||||
object Label1: TLabel
|
|
||||||
Left = 5
|
|
||||||
Height = 30
|
|
||||||
Top = 237
|
|
||||||
Width = 246
|
|
||||||
Align = alBottom
|
|
||||||
BorderSpacing.Around = 5
|
|
||||||
Caption = 'Use Up/Down Arrows to change the Month/Year. Press and hold for long jumps.'
|
|
||||||
ParentColor = False
|
|
||||||
ParentFont = False
|
|
||||||
WordWrap = True
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
@ -5,22 +5,14 @@ unit main;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,
|
SysUtils, Forms, Controls, CalendarLite;
|
||||||
LclType, Buttons, StdCtrls, DateUtils, CalendarLite;
|
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
||||||
{ TForm1 }
|
{ TForm1 }
|
||||||
|
|
||||||
TForm1 = class(TForm)
|
TForm1 = class(TForm)
|
||||||
edtYear: TEdit;
|
|
||||||
edtMonth: TEdit;
|
|
||||||
Label1: TLabel;
|
|
||||||
procedure btnCloseClick(Sender: TObject);
|
|
||||||
procedure edtYearKeyDown(Sender: TObject; var Key: Word; {%H-}Shift: TShiftState);
|
|
||||||
procedure edtMonthKeyDown(Sender: TObject; var Key: Word; {%H-}Shift: TShiftState);
|
|
||||||
procedure FormCreate(Sender: TObject);
|
procedure FormCreate(Sender: TObject);
|
||||||
procedure FormResize(Sender: TObject);
|
|
||||||
private
|
private
|
||||||
{ private declarations }
|
{ private declarations }
|
||||||
CalendarLite1: TCalendarLite;
|
CalendarLite1: TCalendarLite;
|
||||||
@ -35,14 +27,8 @@ implementation
|
|||||||
|
|
||||||
{$R *.lfm}
|
{$R *.lfm}
|
||||||
|
|
||||||
|
|
||||||
{ TForm1 }
|
{ TForm1 }
|
||||||
|
|
||||||
var
|
|
||||||
AYear: Integer;
|
|
||||||
AMonth: Integer;
|
|
||||||
MonthsList: TStringList;
|
|
||||||
|
|
||||||
procedure TForm1.FormCreate(Sender: TObject);
|
procedure TForm1.FormCreate(Sender: TObject);
|
||||||
var
|
var
|
||||||
I: Integer;
|
I: Integer;
|
||||||
@ -50,65 +36,15 @@ begin
|
|||||||
CalendarLite1 := TCalendarLite.Create(self);
|
CalendarLite1 := TCalendarLite.Create(self);
|
||||||
with CalendarLite1 do begin
|
with CalendarLite1 do begin
|
||||||
Parent := self;
|
Parent := self;
|
||||||
Left := 20;
|
Left := 10;
|
||||||
// Height := 160;
|
Top := 10;
|
||||||
Top := 40;
|
|
||||||
Width := self.Width - 2*Left;
|
Width := self.Width - 2*Left;
|
||||||
Height := label1.Top - Top - 20;
|
Height := self.Height - 2*Top;
|
||||||
ParentColor := false;
|
Date := Now();
|
||||||
Date := 41574;
|
|
||||||
DisplayTexts := '"Today is",dd/mm/yyyy,"Holidays during","There are no holidays set for"';
|
DisplayTexts := '"Today is",dd/mm/yyyy,"Holidays during","There are no holidays set for"';
|
||||||
WeekendDays := [dowSaturday];
|
WeekendDays := [dowSaturday];
|
||||||
Anchors := [akLeft, akTop, akRight, akBottom];
|
Anchors := [akLeft, akTop, akRight, akBottom];
|
||||||
end;
|
end;
|
||||||
|
|
||||||
MonthsList:= TStringList.Create;
|
|
||||||
for I:= 0 to 11 do begin
|
|
||||||
MonthsList.Add(AnsiToUTF8(FormatSettings.ShortMonthNames[I+1]));
|
|
||||||
end;
|
|
||||||
|
|
||||||
AYear:= YearOf(Now);
|
|
||||||
AMonth:= MonthOf(Now)-1;
|
|
||||||
edtYear.Caption := IntToStr(AYear);
|
|
||||||
edtMonth.Caption := MonthsList[AMonth];
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TForm1.FormResize(Sender: TObject);
|
|
||||||
begin
|
|
||||||
edtMonth.Left := Width div 2 - edtMonth.Width - 2;
|
|
||||||
edtYear.Left := Width div 2 + 2;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TForm1.btnCloseClick(Sender: TObject);
|
|
||||||
begin
|
|
||||||
FreeAndNil(MonthsList);
|
|
||||||
Close;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TForm1.edtYearKeyDown(Sender: TObject; var Key: Word;
|
|
||||||
Shift: TShiftState);
|
|
||||||
begin
|
|
||||||
case Key of
|
|
||||||
VK_Up : Inc(AYear);
|
|
||||||
VK_Down : Dec(AYear);
|
|
||||||
end;
|
|
||||||
edtYear.Caption := IntToStr(AYear);
|
|
||||||
CalendarLite1.Date := RecodeYear(CalendarLite1.Date,AYear);
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TForm1.edtMonthKeyDown(Sender: TObject; var Key: Word;
|
|
||||||
Shift: TShiftState);
|
|
||||||
begin
|
|
||||||
case Key of
|
|
||||||
VK_Up : Inc(AMonth);
|
|
||||||
VK_Down : Dec(AMonth);
|
|
||||||
end;
|
|
||||||
case AMonth of
|
|
||||||
-1: AMonth := 11;
|
|
||||||
12: AMonth := 0;
|
|
||||||
end;
|
|
||||||
edtMonth.Text:= MonthsList[AMonth];
|
|
||||||
CalendarLite1.Date:= RecodeMonth(CalendarLite1.Date,AMonth+1);
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
@ -27,18 +27,15 @@
|
|||||||
<FormatVersion Value="1"/>
|
<FormatVersion Value="1"/>
|
||||||
</local>
|
</local>
|
||||||
</RunParams>
|
</RunParams>
|
||||||
<RequiredPackages Count="3">
|
<RequiredPackages Count="2">
|
||||||
<Item1>
|
<Item1>
|
||||||
<PackageName Value="callight_pkg"/>
|
<PackageName Value="callight_pkg"/>
|
||||||
</Item1>
|
</Item1>
|
||||||
<Item2>
|
<Item2>
|
||||||
<PackageName Value="RunTimeTypeInfoControls"/>
|
|
||||||
</Item2>
|
|
||||||
<Item3>
|
|
||||||
<PackageName Value="LCL"/>
|
<PackageName Value="LCL"/>
|
||||||
</Item3>
|
</Item2>
|
||||||
</RequiredPackages>
|
</RequiredPackages>
|
||||||
<Units Count="3">
|
<Units Count="2">
|
||||||
<Unit0>
|
<Unit0>
|
||||||
<Filename Value="testCalLite.lpr"/>
|
<Filename Value="testCalLite.lpr"/>
|
||||||
<IsPartOfProject Value="True"/>
|
<IsPartOfProject Value="True"/>
|
||||||
@ -51,11 +48,6 @@
|
|||||||
<ResourceBaseClass Value="Form"/>
|
<ResourceBaseClass Value="Form"/>
|
||||||
<UnitName Value="uMainTestCalLite"/>
|
<UnitName Value="uMainTestCalLite"/>
|
||||||
</Unit1>
|
</Unit1>
|
||||||
<Unit2>
|
|
||||||
<Filename Value="calendarlite.pp"/>
|
|
||||||
<IsPartOfProject Value="True"/>
|
|
||||||
<UnitName Value="CalendarLite"/>
|
|
||||||
</Unit2>
|
|
||||||
</Units>
|
</Units>
|
||||||
</ProjectOptions>
|
</ProjectOptions>
|
||||||
<CompilerOptions>
|
<CompilerOptions>
|
||||||
|
@ -9,7 +9,6 @@ object Form1: TForm1
|
|||||||
Color = clWindow
|
Color = clWindow
|
||||||
Font.CharSet = ANSI_CHARSET
|
Font.CharSet = ANSI_CHARSET
|
||||||
OnCreate = FormCreate
|
OnCreate = FormCreate
|
||||||
OnResize = FormResize
|
|
||||||
LCLVersion = '1.7'
|
LCLVersion = '1.7'
|
||||||
object PSettings: TPanel
|
object PSettings: TPanel
|
||||||
Left = 0
|
Left = 0
|
||||||
@ -174,4 +173,25 @@ object Form1: TForm1
|
|||||||
TabOrder = 5
|
TabOrder = 5
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
object CalendarLite1: TCalendarLite
|
||||||
|
Left = 132
|
||||||
|
Height = 160
|
||||||
|
Top = 489
|
||||||
|
Width = 210
|
||||||
|
Constraints.MinHeight = 120
|
||||||
|
Constraints.MinWidth = 120
|
||||||
|
ParentColor = False
|
||||||
|
TabOrder = 1
|
||||||
|
Date = 42678
|
||||||
|
DisplayTexts = '"Today is",dd/mm/yyyy,"Holidays during","There are no holidays set for"'
|
||||||
|
WeekendDays = [dowSunday, dowSaturday]
|
||||||
|
end
|
||||||
|
object Label1: TLabel
|
||||||
|
Left = 76
|
||||||
|
Height = 15
|
||||||
|
Top = 425
|
||||||
|
Width = 34
|
||||||
|
Caption = 'Label1'
|
||||||
|
ParentColor = False
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -6,16 +6,16 @@ interface
|
|||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, SysUtils, Forms, Graphics, ExtCtrls, StdCtrls, Spin, CalendarLite;
|
Classes, SysUtils, Forms, Graphics, ExtCtrls, StdCtrls, Spin, CalendarLite;
|
||||||
// Easysize;
|
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
||||||
{ TForm1 }
|
{ TForm1 }
|
||||||
|
|
||||||
TForm1 = class(TForm)
|
TForm1 = class(TForm)
|
||||||
|
CalendarLite1: TCalendarLite;
|
||||||
cbUseHolidays: TCheckBox;
|
cbUseHolidays: TCheckBox;
|
||||||
cgOptions: TCheckGroup;
|
cgOptions: TCheckGroup;
|
||||||
//FormResizer1: TFormResizer;
|
Label1: TLabel;
|
||||||
LTitle: TLabel;
|
LTitle: TLabel;
|
||||||
LWidth: TLabel;
|
LWidth: TLabel;
|
||||||
lHeight: TLabel;
|
lHeight: TLabel;
|
||||||
@ -27,14 +27,13 @@ type
|
|||||||
procedure cbUseHolidaysChange(Sender: TObject);
|
procedure cbUseHolidaysChange(Sender: TObject);
|
||||||
procedure cgOptionsItemClick(Sender: TObject; Index: integer);
|
procedure cgOptionsItemClick(Sender: TObject; Index: integer);
|
||||||
procedure FormCreate(Sender: TObject);
|
procedure FormCreate(Sender: TObject);
|
||||||
procedure FormResize(Sender: TObject);
|
|
||||||
procedure rgLanguageClick(Sender: TObject);
|
procedure rgLanguageClick(Sender: TObject);
|
||||||
procedure rgStartingDOWClick(Sender: TObject);
|
procedure rgStartingDOWClick(Sender: TObject);
|
||||||
procedure seHeightChange(Sender: TObject);
|
procedure seHeightChange(Sender: TObject);
|
||||||
procedure seWidthChange(Sender: TObject);
|
procedure seWidthChange(Sender: TObject);
|
||||||
private
|
private
|
||||||
copyCal, demoCal: TCalendarLite;
|
copyCal, demoCal: TCalendarLite;
|
||||||
FnoHolidays: boolean;
|
FNoHolidays: boolean;
|
||||||
procedure RespondToDateChange(Sender: tObject);
|
procedure RespondToDateChange(Sender: tObject);
|
||||||
procedure GetHolidays(Sender: TObject; AMonth, AYear: Integer; // wp
|
procedure GetHolidays(Sender: TObject; AMonth, AYear: Integer; // wp
|
||||||
var Holidays: THolidays);
|
var Holidays: THolidays);
|
||||||
@ -48,6 +47,9 @@ implementation
|
|||||||
|
|
||||||
{$R *.lfm}
|
{$R *.lfm}
|
||||||
|
|
||||||
|
uses
|
||||||
|
Dialogs;
|
||||||
|
|
||||||
function Easter(year:integer) : TDateTime; // wp
|
function Easter(year:integer) : TDateTime; // wp
|
||||||
var
|
var
|
||||||
Day, Month : integer;
|
Day, Month : integer;
|
||||||
@ -82,7 +84,6 @@ end;
|
|||||||
procedure TForm1.FormCreate(Sender: TObject);
|
procedure TForm1.FormCreate(Sender: TObject);
|
||||||
var opt: TCalOption;
|
var opt: TCalOption;
|
||||||
begin
|
begin
|
||||||
// FormResizer1.InitializeForm;
|
|
||||||
demoCal:= TCalendarLite.Create(Self);
|
demoCal:= TCalendarLite.Create(Self);
|
||||||
demoCal.Parent:= Self;
|
demoCal.Parent:= Self;
|
||||||
demoCal.Left:= 10;
|
demoCal.Left:= 10;
|
||||||
@ -115,11 +116,6 @@ begin
|
|||||||
copyCal.Options := copyCal.Options + [coShowBorder,coUseTopRowColors,coDayLine];
|
copyCal.Options := copyCal.Options + [coShowBorder,coUseTopRowColors,coDayLine];
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TForm1.FormResize(Sender: TObject);
|
|
||||||
begin
|
|
||||||
// FormResizer1.ResizeAll;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TForm1.rgLanguageClick(Sender: TObject);
|
procedure TForm1.rgLanguageClick(Sender: TObject);
|
||||||
begin
|
begin
|
||||||
case rgLanguage.ItemIndex of
|
case rgLanguage.ItemIndex of
|
||||||
@ -129,41 +125,6 @@ begin
|
|||||||
3: demoCal.Languages := lgHebrew;
|
3: demoCal.Languages := lgHebrew;
|
||||||
4: demoCal.Languages := lgSpanish;
|
4: demoCal.Languages := lgSpanish;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{
|
|
||||||
case rgLanguage.ItemIndex of
|
|
||||||
0: begin
|
|
||||||
demoCal.DayNames := EnglishDays;
|
|
||||||
demoCal.MonthNames := EnglishMonths;
|
|
||||||
demoCal.DisplayTexts := DefaultDisplayText;
|
|
||||||
demoCal.BiDiMode:= bdLeftToRight;
|
|
||||||
end;
|
|
||||||
1: begin
|
|
||||||
demoCal.DayNames := FrenchDays;
|
|
||||||
demoCal.MonthNames := FrenchMonths;
|
|
||||||
demoCal.DisplayTexts := FrenchTexts;
|
|
||||||
demoCal.BiDiMode:= bdLeftToRight;
|
|
||||||
end;
|
|
||||||
2: begin
|
|
||||||
demoCal.DayNames := GermanDays;
|
|
||||||
demoCal.MonthNames := GermanMonths;
|
|
||||||
demoCal.DisplayTexts := GermamTexts;
|
|
||||||
demoCal.BiDiMode:= bdLeftToRight;
|
|
||||||
end;
|
|
||||||
3: begin
|
|
||||||
demoCal.DayNames := HebrewDays;
|
|
||||||
demoCal.MonthNames := HebrewMonths;
|
|
||||||
demoCal.DisplayTexts := HebrewTexts;
|
|
||||||
demoCal.BiDiMode:= bdRightToLeft;
|
|
||||||
end;
|
|
||||||
4: begin
|
|
||||||
demoCal.DayNames := SpanishDays;
|
|
||||||
demoCal.MonthNames := SpanishMonths;
|
|
||||||
demoCal.DisplayTexts := SpanishTexts;
|
|
||||||
demoCal.BiDiMode:= bdLeftToRight;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
}
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TForm1.rgStartingDOWClick(Sender: TObject);
|
procedure TForm1.rgStartingDOWClick(Sender: TObject);
|
||||||
@ -183,7 +144,7 @@ end;
|
|||||||
|
|
||||||
procedure TForm1.cbUseHolidaysChange(Sender: TObject);
|
procedure TForm1.cbUseHolidaysChange(Sender: TObject);
|
||||||
begin
|
begin
|
||||||
FnoHolidays := not FnoHolidays;
|
FNoHolidays := not FNoHolidays;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TForm1.cgOptionsItemClick(Sender: TObject; Index: integer);
|
procedure TForm1.cgOptionsItemClick(Sender: TObject; Index: integer);
|
||||||
|
@ -105,6 +105,7 @@ type
|
|||||||
coShowTodayFrame, coShowTodayName, coShowTodayRow,
|
coShowTodayFrame, coShowTodayName, coShowTodayRow,
|
||||||
coShowWeekend, coUseTopRowColors);
|
coShowWeekend, coUseTopRowColors);
|
||||||
TCalOptions = set of TCalOption;
|
TCalOptions = set of TCalOption;
|
||||||
|
|
||||||
TLanguage = (lgEnglish, lgFrench, lgGerman, lgHebrew, lgSpanish); //Ariel Rodriguez 12/09/2013
|
TLanguage = (lgEnglish, lgFrench, lgGerman, lgHebrew, lgSpanish); //Ariel Rodriguez 12/09/2013
|
||||||
|
|
||||||
|
|
||||||
@ -124,8 +125,8 @@ type
|
|||||||
FThisYear: word;
|
FThisYear: word;
|
||||||
FTStyle: TTextStyle;
|
FTStyle: TTextStyle;
|
||||||
procedure CalcSettings;
|
procedure CalcSettings;
|
||||||
procedure ChangeDateTo(aCell: TSize);
|
procedure ChangeDateTo(ACell: TSize);
|
||||||
procedure DrawArrow(aRect: TRect; aHead: TArrowhead; aDirn: TArrowDirection);
|
procedure DrawArrow(ARect: TRect; AHead: TArrowhead; ADirec: TArrowDirection);
|
||||||
procedure DrawDayCells;
|
procedure DrawDayCells;
|
||||||
procedure DrawDayLabels;
|
procedure DrawDayLabels;
|
||||||
procedure DrawTodayRow;
|
procedure DrawTodayRow;
|
||||||
@ -136,18 +137,14 @@ type
|
|||||||
function GetLeftColIndex: Integer;
|
function GetLeftColIndex: Integer;
|
||||||
procedure GetMonthYearRects(var AMonthRect, AYearRect: TRect);
|
procedure GetMonthYearRects(var AMonthRect, AYearRect: TRect);
|
||||||
function GetRightColIndex: Integer;
|
function GetRightColIndex: Integer;
|
||||||
procedure GotoDay(aDate: word);
|
procedure GotoDay(ADate: word);
|
||||||
procedure GotoMonth(AMonth: word);
|
procedure GotoMonth(AMonth: word);
|
||||||
procedure GotoToday;
|
procedure GotoToday;
|
||||||
procedure GotoYear(AYear: word);
|
procedure GotoYear(AYear: word);
|
||||||
procedure LeftClick;
|
procedure LeftClick;
|
||||||
procedure NextMonth;
|
|
||||||
procedure NextYear;
|
|
||||||
procedure PrevMonth;
|
|
||||||
procedure PrevYear;
|
|
||||||
procedure RightClick;
|
procedure RightClick;
|
||||||
public
|
public
|
||||||
constructor Create(aCanvas: TCanvas);
|
constructor Create(ACanvas: TCanvas);
|
||||||
procedure Draw;
|
procedure Draw;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -181,7 +178,8 @@ type
|
|||||||
|
|
||||||
{ TCalendarLite }
|
{ TCalendarLite }
|
||||||
|
|
||||||
TCalendarLite = class(TGraphicControl)
|
// TCalendarLite = class(TGraphicControl)
|
||||||
|
TCalendarLite = class(TCustomControl)
|
||||||
private
|
private
|
||||||
FCalDrawer: TCalDrawer;
|
FCalDrawer: TCalDrawer;
|
||||||
FColors: TCalColors;
|
FColors: TCalColors;
|
||||||
@ -215,30 +213,64 @@ type
|
|||||||
procedure SetWeekendDays(AValue: TDaysOfWeek);
|
procedure SetWeekendDays(AValue: TDaysOfWeek);
|
||||||
procedure YearMenuItemClicked(Sender: TObject);
|
procedure YearMenuItemClicked(Sender: TObject);
|
||||||
procedure SetLanguage(AValue: TLanguage); //Ariel Rodriguez 12/09/2013
|
procedure SetLanguage(AValue: TLanguage); //Ariel Rodriguez 12/09/2013
|
||||||
|
|
||||||
protected
|
protected
|
||||||
// procedure CreateHandle; override;
|
|
||||||
class function GetControlClassDefaultSize: TSize; override;
|
class function GetControlClassDefaultSize: TSize; override;
|
||||||
function GetDayName(ADayOfWeek: TDayOfWeek): String;
|
function GetDayName(ADayOfWeek: TDayOfWeek): String;
|
||||||
function GetDisplayText(aTextIndex: TDisplayText): String;
|
function GetDisplayText(aTextIndex: TDisplayText): String;
|
||||||
function GetMonthName(AMonth: Integer): String;
|
function GetMonthName(AMonth: Integer): String;
|
||||||
|
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
|
||||||
procedure MouseDown(Button: TMouseButton; Shift:TShiftState; X,Y:Integer); override;
|
procedure MouseDown(Button: TMouseButton; Shift:TShiftState; X,Y:Integer); override;
|
||||||
procedure Paint; override;
|
procedure Paint; override;
|
||||||
|
|
||||||
public
|
public
|
||||||
constructor Create(anOwner: TComponent); override;
|
constructor Create(anOwner: TComponent); override;
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
|
|
||||||
published
|
published
|
||||||
property Anchors;
|
|
||||||
property Align;
|
property Align;
|
||||||
|
property Anchors;
|
||||||
property BiDiMode;
|
property BiDiMode;
|
||||||
property BorderSpacing;
|
property BorderSpacing;
|
||||||
property Constraints;
|
property Constraints;
|
||||||
|
property Cursor;
|
||||||
property Font;
|
property Font;
|
||||||
|
property Height;
|
||||||
|
property HelpContext;
|
||||||
|
property HelpKeyword;
|
||||||
|
property HelpType;
|
||||||
property Hint;
|
property Hint;
|
||||||
|
property Left;
|
||||||
|
property Name;
|
||||||
|
property ParentBiDiMode;
|
||||||
property ParentColor;
|
property ParentColor;
|
||||||
property ParentFont;
|
property ParentFont;
|
||||||
|
property PopupMenu;
|
||||||
property ParentShowHint;
|
property ParentShowHint;
|
||||||
property ShowHint;
|
property ShowHint;
|
||||||
|
property TabOrder;
|
||||||
|
property TabStop;
|
||||||
|
property Tag;
|
||||||
|
property Top;
|
||||||
property Visible;
|
property Visible;
|
||||||
|
property Width;
|
||||||
|
property OnChangeBounds;
|
||||||
|
property OnClick;
|
||||||
|
property OnContextPopup;
|
||||||
|
property OnDblClick;
|
||||||
|
property OnEnter;
|
||||||
|
property OnExit;
|
||||||
|
property OnKeyDown;
|
||||||
|
property OnKeyPress;
|
||||||
|
property OnKeyUp;
|
||||||
|
property OnMouseDown;
|
||||||
|
property OnMouseEnter;
|
||||||
|
property OnMouseLeave;
|
||||||
|
property OnMouseMove;
|
||||||
|
property OnMouseUp;
|
||||||
|
property OnMouseWheel;
|
||||||
|
property OnMouseWheelDown;
|
||||||
|
property OnMouseWheelUp;
|
||||||
// new properties
|
// new properties
|
||||||
property Colors: TCalColors read FColors;
|
property Colors: TCalColors read FColors;
|
||||||
property Date: TDateTime read FDate write SetDate;
|
property Date: TDateTime read FDate write SetDate;
|
||||||
@ -267,7 +299,7 @@ procedure Register; //Ariel Rodriguez 12/09/2013
|
|||||||
implementation
|
implementation
|
||||||
|
|
||||||
uses
|
uses
|
||||||
LazUTF8, dateutils, math;
|
LCLType, LazUTF8, dateutils, math;
|
||||||
|
|
||||||
|
|
||||||
{ Holiday helpers }
|
{ Holiday helpers }
|
||||||
@ -293,10 +325,10 @@ end;
|
|||||||
|
|
||||||
{ TCalDrawer }
|
{ TCalDrawer }
|
||||||
|
|
||||||
constructor TCalDrawer.Create(aCanvas: TCanvas);
|
constructor TCalDrawer.Create(ACanvas: TCanvas);
|
||||||
begin
|
begin
|
||||||
inherited Create;
|
inherited Create;
|
||||||
FCanvas:= aCanvas;
|
FCanvas:= ACanvas;
|
||||||
FTStyle:= DefTStyle;
|
FTStyle:= DefTStyle;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -362,13 +394,13 @@ begin
|
|||||||
FRowPositions[TodayRow] := FRowPositions[LastDateRow] + borderv + ch + rem;
|
FRowPositions[TodayRow] := FRowPositions[LastDateRow] + borderv + ch + rem;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCalDrawer.ChangeDateTo(aCell: TSize);
|
procedure TCalDrawer.ChangeDateTo(ACell: TSize);
|
||||||
var
|
var
|
||||||
diff: integer;
|
diff: integer;
|
||||||
newDate: TDateTime;
|
newDate: TDateTime;
|
||||||
d, m, y: word;
|
d, m, y: word;
|
||||||
begin
|
begin
|
||||||
diff := aCell.cx + LastCol * (aCell.cy - 2);
|
diff := ACell.cx + LastCol * (ACell.cy - 2);
|
||||||
newDate:= FStartDate + diff - 1;
|
newDate:= FStartDate + diff - 1;
|
||||||
FOwner.FDate := newDate;
|
FOwner.FDate := newDate;
|
||||||
FOwner.DateChange;
|
FOwner.DateChange;
|
||||||
@ -389,7 +421,8 @@ begin
|
|||||||
DrawTodayRow;
|
DrawTodayRow;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCalDrawer.DrawArrow(aRect: TRect; aHead: TArrowhead; aDirn: TArrowDirection);
|
procedure TCalDrawer.DrawArrow(ARect: TRect; AHead: TArrowhead;
|
||||||
|
ADirec: TArrowDirection);
|
||||||
var
|
var
|
||||||
sz: TSize;
|
sz: TSize;
|
||||||
d, ox, oy, half: integer;
|
d, ox, oy, half: integer;
|
||||||
@ -402,12 +435,12 @@ begin
|
|||||||
sz := Size(aRect);
|
sz := Size(aRect);
|
||||||
d := Min(sz.cy, sz.cx) div 3;
|
d := Min(sz.cy, sz.cx) div 3;
|
||||||
half := d div 2;
|
half := d div 2;
|
||||||
ox := aRect.Left + (sz.cx - d) div 2;
|
ox := ARect.Left + (sz.cx - d) div 2;
|
||||||
oy := aRect.Top + (sz.cy - d) div 2;
|
oy := ARect.Top + (sz.cy - d) div 2;
|
||||||
case aHead of
|
case AHead of
|
||||||
ahSingle:
|
ahSingle:
|
||||||
begin
|
begin
|
||||||
case aDirn of
|
case ADirec of
|
||||||
adLeft:
|
adLeft:
|
||||||
begin
|
begin
|
||||||
pts[1]:= Point(ox+d, oy);
|
pts[1]:= Point(ox+d, oy);
|
||||||
@ -424,7 +457,7 @@ begin
|
|||||||
FCanvas.Polygon(pts);
|
FCanvas.Polygon(pts);
|
||||||
end;
|
end;
|
||||||
ahDouble:
|
ahDouble:
|
||||||
case aDirn of
|
case ADirec of
|
||||||
adLeft:
|
adLeft:
|
||||||
begin
|
begin
|
||||||
pts[1]:= Point(ox+half-1, oy);
|
pts[1]:= Point(ox+half-1, oy);
|
||||||
@ -806,11 +839,9 @@ begin
|
|||||||
Result := 1;
|
Result := 1;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCalDrawer.GotoDay(aDate: word);
|
procedure TCalDrawer.GotoDay(ADate: word);
|
||||||
begin
|
begin
|
||||||
FOwner.FDate := aDate;
|
FOwner.Date := ADate;
|
||||||
FOwner.DateChange;
|
|
||||||
FOwner.Invalidate;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCalDrawer.GotoMonth(AMonth: word);
|
procedure TCalDrawer.GotoMonth(AMonth: word);
|
||||||
@ -819,16 +850,12 @@ var
|
|||||||
begin
|
begin
|
||||||
if not TryEncodeDate(FThisYear, AMonth, FThisDay, d) then // Feb 29 in leap year!
|
if not TryEncodeDate(FThisYear, AMonth, FThisDay, d) then // Feb 29 in leap year!
|
||||||
d := EncodeDate(FThisYear, AMonth, FThisDay);
|
d := EncodeDate(FThisYear, AMonth, FThisDay);
|
||||||
FOwner.FDate := d;
|
FOwner.Date := d;
|
||||||
FOwner.DateChange;
|
|
||||||
FOwner.Invalidate;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCalDrawer.GotoToday;
|
procedure TCalDrawer.GotoToday;
|
||||||
begin
|
begin
|
||||||
FOwner.FDate:= Date();
|
FOwner.Date:= Date();
|
||||||
FOwner.DateChange;
|
|
||||||
FOwner.Invalidate;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCalDrawer.GotoYear(AYear: word);
|
procedure TCalDrawer.GotoYear(AYear: word);
|
||||||
@ -837,9 +864,7 @@ var
|
|||||||
begin
|
begin
|
||||||
if not TryEncodeDate(AYear, FThisMonth, FThisDay, d) then // Feb 29 in leap year!
|
if not TryEncodeDate(AYear, FThisMonth, FThisDay, d) then // Feb 29 in leap year!
|
||||||
d := EncodeDate(AYear, FThisMonth, FThisDay);
|
d := EncodeDate(AYear, FThisMonth, FThisDay);
|
||||||
FOwner.FDate := d;
|
FOwner.Date := d;
|
||||||
FOwner.DateChange;
|
|
||||||
FOwner.Invalidate;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCalDrawer.LeftClick;
|
procedure TCalDrawer.LeftClick;
|
||||||
@ -853,8 +878,8 @@ begin
|
|||||||
case cell.cy of
|
case cell.cy of
|
||||||
TopRow:
|
TopRow:
|
||||||
case cell.cx of
|
case cell.cx of
|
||||||
1: PrevYear;
|
1: FOwner.Date := IncYear(FOwner.Date, -1);
|
||||||
2: PrevMonth;
|
2: FOwner.Date := IncMonth(FOwner.Date, -1);
|
||||||
3..5:
|
3..5:
|
||||||
begin
|
begin
|
||||||
GetMonthYearRects(Rm{%H-}, Ry{%H-});
|
GetMonthYearRects(Rm{%H-}, Ry{%H-});
|
||||||
@ -869,45 +894,59 @@ begin
|
|||||||
FOwner.FPopupMenu.Popup(ppopup.x, ppopup.y);
|
FOwner.FPopupMenu.Popup(ppopup.x, ppopup.y);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
6: NextMonth;
|
6: FOwner.Date := IncMonth(FOwner.Date, +1);
|
||||||
7: NextYear;
|
7: FOwner.Date := IncYear(FOwner.Date, +1);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
DayRow: ;
|
DayRow: ;
|
||||||
|
|
||||||
FirstDateRow..LastDateRow :
|
FirstDateRow..LastDateRow :
|
||||||
ChangeDateTo(cell);
|
ChangeDateTo(cell);
|
||||||
else
|
else
|
||||||
GotoToday;
|
GotoToday;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
(*
|
||||||
|
procedure TCalDrawer.NextDay;
|
||||||
|
begin
|
||||||
|
FOwner.Date := IncDay(FOwner.FDate, 1);
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TCalDrawer.NextMonth;
|
procedure TCalDrawer.NextMonth;
|
||||||
begin
|
begin
|
||||||
FOwner.FDate := IncMonth(FOwner.FDate, 1);
|
FOwner.Date := IncMonth(FOwner.FDate, 1);
|
||||||
FOwner.DateChange;
|
end;
|
||||||
FOwner.Invalidate;
|
|
||||||
|
procedure TCalDrawer.NextWeek;
|
||||||
|
begin
|
||||||
|
FOwner.Date := IncWeek(FOwner.FDate, 1);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCalDrawer.NextYear;
|
procedure TCalDrawer.NextYear;
|
||||||
begin
|
begin
|
||||||
FOwner.FDate := IncYear(FOwner.FDate, 1);
|
FOwner.Date := IncYear(FOwner.FDate, 1);
|
||||||
FOwner.DateChange;
|
end;
|
||||||
FOwner.Invalidate;
|
|
||||||
|
procedure TCalDrawer.PrevDay;
|
||||||
|
begin
|
||||||
|
FOwner.Date := IncDay(FOwner.FDate, -1);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCalDrawer.PrevMonth;
|
procedure TCalDrawer.PrevMonth;
|
||||||
begin
|
begin
|
||||||
FOwner.FDate := IncMonth(FOwner.FDate, -1);
|
FOwner.Date := IncMonth(FOwner.FDate, -1);
|
||||||
FOwner.DateChange;
|
end;
|
||||||
FOwner.Invalidate;
|
|
||||||
|
procedure TCalDrawer.PrevWeek;
|
||||||
|
begin
|
||||||
|
FOwner.Date := IncWeek(FOwner.FDate, -1);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCalDrawer.PrevYear;
|
procedure TCalDrawer.PrevYear;
|
||||||
begin
|
begin
|
||||||
FOwner.FDate := IncYear(FOwner.FDate, -1);
|
FOwner.Date := IncYear(FOwner.FDate, -1);
|
||||||
FOwner.DateChange;
|
|
||||||
FOwner.Invalidate;
|
|
||||||
end;
|
end;
|
||||||
|
*)
|
||||||
procedure TCalDrawer.RightClick;
|
procedure TCalDrawer.RightClick;
|
||||||
begin
|
begin
|
||||||
if Assigned(FOwner.FOnGetHolidays) then
|
if Assigned(FOwner.FOnGetHolidays) then
|
||||||
@ -958,22 +997,23 @@ constructor TCalendarLite.Create(anOwner: TComponent);
|
|||||||
begin
|
begin
|
||||||
inherited Create(anOwner);
|
inherited Create(anOwner);
|
||||||
FColors := TCalColors.Create(self);
|
FColors := TCalColors.Create(self);
|
||||||
FDate:= SysUtils.Date;
|
FDate := SysUtils.Date;
|
||||||
Color:= clWhite;
|
Color := clWhite;
|
||||||
FStartingDayOfWeek:= dowSunday;
|
FStartingDayOfWeek:= dowSunday;
|
||||||
with GetControlClassDefaultSize do
|
with GetControlClassDefaultSize do
|
||||||
SetInitialBounds(0, 0, cx, cy);
|
SetInitialBounds(0, 0, cx, cy);
|
||||||
Constraints.MinHeight := DefMinHeight;
|
Constraints.MinHeight := DefMinHeight;
|
||||||
Constraints.MinWidth := DefMinWidth;
|
Constraints.MinWidth := DefMinWidth;
|
||||||
Canvas.Brush.Style:= bsSolid;
|
Canvas.Brush.Style := bsSolid;
|
||||||
|
TabStop := true;
|
||||||
FDayNames := TStringList.Create;
|
FDayNames := TStringList.Create;
|
||||||
FMonthNames := TStringList.Create;
|
FMonthNames := TStringList.Create;
|
||||||
FDisplayTexts := TStringList.Create;
|
FDisplayTexts := TStringList.Create;
|
||||||
FDisplayTexts.StrictDelimiter := True;
|
FDisplayTexts.StrictDelimiter := True;
|
||||||
FDisplayTexts.Delimiter:= ',';
|
FDisplayTexts.Delimiter := ',';
|
||||||
SetDefaultDisplayTexts;
|
SetDefaultDisplayTexts;
|
||||||
FPopupMenu := TPopupMenu.Create(Self);
|
FPopupMenu := TPopupMenu.Create(Self);
|
||||||
FCalDrawer:= TCalDrawer.Create(Canvas);
|
FCalDrawer := TCalDrawer.Create(Canvas);
|
||||||
FCalDrawer.FOwner:= Self;
|
FCalDrawer.FOwner:= Self;
|
||||||
FWeekendDays := [dowSunday, dowSaturday];
|
FWeekendDays := [dowSunday, dowSaturday];
|
||||||
FOptions := [coShowTodayFrame, coBoldHolidays, coShowWeekend, coShowHolidays,
|
FOptions := [coShowTodayFrame, coBoldHolidays, coShowWeekend, coShowHolidays,
|
||||||
@ -1043,10 +1083,41 @@ begin
|
|||||||
FCalDrawer.GotoDay(TMenuItem(Sender).Tag);
|
FCalDrawer.GotoDay(TMenuItem(Sender).Tag);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TCalendarLite.KeyDown(var Key: Word; Shift: TShiftState);
|
||||||
|
|
||||||
|
function Delta(Increase: Boolean): Integer;
|
||||||
|
begin
|
||||||
|
if Increase then Result := +1 else Result := -1;
|
||||||
|
end;
|
||||||
|
|
||||||
|
begin
|
||||||
|
case Key of
|
||||||
|
VK_UP,
|
||||||
|
VK_DOWN : Date := IncWeek(FDate, Delta(Key = VK_DOWN));
|
||||||
|
VK_LEFT,
|
||||||
|
VK_RIGHT : Date := IncDay(FDate, Delta(Key = VK_RIGHT));
|
||||||
|
VK_HOME : Date := StartOfTheMonth(FDate);
|
||||||
|
VK_END : Date := EndOfTheMonth(FDate);
|
||||||
|
VK_PRIOR,
|
||||||
|
VK_NEXT : if (ssCtrl in Shift) then
|
||||||
|
Date := IncYear(FDate, Delta(Key = VK_NEXT)) else
|
||||||
|
Date := IncMonth(FDate, Delta(Key = VK_NEXT));
|
||||||
|
else inherited;
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
|
||||||
|
Key := 0;
|
||||||
|
inherited;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TCalendarLite.MouseDown(Button: TMouseButton; Shift: TShiftState;
|
procedure TCalendarLite.MouseDown(Button: TMouseButton; Shift: TShiftState;
|
||||||
X, Y: Integer);
|
X, Y: Integer);
|
||||||
begin
|
begin
|
||||||
inherited MouseDown(Button, Shift, X, Y);
|
inherited MouseDown(Button, Shift, X, Y);
|
||||||
|
|
||||||
|
if not Focused and not(csNoFocus in ControlStyle) then
|
||||||
|
SetFocus;
|
||||||
|
|
||||||
case Button of
|
case Button of
|
||||||
mbLeft : FCalDrawer.LeftClick;
|
mbLeft : FCalDrawer.LeftClick;
|
||||||
mbRight : FCalDrawer.RightClick;
|
mbRight : FCalDrawer.RightClick;
|
||||||
|
Loading…
Reference in New Issue
Block a user