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),
|
||||||
@@ -128,7 +130,8 @@ 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),
|
||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -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,14 +337,12 @@ 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;
|
||||||
@@ -348,9 +351,8 @@ BDragger::MessageReceived(BMessage *msg)
|
|||||||
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;
|
||||||
@@ -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))
|
||||||
@@ -682,10 +684,11 @@ 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;
|
||||||
}
|
}
|
||||||
@@ -699,7 +702,7 @@ BDragger::_SetViewToDrag(BView *target)
|
|||||||
|
|
||||||
fTarget = target;
|
fTarget = target;
|
||||||
|
|
||||||
if (Window())
|
if (Window() != NULL)
|
||||||
_DetermineRelationship();
|
_DetermineRelationship();
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
@@ -734,7 +737,7 @@ BDragger::_BuildDefaultPopUp()
|
|||||||
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));
|
||||||
@@ -752,7 +755,7 @@ 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