]> git.saurik.com Git - wxWidgets.git/blob - src/msw/fontdlg.cpp
fixed typo in previous commit which, instead of fixing the bug in wxSizerflags::Align...
[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 #ifndef WX_PRECOMP
30 #include "wx/defs.h"
31 #include "wx/utils.h"
32 #include "wx/dialog.h"
33 #endif
34
35 #include "wx/fontdlg.h"
36 #include "wx/msw/wrapcdlg.h"
37
38 #include "wx/cmndata.h"
39 #include "wx/log.h"
40 #include "wx/math.h"
41
42 #include <stdlib.h>
43 #include <string.h>
44
45 // ----------------------------------------------------------------------------
46 // wxWin macros
47 // ----------------------------------------------------------------------------
48
49 IMPLEMENT_DYNAMIC_CLASS(wxFontDialog, wxDialog)
50
51 // ============================================================================
52 // implementation
53 // ============================================================================
54
55 // ----------------------------------------------------------------------------
56 // wxFontDialog
57 // ----------------------------------------------------------------------------
58
59 int wxFontDialog::ShowModal()
60 {
61 // It should be OK to always use GDI simulations
62 DWORD flags = CF_SCREENFONTS /* | CF_NOSIMULATIONS */ ;
63
64 LOGFONT logFont;
65
66 CHOOSEFONT chooseFontStruct;
67 wxZeroMemory(chooseFontStruct);
68
69 chooseFontStruct.lStructSize = sizeof(CHOOSEFONT);
70 if ( m_parent )
71 chooseFontStruct.hwndOwner = GetHwndOf(m_parent);
72 chooseFontStruct.lpLogFont = &logFont;
73
74 if ( m_fontData.m_initialFont.Ok() )
75 {
76 flags |= CF_INITTOLOGFONTSTRUCT;
77 wxFillLogFont(&logFont, &m_fontData.m_initialFont);
78 }
79
80 if ( m_fontData.m_fontColour.Ok() )
81 {
82 chooseFontStruct.rgbColors = wxColourToRGB(m_fontData.m_fontColour);
83 }
84
85 // CF_ANSIONLY flag is obsolete for Win32
86 if ( !m_fontData.GetAllowSymbols() )
87 {
88 flags |= CF_SELECTSCRIPT;
89 logFont.lfCharSet = ANSI_CHARSET;
90 }
91
92 if ( m_fontData.GetEnableEffects() )
93 flags |= CF_EFFECTS;
94 if ( m_fontData.GetShowHelp() )
95 flags |= CF_SHOWHELP;
96
97 if ( m_fontData.m_minSize != 0 || m_fontData.m_maxSize != 0 )
98 {
99 chooseFontStruct.nSizeMin = m_fontData.m_minSize;
100 chooseFontStruct.nSizeMax = m_fontData.m_maxSize;
101 flags |= CF_LIMITSIZE;
102 }
103
104 chooseFontStruct.Flags = flags;
105
106 if ( ChooseFont(&chooseFontStruct) != 0 )
107 {
108 wxRGBToColour(m_fontData.m_fontColour, chooseFontStruct.rgbColors);
109 m_fontData.m_chosenFont = wxCreateFontFromLogFont(&logFont);
110 m_fontData.EncodingInfo().facename = logFont.lfFaceName;
111 m_fontData.EncodingInfo().charset = logFont.lfCharSet;
112
113 return wxID_OK;
114 }
115 else
116 {
117 // common dialog failed - why?
118 #ifdef __WXDEBUG__
119 DWORD dwErr = CommDlgExtendedError();
120 if ( dwErr != 0 )
121 {
122 // this msg is only for developers
123 wxLogError(wxT("Common dialog failed with error code %0lx."),
124 dwErr);
125 }
126 //else: it was just cancelled
127 #endif
128
129 return wxID_CANCEL;
130 }
131 }
132
133 #endif // wxUSE_FONTDLG