- Simplified the logic in Draw, and other small fixes, thanks Karsten!
- Disabled_off picture wasn't archived/unarchived in one_state_mode. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27161 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -16,18 +16,22 @@ BPictureButton::BPictureButton(BRect frame, const char* name,
|
|||||||
BPicture *off, BPicture *on, BMessage *message,
|
BPicture *off, BPicture *on, BMessage *message,
|
||||||
uint32 behavior, uint32 resizeMask, uint32 flags)
|
uint32 behavior, uint32 resizeMask, uint32 flags)
|
||||||
: BControl(frame, name, "", message, resizeMask, flags),
|
: BControl(frame, name, "", message, resizeMask, flags),
|
||||||
|
fDisabledOff(NULL),
|
||||||
|
fDisabledOn(NULL),
|
||||||
fOutlined(false),
|
fOutlined(false),
|
||||||
fBehavior(behavior)
|
fBehavior(behavior)
|
||||||
{
|
{
|
||||||
fEnabledOff = new BPicture(*off);
|
fEnabledOff = new BPicture(*off);
|
||||||
fEnabledOn = new BPicture(*on);
|
fEnabledOn = new BPicture(*on);
|
||||||
fDisabledOff = NULL;
|
|
||||||
fDisabledOn = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BPictureButton::BPictureButton(BMessage *data)
|
BPictureButton::BPictureButton(BMessage *data)
|
||||||
: BControl(data)
|
: BControl(data),
|
||||||
|
fEnabledOff(NULL),
|
||||||
|
fEnabledOn(NULL),
|
||||||
|
fDisabledOff(NULL),
|
||||||
|
fDisabledOn(NULL)
|
||||||
{
|
{
|
||||||
BMessage pictureArchive;
|
BMessage pictureArchive;
|
||||||
|
|
||||||
@@ -42,14 +46,11 @@ BPictureButton::BPictureButton(BMessage *data)
|
|||||||
if (data->FindMessage("_e_off", &pictureArchive) == B_OK)
|
if (data->FindMessage("_e_off", &pictureArchive) == B_OK)
|
||||||
fEnabledOff = new BPicture(&pictureArchive);
|
fEnabledOff = new BPicture(&pictureArchive);
|
||||||
|
|
||||||
if (fBehavior == B_TWO_STATE_BUTTON) {
|
if (data->FindMessage("_d_on", &pictureArchive) == B_OK)
|
||||||
if (data->FindMessage("_d_on", &pictureArchive) == B_OK)
|
fDisabledOn = new BPicture(&pictureArchive);
|
||||||
fDisabledOn = new BPicture(&pictureArchive);
|
|
||||||
|
|
||||||
if (data->FindMessage("_d_off", &pictureArchive) == B_OK)
|
if (data->FindMessage("_d_off", &pictureArchive) == B_OK)
|
||||||
fDisabledOff = new BPicture(&pictureArchive);
|
fDisabledOff = new BPicture(&pictureArchive);
|
||||||
} else
|
|
||||||
fDisabledOn = fDisabledOff = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -95,19 +96,16 @@ BPictureButton::Archive(BMessage *data, bool deep) const
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do we add messages for pictures that don't exist?
|
if (fDisabledOn && fDisabledOn->Archive(&pictureArchive, deep) == B_OK) {
|
||||||
if (fBehavior == B_TWO_STATE_BUTTON) {
|
err = data->AddMessage("_d_on", &pictureArchive);
|
||||||
if (fDisabledOn->Archive(&pictureArchive, deep) == B_OK) {
|
if (err != B_OK)
|
||||||
err = data->AddMessage("_d_on", &pictureArchive);
|
return err;
|
||||||
if (err != B_OK)
|
}
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fDisabledOff->Archive(&pictureArchive, deep) == B_OK) {
|
if (fDisabledOff && fDisabledOff->Archive(&pictureArchive, deep) == B_OK) {
|
||||||
err = data->AddMessage("_d_off", &pictureArchive);
|
err = data->AddMessage("_d_off", &pictureArchive);
|
||||||
if (err != B_OK)
|
if (err != B_OK)
|
||||||
return err;
|
return err;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,46 +118,24 @@ BPictureButton::Draw(BRect updateRect)
|
|||||||
{
|
{
|
||||||
BRect rect = Bounds();
|
BRect rect = Bounds();
|
||||||
|
|
||||||
// Need to check if TWO_STATE, if setEnabled=false, and if diabled picture is null
|
|
||||||
// If so, and in debug, bring up an Alert, if so, and not in debug, output to stdout
|
|
||||||
|
|
||||||
// We should request the view's base color which normaly is (216,216,216)
|
// We should request the view's base color which normaly is (216,216,216)
|
||||||
rgb_color color = ui_color(B_PANEL_BACKGROUND_COLOR);
|
rgb_color color = ui_color(B_PANEL_BACKGROUND_COLOR);
|
||||||
|
|
||||||
if (fBehavior == B_ONE_STATE_BUTTON) {
|
if (IsEnabled()) {
|
||||||
|
if (Value() == B_CONTROL_ON)
|
||||||
if (IsEnabled()) {
|
DrawPicture(fEnabledOn);
|
||||||
if (Value() == B_CONTROL_ON)
|
else
|
||||||
DrawPicture(fEnabledOn);
|
DrawPicture(fEnabledOff);
|
||||||
else
|
|
||||||
DrawPicture(fEnabledOff);
|
|
||||||
} else
|
|
||||||
DrawPicture(fDisabledOff);
|
|
||||||
//a disabled one_state_button is always OFF (ie: not pushed)
|
|
||||||
//since it cannot be pushed while disabled
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// B_TWO_STATE_BUTTON
|
|
||||||
|
if (fDisabledOff == NULL
|
||||||
if (IsEnabled()) {
|
|| (fDisabledOn == NULL && fBehavior == B_TWO_STATE_BUTTON))
|
||||||
if (Value() == B_CONTROL_ON)
|
debugger("Need to set the 'disabled' pictures for this BPictureButton ");
|
||||||
DrawPicture(fEnabledOn);
|
|
||||||
else
|
if (Value() == B_CONTROL_ON)
|
||||||
DrawPicture(fEnabledOff);
|
DrawPicture(fDisabledOn);
|
||||||
} else {
|
else
|
||||||
// disabled
|
DrawPicture(fDisabledOff);
|
||||||
if (Value() == B_CONTROL_ON) {
|
|
||||||
if (fDisabledOn == NULL)
|
|
||||||
debugger("Need to set the 'disabled' pictures for this BPictureButton ");
|
|
||||||
|
|
||||||
DrawPicture(fDisabledOn);
|
|
||||||
} else {
|
|
||||||
if (fDisabledOn == NULL)
|
|
||||||
debugger("Need to set the 'disabled' pictures for this BPictureButton ");
|
|
||||||
|
|
||||||
DrawPicture(fDisabledOff);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IsFocus()) {
|
if (IsFocus()) {
|
||||||
@@ -398,9 +374,7 @@ BPictureButton::GetSupportedSuites(BMessage *data)
|
|||||||
void
|
void
|
||||||
BPictureButton::ResizeToPreferred()
|
BPictureButton::ResizeToPreferred()
|
||||||
{
|
{
|
||||||
float width, height;
|
BControl::ResizeToPreferred();
|
||||||
GetPreferredSize(&width, &height);
|
|
||||||
BControl::ResizeTo(width, height);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -434,10 +408,9 @@ BPictureButton::AllDetached()
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
BPictureButton::Perform (perform_code d, void *arg)
|
BPictureButton::Perform(perform_code d, void *arg)
|
||||||
{
|
{
|
||||||
// Really clutching at straws here....
|
return BControl::Perform(d, arg);
|
||||||
return B_ERROR;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user