Dialogs, ExtDlgs:

- return correct Height/Width for TFindDialog, TCalendarDialog, TCalculatorDialog
- implement Top/Left for TExtCommonDialog

git-svn-id: trunk@47028 -
This commit is contained in:
bart 2014-11-29 16:19:38 +00:00
parent 841a604d6e
commit fbf0df95ec
4 changed files with 147 additions and 76 deletions

View File

@ -68,13 +68,15 @@ type
FCanCloseCalled: Boolean; FCanCloseCalled: Boolean;
FClosing: boolean; FClosing: boolean;
procedure SetHandle(const AValue: THandle); procedure SetHandle(const AValue: THandle);
procedure SetHeight(const AValue: integer);
procedure SetWidth(const AValue: integer);
function IsTitleStored: boolean; function IsTitleStored: boolean;
protected protected
class procedure WSRegisterClass; override; class procedure WSRegisterClass; override;
function DoExecute : boolean; virtual; function DoExecute : boolean; virtual;
function DefaultTitle: string; virtual; function DefaultTitle: string; virtual;
function GetHeight: Integer; virtual;
function GetWidth: Integer; virtual;
procedure SetHeight(const AValue: integer); virtual;
procedure SetWidth(const AValue: integer); virtual;
public public
FCompStyle : LongInt; FCompStyle : LongInt;
constructor Create(TheOwner: TComponent); override; constructor Create(TheOwner: TComponent); override;
@ -91,8 +93,8 @@ type
property OnCanClose: TCloseQueryEvent read FOnCanClose write FOnCanClose; property OnCanClose: TCloseQueryEvent read FOnCanClose write FOnCanClose;
property OnShow: TNotifyEvent read FOnShow write FOnShow; property OnShow: TNotifyEvent read FOnShow write FOnShow;
property HelpContext: THelpContext read FHelpContext write FHelpContext default 0; property HelpContext: THelpContext read FHelpContext write FHelpContext default 0;
property Width: integer read FWidth write SetWidth default 0; property Width: integer read GetWidth write SetWidth default 0;
property Height: integer read FHeight write SetHeight default 0; property Height: integer read GetHeight write SetHeight default 0;
property Title: TTranslateString read FTitle write FTitle stored IsTitleStored; property Title: TTranslateString read FTitle write FTitle stored IsTitleStored;
end; end;
@ -401,6 +403,8 @@ type
procedure HelpClick(Sender: TObject); procedure HelpClick(Sender: TObject);
procedure CancelClick(Sender: TObject); procedure CancelClick(Sender: TObject);
function GetHeight: Integer; override;
function GetWidth: Integer; override;
procedure UpdatePosition; procedure UpdatePosition;
procedure DoCloseForm(Sender: TObject; var CloseAction: TCloseAction);virtual; procedure DoCloseForm(Sender: TObject; var CloseAction: TCloseAction);virtual;
procedure Find; virtual; procedure Find; virtual;

View File

@ -107,9 +107,22 @@ type
TExtCommonDialog = class(TCommonDialog) TExtCommonDialog = class(TCommonDialog)
private private
FDialogPosition: TPosition; FDialogPosition: TPosition;
FLeft: Integer;
FTop: Integer;
FDlgForm: TCustomForm;
protected
function GetLeft: Integer; virtual;
function GetHeight: Integer; override;
function GetTop: Integer; virtual;
function GetWidth: Integer; override;
procedure SetLeft(AValue: Integer); virtual;
procedure SetTop(AValue: Integer); virtual;
property DlgForm: TCustomForm read FDlgForm write FDlgForm;
public public
constructor Create(AOwner: TComponent); override; constructor Create(AOwner: TComponent); override;
destructor Destroy; override; destructor Destroy; override;
property Left: Integer read GetLeft write SetLeft;
property Top: Integer read GetTop write SetTop;
published published
property DialogPosition: TPosition read FDialogPosition write FDialogPosition default poMainFormCenter; property DialogPosition: TPosition read FDialogPosition write FDialogPosition default poMainFormCenter;
end; end;
@ -136,7 +149,6 @@ type
FMemory: Double; FMemory: Double;
FPrecision: Byte; FPrecision: Byte;
FBeepOnError: Boolean; FBeepOnError: Boolean;
FCalc: TCalculatorForm;
FOnChange: TNotifyEvent; FOnChange: TNotifyEvent;
FOnCalcKey: TKeyPressEvent; FOnCalcKey: TKeyPressEvent;
FOnDisplayChange: TNotifyEvent; FOnDisplayChange: TNotifyEvent;
@ -206,7 +218,6 @@ Type
TCalendarDialog = class(TExtCommonDialog) TCalendarDialog = class(TExtCommonDialog)
private private
FDlgForm: TForm;
FDate: TDateTime; FDate: TDateTime;
FDayChanged: TNotifyEvent; FDayChanged: TNotifyEvent;
FDisplaySettings: TDisplaySettings; FDisplaySettings: TDisplaySettings;
@ -216,18 +227,12 @@ Type
FOKCaption:TCaption; FOKCaption:TCaption;
FCancelCaption:TCaption; FCancelCaption:TCaption;
FCalendar:TCalendar; FCalendar:TCalendar;
FLeft: Integer;
FTop: Integer;
function GetLeft: Integer;
function GetTop: Integer;
procedure OnDialogClose(Sender: TObject; var CloseAction: TCloseAction); procedure OnDialogClose(Sender: TObject; var CloseAction: TCloseAction);
procedure OnDialogCloseQuery(Sender : TObject; var CanClose : boolean); procedure OnDialogCloseQuery(Sender : TObject; var CanClose : boolean);
procedure OnCalendarDayChanged(Sender: TObject); procedure OnCalendarDayChanged(Sender: TObject);
procedure OnCalendarMonthChanged(Sender: TObject); procedure OnCalendarMonthChanged(Sender: TObject);
procedure OnCalendarYearChanged(Sender: TObject); procedure OnCalendarYearChanged(Sender: TObject);
procedure OnCalendarChange(Sender: TObject); procedure OnCalendarChange(Sender: TObject);
procedure SetLeft(AValue: Integer);
procedure SetTop(AValue: Integer);
protected protected
class procedure WSRegisterClass; override; class procedure WSRegisterClass; override;
procedure GetNewDate(Sender:TObject);//or onClick procedure GetNewDate(Sender:TObject);//or onClick
@ -531,6 +536,46 @@ end;
{ TExtCommonDialog } { TExtCommonDialog }
function TExtCommonDialog.GetLeft: Integer;
begin
if Assigned(FDlgForm) then FLeft := FDlgForm.Left;
Result := FLeft;
end;
function TExtCommonDialog.GetHeight: Integer;
begin
if Assigned(DlgForm) then
Result := DlgForm.Height
else
Result := inherited GetHeight;
end;
function TExtCommonDialog.GetTop: Integer;
begin
if Assigned(FDlgForm) then FTop := FDlgForm.Top;
Result := FTop;
end;
function TExtCommonDialog.GetWidth: Integer;
begin
if Assigned(DlgForm) then
Result := DlgForm.Width
else
Result := inherited GetWidth;
end;
procedure TExtCommonDialog.SetLeft(AValue: Integer);
begin
if Assigned(FDlgForm) then FDlgForm.Left := AValue;
FLeft := AValue;
end;
procedure TExtCommonDialog.SetTop(AValue: Integer);
begin
if Assigned(FDlgForm) then FDlgForm.Top := AValue;
FTop := AValue;
end;
constructor TExtCommonDialog.Create(AOwner: TComponent); constructor TExtCommonDialog.Create(AOwner: TComponent);
begin begin
inherited Create(AOwner); inherited Create(AOwner);
@ -1064,8 +1109,8 @@ end;
function TCalculatorDialog.GetDisplay: Double; function TCalculatorDialog.GetDisplay: Double;
begin begin
if Assigned(FCalc) then if Assigned(DlgForm) then
Result:=TCalculatorPanel(FCalc.FCalcPanel).GetDisplay Result:=TCalculatorPanel(TCalculatorForm(DlgForm).FCalcPanel).GetDisplay
else Result:=FValue; else Result:=FValue;
end; end;
@ -1084,6 +1129,7 @@ begin
if Assigned(FOnDisplayChange) then FOnDisplayChange(Self); if Assigned(FOnDisplayChange) then FOnDisplayChange(Self);
end; end;
procedure TCalculatorDialog.Change; procedure TCalculatorDialog.Change;
begin begin
if Assigned(FOnChange) then FOnChange(Self); if Assigned(FOnChange) then FOnChange(Self);
@ -1093,14 +1139,21 @@ function TCalculatorDialog.Execute: Boolean;
var var
CPanel: TCalculatorPanel; CPanel: TCalculatorPanel;
begin begin
FCalc:=CreateCalculatorForm(Application, FLayout, HelpContext); DlgForm:=CreateCalculatorForm(Application, FLayout, HelpContext);
try try
if (csDesigning in ComponentState) then if (csDesigning in ComponentState) then
FCalc.Position:=poScreenCenter DlgForm.Position:=poScreenCenter
else else
FCalc.Position:=DialogPosition; DlgForm.Position:=DialogPosition;
CPanel:=TCalculatorPanel(FCalc.FCalcPanel); if (DlgForm.Position=poDesigned) then begin
FCalc.Caption:=Title; DlgForm.Left:=FLeft;
DlgForm.Top:=FTop;
end else begin
FLeft:=DlgForm.Left;
FTop:=DlgForm.Top;
end;
CPanel:=TCalculatorPanel(TCalculatorForm(DlgForm).FCalcPanel);
DlgForm.Caption:=Title;
CPanel.FMemory:=FMemory; CPanel.FMemory:=FMemory;
CPanel.UpdateMemoryLabel; CPanel.UpdateMemoryLabel;
If Precision>2 then If Precision>2 then
@ -1113,7 +1166,12 @@ begin
CPanel.FStatus:=csFirst; CPanel.FStatus:=csFirst;
CPanel.FOperator:='='; CPanel.FOperator:='=';
end; end;
Result := (FCalc.ShowModal = mrOk); Result := (DlgForm.ShowModal = mrOk);
FLeft := DlgForm.Left;
FTop := DlgForm.Top;
//update private fields FHeight and FWidth of ancestor
SetHeight(DlgForm.Height);
SetWidth(DlgForm.Width);
if Result then begin if Result then begin
FMemory:=CPanel.FMemory; FMemory:=CPanel.FMemory;
if CPanel.DisplayValue <> FValue then begin if CPanel.DisplayValue <> FValue then begin
@ -1122,8 +1180,8 @@ begin
end; end;
end; end;
finally finally
FCalc.Free; DlgForm.Free;
FCalc:=nil; DlgForm:=nil;
end; end;
end; end;
@ -1302,18 +1360,6 @@ begin
if Assigned(OnClose) then OnClose(Self); if Assigned(OnClose) then OnClose(Self);
end; end;
function TCalendarDialog.GetLeft: Integer;
begin
if Assigned(FDlgForm) then FLeft := FDlgForm.Left;
Result := FLeft;
end;
function TCalendarDialog.GetTop: Integer;
begin
if Assigned(FDlgForm) then FTop := FDlgForm.Top;
Result := FTop;
end;
procedure TCalendarDialog.OnDialogCloseQuery(Sender: TObject; procedure TCalendarDialog.OnDialogCloseQuery(Sender: TObject;
var CanClose: boolean); var CanClose: boolean);
begin begin
@ -1344,17 +1390,6 @@ begin
if Assigned(FOnChange) then FOnChange(Self); if Assigned(FOnChange) then FOnChange(Self);
end; end;
procedure TCalendarDialog.SetLeft(AValue: Integer);
begin
FLeft := AValue;
if Assigned(FDlgForm) then FDlgForm.Left := FLeft;
end;
procedure TCalendarDialog.SetTop(AValue: Integer);
begin
FTop := AValue;
if Assigned(FDlgForm) then FDlgForm.Top := FTop;
end;
class procedure TCalendarDialog.WSRegisterClass; class procedure TCalendarDialog.WSRegisterClass;
begin begin
@ -1370,31 +1405,31 @@ var
okButton,cancelButton: TButton; okButton,cancelButton: TButton;
panel: TPanel; panel: TPanel;
begin begin
FDlgForm:=TForm.CreateNew(Application, 0); DlgForm:=TForm.CreateNew(Application, 0);
try try
FDlgForm.DisableAlign; DlgForm.DisableAlign;
FDlgForm.Caption:=Title; DlgForm.Caption:=Title;
if (csDesigning in ComponentState) then if (csDesigning in ComponentState) then
FDlgForm.Position:=poScreenCenter DlgForm.Position:=poScreenCenter
else else
FDlgForm.Position:=DialogPosition; DlgForm.Position:=DialogPosition;
if (FDlgForm.Position=poDesigned) then begin if (DlgForm.Position=poDesigned) then begin
FDlgForm.Left:=FLeft; DlgForm.Left:=FLeft;
FDlgForm.Top:=FTop; DlgForm.Top:=FTop;
end else begin end else begin
FLeft:=FDlgForm.Left; FLeft:=DlgForm.Left;
FTop:=FDlgForm.Top; FTop:=DlgForm.Top;
end; end;
FDlgForm.BorderStyle:=bsDialog; DlgForm.BorderStyle:=bsDialog;
FDlgForm.AutoScroll:=false; DlgForm.AutoScroll:=false;
FDlgForm.AutoSize:=true; DlgForm.AutoSize:=true;
FDlgForm.OnShow:=Self.OnShow; DlgForm.OnShow:=Self.OnShow;
FDlgForm.OnClose:=@OnDialogClose; DlgForm.OnClose:=@OnDialogClose;
FDlgForm.OnCloseQuery:=@OnDialogCloseQuery; DlgForm.OnCloseQuery:=@OnDialogCloseQuery;
FCalendar:=TCalendar.Create(FDlgForm); FCalendar:=TCalendar.Create(DlgForm);
with FCalendar do begin with FCalendar do begin
Parent:=FDlgForm; Parent:=DlgForm;
Align:=alTop; Align:=alTop;
DateTime:=Self.Date; DateTime:=Self.Date;
TabStop:=True; TabStop:=True;
@ -1406,22 +1441,22 @@ begin
OnDblClick:=@CalendarDblClick; OnDblClick:=@CalendarDblClick;
end; end;
panel:=TPanel.Create(FDlgForm); panel:=TPanel.Create(DlgForm);
with panel do begin with panel do begin
Parent:=FDlgForm; Parent:=DlgForm;
Caption:=''; Caption:='';
Height:=32; Height:=32;
AnchorToCompanion(akTop, 0, FCalendar); AnchorToCompanion(akTop, 0, FCalendar);
BevelOuter:=bvLowered; BevelOuter:=bvLowered;
end; end;
okButton:=TButton.Create(FDlgForm); okButton:=TButton.Create(DlgForm);
with okButton do begin with okButton do begin
Parent:=panel; Parent:=panel;
Caption:=OKCaption; Caption:=OKCaption;
Constraints.MinWidth:=75; Constraints.MinWidth:=75;
Constraints.MaxWidth:=FCalendar.Width div 2 - bbs; Constraints.MaxWidth:=FCalendar.Width div 2 - bbs;
Width:=FDlgForm.Canvas.TextWidth(OKCaption)+2*dw; Width:=DlgForm.Canvas.TextWidth(OKCaption)+2*dw;
ModalResult:=mrOK; ModalResult:=mrOK;
OnClick:=@GetNewDate; OnClick:=@GetNewDate;
//Align:=alRight; //Align:=alRight;
@ -1433,13 +1468,13 @@ begin
Default:=True; Default:=True;
end; end;
cancelButton:=TButton.Create(FDlgForm); cancelButton:=TButton.Create(DlgForm);
with cancelButton do begin with cancelButton do begin
Parent:=panel; Parent:=panel;
Caption:=CancelCaption; Caption:=CancelCaption;
Constraints.MinWidth:=75; Constraints.MinWidth:=75;
Constraints.MaxWidth:=FCalendar.Width div 2; Constraints.MaxWidth:=FCalendar.Width div 2;
Width:=FDlgForm.Canvas.TextWidth(CancelCaption)+2*dw;; Width:=DlgForm.Canvas.TextWidth(CancelCaption)+2*dw;;
ModalResult:=mrCancel; ModalResult:=mrCancel;
//Align:=alLeft; //Align:=alLeft;
BorderSpacing.Left:=bbs; BorderSpacing.Left:=bbs;
@ -1449,15 +1484,19 @@ begin
AnchorVerticalCenterTo(panel); AnchorVerticalCenterTo(panel);
Cancel:=True; Cancel:=True;
end; end;
FDlgForm.ClientWidth := FCalendar.Width; DlgForm.ClientWidth := FCalendar.Width;
FDlgForm.ClientHeight := panel.Top+panel.Height; DlgForm.ClientHeight := panel.Top+panel.Height;
FDlgForm.EnableAlign; DlgForm.EnableAlign;
Result:=FDlgForm.ShowModal=mrOK; Result:=DlgForm.ShowModal=mrOK;
FLeft:=FDlgForm.Left; FLeft:=DlgForm.Left;
FTop:=FDlgForm.Top; FTop:=DlgForm.Top;
//update private fields FHeight and FWidth of ancestor
SetHeight(DlgForm.Height);
SetWidth(DlgForm.Width);
finally finally
FreeAndNil(FDlgForm); DlgForm.Free;
DlgForm := nil;
end; end;
end; end;

View File

@ -126,3 +126,13 @@ function TCommonDialog.DefaultTitle: string;
begin begin
Result := ''; Result := '';
end; end;
function TCommonDialog.GetHeight: Integer;
begin
Result := FHeight;
end;
function TCommonDialog.GetWidth: Integer;
begin
Result := FWidth;
end;

View File

@ -384,6 +384,22 @@ begin
CloseDialog; CloseDialog;
end; end;
function TFindDialog.GetHeight: Integer;
begin
if Assigned(FFindForm) then
Result := FFindForm.Height
else
Result := inherited GetHeight;
end;
function TFindDialog.GetWidth: Integer;
begin
if Assigned(FFindForm) then
Result := FFindForm.Width
else
Result := inherited GetWidth;
end;
procedure TFindDialog.UpdatePosition; procedure TFindDialog.UpdatePosition;
begin begin
if Assigned(FFindForm) then if Assigned(FFindForm) then
@ -575,6 +591,8 @@ begin
FFindForm.HelpContext:=HelpContext; FFindForm.HelpContext:=HelpContext;
FFindForm.Caption:=Title; FFindForm.Caption:=Title;
FFindForm.Show; FFindForm.Show;
FHeight := FFindForm.Height;
FWidth := FFindForm.Width;
Result := true; Result := true;
end; end;
end; end;