summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2016-08-04 15:43:37 +0100
committerCaolán McNamara <caolanm@redhat.com>2016-08-04 15:48:49 +0100
commitcc62d87d5f1abcff2affd56f1077114289c68c7e (patch)
treee7a607a96b4b1f7136788ee64b408616063cf412 /vcl
parent97746e61ffe48cf3612d2dff5535914a8a1219f6 (diff)
use same scheme in Edit and ListBox for rendering text in ::Draw
Change-Id: I5b17103e838f221cf3815002979c6b8c9c443300
Diffstat (limited to 'vcl')
-rw-r--r--vcl/source/control/edit.cxx33
-rw-r--r--vcl/source/control/listbox.cxx8
2 files changed, 23 insertions, 18 deletions
diff --git a/vcl/source/control/edit.cxx b/vcl/source/control/edit.cxx
index b6a49898d7c8..8e41d0e457b0 100644
--- a/vcl/source/control/edit.cxx
+++ b/vcl/source/control/edit.cxx
@@ -1811,11 +1811,27 @@ void Edit::Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize, DrawF
}
}
+ const long nOnePixel = GetDrawPixel( pDev, 1 );
+ const long nOffX = 3*nOnePixel;
+ DrawTextFlags nTextStyle = DrawTextFlags::VCenter;
+ Rectangle aTextRect( aPos, aSize );
+
+ if ( GetStyle() & WB_CENTER )
+ nTextStyle |= DrawTextFlags::Center;
+ else if ( GetStyle() & WB_RIGHT )
+ {
+ nTextStyle |= DrawTextFlags::Right;
+ aTextRect.Left() += nOffX;
+ }
+ else
+ {
+ nTextStyle |= DrawTextFlags::Left;
+ aTextRect.Right() -= nOffX;
+ }
+
OUString aText = ImplGetText();
long nTextHeight = pDev->GetTextHeight();
long nTextWidth = pDev->GetTextWidth( aText );
- long nOnePixel = GetDrawPixel( pDev, 1 );
- long nOffX = 3*nOnePixel;
long nOffY = (aSize.Height() - nTextHeight) / 2;
// Clipping?
@@ -1829,18 +1845,7 @@ void Edit::Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize, DrawF
pDev->IntersectClipRegion( aClip );
}
- if ( GetStyle() & WB_CENTER )
- {
- aPos.X() += (aSize.Width() - nTextWidth) / 2;
- nOffX = 0;
- }
- else if ( GetStyle() & WB_RIGHT )
- {
- aPos.X() += aSize.Width() - nTextWidth;
- nOffX = -nOffX;
- }
-
- pDev->DrawText( Point( aPos.X() + nOffX, aPos.Y() + nOffY ), aText );
+ pDev->DrawText( aTextRect, aText, nTextStyle );
pDev->Pop();
if ( GetSubEdit() )
diff --git a/vcl/source/control/listbox.cxx b/vcl/source/control/listbox.cxx
index 5b35044b2aab..b95c1dcf855c 100644
--- a/vcl/source/control/listbox.cxx
+++ b/vcl/source/control/listbox.cxx
@@ -412,7 +412,8 @@ void ListBox::Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize, Dr
}
}
- long nOnePixel = GetDrawPixel( pDev, 1 );
+ const long nOnePixel = GetDrawPixel( pDev, 1 );
+ const long nOffX = 3*nOnePixel;
DrawTextFlags nTextStyle = DrawTextFlags::VCenter;
Rectangle aTextRect( aPos, aSize );
@@ -423,15 +424,14 @@ void ListBox::Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize, Dr
else
nTextStyle |= DrawTextFlags::Left;
- aTextRect.Left() += 3*nOnePixel;
- aTextRect.Right() -= 3*nOnePixel;
+ aTextRect.Left() += nOffX;
+ aTextRect.Right() -= nOffX;
if ( IsDropDownBox() )
{
OUString aText = GetSelectEntry();
long nTextHeight = pDev->GetTextHeight();
long nTextWidth = pDev->GetTextWidth( aText );
- long nOffX = 3*nOnePixel;
long nOffY = (aSize.Height()-nTextHeight) / 2;
// Clipping?