mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-16 10:29:28 +02:00
lcl: remove TCalendar.ReadOnly property, add HitTest function
git-svn-id: trunk@19111 -
This commit is contained in:
parent
3ded592929
commit
3b0c402312
@ -33,8 +33,7 @@ unit Calendar;
|
||||
interface
|
||||
|
||||
uses
|
||||
SysUtils, Classes, LCLType, LCLStrConsts, lMessages, Controls;
|
||||
|
||||
SysUtils, Classes, LCLType, LCLStrConsts, lMessages, Controls, LResources;
|
||||
|
||||
type
|
||||
TDisplaySetting = (
|
||||
@ -49,6 +48,16 @@ const
|
||||
DefaultDisplaySettings = [dsShowHeadings, dsShowDayNames];
|
||||
|
||||
type
|
||||
TCalendarPart = (
|
||||
cpNoWhere, // somewhere
|
||||
cpDate, // date part
|
||||
cpWeekNumber, // week number
|
||||
cpTitle, // somewhere in the title
|
||||
cpTitleBtn, // button in the title
|
||||
cpTitleMonth, // month value in the title
|
||||
cpTitleYear // year value in the title
|
||||
);
|
||||
|
||||
EInvalidDate = class(Exception);
|
||||
|
||||
{ TCustomCalendar }
|
||||
@ -59,14 +68,12 @@ type
|
||||
FDate: TDateTime; // last valid date
|
||||
FDisplaySettings : TDisplaySettings;
|
||||
FOnChange: TNotifyEvent;
|
||||
FReadOnly: Boolean;
|
||||
FDayChanged: TNotifyEvent;
|
||||
FMonthChanged: TNotifyEvent;
|
||||
FYearChanged: TNotifyEvent;
|
||||
FPropsChanged: boolean;
|
||||
function GetDateTime: TDateTime;
|
||||
procedure SetDateTime(const AValue: TDateTime);
|
||||
procedure SetReadOnly(const AValue: Boolean);
|
||||
procedure GetProps;
|
||||
procedure SetProps;
|
||||
function GetDisplaySettings: TDisplaySettings;
|
||||
@ -82,12 +89,12 @@ type
|
||||
procedure Loaded; override;
|
||||
public
|
||||
constructor Create(AOwner: TComponent); override;
|
||||
function HitTest(APoint: TPoint): TCalendarPart;
|
||||
procedure InitializeWnd; override;
|
||||
property Date: String read GetDate write SetDate stored False;
|
||||
property DateTime: TDateTime read GetDateTime write SetDateTime;
|
||||
property DisplaySettings: TDisplaySettings read GetDisplaySettings
|
||||
write SetDisplaySettings default DefaultDisplaySettings;
|
||||
property ReadOnly: Boolean read FReadOnly write SetReadOnly default False;
|
||||
property OnChange: TNotifyEvent read FOnChange write FOnChange;
|
||||
property OnDayChanged: TNotifyEvent read FDayChanged write FDayChanged;
|
||||
property OnMonthChanged: TNotifyEvent read FMonthChanged write FMonthChanged;
|
||||
@ -125,7 +132,6 @@ type
|
||||
property OnUTF8KeyPress;
|
||||
property OnYearChanged;
|
||||
property PopupMenu;
|
||||
property ReadOnly;
|
||||
property ShowHint;
|
||||
property TabStop;
|
||||
property Visible;
|
||||
@ -150,12 +156,19 @@ begin
|
||||
inherited Create(AOwner);
|
||||
fCompStyle := csCalendar;
|
||||
SetInitialBounds(0,0,GetControlClassDefaultSize.X,GetControlClassDefaultSize.Y);
|
||||
FReadOnly := False;
|
||||
FDisplaySettings := DefaultDisplaySettings;
|
||||
ControlStyle:=ControlStyle-[csTripleClicks,csQuadClicks,csAcceptsControls,csCaptureMouse];
|
||||
DateTime := Now;
|
||||
end;
|
||||
|
||||
function TCustomCalendar.HitTest(APoint: TPoint): TCalendarPart;
|
||||
begin
|
||||
if HandleAllocated then
|
||||
Result := TWSCustomCalendarClass(WidgetSetClass).HitTest(Self, APoint)
|
||||
else
|
||||
Result := cpNoWhere;
|
||||
end;
|
||||
|
||||
procedure TCustomCalendar.Loaded;
|
||||
begin
|
||||
inherited Loaded;
|
||||
@ -200,15 +213,6 @@ begin
|
||||
SetProps;
|
||||
end;
|
||||
|
||||
procedure TCustomCalendar.SetReadOnly(const AValue: Boolean);
|
||||
begin
|
||||
if (FReadOnly <> aValue) then
|
||||
begin
|
||||
FReadOnly := aValue;
|
||||
SetProps;
|
||||
end;
|
||||
end;
|
||||
|
||||
function TCustomCalendar.GetDateTime: TDateTime;
|
||||
begin
|
||||
GetProps;
|
||||
@ -253,16 +257,15 @@ procedure TCustomCalendar.SetProps;
|
||||
begin
|
||||
if HandleAllocated and ([csLoading,csDestroying]*ComponentState=[]) then
|
||||
begin
|
||||
FPropsChanged:=false;
|
||||
FPropsChanged := False;
|
||||
{$IFDEF VerboseCalenderSetDate}
|
||||
DebugLn('TCustomCalendar.SetProps A ',FDate,' ',FDateAsString);
|
||||
{$ENDIF}
|
||||
TWSCustomCalendarClass(WidgetSetClass).SetDateTime(Self, FDate);
|
||||
TWSCustomCalendarClass(WidgetSetClass).SetDisplaySettings(Self, FDisplaySettings);
|
||||
TWSCustomCalendarClass(WidgetSetClass).SetReadOnly(Self, FReadOnly);
|
||||
end else begin
|
||||
FPropsChanged:=true;
|
||||
end;
|
||||
end
|
||||
else
|
||||
FPropsChanged := True;
|
||||
end;
|
||||
|
||||
procedure TCustomCalendar.LMChanged(var Message: TLMessage);
|
||||
@ -306,4 +309,7 @@ begin
|
||||
if Assigned(OnChange) then OnChange(self);
|
||||
end;
|
||||
|
||||
initialization
|
||||
RegisterPropertyToSkip(TCalendar, 'ReadOnly', 'Obsoleted property', '');
|
||||
|
||||
end.
|
||||
|
@ -56,7 +56,6 @@ type
|
||||
class procedure SetDateTime(const ACalendar: TCustomCalendar; const ADateTime: TDateTime); override;
|
||||
class procedure SetDisplaySettings(const ACalendar: TCustomCalendar;
|
||||
const ADisplaySettings: TDisplaySettings); override;
|
||||
class procedure SetReadOnly(const ACalendar: TCustomCalendar; const AReadOnly: boolean); override;
|
||||
end;
|
||||
|
||||
implementation
|
||||
@ -165,17 +164,6 @@ begin
|
||||
gtk_Calendar_Display_options(GetCalendar(ACalendar), gtkCalendarDisplayOptions);
|
||||
end;
|
||||
|
||||
class procedure TGtkWSCustomCalendar.SetReadOnly(const ACalendar: TCustomCalendar;
|
||||
const AReadOnly: boolean);
|
||||
begin
|
||||
if not WSCheckHandleAllocated(ACalendar, 'SetReadOnly') then
|
||||
Exit;
|
||||
if AReadOnly then
|
||||
gtk_calendar_freeze(GetCalendar(ACalendar))
|
||||
else
|
||||
gtk_calendar_thaw(GetCalendar(ACalendar));
|
||||
end;
|
||||
|
||||
initialization
|
||||
|
||||
////////////////////////////////////////////////////
|
||||
|
@ -57,12 +57,41 @@ type
|
||||
class procedure SetDateTime(const ACalendar: TCustomCalendar; const ADateTime: TDateTime); override;
|
||||
class procedure SetDisplaySettings(const ACalendar: TCustomCalendar;
|
||||
const ADisplaySettings: TDisplaySettings); override;
|
||||
class procedure SetReadOnly(const ACalendar: TCustomCalendar; const AReadOnly: boolean); override;
|
||||
end;
|
||||
|
||||
|
||||
implementation
|
||||
|
||||
type
|
||||
TGtkCalendarPrivate = record
|
||||
header_win: PGdkWindow;
|
||||
day_name_win: PGdkWindow;
|
||||
main_win: PGdkWindow;
|
||||
week_win: PGdkWindow;
|
||||
arrow_win: array[0..3] of PGdkWindow;
|
||||
|
||||
header_h: guint;
|
||||
day_name_h: guint;
|
||||
main_h: guint;
|
||||
|
||||
arrow_state: array[0..3] of guint;
|
||||
arrow_width: guint;
|
||||
max_month_width: guint;
|
||||
max_year_width: guint;
|
||||
|
||||
day_width: guint;
|
||||
week_width: guint;
|
||||
|
||||
min_day_width: guint;
|
||||
max_day_char_width: guint;
|
||||
max_day_char_ascent: guint;
|
||||
max_day_char_descent: guint;
|
||||
max_label_char_ascent: guint;
|
||||
max_label_char_descent: guint;
|
||||
max_week_char_width: guint;
|
||||
end;
|
||||
PGtkCalendarPrivate = ^TGtkCalendarPrivate;
|
||||
|
||||
{ TGtk2WSCustomCalendar }
|
||||
|
||||
class procedure TGtk2WSCustomCalendar.SetCallbacks(const AGtkWidget: PGtkWidget;
|
||||
@ -169,17 +198,6 @@ begin
|
||||
gtk_Calendar_Display_options(GetCalendar(ACalendar), gtkCalendarDisplayOptions);
|
||||
end;
|
||||
|
||||
class procedure TGtk2WSCustomCalendar.SetReadOnly(const ACalendar: TCustomCalendar;
|
||||
const AReadOnly: boolean);
|
||||
begin
|
||||
if not WSCheckHandleAllocated(ACalendar, 'SetReadOnly') then
|
||||
Exit;
|
||||
if AReadOnly then
|
||||
gtk_calendar_freeze(GetCalendar(ACalendar))
|
||||
else
|
||||
gtk_calendar_thaw(GetCalendar(ACalendar));
|
||||
end;
|
||||
|
||||
initialization
|
||||
|
||||
////////////////////////////////////////////////////
|
||||
|
@ -47,7 +47,6 @@ type
|
||||
class function GetDateTime(const ACalendar: TCustomCalendar): TDateTime; override;
|
||||
class procedure SetDateTime(const ACalendar: TCustomCalendar; const ADateTime: TDateTime); override;
|
||||
class procedure SetDisplaySettings(const ACalendar: TCustomCalendar; const ADisplaySettings: TDisplaySettings); override;
|
||||
class procedure SetReadOnly(const ACalendar: TCustomCalendar; const AReadOnly: boolean); override;
|
||||
end;
|
||||
|
||||
|
||||
@ -66,20 +65,6 @@ begin
|
||||
Result := TLCLIntfHandle(QtCalendar);
|
||||
end;
|
||||
|
||||
class procedure TQtWSCustomCalendar.SetReadOnly(const ACalendar: TCustomCalendar; const AReadOnly: boolean);
|
||||
var
|
||||
QtCalendar: TQtCalendar;
|
||||
begin
|
||||
QtCalendar := TQtCalendar(ACalendar.Handle);
|
||||
|
||||
if AReadOnly then
|
||||
QCalendarWidget_setSelectionMode(QCalendarWidgetH(QtCalendar.Widget), QCalendarWidgetNoSelection)
|
||||
else
|
||||
QCalendarWidget_setSelectionMode(QCalendarWidgetH(QtCalendar.Widget), QCalendarWidgetSingleSelection);
|
||||
|
||||
QCalendarWidget_setDateEditEnabled(QCalendarWidgetH(QtCalendar.Widget), not AReadOnly);
|
||||
end;
|
||||
|
||||
class function TQtWSCustomCalendar.GetDateTime(const ACalendar: TCustomCalendar): TDateTime;
|
||||
var
|
||||
QtCalendar: TQtCalendar;
|
||||
|
@ -50,7 +50,6 @@ type
|
||||
class function GetDateTime(const ACalendar: TCustomCalendar): TDateTime; override;
|
||||
class procedure SetDateTime(const ACalendar: TCustomCalendar; const ADateTime: TDateTime); override;
|
||||
class procedure SetDisplaySettings(const ACalendar: TCustomCalendar; const ASettings: TDisplaySettings); override;
|
||||
class procedure SetReadOnly(const ACalendar: TCustomCalendar; const AReadOnly: boolean); override;
|
||||
end;
|
||||
|
||||
|
||||
@ -139,11 +138,6 @@ begin
|
||||
SetWindowLong(ACalendar.Handle, GWL_STYLE, Style);
|
||||
end;
|
||||
|
||||
class procedure TWin32WSCustomCalendar.SetReadOnly(const ACalendar: TCustomCalendar; const AReadOnly: boolean);
|
||||
begin
|
||||
// TODO: implement me!
|
||||
end;
|
||||
|
||||
initialization
|
||||
|
||||
////////////////////////////////////////////////////
|
||||
|
@ -43,7 +43,6 @@ type
|
||||
class function GetDateTime(const ACalendar: TCustomCalendar): TDateTime; override;
|
||||
class procedure SetDateTime(const ACalendar: TCustomCalendar; const ADateTime: TDateTime); override;
|
||||
class procedure SetDisplaySettings(const ACalendar: TCustomCalendar; const ASettings: TDisplaySettings); override;
|
||||
class procedure SetReadOnly(const ACalendar: TCustomCalendar; const AReadOnly: boolean); override;
|
||||
end;
|
||||
|
||||
implementation
|
||||
@ -129,11 +128,6 @@ if not WSCheckHandleAllocated(ACalendar, 'TWin32WSCustomCalendar.SetDisplaySetti
|
||||
SetWindowLong(ACalendar.Handle, GWL_STYLE, Style);
|
||||
end;
|
||||
|
||||
class procedure TWinCEWSCustomCalendar.SetReadOnly(const ACalendar: TCustomCalendar; const AReadOnly: boolean);
|
||||
begin
|
||||
// TODO: implement me!
|
||||
end;
|
||||
|
||||
initialization
|
||||
|
||||
////////////////////////////////////////////////////
|
||||
|
@ -44,22 +44,22 @@ uses
|
||||
// To get as little as posible circles,
|
||||
// uncomment only when needed for registration
|
||||
////////////////////////////////////////////////////
|
||||
Calendar,
|
||||
Types, Calendar,
|
||||
////////////////////////////////////////////////////
|
||||
WSLCLClasses, WSControls;
|
||||
|
||||
type
|
||||
{ TWSCustomCalendar }
|
||||
|
||||
TWSCustomCalendarClass = class of TWSCustomCalendar;
|
||||
TWSCustomCalendar = class(TWSWinControl)
|
||||
published
|
||||
class function GetDateTime(const ACalendar: TCustomCalendar): TDateTime; virtual;
|
||||
class function GetDateTime(const ACalendar: TCustomCalendar): TDateTime; virtual;
|
||||
class function HitTest(const ACalendar: TCustomCalendar; const APoint: TPoint): TCalendarPart; virtual;
|
||||
class procedure SetDateTime(const ACalendar: TCustomCalendar; const ADateTime: TDateTime); virtual;
|
||||
class procedure SetDisplaySettings(const ACalendar: TCustomCalendar;
|
||||
const ADisplaySettings: TDisplaySettings); virtual;
|
||||
class procedure SetReadOnly(const ACalendar: TCustomCalendar; const AReadOnly: boolean); virtual;
|
||||
end;
|
||||
TWSCustomCalendarClass = class of TWSCustomCalendar;
|
||||
|
||||
|
||||
implementation
|
||||
@ -69,6 +69,11 @@ begin
|
||||
Result := 0.0;
|
||||
end;
|
||||
|
||||
class function TWSCustomCalendar.HitTest(const ACalendar: TCustomCalendar; const APoint: TPoint): TCalendarPart;
|
||||
begin
|
||||
Result := cpNoWhere;
|
||||
end;
|
||||
|
||||
class procedure TWSCustomCalendar.SetDateTime(const ACalendar: TCustomCalendar; const ADateTime: TDateTime);
|
||||
begin
|
||||
end;
|
||||
@ -78,10 +83,6 @@ class procedure TWSCustomCalendar.SetDisplaySettings(const ACalendar: TCustomCal
|
||||
begin
|
||||
end;
|
||||
|
||||
class procedure TWSCustomCalendar.SetReadOnly(const ACalendar: TCustomCalendar; const AReadOnly: boolean);
|
||||
begin
|
||||
end;
|
||||
|
||||
initialization
|
||||
|
||||
////////////////////////////////////////////////////
|
||||
@ -90,4 +91,4 @@ initialization
|
||||
////////////////////////////////////////////////////
|
||||
// RegisterWSComponent(TCustomCalendar, TWSCustomCalendar);
|
||||
////////////////////////////////////////////////////
|
||||
end.
|
||||
end.
|
||||
|
Loading…
Reference in New Issue
Block a user