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