Kaydet (Commit) b387a3fe authored tarafından Tomaž Vajngerl's avatar Tomaž Vajngerl

tabbar: use unique_ptr for buttons, sizer & clean-up

Change-Id: I4c479f0581e5fde7c3c2c21dcb2a88a2039e09ba
üst b03a9ae9
...@@ -315,13 +315,9 @@ class SVT_DLLPUBLIC TabBar : public vcl::Window ...@@ -315,13 +315,9 @@ class SVT_DLLPUBLIC TabBar : public vcl::Window
friend class ImplTabSizer; friend class ImplTabSizer;
private: private:
std::unique_ptr<TabBar_Impl> mpImpl;
ImplTabBarList* mpItemList; ImplTabBarList* mpItemList;
ImplTabButton* mpFirstBtn;
ImplTabButton* mpPrevBtn;
ImplTabButton* mpNextBtn;
ImplTabButton* mpLastBtn;
TabBar_Impl* mpImpl;
TabBarEdit* mpEdit;
OUString maEditText; OUString maEditText;
Color maSelColor; Color maSelColor;
Color maSelTextColor; Color maSelTextColor;
...@@ -461,7 +457,7 @@ public: ...@@ -461,7 +457,7 @@ public:
void EndEditMode( bool bCancel = false ); void EndEditMode( bool bCancel = false );
void SetEditText( const OUString& rText ) { maEditText = rText; } void SetEditText( const OUString& rText ) { maEditText = rText; }
const OUString& GetEditText() const { return maEditText; } const OUString& GetEditText() const { return maEditText; }
bool IsInEditMode() const { return (mpEdit != NULL); } bool IsInEditMode() const;
bool IsEditModeCanceled() const { return mbEditCanceled; } bool IsEditModeCanceled() const { return mbEditCanceled; }
sal_uInt16 GetEditPageId() const { return mnEditId; } sal_uInt16 GetEditPageId() const { return mnEditId; }
......
...@@ -352,17 +352,23 @@ IMPL_LINK_NOARG(TabBarEdit, ImplEndTimerHdl) ...@@ -352,17 +352,23 @@ IMPL_LINK_NOARG(TabBarEdit, ImplEndTimerHdl)
struct TabBar_Impl struct TabBar_Impl
{ {
ImplTabSizer* mpSizer; std::unique_ptr<ImplTabSizer> mpSizer;
::svt::AccessibleFactoryAccess maAccessibleFactory; std::unique_ptr<ImplTabButton> mpFirstButton;
std::unique_ptr<ImplTabButton> mpPrevButton;
std::unique_ptr<ImplTabButton> mpNextButton;
std::unique_ptr<ImplTabButton> mpLastButton;
std::unique_ptr<TabBarEdit> mpEdit;
svt::AccessibleFactoryAccess maAccessibleFactory;
TabBar_Impl() TabBar_Impl()
:mpSizer( NULL ) : mpSizer()
{ , mpFirstButton()
} , mpPrevButton()
~TabBar_Impl() , mpNextButton()
{ , mpLastButton()
delete mpSizer; , mpEdit()
} {}
}; };
...@@ -373,13 +379,9 @@ const sal_uInt16 TabBar::INSERT_TAB_POS = ::std::numeric_limits<sal_uInt16>::max ...@@ -373,13 +379,9 @@ const sal_uInt16 TabBar::INSERT_TAB_POS = ::std::numeric_limits<sal_uInt16>::max
void TabBar::ImplInit( WinBits nWinStyle ) void TabBar::ImplInit( WinBits nWinStyle )
{ {
mpImpl.reset(new TabBar_Impl);
mpItemList = new ImplTabBarList; mpItemList = new ImplTabBarList;
mpFirstBtn = NULL;
mpPrevBtn = NULL;
mpNextBtn = NULL;
mpLastBtn = NULL;
mpImpl = new TabBar_Impl;
mpEdit = NULL;
mnMaxPageWidth = 0; mnMaxPageWidth = 0;
mnCurMaxWidth = 0; mnCurMaxWidth = 0;
mnOffX = 0; mnOffX = 0;
...@@ -412,14 +414,14 @@ void TabBar::ImplInit( WinBits nWinStyle ) ...@@ -412,14 +414,14 @@ void TabBar::ImplInit( WinBits nWinStyle )
ImplInitControls(); ImplInitControls();
if(mpFirstBtn) if (mpImpl->mpFirstButton)
mpFirstBtn->SetAccessibleName(SVT_RESSTR(STR_TABBAR_PUSHBUTTON_MOVET0HOME)); mpImpl->mpFirstButton->SetAccessibleName(SVT_RESSTR(STR_TABBAR_PUSHBUTTON_MOVET0HOME));
if(mpPrevBtn) if (mpImpl->mpPrevButton)
mpPrevBtn->SetAccessibleName(SVT_RESSTR(STR_TABBAR_PUSHBUTTON_MOVELEFT)); mpImpl->mpPrevButton->SetAccessibleName(SVT_RESSTR(STR_TABBAR_PUSHBUTTON_MOVELEFT));
if(mpNextBtn) if (mpImpl->mpNextButton)
mpNextBtn->SetAccessibleName(SVT_RESSTR(STR_TABBAR_PUSHBUTTON_MOVERIGHT)); mpImpl->mpNextButton->SetAccessibleName(SVT_RESSTR(STR_TABBAR_PUSHBUTTON_MOVERIGHT));
if(mpLastBtn) if (mpImpl->mpLastButton)
mpLastBtn->SetAccessibleName(SVT_RESSTR(STR_TABBAR_PUSHBUTTON_MOVETOEND)); mpImpl->mpLastButton->SetAccessibleName(SVT_RESSTR(STR_TABBAR_PUSHBUTTON_MOVETOEND));
SetSizePixel( Size( 100, CalcWindowSizePixel().Height() ) ); SetSizePixel( Size( 100, CalcWindowSizePixel().Height() ) );
ImplInitSettings( true, true ); ImplInitSettings( true, true );
...@@ -440,17 +442,6 @@ TabBar::~TabBar() ...@@ -440,17 +442,6 @@ TabBar::~TabBar()
{ {
EndEditMode( true ); EndEditMode( true );
// Controls loeschen
if ( mpPrevBtn )
delete mpPrevBtn;
if ( mpNextBtn )
delete mpNextBtn;
if ( mpFirstBtn )
delete mpFirstBtn;
if ( mpLastBtn )
delete mpLastBtn;
delete mpImpl;
for ( size_t i = 0, n = mpItemList->size(); i < n; ++i ) { for ( size_t i = 0, n = mpItemList->size(); i < n; ++i ) {
delete (*mpItemList)[ i ]; delete (*mpItemList)[ i ];
} }
...@@ -689,63 +680,65 @@ void TabBar::ImplInitControls() ...@@ -689,63 +680,65 @@ void TabBar::ImplInitControls()
{ {
if ( mnWinStyle & WB_SIZEABLE ) if ( mnWinStyle & WB_SIZEABLE )
{ {
if ( !mpImpl->mpSizer ) if (!mpImpl->mpSizer)
mpImpl->mpSizer = new ImplTabSizer( this, mnWinStyle & (WB_DRAG | WB_3DLOOK) ); {
mpImpl->mpSizer.reset(new ImplTabSizer( this, mnWinStyle & (WB_DRAG | WB_3DLOOK)));
}
mpImpl->mpSizer->Show(); mpImpl->mpSizer->Show();
} }
else else
{ {
DELETEZ( mpImpl->mpSizer ); mpImpl->mpSizer.reset();
} }
Link aLink = LINK( this, TabBar, ImplClickHdl ); Link aLink = LINK( this, TabBar, ImplClickHdl );
if ( mnWinStyle & (WB_MINSCROLL | WB_SCROLL) ) if ( mnWinStyle & (WB_MINSCROLL | WB_SCROLL) )
{ {
if ( !mpPrevBtn ) if (!mpImpl->mpPrevButton)
{ {
mpPrevBtn = new ImplTabButton( this, WB_REPEAT ); mpImpl->mpPrevButton.reset(new ImplTabButton(this, WB_REPEAT));
mpPrevBtn->SetClickHdl( aLink ); mpImpl->mpPrevButton->SetClickHdl(aLink);
} }
mpPrevBtn->SetSymbol( mbMirrored ? SymbolType::NEXT : SymbolType::PREV ); mpImpl->mpPrevButton->SetSymbol(mbMirrored ? SymbolType::NEXT : SymbolType::PREV);
mpPrevBtn->Show(); mpImpl->mpPrevButton->Show();
if ( !mpNextBtn ) if (!mpImpl->mpNextButton)
{ {
mpNextBtn = new ImplTabButton( this, WB_REPEAT ); mpImpl->mpNextButton.reset(new ImplTabButton(this, WB_REPEAT));
mpNextBtn->SetClickHdl( aLink ); mpImpl->mpNextButton->SetClickHdl(aLink);
} }
mpNextBtn->SetSymbol( mbMirrored ? SymbolType::PREV : SymbolType::NEXT ); mpImpl->mpNextButton->SetSymbol(mbMirrored ? SymbolType::PREV : SymbolType::NEXT);
mpNextBtn->Show(); mpImpl->mpNextButton->Show();
} }
else else
{ {
DELETEZ( mpPrevBtn ); mpImpl->mpPrevButton.reset();
DELETEZ( mpNextBtn ); mpImpl->mpNextButton.reset();
} }
if ( mnWinStyle & WB_SCROLL ) if ( mnWinStyle & WB_SCROLL )
{ {
if ( !mpFirstBtn ) if (!mpImpl->mpFirstButton)
{ {
mpFirstBtn = new ImplTabButton( this ); mpImpl->mpFirstButton.reset(new ImplTabButton(this));
mpFirstBtn->SetClickHdl( aLink ); mpImpl->mpFirstButton->SetClickHdl(aLink);
} }
mpFirstBtn->SetSymbol( mbMirrored ? SymbolType::LAST : SymbolType::FIRST ); mpImpl->mpFirstButton->SetSymbol(mbMirrored ? SymbolType::LAST : SymbolType::FIRST);
mpFirstBtn->Show(); mpImpl->mpFirstButton->Show();
if ( !mpLastBtn ) if (!mpImpl->mpLastButton)
{ {
mpLastBtn = new ImplTabButton( this ); mpImpl->mpLastButton.reset(new ImplTabButton(this));
mpLastBtn->SetClickHdl( aLink ); mpImpl->mpLastButton->SetClickHdl(aLink);
} }
mpLastBtn->SetSymbol( mbMirrored ? SymbolType::FIRST : SymbolType::LAST ); mpImpl->mpLastButton->SetSymbol(mbMirrored ? SymbolType::FIRST : SymbolType::LAST);
mpLastBtn->Show(); mpImpl->mpLastButton->Show();
} }
else else
{ {
DELETEZ( mpFirstBtn ); mpImpl->mpFirstButton.reset();
DELETEZ( mpLastBtn ); mpImpl->mpLastButton.reset();
} }
mbHasInsertTab = (mnWinStyle & WB_INSERTTAB); mbHasInsertTab = (mnWinStyle & WB_INSERTTAB);
...@@ -760,16 +753,16 @@ void TabBar::ImplEnableControls() ...@@ -760,16 +753,16 @@ void TabBar::ImplEnableControls()
// enable/disable buttons // enable/disable buttons
bool bEnableBtn = mbScrollAlwaysEnabled || mnFirstPos > 0; bool bEnableBtn = mbScrollAlwaysEnabled || mnFirstPos > 0;
if ( mpFirstBtn ) if (mpImpl->mpFirstButton)
mpFirstBtn->Enable( bEnableBtn ); mpImpl->mpFirstButton->Enable(bEnableBtn);
if ( mpPrevBtn ) if (mpImpl->mpPrevButton)
mpPrevBtn->Enable( bEnableBtn ); mpImpl->mpPrevButton->Enable(bEnableBtn);
bEnableBtn = mbScrollAlwaysEnabled || mnFirstPos < ImplGetLastFirstPos(); bEnableBtn = mbScrollAlwaysEnabled || mnFirstPos < ImplGetLastFirstPos();
if ( mpNextBtn ) if (mpImpl->mpNextButton)
mpNextBtn->Enable( bEnableBtn ); mpImpl->mpNextButton->Enable(bEnableBtn);
if ( mpLastBtn ) if (mpImpl->mpLastButton)
mpLastBtn->Enable( bEnableBtn ); mpImpl->mpLastButton->Enable(bEnableBtn);
} }
void TabBar::SetScrollAlwaysEnabled(bool bScrollAlwaysEnabled) void TabBar::SetScrollAlwaysEnabled(bool bScrollAlwaysEnabled)
...@@ -808,22 +801,22 @@ IMPL_LINK( TabBar, ImplClickHdl, ImplTabButton*, pBtn ) ...@@ -808,22 +801,22 @@ IMPL_LINK( TabBar, ImplClickHdl, ImplTabButton*, pBtn )
sal_uInt16 nNewPos = mnFirstPos; sal_uInt16 nNewPos = mnFirstPos;
if (pBtn == mpFirstBtn || (pBtn == mpPrevBtn && pBtn->isModKeyPressed())) if (pBtn == mpImpl->mpFirstButton.get() || (pBtn == mpImpl->mpPrevButton.get() && pBtn->isModKeyPressed()))
{ {
nNewPos = 0; nNewPos = 0;
} }
else if (pBtn == mpLastBtn || (pBtn == mpNextBtn && pBtn->isModKeyPressed())) else if (pBtn == mpImpl->mpLastButton.get() || (pBtn == mpImpl->mpNextButton.get() && pBtn->isModKeyPressed()))
{ {
sal_uInt16 nCount = GetPageCount(); sal_uInt16 nCount = GetPageCount();
if (nCount) if (nCount)
nNewPos = nCount - 1; nNewPos = nCount - 1;
} }
else if (pBtn == mpPrevBtn) else if (pBtn == mpImpl->mpPrevButton.get())
{ {
if (mnFirstPos) if (mnFirstPos)
nNewPos = mnFirstPos - 1; nNewPos = mnFirstPos - 1;
} }
else if (pBtn == mpNextBtn) else if (pBtn == mpImpl->mpNextButton.get())
{ {
sal_uInt16 nCount = GetPageCount(); sal_uInt16 nCount = GetPageCount();
if (mnFirstPos < nCount) if (mnFirstPos < nCount)
...@@ -1418,27 +1411,27 @@ void TabBar::Resize() ...@@ -1418,27 +1411,27 @@ void TabBar::Resize()
nButtonWidth += nButtonMargin; nButtonWidth += nButtonMargin;
Size aBtnSize( nHeight, nHeight ); Size aBtnSize( nHeight, nHeight );
if ( mpFirstBtn ) if (mpImpl->mpFirstButton)
{ {
mpFirstBtn->SetPosSizePixel( Point( nX, 0 ), aBtnSize ); mpImpl->mpFirstButton->SetPosSizePixel( Point( nX, 0 ), aBtnSize );
nX += nXDiff; nX += nXDiff;
nButtonWidth += nHeight; nButtonWidth += nHeight;
} }
if ( mpPrevBtn ) if (mpImpl->mpPrevButton)
{ {
mpPrevBtn->SetPosSizePixel( Point( nX, 0 ), aBtnSize ); mpImpl->mpPrevButton->SetPosSizePixel( Point( nX, 0 ), aBtnSize );
nX += nXDiff; nX += nXDiff;
nButtonWidth += nHeight; nButtonWidth += nHeight;
} }
if ( mpNextBtn ) if (mpImpl->mpNextButton)
{ {
mpNextBtn->SetPosSizePixel( Point( nX, 0 ), aBtnSize ); mpImpl->mpNextButton->SetPosSizePixel( Point( nX, 0 ), aBtnSize );
nX += nXDiff; nX += nXDiff;
nButtonWidth += nHeight; nButtonWidth += nHeight;
} }
if ( mpLastBtn ) if (mpImpl->mpLastButton)
{ {
mpLastBtn->SetPosSizePixel( Point( nX, 0 ), aBtnSize ); mpImpl->mpLastButton->SetPosSizePixel( Point( nX, 0 ), aBtnSize );
nX += nXDiff; nX += nXDiff;
nButtonWidth += nHeight; nButtonWidth += nHeight;
} }
...@@ -1604,12 +1597,18 @@ void TabBar::StateChanged( StateChangedType nType ) ...@@ -1604,12 +1597,18 @@ void TabBar::StateChanged( StateChangedType nType )
else if ( nType == StateChangedType::MIRRORING ) else if ( nType == StateChangedType::MIRRORING )
{ {
// reacts on calls of EnableRTL, have to mirror all child controls // reacts on calls of EnableRTL, have to mirror all child controls
if( mpFirstBtn ) mpFirstBtn->EnableRTL( IsRTLEnabled() ); if (mpImpl->mpFirstButton)
if( mpPrevBtn ) mpPrevBtn->EnableRTL( IsRTLEnabled() ); mpImpl->mpFirstButton->EnableRTL(IsRTLEnabled());
if( mpNextBtn ) mpNextBtn->EnableRTL( IsRTLEnabled() ); if (mpImpl->mpPrevButton)
if( mpLastBtn ) mpLastBtn->EnableRTL( IsRTLEnabled() ); mpImpl->mpPrevButton->EnableRTL(IsRTLEnabled());
if( mpImpl->mpSizer ) mpImpl->mpSizer->EnableRTL( IsRTLEnabled() ); if (mpImpl->mpNextButton)
if( mpEdit ) mpEdit->EnableRTL( IsRTLEnabled() ); mpImpl->mpNextButton->EnableRTL(IsRTLEnabled());
if (mpImpl->mpLastButton)
mpImpl->mpLastButton->EnableRTL(IsRTLEnabled());
if (mpImpl->mpSizer)
mpImpl->mpSizer->EnableRTL(IsRTLEnabled());
if (mpImpl->mpEdit)
mpImpl->mpEdit->EnableRTL(IsRTLEnabled());
} }
} }
...@@ -2271,7 +2270,7 @@ bool TabBar::IsPageSelected( sal_uInt16 nPageId ) const ...@@ -2271,7 +2270,7 @@ bool TabBar::IsPageSelected( sal_uInt16 nPageId ) const
bool TabBar::StartEditMode( sal_uInt16 nPageId ) bool TabBar::StartEditMode( sal_uInt16 nPageId )
{ {
sal_uInt16 nPos = GetPagePos( nPageId ); sal_uInt16 nPos = GetPagePos( nPageId );
if ( mpEdit || (nPos == PAGE_NOT_FOUND) || (mnLastOffX < 8) ) if (mpImpl->mpEdit || (nPos == PAGE_NOT_FOUND) || (mnLastOffX < 8))
return false; return false;
mnEditId = nPageId; mnEditId = nPageId;
...@@ -2281,7 +2280,7 @@ bool TabBar::StartEditMode( sal_uInt16 nPageId ) ...@@ -2281,7 +2280,7 @@ bool TabBar::StartEditMode( sal_uInt16 nPageId )
ImplFormat(); ImplFormat();
Update(); Update();
mpEdit = new TabBarEdit( this, WB_CENTER ); mpImpl->mpEdit.reset(new TabBarEdit(this, WB_CENTER));
Rectangle aRect = GetPageRect( mnEditId ); Rectangle aRect = GetPageRect( mnEditId );
long nX = aRect.Left(); long nX = aRect.Left();
long nWidth = aRect.GetWidth(); long nWidth = aRect.GetWidth();
...@@ -2294,8 +2293,8 @@ bool TabBar::StartEditMode( sal_uInt16 nPageId ) ...@@ -2294,8 +2293,8 @@ bool TabBar::StartEditMode( sal_uInt16 nPageId )
nX = aRect.Left(); nX = aRect.Left();
nWidth = aRect.GetWidth(); nWidth = aRect.GetWidth();
} }
mpEdit->SetText( GetPageText( mnEditId ) ); mpImpl->mpEdit->SetText(GetPageText(mnEditId));
mpEdit->setPosSizePixel( nX, aRect.Top()+mnOffY+1, nWidth, aRect.GetHeight()-3 ); mpImpl->mpEdit->setPosSizePixel(nX, aRect.Top() + mnOffY + 1, nWidth, aRect.GetHeight() - 3);
vcl::Font aFont = GetPointFont(); vcl::Font aFont = GetPointFont();
Color aForegroundColor; Color aForegroundColor;
Color aBackgroundColor; Color aBackgroundColor;
...@@ -2318,12 +2317,12 @@ bool TabBar::StartEditMode( sal_uInt16 nPageId ) ...@@ -2318,12 +2317,12 @@ bool TabBar::StartEditMode( sal_uInt16 nPageId )
} }
if ( GetPageBits( mnEditId ) & TPB_SPECIAL ) if ( GetPageBits( mnEditId ) & TPB_SPECIAL )
aForegroundColor = Color( COL_LIGHTBLUE ); aForegroundColor = Color( COL_LIGHTBLUE );
mpEdit->SetControlFont( aFont ); mpImpl->mpEdit->SetControlFont(aFont);
mpEdit->SetControlForeground( aForegroundColor ); mpImpl->mpEdit->SetControlForeground(aForegroundColor);
mpEdit->SetControlBackground( aBackgroundColor ); mpImpl->mpEdit->SetControlBackground(aBackgroundColor);
mpEdit->GrabFocus(); mpImpl->mpEdit->GrabFocus();
mpEdit->SetSelection( Selection( 0, mpEdit->GetText().getLength() ) ); mpImpl->mpEdit->SetSelection(Selection(0, mpImpl->mpEdit->GetText().getLength()));
mpEdit->Show(); mpImpl->mpEdit->Show();
return true; return true;
} }
else else
...@@ -2333,17 +2332,20 @@ bool TabBar::StartEditMode( sal_uInt16 nPageId ) ...@@ -2333,17 +2332,20 @@ bool TabBar::StartEditMode( sal_uInt16 nPageId )
} }
} }
bool TabBar::IsInEditMode() const
{
return mpImpl->mpEdit.get() != NULL;
}
void TabBar::EndEditMode( bool bCancel ) void TabBar::EndEditMode( bool bCancel )
{ {
if ( mpEdit ) if (mpImpl->mpEdit)
{ {
// call hdl // call hdl
bool bEnd = true; bool bEnd = true;
mbEditCanceled = bCancel; mbEditCanceled = bCancel;
maEditText = mpEdit->GetText(); maEditText = mpImpl->mpEdit->GetText();
mpEdit->SetPostEvent(); mpImpl->mpEdit->SetPostEvent();
if ( !bCancel ) if ( !bCancel )
{ {
TabBarAllowRenamingReturnCode nAllowRenaming = AllowRenaming(); TabBarAllowRenamingReturnCode nAllowRenaming = AllowRenaming();
...@@ -2358,14 +2360,13 @@ void TabBar::EndEditMode( bool bCancel ) ...@@ -2358,14 +2360,13 @@ void TabBar::EndEditMode( bool bCancel )
// renaming not allowed, than reset edit data // renaming not allowed, than reset edit data
if ( !bEnd ) if ( !bEnd )
{ {
mpEdit->ResetPostEvent(); mpImpl->mpEdit->ResetPostEvent();
mpEdit->GrabFocus(); mpImpl->mpEdit->GrabFocus();
} }
else else
{ {
// close edit and call end hdl // close edit and call end hdl
delete mpEdit; mpImpl->mpEdit.reset();
mpEdit = NULL;
EndRenaming(); EndRenaming();
mnEditId = 0; mnEditId = 0;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment