]> git.saurik.com Git - wxWidgets.git/blob - src/msw/fontdlg.cpp
Renamed FWD_ONLY_CURSORS to wxODBC_FWD_ONLY_CURSORS to avoid conflicts with other...
[wxWidgets.git] / src / msw / fontdlg.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: 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 and Markus Holzem
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 #ifdef __GNUG__
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 #ifndef WX_PRECOMP
32 #include "wx/defs.h"
33 #include "wx/utils.h"
34 #include "wx/dialog.h"
35 #endif
36
37 #include "wx/fontdlg.h"
38
39 #if !defined(__WIN32__) || defined(__SALFORDC__) || defined(__WXWINE__)
40 #include <commdlg.h>
41 #endif
42
43 #include "wx/msw/private.h"
44 #include "wx/cmndata.h"
45
46 #include <math.h>
47 #include <stdlib.h>
48 #include <string.h>
49
50 // ----------------------------------------------------------------------------
51 // wxWin macros
52 // ----------------------------------------------------------------------------
53
54 #if !USE_SHARED_LIBRARY
55 IMPLEMENT_DYNAMIC_CLASS(wxFontDialog, wxDialog)
56 #endif
57
58 // ============================================================================
59 // implementation
60 // ============================================================================
61
62 // ----------------------------------------------------------------------------
63 // wxFontDialog
64 // ----------------------------------------------------------------------------
65
66 wxFontDialog::wxFontDialog()
67 {
68 m_parent = NULL;
69 }
70
71 wxFontDialog::wxFontDialog(wxWindow *parent, wxFontData *data)
72 {
73 Create(parent, data);
74 }
75
76 bool wxFontDialog::Create(wxWindow *parent, wxFontData *data)
77 {
78 m_parent = parent;
79
80 wxCHECK_MSG( data, FALSE, _T("no font data in wxFontDialog") );
81
82 m_fontData = *data;
83
84 return TRUE;
85 }
86
87 int wxFontDialog::ShowModal()
88 {
89 DWORD flags = CF_SCREENFONTS | CF_NOSIMULATIONS;
90
91 LOGFONT logFont;
92
93 CHOOSEFONT chooseFontStruct;
94 wxZeroMemory(chooseFontStruct);
95
96 chooseFontStruct.lStructSize = sizeof(CHOOSEFONT);
97 if ( m_parent )
98 chooseFontStruct.hwndOwner = GetHwndOf(m_parent);
99 chooseFontStruct.lpLogFont = &logFont;
100
101 if ( m_fontData.initialFont.Ok() )
102 {
103 flags |= CF_INITTOLOGFONTSTRUCT;
104 wxFillLogFont(&logFont, &m_fontData.initialFont);
105 }
106
107 chooseFontStruct.rgbColors = wxColourToRGB(m_fontData.fontColour);
108
109 // CF_ANSIONLY flag is obsolete for Win32
110 if ( !m_fontData.GetAllowSymbols() )
111 {
112 #ifdef __WIN16__
113 flags |= CF_ANSIONLY;
114 #else // Win32
115 flags |= CF_SELECTSCRIPT;
116 logFont.lfCharSet = ANSI_CHARSET;
117 #endif // Win16/32
118 }
119
120 if ( m_fontData.GetEnableEffects() )
121 flags |= CF_EFFECTS;
122 if ( m_fontData.GetShowHelp() )
123 flags |= CF_SHOWHELP;
124
125 if ( m_fontData.minSize != 0 || m_fontData.maxSize != 0 )
126 {
127 chooseFontStruct.nSizeMin = m_fontData.minSize;
128 chooseFontStruct.nSizeMax = m_fontData.maxSize;
129 flags |= CF_LIMITSIZE;
130 }
131
132 chooseFontStruct.Flags = flags;
133
134 if ( ChooseFont(&chooseFontStruct) != 0 )
135 {
136 wxRGBToColour(m_fontData.fontColour, chooseFontStruct.rgbColors);
137 m_fontData.chosenFont = wxCreateFontFromLogFont(&logFont);
138 m_fontData.EncodingInfo().facename = logFont.lfFaceName;
139 m_fontData.EncodingInfo().charset = logFont.lfCharSet;
140
141 return wxID_OK;
142 }
143 else
144 {
145 // common dialog failed - why?
146 #ifdef __WXDEBUG__
147 DWORD dwErr = CommDlgExtendedError();
148 if ( dwErr != 0 )
149 {
150 // this msg is only for developers
151 wxLogError(wxT("Common dialog failed with error code %0lx."),
152 dwErr);
153 }
154 //else: it was just cancelled
155 #endif
156
157 return wxID_CANCEL;
158 }
159 }