Removes the old, completely broken, TTabControl and substitutes it with the new implementation. This also cleans the namespace for renaming TCustomNotebook

git-svn-id: trunk@31766 -
This commit is contained in:
sekelsenmat 2011-07-20 14:04:55 +00:00
parent 8c15e1bd46
commit 4244d3ea84
5 changed files with 23 additions and 1104 deletions

View File

@ -298,28 +298,6 @@ type
function Page: TPage; virtual;
end;
{ TTabControlComponentEditor
The default component editor for TCustomTabControl. }
TTabControlComponentEditor = class(TDefaultComponentEditor)
protected
procedure DoAddTab; virtual;
procedure DoInsertTab; virtual;
procedure DoDeleteTab; virtual;
procedure DoMoveActiveTabLeft; virtual;
procedure DoMoveActiveTabRight; virtual;
procedure DoMoveTab(CurIndex, NewIndex: Integer); virtual;
procedure AddMenuItemsForTabs(ParentMenuItem: TMenuItem); virtual;
procedure ShowTabMenuItemClick(Sender: TObject);
function CreateNewTabCaption: string;
public
procedure ExecuteVerb(Index: Integer); override;
function GetVerb(Index: Integer): string; override;
function GetVerbCount: Integer; override;
procedure PrepareItem(Index: Integer; const AnItem: TMenuItem); override;
function TabControl: TCustomTabControl; virtual;
end;
{ TStringGridComponentEditor
The default componenteditor for TStringGrid }
@ -1279,141 +1257,6 @@ begin
EditorForms.Free;
end;
{ TTabControlComponentEditor }
const
tcvAddTab = 0;
tcvInsertTab = 1;
tcvDeleteTab = 2;
tcvMoveTabLeft = 3;
tcvMoveTabRight = 4;
procedure TTabControlComponentEditor.DoAddTab;
begin
TabControl.Tabs.Add(CreateNewTabCaption);
Modified;
end;
procedure TTabControlComponentEditor.DoInsertTab;
begin
TabControl.Tabs.Insert(TabControl.TabIndex,CreateNewTabCaption);
Modified;
end;
procedure TTabControlComponentEditor.DoDeleteTab;
begin
if (TabControl.Tabs.Count=0) then exit;
TabControl.Tabs.Delete(TabControl.TabIndex);
Modified;
end;
procedure TTabControlComponentEditor.DoMoveActiveTabLeft;
var
Index: integer;
begin
Index:=TabControl.TabIndex;
if (Index<0) then exit;
DoMoveTab(Index,Index-1);
end;
procedure TTabControlComponentEditor.DoMoveActiveTabRight;
var
Index: integer;
begin
Index:=TabControl.TabIndex;
if (Index>=TabControl.Tabs.Count-1) then exit;
DoMoveTab(Index,Index+1);
end;
procedure TTabControlComponentEditor.DoMoveTab(CurIndex, NewIndex: Integer);
begin
TabControl.Tabs.Move(CurIndex,NewIndex);
Modified;
end;
procedure TTabControlComponentEditor.AddMenuItemsForTabs(
ParentMenuItem: TMenuItem);
var
i: integer;
NewMenuItem: TMenuItem;
begin
ParentMenuItem.Enabled:=TabControl.Tabs.Count>0;
for i:=0 to TabControl.Tabs.Count-1 do begin
NewMenuItem:=TMenuItem.Create(ParentMenuItem);
NewMenuItem.Name:='ShowTab'+IntToStr(i);
NewMenuItem.Caption:='"'+TabControl.Tabs[i]+'"';
NewMenuItem.OnClick:=@ShowTabMenuItemClick;
ParentMenuItem.Add(NewMenuItem);
end;
end;
procedure TTabControlComponentEditor.ShowTabMenuItemClick(Sender: TObject);
var
AMenuItem: TMenuItem;
NewTabIndex: LongInt;
begin
AMenuItem:=TMenuItem(Sender);
if (AMenuItem=nil) or (not (AMenuItem is TMenuItem)) then exit;
NewTabIndex:=AMenuItem.MenuIndex;
if (NewTabIndex<0) or (NewTabIndex>=TabControl.Tabs.Count) then exit;
TabControl.TabIndex:=NewTabIndex;
Modified;
end;
function TTabControlComponentEditor.CreateNewTabCaption: string;
begin
Result:='New Tab';
while TabControl.IndexOfTabWithCaption(Result)>=0 do
Result:=CreateNextIdentifier(Result);
end;
procedure TTabControlComponentEditor.ExecuteVerb(Index: Integer);
begin
case Index of
tcvAddTab: DoAddTab;
tcvInsertTab: DoInsertTab;
tcvDeleteTab: DoDeleteTab; // beware: this can free the editor itself
tcvMoveTabLeft: DoMoveActiveTabLeft;
tcvMoveTabRight: DoMoveActiveTabRight;
end;
end;
function TTabControlComponentEditor.GetVerb(Index: Integer): string;
begin
case Index of
tcvAddTab: Result:=tccesAddTab;
tcvInsertTab: Result:=tccesInsertTab;
tcvDeleteTab: Result:=tccesDeleteTab;
tcvMoveTabLeft: Result:=tccesMoveTabLeft;
tcvMoveTabRight: Result:=tccesMoveTabRight;
else
Result:='';
end;
end;
function TTabControlComponentEditor.GetVerbCount: Integer;
begin
Result:=5;
end;
procedure TTabControlComponentEditor.PrepareItem(Index: Integer;
const AnItem: TMenuItem);
begin
inherited PrepareItem(Index, AnItem);
case Index of
tcvAddTab: ;
tcvInsertTab: AnItem.Enabled:=TabControl.TabIndex>=0;
tcvDeleteTab: AnItem.Enabled:=TabControl.TabIndex>=0;
tcvMoveTabLeft: AnItem.Enabled:=TabControl.TabIndex>0;
tcvMoveTabRight: AnItem.Enabled:=TabControl.TabIndex<TabControl.Tabs.Count-1;
end;
end;
function TTabControlComponentEditor.TabControl: TCustomTabControl;
begin
Result:=TCustomTabControl(GetComponent);
end;
{ TTimerComponentEditor }
constructor TTimerComponentEditor.Create(AComponent: TComponent;
@ -1492,7 +1335,7 @@ initialization
RegisterComponentEditor(TCustomPage, TPageComponentEditor);
RegisterComponentEditor(TNotebook, TUntabbedNotebookComponentEditor);
RegisterComponentEditor(TPage, TUNBPageComponentEditor);
RegisterComponentEditor(TCustomTabControl, TTabControlComponentEditor);
// RegisterComponentEditor(TCustomTabControl, TTabControlComponentEditor);
RegisterComponentEditor(TStringGrid, TStringGridComponentEditor);
RegisterComponentEditor(TCheckListBox, TCheckListBoxComponentEditor);
RegisterComponentEditor(TCheckGroup, TCheckGroupComponentEditor);

View File

@ -581,267 +581,14 @@ type
property Options;
end;
TCustomTabControl = class;
{ TTabControlStrings }
TTabControlStrings = class(TStrings)
private
FHotTrack: Boolean;
FImages: TCustomImageList;
FMultiLine: Boolean;
FMultiSelect: Boolean;
FOwnerDraw: Boolean;
FRaggedRight: Boolean;
FScrollOpposite: Boolean;
FTabControl: TCustomTabControl;
FTabHeight: Smallint;
FTabWidth: Smallint;
FUpdateCount: integer;
protected
function GetTabIndex: integer; virtual; abstract;
procedure SetHotTrack(const AValue: Boolean); virtual;
procedure SetImages(const AValue: TCustomImageList); virtual;
procedure SetMultiLine(const AValue: Boolean); virtual;
procedure SetMultiSelect(const AValue: Boolean); virtual;
procedure SetOwnerDraw(const AValue: Boolean); virtual;
procedure SetRaggedRight(const AValue: Boolean); virtual;
procedure SetScrollOpposite(const AValue: Boolean); virtual;
procedure SetTabHeight(const AValue: Smallint); virtual;
procedure SetTabIndex(const AValue: integer); virtual; abstract;
procedure SetTabWidth(const AValue: Smallint); virtual;
public
constructor Create(TheTabControl: TCustomTabControl); virtual;
function GetHitTestInfoAt(X, Y: Integer): THitTests; virtual;
function GetSize: integer; virtual; abstract;
function IndexOfTabAt(X, Y: Integer): Integer; virtual;
function RowCount: Integer; virtual;
function TabRect(Index: Integer): TRect; virtual;
procedure ImageListChange(Sender: TObject); virtual;
procedure ScrollTabs(Delta: Integer); virtual;
procedure TabControlBoundsChange; virtual;
procedure UpdateTabImages; virtual;
procedure BeginUpdate; virtual;
procedure EndUpdate; virtual;
function IsUpdating: boolean; virtual;
public
property TabControl: TCustomTabControl read FTabControl;
property TabIndex: integer read GetTabIndex write SetTabIndex;
property HotTrack: Boolean read FHotTrack write SetHotTrack;
property Images: TCustomImageList read FImages write SetImages;
property MultiLine: Boolean read FMultiLine write SetMultiLine;
property MultiSelect: Boolean read FMultiSelect write SetMultiSelect;
property OwnerDraw: Boolean read FOwnerDraw write SetOwnerDraw;
property RaggedRight: Boolean read FRaggedRight write SetRaggedRight;
property ScrollOpposite: Boolean read FScrollOpposite
write SetScrollOpposite;
property TabHeight: Smallint read FTabHeight write SetTabHeight;
property TabWidth: Smallint read FTabWidth write SetTabWidth;
end;
{ TTabControlNoteBookStrings }
TTabControlNoteBookStrings = class(TTabControlStrings)
private
FNoteBook: TCustomNoteBook{%H-};
protected
function Get(Index: Integer): string; override;
function GetCount: Integer; override;
function GetObject(Index: Integer): TObject; override;
function GetTabIndex: integer; override;
procedure NBChanging(Sender: TObject; var AllowChange: Boolean); virtual;
procedure NBGetImageIndex(Sender: TObject; TheTabIndex: Integer;
var ImageIndex: Integer); virtual;
procedure NBPageChanged(Sender: TObject); virtual;
procedure Put(Index: Integer; const S: string); override;
procedure PutObject(Index: Integer; AObject: TObject); override;
procedure SetImages(const AValue: TCustomImageList); override;
procedure SetTabIndex(const AValue: integer); override;
procedure SetUpdateState(Updating: Boolean); override;
procedure SetTabHeight(const AValue: Smallint); override;
procedure SetTabWidth(const AValue: Smallint); override;
public
constructor Create(TheTabControl: TCustomTabControl); override;
destructor Destroy; override;
procedure Clear; override;
procedure Delete(Index: Integer); override;
procedure Insert(Index: Integer; const S: string); override;
function GetSize: integer; override;
procedure TabControlBoundsChange; override;
function IndexOfTabAt(X, Y: Integer): Integer; override;
public
property NoteBook: TCustomNoteBook read FNoteBook;
end;
{ TCustomTabControl }
TCustomTabControl = class(TCustomControl)
private
FImageChangeLink: TChangeLink;
FImages: TCustomImageList;
FOnChange: TNotifyEvent;
FOnChangeNeeded: Boolean;
FOnChanging: TTabChangingEvent;
FOnDrawTab: TDrawTabEvent;
FOnGetImageIndex: TTabGetImageEvent;
FStyle: TTabStyle;
FTabControlCreating: Boolean;
FTabPosition: TTabPosition;
FTabs: TStrings;// this is a TTabControlNoteBookStrings
procedure AdjustDisplayRect(var ARect: TRect);
function GetDisplayRect: TRect;
function GetHotTrack: Boolean;
function GetMultiLine: Boolean;
function GetMultiSelect: Boolean;
function GetOwnerDraw: Boolean;
function GetRaggedRight: Boolean;
function GetScrollOpposite: Boolean;
function GetTabHeight: Smallint;
function GetTabIndex: Integer;
function GetTabRectWithBorder: TRect;
function GetTabWidth: Smallint;
procedure SetHotTrack(const AValue: Boolean);
procedure SetImages(const AValue: TCustomImageList);
procedure SetMultiLine(const AValue: Boolean);
procedure SetMultiSelect(const AValue: Boolean);
procedure SetOwnerDraw(const AValue: Boolean);
procedure SetRaggedRight(const AValue: Boolean);
procedure SetScrollOpposite(const AValue: Boolean);
procedure SetStyle(const AValue: TTabStyle);
procedure SetTabHeight(const AValue: Smallint);
procedure SetTabPosition(const AValue: TTabPosition);
procedure SetTabs(const AValue: TStrings);
procedure SetTabWidth(const AValue: Smallint);
protected
function CanChange: Boolean; virtual;
function CanShowTab(ATabIndex: Integer): Boolean; virtual;
procedure Change; virtual;
procedure DrawTab(ATabIndex: Integer; const Rect: TRect; Active: Boolean); virtual;
function GetImageIndex(ATabIndex: Integer): Integer; virtual;
procedure Loaded; override;
procedure CreateWnd; override;
procedure DestroyHandle; override;
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
procedure SetTabIndex(Value: Integer); virtual;
procedure UpdateTabImages;
procedure ImageListChange(Sender: TObject);
procedure DoSetBounds(ALeft, ATop, AWidth, AHeight: integer); override;
class function GetControlClassDefaultSize: TSize; override;
procedure Paint; override;
procedure AdjustDisplayRectWithBorder(var ARect: TRect); virtual;
procedure AdjustClientRect(var ARect: TRect); override;
protected
property DisplayRect: TRect read GetDisplayRect;
property HotTrack: Boolean read GetHotTrack write SetHotTrack default False;
property Images: TCustomImageList read FImages write SetImages;
property MultiLine: Boolean read GetMultiLine write SetMultiLine default False;
property MultiSelect: Boolean read GetMultiSelect write SetMultiSelect default False;
property OnChange: TNotifyEvent read FOnChange write FOnChange;
property OnChanging: TTabChangingEvent read FOnChanging write FOnChanging;
property OnDrawTab: TDrawTabEvent read FOnDrawTab write FOnDrawTab;
property OnGetImageIndex: TTabGetImageEvent read FOnGetImageIndex
write FOnGetImageIndex;
property OwnerDraw: Boolean read GetOwnerDraw write SetOwnerDraw default False;
property RaggedRight: Boolean read GetRaggedRight write SetRaggedRight default False;
property ScrollOpposite: Boolean read GetScrollOpposite
write SetScrollOpposite default False;
property Style: TTabStyle read FStyle write SetStyle default tsTabs;
property TabHeight: Smallint read GetTabHeight write SetTabHeight default 0;
property TabPosition: TTabPosition read FTabPosition write SetTabPosition
default tpTop;
property TabWidth: Smallint read GetTabWidth write SetTabWidth default 0;
public
constructor Create(TheOwner: TComponent); override;
destructor Destroy; override;
function IndexOfTabAt(X, Y: Integer): Integer;
function GetHitTestInfoAt(X, Y: Integer): THitTests;
function IndexOfTabWithCaption(const TabCaption: string): Integer;
function TabRect(Index: Integer): TRect;
function RowCount: Integer;
procedure ScrollTabs(Delta: Integer);
procedure BeginUpdate;
procedure EndUpdate;
function IsUpdating: boolean;
property TabIndex: Integer read GetTabIndex write SetTabIndex default -1;
property Tabs: TStrings read FTabs write SetTabs;
public
property TabStop default True;
end;
{ TTabControl }
TTabControl = class(TCustomTabControl)
public
property DisplayRect;
published
property Align;
property Anchors;
property BorderSpacing;
property Constraints;
property DockSite;
property DragCursor;
property DragKind;
property DragMode;
property Enabled;
property Font;
property HotTrack;
property Images;
property MultiLine;
property MultiSelect;
property OnChange;
property OnChangeBounds;
property OnChanging;
property OnContextPopup;
property OnDockDrop;
property OnDockOver;
property OnDragDrop;
property OnDragOver;
property OnDrawTab;
property OnEndDock;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnGetImageIndex;
property OnGetSiteInfo;
property OnMouseDown;
property OnMouseEnter;
property OnMouseLeave;
property OnMouseMove;
property OnMouseUp;
property OnResize;
property OnStartDock;
property OnStartDrag;
property OnUnDock;
property OwnerDraw;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property RaggedRight;
property ScrollOpposite;
property ShowHint;
property Style;
property TabHeight;
property TabIndex;
property TabOrder;
property TabPosition;
property Tabs;
property TabStop;
property TabWidth;
property Visible;
end;
{ TTabs }
(* TTabs is a replacement for TTabControl, derived from TCustomNotebook.
(* The new TTabControl is a replacement for the old TTabControl, both derived from TCustomNotebook.
TTabPage is a dummy page, for communication with the widgetsets.
TTabPages holds the tabs (Strings[] and Objects[]).
*)
TTabs = class(TCustomNotebook)
TTabControl = class(TCustomNotebook)
protected
procedure DoChange; override;
function GetPage(AIndex: Integer): TCustomPage; override;
@ -851,7 +598,7 @@ type
constructor Create(TheOwner: TComponent); override;
function IndexOf(APage: TPersistent): integer; override;
function IndexOfTabWithCaption(const TabCaption: string): Integer;
published //copied from TTabControl
published
property Align;
property Anchors;
property BorderSpacing;
@ -3480,7 +3227,7 @@ end;
procedure Register;
begin
RegisterComponents('Common Controls',[TTrackbar,TProgressBar,TTreeView,
TListView,TStatusBar,TToolBar,TUpDown,TPageControl,TTabControl,{$IFDEF LCL_REGISTER_TTABS}TTabs,{$ENDIF} THeaderControl]);
TListView,TStatusBar,TToolBar,TUpDown,TPageControl,TTabControl,THeaderControl]);
RegisterNoIcon([TToolButton,TTabSheet]);
end;

View File

@ -21,681 +21,13 @@
}
{ TTabControlStrings }
procedure TTabControlStrings.SetHotTrack(const AValue: Boolean);
begin
if FHotTrack=AValue then exit;
FHotTrack:=AValue;
end;
procedure TTabControlStrings.SetImages(const AValue: TCustomImageList);
begin
if FImages=AValue then exit;
FImages:=AValue;
end;
procedure TTabControlStrings.SetMultiLine(const AValue: Boolean);
begin
if FMultiLine=AValue then exit;
FMultiLine:=AValue;
end;
procedure TTabControlStrings.SetMultiSelect(const AValue: Boolean);
begin
if FMultiSelect=AValue then exit;
FMultiSelect:=AValue;
end;
procedure TTabControlStrings.SetOwnerDraw(const AValue: Boolean);
begin
if FOwnerDraw=AValue then exit;
FOwnerDraw:=AValue;
end;
procedure TTabControlStrings.SetRaggedRight(const AValue: Boolean);
begin
if FRaggedRight=AValue then exit;
FRaggedRight:=AValue;
end;
procedure TTabControlStrings.SetScrollOpposite(const AValue: Boolean);
begin
if FScrollOpposite=AValue then exit;
FScrollOpposite:=AValue;
end;
procedure TTabControlStrings.SetTabHeight(const AValue: Smallint);
begin
if FTabHeight=AValue then exit;
FTabHeight:=AValue;
end;
procedure TTabControlStrings.SetTabWidth(const AValue: Smallint);
begin
if FTabWidth=AValue then exit;
FTabWidth:=AValue;
end;
constructor TTabControlStrings.Create(TheTabControl: TCustomTabControl);
begin
inherited Create;
FTabControl:=TheTabControl;
FHotTrack:=false;
FMultiLine:=false;
FMultiSelect:=false;
FOwnerDraw:=false;
FRaggedRight:=false;
FScrollOpposite:=false;
FTabHeight:=0;
FTabWidth:=0;
end;
procedure TTabControlStrings.TabControlBoundsChange;
begin
end;
function TTabControlStrings.IndexOfTabAt(X, Y: Integer): Integer;
begin
Result:=0;
end;
function TTabControlStrings.GetHitTestInfoAt(X, Y: Integer): THitTests;
begin
Result:=[];
end;
function TTabControlStrings.TabRect(Index: Integer): TRect;
begin
FillChar(Result,SizeOf(Result),0);
end;
function TTabControlStrings.RowCount: Integer;
begin
Result:=1;
end;
procedure TTabControlStrings.ScrollTabs(Delta: Integer);
begin
end;
procedure TTabControlStrings.UpdateTabImages;
begin
end;
procedure TTabControlStrings.BeginUpdate;
begin
inc(FUpdateCount);
end;
procedure TTabControlStrings.EndUpdate;
begin
if FUpdateCount=0 then
RaiseGDBException('TTabControlStrings.EndUpdate');
dec(FUpdateCount);
end;
function TTabControlStrings.IsUpdating: boolean;
begin
Result:=FUpdateCount>0;
end;
procedure TTabControlStrings.ImageListChange(Sender: TObject);
begin
end;
{ TTabControlNoteBookStrings }
procedure TTabControlNoteBookStrings.NBGetImageIndex(Sender: TObject;
TheTabIndex: Integer; var ImageIndex: Integer);
begin
ImageIndex := TabControl.GetImageIndex(TheTabIndex);
end;
procedure TTabControlNoteBookStrings.NBChanging(Sender: TObject;
var AllowChange: Boolean);
begin
AllowChange:=TabControl.CanChange;
end;
procedure TTabControlNoteBookStrings.NBPageChanged(Sender: TObject);
begin
TabControl.Change;
end;
function TTabControlNoteBookStrings.Get(Index: Integer): string;
begin
Result:=FNoteBook.Pages[Index];
end;
function TTabControlNoteBookStrings.GetCount: Integer;
begin
Result:=FNoteBook.PageCount;
end;
function TTabControlNoteBookStrings.GetObject(Index: Integer): TObject;
begin
Result:=FNoteBook.Pages.Objects[Index];
end;
procedure TTabControlNoteBookStrings.Put(Index: Integer; const S: string);
begin
FNoteBook.Pages[Index]:=S;
end;
procedure TTabControlNoteBookStrings.PutObject(Index: Integer; AObject: TObject);
begin
FNoteBook.Pages.Objects[Index]:=AObject;
end;
procedure TTabControlNoteBookStrings.SetImages(const AValue: TCustomImageList);
begin
if AValue is TImageList then
FNoteBook.Images:=TImageList(AValue)
else
FNoteBook.Images:=nil;
end;
procedure TTabControlNoteBookStrings.SetUpdateState(Updating: Boolean);
begin
if Updating then
FNoteBook.Pages.BeginUpdate
else
FNoteBook.Pages.EndUpdate;
end;
procedure TTabControlNoteBookStrings.SetTabHeight(const AValue: Smallint);
begin
if TabHeight=AValue then exit;
inherited SetTabHeight(AValue);
TabControlBoundsChange;
end;
procedure TTabControlNoteBookStrings.SetTabWidth(const AValue: Smallint);
begin
if TabWidth=AValue then exit;
inherited SetTabWidth(AValue);
TabControlBoundsChange;
end;
function TTabControlNoteBookStrings.GetTabIndex: integer;
begin
Result:=FNoteBook.PageIndex;
end;
procedure TTabControlNoteBookStrings.SetTabIndex(const AValue: integer);
begin
FNoteBook.PageIndex:=AValue;
end;
constructor TTabControlNoteBookStrings.Create(TheTabControl: TCustomTabControl);
begin
inherited Create(TheTabControl);
FNoteBook := TCustomNoteBook{%H-}.Create(nil);
FNoteBook.ControlStyle := FNoteBook.ControlStyle + [csNoDesignSelectable];
FNoteBook.Parent := TabControl;
FNoteBook.OnGetImageIndex := @NBGetImageIndex;
FNoteBook.OnChanging := @NBChanging;
FNoteBook.OnPageChanged := @NBPageChanged;
TabControlBoundsChange;
end;
destructor TTabControlNoteBookStrings.Destroy;
begin
FreeThenNil(FNoteBook);
inherited Destroy;
end;
procedure TTabControlNoteBookStrings.Clear;
begin
FNoteBook.Pages.Clear;
end;
procedure TTabControlNoteBookStrings.Delete(Index: Integer);
begin
FNoteBook.Pages.Delete(Index);
end;
procedure TTabControlNoteBookStrings.Insert(Index: Integer; const S: string);
begin
FNoteBook.Pages.Insert(Index, S);
end;
function TTabControlNoteBookStrings.GetSize: integer;
begin
case TabControl.TabPosition of
tpTop, tpBottom: Result:=FNoteBook.Height;
tpLeft, tpRight: Result:=FNoteBook.Width;
end;
end;
procedure TTabControlNoteBookStrings.TabControlBoundsChange;
var
NewHeight: LongInt;
NewWidth: LongInt;
begin
inherited TabControlBoundsChange;
FNoteBook.TabPosition:=TabControl.TabPosition;
case TabControl.TabPosition of
tpTop,tpBottom:
begin
NewHeight:=TabHeight;
if NewHeight<=0 then
NewHeight:=FNoteBook.GetMinimumTabHeight;
NewHeight:=Min(TabControl.Height,NewHeight);
if TabControl.TabPosition=tpTop then
FNoteBook.SetBounds(0,0,TabControl.Width,NewHeight)
else
FNoteBook.SetBounds(0,TabControl.Height-NewHeight,
TabControl.Width,NewHeight);
end;
tpLeft,tpRight:
begin
NewWidth:=TabWidth;
if NewWidth<=0 then
NewWidth:=FNoteBook.GetMinimumTabWidth;
NewWidth:=Min(TabControl.Width,NewWidth);
if TabControl.TabPosition=tpLeft then
FNoteBook.SetBounds(0,0,NewWidth,TabControl.Height)
else
FNoteBook.SetBounds(TabControl.Width-NewWidth,0,
NewWidth,TabControl.Height);
end;
end;
end;
function TTabControlNoteBookStrings.IndexOfTabAt(X, Y: Integer): Integer;
begin
Result:=FNoteBook.TabIndexAtClientPos(Point(X, Y));
end;
{ TCustomTabControl }
procedure TCustomTabControl.AdjustDisplayRect(var ARect: TRect);
begin
AdjustDisplayRectWithBorder(ARect);
if TabPosition<>tpTop then
ARect.Top:=Min(Max(ARect.Top,ARect.Top+BorderWidth),ARect.Bottom);
if TabPosition<>tpBottom then
ARect.Bottom:=Max(Min(ARect.Bottom,ARect.Bottom-BorderWidth),ARect.Top);
if TabPosition<>tpLeft then
ARect.Left:=Min(Max(ARect.Left,ARect.Left+BorderWidth),ARect.Right);
if TabPosition<>tpRight then
ARect.Right:=Max(Min(ARect.Right,ARect.Right-BorderWidth),ARect.Left);
end;
function TCustomTabControl.GetDisplayRect: TRect;
begin
Result:=ClientRect;
AdjustDisplayRect(Result);
end;
function TCustomTabControl.GetHotTrack: Boolean;
begin
Result:=TTabControlStrings(FTabs).HotTrack;
end;
function TCustomTabControl.GetMultiLine: Boolean;
begin
Result:=TTabControlStrings(FTabs).MultiLine;
end;
function TCustomTabControl.GetMultiSelect: Boolean;
begin
Result:=TTabControlStrings(FTabs).MultiSelect;
end;
function TCustomTabControl.GetOwnerDraw: Boolean;
begin
Result:=TTabControlStrings(FTabs).OwnerDraw;
end;
function TCustomTabControl.GetRaggedRight: Boolean;
begin
Result:=TTabControlStrings(FTabs).RaggedRight;
end;
function TCustomTabControl.GetScrollOpposite: Boolean;
begin
Result:=TTabControlStrings(FTabs).ScrollOpposite;
end;
function TCustomTabControl.GetTabHeight: Smallint;
begin
Result:=TTabControlStrings(FTabs).TabHeight;
end;
function TCustomTabControl.GetTabIndex: Integer;
begin
Result:=TTabControlStrings(FTabs).TabIndex;
end;
function TCustomTabControl.GetTabWidth: Smallint;
begin
Result:=TTabControlStrings(FTabs).TabWidth;
end;
procedure TCustomTabControl.SetHotTrack(const AValue: Boolean);
begin
TTabControlStrings(FTabs).HotTrack:=AValue;
end;
procedure TCustomTabControl.SetImages(const AValue: TCustomImageList);
begin
if FImages = AValue then Exit;
if FImages <> nil then
FImages.RemoveFreeNotification(Self);
FImages := AValue;
if FImages <> nil then
FImages.FreeNotification(Self);
TTabControlStrings(FTabs).Images := FImages;
end;
procedure TCustomTabControl.SetMultiLine(const AValue: Boolean);
begin
TTabControlStrings(FTabs).MultiLine:=AValue;
end;
procedure TCustomTabControl.SetMultiSelect(const AValue: Boolean);
begin
TTabControlStrings(FTabs).MultiSelect:=AValue;
end;
procedure TCustomTabControl.SetOwnerDraw(const AValue: Boolean);
begin
TTabControlStrings(FTabs).OwnerDraw:=AValue;
end;
procedure TCustomTabControl.SetRaggedRight(const AValue: Boolean);
begin
TTabControlStrings(FTabs).RaggedRight:=AValue;
end;
procedure TCustomTabControl.SetScrollOpposite(const AValue: Boolean);
begin
TTabControlStrings(FTabs).ScrollOpposite:=AValue;
end;
procedure TCustomTabControl.SetStyle(const AValue: TTabStyle);
begin
if FStyle=AValue then exit;
FStyle:=AValue;
// ToDo
end;
procedure TCustomTabControl.SetTabHeight(const AValue: Smallint);
begin
TTabControlStrings(FTabs).TabHeight:=AValue;
end;
procedure TCustomTabControl.SetTabPosition(const AValue: TTabPosition);
begin
if FTabPosition=AValue then exit;
FTabPosition:=AValue;
TTabControlStrings(FTabs).TabControlBoundsChange;
ReAlign;
end;
procedure TCustomTabControl.SetTabs(const AValue: TStrings);
begin
FTabs.Assign(AValue);
end;
procedure TCustomTabControl.SetTabWidth(const AValue: Smallint);
begin
TTabControlStrings(FTabs).TabWidth:=AValue;
end;
function TCustomTabControl.CanChange: Boolean;
begin
Result:=true;
if FTabControlCreating then exit;
if not IsUpdating and Assigned(FOnChanging) then
FOnChanging(Self,Result);
end;
function TCustomTabControl.CanShowTab(ATabIndex: Integer): Boolean;
begin
Result:=true;
end;
procedure TCustomTabControl.Change;
begin
if FTabControlCreating then exit;
if IsUpdating then begin
FOnChangeNeeded:=true;
exit;
end else
FOnChangeNeeded:=false;
if Assigned(FOnChange) then
FOnChange(Self);
end;
procedure TCustomTabControl.DrawTab(ATabIndex: Integer; const Rect: TRect;
Active: Boolean);
begin
if Assigned(FOnDrawTab) then
FOnDrawTab(TCustomNotebook(Self),TabIndex,Rect,Active)
else
Canvas.FillRect(Rect);
end;
function TCustomTabControl.GetImageIndex(ATabIndex: Integer): Integer;
begin
Result := ATabIndex;
if Assigned(FOnGetImageIndex) then
FOnGetImageIndex(Self, ATabIndex, Result);
end;
procedure TCustomTabControl.Loaded;
begin
inherited Loaded;
end;
procedure TCustomTabControl.CreateWnd;
begin
BeginUpdate;
inherited CreateWnd;
EndUpdate;
end;
procedure TCustomTabControl.DestroyHandle;
begin
BeginUpdate;
inherited DestroyHandle;
EndUpdate;
end;
procedure TCustomTabControl.Notification(AComponent: TComponent;
Operation: TOperation);
begin
inherited Notification(AComponent, Operation);
if (Operation = opRemove) and (AComponent = Images) then
Images := nil;
end;
procedure TCustomTabControl.SetTabIndex(Value: Integer);
begin
TTabControlStrings(FTabs).TabIndex:=Value;
end;
procedure TCustomTabControl.UpdateTabImages;
begin
TTabControlStrings(FTabs).UpdateTabImages;
end;
procedure TCustomTabControl.ImageListChange(Sender: TObject);
begin
TTabControlStrings(FTabs).ImageListChange(Sender);
end;
procedure TCustomTabControl.DoSetBounds(ALeft, ATop, AWidth, AHeight: integer);
begin
inherited DoSetBounds(ALeft, ATop, AWidth, AHeight);
TTabControlStrings(FTabs).TabControlBoundsChange;
end;
class function TCustomTabControl.GetControlClassDefaultSize: TSize;
begin
Result.CX := 200;
Result.CY := 150;
end;
procedure TCustomTabControl.Paint;
var
ARect: TRect;
TS: TTextStyle;
Details: TThemedElementDetails;
begin
//DebugLn(['TCustomTabControl.Paint Bounds=',dbgs(BoundsRect),' ClientRect=',dbgs(ClientRect),' CientOrigin=',dbgs(ClientOrigin)]);
// clear only display area since button area is painted by another control
// draw a frame
ARect := ClientRect;
AdjustDisplayRectWithBorder(ARect);
Details := ThemeServices.GetElementDetails(ttPane);
ThemeServices.DrawElement(Canvas.Handle, Details, ARect);
InflateRect(ARect,BorderWidth,BorderWidth);
Canvas.Frame3d(ARect, BorderWidth, bvRaised);
if (csDesigning in ComponentState) and (Caption <> '') then
begin
ARect:=GetDisplayRect;
TS := Canvas.TextStyle;
TS.Alignment:=taCenter;
TS.Layout:= tlCenter;
TS.Opaque:= false;
TS.Clipping:= false;
Canvas.TextRect(ARect, ARect.Left, ARect.Top, Caption, TS);
end;
end;
procedure TCustomTabControl.AdjustDisplayRectWithBorder(var ARect: TRect);
var
TabAreaSize: LongInt;
begin
TabAreaSize := TTabControlStrings(FTabs).GetSize;
case TabPosition of
tpTop: ARect.Top:=Min(TabAreaSize,ARect.Bottom);
tpBottom: ARect.Bottom:=Max(ARect.Bottom-TabAreaSize,ARect.Top);
tpLeft: ARect.Left:=Min(TabAreaSize,ARect.Right);
tpRight: ARect.Right:=Max(ARect.Right-TabAreaSize,ARect.Left);
end;
end;
function TCustomTabControl.GetTabRectWithBorder: TRect;
var
TabAreaSize: LongInt;
begin
Result := ClientRect;
TabAreaSize := TTabControlStrings(FTabs).GetSize;
case TabPosition of
tpTop: Result.Bottom:=Min(TabAreaSize,Result.Bottom);
tpBottom: Result.Top:=Max(Result.Bottom-TabAreaSize,Result.Top);
tpLeft: Result.Right:=Min(TabAreaSize,Result.Right);
tpRight: Result.Left:=Max(Result.Right-TabAreaSize,Result.Left);
end;
end;
procedure TCustomTabControl.AdjustClientRect(var ARect: TRect);
begin
AdjustDisplayRect(ARect);
end;
constructor TCustomTabControl.Create(TheOwner: TComponent);
begin
FTabControlCreating:=true;
inherited Create(TheOwner);
ControlStyle:=ControlStyle+[csAcceptsControls];
FStyle:=tsTabs;
FTabPosition:=tpTop;
FImageChangeLink := TChangeLink.Create;
FImageChangeLink.OnChange := @ImageListChange;
FTabs:=TTabControlNoteBookStrings.Create(Self);
with GetControlClassDefaultSize do
SetInitialBounds(0, 0, CX, CY);
BorderWidth:=2;
FTabControlCreating:=false;
end;
destructor TCustomTabControl.Destroy;
begin
BeginUpdate;
FreeThenNil(FTabs);
FreeThenNil(FImageChangeLink);
inherited Destroy;
end;
function TCustomTabControl.IndexOfTabAt(X, Y: Integer): Integer;
begin
Result:=TTabControlStrings(FTabs).IndexOfTabAt(X,Y);
end;
function TCustomTabControl.GetHitTestInfoAt(X, Y: Integer): THitTests;
begin
Result:=TTabControlStrings(FTabs).GetHitTestInfoAt(X,Y);
end;
function TCustomTabControl.IndexOfTabWithCaption(const TabCaption: string
): Integer;
begin
Result:=0;
while Result<Tabs.Count do begin
if CompareText(Tabs[Result],TabCaption)=0 then exit;
inc(Result);
end;
Result:=-1;
end;
function TCustomTabControl.TabRect(Index: Integer): TRect;
begin
Result:=TTabControlStrings(FTabs).TabRect(Index);
end;
function TCustomTabControl.RowCount: Integer;
begin
Result:=TTabControlStrings(FTabs).RowCount;
end;
procedure TCustomTabControl.ScrollTabs(Delta: Integer);
begin
TTabControlStrings(FTabs).ScrollTabs(Delta);
end;
procedure TCustomTabControl.BeginUpdate;
begin
if FTabs=nil then exit;
TTabControlStrings(FTabs).BeginUpdate;
//debugln('TCustomTabControl.BeginUpdate ',dbgs(IsUpdating));
end;
procedure TCustomTabControl.EndUpdate;
begin
if FTabs=nil then exit;
TTabControlStrings(FTabs).EndUpdate;
//debugln('TCustomTabControl.EndUpdate ',dbgs(IsUpdating));
if not TTabControlStrings(FTabs).IsUpdating then begin
if FOnChangeNeeded then Change;
end;
end;
function TCustomTabControl.IsUpdating: boolean;
begin
Result:=(FTabs<>nil) and TTabControlStrings(fTabs).IsUpdating;
end;
{ TTabPage }
type
TTabPage = class(TCustomPage)
protected
FIndex: integer;
FTabs: TCustomTabControl;
FTabs: TCustomNotebook;
function GetTabVisible: Boolean; override; //assure always visible
function GetPageIndex: integer; override;
procedure SetPageIndex(AValue: Integer); override;
@ -735,14 +67,14 @@ type
TTabPages = class(TStringList)
protected
FPage: TTabPage;
FTabs: TTabs;
FTabs: TTabControl;
public
constructor Create(ATabCtl: TTabs);
constructor Create(ATabCtl: TTabControl);
function Add(const S: string): Integer; override;
procedure Delete(Index: Integer); override;
end;
constructor TTabPages.Create(ATabCtl: TTabs);
constructor TTabPages.Create(ATabCtl: TTabControl);
begin
inherited Create;
FTabs := ATabCtl;
@ -764,7 +96,7 @@ end;
{ TTabs }
constructor TTabs.Create(TheOwner: TComponent);
constructor TTabControl.Create(TheOwner: TComponent);
begin
FUnPaged:=True;
FAccess := TTabPages.Create(Self); //specialization required for notifications
@ -772,7 +104,7 @@ begin
inherited Create(TheOwner);
end;
procedure TTabs.DoChange;
procedure TTabControl.DoChange;
var
i: integer;
p: TObject;
@ -790,14 +122,14 @@ begin
end;
end;
function TTabs.GetPage(AIndex: Integer): TCustomPage;
function TTabControl.GetPage(AIndex: Integer): TCustomPage;
begin
Result := TTabPages(Tabs).FPage;
Result.PageIndex := AIndex;
Result.Caption := FAccess.Strings[AIndex];
end;
function TTabs.IndexOf(APage: TPersistent): integer;
function TTabControl.IndexOf(APage: TPersistent): integer;
begin
if APage is TTabPage then begin
Result := TTabPage(APage).FIndex;
@ -805,12 +137,12 @@ begin
Result := Tabs.IndexOfObject(APage);
end;
function TTabs.IndexOfTabWithCaption(const TabCaption: string): Integer;
function TTabControl.IndexOfTabWithCaption(const TabCaption: string): Integer;
begin
Result := Tabs.IndexOf(TabCaption);
end;
procedure TTabs.InsertPage(APage: TCustomPage; Index: Integer);
procedure TTabControl.InsertPage(APage: TCustomPage; Index: Integer);
begin
//A page has been added to Pages - notify widgetset
//TWSCustomNotebookClass(WidgetSetClass).AddPage(Self, APage, APage.VisibleIndex);
@ -826,7 +158,7 @@ begin
end;
end;
procedure TTabs.RemovePage(Index: Integer);
procedure TTabControl.RemovePage(Index: Integer);
begin
//A page has been removed from Pages - notify widgetset
//TWSCustomNotebookClass(WidgetSetClass).RemovePage(Self, APage.VisibleIndex);

View File

@ -1681,8 +1681,7 @@ begin
Result := True;
end;
end else begin
if (event^.Button=1) and
((TControl(Data) is TCustomNoteBook) or (TControl(Data) is TCustomTabControl)) then
if (event^.Button=1) and (TControl(Data) is TCustomNoteBook) then
begin
// clicks on the notebook should be handled by the gtk (switching page)
end
@ -1859,9 +1858,8 @@ begin
end else
begin
// stop the signal, so that the widget does not auto react
if (not (TControl(Data) is TCustomNoteBook)) and
(not (TControl(Data) is TCustomTabControl))
then begin
if not (TControl(Data) is TCustomNoteBook) then
begin
g_signal_stop_emission_by_name(PGTKObject(Widget), 'button-release-event');
Result := not CallBackDefaultReturn;
end;

View File

@ -1601,9 +1601,9 @@ begin
end;
end else begin
if (event^.Button=1) and
((TControl(Data) is TCustomNoteBook) or (TControl(Data) is TCustomTabControl)) then
(TControl(Data) is TCustomNoteBook) then
begin
// clicks on the notebook should be handled by the gtk (switching page)
// clicks on the tab control should be handled by the gtk (switching page)
end
else
begin
@ -1967,9 +1967,8 @@ begin
end else
begin
// stop the signal, so that the widget does not auto react
if (not (TControl(Data) is TCustomNoteBook)) and
(not (TControl(Data) is TCustomTabControl))
then begin
if not (TControl(Data) is TCustomNoteBook) then
begin
g_signal_stop_emission_by_name(PGTKObject(Widget), 'button-release-event');
Result := not CallBackDefaultReturn;
end;