forked from jrsoftware/issrc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNewNotebook.pas
329 lines (298 loc) · 8.66 KB
/
NewNotebook.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
unit NewNotebook;
{
Inno Setup
Copyright (C) 1997-2018 Jordan Russell
Portions by Martijn Laan
For conditions of distribution and use, see LICENSE.TXT.
TNewNotebook component
}
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms;
type
TNewNotebookPage = class;
TNewNotebook = class(TWinControl)
private
FActivePage: TNewNotebookPage;
FPages: TList;
function GetPage(Index: Integer): TNewNotebookPage;
function GetPageCount: Integer;
procedure InsertPage(Page: TNewNotebookPage);
procedure RemovePage(Page: TNewNotebookPage);
procedure SetActivePage(Page: TNewNotebookPage);
protected
procedure AlignControls(AControl: TControl; var Rect: TRect); override;
procedure CreateParams(var Params: TCreateParams); override;
procedure ShowControl(AControl: TControl); override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
function FindNextPage(CurPage: TNewNotebookPage; GoForward: Boolean): TNewNotebookPage;
procedure GetChildren(Proc: TGetChildProc; Root: TComponent); override;
property PageCount: Integer read GetPageCount;
property Pages[Index: Integer]: TNewNotebookPage read GetPage;
published
property ActivePage: TNewNotebookPage read FActivePage write SetActivePage;
property Align;
property Anchors;
property Color;
property DragCursor;
property DragMode;
property Enabled;
property Font;
property ParentColor;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ShowHint;
property TabOrder;
property TabStop;
property Visible;
property OnDragDrop;
property OnDragOver;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnStartDrag;
end;
TNewNotebookPage = class(TCustomControl)
private
FNotebook: TNewNotebook;
function GetPageIndex: Integer;
procedure SetNotebook(ANotebook: TNewNotebook);
procedure SetPageIndex(Value: Integer);
protected
procedure Paint; override;
procedure ReadState(Reader: TReader); override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
property Notebook: TNewNotebook read FNotebook write SetNotebook;
published
property Color nodefault; { nodefault needed for Color=clWindow to persist }
property DragMode;
property Enabled;
property Font;
property Height stored False;
property Left stored False;
property PageIndex: Integer read GetPageIndex write SetPageIndex stored False;
property ParentColor;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ShowHint;
property Top stored False;
property Visible stored False;
property Width stored False;
property OnDragDrop;
property OnDragOver;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnStartDrag;
end;
implementation
uses
Types;
{ TNewNotebookPage }
constructor TNewNotebookPage.Create(AOwner: TComponent);
begin
inherited;
Align := alClient;
ControlStyle := ControlStyle + [csAcceptsControls, csNoDesignVisible];
Visible := False;
end;
destructor TNewNotebookPage.Destroy;
begin
if Assigned(FNotebook) then
FNotebook.RemovePage(Self);
inherited;
end;
function TNewNotebookPage.GetPageIndex: Integer;
begin
if Assigned(FNotebook) then
Result := FNotebook.FPages.IndexOf(Self)
else
Result := -1;
end;
procedure TNewNotebookPage.Paint;
begin
inherited;
if csDesigning in ComponentState then begin
Canvas.Pen.Style := psDash;
Canvas.Brush.Style := bsClear;
Canvas.Rectangle(0, 0, Width, Height);
end;
end;
procedure TNewNotebookPage.ReadState(Reader: TReader);
begin
inherited;
if Reader.Parent is TNewNotebook then
Notebook := TNewNotebook(Reader.Parent);
end;
procedure TNewNotebookPage.SetNotebook(ANotebook: TNewNotebook);
begin
if FNotebook <> ANotebook then begin
if Assigned(FNotebook) then
FNotebook.RemovePage(Self);
Parent := ANotebook;
if Assigned(ANotebook) then
ANotebook.InsertPage(Self);
end;
end;
procedure TNewNotebookPage.SetPageIndex(Value: Integer);
begin
if Assigned(FNotebook) then begin
if Value >= FNotebook.FPages.Count then
Value := FNotebook.FPages.Count-1;
if Value < 0 then
Value := 0;
FNotebook.FPages.Move(PageIndex, Value);
end;
end;
{ TNewNotebook }
constructor TNewNotebook.Create(AOwner: TComponent);
begin
inherited;
Width := 150;
Height := 150;
FPages := TList.Create;
end;
destructor TNewNotebook.Destroy;
var
I: Integer;
begin
if Assigned(FPages) then begin
for I := 0 to FPages.Count-1 do
TNewNotebookPage(FPages[I]).FNotebook := nil;
FPages.Free;
end;
inherited;
end;
procedure TNewNotebook.AlignControls(AControl: TControl; var Rect: TRect);
var
I: Integer;
Ctl: TControl;
begin
inherited;
{ The default AlignControls implementation in Delphi 2 and 3 doesn't set
the size of invisible controls. Pages that aren't currently visible must
have valid sizes for BidiUtils' FlipControls to work properly.
Note: We loop through Controls and not FPages here because
TNewNotebookPage.SetNotebook sets Parent (causing AlignControls to be
called) before it calls InsertPage. }
if not IsRectEmpty(Rect) then begin
for I := 0 to ControlCount-1 do begin
Ctl := Controls[I];
if (Ctl is TNewNotebookPage) and not Ctl.Visible then
Ctl.BoundsRect := Rect;
end;
end;
end;
procedure TNewNotebook.CreateParams(var Params: TCreateParams);
begin
inherited;
Params.Style := Params.Style or WS_CLIPCHILDREN;
end;
function TNewNotebook.FindNextPage(CurPage: TNewNotebookPage;
GoForward: Boolean): TNewNotebookPage;
var
I, StartIndex: Integer;
begin
if FPages.Count > 0 then begin
StartIndex := FPages.IndexOf(CurPage);
if StartIndex = -1 then begin
if GoForward then
StartIndex := FPages.Count-1
else
StartIndex := 0;
end;
I := StartIndex;
repeat
if GoForward then begin
Inc(I);
if I = FPages.Count then
I := 0;
end
else begin
if I = 0 then
I := FPages.Count;
Dec(I);
end;
Result := FPages[I];
Exit;
until I = StartIndex;
end;
Result := nil;
end;
procedure TNewNotebook.GetChildren(Proc: TGetChildProc {$IFNDEF DELPHI2} ;
Root: TComponent {$ENDIF});
var
I: Integer;
begin
for I := 0 to FPages.Count-1 do
Proc(TNewNotebookPage(FPages[I]));
end;
function TNewNotebook.GetPage(Index: Integer): TNewNotebookPage;
begin
Result := FPages[Index];
end;
function TNewNotebook.GetPageCount: Integer;
begin
Result := FPages.Count;
end;
procedure TNewNotebook.InsertPage(Page: TNewNotebookPage);
begin
FPages.Add(Page);
Page.FNotebook := Self;
end;
procedure TNewNotebook.RemovePage(Page: TNewNotebookPage);
begin
Page.FNotebook := nil;
FPages.Remove(Page);
if FActivePage = Page then
SetActivePage(nil);
end;
procedure TNewNotebook.ShowControl(AControl: TControl);
begin
if (AControl is TNewNotebookPage) and (TNewNotebookPage(AControl).FNotebook = Self) then
SetActivePage(TNewNotebookPage(AControl));
inherited;
end;
procedure TNewNotebook.SetActivePage(Page: TNewNotebookPage);
var
ParentForm: {$IFDEF DELPHI2} TForm {$ELSE} TCustomForm {$ENDIF};
begin
if Assigned(Page) and (Page.FNotebook <> Self) then
Exit;
if FActivePage <> Page then begin
ParentForm := GetParentForm(Self);
if Assigned(ParentForm) and Assigned(FActivePage) and
FActivePage.ContainsControl(ParentForm.ActiveControl) then
ParentForm.ActiveControl := FActivePage;
if Assigned(Page) then begin
Page.BringToFront;
Page.Visible := True;
if Assigned(ParentForm) and Assigned(FActivePage) and
(ParentForm.ActiveControl = FActivePage) then begin
if Page.CanFocus then
ParentForm.ActiveControl := Page
else
ParentForm.ActiveControl := Self;
end;
end;
if Assigned(FActivePage) then
FActivePage.Visible := False;
FActivePage := Page;
if Assigned(ParentForm) and Assigned(FActivePage) and
(ParentForm.ActiveControl = FActivePage) then
FActivePage.SelectFirst;
end;
end;
end.