diff options
Diffstat (limited to 'vcl/source')
-rw-r--r-- | vcl/source/window/menu.cxx | 61 | ||||
-rw-r--r-- | vcl/source/window/menufloatingwindow.cxx | 1 |
2 files changed, 60 insertions, 2 deletions
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; } |