2006-05-31 19:57:54 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: wx/fontpicker.h
|
|
|
|
// Purpose: wxFontPickerCtrl base header
|
|
|
|
// Author: Francesco Montorsi
|
|
|
|
// Modified by:
|
|
|
|
// Created: 14/4/2006
|
|
|
|
// Copyright: (c) Francesco Montorsi
|
|
|
|
// Licence: wxWindows Licence
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifndef _WX_FONTPICKER_H_BASE_
|
|
|
|
#define _WX_FONTPICKER_H_BASE_
|
|
|
|
|
|
|
|
#include "wx/defs.h"
|
|
|
|
|
|
|
|
|
|
|
|
#if wxUSE_FONTPICKERCTRL
|
|
|
|
|
|
|
|
#include "wx/pickerbase.h"
|
|
|
|
|
|
|
|
|
2007-07-09 06:09:52 -04:00
|
|
|
class WXDLLIMPEXP_FWD_CORE wxFontPickerEvent;
|
2006-05-31 19:57:54 -04:00
|
|
|
|
2008-03-26 11:06:00 -04:00
|
|
|
extern WXDLLIMPEXP_DATA_CORE(const char) wxFontPickerWidgetNameStr[];
|
|
|
|
extern WXDLLIMPEXP_DATA_CORE(const char) wxFontPickerCtrlNameStr[];
|
2006-05-31 19:57:54 -04:00
|
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxFontPickerWidgetBase: a generic abstract interface which must be
|
|
|
|
// implemented by controls used by wxFontPickerCtrl
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class WXDLLIMPEXP_CORE wxFontPickerWidgetBase
|
|
|
|
{
|
|
|
|
public:
|
2017-02-18 13:48:27 -05:00
|
|
|
wxFontPickerWidgetBase() : m_selectedFont(*wxNORMAL_FONT) { }
|
2006-05-31 19:57:54 -04:00
|
|
|
virtual ~wxFontPickerWidgetBase() {}
|
|
|
|
|
|
|
|
wxFont GetSelectedFont() const
|
|
|
|
{ return m_selectedFont; }
|
|
|
|
virtual void SetSelectedFont(const wxFont &f)
|
|
|
|
{ m_selectedFont = f; UpdateFont(); }
|
|
|
|
|
2014-03-18 13:23:13 -04:00
|
|
|
virtual wxColour GetSelectedColour() const = 0;
|
|
|
|
virtual void SetSelectedColour(const wxColour &colour) = 0;
|
|
|
|
|
2006-05-31 19:57:54 -04:00
|
|
|
protected:
|
|
|
|
|
|
|
|
virtual void UpdateFont() = 0;
|
|
|
|
|
|
|
|
// the current font (may be invalid if none)
|
|
|
|
// NOTE: don't call this m_font as wxWindow::m_font already exists
|
|
|
|
wxFont m_selectedFont;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Styles which must be supported by all controls implementing wxFontPickerWidgetBase
|
|
|
|
// NB: these styles must be defined to carefully-chosen values to
|
|
|
|
// avoid conflicts with wxButton's styles
|
|
|
|
|
|
|
|
|
|
|
|
// keeps the label of the button updated with the fontface name + font size
|
|
|
|
// E.g. choosing "Times New Roman bold, italic with size 10" from the fontdialog,
|
|
|
|
// updates the wxFontButtonGeneric's label (overwriting any previous label)
|
|
|
|
// with the "Times New Roman, 10" text (only fontface + fontsize is displayed
|
|
|
|
// to avoid extralong labels).
|
|
|
|
#define wxFNTP_FONTDESC_AS_LABEL 0x0008
|
|
|
|
|
|
|
|
// uses the currently selected font to draw the label of the button
|
|
|
|
#define wxFNTP_USEFONT_FOR_LABEL 0x0010
|
|
|
|
|
2007-11-05 17:31:24 -05:00
|
|
|
#define wxFONTBTN_DEFAULT_STYLE \
|
|
|
|
(wxFNTP_FONTDESC_AS_LABEL | wxFNTP_USEFONT_FOR_LABEL)
|
|
|
|
|
|
|
|
// native version currently only exists in wxGTK2
|
|
|
|
#if defined(__WXGTK20__) && !defined(__WXUNIVERSAL__)
|
2006-05-31 19:57:54 -04:00
|
|
|
#include "wx/gtk/fontpicker.h"
|
|
|
|
#define wxFontPickerWidget wxFontButton
|
|
|
|
#else
|
|
|
|
#include "wx/generic/fontpickerg.h"
|
|
|
|
#define wxFontPickerWidget wxGenericFontButton
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxFontPickerCtrl specific flags
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2006-06-02 08:00:30 -04:00
|
|
|
#define wxFNTP_USE_TEXTCTRL (wxPB_USE_TEXTCTRL)
|
|
|
|
#define wxFNTP_DEFAULT_STYLE (wxFNTP_FONTDESC_AS_LABEL|wxFNTP_USEFONT_FOR_LABEL)
|
2006-05-31 19:57:54 -04:00
|
|
|
|
|
|
|
// not a style but rather the default value of the maximum pointsize allowed
|
|
|
|
#define wxFNTP_MAXPOINT_SIZE 100
|
|
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxFontPickerCtrl: platform-independent class which embeds the
|
|
|
|
// platform-dependent wxFontPickerWidget andm if wxFNTP_USE_TEXTCTRL style is
|
|
|
|
// used, a textctrl next to it.
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class WXDLLIMPEXP_CORE wxFontPickerCtrl : public wxPickerBase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
wxFontPickerCtrl()
|
2012-09-09 09:35:57 -04:00
|
|
|
: m_nMaxPointSize(wxFNTP_MAXPOINT_SIZE)
|
2006-05-31 19:57:54 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~wxFontPickerCtrl() {}
|
|
|
|
|
|
|
|
|
|
|
|
wxFontPickerCtrl(wxWindow *parent,
|
|
|
|
wxWindowID id,
|
2006-11-03 16:54:13 -05:00
|
|
|
const wxFont& initial = wxNullFont,
|
2006-05-31 19:57:54 -04:00
|
|
|
const wxPoint& pos = wxDefaultPosition,
|
|
|
|
const wxSize& size = wxDefaultSize,
|
|
|
|
long style = wxFNTP_DEFAULT_STYLE,
|
|
|
|
const wxValidator& validator = wxDefaultValidator,
|
|
|
|
const wxString& name = wxFontPickerCtrlNameStr)
|
2012-09-09 09:35:57 -04:00
|
|
|
: m_nMaxPointSize(wxFNTP_MAXPOINT_SIZE)
|
2006-05-31 19:57:54 -04:00
|
|
|
{
|
|
|
|
Create(parent, id, initial, pos, size, style, validator, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Create(wxWindow *parent,
|
|
|
|
wxWindowID id,
|
2006-11-03 16:54:13 -05:00
|
|
|
const wxFont& initial = wxNullFont,
|
2006-05-31 19:57:54 -04:00
|
|
|
const wxPoint& pos = wxDefaultPosition,
|
|
|
|
const wxSize& size = wxDefaultSize,
|
|
|
|
long style = wxFNTP_DEFAULT_STYLE,
|
|
|
|
const wxValidator& validator = wxDefaultValidator,
|
|
|
|
const wxString& name = wxFontPickerCtrlNameStr);
|
|
|
|
|
|
|
|
|
|
|
|
public: // public API
|
|
|
|
|
|
|
|
// get the font chosen
|
|
|
|
wxFont GetSelectedFont() const
|
2014-03-18 13:23:06 -04:00
|
|
|
{ return GetPickerWidget()->GetSelectedFont(); }
|
2006-05-31 19:57:54 -04:00
|
|
|
|
|
|
|
// sets currently displayed font
|
|
|
|
void SetSelectedFont(const wxFont& f);
|
|
|
|
|
2014-03-18 13:23:13 -04:00
|
|
|
// returns the selected color
|
|
|
|
wxColour GetSelectedColour() const
|
|
|
|
{ return GetPickerWidget()->GetSelectedColour(); }
|
|
|
|
|
|
|
|
// sets the currently selected color
|
|
|
|
void SetSelectedColour(const wxColour& colour)
|
|
|
|
{ GetPickerWidget()->SetSelectedColour(colour); }
|
|
|
|
|
|
|
|
// set/get the max point size
|
2006-05-31 19:57:54 -04:00
|
|
|
void SetMaxPointSize(unsigned int max)
|
|
|
|
{ m_nMaxPointSize=max; }
|
|
|
|
unsigned int GetMaxPointSize() const
|
|
|
|
{ return m_nMaxPointSize; }
|
|
|
|
|
|
|
|
public: // internal functions
|
|
|
|
|
2014-03-29 20:02:23 -04:00
|
|
|
void UpdatePickerFromTextCtrl() wxOVERRIDE;
|
|
|
|
void UpdateTextCtrlFromPicker() wxOVERRIDE;
|
2006-05-31 19:57:54 -04:00
|
|
|
|
|
|
|
// event handler for our picker
|
|
|
|
void OnFontChange(wxFontPickerEvent &);
|
|
|
|
|
|
|
|
// used to convert wxString <-> wxFont
|
|
|
|
virtual wxString Font2String(const wxFont &font);
|
|
|
|
virtual wxFont String2Font(const wxString &font);
|
|
|
|
|
2006-06-03 15:20:23 -04:00
|
|
|
protected:
|
|
|
|
|
2006-05-31 19:57:54 -04:00
|
|
|
// extracts the style for our picker from wxFontPickerCtrl's style
|
2014-03-29 20:02:23 -04:00
|
|
|
long GetPickerStyle(long style) const wxOVERRIDE
|
2006-05-31 19:57:54 -04:00
|
|
|
{ return (style & (wxFNTP_FONTDESC_AS_LABEL|wxFNTP_USEFONT_FOR_LABEL)); }
|
|
|
|
|
|
|
|
// the maximum pointsize allowed to the user
|
|
|
|
unsigned int m_nMaxPointSize;
|
|
|
|
|
|
|
|
private:
|
2014-03-18 13:23:06 -04:00
|
|
|
wxFontPickerWidget* GetPickerWidget() const
|
|
|
|
{ return static_cast<wxFontPickerWidget*>(m_picker); }
|
|
|
|
|
2015-04-23 07:49:01 -04:00
|
|
|
wxDECLARE_DYNAMIC_CLASS(wxFontPickerCtrl);
|
2006-05-31 19:57:54 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxFontPickerEvent: used by wxFontPickerCtrl only
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2013-04-25 06:11:03 -04:00
|
|
|
wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_FONTPICKER_CHANGED, wxFontPickerEvent );
|
2006-05-31 19:57:54 -04:00
|
|
|
|
|
|
|
class WXDLLIMPEXP_CORE wxFontPickerEvent : public wxCommandEvent
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
wxFontPickerEvent() {}
|
|
|
|
wxFontPickerEvent(wxObject *generator, int id, const wxFont &f)
|
2013-04-25 06:11:03 -04:00
|
|
|
: wxCommandEvent(wxEVT_FONTPICKER_CHANGED, id),
|
2006-05-31 19:57:54 -04:00
|
|
|
m_font(f)
|
|
|
|
{
|
|
|
|
SetEventObject(generator);
|
|
|
|
}
|
|
|
|
|
|
|
|
wxFont GetFont() const { return m_font; }
|
|
|
|
void SetFont(const wxFont &c) { m_font = c; }
|
|
|
|
|
2006-06-08 14:27:44 -04:00
|
|
|
// default copy ctor, assignment operator and dtor are ok
|
2014-03-29 20:02:23 -04:00
|
|
|
virtual wxEvent *Clone() const wxOVERRIDE { return new wxFontPickerEvent(*this); }
|
2006-06-08 14:27:44 -04:00
|
|
|
|
2006-05-31 19:57:54 -04:00
|
|
|
private:
|
|
|
|
wxFont m_font;
|
|
|
|
|
2015-04-23 07:49:01 -04:00
|
|
|
wxDECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxFontPickerEvent);
|
2006-05-31 19:57:54 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// event types and macros
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
typedef void (wxEvtHandler::*wxFontPickerEventFunction)(wxFontPickerEvent&);
|
|
|
|
|
|
|
|
#define wxFontPickerEventHandler(func) \
|
2009-01-12 09:26:13 -05:00
|
|
|
wxEVENT_HANDLER_CAST(wxFontPickerEventFunction, func)
|
2006-05-31 19:57:54 -04:00
|
|
|
|
|
|
|
#define EVT_FONTPICKER_CHANGED(id, fn) \
|
2013-04-25 06:11:03 -04:00
|
|
|
wx__DECLARE_EVT1(wxEVT_FONTPICKER_CHANGED, id, wxFontPickerEventHandler(fn))
|
|
|
|
|
|
|
|
// old wxEVT_COMMAND_* constants
|
|
|
|
#define wxEVT_COMMAND_FONTPICKER_CHANGED wxEVT_FONTPICKER_CHANGED
|
2006-05-31 19:57:54 -04:00
|
|
|
|
|
|
|
|
|
|
|
#endif // wxUSE_FONTPICKERCTRL
|
|
|
|
|
|
|
|
#endif
|
|
|
|
// _WX_FONTPICKER_H_BASE_
|