copied bitwise (i.e. with {\tt memcpy()}), so it would be a bad idea to make
it contain a C++ object (though C struct is fine).
+By default, wxCustomDataObject stores the data inside in a buffer. To put the
+data into the buffer you may use either
+\helpref{SetData}{wxcustomdataobjectsetdata} or
+\helpref{TakeData}{wxcustomdataobjecttakedata} depending on whether you want
+the object to make a copy of data or not.
+
+If you already store the data in another place, it may be more convenient and
+efficient to provide the data on-demand which is possible too if you override
+the virtual functions mentioned below.
+
+\wxheading{Virtual functions to override}
+
+This class may be used as is, but if you don't want store the data inside the
+object but provide it on demand instead, you should override
+\helpref{GetSize}{wxcustomdataobjectgetsize},
+\helpref{GetData}{wxcustomdataobjectgetdata} and
+\helpref{SetData}{wxcustomdataobjectsetdata} (or may be only the first two or
+only the last one if you only allow reading/writing the data)
+
\wxheading{Derived from}
\helpref{wxDataObjectSimple}{wxdataobjectsimple}
should override the destructor in your class as well (which would probably
just call the derived class' version of {\tt Free()}).
+\membersection{wxCustomDataObject::Alloc}\label{wxcustomdataobjectalloc}
-\membersection{wxCustomDataObject::SetData}\label{wxcustomdataobjectsetdata}
+\func{virtual void *}{Alloc}{\param{size\_t }{size}}
-\func{virtual void}{SetData}{\param{const char }{*data}, \param{size\_t }{size}}
+This function is called to allocate {\it size} bytes of memory from SetData().
+The default version just uses the operator new.
-Set the data. The data object will make an internal copy.
+\membersection{wxCustomDataObject::Free}\label{wxcustomdataobjectfree}
+
+\func{virtual void}{Free}{\void}
+
+This function is called when the data is freed, you may override it to anything
+you want (or may be nothing at all). The default version calls operator
+delete\[\] on the data.
\membersection{wxCustomDataObject::GetSize}\label{wxcustomdataobjectgetsize}
-\constfunc{virtual size\_t}{GetDataSize}{\void}
+\constfunc{virtual size\_t}{GetSize}{\void}
-Returns the data size.
+Returns the data size in bytes.
\membersection{wxCustomDataObject::GetData}\label{wxcustomdataobjectgetdata}
-\func{virtual char*}{GetData}{\void}
+\constfunc{virtual void *}{GetData}{\void}
Returns a pointer to the data.
+\membersection{wxCustomDataObject::SetData}\label{wxcustomdataobjectsetdata}
+
+\func{virtual void}{SetData}{
+ \param{size\_t }{size},
+ \param{const void }{*data}
+}
+
+Set the data. The data object will make an internal copy.
+
+\membersection{wxCustomDataObject::TakeData}\label{wxcustomdataobjecttakedata}
+
+\func{virtual void}{TakeData}{
+ \param{size\_t }{size},
+ \param{const void }{*data}
+}
+
+Like \helpref{SetData}{wxcustomdataobjectsetdata}, but doesn't copy the data -
+instead the object takes ownership of the pointer.
wxString facename; // may be empty meaning "any"
#if defined(__WXMSW__)
+ wxNativeEncodingInfo() { charset = 0; /* ANSI_CHARSET */ }
+
int charset;
#elif defined(_WX_X_FONTLIKE)
wxString xregistry,
#pragma interface "font.h"
#endif
-// ----------------------------------------------------------------------------
-// public functions
-// ----------------------------------------------------------------------------
-
-// convert wxFontEncoding into one of Windows XXX_CHARSET constants (fill exact
-// parameter if it's not NULL with TRUE if encoding is realyl supported under
-// Windows and FALSE if not and we just chose something close to it)
-extern int wxCharsetFromEncoding(wxFontEncoding encoding, bool *exact = NULL);
-
// ----------------------------------------------------------------------------
// wxFont
// ----------------------------------------------------------------------------
// Created: 01/02/97
// RCS-ID: $Id$
// Copyright: (c) Julian Smart
-// Licence: wxWindows licence
+// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
-#ifndef _WX_FONTDLG_H_
-#define _WX_FONTDLG_H_
+#ifndef _WX_MSW_FONTDLG_H_
+#define _WX_MSW_FONTDLG_H_
#ifdef __GNUG__
-#pragma interface "fontdlg.h"
+ #pragma interface "fontdlg.h"
#endif
#include "wx/dialog.h"
#include "wx/cmndata.h"
-/*
- * FONT DIALOG
- */
-
-class WXDLLEXPORT wxFontDialog: public wxDialog
-{
-DECLARE_DYNAMIC_CLASS(wxFontDialog)
+// ----------------------------------------------------------------------------
+// wxFontDialog
+// ----------------------------------------------------------------------------
+class WXDLLEXPORT wxFontDialog : public wxDialog
+{
public:
- wxFontDialog(void);
+ wxFontDialog();
wxFontDialog(wxWindow *parent, wxFontData *data = NULL);
bool Create(wxWindow *parent, wxFontData *data = NULL);
- int ShowModal(void);
- wxFontData& GetFontData(void) { return m_fontData; }
+ virtual int ShowModal();
+
+ wxFontData& GetFontData() { return m_fontData; }
protected:
- wxWindow *m_dialogParent;
wxFontData m_fontData;
+
+ DECLARE_DYNAMIC_CLASS(wxFontDialog)
};
#endif
- // _WX_FONTDLG_H_
+ // _WX_MSW_FONTDLG_H_
WXDLLEXPORT_DATA(extern HFONT) wxSTATUS_LINE_FONT;
// ---------------------------------------------------------------------------
-// this defines a CASTWNDPROC macro which casts a pointer to the type of a
-// window proc
+// define things missing from some compilers' headers
// ---------------------------------------------------------------------------
+#if defined(__GNUWIN32__) && !defined(wxUSE_NORLANDER_HEADERS)
+ inline void ZeroMemory(void *buf, size_t len) { memset(buf, 0, len); }
+#endif // old mingw32
+
+// this defines a CASTWNDPROC macro which casts a pointer to the type of a
+// window proc
#if defined(__GNUWIN32__) && !defined(wxUSE_NORLANDER_HEADERS)
# define CASTWNDPROC (long unsigned)
#else
extern void OutputDebugStringW95(const wxChar*, ...);
#endif // USE_DBWIN32
+// ---------------------------------------------------------------------------
+// useful macros and functions
+// ---------------------------------------------------------------------------
+
+// a wrapper macro for ZeroMemory()
+#define wxZeroMemory(obj) ::ZeroMemory(&obj, sizeof(obj))
+
+// make conversion from wxColour and COLORREF a bit less painful
+inline COLORREF wxColourToRGB(const wxColour& c)
+{
+ return RGB(c.Red(), c.Green(), c.Blue());
+}
+
+inline void wxRGBToColour(wxColour& c, COLORREF rgb)
+{
+ c.Set(GetRValue(rgb), GetGValue(rgb), GetBValue(rgb));
+}
+
// ---------------------------------------------------------------------------
// macros to make casting between WXFOO and FOO a bit easier: the GetFoo()
// returns Foo cast to the Windows type for oruselves, while GetFooOf() takes
#define GetHdc() ((HDC)GetHDC())
#define GetHdcOf(dc) ((HDC)(dc).GetHDC())
+#define GetHbitmap() ((HBITMAP)GetHBITMAP())
+#define GetHbitmapOf(bmp) ((HBITMAP)(bmp).GetHBITMAP())
+
#define GetHicon() ((HICON)GetHICON())
#define GetHiconOf(icon) ((HICON)(icon).GetHICON())
WXDLLEXPORT wxWindow* wxFindWinFromHandle(WXHWND hWnd);
WXDLLEXPORT void wxGetCharSize(WXHWND wnd, int *x, int *y,wxFont *the_font);
-WXDLLEXPORT void wxFillLogFont(LOGFONT *logFont, wxFont *font);
-WXDLLEXPORT wxFont wxCreateFontFromLogFont(LOGFONT *logFont);
+WXDLLEXPORT void wxFillLogFont(LOGFONT *logFont, const wxFont *font);
+WXDLLEXPORT wxFont wxCreateFontFromLogFont(const LOGFONT *logFont);
WXDLLEXPORT void wxSliderEvent(WXHWND control, WXWORD wParam, WXWORD pos);
WXDLLEXPORT void wxScrollBarEvent(WXHWND hbar, WXWORD wParam, WXWORD pos);
facenames[n] = fontEnumerator.GetFacenames().Item(n);
if ( silent )
- n = 1;
+ n = 0;
else
n = wxGetSingleChoiceIndex("Choose a facename", "Font demo",
nFacenames, facenames, this);
END_EVENT_TABLE()
MyCanvas::MyCanvas( wxWindow *parent )
- : wxWindow( parent, -1 )
+ : wxWindow( parent, -1 ),
+ m_colour(*wxRED), m_font(*wxNORMAL_FONT)
{
- m_font = *wxNORMAL_FONT;
- m_colour = *wxRED;
}
MyCanvas::~MyCanvas()
wxString *encodingNamesTranslated = new wxString[count];
- for ( size_t n = 0; n < count; n++ )
+ for ( size_t i = 0; i < count; i++ )
{
- encodingNamesTranslated[n] = wxGetTranslation(gs_encodingDescs[n]);
+ encodingNamesTranslated[i] = wxGetTranslation(gs_encodingDescs[i]);
}
// the parent window
wxFontData retData = dialog.GetFontData();
wxFont font = retData.GetChosenFont();
- info->xregistry = retData.EncodingInfo().xregistry;
- info->xencoding = retData.EncodingInfo().xencoding;
+ *info = retData.EncodingInfo();
// remember this in the config
if ( ChangePath(FONTMAPPER_FONT_FROM_ENCODING_PATH, &pathOld) )
return TRUE;
}
- int ff_family = 0;
- wxString ff_face;
-
- switch ( M_FONTDATA->m_family )
- {
- case wxSCRIPT:
- ff_family = FF_SCRIPT ;
- ff_face = wxT("Script") ;
- break ;
-
- case wxDECORATIVE:
- ff_family = FF_DECORATIVE;
- break;
-
- case wxROMAN:
- ff_family = FF_ROMAN;
- ff_face = wxT("Times New Roman") ;
- break;
-
- case wxTELETYPE:
- case wxMODERN:
- ff_family = FF_MODERN;
- ff_face = wxT("Courier New") ;
- break;
-
- case wxSWISS:
- ff_family = FF_SWISS;
- ff_face = wxT("Arial") ;
- break;
-
- case wxDEFAULT:
- default:
- ff_family = FF_SWISS;
- ff_face = wxT("Arial") ;
- }
-
- BYTE ff_italic;
- switch ( M_FONTDATA->m_style )
- {
- case wxITALIC:
- case wxSLANT:
- ff_italic = 1;
- break;
-
- default:
- wxFAIL_MSG(wxT("unknown font slant"));
- // fall through
-
- case wxNORMAL:
- ff_italic = 0;
- }
-
- int ff_weight = 0;
- switch ( M_FONTDATA->m_weight )
- {
- default:
- wxFAIL_MSG(wxT("unknown font weight"));
- // fall through
-
- case wxNORMAL:
- ff_weight = FW_NORMAL;
- break;
-
- case wxLIGHT:
- ff_weight = FW_LIGHT;
- break;
-
- case wxBOLD:
- ff_weight = FW_BOLD;
- break;
- }
-
- const wxChar* pzFace;
- if ( M_FONTDATA->m_faceName.IsEmpty() )
- pzFace = ff_face;
- else
- pzFace = M_FONTDATA->m_faceName ;
-
-#if 0
- /* Always calculate fonts using the screen DC (is this the best strategy?)
- * There may be confusion if a font is selected into a printer
- * DC (say), because the height will be calculated very differently.
- */
- // What sort of display is it?
- int technology = ::GetDeviceCaps(dc, TECHNOLOGY);
-
- int nHeight;
-
- if (technology != DT_RASDISPLAY && technology != DT_RASPRINTER)
- {
- // Have to get screen DC Caps, because a metafile will return 0.
- HDC dc2 = ::GetDC(NULL);
- nHeight = M_FONTDATA->m_pointSize*GetDeviceCaps(dc2, LOGPIXELSY)/72;
- ::ReleaseDC(NULL, dc2);
- }
- else
- {
- nHeight = M_FONTDATA->m_pointSize*GetDeviceCaps(dc, LOGPIXELSY)/72;
- }
-#endif // 0
-
-#if 0
- // Have to get screen DC Caps, because a metafile will return 0.
- HDC dc2 = ::GetDC(NULL);
- ppInch = ::GetDeviceCaps(dc2, LOGPIXELSY);
- ::ReleaseDC(NULL, dc2);
-#endif // 0
-
- // New behaviour: apparently ppInch varies according to Large/Small Fonts
- // setting in Windows. This messes up fonts. So, set ppInch to a constant
- // 96 dpi.
- static const int ppInch = 96;
-
-#if wxFONT_SIZE_COMPATIBILITY
- // Incorrect, but compatible with old wxWindows behaviour
- int nHeight = (M_FONTDATA->m_pointSize*ppInch/72);
-#else
- // Correct for Windows compatibility
- int nHeight = - (M_FONTDATA->m_pointSize*ppInch/72);
-#endif
-
- BYTE ff_underline = M_FONTDATA->m_underlined;
-
- DWORD charset = wxCharsetFromEncoding(GetEncoding());
- HFONT hFont = ::CreateFont
- (
- nHeight, // height
- 0, // width (choose best)
- 0, // escapement
- 0, // orientation
- ff_weight, // weight
- ff_italic, // italic?
- ff_underline, // underlined?
- 0, // strikeout?
- charset, // charset
- OUT_DEFAULT_PRECIS, // precision
- CLIP_DEFAULT_PRECIS, // clip precision
- PROOF_QUALITY, // quality of match
- DEFAULT_PITCH | // fixed or variable
- ff_family, // family id
- pzFace // face name
- );
-
- M_FONTDATA->m_hFont = (WXHFONT)hFont;
- if ( !hFont )
+ LOGFONT lf;
+ wxFillLogFont(&lf, this);
+ M_FONTDATA->m_hFont = (WXHFONT)::CreateFontIndirect(&lf);
+ if ( !M_FONTDATA->m_hFont )
{
wxLogLastError("CreateFont");
+
+ return FALSE;
}
- return hFont != 0;
+ return TRUE;
}
bool wxFont::FreeResource(bool force)
if ( !M_FONTDATA )
return 0;
else
- return (WXHANDLE)M_FONTDATA->m_hFont ;
+ return (WXHANDLE)M_FONTDATA->m_hFont;
}
bool wxFont::IsFree() const
{
wxString str;
if ( M_FONTDATA )
- str = M_FONTDATA->m_faceName ;
+ str = M_FONTDATA->m_faceName;
return str;
}
return M_FONTDATA->m_encoding;
}
-// ----------------------------------------------------------------------------
-// public functions
-// ----------------------------------------------------------------------------
-
-int wxCharsetFromEncoding(wxFontEncoding encoding, bool *exact)
-{
- if ( encoding == wxFONTENCODING_DEFAULT )
- {
- encoding = wxFont::GetDefaultEncoding();
- }
-
- if ( exact )
- *exact = TRUE;
-
- int charset;
- switch ( encoding )
- {
- case wxFONTENCODING_ISO8859_1:
- case wxFONTENCODING_ISO8859_15:
- case wxFONTENCODING_CP1250:
- charset = ANSI_CHARSET;
- break;
-
-#if !defined(__WIN16__)
- case wxFONTENCODING_ISO8859_2:
- case wxFONTENCODING_CP1252:
- charset = EASTEUROPE_CHARSET;
- break;
-
- case wxFONTENCODING_ISO8859_4:
- case wxFONTENCODING_ISO8859_10:
- charset = BALTIC_CHARSET;
- break;
-
- case wxFONTENCODING_ISO8859_5:
- case wxFONTENCODING_CP1251:
- charset = RUSSIAN_CHARSET;
- break;
-
- case wxFONTENCODING_ISO8859_6:
- charset = ARABIC_CHARSET;
- break;
-
- case wxFONTENCODING_ISO8859_7:
- charset = GREEK_CHARSET;
- break;
-
- case wxFONTENCODING_ISO8859_8:
- charset = HEBREW_CHARSET;
- break;
-
- case wxFONTENCODING_ISO8859_9:
- charset = TURKISH_CHARSET;
- break;
-
- case wxFONTENCODING_ISO8859_11:
- charset = THAI_CHARSET;
- break;
-#endif // BC++ 16-bit
-
- case wxFONTENCODING_CP437:
- charset = OEM_CHARSET;
- break;
-
- default:
- if ( exact )
- *exact = FALSE;
- // fall through
-
- case wxFONTENCODING_SYSTEM:
- charset = ANSI_CHARSET;
- }
-
- return charset;
-}
-
// Created: 01/02/97
// RCS-ID: $Id$
// Copyright: (c) Julian Smart and Markus Holzem
-// Licence: wxWindows licence
+// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
+// ============================================================================
+// declarations
+// ============================================================================
+
+// ----------------------------------------------------------------------------
+// headers
+// ----------------------------------------------------------------------------
+
#ifdef __GNUG__
-#pragma implementation "fontdlg.h"
+ #pragma implementation "fontdlg.h"
#endif
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
-#pragma hdrstop
+ #pragma hdrstop
#endif
#ifndef WX_PRECOMP
-#include <stdio.h>
-#include "wx/defs.h"
-#include "wx/utils.h"
-#include "wx/dialog.h"
+ #include "wx/defs.h"
+ #include "wx/utils.h"
+ #include "wx/dialog.h"
#endif
#include "wx/fontdlg.h"
-#include <windows.h>
-
#if !defined(__WIN32__) || defined(__SALFORDC__) || defined(__WXWINE__)
-#include <commdlg.h>
+ #include <commdlg.h>
#endif
#include "wx/msw/private.h"
#include <stdlib.h>
#include <string.h>
-#define wxDIALOG_DEFAULT_X 300
-#define wxDIALOG_DEFAULT_Y 300
+// ----------------------------------------------------------------------------
+// wxWin macros
+// ----------------------------------------------------------------------------
#if !USE_SHARED_LIBRARY
-IMPLEMENT_DYNAMIC_CLASS(wxFontDialog, wxDialog)
+ IMPLEMENT_DYNAMIC_CLASS(wxFontDialog, wxDialog)
#endif
-/*
- * wxFontDialog
- */
+// ============================================================================
+// implementation
+// ============================================================================
+// ----------------------------------------------------------------------------
+// wxFontDialog
+// ----------------------------------------------------------------------------
-wxFontDialog::wxFontDialog(void)
+wxFontDialog::wxFontDialog()
{
- m_dialogParent = NULL;
+ m_parent = NULL;
}
wxFontDialog::wxFontDialog(wxWindow *parent, wxFontData *data)
{
- Create(parent, data);
+ Create(parent, data);
}
bool wxFontDialog::Create(wxWindow *parent, wxFontData *data)
{
- m_dialogParent = parent;
+ m_parent = parent;
+
+ wxCHECK_MSG( data, FALSE, _T("no font data in wxFontDialog") );
- if (data)
m_fontData = *data;
- return TRUE;
+
+ return TRUE;
}
-int wxFontDialog::ShowModal(void)
+int wxFontDialog::ShowModal()
{
- CHOOSEFONT chooseFontStruct;
- LOGFONT logFont;
+ DWORD flags = CF_SCREENFONTS | CF_NOSIMULATIONS;
- DWORD flags = CF_TTONLY | CF_SCREENFONTS | CF_NOSIMULATIONS;
+ LOGFONT logFont;
- memset(&chooseFontStruct, 0, sizeof(CHOOSEFONT));
+ CHOOSEFONT chooseFontStruct;
+ wxZeroMemory(chooseFontStruct);
chooseFontStruct.lStructSize = sizeof(CHOOSEFONT);
- chooseFontStruct.hwndOwner = (HWND) (m_dialogParent ? (HWND) m_dialogParent->GetHWND() : NULL);
+ if ( m_parent )
+ chooseFontStruct.hwndOwner = GetHwndOf(m_parent);
chooseFontStruct.lpLogFont = &logFont;
- if (m_fontData.initialFont.Ok())
+ if ( m_fontData.initialFont.Ok() )
{
- flags |= CF_INITTOLOGFONTSTRUCT;
- wxFillLogFont(&logFont, & m_fontData.initialFont);
+ flags |= CF_INITTOLOGFONTSTRUCT;
+ wxFillLogFont(&logFont, &m_fontData.initialFont);
}
- chooseFontStruct.iPointSize = 0;
- chooseFontStruct.rgbColors = RGB((BYTE)m_fontData.fontColour.Red(), (BYTE)m_fontData.fontColour.Green(), (BYTE)m_fontData.fontColour.Blue());
+ chooseFontStruct.rgbColors = wxColourToRGB(m_fontData.fontColour);
- if (!m_fontData.GetAllowSymbols())
+ // CF_ANSIONLY flag is obsolete for Win32
+ if ( !m_fontData.GetAllowSymbols() )
+ {
+#ifdef __WIN16__
flags |= CF_ANSIONLY;
- if (m_fontData.GetEnableEffects())
+#else // Win32
+ flags |= CF_SELECTSCRIPT;
+ logFont.lfCharSet = ANSI_CHARSET;
+#endif // Win16/32
+ }
+
+ if ( m_fontData.GetEnableEffects() )
flags |= CF_EFFECTS;
- if (m_fontData.GetShowHelp())
+ if ( m_fontData.GetShowHelp() )
flags |= CF_SHOWHELP;
- if (!(m_fontData.minSize == 0 && m_fontData.maxSize == 0))
+
+ if ( m_fontData.minSize != 0 || m_fontData.maxSize != 0 )
{
- chooseFontStruct.nSizeMin = m_fontData.minSize;
- chooseFontStruct.nSizeMax = m_fontData.maxSize;
- flags |= CF_LIMITSIZE;
+ chooseFontStruct.nSizeMin = m_fontData.minSize;
+ chooseFontStruct.nSizeMax = m_fontData.maxSize;
+ flags |= CF_LIMITSIZE;
}
chooseFontStruct.Flags = flags;
- chooseFontStruct.nFontType = SCREEN_FONTTYPE;
- bool success = (ChooseFont(&(chooseFontStruct)) != 0);
- // Restore values
- if (success)
+ if ( ChooseFont(&chooseFontStruct) != 0 )
{
- m_fontData.fontColour.Set(GetRValue(chooseFontStruct.rgbColors), GetGValue(chooseFontStruct.rgbColors),
- GetBValue(chooseFontStruct.rgbColors));
- m_fontData.chosenFont = wxCreateFontFromLogFont(&logFont);
- }
-
- return success ? wxID_OK : wxID_CANCEL;
-}
+ wxRGBToColour(m_fontData.fontColour, chooseFontStruct.rgbColors);
+ m_fontData.chosenFont = wxCreateFontFromLogFont(&logFont);
+ m_fontData.EncodingInfo().facename = logFont.lfFaceName;
+ m_fontData.EncodingInfo().charset = logFont.lfCharSet;
-void wxFillLogFont(LOGFONT *logFont, wxFont *font)
-{
- BYTE ff_italic;
- int ff_weight = 0;
- int ff_family = 0;
- wxString ff_face("");
-
- switch (font->GetFamily())
- {
- case wxSCRIPT: ff_family = FF_SCRIPT ;
- ff_face = "Script" ;
- break ;
- case wxDECORATIVE: ff_family = FF_DECORATIVE;
- break;
- case wxROMAN: ff_family = FF_ROMAN;
- ff_face = "Times New Roman" ;
- break;
- case wxTELETYPE:
- case wxMODERN: ff_family = FF_MODERN;
- ff_face = "Courier New" ;
- break;
- case wxSWISS: ff_family = FF_SWISS;
- ff_face = "Arial";
- break;
- case wxDEFAULT:
- default: ff_family = FF_SWISS;
- ff_face = "MS Sans Serif" ;
+ return wxID_OK;
}
-
- if (font->GetStyle() == wxITALIC || font->GetStyle() == wxSLANT)
- ff_italic = 1;
else
- ff_italic = 0;
-
- if (font->GetWeight() == wxNORMAL)
- ff_weight = FW_NORMAL;
- else if (font->GetWeight() == wxLIGHT)
- ff_weight = FW_LIGHT;
- else if (font->GetWeight() == wxBOLD)
- ff_weight = FW_BOLD;
-
- // Have to get screen DC Caps, because a metafile will return 0.
- HDC dc2 = ::GetDC(NULL);
- int ppInch = ::GetDeviceCaps(dc2, LOGPIXELSY);
- ::ReleaseDC(NULL, dc2);
-
- // New behaviour: apparently ppInch varies according to
- // Large/Small Fonts setting in Windows. This messes
- // up fonts. So, set ppInch to a constant 96 dpi.
- ppInch = 96;
-
-#if wxFONT_SIZE_COMPATIBILITY
- // Incorrect, but compatible with old wxWindows behaviour
- int nHeight = (font->GetPointSize()*ppInch/72);
-#else
- // Correct for Windows compatibility
- int nHeight = - (font->GetPointSize()*ppInch/72);
-#endif
-
- bool ff_underline = font->GetUnderlined();
-
- ff_face = font->GetFaceName();
-
- logFont->lfHeight = nHeight;
- logFont->lfWidth = 0;
- logFont->lfEscapement = 0;
- logFont->lfOrientation = 0;
- logFont->lfWeight = ff_weight;
- logFont->lfItalic = ff_italic;
- logFont->lfUnderline = (BYTE)ff_underline;
- logFont->lfStrikeOut = 0;
- logFont->lfCharSet = wxCharsetFromEncoding(font->GetEncoding());
- logFont->lfOutPrecision = OUT_DEFAULT_PRECIS;
- logFont->lfClipPrecision = CLIP_DEFAULT_PRECIS;
- logFont->lfQuality = PROOF_QUALITY;
- logFont->lfPitchAndFamily = DEFAULT_PITCH | ff_family;
- wxStrcpy(logFont->lfFaceName, ff_face);
-}
-
-wxFont wxCreateFontFromLogFont(LOGFONT *logFont)
-{
- int fontFamily = wxSWISS;
- int fontStyle = wxNORMAL;
- int fontWeight = wxNORMAL;
- int fontPoints = 10;
- bool fontUnderline = FALSE;
- wxChar *fontFace = NULL;
-
- int lfFamily = logFont->lfPitchAndFamily;
- if (lfFamily & FIXED_PITCH)
- lfFamily -= FIXED_PITCH;
- if (lfFamily & VARIABLE_PITCH)
- lfFamily -= VARIABLE_PITCH;
-
- switch (lfFamily)
{
- case FF_ROMAN:
- fontFamily = wxROMAN;
- break;
- case FF_SWISS:
- fontFamily = wxSWISS;
- break;
- case FF_SCRIPT:
- fontFamily = wxSCRIPT;
- break;
- case FF_MODERN:
- fontFamily = wxMODERN;
- break;
- case FF_DECORATIVE:
- fontFamily = wxDECORATIVE;
- break;
- default:
- fontFamily = wxSWISS;
- break;
- }
- switch (logFont->lfWeight)
- {
- case FW_LIGHT:
- fontWeight = wxLIGHT;
- break;
- case FW_NORMAL:
- fontWeight = wxNORMAL;
- break;
- case FW_BOLD:
- fontWeight = wxBOLD;
- break;
- default:
- fontWeight = wxNORMAL;
- break;
- }
- if (logFont->lfItalic)
- fontStyle = wxITALIC;
- else
- fontStyle = wxNORMAL;
-
- if (logFont->lfUnderline)
- fontUnderline = TRUE;
-
- if (logFont->lfFaceName)
- fontFace = logFont->lfFaceName;
-
- wxFontEncoding fontEncoding;
- switch ( logFont->lfCharSet )
- {
- default:
- wxFAIL_MSG(wxT("unsupported charset"));
- // fall through
-
- case ANSI_CHARSET:
- fontEncoding = wxFONTENCODING_ISO8859_1;
- break;
-
- case EASTEUROPE_CHARSET:
- fontEncoding = wxFONTENCODING_ISO8859_2;
- break;
-
- case BALTIC_CHARSET:
- fontEncoding = wxFONTENCODING_ISO8859_4;
- break;
-
- case RUSSIAN_CHARSET:
- fontEncoding = wxFONTENCODING_CP1251;
- break;
-
- case ARABIC_CHARSET:
- fontEncoding = wxFONTENCODING_ISO8859_6;
- break;
-
- case GREEK_CHARSET:
- fontEncoding = wxFONTENCODING_ISO8859_7;
- break;
-
- case HEBREW_CHARSET:
- fontEncoding = wxFONTENCODING_ISO8859_8;
- break;
-
- case TURKISH_CHARSET:
- fontEncoding = wxFONTENCODING_ISO8859_9;
- break;
-
- case THAI_CHARSET:
- fontEncoding = wxFONTENCODING_ISO8859_11;
- break;
-
+ // common dialog failed - why?
+#ifdef __WXDEBUG__
+ DWORD dwErr = CommDlgExtendedError();
+ if ( dwErr != 0 )
+ {
+ // this msg is only for developers
+ wxLogError(wxT("Common dialog failed with error code %0lx."),
+ dwErr);
+ }
+ //else: it was just cancelled
+#endif
- case OEM_CHARSET:
- fontEncoding = wxFONTENCODING_CP437;
- break;
+ return wxID_CANCEL;
}
-
- HDC dc2 = ::GetDC(NULL);
-
- if ( logFont->lfHeight < 0 )
- logFont->lfHeight = - logFont->lfHeight;
- fontPoints = abs(72*logFont->lfHeight/GetDeviceCaps(dc2, LOGPIXELSY));
- ::ReleaseDC(NULL, dc2);
-
- return wxFont(fontPoints, fontFamily, fontStyle,
- fontWeight, fontUnderline, fontFace,
- fontEncoding);
}
-
-
#endif
#include "wx/fontenum.h"
+#include "wx/fontmap.h"
#include "wx/msw/private.h"
// if != -1, enum only fonts which have this encoding
int m_charset;
+ // if not empty, enum only the fonts with this facename
+ wxString m_facename;
+
// if TRUE, enum only fixed fonts
bool m_fixedOnly;
};
bool wxFontEnumeratorHelper::SetEncoding(wxFontEncoding encoding)
{
- bool exact;
- m_charset = wxCharsetFromEncoding(encoding, &exact);
-#ifdef __WIN32__
- if ( !exact )
+ wxNativeEncodingInfo info;
+ if ( !wxGetNativeFontEncoding(encoding, &info) )
{
- m_charset = DEFAULT_CHARSET;
+ if ( !wxTheFontMapper->GetAltForEncoding(encoding, &info) )
+ {
+ // no such encodings at all
+ return FALSE;
+ }
+
+ m_charset = info.charset;
+ m_facename = info.facename;
}
-#endif // Win32
- return exact;
+ return TRUE;
}
void wxFontEnumeratorHelper::DoEnumerate()
#ifdef __WIN32__
LOGFONT lf;
lf.lfCharSet = m_charset;
- lf.lfFaceName[0] = _T('\0');
+ wxStrncpy(lf.lfFaceName, m_facename, WXSIZEOF(lf.lfFaceName));
lf.lfPitchAndFamily = 0;
::EnumFontFamiliesEx(hDC, &lf, (FONTENUMPROC)wxFontEnumeratorProc,
(LPARAM)this, 0 /* reserved */) ;
--- /dev/null
+///////////////////////////////////////////////////////////////////////////////
+// Name: msw/fontutil.cpp
+// Purpose: font-related helper functions for wxMSW
+// Author: Vadim Zeitlin
+// Modified by:
+// Created: 05.11.99
+// RCS-ID: $Id$
+// Copyright: (c) 1999 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
+// Licence: wxWindows license
+///////////////////////////////////////////////////////////////////////////////
+
+// ============================================================================
+// declarations
+// ============================================================================
+
+// ----------------------------------------------------------------------------
+// headers
+// ----------------------------------------------------------------------------
+
+#ifdef __GNUG__
+ #pragma implementation "fontutil.h"
+#endif
+
+// For compilers that support precompilation, includes "wx.h".
+#include "wx/wxprec.h"
+
+#ifdef __BORLANDC__
+ #pragma hdrstop
+#endif
+
+#ifndef WX_PRECOMP
+ #include "wx/string.h"
+ #include "wx/log.h"
+ #include "wx/intl.h"
+#endif //WX_PRECOMP
+
+#include "wx/msw/private.h"
+
+#include "wx/fontutil.h"
+#include "wx/fontmap.h"
+
+#include "wx/tokenzr.h"
+
+// ============================================================================
+// implementation
+// ============================================================================
+
+// ----------------------------------------------------------------------------
+// wxNativeEncodingInfo
+// ----------------------------------------------------------------------------
+
+// convert to/from the string representation: format is
+// facename[;charset]
+
+bool wxNativeEncodingInfo::FromString(const wxString& s)
+{
+ wxStringTokenizer tokenizer(s, _T(";"));
+
+ facename = tokenizer.GetNextToken();
+ if ( !facename )
+ return FALSE;
+
+ wxString tmp = tokenizer.GetNextToken();
+ if ( !tmp )
+ {
+ // default charset (don't use DEFAULT_CHARSET though because of subtle
+ // Windows 9x/NT differences in handling it)
+ charset = ANSI_CHARSET;
+ }
+ else
+ {
+ if ( wxSscanf(tmp, _T("%u"), &charset) != 1 )
+ {
+ // should be a number!
+ return FALSE;
+ }
+ }
+
+ return TRUE;
+}
+
+wxString wxNativeEncodingInfo::ToString() const
+{
+ wxString s(facename);
+ if ( charset != ANSI_CHARSET )
+ {
+ s << _T(';') << charset;
+ }
+
+ return s;
+}
+
+// ----------------------------------------------------------------------------
+// helper functions
+// ----------------------------------------------------------------------------
+
+bool wxGetNativeFontEncoding(wxFontEncoding encoding,
+ wxNativeEncodingInfo *info)
+{
+ wxCHECK_MSG( info, FALSE, _T("bad pointer in wxGetNativeFontEncoding") );
+
+ if ( encoding == wxFONTENCODING_DEFAULT )
+ {
+ encoding = wxFont::GetDefaultEncoding();
+ }
+
+ switch ( encoding )
+ {
+ // although this function is supposed to return an exact match, do do
+ // some mappings here for the most common case of "standard" encoding
+ case wxFONTENCODING_SYSTEM:
+ case wxFONTENCODING_ISO8859_1:
+ case wxFONTENCODING_ISO8859_15:
+ case wxFONTENCODING_CP1252:
+ info->charset = ANSI_CHARSET;
+ break;
+
+#if !defined(__WIN16__)
+ case wxFONTENCODING_CP1250:
+ info->charset = EASTEUROPE_CHARSET;
+ break;
+
+ case wxFONTENCODING_CP1251:
+ info->charset = RUSSIAN_CHARSET;
+ break;
+
+ case wxFONTENCODING_CP1253:
+ info->charset = GREEK_CHARSET;
+ break;
+
+ case wxFONTENCODING_CP1254:
+ info->charset = TURKISH_CHARSET;
+ break;
+
+ case wxFONTENCODING_CP1255:
+ info->charset = HEBREW_CHARSET;
+ break;
+
+ case wxFONTENCODING_CP1256:
+ info->charset = ARABIC_CHARSET;
+ break;
+
+ case wxFONTENCODING_CP1257:
+ info->charset = BALTIC_CHARSET;
+ break;
+#endif // !Win16
+
+ case wxFONTENCODING_CP437:
+ info->charset = OEM_CHARSET;
+ break;
+
+ default:
+ // no way to translate this encoding into a Windows charset
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+bool wxTestFontEncoding(const wxNativeEncodingInfo& info)
+{
+ // try to create such font
+ LOGFONT lf;
+ wxZeroMemory(lf); // all default values
+
+ lf.lfCharSet = info.charset;
+ strncpy(lf.lfFaceName, info.facename, sizeof(lf.lfFaceName));
+
+ HFONT hfont = ::CreateFontIndirect(&lf);
+ if ( !hfont )
+ {
+ // no such font
+ return FALSE;
+ }
+
+ ::DeleteObject((HGDIOBJ)hfont);
+
+ return TRUE;
+}
+
+// ----------------------------------------------------------------------------
+// wxFont <-> LOGFONT conversion
+// ----------------------------------------------------------------------------
+
+void wxFillLogFont(LOGFONT *logFont, const wxFont *font)
+{
+ int ff_family;
+ wxString ff_face;
+
+ switch ( font->GetFamily() )
+ {
+ case wxSCRIPT:
+ ff_family = FF_SCRIPT;
+ ff_face = _T("Script");
+ break;
+
+ case wxDECORATIVE:
+ ff_family = FF_DECORATIVE;
+ break;
+
+ case wxROMAN:
+ ff_family = FF_ROMAN;
+ ff_face = _T("Times New Roman");
+ break;
+
+ case wxTELETYPE:
+ case wxMODERN:
+ ff_family = FF_MODERN;
+ ff_face = _T("Courier New");
+ break;
+
+ case wxSWISS:
+ ff_family = FF_SWISS;
+ ff_face = _T("Arial");
+ break;
+
+ case wxDEFAULT:
+ default:
+ ff_family = FF_SWISS;
+ ff_face = _T("MS Sans Serif");
+ }
+
+ BYTE ff_italic;
+ switch ( font->GetStyle() )
+ {
+ case wxITALIC:
+ case wxSLANT:
+ ff_italic = 1;
+ break;
+
+ default:
+ wxFAIL_MSG(wxT("unknown font slant"));
+ // fall through
+
+ case wxNORMAL:
+ ff_italic = 0;
+ }
+
+ int ff_weight;
+ switch ( font->GetWeight() )
+ {
+ default:
+ wxFAIL_MSG(_T("unknown font weight"));
+ // fall through
+
+ case wxNORMAL:
+ ff_weight = FW_NORMAL;
+ break;
+
+ case wxLIGHT:
+ ff_weight = FW_LIGHT;
+ break;
+
+ case wxBOLD:
+ ff_weight = FW_BOLD;
+ break;
+ }
+
+#if 0
+ HDC dc = ::GetDC(NULL);
+ int ppInch = ::GetDeviceCaps(dc, LOGPIXELSY);
+ ::ReleaseDC(NULL, dc);
+#else
+ // New behaviour: apparently ppInch varies according to Large/Small Fonts
+ // setting in Windows. This messes up fonts. So, set ppInch to a constant
+ // 96 dpi.
+ static const int ppInch = 96;
+#endif // 0/1
+
+#if wxFONT_SIZE_COMPATIBILITY
+ // Incorrect, but compatible with old wxWindows behaviour
+ int nHeight = (font->GetPointSize()*ppInch/72);
+#else
+ // Correct for Windows compatibility
+ int nHeight = - (font->GetPointSize()*ppInch/72);
+#endif
+
+ wxString facename = font->GetFaceName();
+ if ( !!facename )
+ {
+ ff_face = facename;
+ }
+ //else: ff_face is a reasonable default facename for this font family
+
+ // deal with encoding now
+ wxNativeEncodingInfo info;
+ wxFontEncoding encoding = font->GetEncoding();
+ if ( !wxGetNativeFontEncoding(encoding, &info) )
+ {
+ if ( !wxTheFontMapper->GetAltForEncoding(encoding, &info) )
+ {
+ // unsupported encoding, replace with the default
+ info.charset = ANSI_CHARSET;
+ }
+ }
+
+ if ( !info.facename.IsEmpty() )
+ {
+ // the facename determined by the encoding overrides everything else
+ ff_face = info.facename;
+ }
+
+ // transfer all the data to LOGFONT
+ logFont->lfHeight = nHeight;
+ logFont->lfWidth = 0;
+ logFont->lfEscapement = 0;
+ logFont->lfOrientation = 0;
+ logFont->lfWeight = ff_weight;
+ logFont->lfItalic = ff_italic;
+ logFont->lfUnderline = (BYTE)font->GetUnderlined();
+ logFont->lfStrikeOut = 0;
+ logFont->lfCharSet = info.charset;
+ logFont->lfOutPrecision = OUT_DEFAULT_PRECIS;
+ logFont->lfClipPrecision = CLIP_DEFAULT_PRECIS;
+ logFont->lfQuality = PROOF_QUALITY;
+ logFont->lfPitchAndFamily = DEFAULT_PITCH | ff_family;
+ wxStrncpy(logFont->lfFaceName, ff_face, WXSIZEOF(logFont->lfFaceName));
+}
+
+wxFont wxCreateFontFromLogFont(const LOGFONT *logFont)
+{
+ // extract family from pitch-and-family
+ int lfFamily = logFont->lfPitchAndFamily;
+ if ( lfFamily & FIXED_PITCH )
+ lfFamily -= FIXED_PITCH;
+ if ( lfFamily & VARIABLE_PITCH )
+ lfFamily -= VARIABLE_PITCH;
+
+ int fontFamily;
+ switch ( lfFamily )
+ {
+ case FF_ROMAN:
+ fontFamily = wxROMAN;
+ break;
+
+ case FF_SWISS:
+ fontFamily = wxSWISS;
+ break;
+
+ case FF_SCRIPT:
+ fontFamily = wxSCRIPT;
+ break;
+
+ case FF_MODERN:
+ fontFamily = wxMODERN;
+ break;
+
+ case FF_DECORATIVE:
+ fontFamily = wxDECORATIVE;
+ break;
+
+ default:
+ fontFamily = wxSWISS;
+ }
+
+ // weight and style
+ int fontWeight = wxNORMAL;
+ switch ( logFont->lfWeight )
+ {
+ case FW_LIGHT:
+ fontWeight = wxLIGHT;
+ break;
+
+ default:
+ case FW_NORMAL:
+ fontWeight = wxNORMAL;
+ break;
+
+ case FW_BOLD:
+ fontWeight = wxBOLD;
+ break;
+ }
+
+ int fontStyle = logFont->lfItalic ? wxITALIC : wxNORMAL;
+
+ bool fontUnderline = logFont->lfUnderline != 0;
+
+ wxString fontFace = logFont->lfFaceName;
+
+ // font size
+ HDC dc = ::GetDC(NULL);
+
+ // remember that 1pt = 1/72inch
+ int height = abs(logFont->lfHeight);
+ int fontPoints = (72*height)/GetDeviceCaps(dc, LOGPIXELSY);
+
+ ::ReleaseDC(NULL, dc);
+
+ wxFontEncoding fontEncoding;
+ switch ( logFont->lfCharSet )
+ {
+ default:
+ wxFAIL_MSG(wxT("unsupported charset"));
+ // fall through
+
+ case ANSI_CHARSET:
+ fontEncoding = wxFONTENCODING_CP1252;
+ break;
+
+ case EASTEUROPE_CHARSET:
+ fontEncoding = wxFONTENCODING_CP1250;
+ break;
+
+ case BALTIC_CHARSET:
+ fontEncoding = wxFONTENCODING_CP1257;
+ break;
+
+ case RUSSIAN_CHARSET:
+ fontEncoding = wxFONTENCODING_CP1251;
+ break;
+
+ case ARABIC_CHARSET:
+ fontEncoding = wxFONTENCODING_CP1256;
+ break;
+
+ case GREEK_CHARSET:
+ fontEncoding = wxFONTENCODING_CP1253;
+ break;
+
+ case HEBREW_CHARSET:
+ fontEncoding = wxFONTENCODING_CP1255;
+ break;
+
+ case TURKISH_CHARSET:
+ fontEncoding = wxFONTENCODING_CP1254;
+ break;
+
+ case OEM_CHARSET:
+ fontEncoding = wxFONTENCODING_CP437;
+ break;
+ }
+
+ return wxFont(fontPoints, fontFamily, fontStyle,
+ fontWeight, fontUnderline, fontFace,
+ fontEncoding);
+}
+
+
bool wxListCtrl::GetItem(wxListItem& info) const
{
LV_ITEM lvItem;
-#ifdef __GNUWIN32__
- memset(&lvItem, 0, sizeof(lvItem));
-#else
- ZeroMemory(&lvItem, sizeof(lvItem)); // must set all fields to 0
-#endif
+ wxZeroMemory(lvItem);
lvItem.iItem = info.m_itemId;
lvItem.iSubItem = info.m_col;
// else translate it into wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK event
LV_HITTESTINFO lvhti;
-#ifdef __GNUWIN32__
- memset(&lvhti,0,sizeof(LV_HITTESTINFO));
-#else
- ZeroMemory(&lvhti, sizeof(LV_HITTESTINFO)); // must set all fields to 0
-#endif
+ wxZeroMemory(lvhti);
+
::GetCursorPos(&(lvhti.pt));
::ScreenToClient(GetHwnd(),&(lvhti.pt));
if ( ListView_HitTest(GetHwnd(),&lvhti) != -1 )
// private classes
// ----------------------------------------------------------------------------
-
// a simple wrapper around TOOLINFO Win32 structure
#ifdef __VISUALC__
- #pragma warning( disable : 4097 )
+ #pragma warning( disable : 4097 ) // we inherit from a typedef - so what?
#endif
class wxToolInfo : public TOOLINFO
{
wxToolInfo(wxWindow *win)
{
// initialize all members
-#if __GNUWIN32__ && !defined(wxUSE_NORLANDER_HEADERS)
- memset(this, 0, sizeof(TOOLINFO));
-#else
::ZeroMemory(this, sizeof(TOOLINFO));
-#endif
cbSize = sizeof(TOOLINFO);
uFlags = TTF_IDISHWND;
#else // 1
// create the process
STARTUPINFO si;
-#ifdef __GNUWIN32__
- memset(&si, 0, sizeof(si));
-#else
- ::ZeroMemory(&si, sizeof(si));
-#endif
+ wxZeroMemory(si);
si.cb = sizeof(si);