]> git.saurik.com Git - wxWidgets.git/blame - src/msw/fontdlg.cpp
Enable variadic macros for VC9 and later.
[wxWidgets.git] / src / msw / fontdlg.cpp
CommitLineData
2bda0e17 1/////////////////////////////////////////////////////////////////////////////
1e6feb95 2// Name: src/msw/fontdlg.cpp
2bda0e17
KB
3// Purpose: wxFontDialog class
4// Author: Julian Smart
5// Modified by:
6// Created: 01/02/97
7// RCS-ID: $Id$
6c9a19aa 8// Copyright: (c) Julian Smart
65571936 9// Licence: wxWindows licence
2bda0e17
KB
10/////////////////////////////////////////////////////////////////////////////
11
11c7d5b6
VZ
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
2bda0e17
KB
20// For compilers that support precompilation, includes "wx.h".
21#include "wx/wxprec.h"
22
23#ifdef __BORLANDC__
11c7d5b6 24 #pragma hdrstop
2bda0e17
KB
25#endif
26
1e6feb95
VZ
27#if wxUSE_FONTDLG
28
ce5d92e1
WS
29#include "wx/fontdlg.h"
30
2bda0e17 31#ifndef WX_PRECOMP
57bd4c60 32 #include "wx/msw/wrapcdlg.h"
11c7d5b6
VZ
33 #include "wx/utils.h"
34 #include "wx/dialog.h"
e4db172a 35 #include "wx/log.h"
18680f86 36 #include "wx/math.h"
2bda0e17
KB
37#endif
38
2bda0e17
KB
39#include <stdlib.h>
40#include <string.h>
41
11c7d5b6
VZ
42// ----------------------------------------------------------------------------
43// wxWin macros
44// ----------------------------------------------------------------------------
2bda0e17 45
6fe19057 46IMPLEMENT_DYNAMIC_CLASS(wxFontDialog, wxDialog)
2bda0e17 47
11c7d5b6
VZ
48// ============================================================================
49// implementation
50// ============================================================================
2bda0e17 51
11c7d5b6
VZ
52// ----------------------------------------------------------------------------
53// wxFontDialog
54// ----------------------------------------------------------------------------
2bda0e17 55
11c7d5b6 56int wxFontDialog::ShowModal()
2bda0e17 57{
5e80ff3d
JS
58 // It should be OK to always use GDI simulations
59 DWORD flags = CF_SCREENFONTS /* | CF_NOSIMULATIONS */ ;
2bda0e17 60
11c7d5b6 61 LOGFONT logFont;
2bda0e17 62
11c7d5b6
VZ
63 CHOOSEFONT chooseFontStruct;
64 wxZeroMemory(chooseFontStruct);
2bda0e17
KB
65
66 chooseFontStruct.lStructSize = sizeof(CHOOSEFONT);
11c7d5b6
VZ
67 if ( m_parent )
68 chooseFontStruct.hwndOwner = GetHwndOf(m_parent);
2bda0e17
KB
69 chooseFontStruct.lpLogFont = &logFont;
70
a1b806b9 71 if ( m_fontData.m_initialFont.IsOk() )
2bda0e17 72 {
11c7d5b6 73 flags |= CF_INITTOLOGFONTSTRUCT;
ae500232 74 wxFillLogFont(&logFont, &m_fontData.m_initialFont);
2bda0e17
KB
75 }
76
a1b806b9 77 if ( m_fontData.m_fontColour.IsOk() )
951cf90d 78 {
ae500232 79 chooseFontStruct.rgbColors = wxColourToRGB(m_fontData.m_fontColour);
951cf90d 80 }
2bda0e17 81
11c7d5b6
VZ
82 // CF_ANSIONLY flag is obsolete for Win32
83 if ( !m_fontData.GetAllowSymbols() )
84 {
11c7d5b6
VZ
85 flags |= CF_SELECTSCRIPT;
86 logFont.lfCharSet = ANSI_CHARSET;
11c7d5b6
VZ
87 }
88
89 if ( m_fontData.GetEnableEffects() )
2bda0e17 90 flags |= CF_EFFECTS;
11c7d5b6 91 if ( m_fontData.GetShowHelp() )
2bda0e17 92 flags |= CF_SHOWHELP;
11c7d5b6 93
ae500232 94 if ( m_fontData.m_minSize != 0 || m_fontData.m_maxSize != 0 )
2bda0e17 95 {
ae500232
JS
96 chooseFontStruct.nSizeMin = m_fontData.m_minSize;
97 chooseFontStruct.nSizeMax = m_fontData.m_maxSize;
11c7d5b6 98 flags |= CF_LIMITSIZE;
2bda0e17
KB
99 }
100
101 chooseFontStruct.Flags = flags;
2bda0e17 102
11c7d5b6 103 if ( ChooseFont(&chooseFontStruct) != 0 )
2bda0e17 104 {
ae500232
JS
105 wxRGBToColour(m_fontData.m_fontColour, chooseFontStruct.rgbColors);
106 m_fontData.m_chosenFont = wxCreateFontFromLogFont(&logFont);
11c7d5b6
VZ
107 m_fontData.EncodingInfo().facename = logFont.lfFaceName;
108 m_fontData.EncodingInfo().charset = logFont.lfCharSet;
2bda0e17 109
11c7d5b6 110 return wxID_OK;
2bda0e17 111 }
2bda0e17 112 else
a1d58ddc 113 {
11c7d5b6
VZ
114 DWORD dwErr = CommDlgExtendedError();
115 if ( dwErr != 0 )
116 {
4b6a582b 117 wxLogError(_("Common dialog failed with error code %0lx."), dwErr);
11c7d5b6
VZ
118 }
119 //else: it was just cancelled
a1d58ddc 120
11c7d5b6 121 return wxID_CANCEL;
a1d58ddc 122 }
2bda0e17 123}
1e6feb95
VZ
124
125#endif // wxUSE_FONTDLG