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