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

tabbar: use a button for adding of tabs, move button before tabs

Change-Id: I89fcf7427694ea6fc9468220bae639b221d9ec28
üst 6aab2ece
......@@ -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;
......
......@@ -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();
......
......@@ -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. */
......
......@@ -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: */
......@@ -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)
{
......@@ -1369,6 +1364,16 @@ void TabBar::Resize()
nButtonWidth += nHeight;
}
nButtonWidth += nButtonMargin;
nX += mbMirrored ? -nButtonMargin : nButtonMargin;
if (mpImpl->mpAddButton)
{
mpImpl->mpAddButton->SetPosSizePixel( Point( nX, 0 ), aBtnSize );
nX += nXDiff;
nButtonWidth += nHeight;
}
nButtonWidth += nButtonMargin;
// store size
......@@ -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;
}
......
......@@ -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
......
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