Patch by Alex Wilson: Added convenience methods for storing BAlignment and BSize
in BMessages. Also added type codes for them in TypeConstants.h. Closes ticket #6302. Thanks! git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37511 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
f47eacc36c
commit
b1008df2c2
@ -18,6 +18,7 @@
|
||||
#include <AppDefs.h> /* For convenience */
|
||||
#include <TypeConstants.h> /* For convenience */
|
||||
|
||||
class BAlignment;
|
||||
class BBlockCache;
|
||||
class BMessenger;
|
||||
class BHandler;
|
||||
@ -114,8 +115,11 @@ class BMessage {
|
||||
status_t PopSpecifier();
|
||||
|
||||
// Adding data
|
||||
status_t AddAlignment(const char* name,
|
||||
const BAlignment& alignment);
|
||||
status_t AddRect(const char *name, BRect aRect);
|
||||
status_t AddPoint(const char *name, BPoint aPoint);
|
||||
status_t AddSize(const char* name, BSize aSize);
|
||||
status_t AddString(const char *name, const char *aString);
|
||||
status_t AddString(const char *name, const BString &aString);
|
||||
status_t AddInt8(const char *name, int8 value);
|
||||
@ -145,10 +149,20 @@ class BMessage {
|
||||
status_t MakeEmpty();
|
||||
|
||||
// Finding data
|
||||
status_t FindAlignment(const char* name,
|
||||
BAlignment* alignment) const;
|
||||
status_t FindAlignment(const char* name, int32 index,
|
||||
BAlignment* alignment) const;
|
||||
|
||||
status_t FindRect(const char *name, BRect *rect) const;
|
||||
status_t FindRect(const char *name, int32 index, BRect *rect) const;
|
||||
status_t FindPoint(const char *name, BPoint *point) const;
|
||||
status_t FindPoint(const char *name, int32 index, BPoint *point) const;
|
||||
|
||||
status_t FindSize(const char *name, BSize* size) const;
|
||||
status_t FindSize(const char *name,
|
||||
int32 index, BSize* size) const;
|
||||
|
||||
status_t FindString(const char *name, const char **string) const;
|
||||
status_t FindString(const char *name, int32 index, const char **string) const;
|
||||
status_t FindString(const char *name, BString *string) const;
|
||||
@ -191,10 +205,19 @@ class BMessage {
|
||||
const void **data, ssize_t *numBytes) const;
|
||||
|
||||
// Replacing data
|
||||
status_t ReplaceAlignment(const char* name,
|
||||
const BAlignment& alignment);
|
||||
status_t ReplaceAlignment(const char* name, int32 index,
|
||||
const BAlignment& alignment);
|
||||
|
||||
status_t ReplaceRect(const char *name, BRect aRect);
|
||||
status_t ReplaceRect(const char *name, int32 index, BRect aRect);
|
||||
|
||||
status_t ReplacePoint(const char *name, BPoint aPoint);
|
||||
status_t ReplacePoint(const char *name, int32 index, BPoint aPoint);
|
||||
status_t ReplaceSize(const char* name, BSize aSize);
|
||||
status_t ReplaceSize(const char* name, int32 index, BSize aSize);
|
||||
|
||||
status_t ReplaceString(const char *name, const char *aString);
|
||||
status_t ReplaceString(const char *name, int32 index, const char *aString);
|
||||
status_t ReplaceString(const char *name, const BString &aString);
|
||||
@ -245,8 +268,10 @@ class BMessage {
|
||||
void operator delete(void *pointer, size_t size);
|
||||
|
||||
// Private, reserved, or obsolete
|
||||
bool HasAlignment(const char*, int32 n = 0) const;
|
||||
bool HasRect(const char *, int32 n = 0) const;
|
||||
bool HasPoint(const char *, int32 n = 0) const;
|
||||
bool HasSize(const char*, int32 n = 0) const;
|
||||
bool HasString(const char *, int32 n = 0) const;
|
||||
bool HasInt8(const char *, int32 n = 0) const;
|
||||
bool HasUInt8(const char *, int32 n = 0) const;
|
||||
|
@ -14,6 +14,7 @@
|
||||
|
||||
enum {
|
||||
B_AFFINE_TRANSFORM_TYPE = 'AMTX',
|
||||
B_ALIGNMENT_TYPE = 'ALGN',
|
||||
B_ANY_TYPE = 'ANYT',
|
||||
B_ATOM_TYPE = 'ATOM',
|
||||
B_ATOMREF_TYPE = 'ATMR',
|
||||
@ -47,6 +48,7 @@ enum {
|
||||
B_REF_TYPE = 'RREF',
|
||||
B_RGB_32_BIT_TYPE = 'RGBB',
|
||||
B_RGB_COLOR_TYPE = 'RGBC',
|
||||
B_SIZE_TYPE = 'SIZE',
|
||||
B_SIZE_T_TYPE = 'SIZT',
|
||||
B_SSIZE_T_TYPE = 'SSZT',
|
||||
B_STRING_TYPE = 'CSTR',
|
||||
|
@ -17,6 +17,7 @@
|
||||
#include <TokenSpace.h>
|
||||
#include <util/KMessage.h>
|
||||
|
||||
#include <Alignment.h>
|
||||
#include <Application.h>
|
||||
#include <AppMisc.h>
|
||||
#include <BlockCache.h>
|
||||
@ -2382,6 +2383,7 @@ BMessage::Has##typeName(const char *name, int32 index) const \
|
||||
|
||||
DEFINE_FUNCTIONS(BPoint, Point, B_POINT_TYPE);
|
||||
DEFINE_FUNCTIONS(BRect, Rect, B_RECT_TYPE);
|
||||
DEFINE_FUNCTIONS(BSize, Size, B_SIZE_TYPE);
|
||||
DEFINE_FUNCTIONS(int8, Int8, B_INT8_TYPE);
|
||||
DEFINE_FUNCTIONS(uint8, UInt8, B_UINT8_TYPE);
|
||||
DEFINE_FUNCTIONS(int16, Int16, B_INT16_TYPE);
|
||||
@ -2403,6 +2405,7 @@ BMessage::Has##typeName(const char *name, int32 index) const \
|
||||
return HasData(name, typeCode, index); \
|
||||
}
|
||||
|
||||
DEFINE_HAS_FUNCTION(Alignment, B_ALIGNMENT_TYPE);
|
||||
DEFINE_HAS_FUNCTION(String, B_STRING_TYPE);
|
||||
DEFINE_HAS_FUNCTION(Pointer, B_POINTER_TYPE);
|
||||
DEFINE_HAS_FUNCTION(Messenger, B_MESSENGER_TYPE);
|
||||
@ -2433,6 +2436,14 @@ DEFINE_LAZY_FIND_FUNCTION(double, Double, 0);
|
||||
|
||||
#undef DEFINE_LAZY_FIND_FUNCTION
|
||||
|
||||
status_t
|
||||
BMessage::AddAlignment(const char* name, const BAlignment& alignment)
|
||||
{
|
||||
int32 data[2] = {alignment.horizontal, alignment.vertical};
|
||||
return AddData(name, B_ALIGNMENT_TYPE, data, sizeof(data));
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BMessage::AddString(const char *name, const char *string)
|
||||
{
|
||||
@ -2538,6 +2549,38 @@ BMessage::AddFlat(const char *name, BFlattenable *object, int32 count)
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BMessage::FindAlignment(const char* name, BAlignment* alignment) const
|
||||
{
|
||||
return FindAlignment(name, 0, alignment);
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BMessage::FindAlignment(const char* name, int32 index,
|
||||
BAlignment* alignment) const
|
||||
{
|
||||
if (!alignment)
|
||||
return B_BAD_VALUE;
|
||||
|
||||
int32* data;
|
||||
ssize_t bytes;
|
||||
|
||||
status_t err = FindData(name, B_ALIGNMENT_TYPE, index,
|
||||
(const void**)&data, &bytes);
|
||||
|
||||
if (err == B_OK) {
|
||||
if (bytes != sizeof(int32[2]))
|
||||
return B_ERROR;
|
||||
|
||||
alignment->horizontal = (enum alignment)(*data);
|
||||
alignment->vertical = (vertical_alignment)*(data + 1);
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BMessage::FindString(const char *name, const char **string) const
|
||||
{
|
||||
@ -2718,6 +2761,23 @@ BMessage::FindData(const char *name, type_code type, const void **data,
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BMessage::ReplaceAlignment(const char* name, const BAlignment& alignment)
|
||||
{
|
||||
int32 data[2] = {alignment.horizontal, alignment.vertical};
|
||||
return ReplaceData(name, B_ALIGNMENT_TYPE, 0, data, sizeof(data));
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BMessage::ReplaceAlignment(const char* name, int32 index,
|
||||
const BAlignment& alignment)
|
||||
{
|
||||
int32 data[2] = {alignment.horizontal, alignment.vertical};
|
||||
return ReplaceData(name, B_ALIGNMENT_TYPE, index, data, sizeof(data));
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BMessage::ReplaceString(const char *name, const char *string)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user