MG: TNotebook is now streamable

git-svn-id: trunk@3284 -
This commit is contained in:
lazarus 2002-09-05 12:11:43 +00:00
parent 054b715d8d
commit 7c8d67a7ad
6 changed files with 409 additions and 184 deletions

View File

@ -44,34 +44,34 @@ or use TPropertyType
// ptClass, ptMethod,ptWChar, ptLString, LWString, ptVariant); // ptClass, ptMethod,ptWChar, ptLString, LWString, ptVariant);
TIComponentInterface = class TIComponentInterface = class
public public
Function GetComponentType : String; virtual; abstract; Function GetComponentType : String; virtual; abstract;
Function GetComponentHandle : LongInt; virtual; abstract; Function GetComponentHandle : LongInt; virtual; abstract;
Function GetParent : TIComponentInterface; virtual; abstract; Function GetParent : TIComponentInterface; virtual; abstract;
Function IsTControl : Boolean; virtual; abstract; Function IsTControl : Boolean; virtual; abstract;
Function GetPropCount : Integer; virtual; abstract; Function GetPropCount : Integer; virtual; abstract;
Function GetPropType(Index : Integer) : TTypeKind; virtual; abstract; Function GetPropType(Index : Integer) : TTypeKind; virtual; abstract;
// Function GetPropType(Index : Integer) : TPropertyType; virtual; abstract; // Function GetPropType(Index : Integer) : TPropertyType; virtual; abstract;
Function GetPropName(Index : Integer) : String; virtual; abstract; Function GetPropName(Index : Integer) : String; virtual; abstract;
Function GetPropTypebyName(Name : String) : TTypeKind; virtual; abstract; Function GetPropTypebyName(Name : String) : TTypeKind; virtual; abstract;
// Function GetPropTypebyName(Name : String) : TPropertyType; virtual; abstract; // Function GetPropTypebyName(Name : String) : TPropertyType; virtual; abstract;
Function GetPropTypeName(Index : Integer) : String; virtual; abstract; Function GetPropTypeName(Index : Integer) : String; virtual; abstract;
Function GetPropValue(Index : Integer; var Value) : Boolean; virtual; abstract; Function GetPropValue(Index : Integer; var Value) : Boolean; virtual; abstract;
Function GetPropValuebyName(Name: String; var Value) : Boolean; virtual; abstract; Function GetPropValuebyName(Name: String; var Value) : Boolean; virtual; abstract;
Function SetProp(Index : Integer; const Value) : Boolean; virtual; abstract; Function SetProp(Index : Integer; const Value) : Boolean; virtual; abstract;
Function SetPropbyName(Name : String; const Value) : Boolean; virtual; abstract; Function SetPropbyName(Name : String; const Value) : Boolean; virtual; abstract;
Function GetControlCount: Integer; virtual; abstract; Function GetControlCount: Integer; virtual; abstract;
Function GetControl(Index : Integer): TIComponentInterface; virtual; abstract; Function GetControl(Index : Integer): TIComponentInterface; virtual; abstract;
Function GetComponentCount: Integer; virtual; abstract; Function GetComponentCount: Integer; virtual; abstract;
Function GetComponent(Index : Integer): TIComponentInterface; virtual; abstract; Function GetComponent(Index : Integer): TIComponentInterface; virtual; abstract;
Function Select : Boolean; virtual; abstract; Function Select : Boolean; virtual; abstract;
Function Focus : Boolean; virtual; abstract; Function Focus : Boolean; virtual; abstract;
Function Delete : Boolean; virtual; abstract; Function Delete : Boolean; virtual; abstract;
end; end;

View File

@ -37,6 +37,7 @@ type
protected protected
function GetPropertyEditorHook: TPropertyEditorHook; virtual; abstract; function GetPropertyEditorHook: TPropertyEditorHook; virtual; abstract;
public public
function CreateUniqueComponentName(const AClassName: string): string; virtual; abstract;
property PropertyEditorHook: TPropertyEditorHook read GetPropertyEditorHook; property PropertyEditorHook: TPropertyEditorHook read GetPropertyEditorHook;
end; end;
@ -132,6 +133,7 @@ type
function IsInInlined: Boolean; virtual; abstract; function IsInInlined: Boolean; virtual; abstract;
function GetComponent: TComponent; virtual; abstract; function GetComponent: TComponent; virtual; abstract;
function GetDesigner: TComponentEditorDesigner; virtual; abstract; function GetDesigner: TComponentEditorDesigner; virtual; abstract;
function GetHook(var Hook: TPropertyEditorHook): boolean; virtual; abstract;
end; end;
TComponentEditorClass = class of TBaseComponentEditor; TComponentEditorClass = class of TBaseComponentEditor;
@ -161,6 +163,7 @@ type
procedure PrepareItem(Index: Integer; const AnItem: TMenuItem); override; procedure PrepareItem(Index: Integer; const AnItem: TMenuItem); override;
property Component: TComponent read FComponent; property Component: TComponent read FComponent;
property Designer: TComponentEditorDesigner read GetDesigner; property Designer: TComponentEditorDesigner read GetDesigner;
function GetHook(var Hook: TPropertyEditorHook): boolean; override;
end; end;
@ -182,14 +185,16 @@ type
end; end;
{ TNotebookComponentEditor { TNotebookComponentEditor
The default component editor for TNotebook. It adds the following menu items The default component editor for TNotebook. }
to the popupmenu of the designer:
ToDo:
'Insert page', 'Delete page', 'Move page left', 'Move page right',
'Select all pages'}
TNotebookComponentEditor = class(TDefaultComponentEditor) TNotebookComponentEditor = class(TDefaultComponentEditor)
protected protected
procedure AddNewPageToDesigner(Index: integer); virtual;
procedure DoAddPage; virtual;
procedure DoInsertPage; virtual; procedure DoInsertPage; virtual;
procedure DoDeletePage; virtual;
procedure DoMoveActivePageLeft; virtual;
procedure DoMoveActivePageRight; virtual;
procedure DoMoveActivePage(CurIndex, NewIndex: Integer); virtual;
public public
procedure ExecuteVerb(Index: Integer); override; procedure ExecuteVerb(Index: Integer); override;
function GetVerb(Index: Integer): string; override; function GetVerb(Index: Integer): string; override;
@ -459,6 +464,14 @@ begin
// Intended for descendents to implement // Intended for descendents to implement
end; end;
function TComponentEditor.GetHook(var Hook: TPropertyEditorHook): boolean;
begin
Result:=false;
if GetDesigner=nil then exit;
Hook:=GetDesigner.PropertyEditorHook;
Result:=Hook<>nil;
end;
{ TDefaultComponentEditor } { TDefaultComponentEditor }
procedure TDefaultComponentEditor.CheckEdit(Prop: TPropertyEditor); procedure TDefaultComponentEditor.CheckEdit(Prop: TPropertyEditor);
@ -501,8 +514,8 @@ var
Components: TComponentSelectionList; Components: TComponentSelectionList;
PropertyEditorHook: TPropertyEditorHook; PropertyEditorHook: TPropertyEditorHook;
begin begin
PropertyEditorHook:=Designer.PropertyEditorHook; PropertyEditorHook:=nil;
if PropertyEditorHook=nil then exit; if not GetHook(PropertyEditorHook) then exit;
Components := TComponentSelectionList.Create; Components := TComponentSelectionList.Create;
FContinue := True; FContinue := True;
Components.Add(Component); Components.Add(Component);
@ -519,6 +532,7 @@ begin
finally finally
FFirst := nil; FFirst := nil;
FBest := nil; FBest := nil;
Components.Free;
end; end;
end; end;
@ -526,29 +540,109 @@ end;
{ TNotebookComponentEditor } { TNotebookComponentEditor }
const const
nbvInsertPage = 0; nbvAddPage = 0;
nbvDeletePage = 1; nbvInsertPage = 1;
nbvMovePageLeft = 2; nbvDeletePage = 2;
nbvMovePageRight = 3; nbvMovePageLeft = 3;
nbvMovePageRight = 4;
procedure TNotebookComponentEditor.AddNewPageToDesigner(Index: integer);
var
Hook: TPropertyEditorHook;
NewPage: TPage;
NewName: string;
begin
Hook:=nil;
if not GetHook(Hook) then exit;
NewPage:=NoteBook.Page[Index];
writeln('TNotebookComponentEditor.AddNewPageToDesigner ',NewPage<>nil,' ',Hook<>nil);
NewName:=GetDesigner.CreateUniqueComponentName(NewPage.ClassName);
NewPage.Caption:=NewName;
NewPage.Name:=NewName;
writeln('TNotebookComponentEditor.AddNewPageToDesigner ',Index);
NoteBook.PageIndex:=Index;
writeln('TNotebookComponentEditor.AddNewPageToDesigner ',NoteBook.PageIndex);
Hook.ComponentAdded(NewPage,true);
GetDesigner.Modified;
end;
procedure TNotebookComponentEditor.DoAddPage;
var
Hook: TPropertyEditorHook;
begin
if not GetHook(Hook) then exit;
NoteBook.Pages.Add('');
AddNewPageToDesigner(NoteBook.PageCount-1);
end;
procedure TNotebookComponentEditor.DoInsertPage; procedure TNotebookComponentEditor.DoInsertPage;
var
Hook: TPropertyEditorHook;
NewIndex: integer;
begin begin
if not GetHook(Hook) then exit;
NewIndex:=Notebook.PageIndex;
if NewIndex<0 then NewIndex:=0;
Notebook.Pages.Insert(NewIndex,'');
AddNewPageToDesigner(NewIndex);
end;
procedure TNotebookComponentEditor.DoDeletePage;
var
Hook: TPropertyEditorHook;
OldIndex: integer;
begin
OldIndex:=Notebook.PageIndex;
if (OldIndex>=0) and (OldIndex<Notebook.PageCount) then begin
if not GetHook(Hook) then exit;
Hook.DeleteComponent(TComponent(NoteBook.PageList[OldIndex]));
GetDesigner.Modified;
end;
end;
procedure TNotebookComponentEditor.DoMoveActivePageLeft;
var
Index: integer;
begin
Index:=NoteBook.PageIndex;
if (Index<0) then exit;
DoMoveActivePage(Index,Index-1);
end;
procedure TNotebookComponentEditor.DoMoveActivePageRight;
var
Index: integer;
begin
Index:=NoteBook.PageIndex;
if (Index>=0)
and (Index>=NoteBook.PageCount-1) then exit;
DoMoveActivePage(Index,Index+1);
end;
procedure TNotebookComponentEditor.DoMoveActivePage(
CurIndex, NewIndex: Integer);
begin
writeln('TNotebookComponentEditor.DoMoveActivePage ',CurIndex,' -> ',NewIndex,
' ',NoteBook.Pages.ClassName);
NoteBook.Pages.Move(CurIndex,NewIndex);
GetDesigner.Modified;
end; end;
procedure TNotebookComponentEditor.ExecuteVerb(Index: Integer); procedure TNotebookComponentEditor.ExecuteVerb(Index: Integer);
begin begin
case Index of case Index of
nbvAddPage: DoAddPage;
nbvInsertPage: DoInsertPage; nbvInsertPage: DoInsertPage;
nbvDeletePage: ; nbvDeletePage: DoDeletePage;
nbvMovePageLeft: ; nbvMovePageLeft: DoMoveActivePageLeft;
nbvMovePageRight: ; nbvMovePageRight: DoMoveActivePageRight;
end; end;
end; end;
function TNotebookComponentEditor.GetVerb(Index: Integer): string; function TNotebookComponentEditor.GetVerb(Index: Integer): string;
begin begin
case Index of case Index of
nbvAddPage: Result:='Add page';
nbvInsertPage: Result:='Insert page'; nbvInsertPage: Result:='Insert page';
nbvDeletePage: Result:='Delete page'; nbvDeletePage: Result:='Delete page';
nbvMovePageLeft: Result:='Move page left'; nbvMovePageLeft: Result:='Move page left';
@ -560,7 +654,7 @@ end;
function TNotebookComponentEditor.GetVerbCount: Integer; function TNotebookComponentEditor.GetVerbCount: Integer;
begin begin
Result:=4; Result:=5;
end; end;
procedure TNotebookComponentEditor.PrepareItem(Index: Integer; procedure TNotebookComponentEditor.PrepareItem(Index: Integer;
@ -568,7 +662,8 @@ procedure TNotebookComponentEditor.PrepareItem(Index: Integer;
begin begin
inherited PrepareItem(Index, AnItem); inherited PrepareItem(Index, AnItem);
case Index of case Index of
nbvInsertPage: ; nbvAddPage: ;
nbvInsertPage: AnItem.Enabled:=Notebook.PageIndex>=0;
nbvDeletePage: AnItem.Enabled:=Notebook.PageIndex>=0; nbvDeletePage: AnItem.Enabled:=Notebook.PageIndex>=0;
nbvMovePageLeft: AnItem.Enabled:=Notebook.PageIndex>0; nbvMovePageLeft: AnItem.Enabled:=Notebook.PageIndex>0;
nbvMovePageRight: AnItem.Enabled:=Notebook.PageIndex<Notebook.PageCount-1; nbvMovePageRight: AnItem.Enabled:=Notebook.PageIndex<Notebook.PageCount-1;

View File

@ -79,7 +79,9 @@ function GetParentFormRelativeTopLeft(Component: TComponent): TPoint;
function GetParentFormRelativeBounds(Component: TComponent): TRect; function GetParentFormRelativeBounds(Component: TComponent): TRect;
function GetParentFormRelativeClientOrigin(Component: TComponent): TPoint; function GetParentFormRelativeClientOrigin(Component: TComponent): TPoint;
function GetParentFormRelativeParentClientOrigin(Component: TComponent): TPoint; function GetParentFormRelativeParentClientOrigin(Component: TComponent): TPoint;
function GetFormRelativeMousePosition(Form: TCustomForm): TPoint; function GetFormRelativeMousePosition(Form: TCustomForm): TPoint;
function ComponentIsTopLvl(AComponent: TComponent): boolean; function ComponentIsTopLvl(AComponent: TComponent): boolean;
procedure GetComponentBounds(AComponent: TComponent; procedure GetComponentBounds(AComponent: TComponent;
var Left, Top, Width, Height: integer); var Left, Top, Width, Height: integer);
@ -89,8 +91,10 @@ function GetComponentWidth(AComponent: TComponent): integer;
function GetComponentHeight(AComponent: TComponent): integer; function GetComponentHeight(AComponent: TComponent): integer;
implementation implementation
function GetParentFormRelativeTopLeft(Component: TComponent): TPoint; function GetParentFormRelativeTopLeft(Component: TComponent): TPoint;
var var
FormOrigin: TPoint; FormOrigin: TPoint;

View File

@ -121,7 +121,7 @@ TCustomFormEditor
Procedure RemoveFromComponentInterfaceList(Value :TIComponentInterface); Procedure RemoveFromComponentInterfaceList(Value :TIComponentInterface);
procedure SetSelectedComponents(TheSelectedComponents : TComponentSelectionList); procedure SetSelectedComponents(TheSelectedComponents : TComponentSelectionList);
procedure OnObjectInspectorModified(Sender: TObject); procedure OnObjectInspectorModified(Sender: TObject);
procedure SetObj_Inspector(AnObjectInspector: TObjectInspector); procedure SetObj_Inspector(AnObjectInspector: TObjectInspector); virtual;
public public
JITFormList : TJITForms; JITFormList : TJITForms;
constructor Create; constructor Create;
@ -132,8 +132,12 @@ TCustomFormEditor
Function FormModified : Boolean; override; Function FormModified : Boolean; override;
Function FindComponentByName(const Name : ShortString) : TIComponentInterface; override; Function FindComponentByName(const Name : ShortString) : TIComponentInterface; override;
Function FindComponent(AComponent: TComponent): TIComponentInterface; override; Function FindComponent(AComponent: TComponent): TIComponentInterface; override;
function GetComponentEditor(AComponent: TComponent): TBaseComponentEditor; function GetComponentEditor(AComponent: TComponent): TBaseComponentEditor;
Function GetFormComponent : TIComponentInterface; override; Function GetFormComponent: TIComponentInterface; override;
function CreateUniqueComponentName(AComponent: TComponent): string;
function CreateUniqueComponentName(const AClassName: string;
OwnerComponent: TComponent): string;
// Function CreateComponent(CI : TIComponentInterface; TypeName : String; // Function CreateComponent(CI : TIComponentInterface; TypeName : String;
Function CreateComponentInterface(AComponent: TComponent): TIComponentInterface; Function CreateComponentInterface(AComponent: TComponent): TIComponentInterface;
@ -143,7 +147,7 @@ TCustomFormEditor
Procedure SetFormNameAndClass(CI: TIComponentInterface; Procedure SetFormNameAndClass(CI: TIComponentInterface;
const NewFormName, NewClassName: shortstring); const NewFormName, NewClassName: shortstring);
Procedure ClearSelected; Procedure ClearSelected;
property SelectedComponents : TComponentSelectionList property SelectedComponents: TComponentSelectionList
read FSelectedComponents write SetSelectedComponents; read FSelectedComponents write SetSelectedComponents;
property Obj_Inspector : TObjectInspector property Obj_Inspector : TObjectInspector
read FObj_Inspector write SetObj_Inspector; read FObj_Inspector write SetObj_Inspector;
@ -684,33 +688,28 @@ end;
Function TCustomFormEditor.CreateComponent(ParentCI : TIComponentInterface; Function TCustomFormEditor.CreateComponent(ParentCI : TIComponentInterface;
TypeClass : TComponentClass; X,Y,W,H : Integer): TIComponentInterface; TypeClass : TComponentClass; X,Y,W,H : Integer): TIComponentInterface;
Var Var
Temp : TComponentInterface; Temp: TComponentInterface;
TempName : String; NewFormIndex: Integer;
Found : Boolean;
I, Num,NewFormIndex : Integer;
CompLeft, CompTop, CompWidth, CompHeight: integer; CompLeft, CompTop, CompWidth, CompHeight: integer;
DummyComponent:TComponent; OwnerComponent: TComponent;
ParentComponent: TComponent; ParentComponent: TComponent;
Begin Begin
writeln('[TCustomFormEditor.CreateComponent] Class='''+TypeClass.ClassName+''''); writeln('[TCustomFormEditor.CreateComponent] Class='''+TypeClass.ClassName+'''');
{$IFDEF IDE_MEM_CHECK}CheckHeap('TCustomFormEditor.CreateComponent A '+IntToStr(GetMem_Cnt));{$ENDIF} {$IFDEF IDE_MEM_CHECK}CheckHeap('TCustomFormEditor.CreateComponent A '+IntToStr(GetMem_Cnt));{$ENDIF}
Temp := TComponentInterface.Create; Temp := TComponentInterface.Create;
{$IFDEF IDE_MEM_CHECK}CheckHeap('TCustomFormEditor.CreateComponent B '+IntToStr(GetMem_Cnt));{$ENDIF}
if Assigned(ParentCI) then OwnerComponent:=nil;
if Assigned(ParentCI) and (ParentCI.IsTControl) then
begin begin
ParentComponent:=TComponentInterface(ParentCI).Component; ParentComponent:=TComponentInterface(ParentCI).Component;
if (not(ParentComponent is TCustomForm)) OwnerComponent:=GetParentForm(TControl(ParentComponent));
and Assigned(ParentComponent.Owner) if OwnerComponent=nil then
then OwnerComponent:=ParentComponent;
Temp.FComponent := TypeClass.Create(ParentComponent.Owner) Temp.FComponent := TypeClass.Create(OwnerComponent);
else
Temp.FComponent := TypeClass.Create(ParentComponent);
end else begin end else begin
//this should be a form //this should be a form
ParentComponent:=nil; ParentComponent:=nil;
{$IFDEF IDE_MEM_CHECK}CheckHeap('TCustomFormEditor.CreateComponent B2 '+IntToStr(GetMem_Cnt));{$ENDIF}
NewFormIndex := JITFormList.AddNewJITForm; NewFormIndex := JITFormList.AddNewJITForm;
{$IFDEF IDE_MEM_CHECK}CheckHeap('TCustomFormEditor.CreateComponent B3 '+IntToStr(GetMem_Cnt));{$ENDIF}
if NewFormIndex >= 0 then if NewFormIndex >= 0 then
Temp.FComponent := JITFormList[NewFormIndex] Temp.FComponent := JITFormList[NewFormIndex]
else begin else begin
@ -738,32 +737,8 @@ Begin
end; end;
{$IFDEF IDE_MEM_CHECK}CheckHeap('TCustomFormEditor.CreateComponent D '+IntToStr(GetMem_Cnt));{$ENDIF} {$IFDEF IDE_MEM_CHECK}CheckHeap('TCustomFormEditor.CreateComponent D '+IntToStr(GetMem_Cnt));{$ENDIF}
if ParentCI <> nil then Begin Temp.Component.Name := CreateUniqueComponentName(Temp.Component);
TempName := Temp.Component.ClassName;
delete(TempName,1,1);
{$IfNDef VER1_1}
//make it more presentable
TempName := TempName[1] + lowercase(Copy(TempName,2,length(tempname)));
{$EndIf}
Num := 0;
Found := True;
While Found do Begin
Found := False;
inc(num);
for I := 0 to Temp.Component.Owner.ComponentCount-1 do
begin
DummyComponent:=Temp.Component.Owner.Components[i];
if AnsiCompareText(DummyComponent.Name,TempName+IntToStr(Num))=0 then
begin
Found := True;
break;
end;
end;
end;
Temp.Component.Name := TempName+IntToStr(Num);
end;
{$IFDEF IDE_MEM_CHECK}CheckHeap('TCustomFormEditor.CreateComponent E '+IntToStr(GetMem_Cnt));{$ENDIF}
if (Temp.Component is TControl) then if (Temp.Component is TControl) then
Begin Begin
CompLeft:=X; CompLeft:=X;
@ -841,6 +816,42 @@ Begin
Result := nil; Result := nil;
end; end;
function TCustomFormEditor.CreateUniqueComponentName(AComponent: TComponent
): string;
begin
Result:='';
if (AComponent=nil) then exit;
Result:=AComponent.Name;
if (AComponent.Owner=nil) or (Result<>'') then exit;
Result:=CreateUniqueComponentName(AComponent.ClassName,AComponent.Owner);
end;
function TCustomFormEditor.CreateUniqueComponentName(const AClassName: string;
OwnerComponent: TComponent): string;
var
i, j: integer;
begin
Result:=AClassName;
if (OwnerComponent=nil) or (Result='') then exit;
i:=1;
while true do begin
j:=OwnerComponent.ComponentCount-1;
Result:=AClassName;
if (length(Result)>1) and (Result[1]='T') then
Result:=RightStr(Result,length(Result)-1);
{$IfNDef VER1_1}
//make it more presentable
Result := Result[1] + lowercase(Copy(Result,2,length(Result)));
{$EndIf}
Result:=Result+IntToStr(i);
while (j>=0)
and (AnsiCompareText(Result,OwnerComponent.Components[j].Name)<>0) do
dec(j);
if j<0 then exit;
inc(i);
end;
end;
Procedure TCustomFormEditor.ClearSelected; Procedure TCustomFormEditor.ClearSelected;
Begin Begin
FSelectedComponents.Clear; FSelectedComponents.Clear;
@ -873,9 +884,17 @@ procedure TCustomFormEditor.SetObj_Inspector(
AnObjectInspector: TObjectInspector); AnObjectInspector: TObjectInspector);
begin begin
if AnObjectInspector=FObj_Inspector then exit; if AnObjectInspector=FObj_Inspector then exit;
if FObj_Inspector<>nil then FObj_Inspector.OnModified:=nil; if FObj_Inspector<>nil then begin
FObj_Inspector.OnModified:=nil;
end;
FObj_Inspector:=AnObjectInspector; FObj_Inspector:=AnObjectInspector;
FObj_Inspector.OnModified:=@OnObjectInspectorModified;
if FObj_Inspector<>nil then begin
FObj_Inspector.OnModified:=@OnObjectInspectorModified;
end;
end; end;
end. end.

View File

@ -330,14 +330,17 @@ type
end; end;
TProcedure = procedure; TProcedure = procedure;
function KeysToShiftState(Keys:Word): TShiftState; function KeysToShiftState(Keys:Word): TShiftState;
function KeyDataToShiftState(KeyData: Longint): TShiftState; function KeyDataToShiftState(KeyData: Longint): TShiftState;
function GetParentForm(Control:TControl): TCustomForm; function GetParentForm(Control:TControl): TCustomForm;
function FindDesigner(AComponent: TComponent): TIDesigner;
function IsAccel(VK : Word; const Str : ShortString): Boolean; function IsAccel(VK : Word; const Str : ShortString): Boolean;
function InitResourceComponent(Instance: TComponent; RootAncestor: TClass):Boolean; function InitResourceComponent(Instance: TComponent; RootAncestor: TClass):Boolean;
@ -392,7 +395,7 @@ end;
function GetParentForm(Control:TControl): TCustomForm; function GetParentForm(Control:TControl): TCustomForm;
begin begin
while Control.parent <> nil do while Control.Parent <> nil do
Control := Control.Parent; Control := Control.Parent;
if Control is TCustomForm if Control is TCustomForm
then Result := TCustomForm(Control) then Result := TCustomForm(Control)
@ -472,6 +475,28 @@ begin
end; end;
function FindDesigner(AComponent: TComponent): TIDesigner;
var
Form: TCustomForm;
begin
Result:=nil;
if AComponent=nil then exit;
while (AComponent<>nil) do begin
if (AComponent is TCustomForm) then begin
Form:=TCustomForm(AComponent);
if Form.Parent=nil then begin
Result:=Form.Designer;
exit;
end;
end;
if AComponent is TControl then begin
AComponent:=TControl(AComponent).Parent;
end else begin
exit;
end;
end;
end;
//============================================================================== //==============================================================================

View File

@ -73,25 +73,69 @@ begin
Msg.fCompStyle := fNotebook.fCompStyle; Msg.fCompStyle := fNotebook.fCompStyle;
Msg.Str := S; Msg.Str := S;
{$IFDEF NOTEBOOK_DEBUG} {$IFDEF NOTEBOOK_DEBUG}
writeln('[TNBPages.Put] A ',Index,' ',S); writeln('[TNBPages.Put] A ',fNoteBook.Name,' ',Index,' ',S);
{$ENDIF} {$ENDIF}
CNSendMessage(LM_SetLabel, fNotebook, @Msg); CNSendMessage(LM_SetLabel, fNotebook, @Msg);
{$IFDEF NOTEBOOK_DEBUG} {$IFDEF NOTEBOOK_DEBUG}
writeln('[TNBPages.Put] B '); writeln('[TNBPages.Put] B ',fNoteBook.Name);
{$ENDIF} {$ENDIF}
end; end;
end; end;
procedure TNBPages.RemovePage(Index: integer);
var
Msg: TLMNotebookEvent;
NewPageIndex: integer;
begin
// Make sure Index is in the range of valid pages to delete
{$IFDEF NOTEBOOK_DEBUG}
writeln('TNBPages.RemovePage A ',fNoteBook.Name,' Index=',Index,
' fPageList.Count=',fPageList.Count,' fNoteBook.PageIndex=',fNoteBook.PageIndex);
{$ENDIF}
if (Index >= 0) and
(Index < fPageList.Count) then
begin
if not (csLoading in fNoteBook.ComponentState) then begin
// If that page is showing, then show the next page before deleting it
NewPageIndex:=fNoteBook.PageIndex;
if (Index = fNoteBook.PageIndex) then begin
if NewPageIndex<fPageList.Count-1 then
// switch current page to next (right) page
inc(NewPageIndex)
else if fPageList.Count>0 then
// switch to previous (left) page
dec(NewPageIndex)
else
// deleting last page
NewPageIndex:=-1;
end;
fNoteBook.PageIndex:=NewPageIndex;
end;
if (FNoteBook.HandleAllocated) and (TPage(fPageList[Index]).HandleAllocated)
then begin
Msg.Parent := fNotebook;
Msg.fCompStyle := fNotebook.fCompStyle;
Msg.Page := Index;
CNSendMessage(LM_REMOVEPAGE, fNotebook, @Msg);
end;
fPageList.Delete(Index);
if not (csLoading in fNoteBook.ComponentState) then begin
if NewPageIndex>=Index then
fNoteBook.PageIndex:=NewPageIndex-1;
end;
end;
{$IFDEF NOTEBOOK_DEBUG}
writeln('TNBPages.RemovePage END ',fNoteBook.Name,' Index=',Index,' fPageList.Count=',fPageList.Count,' fNoteBook.PageIndex=',fNoteBook.PageIndex);
{$ENDIF}
end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
TNBPages Clear TNBPages Clear
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
procedure TNBPages.Clear; procedure TNBPages.Clear;
var
i: Integer;
begin begin
for i := 0 to fPageList.Count - 1 do while fPageList.Count>0 do
TPage(fPageList[I]).Free; Delete(fPageList.Count-1);
fPageList.Clear;
end; end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
@ -99,65 +143,53 @@ end;
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
procedure TNBPages.Delete(Index: Integer); procedure TNBPages.Delete(Index: Integer);
var var
Msg: TLMNotebookEvent; APage: TPage;
NewPageIndex: integer;
begin begin
// Make sure Index is in the range of valid pages to delete // Make sure Index is in the range of valid pages to delete
{$IFDEF NOTEBOOK_DEBUG} {$IFDEF NOTEBOOK_DEBUG}
//writeln('TNBPages.Delete A Index=',Index); //writeln('TNBPages.Delete A Index=',Index);
writeln('TNBPages.Delete B Index=',Index,' fPageList.Count=',fPageList.Count,' fNoteBook.PageIndex=',fNoteBook.PageIndex); writeln('TNBPages.Delete B ',fNoteBook.Name,' Index=',Index,' fPageList.Count=',fPageList.Count,' fNoteBook.PageIndex=',fNoteBook.PageIndex);
{$ENDIF} {$ENDIF}
if (Index >= 0) and if (Index >= 0) and
(Index < fPageList.Count) then (Index < fPageList.Count) then
begin begin
// If that page is showing, then show the next page before deleting it APage:=TPage(fPageList[Index]);
NewPageIndex:=fNoteBook.PageIndex; RemovePage(Index);
if (Index = fNoteBook.PageIndex) then begin APage.Free;
if NewPageIndex<fPageList.Count-1 then
// switch current page to next (right) page
inc(NewPageIndex)
else if fPageList.Count>0 then
// switch to previous (left) page
dec(NewPageIndex)
else
// deleting last page
NewPageIndex:=-1;
end;
fNoteBook.PageIndex:=NewPageIndex;
if (FNoteBook.HandleAllocated)
and (not (csLoading in FNoteBook.ComponentState)) then begin
Msg.Parent := fNotebook;
Msg.fCompStyle := fNotebook.fCompStyle;
Msg.Page := Index;
CNSendMessage(LM_REMOVEPAGE, fNotebook, @Msg);
end;
TPage(fPageList[Index]).Free;
fPageList.Delete(Index);
if NewPageIndex>=Index then
fNoteBook.PageIndex:=NewPageIndex-1;
end; end;
{$IFDEF NOTEBOOK_DEBUG} {$IFDEF NOTEBOOK_DEBUG}
writeln('TNBPages.Delete END Index=',Index,' fPageList.Count=',fPageList.Count,' fNoteBook.PageIndex=',fNoteBook.PageIndex); writeln('TNBPages.Delete END ',fNoteBook.Name,' Index=',Index,' fPageList.Count=',fPageList.Count,' fNoteBook.PageIndex=',fNoteBook.PageIndex);
{$ENDIF} {$ENDIF}
end; end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
TNBPages Insert TNBPages Insert
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
procedure TNBPages.Insert(Index: Integer; const S: String); procedure TNBPages.Insert(Index: Integer; const S: String);
var var
tmpPage: TPage; tmpPage: TPage;
NewOwner: TComponent;
begin begin
tmpPage := TPage.Create(fNotebook); {$IFDEF NOTEBOOK_DEBUG}
writeln('TNBPages.Insert A ',fNoteBook.Name,' Index=',Index,' S="',S,'"');
{$ENDIF}
NewOwner:=fNotebook.Owner;
if NewOwner=nil then
NewOwner:=fNotebook;
tmpPage := TPage.Create(fNotebook.Owner);
with tmpPage do with tmpPage do
begin begin
Parent := fNotebook;
Caption := S; Caption := S;
Visible := true; Visible := true;
end; end;
{$IFDEF NOTEBOOK_DEBUG}
writeln('TNBPages.Insert B ',fNoteBook.Name,' Index=',Index,' S="',S,'"');
{$ENDIF}
InsertPage(Index,tmpPage); InsertPage(Index,tmpPage);
{$IFDEF NOTEBOOK_DEBUG}
writeln('TNBPages.Insert END ',fNoteBook.Name,' Index=',Index,' S="',S,'"');
{$ENDIF}
end; end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
@ -166,8 +198,22 @@ end;
procedure TNBPages.InsertPage(Index:integer; APage: TPage); procedure TNBPages.InsertPage(Index:integer; APage: TPage);
var var
Msg: TLMNotebookEvent; Msg: TLMNotebookEvent;
NewZPosition: integer;
begin begin
{$IFDEF NOTEBOOK_DEBUG}
writeln('TNBPages.InsertPage A ',fNoteBook.Name,' Index=',Index,' Name=',APage.Name,' Caption=',APage.Caption);
{$ENDIF}
if Index<fPageList.Count then
NewZPosition:=fNoteBook.GetControlIndex(TPage(fPageList[Index]))
else
NewZPosition:=-1;
fPageList.Insert(Index,APage); fPageList.Insert(Index,APage);
APage.Parent := fNotebook;
if NewZPosition>=0 then
fNoteBook.SetControlIndex(APage,NewZPosition);
// this is workaround til visible=true is default in TControl
APage.Visible:=true;
if FNoteBook.HandleAllocated if FNoteBook.HandleAllocated
and (not (csLoading in FNoteBook.ComponentState)) and (not (csLoading in FNoteBook.ComponentState))
@ -178,26 +224,66 @@ begin
Msg.Page := Index; Msg.Page := Index;
CNSendMessage(LM_ADDPAGE, fNotebook, @Msg); CNSendMessage(LM_ADDPAGE, fNotebook, @Msg);
if fNoteBook.PageIndex = Index then
fNoteBook.PageIndex := Index; fNoteBook.DoSendPageIndex
else
fNoteBook.PageIndex := Index;
end; end;
{$IFDEF NOTEBOOK_DEBUG}
writeln('TNBPages.InsertPage END ',fNoteBook.Name,' Index=',Index,' Name=',APage.Name,' Caption=',APage.Caption);
{$ENDIF}
end; end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
TNBPages Move TNBPages Move
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
procedure TNBPages.Move(CurIndex, NewIndex: Integer); procedure TNBPages.Move(CurIndex, NewIndex: Integer);
// ToDo var
//var APage: TPage;
// theObject: TObject; Msg: TLMNotebookEvent;
NewControlIndex, NewPageIndex: integer;
begin begin
// move TPage components if CurIndex=NewIndex then exit;
//fPageList.Move(CurIndex, NewIndex);
//theObject := fPageList[CurIndex]; APage:=TPage(fPageList[CurIndex]);
//fPageList[CurIndex] := fPageList[NewIndex];
//fPageList[NewIndex] := theObject; // calculate new control index (i.e. ZOrderPosition)
//MoveThePage(CurIndex, NewIndex); if NewIndex>=fPageList.Count-1 then
{ Still need to implement } NewControlIndex:=fNoteBook.ControlCount-1
else
NewControlIndex:=fNoteBook.GetControlIndex(TPage(fPageList[NewIndex]));
// calculate new PageIndex
if fNoteBook.PageIndex=CurIndex then
NewPageIndex:=NewIndex
else if fNoteBook.PageIndex>CurIndex then begin
if fNoteBook.PageIndex<=NewIndex then
NewPageIndex:=fNoteBook.PageIndex-1;
end else begin
if fNoteBook.PageIndex>=NewIndex then
NewPageIndex:=fNoteBook.PageIndex+1;
end;
// move Page in fPageList
fPageList.Move(CurIndex, NewIndex);
// move in wincontrol list
fNoteBook.SetControlIndex(APage,NewControlIndex);
// move Page in notebook handle
if FNoteBook.HandleAllocated
and (not (csLoading in FNoteBook.ComponentState))
then begin
Msg.Parent := TControl(fNotebook);
Msg.Child := APage;
Msg.fCompStyle := fNotebook.fCompStyle;
Msg.Page := NewIndex;
CNSendMessage(LM_MOVEPAGE, fNotebook, @Msg);
end;
// update PageIndex
fNoteBook.PageIndex:=NewPageIndex;
end; end;
@ -230,23 +316,30 @@ end;
Creates the interface object. Creates the interface object.
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
procedure TCustomNotebook.CreateWnd; procedure TCustomNotebook.CreateWnd;
var
n: Integer;
Msg: TLMNotebookEvent;
begin begin
inherited CreateWnd; inherited CreateWnd;
DoCreateWnd;
end;
Assert(False, 'Trace:[TCustomNotebook.CreateWnd] add pages'); {------------------------------------------------------------------------------
for n := 0 to FPageList.Count -1 do begin procedure TCustomNotebook.DoCreateWnd;
// this is workaround til visible=true is default in TControl
TControl(FPageList[n]).Visible:=true; Creates the handles for the pages and updates the notebook handle.
------------------------------------------------------------------------------}
procedure TCustomNotebook.DoCreateWnd;
var
i: Integer;
Msg: TLMNotebookEvent;
begin
fAddingPages:=true;
for i := 0 to FPageList.Count -1 do begin
Msg.Parent := Self; Msg.Parent := Self;
Msg.Child := TControl(FPageList[n]); Msg.Child := TControl(FPageList[i]);
Msg.fCompStyle := FCompStyle; Msg.fCompStyle := FCompStyle;
Msg.Page := n; Msg.Page := i;
CNSendMessage(LM_ADDPAGE, Self, @Msg); CNSendMessage(LM_ADDPAGE, Self, @Msg);
end; end;
fAddingPages:=false;
DoSendShowTabs; DoSendShowTabs;
DoSendTabPosition; DoSendTabPosition;
@ -340,21 +433,17 @@ end;
TCustomNotebook GetPageIndex TCustomNotebook GetPageIndex
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
function TCustomNotebook.GetPageIndex: Integer; function TCustomNotebook.GetPageIndex: Integer;
//var
// Msg: TLMNotebookEvent;
begin begin
//we don't have to query the contol. FPageindex should track this along with the pagechanged handler. //we don't have to query the control.
{ if HandleAllocated // FPageindex should track this along with the pagechanged handler.
then begin
Msg.Parent := Self;
Msg.fCompStyle := fCompStyle;
CNSendMessage(LM_GETITEMINDEX, Self, @Msg);
fPageIndex := Msg.Page;
end;}
Result := fPageIndex; Result := fPageIndex;
end; end;
function TCustomNotebook.IsStoredActivePage: boolean;
begin
Result:=false;
end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
TCustomNotebook GetPageCount TCustomNotebook GetPageCount
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
@ -409,25 +498,6 @@ begin
inherited CreateParams(Params); inherited CreateParams(Params);
end; end;
{------------------------------------------------------------------------------
TCustomNotebook GetChildOwner
------------------------------------------------------------------------------}
function TCustomNotebook.GetChildOwner: TComponent;
begin
Result := Self;
end;
{------------------------------------------------------------------------------
TCustomNotebook GetChildren
------------------------------------------------------------------------------}
procedure TCustomNotebook.GetChildren(Proc: TGetChildProc; Root: TComponent);
var
i: LongInt;
begin
for i := 0 to fPageList.Count - 1 do
Proc(TControl(fPageList[i]));
end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
TCustomNotebook ReadState TCustomNotebook ReadState
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
@ -479,6 +549,12 @@ Begin
if Assigned(fOnPageChanged) then fOnPageChanged(self); if Assigned(fOnPageChanged) then fOnPageChanged(self);
end; end;
procedure TCustomNotebook.Loaded;
begin
inherited Loaded;
if HandleAllocated then DoCreateWnd;
end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
TCustomNotebook CNNotify TCustomNotebook CNNotify
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
@ -489,10 +565,13 @@ Begin
TCN_SELCHANGE: TCN_SELCHANGE:
Begin Begin
//set the page from the NMHDR^.idfrom //set the page from the NMHDR^.idfrom
FPageIndex := NMHDR^.idfrom; if (not (csLoading in ComponentState))
if FPageIndex>=PageCount then and (not fAddingPages) then begin
FPageIndex:=-1; FPageIndex := NMHDR^.idfrom;
Change; if FPageIndex>=PageCount then
FPageIndex:=-1;
Change;
end;
end; end;
else else
begin begin
@ -513,13 +592,14 @@ begin
if not HandleAllocated or (csLoading in ComponentState) then exit; if not HandleAllocated or (csLoading in ComponentState) then exit;
Msg.Parent := Self; Msg.Parent := Self;
Msg.fCompStyle := fCompStyle; Msg.fCompStyle := fCompStyle;
if (FPageIndex<0) and (PageCount>0) then fPageIndex:=0;
Msg.Page := FPageIndex; Msg.Page := FPageIndex;
{$IFDEF NOTEBOOK_DEBUG} {$IFDEF NOTEBOOK_DEBUG}
writeln('[TCustomNotebook.SetPageIndex] A'); writeln('[TCustomNotebook.DoSendPageIndex] A ',Name,' PageIndex=',fPageIndex);
{$ENDIF} {$ENDIF}
CNSendMessage(LM_SETITEMINDEX, Self, @Msg); CNSendMessage(LM_SETITEMINDEX, Self, @Msg);
{$IFDEF NOTEBOOK_DEBUG} {$IFDEF NOTEBOOK_DEBUG}
writeln('[TCustomNotebook.SetPageIndex] B'); writeln('[TCustomNotebook.DoSendPageIndex] B');
{$ENDIF} {$ENDIF}
end; end;
@ -535,11 +615,11 @@ begin
Msg.fCompStyle := fCompStyle; Msg.fCompStyle := fCompStyle;
Msg.ShowTabs := fShowTabs; Msg.ShowTabs := fShowTabs;
{$IFDEF NOTEBOOK_DEBUG} {$IFDEF NOTEBOOK_DEBUG}
writeln('[TCustomNotebook.SetShowTabs] A'); writeln('[TCustomNotebook.DoSendShowTabs] A ',Name);
{$ENDIF} {$ENDIF}
CNSendMessage(LM_SHOWTABS, Self, @Msg); CNSendMessage(LM_SHOWTABS, Self, @Msg);
{$IFDEF NOTEBOOK_DEBUG} {$IFDEF NOTEBOOK_DEBUG}
writeln('[TCustomNotebook.SetShowTabs] B'); writeln('[TCustomNotebook.DoSendShowTabs] B ',Name);
{$ENDIF} {$ENDIF}
end; end;
@ -554,7 +634,6 @@ begin
Msg.Parent := Self; Msg.Parent := Self;
Msg.fCompStyle := fCompStyle; Msg.fCompStyle := fCompStyle;
Msg.TabPosition := @fTabPosition; Msg.TabPosition := @fTabPosition;
//InterfaceObject.IntCNSendMessage2(LM_SETTABPOSITION, Self, nil, @fTabPosition);
CNSendMessage(LM_SetTabPosition, Self, @Msg); CNSendMessage(LM_SetTabPosition, Self, @Msg);
end; end;
@ -586,6 +665,9 @@ end;}
{ ============================================================================= { =============================================================================
$Log$ $Log$
Revision 1.21 2002/09/05 12:11:43 lazarus
MG: TNotebook is now streamable
Revision 1.20 2002/09/02 20:05:44 lazarus Revision 1.20 2002/09/02 20:05:44 lazarus
MG: fixed GetActivePage MG: fixed GetActivePage