diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2015-05-17 11:51:14 +0900 |
---|---|---|
committer | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2015-05-17 12:25:53 +0900 |
commit | e4164351dc311839f4a7eb2743be8af17592b8e5 (patch) | |
tree | 238d894fa2c4ec95052927de49db77a3d6277935 | |
parent | 6aab2eceaa386c14c2283631d3107cab7484f0f8 (diff) |
tabbar: use a button for adding of tabs, move button before tabs
Change-Id: I89fcf7427694ea6fc9468220bae639b221d9ec28
-rw-r--r-- | include/svtools/tabbar.hxx | 10 | ||||
-rw-r--r-- | sc/source/ui/inc/tabcont.hxx | 2 | ||||
-rw-r--r-- | sc/source/ui/view/tabcont.cxx | 40 | ||||
-rw-r--r-- | svtools/source/control/filectrl.src | 4 | ||||
-rw-r--r-- | svtools/source/control/tabbar.cxx | 69 | ||||
-rw-r--r-- | svtools/source/inc/filectrl.hrc | 9 |
6 files changed, 73 insertions, 61 deletions
diff --git a/include/svtools/tabbar.hxx b/include/svtools/tabbar.hxx index b1b692bf5d1d..2e071306c82c 100644 --- a/include/svtools/tabbar.hxx +++ b/include/svtools/tabbar.hxx @@ -374,16 +374,20 @@ private: SVT_DLLPRIVATE ImplTabBarItem* ImplGetLastTabBarItem( sal_uInt16 nItemCount ); SVT_DLLPRIVATE Rectangle ImplGetInsertTabRect(ImplTabBarItem* pItem) const; - DECL_DLLPRIVATE_LINK( ImplClickHdl, ImplTabButton* ); + DECL_DLLPRIVATE_LINK(ImplClickHdl, ImplTabButton*); + + DECL_DLLPRIVATE_LINK(ImplAddClickHandler, void*); ImplTabBarItem* seek( size_t i ); ImplTabBarItem* prev(); ImplTabBarItem* next(); +protected: + virtual void AddTabClick(); + public: static const sal_uInt16 APPEND; static const sal_uInt16 PAGE_NOT_FOUND; - static const sal_uInt16 INSERT_TAB_POS; TabBar( vcl::Window* pParent, WinBits nWinStyle = WB_STDTABBAR ); virtual ~TabBar(); @@ -429,7 +433,7 @@ public: sal_uInt16 GetPageCount() const; sal_uInt16 GetPageId( sal_uInt16 nPos ) const; sal_uInt16 GetPagePos( sal_uInt16 nPageId ) const; - sal_uInt16 GetPageId( const Point& rPos, bool bCheckInsTab = false ) const; + sal_uInt16 GetPageId( const Point& rPos ) const; Rectangle GetPageRect( sal_uInt16 nPageId ) const; // returns the rectangle in which page tabs are drawn Rectangle GetPageArea() const; diff --git a/sc/source/ui/inc/tabcont.hxx b/sc/source/ui/inc/tabcont.hxx index 3b0d687f201c..d1515c56b843 100644 --- a/sc/source/ui/inc/tabcont.hxx +++ b/sc/source/ui/inc/tabcont.hxx @@ -61,6 +61,8 @@ protected: virtual void EndRenaming() SAL_OVERRIDE; virtual void Mirror() SAL_OVERRIDE; + virtual void AddTabClick() SAL_OVERRIDE; + public: ScTabControl( vcl::Window* pParent, ScViewData* pData ); virtual ~ScTabControl(); diff --git a/sc/source/ui/view/tabcont.cxx b/sc/source/ui/view/tabcont.cxx index 7801b719c08b..1c19b55751bf 100644 --- a/sc/source/ui/view/tabcont.cxx +++ b/sc/source/ui/view/tabcont.cxx @@ -174,13 +174,8 @@ void ScTabControl::MouseButtonDown( const MouseEvent& rMEvt ) pViewData->GetView()->ActiveGrabFocus(); } - /* Click into free area -> insert new sheet (like in Draw). - Needing clean left click without modifiers (may be context menu). - Remember clicks to all pages, to be able to move mouse pointer later. */ - if( rMEvt.IsLeft() && (rMEvt.GetModifier() == 0) ) - nMouseClickPageId = GetPageId( rMEvt.GetPosPixel(), true ); - else - nMouseClickPageId = TabBar::PAGE_NOT_FOUND; + if (rMEvt.IsLeft() && rMEvt.GetModifier() == 0) + nMouseClickPageId = GetPageId(rMEvt.GetPosPixel()); TabBar::MouseButtonDown( rMEvt ); } @@ -190,23 +185,9 @@ void ScTabControl::MouseButtonUp( const MouseEvent& rMEvt ) Point aPos = PixelToLogic( rMEvt.GetPosPixel() ); // mouse button down and up on same page? - if( nMouseClickPageId != GetPageId( aPos, true ) ) + if( nMouseClickPageId != GetPageId(aPos)) nMouseClickPageId = TabBar::PAGE_NOT_FOUND; - if (nMouseClickPageId == TabBar::INSERT_TAB_POS) - { - // Insert a new sheet at the right end, with default name. - ScDocument* pDoc = pViewData->GetDocument(); - ScModule* pScMod = SC_MOD(); - if (!pDoc->IsDocEditable() || pScMod->IsTableLocked()) - return; - OUString aName; - pDoc->CreateValidTabName(aName); - SCTAB nTabCount = pDoc->GetTableCount(); - pViewData->GetViewShell()->InsertTable(aName, nTabCount); - return; - } - if ( rMEvt.GetClicks() == 2 && rMEvt.IsLeft() && nMouseClickPageId != 0 && nMouseClickPageId != TAB_PAGE_NOTFOUND ) { SfxDispatcher* pDispatcher = pViewData->GetViewShell()->GetViewFrame()->GetDispatcher(); @@ -229,6 +210,21 @@ void ScTabControl::MouseButtonUp( const MouseEvent& rMEvt ) TabBar::MouseButtonUp( rMEvt ); } +void ScTabControl::AddTabClick() +{ + TabBar::AddTabClick(); + + // Insert a new sheet at the right end, with default name. + ScDocument* pDoc = pViewData->GetDocument(); + ScModule* pScMod = SC_MOD(); + if (!pDoc->IsDocEditable() || pScMod->IsTableLocked()) + return; + OUString aName; + pDoc->CreateValidTabName(aName); + SCTAB nTabCount = pDoc->GetTableCount(); + pViewData->GetViewShell()->InsertTable(aName, nTabCount); +} + void ScTabControl::Select() { /* Remember last clicked page ID. */ diff --git a/svtools/source/control/filectrl.src b/svtools/source/control/filectrl.src index 4c70c58aa11f..357170c4ef1d 100644 --- a/svtools/source/control/filectrl.src +++ b/svtools/source/control/filectrl.src @@ -39,5 +39,9 @@ String STR_TABBAR_PUSHBUTTON_MOVETOEND { Text [ en-US ] = "Move To End" ; }; +String STR_TABBAR_PUSHBUTTON_ADDTAB +{ + Text [ en-US ] = "Add" ; +}; /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svtools/source/control/tabbar.cxx b/svtools/source/control/tabbar.cxx index f65b7257e0f9..2fe1724eec83 100644 --- a/svtools/source/control/tabbar.cxx +++ b/svtools/source/control/tabbar.cxx @@ -166,20 +166,6 @@ public: } } - void drawPlusImage() - { - DecorationView aDecorationView(&mrRenderContext); - sal_Int32 aScaleFactor = mrRenderContext.GetDPIScaleFactor(); - Size aSize(12 * aScaleFactor, 12 * aScaleFactor); - - Point aPosition = maRect.TopLeft(); - long nXOffSet = (maRect.GetWidth() - aSize.Width()) / 2; - long nYOffset = (maRect.GetHeight() - aSize.Height()) / 2; - aPosition += Point(nXOffSet, nYOffset); - - aDecorationView.DrawSymbol(Rectangle(aPosition, aSize), SymbolType::PLUS, mrStyleSettings.GetDarkShadowColor()); - } - void setRect(const Rectangle& rRect) { maRect = rRect; @@ -513,6 +499,7 @@ struct TabBar_Impl ScopedVclPtr<ImplTabButton> mpPrevButton; ScopedVclPtr<ImplTabButton> mpNextButton; ScopedVclPtr<ImplTabButton> mpLastButton; + ScopedVclPtr<ImplTabButton> mpAddButton; ScopedVclPtr<TabBarEdit> mpEdit; ImplTabBarList mpItemList; @@ -556,7 +543,6 @@ void TabBar::dispose() const sal_uInt16 TabBar::APPEND = ::std::numeric_limits<sal_uInt16>::max(); const sal_uInt16 TabBar::PAGE_NOT_FOUND = ::std::numeric_limits<sal_uInt16>::max(); -const sal_uInt16 TabBar::INSERT_TAB_POS = ::std::numeric_limits<sal_uInt16>::max() - 1; void TabBar::ImplInit( WinBits nWinStyle ) { @@ -603,6 +589,9 @@ void TabBar::ImplInit( WinBits nWinStyle ) if (mpImpl->mpLastButton) mpImpl->mpLastButton->SetAccessibleName(SVT_RESSTR(STR_TABBAR_PUSHBUTTON_MOVETOEND)); + if (mpImpl->mpAddButton) + mpImpl->mpAddButton->SetAccessibleName(SVT_RESSTR(STR_TABBAR_PUSHBUTTON_ADDTAB)); + SetSizePixel( Size( 100, CalcWindowSizePixel().Height() ) ); ImplInitSettings( true, true ); } @@ -835,6 +824,15 @@ void TabBar::ImplInitControls() else mpImpl->mpSizer.disposeAndClear(); + if (mbHasInsertTab && !mpImpl->mpAddButton) + { + Link<> aLink = LINK(this, TabBar, ImplAddClickHandler); + mpImpl->mpAddButton.reset(VclPtr<ImplTabButton>::Create(this, WB_REPEAT)); + mpImpl->mpAddButton->SetClickHdl(aLink); + mpImpl->mpAddButton->SetSymbol(SymbolType::PLUS); + mpImpl->mpAddButton->Show(); + } + Link<> aLink = LINK( this, TabBar, ImplClickHdl ); if ( mnWinStyle & (WB_MINSCROLL | WB_SCROLL) ) @@ -975,6 +973,12 @@ IMPL_LINK( TabBar, ImplClickHdl, ImplTabButton*, pBtn ) return 0; } +IMPL_LINK_NOARG(TabBar, ImplAddClickHandler) +{ + AddTabClick(); + return 0; +} + void TabBar::MouseMove( const MouseEvent& rMEvt ) { if ( rMEvt.IsLeaveWindow() ) @@ -1228,15 +1232,6 @@ void TabBar::Paint(vcl::RenderContext& rRenderContext, const Rectangle& rect) // Now, start drawing the tabs. ImplTabBarItem* pItem = ImplGetLastTabBarItem(nItemCount); - - if (pItem && mbHasInsertTab) - { - // Draw the insert tab at the right end. - Rectangle aRect = ImplGetInsertTabRect(pItem); - aDrawer.setRect(aRect); - aDrawer.drawPlusImage(); - } - ImplTabBarItem* pCurItem = NULL; while (pItem) { @@ -1370,6 +1365,16 @@ void TabBar::Resize() } nButtonWidth += nButtonMargin; + nX += mbMirrored ? -nButtonMargin : nButtonMargin; + + if (mpImpl->mpAddButton) + { + mpImpl->mpAddButton->SetPosSizePixel( Point( nX, 0 ), aBtnSize ); + nX += nXDiff; + nButtonWidth += nHeight; + } + + nButtonWidth += nButtonMargin; // store size maWinSize = aNewSize; @@ -1538,6 +1543,8 @@ void TabBar::StateChanged( StateChangedType nType ) mpImpl->mpLastButton->EnableRTL(IsRTLEnabled()); if (mpImpl->mpSizer) mpImpl->mpSizer->EnableRTL(IsRTLEnabled()); + if (mpImpl->mpAddButton) + mpImpl->mpAddButton->EnableRTL(IsRTLEnabled()); if (mpImpl->mpEdit) mpImpl->mpEdit->EnableRTL(IsRTLEnabled()); } @@ -1696,6 +1703,11 @@ void TabBar::Mirror() } +void TabBar::AddTabClick() +{ + +} + void TabBar::InsertPage( sal_uInt16 nPageId, const OUString& rText, TabBarPageBits nBits, sal_uInt16 nPos ) { @@ -1907,7 +1919,7 @@ sal_uInt16 TabBar::GetPagePos( sal_uInt16 nPageId ) const return PAGE_NOT_FOUND; } -sal_uInt16 TabBar::GetPageId( const Point& rPos, bool bCheckInsTab ) const +sal_uInt16 TabBar::GetPageId( const Point& rPos ) const { for (size_t i = 0; i < mpImpl->mpItemList.size(); ++i) { @@ -1916,13 +1928,6 @@ sal_uInt16 TabBar::GetPageId( const Point& rPos, bool bCheckInsTab ) const return pItem->mnId; } - if (bCheckInsTab && mbHasInsertTab && !mpImpl->mpItemList.empty()) - { - ImplTabBarItem* pItem = mpImpl->mpItemList.back(); - if (ImplGetInsertTabRect(pItem).IsInside(rPos)) - return INSERT_TAB_POS; - } - return 0; } diff --git a/svtools/source/inc/filectrl.hrc b/svtools/source/inc/filectrl.hrc index 8eb13c2733da..75cf6ace23b7 100644 --- a/svtools/source/inc/filectrl.hrc +++ b/svtools/source/inc/filectrl.hrc @@ -22,10 +22,11 @@ #define STR_FILECTRL_BUTTONTEXT 333 // ID-Range?! -#define STR_TABBAR_PUSHBUTTON_MOVET0HOME ( STR_FILECTRL_BUTTONTEXT+ 1) -#define STR_TABBAR_PUSHBUTTON_MOVELEFT ( STR_FILECTRL_BUTTONTEXT+ 2) -#define STR_TABBAR_PUSHBUTTON_MOVERIGHT ( STR_FILECTRL_BUTTONTEXT+ 3) -#define STR_TABBAR_PUSHBUTTON_MOVETOEND ( STR_FILECTRL_BUTTONTEXT+ 4) +#define STR_TABBAR_PUSHBUTTON_MOVET0HOME (STR_FILECTRL_BUTTONTEXT + 1) +#define STR_TABBAR_PUSHBUTTON_MOVELEFT (STR_FILECTRL_BUTTONTEXT + 2) +#define STR_TABBAR_PUSHBUTTON_MOVERIGHT (STR_FILECTRL_BUTTONTEXT + 3) +#define STR_TABBAR_PUSHBUTTON_MOVETOEND (STR_FILECTRL_BUTTONTEXT + 4) +#define STR_TABBAR_PUSHBUTTON_ADDTAB (STR_FILECTRL_BUTTONTEXT + 5) #endif // INCLUDED_SVTOOLS_SOURCE_INC_FILECTRL_HRC |