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