fixed TCalendar resizing problems from Salvatore

git-svn-id: trunk@6842 -
This commit is contained in:
mattias 2005-02-25 18:16:41 +00:00
parent 383be2bf12
commit 0c61b784a6
3 changed files with 171 additions and 312 deletions

View File

@ -139,7 +139,7 @@ constructor TCustomCalendar.Create(TheOwner: TComponent);
begin
inherited Create(TheOwner);
fCompStyle := csCalendar;
SetInitialBounds(0,0,250,150);
SetInitialBounds(0,0,190,153);
fDisplaySettings := [dsShowHeadings, dsShowDayNames];
ControlStyle:=ControlStyle-csMultiClicks-[csAcceptsControls];
Date := FormatDateTime(ShortDateFormat,Now);

View File

@ -287,76 +287,36 @@ type
{ TDateEdit }
TAcceptDateEvent = Procedure (Sender : TObject; Var ADate : TDateTime;
Var AcceptDate: Boolean) of Object;
TDateEdit = Class(TCustomEditButton)
TDateEdit=class(TEditButton)
private
FDialogTitle: String;
FDialogTitle:TCaption;
FDisplaySettings: TDisplaySettings;
FOnAcceptDate: TAcceptDateEvent;
function GetDate: TDateTime;
procedure SetDate(const AValue: TDateTime);
Function StoreTitle : Boolean;
Protected
Function CreateDateBitmap : TBitmap; Virtual;
FOKCaption:TCaption;
FCancelCaption:TCaption;
FDate: TDateTime;
function IsStoreTitle: boolean;
procedure SetDate(Value:TDateTime);
protected
procedure DoButtonClick (Sender: TObject); override;
Procedure RunDialog; Virtual;
Public
procedure Change; override;
public
constructor Create(AOwner: TComponent); override;
Destructor Destroy; override;
Property Date : TDateTime Read GetDate Write SetDate;
Published
// TDateEdit settings
destructor Destroy; override;
published
property DialogTitle:TCaption Read FDialogTitle Write FDialogTitle Stored IsStoreTitle;
Property CalendarDisplaySettings : TDisplaySettings Read FDisplaySettings Write FDisplaySettings;
Property OnAcceptDate : TAcceptDateEvent Read FOnAcceptDAte Write FOnAcceptDate;
Property DialogTitle : String Read FDialogTitle Write FDialogTitle Stored StoreTitle;
// TEditButton properties.
Property ButtonWidth;
Property DirectInput;
Property ButtonOnlyWhenFocused;
// property Glyph;
property NumGlyphs;
Property Flat;
// Other properties
property Align;
property Anchors;
property BorderSpacing;
property AutoSize;
property Color;
property Ctl3D;
property DragCursor;
property DragMode;
property Enabled;
property Font;
property MaxLength;
property ParentColor;
property ParentCtl3D;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ReadOnly;
property ShowHint;
property TabOrder;
property TabStop;
property Visible;
property OnChange;
property OnClick;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnStartDrag;
property OKCaption:TCaption Read FOKCaption Write FOKCaption;
property CancelCaption:TCaption Read FCancelCaption Write FCancelCaption;
property Date: TDateTime Read FDate Write SetDate;
end;
{ TCalcEdit }
@ -833,9 +793,19 @@ end;
constructor TDateEdit.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FDate:=Now;
Date:=trunc(FDate);
Text:=DateToStr(Date);
FDisplaySettings:=[dsShowHeadings, dsShowDayNames];
FDialogTitle:=rsPickDate;
Glyph:=CreateDateBitmap;
DialogTitle:='Select a date';
OKCaption:='OK';
CancelCaption:='Cancel';
ReadOnly:=true;
Color:=clBtnFace;
Button.Glyph:=CreateDateGlyph;//.LoadFromLazarusResource('DateEditGlyph'); //GlyphFromBitmapOrResource(DateGlyph,ResBtnCalendar)
Button.OnClick:= @DoButtonClick;
// OnChange:=@Change;
OnDblClick:=@DoButtonClick;
end;
destructor TDateEdit.Destroy;
@ -843,73 +813,62 @@ begin
inherited Destroy;
end;
function TDateEdit.GetDate: TDateTime;
begin
Result:=0;
Try
Result:=StrToDate(Text)
Except
// Catch errors.
end;
end;
procedure TDateEdit.SetDate(const AValue: TDateTime);
begin
Text:=DateToStr(AValue);
end;
function TDateEdit.StoreTitle: Boolean;
begin
Result:=FDialogTitle<>rsPickDate;
end;
function TDateEdit.CreateDateBitmap: TBitmap;
begin
Result:=CreateDateGlyph;
end;
procedure TDateEdit.DoButtonClick(Sender: TObject);
procedure TDateEdit.DoButtonClick(Sender:TObject);//or onClick
var CD:TCalendarDialog;
B:Boolean;
D:TDateTime;
begin
inherited DoButtonClick(Sender);
RunDialog;
end;
procedure TDateEdit.RunDialog;
Var
FCalendar : TCalendarDialogForm;
B : Boolean;
D : TDateTime;
P : TPoint;
begin
FCalendar:=CreateCalendarForm(Self,0);
Try
P.X:=Self.Left;
P.Y:=Self.top;
P:=ClientToScreen(P);
P.Y:=P.Y+Self.Height;
FCalendar.Top:=P.Y;
FCalendar.Left:=P.X;
FCalendar.DisplaySettings:=FDisplaySettings;
FCalendar.Date:=Date;
FCalendar.Caption:=DialogTitle;
If FCalendar.ShowModal=mrOK then
begin
D:=FCalendar.Date;
B:=True;
CD:=TCalendarDialog.Create(Self);
with CD do begin
Date:=Self.Date;
CancelCaption:=Self.CancelCaption;
OKCaption:=Self.OKCaption;
DialogTitle:=Self.DialogTitle;
DisplaySettings:=Self.CalendarDisplaySettings;
end;
try
if CD.Execute then begin
FDate:=CD.Date;
Self.Date:=FDate;
D:=FDate;
B:=true;
If Assigned(FOnAcceptDate) then
FOnAcceptDate(Self,D,B);
If B then
Date:=D;
end;
Finally
FCalendar.Free;
Text:=DateToStr(FDate);
end;
except
raise Exception.Create('Errore in calendar dialog di dateedit');
end;
FreeAndNil(CD);
end;
procedure TDateEdit.Change;//(Sender:TObject);
var Datetmp:TDate;
begin
inherited Change;//(Sender);
try
Datetmp:=StrToDate(Text);
Date:=Datetmp;
except
//inherited Change(Sender)
end;
end;
function TDateEdit.IsStoreTitle: boolean;
begin
Result:=DialogTitle<>rsPickDate;
end;
procedure TDateEdit.SetDate(Value:TDateTime);
begin
if FDate=Value then exit;
FDate:=Value;
Text:=DateToStr(FDate);
end;
{ TCalcEdit }

View File

@ -192,29 +192,7 @@ function CreateCalculatorForm(AOwner: TComponent; ALayout : TCalculatorLayout; A
Type
TCalendarDialogForm = Class(TForm)
private
FCalendar : TCalendar;
FPanel : TPanel;
FOK : TButton;
FCancel : TButton;
function GetDate: TDateTime;
Procedure SetDate (Value : TDateTime);
function GetDisplaySettings: TDisplaySettings;
procedure SetDisplaySettings(const AValue: TDisplaySettings);
Protected
Property Calendar : TCalendar Read FCalendar;
Property ButtonPanel : TPanel Read FPanel;
Property OKButton : TButton Read FOK;
Property CancelButton : TButton Read FCancel;
Procedure InitForm; virtual;
Public
Constructor Create(AOwner : TComponent); override;
Destructor Destroy; override;
Property Date : TDateTime Read GetDate Write SetDate;
Property DisplaySettings : TDisplaySettings Read GetDisplaySettings Write SetDisplaySettings;
end;
{ TCalendarDialog }
TCalendarDialog = class(TCommonDialog)
private
FDate: TDateTime;
@ -223,26 +201,29 @@ Type
FHelpContext: THelpContext;
FMonthChanged: TNotifyEvent;
FYearChanged: TNotifyEvent;
function GetDialogTitle: String;
procedure SetDialogTitle(const AValue: String);
Function IsTitleStored: Boolean;
Public
Constructor Create(AOwner: TComponent); override;
Destructor Destroy; override;
Function Execute: Boolean; override;
Function CreateForm: TCalendarDialogForm; virtual;
Published
Property DialogTitle: String Read GetDialogTitle Write SetDialogTitle Stored IsTitleStored;
Property Date: TDateTime Read FDate Write FDate;
Property DisplaySettings: TDisplaySettings Read FDisplaySettings Write FDisplaySettings;
property HelpContext: THelpContext read FHelpContext write FHelpContext default 0;
FDialogTitle:TCaption;
FOKCaption:TCaption;
FCancelCaption:TCaption;
FCalendar:TCalendar;
function IsTitleStored: Boolean;
protected
procedure GetNewDate(Sender:TObject);//or onClick
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
function Execute: Boolean; override;
published
property Date: TDateTime Read FDate Write FDate;
property OnDayChanged: TNotifyEvent read FDayChanged write FDayChanged;
property DisplaySettings: TDisplaySettings Read FDisplaySettings Write FDisplaySettings;
property HelpContext: THelpContext read FHelpContext write FHelpContext default 0;
property OnMonthChanged: TNotifyEvent read FMonthChanged write FMonthChanged;
property OnYearChanged: TNotifyEvent read FYearChanged write FYearChanged;
property DialogTitle:TCaption Read FDialogTitle Write FDialogTitle Stored IsTitleStored;
property OKCaption:TCaption Read FOKCaption Write FOKCaption;
property CancelCaption:TCaption Read FCancelCaption Write FCancelCaption;
end;
function CreateCalendarForm(AOwner: TComponent; AHelpContext: THelpContext): TCalendarDialogForm;
procedure Register;
@ -481,21 +462,6 @@ begin
end;
end;
function CreateCalendarForm(AOwner: TComponent; AHelpContext: THelpContext
): TCalendarDialogForm;
begin
Result:=TCalendarDialogForm.Create(AOwner);
With Result do
Try
HelpContext:=AHelpContext;
Left:=(Screen.Width div 2) - (Width div 2);
Top:=(Screen.Height div 2) - (Height div 2);
except
Free;
Raise;
end;
end;
{ ---------------------------------------------------------------------
Calculator Dialog
---------------------------------------------------------------------}
@ -1184,126 +1150,16 @@ end;
TCalendarDialog
---------------------------------------------------------------------}
{ TCalendarDialogForm }
function TCalendarDialogForm.GetDate: TDateTime;
begin
Try
Result:=StrToDate(FCalendar.Date);
Except
Result:=0;
end;
end;
procedure TCalendarDialogForm.SetDate(Value: TDateTime);
begin
FCalendar.Date:=DateToStr(Date);
end;
function TCalendarDialogForm.GetDisplaySettings: TDisplaySettings;
begin
Result:=FCalendar.DisplaySettings;
end;
procedure TCalendarDialogForm.SetDisplaySettings(const AValue: TDisplaySettings);
begin
FCalendar.DisplaySettings:=AValue;
end;
procedure TCalendarDialogForm.InitForm;
begin
// TODO: let the size of this dialog dependent on the prefered size of
// the calendar, because the gtk calendar is smaller than the win32 calendar.
Height:=170;
Width:=200;
Position:=poScreenCenter;
BorderStyle:=bsDialog;
FCalendar:=TCalendar.Create(Self);
With FCalendar do
begin
Parent:=Self;
SetBounds(0,0,Self.Width,118);
Align:=alClient;
//Anchors:=[akLeft,akRight,akTop,akBottom];
end;
FPanel:=TPanel.Create(Self);
With FPanel do
begin
Parent:=Self;
Top:=109;
Height:=32;
Width:=200;
Align:=alBottom;
Anchors:=[akLeft,akRight,akBottom];
Caption:='';
BevelOuter:=bvLowered;
end;
FOK:=TButton.Create(Self);
With FOK do
begin
Parent:=FPanel;
Caption:='&OK';
Top:=4;
Height:=24;
Width:=50;
Left:=Self.Width-FOK.Width-4;
Anchors:=[akRight,akTop];
Default:=True;
ModalResult:=MrOK;
end;
FCancel:=TButton.Create(Self);
With FCancel do
begin
Parent:=FPanel;
Caption:='&Cancel';
Height:=24;
Top:=4;
Width:=50;
Left:=FOK.Left-FCancel.Width-4;
Anchors:=[akright,aktop];
Cancel:=True;
ModalResult:=MrCancel;
end;
end;
constructor TCalendarDialogForm.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
InitForm;
end;
destructor TCalendarDialogForm.Destroy;
begin
FCalendar.Free;
FOK.Free;
FCancel.Free;
FPanel.Free;
inherited Destroy;
end;
{ TCalendarDialog }
function TCalendarDialog.IsTitleStored: Boolean;
begin
Result:=Title<>rsPickDate;
end;
function TCalendarDialog.GetDialogTitle: String;
begin
Result:=Title;
end;
procedure TCalendarDialog.SetDialogTitle(const AValue: String);
begin
Title:=AValue;
end;
constructor TCalendarDialog.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FDate:=Sysutils.Date;
Title:=rsPickDate;
FDate:=Now;
Date:=trunc(FDate);
DialogTitle:=rsPickDate;
OKCaption:=rsMbOK;
CancelCaption:=rsMbCancel;
end;
destructor TCalendarDialog.Destroy;
@ -1311,37 +1167,81 @@ begin
inherited Destroy;
end;
function TCalendarDialog.Execute: Boolean;
Var
Dlg: TCalendarDialogForm;
D: TDateTime;
procedure TCalendarDialog.GetNewDate(Sender:TObject);//or onClick
begin
Dlg:=CreateForm;
With Dlg do
Try
D:=FDate;
Dlg.Date:=D;
Result:=ShowModal=mrOK;
If Result then
Self.Date:=Dlg.Date;
Finally
Free;
end;
Date:=FCalendar.DateTime;
end;
function TCalendarDialog.CreateForm: TCalendarDialogForm;
function TCalendarDialog.IsTitleStored: Boolean;
begin
Result:=CreateCalendarForm(Self,HelpContext);
Result.Caption:=DialogTitle;
With Result.Calendar do
begin
displaySettings:=Self.DisplaySettings;
Result:=DialogTitle<>rsPickDate;//controllare
end;
function TCalendarDialog.Execute:boolean;
const dw=8;
var DF:TForm;
okButton,cancelButton:TButton;
panel:TPanel;
begin
DF:=TForm.Create(Self);
DF.Caption:=FDialogTitle;
DF.Position:=poMainFormCenter;
DF.BorderStyle:=bsDialog;
FCalendar:=TCalendar.Create(Self);
with FCalendar do begin
Parent:=DF;
DF.Width:=Width;
Align:=alTop;
DateTime:=Self.Date;
DisplaySettings:=Self.DisplaySettings;
OnDayChanged:=Self.OnDayChanged;
OnMonthChanged:=Self.OnMonthChanged;
OnYearChanged:=Self.OnYearChanged;
end;
end;
panel:=TPanel.Create(Self);
with panel do begin
Parent:=DF;
Caption:='';
Height:=32;
DF.Height:=FCalendar.Height+Height;
Align:=alBottom;
BevelOuter:=bvLowered;
end;
okButton:=TButton.Create(Self);
with okButton do begin
Parent:=panel;
Caption:=OKCaption;
Constraints.MinWidth:=75;
Constraints.MaxWidth:=FCalendar.Width div 2;
Width:=DF.Canvas.TextWidth(OKCaption)+2*dw;
ModalResult:=mrOK;
OnClick:=@GetNewDate;
Align:=alRight;
end;
cancelButton:=TButton.Create(Self);
with cancelButton do begin
Parent:=panel;
Caption:=CancelCaption;
Constraints.MinWidth:=75;
Constraints.MaxWidth:=FCalendar.Width div 2;
Width:=DF.Canvas.TextWidth(CancelCaption)+2*dw;;
ModalResult:=mrCancel;
Align:=alLeft;
end;
Result:=DF.ShowModal=mrOK;
FreeAndNil(FCalendar);
FreeAndNil(panel);
FreeAndNil(okButton);
FreeAndNil(cancelButton);
FreeAndNil(DF);
end;
Initialization
{$i extdlgs.lrs}