diff --git a/headers/os/interface/Shelf.h b/headers/os/interface/Shelf.h index ac0abbc2fe..7918e7cffb 100644 --- a/headers/os/interface/Shelf.h +++ b/headers/os/interface/Shelf.h @@ -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); diff --git a/src/kits/interface/Shelf.cpp b/src/kits/interface/Shelf.cpp index 08fc4b2c39..a57c3f7f12 100644 --- a/src/kits/interface/Shelf.cpp +++ b/src/kits/interface/Shelf.cpp @@ -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) {