mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-04 12:00:18 +02:00
DateTimePicker: add InMonthView function to TCalendarControlWrapper - adds layer of abstraction to using of calendar "view"
git-svn-id: trunk@64325 -
This commit is contained in:
parent
519788b865
commit
6b53432dd4
@ -21,7 +21,7 @@ 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).
|
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
|
When creating new wrapper, there are four abstract methods which need to be
|
||||||
overriden. Please see the coments in code below.
|
overriden. Please see the comments in code below.
|
||||||
|
|
||||||
-----------------------------------------------------------
|
-----------------------------------------------------------
|
||||||
LICENCE
|
LICENCE
|
||||||
@ -51,11 +51,11 @@ type
|
|||||||
|
|
||||||
{ TCalendarControlWrapper }
|
{ TCalendarControlWrapper }
|
||||||
|
|
||||||
TCalendarControlWrapper = class
|
TCalendarControlWrapper = class abstract (TObject)
|
||||||
private
|
private
|
||||||
FCalendarControl: TControl;
|
FCalendarControl: TControl;
|
||||||
public
|
public
|
||||||
{ There are four methods that derived classes should override: }
|
{ There are four abstract methods that derived classes should override: }
|
||||||
|
|
||||||
{ Should be overriden to just return the class of the calendar control. }
|
{ Should be overriden to just return the class of the calendar control. }
|
||||||
class function GetCalendarControlClass: TControlClass; virtual abstract;
|
class function GetCalendarControlClass: TControlClass; virtual abstract;
|
||||||
@ -72,6 +72,16 @@ type
|
|||||||
date or not). }
|
date or not). }
|
||||||
function AreCoordinatesOnDate(X, Y: Integer): Boolean; virtual abstract;
|
function AreCoordinatesOnDate(X, Y: Integer): Boolean; virtual abstract;
|
||||||
|
|
||||||
|
public
|
||||||
|
{ Not mandatory to override: }
|
||||||
|
|
||||||
|
{ Override only if the calendar class have "views", like Windows calendar
|
||||||
|
control (LCL's TCalendar in Win WS).
|
||||||
|
Should return False only when the calendar is in some view other than month.
|
||||||
|
DateTimePicker asks this when closing calendar. }
|
||||||
|
function InMonthView: Boolean; virtual;
|
||||||
|
|
||||||
|
public
|
||||||
function GetCalendarControl: TControl;
|
function GetCalendarControl: TControl;
|
||||||
constructor Create; virtual;
|
constructor Create; virtual;
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
@ -83,6 +93,11 @@ implementation
|
|||||||
|
|
||||||
{ TCalendarControlWrapper }
|
{ TCalendarControlWrapper }
|
||||||
|
|
||||||
|
function TCalendarControlWrapper.InMonthView: Boolean;
|
||||||
|
begin
|
||||||
|
Result := True;
|
||||||
|
end;
|
||||||
|
|
||||||
function TCalendarControlWrapper.GetCalendarControl: TControl;
|
function TCalendarControlWrapper.GetCalendarControl: TControl;
|
||||||
begin
|
begin
|
||||||
Result := FCalendarControl;
|
Result := FCalendarControl;
|
||||||
|
@ -46,7 +46,7 @@ uses
|
|||||||
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, Buttons,
|
Classes, SysUtils, Controls, LCLType, Graphics, Math, StdCtrls, Buttons,
|
||||||
ExtCtrls, Forms, ComCtrls, Types, LMessages, Calendar, LazUTF8, LCLIntf,
|
ExtCtrls, Forms, ComCtrls, Types, LMessages, LazUTF8, LCLIntf,
|
||||||
LCLProc, Themes, CalControlWrapper;
|
LCLProc, Themes, CalControlWrapper;
|
||||||
|
|
||||||
const
|
const
|
||||||
@ -769,9 +769,7 @@ begin
|
|||||||
case Key of
|
case Key of
|
||||||
|
|
||||||
VK_ESCAPE, VK_RETURN, VK_SPACE, VK_TAB:
|
VK_ESCAPE, VK_RETURN, VK_SPACE, VK_TAB:
|
||||||
if (not(Cal.GetCalendarControl is TCustomCalendar))
|
if Cal.InMonthView then begin
|
||||||
or (TCustomCalendar(Cal.GetCalendarControl).GetCalendarView = cvMonth)
|
|
||||||
then begin
|
|
||||||
ApplyTheDate := Key in [VK_RETURN, VK_SPACE];
|
ApplyTheDate := Key in [VK_RETURN, VK_SPACE];
|
||||||
Key := 0;
|
Key := 0;
|
||||||
CloseCalendarForm(ApplyTheDate);
|
CloseCalendarForm(ApplyTheDate);
|
||||||
@ -819,7 +817,7 @@ procedure TDTCalendarForm.WMActivate(var Message: TLMActivate);
|
|||||||
var
|
var
|
||||||
PP: HWND;
|
PP: HWND;
|
||||||
begin
|
begin
|
||||||
inherited;
|
inherited WMActivate(Message);
|
||||||
|
|
||||||
PP := LCLIntf.GetParent(Handle);
|
PP := LCLIntf.GetParent(Handle);
|
||||||
if (PP <> 0) then
|
if (PP <> 0) then
|
||||||
|
@ -47,6 +47,7 @@ type
|
|||||||
procedure SetDate(Date: TDate); override;
|
procedure SetDate(Date: TDate); override;
|
||||||
function GetDate: TDate; override;
|
function GetDate: TDate; override;
|
||||||
function AreCoordinatesOnDate(X, Y: Integer): Boolean; override;
|
function AreCoordinatesOnDate(X, Y: Integer): Boolean; override;
|
||||||
|
function InMonthView: Boolean; override;
|
||||||
|
|
||||||
constructor Create; override;
|
constructor Create; override;
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
@ -60,7 +61,7 @@ procedure TLCLCalendarWrapper.LCLCalendarWrapperWndProc(
|
|||||||
var TheMessage: TLMessage);
|
var TheMessage: TLMessage);
|
||||||
begin
|
begin
|
||||||
if TheMessage.msg = LM_LBUTTONDOWN then
|
if TheMessage.msg = LM_LBUTTONDOWN then
|
||||||
CanClose := TCalendar(GetCalendarControl).GetCalendarView = cvMonth;
|
CanClose := InMonthView;
|
||||||
|
|
||||||
if Assigned(PrevCalendarWndProc) then
|
if Assigned(PrevCalendarWndProc) then
|
||||||
PrevCalendarWndProc(TheMessage);
|
PrevCalendarWndProc(TheMessage);
|
||||||
@ -84,13 +85,17 @@ end;
|
|||||||
function TLCLCalendarWrapper.AreCoordinatesOnDate(X, Y: Integer): Boolean;
|
function TLCLCalendarWrapper.AreCoordinatesOnDate(X, Y: Integer): Boolean;
|
||||||
begin
|
begin
|
||||||
Result :=
|
Result :=
|
||||||
CanClose and
|
CanClose and InMonthView and
|
||||||
(TCalendar(GetCalendarControl).GetCalendarView = cvMonth) and
|
|
||||||
(TCalendar(GetCalendarControl).HitTest(Point(X, Y)) in [cpDate, cpNoWhere]);
|
(TCalendar(GetCalendarControl).HitTest(Point(X, Y)) in [cpDate, cpNoWhere]);
|
||||||
|
|
||||||
CanClose := True;
|
CanClose := True;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TLCLCalendarWrapper.InMonthView: Boolean;
|
||||||
|
begin
|
||||||
|
Result := TCalendar(GetCalendarControl).GetCalendarView = cvMonth;
|
||||||
|
end;
|
||||||
|
|
||||||
constructor TLCLCalendarWrapper.Create;
|
constructor TLCLCalendarWrapper.Create;
|
||||||
begin
|
begin
|
||||||
inherited Create;
|
inherited Create;
|
||||||
|
Loading…
Reference in New Issue
Block a user