Made constants static, coding style cleanup.
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2001-2009, Haiku.
|
* Copyright 2001-2012, Haiku.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
@@ -8,6 +8,7 @@
|
|||||||
* Alexandre Deckner ([email protected])
|
* Alexandre Deckner ([email protected])
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
//! BDragger represents a replicant "handle".
|
//! BDragger represents a replicant "handle".
|
||||||
|
|
||||||
|
|
||||||
@@ -45,10 +46,10 @@ using BPrivate::gSystemCatalog;
|
|||||||
#define B_TRANSLATE(str) \
|
#define B_TRANSLATE(str) \
|
||||||
gSystemCatalog.GetString(B_TRANSLATE_MARK(str), "Dragger")
|
gSystemCatalog.GetString(B_TRANSLATE_MARK(str), "Dragger")
|
||||||
|
|
||||||
const uint32 kMsgDragStarted = 'Drgs';
|
|
||||||
|
|
||||||
const unsigned char
|
static const uint32 kMsgDragStarted = 'Drgs';
|
||||||
kHandBitmap[] = {
|
|
||||||
|
static const unsigned char kHandBitmap[] = {
|
||||||
255, 255, 0, 0, 0, 255, 255, 255,
|
255, 255, 0, 0, 0, 255, 255, 255,
|
||||||
255, 255, 0, 131, 131, 0, 255, 255,
|
255, 255, 0, 131, 131, 0, 255, 255,
|
||||||
0, 0, 0, 0, 131, 131, 0, 0,
|
0, 0, 0, 0, 131, 131, 0, 0,
|
||||||
@@ -112,8 +113,9 @@ DraggerManager* DraggerManager::sDefaultInstance = NULL;
|
|||||||
} // unnamed namespace
|
} // unnamed namespace
|
||||||
|
|
||||||
|
|
||||||
BDragger::BDragger(BRect bounds, BView *target, uint32 rmask, uint32 flags)
|
BDragger::BDragger(BRect bounds, BView* target, uint32 resizeMask, uint32 flags)
|
||||||
: BView(bounds, "_dragger_", rmask, flags),
|
:
|
||||||
|
BView(bounds, "_dragger_", resizeMask, flags),
|
||||||
fTarget(target),
|
fTarget(target),
|
||||||
fRelation(TARGET_UNKNOWN),
|
fRelation(TARGET_UNKNOWN),
|
||||||
fShelf(NULL),
|
fShelf(NULL),
|
||||||
@@ -127,8 +129,9 @@ BDragger::BDragger(BRect bounds, BView *target, uint32 rmask, uint32 flags)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BDragger::BDragger(BMessage *data)
|
BDragger::BDragger(BMessage* data)
|
||||||
: BView(data),
|
:
|
||||||
|
BView(data),
|
||||||
fTarget(NULL),
|
fTarget(NULL),
|
||||||
fRelation(TARGET_UNKNOWN),
|
fRelation(TARGET_UNKNOWN),
|
||||||
fShelf(NULL),
|
fShelf(NULL),
|
||||||
@@ -138,16 +141,16 @@ BDragger::BDragger(BMessage *data)
|
|||||||
fPopUpIsCustom(false),
|
fPopUpIsCustom(false),
|
||||||
fPopUp(NULL)
|
fPopUp(NULL)
|
||||||
{
|
{
|
||||||
data->FindInt32("_rel", (int32 *)&fRelation);
|
data->FindInt32("_rel", (int32*)&fRelation);
|
||||||
|
|
||||||
_InitData();
|
_InitData();
|
||||||
|
|
||||||
BMessage popupMsg;
|
BMessage popupMsg;
|
||||||
if (data->FindMessage("_popup", &popupMsg) == B_OK) {
|
if (data->FindMessage("_popup", &popupMsg) == B_OK) {
|
||||||
BArchivable *archivable = instantiate_object(&popupMsg);
|
BArchivable* archivable = instantiate_object(&popupMsg);
|
||||||
|
|
||||||
if (archivable) {
|
if (archivable) {
|
||||||
fPopUp = dynamic_cast<BPopUpMenu *>(archivable);
|
fPopUp = dynamic_cast<BPopUpMenu*>(archivable);
|
||||||
fPopUpIsCustom = true;
|
fPopUpIsCustom = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -162,7 +165,7 @@ BDragger::~BDragger()
|
|||||||
|
|
||||||
|
|
||||||
BArchivable *
|
BArchivable *
|
||||||
BDragger::Instantiate(BMessage *data)
|
BDragger::Instantiate(BMessage* data)
|
||||||
{
|
{
|
||||||
if (validate_instantiation(data, "BDragger"))
|
if (validate_instantiation(data, "BDragger"))
|
||||||
return new BDragger(data);
|
return new BDragger(data);
|
||||||
@@ -171,7 +174,7 @@ BDragger::Instantiate(BMessage *data)
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
BDragger::Archive(BMessage *data, bool deep) const
|
BDragger::Archive(BMessage* data, bool deep) const
|
||||||
{
|
{
|
||||||
status_t ret = BView::Archive(data, deep);
|
status_t ret = BView::Archive(data, deep);
|
||||||
if (ret != B_OK)
|
if (ret != B_OK)
|
||||||
@@ -179,15 +182,16 @@ BDragger::Archive(BMessage *data, bool deep) const
|
|||||||
|
|
||||||
BMessage popupMsg;
|
BMessage popupMsg;
|
||||||
|
|
||||||
if (fPopUp && fPopUpIsCustom) {
|
if (fPopUp != NULL && fPopUpIsCustom) {
|
||||||
bool windowLocked = fPopUp->Window()->Lock();
|
bool windowLocked = fPopUp->Window()->Lock();
|
||||||
|
|
||||||
ret = fPopUp->Archive(&popupMsg, deep);
|
ret = fPopUp->Archive(&popupMsg, deep);
|
||||||
|
|
||||||
if (windowLocked)
|
if (windowLocked) {
|
||||||
fPopUp->Window()->Unlock();
|
fPopUp->Window()->Unlock();
|
||||||
// TODO: Investigate, in some (rare) occasions the menu window
|
// TODO: Investigate, in some (rare) occasions the menu window
|
||||||
// has already been unlocked
|
// has already been unlocked
|
||||||
|
}
|
||||||
|
|
||||||
if (ret == B_OK)
|
if (ret == B_OK)
|
||||||
ret = data->AddMessage("_popup", &popupMsg);
|
ret = data->AddMessage("_popup", &popupMsg);
|
||||||
@@ -229,8 +233,8 @@ BDragger::Draw(BRect update)
|
|||||||
{
|
{
|
||||||
BRect bounds(Bounds());
|
BRect bounds(Bounds());
|
||||||
|
|
||||||
if (AreDraggersDrawn() && (!fShelf || fShelf->AllowsDragging())) {
|
if (AreDraggersDrawn() && (fShelf == NULL || fShelf->AllowsDragging())) {
|
||||||
if (Parent() && (Parent()->Flags() & B_DRAW_ON_CHILDREN) == 0) {
|
if (Parent() != NULL && (Parent()->Flags() & B_DRAW_ON_CHILDREN) == 0) {
|
||||||
uint32 flags = Parent()->Flags();
|
uint32 flags = Parent()->Flags();
|
||||||
Parent()->SetFlags(flags | B_DRAW_ON_CHILDREN);
|
Parent()->SetFlags(flags | B_DRAW_ON_CHILDREN);
|
||||||
Parent()->Draw(Frame() & ConvertToParent(update));
|
Parent()->Draw(Frame() & ConvertToParent(update));
|
||||||
@@ -248,7 +252,7 @@ BDragger::Draw(BRect update)
|
|||||||
// TODO: should draw it differently ?
|
// TODO: should draw it differently ?
|
||||||
}
|
}
|
||||||
} else if (IsVisibilityChanging()) {
|
} else if (IsVisibilityChanging()) {
|
||||||
if (Parent()) {
|
if (Parent() != NULL) {
|
||||||
if ((Parent()->Flags() & B_DRAW_ON_CHILDREN) == 0) {
|
if ((Parent()->Flags() & B_DRAW_ON_CHILDREN) == 0) {
|
||||||
uint32 flags = Parent()->Flags();
|
uint32 flags = Parent()->Flags();
|
||||||
Parent()->SetFlags(flags | B_DRAW_ON_CHILDREN);
|
Parent()->SetFlags(flags | B_DRAW_ON_CHILDREN);
|
||||||
@@ -266,13 +270,13 @@ BDragger::Draw(BRect update)
|
|||||||
void
|
void
|
||||||
BDragger::MouseDown(BPoint where)
|
BDragger::MouseDown(BPoint where)
|
||||||
{
|
{
|
||||||
if (!fTarget || !AreDraggersDrawn())
|
if (fTarget == NULL || !AreDraggersDrawn())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
uint32 buttons;
|
uint32 buttons;
|
||||||
Window()->CurrentMessage()->FindInt32("buttons", (int32 *)&buttons);
|
Window()->CurrentMessage()->FindInt32("buttons", (int32*)&buttons);
|
||||||
|
|
||||||
if (fShelf != NULL && (buttons & B_SECONDARY_MOUSE_BUTTON))
|
if (fShelf != NULL && (buttons & B_SECONDARY_MOUSE_BUTTON) != 0)
|
||||||
_ShowPopUp(fTarget, where);
|
_ShowPopUp(fTarget, where);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -285,14 +289,14 @@ BDragger::MouseUp(BPoint point)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BDragger::MouseMoved(BPoint point, uint32 code, const BMessage *msg)
|
BDragger::MouseMoved(BPoint point, uint32 code, const BMessage* msg)
|
||||||
{
|
{
|
||||||
BView::MouseMoved(point, code, msg);
|
BView::MouseMoved(point, code, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BDragger::MessageReceived(BMessage *msg)
|
BDragger::MessageReceived(BMessage* msg)
|
||||||
{
|
{
|
||||||
switch (msg->what) {
|
switch (msg->what) {
|
||||||
case B_TRASH_TARGET:
|
case B_TRASH_TARGET:
|
||||||
@@ -316,7 +320,8 @@ BDragger::MessageReceived(BMessage *msg)
|
|||||||
Flush();
|
Flush();
|
||||||
fTransition = false;
|
fTransition = false;
|
||||||
} else {
|
} else {
|
||||||
if ((fShelf && (fShelf->AllowsDragging() && AreDraggersDrawn()))
|
if ((fShelf != NULL && fShelf->AllowsDragging()
|
||||||
|
&& AreDraggersDrawn())
|
||||||
|| AreDraggersDrawn()) {
|
|| AreDraggersDrawn()) {
|
||||||
Show();
|
Show();
|
||||||
} else
|
} else
|
||||||
@@ -332,25 +337,22 @@ BDragger::MessageReceived(BMessage *msg)
|
|||||||
fTarget->Archive(&archive);
|
fTarget->Archive(&archive);
|
||||||
else if (fRelation == TARGET_IS_CHILD)
|
else if (fRelation == TARGET_IS_CHILD)
|
||||||
Archive(&archive);
|
Archive(&archive);
|
||||||
else {
|
else if (fTarget->Archive(&archive)) {
|
||||||
if (fTarget->Archive(&archive)) {
|
BMessage archivedSelf(B_ARCHIVED_OBJECT);
|
||||||
BMessage archivedSelf(B_ARCHIVED_OBJECT);
|
|
||||||
|
|
||||||
if (Archive(&archivedSelf))
|
if (Archive(&archivedSelf))
|
||||||
archive.AddMessage("__widget", &archivedSelf);
|
archive.AddMessage("__widget", &archivedSelf);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
archive.AddInt32("be:actions", B_TRASH_TARGET);
|
archive.AddInt32("be:actions", B_TRASH_TARGET);
|
||||||
BPoint offset;
|
BPoint offset;
|
||||||
drawing_mode mode;
|
drawing_mode mode;
|
||||||
BBitmap *bitmap = DragBitmap(&offset, &mode);
|
BBitmap* bitmap = DragBitmap(&offset, &mode);
|
||||||
if (bitmap != NULL)
|
if (bitmap != NULL)
|
||||||
DragMessage(&archive, bitmap, mode, offset, this);
|
DragMessage(&archive, bitmap, mode, offset, this);
|
||||||
else {
|
else {
|
||||||
DragMessage(&archive,
|
DragMessage(&archive, ConvertFromScreen(
|
||||||
ConvertFromScreen(fTarget->ConvertToScreen(fTarget->Bounds())),
|
fTarget->ConvertToScreen(fTarget->Bounds())), this);
|
||||||
this);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -543,7 +545,7 @@ BDragger::AllDetached()
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
BDragger::SetPopUp(BPopUpMenu *menu)
|
BDragger::SetPopUp(BPopUpMenu* menu)
|
||||||
{
|
{
|
||||||
if (menu != NULL && menu != fPopUp) {
|
if (menu != NULL && menu != fPopUp) {
|
||||||
delete fPopUp;
|
delete fPopUp;
|
||||||
@@ -555,11 +557,11 @@ BDragger::SetPopUp(BPopUpMenu *menu)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BPopUpMenu *
|
BPopUpMenu*
|
||||||
BDragger::PopUp() const
|
BDragger::PopUp() const
|
||||||
{
|
{
|
||||||
if (fPopUp == NULL && fTarget)
|
if (fPopUp == NULL && fTarget)
|
||||||
const_cast<BDragger *>(this)->_BuildDefaultPopUp();
|
const_cast<BDragger*>(this)->_BuildDefaultPopUp();
|
||||||
|
|
||||||
return fPopUp;
|
return fPopUp;
|
||||||
}
|
}
|
||||||
@@ -572,15 +574,15 @@ BDragger::InShelf() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BView *
|
BView*
|
||||||
BDragger::Target() const
|
BDragger::Target() const
|
||||||
{
|
{
|
||||||
return fTarget;
|
return fTarget;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BBitmap *
|
BBitmap*
|
||||||
BDragger::DragBitmap(BPoint *offset, drawing_mode *mode)
|
BDragger::DragBitmap(BPoint* offset, drawing_mode* mode)
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -598,8 +600,8 @@ void BDragger::_ReservedDragger3() {}
|
|||||||
void BDragger::_ReservedDragger4() {}
|
void BDragger::_ReservedDragger4() {}
|
||||||
|
|
||||||
|
|
||||||
BDragger &
|
BDragger&
|
||||||
BDragger::operator=(const BDragger &)
|
BDragger::operator=(const BDragger&)
|
||||||
{
|
{
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@@ -663,7 +665,7 @@ BDragger::_RemoveFromList()
|
|||||||
status_t
|
status_t
|
||||||
BDragger::_DetermineRelationship()
|
BDragger::_DetermineRelationship()
|
||||||
{
|
{
|
||||||
if (fTarget) {
|
if (fTarget != NULL) {
|
||||||
if (fTarget == Parent())
|
if (fTarget == Parent())
|
||||||
fRelation = TARGET_IS_PARENT;
|
fRelation = TARGET_IS_PARENT;
|
||||||
else if (fTarget == ChildAt(0))
|
else if (fTarget == ChildAt(0))
|
||||||
@@ -680,11 +682,12 @@ BDragger::_DetermineRelationship()
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (fRelation == TARGET_IS_PARENT) {
|
if (fRelation == TARGET_IS_PARENT) {
|
||||||
BRect bounds (Frame());
|
BRect bounds(Frame());
|
||||||
BRect parentBounds (Parent()->Bounds());
|
BRect parentBounds(Parent()->Bounds());
|
||||||
if (!parentBounds.Contains(bounds))
|
if (!parentBounds.Contains(bounds)) {
|
||||||
MoveTo(parentBounds.right - bounds.Width(),
|
MoveTo(parentBounds.right - bounds.Width(),
|
||||||
parentBounds.bottom - bounds.Height());
|
parentBounds.bottom - bounds.Height());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
@@ -692,14 +695,14 @@ BDragger::_DetermineRelationship()
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
BDragger::_SetViewToDrag(BView *target)
|
BDragger::_SetViewToDrag(BView* target)
|
||||||
{
|
{
|
||||||
if (target->Window() != Window())
|
if (target->Window() != Window())
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
|
|
||||||
fTarget = target;
|
fTarget = target;
|
||||||
|
|
||||||
if (Window())
|
if (Window() != NULL)
|
||||||
_DetermineRelationship();
|
_DetermineRelationship();
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
@@ -707,7 +710,7 @@ BDragger::_SetViewToDrag(BView *target)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BDragger::_SetShelf(BShelf *shelf)
|
BDragger::_SetShelf(BShelf* shelf)
|
||||||
{
|
{
|
||||||
fShelf = shelf;
|
fShelf = shelf;
|
||||||
}
|
}
|
||||||
@@ -731,13 +734,13 @@ BDragger::_BuildDefaultPopUp()
|
|||||||
fPopUp = new BPopUpMenu("Shelf", false, false, B_ITEMS_IN_COLUMN);
|
fPopUp = new BPopUpMenu("Shelf", false, false, B_ITEMS_IN_COLUMN);
|
||||||
|
|
||||||
// About
|
// About
|
||||||
BMessage *msg = new BMessage(B_ABOUT_REQUESTED);
|
BMessage* msg = new BMessage(B_ABOUT_REQUESTED);
|
||||||
|
|
||||||
const char *name = fTarget->Name();
|
const char* name = fTarget->Name();
|
||||||
if (name)
|
if (name != NULL)
|
||||||
msg->AddString("target", name);
|
msg->AddString("target", name);
|
||||||
|
|
||||||
BString about(B_TRANSLATE("About %app"B_UTF8_ELLIPSIS));
|
BString about(B_TRANSLATE("About %app" B_UTF8_ELLIPSIS));
|
||||||
about.ReplaceFirst("%app", name);
|
about.ReplaceFirst("%app", name);
|
||||||
|
|
||||||
fPopUp->AddItem(new BMenuItem(about.String(), msg));
|
fPopUp->AddItem(new BMenuItem(about.String(), msg));
|
||||||
@@ -748,11 +751,11 @@ BDragger::_BuildDefaultPopUp()
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BDragger::_ShowPopUp(BView *target, BPoint where)
|
BDragger::_ShowPopUp(BView* target, BPoint where)
|
||||||
{
|
{
|
||||||
BPoint point = ConvertToScreen(where);
|
BPoint point = ConvertToScreen(where);
|
||||||
|
|
||||||
if (!fPopUp && fTarget)
|
if (fPopUp == NULL && fTarget != NULL)
|
||||||
_BuildDefaultPopUp();
|
_BuildDefaultPopUp();
|
||||||
|
|
||||||
fPopUp->SetTargetForItems(fTarget);
|
fPopUp->SetTargetForItems(fTarget);
|
||||||
|
|||||||
Reference in New Issue
Block a user