📄 umainformframe.pas
字号:
{ JADD - Just Another DelphiDoc: Documentation from Delphi Source Code
Copyright (C) 2002-2008 Gerold Veith
This file is part of JADD - Just Another DelphiDoc.
DelphiDoc is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License version 3 as
published by the Free Software Foundation.
DelphiDoc 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. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
}
unit UMainFormFrame;
{Contains the base class of all frames/pages of the main form. I'm developing
with Delphi 4, and TFrame has only be introduced in Delphi 5, so this is the
work-around and the TFrame is a TForm. }
interface
uses Windows, Classes, Forms, Controls, StdCtrls, ExtCtrls,
UPascalConsts, UBaseIdents,
UJADDState;
type
//base class of all frames/pages for the main form
TMainFormFrame = class;
{Call back procedure to show some source code.
~param Sender the sender, the requester to show the source code
~param Ident nil, or the identifier whose declaration should be
shown
~param TheFile if ident is nil, the file to show the source code of
~param Position the position in TheFile to show
~param EffectiveFile if different that TheFile, this file has been
included (maybe indirectly) by TheFile, show source
of this file instead
~param EffectivePosition the position in EffectiveFile to show }
TShowSourceCallBack = procedure (Sender: TMainFormFrame;
Ident: TIdentifier;
TheFile: TPascalFile;
Position: TPosition;
EffectiveFile: TPascalFile;
EffectivePosition: TPosition) of object;
//possible properties of the pages
TMFFrameProperty = (
//the page accepts dropped files via
//~[link TMainFormFrame.FilesDropped]
mffpAcceptsFileDrop);
//the possible properties of the pages
TMFFrameProperties = set of TMFFrameProperty;
//classes of the pages on/frames of the main form
TMainFormFrameClass = class of TMainFormFrame;
{Base class of all frames/pages for the main form. }
TMainFormFrame = class(TForm)
PanelEditor: TPanel;
MemoDescription: TMemo;
private
//the state of the program that can be edited by this frame
FState: TJADDState;
//the control to show the form/frame/page in
FShowIn: TWinControl;
//method to call in order to show some source code
FShowSourceCode: TShowSourceCallBack;
protected
//the properties of the frame
FProperties: TMFFrameProperties;
//Called when the list of parsed files changes.
procedure StateFileListChanged(State: TJADDState); virtual;
//Called when the generator changes.
procedure StateGeneratorChanged(State: TJADDState); virtual;
//Called when extractor of comments for the generator changes.
procedure StateExtractorChanged(State: TJADDState); virtual;
//Called when evaluator of comments for the generator changes.
procedure StateEvaluatorChanged(State: TJADDState); virtual;
property State: TJADDState read FState;
public
//Creates the components.
constructor Create(Parent: TWinControl; State: TJADDState); reintroduce;
virtual;
//Places the frame in the new parent and calls all event handlers to adjust
//to the current state.
procedure AfterConstruction; override;
//Unregisters the event handlers and frees the frame.
destructor Destroy; override;
//Called sometimes when the frame is to be replaced by another frame.
procedure SelectNextFrame(var NewFrameClass: TMainFormFrameClass;
IsNext: Boolean); virtual;
//Called when some files are dropped on the form.
procedure FilesDropped(Files: TStrings); virtual;
//Called when the default action of the form should be executed.
procedure DefaultAction; virtual;
property Properties: TMFFrameProperties read FProperties;
property ShowSourceCode: TShowSourceCallBack read FShowSourceCode
write FShowSourceCode;
end;
implementation
{$R *.dfm}
uses SysUtils,
GeneralVCL;
{Creates the components.
~param Parent the component to show the frame in, preferably a TPanel or a
similar component
~param State the state of the program }
constructor TMainFormFrame.Create(Parent: TWinControl; State: TJADDState);
begin
inherited Create(nil); //create the frame/page
Assert((PanelEditor.HelpContext = HelpContext + 1) or
ClassNameIs('TMFWelcome'));
Assert(HelpContext <> 0);
Assert(HelpContext <> 11000);
Assert(MemoDescription.HelpContext = 0);
FState := State; //save the state
FShowIn := Parent; //and the parent control
MemoDescription.Text := TrimRight(MemoDescription.Text);
MemoDescription.WordWrap := True; //wrap the text in the visible width
//register handlers to be notified when the state changes
State.OnFileListChanged.Add(StateFileListChanged);
State.OnGeneratorChanged.Add(StateGeneratorChanged);
State.OnExtractorChanged.Add(StateExtractorChanged);
State.OnEvaluatorChanged.Add(StateEvaluatorChanged);
end;
{Places the frame in the new parent and calls all event handlers to adjust to
the current state.}
procedure TMainFormFrame.AfterConstruction;
var Panel :TPanel; //the panel with the content
begin
inherited AfterConstruction; //handle OnCreate
PanelEditor.Parent := FShowIn; //show inside the other control
Panel := PanelEditor; //save the panel
PanelEditor.Name := Self.Name; //update name for generating help
//re-assign the panel (will be removed when changing name)
PanelEditor := Panel;
//and only show vertical scroll bar when it's needed
GeneralVCL.RegisterMemoToHideVerticalScrollbar(MemoDescription);
StateFileListChanged(FState); //adjust to current state
StateGeneratorChanged(FState);
StateExtractorChanged(FState);
StateEvaluatorChanged(FState);
// Caption := IntToStr(Round(sqrt(Screen.FormCount)));
end;
{Unregisters the event handlers and frees the frame. }
destructor TMainFormFrame.Destroy;
begin
if Assigned(State) then
begin
//unregister handlers to be notified when the state changes
State.OnFileListChanged.Remove(StateFileListChanged);
State.OnGeneratorChanged.Remove(StateGeneratorChanged);
State.OnExtractorChanged.Remove(StateExtractorChanged);
State.OnEvaluatorChanged.Remove(StateEvaluatorChanged);
end;
inherited Destroy; //free the frame
end;
{Called when the list of parsed files changes.
~param State the state that has been changed }
procedure TMainFormFrame.StateFileListChanged(State: TJADDState);
begin
end;
{Called when the generator changes.
~param State the state that has been changed }
procedure TMainFormFrame.StateGeneratorChanged(State: TJADDState);
begin
end;
{Called when extractor of comments for the generator changes.
~param State the state that has been changed }
procedure TMainFormFrame.StateExtractorChanged(State: TJADDState);
begin
end;
{Called when evaluator of comments for the generator changes.
~param State the state that has been changed }
procedure TMainFormFrame.StateEvaluatorChanged(State: TJADDState);
begin
end;
{Called sometimes when the frame is to be replaced by another frame. This
method is ~[em not] always called before the frame is being replaced (and
freed).
~param NewFrameClass the class of the frame that should replace this one
~param IsNext if the next frame should be shown (instead of the previous
one) in some kind of an order }
procedure TMainFormFrame.SelectNextFrame(
var NewFrameClass: TMainFormFrameClass; IsNext: Boolean);
begin
end;
{Called when some files are dropped on the form.
~param Files the list of the dropped files }
procedure TMainFormFrame.FilesDropped(Files: TStrings);
begin
assert(mffpAcceptsFileDrop in FProperties);
assert(False);
end;
{Called when the default action of the form should be executed.
By default executes the action of the default button. }
procedure TMainFormFrame.DefaultAction;
var Button :TComponent; //the default button
i :Integer; //counter through components
begin
Button := nil; //default button not found yet
i := ComponentCount - 1; //for each component in the page
while (i >= 0) and not Assigned(Button) do //while default button not found
begin
Button := Components[i]; //get next component
if not (Button is TButton) or //isn't the default button?
not TButton(Button).Enabled or not TButton(Button).Default or
not Assigned(TButton(Button).OnClick) then
begin
Button := nil; //button not found
Dec(i); //next component
end;
end;
if Assigned(Button) then //default button found?
begin
Assert(Button is TButton);
Assert(TButton(Button).Enabled and TButton(Button).Default);
Assert(Assigned(TButton(Button).OnClick));
TButton(Button).OnClick(Button); //execute its default action
end;
//else no action by default
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -