summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGraeme Geldenhuys <graeme@mastermaths.co.za>2011-01-13 12:53:47 +0200
committerGraeme Geldenhuys <graeme@mastermaths.co.za>2011-01-13 12:53:47 +0200
commit8bb4ab508334b8a7c9c68c82feb8e624461ce371 (patch)
treeb7b903e7e2a74113c547d539295502c07ee767c0 /src
parent0764f8fa4732c086562699e39211468ff7337ab7 (diff)
downloadfpGUI-8bb4ab508334b8a7c9c68c82feb8e624461ce371.tar.xz
tabs: When creating tabsheets, there sizes are immediately calculated.
* A new constructor was also added where you can pass the tabsheet title, so tabsheet size can be better calculated if tabs are set to Left or Right.
Diffstat (limited to 'src')
-rw-r--r--src/gui/fpg_tab.pas115
1 files changed, 108 insertions, 7 deletions
diff --git a/src/gui/fpg_tab.pas b/src/gui/fpg_tab.pas
index ab9ee9e0..57aac086 100644
--- a/src/gui/fpg_tab.pas
+++ b/src/gui/fpg_tab.pas
@@ -66,7 +66,9 @@ type
procedure SetName(const NewName: TComponentName); override;
public
constructor Create(AOwner: TComponent); override;
+ constructor CreateWithTitle(AOwner: TComponent; const AText: TfpgString = ''); virtual;
destructor Destroy; override;
+ procedure AfterConstruction; override;
property PageIndex: Integer read GetPageIndex write SetPageIndex;
property PageControl: TfpgPageControl read FPageControl write SetPageControl;
property TabVisible: boolean read FTabVisible write FTabVisible;
@@ -106,10 +108,12 @@ type
function GetActivePageIndex: integer;
function GetPage(AIndex: integer): TfpgTabSheet;
function GetPageCount: Integer;
- procedure InsertPage(const APage: TfpgTabSheet; SuppressOnChangeEvent: boolean = False);
+ procedure InsertPage(var APage: TfpgTabSheet; SuppressOnChangeEvent: boolean = False);
procedure RemovePage(const APage: TfpgTabSheet);
procedure SetActivePageIndex(const AValue: integer);
procedure SetActivePage(const AValue: TfpgTabSheet);
+ procedure PositionTabSheets;
+ procedure PositionTabSheet(var APage: TfpgTabSheet);
function MaxButtonWidthSum: integer;
function MaxButtonHeightSum: integer;
function MaxButtonWidth: integer;
@@ -252,11 +256,12 @@ begin
FBackgroundColor := Parent.BackgroundColor;
FTextColor := Parent.TextColor;
FIsContainer := True;
- if (AOwner <> nil) and (AOwner is TfpgPageControl) then
- begin
- FPageControl:=TfpgPageControl(AOwner);
- FPageControl.InsertPage(self, True);
- end;
+end;
+
+constructor TfpgTabSheet.CreateWithTitle(AOwner: TComponent; const AText: TfpgString);
+begin
+ Create(AOwner);
+ FText := AText;
end;
destructor TfpgTabSheet.Destroy;
@@ -266,6 +271,16 @@ begin
inherited Destroy;
end;
+procedure TfpgTabSheet.AfterConstruction;
+begin
+ if (Owner <> nil) and (Owner is TfpgPageControl) then
+ begin
+ FPageControl:=TfpgPageControl(Owner);
+ FPageControl.InsertPage(self, True);
+ end;
+ inherited AfterConstruction;
+end;
+
procedure TfpgTabSheet.SetPageControl(APageControl: TfpgPageControl);
begin
FPageControl := APageControl;
@@ -293,11 +308,12 @@ begin
Result := FPages.Count;
end;
-procedure TfpgPageControl.InsertPage(const APage: TfpgTabSheet; SuppressOnChangeEvent: boolean = False);
+procedure TfpgPageControl.InsertPage(var APage: TfpgTabSheet; SuppressOnChangeEvent: boolean = False);
begin
if FPages.IndexOf(APage) <> -1 then
Exit; //==> The page has already been added.
FPages.Add(APage);
+ PositionTabSheets;
{ TODO: This behaviour could maybe be controlled by a Options property }
if FPages.Count=1 then
begin
@@ -365,6 +381,91 @@ begin
DoPageChange(FActivePage);
end;
+procedure TfpgPageControl.PositionTabSheets;
+var
+ i: integer;
+ t: TfpgTabSheet;
+begin
+ for i := 0 to FPages.Count-1 do
+ begin
+ t := TfpgTabSheet(FPages[i]);
+ PositionTabSheet(t);
+ t.Anchors := [anLeft, anTop, anRight, anBottom];
+ end;
+end;
+
+procedure TfpgPageControl.PositionTabSheet(var APage: TfpgTabSheet);
+var
+ r: TRect;
+ w: integer;
+ wd: integer; { width delta }
+ h: integer;
+ hd: integer; { height delta }
+ msg: TfpgMessageParams;
+begin
+ // PageControl has bevelled edges in some themes
+ r := fpgStyle.GetControlFrameBorders;
+
+ { Calculate and set Width and Height }
+ if TabPosition in [tpTop, tpBottom] then
+ begin
+ w := Width - (FMargin*2) - r.Left - r.Right;
+ wd := APage.Width - w;
+ APage.Width := w;
+ h := Height - ButtonHeight - (FMargin*2) - r.Top - r.Bottom;
+ hd := APage.Height - h;
+ APage.Height := h;
+ end
+ else if TabPosition in [tpLeft, tpRight] then
+ begin
+ w := Width - MaxButtonWidth - (FMargin*2) - r.Left - r.Right;
+ wd := APage.Width - w;
+ APage.Width := w;
+ h := Height - (FMargin*2) - r.Top - r.Bottom;
+ hd := APage.Height - h;
+ APage.Height := h;
+ end
+ else
+ begin // tpNone
+ w := Width - (FMargin*2) - r.Left - r.Right;
+ wd := APage.Width - w;
+ APage.Width := w;
+ h := Height - (FMargin*2) - r.Top - r.Bottom;
+ hd := APage.Height - h;
+ APage.Height := h;
+ end;
+
+ { Calculate and set Top and Left }
+ if TabPosition = tpTop then
+ begin
+ APage.Left := FMargin + r.Left;
+ APage.Top := ButtonHeight + FMargin + r.Top;
+ end
+ else if TabPosition = tpBottom then
+ begin
+ APage.Left := FMargin + r.Left;
+ APage.Top := FMargin + r.Top;
+ end
+ else if TabPosition = tpLeft then
+ begin
+ APage.Left := MaxButtonWidth + FMargin + r.Left;
+ APage.Top := FMargin + r.Top;
+ end
+ else if TabPosition = tpRight then
+ begin
+ APage.Left := FMargin + r.Left;
+ APage.Top := FMargin + r.Top;
+ end;
+
+ if TabPosition in [tpNone] then
+ begin
+ APage.Left := FMargin + r.Left;
+ APage.Top := FMargin + r.Top;
+ end;
+
+ APage.UpdateWindowPosition; { Internal state is now resolved }
+end;
+
function TfpgPageControl.MaxButtonWidthSum: integer;
var
i: integer;