Fix MSW EDIT_HEIGHT_FROM_CHAR_HEIGHT() for high DPI
Apply DPI scaling to the extra vertical margin added by this macro to the font height. This makes sense and results in wxTextCtrl (and other controls, e.g. wxSearchCtrl) having the same height as native ones when using high DPI too. Note that this required adding wxGetEditHeightFromCharHeight() function as one of the existing uses of EDIT_HEIGHT_FROM_CHAR_HEIGHT() wasn't inside a wxWindow-derived class method and also adding wxUSE_GUI guard around these GUI-only definitions as a function, unlike a macro, can't be compiled without full wxWindow declaration in scope.
This commit is contained in:
@@ -82,19 +82,35 @@ WXDLLIMPEXP_BASE void wxSetInstance(HINSTANCE hInst);
|
|||||||
// misc macros
|
// misc macros
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#if wxUSE_GUI
|
||||||
|
|
||||||
#define MEANING_CHARACTER '0'
|
#define MEANING_CHARACTER '0'
|
||||||
#define DEFAULT_ITEM_WIDTH 100
|
#define DEFAULT_ITEM_WIDTH 100
|
||||||
#define DEFAULT_ITEM_HEIGHT 80
|
#define DEFAULT_ITEM_HEIGHT 80
|
||||||
|
|
||||||
// Scale font to get edit control height
|
// Return the height of a native text control corresponding to the given
|
||||||
//#define EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy) (3*(cy)/2)
|
// character height (as returned by GetCharHeight() or wxGetCharSize()).
|
||||||
#define EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy) (cy+8)
|
//
|
||||||
|
// The wxWindow parameter must be valid and used for getting the DPI.
|
||||||
|
inline int wxGetEditHeightFromCharHeight(int cy, const wxWindow* w)
|
||||||
|
{
|
||||||
|
// The value 8 here is empiric, i.e. it's not necessarily correct, but
|
||||||
|
// seems to work relatively well.
|
||||||
|
return cy + w->FromDIP(8);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Compatibility macro used in the existing code. It assumes that it's called
|
||||||
|
// from a method of wxWindow-derived object.
|
||||||
|
#define EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy) \
|
||||||
|
wxGetEditHeightFromCharHeight((cy), this)
|
||||||
|
|
||||||
// Generic subclass proc, for panel item moving/sizing and intercept
|
// Generic subclass proc, for panel item moving/sizing and intercept
|
||||||
// EDIT control VK_RETURN messages
|
// EDIT control VK_RETURN messages
|
||||||
extern LONG APIENTRY
|
extern LONG APIENTRY
|
||||||
wxSubclassedGenericControlProc(WXHWND hWnd, WXUINT message, WXWPARAM wParam, WXLPARAM lParam);
|
wxSubclassedGenericControlProc(WXHWND hWnd, WXUINT message, WXWPARAM wParam, WXLPARAM lParam);
|
||||||
|
|
||||||
|
#endif // wxUSE_GUI
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// useful macros and functions
|
// useful macros and functions
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
@@ -441,7 +441,7 @@ wxSize wxMSWButton::IncreaseToStdSizeAndCache(wxControl *btn, const wxSize& size
|
|||||||
// so make them as high as it.
|
// so make them as high as it.
|
||||||
int yText;
|
int yText;
|
||||||
wxGetCharSize(GetHwndOf(btn), NULL, &yText, btn->GetFont());
|
wxGetCharSize(GetHwndOf(btn), NULL, &yText, btn->GetFont());
|
||||||
yText = EDIT_HEIGHT_FROM_CHAR_HEIGHT(yText);
|
yText = wxGetEditHeightFromCharHeight(yText, btn);
|
||||||
|
|
||||||
sizeBtn.IncTo(wxSize(-1, yText));
|
sizeBtn.IncTo(wxSize(-1, yText));
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user