\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}}
\membersection{wxFontDialog::GetFontData}
+\constfunc{const wxFontData\&}{GetFontData}{\void}
+
\func{wxFontData\&}{GetFontData}{\void}
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.
+///////////////////////////////////////////////////////////////////////////////
+// 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
#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); }
+
+ virtual ~wxFontDialog();
+
+ // implementation only
+ void SetChosenFont(const char *name);
- wxFontData& GetFontData() { return m_fontData; }
+ // deprecated interface, don't use
+ wxFontDialog(wxWindow *parent, const wxFontData *data)
+ : wxFontDialogBase(parent, data) { Create(parent, data); }
-//protected:
- wxFontData m_fontData;
+protected:
+ // create the GTK dialog
+ virtual bool DoCreate(wxWindow *parent);
private:
DECLARE_DYNAMIC_CLASS(wxFontDialog)
#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); }
+
+ virtual ~wxFontDialog();
+
+ // implementation only
+ void SetChosenFont(const char *name);
- wxFontData& GetFontData() { return m_fontData; }
+ // deprecated interface, don't use
+ wxFontDialog(wxWindow *parent, const wxFontData *data)
+ : wxFontDialogBase(parent, data) { Create(parent, data); }
-//protected:
- wxFontData m_fontData;
+protected:
+ // create the GTK dialog
+ virtual bool DoCreate(wxWindow *parent);
private:
DECLARE_DYNAMIC_CLASS(wxFontDialog)
#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)
};
void MyFrame::ChooseFont(wxCommandEvent& WXUNUSED(event) )
{
- wxFontData data;
- data.SetInitialFont(wxGetApp().m_canvasFont);
- data.SetColour(wxGetApp().m_canvasTextColour);
+ wxFontData data;
+ data.SetInitialFont(wxGetApp().m_canvasFont);
+ data.SetColour(wxGetApp().m_canvasTextColour);
- wxFontDialog *dialog = new wxFontDialog(this, &data);
- if (dialog->ShowModal() == wxID_OK)
- {
- wxFontData retData = dialog->GetFontData();
+ // 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();
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
#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
{
}
+#if wxUSE_FONTDLG
+
+wxFontDialogBase::~wxFontDialogBase()
+{
+}
+
+#endif // wxUSE_FONTDLG
+
#if wxUSE_PRINTING_ARCHITECTURE
// ----------------------------------------------------------------------------
// Print data
#if TARGET_CARBON
m_macPageFormat = kPMNoPageFormat;
m_macPrintSettings = kPMNoPrintSettings;
-
+
#if PM_USE_SESSION_APIS
PMPrintSession macPrintSession = kPMNoReference;
OSStatus err;
-
+
err = ::UMAPrOpen(&macPrintSession) ;
if ( err == noErr )
- {
+ {
err = PMCreatePageFormat((PMPageFormat *)&m_macPageFormat);
-
+
// Note that PMPageFormat is not session-specific, but calling
// PMSessionDefaultPageFormat assigns values specific to the printer
// associated with the current printing session.
err = PMSessionDefaultPageFormat((PMPrintSession)macPrintSession,
(PMPageFormat)m_macPageFormat);
}
-
+
err = PMCreatePrintSettings((PMPrintSettings *)&m_macPrintSettings);
-
+
// Note that PMPrintSettings is not session-specific, but calling
// PMSessionDefaultPrintSettings assigns values specific to the printer
// associated with the current printing session.
#endif
m_macPrintSettings = kPMNoPrintSettings;
}
-
+
#else
wxASSERT( m_macPrintSettings );
// we should perhaps delete
return (m_devMode != NULL) ;
#else
return TRUE;
-#endif
+#endif
}
// ----------------------------------------------------------------------------
gchar *fontname = gtk_font_selection_dialog_get_font_name(fontdlg);
- dialog->m_fontData.SetChosenFont(wxFont(fontname));
+ dialog->SetChosenFont(fontname);
g_free( fontname );
// 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;
!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") );
m_widget = gtk_font_selection_dialog_new( m_message.mbc_str() );
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
gchar *fontname = gtk_font_selection_dialog_get_font_name(fontdlg);
- dialog->m_fontData.SetChosenFont(wxFont(fontname));
+ dialog->SetChosenFont(fontname);
g_free( fontname );
// 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;
!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") );
m_widget = gtk_font_selection_dialog_new( m_message.mbc_str() );
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
// 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;