* 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:
|
||||||
@@ -31,8 +31,8 @@ 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,14 +168,15 @@ IconButton::Draw(BRect area)
|
|||||||
void
|
void
|
||||||
IconButton::MouseDown(BPoint where)
|
IconButton::MouseDown(BPoint where)
|
||||||
{
|
{
|
||||||
if (IsValid()) {
|
if (!IsValid())
|
||||||
if (_HasFlags(STATE_ENABLED)/* && !_HasFlags(STATE_FORCE_PRESSED)*/) {
|
return;
|
||||||
if (Bounds().Contains(where)) {
|
|
||||||
SetMouseEventMask(B_POINTER_EVENTS, B_LOCK_WINDOW_FOCUS);
|
if (_HasFlags(STATE_ENABLED)/* && !_HasFlags(STATE_FORCE_PRESSED)*/) {
|
||||||
_AddFlags(STATE_PRESSED | STATE_TRACKING);
|
if (Bounds().Contains(where)) {
|
||||||
} else {
|
SetMouseEventMask(B_POINTER_EVENTS, B_LOCK_WINDOW_FOCUS);
|
||||||
_ClearFlags(STATE_PRESSED | STATE_TRACKING);
|
_AddFlags(STATE_PRESSED | STATE_TRACKING);
|
||||||
}
|
} else {
|
||||||
|
_ClearFlags(STATE_PRESSED | STATE_TRACKING);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -185,42 +185,44 @@ IconButton::MouseDown(BPoint where)
|
|||||||
void
|
void
|
||||||
IconButton::MouseUp(BPoint where)
|
IconButton::MouseUp(BPoint where)
|
||||||
{
|
{
|
||||||
if (IsValid()) {
|
if (!IsValid())
|
||||||
// if (!_HasFlags(STATE_FORCE_PRESSED)) {
|
return;
|
||||||
if (_HasFlags(STATE_ENABLED) && _HasFlags(STATE_PRESSED) && Bounds().Contains(where))
|
|
||||||
Invoke();
|
// if (!_HasFlags(STATE_FORCE_PRESSED)) {
|
||||||
else if (Bounds().Contains(where))
|
if (_HasFlags(STATE_ENABLED) && _HasFlags(STATE_PRESSED) && Bounds().Contains(where))
|
||||||
_AddFlags(STATE_INSIDE);
|
Invoke();
|
||||||
_ClearFlags(STATE_PRESSED | STATE_TRACKING);
|
else if (Bounds().Contains(where))
|
||||||
// }
|
_AddFlags(STATE_INSIDE);
|
||||||
}
|
_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())
|
||||||
uint32 buttons = 0;
|
return;
|
||||||
Window()->CurrentMessage()->FindInt32("buttons", (int32*)&buttons);
|
|
||||||
// catch a mouse up event that we might have missed
|
uint32 buttons = 0;
|
||||||
if (!buttons && _HasFlags(STATE_PRESSED)) {
|
Window()->CurrentMessage()->FindInt32("buttons", (int32*)&buttons);
|
||||||
MouseUp(where);
|
// catch a mouse up event that we might have missed
|
||||||
return;
|
if (!buttons && _HasFlags(STATE_PRESSED)) {
|
||||||
}
|
MouseUp(where);
|
||||||
if (buttons && !_HasFlags(STATE_TRACKING))
|
return;
|
||||||
return;
|
}
|
||||||
if ((transit == B_INSIDE_VIEW || transit == B_ENTERED_VIEW)
|
if (buttons && !_HasFlags(STATE_TRACKING))
|
||||||
&& _HasFlags(STATE_ENABLED))
|
return;
|
||||||
_AddFlags(STATE_INSIDE);
|
if ((transit == B_INSIDE_VIEW || transit == B_ENTERED_VIEW)
|
||||||
else
|
&& _HasFlags(STATE_ENABLED))
|
||||||
_ClearFlags(STATE_INSIDE);
|
_AddFlags(STATE_INSIDE);
|
||||||
if (_HasFlags(STATE_TRACKING)) {
|
else
|
||||||
if (Bounds().Contains(where))
|
_ClearFlags(STATE_INSIDE);
|
||||||
_AddFlags(STATE_PRESSED);
|
if (_HasFlags(STATE_TRACKING)) {
|
||||||
else
|
if (Bounds().Contains(where))
|
||||||
_ClearFlags(STATE_PRESSED);
|
_AddFlags(STATE_PRESSED);
|
||||||
}
|
else
|
||||||
|
_ClearFlags(STATE_PRESSED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -294,41 +296,42 @@ 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);
|
if (!entry.Exists()) {
|
||||||
if (!entry.Exists()) {
|
app_info info;
|
||||||
app_info info;
|
status = be_app->GetAppInfo(&info);
|
||||||
status = be_app->GetAppInfo(&info);
|
if (status == B_OK) {
|
||||||
|
BEntry app_entry(&info.ref, true);
|
||||||
|
BPath path;
|
||||||
|
app_entry.GetPath(&path);
|
||||||
|
status = path.InitCheck();
|
||||||
if (status == B_OK) {
|
if (status == B_OK) {
|
||||||
BEntry app_entry(&info.ref, true);
|
status = path.GetParent(&path);
|
||||||
BPath path;
|
|
||||||
app_entry.GetPath(&path);
|
|
||||||
status = path.InitCheck();
|
|
||||||
if (status == B_OK) {
|
if (status == B_OK) {
|
||||||
status = path.GetParent(&path);
|
status = path.Append(pathToBitmap, true);
|
||||||
if (status == B_OK) {
|
if (status == B_OK)
|
||||||
status = path.Append(pathToBitmap, true);
|
fileBitmap = BTranslationUtils::GetBitmap(path.Path());
|
||||||
if (status == B_OK)
|
else
|
||||||
fileBitmap = BTranslationUtils::GetBitmap(path.Path());
|
printf("IconButton::SetIcon() - path.Append() failed: %s\n", strerror(status));
|
||||||
else
|
|
||||||
printf("IconButton::SetIcon() - path.Append() failed: %s\n", strerror(status));
|
|
||||||
} else
|
|
||||||
printf("IconButton::SetIcon() - path.GetParent() failed: %s\n", strerror(status));
|
|
||||||
} else
|
} else
|
||||||
printf("IconButton::SetIcon() - path.InitCheck() failed: %s\n", strerror(status));
|
printf("IconButton::SetIcon() - path.GetParent() failed: %s\n", strerror(status));
|
||||||
} else
|
} else
|
||||||
printf("IconButton::SetIcon() - be_app->GetAppInfo() failed: %s\n", strerror(status));
|
printf("IconButton::SetIcon() - path.InitCheck() failed: %s\n", strerror(status));
|
||||||
} else
|
} else
|
||||||
fileBitmap = BTranslationUtils::GetBitmap(pathToBitmap);
|
printf("IconButton::SetIcon() - be_app->GetAppInfo() failed: %s\n", strerror(status));
|
||||||
if (fileBitmap) {
|
} else
|
||||||
status = _MakeBitmaps(fileBitmap);
|
fileBitmap = BTranslationUtils::GetBitmap(pathToBitmap);
|
||||||
delete fileBitmap;
|
if (fileBitmap) {
|
||||||
} else
|
status = _MakeBitmaps(fileBitmap);
|
||||||
status = B_ERROR;
|
delete fileBitmap;
|
||||||
}
|
} else
|
||||||
|
status = B_ERROR;
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -378,7 +381,7 @@ IconButton::SetIcon(const BMimeType* fileType, bool small)
|
|||||||
// SetIcon
|
// SetIcon
|
||||||
status_t
|
status_t
|
||||||
IconButton::SetIcon(const unsigned char* bitsFromQuickRes,
|
IconButton::SetIcon(const unsigned char* bitsFromQuickRes,
|
||||||
uint32 width, uint32 height, color_space format, bool convertToBW)
|
uint32 width, uint32 height, color_space format, bool convertToBW)
|
||||||
{
|
{
|
||||||
status_t status = B_BAD_VALUE;
|
status_t status = B_BAD_VALUE;
|
||||||
if (bitsFromQuickRes && width > 0 && height > 0) {
|
if (bitsFromQuickRes && width > 0 && height > 0) {
|
||||||
@@ -485,15 +488,15 @@ 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
|
||||||
void
|
void
|
||||||
IconButton::DrawNormalBorder(BRect r, rgb_color background,
|
IconButton::DrawNormalBorder(BRect r, rgb_color background,
|
||||||
rgb_color shadow, rgb_color darkShadow,
|
rgb_color shadow, rgb_color darkShadow,
|
||||||
rgb_color lightShadow, rgb_color light)
|
rgb_color lightShadow, rgb_color light)
|
||||||
{
|
{
|
||||||
_DrawFrame(r, shadow, darkShadow, light, lightShadow);
|
_DrawFrame(r, shadow, darkShadow, light, lightShadow);
|
||||||
}
|
}
|
||||||
@@ -501,8 +504,8 @@ IconButton::DrawNormalBorder(BRect r, rgb_color background,
|
|||||||
// DrawPressedBorder
|
// DrawPressedBorder
|
||||||
void
|
void
|
||||||
IconButton::DrawPressedBorder(BRect r, rgb_color background,
|
IconButton::DrawPressedBorder(BRect r, rgb_color background,
|
||||||
rgb_color shadow, rgb_color darkShadow,
|
rgb_color shadow, rgb_color darkShadow,
|
||||||
rgb_color lightShadow, rgb_color light)
|
rgb_color lightShadow, rgb_color light)
|
||||||
{
|
{
|
||||||
_DrawFrame(r, shadow, light, darkShadow, background);
|
_DrawFrame(r, shadow, light, darkShadow, background);
|
||||||
}
|
}
|
||||||
@@ -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