* BIconButton now inherits from BControl, solving a TODO comment.
* I tried to reuse as much state from BControl as possible, so I removed a few states. * Also made the flags private, and added protected SetInside()/IsInside() methods. * Removed useless BIconButton::ID(). * Adjusted users. * Minor cleanup, automatic white space cleanup. -alpha git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@41611 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -11,12 +11,9 @@
|
|||||||
|
|
||||||
//! GUI class that loads an image from disk and shows it as clickable button.
|
//! GUI class that loads an image from disk and shows it as clickable button.
|
||||||
|
|
||||||
// TODO: inherit from BControl
|
|
||||||
|
|
||||||
|
#include <Control.h>
|
||||||
#include <Invoker.h>
|
|
||||||
#include <String.h>
|
#include <String.h>
|
||||||
#include <View.h>
|
|
||||||
|
|
||||||
|
|
||||||
class BBitmap;
|
class BBitmap;
|
||||||
@@ -26,13 +23,12 @@ class BMimeType;
|
|||||||
namespace BPrivate {
|
namespace BPrivate {
|
||||||
|
|
||||||
|
|
||||||
class BIconButton : public BView, public BInvoker {
|
class BIconButton : public BControl {
|
||||||
public:
|
public:
|
||||||
BIconButton(const char* name,
|
BIconButton(const char* name,
|
||||||
uint32 id,
|
const char* label = NULL,
|
||||||
const char* label = NULL,
|
BMessage* message = NULL,
|
||||||
BMessage* message = NULL,
|
BHandler* target = NULL);
|
||||||
BHandler* target = NULL);
|
|
||||||
virtual ~BIconButton();
|
virtual ~BIconButton();
|
||||||
|
|
||||||
// BView interface
|
// BView interface
|
||||||
@@ -63,49 +59,34 @@ public:
|
|||||||
// BInvoker interface
|
// BInvoker interface
|
||||||
virtual status_t Invoke(BMessage* message = NULL);
|
virtual status_t Invoke(BMessage* message = NULL);
|
||||||
|
|
||||||
|
// BControl interface
|
||||||
|
virtual void SetValue(int32 value);
|
||||||
|
virtual void SetEnabled(bool enable);
|
||||||
|
|
||||||
// BIconButton
|
// BIconButton
|
||||||
bool IsValid() const;
|
bool IsValid() const;
|
||||||
|
|
||||||
virtual int32 Value() const;
|
|
||||||
virtual void SetValue(int32 value);
|
|
||||||
|
|
||||||
bool IsEnabled() const;
|
|
||||||
void SetEnabled(bool enable);
|
|
||||||
|
|
||||||
void SetPressed(bool pressed);
|
void SetPressed(bool pressed);
|
||||||
bool IsPressed() const;
|
bool IsPressed() const;
|
||||||
uint32 ID() const
|
|
||||||
{ return fID; }
|
|
||||||
|
|
||||||
status_t SetIcon(int32 resourceID);
|
status_t SetIcon(int32 resourceID);
|
||||||
status_t SetIcon(const char* pathToBitmap);
|
status_t SetIcon(const char* pathToBitmap);
|
||||||
status_t SetIcon(const BBitmap* bitmap);
|
status_t SetIcon(const BBitmap* bitmap);
|
||||||
status_t SetIcon(const BMimeType* fileType,
|
status_t SetIcon(const BMimeType* fileType,
|
||||||
bool small = true);
|
bool small = true);
|
||||||
status_t SetIcon(const unsigned char* bitsFromQuickRes,
|
status_t SetIcon(const unsigned char* bitsFromQuickRes,
|
||||||
uint32 width, uint32 height,
|
uint32 width, uint32 height,
|
||||||
color_space format,
|
color_space format,
|
||||||
bool convertToBW = false);
|
bool convertToBW = false);
|
||||||
void ClearIcon();
|
void ClearIcon();
|
||||||
void TrimIcon(bool keepAspect = true);
|
void TrimIcon(bool keepAspect = true);
|
||||||
|
|
||||||
BBitmap* Bitmap() const;
|
BBitmap* Bitmap() const;
|
||||||
// caller has to delete the returned bitmap
|
// caller has to delete the returned bitmap
|
||||||
const BString& Label() const;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
enum {
|
bool IsInside() const;
|
||||||
STATE_NONE = 0x0000,
|
void SetInside(bool inside);
|
||||||
STATE_TRACKING = 0x0001,
|
|
||||||
STATE_PRESSED = 0x0002,
|
|
||||||
STATE_ENABLED = 0x0004,
|
|
||||||
STATE_INSIDE = 0x0008,
|
|
||||||
STATE_FORCE_PRESSED = 0x0010,
|
|
||||||
};
|
|
||||||
|
|
||||||
void _AddFlags(uint32 flags);
|
|
||||||
void _ClearFlags(uint32 flags);
|
|
||||||
bool _HasFlags(uint32 flags) const;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BBitmap* _ConvertToRGB32(const BBitmap* bitmap) const;
|
BBitmap* _ConvertToRGB32(const BBitmap* bitmap) const;
|
||||||
@@ -113,15 +94,16 @@ private:
|
|||||||
void _DeleteBitmaps();
|
void _DeleteBitmaps();
|
||||||
void _SendMessage() const;
|
void _SendMessage() const;
|
||||||
void _Update();
|
void _Update();
|
||||||
|
void _SetTracking(bool state);
|
||||||
|
void _SetFlags(uint32 flags, bool set);
|
||||||
|
bool _HasFlags(uint32 flags) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint32 fButtonState;
|
uint32 fButtonState;
|
||||||
int32 fID;
|
|
||||||
BBitmap* fNormalBitmap;
|
BBitmap* fNormalBitmap;
|
||||||
BBitmap* fDisabledBitmap;
|
BBitmap* fDisabledBitmap;
|
||||||
BBitmap* fClickedBitmap;
|
BBitmap* fClickedBitmap;
|
||||||
BBitmap* fDisabledClickedBitmap;
|
BBitmap* fDisabledClickedBitmap;
|
||||||
BString fLabel;
|
|
||||||
|
|
||||||
BHandler* fTargetCache;
|
BHandler* fTargetCache;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -3,15 +3,16 @@
|
|||||||
* All rights reserved. Distributed under the terms of the MIT License.
|
* All rights reserved. Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "LaunchButton.h"
|
#include "LaunchButton.h"
|
||||||
|
|
||||||
#include <malloc.h> // string.h is not enough on Haiku?!?
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include <Application.h>
|
|
||||||
#include <AppDefs.h>
|
#include <AppDefs.h>
|
||||||
#include <AppFileInfo.h>
|
#include <AppFileInfo.h>
|
||||||
|
#include <Application.h>
|
||||||
#include <Bitmap.h>
|
#include <Bitmap.h>
|
||||||
#include <Catalog.h>
|
#include <Catalog.h>
|
||||||
#include <File.h>
|
#include <File.h>
|
||||||
@@ -24,25 +25,24 @@
|
|||||||
#include "PadView.h"
|
#include "PadView.h"
|
||||||
#include "MainWindow.h"
|
#include "MainWindow.h"
|
||||||
|
|
||||||
|
|
||||||
#undef B_TRANSLATE_CONTEXT
|
#undef B_TRANSLATE_CONTEXT
|
||||||
#define B_TRANSLATE_CONTEXT "LaunchBox"
|
#define B_TRANSLATE_CONTEXT "LaunchBox"
|
||||||
|
|
||||||
|
|
||||||
static const float kDragStartDist = 10.0;
|
static const float kDragStartDist = 10.0;
|
||||||
static const float kDragBitmapAlphaScale = 0.6;
|
static const float kDragBitmapAlphaScale = 0.6;
|
||||||
static const char* kEmptyHelpString = B_TRANSLATE("You can drag an icon here.");
|
static const char* kEmptyHelpString = B_TRANSLATE("You can drag an icon here.");
|
||||||
|
|
||||||
|
|
||||||
bigtime_t
|
bigtime_t LaunchButton::sClickSpeed = 0;
|
||||||
LaunchButton::sClickSpeed = 0;
|
bool LaunchButton::sIgnoreDoubleClick = true;
|
||||||
|
|
||||||
bool
|
|
||||||
LaunchButton::sIgnoreDoubleClick = true;
|
|
||||||
|
|
||||||
|
|
||||||
LaunchButton::LaunchButton(const char* name, uint32 id, const char* label,
|
LaunchButton::LaunchButton(const char* name, const char* label,
|
||||||
BMessage* message, BHandler* target)
|
BMessage* message, BHandler* target)
|
||||||
:
|
:
|
||||||
BIconButton(name, id, label, message, target),
|
BIconButton(name, label, message, target),
|
||||||
fRef(NULL),
|
fRef(NULL),
|
||||||
fAppSig(NULL),
|
fAppSig(NULL),
|
||||||
fDescription(""),
|
fDescription(""),
|
||||||
@@ -166,10 +166,10 @@ LaunchButton::MouseDown(BPoint where)
|
|||||||
if (BMessage* message = Window()->CurrentMessage()) {
|
if (BMessage* message = Window()->CurrentMessage()) {
|
||||||
uint32 buttons;
|
uint32 buttons;
|
||||||
message->FindInt32("buttons", (int32*)&buttons);
|
message->FindInt32("buttons", (int32*)&buttons);
|
||||||
if (buttons & B_SECONDARY_MOUSE_BUTTON) {
|
if ((buttons & B_SECONDARY_MOUSE_BUTTON) != 0 && IsInside()) {
|
||||||
if (PadView* parent = dynamic_cast<PadView*>(Parent())) {
|
if (PadView* parent = dynamic_cast<PadView*>(Parent())) {
|
||||||
parent->DisplayMenu(ConvertToParent(where), this);
|
parent->DisplayMenu(ConvertToParent(where), this);
|
||||||
_ClearFlags(STATE_INSIDE);
|
SetInside(false);
|
||||||
callInherited = false;
|
callInherited = false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -211,12 +211,15 @@ LaunchButton::MouseMoved(BPoint where, uint32 transit,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// see if we should create a drag message
|
// see if we should create a drag message
|
||||||
if (_HasFlags(STATE_TRACKING) && fRef) {
|
if (IsTracking() && fRef != NULL) {
|
||||||
BPoint diff = where - fDragStart;
|
BPoint diff = where - fDragStart;
|
||||||
float dist = sqrtf(diff.x * diff.x + diff.y * diff.y);
|
float dist = sqrtf(diff.x * diff.x + diff.y * diff.y);
|
||||||
if (dist >= kDragStartDist) {
|
if (dist >= kDragStartDist) {
|
||||||
// stop tracking
|
// stop tracking
|
||||||
_ClearFlags(STATE_PRESSED | STATE_TRACKING | STATE_INSIDE);
|
SetTracking(false);
|
||||||
|
SetPressed(false);
|
||||||
|
SetInside(false);
|
||||||
|
|
||||||
// create drag bitmap and message
|
// create drag bitmap and message
|
||||||
if (BBitmap* bitmap = Bitmap()) {
|
if (BBitmap* bitmap = Bitmap()) {
|
||||||
if (bitmap->ColorSpace() == B_RGB32) {
|
if (bitmap->ColorSpace() == B_RGB32) {
|
||||||
@@ -263,11 +266,11 @@ LaunchButton::PreferredSize()
|
|||||||
float hPadding = max_c(6.0, ceilf(minHeight / 3.0));
|
float hPadding = max_c(6.0, ceilf(minHeight / 3.0));
|
||||||
float vPadding = max_c(6.0, ceilf(minWidth / 3.0));
|
float vPadding = max_c(6.0, ceilf(minWidth / 3.0));
|
||||||
|
|
||||||
if (Label().CountChars() > 0) {
|
if (Label() != NULL && Label()[0] != '\0') {
|
||||||
font_height fh;
|
font_height fh;
|
||||||
GetFontHeight(&fh);
|
GetFontHeight(&fh);
|
||||||
minHeight += ceilf(fh.ascent + fh.descent) + vPadding;
|
minHeight += ceilf(fh.ascent + fh.descent) + vPadding;
|
||||||
minWidth += StringWidth(Label().String()) + vPadding;
|
minWidth += StringWidth(Label()) + vPadding;
|
||||||
}
|
}
|
||||||
|
|
||||||
return BSize(minWidth + hPadding, minHeight + vPadding);
|
return BSize(minWidth + hPadding, minHeight + vPadding);
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ enum {
|
|||||||
|
|
||||||
class LaunchButton : public BIconButton {
|
class LaunchButton : public BIconButton {
|
||||||
public:
|
public:
|
||||||
LaunchButton(const char* name, uint32 id,
|
LaunchButton(const char* name,
|
||||||
const char* label = NULL,
|
const char* label = NULL,
|
||||||
BMessage* message = NULL,
|
BMessage* message = NULL,
|
||||||
BHandler* target = NULL);
|
BHandler* target = NULL);
|
||||||
|
|||||||
@@ -36,7 +36,6 @@ MainWindow::MainWindow(const char* name, BRect frame, bool addDefaultButtons)
|
|||||||
B_ALL_WORKSPACES),
|
B_ALL_WORKSPACES),
|
||||||
fSettings(new BMessage('sett')),
|
fSettings(new BMessage('sett')),
|
||||||
fPadView(new PadView("pad view")),
|
fPadView(new PadView("pad view")),
|
||||||
fLastID(0),
|
|
||||||
fNamePanelFrame(-1000.0, -1000.0, -800.0, -900.0),
|
fNamePanelFrame(-1000.0, -1000.0, -800.0, -900.0),
|
||||||
fAutoRaise(false),
|
fAutoRaise(false),
|
||||||
fShowOnAllWorkspaces(true)
|
fShowOnAllWorkspaces(true)
|
||||||
@@ -66,7 +65,6 @@ MainWindow::MainWindow(const char* name, BRect frame, BMessage* settings)
|
|||||||
B_ALL_WORKSPACES),
|
B_ALL_WORKSPACES),
|
||||||
fSettings(settings),
|
fSettings(settings),
|
||||||
fPadView(new PadView("pad view")),
|
fPadView(new PadView("pad view")),
|
||||||
fLastID(0),
|
|
||||||
fNamePanelFrame(-1000.0, -1000.0, -900.0, -900.0),
|
fNamePanelFrame(-1000.0, -1000.0, -900.0, -900.0),
|
||||||
fAutoRaise(false),
|
fAutoRaise(false),
|
||||||
fShowOnAllWorkspaces(true)
|
fShowOnAllWorkspaces(true)
|
||||||
@@ -182,7 +180,7 @@ MainWindow::MessageReceived(BMessage* message)
|
|||||||
case MSG_ADD_SLOT: {
|
case MSG_ADD_SLOT: {
|
||||||
LaunchButton* button;
|
LaunchButton* button;
|
||||||
if (message->FindPointer("be:source", (void**)&button) >= B_OK) {
|
if (message->FindPointer("be:source", (void**)&button) >= B_OK) {
|
||||||
fPadView->AddButton(new LaunchButton("launch button", fLastID++,
|
fPadView->AddButton(new LaunchButton("launch button",
|
||||||
NULL, new BMessage(MSG_LAUNCH)), button);
|
NULL, new BMessage(MSG_LAUNCH)), button);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -378,7 +376,7 @@ MainWindow::LoadSettings(const BMessage* message)
|
|||||||
const char* path;
|
const char* path;
|
||||||
bool buttonAdded = false;
|
bool buttonAdded = false;
|
||||||
for (int32 i = 0; message->FindString("path", i, &path) >= B_OK; i++) {
|
for (int32 i = 0; message->FindString("path", i, &path) >= B_OK; i++) {
|
||||||
LaunchButton* button = new LaunchButton("launch button", fLastID++,
|
LaunchButton* button = new LaunchButton("launch button",
|
||||||
NULL, new BMessage(MSG_LAUNCH));
|
NULL, new BMessage(MSG_LAUNCH));
|
||||||
fPadView->AddButton(button);
|
fPadView->AddButton(button);
|
||||||
BString signature;
|
BString signature;
|
||||||
@@ -555,38 +553,33 @@ void
|
|||||||
MainWindow::_AddDefaultButtons()
|
MainWindow::_AddDefaultButtons()
|
||||||
{
|
{
|
||||||
// Mail
|
// Mail
|
||||||
LaunchButton* button = new LaunchButton("launch button", fLastID++, NULL,
|
LaunchButton* button = new LaunchButton("launch button", NULL,
|
||||||
new BMessage(MSG_LAUNCH));
|
new BMessage(MSG_LAUNCH));
|
||||||
fPadView->AddButton(button);
|
fPadView->AddButton(button);
|
||||||
button->SetTo("application/x-vnd.Be-MAIL", true);
|
button->SetTo("application/x-vnd.Be-MAIL", true);
|
||||||
|
|
||||||
// StyledEdit
|
// StyledEdit
|
||||||
button = new LaunchButton("launch button", fLastID++, NULL,
|
button = new LaunchButton("launch button", NULL, new BMessage(MSG_LAUNCH));
|
||||||
new BMessage(MSG_LAUNCH));
|
|
||||||
fPadView->AddButton(button);
|
fPadView->AddButton(button);
|
||||||
button->SetTo("application/x-vnd.Haiku-StyledEdit", true);
|
button->SetTo("application/x-vnd.Haiku-StyledEdit", true);
|
||||||
|
|
||||||
// ShowImage
|
// ShowImage
|
||||||
button = new LaunchButton("launch button", fLastID++, NULL,
|
button = new LaunchButton("launch button", NULL, new BMessage(MSG_LAUNCH));
|
||||||
new BMessage(MSG_LAUNCH));
|
|
||||||
fPadView->AddButton(button);
|
fPadView->AddButton(button);
|
||||||
button->SetTo("application/x-vnd.Haiku-ShowImage", true);
|
button->SetTo("application/x-vnd.Haiku-ShowImage", true);
|
||||||
|
|
||||||
// MediaPlayer
|
// MediaPlayer
|
||||||
button = new LaunchButton("launch button", fLastID++, NULL,
|
button = new LaunchButton("launch button", NULL, new BMessage(MSG_LAUNCH));
|
||||||
new BMessage(MSG_LAUNCH));
|
|
||||||
fPadView->AddButton(button);
|
fPadView->AddButton(button);
|
||||||
button->SetTo("application/x-vnd.Haiku-MediaPlayer", true);
|
button->SetTo("application/x-vnd.Haiku-MediaPlayer", true);
|
||||||
|
|
||||||
// DeskCalc
|
// DeskCalc
|
||||||
button = new LaunchButton("launch button", fLastID++, NULL,
|
button = new LaunchButton("launch button", NULL, new BMessage(MSG_LAUNCH));
|
||||||
new BMessage(MSG_LAUNCH));
|
|
||||||
fPadView->AddButton(button);
|
fPadView->AddButton(button);
|
||||||
button->SetTo("application/x-vnd.Haiku-DeskCalc", true);
|
button->SetTo("application/x-vnd.Haiku-DeskCalc", true);
|
||||||
|
|
||||||
// Terminal
|
// Terminal
|
||||||
button = new LaunchButton("launch button", fLastID++, NULL,
|
button = new LaunchButton("launch button", NULL, new BMessage(MSG_LAUNCH));
|
||||||
new BMessage(MSG_LAUNCH));
|
|
||||||
fPadView->AddButton(button);
|
fPadView->AddButton(button);
|
||||||
button->SetTo("application/x-vnd.Haiku-Terminal", true);
|
button->SetTo("application/x-vnd.Haiku-Terminal", true);
|
||||||
}
|
}
|
||||||
@@ -595,16 +588,14 @@ MainWindow::_AddDefaultButtons()
|
|||||||
void
|
void
|
||||||
MainWindow::_AddEmptyButtons()
|
MainWindow::_AddEmptyButtons()
|
||||||
{
|
{
|
||||||
LaunchButton* button = new LaunchButton("launch button", fLastID++, NULL,
|
LaunchButton* button = new LaunchButton("launch button", NULL,
|
||||||
new BMessage(MSG_LAUNCH));
|
new BMessage(MSG_LAUNCH));
|
||||||
fPadView->AddButton(button);
|
fPadView->AddButton(button);
|
||||||
|
|
||||||
button = new LaunchButton("launch button", fLastID++, NULL,
|
button = new LaunchButton("launch button", NULL, new BMessage(MSG_LAUNCH));
|
||||||
new BMessage(MSG_LAUNCH));
|
|
||||||
fPadView->AddButton(button);
|
fPadView->AddButton(button);
|
||||||
|
|
||||||
button = new LaunchButton("launch button", fLastID++, NULL,
|
button = new LaunchButton("launch button", NULL, new BMessage(MSG_LAUNCH));
|
||||||
new BMessage(MSG_LAUNCH));
|
|
||||||
fPadView->AddButton(button);
|
fPadView->AddButton(button);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -65,9 +65,9 @@ private:
|
|||||||
|
|
||||||
void _NotifySettingsChanged();
|
void _NotifySettingsChanged();
|
||||||
|
|
||||||
|
private:
|
||||||
BMessage* fSettings;
|
BMessage* fSettings;
|
||||||
PadView* fPadView;
|
PadView* fPadView;
|
||||||
int32 fLastID;
|
|
||||||
|
|
||||||
float fBorderDist;
|
float fBorderDist;
|
||||||
BPoint fScreenPosition;
|
BPoint fScreenPosition;
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ void
|
|||||||
ToolBarView::AddAction(BMessage* message, BHandler* target, const BBitmap* icon,
|
ToolBarView::AddAction(BMessage* message, BHandler* target, const BBitmap* icon,
|
||||||
const char* toolTipText)
|
const char* toolTipText)
|
||||||
{
|
{
|
||||||
BIconButton* button = new BIconButton(NULL, 0, NULL, message, target);
|
BIconButton* button = new BIconButton(NULL, NULL, message, target);
|
||||||
button->SetIcon(icon);
|
button->SetIcon(icon);
|
||||||
if (toolTipText != NULL)
|
if (toolTipText != NULL)
|
||||||
button->SetToolTip(toolTipText);
|
button->SetToolTip(toolTipText);
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
* Stephan Aßmus <superstippi@gmx.de>
|
* Stephan Aßmus <superstippi@gmx.de>
|
||||||
|
* Axel Dörfler, axeld@pinc-software.de.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
@@ -29,20 +30,30 @@
|
|||||||
#include <Window.h>
|
#include <Window.h>
|
||||||
|
|
||||||
|
|
||||||
BIconButton::BIconButton(const char* name, uint32 id, const char* label,
|
namespace BPrivate {
|
||||||
BMessage* message, BHandler* target)
|
|
||||||
|
|
||||||
|
enum {
|
||||||
|
STATE_NONE = 0x0000,
|
||||||
|
STATE_PRESSED = 0x0002,
|
||||||
|
STATE_INSIDE = 0x0008,
|
||||||
|
STATE_FORCE_PRESSED = 0x0010,
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
BIconButton::BIconButton(const char* name, const char* label,
|
||||||
|
BMessage* message, BHandler* target)
|
||||||
:
|
:
|
||||||
BView(name, B_WILL_DRAW),
|
BControl(name, label, message, B_WILL_DRAW),
|
||||||
BInvoker(message, target),
|
fButtonState(0),
|
||||||
fButtonState(STATE_ENABLED),
|
|
||||||
fID(id),
|
|
||||||
fNormalBitmap(NULL),
|
fNormalBitmap(NULL),
|
||||||
fDisabledBitmap(NULL),
|
fDisabledBitmap(NULL),
|
||||||
fClickedBitmap(NULL),
|
fClickedBitmap(NULL),
|
||||||
fDisabledClickedBitmap(NULL),
|
fDisabledClickedBitmap(NULL),
|
||||||
fLabel(label),
|
|
||||||
fTargetCache(target)
|
fTargetCache(target)
|
||||||
{
|
{
|
||||||
|
SetTarget(target);
|
||||||
SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||||
SetViewColor(B_TRANSPARENT_32_BIT);
|
SetViewColor(B_TRANSPARENT_32_BIT);
|
||||||
}
|
}
|
||||||
@@ -126,8 +137,8 @@ BIconButton::Draw(BRect updateRect)
|
|||||||
bool
|
bool
|
||||||
BIconButton::ShouldDrawBorder() const
|
BIconButton::ShouldDrawBorder() const
|
||||||
{
|
{
|
||||||
return ((IsEnabled() && (_HasFlags(STATE_INSIDE)
|
return (IsEnabled() && (IsInside() || IsTracking()))
|
||||||
|| _HasFlags(STATE_TRACKING))) || _HasFlags(STATE_FORCE_PRESSED));
|
|| _HasFlags(STATE_FORCE_PRESSED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -155,12 +166,14 @@ BIconButton::MouseDown(BPoint where)
|
|||||||
if (!IsValid())
|
if (!IsValid())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (_HasFlags(STATE_ENABLED)) {
|
if (IsEnabled()) {
|
||||||
if (Bounds().Contains(where)) {
|
if (Bounds().Contains(where)) {
|
||||||
SetMouseEventMask(B_POINTER_EVENTS, B_LOCK_WINDOW_FOCUS);
|
SetMouseEventMask(B_POINTER_EVENTS, B_LOCK_WINDOW_FOCUS);
|
||||||
_AddFlags(STATE_PRESSED | STATE_TRACKING);
|
_SetFlags(STATE_PRESSED, true);
|
||||||
|
_SetTracking(true);
|
||||||
} else {
|
} else {
|
||||||
_ClearFlags(STATE_PRESSED | STATE_TRACKING);
|
_SetFlags(STATE_PRESSED, false);
|
||||||
|
_SetTracking(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -172,12 +185,14 @@ BIconButton::MouseUp(BPoint where)
|
|||||||
if (!IsValid())
|
if (!IsValid())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (_HasFlags(STATE_ENABLED) && _HasFlags(STATE_PRESSED)
|
if (IsEnabled() && _HasFlags(STATE_PRESSED)
|
||||||
&& Bounds().Contains(where)) {
|
&& Bounds().Contains(where)) {
|
||||||
Invoke();
|
Invoke();
|
||||||
} else if (Bounds().Contains(where))
|
} else if (Bounds().Contains(where))
|
||||||
_AddFlags(STATE_INSIDE);
|
SetInside(true);
|
||||||
_ClearFlags(STATE_PRESSED | STATE_TRACKING);
|
|
||||||
|
_SetFlags(STATE_PRESSED, false);
|
||||||
|
_SetTracking(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -194,19 +209,13 @@ BIconButton::MouseMoved(BPoint where, uint32 transit, const BMessage* message)
|
|||||||
MouseUp(where);
|
MouseUp(where);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (buttons && !_HasFlags(STATE_TRACKING))
|
if (buttons != 0 && !IsTracking())
|
||||||
return;
|
return;
|
||||||
if ((transit == B_INSIDE_VIEW || transit == B_ENTERED_VIEW)
|
|
||||||
&& _HasFlags(STATE_ENABLED))
|
SetInside((transit == B_INSIDE_VIEW || transit == B_ENTERED_VIEW)
|
||||||
_AddFlags(STATE_INSIDE);
|
&& IsEnabled());
|
||||||
else
|
if (IsTracking())
|
||||||
_ClearFlags(STATE_INSIDE);
|
_SetFlags(STATE_PRESSED, Bounds().Contains(where));
|
||||||
if (_HasFlags(STATE_TRACKING)) {
|
|
||||||
if (Bounds().Contains(where))
|
|
||||||
_AddFlags(STATE_PRESSED);
|
|
||||||
else
|
|
||||||
_ClearFlags(STATE_PRESSED);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -229,11 +238,11 @@ BIconButton::GetPreferredSize(float* width, float* height)
|
|||||||
float hPadding = max_c(6.0f, ceilf(minHeight / 4.0f));
|
float hPadding = max_c(6.0f, ceilf(minHeight / 4.0f));
|
||||||
float vPadding = max_c(6.0f, ceilf(minWidth / 4.0f));
|
float vPadding = max_c(6.0f, ceilf(minWidth / 4.0f));
|
||||||
|
|
||||||
if (fLabel.CountChars() > 0) {
|
if (Label() != NULL && Label()[0] != '\0') {
|
||||||
font_height fh;
|
font_height fh;
|
||||||
GetFontHeight(&fh);
|
GetFontHeight(&fh);
|
||||||
minHeight += ceilf(fh.ascent + fh.descent) + vPadding;
|
minHeight += ceilf(fh.ascent + fh.descent) + vPadding;
|
||||||
minWidth += StringWidth(fLabel.String()) + vPadding;
|
minWidth += StringWidth(Label()) + vPadding;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (width)
|
if (width)
|
||||||
@@ -269,7 +278,6 @@ BIconButton::Invoke(BMessage* message)
|
|||||||
clone.AddInt64("be:when", system_time());
|
clone.AddInt64("be:when", system_time());
|
||||||
clone.AddPointer("be:source", (BView*)this);
|
clone.AddPointer("be:source", (BView*)this);
|
||||||
clone.AddInt32("be:value", Value());
|
clone.AddInt32("be:value", Value());
|
||||||
clone.AddInt32("id", ID());
|
|
||||||
return BInvoker::Invoke(&clone);
|
return BInvoker::Invoke(&clone);
|
||||||
}
|
}
|
||||||
return BInvoker::Invoke(message);
|
return BInvoker::Invoke(message);
|
||||||
@@ -279,10 +287,7 @@ BIconButton::Invoke(BMessage* message)
|
|||||||
void
|
void
|
||||||
BIconButton::SetPressed(bool pressed)
|
BIconButton::SetPressed(bool pressed)
|
||||||
{
|
{
|
||||||
if (pressed)
|
_SetFlags(STATE_FORCE_PRESSED, pressed);
|
||||||
_AddFlags(STATE_FORCE_PRESSED);
|
|
||||||
else
|
|
||||||
_ClearFlags(STATE_FORCE_PRESSED);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -618,44 +623,39 @@ BIconButton::Bitmap() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const BString&
|
|
||||||
BIconButton::Label() const
|
|
||||||
{
|
|
||||||
return fLabel;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int32
|
|
||||||
BIconButton::Value() const
|
|
||||||
{
|
|
||||||
return _HasFlags(STATE_PRESSED) ? B_CONTROL_ON : B_CONTROL_OFF;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BIconButton::SetValue(int32 value)
|
BIconButton::SetValue(int32 value)
|
||||||
{
|
{
|
||||||
if (value)
|
BControl::SetValue(value);
|
||||||
_AddFlags(STATE_PRESSED);
|
_SetFlags(STATE_PRESSED, value != 0);
|
||||||
else
|
|
||||||
_ClearFlags(STATE_PRESSED);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool
|
|
||||||
BIconButton::IsEnabled() const
|
|
||||||
{
|
|
||||||
return _HasFlags(STATE_ENABLED) ? B_CONTROL_ON : B_CONTROL_OFF;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BIconButton::SetEnabled(bool enabled)
|
BIconButton::SetEnabled(bool enabled)
|
||||||
{
|
{
|
||||||
if (enabled)
|
BControl::SetEnabled(enabled);
|
||||||
_AddFlags(STATE_ENABLED);
|
if (!enabled) {
|
||||||
else
|
SetInside(false);
|
||||||
_ClearFlags(STATE_ENABLED | STATE_TRACKING | STATE_INSIDE);
|
_SetTracking(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// #pragma mark - protected
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
BIconButton::IsInside() const
|
||||||
|
{
|
||||||
|
return _HasFlags(STATE_INSIDE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
BIconButton::SetInside(bool inside)
|
||||||
|
{
|
||||||
|
_SetFlags(STATE_INSIDE, inside);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -690,7 +690,7 @@ status_t
|
|||||||
BIconButton::_MakeBitmaps(const BBitmap* bitmap)
|
BIconButton::_MakeBitmaps(const BBitmap* bitmap)
|
||||||
{
|
{
|
||||||
status_t status = bitmap ? bitmap->InitCheck() : B_BAD_VALUE;
|
status_t status = bitmap ? bitmap->InitCheck() : B_BAD_VALUE;
|
||||||
if (status >= B_OK) {
|
if (status == B_OK) {
|
||||||
// make our own versions of the bitmap
|
// make our own versions of the bitmap
|
||||||
BRect b(bitmap->Bounds());
|
BRect b(bitmap->Bounds());
|
||||||
_DeleteBitmaps();
|
_DeleteBitmaps();
|
||||||
@@ -838,20 +838,16 @@ BIconButton::_Update()
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BIconButton::_AddFlags(uint32 flags)
|
BIconButton::_SetFlags(uint32 flags, bool set)
|
||||||
{
|
{
|
||||||
if (!_HasFlags(flags)) {
|
if (_HasFlags(flags) != set) {
|
||||||
fButtonState |= flags;
|
if (set)
|
||||||
_Update();
|
fButtonState |= flags;
|
||||||
}
|
else
|
||||||
}
|
fButtonState &= ~flags;
|
||||||
|
|
||||||
|
if ((flags & STATE_PRESSED) != 0)
|
||||||
void
|
SetValueNoUpdate(set ? B_CONTROL_ON : B_CONTROL_OFF);
|
||||||
BIconButton::_ClearFlags(uint32 flags)
|
|
||||||
{
|
|
||||||
if (_HasFlags(flags)) {
|
|
||||||
fButtonState &= ~flags;
|
|
||||||
_Update();
|
_Update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -863,3 +859,17 @@ BIconButton::_HasFlags(uint32 flags) const
|
|||||||
return (fButtonState & flags) != 0;
|
return (fButtonState & flags) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//! This one calls _Update() if needed; BControl::SetTracking() isn't virtual.
|
||||||
|
void
|
||||||
|
BIconButton::_SetTracking(bool tracking)
|
||||||
|
{
|
||||||
|
if (IsTracking() == tracking)
|
||||||
|
return;
|
||||||
|
|
||||||
|
SetTracking(tracking);
|
||||||
|
_Update();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace BPrivate
|
||||||
|
|||||||
Reference in New Issue
Block a user