]> git.saurik.com Git - wxWidgets.git/blob - src/msw/fontdlg.cpp
Also need to override Show
[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
31 #ifndef WX_PRECOMP
32 #include "wx/utils.h"
33 #include "wx/dialog.h"
34 #include "wx/log.h"
35 #include "wx/cmndata.h"
36 #include "wx/math.h"
37 #endif
38
39 #include "wx/msw/wrapcdlg.h"
40
41 #include <stdlib.h>
42 #include <string.h>
43
44 // ----------------------------------------------------------------------------
45 // wxWin macros
46 // ----------------------------------------------------------------------------
47
48 IMPLEMENT_DYNAMIC_CLASS(wxFontDialog, wxDialog)
49
50 // ============================================================================
51 // implementation
52 // ============================================================================
53
54 // ----------------------------------------------------------------------------
55 // wxFontDialog
56 // ----------------------------------------------------------------------------
57
58 int wxFontDialog::ShowModal()
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.Ok() )
74 {
75 flags |= CF_INITTOLOGFONTSTRUCT;
76 wxFillLogFont(&logFont, &m_fontData.m_initialFont);
77 }
78
79 if ( m_fontData.m_fontColour.Ok() )
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 // common dialog failed - why?
117 #ifdef __WXDEBUG__
118 DWORD dwErr = CommDlgExtendedError();
119 if ( dwErr != 0 )
120 {
121 // this msg is only for developers
122 wxLogError(wxT("Common dialog failed with error code %0lx."),
123 dwErr);
124 }
125 //else: it was just cancelled
126 #endif
127
128 return wxID_CANCEL;
129 }
130 }
131
132 #endif // wxUSE_FONTDLG