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