diff --git a/headers/private/shared/Variant.h b/headers/private/shared/Variant.h index b5b226846b..bbbaa7a6ae 100644 --- a/headers/private/shared/Variant.h +++ b/headers/private/shared/Variant.h @@ -1,11 +1,13 @@ /* * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. + * Copyright 2011, Rene Gollent, rene@gollent.com. * Distributed under the terms of the MIT License. */ #ifndef _VARIANT_H #define _VARIANT_H +#include #include #include @@ -36,6 +38,9 @@ public: inline BVariant(uint64 value); inline BVariant(float value); inline BVariant(double value); + inline BVariant(const BRect &value); + inline BVariant(float left, float top, float right, + float bottom); inline BVariant(const void* value); inline BVariant(const char* value, uint32 flags = 0); @@ -56,6 +61,9 @@ public: inline void SetTo(uint64 value); inline void SetTo(float value); inline void SetTo(double value); + inline void SetTo(const BRect& value); + inline void SetTo(float left, float top, float right, + float bottom); inline void SetTo(const void* value); inline void SetTo(const char* value, uint32 flags = 0); @@ -92,6 +100,7 @@ public: double ToDouble() const; void* ToPointer() const; const char* ToString() const; + BRect ToRect() const; BReferenceable* ToReferenceable() const; void SwapEndianess(); @@ -123,6 +132,8 @@ private: void _SetTo(float value); void _SetTo(double value); void _SetTo(const void* value); + void _SetTo(float left, float top, float right, + float bottom); bool _SetTo(const char* value, uint32 flags); void _SetTo(BReferenceable* value, type_code type); @@ -150,6 +161,11 @@ private: BReferenceable* fReferenceable; uint8 fBytes[8]; }; + + float fLeft; + float fTop; + float fRight; + float fBottom; }; @@ -227,6 +243,18 @@ BVariant::BVariant(double value) } +BVariant::BVariant(const BRect& value) +{ + _SetTo(value); +} + + +BVariant::BVariant(float left, float top, float right, float bottom) +{ + _SetTo(left, top, right, bottom); +} + + BVariant::BVariant(const void* value) { _SetTo(value); @@ -363,6 +391,22 @@ BVariant::SetTo(double value) } +void +BVariant::SetTo(const BRect& value) +{ + Unset(); + _SetTo(value.left, value.top, value.right, value.bottom); +} + + +void +BVariant::SetTo(float left, float top, float right, float bottom) +{ + Unset(); + _SetTo(left, top, right, bottom); +} + + void BVariant::SetTo(const void* value) { diff --git a/src/kits/shared/Variant.cpp b/src/kits/shared/Variant.cpp index 352a8ded9b..d81df4b269 100644 --- a/src/kits/shared/Variant.cpp +++ b/src/kits/shared/Variant.cpp @@ -1,5 +1,6 @@ /* * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. + * Copyright 2011, Rene Gollent, rene@gollent.com. * Distributed under the terms of the MIT License. */ @@ -96,6 +97,12 @@ BVariant::SetToTypedData(const void* data, type_code type) break; case B_STRING_TYPE: return _SetTo((const char*)data, 0) ? B_OK : B_NO_MEMORY; + case B_RECT_TYPE: + { + BRect *rect = (BRect *)data; + _SetTo(rect->left, rect->top, rect->right, rect->bottom); + break; + } default: return B_BAD_TYPE; } @@ -169,6 +176,9 @@ BVariant::operator==(const BVariant& other) const if (fString == NULL || other.fString == NULL) return fString == other.fString; return strcmp(fString, other.fString) == 0; + case B_RECT_TYPE: + return BRect(fLeft, fTop, fRight, fBottom) == BRect( + other.fLeft, other.fTop, other.fRight, other.fBottom); default: return false; } @@ -303,6 +313,13 @@ BVariant::ToDouble() const } +BRect +BVariant::ToRect() const +{ + return BRect(fLeft, fTop, fRight, fBottom); +} + + void* BVariant::ToPointer() const { @@ -387,6 +404,9 @@ BVariant::AddToMessage(BMessage& message, const char* fieldName) const return message.AddPointer(fieldName, fPointer); case B_STRING_TYPE: return message.AddString(fieldName, fString); + case B_RECT_TYPE: + return message.AddRect(fieldName, BRect(fLeft, fTop, fRight, + fBottom)); default: return B_UNSUPPORTED; } @@ -443,6 +463,8 @@ BVariant::SizeOfType(type_code type) return sizeof(double); case B_POINTER_TYPE: return sizeof(void*); + case B_RECT_TYPE: + return sizeof(BRect); default: return 0; } @@ -606,6 +628,18 @@ BVariant::_SetTo(double value) } +void +BVariant::_SetTo(float left, float top, float right, float bottom) +{ + fType = B_RECT_TYPE; + fFlags = 0; + fLeft = left; + fTop = top; + fRight = right; + fBottom = bottom; +} + + void BVariant::_SetTo(const void* value) {