* Improve indentation.
* Use layout friendly constructor of BView. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28088 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006, Haiku.
|
||||
* Copyright 2006-2008, Haiku.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
@@ -32,7 +32,7 @@ using std::nothrow;
|
||||
// constructor
|
||||
IconButton::IconButton(const char* name, uint32 id, const char* label,
|
||||
BMessage* message, BHandler* target)
|
||||
: BView(BRect(0.0, 0.0, 10.0, 10.0), name, B_FOLLOW_NONE, B_WILL_DRAW),
|
||||
: BView(name, B_WILL_DRAW),
|
||||
BInvoker(message, target),
|
||||
fButtonState(STATE_ENABLED),
|
||||
fID(id),
|
||||
@@ -69,9 +69,8 @@ void
|
||||
IconButton::AttachedToWindow()
|
||||
{
|
||||
SetTarget(fTargetCache);
|
||||
if (!Target()) {
|
||||
if (!Target())
|
||||
SetTarget(Window());
|
||||
}
|
||||
}
|
||||
|
||||
// Draw
|
||||
@@ -169,7 +168,9 @@ IconButton::Draw(BRect area)
|
||||
void
|
||||
IconButton::MouseDown(BPoint where)
|
||||
{
|
||||
if (IsValid()) {
|
||||
if (!IsValid())
|
||||
return;
|
||||
|
||||
if (_HasFlags(STATE_ENABLED)/* && !_HasFlags(STATE_FORCE_PRESSED)*/) {
|
||||
if (Bounds().Contains(where)) {
|
||||
SetMouseEventMask(B_POINTER_EVENTS, B_LOCK_WINDOW_FOCUS);
|
||||
@@ -178,14 +179,15 @@ IconButton::MouseDown(BPoint where)
|
||||
_ClearFlags(STATE_PRESSED | STATE_TRACKING);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MouseUp
|
||||
void
|
||||
IconButton::MouseUp(BPoint where)
|
||||
{
|
||||
if (IsValid()) {
|
||||
if (!IsValid())
|
||||
return;
|
||||
|
||||
// if (!_HasFlags(STATE_FORCE_PRESSED)) {
|
||||
if (_HasFlags(STATE_ENABLED) && _HasFlags(STATE_PRESSED) && Bounds().Contains(where))
|
||||
Invoke();
|
||||
@@ -193,14 +195,15 @@ IconButton::MouseUp(BPoint where)
|
||||
_AddFlags(STATE_INSIDE);
|
||||
_ClearFlags(STATE_PRESSED | STATE_TRACKING);
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
// MouseMoved
|
||||
void
|
||||
IconButton::MouseMoved(BPoint where, uint32 transit, const BMessage* message)
|
||||
{
|
||||
if (IsValid()) {
|
||||
if (!IsValid())
|
||||
return;
|
||||
|
||||
uint32 buttons = 0;
|
||||
Window()->CurrentMessage()->FindInt32("buttons", (int32*)&buttons);
|
||||
// catch a mouse up event that we might have missed
|
||||
@@ -221,7 +224,6 @@ IconButton::MouseMoved(BPoint where, uint32 transit, const BMessage* message)
|
||||
else
|
||||
_ClearFlags(STATE_PRESSED);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#define MIN_SPACE 15.0
|
||||
@@ -294,8 +296,10 @@ IconButton::IsPressed() const
|
||||
status_t
|
||||
IconButton::SetIcon(const char* pathToBitmap)
|
||||
{
|
||||
if (pathToBitmap == NULL)
|
||||
return B_BAD_VALUE;
|
||||
|
||||
status_t status = B_BAD_VALUE;
|
||||
if (pathToBitmap) {
|
||||
BBitmap* fileBitmap = NULL;
|
||||
// try to load bitmap from either relative or absolute path
|
||||
BEntry entry(pathToBitmap, true);
|
||||
@@ -328,7 +332,6 @@ IconButton::SetIcon(const char* pathToBitmap)
|
||||
delete fileBitmap;
|
||||
} else
|
||||
status = B_ERROR;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -485,8 +488,8 @@ IconButton::Bitmap() const
|
||||
bool
|
||||
IconButton::DrawBorder() const
|
||||
{
|
||||
return (IsEnabled() && (_HasFlags(STATE_INSIDE) || _HasFlags(STATE_TRACKING))
|
||||
|| _HasFlags(STATE_FORCE_PRESSED));
|
||||
return (IsEnabled() && (_HasFlags(STATE_INSIDE)
|
||||
|| _HasFlags(STATE_TRACKING)) || _HasFlags(STATE_FORCE_PRESSED));
|
||||
}
|
||||
|
||||
// DrawNormalBorder
|
||||
@@ -511,7 +514,8 @@ IconButton::DrawPressedBorder(BRect r, rgb_color background,
|
||||
bool
|
||||
IconButton::IsValid() const
|
||||
{
|
||||
return (fNormalBitmap && fDisabledBitmap && fClickedBitmap && fDisabledClickedBitmap
|
||||
return (fNormalBitmap && fDisabledBitmap && fClickedBitmap
|
||||
&& fDisabledClickedBitmap
|
||||
&& fNormalBitmap->IsValid()
|
||||
&& fDisabledBitmap->IsValid()
|
||||
&& fClickedBitmap->IsValid()
|
||||
@@ -556,7 +560,8 @@ IconButton::SetEnabled(bool enabled)
|
||||
BBitmap*
|
||||
IconButton::_ConvertToRGB32(const BBitmap* bitmap) const
|
||||
{
|
||||
BBitmap* convertedBitmap = new(nothrow) BBitmap(bitmap->Bounds(), B_BITMAP_ACCEPTS_VIEWS, B_RGBA32);
|
||||
BBitmap* convertedBitmap = new(nothrow) BBitmap(bitmap->Bounds(),
|
||||
B_BITMAP_ACCEPTS_VIEWS, B_RGBA32);
|
||||
if (convertedBitmap && convertedBitmap->IsValid()) {
|
||||
memset(convertedBitmap->Bits(), 0, convertedBitmap->BitsLength());
|
||||
BView* helper = new BView(bitmap->Bounds(), "helper",
|
||||
|
||||
Reference in New Issue
Block a user