From 23a830ae16de33d30ee184097e42b5998c3ebb73 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 20 Dec 2017 22:53:12 +0100 Subject: [PATCH] Use symbolic names in wxMSW wxStaticBox drawing code Introduce symbolic constants instead of using raw magic numbers. No real changes and these numbers are still as magic as before, but at least they will be easier to change now. --- src/msw/statbox.cpp | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/src/msw/statbox.cpp b/src/msw/statbox.cpp index 9ae5c230df..bcc79cd1f7 100644 --- a/src/msw/statbox.cpp +++ b/src/msw/statbox.cpp @@ -54,6 +54,21 @@ #define TMT_FONT 210 +namespace +{ + +// Offset of the first pixel of the label from the box left border. +// +// FIXME: value is hardcoded as this is what it is on my system, no idea if +// it's true everywhere +const int LABEL_HORZ_OFFSET = 9; + +// Extra borders around the label on left/right and bottom sides. +const int LABEL_HORZ_BORDER = 2; +const int LABEL_VERT_BORDER = 2; + +} // anonymous namespace + // ---------------------------------------------------------------------------- // wxWin macros // ---------------------------------------------------------------------------- @@ -443,23 +458,17 @@ void wxStaticBox::PaintForeground(wxDC& dc, const RECT&) dc.GetTextExtent(wxStripMenuCodes(label, wxStrip_Mnemonics), &width, &height); - int x; - int y = height; - // first we need to correctly paint the background of the label // as Windows ignores the brush offset when doing it - // - // FIXME: value of x is hardcoded as this is what it is on my system, - // no idea if it's true everywhere - RECT dimensions = {0, 0, 0, y}; - x = 9; + const int x = LABEL_HORZ_OFFSET; + RECT dimensions = { x, 0, 0, height }; dimensions.left = x; dimensions.right = x + width; // need to adjust the rectangle to cover all the label background - dimensions.left -= 2; - dimensions.right += 2; - dimensions.bottom += 2; + dimensions.left -= LABEL_HORZ_BORDER; + dimensions.right += LABEL_HORZ_BORDER; + dimensions.bottom += LABEL_VERT_BORDER; if ( UseBgCol() ) { @@ -489,7 +498,7 @@ void wxStaticBox::PaintForeground(wxDC& dc, const RECT&) } // now draw the text - RECT rc2 = { x, 0, x + width, y }; + RECT rc2 = { x, 0, x + width, height }; ::DrawText(hdc, label.t_str(), label.length(), &rc2, drawTextFlags); }