]> git.saurik.com Git - wxWidgets.git/blob - src/msw/fontdlg.cpp
Set the correct svn properties on the new files. Correct a minor date typo.
[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
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
22
23 #ifdef __BORLANDC__
24 #pragma hdrstop
25 #endif
26
27 #if wxUSE_FONTDLG
28
29 #include "wx/fontdlg.h"
30
31 #ifndef WX_PRECOMP
32 #include "wx/msw/wrapcdlg.h"
33 #include "wx/utils.h"
34 #include "wx/dialog.h"
35 #include "wx/log.h"
36 #include "wx/math.h"
37 #endif
38
39 #include <stdlib.h>
40 #include <string.h>
41
42 // ----------------------------------------------------------------------------
43 // wxWin macros
44 // ----------------------------------------------------------------------------
45
46 IMPLEMENT_DYNAMIC_CLASS(wxFontDialog, wxDialog)
47
48 // ============================================================================
49 // implementation
50 // ============================================================================
51
52 // ----------------------------------------------------------------------------
53 // wxFontDialog
54 // ----------------------------------------------------------------------------
55
56 int wxFontDialog::ShowModal()
57 {
58 // It should be OK to always use GDI simulations
59 DWORD flags = CF_SCREENFONTS /* | CF_NOSIMULATIONS */ ;
60
61 LOGFONT logFont;
62
63 CHOOSEFONT chooseFontStruct;
64 wxZeroMemory(chooseFontStruct);
65
66 chooseFontStruct.lStructSize = sizeof(CHOOSEFONT);
67 if ( m_parent )
68 chooseFontStruct.hwndOwner = GetHwndOf(m_parent);
69 chooseFontStruct.lpLogFont = &logFont;
70
71 if ( m_fontData.m_initialFont.Ok() )
72 {
73 flags |= CF_INITTOLOGFONTSTRUCT;
74 wxFillLogFont(&logFont, &m_fontData.m_initialFont);
75 }
76
77 if ( m_fontData.m_fontColour.Ok() )
78 {
79 chooseFontStruct.rgbColors = wxColourToRGB(m_fontData.m_fontColour);
80 }
81
82 // CF_ANSIONLY flag is obsolete for Win32
83 if ( !m_fontData.GetAllowSymbols() )
84 {
85 flags |= CF_SELECTSCRIPT;
86 logFont.lfCharSet = ANSI_CHARSET;
87 }
88
89 if ( m_fontData.GetEnableEffects() )
90 flags |= CF_EFFECTS;
91 if ( m_fontData.GetShowHelp() )
92 flags |= CF_SHOWHELP;
93
94 if ( m_fontData.m_minSize != 0 || m_fontData.m_maxSize != 0 )
95 {
96 chooseFontStruct.nSizeMin = m_fontData.m_minSize;
97 chooseFontStruct.nSizeMax = m_fontData.m_maxSize;
98 flags |= CF_LIMITSIZE;
99 }
100
101 chooseFontStruct.Flags = flags;
102
103 if ( ChooseFont(&chooseFontStruct) != 0 )
104 {
105 wxRGBToColour(m_fontData.m_fontColour, chooseFontStruct.rgbColors);
106 m_fontData.m_chosenFont = wxCreateFontFromLogFont(&logFont);
107 m_fontData.EncodingInfo().facename = logFont.lfFaceName;
108 m_fontData.EncodingInfo().charset = logFont.lfCharSet;
109
110 return wxID_OK;
111 }
112 else
113 {
114 DWORD dwErr = CommDlgExtendedError();
115 if ( dwErr != 0 )
116 {
117 wxLogError(_("Common dialog failed with error code %0lx."), dwErr);
118 }
119 //else: it was just cancelled
120
121 return wxID_CANCEL;
122 }
123 }
124
125 #endif // wxUSE_FONTDLG