source: branches/2.19_branch/Components/Notebook2Unit.pas@ 275

Last change on this file since 275 was 15, checked in by RBRi, 19 years ago

+ components stuff

  • Property svn:eol-style set to native
File size: 9.3 KB
Line 
1unit Notebook2Unit;
2
3interface
4
5uses
6 Messages, Os2Def, SysUtils, Classes, Forms, Graphics,
7 StdCtrls;
8
9type
10
11 TNotebook2Page = class(TControl)
12 private
13 procedure WMHitTest(var Message:TMessage); message WM_HITTEST;
14 protected
15// procedure ReadState(Reader: TReader); override;
16 procedure Paint(const Rect:TRect); override;
17 public
18 constructor Create(AOwner: TComponent); override;
19 published
20 property Caption;
21{
22 property Height stored False;
23 property TabOrder stored False;
24 property Visible stored False;
25 property Width stored False;
26}
27 end;
28
29 TNotebook2 = class(TControl)
30 private
31 FPageList: TList;
32 FAccess: TStrings;
33 FPageIndex: Integer;
34 FOnPageChanged: TNotifyEvent;
35 procedure SetPages(Value: TStrings);
36 procedure SetActivePage(const Value: string);
37 function GetActivePage: string;
38 procedure SetPageIndex(Value: Integer);
39 protected
40 procedure CreateParams(var Params: TCreateParams); override;
41// function GetChildOwner: TComponent; override;
42 procedure GetChildren(Proc: TGetChildProc; Root: TComponent); override;
43// procedure ReadState(Reader: TReader); override;
44// procedure ShowControl(AControl: TControl); //override;
45 public
46 constructor Create(AOwner: TComponent); override;
47 destructor Destroy; override;
48 published
49 property ActivePage: string read GetActivePage write SetActivePage stored False;
50 property Align;
51// property Anchors;
52 property Color;
53 property Ctl3D;
54 property DragCursor;
55// property DragKind;
56 property DragMode;
57 property Font;
58 property Enabled;
59// property Constraints;
60 property PageIndex: Integer read FPageIndex write SetPageIndex default 0;
61 property Pages: TStrings read FAccess write SetPages stored False;
62 property ParentColor;
63// property ParentCtl3D;
64 property ParentFont;
65 property ParentShowHint;
66 property PopupMenu;
67 property ShowHint;
68 property TabOrder;
69 property TabStop;
70 property Visible;
71 property OnClick;
72 property OnDblClick;
73 property OnDragDrop;
74 property OnDragOver;
75// property OnEndDock;
76 property OnEndDrag;
77 property OnEnter;
78 property OnExit;
79 property OnMouseDown;
80 property OnMouseMove;
81 property OnMouseUp;
82 property OnPageChanged: TNotifyEvent read FOnPageChanged write FOnPageChanged;
83// property OnStartDock;
84 property OnStartDrag;
85 end;
86
87{
88procedure NotebookHandlesNeeded(Notebook: TNotebook2);
89}
90
91Exports
92 TNotebook2, 'User', 'Notebook2.bmp';
93
94implementation
95
96//uses Consts;
97uses
98 PmWin;
99
100
101// Call HandleNeeded for each page in notebook. Used to allow anchors to work
102// on invisible pages.
103{
104procedure NotebookHandlesNeeded(Notebook: TNotebook2);
105var
106 I: Integer;
107begin
108 if Notebook <> nil then
109 for I := 0 to Notebook.FPageList.Count - 1 do
110 with TNotebook2Page(Notebook.FPageList[I]) do
111 begin
112 DisableAlign;
113 try
114 HandleNeeded;
115 ControlState := ControlState - [csAlignmentNeeded];
116 finally
117 EnableAlign;
118 end;
119 end;
120end;
121}
122{ TPageAccess }
123
124type
125 TPageAccess = class(TStrings)
126 private
127 PageList: TList;
128 Notebook: TNotebook2;
129 protected
130 function GetCount: longint; override;
131 function Get(Index: longint): string; override;
132 procedure Put(Index: longint; const S: string); override;
133 function GetObject(Index: longint): TObject; override;
134 procedure SetUpdateState(Updating: Boolean); override;
135 public
136 constructor Create(APageList: TList; ANotebook: TNotebook2);
137 procedure Clear; override;
138 procedure Delete(Index: longint); override;
139 procedure Insert(Index: longint; const S: string); override;
140 procedure Move(CurIndex, NewIndex: longint); override;
141 end;
142
143constructor TPageAccess.Create(APageList: TList; ANotebook: TNotebook2);
144begin
145 inherited Create;
146 PageList := APageList;
147 Notebook := ANotebook;
148end;
149
150function TPageAccess.GetCount: Integer;
151begin
152 Result := PageList.Count;
153end;
154
155function TPageAccess.Get(Index: longint): string;
156begin
157 Result := TNotebook2Page(PageList[Index]).Caption;
158end;
159
160procedure TPageAccess.Put(Index: longint; const S: string);
161begin
162 TNotebook2Page(PageList[Index]).Caption := S;
163end;
164
165function TPageAccess.GetObject(Index: longint): TObject;
166begin
167 Result := PageList[Index];
168end;
169
170procedure TPageAccess.SetUpdateState(Updating: Boolean);
171begin
172 { do nothing }
173end;
174
175procedure TPageAccess.Clear;
176var
177 I: Integer;
178begin
179 for I := 0 to PageList.Count - 1 do
180 TNotebook2Page(PageList[I]).Free;
181 PageList.Clear;
182end;
183
184procedure TPageAccess.Delete(Index: longint);
185//var
186// Form: TForm;
187begin
188 TNotebook2Page(PageList[Index]).Free;
189 PageList.Delete(Index);
190 NoteBook.PageIndex := 0;
191
192{ if csDesigning in NoteBook.ComponentState then
193 begin
194 Form := GetParentForm(NoteBook);
195 if (Form <> nil) and (Form.Designer <> nil) then
196 Form.Designer.Modified;
197 end;}
198end;
199
200procedure TPageAccess.Insert(Index: longint; const S: string);
201var
202 Page: TNotebook2Page;
203// Form: TForm;
204begin
205 Page := TNotebook2Page.Create(Notebook);
206 with Page do
207 begin
208 Parent := Notebook;
209 Caption := S;
210 end;
211 PageList.Insert(Index, Page);
212
213 NoteBook.PageIndex := Index;
214
215{
216 if csDesigning in NoteBook.ComponentState then
217 begin
218 Form := GetParentForm(NoteBook);
219 if (Form <> nil) and (Form.Designer <> nil) then
220 Form.Designer.Modified;
221 end;
222}
223end;
224
225procedure TPageAccess.Move(CurIndex, NewIndex: longint);
226var
227 AObject: TObject;
228begin
229 if CurIndex <> NewIndex then
230 begin
231 AObject := PageList[CurIndex];
232 PageList[CurIndex] := PageList[NewIndex];
233 PageList[NewIndex] := AObject;
234 end;
235end;
236
237{ TNotebook2Page }
238
239constructor TNotebook2Page.Create(AOwner: TComponent);
240begin
241 inherited Create(AOwner);
242 Visible := False;
243 //ControlStyle := ControlStyle + [csAcceptsControls, csNoDesignVisible];
244 Include( ComponentState, csAcceptsControls );
245 Align := alClient;
246end;
247
248procedure TNotebook2Page.Paint(const Rect:TRect);
249begin
250 inherited Paint(Rect);
251 if csDesigning in ComponentState then
252 with Canvas do
253 begin
254 Pen.Style := psDash;
255 Brush.Style := bsClear;
256 Rectangle( Forms.Rect(0, 0, Width, Height));
257 end;
258end;
259
260{
261procedure TNotebook2Page.ReadState(Reader: TReader);
262begin
263 if Reader.Parent is TNotebook2 then
264 TNotebook2(Reader.Parent).FPageList.Add(Self);
265 inherited ReadState(Reader);
266end;
267}
268procedure TNotebook2Page.WMHitTest(var Message:TMessage);
269begin
270 if not (csDesigning in ComponentState) then
271 Message.Result := HT_TRANSPARENT
272 else
273 inherited;
274end;
275
276{ TNotebook2 }
277
278const
279 Registered: Boolean = False;
280
281constructor TNotebook2.Create(AOwner: TComponent);
282begin
283 inherited Create(AOwner);
284 Width := 150;
285 Height := 150;
286 FPageList := TList.Create;
287 FAccess := TPageAccess.Create(FPageList, Self);
288 FPageIndex := -1;
289 FAccess.Add('Default');
290 PageIndex := 0;
291// Exclude(FComponentStyle, csInheritable);
292 if not Registered then
293 begin
294 Classes.RegisterClasses([TNotebook2Page]);
295 Registered := True;
296 end;
297end;
298
299destructor TNotebook2.Destroy;
300begin
301 FAccess.Free;
302 FPageList.Free;
303 inherited Destroy;
304end;
305
306procedure TNotebook2.CreateParams(var Params: TCreateParams);
307begin
308 inherited CreateParams(Params);
309 with Params do
310 begin
311 Style := Style or WS_CLIPCHILDREN
312 and not (CS_SIZEREDRAW);
313 end;
314end;
315
316{function TNotebook2.GetChildOwner: TComponent;
317begin
318 Result := Self;
319end;
320}
321procedure TNotebook2.GetChildren(Proc: TGetChildProc; Root: TComponent);
322var
323 I: Integer;
324begin
325 for I := 0 to FPageList.Count - 1 do Proc(TControl(FPageList[I]));
326end;
327
328{
329procedure TNotebook2.ReadState(Reader: TReader);
330begin
331 Pages.Clear;
332 inherited ReadState(Reader);
333 if (FPageIndex <> -1) and (FPageIndex >= 0) and (FPageIndex < FPageList.Count) then
334 with TNotebook2Page(FPageList[FPageIndex]) do
335 begin
336 BringToFront;
337 Visible := True;
338 Align := alClient;
339 end
340 else FPageIndex := -1;
341end;
342
343procedure TNotebook2.ShowControl(AControl: TControl);
344var
345 I: Integer;
346begin
347 for I := 0 to FPageList.Count - 1 do
348 if FPageList[I] = AControl then
349 begin
350 SetPageIndex(I);
351 Exit;
352 end;
353 inherited ShowControl(AControl);
354end;
355}
356procedure TNotebook2.SetPages(Value: TStrings);
357begin
358 FAccess.Assign(Value);
359end;
360
361procedure TNotebook2.SetPageIndex(Value: Integer);
362var
363 ParentForm: TForm;
364 Page: TNotebook2Page;
365begin
366 if csLoading in ComponentState then
367 begin
368 FPageIndex := Value;
369 Exit;
370 end;
371 if (Value <> FPageIndex) and (Value >= 0) and (Value < FPageList.Count) then
372 begin
373 ParentForm := GetParentForm(Self);
374 if ParentForm <> nil then
375 if ContainsControl(ParentForm.ActiveControl) then
376 ParentForm.ActiveControl := Self;
377 Page := TNotebook2Page(FPageList[Value]);
378 with Page do
379 begin
380 BringToFront;
381 Visible := True;
382 Align := alClient;
383 end;
384 if (FPageIndex >= 0) and (FPageIndex < FPageList.Count) then
385 TNotebook2Page(FPageList[FPageIndex]).Visible := False;
386 FPageIndex := Value;
387// if ParentForm <> nil then
388// if ParentForm.ActiveControl = Self then SelectFirst;
389 if Assigned(FOnPageChanged) then
390 FOnPageChanged(Self);
391 end;
392end;
393
394procedure TNotebook2.SetActivePage(const Value: string);
395begin
396 SetPageIndex(FAccess.IndexOf(Value));
397end;
398
399function TNotebook2.GetActivePage: string;
400begin
401 Result := FAccess[FPageIndex];
402end;
403
404initialization
405 RegisterClasses( [TNotebook2] );
406end.
Note: See TracBrowser for help on using the repository browser.