LCL/Calendar: Remove option dsStartMonday from Calendar.DisplaySettings and replace it by Delphi-compatible Calendar.FirstDayOfWeek

git-svn-id: trunk@63220 -
This commit is contained in:
wp 2020-05-25 14:16:57 +00:00
parent 0b121ff6fe
commit 254e43bb4f
11 changed files with 117 additions and 28 deletions

View File

@ -37,10 +37,10 @@ type
dsShowHeadings,
dsShowDayNames,
dsNoMonthChange,
dsShowWeekNumbers,
dsStartMonday
dsShowWeekNumbers
);
TDisplaySettings = set of TDisplaySetting;
const
DefaultDisplaySettings = [dsShowHeadings, dsShowDayNames];
@ -65,6 +65,11 @@ type
cvCentury // grid with decades of one century
);
TCalDayOfWeek = (
dowMonday, dowTuesday, dowWednesday, dowThursday,
dowFriday, dowSaturday, dowSunday, dowDefault
);
EInvalidDate = class(Exception);
{ TCustomCalendar }
@ -74,6 +79,7 @@ type
FDateAsString : String;
FDate: TDateTime; // last valid date
FDisplaySettings : TDisplaySettings;
FFirstDayOfWeek: TCalDayOfWeek;
FOnChange: TNotifyEvent;
FDayChanged: TNotifyEvent;
FMonthChanged: TNotifyEvent;
@ -87,6 +93,7 @@ type
procedure SetDisplaySettings(const AValue: TDisplaySettings);
function GetDate: String;
procedure SetDate(const AValue: String);
procedure SetFirstDayOfWeek(const AValue: TCalDayOfWeek);
protected
class procedure WSRegisterClass; override;
procedure LMChanged(var Message: TLMessage); message LM_CHANGED;
@ -105,6 +112,7 @@ type
property DateTime: TDateTime read GetDateTime write SetDateTime;
property DisplaySettings: TDisplaySettings read GetDisplaySettings
write SetDisplaySettings default DefaultDisplaySettings;
property FirstDayOfWeek: TCalDayOfWeek read FFirstDayOfWeek write SetFirstDayOfWeek default dowDefault;
property OnChange: TNotifyEvent read FOnChange write FOnChange;
property OnDayChanged: TNotifyEvent read FDayChanged write FDayChanged;
property OnMonthChanged: TNotifyEvent read FMonthChanged write FMonthChanged;
@ -123,6 +131,7 @@ type
property DateTime;
property DisplaySettings;
property DoubleBuffered;
property FirstDayOfWeek;
property Hint;
property OnChange;
property OnChangeBounds;
@ -177,6 +186,7 @@ begin
fCompStyle := csCalendar;
SetInitialBounds(0, 0, GetControlClassDefaultSize.CX, GetControlClassDefaultSize.CY);
FDisplaySettings := DefaultDisplaySettings;
FFirstDayOfWeek := dowDefault;
ControlStyle:=ControlStyle-[csTripleClicks,csQuadClicks,csAcceptsControls,csCaptureMouse];
DateTime := Now;
end;
@ -283,6 +293,13 @@ begin
SetProps;
end;
procedure TCustomCalendar.SetFirstDayOfWeek(const AValue: TCalDayOfWeek);
begin
if AValue = FFirstDayOfWeek then exit;
FFirstDayOfWeek := AValue;
SetProps;
end;
procedure TCustomCalendar.GetProps;
begin
if HandleAllocated and ([csLoading,csDestroying]*ComponentState=[]) then
@ -305,6 +322,7 @@ begin
{$ENDIF}
TWSCustomCalendarClass(WidgetSetClass).SetDateTime(Self, FDate);
TWSCustomCalendarClass(WidgetSetClass).SetDisplaySettings(Self, FDisplaySettings);
TWSCustomCalendarClass(WidgetSetClass).SetFirstDayOfWeek(Self, FFirstDayOfWeek);
end
else
FPropsChanged := True;

View File

@ -151,9 +151,10 @@ begin
if (dsShowWeekNumbers in ADisplaySettings) then
num := Num + (1 shl 3);
{
if (dsStartMonday in ADisplaySettings) then
num := Num + (1 shl 4);
}
gtkCalendarDisplayOptions := TGtkCalendarDisplayOptions(num);
gtk_Calendar_Display_options(GetCalendar(ACalendar), gtkCalendarDisplayOptions);
end;

View File

@ -283,9 +283,10 @@ begin
if (dsShowWeekNumbers in ADisplaySettings) then
num := Num + (1 shl 3);
{
if (dsStartMonday in ADisplaySettings) then
num := Num + (1 shl 4);
}
gtkCalendarDisplayOptions := TGtkCalendarDisplayOptions(num);
gtk_Calendar_Display_options(GetCalendar(ACalendar), gtkCalendarDisplayOptions);
end;

View File

@ -290,10 +290,10 @@ begin
if (dsShowWeekNumbers in ADisplaySettings) then
num := Num or $08;
{
if (dsStartMonday in ADisplaySettings) then
num := Num or $20;
}
TGtk3Calendar(ACalendar.Handle).setDisplayOptions(TGtkCalendarDisplayOptions(num));
end;

View File

@ -1865,9 +1865,8 @@ type
const AHHdrFmt: QCalendarWidgetHorizontalHeaderFormat;
const AVHdrFmt: QCalendarWidgetVerticalHeaderFormat;
const ASelMode: QCalendarWidgetSelectionMode;
const ANavBarVisible: Boolean; const AGridVisible: Boolean;
const AStartMonday: Boolean
);
const ANavBarVisible: Boolean; const AGridVisible: Boolean);
procedure SetFirstDayOfWeek(const ADayOfWeek: QtDayOfWeek);
procedure SignalActivated(ADate: QDateH); cdecl;
procedure SignalClicked(ADate: QDateH); cdecl;
procedure SignalSelectionChanged; cdecl;
@ -17796,20 +17795,21 @@ procedure TQtCalendar.SetDisplaySettings(
const AHHdrFmt: QCalendarWidgetHorizontalHeaderFormat;
const AVHdrFmt: QCalendarWidgetVerticalHeaderFormat;
const ASelMode: QCalendarWidgetSelectionMode;
const ANavBarVisible: Boolean; const AGridVisible: Boolean;
const AStartMonday: Boolean);
const ANavBarVisible: Boolean; const AGridVisible: Boolean);
// const AStartMonday: Boolean);
begin
QCalendarWidget_setHorizontalHeaderFormat(QCalendarWidgetH(Widget), AHHdrFmt);
QCalendarWidget_setNavigationBarVisible(QCalendarWidgetH(Widget), ANavBarVisible);
QCalendarWidget_setVerticalHeaderFormat(QCalendarWidgetH(Widget), AVHdrFmt);
QCalendarWidget_setGridVisible(QCalendarWidgetH(Widget), AGridVisible);
if AStartMonday then
QCalendarWidget_setFirstDayOfWeek(QCalendarWidgetH(Widget), QtMonday)
else
QCalendarWidget_setFirstDayOfWeek(QCalendarWidgetH(Widget), QtSunday);
QCalendarWidget_setSelectionMode(QCalendarWidgetH(Widget), ASelMode);
end;
procedure TQtCalendar.SetFirstDayOfWeek(const ADayOfWeek: QtDayOfWeek);
begin
QCalendarWidget_setFirstDayOfWeek(QCalendarWidgetH(Widget), ADayOfWeek);
end;
function TQtCalendar.DeliverDayChanged(ADate: QDateH): boolean;
var
y,m,d: Integer;

View File

@ -42,6 +42,7 @@ type
class function HitTest(const ACalendar: TCustomCalendar; const APoint: TPoint): TCalendarPart; override;
class procedure SetDateTime(const ACalendar: TCustomCalendar; const ADateTime: TDateTime); override;
class procedure SetDisplaySettings(const ACalendar: TCustomCalendar; const ADisplaySettings: TDisplaySettings); override;
class procedure SetFirstDayOfWeek(const ACalendar: TCustomCalendar; const ADayOfWeek: TCalDayOfWeek); override;
end;
@ -115,8 +116,24 @@ begin
QtCalendar.BeginUpdate;
QtCalendar.SetDisplaySettings(HHdrFmt, VHdrFmt, SelMode,
dsShowHeadings in ADisplaySettings, dsShowWeekNumbers in ADisplaySettings,
dsStartMonday in ADisplaySettings);
dsShowHeadings in ADisplaySettings, dsShowWeekNumbers in ADisplaySettings);
QtCalendar.EndUpdate;
end;
class procedure TQtWSCustomCalendar.SetFirstDayOfWeek(const ACalendar: TCustomCalendar;
const ADayOfWeek: TCalDayOfWeek);
var
QtCalendar: TQtCalendar;
dow: QtDayOfWeek;
begin
QtCalendar := TQtCalendar(ACalendar.Handle);
if ADayOfWeek = dowDefault then begin
// QLocale_firstDayOfWeek does not yet exist in qt 4.5 --> use Monday as default
dow := QtMonday;
end else
dow := QtDayOfWeek(ord(ADayOfWeek) + 1);
QtCalendar.BeginUpdate;
QtCalendar.SetFirstDayOfWeek(dow);
QtCalendar.EndUpdate;
end;

View File

@ -1872,9 +1872,8 @@ type
const AHHdrFmt: QCalendarWidgetHorizontalHeaderFormat;
const AVHdrFmt: QCalendarWidgetVerticalHeaderFormat;
const ASelMode: QCalendarWidgetSelectionMode;
const ANavBarVisible: Boolean; const AGridVisible: Boolean;
const AStartMonday: Boolean
);
const ANavBarVisible: Boolean; const AGridVisible: Boolean);
procedure SetFirstDayOfWeek(const ADayOfWeek: QtDayOfWeek);
procedure SignalActivated(ADate: QDateH); cdecl;
procedure SignalClicked(ADate: QDateH); cdecl;
procedure SignalSelectionChanged; cdecl;
@ -17815,20 +17814,20 @@ procedure TQtCalendar.SetDisplaySettings(
const AHHdrFmt: QCalendarWidgetHorizontalHeaderFormat;
const AVHdrFmt: QCalendarWidgetVerticalHeaderFormat;
const ASelMode: QCalendarWidgetSelectionMode;
const ANavBarVisible: Boolean; const AGridVisible: Boolean;
const AStartMonday: Boolean);
const ANavBarVisible: Boolean; const AGridVisible: Boolean);
begin
QCalendarWidget_setHorizontalHeaderFormat(QCalendarWidgetH(Widget), AHHdrFmt);
QCalendarWidget_setNavigationBarVisible(QCalendarWidgetH(Widget), ANavBarVisible);
QCalendarWidget_setVerticalHeaderFormat(QCalendarWidgetH(Widget), AVHdrFmt);
QCalendarWidget_setGridVisible(QCalendarWidgetH(Widget), AGridVisible);
if AStartMonday then
QCalendarWidget_setFirstDayOfWeek(QCalendarWidgetH(Widget), QtMonday)
else
QCalendarWidget_setFirstDayOfWeek(QCalendarWidgetH(Widget), QtSunday);
QCalendarWidget_setSelectionMode(QCalendarWidgetH(Widget), ASelMode);
end;
procedure TQtCalendar.SetFirstDayOfWeek(const ADayOfWeek: QtDayOfWeek);
begin
QCalendarWidget_setFirstDayOfWeek(QCalendarWidgetH(Widget), ADayOfWeek);
end;
function TQtCalendar.DeliverDayChanged(ADate: QDateH): boolean;
var
y,m,d: Integer;

View File

@ -41,6 +41,7 @@ type
class function HitTest(const ACalendar: TCustomCalendar; const APoint: TPoint): TCalendarPart; override;
class procedure SetDateTime(const ACalendar: TCustomCalendar; const ADateTime: TDateTime); override;
class procedure SetDisplaySettings(const ACalendar: TCustomCalendar; const ADisplaySettings: TDisplaySettings); override;
class procedure SetFirstDayOfWeek(const ACalendar: TCustomCalendar; const ADayOfWeek: TCalDayOfWeek); override;
end;
@ -114,8 +115,31 @@ begin
QtCalendar.BeginUpdate;
QtCalendar.SetDisplaySettings(HHdrFmt, VHdrFmt, SelMode,
dsShowHeadings in ADisplaySettings, dsShowWeekNumbers in ADisplaySettings,
dsStartMonday in ADisplaySettings);
dsShowHeadings in ADisplaySettings, dsShowWeekNumbers in ADisplaySettings);
QtCalendar.EndUpdate;
end;
class procedure TQtWSCustomCalendar.SetFirstDayOfWeek(const ACalendar: TCustomCalendar;
const ADayOfWeek: TCalDayOfWeek);
var
QtCalendar: TQtCalendar;
H: QLocaleH;
dow: QtDayOfWeek;
begin
QtCalendar := TQtCalendar(ACalendar.Handle);
if ADayOfWeek = dowDefault then begin
H := QLocale_Create();
try
dow := QLocale_firstDayOfWeek(H);
finally
QLocale_Destroy(H);
end;
end else
dow := QtDayOfWeek(ord(ADayOfWeek) + 1);
QtCalendar.BeginUpdate;
QtCalendar.SetFirstDayOfWeek(dow);
QtCalendar.EndUpdate;
end;

View File

@ -51,6 +51,7 @@ type
class function GetCurrentView(const ACalendar: TCustomCalendar): TCalendarView; override;
class procedure SetDateTime(const ACalendar: TCustomCalendar; const ADateTime: TDateTime); override;
class procedure SetDisplaySettings(const ACalendar: TCustomCalendar; const ASettings: TDisplaySettings); override;
class procedure SetFirstDayOfWeek(const ACalendar: TCustomCalendar; const ADayOfWeek: TCalDayOfWeek); override;
end;
@ -222,4 +223,19 @@ begin
SetWindowLong(ACalendar.Handle, GWL_STYLE, Style);
end;
class procedure TWin32WSCustomCalendar.SetFirstDayOfWeek(const ACalendar: TCustomCalendar; const ADayOfWeek: TCalDayOfWeek);
var
dow: LongInt;
tmp: array[0..1] of widechar;
begin
if not WSCheckHandleAllocated(ACalendar, 'TWin32WSCustomCalendar.SetFirstDayOfWeek') then
Exit;
if ADayOfWeek = dowDefault then begin
GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_IFIRSTDAYOFWEEK, PWideChar(tmp), SizeOf(tmp));
dow := StrToInt(tmp[0]);
end else
dow := ord(ADayOfWeek);
MonthCal_SetFirstDayOfWeek(ACalendar.Handle, dow);
end;
end.

View File

@ -43,6 +43,7 @@ type
class function HitTest(const ACalendar: TCustomCalendar; const APoint: TPoint): TCalendarPart; override;
class procedure SetDateTime(const ACalendar: TCustomCalendar; const ADateTime: TDateTime); override;
class procedure SetDisplaySettings(const ACalendar: TCustomCalendar; const ASettings: TDisplaySettings); override;
class procedure SetFirstDayOfWeek(const ACalendar: TCustomCalendar; const ADayOfWeek: TCalDayOfWeek); override;
end;
implementation
@ -154,4 +155,9 @@ begin
SetWindowLong(ACalendar.Handle, GWL_STYLE, Style);
end;
class procedure TWinCEWSCustomCalendar.SetFirstDayOfWeek(const ACalendar: TCustomCalendar; const ADayOfWeek: TCalDayOfWeek);
begin
// MonthCal_SetFirstDayOfWeek not supported by WinCE
end;
end.

View File

@ -53,6 +53,8 @@ type
class procedure SetDateTime(const ACalendar: TCustomCalendar; const ADateTime: TDateTime); virtual;
class procedure SetDisplaySettings(const ACalendar: TCustomCalendar;
const ADisplaySettings: TDisplaySettings); virtual;
class procedure SetFirstDayOfWeek(const ACalendar: TCustomCalendar;
const ADayOfWeek: TCalDayOfWeek); virtual;
end;
TWSCustomCalendarClass = class of TWSCustomCalendar;
@ -90,6 +92,11 @@ class procedure TWSCustomCalendar.SetDisplaySettings(const ACalendar: TCustomCal
begin
end;
class procedure TWSCustomCalendar.SetFirstDayOfWeek(const ACalendar: TCustomCalendar;
const ADayOfWeek: TCalDayOfWeek);
begin
end;
{ WidgetSetRegistration }
procedure RegisterCustomCalendar;