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