]>
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 |
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 | ||
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" | |
40 | ||
b4da152e | 41 | #if !defined(__WIN32__) || defined(__SALFORDC__) |
3bce6687 JS |
42 | #include <windows.h> |
43 | #include <commdlg.h> | |
2bda0e17 KB |
44 | #endif |
45 | ||
46 | #include "wx/msw/private.h" | |
47 | #include "wx/cmndata.h" | |
01dba85a | 48 | #include "wx/log.h" |
2bda0e17 KB |
49 | |
50 | #include <math.h> | |
51 | #include <stdlib.h> | |
52 | #include <string.h> | |
53 | ||
11c7d5b6 VZ |
54 | // ---------------------------------------------------------------------------- |
55 | // wxWin macros | |
56 | // ---------------------------------------------------------------------------- | |
2bda0e17 | 57 | |
6fe19057 | 58 | IMPLEMENT_DYNAMIC_CLASS(wxFontDialog, wxDialog) |
2bda0e17 | 59 | |
11c7d5b6 VZ |
60 | // ============================================================================ |
61 | // implementation | |
62 | // ============================================================================ | |
2bda0e17 | 63 | |
11c7d5b6 VZ |
64 | // ---------------------------------------------------------------------------- |
65 | // wxFontDialog | |
66 | // ---------------------------------------------------------------------------- | |
2bda0e17 | 67 | |
11c7d5b6 | 68 | int wxFontDialog::ShowModal() |
2bda0e17 | 69 | { |
11c7d5b6 | 70 | DWORD flags = CF_SCREENFONTS | CF_NOSIMULATIONS; |
2bda0e17 | 71 | |
11c7d5b6 | 72 | LOGFONT logFont; |
2bda0e17 | 73 | |
11c7d5b6 VZ |
74 | CHOOSEFONT chooseFontStruct; |
75 | wxZeroMemory(chooseFontStruct); | |
2bda0e17 KB |
76 | |
77 | chooseFontStruct.lStructSize = sizeof(CHOOSEFONT); | |
11c7d5b6 VZ |
78 | if ( m_parent ) |
79 | chooseFontStruct.hwndOwner = GetHwndOf(m_parent); | |
2bda0e17 KB |
80 | chooseFontStruct.lpLogFont = &logFont; |
81 | ||
11c7d5b6 | 82 | if ( m_fontData.initialFont.Ok() ) |
2bda0e17 | 83 | { |
11c7d5b6 VZ |
84 | flags |= CF_INITTOLOGFONTSTRUCT; |
85 | wxFillLogFont(&logFont, &m_fontData.initialFont); | |
2bda0e17 KB |
86 | } |
87 | ||
951cf90d VZ |
88 | if ( m_fontData.fontColour.Ok() ) |
89 | { | |
90 | chooseFontStruct.rgbColors = wxColourToRGB(m_fontData.fontColour); | |
91 | ||
92 | // need this for the colour to be taken into account | |
93 | flags |= CF_EFFECTS; | |
94 | } | |
2bda0e17 | 95 | |
11c7d5b6 VZ |
96 | // CF_ANSIONLY flag is obsolete for Win32 |
97 | if ( !m_fontData.GetAllowSymbols() ) | |
98 | { | |
99 | #ifdef __WIN16__ | |
2bda0e17 | 100 | flags |= CF_ANSIONLY; |
11c7d5b6 VZ |
101 | #else // Win32 |
102 | flags |= CF_SELECTSCRIPT; | |
103 | logFont.lfCharSet = ANSI_CHARSET; | |
104 | #endif // Win16/32 | |
105 | } | |
106 | ||
107 | if ( m_fontData.GetEnableEffects() ) | |
2bda0e17 | 108 | flags |= CF_EFFECTS; |
11c7d5b6 | 109 | if ( m_fontData.GetShowHelp() ) |
2bda0e17 | 110 | flags |= CF_SHOWHELP; |
11c7d5b6 VZ |
111 | |
112 | if ( m_fontData.minSize != 0 || m_fontData.maxSize != 0 ) | |
2bda0e17 | 113 | { |
11c7d5b6 VZ |
114 | chooseFontStruct.nSizeMin = m_fontData.minSize; |
115 | chooseFontStruct.nSizeMax = m_fontData.maxSize; | |
116 | flags |= CF_LIMITSIZE; | |
2bda0e17 KB |
117 | } |
118 | ||
119 | chooseFontStruct.Flags = flags; | |
2bda0e17 | 120 | |
11c7d5b6 | 121 | if ( ChooseFont(&chooseFontStruct) != 0 ) |
2bda0e17 | 122 | { |
11c7d5b6 VZ |
123 | wxRGBToColour(m_fontData.fontColour, chooseFontStruct.rgbColors); |
124 | m_fontData.chosenFont = wxCreateFontFromLogFont(&logFont); | |
125 | m_fontData.EncodingInfo().facename = logFont.lfFaceName; | |
126 | m_fontData.EncodingInfo().charset = logFont.lfCharSet; | |
2bda0e17 | 127 | |
11c7d5b6 | 128 | return wxID_OK; |
2bda0e17 | 129 | } |
2bda0e17 | 130 | else |
a1d58ddc | 131 | { |
11c7d5b6 VZ |
132 | // common dialog failed - why? |
133 | #ifdef __WXDEBUG__ | |
134 | DWORD dwErr = CommDlgExtendedError(); | |
135 | if ( dwErr != 0 ) | |
136 | { | |
137 | // this msg is only for developers | |
138 | wxLogError(wxT("Common dialog failed with error code %0lx."), | |
139 | dwErr); | |
140 | } | |
141 | //else: it was just cancelled | |
142 | #endif | |
a1d58ddc | 143 | |
11c7d5b6 | 144 | return wxID_CANCEL; |
a1d58ddc | 145 | } |
2bda0e17 | 146 | } |
1e6feb95 VZ |
147 | |
148 | #endif // wxUSE_FONTDLG |