#endif
#include <wx/fontdlg.h>
+#include <wx/fontenum.h>
// ----------------------------------------------------------------------------
// private classes
void OnAbout(wxCommandEvent& event);
void OnSelectFont(wxCommandEvent& event);
void OnCreateFont(wxCommandEvent& event);
+ void OnEnumerateFamilies(wxCommandEvent& WXUNUSED(event))
+ { DoEnumerateFamilies(FALSE); }
+ void OnEnumerateFixedFamilies(wxCommandEvent& WXUNUSED(event))
+ { DoEnumerateFamilies(TRUE); }
protected:
+ void DoEnumerateFamilies(bool fixedWidthOnly);
+
MyCanvas *m_canvas;
private:
Font_Quit = 1,
Font_About,
Font_Choose = 100,
- Font_Create
+ Font_Create,
+ Font_EnumFamilies,
+ Font_EnumFixedFamilies,
+ Font_Max
};
// ----------------------------------------------------------------------------
EVT_MENU(Font_About, MyFrame::OnAbout)
EVT_MENU(Font_Choose, MyFrame::OnSelectFont)
EVT_MENU(Font_Create, MyFrame::OnCreateFont)
+ EVT_MENU(Font_EnumFamilies, MyFrame::OnEnumerateFamilies)
+ EVT_MENU(Font_EnumFixedFamilies, MyFrame::OnEnumerateFixedFamilies)
END_EVENT_TABLE()
// Create a new application object: this macro will allow wxWindows to create
bool MyApp::OnInit()
{
// Create the main application window
- MyFrame *frame = new MyFrame("Minimal wxWindows App",
+ MyFrame *frame = new MyFrame("Font wxWindows demo",
wxPoint(50, 50), wxSize(450, 340));
// Show it and tell the application that it's our main window
MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
: wxFrame((wxFrame *)NULL, -1, title, pos, size)
{
- // set the frame icon
- SetIcon(wxICON(mondrian));
-
// create a menu bar
wxMenu *menuFile = new wxMenu;
menuFile->Append(Font_Quit, "E&xit\tAlt-X", "Quit this program");
wxMenu *menuFont = new wxMenu;
- menuFont->Append(Font_Choose, "&Select font...\tCtrl-F",
+ menuFont->Append(Font_Choose, "&Select font...\tCtrl-S",
"Select a standard font");
menuFont->Append(Font_Create, "&Create font...\tCtrl-C",
"Create a custom font");
+ menuFont->AppendSeparator();
+ menuFont->Append(Font_EnumFamilies, "&Enumerate font families\tCtrl-E");
+ menuFont->Append(Font_EnumFixedFamilies,
+ "&Enumerate fixed font families\tCtrl-F");
// now append the freshly created menu to the menu bar...
wxMenuBar *menuBar = new wxMenuBar;
// event handlers
+void MyFrame::DoEnumerateFamilies(bool fixedWidthOnly)
+{
+ class MyFontEnumerator : public wxFontEnumerator
+ {
+ public:
+ MyFontEnumerator() { m_n = 0; }
+
+ protected:
+ virtual bool OnFontFamily(const wxString& family)
+ {
+ wxLogMessage("Font family %d: %s\n", ++m_n, family.c_str());
+
+ return TRUE;
+ }
+
+ private:
+ size_t m_n;
+ } fontEnumerator;
+
+ wxLogMessage("Enumerating %s font families:",
+ fixedWidthOnly ? "fixed width" : "all");
+ fontEnumerator.EnumerateFamilies(fixedWidthOnly);
+}
+
void MyFrame::OnCreateFont(wxCommandEvent& WXUNUSED(event))
{
MyFontDialog dialog(this);