From b28934bb745b654a017999d1d0ade74ae98852ac Mon Sep 17 00:00:00 2001 From: dopi Date: Sat, 21 Apr 2012 15:38:55 +0000 Subject: [PATCH] git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@2398 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- components/tdi/Demo/TDIDemo.lpi | 1 + components/tdi/Demo/TDIDemo.lps | 584 ++++++++++++++---------------- components/tdi/Demo/uform2.lfm | 35 +- components/tdi/Demo/uform2.pas | 1 + components/tdi/Demo/umainform.lfm | 5 + components/tdi/Demo/umainform.pas | 13 + components/tdi/tdiclass.pas | 106 +++++- 7 files changed, 410 insertions(+), 335 deletions(-) diff --git a/components/tdi/Demo/TDIDemo.lpi b/components/tdi/Demo/TDIDemo.lpi index 2d0ae6403..766f69113 100644 --- a/components/tdi/Demo/TDIDemo.lpi +++ b/components/tdi/Demo/TDIDemo.lpi @@ -69,6 +69,7 @@ + diff --git a/components/tdi/Demo/TDIDemo.lps b/components/tdi/Demo/TDIDemo.lps index 730b21570..d0607d33d 100644 --- a/components/tdi/Demo/TDIDemo.lps +++ b/components/tdi/Demo/TDIDemo.lps @@ -4,7 +4,7 @@ - + @@ -12,7 +12,7 @@ - + @@ -23,7 +23,7 @@ - + @@ -34,75 +34,91 @@ - - - + + + + + + + + + + + + + + + + + + + - - - + + + - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + - - - + + + - - - - - - - - + + + + + + + + - + - + - - + + @@ -111,41 +127,41 @@ - - - + + + - - - + + + - - - + + + - + - - + + - - - + + + @@ -156,243 +172,245 @@ - + - - + + - + - + - - + + - - - - - + + + + + - - - + + + - + - - - - - - - - + + + + + + + + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - - - - - - + + + + + + + + - - - + + + - - - + + + - - - + + + - - - - - + + + + + - - - + + + - - - - - - - - + + + + + + + + @@ -401,91 +419,91 @@ - - - - - - - - + + + + + + + + - - - + + + - - + + - - + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + @@ -494,175 +512,119 @@ - - - + + + - - - + + + - - - + + + - - - - - - - - + - - - - - - + - - - - - + + + + + + + + + + + + + + + + + - + - + - + - + - + - + - - + + - - + + - + - - + + - - + + - - + + - - + + - + - - + + - - + + - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -671,8 +633,8 @@ - - + + diff --git a/components/tdi/Demo/uform2.lfm b/components/tdi/Demo/uform2.lfm index d03b0cb56..bf08e93ab 100644 --- a/components/tdi/Demo/uform2.lfm +++ b/components/tdi/Demo/uform2.lfm @@ -1,11 +1,11 @@ object Form2: TForm2 Left = 709 - Height = 240 + Height = 243 Top = 330 - Width = 320 + Width = 307 Caption = 'Form2' - ClientHeight = 240 - ClientWidth = 320 + ClientHeight = 243 + ClientWidth = 307 OnClose = FormClose OnCloseQuery = FormCloseQuery OnDestroy = FormDestroy @@ -13,42 +13,45 @@ object Form2: TForm2 OnShow = FormShow LCLVersion = '1.1' object Edit1: TEdit - Left = 51 + Left = 56 Height = 23 - Top = 37 - Width = 80 + Top = 32 + Width = 211 + Anchors = [akTop, akLeft, akRight] TabOrder = 0 Text = 'Edit1' end object Edit2: TEdit - Left = 159 + Left = 56 Height = 23 - Top = 37 - Width = 80 + Top = 72 + Width = 211 + Anchors = [akTop, akLeft, akRight] TabOrder = 1 Text = 'Edit2' end object CheckBox1: TCheckBox - Left = 51 + Left = 56 Height = 19 - Top = 72 + Top = 104 Width = 78 Caption = 'CheckBox1' TabOrder = 2 end object CheckBox2: TCheckBox - Left = 51 + Left = 56 Height = 19 - Top = 104 + Top = 136 Width = 78 Caption = 'CheckBox2' TabOrder = 3 end object Button1: TButton - Left = 208 + Left = 195 Height = 25 - Top = 186 + Top = 189 Width = 86 + Anchors = [akRight, akBottom] AutoSize = True Caption = 'Close Form' OnClick = Button1Click diff --git a/components/tdi/Demo/uform2.pas b/components/tdi/Demo/uform2.pas index e8df7c88c..4d1305596 100644 --- a/components/tdi/Demo/uform2.pas +++ b/components/tdi/Demo/uform2.pas @@ -47,6 +47,7 @@ end; procedure TForm2.Button1Click(Sender : TObject) ; begin Close; + ClientRect; end; procedure TForm2.FormCloseQuery(Sender : TObject ; var CanClose : boolean) ; diff --git a/components/tdi/Demo/umainform.lfm b/components/tdi/Demo/umainform.lfm index aa69e33ca..ad3198315 100644 --- a/components/tdi/Demo/umainform.lfm +++ b/components/tdi/Demo/umainform.lfm @@ -10,6 +10,7 @@ object fMainForm: TfMainForm OnClose = FormClose OnCloseQuery = FormCloseQuery OnCreate = FormCreate + OnDestroy = FormDestroy LCLVersion = '1.1' object StatusBar1: TStatusBar Left = 0 @@ -674,6 +675,10 @@ object fMainForm: TfMainForm Caption = 'Show Already Created Form 2' OnClick = miForm2Click end + object MenuItem3: TMenuItem + Caption = 'Show Form2' + OnClick = MenuItem3Click + end object MenuItem2: TMenuItem Caption = '-' end diff --git a/components/tdi/Demo/umainform.pas b/components/tdi/Demo/umainform.pas index 30459c32d..913b776bd 100644 --- a/components/tdi/Demo/umainform.pas +++ b/components/tdi/Demo/umainform.pas @@ -22,6 +22,7 @@ type Label2 : TLabel ; Label3 : TLabel ; MainMenu1 : TMainMenu ; + MenuItem3 : TMenuItem ; mEvents : TMemo ; MenuItem1 : TMenuItem ; MenuItem2 : TMenuItem ; @@ -39,6 +40,8 @@ type procedure FormClose(Sender : TObject ; var CloseAction : TCloseAction) ; procedure FormCloseQuery(Sender : TObject ; var CanClose : boolean) ; procedure FormCreate(Sender : TObject) ; + procedure FormDestroy(Sender : TObject) ; + procedure MenuItem3Click(Sender : TObject) ; procedure miExitClick(Sender : TObject) ; procedure miForm1Click(Sender : TObject) ; procedure miForm2Click(Sender : TObject) ; @@ -71,6 +74,16 @@ begin cbxBackgroundCorner.ItemIndex := Integer(TDINoteBook1.BackgroundCorner); end; +procedure TfMainForm.FormDestroy(Sender : TObject) ; +begin + mEvents.Lines.Add('fMainForm.Destroy'); +end; + +procedure TfMainForm.MenuItem3Click(Sender : TObject) ; +begin + Form2.Show; +end; + procedure TfMainForm.cbxBackgroundCornerChange(Sender : TObject) ; begin TDINoteBook1.BackgroundCorner := TTDIBackgroundCorner( cbxBackgroundCorner.ItemIndex ); diff --git a/components/tdi/tdiclass.pas b/components/tdi/tdiclass.pas index 2b868c822..00912b63d 100644 --- a/components/tdi/tdiclass.pas +++ b/components/tdi/tdiclass.pas @@ -49,9 +49,17 @@ type TTDIPage = class(TTabSheet) private fsFormInPage : TForm ; + fsFormOldParent: TWinControl; + fsFormOldCloseEvent : TCloseEvent; + fsFormOldAlign : TAlign; + fsFormOldClientRect : TRect; + fsFormOldBorderStyle : TFormBorderStyle; fsLastActiveControl: TWinControl; procedure OnResizeTDIPage(Sender : TObject) ; + procedure OnFormClose(Sender: TObject; var CloseAction: TCloseAction); + procedure SaveFormProperties ; + procedure RestoreFormProperties ; procedure SetFormInPage(AValue : TForm) ; protected @@ -108,6 +116,7 @@ type procedure TimerRestoreLastFocus( Sender: TObject ); + procedure RemoveInvalidPages ; protected function CanChange: Boolean; override; procedure DoChange; override; @@ -223,13 +232,19 @@ procedure TTDIPage.SetFormInPage(AValue : TForm) ; begin fsFormInPage := AValue ; + // Saving Form Properties // + SaveFormProperties ; + // Adjusting Page Caption and Color as the Form // Caption := fsFormInPage.Caption; //Color := fsFormInPage.Color; + // HiJacking the Form.OnClose Event, to detect Form Closed from Inside // + fsFormInPage.OnClose := @OnFormClose; + // Adjusting AForm Border Style and Align // fsFormInPage.BorderStyle := bsNone ; - //fsFormInPage.Align := alClient ; // This will be done in OnResizeTDIPage + fsFormInPage.Align := alClient ; // Change Form Parent to the Page // fsFormInPage.Parent := Self; @@ -247,8 +262,17 @@ procedure TTDIPage.Notification(AComponent : TComponent ; Operation : TOperation begin inherited Notification(AComponent, Operation) ; + if ([csDesigning, csDestroying] * ComponentState <> []) then exit ; + if (Operation = opRemove) and (AComponent = fsFormInPage) then + begin + RestoreFormProperties; + fsFormInPage := nil; + + if Assigned( Parent ) then + Parent.RemoveComponent( Self ); + end ; end ; procedure TTDIPage.CheckFormAlign ; @@ -257,15 +281,19 @@ begin { If Form has MaxConstrains and doesn't fill all the Screen, Centralize on TabSheet } - if (fsFormInPage.Width < Width) and (fsFormInPage.Height < Height) then + if (fsFormInPage.Width < Width) or (fsFormInPage.Height < Height) then begin fsFormInPage.Align := alNone; if (fsFormInPage.Width < Width) then - fsFormInPage.Left := Trunc( (Width - fsFormInPage.Width) / 2 ); + fsFormInPage.Left := Trunc( (Width - fsFormInPage.Width) / 2 ) + else + fsFormInPage.Left := 0 ; if (fsFormInPage.Height < Height) then - fsFormInPage.Top := Trunc( (Height - fsFormInPage.Height) / 2 ); + fsFormInPage.Top := Trunc( (Height - fsFormInPage.Height) / 2 ) + else + fsFormInPage.Top := 0 ; end else fsFormInPage.Align := alClient; @@ -276,6 +304,46 @@ begin CheckFormAlign; end ; +procedure TTDIPage.OnFormClose(Sender : TObject ; var CloseAction : TCloseAction + ) ; +begin + if Assigned( fsFormOldCloseEvent ) then + fsFormOldCloseEvent( Sender, CloseAction ); + + // This will force this page be killed by TTDINoteBook.Notification(); + if Assigned( fsFormInPage ) then + RemoveComponent( fsFormInPage ); +end ; + +procedure TTDIPage.SaveFormProperties ; +begin + if not Assigned( fsFormInPage ) then exit ; + + fsFormOldParent := fsFormInPage.Parent; + fsFormOldCloseEvent := fsFormInPage.OnClose; + fsFormOldAlign := fsFormInPage.Align; + fsFormOldBorderStyle := fsFormInPage.BorderStyle; + fsFormOldClientRect.Top := fsFormInPage.Top; + fsFormOldClientRect.Left := fsFormInPage.Left; + fsFormOldClientRect.Right := fsFormInPage.Width; + fsFormOldClientRect.Bottom := fsFormInPage.Height; +end ; + +procedure TTDIPage.RestoreFormProperties ; +begin + if not Assigned( fsFormInPage ) then exit ; + + fsFormInPage.Parent := fsFormOldParent; + fsFormInPage.Visible := False; + fsFormInPage.OnClose := fsFormOldCloseEvent; + fsFormInPage.Align := fsFormOldAlign; + fsFormInPage.BorderStyle := fsFormOldBorderStyle; + fsFormInPage.Top := fsFormOldClientRect.Top; + fsFormInPage.Left := fsFormOldClientRect.Left; + fsFormInPage.Width := fsFormOldClientRect.Right; + fsFormInPage.Height := fsFormOldClientRect.Bottom; +end ; + { TTDINoteBook } constructor TTDINoteBook.Create(TheOwner : TComponent) ; @@ -815,12 +883,10 @@ begin if (AComponent = FMainMenu) then FMainMenu := nil ; - if ([csDesigning, csDestroying] * ComponentState <> []) then exit ; - if (AComponent is TForm) then - if TForm(AComponent).Parent is TTDIPage then - RemovePage( TTDIPage(TForm(AComponent).Parent).PageIndex ); + if {(AComponent is TForm) or} (AComponent is TTDIPage) then + RemoveInvalidPages; end ; end ; @@ -868,5 +934,29 @@ begin FBackgroundImage.Visible := True ; end ; +procedure TTDINoteBook.RemoveInvalidPages ; +var + I : Integer ; +begin + // Remove all TTDIPage with FormInPage not assigned //; + I := 0 ; + while I < PageCount do + begin + if Page[I] is TTDIPage then + begin + with TTDIPage( Page[I] ) do + begin + if FormInPage = nil then + begin + RemovePage( I ); + Dec( I ) ; + end ; + end ; + end ; + + Inc( I ) ; + end ; +end ; + end.