[15] | 1 | unit Notebook2Unit;
|
---|
| 2 |
|
---|
| 3 | interface
|
---|
| 4 |
|
---|
| 5 | uses
|
---|
| 6 | Messages, Os2Def, SysUtils, Classes, Forms, Graphics,
|
---|
| 7 | StdCtrls;
|
---|
| 8 |
|
---|
| 9 | type
|
---|
| 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 | {
|
---|
| 88 | procedure NotebookHandlesNeeded(Notebook: TNotebook2);
|
---|
| 89 | }
|
---|
| 90 |
|
---|
| 91 | Exports
|
---|
| 92 | TNotebook2, 'User', 'Notebook2.bmp';
|
---|
| 93 |
|
---|
| 94 | implementation
|
---|
| 95 |
|
---|
| 96 | //uses Consts;
|
---|
| 97 | uses
|
---|
| 98 | PmWin;
|
---|
| 99 |
|
---|
| 100 |
|
---|
| 101 | // Call HandleNeeded for each page in notebook. Used to allow anchors to work
|
---|
| 102 | // on invisible pages.
|
---|
| 103 | {
|
---|
| 104 | procedure NotebookHandlesNeeded(Notebook: TNotebook2);
|
---|
| 105 | var
|
---|
| 106 | I: Integer;
|
---|
| 107 | begin
|
---|
| 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;
|
---|
| 120 | end;
|
---|
| 121 | }
|
---|
| 122 | { TPageAccess }
|
---|
| 123 |
|
---|
| 124 | type
|
---|
| 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 |
|
---|
| 143 | constructor TPageAccess.Create(APageList: TList; ANotebook: TNotebook2);
|
---|
| 144 | begin
|
---|
| 145 | inherited Create;
|
---|
| 146 | PageList := APageList;
|
---|
| 147 | Notebook := ANotebook;
|
---|
| 148 | end;
|
---|
| 149 |
|
---|
| 150 | function TPageAccess.GetCount: Integer;
|
---|
| 151 | begin
|
---|
| 152 | Result := PageList.Count;
|
---|
| 153 | end;
|
---|
| 154 |
|
---|
| 155 | function TPageAccess.Get(Index: longint): string;
|
---|
| 156 | begin
|
---|
| 157 | Result := TNotebook2Page(PageList[Index]).Caption;
|
---|
| 158 | end;
|
---|
| 159 |
|
---|
| 160 | procedure TPageAccess.Put(Index: longint; const S: string);
|
---|
| 161 | begin
|
---|
| 162 | TNotebook2Page(PageList[Index]).Caption := S;
|
---|
| 163 | end;
|
---|
| 164 |
|
---|
| 165 | function TPageAccess.GetObject(Index: longint): TObject;
|
---|
| 166 | begin
|
---|
| 167 | Result := PageList[Index];
|
---|
| 168 | end;
|
---|
| 169 |
|
---|
| 170 | procedure TPageAccess.SetUpdateState(Updating: Boolean);
|
---|
| 171 | begin
|
---|
| 172 | { do nothing }
|
---|
| 173 | end;
|
---|
| 174 |
|
---|
| 175 | procedure TPageAccess.Clear;
|
---|
| 176 | var
|
---|
| 177 | I: Integer;
|
---|
| 178 | begin
|
---|
| 179 | for I := 0 to PageList.Count - 1 do
|
---|
| 180 | TNotebook2Page(PageList[I]).Free;
|
---|
| 181 | PageList.Clear;
|
---|
| 182 | end;
|
---|
| 183 |
|
---|
| 184 | procedure TPageAccess.Delete(Index: longint);
|
---|
| 185 | //var
|
---|
| 186 | // Form: TForm;
|
---|
| 187 | begin
|
---|
| 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;}
|
---|
| 198 | end;
|
---|
| 199 |
|
---|
| 200 | procedure TPageAccess.Insert(Index: longint; const S: string);
|
---|
| 201 | var
|
---|
| 202 | Page: TNotebook2Page;
|
---|
| 203 | // Form: TForm;
|
---|
| 204 | begin
|
---|
| 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 | }
|
---|
| 223 | end;
|
---|
| 224 |
|
---|
| 225 | procedure TPageAccess.Move(CurIndex, NewIndex: longint);
|
---|
| 226 | var
|
---|
| 227 | AObject: TObject;
|
---|
| 228 | begin
|
---|
| 229 | if CurIndex <> NewIndex then
|
---|
| 230 | begin
|
---|
| 231 | AObject := PageList[CurIndex];
|
---|
| 232 | PageList[CurIndex] := PageList[NewIndex];
|
---|
| 233 | PageList[NewIndex] := AObject;
|
---|
| 234 | end;
|
---|
| 235 | end;
|
---|
| 236 |
|
---|
| 237 | { TNotebook2Page }
|
---|
| 238 |
|
---|
| 239 | constructor TNotebook2Page.Create(AOwner: TComponent);
|
---|
| 240 | begin
|
---|
| 241 | inherited Create(AOwner);
|
---|
| 242 | Visible := False;
|
---|
| 243 | //ControlStyle := ControlStyle + [csAcceptsControls, csNoDesignVisible];
|
---|
| 244 | Include( ComponentState, csAcceptsControls );
|
---|
| 245 | Align := alClient;
|
---|
| 246 | end;
|
---|
| 247 |
|
---|
| 248 | procedure TNotebook2Page.Paint(const Rect:TRect);
|
---|
| 249 | begin
|
---|
| 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;
|
---|
| 258 | end;
|
---|
| 259 |
|
---|
| 260 | {
|
---|
| 261 | procedure TNotebook2Page.ReadState(Reader: TReader);
|
---|
| 262 | begin
|
---|
| 263 | if Reader.Parent is TNotebook2 then
|
---|
| 264 | TNotebook2(Reader.Parent).FPageList.Add(Self);
|
---|
| 265 | inherited ReadState(Reader);
|
---|
| 266 | end;
|
---|
| 267 | }
|
---|
| 268 | procedure TNotebook2Page.WMHitTest(var Message:TMessage);
|
---|
| 269 | begin
|
---|
| 270 | if not (csDesigning in ComponentState) then
|
---|
| 271 | Message.Result := HT_TRANSPARENT
|
---|
| 272 | else
|
---|
| 273 | inherited;
|
---|
| 274 | end;
|
---|
| 275 |
|
---|
| 276 | { TNotebook2 }
|
---|
| 277 |
|
---|
| 278 | const
|
---|
| 279 | Registered: Boolean = False;
|
---|
| 280 |
|
---|
| 281 | constructor TNotebook2.Create(AOwner: TComponent);
|
---|
| 282 | begin
|
---|
| 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;
|
---|
| 297 | end;
|
---|
| 298 |
|
---|
| 299 | destructor TNotebook2.Destroy;
|
---|
| 300 | begin
|
---|
| 301 | FAccess.Free;
|
---|
| 302 | FPageList.Free;
|
---|
| 303 | inherited Destroy;
|
---|
| 304 | end;
|
---|
| 305 |
|
---|
| 306 | procedure TNotebook2.CreateParams(var Params: TCreateParams);
|
---|
| 307 | begin
|
---|
| 308 | inherited CreateParams(Params);
|
---|
| 309 | with Params do
|
---|
| 310 | begin
|
---|
| 311 | Style := Style or WS_CLIPCHILDREN
|
---|
| 312 | and not (CS_SIZEREDRAW);
|
---|
| 313 | end;
|
---|
| 314 | end;
|
---|
| 315 |
|
---|
| 316 | {function TNotebook2.GetChildOwner: TComponent;
|
---|
| 317 | begin
|
---|
| 318 | Result := Self;
|
---|
| 319 | end;
|
---|
| 320 | }
|
---|
| 321 | procedure TNotebook2.GetChildren(Proc: TGetChildProc; Root: TComponent);
|
---|
| 322 | var
|
---|
| 323 | I: Integer;
|
---|
| 324 | begin
|
---|
| 325 | for I := 0 to FPageList.Count - 1 do Proc(TControl(FPageList[I]));
|
---|
| 326 | end;
|
---|
| 327 |
|
---|
| 328 | {
|
---|
| 329 | procedure TNotebook2.ReadState(Reader: TReader);
|
---|
| 330 | begin
|
---|
| 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;
|
---|
| 341 | end;
|
---|
| 342 |
|
---|
| 343 | procedure TNotebook2.ShowControl(AControl: TControl);
|
---|
| 344 | var
|
---|
| 345 | I: Integer;
|
---|
| 346 | begin
|
---|
| 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);
|
---|
| 354 | end;
|
---|
| 355 | }
|
---|
| 356 | procedure TNotebook2.SetPages(Value: TStrings);
|
---|
| 357 | begin
|
---|
| 358 | FAccess.Assign(Value);
|
---|
| 359 | end;
|
---|
| 360 |
|
---|
| 361 | procedure TNotebook2.SetPageIndex(Value: Integer);
|
---|
| 362 | var
|
---|
| 363 | ParentForm: TForm;
|
---|
| 364 | Page: TNotebook2Page;
|
---|
| 365 | begin
|
---|
| 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;
|
---|
| 392 | end;
|
---|
| 393 |
|
---|
| 394 | procedure TNotebook2.SetActivePage(const Value: string);
|
---|
| 395 | begin
|
---|
| 396 | SetPageIndex(FAccess.IndexOf(Value));
|
---|
| 397 | end;
|
---|
| 398 |
|
---|
| 399 | function TNotebook2.GetActivePage: string;
|
---|
| 400 | begin
|
---|
| 401 | Result := FAccess[FPageIndex];
|
---|
| 402 | end;
|
---|
| 403 |
|
---|
| 404 | initialization
|
---|
| 405 | RegisterClasses( [TNotebook2] );
|
---|
| 406 | end.
|
---|