-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmagicformframe1.pas
128 lines (108 loc) · 3.37 KB
/
magicformframe1.pas
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
//Copyright (c) 2012 by Donald R. Ziesig
//
//Donald.at.Ziesig.org
//
//This file is part of MagicLibrary.
//
//MagicLibrary is free software: you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.
//
//MagicLibrary 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 MagicLibrary. If not, see <http://www.gnu.org/licenses/>.
{==============================================================================}
{ The MagicFormFrame is a frame that can host multiple Forms (from TForm ) }
{ such that the user interface can be limited to a single window but the code }
{ (and components) can be separated into individual files (so you don't have a }
{ single humongous file defining the user interface. }
{==============================================================================}
unit MagicFormFrame1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, StdCtrls;
type
{ TFrame1 }
TFrame1 = class(TFrame)
private
{ private declarations }
FForm: TForm;
FOnAfterFormChanged: TNotifyEvent;
FOnBeforeFormChanged: TNotifyEvent;
procedure SetForm(AValue: TForm);
protected
{ protected declarations }
procedure AfterFormChanged; virtual;
procedure BeforeFormChanged; virtual;
procedure Paint; override;
procedure Resize; override;
public
{ public declarations }
property Form: TForm read FForm write SetForm;
property OnAfterFormChanged : TNotifyEvent read FOnAfterFormChanged write FOnAfterFormChanged;
property OnBeforeFormChanged : TNotifyEvent read FOnBeforeFormChanged write FOnBeforeFormChanged;
end;
implementation
{$R *.lfm}
{ TFrame1 }
procedure TFrame1.SetForm(AValue: TForm);
var
I : Integer;
begin
if AValue <> FForm then
begin
BeforeFormChanged;
if (FForm <> nil) then { hide current form }
FForm.Visible := False;
FForm := AValue;
if (FForm <> nil) then
begin
FForm.Parent := Self;
//FForm.BorderIcons := [];
//FForm.BorderStyle := bsNone; { this will change AutoScroll }
// FForm.AutoScroll := True; { re-assign after changing BorderStyle }
// FForm.AutoSize := False;
// FForm.Position := poDesigned;
// Resize;
FForm.Visible := True;
end;
AfterFormChanged;
end;
end;
procedure TFrame1.AfterFormChanged;
begin
if Assigned(FOnAfterFormChanged) then FOnAfterFormChanged(Self);
end;
procedure TFrame1.BeforeFormChanged;
begin
if Assigned(FOnBeforeFormChanged) then FOnBeforeFormChanged(Self);
end;
procedure TFrame1.Paint;
var
NewForm: TForm;
FormClassName: String;
I: Integer;
begin
inherited Paint;
if FForm <> nil then
SetForm(FForm);
end;
procedure TFrame1.Resize;
var
Rect0, Rect1 : TRect;
PWidth, PHeight : Integer;
begin
inherited;
if (FForm <> nil) and not (csDestroying in ComponentState) then
begin
//FForm.GetPreferredSize( PWidth, PHeight, True );
//FForm.SetBounds(0, 0, PWidth, PHeight);
end;
end;
end.