Add font colour support to wxFontPickerCtrl.
Currently this is only really implemented under Windows, just as the colour support in wxFontDialog, but make the API available under all platforms for consistency. Closes #11614. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@76160 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -54,6 +54,7 @@ wxMSW:
|
||||
- Fix loading of bitmap with non-pre-multiplied alpha (Artur Wieczorek).
|
||||
- Support multiline strings in wxDC::DrawRotatedText() (Artur Wieczorek).
|
||||
- Fix stretchable spacers in vertical toolbars (Artur Wieczorek).
|
||||
- Add font colour support to wxFontPickerCtrl (Pana Alexandru).
|
||||
- Add wxEnhMetaFile::Detach() (Luca Bacci).
|
||||
- Add support for saving 256*256 32bpp ICOs in PNG format (Artur Wieczorek).
|
||||
|
||||
|
@@ -41,6 +41,9 @@ public:
|
||||
virtual void SetSelectedFont(const wxFont &f)
|
||||
{ m_selectedFont = f; UpdateFont(); }
|
||||
|
||||
virtual wxColour GetSelectedColour() const = 0;
|
||||
virtual void SetSelectedColour(const wxColour &colour) = 0;
|
||||
|
||||
protected:
|
||||
|
||||
virtual void UpdateFont() = 0;
|
||||
@@ -138,7 +141,15 @@ public: // public API
|
||||
// sets currently displayed font
|
||||
void SetSelectedFont(const wxFont& f);
|
||||
|
||||
// set/get the max pointsize
|
||||
// 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
|
||||
void SetMaxPointSize(unsigned int max)
|
||||
{ m_nMaxPointSize=max; }
|
||||
unsigned int GetMaxPointSize() const
|
||||
|
@@ -35,6 +35,12 @@ public:
|
||||
Create(parent, id, initial, pos, size, style, validator, name);
|
||||
}
|
||||
|
||||
virtual wxColour GetSelectedColour() const
|
||||
{ return m_data.GetColour(); }
|
||||
|
||||
virtual void SetSelectedColour(const wxColour &colour)
|
||||
{ m_data.SetColour(colour); UpdateFont(); }
|
||||
|
||||
virtual ~wxGenericFontButton() {}
|
||||
|
||||
|
||||
|
@@ -21,7 +21,7 @@ class WXDLLIMPEXP_CORE wxFontButton : public wxButton,
|
||||
public wxFontPickerWidgetBase
|
||||
{
|
||||
public:
|
||||
wxFontButton() {}
|
||||
wxFontButton() { Init(); }
|
||||
wxFontButton(wxWindow *parent,
|
||||
wxWindowID id,
|
||||
const wxFont& initial = wxNullFont,
|
||||
@@ -31,7 +31,9 @@ public:
|
||||
const wxValidator& validator = wxDefaultValidator,
|
||||
const wxString& name = wxFontPickerWidgetNameStr)
|
||||
{
|
||||
Create(parent, id, initial, pos, size, style, validator, name);
|
||||
Init();
|
||||
|
||||
Create(parent, id, initial, pos, size, style, validator, name);
|
||||
}
|
||||
|
||||
bool Create(wxWindow *parent,
|
||||
@@ -43,6 +45,12 @@ public:
|
||||
const wxValidator& validator = wxDefaultValidator,
|
||||
const wxString& name = wxFontPickerWidgetNameStr);
|
||||
|
||||
virtual wxColour GetSelectedColour() const
|
||||
{ return m_selectedColour; }
|
||||
|
||||
void SetSelectedColour(const wxColour &colour)
|
||||
{ m_selectedColour = colour; }
|
||||
|
||||
virtual ~wxFontButton();
|
||||
|
||||
protected:
|
||||
@@ -55,6 +63,16 @@ public: // used by the GTK callback only
|
||||
{ m_selectedFont.SetNativeFontInfo(wxString::FromAscii(gtkdescription)); }
|
||||
|
||||
private:
|
||||
// Common part of both ctors.
|
||||
void Init()
|
||||
{
|
||||
m_selectedColour = *wxBLACK;
|
||||
}
|
||||
|
||||
// This can't be changed by the user, but is provided to
|
||||
// satisfy the wxFontPickerWidgetBase interface.
|
||||
wxColour m_selectedColour;
|
||||
|
||||
DECLARE_DYNAMIC_CLASS(wxFontButton)
|
||||
};
|
||||
|
||||
|
@@ -109,6 +109,17 @@ public:
|
||||
*/
|
||||
unsigned int GetMaxPointSize() const;
|
||||
|
||||
/**
|
||||
Returns the currently selected colour.
|
||||
|
||||
Note that the colour of the font can only be set by the user under
|
||||
Windows currently, elsewhere this method simply returns the colour
|
||||
previously set by SetSelectedColour() or black if it hadn't been called.
|
||||
|
||||
@since 3.1.0
|
||||
*/
|
||||
wxColour GetSelectedColour() const;
|
||||
|
||||
/**
|
||||
Returns the currently selected font.
|
||||
Note that this function is completely different from wxWindow::GetFont.
|
||||
@@ -126,6 +137,16 @@ public:
|
||||
*/
|
||||
void SetMaxPointSize(unsigned int max);
|
||||
|
||||
/**
|
||||
Sets the font colour.
|
||||
|
||||
The font colour is actually only used under Windows currently, but this
|
||||
function is available under all platforms for consistency.
|
||||
|
||||
@since 3.1.0
|
||||
*/
|
||||
void SetSelectedColour(const wxColour& colour);
|
||||
|
||||
/**
|
||||
Sets the currently selected font.
|
||||
Note that this function is completely different from wxWindow::SetFont.
|
||||
|
@@ -62,9 +62,10 @@ bool wxGenericFontButton::Create( wxWindow *parent, wxWindowID id,
|
||||
wxCommandEventHandler(wxGenericFontButton::OnButtonClick),
|
||||
NULL, this);
|
||||
|
||||
InitFontData();
|
||||
|
||||
m_selectedFont = initial.IsOk() ? initial : *wxNORMAL_FONT;
|
||||
UpdateFont();
|
||||
InitFontData();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@@ -20,6 +20,7 @@
|
||||
#include "wx/filepicker.h"
|
||||
#include "wx/fontpicker.h"
|
||||
#include "pickerbasetest.h"
|
||||
#include "asserthelper.h"
|
||||
|
||||
#if wxUSE_COLOURPICKERCTRL
|
||||
|
||||
@@ -172,8 +173,11 @@ private:
|
||||
|
||||
CPPUNIT_TEST_SUITE( FontPickerCtrlTestCase );
|
||||
wxPICKER_BASE_TESTS();
|
||||
CPPUNIT_TEST( ColourSelection );
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
void ColourSelection();
|
||||
|
||||
wxFontPickerCtrl *m_font;
|
||||
|
||||
DECLARE_NO_COPY_CLASS(FontPickerCtrlTestCase)
|
||||
@@ -198,4 +202,16 @@ void FontPickerCtrlTestCase::tearDown()
|
||||
wxDELETE(m_font);
|
||||
}
|
||||
|
||||
void FontPickerCtrlTestCase::ColourSelection()
|
||||
{
|
||||
wxColour selectedColour(0xFF4269UL);
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL_MESSAGE("Default font picker color must be black",
|
||||
m_font->GetSelectedColour(), wxColour(*wxBLACK));
|
||||
|
||||
m_font->SetSelectedColour(selectedColour);
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL_MESSAGE("Font picker did not react to color selection",
|
||||
m_font->GetSelectedColour(), selectedColour);
|
||||
}
|
||||
#endif //wxUSE_FONTPICKERCTRL
|
||||
|
Reference in New Issue
Block a user