fixed wxFontDialog API: accept const ref instead of (well, in addition to) a possibly NULL pointer
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@15534 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -167,10 +167,29 @@ This class represents the font chooser dialog.
|
||||
|
||||
\membersection{wxFontDialog::wxFontDialog}
|
||||
|
||||
\func{}{wxFontDialog}{\param{wxWindow* }{parent}, \param{wxFontData* }{data = NULL}}
|
||||
\func{}{wxFontDialog}{\void}
|
||||
|
||||
Constructor. Pass a parent window, and optionally a pointer to a block of font
|
||||
data, which will be copied to the font dialog's font data.
|
||||
\func{}{wxFontDialog}{\param{wxWindow* }{parent}}
|
||||
|
||||
\func{}{wxFontDialog}{\param{wxWindow* }{parent}, \param{const wxFontData\& }{data}}
|
||||
|
||||
Constructor. Pass a parent window, and optionally the
|
||||
\helpref{font data}{wxfontdata} object to be used to initialize the dialog
|
||||
controls. If the default constructor is used,
|
||||
\helpref{Create()}{wxfontdialogcreate} must be called before the dialog can be
|
||||
shown.
|
||||
|
||||
\membersection{wxFontDialog::Create}\label{wxfontdialogcreate}
|
||||
|
||||
\func{bool}{Create}{\void}
|
||||
|
||||
\func{bool}{Create}{\param{wxWindow* }{parent}}
|
||||
|
||||
\func{bool}{Create}{\param{wxWindow* }{parent}, \param{const wxFontData\& }{data}}
|
||||
|
||||
Creates the dialog if it the wxFontDialog object had been initialized using the
|
||||
default constructor. Returns {\tt TRUE} on success and {\tt FALSE} if an error
|
||||
occured.
|
||||
|
||||
\membersection{wxFontDialog::\destruct{wxFontDialog}}
|
||||
|
||||
@@ -180,6 +199,8 @@ Destructor.
|
||||
|
||||
\membersection{wxFontDialog::GetFontData}
|
||||
|
||||
\constfunc{const wxFontData\&}{GetFontData}{\void}
|
||||
|
||||
\func{wxFontData\&}{GetFontData}{\void}
|
||||
|
||||
Returns the \helpref{font data}{wxfontdata} associated with the font dialog.
|
||||
@@ -188,10 +209,10 @@ Returns the \helpref{font data}{wxfontdata} associated with the font dialog.
|
||||
|
||||
\func{int}{ShowModal}{\void}
|
||||
|
||||
Shows the dialog, returning wxID\_OK if the user pressed Ok, and wxID\_CANCEL
|
||||
otherwise.
|
||||
Shows the dialog, returning {\tt wxID\_OK} if the user pressed Ok, and
|
||||
{\tt wxID\_CANCEL} otherwise.
|
||||
|
||||
If the user cancels the dialog (ShowModal returns wxID\_CANCEL), no font will be
|
||||
created. If the user presses OK (ShowModal returns wxID\_OK), a new wxFont will
|
||||
be created and stored in the font dialog's wxFontData structure.
|
||||
If the user cancels the dialog (ShowModal returns {\tt wxID\_CANCEL}), no font
|
||||
will be created. If the user presses OK, a new wxFont will be created and
|
||||
stored in the font dialog's wxFontData structure.
|
||||
|
||||
|
@@ -1,20 +1,80 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: wx/fontdlg.h
|
||||
// Purpose: common interface for different wxFontDialog classes
|
||||
// Author: Vadim Zeitlin
|
||||
// Modified by:
|
||||
// Created: 12.05.02
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) 1997-2002 wxWindows team
|
||||
// Licence: wxWindows license
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _WX_FONTDLG_H_BASE_
|
||||
#define _WX_FONTDLG_H_BASE_
|
||||
|
||||
#include "wx/defs.h" // for wxUSE_FONTDLG
|
||||
|
||||
#if wxUSE_FONTDLG
|
||||
|
||||
#include "wx/dialog.h" // the base class
|
||||
#include "wx/cmndata.h" // wxFontData
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxFontDialog interface
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class WXDLLEXPORT wxFontDialogBase : public wxDialog
|
||||
{
|
||||
public:
|
||||
// create the font dialog
|
||||
wxFontDialogBase() { }
|
||||
wxFontDialogBase(wxWindow *parent) { }
|
||||
wxFontDialogBase(wxWindow *parent, const wxFontData& data) { }
|
||||
|
||||
bool Create(wxWindow *parent)
|
||||
{ return DoCreate(parent); }
|
||||
bool Create(wxWindow *parent, const wxFontData& data)
|
||||
{ m_fontData = data; return Create(parent); }
|
||||
|
||||
virtual ~wxFontDialogBase();
|
||||
|
||||
// retrieve the font data
|
||||
const wxFontData& GetFontData() const { return m_fontData; }
|
||||
wxFontData& GetFontData() { return m_fontData; }
|
||||
|
||||
// deprecated interface, for compatibility only, don't use
|
||||
wxFontDialogBase(wxWindow *parent, const wxFontData *data)
|
||||
{ Init(); Create(parent, data); }
|
||||
|
||||
bool Create(wxWindow *parent, const wxFontData *data)
|
||||
{ if ( data ) m_fontData = *data; return Create(parent); }
|
||||
|
||||
protected:
|
||||
virtual bool DoCreate(wxWindow *parent) { m_parent = parent; return TRUE; }
|
||||
|
||||
wxFontData m_fontData;
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// platform-specific wxFontDialog implementation
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#if defined(__WXUNIVERSAL__) || defined(__WXMOTIF__) || defined(__WXMAC__)
|
||||
# include "wx/generic/fontdlgg.h"
|
||||
# define wxFontDialog wxGenericFontDialog
|
||||
# define sm_classwxFontDialog sm_classwxGenericFontDialog
|
||||
#include "wx/generic/fontdlgg.h"
|
||||
#define wxFontDialog wxGenericFontDialog
|
||||
#define sm_classwxFontDialog sm_classwxGenericFontDialog
|
||||
#elif defined(__WXMSW__)
|
||||
# include "wx/msw/fontdlg.h"
|
||||
#include "wx/msw/fontdlg.h"
|
||||
#elif defined(__WXGTK__)
|
||||
# include "wx/gtk/fontdlg.h"
|
||||
#include "wx/gtk/fontdlg.h"
|
||||
#elif defined(__WXPM__)
|
||||
# include "wx/os2/fontdlg.h"
|
||||
#include "wx/os2/fontdlg.h"
|
||||
#endif
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// global public functions
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// get the font from user and return it, returns wxNullFont if the dialog was
|
||||
// cancelled
|
||||
wxFont WXDLLEXPORT
|
||||
|
@@ -15,33 +15,31 @@
|
||||
#pragma interface "fontdlg.h"
|
||||
#endif
|
||||
|
||||
#include "wx/setup.h"
|
||||
#include "wx/gdicmn.h"
|
||||
#include "wx/font.h"
|
||||
#include "wx/dialog.h"
|
||||
#include "wx/cmndata.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// classes
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class wxFontDialog;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// wxFontDialog
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class wxFontDialog: public wxDialog
|
||||
class wxFontDialog : public wxFontDialogBase
|
||||
{
|
||||
public:
|
||||
wxFontDialog() {}
|
||||
wxFontDialog( wxWindow *parent, wxFontData *data = (wxFontData *) NULL );
|
||||
~wxFontDialog();
|
||||
wxFontDialog() : wxFontDialogBase() { /* must be Create()d later */ }
|
||||
wxFontDialog(wxWindow *parent)
|
||||
: wxFontDialogBase(parent) { Create(parent); }
|
||||
wxFontDialog(wxWindow *parent, const wxFontData& data)
|
||||
: wxFontDialogBase(parent, data) { Create(parent, data); }
|
||||
|
||||
wxFontData& GetFontData() { return m_fontData; }
|
||||
virtual ~wxFontDialog();
|
||||
|
||||
//protected:
|
||||
wxFontData m_fontData;
|
||||
// implementation only
|
||||
void SetChosenFont(const char *name);
|
||||
|
||||
// deprecated interface, don't use
|
||||
wxFontDialog(wxWindow *parent, const wxFontData *data)
|
||||
: wxFontDialogBase(parent, data) { Create(parent, data); }
|
||||
|
||||
protected:
|
||||
// create the GTK dialog
|
||||
virtual bool DoCreate(wxWindow *parent);
|
||||
|
||||
private:
|
||||
DECLARE_DYNAMIC_CLASS(wxFontDialog)
|
||||
|
@@ -15,33 +15,31 @@
|
||||
#pragma interface "fontdlg.h"
|
||||
#endif
|
||||
|
||||
#include "wx/setup.h"
|
||||
#include "wx/gdicmn.h"
|
||||
#include "wx/font.h"
|
||||
#include "wx/dialog.h"
|
||||
#include "wx/cmndata.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// classes
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class wxFontDialog;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// wxFontDialog
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class wxFontDialog: public wxDialog
|
||||
class wxFontDialog : public wxFontDialogBase
|
||||
{
|
||||
public:
|
||||
wxFontDialog() {}
|
||||
wxFontDialog( wxWindow *parent, wxFontData *data = (wxFontData *) NULL );
|
||||
~wxFontDialog();
|
||||
wxFontDialog() : wxFontDialogBase() { /* must be Create()d later */ }
|
||||
wxFontDialog(wxWindow *parent)
|
||||
: wxFontDialogBase(parent) { Create(parent); }
|
||||
wxFontDialog(wxWindow *parent, const wxFontData& data)
|
||||
: wxFontDialogBase(parent, data) { Create(parent, data); }
|
||||
|
||||
wxFontData& GetFontData() { return m_fontData; }
|
||||
virtual ~wxFontDialog();
|
||||
|
||||
//protected:
|
||||
wxFontData m_fontData;
|
||||
// implementation only
|
||||
void SetChosenFont(const char *name);
|
||||
|
||||
// deprecated interface, don't use
|
||||
wxFontDialog(wxWindow *parent, const wxFontData *data)
|
||||
: wxFontDialogBase(parent, data) { Create(parent, data); }
|
||||
|
||||
protected:
|
||||
// create the GTK dialog
|
||||
virtual bool DoCreate(wxWindow *parent);
|
||||
|
||||
private:
|
||||
DECLARE_DYNAMIC_CLASS(wxFontDialog)
|
||||
|
@@ -16,28 +16,25 @@
|
||||
#pragma interface "fontdlg.h"
|
||||
#endif
|
||||
|
||||
#include "wx/dialog.h"
|
||||
#include "wx/cmndata.h"
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxFontDialog
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class WXDLLEXPORT wxFontDialog : public wxDialog
|
||||
class WXDLLEXPORT wxFontDialog : public wxFontDialogBase
|
||||
{
|
||||
public:
|
||||
wxFontDialog();
|
||||
wxFontDialog(wxWindow *parent, wxFontData *data = NULL);
|
||||
|
||||
bool Create(wxWindow *parent, wxFontData *data = NULL);
|
||||
wxFontDialog() : wxFontDialogBase() { }
|
||||
wxFontDialog(wxWindow *parent) : wxFontDialogBase(parent) { }
|
||||
wxFontDialog(wxWindow *parent, const wxFontData& data)
|
||||
: wxFontDialogBase(parent, data) { }
|
||||
|
||||
virtual int ShowModal();
|
||||
|
||||
wxFontData& GetFontData() { return m_fontData; }
|
||||
// deprecated
|
||||
wxFontDialog(wxWindow *parent, wxFontData *data)
|
||||
: wxFontDialogBase(parent, data) { }
|
||||
|
||||
protected:
|
||||
wxFontData m_fontData;
|
||||
|
||||
DECLARE_DYNAMIC_CLASS(wxFontDialog)
|
||||
};
|
||||
|
||||
|
@@ -243,15 +243,21 @@ void MyFrame::ChooseFont(wxCommandEvent& WXUNUSED(event) )
|
||||
data.SetInitialFont(wxGetApp().m_canvasFont);
|
||||
data.SetColour(wxGetApp().m_canvasTextColour);
|
||||
|
||||
wxFontDialog *dialog = new wxFontDialog(this, &data);
|
||||
if (dialog->ShowModal() == wxID_OK)
|
||||
// you might also do this:
|
||||
//
|
||||
// wxFontDialog dialog;
|
||||
// if ( !dialog.Create(this, data) { ... error ... }
|
||||
//
|
||||
wxFontDialog dialog(this, data);
|
||||
|
||||
if (dialog.ShowModal() == wxID_OK)
|
||||
{
|
||||
wxFontData retData = dialog->GetFontData();
|
||||
wxFontData retData = dialog.GetFontData();
|
||||
wxGetApp().m_canvasFont = retData.GetChosenFont();
|
||||
wxGetApp().m_canvasTextColour = retData.GetColour();
|
||||
myCanvas->Refresh();
|
||||
}
|
||||
dialog->Destroy();
|
||||
//else: cancelled by the user, don't change the font
|
||||
}
|
||||
|
||||
#if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW
|
||||
|
@@ -39,6 +39,10 @@
|
||||
#include "wx/cmndata.h"
|
||||
#include "wx/log.h"
|
||||
|
||||
#if wxUSE_FONTDLG
|
||||
#include "wx/fontdlg.h"
|
||||
#endif // wxUSE_FONTDLG
|
||||
|
||||
// For compatibility
|
||||
#if (defined(__WXMOTIF__) || defined(__WXGTK__) || defined(__WXX11__)|| defined(__WXPM__) || defined(__WXMAC__)) && wxUSE_POSTSCRIPT
|
||||
#define wxCOMPATIBILITY_WITH_PRINTSETUPDATA 1
|
||||
@@ -178,6 +182,14 @@ wxFontData::~wxFontData()
|
||||
{
|
||||
}
|
||||
|
||||
#if wxUSE_FONTDLG
|
||||
|
||||
wxFontDialogBase::~wxFontDialogBase()
|
||||
{
|
||||
}
|
||||
|
||||
#endif // wxUSE_FONTDLG
|
||||
|
||||
#if wxUSE_PRINTING_ARCHITECTURE
|
||||
// ----------------------------------------------------------------------------
|
||||
// Print data
|
||||
|
@@ -76,7 +76,7 @@ void gtk_fontdialog_ok_callback( GtkWidget *WXUNUSED(widget), wxFontDialog *dial
|
||||
|
||||
gchar *fontname = gtk_font_selection_dialog_get_font_name(fontdlg);
|
||||
|
||||
dialog->m_fontData.SetChosenFont(wxFont(fontname));
|
||||
dialog->SetChosenFont(fontname);
|
||||
|
||||
g_free( fontname );
|
||||
|
||||
@@ -105,10 +105,9 @@ void gtk_fontdialog_cancel_callback( GtkWidget *WXUNUSED(w), wxFontDialog *dialo
|
||||
// wxFontDialog
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxFontDialog,wxDialog)
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxFontDialog, wxDialog)
|
||||
|
||||
wxFontDialog::wxFontDialog( wxWindow *parent, wxFontData *fontdata )
|
||||
: m_fontData(*fontdata)
|
||||
bool wxFontDialog::DoCreate(wxWindow *parent)
|
||||
{
|
||||
m_needParent = FALSE;
|
||||
|
||||
@@ -116,8 +115,8 @@ wxFontDialog::wxFontDialog( wxWindow *parent, wxFontData *fontdata )
|
||||
!CreateBase( parent, -1, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE,
|
||||
wxDefaultValidator, wxT("fontdialog") ))
|
||||
{
|
||||
wxFAIL_MSG( wxT("wxXX creation failed") );
|
||||
return;
|
||||
wxFAIL_MSG( wxT("wxFontDialog creation failed") );
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
wxString m_message( _("Choose font") );
|
||||
@@ -166,11 +165,18 @@ wxFontDialog::wxFontDialog( wxWindow *parent, wxFontData *fontdata )
|
||||
wxFAIL_MSG(_T("font is ok but no native font info?"));
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
wxFontDialog::~wxFontDialog()
|
||||
{
|
||||
}
|
||||
|
||||
void wxFontDialog::SetChosenFont(const char *fontname)
|
||||
{
|
||||
m_fontData.SetChosenFont(wxFont(fontname));
|
||||
}
|
||||
|
||||
#endif // wxUSE_FONTDLG
|
||||
|
||||
|
@@ -76,7 +76,7 @@ void gtk_fontdialog_ok_callback( GtkWidget *WXUNUSED(widget), wxFontDialog *dial
|
||||
|
||||
gchar *fontname = gtk_font_selection_dialog_get_font_name(fontdlg);
|
||||
|
||||
dialog->m_fontData.SetChosenFont(wxFont(fontname));
|
||||
dialog->SetChosenFont(fontname);
|
||||
|
||||
g_free( fontname );
|
||||
|
||||
@@ -105,10 +105,9 @@ void gtk_fontdialog_cancel_callback( GtkWidget *WXUNUSED(w), wxFontDialog *dialo
|
||||
// wxFontDialog
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxFontDialog,wxDialog)
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxFontDialog, wxDialog)
|
||||
|
||||
wxFontDialog::wxFontDialog( wxWindow *parent, wxFontData *fontdata )
|
||||
: m_fontData(*fontdata)
|
||||
bool wxFontDialog::DoCreate(wxWindow *parent)
|
||||
{
|
||||
m_needParent = FALSE;
|
||||
|
||||
@@ -116,8 +115,8 @@ wxFontDialog::wxFontDialog( wxWindow *parent, wxFontData *fontdata )
|
||||
!CreateBase( parent, -1, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE,
|
||||
wxDefaultValidator, wxT("fontdialog") ))
|
||||
{
|
||||
wxFAIL_MSG( wxT("wxXX creation failed") );
|
||||
return;
|
||||
wxFAIL_MSG( wxT("wxFontDialog creation failed") );
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
wxString m_message( _("Choose font") );
|
||||
@@ -166,11 +165,18 @@ wxFontDialog::wxFontDialog( wxWindow *parent, wxFontData *fontdata )
|
||||
wxFAIL_MSG(_T("font is ok but no native font info?"));
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
wxFontDialog::~wxFontDialog()
|
||||
{
|
||||
}
|
||||
|
||||
void wxFontDialog::SetChosenFont(const char *fontname)
|
||||
{
|
||||
m_fontData.SetChosenFont(wxFont(fontname));
|
||||
}
|
||||
|
||||
#endif // wxUSE_FONTDLG
|
||||
|
||||
|
@@ -64,27 +64,6 @@ IMPLEMENT_DYNAMIC_CLASS(wxFontDialog, wxDialog)
|
||||
// wxFontDialog
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
wxFontDialog::wxFontDialog()
|
||||
{
|
||||
m_parent = NULL;
|
||||
}
|
||||
|
||||
wxFontDialog::wxFontDialog(wxWindow *parent, wxFontData *data)
|
||||
{
|
||||
Create(parent, data);
|
||||
}
|
||||
|
||||
bool wxFontDialog::Create(wxWindow *parent, wxFontData *data)
|
||||
{
|
||||
m_parent = parent;
|
||||
|
||||
wxCHECK_MSG( data, FALSE, _T("no font data in wxFontDialog") );
|
||||
|
||||
m_fontData = *data;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
int wxFontDialog::ShowModal()
|
||||
{
|
||||
DWORD flags = CF_SCREENFONTS | CF_NOSIMULATIONS;
|
||||
|
Reference in New Issue
Block a user