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:
@@ -78,6 +78,11 @@ public:
|
|||||||
virtual bool RealizeResource();
|
virtual bool RealizeResource();
|
||||||
virtual WXHANDLE GetResourceHandle();
|
virtual WXHANDLE GetResourceHandle();
|
||||||
virtual bool FreeResource(bool force = FALSE);
|
virtual bool FreeResource(bool force = FALSE);
|
||||||
|
|
||||||
|
// for consistency with other wxMSW classes and to have a const
|
||||||
|
// GetResourceHandle()-like function we have a synonym for it
|
||||||
|
WXHFONT GetHFONT() const;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
virtual bool UseResource();
|
virtual bool UseResource();
|
||||||
virtual bool ReleaseResource();
|
virtual bool ReleaseResource();
|
||||||
|
@@ -289,6 +289,9 @@ private:
|
|||||||
#define GetHcursor() ((HCURSOR)GetHCURSOR())
|
#define GetHcursor() ((HCURSOR)GetHCURSOR())
|
||||||
#define GetHcursorOf(cursor) ((HCURSOR)(cursor).GetHCURSOR())
|
#define GetHcursorOf(cursor) ((HCURSOR)(cursor).GetHCURSOR())
|
||||||
|
|
||||||
|
#define GetHfont() ((HFONT)GetHFONT())
|
||||||
|
#define GetHfontOf(font) ((HFONT)(font).GetHFONT())
|
||||||
|
|
||||||
#endif // wxUSE_GUI
|
#endif // wxUSE_GUI
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
1
locale/.cvsignore
Normal file
1
locale/.cvsignore
Normal file
@@ -0,0 +1 @@
|
|||||||
|
*.mo
|
@@ -84,6 +84,9 @@ public:
|
|||||||
// event handlers (these functions should _not_ be virtual)
|
// event handlers (these functions should _not_ be virtual)
|
||||||
void OnQuit(wxCommandEvent& event);
|
void OnQuit(wxCommandEvent& event);
|
||||||
void OnAbout(wxCommandEvent& event);
|
void OnAbout(wxCommandEvent& event);
|
||||||
|
void OnIncFont(wxCommandEvent& event) { DoResizeFont(+2); }
|
||||||
|
void OnDecFont(wxCommandEvent& event) { DoResizeFont(-2); }
|
||||||
|
|
||||||
void OnViewMsg(wxCommandEvent& event);
|
void OnViewMsg(wxCommandEvent& event);
|
||||||
void OnSelectFont(wxCommandEvent& event);
|
void OnSelectFont(wxCommandEvent& event);
|
||||||
void OnEnumerateFamiliesForEncoding(wxCommandEvent& event);
|
void OnEnumerateFamiliesForEncoding(wxCommandEvent& event);
|
||||||
@@ -100,10 +103,13 @@ protected:
|
|||||||
wxFontEncoding encoding = wxFONTENCODING_SYSTEM,
|
wxFontEncoding encoding = wxFONTENCODING_SYSTEM,
|
||||||
bool silent = FALSE);
|
bool silent = FALSE);
|
||||||
|
|
||||||
|
void DoResizeFont(int diff);
|
||||||
void DoChangeFont(const wxFont& font, const wxColour& col = wxNullColour);
|
void DoChangeFont(const wxFont& font, const wxColour& col = wxNullColour);
|
||||||
|
|
||||||
void Resize(const wxSize& size, const wxFont& font = wxNullFont);
|
void Resize(const wxSize& size, const wxFont& font = wxNullFont);
|
||||||
|
|
||||||
|
size_t m_fontSize; // in points
|
||||||
|
|
||||||
wxTextCtrl *m_textctrl;
|
wxTextCtrl *m_textctrl;
|
||||||
MyCanvas *m_canvas;
|
MyCanvas *m_canvas;
|
||||||
|
|
||||||
@@ -123,6 +129,8 @@ enum
|
|||||||
Font_Quit = 1,
|
Font_Quit = 1,
|
||||||
Font_About,
|
Font_About,
|
||||||
Font_ViewMsg,
|
Font_ViewMsg,
|
||||||
|
Font_IncSize,
|
||||||
|
Font_DecSize,
|
||||||
Font_Choose = 100,
|
Font_Choose = 100,
|
||||||
Font_EnumFamiliesForEncoding,
|
Font_EnumFamiliesForEncoding,
|
||||||
Font_EnumFamilies,
|
Font_EnumFamilies,
|
||||||
@@ -141,6 +149,8 @@ enum
|
|||||||
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
||||||
EVT_MENU(Font_Quit, MyFrame::OnQuit)
|
EVT_MENU(Font_Quit, MyFrame::OnQuit)
|
||||||
EVT_MENU(Font_About, MyFrame::OnAbout)
|
EVT_MENU(Font_About, MyFrame::OnAbout)
|
||||||
|
EVT_MENU(Font_IncSize, MyFrame::OnIncFont)
|
||||||
|
EVT_MENU(Font_DecSize, MyFrame::OnDecFont)
|
||||||
EVT_MENU(Font_ViewMsg, MyFrame::OnViewMsg)
|
EVT_MENU(Font_ViewMsg, MyFrame::OnViewMsg)
|
||||||
EVT_MENU(Font_Choose, MyFrame::OnSelectFont)
|
EVT_MENU(Font_Choose, MyFrame::OnSelectFont)
|
||||||
EVT_MENU(Font_EnumFamiliesForEncoding, MyFrame::OnEnumerateFamiliesForEncoding)
|
EVT_MENU(Font_EnumFamiliesForEncoding, MyFrame::OnEnumerateFamiliesForEncoding)
|
||||||
@@ -191,6 +201,8 @@ bool MyApp::OnInit()
|
|||||||
MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
|
MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
|
||||||
: wxFrame((wxFrame *)NULL, -1, title, pos, size), m_textctrl(NULL)
|
: wxFrame((wxFrame *)NULL, -1, title, pos, size), m_textctrl(NULL)
|
||||||
{
|
{
|
||||||
|
m_fontSize = 12;
|
||||||
|
|
||||||
// create a menu bar
|
// create a menu bar
|
||||||
wxMenu *menuFile = new wxMenu;
|
wxMenu *menuFile = new wxMenu;
|
||||||
|
|
||||||
@@ -202,12 +214,15 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
|
|||||||
menuFile->Append(Font_Quit, "E&xit\tAlt-X", "Quit this program");
|
menuFile->Append(Font_Quit, "E&xit\tAlt-X", "Quit this program");
|
||||||
|
|
||||||
wxMenu *menuFont = new wxMenu;
|
wxMenu *menuFont = new wxMenu;
|
||||||
|
menuFont->Append(Font_IncSize, "&Increase font size by 2 points\tCtrl-I");
|
||||||
|
menuFont->Append(Font_DecSize, "&Decrease font size by 2 points\tCtrl-D");
|
||||||
|
menuFont->AppendSeparator();
|
||||||
menuFont->Append(Font_Choose, "&Select font...\tCtrl-S",
|
menuFont->Append(Font_Choose, "&Select font...\tCtrl-S",
|
||||||
"Select a standard font");
|
"Select a standard font");
|
||||||
menuFont->AppendSeparator();
|
menuFont->AppendSeparator();
|
||||||
menuFont->Append(Font_EnumFamilies, "Enumerate font &families\tCtrl-F");
|
menuFont->Append(Font_EnumFamilies, "Enumerate font &families\tCtrl-F");
|
||||||
menuFont->Append(Font_EnumFixedFamilies,
|
menuFont->Append(Font_EnumFixedFamilies,
|
||||||
"Enumerate f&ixed font families\tCtrl-I");
|
"Enumerate fi&xed font families\tCtrl-X");
|
||||||
menuFont->Append(Font_EnumEncodings,
|
menuFont->Append(Font_EnumEncodings,
|
||||||
"Enumerate &encodings\tCtrl-E");
|
"Enumerate &encodings\tCtrl-E");
|
||||||
menuFont->Append(Font_EnumFamiliesForEncoding,
|
menuFont->Append(Font_EnumFamiliesForEncoding,
|
||||||
@@ -391,6 +406,23 @@ void MyFrame::OnEnumerateFamiliesForEncoding(wxCommandEvent& WXUNUSED(event))
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MyFrame::DoResizeFont(int diff)
|
||||||
|
{
|
||||||
|
wxFont fontOld = m_canvas->GetTextFont();
|
||||||
|
|
||||||
|
DoChangeFont(
|
||||||
|
wxFont(
|
||||||
|
fontOld.GetPointSize() + diff,
|
||||||
|
fontOld.GetFamily(),
|
||||||
|
fontOld.GetStyle(),
|
||||||
|
fontOld.GetWeight(),
|
||||||
|
fontOld.GetUnderlined(),
|
||||||
|
fontOld.GetFaceName(),
|
||||||
|
fontOld.GetEncoding()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
void MyFrame::DoChangeFont(const wxFont& font, const wxColour& col)
|
void MyFrame::DoChangeFont(const wxFont& font, const wxColour& col)
|
||||||
{
|
{
|
||||||
Resize(GetSize(), font);
|
Resize(GetSize(), font);
|
||||||
@@ -610,7 +642,8 @@ void MyCanvas::OnPaint( wxPaintEvent &WXUNUSED(event) )
|
|||||||
|
|
||||||
// output the font name/info
|
// output the font name/info
|
||||||
wxString fontInfo;
|
wxString fontInfo;
|
||||||
fontInfo.Printf("Font family is '%s', style '%s', weight '%s'",
|
fontInfo.Printf("Font size is %d points, family is %s, style %s, weight %s",
|
||||||
|
m_font.GetPointSize(),
|
||||||
m_font.GetFamilyString().c_str(),
|
m_font.GetFamilyString().c_str(),
|
||||||
m_font.GetStyleString().c_str(),
|
m_font.GetStyleString().c_str(),
|
||||||
m_font.GetWeightString().c_str());
|
m_font.GetWeightString().c_str());
|
||||||
|
@@ -228,6 +228,11 @@ bool wxFont::FreeResource(bool force)
|
|||||||
}
|
}
|
||||||
|
|
||||||
WXHANDLE wxFont::GetResourceHandle()
|
WXHANDLE wxFont::GetResourceHandle()
|
||||||
|
{
|
||||||
|
return GetHFONT();
|
||||||
|
}
|
||||||
|
|
||||||
|
WXHFONT wxFont::GetHFONT() const
|
||||||
{
|
{
|
||||||
if ( !M_FONTDATA )
|
if ( !M_FONTDATA )
|
||||||
return 0;
|
return 0;
|
||||||
|
@@ -134,6 +134,9 @@ wxWindow *wxFindWinFromHandle(WXHWND hWnd);
|
|||||||
// mouse clicks
|
// mouse clicks
|
||||||
static void TranslateKbdEventToMouse(wxWindow *win, int *x, int *y, WPARAM *flags);
|
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
|
// event tables
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
@@ -1334,26 +1337,14 @@ void wxWindow::AdjustForParentClientOrigin(int& x, int& y, int sizeFlags)
|
|||||||
|
|
||||||
int wxWindow::GetCharHeight() const
|
int wxWindow::GetCharHeight() const
|
||||||
{
|
{
|
||||||
TEXTMETRIC lpTextMetric;
|
return wxGetTextMetrics(this).tmHeight;
|
||||||
HWND hWnd = GetHwnd();
|
|
||||||
HDC dc = ::GetDC(hWnd);
|
|
||||||
|
|
||||||
GetTextMetrics(dc, &lpTextMetric);
|
|
||||||
::ReleaseDC(hWnd, dc);
|
|
||||||
|
|
||||||
return lpTextMetric.tmHeight;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int wxWindow::GetCharWidth() const
|
int wxWindow::GetCharWidth() const
|
||||||
{
|
{
|
||||||
TEXTMETRIC lpTextMetric;
|
// +1 is needed because Windows apparently adds it when calculating the
|
||||||
HWND hWnd = GetHwnd();
|
// dialog units size in pixels
|
||||||
HDC dc = ::GetDC(hWnd);
|
return wxGetTextMetrics(this).tmAveCharWidth + 1;
|
||||||
|
|
||||||
GetTextMetrics(dc, &lpTextMetric);
|
|
||||||
::ReleaseDC(hWnd, dc);
|
|
||||||
|
|
||||||
return lpTextMetric.tmAveCharWidth;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxWindow::GetTextExtent(const wxString& string,
|
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);
|
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;
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user