1. added wxFont::GetHFONT() const (GetResourceHandle() is not const...)

2. added GetHfont[Of] convenience macros to msw/private.h
3. wxWindow::GetCharWidth/Height() now use correct font


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_2_BRANCH@7643 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2000-06-27 10:22:06 +00:00
parent 9e677ba35c
commit a750cce7a5
6 changed files with 84 additions and 18 deletions

View File

@@ -134,6 +134,9 @@ wxWindow *wxFindWinFromHandle(WXHWND hWnd);
// mouse clicks
static void TranslateKbdEventToMouse(wxWindow *win, int *x, int *y, WPARAM *flags);
// get the text metrics for the current font
static TEXTMETRIC wxGetTextMetrics(const wxWindow *win);
// ---------------------------------------------------------------------------
// event tables
// ---------------------------------------------------------------------------
@@ -1334,26 +1337,14 @@ void wxWindow::AdjustForParentClientOrigin(int& x, int& y, int sizeFlags)
int wxWindow::GetCharHeight() const
{
TEXTMETRIC lpTextMetric;
HWND hWnd = GetHwnd();
HDC dc = ::GetDC(hWnd);
GetTextMetrics(dc, &lpTextMetric);
::ReleaseDC(hWnd, dc);
return lpTextMetric.tmHeight;
return wxGetTextMetrics(this).tmHeight;
}
int wxWindow::GetCharWidth() const
{
TEXTMETRIC lpTextMetric;
HWND hWnd = GetHwnd();
HDC dc = ::GetDC(hWnd);
GetTextMetrics(dc, &lpTextMetric);
::ReleaseDC(hWnd, dc);
return lpTextMetric.tmAveCharWidth;
// +1 is needed because Windows apparently adds it when calculating the
// dialog units size in pixels
return wxGetTextMetrics(this).tmAveCharWidth + 1;
}
void wxWindow::GetTextExtent(const wxString& string,
@@ -4280,3 +4271,31 @@ static void TranslateKbdEventToMouse(wxWindow *win, int *x, int *y, WPARAM *flag
win->ScreenToClient(x, y);
}
static TEXTMETRIC wxGetTextMetrics(const wxWindow *win)
{
// prepare the DC
TEXTMETRIC tm;
HWND hwnd = GetHwndOf(win);
HDC hdc = ::GetDC(hwnd);
// and select the current font into it
HFONT hfont = GetHfontOf(win->GetFont());
if ( hfont )
{
hfont = (HFONT)::SelectObject(hdc, hfont);
}
// finally retrieve the text metrics from it
GetTextMetrics(hdc, &tm);
// and clean up
if ( hfont )
{
(void)::SelectObject(hdc, hfont);
}
::ReleaseDC(hwnd, hdc);
return tm;
}