Fix harmless MinGW warning in wxMSW wxListCtrl code.
[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 #include "wx/modalhook.h"
31
32 #ifndef WX_PRECOMP
33 #include "wx/msw/wrapcdlg.h"
34 #include "wx/utils.h"
35 #include "wx/dialog.h"
36 #include "wx/log.h"
37 #include "wx/math.h"
38 #endif
39
40 #include <stdlib.h>
41 #include <string.h>
42
43 // ----------------------------------------------------------------------------
44 // wxWin macros
45 // ----------------------------------------------------------------------------
46
47 IMPLEMENT_DYNAMIC_CLASS(wxFontDialog, wxDialog)
48
49 // ============================================================================
50 // implementation
51 // ============================================================================
52
53 // ----------------------------------------------------------------------------
54 // wxFontDialog
55 // ----------------------------------------------------------------------------
56
57 int wxFontDialog::ShowModal()
58 {
59 WX_HOOK_MODAL_DIALOG();
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.IsOk() )
75 {
76 flags |= CF_INITTOLOGFONTSTRUCT;
77 wxFillLogFont(&logFont, &m_fontData.m_initialFont);
78 }
79
80 if ( m_fontData.m_fontColour.IsOk() )
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 DWORD dwErr = CommDlgExtendedError();
118 if ( dwErr != 0 )
119 {
120 wxLogError(_("Common dialog failed with error code %0lx."), dwErr);
121 }
122 //else: it was just cancelled
123
124 return wxID_CANCEL;
125 }
126 }
127
128 #endif // wxUSE_FONTDLG