]> git.saurik.com Git - wxWidgets.git/blame - samples/font/font.cpp
Remove wxRTTI macro for wxComboBox from Motif port.
[wxWidgets.git] / samples / font / font.cpp
CommitLineData
1ccd74da
VZ
1/////////////////////////////////////////////////////////////////////////////
2// Name: font.cpp
3// Purpose: wxFont demo
4// Author: Vadim Zeitlin
5// Modified by:
6// Created: 30.09.99
7// RCS-ID: $Id$
36f210c8 8// Copyright: (c) 1999 Vadim Zeitlin
1ccd74da
VZ
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12// For compilers that support precompilation, includes "wx/wx.h".
92a19c2e 13#include "wx/wxprec.h"
1ccd74da
VZ
14
15#ifdef __BORLANDC__
16 #pragma hdrstop
17#endif
18
19// for all others, include the necessary headers (this file is usually all you
be5a51fb 20// need because it includes almost all standard wxWidgets headers
1ccd74da 21#ifndef WX_PRECOMP
84e89e2a 22 #include "wx/wx.h"
1ccd74da 23
84e89e2a 24 #include "wx/log.h"
1ccd74da
VZ
25#endif
26
84e89e2a
GD
27#include "wx/choicdlg.h"
28#include "wx/fontdlg.h"
29#include "wx/fontenum.h"
30#include "wx/fontmap.h"
31#include "wx/encconv.h"
32#include "wx/splitter.h"
33#include "wx/textfile.h"
6e19eb9c 34#include "wx/settings.h"
1ccd74da 35
18922659
JS
36#include "../sample.xpm"
37
925e9792 38#ifdef __WXMAC__
c6b72960 39 #undef wxFontDialog
509f339a 40 #include "wx/osx/fontdlg.h"
925e9792 41#endif
801d0407 42
c6b72960 43// used as title for several dialog boxes
9a83f860 44static const wxChar SAMPLE_TITLE[] = wxT("wxWidgets Font Sample");
c6b72960 45
1ccd74da
VZ
46// ----------------------------------------------------------------------------
47// private classes
48// ----------------------------------------------------------------------------
49
50// Define a new application type, each program should derive a class from wxApp
51class MyApp : public wxApp
52{
53public:
54 // override base class virtuals
55 // ----------------------------
56
57 // this one is called on application startup and is a good place for the app
58 // initialization (doing it here and not in the ctor allows to have an error
59 // return: if OnInit() returns false, the application terminates)
60 virtual bool OnInit();
61};
62
63// MyCanvas is a canvas on which we show the font sample
64class MyCanvas: public wxWindow
65{
66public:
67 MyCanvas( wxWindow *parent );
925e9792 68 virtual ~MyCanvas(){};
1ccd74da
VZ
69
70 // accessors for the frame
71 const wxFont& GetTextFont() const { return m_font; }
72 const wxColour& GetColour() const { return m_colour; }
73 void SetTextFont(const wxFont& font) { m_font = font; }
74 void SetColour(const wxColour& colour) { m_colour = colour; }
75
76 // event handlers
77 void OnPaint( wxPaintEvent &event );
78
79private:
80 wxColour m_colour;
81 wxFont m_font;
82
83 DECLARE_EVENT_TABLE()
84};
85
86// Define a new frame type: this is going to be our main frame
87class MyFrame : public wxFrame
88{
89public:
90 // ctor(s)
91 MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
92
93 // accessors
94 MyCanvas *GetCanvas() const { return m_canvas; }
95
96 // event handlers (these functions should _not_ be virtual)
97 void OnQuit(wxCommandEvent& event);
98 void OnAbout(wxCommandEvent& event);
409d5a58 99
d1f47235
DS
100 void OnIncFont(wxCommandEvent& WXUNUSED(event)) { DoResizeFont(+2); }
101 void OnDecFont(wxCommandEvent& WXUNUSED(event)) { DoResizeFont(-2); }
f6bcfd97 102
409d5a58 103 void OnBold(wxCommandEvent& event);
a82a59f5 104 void OnLight(wxCommandEvent& event);
ce00f59b 105
409d5a58 106 void OnItalic(wxCommandEvent& event);
a82a59f5 107 void OnSlant(wxCommandEvent& event);
ce00f59b 108
409d5a58 109 void OnUnderline(wxCommandEvent& event);
c7a49742 110 void OnStrikethrough(wxCommandEvent& event);
409d5a58 111
818503a1 112 void OnwxPointerFont(wxCommandEvent& event);
6e19eb9c 113 void OnwxSystemSettingsFont(wxCommandEvent& event);
818503a1 114
de47428c 115 void OnTestTextValue(wxCommandEvent& event);
3c1866e8 116 void OnViewMsg(wxCommandEvent& event);
1ccd74da 117 void OnSelectFont(wxCommandEvent& event);
36f210c8 118 void OnEnumerateFamiliesForEncoding(wxCommandEvent& event);
ddc8c2e3 119 void OnEnumerateFamilies(wxCommandEvent& WXUNUSED(event))
a7a5165c 120 { DoEnumerateFamilies(false); }
ddc8c2e3 121 void OnEnumerateFixedFamilies(wxCommandEvent& WXUNUSED(event))
a7a5165c 122 { DoEnumerateFamilies(true); }
d111a89a 123 void OnEnumerateEncodings(wxCommandEvent& event);
1ccd74da 124
c6b72960
VZ
125 void OnSetNativeDesc(wxCommandEvent& event);
126 void OnSetNativeUserDesc(wxCommandEvent& event);
ce00f59b 127
a82a59f5 128 void OnSetFamily(wxCommandEvent& event);
c6b72960
VZ
129 void OnSetFaceName(wxCommandEvent& event);
130 void OnSetEncoding(wxCommandEvent& event);
30764ab5 131
1ccd74da 132protected:
7beba2fc
VZ
133 bool DoEnumerateFamilies(bool fixedWidthOnly,
134 wxFontEncoding encoding = wxFONTENCODING_SYSTEM,
a7a5165c 135 bool silent = false);
36f210c8 136
f6bcfd97 137 void DoResizeFont(int diff);
a1d58ddc
VZ
138 void DoChangeFont(const wxFont& font, const wxColour& col = wxNullColour);
139
c6b72960
VZ
140 // ask the user to choose an encoding and return it or
141 // wxFONTENCODING_SYSTEM if the dialog was cancelled
142 wxFontEncoding GetEncodingFromUser();
143
a82a59f5
FM
144 // ask the user to choose a font family and return it or
145 // wxFONTFAMILY_DEFAULT if the dialog was cancelled
146 wxFontFamily GetFamilyFromUser();
c6b72960 147
f6bcfd97
BP
148 size_t m_fontSize; // in points
149
36f210c8
VZ
150 wxTextCtrl *m_textctrl;
151 MyCanvas *m_canvas;
1ccd74da
VZ
152
153private:
be5a51fb 154 // any class wishing to process wxWidgets events must use this macro
1ccd74da
VZ
155 DECLARE_EVENT_TABLE()
156};
157
1ccd74da
VZ
158// ----------------------------------------------------------------------------
159// constants
160// ----------------------------------------------------------------------------
161
162// IDs for the controls and the menu commands
163enum
164{
165 // menu items
6e19eb9c
FM
166 Font_Quit = wxID_EXIT,
167 Font_About = wxID_ABOUT,
ce00f59b 168
6e19eb9c 169 Font_ViewMsg = wxID_HIGHEST+1,
de47428c
VZ
170 Font_TestTextValue,
171
f6bcfd97
BP
172 Font_IncSize,
173 Font_DecSize,
ce00f59b 174
409d5a58 175 Font_Bold,
a82a59f5 176 Font_Light,
ce00f59b 177
409d5a58 178 Font_Italic,
a82a59f5 179 Font_Slant,
ce00f59b 180
409d5a58 181 Font_Underlined,
c7a49742 182 Font_Strikethrough,
ce00f59b 183
6e19eb9c 184 // standard global wxFont objects:
818503a1
VZ
185 Font_wxNORMAL_FONT,
186 Font_wxSMALL_FONT,
187 Font_wxITALIC_FONT,
188 Font_wxSWISS_FONT,
643dcb7a 189 Font_Standard,
818503a1 190
6e19eb9c
FM
191 // wxSystemSettings::GetFont possible objects:
192 Font_wxSYS_OEM_FIXED_FONT,
193 Font_wxSYS_ANSI_FIXED_FONT,
194 Font_wxSYS_ANSI_VAR_FONT,
195 Font_wxSYS_SYSTEM_FONT,
196 Font_wxSYS_DEVICE_DEFAULT_FONT,
197 Font_wxSYS_DEFAULT_GUI_FONT,
a82a59f5 198 Font_SystemSettings,
6e19eb9c 199
1ccd74da 200 Font_Choose = 100,
36f210c8 201 Font_EnumFamiliesForEncoding,
ddc8c2e3
VZ
202 Font_EnumFamilies,
203 Font_EnumFixedFamilies,
d111a89a 204 Font_EnumEncodings,
c6b72960
VZ
205 Font_SetNativeDesc,
206 Font_SetNativeUserDesc,
a82a59f5 207 Font_SetFamily,
c6b72960
VZ
208 Font_SetFaceName,
209 Font_SetEncoding,
189e08b4 210 Font_Max
1ccd74da
VZ
211};
212
213// ----------------------------------------------------------------------------
be5a51fb 214// event tables and other macros for wxWidgets
1ccd74da
VZ
215// ----------------------------------------------------------------------------
216
be5a51fb 217// the event tables connect the wxWidgets events with the functions (event
1ccd74da
VZ
218// handlers) which process them. It can be also done at run-time, but for the
219// simple menu events like this the static method is much simpler.
220BEGIN_EVENT_TABLE(MyFrame, wxFrame)
221 EVT_MENU(Font_Quit, MyFrame::OnQuit)
de47428c 222 EVT_MENU(Font_TestTextValue, MyFrame::OnTestTextValue)
409d5a58 223 EVT_MENU(Font_ViewMsg, MyFrame::OnViewMsg)
1ccd74da 224 EVT_MENU(Font_About, MyFrame::OnAbout)
409d5a58 225
f6bcfd97
BP
226 EVT_MENU(Font_IncSize, MyFrame::OnIncFont)
227 EVT_MENU(Font_DecSize, MyFrame::OnDecFont)
ce00f59b 228
409d5a58 229 EVT_MENU(Font_Bold, MyFrame::OnBold)
a82a59f5 230 EVT_MENU(Font_Light, MyFrame::OnLight)
ce00f59b 231
409d5a58 232 EVT_MENU(Font_Italic, MyFrame::OnItalic)
a82a59f5 233 EVT_MENU(Font_Slant, MyFrame::OnSlant)
ce00f59b 234
409d5a58 235 EVT_MENU(Font_Underlined, MyFrame::OnUnderline)
c7a49742 236 EVT_MENU(Font_Strikethrough, MyFrame::OnStrikethrough)
818503a1
VZ
237
238 EVT_MENU(Font_wxNORMAL_FONT, MyFrame::OnwxPointerFont)
239 EVT_MENU(Font_wxSMALL_FONT, MyFrame::OnwxPointerFont)
240 EVT_MENU(Font_wxITALIC_FONT, MyFrame::OnwxPointerFont)
241 EVT_MENU(Font_wxSWISS_FONT, MyFrame::OnwxPointerFont)
242
6e19eb9c
FM
243 EVT_MENU(Font_wxSYS_OEM_FIXED_FONT, MyFrame::OnwxSystemSettingsFont)
244 EVT_MENU(Font_wxSYS_ANSI_FIXED_FONT, MyFrame::OnwxSystemSettingsFont)
245 EVT_MENU(Font_wxSYS_ANSI_VAR_FONT, MyFrame::OnwxSystemSettingsFont)
246 EVT_MENU(Font_wxSYS_SYSTEM_FONT, MyFrame::OnwxSystemSettingsFont)
247 EVT_MENU(Font_wxSYS_DEVICE_DEFAULT_FONT, MyFrame::OnwxSystemSettingsFont)
248 EVT_MENU(Font_wxSYS_DEFAULT_GUI_FONT, MyFrame::OnwxSystemSettingsFont)
85ab460e 249
c6b72960
VZ
250 EVT_MENU(Font_SetNativeDesc, MyFrame::OnSetNativeDesc)
251 EVT_MENU(Font_SetNativeUserDesc, MyFrame::OnSetNativeUserDesc)
a82a59f5 252 EVT_MENU(Font_SetFamily, MyFrame::OnSetFamily)
c6b72960
VZ
253 EVT_MENU(Font_SetFaceName, MyFrame::OnSetFaceName)
254 EVT_MENU(Font_SetEncoding, MyFrame::OnSetEncoding)
409d5a58 255
1ccd74da 256 EVT_MENU(Font_Choose, MyFrame::OnSelectFont)
36f210c8 257 EVT_MENU(Font_EnumFamiliesForEncoding, MyFrame::OnEnumerateFamiliesForEncoding)
ddc8c2e3
VZ
258 EVT_MENU(Font_EnumFamilies, MyFrame::OnEnumerateFamilies)
259 EVT_MENU(Font_EnumFixedFamilies, MyFrame::OnEnumerateFixedFamilies)
d111a89a 260 EVT_MENU(Font_EnumEncodings, MyFrame::OnEnumerateEncodings)
1ccd74da
VZ
261END_EVENT_TABLE()
262
be5a51fb 263// Create a new application object: this macro will allow wxWidgets to create
1ccd74da
VZ
264// the application object during program execution (it's better than using a
265// static object for many reasons) and also declares the accessor function
266// wxGetApp() which will return the reference of the right type (i.e. MyApp and
267// not wxApp)
268IMPLEMENT_APP(MyApp)
269
270// ============================================================================
271// implementation
272// ============================================================================
273
274// ----------------------------------------------------------------------------
275// the application class
276// ----------------------------------------------------------------------------
277
278// `Main program' equivalent: the program execution "starts" here
279bool MyApp::OnInit()
280{
45e6e6f8
VZ
281 if ( !wxApp::OnInit() )
282 return false;
283
1ccd74da 284 // Create the main application window
be5a51fb 285 MyFrame *frame = new MyFrame(wxT("Font wxWidgets demo"),
53f6aab7 286 wxPoint(50, 50), wxSize(600, 400));
1ccd74da 287
18f42b94 288 // Show it
a7a5165c 289 frame->Show(true);
1ccd74da
VZ
290
291 // success: wxApp::OnRun() will be called which will enter the main message
a7a5165c 292 // loop and the application will run. If we returned 'false' here, the
1ccd74da 293 // application would exit immediately.
a7a5165c 294 return true;
1ccd74da
VZ
295}
296
297// ----------------------------------------------------------------------------
298// main frame
299// ----------------------------------------------------------------------------
300
301// frame constructor
302MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
a7a5165c 303 : wxFrame((wxFrame *)NULL, wxID_ANY, title, pos, size), m_textctrl(NULL)
1ccd74da 304{
63a8f2d3 305 m_fontSize = wxNORMAL_FONT->GetPointSize();
f6bcfd97 306
3cb332c1 307 SetIcon(wxICON(sample));
71307412 308
1ccd74da
VZ
309 // create a menu bar
310 wxMenu *menuFile = new wxMenu;
311
de47428c
VZ
312 menuFile->Append(Font_TestTextValue, wxT("&Test text value"),
313 wxT("Verify that getting and setting text value doesn't change it"));
2b5f62a0
VZ
314 menuFile->Append(Font_ViewMsg, wxT("&View...\tCtrl-V"),
315 wxT("View an email message file"));
3c1866e8 316 menuFile->AppendSeparator();
2d143b66 317 menuFile->Append(Font_About, wxT("&About\tCtrl-A"), wxT("Show about dialog"));
1ccd74da 318 menuFile->AppendSeparator();
2b5f62a0 319 menuFile->Append(Font_Quit, wxT("E&xit\tAlt-X"), wxT("Quit this program"));
1ccd74da
VZ
320
321 wxMenu *menuFont = new wxMenu;
2b5f62a0
VZ
322 menuFont->Append(Font_IncSize, wxT("&Increase font size by 2 points\tCtrl-I"));
323 menuFont->Append(Font_DecSize, wxT("&Decrease font size by 2 points\tCtrl-D"));
f6bcfd97 324 menuFont->AppendSeparator();
2153bf89 325 menuFont->AppendCheckItem(Font_Bold, wxT("&Bold\tCtrl-B"), wxT("Toggle bold state"));
a82a59f5
FM
326 menuFont->AppendCheckItem(Font_Light, wxT("&Light\tCtrl-L"), wxT("Toggle light state"));
327 menuFont->AppendSeparator();
2153bf89 328 menuFont->AppendCheckItem(Font_Italic, wxT("&Oblique\tCtrl-O"), wxT("Toggle italic state"));
f2c1b903
FM
329#ifndef __WXMSW__
330 // under wxMSW slant == italic so there's no reason to provide another menu item for the same thing
a82a59f5 331 menuFont->AppendCheckItem(Font_Slant, wxT("&Slant\tCtrl-S"), wxT("Toggle slant state"));
f2c1b903 332#endif
a82a59f5 333 menuFont->AppendSeparator();
2153bf89 334 menuFont->AppendCheckItem(Font_Underlined, wxT("&Underlined\tCtrl-U"),
a82a59f5 335 wxT("Toggle underlined state"));
c7a49742
VZ
336 menuFont->AppendCheckItem(Font_Strikethrough, wxT("&Strikethrough"),
337 wxT("Toggle strikethrough state"));
818503a1 338
ddc8c2e3 339 menuFont->AppendSeparator();
c6b72960 340 menuFont->Append(Font_SetNativeDesc,
1baec21f 341 wxT("Set native font &description\tShift-Ctrl-D"));
c6b72960 342 menuFont->Append(Font_SetNativeUserDesc,
1baec21f 343 wxT("Set &user font description\tShift-Ctrl-U"));
a82a59f5
FM
344 menuFont->AppendSeparator();
345 menuFont->Append(Font_SetFamily, wxT("Set font family"));
ce00f59b 346 menuFont->Append(Font_SetFaceName, wxT("Set font face name"));
c6b72960 347 menuFont->Append(Font_SetEncoding, wxT("Set font &encoding\tShift-Ctrl-E"));
409d5a58
VZ
348
349 wxMenu *menuSelect = new wxMenu;
2b5f62a0 350 menuSelect->Append(Font_Choose, wxT("&Select font...\tCtrl-S"),
a82a59f5 351 wxT("Select a standard font"));
818503a1
VZ
352
353 wxMenu *menuStdFonts = new wxMenu;
be5a51fb
JS
354 menuStdFonts->Append(Font_wxNORMAL_FONT, wxT("wxNORMAL_FONT"), wxT("Normal font used by wxWidgets"));
355 menuStdFonts->Append(Font_wxSMALL_FONT, wxT("wxSMALL_FONT"), wxT("Small font used by wxWidgets"));
356 menuStdFonts->Append(Font_wxITALIC_FONT, wxT("wxITALIC_FONT"), wxT("Italic font used by wxWidgets"));
357 menuStdFonts->Append(Font_wxSWISS_FONT, wxT("wxSWISS_FONT"), wxT("Swiss font used by wxWidgets"));
a82a59f5
FM
358 menuSelect->Append(Font_Standard, wxT("Standar&d fonts"), menuStdFonts);
359
360 wxMenu *menuSettingFonts = new wxMenu;
ce00f59b 361 menuSettingFonts->Append(Font_wxSYS_OEM_FIXED_FONT, wxT("wxSYS_OEM_FIXED_FONT"),
6e19eb9c 362 wxT("Original equipment manufacturer dependent fixed-pitch font."));
ce00f59b 363 menuSettingFonts->Append(Font_wxSYS_ANSI_FIXED_FONT, wxT("wxSYS_ANSI_FIXED_FONT"),
6e19eb9c 364 wxT("Windows fixed-pitch (monospaced) font. "));
ce00f59b 365 menuSettingFonts->Append(Font_wxSYS_ANSI_VAR_FONT, wxT("wxSYS_ANSI_VAR_FONT"),
6e19eb9c 366 wxT("Windows variable-pitch (proportional) font."));
ce00f59b 367 menuSettingFonts->Append(Font_wxSYS_SYSTEM_FONT, wxT("wxSYS_SYSTEM_FONT"),
6e19eb9c 368 wxT("System font."));
a82a59f5 369 menuSettingFonts->Append(Font_wxSYS_DEVICE_DEFAULT_FONT, wxT("wxSYS_DEVICE_DEFAULT_FONT"),
6e19eb9c 370 wxT("Device-dependent font."));
ce00f59b 371 menuSettingFonts->Append(Font_wxSYS_DEFAULT_GUI_FONT, wxT("wxSYS_DEFAULT_GUI_FONT"),
6e19eb9c 372 wxT("Default font for user interface objects such as menus and dialog boxes. "));
a82a59f5 373 menuSelect->Append(Font_SystemSettings, wxT("System fonts"), menuSettingFonts);
ce00f59b
VZ
374
375
409d5a58 376 menuSelect->AppendSeparator();
2b5f62a0 377 menuSelect->Append(Font_EnumFamilies, wxT("Enumerate font &families\tCtrl-F"));
409d5a58 378 menuSelect->Append(Font_EnumFixedFamilies,
2b5f62a0 379 wxT("Enumerate fi&xed font families\tCtrl-X"));
409d5a58 380 menuSelect->Append(Font_EnumEncodings,
2b5f62a0 381 wxT("Enumerate &encodings\tCtrl-E"));
409d5a58 382 menuSelect->Append(Font_EnumFamiliesForEncoding,
2b5f62a0
VZ
383 wxT("Find font for en&coding...\tCtrl-C"),
384 wxT("Find font families for given encoding"));
1ccd74da
VZ
385
386 // now append the freshly created menu to the menu bar...
387 wxMenuBar *menuBar = new wxMenuBar;
2b5f62a0
VZ
388 menuBar->Append(menuFile, wxT("&File"));
389 menuBar->Append(menuFont, wxT("F&ont"));
390 menuBar->Append(menuSelect, wxT("&Select"));
1ccd74da
VZ
391
392 // ... and attach this menu bar to the frame
393 SetMenuBar(menuBar);
394
75421bf1
VZ
395 wxSplitterWindow *splitter = new wxSplitterWindow(this);
396
a7a5165c 397 m_textctrl = new wxTextCtrl(splitter, wxID_ANY,
2b5f62a0 398 wxT("Paste text here to see how it looks\nlike in the given font"),
36f210c8
VZ
399 wxDefaultPosition, wxDefaultSize,
400 wxTE_MULTILINE);
401
75421bf1
VZ
402 m_canvas = new MyCanvas(splitter);
403
404 splitter->SplitHorizontally(m_textctrl, m_canvas, 100);
1ccd74da 405
8520f137 406#if wxUSE_STATUSBAR
1ccd74da 407 // create a status bar just for fun (by default with 1 pane only)
a1d58ddc 408 CreateStatusBar();
be5a51fb 409 SetStatusText(wxT("Welcome to wxWidgets font demo!"));
8520f137 410#endif // wxUSE_STATUSBAR
1ccd74da
VZ
411}
412
e680a378 413// --------------------------------------------------------
1ccd74da 414
e680a378 415class MyEncodingEnumerator : public wxFontEnumerator
d111a89a 416{
e680a378 417public:
bb84929e 418 MyEncodingEnumerator()
e680a378 419 { m_n = 0; }
d111a89a 420
bb84929e 421 const wxString& GetText() const
e680a378 422 { return m_text; }
d111a89a 423
e680a378
RR
424protected:
425 virtual bool OnFontEncoding(const wxString& facename,
426 const wxString& encoding)
427 {
428 wxString text;
801d0407
RN
429 text.Printf(wxT("Encoding %u: %s (available in facename '%s')\n"),
430 (unsigned int) ++m_n, encoding.c_str(), facename.c_str());
e680a378 431 m_text += text;
a7a5165c 432 return true;
e680a378 433 }
d111a89a 434
e680a378
RR
435private:
436 size_t m_n;
437 wxString m_text;
438};
d111a89a 439
e680a378
RR
440void MyFrame::OnEnumerateEncodings(wxCommandEvent& WXUNUSED(event))
441{
442 MyEncodingEnumerator fontEnumerator;
d111a89a
VZ
443
444 fontEnumerator.EnumerateEncodings();
445
4693b20c 446 wxLogMessage(wxT("Enumerating all available encodings:\n%s"),
d111a89a
VZ
447 fontEnumerator.GetText().c_str());
448}
1ccd74da 449
e680a378 450// -------------------------------------------------------------
36f210c8 451
e680a378
RR
452class MyFontEnumerator : public wxFontEnumerator
453{
454public:
bb84929e 455 bool GotAny() const
e680a378 456 { return !m_facenames.IsEmpty(); }
d111a89a 457
bb84929e 458 const wxArrayString& GetFacenames() const
e680a378 459 { return m_facenames; }
ddc8c2e3 460
e680a378
RR
461protected:
462 virtual bool OnFacename(const wxString& facename)
463 {
464 m_facenames.Add(facename);
a7a5165c 465 return true;
e680a378 466 }
ddc8c2e3
VZ
467
468 private:
a1d58ddc 469 wxArrayString m_facenames;
e680a378
RR
470} fontEnumerator;
471
472bool MyFrame::DoEnumerateFamilies(bool fixedWidthOnly,
473 wxFontEncoding encoding,
474 bool silent)
475{
476 MyFontEnumerator fontEnumerator;
ddc8c2e3 477
3c1866e8 478 fontEnumerator.EnumerateFacenames(encoding, fixedWidthOnly);
d111a89a 479
36f210c8
VZ
480 if ( fontEnumerator.GotAny() )
481 {
ea9144a3
VZ
482 int nFacenames = fontEnumerator.GetFacenames().GetCount();
483 if ( !silent )
484 {
4693b20c
MB
485 wxLogStatus(this, wxT("Found %d %sfonts"),
486 nFacenames, fixedWidthOnly ? wxT("fixed width ") : wxT(""));
ea9144a3 487 }
a1d58ddc 488
ea9144a3 489 wxString facename;
71307412 490
7beba2fc 491 if ( silent )
ea9144a3
VZ
492 {
493 // choose the first
494 facename = fontEnumerator.GetFacenames().Item(0);
495 }
7beba2fc 496 else
ea9144a3
VZ
497 {
498 // let the user choose
499 wxString *facenames = new wxString[nFacenames];
500 int n;
501 for ( n = 0; n < nFacenames; n++ )
502 facenames[n] = fontEnumerator.GetFacenames().Item(n);
503
c6b72960
VZ
504 n = wxGetSingleChoiceIndex
505 (
506 wxT("Choose a facename"),
507 SAMPLE_TITLE,
508 nFacenames,
509 facenames,
510 this
511 );
ea9144a3
VZ
512
513 if ( n != -1 )
514 facename = facenames[n];
515
516 delete [] facenames;
517 }
518
71307412 519 if ( !facename.empty() )
a1d58ddc 520 {
63a8f2d3
VZ
521 wxFont font(wxNORMAL_FONT->GetPointSize(),
522 wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL,
a7a5165c 523 wxFONTWEIGHT_NORMAL, false, facename, encoding);
a1d58ddc
VZ
524
525 DoChangeFont(font);
526 }
527
a7a5165c 528 return true;
36f210c8 529 }
7beba2fc 530 else if ( !silent )
36f210c8 531 {
4693b20c 532 wxLogWarning(wxT("No such fonts found."));
36f210c8 533 }
7beba2fc 534
a7a5165c 535 return false;
ddc8c2e3
VZ
536}
537
36f210c8 538void MyFrame::OnEnumerateFamiliesForEncoding(wxCommandEvent& WXUNUSED(event))
1ccd74da 539{
c6b72960
VZ
540 wxFontEncoding enc = GetEncodingFromUser();
541 if ( enc != wxFONTENCODING_SYSTEM )
36f210c8 542 {
c6b72960 543 DoEnumerateFamilies(false, enc);
36f210c8 544 }
1ccd74da
VZ
545}
546
c6b72960 547void MyFrame::OnSetNativeDesc(wxCommandEvent& WXUNUSED(event))
30764ab5 548{
1baec21f
VZ
549 wxString fontInfo = wxGetTextFromUser
550 (
551 wxT("Enter native font string"),
552 wxT("Input font description"),
553 m_canvas->GetTextFont().GetNativeFontInfoDesc(),
554 this
555 );
71307412 556 if ( fontInfo.empty() )
1baec21f
VZ
557 return; // user clicked "Cancel" - do nothing
558
559 wxFont font;
560 font.SetNativeFontInfo(fontInfo);
a1b806b9 561 if ( !font.IsOk() )
7826e2dd 562 {
1baec21f
VZ
563 wxLogError(wxT("Font info string \"%s\" is invalid."),
564 fontInfo.c_str());
565 return;
7826e2dd 566 }
ab5fe833 567
1baec21f 568 DoChangeFont(font);
30764ab5
VZ
569}
570
a82a59f5 571void MyFrame::OnSetNativeUserDesc(wxCommandEvent& WXUNUSED(event))
85ab460e 572{
a82a59f5
FM
573 wxString fontdesc = GetCanvas()->GetTextFont().GetNativeFontInfoUserDesc();
574 wxString fontUserInfo = wxGetTextFromUser(
575 wxT("Here you can edit current font description"),
576 wxT("Input font description"), fontdesc,
85ab460e 577 this);
a82a59f5 578 if (fontUserInfo.IsEmpty())
85ab460e
VZ
579 return; // user clicked "Cancel" - do nothing
580
a82a59f5
FM
581 wxFont font;
582 if (font.SetNativeFontInfoUserDesc(fontUserInfo))
85ab460e 583 {
a1b806b9 584 wxASSERT_MSG(font.IsOk(), wxT("The font should now be valid"));
85ab460e
VZ
585 DoChangeFont(font);
586 }
587 else
588 {
a1b806b9 589 wxASSERT_MSG(!font.IsOk(), wxT("The font should now be invalid"));
a82a59f5
FM
590 wxMessageBox(wxT("Error trying to create a font with such description..."));
591 }
85ab460e
VZ
592}
593
a82a59f5 594void MyFrame::OnSetFamily(wxCommandEvent& WXUNUSED(event))
85ab460e 595{
a82a59f5
FM
596 wxFontFamily f = GetFamilyFromUser();
597
598 wxFont font = m_canvas->GetTextFont();
599 font.SetFamily(f);
600 DoChangeFont(font);
601}
602
603void MyFrame::OnSetFaceName(wxCommandEvent& WXUNUSED(event))
604{
605 wxString facename = GetCanvas()->GetTextFont().GetFaceName();
606 wxString newFaceName = wxGetTextFromUser(
607 wxT("Here you can edit current font face name."),
608 wxT("Input font facename"), facename,
85ab460e 609 this);
a82a59f5 610 if (newFaceName.IsEmpty())
85ab460e
VZ
611 return; // user clicked "Cancel" - do nothing
612
a82a59f5
FM
613 wxFont font(GetCanvas()->GetTextFont());
614 if (font.SetFaceName(newFaceName)) // change facename only
85ab460e 615 {
a1b806b9 616 wxASSERT_MSG(font.IsOk(), wxT("The font should now be valid"));
85ab460e
VZ
617 DoChangeFont(font);
618 }
619 else
620 {
a1b806b9 621 wxASSERT_MSG(!font.IsOk(), wxT("The font should now be invalid"));
a82a59f5
FM
622 wxMessageBox(wxT("There is no font with such face name..."),
623 wxT("Invalid face name"), wxOK|wxICON_ERROR, this);
85ab460e
VZ
624 }
625}
626
c6b72960
VZ
627void MyFrame::OnSetEncoding(wxCommandEvent& WXUNUSED(event))
628{
629 wxFontEncoding enc = GetEncodingFromUser();
630 if ( enc == wxFONTENCODING_SYSTEM )
631 return;
632
633 wxFont font = m_canvas->GetTextFont();
634 font.SetEncoding(enc);
635 DoChangeFont(font);
636}
637
638wxFontEncoding MyFrame::GetEncodingFromUser()
639{
640 wxArrayString names;
641 wxArrayInt encodings;
642
643 const size_t count = wxFontMapper::GetSupportedEncodingsCount();
644 names.reserve(count);
645 encodings.reserve(count);
646
647 for ( size_t n = 0; n < count; n++ )
648 {
649 wxFontEncoding enc = wxFontMapper::GetEncoding(n);
650 encodings.push_back(enc);
651 names.push_back(wxFontMapper::GetEncodingName(enc));
652 }
653
654 int i = wxGetSingleChoiceIndex
655 (
656 wxT("Choose the encoding"),
657 SAMPLE_TITLE,
658 names,
659 this
660 );
661
662 return i == -1 ? wxFONTENCODING_SYSTEM : (wxFontEncoding)encodings[i];
663}
664
a82a59f5
FM
665wxFontFamily MyFrame::GetFamilyFromUser()
666{
667 wxArrayString names;
668 wxArrayInt families;
669
670 families.push_back(wxFONTFAMILY_DECORATIVE);
671 families.push_back(wxFONTFAMILY_ROMAN);
672 families.push_back(wxFONTFAMILY_SCRIPT);
673 families.push_back(wxFONTFAMILY_SWISS);
674 families.push_back(wxFONTFAMILY_MODERN);
675 families.push_back(wxFONTFAMILY_TELETYPE);
676
677 names.push_back("DECORATIVE");
678 names.push_back("ROMAN");
679 names.push_back("SCRIPT");
680 names.push_back("SWISS");
681 names.push_back("MODERN");
682 names.push_back("TELETYPE");
683
684 int i = wxGetSingleChoiceIndex
685 (
686 wxT("Choose the family"),
687 SAMPLE_TITLE,
688 names,
689 this
690 );
691
692 return i == -1 ? wxFONTFAMILY_DEFAULT : (wxFontFamily)families[i];
693}
694
f6bcfd97
BP
695void MyFrame::DoResizeFont(int diff)
696{
ab5fe833
VZ
697 wxFont font = m_canvas->GetTextFont();
698
699 font.SetPointSize(font.GetPointSize() + diff);
700 DoChangeFont(font);
f6bcfd97
BP
701}
702
409d5a58
VZ
703void MyFrame::OnBold(wxCommandEvent& event)
704{
705 wxFont font = m_canvas->GetTextFont();
706
707 font.SetWeight(event.IsChecked() ? wxFONTWEIGHT_BOLD : wxFONTWEIGHT_NORMAL);
708 DoChangeFont(font);
709}
710
a82a59f5
FM
711void MyFrame::OnLight(wxCommandEvent& event)
712{
713 wxFont font = m_canvas->GetTextFont();
714
715 font.SetWeight(event.IsChecked() ? wxFONTWEIGHT_LIGHT : wxFONTWEIGHT_NORMAL);
716 DoChangeFont(font);
717}
718
409d5a58
VZ
719void MyFrame::OnItalic(wxCommandEvent& event)
720{
721 wxFont font = m_canvas->GetTextFont();
722
723 font.SetStyle(event.IsChecked() ? wxFONTSTYLE_ITALIC : wxFONTSTYLE_NORMAL);
724 DoChangeFont(font);
725}
726
a82a59f5
FM
727void MyFrame::OnSlant(wxCommandEvent& event)
728{
729 wxFont font = m_canvas->GetTextFont();
730
731 font.SetStyle(event.IsChecked() ? wxFONTSTYLE_SLANT : wxFONTSTYLE_NORMAL);
732 DoChangeFont(font);
733}
734
409d5a58
VZ
735void MyFrame::OnUnderline(wxCommandEvent& event)
736{
737 wxFont font = m_canvas->GetTextFont();
738
739 font.SetUnderlined(event.IsChecked());
740 DoChangeFont(font);
741}
742
c7a49742
VZ
743void MyFrame::OnStrikethrough(wxCommandEvent& event)
744{
745 wxFont font = m_canvas->GetTextFont();
746 font.SetStrikethrough(event.IsChecked());
747 DoChangeFont(font);
748}
749
818503a1
VZ
750void MyFrame::OnwxPointerFont(wxCommandEvent& event)
751{
752 wxFont font;
753
c6b72960 754 switch ( event.GetId() )
818503a1 755 {
c6b72960
VZ
756 case Font_wxNORMAL_FONT:
757 font = *wxNORMAL_FONT;
758 break;
759
760 case Font_wxSMALL_FONT:
761 font = *wxSMALL_FONT;
762 break;
763
764 case Font_wxITALIC_FONT:
765 font = *wxITALIC_FONT;
766 break;
767
768 case Font_wxSWISS_FONT:
769 font = *wxSWISS_FONT;
770 break;
771
772 default:
773 wxFAIL_MSG( wxT("unknown standard font") );
774 return;
818503a1
VZ
775 }
776
6e19eb9c
FM
777 DoChangeFont(font);
778}
779
780void MyFrame::OnwxSystemSettingsFont(wxCommandEvent& event)
781{
782 wxFont font;
783
784 switch ( event.GetId() )
785 {
786 case Font_wxSYS_OEM_FIXED_FONT:
787 font = wxSystemSettings::GetFont(wxSYS_OEM_FIXED_FONT);
788 break;
789
790 case Font_wxSYS_ANSI_FIXED_FONT:
791 font = wxSystemSettings::GetFont(wxSYS_ANSI_FIXED_FONT);
792 break;
793
794 case Font_wxSYS_ANSI_VAR_FONT:
795 font = wxSystemSettings::GetFont(wxSYS_ANSI_VAR_FONT);
796 break;
797
798 case Font_wxSYS_SYSTEM_FONT:
799 font = wxSystemSettings::GetFont(wxSYS_SYSTEM_FONT);
800 break;
801
802 case Font_wxSYS_DEVICE_DEFAULT_FONT:
803 font = wxSystemSettings::GetFont(wxSYS_DEVICE_DEFAULT_FONT);
804 break;
805
806 case Font_wxSYS_DEFAULT_GUI_FONT:
807 font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
808 break;
809
810 default:
811 wxFAIL_MSG( wxT("unknown standard font") );
812 return;
813 }
814
818503a1
VZ
815 DoChangeFont(font);
816}
817
a1d58ddc
VZ
818void MyFrame::DoChangeFont(const wxFont& font, const wxColour& col)
819{
a1d58ddc 820 m_canvas->SetTextFont(font);
a1b806b9 821 if ( col.IsOk() )
a1d58ddc
VZ
822 m_canvas->SetColour(col);
823 m_canvas->Refresh();
824
825 m_textctrl->SetFont(font);
a1b806b9 826 if ( col.IsOk() )
a1d58ddc 827 m_textctrl->SetForegroundColour(col);
c7a49742 828 m_textctrl->Refresh();
85ab460e
VZ
829
830 // update the state of the bold/italic/underlined menu items
831 wxMenuBar *mbar = GetMenuBar();
832 if ( mbar )
833 {
a82a59f5 834 mbar->Check(Font_Light, font.GetWeight() == wxFONTWEIGHT_LIGHT);
85ab460e 835 mbar->Check(Font_Bold, font.GetWeight() == wxFONTWEIGHT_BOLD);
ce00f59b 836
85ab460e 837 mbar->Check(Font_Italic, font.GetStyle() == wxFONTSTYLE_ITALIC);
f2c1b903 838#ifndef __WXMSW__
a82a59f5 839 mbar->Check(Font_Slant, font.GetStyle() == wxFONTSTYLE_SLANT);
f2c1b903 840#endif
ce00f59b 841
85ab460e 842 mbar->Check(Font_Underlined, font.GetUnderlined());
c7a49742 843 mbar->Check(Font_Strikethrough, font.GetStrikethrough());
85ab460e 844 }
a1d58ddc
VZ
845}
846
1ccd74da
VZ
847void MyFrame::OnSelectFont(wxCommandEvent& WXUNUSED(event))
848{
849 wxFontData data;
850 data.SetInitialFont(m_canvas->GetTextFont());
851 data.SetColour(m_canvas->GetColour());
852
8fb97d46 853 wxFontDialog dialog(this, data);
1ccd74da
VZ
854 if ( dialog.ShowModal() == wxID_OK )
855 {
856 wxFontData retData = dialog.GetFontData();
36f210c8
VZ
857 wxFont font = retData.GetChosenFont();
858 wxColour colour = retData.GetColour();
859
a1d58ddc 860 DoChangeFont(font, colour);
1ccd74da
VZ
861 }
862}
863
864void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
865{
a7a5165c
WS
866 // true is to force the frame to close
867 Close(true);
1ccd74da
VZ
868}
869
de47428c
VZ
870void MyFrame::OnTestTextValue(wxCommandEvent& WXUNUSED(event))
871{
872 wxString value = m_textctrl->GetValue();
873 m_textctrl->SetValue(value);
874 if ( m_textctrl->GetValue() != value )
875 {
876 wxLogError(wxT("Text value changed after getting and setting it"));
877 }
878}
879
3c1866e8
VZ
880void MyFrame::OnViewMsg(wxCommandEvent& WXUNUSED(event))
881{
71307412 882#if wxUSE_FILEDLG
3c1866e8
VZ
883 // first, choose the file
884 static wxString s_dir, s_file;
2b5f62a0 885 wxFileDialog dialog(this, wxT("Open an email message file"),
3c1866e8
VZ
886 s_dir, s_file);
887 if ( dialog.ShowModal() != wxID_OK )
888 return;
889
890 // save for the next time
891 s_dir = dialog.GetDirectory();
892 s_file = dialog.GetFilename();
893
894 wxString filename = dialog.GetPath();
895
896 // load it and search for Content-Type header
897 wxTextFile file(filename);
898 if ( !file.Open() )
899 return;
900
901 wxString charset;
902
2b5f62a0
VZ
903 static const wxChar *prefix = wxT("Content-Type: text/plain; charset=");
904 const size_t len = wxStrlen(prefix);
3c1866e8
VZ
905
906 size_t n, count = file.GetLineCount();
907 for ( n = 0; n < count; n++ )
908 {
909 wxString line = file[n];
910
911 if ( !line )
912 {
913 // if it is an email message, headers are over, no need to parse
914 // all the file
915 break;
916 }
917
918 if ( line.Left(len) == prefix )
919 {
920 // found!
4693b20c 921 const wxChar *pc = line.c_str() + len;
2b5f62a0 922 if ( *pc == wxT('"') )
3c1866e8
VZ
923 pc++;
924
2b5f62a0 925 while ( *pc && *pc != wxT('"') )
3c1866e8
VZ
926 {
927 charset += *pc++;
928 }
929
930 break;
931 }
932 }
933
934 if ( !charset )
935 {
4693b20c 936 wxLogError(wxT("The file '%s' doesn't contain charset information."),
3c1866e8
VZ
937 filename.c_str());
938
939 return;
940 }
941
942 // ok, now get the corresponding encoding
142b3bc2 943 wxFontEncoding fontenc = wxFontMapper::Get()->CharsetToEncoding(charset);
3c1866e8
VZ
944 if ( fontenc == wxFONTENCODING_SYSTEM )
945 {
4693b20c 946 wxLogError(wxT("Charset '%s' is unsupported."), charset.c_str());
3c1866e8
VZ
947 return;
948 }
949
7337790c
VS
950 m_textctrl->LoadFile(filename);
951
bb84929e 952 if ( fontenc == wxFONTENCODING_UTF8 ||
142b3bc2 953 !wxFontMapper::Get()->IsEncodingAvailable(fontenc) )
7337790c
VS
954 {
955 // try to find some similar encoding:
3e2dd3db 956 wxFontEncoding encAlt;
142b3bc2 957 if ( wxFontMapper::Get()->GetAltForEncoding(fontenc, &encAlt) )
7337790c
VS
958 {
959 wxEncodingConverter conv;
bb84929e 960
3e2dd3db 961 if (conv.Init(fontenc, encAlt))
7337790c 962 {
3e2dd3db 963 fontenc = encAlt;
7337790c
VS
964 m_textctrl -> SetValue(conv.Convert(m_textctrl -> GetValue()));
965 }
966 else
3e2dd3db 967 {
4693b20c 968 wxLogWarning(wxT("Cannot convert from '%s' to '%s'."),
7337790c 969 wxFontMapper::GetEncodingDescription(fontenc).c_str(),
3e2dd3db
VZ
970 wxFontMapper::GetEncodingDescription(encAlt).c_str());
971 }
7337790c
VS
972 }
973 else
4693b20c 974 wxLogWarning(wxT("No fonts for encoding '%s' on this system."),
7337790c
VS
975 wxFontMapper::GetEncodingDescription(fontenc).c_str());
976 }
977
3c1866e8 978 // and now create the correct font
a7a5165c 979 if ( !DoEnumerateFamilies(false, fontenc, true /* silent */) )
7beba2fc 980 {
63a8f2d3
VZ
981 wxFont font(wxNORMAL_FONT->GetPointSize(),
982 wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL,
a7a5165c 983 wxFONTWEIGHT_NORMAL, false /* !underlined */,
7beba2fc 984 wxEmptyString /* facename */, fontenc);
a1b806b9 985 if ( font.IsOk() )
7beba2fc
VZ
986 {
987 DoChangeFont(font);
988 }
989 else
990 {
4693b20c 991 wxLogWarning(wxT("No fonts for encoding '%s' on this system."),
7beba2fc
VZ
992 wxFontMapper::GetEncodingDescription(fontenc).c_str());
993 }
994 }
71307412 995#endif // wxUSE_FILEDLG
3c1866e8
VZ
996}
997
1ccd74da
VZ
998void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
999{
de47428c
VZ
1000 wxMessageBox(wxT("wxWidgets font sample\n")
1001 wxT("(c) 1999-2006 Vadim Zeitlin"),
1002 wxString(wxT("About ")) + SAMPLE_TITLE,
1ccd74da
VZ
1003 wxOK | wxICON_INFORMATION, this);
1004}
1005
1ccd74da
VZ
1006// ----------------------------------------------------------------------------
1007// MyCanvas
1008// ----------------------------------------------------------------------------
1009
1010BEGIN_EVENT_TABLE(MyCanvas, wxWindow)
1011 EVT_PAINT(MyCanvas::OnPaint)
1012END_EVENT_TABLE()
1013
1014MyCanvas::MyCanvas( wxWindow *parent )
a7a5165c 1015 : wxWindow( parent, wxID_ANY ),
11c7d5b6 1016 m_colour(*wxRED), m_font(*wxNORMAL_FONT)
1ccd74da 1017{
1ccd74da
VZ
1018}
1019
1ccd74da
VZ
1020void MyCanvas::OnPaint( wxPaintEvent &WXUNUSED(event) )
1021{
1022 wxPaintDC dc(this);
1023 PrepareDC(dc);
1024
1025 // set background
de914436 1026 dc.SetBackground(*wxWHITE_BRUSH);
1ccd74da 1027 dc.Clear();
27db5c55 1028 dc.SetFont(m_font);
1ccd74da 1029
53f6aab7
VZ
1030 // one text line height
1031 wxCoord hLine = dc.GetCharHeight();
1032
1033 // the current text origin
1034 wxCoord x = 5,
1035 y = 5;
1036
1ccd74da
VZ
1037 // output the font name/info
1038 wxString fontInfo;
ce00f59b 1039
f2c1b903
FM
1040 fontInfo.Printf(wxT("Face name: %s, family: %s"),
1041 m_font.GetFaceName().c_str(),
1042 m_font.GetFamilyString().c_str());
1043
1044 dc.DrawText(fontInfo, x, y);
1045 y += hLine;
1046
27db5c55 1047 fontInfo.Printf(wxT("Size: %d points or %d pixels; %d*%d average char size"),
f6bcfd97 1048 m_font.GetPointSize(),
27db5c55
VZ
1049 m_font.GetPixelSize().y,
1050 dc.GetCharWidth(), dc.GetCharHeight());
53f6aab7
VZ
1051
1052 dc.DrawText(fontInfo, x, y);
1053 y += hLine;
7ab2c081 1054
27db5c55 1055 fontInfo.Printf(wxT("Style: %s, weight: %s, fixed width: %s, encoding: %s"),
1ccd74da 1056 m_font.GetStyleString().c_str(),
53f6aab7 1057 m_font.GetWeightString().c_str(),
27db5c55
VZ
1058 m_font.IsFixedWidth() ? wxT("yes") : wxT("no"),
1059 wxFontMapper::GetEncodingDescription(m_font.GetEncoding()));
1ccd74da 1060
53f6aab7
VZ
1061 dc.DrawText(fontInfo, x, y);
1062 y += hLine;
1ccd74da 1063
a1b806b9 1064 if ( m_font.IsOk() )
30764ab5 1065 {
ca2bd5e3 1066 const wxNativeFontInfo *info = m_font.GetNativeFontInfo();
409d5a58
VZ
1067 if ( info )
1068 {
409d5a58
VZ
1069 wxString fontDesc = m_font.GetNativeFontInfoUserDesc();
1070 fontInfo.Printf(wxT("Native font info: %s"), fontDesc.c_str());
1071
1072 dc.DrawText(fontInfo, x, y);
1073 y += hLine;
1074 }
30764ab5
VZ
1075 }
1076
53f6aab7 1077 y += hLine;
25faedaa 1078
1ccd74da 1079 // prepare to draw the font
1ccd74da
VZ
1080 dc.SetTextForeground(m_colour);
1081
25faedaa 1082 // the size of one cell (Normally biggest char + small margin)
6f207e66 1083 wxCoord maxCharWidth, maxCharHeight;
25faedaa
VZ
1084 dc.GetTextExtent(wxT("W"), &maxCharWidth, &maxCharHeight);
1085 int w = maxCharWidth + 5,
1086 h = maxCharHeight + 4;
1ccd74da 1087
1ccd74da
VZ
1088
1089 // print all font symbols from 32 to 256 in 7 rows of 32 chars each
25faedaa 1090 for ( int i = 0; i < 7; i++ )
1ccd74da
VZ
1091 {
1092 for ( int j = 0; j < 32; j++ )
1093 {
925e9792 1094 wxChar c = (wxChar)(32 * (i + 1) + j);
25faedaa 1095
6f207e66 1096 wxCoord charWidth, charHeight;
25faedaa
VZ
1097 dc.GetTextExtent(c, &charWidth, &charHeight);
1098 dc.DrawText
1099 (
1100 c,
1101 x + w*j + (maxCharWidth - charWidth) / 2 + 1,
1102 y + h*i + (maxCharHeight - charHeight) / 2
1103 );
1ccd74da
VZ
1104 }
1105 }
1106
1107 // draw the lines between them
de914436 1108 dc.SetPen(*wxBLUE_PEN);
1ccd74da
VZ
1109 int l;
1110
1111 // horizontal
1ccd74da
VZ
1112 for ( l = 0; l < 8; l++ )
1113 {
1114 int yl = y + h*l - 2;
25faedaa 1115 dc.DrawLine(x - 2, yl, x + 32*w - 1, yl);
1ccd74da
VZ
1116 }
1117
1118 // and vertical
1119 for ( l = 0; l < 33; l++ )
1120 {
1121 int xl = x + w*l - 2;
25faedaa 1122 dc.DrawLine(xl, y - 2, xl, y + 7*h - 1);
1ccd74da
VZ
1123 }
1124}