]> git.saurik.com Git - wxWidgets.git/commitdiff
Add wxPoint::IsFullySpecified() and SetDefaults().
authorVadim Zeitlin <vadim@wxwidgets.org>
Wed, 11 Aug 2010 16:03:51 +0000 (16:03 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Wed, 11 Aug 2010 16:03:51 +0000 (16:03 +0000)
These methods do the same thing as wxSize methods with the same names and are
useful for the same reasons.

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

include/wx/gdicmn.h
interface/wx/gdicmn.h

index 012a90e61f709dedf955a2c44bdcb0efc84c4d47..47de6eefbba7198f2b52c9cdbfe09b40138998c0 100644 (file)
@@ -524,6 +524,18 @@ public:
 
     wxPoint& operator+=(const wxSize& s) { x += s.GetWidth(); y += s.GetHeight(); return *this; }
     wxPoint& operator-=(const wxSize& s) { x -= s.GetWidth(); y -= s.GetHeight(); return *this; }
+
+    // check if both components are set/initialized
+    bool IsFullySpecified() const { return x != wxDefaultCoord && y != wxDefaultCoord; }
+
+    // fill in the unset components with the values from the other point
+    void SetDefaults(const wxPoint& pt)
+    {
+        if ( x == wxDefaultCoord )
+            x = pt.x;
+        if ( y == wxDefaultCoord )
+            y = pt.y;
+    }
 };
 
 
index 2fafd4da0d041bab9e45017adb7d48242440309e..867a0c4ed19980e3f6668700afa45cefa0d33f43 100644 (file)
@@ -583,6 +583,49 @@ public:
     wxSize& operator *=(int factor);
     //@}
 
+
+    /**
+        @name Defaults handling.
+
+        Test for and set non-specified wxPoint components.
+
+        Although a wxPoint is always initialized to (0, 0), wxWidgets commonly
+        uses wxDefaultCoord (defined as @c -1) to indicate that a point hasn't
+        been initialized or specified. In particular, ::wxDefaultPosition is
+        used in many places with this meaning.
+     */
+    //@{
+
+    /**
+        Returns @true if neither of the point components is equal to
+        wxDefaultCoord.
+
+        This method is typically used before calling SetDefaults().
+
+        @since 2.9.2
+    */
+    bool IsFullySpecified() const;
+
+    /**
+        Combine this object with another one replacing the uninitialized
+        values.
+
+        It is typically used like this:
+
+        @code
+        if ( !pos.IsFullySpecified() )
+        {
+            pos.SetDefaults(GetDefaultPosition());
+        }
+        @endcode
+
+        @see IsFullySpecified()
+
+        @since 2.9.2
+    */
+    void SetDefaults(const wxSize& sizeDefault);
+    //@}
+
     /**
         x member.
     */
@@ -595,7 +638,7 @@ public:
 };
 
 /**
-    Global istance of a wxPoint initialized with values (-1,-1).
+    Global instance of a wxPoint initialized with values (-1,-1).
 */
 wxPoint wxDefaultPosition;