/usr/lib/lazarus/0.9.30.4/lcl/calendar.pp is in lazarus-src-0.9.30.4 0.9.30.4-6.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 | {
/***************************************************************************
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+}
{off $Define VerboseCalenderSetDate}
interface
uses
{$IFDEF VerboseCalenderSetDate}LCLProc,{$ENDIF}
Types, 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: TSize; override;
procedure Loaded; override;
procedure InitializeWnd; override;
procedure DestroyWnd; override;
public
constructor Create(AOwner: TComponent); override;
function HitTest(APoint: TPoint): TCalendarPart;
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)
published
property Align;
property Anchors;
property AutoSize;
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;
with GetControlClassDefaultSize do
SetInitialBounds(0, 0, CX, CY);
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;
procedure TCustomCalendar.DestroyWnd;
begin
// fetch widgetset values in local variables
GetProps;
inherited DestroyWnd;
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(DefaultFormatSettings.ShortDateFormat,FDate);
{$IFDEF VerboseCalenderSetDate}
DebugLn('TCustomCalendar.SetDateTime FDate=',DateToStr(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(DefaultFormatSettings.ShortDateFormat,FDate);
{$IFDEF VerboseCalenderSetDate}
DebugLn('TCustomCalendar.GetProps A ',DateToStr(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 ',DateToStr(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: TSize;
begin
Result.CX := 220;
Result.CY := 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;
end.
|