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