mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-13 12:19:16 +02:00
MG: TNotebook is now streamable
git-svn-id: trunk@3284 -
This commit is contained in:
parent
054b715d8d
commit
7c8d67a7ad
@ -44,34 +44,34 @@ or use TPropertyType
|
||||
// ptClass, ptMethod,ptWChar, ptLString, LWString, ptVariant);
|
||||
|
||||
TIComponentInterface = class
|
||||
public
|
||||
Function GetComponentType : String; virtual; abstract;
|
||||
Function GetComponentHandle : LongInt; virtual; abstract;
|
||||
Function GetParent : TIComponentInterface; virtual; abstract;
|
||||
Function IsTControl : Boolean; virtual; abstract;
|
||||
Function GetPropCount : Integer; virtual; abstract;
|
||||
Function GetPropType(Index : Integer) : TTypeKind; virtual; abstract;
|
||||
public
|
||||
Function GetComponentType : String; virtual; abstract;
|
||||
Function GetComponentHandle : LongInt; virtual; abstract;
|
||||
Function GetParent : TIComponentInterface; virtual; abstract;
|
||||
Function IsTControl : Boolean; virtual; abstract;
|
||||
Function GetPropCount : Integer; virtual; abstract;
|
||||
Function GetPropType(Index : Integer) : TTypeKind; virtual; abstract;
|
||||
// Function GetPropType(Index : Integer) : TPropertyType; virtual; abstract;
|
||||
Function GetPropName(Index : Integer) : String; virtual; abstract;
|
||||
Function GetPropTypebyName(Name : String) : TTypeKind; virtual; abstract;
|
||||
Function GetPropName(Index : Integer) : String; virtual; abstract;
|
||||
Function GetPropTypebyName(Name : String) : TTypeKind; 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 GetPropValuebyName(Name: String; var Value) : Boolean; virtual; abstract;
|
||||
Function SetProp(Index : Integer; const Value) : Boolean; virtual; abstract;
|
||||
Function SetPropbyName(Name : String; const Value) : Boolean; virtual; abstract;
|
||||
Function GetPropValue(Index : Integer; var Value) : Boolean; virtual; abstract;
|
||||
Function GetPropValuebyName(Name: String; var Value) : Boolean; virtual; abstract;
|
||||
Function SetProp(Index : Integer; const Value) : Boolean; virtual; abstract;
|
||||
Function SetPropbyName(Name : String; const Value) : Boolean; virtual; abstract;
|
||||
|
||||
Function GetControlCount: Integer; virtual; abstract;
|
||||
Function GetControl(Index : Integer): TIComponentInterface; virtual; abstract;
|
||||
Function GetControlCount: Integer; virtual; abstract;
|
||||
Function GetControl(Index : Integer): TIComponentInterface; virtual; abstract;
|
||||
|
||||
Function GetComponentCount: Integer; virtual; abstract;
|
||||
Function GetComponent(Index : Integer): TIComponentInterface; virtual; abstract;
|
||||
Function GetComponentCount: Integer; virtual; abstract;
|
||||
Function GetComponent(Index : Integer): TIComponentInterface; virtual; abstract;
|
||||
|
||||
Function Select : Boolean; virtual; abstract;
|
||||
Function Focus : Boolean; virtual; abstract;
|
||||
Function Delete : Boolean; virtual; abstract;
|
||||
Function Select : Boolean; virtual; abstract;
|
||||
Function Focus : Boolean; virtual; abstract;
|
||||
Function Delete : Boolean; virtual; abstract;
|
||||
end;
|
||||
|
||||
|
||||
|
@ -37,6 +37,7 @@ type
|
||||
protected
|
||||
function GetPropertyEditorHook: TPropertyEditorHook; virtual; abstract;
|
||||
public
|
||||
function CreateUniqueComponentName(const AClassName: string): string; virtual; abstract;
|
||||
property PropertyEditorHook: TPropertyEditorHook read GetPropertyEditorHook;
|
||||
end;
|
||||
|
||||
@ -132,6 +133,7 @@ type
|
||||
function IsInInlined: Boolean; virtual; abstract;
|
||||
function GetComponent: TComponent; virtual; abstract;
|
||||
function GetDesigner: TComponentEditorDesigner; virtual; abstract;
|
||||
function GetHook(var Hook: TPropertyEditorHook): boolean; virtual; abstract;
|
||||
end;
|
||||
|
||||
TComponentEditorClass = class of TBaseComponentEditor;
|
||||
@ -161,6 +163,7 @@ type
|
||||
procedure PrepareItem(Index: Integer; const AnItem: TMenuItem); override;
|
||||
property Component: TComponent read FComponent;
|
||||
property Designer: TComponentEditorDesigner read GetDesigner;
|
||||
function GetHook(var Hook: TPropertyEditorHook): boolean; override;
|
||||
end;
|
||||
|
||||
|
||||
@ -182,14 +185,16 @@ type
|
||||
end;
|
||||
|
||||
{ TNotebookComponentEditor
|
||||
The default component editor for TNotebook. It adds the following menu items
|
||||
to the popupmenu of the designer:
|
||||
ToDo:
|
||||
'Insert page', 'Delete page', 'Move page left', 'Move page right',
|
||||
'Select all pages'}
|
||||
The default component editor for TNotebook. }
|
||||
TNotebookComponentEditor = class(TDefaultComponentEditor)
|
||||
protected
|
||||
procedure AddNewPageToDesigner(Index: integer); virtual;
|
||||
procedure DoAddPage; virtual;
|
||||
procedure DoInsertPage; virtual;
|
||||
procedure DoDeletePage; virtual;
|
||||
procedure DoMoveActivePageLeft; virtual;
|
||||
procedure DoMoveActivePageRight; virtual;
|
||||
procedure DoMoveActivePage(CurIndex, NewIndex: Integer); virtual;
|
||||
public
|
||||
procedure ExecuteVerb(Index: Integer); override;
|
||||
function GetVerb(Index: Integer): string; override;
|
||||
@ -459,6 +464,14 @@ begin
|
||||
// Intended for descendents to implement
|
||||
end;
|
||||
|
||||
function TComponentEditor.GetHook(var Hook: TPropertyEditorHook): boolean;
|
||||
begin
|
||||
Result:=false;
|
||||
if GetDesigner=nil then exit;
|
||||
Hook:=GetDesigner.PropertyEditorHook;
|
||||
Result:=Hook<>nil;
|
||||
end;
|
||||
|
||||
{ TDefaultComponentEditor }
|
||||
|
||||
procedure TDefaultComponentEditor.CheckEdit(Prop: TPropertyEditor);
|
||||
@ -501,8 +514,8 @@ var
|
||||
Components: TComponentSelectionList;
|
||||
PropertyEditorHook: TPropertyEditorHook;
|
||||
begin
|
||||
PropertyEditorHook:=Designer.PropertyEditorHook;
|
||||
if PropertyEditorHook=nil then exit;
|
||||
PropertyEditorHook:=nil;
|
||||
if not GetHook(PropertyEditorHook) then exit;
|
||||
Components := TComponentSelectionList.Create;
|
||||
FContinue := True;
|
||||
Components.Add(Component);
|
||||
@ -519,6 +532,7 @@ begin
|
||||
finally
|
||||
FFirst := nil;
|
||||
FBest := nil;
|
||||
Components.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
@ -526,29 +540,109 @@ end;
|
||||
{ TNotebookComponentEditor }
|
||||
|
||||
const
|
||||
nbvInsertPage = 0;
|
||||
nbvDeletePage = 1;
|
||||
nbvMovePageLeft = 2;
|
||||
nbvMovePageRight = 3;
|
||||
nbvAddPage = 0;
|
||||
nbvInsertPage = 1;
|
||||
nbvDeletePage = 2;
|
||||
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;
|
||||
var
|
||||
Hook: TPropertyEditorHook;
|
||||
NewIndex: integer;
|
||||
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;
|
||||
|
||||
procedure TNotebookComponentEditor.ExecuteVerb(Index: Integer);
|
||||
begin
|
||||
case Index of
|
||||
nbvAddPage: DoAddPage;
|
||||
nbvInsertPage: DoInsertPage;
|
||||
nbvDeletePage: ;
|
||||
nbvMovePageLeft: ;
|
||||
nbvMovePageRight: ;
|
||||
nbvDeletePage: DoDeletePage;
|
||||
nbvMovePageLeft: DoMoveActivePageLeft;
|
||||
nbvMovePageRight: DoMoveActivePageRight;
|
||||
end;
|
||||
end;
|
||||
|
||||
function TNotebookComponentEditor.GetVerb(Index: Integer): string;
|
||||
begin
|
||||
case Index of
|
||||
nbvAddPage: Result:='Add page';
|
||||
nbvInsertPage: Result:='Insert page';
|
||||
nbvDeletePage: Result:='Delete page';
|
||||
nbvMovePageLeft: Result:='Move page left';
|
||||
@ -560,7 +654,7 @@ end;
|
||||
|
||||
function TNotebookComponentEditor.GetVerbCount: Integer;
|
||||
begin
|
||||
Result:=4;
|
||||
Result:=5;
|
||||
end;
|
||||
|
||||
procedure TNotebookComponentEditor.PrepareItem(Index: Integer;
|
||||
@ -568,7 +662,8 @@ procedure TNotebookComponentEditor.PrepareItem(Index: Integer;
|
||||
begin
|
||||
inherited PrepareItem(Index, AnItem);
|
||||
case Index of
|
||||
nbvInsertPage: ;
|
||||
nbvAddPage: ;
|
||||
nbvInsertPage: AnItem.Enabled:=Notebook.PageIndex>=0;
|
||||
nbvDeletePage: AnItem.Enabled:=Notebook.PageIndex>=0;
|
||||
nbvMovePageLeft: AnItem.Enabled:=Notebook.PageIndex>0;
|
||||
nbvMovePageRight: AnItem.Enabled:=Notebook.PageIndex<Notebook.PageCount-1;
|
||||
|
@ -79,7 +79,9 @@ function GetParentFormRelativeTopLeft(Component: TComponent): TPoint;
|
||||
function GetParentFormRelativeBounds(Component: TComponent): TRect;
|
||||
function GetParentFormRelativeClientOrigin(Component: TComponent): TPoint;
|
||||
function GetParentFormRelativeParentClientOrigin(Component: TComponent): TPoint;
|
||||
|
||||
function GetFormRelativeMousePosition(Form: TCustomForm): TPoint;
|
||||
|
||||
function ComponentIsTopLvl(AComponent: TComponent): boolean;
|
||||
procedure GetComponentBounds(AComponent: TComponent;
|
||||
var Left, Top, Width, Height: integer);
|
||||
@ -89,8 +91,10 @@ function GetComponentWidth(AComponent: TComponent): integer;
|
||||
function GetComponentHeight(AComponent: TComponent): integer;
|
||||
|
||||
|
||||
|
||||
implementation
|
||||
|
||||
|
||||
function GetParentFormRelativeTopLeft(Component: TComponent): TPoint;
|
||||
var
|
||||
FormOrigin: TPoint;
|
||||
|
@ -121,7 +121,7 @@ TCustomFormEditor
|
||||
Procedure RemoveFromComponentInterfaceList(Value :TIComponentInterface);
|
||||
procedure SetSelectedComponents(TheSelectedComponents : TComponentSelectionList);
|
||||
procedure OnObjectInspectorModified(Sender: TObject);
|
||||
procedure SetObj_Inspector(AnObjectInspector: TObjectInspector);
|
||||
procedure SetObj_Inspector(AnObjectInspector: TObjectInspector); virtual;
|
||||
public
|
||||
JITFormList : TJITForms;
|
||||
constructor Create;
|
||||
@ -132,8 +132,12 @@ TCustomFormEditor
|
||||
Function FormModified : Boolean; override;
|
||||
Function FindComponentByName(const Name : ShortString) : TIComponentInterface; override;
|
||||
Function FindComponent(AComponent: TComponent): TIComponentInterface; override;
|
||||
|
||||
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 CreateComponentInterface(AComponent: TComponent): TIComponentInterface;
|
||||
|
||||
@ -143,7 +147,7 @@ TCustomFormEditor
|
||||
Procedure SetFormNameAndClass(CI: TIComponentInterface;
|
||||
const NewFormName, NewClassName: shortstring);
|
||||
Procedure ClearSelected;
|
||||
property SelectedComponents : TComponentSelectionList
|
||||
property SelectedComponents: TComponentSelectionList
|
||||
read FSelectedComponents write SetSelectedComponents;
|
||||
property Obj_Inspector : TObjectInspector
|
||||
read FObj_Inspector write SetObj_Inspector;
|
||||
@ -684,33 +688,28 @@ end;
|
||||
Function TCustomFormEditor.CreateComponent(ParentCI : TIComponentInterface;
|
||||
TypeClass : TComponentClass; X,Y,W,H : Integer): TIComponentInterface;
|
||||
Var
|
||||
Temp : TComponentInterface;
|
||||
TempName : String;
|
||||
Found : Boolean;
|
||||
I, Num,NewFormIndex : Integer;
|
||||
Temp: TComponentInterface;
|
||||
NewFormIndex: Integer;
|
||||
CompLeft, CompTop, CompWidth, CompHeight: integer;
|
||||
DummyComponent:TComponent;
|
||||
OwnerComponent: TComponent;
|
||||
ParentComponent: TComponent;
|
||||
Begin
|
||||
writeln('[TCustomFormEditor.CreateComponent] Class='''+TypeClass.ClassName+'''');
|
||||
{$IFDEF IDE_MEM_CHECK}CheckHeap('TCustomFormEditor.CreateComponent A '+IntToStr(GetMem_Cnt));{$ENDIF}
|
||||
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
|
||||
ParentComponent:=TComponentInterface(ParentCI).Component;
|
||||
if (not(ParentComponent is TCustomForm))
|
||||
and Assigned(ParentComponent.Owner)
|
||||
then
|
||||
Temp.FComponent := TypeClass.Create(ParentComponent.Owner)
|
||||
else
|
||||
Temp.FComponent := TypeClass.Create(ParentComponent);
|
||||
OwnerComponent:=GetParentForm(TControl(ParentComponent));
|
||||
if OwnerComponent=nil then
|
||||
OwnerComponent:=ParentComponent;
|
||||
Temp.FComponent := TypeClass.Create(OwnerComponent);
|
||||
end else begin
|
||||
//this should be a form
|
||||
ParentComponent:=nil;
|
||||
{$IFDEF IDE_MEM_CHECK}CheckHeap('TCustomFormEditor.CreateComponent B2 '+IntToStr(GetMem_Cnt));{$ENDIF}
|
||||
NewFormIndex := JITFormList.AddNewJITForm;
|
||||
{$IFDEF IDE_MEM_CHECK}CheckHeap('TCustomFormEditor.CreateComponent B3 '+IntToStr(GetMem_Cnt));{$ENDIF}
|
||||
if NewFormIndex >= 0 then
|
||||
Temp.FComponent := JITFormList[NewFormIndex]
|
||||
else begin
|
||||
@ -738,32 +737,8 @@ Begin
|
||||
end;
|
||||
|
||||
{$IFDEF IDE_MEM_CHECK}CheckHeap('TCustomFormEditor.CreateComponent D '+IntToStr(GetMem_Cnt));{$ENDIF}
|
||||
if ParentCI <> nil then Begin
|
||||
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;
|
||||
Temp.Component.Name := CreateUniqueComponentName(Temp.Component);
|
||||
|
||||
{$IFDEF IDE_MEM_CHECK}CheckHeap('TCustomFormEditor.CreateComponent E '+IntToStr(GetMem_Cnt));{$ENDIF}
|
||||
if (Temp.Component is TControl) then
|
||||
Begin
|
||||
CompLeft:=X;
|
||||
@ -841,6 +816,42 @@ Begin
|
||||
Result := nil;
|
||||
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;
|
||||
Begin
|
||||
FSelectedComponents.Clear;
|
||||
@ -873,9 +884,17 @@ procedure TCustomFormEditor.SetObj_Inspector(
|
||||
AnObjectInspector: TObjectInspector);
|
||||
begin
|
||||
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.OnModified:=@OnObjectInspectorModified;
|
||||
|
||||
if FObj_Inspector<>nil then begin
|
||||
FObj_Inspector.OnModified:=@OnObjectInspectorModified;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
end.
|
||||
|
||||
|
29
lcl/forms.pp
29
lcl/forms.pp
@ -330,14 +330,17 @@ type
|
||||
end;
|
||||
|
||||
|
||||
|
||||
TProcedure = procedure;
|
||||
|
||||
|
||||
function KeysToShiftState(Keys:Word): TShiftState;
|
||||
function KeyDataToShiftState(KeyData: Longint): TShiftState;
|
||||
|
||||
function GetParentForm(Control:TControl): TCustomForm;
|
||||
function FindDesigner(AComponent: TComponent): TIDesigner;
|
||||
|
||||
function IsAccel(VK : Word; const Str : ShortString): Boolean;
|
||||
|
||||
function InitResourceComponent(Instance: TComponent; RootAncestor: TClass):Boolean;
|
||||
|
||||
|
||||
@ -392,7 +395,7 @@ end;
|
||||
|
||||
function GetParentForm(Control:TControl): TCustomForm;
|
||||
begin
|
||||
while Control.parent <> nil do
|
||||
while Control.Parent <> nil do
|
||||
Control := Control.Parent;
|
||||
if Control is TCustomForm
|
||||
then Result := TCustomForm(Control)
|
||||
@ -472,6 +475,28 @@ begin
|
||||
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;
|
||||
|
||||
//==============================================================================
|
||||
|
||||
|
||||
|
@ -73,25 +73,69 @@ begin
|
||||
Msg.fCompStyle := fNotebook.fCompStyle;
|
||||
Msg.Str := S;
|
||||
{$IFDEF NOTEBOOK_DEBUG}
|
||||
writeln('[TNBPages.Put] A ',Index,' ',S);
|
||||
writeln('[TNBPages.Put] A ',fNoteBook.Name,' ',Index,' ',S);
|
||||
{$ENDIF}
|
||||
CNSendMessage(LM_SetLabel, fNotebook, @Msg);
|
||||
{$IFDEF NOTEBOOK_DEBUG}
|
||||
writeln('[TNBPages.Put] B ');
|
||||
writeln('[TNBPages.Put] B ',fNoteBook.Name);
|
||||
{$ENDIF}
|
||||
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
|
||||
------------------------------------------------------------------------------}
|
||||
procedure TNBPages.Clear;
|
||||
var
|
||||
i: Integer;
|
||||
begin
|
||||
for i := 0 to fPageList.Count - 1 do
|
||||
TPage(fPageList[I]).Free;
|
||||
fPageList.Clear;
|
||||
while fPageList.Count>0 do
|
||||
Delete(fPageList.Count-1);
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
@ -99,65 +143,53 @@ end;
|
||||
------------------------------------------------------------------------------}
|
||||
procedure TNBPages.Delete(Index: Integer);
|
||||
var
|
||||
Msg: TLMNotebookEvent;
|
||||
NewPageIndex: integer;
|
||||
APage: TPage;
|
||||
begin
|
||||
// Make sure Index is in the range of valid pages to delete
|
||||
{$IFDEF NOTEBOOK_DEBUG}
|
||||
//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}
|
||||
if (Index >= 0) and
|
||||
(Index < fPageList.Count) 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;
|
||||
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;
|
||||
APage:=TPage(fPageList[Index]);
|
||||
RemovePage(Index);
|
||||
APage.Free;
|
||||
end;
|
||||
{$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}
|
||||
end;
|
||||
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
TNBPages Insert
|
||||
------------------------------------------------------------------------------}
|
||||
procedure TNBPages.Insert(Index: Integer; const S: String);
|
||||
var
|
||||
tmpPage: TPage;
|
||||
NewOwner: TComponent;
|
||||
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
|
||||
begin
|
||||
Parent := fNotebook;
|
||||
Caption := S;
|
||||
Visible := true;
|
||||
end;
|
||||
|
||||
{$IFDEF NOTEBOOK_DEBUG}
|
||||
writeln('TNBPages.Insert B ',fNoteBook.Name,' Index=',Index,' S="',S,'"');
|
||||
{$ENDIF}
|
||||
InsertPage(Index,tmpPage);
|
||||
{$IFDEF NOTEBOOK_DEBUG}
|
||||
writeln('TNBPages.Insert END ',fNoteBook.Name,' Index=',Index,' S="',S,'"');
|
||||
{$ENDIF}
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
@ -166,8 +198,22 @@ end;
|
||||
procedure TNBPages.InsertPage(Index:integer; APage: TPage);
|
||||
var
|
||||
Msg: TLMNotebookEvent;
|
||||
NewZPosition: integer;
|
||||
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);
|
||||
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
|
||||
and (not (csLoading in FNoteBook.ComponentState))
|
||||
@ -178,26 +224,66 @@ begin
|
||||
Msg.Page := Index;
|
||||
|
||||
CNSendMessage(LM_ADDPAGE, fNotebook, @Msg);
|
||||
|
||||
fNoteBook.PageIndex := Index;
|
||||
if fNoteBook.PageIndex = Index then
|
||||
fNoteBook.DoSendPageIndex
|
||||
else
|
||||
fNoteBook.PageIndex := Index;
|
||||
end;
|
||||
{$IFDEF NOTEBOOK_DEBUG}
|
||||
writeln('TNBPages.InsertPage END ',fNoteBook.Name,' Index=',Index,' Name=',APage.Name,' Caption=',APage.Caption);
|
||||
{$ENDIF}
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
TNBPages Move
|
||||
------------------------------------------------------------------------------}
|
||||
procedure TNBPages.Move(CurIndex, NewIndex: Integer);
|
||||
// ToDo
|
||||
//var
|
||||
// theObject: TObject;
|
||||
var
|
||||
APage: TPage;
|
||||
Msg: TLMNotebookEvent;
|
||||
NewControlIndex, NewPageIndex: integer;
|
||||
begin
|
||||
// move TPage components
|
||||
//fPageList.Move(CurIndex, NewIndex);
|
||||
//theObject := fPageList[CurIndex];
|
||||
//fPageList[CurIndex] := fPageList[NewIndex];
|
||||
//fPageList[NewIndex] := theObject;
|
||||
//MoveThePage(CurIndex, NewIndex);
|
||||
{ Still need to implement }
|
||||
if CurIndex=NewIndex then exit;
|
||||
|
||||
APage:=TPage(fPageList[CurIndex]);
|
||||
|
||||
// calculate new control index (i.e. ZOrderPosition)
|
||||
if NewIndex>=fPageList.Count-1 then
|
||||
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;
|
||||
|
||||
|
||||
@ -230,23 +316,30 @@ end;
|
||||
Creates the interface object.
|
||||
------------------------------------------------------------------------------}
|
||||
procedure TCustomNotebook.CreateWnd;
|
||||
var
|
||||
n: Integer;
|
||||
Msg: TLMNotebookEvent;
|
||||
begin
|
||||
inherited CreateWnd;
|
||||
DoCreateWnd;
|
||||
end;
|
||||
|
||||
Assert(False, 'Trace:[TCustomNotebook.CreateWnd] add pages');
|
||||
for n := 0 to FPageList.Count -1 do begin
|
||||
// this is workaround til visible=true is default in TControl
|
||||
TControl(FPageList[n]).Visible:=true;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
procedure TCustomNotebook.DoCreateWnd;
|
||||
|
||||
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.Child := TControl(FPageList[n]);
|
||||
Msg.Child := TControl(FPageList[i]);
|
||||
Msg.fCompStyle := FCompStyle;
|
||||
Msg.Page := n;
|
||||
Msg.Page := i;
|
||||
CNSendMessage(LM_ADDPAGE, Self, @Msg);
|
||||
end;
|
||||
fAddingPages:=false;
|
||||
|
||||
DoSendShowTabs;
|
||||
DoSendTabPosition;
|
||||
@ -340,21 +433,17 @@ end;
|
||||
TCustomNotebook GetPageIndex
|
||||
------------------------------------------------------------------------------}
|
||||
function TCustomNotebook.GetPageIndex: Integer;
|
||||
//var
|
||||
// Msg: TLMNotebookEvent;
|
||||
begin
|
||||
//we don't have to query the contol. FPageindex should track this along with the pagechanged handler.
|
||||
{ if HandleAllocated
|
||||
then begin
|
||||
Msg.Parent := Self;
|
||||
Msg.fCompStyle := fCompStyle;
|
||||
CNSendMessage(LM_GETITEMINDEX, Self, @Msg);
|
||||
fPageIndex := Msg.Page;
|
||||
end;}
|
||||
|
||||
//we don't have to query the control.
|
||||
// FPageindex should track this along with the pagechanged handler.
|
||||
Result := fPageIndex;
|
||||
end;
|
||||
|
||||
function TCustomNotebook.IsStoredActivePage: boolean;
|
||||
begin
|
||||
Result:=false;
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
TCustomNotebook GetPageCount
|
||||
------------------------------------------------------------------------------}
|
||||
@ -409,25 +498,6 @@ begin
|
||||
inherited CreateParams(Params);
|
||||
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
|
||||
------------------------------------------------------------------------------}
|
||||
@ -479,6 +549,12 @@ Begin
|
||||
if Assigned(fOnPageChanged) then fOnPageChanged(self);
|
||||
end;
|
||||
|
||||
procedure TCustomNotebook.Loaded;
|
||||
begin
|
||||
inherited Loaded;
|
||||
if HandleAllocated then DoCreateWnd;
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
TCustomNotebook CNNotify
|
||||
------------------------------------------------------------------------------}
|
||||
@ -489,10 +565,13 @@ Begin
|
||||
TCN_SELCHANGE:
|
||||
Begin
|
||||
//set the page from the NMHDR^.idfrom
|
||||
FPageIndex := NMHDR^.idfrom;
|
||||
if FPageIndex>=PageCount then
|
||||
FPageIndex:=-1;
|
||||
Change;
|
||||
if (not (csLoading in ComponentState))
|
||||
and (not fAddingPages) then begin
|
||||
FPageIndex := NMHDR^.idfrom;
|
||||
if FPageIndex>=PageCount then
|
||||
FPageIndex:=-1;
|
||||
Change;
|
||||
end;
|
||||
end;
|
||||
else
|
||||
begin
|
||||
@ -513,13 +592,14 @@ begin
|
||||
if not HandleAllocated or (csLoading in ComponentState) then exit;
|
||||
Msg.Parent := Self;
|
||||
Msg.fCompStyle := fCompStyle;
|
||||
if (FPageIndex<0) and (PageCount>0) then fPageIndex:=0;
|
||||
Msg.Page := FPageIndex;
|
||||
{$IFDEF NOTEBOOK_DEBUG}
|
||||
writeln('[TCustomNotebook.SetPageIndex] A');
|
||||
writeln('[TCustomNotebook.DoSendPageIndex] A ',Name,' PageIndex=',fPageIndex);
|
||||
{$ENDIF}
|
||||
CNSendMessage(LM_SETITEMINDEX, Self, @Msg);
|
||||
{$IFDEF NOTEBOOK_DEBUG}
|
||||
writeln('[TCustomNotebook.SetPageIndex] B');
|
||||
writeln('[TCustomNotebook.DoSendPageIndex] B');
|
||||
{$ENDIF}
|
||||
end;
|
||||
|
||||
@ -535,11 +615,11 @@ begin
|
||||
Msg.fCompStyle := fCompStyle;
|
||||
Msg.ShowTabs := fShowTabs;
|
||||
{$IFDEF NOTEBOOK_DEBUG}
|
||||
writeln('[TCustomNotebook.SetShowTabs] A');
|
||||
writeln('[TCustomNotebook.DoSendShowTabs] A ',Name);
|
||||
{$ENDIF}
|
||||
CNSendMessage(LM_SHOWTABS, Self, @Msg);
|
||||
{$IFDEF NOTEBOOK_DEBUG}
|
||||
writeln('[TCustomNotebook.SetShowTabs] B');
|
||||
writeln('[TCustomNotebook.DoSendShowTabs] B ',Name);
|
||||
{$ENDIF}
|
||||
end;
|
||||
|
||||
@ -554,7 +634,6 @@ begin
|
||||
Msg.Parent := Self;
|
||||
Msg.fCompStyle := fCompStyle;
|
||||
Msg.TabPosition := @fTabPosition;
|
||||
//InterfaceObject.IntCNSendMessage2(LM_SETTABPOSITION, Self, nil, @fTabPosition);
|
||||
CNSendMessage(LM_SetTabPosition, Self, @Msg);
|
||||
end;
|
||||
|
||||
@ -586,6 +665,9 @@ end;}
|
||||
{ =============================================================================
|
||||
|
||||
$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
|
||||
MG: fixed GetActivePage
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user