mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-06 06:57:54 +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).
|
||||
|
||||
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
|
||||
@ -51,11 +51,11 @@ type
|
||||
|
||||
{ TCalendarControlWrapper }
|
||||
|
||||
TCalendarControlWrapper = class
|
||||
TCalendarControlWrapper = class abstract (TObject)
|
||||
private
|
||||
FCalendarControl: TControl;
|
||||
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. }
|
||||
class function GetCalendarControlClass: TControlClass; virtual abstract;
|
||||
@ -69,9 +69,19 @@ type
|
||||
{ This function should return True if coordinates (X, Y) are on the date in
|
||||
the calendar control (DateTimePicker calls this function when the calendar
|
||||
is clicked, to determine whether the drop-down calendar should return the
|
||||
date or not). }
|
||||
date or not). }
|
||||
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;
|
||||
constructor Create; virtual;
|
||||
destructor Destroy; override;
|
||||
@ -83,6 +93,11 @@ implementation
|
||||
|
||||
{ TCalendarControlWrapper }
|
||||
|
||||
function TCalendarControlWrapper.InMonthView: Boolean;
|
||||
begin
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
function TCalendarControlWrapper.GetCalendarControl: TControl;
|
||||
begin
|
||||
Result := FCalendarControl;
|
||||
|
@ -46,7 +46,7 @@ uses
|
||||
clocale, // needed to initialize default locale settings on Linux.
|
||||
{$endif}
|
||||
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;
|
||||
|
||||
const
|
||||
@ -769,9 +769,7 @@ begin
|
||||
case Key of
|
||||
|
||||
VK_ESCAPE, VK_RETURN, VK_SPACE, VK_TAB:
|
||||
if (not(Cal.GetCalendarControl is TCustomCalendar))
|
||||
or (TCustomCalendar(Cal.GetCalendarControl).GetCalendarView = cvMonth)
|
||||
then begin
|
||||
if Cal.InMonthView then begin
|
||||
ApplyTheDate := Key in [VK_RETURN, VK_SPACE];
|
||||
Key := 0;
|
||||
CloseCalendarForm(ApplyTheDate);
|
||||
@ -819,7 +817,7 @@ procedure TDTCalendarForm.WMActivate(var Message: TLMActivate);
|
||||
var
|
||||
PP: HWND;
|
||||
begin
|
||||
inherited;
|
||||
inherited WMActivate(Message);
|
||||
|
||||
PP := LCLIntf.GetParent(Handle);
|
||||
if (PP <> 0) then
|
||||
|
@ -47,6 +47,7 @@ type
|
||||
procedure SetDate(Date: TDate); override;
|
||||
function GetDate: TDate; override;
|
||||
function AreCoordinatesOnDate(X, Y: Integer): Boolean; override;
|
||||
function InMonthView: Boolean; override;
|
||||
|
||||
constructor Create; override;
|
||||
destructor Destroy; override;
|
||||
@ -60,7 +61,7 @@ procedure TLCLCalendarWrapper.LCLCalendarWrapperWndProc(
|
||||
var TheMessage: TLMessage);
|
||||
begin
|
||||
if TheMessage.msg = LM_LBUTTONDOWN then
|
||||
CanClose := TCalendar(GetCalendarControl).GetCalendarView = cvMonth;
|
||||
CanClose := InMonthView;
|
||||
|
||||
if Assigned(PrevCalendarWndProc) then
|
||||
PrevCalendarWndProc(TheMessage);
|
||||
@ -84,13 +85,17 @@ end;
|
||||
function TLCLCalendarWrapper.AreCoordinatesOnDate(X, Y: Integer): Boolean;
|
||||
begin
|
||||
Result :=
|
||||
CanClose and
|
||||
(TCalendar(GetCalendarControl).GetCalendarView = cvMonth) and
|
||||
CanClose and InMonthView and
|
||||
(TCalendar(GetCalendarControl).HitTest(Point(X, Y)) in [cpDate, cpNoWhere]);
|
||||
|
||||
CanClose := True;
|
||||
end;
|
||||
|
||||
function TLCLCalendarWrapper.InMonthView: Boolean;
|
||||
begin
|
||||
Result := TCalendar(GetCalendarControl).GetCalendarView = cvMonth;
|
||||
end;
|
||||
|
||||
constructor TLCLCalendarWrapper.Create;
|
||||
begin
|
||||
inherited Create;
|
||||
|
Loading…
Reference in New Issue
Block a user