1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxFontDialog class
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "fontdlg.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
27 #include "wx/dialog.h"
30 #include "wx/fontdlg.h"
34 #if !defined(__WIN32__) || defined(__SALFORDC__) || defined(__WXWINE__)
38 #include "wx/msw/private.h"
39 #include "wx/cmndata.h"
45 #define wxDIALOG_DEFAULT_X 300
46 #define wxDIALOG_DEFAULT_Y 300
48 #if !USE_SHARED_LIBRARY
49 IMPLEMENT_DYNAMIC_CLASS(wxFontDialog
, wxDialog
)
57 wxFontDialog::wxFontDialog(void)
59 m_dialogParent
= NULL
;
62 wxFontDialog::wxFontDialog(wxWindow
*parent
, wxFontData
*data
)
67 bool wxFontDialog::Create(wxWindow
*parent
, wxFontData
*data
)
69 m_dialogParent
= parent
;
76 int wxFontDialog::ShowModal(void)
78 CHOOSEFONT chooseFontStruct
;
81 DWORD flags
= CF_TTONLY
| CF_SCREENFONTS
| CF_NOSIMULATIONS
;
83 memset(&chooseFontStruct
, 0, sizeof(CHOOSEFONT
));
85 chooseFontStruct
.lStructSize
= sizeof(CHOOSEFONT
);
86 chooseFontStruct
.hwndOwner
= (HWND
) (m_dialogParent
? (HWND
) m_dialogParent
->GetHWND() : NULL
);
87 chooseFontStruct
.lpLogFont
= &logFont
;
89 if (m_fontData
.initialFont
.Ok())
91 flags
|= CF_INITTOLOGFONTSTRUCT
;
92 wxFillLogFont(&logFont
, & m_fontData
.initialFont
);
95 chooseFontStruct
.iPointSize
= 0;
96 chooseFontStruct
.rgbColors
= RGB((BYTE
)m_fontData
.fontColour
.Red(), (BYTE
)m_fontData
.fontColour
.Green(), (BYTE
)m_fontData
.fontColour
.Blue());
98 if (!m_fontData
.GetAllowSymbols())
100 if (m_fontData
.GetEnableEffects())
102 if (m_fontData
.GetShowHelp())
103 flags
|= CF_SHOWHELP
;
104 if (!(m_fontData
.minSize
== 0 && m_fontData
.maxSize
== 0))
106 chooseFontStruct
.nSizeMin
= m_fontData
.minSize
;
107 chooseFontStruct
.nSizeMax
= m_fontData
.maxSize
;
108 flags
|= CF_LIMITSIZE
;
111 chooseFontStruct
.Flags
= flags
;
112 chooseFontStruct
.nFontType
= SCREEN_FONTTYPE
;
113 bool success
= (ChooseFont(&(chooseFontStruct
)) != 0);
118 m_fontData
.fontColour
.Set(GetRValue(chooseFontStruct
.rgbColors
), GetGValue(chooseFontStruct
.rgbColors
),
119 GetBValue(chooseFontStruct
.rgbColors
));
120 m_fontData
.chosenFont
= wxCreateFontFromLogFont(&logFont
);
123 return success
? wxID_OK
: wxID_CANCEL
;
126 void wxFillLogFont(LOGFONT
*logFont
, wxFont
*font
)
131 wxString
ff_face("");
133 switch (font
->GetFamily())
135 case wxSCRIPT
: ff_family
= FF_SCRIPT
;
138 case wxDECORATIVE
: ff_family
= FF_DECORATIVE
;
140 case wxROMAN
: ff_family
= FF_ROMAN
;
141 ff_face
= "Times New Roman" ;
144 case wxMODERN
: ff_family
= FF_MODERN
;
145 ff_face
= "Courier New" ;
147 case wxSWISS
: ff_family
= FF_SWISS
;
151 default: ff_family
= FF_SWISS
;
152 ff_face
= "MS Sans Serif" ;
155 if (font
->GetStyle() == wxITALIC
|| font
->GetStyle() == wxSLANT
)
160 if (font
->GetWeight() == wxNORMAL
)
161 ff_weight
= FW_NORMAL
;
162 else if (font
->GetWeight() == wxLIGHT
)
163 ff_weight
= FW_LIGHT
;
164 else if (font
->GetWeight() == wxBOLD
)
167 // Have to get screen DC Caps, because a metafile will return 0.
168 HDC dc2
= ::GetDC(NULL
);
169 int ppInch
= ::GetDeviceCaps(dc2
, LOGPIXELSY
);
170 ::ReleaseDC(NULL
, dc2
);
172 // New behaviour: apparently ppInch varies according to
173 // Large/Small Fonts setting in Windows. This messes
174 // up fonts. So, set ppInch to a constant 96 dpi.
177 #if wxFONT_SIZE_COMPATIBILITY
178 // Incorrect, but compatible with old wxWindows behaviour
179 int nHeight
= (font
->GetPointSize()*ppInch
/72);
181 // Correct for Windows compatibility
182 int nHeight
= - (font
->GetPointSize()*ppInch
/72);
185 bool ff_underline
= font
->GetUnderlined();
187 ff_face
= font
->GetFaceName();
189 logFont
->lfHeight
= nHeight
;
190 logFont
->lfWidth
= 0;
191 logFont
->lfEscapement
= 0;
192 logFont
->lfOrientation
= 0;
193 logFont
->lfWeight
= ff_weight
;
194 logFont
->lfItalic
= ff_italic
;
195 logFont
->lfUnderline
= (BYTE
)ff_underline
;
196 logFont
->lfStrikeOut
= 0;
197 logFont
->lfCharSet
= ANSI_CHARSET
;
198 logFont
->lfOutPrecision
= OUT_DEFAULT_PRECIS
;
199 logFont
->lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
200 logFont
->lfQuality
= PROOF_QUALITY
;
201 logFont
->lfPitchAndFamily
= DEFAULT_PITCH
| ff_family
;
202 wxStrcpy(logFont
->lfFaceName
, ff_face
);
205 wxFont
wxCreateFontFromLogFont(LOGFONT
*logFont
) // , bool createNew)
207 int fontFamily
= wxSWISS
;
208 int fontStyle
= wxNORMAL
;
209 int fontWeight
= wxNORMAL
;
211 bool fontUnderline
= FALSE
;
212 wxChar
*fontFace
= NULL
;
214 // int lfFamily = logFont->lfPitchAndFamily & 0xF0;
215 int lfFamily
= logFont
->lfPitchAndFamily
;
216 if (lfFamily
& FIXED_PITCH
)
217 lfFamily
-= FIXED_PITCH
;
218 if (lfFamily
& VARIABLE_PITCH
)
219 lfFamily
-= VARIABLE_PITCH
;
224 fontFamily
= wxROMAN
;
227 fontFamily
= wxSWISS
;
230 fontFamily
= wxSCRIPT
;
233 fontFamily
= wxMODERN
;
236 fontFamily
= wxDECORATIVE
;
239 fontFamily
= wxSWISS
;
242 switch (logFont
->lfWeight
)
245 fontWeight
= wxLIGHT
;
248 fontWeight
= wxNORMAL
;
254 fontWeight
= wxNORMAL
;
257 if (logFont
->lfItalic
)
258 fontStyle
= wxITALIC
;
260 fontStyle
= wxNORMAL
;
262 if (logFont
->lfUnderline
)
263 fontUnderline
= TRUE
;
265 if (logFont
->lfFaceName
)
266 fontFace
= logFont
->lfFaceName
;
268 HDC dc2
= ::GetDC(NULL
);
270 if ( logFont
->lfHeight
< 0 )
271 logFont
->lfHeight
= - logFont
->lfHeight
;
272 fontPoints
= abs(72*logFont
->lfHeight
/GetDeviceCaps(dc2
, LOGPIXELSY
));
273 ::ReleaseDC(NULL
, dc2
);
276 return wxFont(fontPoints
, fontFamily
, fontStyle
, fontWeight
, fontUnderline
, fontFace
);
278 // return wxTheFontList->FindOrCreateFont(fontPoints, fontFamily, fontStyle, fontWeight, fontUnderline, fontFace);