* GetPreferredSize() no longer crashes when given a NULL parameter (as the

other interface views already do).
* Minor cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25019 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2008-04-18 12:01:07 +00:00
parent 00d5cfaa7e
commit 28d5567e28
+88 -60
View File
@@ -66,22 +66,28 @@ using std::nothrow;
static property_info sViewPropInfo[] = {
{ "Frame", { B_GET_PROPERTY, 0 },
{ B_DIRECT_SPECIFIER, 0 }, "Returns the view's frame rectangle.", 0, { B_RECT_TYPE }
{ B_DIRECT_SPECIFIER, 0 }, "Returns the view's frame rectangle.", 0,
{ B_RECT_TYPE }
},
{ "Frame", { B_SET_PROPERTY, 0 },
{ B_DIRECT_SPECIFIER, 0 }, "Sets the view's frame rectangle.", 0, { B_RECT_TYPE }
{ B_DIRECT_SPECIFIER, 0 }, "Sets the view's frame rectangle.", 0,
{ B_RECT_TYPE }
},
{ "Hidden", { B_GET_PROPERTY, 0 },
{ B_DIRECT_SPECIFIER, 0 }, "Returns true if the view is hidden; false otherwise.", 0, { B_BOOL_TYPE }
{ B_DIRECT_SPECIFIER, 0 }, "Returns wether or not the view is hidden.",
0, { B_BOOL_TYPE }
},
{ "Hidden", { B_SET_PROPERTY, 0 },
{ B_DIRECT_SPECIFIER, 0 }, "Hides or shows the view.", 0, { B_BOOL_TYPE }
{ B_DIRECT_SPECIFIER, 0 }, "Hides or shows the view.", 0,
{ B_BOOL_TYPE }
},
{ "Shelf", { 0 },
{ B_DIRECT_SPECIFIER, 0 }, "Directs the scripting message to the shelf.", 0
{ B_DIRECT_SPECIFIER, 0 }, "Directs the scripting message to the "
"shelf.", 0
},
{ "View", { B_COUNT_PROPERTIES, 0 },
{ B_DIRECT_SPECIFIER, 0 }, "Returns the number of of child views.", 0, { B_INT32_TYPE }
{ B_DIRECT_SPECIFIER, 0 }, "Returns the number of of child views.", 0,
{ B_INT32_TYPE }
},
{ "View", { 0 },
{ B_INDEX_SPECIFIER, B_REVERSE_INDEX_SPECIFIER, B_NAME_SPECIFIER, 0 },
@@ -1002,7 +1008,8 @@ BView::SetOrigin(float x, float y)
fState->valid_flags |= B_VIEW_ORIGIN_BIT;
}
// our local coord system origin has changed, so when archiving we'll add this too
// our local coord system origin has changed, so when archiving we'll add
// this too
fState->archiving_flags |= B_VIEW_ORIGIN_BIT;
}
@@ -1181,8 +1188,10 @@ BView::GetPreferredSize(float* _width, float* _height)
{
STRACE(("\tHOOK: BView(%s)::GetPreferredSize()\n", Name()));
*_width = fBounds.Width();
*_height = fBounds.Height();
if (_width != NULL)
*_width = fBounds.Width();
if (_height != NULL)
*_height = fBounds.Height();
}
@@ -1377,7 +1386,8 @@ BView::DragMessage(BMessage *message, BBitmap *image,
BMessage *msg = fOwner->CurrentMessage();
uint32 buttons;
if (msg == NULL || msg->FindInt32("buttons", (int32 *)&buttons) != B_OK) {
if (msg == NULL
|| msg->FindInt32("buttons", (int32 *)&buttons) != B_OK) {
BPoint point;
GetMouse(&point, &buttons, false);
}
@@ -1410,7 +1420,8 @@ BView::DragMessage(BMessage *message, BBitmap *image,
delete [] buffer;
} else {
fprintf(stderr, "BView::DragMessage() - no memory to flatten drag message\n");
fprintf(stderr, "BView::DragMessage() - no memory to flatten drag "
"message\n");
}
delete image;
@@ -1589,7 +1600,7 @@ BView::SetEventMask(uint32 mask, uint32 options)
if (fEventMask == mask && fEventOptions == options)
return B_OK;
fEventMask = mask | (fEventMask & 0xFFFF0000);
fEventMask = mask | (fEventMask & 0xffff0000);
fEventOptions = options;
fState->archiving_flags |= B_VIEW_EVENT_MASK_BIT;
@@ -1860,8 +1871,7 @@ BView::GetBlendingMode(source_alpha *_sourceAlpha,
fOwner->fLink->StartMessage(AS_VIEW_GET_BLENDING_MODE);
int32 code;
if (fOwner->fLink->FlushWithReply(code) == B_OK
&& code == B_OK) {
if (fOwner->fLink->FlushWithReply(code) == B_OK && code == B_OK) {
int8 alphaSourceMode, alphaFunctionMode;
fOwner->fLink->Read<int8>(&alphaSourceMode);
fOwner->fLink->Read<int8>(&alphaFunctionMode);
@@ -2117,7 +2127,8 @@ BView::ViewColor() const
void
BView::ForceFontAliasing(bool enable)
{
if (fState->IsValid(B_VIEW_FONT_ALIASING_BIT) && enable == fState->font_aliasing)
if (fState->IsValid(B_VIEW_FONT_ALIASING_BIT)
&& enable == fState->font_aliasing)
return;
if (fOwner) {
@@ -2301,7 +2312,6 @@ BView::ConstrainClippingRegion(BRegion* region)
// #pragma mark - Drawing Functions
//---------------------------------------------------------------------------
void
@@ -2466,10 +2476,10 @@ BView::DrawString(const char *string, int32 length, BPoint location,
void
BView::StrokeEllipse(BPoint center, float xRadius, float yRadius,
pattern p)
::pattern pattern)
{
StrokeEllipse(BRect(center.x - xRadius, center.y - yRadius, center.x + xRadius,
center.y + yRadius), p);
StrokeEllipse(BRect(center.x - xRadius, center.y - yRadius,
center.x + xRadius, center.y + yRadius), pattern);
}
@@ -2515,11 +2525,11 @@ BView::FillEllipse(BRect rect, ::pattern pattern)
void
BView::StrokeArc(BPoint center, float xRadius, float yRadius,
float startAngle, float arcAngle, pattern p)
BView::StrokeArc(BPoint center, float xRadius, float yRadius, float startAngle,
float arcAngle, ::pattern pattern)
{
StrokeArc(BRect(center.x - xRadius, center.y - yRadius, center.x + xRadius,
center.y + yRadius), startAngle, arcAngle, p);
center.y + yRadius), startAngle, arcAngle, pattern);
}
@@ -2543,8 +2553,8 @@ BView::StrokeArc(BRect rect, float startAngle, float arcAngle,
void
BView::FillArc(BPoint center,float xRadius, float yRadius,
float startAngle, float arcAngle, ::pattern pattern)
BView::FillArc(BPoint center,float xRadius, float yRadius, float startAngle,
float arcAngle, ::pattern pattern)
{
FillArc(BRect(center.x - xRadius, center.y - yRadius, center.x + xRadius,
center.y + yRadius), startAngle, arcAngle, pattern);
@@ -2609,21 +2619,24 @@ BView::FillBezier(BPoint *controlPoints, ::pattern pattern)
void
BView::StrokePolygon(const BPolygon *polygon, bool closed, pattern p)
BView::StrokePolygon(const BPolygon *polygon, bool closed, ::pattern pattern)
{
if (!polygon)
return;
StrokePolygon(polygon->fPoints, polygon->fCount, polygon->Frame(), closed, p);
StrokePolygon(polygon->fPoints, polygon->fCount, polygon->Frame(), closed,
pattern);
}
void
BView::StrokePolygon(const BPoint *ptArray, int32 numPoints, bool closed, pattern p)
BView::StrokePolygon(const BPoint* pointArray, int32 numPoints, bool closed,
::pattern pattern)
{
BPolygon polygon(ptArray, numPoints);
BPolygon polygon(pointArray, numPoints);
StrokePolygon(polygon.fPoints, polygon.fCount, polygon.Frame(), closed, p);
StrokePolygon(polygon.fPoints, polygon.fCount, polygon.Frame(), closed,
pattern);
}
@@ -2643,8 +2656,8 @@ BView::StrokePolygon(const BPoint *ptArray, int32 numPoints, BRect bounds,
polygon.MapTo(polygon.Frame(), bounds);
if (fOwner->fLink->StartMessage(AS_STROKE_POLYGON,
polygon.fCount * sizeof(BPoint) + sizeof(BRect) + sizeof(bool) + sizeof(int32))
== B_OK) {
polygon.fCount * sizeof(BPoint) + sizeof(BRect) + sizeof(bool)
+ sizeof(int32)) == B_OK) {
fOwner->fLink->Attach<BRect>(polygon.Frame());
fOwner->fLink->Attach<bool>(closed);
fOwner->fLink->Attach<int32>(polygon.fCount);
@@ -2670,10 +2683,12 @@ BView::FillPolygon(const BPolygon *polygon, ::pattern pattern)
_UpdatePattern(pattern);
if (fOwner->fLink->StartMessage(AS_FILL_POLYGON,
polygon->fCount * sizeof(BPoint) + sizeof(BRect) + sizeof(int32)) == B_OK) {
polygon->fCount * sizeof(BPoint) + sizeof(BRect) + sizeof(int32))
== B_OK) {
fOwner->fLink->Attach<BRect>(polygon->Frame());
fOwner->fLink->Attach<int32>(polygon->fCount);
fOwner->fLink->Attach(polygon->fPoints, polygon->fCount * sizeof(BPoint));
fOwner->fLink->Attach(polygon->fPoints,
polygon->fCount * sizeof(BPoint));
_FlushIfNotInTransaction();
} else {
@@ -2804,8 +2819,8 @@ BView::FillRegion(BRegion *region, ::pattern pattern)
void
BView::StrokeTriangle(BPoint pt1, BPoint pt2, BPoint pt3,
BRect bounds, ::pattern pattern)
BView::StrokeTriangle(BPoint pt1, BPoint pt2, BPoint pt3, BRect bounds,
::pattern pattern)
{
if (fOwner == NULL)
return;
@@ -2962,7 +2977,8 @@ BView::StrokeShape(BShape *shape, ::pattern pattern)
_CheckLockAndSwitchCurrent();
_UpdatePattern(pattern);
if ((sd->opCount * sizeof(uint32)) + (sd->ptCount * sizeof(BPoint)) < MAX_ATTACHMENT_SIZE) {
if ((sd->opCount * sizeof(uint32)) + (sd->ptCount * sizeof(BPoint))
< MAX_ATTACHMENT_SIZE) {
fOwner->fLink->StartMessage(AS_STROKE_SHAPE);
fOwner->fLink->Attach<BRect>(shape->Bounds());
fOwner->fLink->Attach<int32>(sd->opCount);
@@ -2990,7 +3006,8 @@ BView::FillShape(BShape *shape, ::pattern pattern)
_CheckLockAndSwitchCurrent();
_UpdatePattern(pattern);
if ((sd->opCount * sizeof(uint32)) + (sd->ptCount * sizeof(BPoint)) < MAX_ATTACHMENT_SIZE) {
if ((sd->opCount * sizeof(uint32)) + (sd->ptCount * sizeof(BPoint))
< MAX_ATTACHMENT_SIZE) {
fOwner->fLink->StartMessage(AS_FILL_SHAPE);
fOwner->fLink->Attach<BRect>(shape->Bounds());
fOwner->fLink->Attach<int32>(sd->opCount);
@@ -3708,7 +3725,8 @@ BView::ResolveSpecifier(BMessage *msg, int32 index, BMessage *specifier,
replyMsg.AddString("message", "This window doesn't have a shelf");
break;
case 6: {
case 6:
{
if (!fFirstChild) {
err = B_NAME_NOT_FOUND;
replyMsg.AddString("message", "This window doesn't have children.");
@@ -3716,21 +3734,24 @@ BView::ResolveSpecifier(BMessage *msg, int32 index, BMessage *specifier,
}
BView *child = NULL;
switch (what) {
case B_INDEX_SPECIFIER: {
case B_INDEX_SPECIFIER:
{
int32 index;
err = specifier->FindInt32("index", &index);
if (err == B_OK)
child = ChildAt(index);
break;
}
case B_REVERSE_INDEX_SPECIFIER: {
case B_REVERSE_INDEX_SPECIFIER:
{
int32 rindex;
err = specifier->FindInt32("index", &rindex);
if (err == B_OK)
child = ChildAt(CountChildren() - rindex);
break;
}
case B_NAME_SPECIFIER: {
case B_NAME_SPECIFIER:
{
const char *name;
err = specifier->FindString("name", &name);
if (err == B_OK)
@@ -3746,11 +3767,15 @@ BView::ResolveSpecifier(BMessage *msg, int32 index, BMessage *specifier,
if (err == B_OK)
err = B_BAD_INDEX;
replyMsg.AddString("message", "Cannot find view at/with specified index/name.");
replyMsg.AddString("message",
"Cannot find view at/with specified index/name.");
break;
}
default:
return BHandler::ResolveSpecifier(msg, index, specifier, what, property);
return BHandler::ResolveSpecifier(msg, index, specifier, what,
property);
}
if (err < B_OK) {
@@ -3769,7 +3794,7 @@ BView::ResolveSpecifier(BMessage *msg, int32 index, BMessage *specifier,
void
BView::MessageReceived(BMessage *msg)
BView::MessageReceived(BMessage* msg)
{
if (!msg->HasSpecifiers()) {
switch (msg->what) {
@@ -3850,7 +3875,8 @@ BView::MessageReceived(BMessage *msg)
case 0:
err = replyMsg.AddRect("result", Frame());
break;
case 1: {
case 1:
{
BRect newFrame;
err = msg->FindRect("data", &newFrame);
if (err == B_OK) {
@@ -3862,7 +3888,8 @@ BView::MessageReceived(BMessage *msg)
case 2:
err = replyMsg.AddBool( "result", IsHidden());
break;
case 3: {
case 3:
{
bool newHiddenState;
err = msg->FindBool("data", &newHiddenState);
if (err == B_OK) {
@@ -4190,7 +4217,8 @@ BView::_Layout(bool force, BLayoutContext* context)
void
BView::_InitData(BRect frame, const char *name, uint32 resizingMode, uint32 flags)
BView::_InitData(BRect frame, const char *name, uint32 resizingMode,
uint32 flags)
{
// Info: The name of the view is set by BHandler constructor
@@ -4430,7 +4458,8 @@ BView::_CreateSelf()
// we create all its children, too
for (BView *child = fFirstChild; child != NULL; child = child->fNextSibling) {
for (BView *child = fFirstChild; child != NULL;
child = child->fNextSibling) {
child->_CreateSelf();
}
@@ -4439,8 +4468,7 @@ BView::_CreateSelf()
}
/*!
Sets the new view position.
/*! Sets the new view position.
It doesn't contact the server, though - the only case where this
is called outside of MoveTo() is as reaction of moving a view
in the server (a.k.a. B_WINDOW_RESIZED).
@@ -4462,8 +4490,7 @@ BView::_MoveTo(int32 x, int32 y)
}
/*!
Computes the actual new frame size and recalculates the size of
/*! Computes the actual new frame size and recalculates the size of
the children as well.
It doesn't contact the server, though - the only case where this
is called outside of ResizeBy() is as reaction of resizing a view
@@ -4502,9 +4529,7 @@ BView::_ResizeBy(int32 deltaWidth, int32 deltaHeight)
}
/*!
Relayouts the view according to its resizing mode.
*/
/*! Relayouts the view according to its resizing mode. */
void
BView::_ParentResizedBy(int32 x, int32 y)
{
@@ -4554,7 +4579,8 @@ BView::_Activate(bool active)
{
WindowActivated(active);
for (BView *child = fFirstChild; child != NULL; child = child->fNextSibling) {
for (BView *child = fFirstChild; child != NULL;
child = child->fNextSibling) {
child->_Activate(active);
}
}
@@ -4580,7 +4606,8 @@ BView::_Attach()
Invalidate();
}
for (BView* child = fFirstChild; child != NULL; child = child->fNextSibling) {
for (BView* child = fFirstChild; child != NULL;
child = child->fNextSibling) {
// we need to check for fAttached as new views could have been
// added in AttachedToWindow() - and those are already attached
if (!child->fAttached)
@@ -4597,7 +4624,8 @@ BView::_Detach()
DetachedFromWindow();
fAttached = false;
for (BView* child = fFirstChild; child != NULL; child = child->fNextSibling) {
for (BView* child = fFirstChild; child != NULL;
child = child->fNextSibling) {
child->_Detach();
}
@@ -4772,8 +4800,8 @@ BView::_SetShelf(BShelf *shelf)
status_t
BView::_SetViewBitmap(const BBitmap* bitmap, BRect srcRect,
BRect dstRect, uint32 followFlags, uint32 options)
BView::_SetViewBitmap(const BBitmap* bitmap, BRect srcRect, BRect dstRect,
uint32 followFlags, uint32 options)
{
if (!_CheckOwnerLockAndSwitchCurrent())
return B_ERROR;