]>
Commit | Line | Data |
---|---|---|
2bda0e17 | 1 | ///////////////////////////////////////////////////////////////////////////// |
1e6feb95 | 2 | // Name: src/msw/fontdlg.cpp |
2bda0e17 KB |
3 | // Purpose: wxFontDialog class |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 01/02/97 | |
7 | // RCS-ID: $Id$ | |
6c9a19aa | 8 | // Copyright: (c) Julian Smart |
65571936 | 9 | // Licence: wxWindows licence |
2bda0e17 KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
11c7d5b6 VZ |
12 | // ============================================================================ |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
14f355c2 | 20 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
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 | ||
1e6feb95 VZ |
31 | #if wxUSE_FONTDLG |
32 | ||
2bda0e17 | 33 | #ifndef WX_PRECOMP |
11c7d5b6 VZ |
34 | #include "wx/defs.h" |
35 | #include "wx/utils.h" | |
36 | #include "wx/dialog.h" | |
2bda0e17 KB |
37 | #endif |
38 | ||
39 | #include "wx/fontdlg.h" | |
4676948b | 40 | #include "wx/msw/private.h" |
2bda0e17 | 41 | |
4676948b | 42 | #if !defined(__WIN32__) || defined(__WXWINCE__) |
3bce6687 | 43 | #include <commdlg.h> |
2bda0e17 KB |
44 | #endif |
45 | ||
2bda0e17 | 46 | #include "wx/cmndata.h" |
01dba85a | 47 | #include "wx/log.h" |
2bda0e17 KB |
48 | |
49 | #include <math.h> | |
50 | #include <stdlib.h> | |
51 | #include <string.h> | |
52 | ||
11c7d5b6 VZ |
53 | // ---------------------------------------------------------------------------- |
54 | // wxWin macros | |
55 | // ---------------------------------------------------------------------------- | |
2bda0e17 | 56 | |
6fe19057 | 57 | IMPLEMENT_DYNAMIC_CLASS(wxFontDialog, wxDialog) |
2bda0e17 | 58 | |
11c7d5b6 VZ |
59 | // ============================================================================ |
60 | // implementation | |
61 | // ============================================================================ | |
2bda0e17 | 62 | |
11c7d5b6 VZ |
63 | // ---------------------------------------------------------------------------- |
64 | // wxFontDialog | |
65 | // ---------------------------------------------------------------------------- | |
2bda0e17 | 66 | |
11c7d5b6 | 67 | int wxFontDialog::ShowModal() |
2bda0e17 | 68 | { |
11c7d5b6 | 69 | DWORD flags = CF_SCREENFONTS | CF_NOSIMULATIONS; |
2bda0e17 | 70 | |
11c7d5b6 | 71 | LOGFONT logFont; |
2bda0e17 | 72 | |
11c7d5b6 VZ |
73 | CHOOSEFONT chooseFontStruct; |
74 | wxZeroMemory(chooseFontStruct); | |
2bda0e17 KB |
75 | |
76 | chooseFontStruct.lStructSize = sizeof(CHOOSEFONT); | |
11c7d5b6 VZ |
77 | if ( m_parent ) |
78 | chooseFontStruct.hwndOwner = GetHwndOf(m_parent); | |
2bda0e17 KB |
79 | chooseFontStruct.lpLogFont = &logFont; |
80 | ||
ae500232 | 81 | if ( m_fontData.m_initialFont.Ok() ) |
2bda0e17 | 82 | { |
11c7d5b6 | 83 | flags |= CF_INITTOLOGFONTSTRUCT; |
ae500232 | 84 | wxFillLogFont(&logFont, &m_fontData.m_initialFont); |
2bda0e17 KB |
85 | } |
86 | ||
ae500232 | 87 | if ( m_fontData.m_fontColour.Ok() ) |
951cf90d | 88 | { |
ae500232 | 89 | chooseFontStruct.rgbColors = wxColourToRGB(m_fontData.m_fontColour); |
951cf90d VZ |
90 | |
91 | // need this for the colour to be taken into account | |
92 | flags |= CF_EFFECTS; | |
93 | } | |
2bda0e17 | 94 | |
11c7d5b6 VZ |
95 | // CF_ANSIONLY flag is obsolete for Win32 |
96 | if ( !m_fontData.GetAllowSymbols() ) | |
97 | { | |
11c7d5b6 VZ |
98 | flags |= CF_SELECTSCRIPT; |
99 | logFont.lfCharSet = ANSI_CHARSET; | |
11c7d5b6 VZ |
100 | } |
101 | ||
102 | if ( m_fontData.GetEnableEffects() ) | |
2bda0e17 | 103 | flags |= CF_EFFECTS; |
11c7d5b6 | 104 | if ( m_fontData.GetShowHelp() ) |
2bda0e17 | 105 | flags |= CF_SHOWHELP; |
11c7d5b6 | 106 | |
ae500232 | 107 | if ( m_fontData.m_minSize != 0 || m_fontData.m_maxSize != 0 ) |
2bda0e17 | 108 | { |
ae500232 JS |
109 | chooseFontStruct.nSizeMin = m_fontData.m_minSize; |
110 | chooseFontStruct.nSizeMax = m_fontData.m_maxSize; | |
11c7d5b6 | 111 | flags |= CF_LIMITSIZE; |
2bda0e17 KB |
112 | } |
113 | ||
114 | chooseFontStruct.Flags = flags; | |
2bda0e17 | 115 | |
11c7d5b6 | 116 | if ( ChooseFont(&chooseFontStruct) != 0 ) |
2bda0e17 | 117 | { |
ae500232 JS |
118 | wxRGBToColour(m_fontData.m_fontColour, chooseFontStruct.rgbColors); |
119 | m_fontData.m_chosenFont = wxCreateFontFromLogFont(&logFont); | |
11c7d5b6 VZ |
120 | m_fontData.EncodingInfo().facename = logFont.lfFaceName; |
121 | m_fontData.EncodingInfo().charset = logFont.lfCharSet; | |
2bda0e17 | 122 | |
11c7d5b6 | 123 | return wxID_OK; |
2bda0e17 | 124 | } |
2bda0e17 | 125 | else |
a1d58ddc | 126 | { |
11c7d5b6 VZ |
127 | // common dialog failed - why? |
128 | #ifdef __WXDEBUG__ | |
129 | DWORD dwErr = CommDlgExtendedError(); | |
130 | if ( dwErr != 0 ) | |
131 | { | |
132 | // this msg is only for developers | |
133 | wxLogError(wxT("Common dialog failed with error code %0lx."), | |
134 | dwErr); | |
135 | } | |
136 | //else: it was just cancelled | |
137 | #endif | |
a1d58ddc | 138 | |
11c7d5b6 | 139 | return wxID_CANCEL; |
a1d58ddc | 140 | } |
2bda0e17 | 141 | } |
1e6feb95 VZ |
142 | |
143 | #endif // wxUSE_FONTDLG |