fix setting the properties of a valid but unshared font object broken in the last commit (HFONT wasn't recreated)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@44788 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -132,6 +132,9 @@ protected:
|
|||||||
const wxString& face = wxEmptyString,
|
const wxString& face = wxEmptyString,
|
||||||
wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
|
wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
|
||||||
|
|
||||||
|
// this is the same as FreeResource() followed by RealizeResource()
|
||||||
|
bool Recreate();
|
||||||
|
|
||||||
virtual void DoSetNativeFontInfo(const wxNativeFontInfo& info);
|
virtual void DoSetNativeFontInfo(const wxNativeFontInfo& info);
|
||||||
|
|
||||||
// implement wxObject virtuals which are used by AllocExclusive()
|
// implement wxObject virtuals which are used by AllocExclusive()
|
||||||
|
@@ -806,9 +806,7 @@ bool wxFont::Create(const wxNativeFontInfo& info, WXHFONT hFont)
|
|||||||
|
|
||||||
m_refData = new wxFontRefData(info, hFont);
|
m_refData = new wxFontRefData(info, hFont);
|
||||||
|
|
||||||
RealizeResource();
|
return RealizeResource();
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wxFont::wxFont(const wxString& fontdesc)
|
wxFont::wxFont(const wxString& fontdesc)
|
||||||
@@ -818,9 +816,6 @@ wxFont::wxFont(const wxString& fontdesc)
|
|||||||
(void)Create(info);
|
(void)Create(info);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Constructor for a font. Note that the real construction is done
|
|
||||||
* in wxDC::SetFont, when information is available about scaling etc.
|
|
||||||
*/
|
|
||||||
bool wxFont::DoCreate(int pointSize,
|
bool wxFont::DoCreate(int pointSize,
|
||||||
const wxSize& pixelSize,
|
const wxSize& pixelSize,
|
||||||
bool sizeUsingPixels,
|
bool sizeUsingPixels,
|
||||||
@@ -844,9 +839,7 @@ bool wxFont::DoCreate(int pointSize,
|
|||||||
family, style, weight,
|
family, style, weight,
|
||||||
underlined, faceName, encoding);
|
underlined, faceName, encoding);
|
||||||
|
|
||||||
RealizeResource();
|
return RealizeResource();
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wxFont::~wxFont()
|
wxFont::~wxFont()
|
||||||
@@ -869,26 +862,21 @@ wxObjectRefData *wxFont::CloneRefData(const wxObjectRefData *data) const
|
|||||||
|
|
||||||
bool wxFont::RealizeResource()
|
bool wxFont::RealizeResource()
|
||||||
{
|
{
|
||||||
if ( GetResourceHandle() )
|
// don't do anything if we already have a valid font
|
||||||
{
|
if ( GetHFONT() )
|
||||||
// VZ: the old code returned false in this case, but it doesn't seem
|
|
||||||
// to make sense because the font _was_ created
|
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
|
|
||||||
return M_FONTDATA->Alloc(this);
|
return M_FONTDATA->Alloc(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxFont::FreeResource(bool WXUNUSED(force))
|
bool wxFont::FreeResource(bool WXUNUSED(force))
|
||||||
{
|
{
|
||||||
if ( GetResourceHandle() )
|
if ( !GetHFONT() )
|
||||||
{
|
return false;
|
||||||
M_FONTDATA->Free();
|
|
||||||
|
|
||||||
return true;
|
M_FONTDATA->Free();
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
WXHANDLE wxFont::GetResourceHandle() const
|
WXHANDLE wxFont::GetResourceHandle() const
|
||||||
@@ -906,6 +894,17 @@ bool wxFont::IsFree() const
|
|||||||
return M_FONTDATA && (M_FONTDATA->GetHFONT() == 0);
|
return M_FONTDATA && (M_FONTDATA->GetHFONT() == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool wxFont::Recreate()
|
||||||
|
{
|
||||||
|
// this function can be used to recreate the font after its wxFontRefData
|
||||||
|
// changes and does it unconditionally, i.e. even if already had a valid
|
||||||
|
// font before
|
||||||
|
wxCHECK_MSG( M_FONTDATA, false, _T("no font to recreate") );
|
||||||
|
|
||||||
|
M_FONTDATA->Free();
|
||||||
|
return M_FONTDATA->Alloc(this);
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// change font attribute: we recreate font when doing it
|
// change font attribute: we recreate font when doing it
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@@ -916,7 +915,7 @@ void wxFont::SetPointSize(int pointSize)
|
|||||||
|
|
||||||
M_FONTDATA->SetPointSize(pointSize);
|
M_FONTDATA->SetPointSize(pointSize);
|
||||||
|
|
||||||
RealizeResource();
|
Recreate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxFont::SetPixelSize(const wxSize& pixelSize)
|
void wxFont::SetPixelSize(const wxSize& pixelSize)
|
||||||
@@ -925,7 +924,7 @@ void wxFont::SetPixelSize(const wxSize& pixelSize)
|
|||||||
|
|
||||||
M_FONTDATA->SetPixelSize(pixelSize);
|
M_FONTDATA->SetPixelSize(pixelSize);
|
||||||
|
|
||||||
RealizeResource();
|
Recreate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxFont::SetFamily(int family)
|
void wxFont::SetFamily(int family)
|
||||||
@@ -934,7 +933,7 @@ void wxFont::SetFamily(int family)
|
|||||||
|
|
||||||
M_FONTDATA->SetFamily(family);
|
M_FONTDATA->SetFamily(family);
|
||||||
|
|
||||||
RealizeResource();
|
Recreate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxFont::SetStyle(int style)
|
void wxFont::SetStyle(int style)
|
||||||
@@ -943,7 +942,7 @@ void wxFont::SetStyle(int style)
|
|||||||
|
|
||||||
M_FONTDATA->SetStyle(style);
|
M_FONTDATA->SetStyle(style);
|
||||||
|
|
||||||
RealizeResource();
|
Recreate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxFont::SetWeight(int weight)
|
void wxFont::SetWeight(int weight)
|
||||||
@@ -952,7 +951,7 @@ void wxFont::SetWeight(int weight)
|
|||||||
|
|
||||||
M_FONTDATA->SetWeight(weight);
|
M_FONTDATA->SetWeight(weight);
|
||||||
|
|
||||||
RealizeResource();
|
Recreate();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxFont::SetFaceName(const wxString& faceName)
|
bool wxFont::SetFaceName(const wxString& faceName)
|
||||||
@@ -961,7 +960,7 @@ bool wxFont::SetFaceName(const wxString& faceName)
|
|||||||
|
|
||||||
bool refdataok = M_FONTDATA->SetFaceName(faceName);
|
bool refdataok = M_FONTDATA->SetFaceName(faceName);
|
||||||
|
|
||||||
RealizeResource();
|
Recreate();
|
||||||
|
|
||||||
// NB: using win32's GetObject() API on M_FONTDATA->GetHFONT()
|
// NB: using win32's GetObject() API on M_FONTDATA->GetHFONT()
|
||||||
// to retrieve a LOGFONT and then compare lf.lfFaceName
|
// to retrieve a LOGFONT and then compare lf.lfFaceName
|
||||||
@@ -979,7 +978,7 @@ void wxFont::SetUnderlined(bool underlined)
|
|||||||
|
|
||||||
M_FONTDATA->SetUnderlined(underlined);
|
M_FONTDATA->SetUnderlined(underlined);
|
||||||
|
|
||||||
RealizeResource();
|
Recreate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxFont::SetEncoding(wxFontEncoding encoding)
|
void wxFont::SetEncoding(wxFontEncoding encoding)
|
||||||
@@ -988,7 +987,7 @@ void wxFont::SetEncoding(wxFontEncoding encoding)
|
|||||||
|
|
||||||
M_FONTDATA->SetEncoding(encoding);
|
M_FONTDATA->SetEncoding(encoding);
|
||||||
|
|
||||||
RealizeResource();
|
Recreate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxFont::DoSetNativeFontInfo(const wxNativeFontInfo& info)
|
void wxFont::DoSetNativeFontInfo(const wxNativeFontInfo& info)
|
||||||
@@ -997,7 +996,7 @@ void wxFont::DoSetNativeFontInfo(const wxNativeFontInfo& info)
|
|||||||
|
|
||||||
*M_FONTDATA = wxFontRefData(info);
|
*M_FONTDATA = wxFontRefData(info);
|
||||||
|
|
||||||
RealizeResource();
|
Recreate();
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
Reference in New Issue
Block a user