IDE: source editor: replaced TNoteBook with TPageControl

git-svn-id: trunk@27300 -
This commit is contained in:
mattias 2010-09-11 13:49:24 +00:00
parent 591f9e03b3
commit f87802b542
3 changed files with 71 additions and 70 deletions

View File

@ -1,6 +1,6 @@
{ DividerBevel
Copyright (C) 2010 <name of author> <contact>
Copyright (C) 2010 Lazarus team
This library is free software; you can redistribute it and/or modify it
under the same terms as the Lazarus Component Library (LCL)
@ -16,8 +16,8 @@ unit ExtendedNotebook;
interface
uses
Classes, sysutils, LResources, Forms, Controls, Graphics, Dialogs, ExtCtrls,
LCLIntf, LCLType, math;
Classes, sysutils, math, LCLIntf, LCLType, LResources, Forms, Controls,
Graphics, Dialogs, ExtCtrls, ComCtrls;
type
@ -32,7 +32,7 @@ type
{ TExtendedNotebook }
TExtendedNotebook = class(TNotebook)
TExtendedNotebook = class(TPageControl)
private
FDraggingTabIndex: Integer;
FOnTabDragDrop: TDragDropEvent;
@ -180,7 +180,7 @@ end;
procedure TExtendedNotebook.DragOver(Source: TObject; X, Y: Integer; State: TDragState;
var Accept: Boolean);
var
TabIndex: Integer;
TabId: Integer;
LastRect, LastNRect: TRect;
LastIndex: Integer;
LastRight, NeedInvalidate: Boolean;
@ -196,15 +196,15 @@ begin
end;
// Tab drag over
TabIndex := TabIndexForDrag(X,Y);
TabId := TabIndexForDrag(X,Y);
Accept := (FTabDragAcceptMode = dmAutomatic) and (Source = Self) and
(TabIndex >= 0) and (TabIndex <> FDraggingTabIndex);
(TabId >= 0) and (TabId <> FDraggingTabIndex);
if Assigned(FOnTabDragOver) then
FOnTabDragOver(Self,Source,X,Y,State,Accept);
if ((state = dsDragLeave) or (TabIndex < 0)) and
if ((state = dsDragLeave) or (TabId < 0)) and
(FDragOverIndex >= 0)
then begin
InvalidateRect(FDragOverTabRect);
@ -212,7 +212,7 @@ begin
FDragOverIndex := -1;
end;
if (TabIndex < 0) then
if (TabId < 0) then
exit;
Ctrl := (GetKeyState(VK_CONTROL) and $8000)<>0;
@ -225,12 +225,12 @@ begin
LastRight := FDragToRightSide;
LastRect := FDragOverTabRect;
LastNRect := FDragNextToTabRect;
FDragOverIndex := TabIndex;
FDragOverTabRect := TabRectEx(TabIndex, X, Y, FDragToRightSide);
FDragOverIndex := TabId;
FDragOverTabRect := TabRectEx(TabId, X, Y, FDragToRightSide);
if (Source = Self) and (TabIndex = FDraggingTabIndex - 1) then
if (Source = Self) and (TabId = FDraggingTabIndex - 1) then
FDragToRightSide := False;
if (Source = Self) and (TabIndex = FDraggingTabIndex + 1) then
if (Source = Self) and (TabId = FDraggingTabIndex + 1) then
FDragToRightSide := True;
NeedInvalidate := (FDragOverIndex <> LastIndex) or (FDragToRightSide <> LastRight);
@ -242,22 +242,22 @@ begin
end;
if FDragToRightSide then begin
inc(TabIndex);
if TabIndex < PageCount then
FDragNextToTabRect := TabRect(TabIndex);
inc(TabId);
if TabId < PageCount then
FDragNextToTabRect := TabRect(TabId);
end else begin
if TabIndex > 0 then
FDragNextToTabRect := TabRect(TabIndex - 1);
if TabId > 0 then
FDragNextToTabRect := TabRect(TabId - 1);
end;
if NeedInvalidate then
InvalidateRect(FDragNextToTabRect);
Src := TExtendedNotebook(Source);
if (Source = self) and (TabIndex > Src.DraggingTabIndex) then
dec(TabIndex);
if (Source = self) and (TabId > Src.DraggingTabIndex) then
dec(TabId);
if Assigned(FOnTabDragOverEx) then
FOnTabDragOverEx(Self, Source, Src.DraggingTabIndex, TabIndex, Ctrl, Accept);
FOnTabDragOverEx(Self, Source, Src.DraggingTabIndex, TabId, Ctrl, Accept);
if (not Accept) or (state = dsDragLeave) then begin
InvalidateRect(FDragOverTabRect);
@ -380,7 +380,7 @@ end;
procedure TExtendedNotebook.DragDrop(Source: TObject; X, Y: Integer);
var
TabIndex, TabIndex2: Integer;
TabId, TabId2: Integer;
ToRight: Boolean;
Ctrl: Boolean;
Src: TExtendedNotebook;
@ -404,34 +404,34 @@ begin
FDragOverIndex := -1;
DragCursor := crDrag;
TabIndex := TabIndexForDrag(X,Y);
TabRectEx(TabIndex, X, Y, ToRight);
TabId := TabIndexForDrag(X,Y);
TabRectEx(TabId, X, Y, ToRight);
if (Source = Self) and (TabIndex = FDraggingTabIndex - 1) then
if (Source = Self) and (TabId = FDraggingTabIndex - 1) then
ToRight := False;
if (Source = Self) and (TabIndex = FDraggingTabIndex + 1) then
if (Source = Self) and (TabId = FDraggingTabIndex + 1) then
ToRight := True;
if ToRight then
inc(TabIndex);
inc(TabId);
Src := TExtendedNotebook(Source);
TabIndex2 := TabIndex;
if (Source = self) and (TabIndex > Src.DraggingTabIndex) then
dec(TabIndex);
TabId2 := TabId;
if (Source = self) and (TabId > Src.DraggingTabIndex) then
dec(TabId);
if assigned(FOnTabDragDropEx) then begin
Ctrl := (GetKeyState(VK_CONTROL) and $8000)<>0;
Accept := True;
if Assigned(FOnTabDragOverEx) then
FOnTabDragOverEx(Self, Source, Src.DraggingTabIndex, TabIndex, Ctrl, Accept);
FOnTabDragOverEx(Self, Source, Src.DraggingTabIndex, TabId, Ctrl, Accept);
if Accept then
FOnTabDragDropEx(Self, Source, Src.DraggingTabIndex, TabIndex, Ctrl, FTabDragged);
FOnTabDragDropEx(Self, Source, Src.DraggingTabIndex, TabId, Ctrl, FTabDragged);
end;
if (not FTabDragged) and (FTabDragAcceptMode = dmAutomatic) and
(Source = Self) and (TabIndex2 >= 0) and (TabIndex2 <> FDraggingTabIndex)
(Source = Self) and (TabId2 >= 0) and (TabId2 <> FDraggingTabIndex)
then begin
Pages.Move(Src.DraggingTabIndex, TabIndex);
TCustomNotebook(Self).Pages.Move(Src.DraggingTabIndex, TabId);
FTabDragged := True;
end;
end;

View File

@ -2747,8 +2747,8 @@ var
PageIndex: integer;
NB: TSourceNotebook;
begin
if Sender is TPage then begin
NB := SourceEditorManager.SourceWindowWithPage(TPage(Sender));
if Sender is TTabSheet then begin
NB := SourceEditorManager.SourceWindowWithPage(TTabSheet(Sender));
if NB = nil then exit;
PageIndex := NB.NotebookPages.IndexOfObject(Sender);
end else begin
@ -2792,8 +2792,8 @@ var
begin
if InvertedClose then begin
// close all source editors except the clicked
if Sender is TPage then begin
ActiveSrcNoteBook := SourceEditorManager.SourceWindowWithPage(TPage(Sender));
if Sender is TTabSheet then begin
ActiveSrcNoteBook := SourceEditorManager.SourceWindowWithPage(TTabSheet(Sender));
if ActiveSrcNoteBook = nil then exit;
PageIndex := ActiveSrcNoteBook.NotebookPages.IndexOfObject(Sender);
end else begin

View File

@ -272,7 +272,7 @@ type
function GotoLine(Value: Integer): Integer;
procedure CreateEditor(AOwner: TComponent; AParent: TWinControl);
procedure UpdateNoteBook(const ANewNoteBook: TSourceNotebook; ANewPage: TPage);
procedure UpdateNoteBook(const ANewNoteBook: TSourceNotebook; ANewPage: TTabSheet);
procedure SetVisible(Value: boolean);
procedure UnbindEditor;
protected
@ -611,7 +611,7 @@ type
procedure BuildPopupMenu;
procedure AssignPopupMenu;
//forwarders to FNoteBook
function GetNoteBookPage(Index: Integer): TPage;
function GetNoteBookPage(Index: Integer): TTabSheet;
function GetNotebookPages: TStrings;
function GetPageCount: Integer;
function GetPageIndex: Integer;
@ -636,13 +636,13 @@ type
procedure UpdatePageNames;
procedure UpdateProjectFiles;
property NoteBookPage[Index: Integer]: TPage read GetNoteBookPage;
property NoteBookPage[Index: Integer]: TTabSheet read GetNoteBookPage;
procedure NoteBookInsertPage(Index: Integer; const S: string);
procedure NoteBookDeletePage(APageIndex: Integer);
procedure UpdateTabsAndPageTitle;
procedure UpdateTabsAndPageTimeReached(Sender: TObject);
protected
function NoteBookIndexOfPage(APage: TPage): Integer;
function NoteBookIndexOfPage(APage: TTabSheet): Integer;
procedure DragOver(Source: TObject; X, Y: Integer; State: TDragState;
var Accept: Boolean); override;
procedure DragCanceled; override;
@ -738,9 +738,9 @@ type
procedure ToggleObjectInspClicked(Sender: TObject);
// editor page history
procedure HistorySetMostRecent(APage: TPage);
procedure HistoryAdd(APage: TPage);
procedure HistoryRemove(APage: TPage);
procedure HistorySetMostRecent(APage: TTabSheet);
procedure HistoryAdd(APage: TTabSheet);
procedure HistoryRemove(APage: TTabSheet);
function HistoryGetTopPageIndex: Integer;
// incremental find
@ -932,7 +932,7 @@ type
var AForm: TCustomForm; DoDisableAutoSizing: boolean);
procedure GetDefaultLayout(Sender: TObject; aFormName: string;
out aBounds: TRect; out DockSibling: string; out DockAlign: TAlign);
function SourceWindowWithPage(const APage: TPage): TSourceNotebook;
function SourceWindowWithPage(const APage: TTabSheet): TSourceNotebook;
property SourceWindowByLastFocused[Index: Integer]: TSourceNotebook
read GetSourceNbByLastFocused;
// Editors
@ -2284,7 +2284,7 @@ end;
{ The constructor for @link(TSourceEditor).
AOwner is the @link(TSourceNotebook)
and the AParent is usually a page of a @link(TNotebook) }
and the AParent is usually a page of a @link(TPageControl) }
constructor TSourceEditor.Create(AOwner: TComponent; AParent: TWinControl;
ASharedEditor: TSourceEditor = nil);
var
@ -3843,7 +3843,7 @@ begin
end;
end;
procedure TSourceEditor.UpdateNoteBook(const ANewNoteBook: TSourceNotebook; ANewPage: TPage);
procedure TSourceEditor.UpdateNoteBook(const ANewNoteBook: TSourceNotebook; ANewPage: TTabSheet);
begin
if FSourceNoteBook = ANewNoteBook then exit;
@ -3859,7 +3859,7 @@ begin
end;
{ AOwner is the TSourceNotebook
AParent is a page of the TNotebook }
AParent is a page of the TPageControl }
Procedure TSourceEditor.CreateEditor(AOwner: TComponent; AParent: TWinControl);
var
NewName: string;
@ -4893,6 +4893,8 @@ begin
end;
Procedure TSourceNotebook.CreateNotebook;
var
APage: TTabSheet;
Begin
{$IFDEF IDE_DEBUG}
writeln('[TSourceNotebook.CreateNotebook] START');
@ -4911,13 +4913,12 @@ Begin
Name:='SrcEditNotebook';
Parent := Self;
{$IFDEF IDE_DEBUG}
writeln('[TSourceNotebook.CreateNotebook] C');
debugln('[TSourceNotebook.CreateNotebook] C');
{$ENDIF}
Align := alClient;
if PageCount>0 then
Pages.Strings[0] := 'unit1'
else
Pages.Add('unit1');
APage:=TTabSheet.Create(FNotebook);
APage.Caption:='unit1';
APage.Parent:=FNotebook;
PageIndex := 0; // Set it to the first page
if not (nbcPageListPopup in GetCapabilities) then
PopupMenu := SrcPopupMenu;
@ -4937,12 +4938,12 @@ Begin
ShowHint:=true;
OnShowHint:=@NotebookShowTabHint;
{$IFDEF IDE_DEBUG}
writeln('[TSourceNotebook.CreateNotebook] D');
debugln('[TSourceNotebook.CreateNotebook] D');
{$ENDIF}
Visible := False;
end; //with
{$IFDEF IDE_DEBUG}
writeln('[TSourceNotebook.CreateNotebook] END');
debugln('[TSourceNotebook.CreateNotebook] END');
{$ENDIF}
{$IFDEF IDE_MEM_CHECK}
CheckHeapWrtMemCnt('[TSourceNotebook.CreateNotebook] END ');
@ -5411,10 +5412,10 @@ begin
{$ENDIF}
end;
function TSourceNotebook.GetNoteBookPage(Index: Integer): TPage;
function TSourceNotebook.GetNoteBookPage(Index: Integer): TTabSheet;
begin
if FNotebook.Visible then
Result := FNotebook.Page[Index]
Result := FNotebook.Pages[Index]
else
Result := nil;
end;
@ -5422,7 +5423,7 @@ end;
function TSourceNotebook.GetNotebookPages: TStrings;
begin
if FNotebook.Visible then
Result := FNotebook.Pages
Result := TCustomNotebook(FNotebook).Pages
else
Result := nil;
end;
@ -5458,7 +5459,7 @@ begin
FNotebook.PageIndex := FPageIndex;
if snNotbookPageChangedNeeded in States then
NotebookPageChanged(nil);
HistorySetMostRecent(FNotebook.Page[FPageIndex]);
HistorySetMostRecent(FNotebook.Pages[FPageIndex]);
end;
end;
@ -5864,7 +5865,7 @@ begin
FNotebook.Visible := True;
NotebookPages[Index] := S;
end;
HistoryAdd(FNotebook.Page[Index]);
HistoryAdd(FNotebook.Pages[Index]);
UpdateTabsAndPageTitle;
end;
@ -5875,7 +5876,7 @@ begin
// widgetset will choose one and will send a message
// if this is the current page, switch to right APageIndex (if possible)
//todo: determine whether we can use SetPageIndex instead
HistoryRemove(FNotebook.Page[APageIndex]);
HistoryRemove(FNotebook.Pages[APageIndex]);
if PageIndex = APageIndex then begin
if EditorOpts.UseTabHistory then
FPageIndex := HistoryGetTopPageIndex
@ -5912,7 +5913,7 @@ begin
UpdateTabsAndPageTitle;
end;
function TSourceNotebook.NoteBookIndexOfPage(APage: TPage): Integer;
function TSourceNotebook.NoteBookIndexOfPage(APage: TTabSheet): Integer;
begin
Result := FNoteBook.IndexOf(APage);
end;
@ -6723,7 +6724,7 @@ begin
Manager.OnToggleObjectInspClicked(Sender);
end;
procedure TSourceNotebook.HistorySetMostRecent(APage: TPage);
procedure TSourceNotebook.HistorySetMostRecent(APage: TTabSheet);
var
Index: Integer;
begin
@ -6735,12 +6736,12 @@ begin
FHistoryList.Insert(0, APage);
end;
procedure TSourceNotebook.HistoryAdd(APage: TPage);
procedure TSourceNotebook.HistoryAdd(APage: TTabSheet);
begin
FHistoryList.Add(APage);
end;
procedure TSourceNotebook.HistoryRemove(APage: TPage);
procedure TSourceNotebook.HistoryRemove(APage: TTabSheet);
var
Index: Integer;
begin
@ -6892,10 +6893,10 @@ End;
function TSourceNotebook.FindPageWithEditor(
ASourceEditor: TSourceEditor):integer;
begin
if (ASourceEditor.EditorComponent.Parent is TPage) and
(TPage(ASourceEditor.EditorComponent.Parent).Parent = FNotebook)
if (ASourceEditor.EditorComponent.Parent is TTabSheet) and
(TTabSheet(ASourceEditor.EditorComponent.Parent).Parent = FNotebook)
then
Result:=TPage(ASourceEditor.EditorComponent.Parent).PageIndex
Result:=TTabSheet(ASourceEditor.EditorComponent.Parent).PageIndex
else
Result:=-1;
end;
@ -8174,7 +8175,7 @@ begin
end;
end;
function TSourceEditorManager.SourceWindowWithPage(const APage: TPage
function TSourceEditorManager.SourceWindowWithPage(const APage: TTabSheet
): TSourceNotebook;
var
i: Integer;