Kaydet (Commit) 415454cf authored tarafından Philippe Jung's avatar Philippe Jung Kaydeden (comit) Adolfo Jayme Barrientos

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/15716Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarAdolfo Jayme Barrientos <fitojb@ubuntu.com>
üst fa4a87bc
...@@ -1765,6 +1765,9 @@ bool ToolBarManager::MenuItemAllowed( sal_uInt16 ) const ...@@ -1765,6 +1765,9 @@ bool ToolBarManager::MenuItemAllowed( sal_uInt16 ) const
pMenu->SetPopupMenu( 1, pItemMenu ); pMenu->SetPopupMenu( 1, pItemMenu );
} }
// Set the title of the menu
pMenu->SetText( pToolBar->GetText() );
if ( bHideDisabledEntries ) if ( bHideDisabledEntries )
pMenu->RemoveDisabledEntries(); pMenu->RemoveDisabledEntries();
......
...@@ -136,6 +136,7 @@ private: ...@@ -136,6 +136,7 @@ private:
VclEventListeners maChildEventListeners; VclEventListeners maChildEventListeners;
OUString aTitleText; // PopupMenu text OUString aTitleText; // PopupMenu text
sal_uInt16 nTitleHeight;
ImplSVEvent * nEventId; ImplSVEvent * nEventId;
sal_uInt16 mnHighlightedItemPos; // for native menus: keeps track of the highlighted item sal_uInt16 mnHighlightedItemPos; // for native menus: keeps track of the highlighted item
...@@ -159,7 +160,7 @@ protected: ...@@ -159,7 +160,7 @@ protected:
SAL_DLLPRIVATE Menu* ImplGetStartMenu(); SAL_DLLPRIVATE Menu* ImplGetStartMenu();
SAL_DLLPRIVATE Menu* ImplFindSelectMenu(); SAL_DLLPRIVATE Menu* ImplFindSelectMenu();
SAL_DLLPRIVATE Menu* ImplFindMenu( sal_uInt16 nId ); 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 ImplIsVisible( sal_uInt16 nPos ) const;
SAL_DLLPRIVATE bool ImplIsSelectable( sal_uInt16 nPos ) const; SAL_DLLPRIVATE bool ImplIsSelectable( sal_uInt16 nPos ) const;
SAL_DLLPRIVATE sal_uInt16 ImplGetVisibleItemCount() const; SAL_DLLPRIVATE sal_uInt16 ImplGetVisibleItemCount() const;
...@@ -167,6 +168,7 @@ protected: ...@@ -167,6 +168,7 @@ protected:
SAL_DLLPRIVATE sal_uInt16 ImplGetPrevVisible( sal_uInt16 nPos ) const; SAL_DLLPRIVATE sal_uInt16 ImplGetPrevVisible( sal_uInt16 nPos ) const;
SAL_DLLPRIVATE sal_uInt16 ImplGetNextVisible( 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 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 ImplSelect();
SAL_DLLPRIVATE void ImplCallHighlight( sal_uInt16 nHighlightItem ); SAL_DLLPRIVATE void ImplCallHighlight( sal_uInt16 nHighlightItem );
SAL_DLLPRIVATE void ImplCallEventListeners( sal_uLong nEvent, sal_uInt16 nPos ); SAL_DLLPRIVATE void ImplCallEventListeners( sal_uLong nEvent, sal_uInt16 nPos );
...@@ -332,6 +334,8 @@ public: ...@@ -332,6 +334,8 @@ public:
bool HasLogo() const { return pLogo != nullptr; } bool HasLogo() const { return pLogo != nullptr; }
sal_uInt16 GetTitleHeight() { return nTitleHeight; }
void AddEventListener( const Link<>& rEventListener ); void AddEventListener( const Link<>& rEventListener );
void RemoveEventListener( const Link<>& rEventListener ); void RemoveEventListener( const Link<>& rEventListener );
void AddChildEventListener( const Link<>& rEventListener ); void AddChildEventListener( const Link<>& rEventListener );
......
...@@ -85,6 +85,7 @@ using namespace ::com::sun::star; ...@@ -85,6 +85,7 @@ using namespace ::com::sun::star;
using namespace vcl; using namespace vcl;
#define EXTRAITEMHEIGHT 4 #define EXTRAITEMHEIGHT 4
#define SPACE_AROUND_TITLE 2
static bool ImplAccelDisabled() static bool ImplAccelDisabled()
{ {
...@@ -118,6 +119,7 @@ Menu::Menu() ...@@ -118,6 +119,7 @@ Menu::Menu()
pLogo(NULL), pLogo(NULL),
pStartedFrom(NULL), pStartedFrom(NULL),
pWindow(NULL), pWindow(NULL),
nTitleHeight(0),
nEventId(0), nEventId(0),
mnHighlightedItemPos(ITEMPOS_INVALID), mnHighlightedItemPos(ITEMPOS_INVALID),
nMenuFlags(0), nMenuFlags(0),
...@@ -1263,6 +1265,7 @@ Menu& Menu::operator=( const Menu& rMenu ) ...@@ -1263,6 +1265,7 @@ Menu& Menu::operator=( const Menu& rMenu )
aHighlightHdl = rMenu.aHighlightHdl; aHighlightHdl = rMenu.aHighlightHdl;
aSelectHdl = rMenu.aSelectHdl; aSelectHdl = rMenu.aSelectHdl;
aTitleText = rMenu.aTitleText; aTitleText = rMenu.aTitleText;
nTitleHeight = rMenu.nTitleHeight;
return *this; return *this;
} }
...@@ -1508,7 +1511,7 @@ void Menu::ImplRemoveDel( ImplMenuDelData& rDel ) ...@@ -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| // | Check/Radio/Image| Text| Accel/Popup|
...@@ -1566,7 +1569,7 @@ Size Menu::ImplCalcSize( const vcl::Window* pWin ) ...@@ -1566,7 +1569,7 @@ Size Menu::ImplCalcSize( const vcl::Window* pWin )
// Separator // Separator
if (!IsMenuBar()&& (pData->eType == MenuItemType::SEPARATOR)) if (!IsMenuBar()&& (pData->eType == MenuItemType::SEPARATOR))
{ {
DBG_ASSERT( !IsMenuBar(), "Separator in MenuBar ?! " ); //Useless: DBG_ASSERT( !IsMenuBar(), "Separator in MenuBar ?! " );
pData->aSz.Height() = 4; pData->aSz.Height() = 4;
} }
...@@ -1647,6 +1650,24 @@ Size Menu::ImplCalcSize( const vcl::Window* pWin ) ...@@ -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()) if (!IsMenuBar())
{ {
// popup menus should not be wider than half the screen // 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 ...@@ -1762,6 +1783,38 @@ static OUString getShortenedString( const OUString& i_rLong, vcl::Window* i_pWin
return aNonMnem; 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 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 // for symbols: nFontHeight x nFontHeight
...@@ -1792,6 +1845,10 @@ void Menu::ImplPaint( vcl::Window* pWin, sal_uInt16 nBorder, long nStartY, MenuI ...@@ -1792,6 +1845,10 @@ void Menu::ImplPaint( vcl::Window* pWin, sal_uInt16 nBorder, long nStartY, MenuI
if( bLayout ) if( bLayout )
mpLayoutData->m_aVisibleItemBoundRects.clear(); mpLayoutData->m_aVisibleItemBoundRects.clear();
// Paint title
if ( !pThisItemOnly && !IsMenuBar() && nTitleHeight > 0 )
ImplPaintMenuTitle( pWin, Rectangle( aTopLeft, aOutSz ) );
for ( size_t n = 0; n < nCount; n++ ) for ( size_t n = 0; n < nCount; n++ )
{ {
MenuItemData* pData = pItemList->GetDataFromPos( n ); MenuItemData* pData = pItemList->GetDataFromPos( n );
......
...@@ -126,6 +126,7 @@ long MenuFloatingWindow::ImplGetStartY() const ...@@ -126,6 +126,7 @@ long MenuFloatingWindow::ImplGetStartY() const
{ {
for ( sal_uInt16 n = 0; n < nFirstEntry; n++ ) for ( sal_uInt16 n = 0; n < nFirstEntry; n++ )
nY += pMenu->GetItemList()->GetDataFromPos( n )->aSz.Height(); nY += pMenu->GetItemList()->GetDataFromPos( n )->aSz.Height();
nY -= pMenu->GetTitleHeight();
} }
return -nY; return -nY;
} }
......
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