]> git.saurik.com Git - wxWidgets.git/blob - src/msw/fontdlg.cpp
fixed compilation and added a test for OnErase() to the sample
[wxWidgets.git] / src / msw / fontdlg.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/fontdlg.cpp
3 // Purpose: wxFontDialog class
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 01/02/97
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 #ifdef __GNUG__
21 #pragma implementation "fontdlg.h"
22 #endif
23
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
26
27 #ifdef __BORLANDC__
28 #pragma hdrstop
29 #endif
30
31 #if wxUSE_FONTDLG
32
33 #ifndef WX_PRECOMP
34 #include "wx/defs.h"
35 #include "wx/utils.h"
36 #include "wx/dialog.h"
37 #endif
38
39 #include "wx/fontdlg.h"
40
41 #if !defined(__WIN32__) || defined(__SALFORDC__) || defined(__WXWINE__)
42 #include <commdlg.h>
43 #endif
44
45 #include "wx/msw/private.h"
46 #include "wx/cmndata.h"
47 #include "wx/log.h"
48
49 #include <math.h>
50 #include <stdlib.h>
51 #include <string.h>
52
53 // ----------------------------------------------------------------------------
54 // wxWin macros
55 // ----------------------------------------------------------------------------
56
57 IMPLEMENT_DYNAMIC_CLASS(wxFontDialog, wxDialog)
58
59 // ============================================================================
60 // implementation
61 // ============================================================================
62
63 // ----------------------------------------------------------------------------
64 // wxFontDialog
65 // ----------------------------------------------------------------------------
66
67 wxFontDialog::wxFontDialog()
68 {
69 m_parent = NULL;
70 }
71
72 wxFontDialog::wxFontDialog(wxWindow *parent, wxFontData *data)
73 {
74 Create(parent, data);
75 }
76
77 bool wxFontDialog::Create(wxWindow *parent, wxFontData *data)
78 {
79 m_parent = parent;
80
81 wxCHECK_MSG( data, FALSE, _T("no font data in wxFontDialog") );
82
83 m_fontData = *data;
84
85 return TRUE;
86 }
87
88 int wxFontDialog::ShowModal()
89 {
90 DWORD flags = CF_SCREENFONTS | CF_NOSIMULATIONS;
91
92 LOGFONT logFont;
93
94 CHOOSEFONT chooseFontStruct;
95 wxZeroMemory(chooseFontStruct);
96
97 chooseFontStruct.lStructSize = sizeof(CHOOSEFONT);
98 if ( m_parent )
99 chooseFontStruct.hwndOwner = GetHwndOf(m_parent);
100 chooseFontStruct.lpLogFont = &logFont;
101
102 if ( m_fontData.initialFont.Ok() )
103 {
104 flags |= CF_INITTOLOGFONTSTRUCT;
105 wxFillLogFont(&logFont, &m_fontData.initialFont);
106 }
107
108 if ( m_fontData.fontColour.Ok() )
109 {
110 chooseFontStruct.rgbColors = wxColourToRGB(m_fontData.fontColour);
111
112 // need this for the colour to be taken into account
113 flags |= CF_EFFECTS;
114 }
115
116 // CF_ANSIONLY flag is obsolete for Win32
117 if ( !m_fontData.GetAllowSymbols() )
118 {
119 #ifdef __WIN16__
120 flags |= CF_ANSIONLY;
121 #else // Win32
122 flags |= CF_SELECTSCRIPT;
123 logFont.lfCharSet = ANSI_CHARSET;
124 #endif // Win16/32
125 }
126
127 if ( m_fontData.GetEnableEffects() )
128 flags |= CF_EFFECTS;
129 if ( m_fontData.GetShowHelp() )
130 flags |= CF_SHOWHELP;
131
132 if ( m_fontData.minSize != 0 || m_fontData.maxSize != 0 )
133 {
134 chooseFontStruct.nSizeMin = m_fontData.minSize;
135 chooseFontStruct.nSizeMax = m_fontData.maxSize;
136 flags |= CF_LIMITSIZE;
137 }
138
139 chooseFontStruct.Flags = flags;
140
141 if ( ChooseFont(&chooseFontStruct) != 0 )
142 {
143 wxRGBToColour(m_fontData.fontColour, chooseFontStruct.rgbColors);
144 m_fontData.chosenFont = wxCreateFontFromLogFont(&logFont);
145 m_fontData.EncodingInfo().facename = logFont.lfFaceName;
146 m_fontData.EncodingInfo().charset = logFont.lfCharSet;
147
148 return wxID_OK;
149 }
150 else
151 {
152 // common dialog failed - why?
153 #ifdef __WXDEBUG__
154 DWORD dwErr = CommDlgExtendedError();
155 if ( dwErr != 0 )
156 {
157 // this msg is only for developers
158 wxLogError(wxT("Common dialog failed with error code %0lx."),
159 dwErr);
160 }
161 //else: it was just cancelled
162 #endif
163
164 return wxID_CANCEL;
165 }
166 }
167
168 #endif // wxUSE_FONTDLG