diff --git a/interface/wx/settings.h b/interface/wx/settings.h index 7b2ebc087a..cec68d3332 100644 --- a/interface/wx/settings.h +++ b/interface/wx/settings.h @@ -217,8 +217,9 @@ enum wxSystemScreenType @class wxSystemSettings wxSystemSettings allows the application to ask for details about the system. - This can include settings such as standard colours, fonts, - and user interface element sizes. + + This can include settings such as standard colours, fonts, and user interface + element sizes. @library{wxcore} @category{cfg} @@ -238,13 +239,23 @@ public: /** Returns a system colour. - @a index can be one of the ::wxSystemColour enum values. + + @param index + Can be one of the ::wxSystemColour enum values. + + @return + The returned colour is always valid. */ static wxColour GetColour(wxSystemColour index); /** Returns a system font. - @a index can be one of the ::wxSystemFont enum values. + + @param index + Can be one of the ::wxSystemFont enum values. + + @return + The returned font is always valid. */ static wxFont GetFont(wxSystemFont index); diff --git a/src/gtk/settings.cpp b/src/gtk/settings.cpp index 6e5e0f363f..89cb46dbad 100644 --- a/src/gtk/settings.cpp +++ b/src/gtk/settings.cpp @@ -19,6 +19,7 @@ #endif #include "wx/fontutil.h" +#include "wx/fontenum.h" #include #include "wx/gtk/private/win_gtk.h" @@ -232,6 +233,7 @@ wxColour wxSystemSettingsNative::GetColour( wxSystemColour index ) break; } + wxASSERT(color.IsOk()); return color; } @@ -255,6 +257,13 @@ wxFont wxSystemSettingsNative::GetFont( wxSystemFont index ) wxNativeFontInfo info; info.description = ButtonStyle()->font_desc; gs_fontSystem = wxFont(info); + + // (try to) heal the default font (on some common systems e.g. Ubuntu + // it's "Sans Serif" but the real font is called "Sans"): + if (!wxFontEnumerator::IsValidFacename(gs_fontSystem.GetFaceName()) && + gs_fontSystem.GetFaceName() == "Sans Serif") + gs_fontSystem.SetFaceName("Sans"); + info.description = NULL; } font = gs_fontSystem; @@ -263,6 +272,9 @@ wxFont wxSystemSettingsNative::GetFont( wxSystemFont index ) default: break; } + + wxASSERT(font.IsOk() && wxFontEnumerator::IsValidFacename(font.GetFaceName())); + return font; } diff --git a/src/msw/settings.cpp b/src/msw/settings.cpp index 591b4f7c63..e627033416 100644 --- a/src/msw/settings.cpp +++ b/src/msw/settings.cpp @@ -40,6 +40,7 @@ #endif #include "wx/fontutil.h" +#include "wx/fontenum.h" // ---------------------------------------------------------------------------- // private classes @@ -207,8 +208,10 @@ wxColour wxSystemSettingsNative::GetColour(wxSystemColour index) colSys = ::GetSysColor(index); #endif } - - return wxRGBToColour(colSys); + + wxColour ret = wxRGBToColour(colSys); + wxASSERT(ret.IsOk()); + return ret; } // ---------------------------------------------------------------------------- @@ -267,6 +270,8 @@ wxFont wxSystemSettingsNative::GetFont(wxSystemFont index) gs_fontDefault = new wxFont(wxCreateFontFromStockObject(SYSTEM_FONT)); } + wxASSERT(gs_fontDefault->IsOk() && + wxFontEnumerator::IsValidFacename(gs_fontDefault->GetFaceName())); return *gs_fontDefault; #else // !__WXWINCE__ // wxWindow ctor calls GetFont(wxSYS_DEFAULT_GUI_FONT) so we're @@ -286,6 +291,7 @@ wxFont wxSystemSettingsNative::GetFont(wxSystemFont index) gs_fontDefault = new wxFont(font); } + wxASSERT(font.IsOk() && wxFontEnumerator::IsValidFacename(font.GetFaceName())); return font; #endif // __WXWINCE__/!__WXWINCE__ } diff --git a/src/osx/carbon/settings.cpp b/src/osx/carbon/settings.cpp index ad5c4f7987..b7608a7e25 100644 --- a/src/osx/carbon/settings.cpp +++ b/src/osx/carbon/settings.cpp @@ -19,6 +19,7 @@ #endif #include "wx/osx/private.h" +#include "wx/fontenum.h" // ---------------------------------------------------------------------------- // wxSystemSettingsNative @@ -146,6 +147,8 @@ wxColour wxSystemSettingsNative::GetColour(wxSystemColour index) break ; } + //wxASSERT(resultColor.IsOk()); + return resultColor; } @@ -155,20 +158,25 @@ wxColour wxSystemSettingsNative::GetColour(wxSystemColour index) wxFont wxSystemSettingsNative::GetFont(wxSystemFont index) { + wxFont font; + switch (index) { case wxSYS_ANSI_VAR_FONT : case wxSYS_SYSTEM_FONT : case wxSYS_DEVICE_DEFAULT_FONT : case wxSYS_DEFAULT_GUI_FONT : - return *wxSMALL_FONT ; + font = *wxSMALL_FONT ; break ; default : + font = *wxNORMAL_FONT ; break ; } - return *wxNORMAL_FONT; + //wxASSERT(font.IsOk() && wxFontEnumerator::IsValidFacename(font.GetFaceName())); + + return font; } // ---------------------------------------------------------------------------- diff --git a/tests/Makefile.in b/tests/Makefile.in index 829f622e99..3ac2885e14 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -141,6 +141,7 @@ TEST_GUI_OBJECTS = \ test_gui_guifuncs.o \ test_gui_selstoretest.o \ test_gui_garbage.o \ + test_gui_settings.o \ test_gui_socket.o \ test_gui_clientsize.o \ test_gui_setsize.o @@ -602,6 +603,9 @@ test_gui_selstoretest.o: $(srcdir)/misc/selstoretest.cpp $(TEST_GUI_ODEP) test_gui_garbage.o: $(srcdir)/misc/garbage.cpp $(TEST_GUI_ODEP) $(CXXC) -c -o $@ $(TEST_GUI_CXXFLAGS) $(srcdir)/misc/garbage.cpp +test_gui_settings.o: $(srcdir)/misc/settings.cpp $(TEST_GUI_ODEP) + $(CXXC) -c -o $@ $(TEST_GUI_CXXFLAGS) $(srcdir)/misc/settings.cpp + test_gui_socket.o: $(srcdir)/net/socket.cpp $(TEST_GUI_ODEP) $(CXXC) -c -o $@ $(TEST_GUI_CXXFLAGS) $(srcdir)/net/socket.cpp diff --git a/tests/makefile.bcc b/tests/makefile.bcc index 0680d67ac9..1abc6619b7 100644 --- a/tests/makefile.bcc +++ b/tests/makefile.bcc @@ -126,6 +126,7 @@ TEST_GUI_OBJECTS = \ $(OBJS)\test_gui_guifuncs.obj \ $(OBJS)\test_gui_selstoretest.obj \ $(OBJS)\test_gui_garbage.obj \ + $(OBJS)\test_gui_settings.obj \ $(OBJS)\test_gui_socket.obj \ $(OBJS)\test_gui_clientsize.obj \ $(OBJS)\test_gui_setsize.obj @@ -644,6 +645,9 @@ $(OBJS)\test_gui_selstoretest.obj: .\misc\selstoretest.cpp $(OBJS)\test_gui_garbage.obj: .\misc\garbage.cpp $(CXX) -q -c -P -o$@ $(TEST_GUI_CXXFLAGS) .\misc\garbage.cpp +$(OBJS)\test_gui_settings.obj: .\misc\settings.cpp + $(CXX) -q -c -P -o$@ $(TEST_GUI_CXXFLAGS) .\misc\settings.cpp + $(OBJS)\test_gui_socket.obj: .\net\socket.cpp $(CXX) -q -c -P -o$@ $(TEST_GUI_CXXFLAGS) .\net\socket.cpp diff --git a/tests/makefile.gcc b/tests/makefile.gcc index 5b72865aa9..c96c6b7dd9 100644 --- a/tests/makefile.gcc +++ b/tests/makefile.gcc @@ -119,6 +119,7 @@ TEST_GUI_OBJECTS = \ $(OBJS)\test_gui_guifuncs.o \ $(OBJS)\test_gui_selstoretest.o \ $(OBJS)\test_gui_garbage.o \ + $(OBJS)\test_gui_settings.o \ $(OBJS)\test_gui_socket.o \ $(OBJS)\test_gui_clientsize.o \ $(OBJS)\test_gui_setsize.o @@ -624,6 +625,9 @@ $(OBJS)\test_gui_selstoretest.o: ./misc/selstoretest.cpp $(OBJS)\test_gui_garbage.o: ./misc/garbage.cpp $(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $< +$(OBJS)\test_gui_settings.o: ./misc/settings.cpp + $(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $< + $(OBJS)\test_gui_socket.o: ./net/socket.cpp $(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $< diff --git a/tests/makefile.vc b/tests/makefile.vc index 108eb43853..3437a89141 100644 --- a/tests/makefile.vc +++ b/tests/makefile.vc @@ -122,6 +122,7 @@ TEST_GUI_OBJECTS = \ $(OBJS)\test_gui_guifuncs.obj \ $(OBJS)\test_gui_selstoretest.obj \ $(OBJS)\test_gui_garbage.obj \ + $(OBJS)\test_gui_settings.obj \ $(OBJS)\test_gui_socket.obj \ $(OBJS)\test_gui_clientsize.obj \ $(OBJS)\test_gui_setsize.obj @@ -729,6 +730,9 @@ $(OBJS)\test_gui_selstoretest.obj: .\misc\selstoretest.cpp $(OBJS)\test_gui_garbage.obj: .\misc\garbage.cpp $(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\misc\garbage.cpp +$(OBJS)\test_gui_settings.obj: .\misc\settings.cpp + $(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\misc\settings.cpp + $(OBJS)\test_gui_socket.obj: .\net\socket.cpp $(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\net\socket.cpp diff --git a/tests/makefile.wat b/tests/makefile.wat index be9cb430d5..e68b7d9166 100644 --- a/tests/makefile.wat +++ b/tests/makefile.wat @@ -357,6 +357,7 @@ TEST_GUI_OBJECTS = & $(OBJS)\test_gui_guifuncs.obj & $(OBJS)\test_gui_selstoretest.obj & $(OBJS)\test_gui_garbage.obj & + $(OBJS)\test_gui_settings.obj & $(OBJS)\test_gui_socket.obj & $(OBJS)\test_gui_clientsize.obj & $(OBJS)\test_gui_setsize.obj @@ -685,6 +686,9 @@ $(OBJS)\test_gui_selstoretest.obj : .AUTODEPEND .\misc\selstoretest.cpp $(OBJS)\test_gui_garbage.obj : .AUTODEPEND .\misc\garbage.cpp $(CXX) -bt=nt -zq -fo=$^@ $(TEST_GUI_CXXFLAGS) $< +$(OBJS)\test_gui_settings.obj : .AUTODEPEND .\misc\settings.cpp + $(CXX) -bt=nt -zq -fo=$^@ $(TEST_GUI_CXXFLAGS) $< + $(OBJS)\test_gui_socket.obj : .AUTODEPEND .\net\socket.cpp $(CXX) -bt=nt -zq -fo=$^@ $(TEST_GUI_CXXFLAGS) $< diff --git a/tests/misc/settings.cpp b/tests/misc/settings.cpp new file mode 100644 index 0000000000..c87e8310cc --- /dev/null +++ b/tests/misc/settings.cpp @@ -0,0 +1,159 @@ +/////////////////////////////////////////////////////////////////////////////// +// Name: tests/misc/settings.cpp +// Purpose: test wxSettings +// Author: Francesco Montorsi +// Created: 2009-03-24 +// RCS-ID: $Id$ +// Copyright: (c) 2009 Francesco Montorsi +/////////////////////////////////////////////////////////////////////////////// + +// ---------------------------------------------------------------------------- +// headers +// ---------------------------------------------------------------------------- + +#include "testprec.h" + +#ifdef __BORLANDC__ + #pragma hdrstop +#endif + +#include "wx/settings.h" +#include "wx/fontenum.h" + +// ---------------------------------------------------------------------------- +// test class +// ---------------------------------------------------------------------------- + +class SettingsTestCase : public CppUnit::TestCase +{ +public: + SettingsTestCase() { } + +private: + CPPUNIT_TEST_SUITE( SettingsTestCase ); + CPPUNIT_TEST( GetColour ); + CPPUNIT_TEST( GetFont ); + CPPUNIT_TEST( GlobalColours ); + CPPUNIT_TEST( GlobalFonts ); + CPPUNIT_TEST( GlobalBrushes ); + CPPUNIT_TEST( GlobalPens ); + CPPUNIT_TEST_SUITE_END(); + + void GetColour(); + void GetFont(); + + // not really wxSystemSettings stuff but still nice to test: + void GlobalColours(); + void GlobalFonts(); + void GlobalBrushes(); + void GlobalPens(); + + DECLARE_NO_COPY_CLASS(SettingsTestCase) +}; + +// register in the unnamed registry so that these tests are run by default +CPPUNIT_TEST_SUITE_REGISTRATION( SettingsTestCase ); + +// also include in it's own registry so that these tests can be run alone +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( SettingsTestCase, "SettingsTestCase" ); + + +void SettingsTestCase::GetColour() +{ + for (unsigned int i=wxSYS_COLOUR_SCROLLBAR; i < wxSYS_COLOUR_MAX; i++) + CPPUNIT_ASSERT( wxSystemSettings::GetColour((wxSystemColour)i).IsOk() ); +} + +void SettingsTestCase::GetFont() +{ + const wxSystemFont ids[] = + { + wxSYS_OEM_FIXED_FONT, + wxSYS_ANSI_FIXED_FONT, + wxSYS_ANSI_VAR_FONT, + wxSYS_SYSTEM_FONT, + wxSYS_DEVICE_DEFAULT_FONT, + wxSYS_SYSTEM_FIXED_FONT, + wxSYS_DEFAULT_GUI_FONT + }; + + for (unsigned int i=0; i < WXSIZEOF(ids); i++) + { + const wxFont& font = wxSystemSettings::GetFont(ids[i]); + CPPUNIT_ASSERT( font.IsOk() && + wxFontEnumerator::IsValidFacename(font.GetFaceName()) ); + } +} + +void SettingsTestCase::GlobalColours() +{ + wxColour col[] = + { + *wxBLACK, + *wxBLUE, + *wxCYAN, + *wxGREEN, + *wxLIGHT_GREY, + *wxRED, + *wxWHITE + }; + + for (unsigned int i=0; i < WXSIZEOF(col); i++) + CPPUNIT_ASSERT( col[i].IsOk() ); +} + +void SettingsTestCase::GlobalFonts() +{ + wxFont font[] = + { + *wxNORMAL_FONT, + *wxSMALL_FONT, + *wxITALIC_FONT, + *wxSWISS_FONT + }; + + for (unsigned int i=0; i < WXSIZEOF(font); i++) + CPPUNIT_ASSERT( font[i].IsOk() && + wxFontEnumerator::IsValidFacename(font[i].GetFaceName()) ); +} + +void SettingsTestCase::GlobalBrushes() +{ + wxBrush brush[] = + { + *wxBLACK_BRUSH, + *wxBLUE_BRUSH, + *wxCYAN_BRUSH, + *wxGREEN_BRUSH, + *wxGREY_BRUSH, + *wxLIGHT_GREY_BRUSH, + *wxMEDIUM_GREY_BRUSH, + *wxRED_BRUSH, + *wxTRANSPARENT_BRUSH, + *wxWHITE_BRUSH + }; + + for (unsigned int i=0; i < WXSIZEOF(brush); i++) + CPPUNIT_ASSERT( brush[i].IsOk() ); +} + +void SettingsTestCase::GlobalPens() +{ + wxPen pen[] = + { + *wxBLACK_DASHED_PEN, + *wxBLACK_PEN, + *wxBLUE_PEN, + *wxCYAN_PEN, + *wxGREEN_PEN, + *wxGREY_PEN, + *wxLIGHT_GREY_PEN, + *wxMEDIUM_GREY_PEN, + *wxRED_PEN, + *wxTRANSPARENT_PEN, + *wxWHITE_PEN + }; + + for (unsigned int i=0; i < WXSIZEOF(pen); i++) + CPPUNIT_ASSERT( pen[i].IsOk() ); +} diff --git a/tests/test.bkl b/tests/test.bkl index 8aa99d7080..868899f3a2 100644 --- a/tests/test.bkl +++ b/tests/test.bkl @@ -123,6 +123,7 @@ misc/guifuncs.cpp misc/selstoretest.cpp misc/garbage.cpp + misc/settings.cpp