Author: anevilyak Date: 2011-11-01 21:57:31 +0100 (Tue, 01 Nov 2011) New Revision: 43080 Changeset: https://dev.haiku-os.org/changeset/43080 Modified: haiku/trunk/headers/private/shared/Variant.h haiku/trunk/src/kits/shared/Variant.cpp Log: Extend BVariant to support storing BRects as well. Modified: haiku/trunk/headers/private/shared/Variant.h =================================================================== --- haiku/trunk/headers/private/shared/Variant.h 2011-11-01 20:35:49 UTC (rev 43079) +++ haiku/trunk/headers/private/shared/Variant.h 2011-11-01 20:57:31 UTC (rev 43080) @@ -1,11 +1,13 @@ /* * Copyright 2009, Ingo Weinhold, ingo_weinhold@xxxxxxx + * Copyright 2011, Rene Gollent, rene@xxxxxxxxxxxx * Distributed under the terms of the MIT License. */ #ifndef _VARIANT_H #define _VARIANT_H +#include <Rect.h> #include <SupportDefs.h> #include <TypeConstants.h> @@ -36,6 +38,9 @@ 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 @@ 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 @@ double ToDouble() const; void* ToPointer() const; const char* ToString() const; + BRect ToRect() const; BReferenceable* ToReferenceable() const; void SwapEndianess(); @@ -123,6 +132,8 @@ 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 @@ BReferenceable* fReferenceable; uint8 fBytes[8]; }; + + float fLeft; + float fTop; + float fRight; + float fBottom; }; @@ -227,6 +243,18 @@ } +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); @@ -364,6 +392,22 @@ 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) { Unset(); Modified: haiku/trunk/src/kits/shared/Variant.cpp =================================================================== --- haiku/trunk/src/kits/shared/Variant.cpp 2011-11-01 20:35:49 UTC (rev 43079) +++ haiku/trunk/src/kits/shared/Variant.cpp 2011-11-01 20:57:31 UTC (rev 43080) @@ -1,5 +1,6 @@ /* * Copyright 2009, Ingo Weinhold, ingo_weinhold@xxxxxxx + * Copyright 2011, Rene Gollent, rene@xxxxxxxxxxxx * Distributed under the terms of the MIT License. */ @@ -96,6 +97,12 @@ 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 @@ 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 @@ } +BRect +BVariant::ToRect() const +{ + return BRect(fLeft, fTop, fRight, fBottom); +} + + void* BVariant::ToPointer() const { @@ -387,6 +404,9 @@ 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 @@ return sizeof(double); case B_POINTER_TYPE: return sizeof(void*); + case B_RECT_TYPE: + return sizeof(BRect); default: return 0; } @@ -607,6 +629,18 @@ 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) { fType = B_POINTER_TYPE;