]> git.saurik.com Git - wxWidgets.git/blame - src/msw/fontdlg.cpp
return begining of the selection for GetInsertionPoint to match what
[wxWidgets.git] / src / msw / fontdlg.cpp
CommitLineData
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"
660296aa 40#include "wx/msw/wrapcdlg.h"
2bda0e17 41
2bda0e17 42#include "wx/cmndata.h"
01dba85a 43#include "wx/log.h"
b713f891 44#include "wx/math.h"
2bda0e17 45
2bda0e17
KB
46#include <stdlib.h>
47#include <string.h>
48
11c7d5b6
VZ
49// ----------------------------------------------------------------------------
50// wxWin macros
51// ----------------------------------------------------------------------------
2bda0e17 52
6fe19057 53IMPLEMENT_DYNAMIC_CLASS(wxFontDialog, wxDialog)
2bda0e17 54
11c7d5b6
VZ
55// ============================================================================
56// implementation
57// ============================================================================
2bda0e17 58
11c7d5b6
VZ
59// ----------------------------------------------------------------------------
60// wxFontDialog
61// ----------------------------------------------------------------------------
2bda0e17 62
11c7d5b6 63int wxFontDialog::ShowModal()
2bda0e17 64{
5e80ff3d
JS
65 // It should be OK to always use GDI simulations
66 DWORD flags = CF_SCREENFONTS /* | CF_NOSIMULATIONS */ ;
2bda0e17 67
11c7d5b6 68 LOGFONT logFont;
2bda0e17 69
11c7d5b6
VZ
70 CHOOSEFONT chooseFontStruct;
71 wxZeroMemory(chooseFontStruct);
2bda0e17
KB
72
73 chooseFontStruct.lStructSize = sizeof(CHOOSEFONT);
11c7d5b6
VZ
74 if ( m_parent )
75 chooseFontStruct.hwndOwner = GetHwndOf(m_parent);
2bda0e17
KB
76 chooseFontStruct.lpLogFont = &logFont;
77
ae500232 78 if ( m_fontData.m_initialFont.Ok() )
2bda0e17 79 {
11c7d5b6 80 flags |= CF_INITTOLOGFONTSTRUCT;
ae500232 81 wxFillLogFont(&logFont, &m_fontData.m_initialFont);
2bda0e17
KB
82 }
83
ae500232 84 if ( m_fontData.m_fontColour.Ok() )
951cf90d 85 {
ae500232 86 chooseFontStruct.rgbColors = wxColourToRGB(m_fontData.m_fontColour);
951cf90d 87 }
2bda0e17 88
11c7d5b6
VZ
89 // CF_ANSIONLY flag is obsolete for Win32
90 if ( !m_fontData.GetAllowSymbols() )
91 {
11c7d5b6
VZ
92 flags |= CF_SELECTSCRIPT;
93 logFont.lfCharSet = ANSI_CHARSET;
11c7d5b6
VZ
94 }
95
96 if ( m_fontData.GetEnableEffects() )
2bda0e17 97 flags |= CF_EFFECTS;
11c7d5b6 98 if ( m_fontData.GetShowHelp() )
2bda0e17 99 flags |= CF_SHOWHELP;
11c7d5b6 100
ae500232 101 if ( m_fontData.m_minSize != 0 || m_fontData.m_maxSize != 0 )
2bda0e17 102 {
ae500232
JS
103 chooseFontStruct.nSizeMin = m_fontData.m_minSize;
104 chooseFontStruct.nSizeMax = m_fontData.m_maxSize;
11c7d5b6 105 flags |= CF_LIMITSIZE;
2bda0e17
KB
106 }
107
108 chooseFontStruct.Flags = flags;
2bda0e17 109
11c7d5b6 110 if ( ChooseFont(&chooseFontStruct) != 0 )
2bda0e17 111 {
ae500232
JS
112 wxRGBToColour(m_fontData.m_fontColour, chooseFontStruct.rgbColors);
113 m_fontData.m_chosenFont = wxCreateFontFromLogFont(&logFont);
11c7d5b6
VZ
114 m_fontData.EncodingInfo().facename = logFont.lfFaceName;
115 m_fontData.EncodingInfo().charset = logFont.lfCharSet;
2bda0e17 116
11c7d5b6 117 return wxID_OK;
2bda0e17 118 }
2bda0e17 119 else
a1d58ddc 120 {
11c7d5b6
VZ
121 // common dialog failed - why?
122#ifdef __WXDEBUG__
123 DWORD dwErr = CommDlgExtendedError();
124 if ( dwErr != 0 )
125 {
126 // this msg is only for developers
127 wxLogError(wxT("Common dialog failed with error code %0lx."),
128 dwErr);
129 }
130 //else: it was just cancelled
131#endif
a1d58ddc 132
11c7d5b6 133 return wxID_CANCEL;
a1d58ddc 134 }
2bda0e17 135}
1e6feb95
VZ
136
137#endif // wxUSE_FONTDLG