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
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
|
#include <TPageControl.h>
TPageControl::TPageControl(TComponent *AOwner) : TCustomTabControl(AOwner) {
}
TPageControl::~TPageControl() {
}
/*
{ TPageControl }
constructor TPageControl.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
ControlStyle := [csDoubleClicks, csOpaque];
FPages := TList.Create;
end;
destructor TPageControl.Destroy;
var
I: Integer;
begin
for I := 0 to FPages.Count - 1 do TTabSheet(FPages[I]).FPageControl := nil;
FPages.Free;
inherited Destroy;
end;
function TPageControl.CanShowTab(TabIndex: Integer): Boolean;
begin
Result := TTabSheet(FPages[TabIndex]).Enabled;
end;
procedure TPageControl.Change;
var
Form: TCustomForm;
begin
UpdateActivePage;
if csDesigning in ComponentState then
begin
Form := GetParentForm(Self);
if (Form <> nil) and (Form.Designer <> nil) then Form.Designer.Modified;
end;
inherited Change;
end;
procedure TPageControl.ChangeActivePage(Page: TTabSheet);
var
ParentForm: TCustomForm;
begin
if FActivePage <> Page then
begin
ParentForm := GetParentForm(Self);
if (ParentForm <> nil) and (FActivePage <> nil) and
FActivePage.ContainsControl(ParentForm.ActiveControl) then
begin
ParentForm.ActiveControl := FActivePage;
if ParentForm.ActiveControl <> FActivePage then
begin
TabIndex := FActivePage.TabIndex;
Exit;
end;
end;
if Page <> nil then
begin
Page.BringToFront;
Page.Visible := True;
if (ParentForm <> nil) and (FActivePage <> nil) and
(ParentForm.ActiveControl = FActivePage) then
if Page.CanFocus then
ParentForm.ActiveControl := Page else
ParentForm.ActiveControl := Self;
end;
if FActivePage <> nil then FActivePage.Visible := False;
FActivePage := Page;
if (ParentForm <> nil) and (FActivePage <> nil) and
(ParentForm.ActiveControl = FActivePage) then
FActivePage.SelectFirst;
end;
end;
procedure TPageControl.DeleteTab(Page: TTabSheet; Index: Integer);
var
UpdateIndex: Boolean;
begin
UpdateIndex := Page = ActivePage;
Tabs.Delete(Index);
if UpdateIndex then
begin
if Index >= Tabs.Count then
Index := Tabs.Count - 1;
TabIndex := Index;
end;
UpdateActivePage;
end;
procedure TPageControl.DoAddDockClient(Client: TControl; const ARect: TRect);
begin
if FNewDockSheet <> nil then Client.Parent := FNewDockSheet;
end;
procedure TPageControl.DockOver(Source: TDragDockObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
var
R: TRect;
begin
GetWindowRect(Handle, R);
Source.DockRect := R;
DoDockOver(Source, X, Y, State, Accept);
end;
procedure TPageControl.DoRemoveDockClient(Client: TControl);
begin
if (FUndockingPage <> nil) and not (csDestroying in ComponentState) then
begin
SelectNextPage(True);
FUndockingPage.Free;
FUndockingPage := nil;
end;
end;
function TPageControl.FindNextPage(CurPage: TTabSheet;
GoForward, CheckTabVisible: Boolean): TTabSheet;
var
I, StartIndex: Integer;
begin
if FPages.Count <> 0 then
begin
StartIndex := FPages.IndexOf(CurPage);
if StartIndex = -1 then
if GoForward then StartIndex := FPages.Count - 1 else StartIndex := 0;
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];
if not CheckTabVisible or Result.TabVisible then Exit;
until I = StartIndex;
end;
Result := nil;
end;
procedure TPageControl.GetChildren(Proc: TGetChildProc; Root: TComponent);
var
I: Integer;
begin
for I := 0 to FPages.Count - 1 do Proc(TComponent(FPages[I]));
end;
function TPageControl.GetImageIndex(TabIndex: Integer): Integer;
begin
if Assigned(FOnGetImageIndex) then
Result := inherited GetImageIndex(TabIndex) else
Result := GetPage(TabIndex).ImageIndex;
end;
function TPageControl.GetPageFromDockClient(Client: TControl): TTabSheet;
var
I: Integer;
begin
Result := nil;
for I := 0 to PageCount - 1 do
begin
if (Client.Parent = Pages[I]) and (Client.HostDockSite = Self) then
begin
Result := Pages[I];
Exit;
end;
end;
end;
function TPageControl.GetPage(Index: Integer): TTabSheet;
begin
Result := FPages[Index];
end;
function TPageControl.GetPageCount: Integer;
begin
Result := FPages.Count;
end;
procedure TPageControl.GetSiteInfo(Client: TControl; var InfluenceRect: TRect;
MousePos: TPoint; var CanDock: Boolean);
begin
CanDock := GetPageFromDockClient(Client) = nil;
inherited GetSiteInfo(Client, InfluenceRect, MousePos, CanDock);
end;
procedure TPageControl.InsertPage(Page: TTabSheet);
begin
FPages.Add(Page);
Page.FPageControl := Self;
Page.UpdateTabShowing;
end;
procedure TPageControl.InsertTab(Page: TTabSheet);
begin
Tabs.InsertObject(Page.TabIndex, Page.Caption, Page);
UpdateActivePage;
end;
procedure TPageControl.MoveTab(CurIndex, NewIndex: Integer);
begin
Tabs.Move(CurIndex, NewIndex);
end;
procedure TPageControl.RemovePage(Page: TTabSheet);
var
NextSheet: TTabSheet;
begin
NextSheet := FindNextPage(Page, True, not (csDesigning in ComponentState));
if NextSheet = Page then NextSheet := nil;
Page.SetTabShowing(False);
Page.FPageControl := nil;
FPages.Remove(Page);
SetActivePage(NextSheet);
end;
procedure TPageControl.SelectNextPage(GoForward: Boolean);
var
Page: TTabSheet;
begin
Page := FindNextPage(ActivePage, GoForward, True);
if (Page <> nil) and (Page <> ActivePage) and CanChange then
begin
TabIndex := Page.TabIndex;
Change;
end;
end;
procedure TPageControl.SetActivePage(Page: TTabSheet);
begin
if (Page <> nil) and (Page.PageControl <> Self) then Exit;
ChangeActivePage(Page);
if Page = nil then
TabIndex := -1
else if Page = FActivePage then
TabIndex := Page.TabIndex;
end;
procedure TPageControl.SetChildOrder(Child: TComponent; Order: Integer);
begin
TTabSheet(Child).PageIndex := Order;
end;
procedure TPageControl.ShowControl(AControl: TControl);
begin
if (AControl is TTabSheet) and (TTabSheet(AControl).PageControl = Self) then
SetActivePage(TTabSheet(AControl));
inherited ShowControl(AControl);
end;
procedure TPageControl.UpdateTab(Page: TTabSheet);
begin
Tabs[Page.TabIndex] := Page.Caption;
end;
procedure TPageControl.UpdateActivePage;
begin
if TabIndex >= 0 then
SetActivePage(TTabSheet(Tabs.Objects[TabIndex]))
else
SetActivePage(nil);
end;
procedure TPageControl.CMDesignHitTest(var Message: TCMDesignHitTest);
var
HitIndex: Integer;
HitTestInfo: TTCHitTestInfo;
begin
HitTestInfo.pt := SmallPointToPoint(Message.Pos);
HitIndex := SendMessage(Handle, TCM_HITTEST, 0, Longint(@HitTestInfo));
if (HitIndex >= 0) and (HitIndex <> TabIndex) then Message.Result := 1;
end;
procedure TPageControl.CMDialogKey(var Message: TCMDialogKey);
begin
if (Focused or Windows.IsChild(Handle, Windows.GetFocus)) and
(Message.CharCode = VK_TAB) and (GetKeyState(VK_CONTROL) < 0) then
begin
SelectNextPage(GetKeyState(VK_SHIFT) >= 0);
Message.Result := 1;
end else
inherited;
end;
procedure TPageControl.CMDockClient(var Message: TCMDockClient);
var
IsVisible: Boolean;
DockCtl: TControl;
begin
Message.Result := 0;
FNewDockSheet := TTabSheet.Create(Self);
try
try
DockCtl := Message.DockSource.Control;
if DockCtl is TCustomForm then
FNewDockSheet.Caption := TCustomForm(DockCtl).Caption;
FNewDockSheet.PageControl := Self;
DockCtl.Dock(Self, Message.DockSource.DockRect);
except
FNewDockSheet.Free;
raise;
end;
IsVisible := DockCtl.Visible;
FNewDockSheet.TabVisible := IsVisible;
if IsVisible then ActivePage := FNewDockSheet;
DockCtl.Align := alClient;
finally
FNewDockSheet := nil;
end;
end;
procedure TPageControl.CMDockNotification(var Message: TCMDockNotification);
var
I: Integer;
S: string;
Page: TTabSheet;
begin
Page := GetPageFromDockClient(Message.Client);
if Page <> nil then
case Message.NotifyRec.ClientMsg of
WM_SETTEXT:
begin
S := PChar(Message.NotifyRec.MsgLParam);
{ Search for first CR/LF and end string there }
for I := 1 to Length(S) do
if S[I] in [#13, #10] then
begin
SetLength(S, I - 1);
Break;
end;
Page.Caption := S;
end;
CM_VISIBLECHANGED:
with Page do
begin
Visible := Boolean(Message.NotifyRec.MsgWParam);
TabVisible := Boolean(Message.NotifyRec.MsgWParam);;
end;
end;
inherited;
end;
procedure TPageControl.CMUnDockClient(var Message: TCMUnDockClient);
var
Page: TTabSheet;
begin
Message.Result := 0;
Page := GetPageFromDockClient(Message.Client);
if Page <> nil then
begin
FUndockingPage := Page;
Message.Client.Align := alNone;
end;
end;
function TPageControl.GetDockClientFromMousePos(MousePos: TPoint): TControl;
var
HitIndex: Integer;
HitTestInfo: TTCHitTestInfo;
Page: TTabSheet;
begin
Result := nil;
if DockSite then
begin
HitTestInfo.pt := MousePos;
HitIndex := SendMessage(Handle, TCM_HITTEST, 0, Longint(@HitTestInfo));
if HitIndex >= 0 then
begin
Page := Pages[HitIndex];
if not Page.TabVisible then Page := FindNextPage(Page, True, True);
if (Page <> nil) and (Page.ControlCount > 0) then
begin
Result := Page.Controls[0];
if Result.HostDockSite <> Self then Result := nil;
end;
end;
end;
end;
procedure TPageControl.WMLButtonDown(var Message: TWMLButtonDown);
var
DockCtl: TControl;
begin
inherited;
DockCtl := GetDockClientFromMousePos(SmallPointToPoint(Message.Pos));
if DockCtl <> nil then DockCtl.BeginDrag(False);
end;
procedure TPageControl.WMLButtonDblClk(var Message: TWMLButtonDblClk);
var
DockCtl: TControl;
begin
inherited;
DockCtl := GetDockClientFromMousePos(SmallPointToPoint(Message.Pos));
if DockCtl <> nil then DockCtl.ManualDock(nil, nil, alNone);
end;
*/
|