if ( m_nativeFontInfoOk )
return m_nativeFontInfo.SetFaceName(faceName);
- m_faceName = faceName;
+ m_faceName = faceName;
return true;
}
bool m_nativeFontInfoOk;
};
+#define M_FONTDATA ((wxFontRefData*)m_refData)
+
// ============================================================================
// implementation
// ============================================================================
// real implementation
// ----------------------------------------------------------------------------
+wxObjectRefData *wxFont::CreateRefData() const
+{
+ return new wxFontRefData();
+}
+
+wxObjectRefData *wxFont::CloneRefData(const wxObjectRefData *data) const
+{
+ return new wxFontRefData(*wx_static_cast(const wxFontRefData *, data));
+}
+
bool wxFont::RealizeResource()
{
if ( GetResourceHandle() )
return M_FONTDATA && (M_FONTDATA->GetHFONT() == 0);
}
-void wxFont::Unshare()
-{
- // Don't change shared data
- if ( !m_refData )
- {
- m_refData = new wxFontRefData();
- }
- else
- {
- wxFontRefData* ref = new wxFontRefData(*M_FONTDATA);
- UnRef();
- m_refData = ref;
- }
-}
-
// ----------------------------------------------------------------------------
// change font attribute: we recreate font when doing it
// ----------------------------------------------------------------------------
void wxFont::SetPointSize(int pointSize)
{
- Unshare();
+ AllocExclusive();
M_FONTDATA->SetPointSize(pointSize);
void wxFont::SetPixelSize(const wxSize& pixelSize)
{
- Unshare();
+ AllocExclusive();
M_FONTDATA->SetPixelSize(pixelSize);
void wxFont::SetFamily(int family)
{
- Unshare();
+ AllocExclusive();
M_FONTDATA->SetFamily(family);
void wxFont::SetStyle(int style)
{
- Unshare();
+ AllocExclusive();
M_FONTDATA->SetStyle(style);
void wxFont::SetWeight(int weight)
{
- Unshare();
+ AllocExclusive();
M_FONTDATA->SetWeight(weight);
bool wxFont::SetFaceName(const wxString& faceName)
{
- Unshare();
+ AllocExclusive();
bool refdataok = M_FONTDATA->SetFaceName(faceName);
void wxFont::SetUnderlined(bool underlined)
{
- Unshare();
+ AllocExclusive();
M_FONTDATA->SetUnderlined(underlined);
void wxFont::SetEncoding(wxFontEncoding encoding)
{
- Unshare();
+ AllocExclusive();
M_FONTDATA->SetEncoding(encoding);
void wxFont::DoSetNativeFontInfo(const wxNativeFontInfo& info)
{
- Unshare();
-
- FreeResource();
+ AllocExclusive();
*M_FONTDATA = wxFontRefData(info);
wxSize wxFont::GetPixelSize() const
{
+ wxCHECK_MSG( Ok(), wxDefaultSize, wxT("invalid font") );
+
return M_FONTDATA->GetPixelSize();
}
const wxNativeFontInfo *wxFont::GetNativeFontInfo() const
{
- return M_FONTDATA->HasNativeFontInfo() ? &(M_FONTDATA->GetNativeFontInfo())
+ return Ok() && M_FONTDATA->HasNativeFontInfo() ? &(M_FONTDATA->GetNativeFontInfo())
: NULL;
}
wxString wxFont::GetNativeFontInfoDesc() const
{
+ wxCHECK_MSG( Ok(), wxEmptyString, wxT("invalid font") );
+
// be sure we have an HFONT associated...
wxConstCast(this, wxFont)->RealizeResource();
return wxFontBase::GetNativeFontInfoDesc();
wxString wxFont::GetNativeFontInfoUserDesc() const
{
+ wxCHECK_MSG( Ok(), wxEmptyString, wxT("invalid font") );
+
// be sure we have an HFONT associated...
wxConstCast(this, wxFont)->RealizeResource();
return wxFontBase::GetNativeFontInfoUserDesc();