238 lines
5.5 KiB
ObjectPascal
238 lines
5.5 KiB
ObjectPascal
|
|
unit uCustomView;
|
||
|
|
|
||
|
|
interface
|
||
|
|
|
||
|
|
uses
|
||
|
|
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
|
||
|
|
Dialogs, StdCtrls, uGUIBase, DesignEditors;
|
||
|
|
|
||
|
|
type
|
||
|
|
TCustomView = class(TFrame, ICustomView)
|
||
|
|
private
|
||
|
|
FOnGetModified: TOnGetModifiedEvent;
|
||
|
|
FOnViewModified: TOnViewModifiedEvent;
|
||
|
|
FReadOnly: Boolean;
|
||
|
|
FOnCreate: TNotifyEvent;
|
||
|
|
FOnDestroy: TNotifyEvent;
|
||
|
|
FOnHide: TNotifyEvent;
|
||
|
|
FOnShow: TNotifyEvent;
|
||
|
|
procedure ShowEmbedded; overload;
|
||
|
|
procedure CMShowingChanged(var Message: TMessage); message CM_SHOWINGCHANGED;
|
||
|
|
protected
|
||
|
|
FObserver: IObserver;
|
||
|
|
function GetOnGetModified: TOnGetModifiedEvent;
|
||
|
|
procedure SetOnGetModified(const Value : TOnGetModifiedEvent);
|
||
|
|
function GetOnViewModified: TOnViewModifiedEvent;
|
||
|
|
procedure SetOnViewModified(const Value : TOnViewModifiedEvent);
|
||
|
|
procedure SetModified(const Value : Boolean); virtual;
|
||
|
|
function GetModified: Boolean; virtual;
|
||
|
|
function GetReadOnly: Boolean; virtual;
|
||
|
|
function GetValid: Boolean; virtual;
|
||
|
|
procedure Release;
|
||
|
|
procedure SetReadOnly(Value: Boolean); virtual;
|
||
|
|
procedure DoCreate; virtual;
|
||
|
|
procedure DoDestroy; virtual;
|
||
|
|
procedure DoHide; dynamic;
|
||
|
|
procedure DoShow; dynamic;
|
||
|
|
public
|
||
|
|
constructor Create(AOwner: TComponent); override;
|
||
|
|
constructor CreateEmbedded(AOwner: TComponent; AParent: TWinControl);
|
||
|
|
destructor Destroy; override;
|
||
|
|
procedure ShowEmbedded(const AParent : TWinControl); overload; virtual;
|
||
|
|
property Modified: Boolean read GetModified write SetModified;
|
||
|
|
published
|
||
|
|
property OnGetModified: TOnGetModifiedEvent read GetOnGetModified write
|
||
|
|
SetOnGetModified;
|
||
|
|
property OnViewModified: TOnViewModifiedEvent read GetOnViewModified write
|
||
|
|
SetOnViewModified;
|
||
|
|
property ReadOnly: Boolean read GetReadOnly write SetReadOnly;
|
||
|
|
property Valid: Boolean read GetValid;
|
||
|
|
property OnCreate: TNotifyEvent read FOnCreate write FOnCreate;
|
||
|
|
property OnDestroy: TNotifyEvent read FOnDestroy write FOnDestroy;
|
||
|
|
property OnHide: TNotifyEvent read FOnHide write FOnHide;
|
||
|
|
property OnShow: TNotifyEvent read FOnShow write FOnShow;
|
||
|
|
end;
|
||
|
|
|
||
|
|
TCustomViewClass = class of TCustomView;
|
||
|
|
|
||
|
|
TCustomViewModule = class(TCustomModule)
|
||
|
|
public
|
||
|
|
function Nestable: Boolean; override;
|
||
|
|
end;
|
||
|
|
|
||
|
|
implementation
|
||
|
|
|
||
|
|
{$R *.dfm}
|
||
|
|
|
||
|
|
{ TCustomView }
|
||
|
|
|
||
|
|
uses
|
||
|
|
DesignIntf, uGUIUtils, RTLConsts;
|
||
|
|
|
||
|
|
{
|
||
|
|
********************************* TCustomView **********************************
|
||
|
|
}
|
||
|
|
procedure TCustomView.CMShowingChanged(var Message: TMessage);
|
||
|
|
begin
|
||
|
|
inherited;
|
||
|
|
|
||
|
|
if Showing then
|
||
|
|
begin
|
||
|
|
// Put your OnShow logic here.
|
||
|
|
// When this is called, the frame's window handle has already
|
||
|
|
// been created, as have the handles for the controls on the
|
||
|
|
// frame - so you can do most anything you need to do.
|
||
|
|
if Assigned(FOnShow) then
|
||
|
|
FOnShow(Self);
|
||
|
|
end
|
||
|
|
else
|
||
|
|
begin
|
||
|
|
// Put your OnHide logic here, but see the caveats below.
|
||
|
|
if Assigned(FOnHide) then
|
||
|
|
FOnHide(Self);
|
||
|
|
end;
|
||
|
|
end;
|
||
|
|
|
||
|
|
constructor TCustomView.Create(AOwner: TComponent);
|
||
|
|
begin
|
||
|
|
inherited Create(AOwner);
|
||
|
|
FObserver := NIL;
|
||
|
|
DoCreate;
|
||
|
|
end;
|
||
|
|
|
||
|
|
constructor TCustomView.CreateEmbedded(AOwner: TComponent; AParent:
|
||
|
|
TWinControl);
|
||
|
|
begin
|
||
|
|
Create(AOwner);
|
||
|
|
Parent := AParent;
|
||
|
|
Align := alClient;
|
||
|
|
end;
|
||
|
|
|
||
|
|
destructor TCustomView.Destroy;
|
||
|
|
begin
|
||
|
|
DoDestroy;
|
||
|
|
inherited Destroy;
|
||
|
|
end;
|
||
|
|
|
||
|
|
procedure TCustomView.DoCreate;
|
||
|
|
begin
|
||
|
|
if Assigned(FOnCreate) then
|
||
|
|
begin
|
||
|
|
try
|
||
|
|
FOnCreate(Self);
|
||
|
|
except
|
||
|
|
Application.HandleException(Self);
|
||
|
|
end;
|
||
|
|
end;
|
||
|
|
end;
|
||
|
|
|
||
|
|
procedure TCustomView.DoDestroy;
|
||
|
|
begin
|
||
|
|
if Assigned(FOnDestroy) then
|
||
|
|
begin
|
||
|
|
try
|
||
|
|
FOnDestroy(Self);
|
||
|
|
except
|
||
|
|
Application.HandleException(Self);
|
||
|
|
end;
|
||
|
|
end;
|
||
|
|
end;
|
||
|
|
|
||
|
|
procedure TCustomView.DoHide;
|
||
|
|
begin
|
||
|
|
if Assigned(FOnHide) then
|
||
|
|
begin
|
||
|
|
try
|
||
|
|
FOnHide(Self);
|
||
|
|
except
|
||
|
|
Application.HandleException(Self);
|
||
|
|
end;
|
||
|
|
end;
|
||
|
|
end;
|
||
|
|
|
||
|
|
procedure TCustomView.DoShow;
|
||
|
|
begin
|
||
|
|
if Assigned(FOnShow) then
|
||
|
|
begin
|
||
|
|
try
|
||
|
|
FOnShow(Self);
|
||
|
|
except
|
||
|
|
Application.HandleException(Self);
|
||
|
|
end;
|
||
|
|
end;
|
||
|
|
end;
|
||
|
|
|
||
|
|
function TCustomView.GetModified: Boolean;
|
||
|
|
begin
|
||
|
|
Result := ControlIsModified(Self);
|
||
|
|
if Assigned(FOnGetModified) then
|
||
|
|
FOnGetModified(Self, Result);
|
||
|
|
end;
|
||
|
|
|
||
|
|
function TCustomView.GetOnGetModified: TOnGetModifiedEvent;
|
||
|
|
begin
|
||
|
|
Result := FOnGetModified;
|
||
|
|
end;
|
||
|
|
|
||
|
|
function TCustomView.GetOnViewModified: TOnViewModifiedEvent;
|
||
|
|
begin
|
||
|
|
Result := FOnViewModified;
|
||
|
|
end;
|
||
|
|
|
||
|
|
function TCustomView.GetReadOnly: Boolean;
|
||
|
|
begin
|
||
|
|
Result := FReadOnly;
|
||
|
|
end;
|
||
|
|
|
||
|
|
function TCustomView.GetValid: Boolean;
|
||
|
|
begin
|
||
|
|
Result := True;
|
||
|
|
end;
|
||
|
|
|
||
|
|
procedure TCustomView.Release;
|
||
|
|
begin
|
||
|
|
Free;
|
||
|
|
end;
|
||
|
|
|
||
|
|
procedure TCustomView.SetModified(const Value: Boolean);
|
||
|
|
begin
|
||
|
|
if Assigned(FOnViewModified) then
|
||
|
|
FOnViewModified(Self);
|
||
|
|
end;
|
||
|
|
|
||
|
|
procedure TCustomView.SetOnGetModified(const Value: TOnGetModifiedEvent);
|
||
|
|
begin
|
||
|
|
FOnGetModified := Value;
|
||
|
|
end;
|
||
|
|
|
||
|
|
procedure TCustomView.SetOnViewModified(const Value: TOnViewModifiedEvent);
|
||
|
|
begin
|
||
|
|
FOnViewModified := Value;
|
||
|
|
end;
|
||
|
|
|
||
|
|
procedure TCustomView.SetReadOnly(Value: Boolean);
|
||
|
|
begin
|
||
|
|
FReadOnly := Value;
|
||
|
|
end;
|
||
|
|
|
||
|
|
procedure TCustomView.ShowEmbedded;
|
||
|
|
begin
|
||
|
|
Align := alClient;
|
||
|
|
Show;
|
||
|
|
end;
|
||
|
|
|
||
|
|
procedure TCustomView.ShowEmbedded(const AParent : TWinControl);
|
||
|
|
begin
|
||
|
|
Parent := AParent;
|
||
|
|
ShowEmbedded;
|
||
|
|
end;
|
||
|
|
|
||
|
|
{ TCustomViewModule }
|
||
|
|
|
||
|
|
function TCustomViewModule.Nestable: Boolean;
|
||
|
|
begin
|
||
|
|
Result := True;
|
||
|
|
end;
|
||
|
|
|
||
|
|
end.
|