[Libreoffice-commits] core.git: vcl/source
Philippe Jung
phil.jung at free.fr
Thu Jun 18 02:17:12 PDT 2015
vcl/source/window/menu.cxx | 29 ++++++++++++++++++-----------
1 file changed, 18 insertions(+), 11 deletions(-)
New commits:
commit a18c551725d7067c8bcf5b6a5ab71b2e78ba3bfa
Author: Philippe Jung <phil.jung at free.fr>
Date: Thu Jun 18 11:04:10 2015 +0200
Better position for Toolbar name
The text is badly centered. Replaced GetTextHeight by GetTextBoundRect
and updated computation of text bounds.
Change-Id: I1e177a15787c6eddf2878a7d0254f71f3501ec34
Reviewed-on: https://gerrit.libreoffice.org/16354
Reviewed-by: Philippe Jung <phil.jung at free.fr>
Tested-by: Philippe Jung <phil.jung at free.fr>
diff --git a/vcl/source/window/menu.cxx b/vcl/source/window/menu.cxx
index d2b5716..7acd139 100644
--- a/vcl/source/window/menu.cxx
+++ b/vcl/source/window/menu.cxx
@@ -85,7 +85,7 @@ using namespace ::com::sun::star;
using namespace vcl;
#define EXTRAITEMHEIGHT 4
-#define SPACE_AROUND_TITLE 2
+#define SPACE_AROUND_TITLE 4
static bool ImplAccelDisabled()
{
@@ -1631,16 +1631,21 @@ Size Menu::ImplCalcSize( 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
+ // Set expected 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;
+
+ // Compute text bounding box
+ Rectangle aTextBoundRect;
+ pWin->GetTextBoundRect(aTextBoundRect, aTitleText);
+
+ // Vertically, one height of char + extra space for decoration
+ nTitleHeight = aTextBoundRect.GetSize().Height() + 4 * SPACE_AROUND_TITLE ;
+ aSz.Height() += nTitleHeight;
+
+ long nWidth = aTextBoundRect.GetSize().Width() + 4 * SPACE_AROUND_TITLE;
pWin->Pop();
if ( nWidth > nMaxWidth )
nMaxWidth = nWidth;
@@ -1784,10 +1789,12 @@ void Menu::ImplPaintMenuTitle(vcl::RenderContext& rRenderContext, const Rectangl
rRenderContext.DrawRect(aBgRect);
// Draw the text centered
- Point aTextTopLeft(rRect.TopLeft());
- long textWidth = rRenderContext.GetTextWidth(aTitleText);
- aTextTopLeft.X() += (aBgRect.getWidth() - textWidth) / 2;
- aTextTopLeft.Y() += SPACE_AROUND_TITLE;
+ Point aTextTopLeft(aBgRect.TopLeft());
+ Rectangle aTextBoundRect;
+ rRenderContext.GetTextBoundRect( aTextBoundRect, aTitleText );
+ aTextTopLeft.X() += (aBgRect.getWidth() - aTextBoundRect.GetSize().Width()) / 2;
+ aTextTopLeft.Y() += (aBgRect.GetHeight() - aTextBoundRect.GetSize().Height()) / 2
+ - aTextBoundRect.TopLeft().Y();
rRenderContext.DrawText(aTextTopLeft, aTitleText, 0, aTitleText.getLength());
// Restore
More information about the Libreoffice-commits
mailing list