Carbon LCL: improved TPageControl page removing a bit

git-svn-id: trunk@14132 -
This commit is contained in:
tombo 2008-02-14 12:17:01 +00:00
parent e533a2bb89
commit d52b3b49a7
2 changed files with 78 additions and 47 deletions

View File

@ -80,8 +80,12 @@ type
function GetContent: ControlRef; override; function GetContent: ControlRef; override;
procedure ShowTab; procedure ShowTab;
procedure UpdateTabs(EnsureLastVisible: Boolean = False); procedure UpdateTabs(EnsureLastVisible: Boolean = False; UpdateIndex: Boolean = True);
procedure UpdateTabIndex;
procedure Remove(ATab: TCarbonTab); procedure Remove(ATab: TCarbonTab);
function GetControlTabIndex: Integer;
function GetTabIndex(APageIndex: Integer): Integer;
function TabIndexToPageIndex(AIndex: Integer): Integer;
public public
class function GetValidEvents: TCarbonControlEvents; override; class function GetValidEvents: TCarbonControlEvents; override;
procedure ValueChanged; override; procedure ValueChanged; override;
@ -98,7 +102,7 @@ type
procedure Add(ATab: TCarbonTab; AIndex: Integer); procedure Add(ATab: TCarbonTab; AIndex: Integer);
procedure Remove(AIndex: Integer); procedure Remove(AIndex: Integer);
procedure SetTabIndex(AIndex: Integer); procedure SetPageIndex(AIndex: Integer);
procedure ShowTabs(AShow: Boolean); procedure ShowTabs(AShow: Boolean);
procedure SetTabPosition(ATabPosition: TTabPosition); procedure SetTabPosition(ATabPosition: TTabPosition);
end; end;
@ -132,7 +136,7 @@ end;
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
procedure TCarbonTab.DestroyWidget; procedure TCarbonTab.DestroyWidget;
begin begin
FParent.Remove(Self); if FParent <> nil then FParent.Remove(Self);
inherited DestroyWidget; inherited DestroyWidget;
end; end;
@ -168,9 +172,9 @@ end;
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
function TCarbonTab.SetText(const S: String): Boolean; function TCarbonTab.SetText(const S: String): Boolean;
begin begin
FText := S;
if FParent = nil then Exit; if FParent = nil then Exit;
FText := S;
Result := False; Result := False;
FParent.UpdateTabs; FParent.UpdateTabs;
Result := True; Result := True;
@ -383,20 +387,18 @@ procedure TCarbonTabsControl.ShowTab;
var var
I: Integer; I: Integer;
R: TRect; R: TRect;
Page: TCustomPage;
begin begin
// show tab with FTabIndex, hide the others // show tab with FTabIndex, hide the others
for I := 0 to FTabs.Count - 1 do for I := 0 to FTabs.Count - 1 do
begin begin
Page := TCarbonTab(FTabs[I]).LCLObject as TCustomPage; if I = FTabIndex then // update tab bounds
if Page.PageIndex = FTabIndex then // update tab bounds
begin begin
GetClientRect(R); GetClientRect(R);
OffsetRect(R, -R.Left, -R.Top); OffsetRect(R, -R.Left, -R.Top);
TCarbonTab(FTabs[I]).SetBounds(R); TCarbonTab(FTabs[I]).SetBounds(R);
end; end;
TCarbonTab(FTabs[I]).ShowHide(Page.PageIndex = FTabIndex); TCarbonTab(FTabs[I]).ShowHide(I = FTabIndex);
end; end;
end; end;
@ -405,7 +407,7 @@ end;
Updates tabs properties Updates tabs properties
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
procedure TCarbonTabsControl.UpdateTabs(EnsureLastVisible: Boolean); procedure TCarbonTabsControl.UpdateTabs(EnsureLastVisible: Boolean; UpdateIndex: Boolean = True);
var var
I, L: Integer; I, L: Integer;
TabSizes: Array of Integer; TabSizes: Array of Integer;
@ -414,7 +416,6 @@ var
ControlSize: Integer; ControlSize: Integer;
TempFont: TCarbonFont; TempFont: TCarbonFont;
TabInfo: ControlTabInfoRecV1; TabInfo: ControlTabInfoRecV1;
ControlIndex: Integer;
const const
SName = 'UpdateTabs'; SName = 'UpdateTabs';
begin begin
@ -426,8 +427,8 @@ begin
SetControl32BitMaximum(ControlRef(Widget), 0); SetControl32BitMaximum(ControlRef(Widget), 0);
UpdateTabIndex;
// set tab count // set tab count
ControlIndex := 0;
Exit; Exit;
end; end;
@ -487,8 +488,6 @@ begin
end end
else Break; else Break;
end; end;
end end
else else
begin begin
@ -525,10 +524,6 @@ begin
// set tab count // set tab count
SetControl32BitMaximum(ControlRef(Widget), FLastIndex - FFirstIndex + 1); SetControl32BitMaximum(ControlRef(Widget), FLastIndex - FFirstIndex + 1);
ControlIndex := 0;
if FTabIndex < FFirstIndex then FTabIndex := FFirstIndex
else
if FTabIndex > FLastIndex then FTabIndex := FLastIndex;
// update tabs // update tabs
TabInfo.version := kControlTabInfoVersionOne; TabInfo.version := kControlTabInfoVersionOne;
TabInfo.iconSuiteID := 0; TabInfo.iconSuiteID := 0;
@ -537,8 +532,6 @@ begin
for I := FFirstIndex to FLastIndex do for I := FFirstIndex to FLastIndex do
begin begin
S := TCarbonTab(FTabs[I]).FText; S := TCarbonTab(FTabs[I]).FText;
if (TCarbonTab(FTabs[I]).LCLObject as TCustomPage).PageIndex = FTabIndex then
ControlIndex := I - FFirstIndex + 1;
DeleteAmpersands(S); DeleteAmpersands(S);
CreateCFString(S, TabInfo.name); CreateCFString(S, TabInfo.name);
@ -552,17 +545,21 @@ begin
end; end;
finally finally
// set tab index
SetControl32BitValue(ControlRef(Widget), ControlIndex);
ValueChanged;
// update arrows visible // update arrows visible
OSError(HIViewSetVisible(FPrevArrow, FFirstIndex > 0), Self, SName, SViewVisible); OSError(HIViewSetVisible(FPrevArrow, FFirstIndex > 0), Self, SName, SViewVisible);
OSError(HIViewSetVisible(FNextArrow, FLastIndex < FTabs.Count - 1), Self, SName, SViewVisible); OSError(HIViewSetVisible(FNextArrow, FLastIndex < FTabs.Count - 1), Self, SName, SViewVisible);
if UpdateIndex then UpdateTabIndex;
end;
end;
procedure TCarbonTabsControl.UpdateTabIndex;
begin
// set tab index
SetControl32BitValue(ControlRef(Widget), GetControlTabIndex);
Invalidate; Invalidate;
ShowTab; ShowTab;
end; end;
end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
Method: TCarbonTabsControl.Remove Method: TCarbonTabsControl.Remove
@ -572,9 +569,45 @@ end;
procedure TCarbonTabsControl.Remove(ATab: TCarbonTab); procedure TCarbonTabsControl.Remove(ATab: TCarbonTab);
begin begin
FTabs.Remove(ATab); FTabs.Remove(ATab);
UpdateTabs; UpdateTabs(False, False);
end; end;
function TCarbonTabsControl.GetControlTabIndex: Integer;
begin
Result := FTabIndex - FFirstIndex + 1;
end;
function TCarbonTabsControl.GetTabIndex(APageIndex: Integer): Integer;
var
I: Integer;
begin
Result := -1;
for I := 0 to FTabs.Count - 1 do
begin
if ((FTabs[I] as TCarbonTab).LCLObject as TCustomPage).PageIndex = APageIndex then
begin
Result := I;
Break;
end;
end;
end;
function TCarbonTabsControl.TabIndexToPageIndex(AIndex: Integer): Integer;
var
I: Integer;
begin
Result := AIndex;
if csDesigning in LCLObject.ComponentState then Exit;
I := 0;
while (I < (LCLObject as TCustomNotebook).PageCount) and (I <= Result) do
begin
if not (LCLObject as TCustomNotebook).Page[I].TabVisible then Inc(Result);
Inc(I);
end;
end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
Method: TCarbonTabsControl.GetValidEvents Method: TCarbonTabsControl.GetValidEvents
Returns: Set of events with installed handlers Returns: Set of events with installed handlers
@ -602,7 +635,7 @@ begin
FOldTabIndex := Index; FOldTabIndex := Index;
if (Index >= 0) and (Index < FTabs.Count) then if (Index >= 0) and (Index < FTabs.Count) then
PIndex := (TCarbonTab(FTabs[Index]).LCLObject as TCustomPage).PageIndex PIndex := TabIndexToPageIndex(Index)
else else
PIndex := -1; PIndex := -1;
@ -619,11 +652,11 @@ begin
if DeliverMessage(LCLObject, Msg) <> 0 then if DeliverMessage(LCLObject, Msg) <> 0 then
begin // tab change cancelled begin // tab change cancelled
SetTabIndex((LCLObject as TCustomNoteBook).PageIndex); SetPageIndex((LCLObject as TCustomNoteBook).PageIndex);
Exit; Exit;
end; end;
SetTabIndex(Index); SetPageIndex(Index);
// send change // send change
FillChar(Msg, SizeOf(TLMNotify), 0); FillChar(Msg, SizeOf(TLMNotify), 0);
@ -759,41 +792,39 @@ end;
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
procedure TCarbonTabsControl.Remove(AIndex: Integer); procedure TCarbonTabsControl.Remove(AIndex: Integer);
begin begin
//DebugLn('TCarbonTabsControl.Remove ' + DbgS(AIndex)); Remove(FTabs[AIndex] as TCarbonTab);
FTabs.Delete(AIndex);
UpdateTabs;
end; end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
Method: TCarbonTabsControl.SetTabIndex Method: TCarbonTabsControl.SetPageIndex
Params: AIndex - New index Params: AIndex - New index
Changes the current Carbon tab Changes the current Carbon page
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
procedure TCarbonTabsControl.SetTabIndex(AIndex: Integer); procedure TCarbonTabsControl.SetPageIndex(AIndex: Integer);
var
ATabIndex: Integer;
begin begin
if (AIndex < 0) or (AIndex >= FTabs.Count) then ATabIndex := GetTabIndex(AIndex);
//DebugLn('TCarbonTabsControl.SetPageIndex Page: ' + DbgS(AIndex) + ' Tab: ' + DbgS(ATabIndex));
if (ATabIndex < 0) or (ATabIndex >= FTabs.Count) then
begin begin
ATabIndex := -1;
SetControl32BitValue(ControlRef(Widget), 0); SetControl32BitValue(ControlRef(Widget), 0);
ShowTab; ShowTab;
Exit; Exit;
end; end;
//DebugLn('TCarbonTabsControl.SetTabIndex ' + DbgS(AIndex) + ' ' + DbgS((LCLObject as TCustomNotebook).PageCount)); FTabIndex := ATabIndex;
if (ATabIndex < FFirstIndex) or (ATabIndex > FLastIndex) then
FTabIndex := AIndex;
if (AIndex < FFirstIndex) or (AIndex > FLastIndex) then
begin begin
FFirstIndex := AIndex; FFirstIndex := ATabIndex;
UpdateTabs; UpdateTabs;
end end
else else
begin UpdateTabIndex;
SetControl32BitValue(ControlRef(Widget), FTabIndex - FFirstIndex + 1);
Invalidate;
ShowTab;
end;
end; end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------

View File

@ -321,7 +321,7 @@ class procedure TCarbonWSCustomNotebook.SetPageIndex(const ANotebook: TCustomNot
begin begin
if not CheckHandle(ANotebook, Self, 'SetPageIndex') then Exit; if not CheckHandle(ANotebook, Self, 'SetPageIndex') then Exit;
TCarbonTabsControl(ANotebook.Handle).SetTabIndex(AIndex); TCarbonTabsControl(ANotebook.Handle).SetPageIndex(AIndex);
end; end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------