Put the code to Extract a replicant into its own function.

BShelf::_AddReplicant() is finally getting acceptable.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23182 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stefano Ceccherini 2007-12-28 11:07:28 +00:00
parent 898edb5ba7
commit d73c4e9fb1
2 changed files with 64 additions and 55 deletions

View File

@ -101,6 +101,8 @@ class BShelf : public BHandler {
status_t _DeleteReplicant(BPrivate::replicant_data* replicant);
status_t _AddReplicant(BMessage* data,
BPoint* location, uint32 uniqueID);
BView *_GetReplicant(BMessage *data, BView *view, const BPoint &point,
BDragger *&dragger, BDragger::relation &relation);
_BZombieReplicantView_ *_CreateZombie(BMessage *data, BDragger *&dragger);
status_t _GetProperty(BMessage* message, BMessage* reply);

View File

@ -1142,11 +1142,6 @@ BShelf::_AddReplicant(BMessage *data, BPoint *location, uint32 uniqueID)
}
}
}
BDragger* dragger = NULL;
BView* replicant = NULL;
BDragger::relation relation = BDragger::TARGET_UNKNOWN;
_BZombieReplicantView_* zombie = NULL;
// Instantiate the object, if this fails we have a zombie
image_id image;
@ -1157,58 +1152,16 @@ BShelf::_AddReplicant(BMessage *data, BPoint *location, uint32 uniqueID)
return send_reply(data, B_ERROR, uniqueID);
}
BDragger* dragger = NULL;
BView* replicant = NULL;
BDragger::relation relation = BDragger::TARGET_UNKNOWN;
_BZombieReplicantView_* zombie = NULL;
if (view != NULL) {
BPoint point;
if (location)
point = *location;
else
point = view->Frame().LeftTop();
const BPoint point = location ? *location : view->Frame().LeftTop();
replicant = _GetReplicant(data, view, point, dragger, relation);
if (replicant == NULL)
send_reply(data, B_ERROR, uniqueID);
// TODO: test me -- there seems to be lots of bugs parked here!
_GetReplicantData(data, view, replicant, dragger, relation);
if (dragger != NULL)
dragger->_SetShelf(this);
BRect frame;
if (relation == BDragger::TARGET_IS_CHILD)
frame = dragger->Frame().OffsetToCopy(point);
else {
frame = replicant->Frame().OffsetToCopy(point);
fContainerView->AddChild(replicant);
}
if (!CanAcceptReplicantView(frame, replicant, data)) {
// the view has not been accepted
if (relation == BDragger::TARGET_IS_PARENT
|| relation == BDragger::TARGET_IS_SIBLING) {
replicant->RemoveSelf();
delete replicant;
}
if (relation == BDragger::TARGET_IS_CHILD
|| relation == BDragger::TARGET_IS_SIBLING) {
dragger->RemoveSelf();
delete dragger;
}
return send_reply(data, B_ERROR, uniqueID);
}
BPoint adjust = AdjustReplicantBy(frame, data);
// TODO: that's probably not correct for all relations (or any?)
// At least, commenting this line fixes a bug in BSnow
view->MoveTo(point + adjust);
// if it's a sibling or a child, we need to add the dragger
if (relation == BDragger::TARGET_IS_SIBLING
|| relation == BDragger::TARGET_IS_CHILD)
fContainerView->AddChild(dragger);
replicant->AddFilter(new ReplicantViewFilter(this, replicant));
} else if (fDisplayZombies && fAllowZombies)
zombie = _CreateZombie(data, dragger);
@ -1233,6 +1186,60 @@ BShelf::_AddReplicant(BMessage *data, BPoint *location, uint32 uniqueID)
}
BView *
BShelf::_GetReplicant(BMessage *data, BView *view, const BPoint &point,
BDragger *&dragger, BDragger::relation &relation)
{
// TODO: test me -- there seems to be lots of bugs parked here!
BView *replicant = NULL;
_GetReplicantData(data, view, replicant, dragger, relation);
if (dragger != NULL)
dragger->_SetShelf(this);
BRect frame;
if (relation == BDragger::TARGET_IS_CHILD)
frame = dragger->Frame().OffsetToCopy(point);
else {
frame = replicant->Frame().OffsetToCopy(point);
fContainerView->AddChild(replicant);
}
if (!CanAcceptReplicantView(frame, replicant, data)) {
// the view has not been accepted
if (relation == BDragger::TARGET_IS_PARENT
|| relation == BDragger::TARGET_IS_SIBLING) {
replicant->RemoveSelf();
delete replicant;
}
if (relation == BDragger::TARGET_IS_CHILD
|| relation == BDragger::TARGET_IS_SIBLING) {
dragger->RemoveSelf();
delete dragger;
}
return NULL;
}
BPoint adjust = AdjustReplicantBy(frame, data);
// TODO: that's probably not correct for all relations (or any?)
// At least, commenting this line fixes a bug in BSnow
view->MoveTo(point + adjust);
// if it's a sibling or a child, we need to add the dragger
if (relation == BDragger::TARGET_IS_SIBLING
|| relation == BDragger::TARGET_IS_CHILD)
fContainerView->AddChild(dragger);
replicant->AddFilter(new ReplicantViewFilter(this, replicant));
return replicant;
}
_BZombieReplicantView_ *
BShelf::_CreateZombie(BMessage *data, BDragger *&dragger)
{