+ CreateStatusBar();
+ SetStatusText("Welcome to wxWindows font demo!");
+}
+
+// --------------------------------------------------------
+
+class MyEncodingEnumerator : public wxFontEnumerator
+{
+public:
+ MyEncodingEnumerator()
+ { m_n = 0; }
+
+ const wxString& GetText() const
+ { return m_text; }
+
+protected:
+ virtual bool OnFontEncoding(const wxString& facename,
+ const wxString& encoding)
+ {
+ wxString text;
+ text.Printf("Encoding %d: %s (available in facename '%s')\n",
+ ++m_n, encoding.c_str(), facename.c_str());
+ m_text += text;
+ return TRUE;
+ }
+
+private:
+ size_t m_n;
+ wxString m_text;
+};
+
+void MyFrame::OnEnumerateEncodings(wxCommandEvent& WXUNUSED(event))
+{
+ MyEncodingEnumerator fontEnumerator;
+
+ fontEnumerator.EnumerateEncodings();
+
+ 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 wxString encodingNames[] =
+ {
+ "Western European (ISO-8859-1)",
+ "Central European (ISO-8859-2)",
+ "Cyrillic (ISO-8859-5)",
+ "Greek (ISO-8859-7)",
+ "Western European with Euro (ISO-8859-15)",
+ "KOI8-R",
+ "Windows Central European (CP 1250)",
+ "Windows Cyrillic (CP 1251)",
+ "Windows Western European (CP 1252)",
+ };
+
+ int n = wxGetSingleChoiceIndex("Choose an encoding", "Font demo",
+ WXSIZEOF(encodingNames),
+ encodingNames,
+ this);
+
+ if ( n != -1 )
+ {
+ DoEnumerateFamilies(FALSE, encodings[n]);
+ }