+ wxLogMessage("Enumerating all available encodings:\n%s",
+ fontEnumerator.GetText().c_str());
+}
+
+// -------------------------------------------------------------
+
+class MyFontEnumerator : public wxFontEnumerator
+{
+public:
+ bool GotAny() const
+ { return !m_facenames.IsEmpty(); }
+
+ const wxArrayString& GetFacenames() const
+ { return m_facenames; }
+
+protected:
+ virtual bool OnFacename(const wxString& facename)
+ {
+ m_facenames.Add(facename);
+ return TRUE;
+ }
+
+ private:
+ wxArrayString m_facenames;
+} fontEnumerator;
+
+bool MyFrame::DoEnumerateFamilies(bool fixedWidthOnly,
+ wxFontEncoding encoding,
+ bool silent)
+{
+ MyFontEnumerator fontEnumerator;
+
+ fontEnumerator.EnumerateFacenames(encoding, fixedWidthOnly);
+
+ if ( fontEnumerator.GotAny() )
+ {
+ int nFacenames = fontEnumerator.GetFacenames().GetCount();
+ if ( !silent )
+ {
+ wxLogStatus(this, "Found %d %sfonts",
+ nFacenames, fixedWidthOnly ? "fixed width " : "");
+ }
+
+ wxString facename;
+ if ( silent )
+ {
+ // choose the first
+ facename = fontEnumerator.GetFacenames().Item(0);
+ }
+ else
+ {
+ // let the user choose
+ wxString *facenames = new wxString[nFacenames];
+ int n;
+ for ( n = 0; n < nFacenames; n++ )
+ facenames[n] = fontEnumerator.GetFacenames().Item(n);
+
+ n = wxGetSingleChoiceIndex("Choose a facename", "Font demo",
+ nFacenames, facenames, this);
+
+ if ( n != -1 )
+ facename = facenames[n];
+
+ delete [] facenames;
+ }
+
+ if ( !facename.IsEmpty() )
+ {
+ wxFont font(12, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL,
+ wxFONTWEIGHT_NORMAL, FALSE, facename, encoding);
+
+ DoChangeFont(font);
+ }
+
+ return TRUE;
+ }
+ else if ( !silent )
+ {
+ wxLogWarning("No such fonts found.");
+ }
+
+ return FALSE;
+}
+
+void MyFrame::OnEnumerateFamiliesForEncoding(wxCommandEvent& WXUNUSED(event))
+{
+ static wxFontEncoding encodings[] =
+ {
+ wxFONTENCODING_ISO8859_1,
+ wxFONTENCODING_ISO8859_2,
+ wxFONTENCODING_ISO8859_5,
+ wxFONTENCODING_ISO8859_7,
+ wxFONTENCODING_ISO8859_15,
+ wxFONTENCODING_KOI8,
+ wxFONTENCODING_CP1250,
+ wxFONTENCODING_CP1251,
+ wxFONTENCODING_CP1252,
+ };
+
+ static const char *encodingNames[] =
+ {
+ "West European (Latin 1)",
+ "Central European (Latin 2)",
+ "Cyrillic (Latin 5)",
+ "Greek (Latin 7)",
+ "West European new (Latin 0)",
+ "KOI8-R",
+ "Windows Latin 2",
+ "Windows Cyrillic",
+ "Windows Latin 1",
+ };
+
+ int n = wxGetSingleChoiceIndex("Choose an encoding", "Font demo",
+ WXSIZEOF(encodingNames),
+ (char **)encodingNames,
+ this);
+
+ if ( n != -1 )
+ {
+ DoEnumerateFamilies(FALSE, encodings[n]);
+ }
+}
+
+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)
+{
+ Resize(GetSize(), font);
+
+ m_canvas->SetTextFont(font);
+ if ( col.Ok() )
+ m_canvas->SetColour(col);
+ m_canvas->Refresh();
+
+ m_textctrl->SetFont(font);
+ if ( col.Ok() )
+ m_textctrl->SetForegroundColour(col);