summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilippe Jung <phil.jung@free.fr>2015-05-13 15:59:40 +0200
committerAdolfo Jayme Barrientos <fitojb@ubuntu.com>2015-05-14 17:17:55 +0000
commit415454cfbc6add8534e1dcff1ff16cc8dcc9296c (patch)
treecc6b89d02bb4ae51c34202d91e060fba939ff075
parentfa4a87bc539865962dabf00aea465479d34faf92 (diff)
tdf#86138 Context menu should state the name of the toolbar
When Menu::SetText is called, it defines the title of the menu (reuse of an already defined & not used aTitleText) Popup-menu with a title defined paint it on top of the popup. Text is bold with a background slightly darker than the rest of the popup. Change-Id: Ifca1be60541400f76f562b03f6e3c40dc5fecb29 Reviewed-on: https://gerrit.libreoffice.org/15716 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Adolfo Jayme Barrientos <fitojb@ubuntu.com>
-rw-r--r--framework/source/uielement/toolbarmanager.cxx3
-rw-r--r--include/vcl/menu.hxx6
-rw-r--r--vcl/source/window/menu.cxx61
-rw-r--r--vcl/source/window/menufloatingwindow.cxx1
4 files changed, 68 insertions, 3 deletions
diff --git a/framework/source/uielement/toolbarmanager.cxx b/framework/source/uielement/toolbarmanager.cxx
index 3e12b5efef78..7f55ed11ef57 100644
--- a/framework/source/uielement/toolbarmanager.cxx
+++ b/framework/source/uielement/toolbarmanager.cxx
@@ -1765,6 +1765,9 @@ bool ToolBarManager::MenuItemAllowed( sal_uInt16 ) const
pMenu->SetPopupMenu( 1, pItemMenu );
}
+ // Set the title of the menu
+ pMenu->SetText( pToolBar->GetText() );
+
if ( bHideDisabledEntries )
pMenu->RemoveDisabledEntries();
diff --git a/include/vcl/menu.hxx b/include/vcl/menu.hxx
index 24c716daa466..4899455eb3de 100644
--- a/include/vcl/menu.hxx
+++ b/include/vcl/menu.hxx
@@ -136,6 +136,7 @@ private:
VclEventListeners maChildEventListeners;
OUString aTitleText; // PopupMenu text
+ sal_uInt16 nTitleHeight;
ImplSVEvent * nEventId;
sal_uInt16 mnHighlightedItemPos; // for native menus: keeps track of the highlighted item
@@ -159,7 +160,7 @@ protected:
SAL_DLLPRIVATE Menu* ImplGetStartMenu();
SAL_DLLPRIVATE Menu* ImplFindSelectMenu();
SAL_DLLPRIVATE Menu* ImplFindMenu( sal_uInt16 nId );
- SAL_DLLPRIVATE Size ImplCalcSize( const vcl::Window* pWin );
+ SAL_DLLPRIVATE Size ImplCalcSize( vcl::Window* pWin );
SAL_DLLPRIVATE bool ImplIsVisible( sal_uInt16 nPos ) const;
SAL_DLLPRIVATE bool ImplIsSelectable( sal_uInt16 nPos ) const;
SAL_DLLPRIVATE sal_uInt16 ImplGetVisibleItemCount() const;
@@ -167,6 +168,7 @@ protected:
SAL_DLLPRIVATE sal_uInt16 ImplGetPrevVisible( sal_uInt16 nPos ) const;
SAL_DLLPRIVATE sal_uInt16 ImplGetNextVisible( sal_uInt16 nPos ) const;
SAL_DLLPRIVATE void ImplPaint( vcl::Window* pWin, sal_uInt16 nBorder, long nOffY = 0, MenuItemData* pThisDataOnly = 0, bool bHighlighted = false, bool bLayout = false, bool bRollover = false ) const;
+ SAL_DLLPRIVATE void ImplPaintMenuTitle( vcl::Window* pWin, const Rectangle& rRect ) const;
SAL_DLLPRIVATE void ImplSelect();
SAL_DLLPRIVATE void ImplCallHighlight( sal_uInt16 nHighlightItem );
SAL_DLLPRIVATE void ImplCallEventListeners( sal_uLong nEvent, sal_uInt16 nPos );
@@ -332,6 +334,8 @@ public:
bool HasLogo() const { return pLogo != nullptr; }
+ sal_uInt16 GetTitleHeight() { return nTitleHeight; }
+
void AddEventListener( const Link<>& rEventListener );
void RemoveEventListener( const Link<>& rEventListener );
void AddChildEventListener( const Link<>& rEventListener );
diff --git a/vcl/source/window/menu.cxx b/vcl/source/window/menu.cxx
index 98f95310478d..f3defdd42943 100644
--- a/vcl/source/window/menu.cxx
+++ b/vcl/source/window/menu.cxx
@@ -85,6 +85,7 @@ using namespace ::com::sun::star;
using namespace vcl;
#define EXTRAITEMHEIGHT 4
+#define SPACE_AROUND_TITLE 2
static bool ImplAccelDisabled()
{
@@ -118,6 +119,7 @@ Menu::Menu()
pLogo(NULL),
pStartedFrom(NULL),
pWindow(NULL),
+ nTitleHeight(0),
nEventId(0),
mnHighlightedItemPos(ITEMPOS_INVALID),
nMenuFlags(0),
@@ -1263,6 +1265,7 @@ Menu& Menu::operator=( const Menu& rMenu )
aHighlightHdl = rMenu.aHighlightHdl;
aSelectHdl = rMenu.aSelectHdl;
aTitleText = rMenu.aTitleText;
+ nTitleHeight = rMenu.nTitleHeight;
return *this;
}
@@ -1508,7 +1511,7 @@ void Menu::ImplRemoveDel( ImplMenuDelData& rDel )
}
}
-Size Menu::ImplCalcSize( const vcl::Window* pWin )
+Size Menu::ImplCalcSize( vcl::Window* pWin )
{
// | Check/Radio/Image| Text| Accel/Popup|
@@ -1566,7 +1569,7 @@ Size Menu::ImplCalcSize( const vcl::Window* pWin )
// Separator
if (!IsMenuBar()&& (pData->eType == MenuItemType::SEPARATOR))
{
- DBG_ASSERT( !IsMenuBar(), "Separator in MenuBar ?! " );
+ //Useless: DBG_ASSERT( !IsMenuBar(), "Separator in MenuBar ?! " );
pData->aSz.Height() = 4;
}
@@ -1647,6 +1650,24 @@ Size Menu::ImplCalcSize( const vcl::Window* pWin )
}
}
+ // Additional space for title
+ nTitleHeight = 0;
+ if (!IsMenuBar() && aTitleText.getLength() > 0) {
+ // Vertically, one height of char + extra space for decoration
+ nTitleHeight = nFontHeight + 4 * SPACE_AROUND_TITLE ;
+ aSz.Height() += nTitleHeight;
+
+ // Horizontally, compute text width with bold font
+ pWin->Push(PushFlags::FONT);
+ vcl::Font aFont = pWin->GetFont();
+ aFont.SetWeight(WEIGHT_BOLD);
+ pWin->SetFont(aFont);
+ long nWidth = pWin->GetTextWidth( aTitleText ) + 4 * SPACE_AROUND_TITLE;
+ pWin->Pop();
+ if ( nWidth > nMaxWidth )
+ nMaxWidth = nWidth;
+ }
+
if (!IsMenuBar())
{
// popup menus should not be wider than half the screen
@@ -1762,6 +1783,38 @@ static OUString getShortenedString( const OUString& i_rLong, vcl::Window* i_pWin
return aNonMnem;
}
+void Menu::ImplPaintMenuTitle( vcl::Window* pWin, const Rectangle& rRect ) const
+{
+ // Save previous graphical settings, set new one
+ pWin->Push( PushFlags::FONT | PushFlags::FILLCOLOR );
+ Color aBg = pWin->GetSettings().GetStyleSettings().GetMenuBarColor();
+ pWin->SetBackground( Wallpaper( aBg ) );
+ pWin->SetFillColor( aBg );
+ vcl::Font aFont = pWin->GetFont();
+ aFont.SetWeight(WEIGHT_BOLD);
+ pWin->SetFont(aFont);
+
+ // Draw background rectangle
+ Rectangle aBgRect( rRect );
+ int nOuterSpaceX = ImplGetSVData()->maNWFData.mnMenuFormatBorderX;
+ aBgRect.setX( aBgRect.getX() + SPACE_AROUND_TITLE);
+ aBgRect.setWidth( aBgRect.getWidth() - 2 * SPACE_AROUND_TITLE - 2 * nOuterSpaceX );
+ aBgRect.setY( aBgRect.getY() + SPACE_AROUND_TITLE );
+ aBgRect.setHeight( nTitleHeight - 2 * SPACE_AROUND_TITLE );
+ pWin->DrawRect( aBgRect );
+
+ // Draw the text centered
+ Point aTextTopLeft( rRect.TopLeft() );
+ long textWidth = pWin->GetTextWidth(aTitleText);
+ aTextTopLeft.X() += ( aBgRect.getWidth() - textWidth ) / 2;
+ aTextTopLeft.Y() += SPACE_AROUND_TITLE;
+ pWin->DrawText( aTextTopLeft, aTitleText, 0, aTitleText.getLength() );
+
+ // Restore
+ pWin->SetBackground();
+ pWin->Pop();
+}
+
void Menu::ImplPaint( vcl::Window* pWin, sal_uInt16 nBorder, long nStartY, MenuItemData* pThisItemOnly, bool bHighlighted, bool bLayout, bool bRollover ) const
{
// for symbols: nFontHeight x nFontHeight
@@ -1792,6 +1845,10 @@ void Menu::ImplPaint( vcl::Window* pWin, sal_uInt16 nBorder, long nStartY, MenuI
if( bLayout )
mpLayoutData->m_aVisibleItemBoundRects.clear();
+ // Paint title
+ if ( !pThisItemOnly && !IsMenuBar() && nTitleHeight > 0 )
+ ImplPaintMenuTitle( pWin, Rectangle( aTopLeft, aOutSz ) );
+
for ( size_t n = 0; n < nCount; n++ )
{
MenuItemData* pData = pItemList->GetDataFromPos( n );
diff --git a/vcl/source/window/menufloatingwindow.cxx b/vcl/source/window/menufloatingwindow.cxx
index 3221294687a9..e4a979804ec2 100644
--- a/vcl/source/window/menufloatingwindow.cxx
+++ b/vcl/source/window/menufloatingwindow.cxx
@@ -126,6 +126,7 @@ long MenuFloatingWindow::ImplGetStartY() const
{
for ( sal_uInt16 n = 0; n < nFirstEntry; n++ )
nY += pMenu->GetItemList()->GetDataFromPos( n )->aSz.Height();
+ nY -= pMenu->GetTitleHeight();
}
return -nY;
}