]> git.saurik.com Git - wxWidgets.git/blame - src/msw/fontdlg.cpp
Fix compilation for some wxMSW configurations.
[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"
ce5d92e1 36 #include "wx/cmndata.h"
18680f86 37 #include "wx/math.h"
2bda0e17
KB
38#endif
39
2bda0e17
KB
40#include <stdlib.h>
41#include <string.h>
42
11c7d5b6
VZ
43// ----------------------------------------------------------------------------
44// wxWin macros
45// ----------------------------------------------------------------------------
2bda0e17 46
6fe19057 47IMPLEMENT_DYNAMIC_CLASS(wxFontDialog, wxDialog)
2bda0e17 48
11c7d5b6
VZ
49// ============================================================================
50// implementation
51// ============================================================================
2bda0e17 52
11c7d5b6
VZ
53// ----------------------------------------------------------------------------
54// wxFontDialog
55// ----------------------------------------------------------------------------
2bda0e17 56
11c7d5b6 57int wxFontDialog::ShowModal()
2bda0e17 58{
5e80ff3d
JS
59 // It should be OK to always use GDI simulations
60 DWORD flags = CF_SCREENFONTS /* | CF_NOSIMULATIONS */ ;
2bda0e17 61
11c7d5b6 62 LOGFONT logFont;
2bda0e17 63
11c7d5b6
VZ
64 CHOOSEFONT chooseFontStruct;
65 wxZeroMemory(chooseFontStruct);
2bda0e17
KB
66
67 chooseFontStruct.lStructSize = sizeof(CHOOSEFONT);
11c7d5b6
VZ
68 if ( m_parent )
69 chooseFontStruct.hwndOwner = GetHwndOf(m_parent);
2bda0e17
KB
70 chooseFontStruct.lpLogFont = &logFont;
71
ae500232 72 if ( m_fontData.m_initialFont.Ok() )
2bda0e17 73 {
11c7d5b6 74 flags |= CF_INITTOLOGFONTSTRUCT;
ae500232 75 wxFillLogFont(&logFont, &m_fontData.m_initialFont);
2bda0e17
KB
76 }
77
ae500232 78 if ( m_fontData.m_fontColour.Ok() )
951cf90d 79 {
ae500232 80 chooseFontStruct.rgbColors = wxColourToRGB(m_fontData.m_fontColour);
951cf90d 81 }
2bda0e17 82
11c7d5b6
VZ
83 // CF_ANSIONLY flag is obsolete for Win32
84 if ( !m_fontData.GetAllowSymbols() )
85 {
11c7d5b6
VZ
86 flags |= CF_SELECTSCRIPT;
87 logFont.lfCharSet = ANSI_CHARSET;
11c7d5b6
VZ
88 }
89
90 if ( m_fontData.GetEnableEffects() )
2bda0e17 91 flags |= CF_EFFECTS;
11c7d5b6 92 if ( m_fontData.GetShowHelp() )
2bda0e17 93 flags |= CF_SHOWHELP;
11c7d5b6 94
ae500232 95 if ( m_fontData.m_minSize != 0 || m_fontData.m_maxSize != 0 )
2bda0e17 96 {
ae500232
JS
97 chooseFontStruct.nSizeMin = m_fontData.m_minSize;
98 chooseFontStruct.nSizeMax = m_fontData.m_maxSize;
11c7d5b6 99 flags |= CF_LIMITSIZE;
2bda0e17
KB
100 }
101
102 chooseFontStruct.Flags = flags;
2bda0e17 103
11c7d5b6 104 if ( ChooseFont(&chooseFontStruct) != 0 )
2bda0e17 105 {
ae500232
JS
106 wxRGBToColour(m_fontData.m_fontColour, chooseFontStruct.rgbColors);
107 m_fontData.m_chosenFont = wxCreateFontFromLogFont(&logFont);
11c7d5b6
VZ
108 m_fontData.EncodingInfo().facename = logFont.lfFaceName;
109 m_fontData.EncodingInfo().charset = logFont.lfCharSet;
2bda0e17 110
11c7d5b6 111 return wxID_OK;
2bda0e17 112 }
2bda0e17 113 else
a1d58ddc 114 {
11c7d5b6
VZ
115 DWORD dwErr = CommDlgExtendedError();
116 if ( dwErr != 0 )
117 {
4b6a582b 118 wxLogError(_("Common dialog failed with error code %0lx."), dwErr);
11c7d5b6
VZ
119 }
120 //else: it was just cancelled
a1d58ddc 121
11c7d5b6 122 return wxID_CANCEL;
a1d58ddc 123 }
2bda0e17 124}
1e6feb95
VZ
125
126#endif // wxUSE_FONTDLG