]> git.saurik.com Git - wxWidgets.git/commitdiff
Add wxFont ctor taking a single flags argument instead of style/weight/...
authorVadim Zeitlin <vadim@wxwidgets.org>
Mon, 23 Jan 2012 11:28:21 +0000 (11:28 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Mon, 23 Jan 2012 11:28:21 +0000 (11:28 +0000)
Currently this ctor just does the same thing as the existing ctors in a
different way but it will be extended to support wxFONTFLAG_STRIKETHROUGH in
the next commits.

See #9907.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@70445 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

14 files changed:
include/wx/cocoa/font.h
include/wx/dfb/font.h
include/wx/font.h
include/wx/gtk/font.h
include/wx/gtk1/font.h
include/wx/motif/font.h
include/wx/msw/font.h
include/wx/os2/font.h
include/wx/osx/font.h
include/wx/x11/font.h
interface/wx/font.h
src/common/fontcmn.cpp
src/gtk/font.cpp
src/msw/font.cpp

index d54a07f6e1211653794961c4644bc505ab281dda..a8989845dbe531aa31e14074aed4408e2a589b9f 100644 (file)
@@ -75,6 +75,19 @@ public:
         SetPixelSize(pixelSize);
     }
 
+    wxFont(int pointSize,
+           wxFontFamily family,
+           int flags = wxFONTFLAG_DEFAULT,
+           const wxString& face = wxEmptyString,
+           wxFontEncoding encoding = wxFONTENCODING_DEFAULT)
+    {
+        Create(pointSize, family,
+               GetStyleFromFlags(flags),
+               GetWeightFromFlags(flags),
+               GetUnderlinedFromFlags(flags),
+               face, encoding);
+    }
+
     /*! @abstract   Construction with opaque wxNativeFontInfo
      */
     wxFont(const wxNativeFontInfo& info)
index ad0e586e1e2fd3bf93871093117acf22a70c6ac3..3ccdebb42241158dec9ca25e19f47d375e7df10d 100644 (file)
@@ -60,6 +60,19 @@ public:
         SetPixelSize(pixelSize);
     }
 
+    wxFont(int pointSize,
+           wxFontFamily family,
+           int flags = wxFONTFLAG_DEFAULT,
+           const wxString& face = wxEmptyString,
+           wxFontEncoding encoding = wxFONTENCODING_DEFAULT)
+    {
+        Create(pointSize, family,
+               GetStyleFromFlags(flags),
+               GetWeightFromFlags(flags),
+               GetUnderlinedFromFlags(flags),
+               face, encoding);
+    }
+
     bool Create(int size,
                 wxFontFamily family,
                 wxFontStyle style,
index 0d70d3f41a02e0bd85547d9571156e9aacb6f918..0a7623ee49b9861fe0088a7ead9dea26a9b430cc 100644 (file)
@@ -290,6 +290,33 @@ protected:
     // wxFONTFAMILY_UNKNOWN unlike the public method (see comment there).
     virtual wxFontFamily DoGetFamily() const = 0;
 
+
+    // Helper functions to recover wxFONTSTYLE/wxFONTWEIGHT and underlined flg
+    // values from flags containing a combination of wxFONTFLAG_XXX.
+    static wxFontStyle GetStyleFromFlags(int flags)
+    {
+        return flags & wxFONTFLAG_ITALIC
+                        ? wxFONTSTYLE_ITALIC
+                        : flags & wxFONTFLAG_SLANT
+                            ? wxFONTSTYLE_SLANT
+                            : wxFONTSTYLE_NORMAL;
+    }
+
+    static wxFontWeight GetWeightFromFlags(int flags)
+    {
+        return flags & wxFONTFLAG_LIGHT
+                        ? wxFONTWEIGHT_LIGHT
+                        : flags & wxFONTFLAG_BOLD
+                            ? wxFONTWEIGHT_BOLD
+                            : wxFONTWEIGHT_NORMAL;
+    }
+
+    static bool GetUnderlinedFromFlags(int flags)
+    {
+        return (flags & wxFONTFLAG_UNDERLINED) != 0;
+    }
+
+
 private:
     // the currently default encoding: by default, it's the default system
     // encoding, but may be changed by the application using
index da9c9a474f2cd429fd303b3d6fb5e5bcf36f3d6d..a73e9669cbca891f3df46920ace57e2dff6c37ce 100644 (file)
@@ -63,6 +63,12 @@ public:
         SetPixelSize(pixelSize);
     }
 
+    wxFont(int pointSize,
+           wxFontFamily family,
+           int flags = wxFONTFLAG_DEFAULT,
+           const wxString& face = wxEmptyString,
+           wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
+
     bool Create(int size,
                 wxFontFamily family,
                 wxFontStyle style,
index b5e7e4ea207e6760b4465b302cd8da7c9e1e6d43..87d21b1f1198fa3c8faa46a558c1dd35387c1924 100644 (file)
@@ -76,6 +76,19 @@ public:
         SetPixelSize(pixelSize);
     }
 
+    wxFont(int pointSize,
+           wxFontFamily family,
+           int flags = wxFONTFLAG_DEFAULT,
+           const wxString& face = wxEmptyString,
+           wxFontEncoding encoding = wxFONTENCODING_DEFAULT)
+    {
+        Create(pointSize, family,
+               GetStyleFromFlags(flags),
+               GetWeightFromFlags(flags),
+               GetUnderlinedFromFlags(flags),
+               face, encoding);
+    }
+
     bool Create(int size,
                 wxFontFamily family,
                 wxFontStyle style,
index e00eb848d355165e76272d6b4da2535990af04c7..935581f2e4d867f7f72bbe1f050ac2015719e6f5 100644 (file)
@@ -66,6 +66,19 @@ public:
         SetPixelSize(pixelSize);
     }
 
+    wxFont(int pointSize,
+           wxFontFamily family,
+           int flags = wxFONTFLAG_DEFAULT,
+           const wxString& face = wxEmptyString,
+           wxFontEncoding encoding = wxFONTENCODING_DEFAULT)
+    {
+        Create(pointSize, family,
+               GetStyleFromFlags(flags),
+               GetWeightFromFlags(flags),
+               GetUnderlinedFromFlags(flags),
+               face, encoding);
+    }
+
     bool Create(int size,
                 wxFontFamily family,
                 wxFontStyle style,
index 3f49e65e78287e67530c2054a8ac4ac82ed7b2d9..eb4ed5b17e7f7c87127795f9cae2c99a067e0369 100644 (file)
@@ -91,6 +91,12 @@ public:
         Create(info, hFont);
     }
 
+    wxFont(int pointSize,
+           wxFontFamily family,
+           int flags = wxFONTFLAG_DEFAULT,
+           const wxString& face = wxEmptyString,
+           wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
+
     wxFont(const wxString& fontDesc);
 
 
index 7060847d66b2f536e3f1797b9a1ede4d48c67bd5..39be035dfc00d22a13afaae53d2c618852bfbd23 100644 (file)
@@ -63,6 +63,19 @@ public:
         SetPixelSize(pixelSize);
     }
 
+    wxFont(int pointSize,
+           wxFontFamily family,
+           int flags = wxFONTFLAG_DEFAULT,
+           const wxString& face = wxEmptyString,
+           wxFontEncoding encoding = wxFONTENCODING_DEFAULT)
+    {
+        Create(pointSize, family,
+               GetStyleFromFlags(flags),
+               GetWeightFromFlags(flags),
+               GetUnderlinedFromFlags(flags),
+               face, encoding);
+    }
+
     bool Create(int size,
                 wxFontFamily family,
                 wxFontStyle style,
index 7eb86a6809deb0837994777967fdfb8ceb606496..fb7fea783a97fc3f9ed0dd82cc31598f2cb4ec28 100644 (file)
@@ -79,6 +79,19 @@ public:
         SetPixelSize(pixelSize);
     }
 
+    wxFont(int pointSize,
+           wxFontFamily family,
+           int flags = wxFONTFLAG_DEFAULT,
+           const wxString& face = wxEmptyString,
+           wxFontEncoding encoding = wxFONTENCODING_DEFAULT)
+    {
+        Create(pointSize, family,
+               GetStyleFromFlags(flags),
+               GetWeightFromFlags(flags),
+               GetUnderlinedFromFlags(flags),
+               face, encoding);
+    }
+
     bool Create(int size,
                 wxFontFamily family,
                 wxFontStyle style,
index b2c8718392aff65d09063dbeea730c10963bb7ce..a7cabdeb9f5240a8c6091cfecacb425ec471ab2d 100644 (file)
@@ -57,6 +57,19 @@ public:
         SetPixelSize(pixelSize);
     }
 
+    wxFont(int pointSize,
+           wxFontFamily family,
+           int flags = wxFONTFLAG_DEFAULT,
+           const wxString& face = wxEmptyString,
+           wxFontEncoding encoding = wxFONTENCODING_DEFAULT)
+    {
+        Create(pointSize, family,
+               GetStyleFromFlags(flags),
+               GetWeightFromFlags(flags),
+               GetUnderlinedFromFlags(flags),
+               face, encoding);
+    }
+
     bool Create(int size,
                 wxFontFamily family,
                 wxFontStyle style,
index c8de700f481b2e942089dd7b3aa82ace294c2bbc..cde804883bd4471945a1196871b6dca6d51b54e0 100644 (file)
@@ -303,7 +303,7 @@ public:
     wxFont(const wxFont& font);
 
     /**
-        Creates a font object with the specified attributes.
+        Creates a font object with the specified attributes and size in points.
 
         @param pointSize
             Size in points. See SetPointSize() for more info.
@@ -349,7 +349,7 @@ public:
            wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
 
     /**
-        Creates a font object with the specified attributes.
+        Creates a font object with the specified attributes and size in pixels.
 
         @param pixelSize
             Size in pixels. See SetPixelSize() for more info.
@@ -394,6 +394,22 @@ public:
            const wxString& faceName = wxEmptyString,
            wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
 
+    /**
+        Creates a font object using font flags.
+
+        This constructor is similar to the constructors above except it
+        specifies the font styles such as underlined, italic, bold, ... in a
+        single @a flags argument instead of using separate arguments for them.
+        This parameter can be a combination of ::wxFontFlag enum elements.
+        The meaning of the remaining arguments is the same as in the other
+        constructors, please see their documentation for details.
+
+        @since 2.9.4
+     */
+    wxFont(int pointSize, wxFontFamily family, int flags,
+           const wxString& faceName = wxEmptyString,
+           wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
+
     /**
         Constructor from font description string.
 
index d54521c449fa92cf323fa2c009eb4f2dd5ca09c6..de35aa96d1a96fb3bf36f74fbefec1ab004bfc76 100644 (file)
@@ -128,33 +128,6 @@ wxEMPTY_HANDLERS_TABLE(wxFont)
 // implementation
 // ============================================================================
 
-// ----------------------------------------------------------------------------
-// helper functions
-// ----------------------------------------------------------------------------
-
-static inline int flags2Style(int flags)
-{
-    return flags & wxFONTFLAG_ITALIC
-                    ? wxFONTSTYLE_ITALIC
-                    : flags & wxFONTFLAG_SLANT
-                        ? wxFONTSTYLE_SLANT
-                        : wxFONTSTYLE_NORMAL;
-}
-
-static inline int flags2Weight(int flags)
-{
-    return flags & wxFONTFLAG_LIGHT
-                    ? wxFONTWEIGHT_LIGHT
-                    : flags & wxFONTFLAG_BOLD
-                        ? wxFONTWEIGHT_BOLD
-                        : wxFONTWEIGHT_NORMAL;
-}
-
-static inline bool flags2Underlined(int flags)
-{
-    return (flags & wxFONTFLAG_UNDERLINED) != 0;
-}
-
 // ----------------------------------------------------------------------------
 // wxFontBase
 // ----------------------------------------------------------------------------
@@ -209,8 +182,11 @@ wxFont *wxFontBase::New(int pointSize,
                         const wxString& face,
                         wxFontEncoding encoding)
 {
-    return New(pointSize, family, flags2Style(flags), flags2Weight(flags),
-               flags2Underlined(flags), face, encoding);
+    return New(pointSize, family,
+               GetStyleFromFlags(flags),
+               GetWeightFromFlags(flags),
+               GetUnderlinedFromFlags(flags),
+               face, encoding);
 }
 
 /* static */
@@ -220,8 +196,11 @@ wxFont *wxFontBase::New(const wxSize& pixelSize,
                         const wxString& face,
                         wxFontEncoding encoding)
 {
-    return New(pixelSize, family, flags2Style(flags), flags2Weight(flags),
-               flags2Underlined(flags), face, encoding);
+    return New(pixelSize, family,
+               GetStyleFromFlags(flags),
+               GetWeightFromFlags(flags),
+               GetUnderlinedFromFlags(flags),
+               face, encoding);
 }
 
 /* static */
index 3ac8f4590aebc8f817dcec6caf46f57833692933..5ca1b2b600049bccc51795395affeebb107bf003 100644 (file)
@@ -277,6 +277,19 @@ wxFont::wxFont(const wxNativeFontInfo& info)
             info.GetEncoding() );
 }
 
+wxFont::wxFont(int pointSize,
+               wxFontFamily family,
+               int flags,
+               const wxString& face,
+               wxFontEncoding encoding)
+{
+    m_refData = new wxFontRefData(pointSize, family,
+                                  GetStyleFromFlags(flags),
+                                  GetWeightFromFlags(flags),
+                                  GetUnderlinedFromFlags(flags),
+                                  face, encoding);
+}
+
 bool wxFont::Create( int pointSize,
                      wxFontFamily family,
                      wxFontStyle style,
index 376b8b3b870865afb7fd5eba664763d96417f6c1..72294a58b189f31095de95e4ec37ca248dd0578c 100644 (file)
@@ -778,6 +778,20 @@ wxFont::wxFont(const wxString& fontdesc)
         (void)Create(info);
 }
 
+wxFont::wxFont(int pointSize,
+               wxFontFamily family,
+               int flags,
+               const wxString& face,
+               wxFontEncoding encoding)
+{
+    m_refData = new wxFontRefData(pointSize, wxDefaultSize, false,
+                                  family,
+                                  GetStyleFromFlags(flags),
+                                  GetWeightFromFlags(flags),
+                                  GetUnderlinedFromFlags(flags),
+                                  face, encoding);
+}
+
 bool wxFont::Create(const wxNativeFontInfo& info, WXHFONT hFont)
 {
     UnRef();