lazarus/lcl/calendar.pp
paul f02c53c71c merge lcl-smartlink branch:
------------------------------------------------------------------------
r19294 | paul | 2009-04-10 11:17:35 +0800 (Птн, 10 Апр 2009) | 1 line

lcl, win32: start optimizations: imglist (all), controls (all), combtrls (statubar)
------------------------------------------------------------------------
r19305 | martin | 2009-04-10 21:53:27 +0800 (Птн, 10 Апр 2009) | 1 line

Moved "DoneRegisterCheck" to global LCL
------------------------------------------------------------------------
r19306 | martin | 2009-04-10 22:14:57 +0800 (Птн, 10 Апр 2009) | 1 line

Moved "DoneRegisterCheck" to global LCL (more)
------------------------------------------------------------------------
r19307 | martin | 2009-04-10 22:22:44 +0800 (Птн, 10 Апр 2009) | 1 line

changed case true => True
------------------------------------------------------------------------
r19308 | paul | 2009-04-10 22:28:28 +0800 (Птн, 10 Апр 2009) | 1 line

fix file case
------------------------------------------------------------------------
r19311 | martin | 2009-04-10 23:09:16 +0800 (Птн, 10 Апр 2009) | 1 line

Moved Registration of TCustomCalendar
------------------------------------------------------------------------
r19312 | martin | 2009-04-10 23:28:03 +0800 (Птн, 10 Апр 2009) | 1 line

Moved PropertyToSkip for TCalender
------------------------------------------------------------------------
r19314 | paul | 2009-04-10 23:50:30 +0800 (Птн, 10 Апр 2009) | 1 line

merge r13913 #999e8b059d
------------------------------------------------------------------------
r19315 | paul | 2009-04-10 23:53:07 +0800 (Птн, 10 Апр 2009) | 1 line

cleanup WSCalendar
------------------------------------------------------------------------
r19316 | paul | 2009-04-11 00:37:44 +0800 (Сбт, 11 Апр 2009) | 1 line

finish with ComCtrls
------------------------------------------------------------------------
r19318 | martin | 2009-04-11 01:37:40 +0800 (Сбт, 11 Апр 2009) | 1 line

Moved dialogs
------------------------------------------------------------------------
r19319 | martin | 2009-04-11 01:47:30 +0800 (Сбт, 11 Апр 2009) | 1 line

Moved dialogs
------------------------------------------------------------------------
r19320 | martin | 2009-04-11 02:47:52 +0800 (Сбт, 11 Апр 2009) | 1 line

Moved ExtCtrls, ExtDlgs
------------------------------------------------------------------------
r19321 | martin | 2009-04-11 03:23:32 +0800 (Сбт, 11 Апр 2009) | 1 line

Moved PropertyToSkip
------------------------------------------------------------------------
r19322 | martin | 2009-04-11 03:37:39 +0800 (Сбт, 11 Апр 2009) | 1 line

Moved StdCtrls
------------------------------------------------------------------------
r19323 | martin | 2009-04-11 04:05:50 +0800 (Сбт, 11 Апр 2009) | 1 line

Moved Buttons
------------------------------------------------------------------------
r19325 | paul | 2009-04-11 11:02:26 +0800 (Сбт, 11 Апр 2009) | 1 line

remove DirSel
------------------------------------------------------------------------
r19326 | paul | 2009-04-11 11:11:37 +0800 (Сбт, 11 Апр 2009) | 1 line

RegisterArrow
------------------------------------------------------------------------
r19327 | paul | 2009-04-11 11:32:09 +0800 (Сбт, 11 Апр 2009) | 1 line

register WS classes only for TCustomXXX classes if they are available (like TCustomScrollBar instead of TScrollBar) and only for those descendants which really differ (like TRadioButton, TToggleButton)
------------------------------------------------------------------------
r19328 | paul | 2009-04-11 11:40:00 +0800 (Сбт, 11 Апр 2009) | 1 line

RegisterCustomCheckBox
------------------------------------------------------------------------
r19329 | paul | 2009-04-11 11:57:22 +0800 (Сбт, 11 Апр 2009) | 1 line

RegisterXXX for Forms
------------------------------------------------------------------------
r19330 | paul | 2009-04-11 12:13:05 +0800 (Сбт, 11 Апр 2009) | 1 line

RegisterCustomGrid + move of RegisterPropertyToSkip
------------------------------------------------------------------------
r19331 | paul | 2009-04-11 12:24:29 +0800 (Сбт, 11 Апр 2009) | 1 line

RegisterXXX for Menus
------------------------------------------------------------------------
r19332 | paul | 2009-04-11 12:35:16 +0800 (Сбт, 11 Апр 2009) | 1 line

RegisterXXX for PairSplitter
------------------------------------------------------------------------
r19333 | paul | 2009-04-11 12:47:39 +0800 (Сбт, 11 Апр 2009) | 1 line

RegisterXXX for Spin
------------------------------------------------------------------------
r19334 | paul | 2009-04-11 12:58:55 +0800 (Сбт, 11 Апр 2009) | 1 line

RegisterCustomRubberBand
------------------------------------------------------------------------
r19335 | paul | 2009-04-11 13:31:43 +0800 (Сбт, 11 Апр 2009) | 1 line

remove 2 initialization sections
------------------------------------------------------------------------
r19336 | paul | 2009-04-11 13:46:26 +0800 (Сбт, 11 Апр 2009) | 1 line

remove TPopupNotifier.png from LCL
------------------------------------------------------------------------
r19338 | paul | 2009-04-11 13:54:03 +0800 (Сбт, 11 Апр 2009) | 1 line

cleanup
------------------------------------------------------------------------
r19341 | paul | 2009-04-11 14:59:27 +0800 (Сбт, 11 Апр 2009) | 1 line

cleanup
------------------------------------------------------------------------
r19343 | martin | 2009-04-11 19:59:18 +0800 (Сбт, 11 Апр 2009) | 1 line

Reduced Unit-Circles, by moving Register* into WS* units
------------------------------------------------------------------------
r19344 | martin | 2009-04-11 20:22:49 +0800 (Сбт, 11 Апр 2009) | 1 line

Dummy file for gtk
------------------------------------------------------------------------
r19345 | martin | 2009-04-11 21:06:55 +0800 (Сбт, 11 Апр 2009) | 1 line

Initial move of gtk1 register
------------------------------------------------------------------------
r19346 | martin | 2009-04-11 21:19:48 +0800 (Сбт, 11 Апр 2009) | 1 line

Missing dependencies in gtk1 wsfactory
------------------------------------------------------------------------
r19347 | martin | 2009-04-11 22:36:42 +0800 (Сбт, 11 Апр 2009) | 1 line

Declare register* in interface, to keep external linker happy
------------------------------------------------------------------------
r19348 | martin | 2009-04-11 23:34:16 +0800 (Сбт, 11 Апр 2009) | 1 line

Declare register* in interface, to keep external linker happy 
------------------------------------------------------------------------
r19349 | martin | 2009-04-11 23:39:20 +0800 (Сбт, 11 Апр 2009) | 1 line

moved uses for factory
------------------------------------------------------------------------
r19350 | martin | 2009-04-11 23:41:57 +0800 (Сбт, 11 Апр 2009) | 1 line

corrected a few accidental "Result := False"
------------------------------------------------------------------------
r19351 | paul | 2009-04-12 00:04:15 +0800 (Вск, 12 Апр 2009) | 1 line

removed unused units
------------------------------------------------------------------------
r19352 | paul | 2009-04-12 00:05:26 +0800 (Вск, 12 Апр 2009) | 1 line

qt: move RegisterWS calls to qtwsfactory
------------------------------------------------------------------------
r19354 | paul | 2009-04-12 01:04:04 +0800 (Вск, 12 Апр 2009) | 1 line

wince: move RegisterWS calls to WinCEWSFactory
------------------------------------------------------------------------
r19356 | martin | 2009-04-12 01:39:56 +0800 (Вск, 12 Апр 2009) | 1 line

moved GTK2
------------------------------------------------------------------------
r19357 | martin | 2009-04-12 01:45:31 +0800 (Вск, 12 Апр 2009) | 1 line

moved GTK2 / missing units
------------------------------------------------------------------------
r19358 | martin | 2009-04-12 01:57:43 +0800 (Вск, 12 Апр 2009) | 1 line

Fixed one return value from register
------------------------------------------------------------------------
r19360 | martin | 2009-04-12 02:47:42 +0800 (Вск, 12 Апр 2009) | 1 line

Gtk2 , needs 2 registrations for WinControl
------------------------------------------------------------------------
r19361 | martin | 2009-04-12 02:57:58 +0800 (Вск, 12 Апр 2009) | 1 line

Gtk2 , needs 2nd registrations
------------------------------------------------------------------------
r19368 | paul | 2009-04-12 13:09:59 +0800 (Вск, 12 Апр 2009) | 1 line

cleanup
------------------------------------------------------------------------
r19373 | paul | 2009-04-12 13:45:17 +0800 (Вск, 12 Апр 2009) | 1 line

wince: forgotten file
------------------------------------------------------------------------
r19374 | paul | 2009-04-12 14:04:04 +0800 (Вск, 12 Апр 2009) | 1 line

carbon: move RegisterWSComponent to CarbonWSFactory
------------------------------------------------------------------------
r19375 | paul | 2009-04-12 14:27:47 +0800 (Вск, 12 Апр 2009) | 1 line

cleanup
------------------------------------------------------------------------

git-svn-id: trunk@19376 -
2009-04-12 08:46:31 +00:00

330 lines
9.7 KiB
ObjectPascal

{
/***************************************************************************
Calendar.pp
-------------------
Component Library Calendar Component
Initial Revision : Wed Dec 05 2001
***************************************************************************/
*****************************************************************************
* *
* This file is part of the Lazarus Component Library (LCL) *
* *
* See the file COPYING.modifiedLGPL.txt, included in this distribution, *
* for details about the copyright. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* *
*****************************************************************************
}
{
@abstract(Calendar component)
@author(Shane Miller)
@created(05 Dev 2001)
}
unit Calendar;
{$mode objfpc}{$H+}
interface
uses
SysUtils, Classes, LCLType, LCLStrConsts, lMessages, Controls, LResources;
type
TDisplaySetting = (
dsShowHeadings,
dsShowDayNames,
dsNoMonthChange,
dsShowWeekNumbers,
dsStartMonday
);
TDisplaySettings = set of TDisplaySetting;
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 }
TCustomCalendar = class(TWinControl)
private
FDateAsString : String;
FDate: TDateTime; // last valid date
FDisplaySettings : TDisplaySettings;
FOnChange: TNotifyEvent;
FDayChanged: TNotifyEvent;
FMonthChanged: TNotifyEvent;
FYearChanged: TNotifyEvent;
FPropsChanged: boolean;
function GetDateTime: TDateTime;
procedure SetDateTime(const AValue: TDateTime);
procedure GetProps;
procedure SetProps;
function GetDisplaySettings: TDisplaySettings;
procedure SetDisplaySettings(const AValue: TDisplaySettings);
function GetDate: String;
procedure SetDate(const AValue: String);
protected
class procedure WSRegisterClass; override;
procedure LMChanged(var Message: TLMessage); message LM_CHANGED;
procedure LMMonthChanged(var Message: TLMessage); message LM_MONTHCHANGED;
procedure LMYearChanged(var Message: TLMessage); message LM_YEARCHANGED;
procedure LMDayChanged(var Message: TLMessage); message LM_DAYCHANGED;
class function GetControlClassDefaultSize: TPoint; override;
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 OnChange: TNotifyEvent read FOnChange write FOnChange;
property OnDayChanged: TNotifyEvent read FDayChanged write FDayChanged;
property OnMonthChanged: TNotifyEvent read FMonthChanged write FMonthChanged;
property OnYearChanged: TNotifyEvent read FYearChanged write FYearChanged;
end;
{ TCalendar }
TCalendar = class(TCustomCalendar)
protected
class procedure WSRegisterClass; override;
published
property Align;
property Anchors;
property BorderSpacing;
property Constraints;
property Date;
property DateTime;
property DisplaySettings;
property OnChange;
property OnChangeBounds;
property OnClick;
property OnDayChanged;
property OnDblClick;
property OnEnter;
property OnExit;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMonthChanged;
property OnMouseDown;
property OnMouseEnter;
property OnMouseLeave;
property OnMouseMove;
property OnMouseUp;
property OnResize;
property OnUTF8KeyPress;
property OnYearChanged;
property PopupMenu;
property ShowHint;
property TabStop;
property Visible;
end;
procedure Register;
implementation
uses
WSCalendar;
procedure Register;
begin
RegisterComponents('Misc',[TCalendar]);
end;
{ TCustomCalendar }
constructor TCustomCalendar.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
fCompStyle := csCalendar;
SetInitialBounds(0,0,GetControlClassDefaultSize.X,GetControlClassDefaultSize.Y);
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;
if FPropsChanged then SetProps;
end;
procedure TCustomCalendar.InitializeWnd;
begin
inherited InitializeWnd;
if FPropsChanged then SetProps;
end;
function TCustomCalendar.GetDate: String;
begin
Result := '';
GetProps;
Result := FDateAsString;
end;
procedure TCustomCalendar.SetDate(const AValue: String);
var
NewDate: TDateTime;
begin
if FDateAsString = AValue then Exit;
NewDate:=StrToDate(AValue); //test to see if date valid ....
// no exception => set valid date
FDateAsString := AValue;
FDate := NewDate;
SetProps;
end;
class procedure TCustomCalendar.WSRegisterClass;
begin
inherited WSRegisterClass;
RegisterCustomCalendar;
end;
function TCustomCalendar.GetDisplaySettings: TDisplaySettings;
begin
Result := FDisplaySettings;
end;
procedure TCustomCalendar.SetDisplaySettings(const AValue: TDisplaySettings);
begin
if FDisplaySettings = AValue then exit;
FDisplaySettings := AValue;
SetProps;
end;
function TCustomCalendar.GetDateTime: TDateTime;
begin
GetProps;
Result:=FDate;
end;
procedure TCustomCalendar.SetDateTime(const AValue: TDateTime);
{$IFDEF WINDOWS}
var
CalendarMinDate,CalendarMaxDate: integer;
{$ENDIF}
begin
if AValue=FDate then exit;
{$IFDEF WINDOWS} // TODO: move this test to the win32 interface?
CalendarMinDate:=-53787;// 14 sep 1752, start of Gregorian calendar in England
CalendarMaxDate:=trunc(MaxDateTime);
if not ((AValue>=CalendarMinDate)and(AValue<=CalendarMaxDate)) then
raise EInvalidDate.CreateFmt(rsInvalidDateRangeHint, [DateToStr(AValue),
DateToStr(CalendarMinDate), DateToStr(CalendarMaxDate)]);
{$ENDIF}
FDate:=AValue;
FDateAsString:=FormatDateTime(ShortDateFormat,FDate);
{$IFDEF VerboseCalenderSetDate}
DebugLn('TCustomCalendar.SetDateTime FDate=',FDate,' FDateAsString=',FDateAsString,' ShortDateFormat=',ShortDateFormat);
{$ENDIF}
SetProps;
end;
procedure TCustomCalendar.GetProps;
begin
if HandleAllocated and ([csLoading,csDestroying]*ComponentState=[]) then
begin
FDate := TWSCustomCalendarClass(WidgetSetClass).GetDateTime(Self);
FDateAsString := FormatDateTime(ShortDateFormat,FDate);
{$IFDEF VerboseCalenderSetDate}
DebugLn('TCustomCalendar.GetProps A ',FDate,' ',FDateAsString);
{$ENDIF}
end;
end;
procedure TCustomCalendar.SetProps;
begin
if HandleAllocated and ([csLoading,csDestroying]*ComponentState=[]) then
begin
FPropsChanged := False;
{$IFDEF VerboseCalenderSetDate}
DebugLn('TCustomCalendar.SetProps A ',FDate,' ',FDateAsString);
{$ENDIF}
TWSCustomCalendarClass(WidgetSetClass).SetDateTime(Self, FDate);
TWSCustomCalendarClass(WidgetSetClass).SetDisplaySettings(Self, FDisplaySettings);
end
else
FPropsChanged := True;
end;
procedure TCustomCalendar.LMChanged(var Message: TLMessage);
var
NewDate: TDateTime;
OldDay, OldMonth, OldYear: word;
NewDay, NewMonth, NewYear: word;
begin
NewDate := TWSCustomCalendarClass(WidgetSetClass).GetDateTime(Self);
if (NewDate=FDate) then exit;
DecodeDate(NewDate, NewYear, NewMonth, NewDay);
DecodeDate(FDate, OldYear, OldMonth, OldDay);
FDate:= NewDate;
if (OldYear<>NewYear) and Assigned(OnYearChanged) then OnYearChanged(self);
if (OldMonth<>NewMonth) and Assigned(OnMonthChanged) then OnMonthChanged(self);
if (OldDay<>NewDay) and Assigned(OnDayChanged) then OnDayChanged(self);
if Assigned(OnChange) then OnChange(self);
end;
procedure TCustomCalendar.LMDAYChanged(var Message: TLMessage);
begin
if Assigned(OnDayChanged) then OnDayChanged(self);
if Assigned(OnChange) then OnChange(self);
end;
class function TCustomCalendar.GetControlClassDefaultSize: TPoint;
begin
Result.X:=220;
Result.Y:=190;
end;
procedure TCustomCalendar.LMMonthChanged(var Message: TLMessage);
begin
if Assigned(OnMonthChanged) then OnMonthChanged(self);
if Assigned(OnChange) then OnChange(self);
end;
procedure TCustomCalendar.LMYEARChanged(var Message: TLMessage);
begin
if Assigned(OnYearChanged) then OnYearChanged(self);
if Assigned(OnChange) then OnChange(self);
end;
{ TCalendar }
class procedure TCalendar.WSRegisterClass;
begin
RegisterPropertyToSkip(TCalendar, 'ReadOnly', 'Obsoleted property', '');
inherited WSRegisterClass;
end;
end.