From f14005671fea60e31d0cd5018c43fc2d0ea00f6c Mon Sep 17 00:00:00 2001 From: dopi Date: Sat, 21 Apr 2012 21:13:38 +0000 Subject: [PATCH] git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@2399 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- components/tdi/Demo/TDIDemo.lps | 223 ++++++++++++++++++------------ components/tdi/Demo/uform1.lfm | 53 +++++-- components/tdi/Demo/uform1.pas | 2 + components/tdi/Demo/uform2.lfm | 64 ++++++--- components/tdi/Demo/uform2.pas | 8 +- components/tdi/Demo/umainform.lfm | 5 +- components/tdi/Demo/umainform.pas | 7 + components/tdi/tdiclass.pas | 73 ++++++---- 8 files changed, 290 insertions(+), 145 deletions(-) diff --git a/components/tdi/Demo/TDIDemo.lps b/components/tdi/Demo/TDIDemo.lps index d0607d33d..92b7e543f 100644 --- a/components/tdi/Demo/TDIDemo.lps +++ b/components/tdi/Demo/TDIDemo.lps @@ -12,7 +12,7 @@ - + @@ -23,7 +23,7 @@ - + @@ -32,11 +32,11 @@ - + - - - + + + @@ -47,11 +47,11 @@ - + - - - + + + @@ -64,9 +64,9 @@ - - - + + + @@ -75,13 +75,13 @@ - - - + + + - - - + + + @@ -96,27 +96,27 @@ + - - - + + + + - - - + + + - - @@ -178,20 +178,20 @@ - - + - - + + + @@ -204,18 +204,20 @@ + + - + - - + + @@ -406,8 +408,8 @@ - - + + @@ -423,10 +425,12 @@ + - - - + + + + @@ -438,10 +442,12 @@ + - - - + + + + @@ -531,9 +537,9 @@ - - - + + + @@ -545,8 +551,8 @@ - - + + @@ -560,82 +566,127 @@ - + - - + + - - + + - - + + - - + + - - + + - + - - + + - - + + - + - + - + - + - - + + - - + + - - + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - diff --git a/components/tdi/Demo/uform1.lfm b/components/tdi/Demo/uform1.lfm index 638704e9b..922613c1f 100644 --- a/components/tdi/Demo/uform1.lfm +++ b/components/tdi/Demo/uform1.lfm @@ -16,19 +16,19 @@ object Form1: TForm1 OnDestroy = FormDestroy LCLVersion = '1.1' object bClose: TButton - Left = 376 + Left = 392 Height = 25 Top = 216 - Width = 111 + Width = 86 AutoSize = True - Caption = 'Close,Free Form' + Caption = 'Close Form' OnClick = bCloseClick TabOrder = 2 end object Edit1: TEdit Left = 24 Height = 23 - Top = 80 + Top = 62 Width = 82 TabOrder = 0 Text = 'Edit1' @@ -36,7 +36,7 @@ object Form1: TForm1 object Edit2: TEdit Left = 24 Height = 23 - Top = 136 + Top = 104 Width = 82 OnExit = Edit2Exit TabOrder = 1 @@ -62,9 +62,11 @@ object Form1: TForm1 ParentFont = False end object Label3: TLabel - Left = 16 + AnchorSideTop.Control = bClose + AnchorSideTop.Side = asrCenter + Left = 32 Height = 46 - Top = 208 + Top = 205 Width = 324 Caption = 'You can Close or Hide your Forms the same way you used to.'#13#10'No Special method is necessary. TDINotebook will detect by '#13#10'internal Notification and Close the Tab Sheet' ParentColor = False @@ -72,9 +74,9 @@ object Form1: TForm1 object bHide: TButton AnchorSideLeft.Control = bClose AnchorSideLeft.Side = asrCenter - Left = 390 + Left = 394 Height = 25 - Top = 256 + Top = 159 Width = 82 AutoSize = True Caption = 'Hide Form' @@ -82,9 +84,11 @@ object Form1: TForm1 TabOrder = 3 end object lShowmeAgain: TLabel + AnchorSideTop.Control = bHide + AnchorSideTop.Side = asrCenter Left = 16 Height = 16 - Top = 272 + Top = 163 Width = 364 Caption = 'But, If you Hide the Form, is better you have a way to Show it again :)' Font.Color = clRed @@ -97,7 +101,7 @@ object Form1: TForm1 AnchorSideTop.Side = asrCenter Left = 120 Height = 16 - Top = 83 + Top = 65 Width = 106 Caption = 'This is a regular Edit' ParentColor = False @@ -107,11 +111,36 @@ object Form1: TForm1 AnchorSideTop.Side = asrCenter Left = 120 Height = 46 - Top = 124 + Top = 92 Width = 347 Caption = 'This Edit has a OnExit Validation, who doesn''t allow Page Change'#13#10' if this Edit is empty, and the focus is on it... '#13#10'This can be disabled changing the property "VerifyIfCanChange"' ParentColor = False end + object Label6: TLabel + AnchorSideLeft.Control = bClose + AnchorSideLeft.Side = asrCenter + AnchorSideTop.Side = asrBottom + AnchorSideBottom.Control = bClose + Left = 379 + Height = 16 + Top = 194 + Width = 112 + Anchors = [akLeft, akBottom] + BorderSpacing.Bottom = 6 + Caption = 'This Form use caFree' + ParentColor = False + end + object Label7: TLabel + AnchorSideLeft.Control = Owner + AnchorSideLeft.Side = asrCenter + AnchorSideTop.Side = asrCenter + Left = 35 + Height = 16 + Top = 264 + Width = 431 + Caption = 'This Form demonstrate that TDINotebook respects your OnCloseQuery Validation' + ParentColor = False + end object tShowmeAgain: TTimer Enabled = False Interval = 3000 diff --git a/components/tdi/Demo/uform1.pas b/components/tdi/Demo/uform1.pas index f8af745d9..8b18b6946 100644 --- a/components/tdi/Demo/uform1.pas +++ b/components/tdi/Demo/uform1.pas @@ -22,6 +22,8 @@ type Label3 : TLabel ; Label4 : TLabel ; Label5 : TLabel ; + Label6 : TLabel ; + Label7 : TLabel ; lShowmeAgain : TLabel ; tShowmeAgain : TTimer ; procedure bCloseClick(Sender : TObject) ; diff --git a/components/tdi/Demo/uform2.lfm b/components/tdi/Demo/uform2.lfm index bf08e93ab..933336e9a 100644 --- a/components/tdi/Demo/uform2.lfm +++ b/components/tdi/Demo/uform2.lfm @@ -1,11 +1,11 @@ object Form2: TForm2 - Left = 709 - Height = 243 + Left = 564 + Height = 252 Top = 330 - Width = 307 + Width = 452 Caption = 'Form2' - ClientHeight = 243 - ClientWidth = 307 + ClientHeight = 252 + ClientWidth = 452 OnClose = FormClose OnCloseQuery = FormCloseQuery OnDestroy = FormDestroy @@ -13,48 +13,74 @@ object Form2: TForm2 OnShow = FormShow LCLVersion = '1.1' object Edit1: TEdit - Left = 56 + Left = 48 Height = 23 - Top = 32 - Width = 211 + Top = 80 + Width = 356 Anchors = [akTop, akLeft, akRight] TabOrder = 0 Text = 'Edit1' end object Edit2: TEdit - Left = 56 + Left = 48 Height = 23 - Top = 72 - Width = 211 + Top = 120 + Width = 356 Anchors = [akTop, akLeft, akRight] TabOrder = 1 Text = 'Edit2' end object CheckBox1: TCheckBox - Left = 56 + Left = 48 Height = 19 - Top = 104 + Top = 152 Width = 78 Caption = 'CheckBox1' TabOrder = 2 end object CheckBox2: TCheckBox - Left = 56 + Left = 48 Height = 19 - Top = 136 + Top = 184 Width = 78 Caption = 'CheckBox2' TabOrder = 3 end - object Button1: TButton - Left = 195 + object bClose: TButton + Left = 318 Height = 25 - Top = 189 + Top = 192 Width = 86 Anchors = [akRight, akBottom] AutoSize = True Caption = 'Close Form' - OnClick = Button1Click + OnClick = bCloseClick TabOrder = 4 end + object Label2: TLabel + AnchorSideLeft.Control = Owner + AnchorSideLeft.Side = asrCenter + Left = 21 + Height = 31 + Top = 16 + Width = 411 + Alignment = taCenter + Caption = 'This Form does NOT have Max Constraints. It will be Aligned by "alClient". '#13#10'Design forms like this using Anchors to expand controls all over the Page' + Font.Style = [fsBold] + ParentColor = False + ParentFont = False + end + object Label1: TLabel + AnchorSideLeft.Control = bClose + AnchorSideLeft.Side = asrCenter + AnchorSideTop.Control = bClose + AnchorSideTop.Side = asrBottom + Left = 302 + Height = 16 + Top = 223 + Width = 118 + BorderSpacing.Top = 6 + Caption = 'This Form is not Freed' + ParentColor = False + end end diff --git a/components/tdi/Demo/uform2.pas b/components/tdi/Demo/uform2.pas index 4d1305596..7140c814c 100644 --- a/components/tdi/Demo/uform2.pas +++ b/components/tdi/Demo/uform2.pas @@ -13,12 +13,14 @@ type { TForm2 } TForm2 = class(TForm) - Button1 : TButton ; + bClose : TButton ; CheckBox1 : TCheckBox ; CheckBox2 : TCheckBox ; Edit1 : TEdit ; Edit2 : TEdit ; - procedure Button1Click(Sender : TObject) ; + Label1 : TLabel ; + Label2 : TLabel ; + procedure bCloseClick(Sender : TObject) ; procedure FormClose(Sender : TObject ; var CloseAction : TCloseAction) ; procedure FormCloseQuery(Sender : TObject ; var CanClose : boolean) ; procedure FormDestroy(Sender : TObject) ; @@ -44,7 +46,7 @@ begin fMainForm.mEvents.Lines.Add( 'Form2.Close' ); end; -procedure TForm2.Button1Click(Sender : TObject) ; +procedure TForm2.bCloseClick(Sender : TObject) ; begin Close; ClientRect; diff --git a/components/tdi/Demo/umainform.lfm b/components/tdi/Demo/umainform.lfm index ad3198315..8914c719c 100644 --- a/components/tdi/Demo/umainform.lfm +++ b/components/tdi/Demo/umainform.lfm @@ -32,7 +32,6 @@ object fMainForm: TfMainForm Height = 391 Top = 0 Width = 587 - TabStop = False ActivePage = tsFixed Align = alClient Constraints.MinHeight = 300 @@ -42,6 +41,7 @@ object fMainForm: TfMainForm TabIndex = 0 TabOrder = 1 OnChange = TDINoteBook1Change + OnCloseTabClicked = TDINoteBook1CloseTabClicked Options = [nboShowCloseButtons, nboMultiLine, nboKeyboardTabSwitch, nboShowAddTabButton] TabDragMode = dmAutomatic TabDragAcceptMode = dmAutomatic @@ -87,6 +87,9 @@ object fMainForm: TfMainForm TabOrder = 0 end end + object TabSheet1: TTabSheet + Caption = 'TabSheet1' + end end object pBottom: TPanel Left = 0 diff --git a/components/tdi/Demo/umainform.pas b/components/tdi/Demo/umainform.pas index 913b776bd..b861b19f1 100644 --- a/components/tdi/Demo/umainform.pas +++ b/components/tdi/Demo/umainform.pas @@ -33,6 +33,7 @@ type seFixedPages : TSpinEdit ; Splitter1 : TSplitter ; StatusBar1 : TStatusBar ; + TabSheet1 : TTabSheet ; tsFixed : TTabSheet ; TDINoteBook1 : TTDINoteBook ; procedure bToggleLogClick(Sender : TObject) ; @@ -47,6 +48,7 @@ type procedure miForm2Click(Sender : TObject) ; procedure seFixedPagesChange(Sender : TObject) ; procedure TDINoteBook1Change(Sender : TObject) ; + procedure TDINoteBook1CloseTabClicked(Sender : TObject) ; private { private declarations } Procedure ShowNewControl(Sender: TObject); @@ -136,6 +138,11 @@ begin mEvents.Lines.Add('OnChange'); end; +procedure TfMainForm.TDINoteBook1CloseTabClicked(Sender : TObject) ; +begin + mEvents.Lines.Add( 'TDINoteBook1.OnCloseTabClicked' ); +end; + procedure TfMainForm.ShowNewControl(Sender : TObject) ; var ControlCaption : String ; diff --git a/components/tdi/tdiclass.pas b/components/tdi/tdiclass.pas index 00912b63d..529dee75b 100644 --- a/components/tdi/tdiclass.pas +++ b/components/tdi/tdiclass.pas @@ -100,6 +100,7 @@ type FTabsMenuItem : TMenuItem ; FTimerRestoreLastControl : TTimer; FVerifyIfCanChangePage : Boolean ; + FIsRemovingAPage : Boolean; procedure CreateCloseBitBtn ; procedure CreateCloseMenuItem ; @@ -269,9 +270,6 @@ begin RestoreFormProperties; fsFormInPage := nil; - - if Assigned( Parent ) then - Parent.RemoveComponent( Self ); end ; end ; @@ -312,7 +310,14 @@ begin // This will force this page be killed by TTDINoteBook.Notification(); if Assigned( fsFormInPage ) then - RemoveComponent( fsFormInPage ); + begin + RestoreFormProperties; + + fsFormInPage := nil; + + if Assigned( Parent ) then + Parent.RemoveComponent( Self ); + end ; end ; procedure TTDIPage.SaveFormProperties ; @@ -333,15 +338,17 @@ procedure TTDIPage.RestoreFormProperties ; begin if not Assigned( fsFormInPage ) then exit ; + if ([csDesigning, csDestroying] * fsFormInPage.ComponentState <> []) 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; + fsFormInPage.OnClose := fsFormOldCloseEvent; end ; { TTDINoteBook } @@ -355,6 +362,7 @@ begin FFixedPages := 0; FRestoreActiveControl := True; FVerifyIfCanChangePage := True; + FIsRemovingAPage := False; FBackgroundImage := nil; FCloseBitBtn := nil; FCloseMenuItem := nil; @@ -846,27 +854,41 @@ end ; procedure TTDINoteBook.RemovePage(Index : Integer) ; Var CanRemovePage : Boolean ; + LastPageCount : Integer ; begin CanRemovePage := True; + FIsRemovingAPage := True; - if ([csDesigning, csDestroying] * ComponentState = []) then - if Pages[Index] is TTDIPage then - with TTDIPage(Pages[Index]) do - begin - if Assigned( FormInPage ) then + try + if ([csDesigning, csDestroying] * ComponentState = []) then + if Pages[Index] is TTDIPage then + with TTDIPage(Pages[Index]) do begin - CanRemovePage := FormInPage.CloseQuery ; - if CanRemovePage then + if Assigned( FormInPage ) then + begin + { // This code is ok, but calls CloseQuery twice // + CanRemovePage := FormInPage.CloseQuery ; + if CanRemovePage then + FormInPage.Close ; + } + LastPageCount := PageCount; FormInPage.Close ; + CanRemovePage := (LastPageCount = PageCount ) and // Page wasn't removed by Notification ? + ( (not Assigned(FormInPage)) or // Form Isn't valid ? + ( not FormInPage.Showing ) // Form is not showing ? + ); + end ; end ; - end ; - if CanRemovePage then - begin - inherited RemovePage(Index) ; + if CanRemovePage then + begin + inherited RemovePage(Index) ; - if PageCount < 1 then // On this case, DoChange is not fired // - CheckInterface; + if PageCount < 1 then // On this case, DoChange is not fired // + CheckInterface; + end ; + finally + FIsRemovingAPage := False; end ; end ; @@ -878,15 +900,18 @@ begin if (Operation = opRemove) then begin if (AComponent = FBackgroundImage) then - FBackgroundImage := nil ; + FBackgroundImage := nil - if (AComponent = FMainMenu) then - FMainMenu := nil ; + else if (AComponent = FMainMenu) then + FMainMenu := nil - if ([csDesigning, csDestroying] * ComponentState <> []) then exit ; + else if ([csDesigning, csDestroying] * ComponentState <> []) then - if {(AComponent is TForm) or} (AComponent is TTDIPage) then - RemoveInvalidPages; + else if (AComponent is TForm) then + RemoveInvalidPages + + else if (AComponent is TTDIPage) and (not FIsRemovingAPage) then + RemovePage( TTDIPage( AComponent ).PageIndex ) ; end ; end ;