*** empty log message ***
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3126 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -79,8 +79,8 @@ status_t BButton::Archive(BMessage* archive, bool deep) const
|
|||||||
if (err != B_OK)
|
if (err != B_OK)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
if (fDrawAsDefault)
|
if (IsDefault())
|
||||||
err = archive->AddBool("_default", fDrawAsDefault);
|
err = archive->AddBool("_default", true);
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
@@ -181,10 +181,7 @@ void BButton::Draw(BRect updateRect)
|
|||||||
rect.top -= 3;
|
rect.top -= 3;
|
||||||
rect.right += 2;
|
rect.right += 2;
|
||||||
rect.bottom += 2;
|
rect.bottom += 2;
|
||||||
SetDrawingMode(B_OP_INVERT);
|
InvertRect(rect);
|
||||||
SetHighColor(0, 0, 0);
|
|
||||||
FillRect(rect);
|
|
||||||
SetDrawingMode(B_OP_COPY);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Label
|
// Label
|
||||||
@@ -275,15 +272,35 @@ void BButton::Draw(BRect updateRect)
|
|||||||
void BButton::MouseDown(BPoint point)
|
void BButton::MouseDown(BPoint point)
|
||||||
{
|
{
|
||||||
if (!IsEnabled())
|
if (!IsEnabled())
|
||||||
{
|
|
||||||
BControl::MouseDown(point);
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
SetMouseEventMask(B_POINTER_EVENTS, B_NO_POINTER_HISTORY | B_SUSPEND_VIEW_FOCUS);
|
|
||||||
|
|
||||||
SetValue(B_CONTROL_ON);
|
SetValue(B_CONTROL_ON);
|
||||||
SetTracking(true);
|
|
||||||
|
if (Window()->Flags() & B_ASYNCHRONOUS_CONTROLS)
|
||||||
|
{
|
||||||
|
BRect bounds = Bounds();
|
||||||
|
uint32 buttons;
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
snooze(40000);
|
||||||
|
|
||||||
|
GetMouse(&point, &buttons, true);
|
||||||
|
|
||||||
|
bool inside = bounds.Contains(point);
|
||||||
|
|
||||||
|
if ((Value() == B_CONTROL_ON) != inside)
|
||||||
|
SetValue(inside ? B_CONTROL_ON : B_CONTROL_OFF);
|
||||||
|
} while (buttons != 0);
|
||||||
|
|
||||||
|
if (Value() == B_CONTROL_ON)
|
||||||
|
Invoke();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SetTracking(true);
|
||||||
|
SetMouseEventMask(B_POINTER_EVENTS, B_LOCK_WINDOW_FOCUS);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BButton::AttachedToWindow()
|
void BButton::AttachedToWindow()
|
||||||
@@ -294,23 +311,15 @@ void BButton::AttachedToWindow()
|
|||||||
Window()->SetDefaultButton(this);
|
Window()->SetDefaultButton(this);
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BButton::KeyDown ( const char *bytes, int32 numBytes )
|
void BButton::KeyDown(const char *bytes, int32 numBytes)
|
||||||
{
|
{
|
||||||
if (numBytes == 1)
|
if (*bytes == B_ENTER || *bytes == B_SPACE)
|
||||||
{
|
{
|
||||||
switch (bytes[0])
|
if (!IsEnabled())
|
||||||
{
|
return;
|
||||||
case B_ENTER:
|
|
||||||
case B_SPACE:
|
|
||||||
SetValue(B_CONTROL_ON);
|
|
||||||
snooze(50000);
|
|
||||||
SetValue(B_CONTROL_OFF);
|
|
||||||
Invoke();
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
SetValue(B_CONTROL_ON);
|
||||||
BControl::KeyDown(bytes, numBytes);
|
Invoke();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
BControl::KeyDown(bytes, numBytes);
|
BControl::KeyDown(bytes, numBytes);
|
||||||
@@ -318,26 +327,36 @@ void BButton::KeyDown ( const char *bytes, int32 numBytes )
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BButton::MakeDefault(bool flag)
|
void BButton::MakeDefault(bool flag)
|
||||||
{
|
{
|
||||||
if (flag == IsDefault())
|
BButton *oldDefault = NULL;
|
||||||
return;
|
|
||||||
|
|
||||||
fDrawAsDefault = flag;
|
|
||||||
BWindow *window = Window();
|
BWindow *window = Window();
|
||||||
|
|
||||||
|
if (window)
|
||||||
|
oldDefault = window->DefaultButton();
|
||||||
|
|
||||||
if (flag)
|
if (flag)
|
||||||
{
|
{
|
||||||
|
if (fDrawAsDefault && oldDefault == this)
|
||||||
|
return;
|
||||||
|
|
||||||
|
fDrawAsDefault = true;
|
||||||
|
|
||||||
ResizeBy(6.0f, 6.0f);
|
ResizeBy(6.0f, 6.0f);
|
||||||
MoveBy(-3.0f, -3.0f);
|
MoveBy(-3.0f, -3.0f);
|
||||||
|
|
||||||
if (window)
|
if (window && oldDefault != this)
|
||||||
window->SetDefaultButton((BButton*)this);
|
window->SetDefaultButton(this);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
if (!fDrawAsDefault)
|
||||||
|
return;
|
||||||
|
|
||||||
|
fDrawAsDefault = false;
|
||||||
|
|
||||||
ResizeBy(-6.0f, -6.0f);
|
ResizeBy(-6.0f, -6.0f);
|
||||||
MoveBy(3.0f, 3.0f);
|
MoveBy(3.0f, 3.0f);
|
||||||
|
|
||||||
if (window)
|
if (window && oldDefault == this)
|
||||||
window->SetDefaultButton(NULL);
|
window->SetDefaultButton(NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -364,32 +383,24 @@ void BButton::WindowActivated(bool active)
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BButton::MouseMoved(BPoint point, uint32 transit, const BMessage *message)
|
void BButton::MouseMoved(BPoint point, uint32 transit, const BMessage *message)
|
||||||
{
|
{
|
||||||
if (IsEnabled() && IsTracking())
|
if (!IsTracking())
|
||||||
{
|
return;
|
||||||
if (transit == B_EXITED_VIEW)
|
|
||||||
SetValue(B_CONTROL_OFF);
|
bool inside = Bounds().Contains(point);
|
||||||
else if (transit == B_ENTERED_VIEW)
|
|
||||||
SetValue(B_CONTROL_ON);
|
if ((Value() == B_CONTROL_ON) != inside)
|
||||||
}
|
SetValue(inside ? B_CONTROL_ON : B_CONTROL_OFF);
|
||||||
else
|
|
||||||
BControl::MouseMoved(point, transit, message);
|
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BButton::MouseUp(BPoint point)
|
void BButton::MouseUp(BPoint point)
|
||||||
{
|
{
|
||||||
if (IsEnabled() && IsTracking())
|
if (!IsTracking())
|
||||||
{
|
return;
|
||||||
if (Bounds().Contains(point))
|
|
||||||
{
|
if (Bounds().Contains(point))
|
||||||
if ( Value() == B_CONTROL_ON)
|
Invoke();
|
||||||
{
|
|
||||||
SetValue(B_CONTROL_OFF);
|
SetTracking(false);
|
||||||
Invoke();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
SetTracking(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BButton::DetachedFromWindow()
|
void BButton::DetachedFromWindow()
|
||||||
@@ -427,7 +438,14 @@ void BButton::ResizeToPreferred()
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
status_t BButton::Invoke(BMessage *message)
|
status_t BButton::Invoke(BMessage *message)
|
||||||
{
|
{
|
||||||
return BControl::Invoke(message);
|
Sync();
|
||||||
|
snooze(50000);
|
||||||
|
|
||||||
|
status_t err = BControl::Invoke(message);
|
||||||
|
|
||||||
|
SetValue(B_CONTROL_OFF);
|
||||||
|
|
||||||
|
return err;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BButton::FrameMoved(BPoint newLocation)
|
void BButton::FrameMoved(BPoint newLocation)
|
||||||
@@ -469,9 +487,8 @@ status_t BButton::GetSupportedSuites(BMessage *message)
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
status_t BButton::Perform(perform_code d, void *arg)
|
status_t BButton::Perform(perform_code d, void *arg)
|
||||||
{
|
{
|
||||||
return B_ERROR;
|
return BControl::Perform(d, arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BButton::_ReservedButton1() {}
|
void BButton::_ReservedButton1() {}
|
||||||
void BButton::_ReservedButton2() {}
|
void BButton::_ReservedButton2() {}
|
||||||
@@ -545,7 +562,10 @@ BRect BButton::DrawDefault(BRect bounds, bool enabled)
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
status_t BButton::Execute()
|
status_t BButton::Execute()
|
||||||
{
|
{
|
||||||
// TODO: Is there a use for this? Maybe visual feedback happens here?
|
if (!IsEnabled())
|
||||||
|
return B_ERROR;
|
||||||
|
|
||||||
|
SetValue(B_CONTROL_ON);
|
||||||
return Invoke();
|
return Invoke();
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -28,6 +28,7 @@
|
|||||||
|
|
||||||
// System Includes -------------------------------------------------------------
|
// System Includes -------------------------------------------------------------
|
||||||
#include <CheckBox.h>
|
#include <CheckBox.h>
|
||||||
|
#include <Window.h>
|
||||||
#include <Errors.h>
|
#include <Errors.h>
|
||||||
|
|
||||||
// Project Includes ------------------------------------------------------------
|
// Project Includes ------------------------------------------------------------
|
||||||
@@ -47,7 +48,7 @@ BCheckBox::BCheckBox(BRect frame, const char *name, const char *label,
|
|||||||
// Resize to minimum height if needed
|
// Resize to minimum height if needed
|
||||||
font_height fh;
|
font_height fh;
|
||||||
GetFontHeight(&fh);
|
GetFontHeight(&fh);
|
||||||
float minHeight = 6.0f + (float)ceil(fh.ascent + fh.descent);
|
float minHeight = (float)ceil(6.0f + fh.ascent + fh.descent);
|
||||||
if (Bounds().Height() < minHeight)
|
if (Bounds().Height() < minHeight)
|
||||||
ResizeTo(Bounds().Width(), minHeight);
|
ResizeTo(Bounds().Width(), minHeight);
|
||||||
}
|
}
|
||||||
@@ -240,17 +241,50 @@ void BCheckBox::AttachedToWindow()
|
|||||||
void BCheckBox::MouseDown(BPoint point)
|
void BCheckBox::MouseDown(BPoint point)
|
||||||
{
|
{
|
||||||
if (!IsEnabled())
|
if (!IsEnabled())
|
||||||
{
|
|
||||||
BControl::MouseDown(point);
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
SetMouseEventMask(B_POINTER_EVENTS, B_NO_POINTER_HISTORY |
|
|
||||||
B_SUSPEND_VIEW_FOCUS);
|
|
||||||
|
|
||||||
fOutlined = true;
|
fOutlined = true;
|
||||||
SetTracking(true);
|
Draw(Bounds());
|
||||||
Invalidate();
|
Flush();
|
||||||
|
|
||||||
|
if (Window()->Flags() & B_ASYNCHRONOUS_CONTROLS)
|
||||||
|
{
|
||||||
|
BRect bounds = Bounds();
|
||||||
|
uint32 buttons;
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
snooze(40000);
|
||||||
|
|
||||||
|
GetMouse(&point, &buttons, true);
|
||||||
|
|
||||||
|
bool inside = bounds.Contains(point);
|
||||||
|
|
||||||
|
if (fOutlined != inside)
|
||||||
|
{
|
||||||
|
fOutlined = inside;
|
||||||
|
Draw(Bounds());
|
||||||
|
Flush();
|
||||||
|
}
|
||||||
|
} while (buttons != 0);
|
||||||
|
|
||||||
|
if (fOutlined)
|
||||||
|
{
|
||||||
|
fOutlined = false;
|
||||||
|
SetValue(!Value());
|
||||||
|
Invoke();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Draw(Bounds());
|
||||||
|
Flush();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SetTracking(true);
|
||||||
|
SetMouseEventMask(B_POINTER_EVENTS, B_LOCK_WINDOW_FOCUS);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BCheckBox::MessageReceived(BMessage *message)
|
void BCheckBox::MessageReceived(BMessage *message)
|
||||||
@@ -270,41 +304,50 @@ void BCheckBox::KeyDown(const char *bytes, int32 numBytes)
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BCheckBox::MouseUp(BPoint point)
|
void BCheckBox::MouseUp(BPoint point)
|
||||||
{
|
{
|
||||||
if (IsEnabled() && IsTracking())
|
if (!IsTracking())
|
||||||
{
|
|
||||||
fOutlined = false;
|
|
||||||
|
|
||||||
if (Bounds().Contains(point))
|
|
||||||
{
|
|
||||||
if (Value() == B_CONTROL_OFF)
|
|
||||||
SetValue(B_CONTROL_ON);
|
|
||||||
else
|
|
||||||
SetValue(B_CONTROL_OFF);
|
|
||||||
|
|
||||||
BControl::Invoke();
|
|
||||||
}
|
|
||||||
SetTracking(false);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
BControl::MouseUp(point);
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
bool inside = Bounds().Contains(point);
|
||||||
|
|
||||||
|
if (fOutlined != inside)
|
||||||
|
{
|
||||||
|
fOutlined = inside;
|
||||||
|
Draw(Bounds());
|
||||||
|
Flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (fOutlined)
|
||||||
|
{
|
||||||
|
if (fOutlined)
|
||||||
|
{
|
||||||
|
fOutlined = false;
|
||||||
|
SetValue(!Value());
|
||||||
|
Invoke();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Draw(Bounds());
|
||||||
|
Flush();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SetTracking(false);
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BCheckBox::MouseMoved(BPoint point, uint32 transit, const BMessage *message)
|
void BCheckBox::MouseMoved(BPoint point, uint32 transit,
|
||||||
|
const BMessage *message)
|
||||||
{
|
{
|
||||||
if (IsEnabled() && IsTracking())
|
if (!IsTracking())
|
||||||
{
|
return;
|
||||||
if (transit == B_EXITED_VIEW)
|
|
||||||
fOutlined = false;
|
|
||||||
else if (transit == B_ENTERED_VIEW)
|
|
||||||
fOutlined = true;
|
|
||||||
|
|
||||||
Invalidate();
|
bool inside = Bounds().Contains(point);
|
||||||
|
|
||||||
|
if (fOutlined != inside)
|
||||||
|
{
|
||||||
|
fOutlined = inside;
|
||||||
|
Draw(Bounds());
|
||||||
|
Flush();
|
||||||
}
|
}
|
||||||
else
|
|
||||||
BControl::MouseMoved(point, transit, message);
|
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BCheckBox::DetachedFromWindow()
|
void BCheckBox::DetachedFromWindow()
|
||||||
@@ -322,8 +365,13 @@ void BCheckBox::GetPreferredSize(float *width, float *height)
|
|||||||
font_height fh;
|
font_height fh;
|
||||||
GetFontHeight(&fh);
|
GetFontHeight(&fh);
|
||||||
|
|
||||||
*height = 6.0f + (float)ceil(fh.ascent + fh.descent);
|
*height = (float)ceil(6.0f + fh.ascent + fh.descent);
|
||||||
*width = 12.0f + (float)ceil(fh.ascent) + (float)ceil(StringWidth(Label()));
|
*width = 12.0f + fh.ascent;
|
||||||
|
|
||||||
|
if (Label())
|
||||||
|
*width += StringWidth(Label());
|
||||||
|
|
||||||
|
*width = (float)ceil(*width);
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BCheckBox::ResizeToPreferred()
|
void BCheckBox::ResizeToPreferred()
|
||||||
@@ -375,7 +423,7 @@ void BCheckBox::AllDetached()
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
status_t BCheckBox::Perform(perform_code d, void *arg)
|
status_t BCheckBox::Perform(perform_code d, void *arg)
|
||||||
{
|
{
|
||||||
return B_ERROR;
|
return BControl::Perform(d, arg);
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BCheckBox::_ReservedCheckBox1() {}
|
void BCheckBox::_ReservedCheckBox1() {}
|
||||||
|
|||||||
+166
-172
@@ -89,50 +89,51 @@ static property_info prop_list[] =
|
|||||||
};
|
};
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
BControl::BControl(BRect frame, const char *name, const char *label, BMessage *message,
|
BControl::BControl(BRect frame, const char *name, const char *label,
|
||||||
uint32 resizingMode, uint32 flags)
|
BMessage *message, uint32 resizingMode, uint32 flags)
|
||||||
: BView(frame, name, resizingMode, flags),
|
: BView(frame, name, resizingMode, flags)
|
||||||
BInvoker(message, NULL),
|
|
||||||
fValue(B_CONTROL_OFF),
|
|
||||||
fEnabled(true),
|
|
||||||
fFocusChanging(false),
|
|
||||||
fTracking(false),
|
|
||||||
fWantsNav(true)
|
|
||||||
{
|
{
|
||||||
fLabel = strdup(label);
|
InitData(NULL);
|
||||||
|
|
||||||
|
SetLabel(label);
|
||||||
|
SetMessage(message);
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
BControl::~BControl()
|
BControl::~BControl()
|
||||||
{
|
{
|
||||||
if (fLabel)
|
if (fLabel)
|
||||||
free(fLabel);
|
free(fLabel);
|
||||||
|
|
||||||
|
SetMessage(NULL);
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
BControl::BControl(BMessage *archive) : BView(archive)
|
BControl::BControl(BMessage *archive)
|
||||||
|
: BView(archive)
|
||||||
{
|
{
|
||||||
const char *label;
|
InitData(archive);
|
||||||
|
|
||||||
if (archive->FindInt32("_val", &fValue) != B_OK)
|
|
||||||
fValue = B_CONTROL_OFF;
|
|
||||||
|
|
||||||
if (archive->FindString("_label", &label) != B_OK)
|
|
||||||
fLabel = NULL;
|
|
||||||
else
|
|
||||||
SetLabel(label);
|
|
||||||
|
|
||||||
if ( archive->FindBool("_disable", &fEnabled) != B_OK)
|
|
||||||
fEnabled = true;
|
|
||||||
else
|
|
||||||
fEnabled = !fEnabled;
|
|
||||||
|
|
||||||
fFocusChanging = false;
|
|
||||||
fTracking = false;
|
|
||||||
fWantsNav = true;
|
|
||||||
|
|
||||||
BMessage message;
|
BMessage message;
|
||||||
|
|
||||||
if (archive->FindMessage("_msg", &message) == B_OK)
|
if (archive->FindMessage("_msg", &message) == B_OK)
|
||||||
SetMessage(new BMessage(message));
|
SetMessage(new BMessage(message));
|
||||||
|
|
||||||
|
const char *label;
|
||||||
|
|
||||||
|
if (archive->FindString("_label", &label) != B_OK)
|
||||||
|
SetLabel(label);
|
||||||
|
|
||||||
|
int32 value;
|
||||||
|
|
||||||
|
if (archive->FindInt32("_val", &value) != B_OK)
|
||||||
|
SetValue(value);
|
||||||
|
|
||||||
|
bool toggle;
|
||||||
|
|
||||||
|
if (archive->FindBool("_disable", &toggle) != B_OK)
|
||||||
|
SetEnabled(!toggle);
|
||||||
|
|
||||||
|
if (archive->FindBool("be:wants_nav", &toggle) != B_OK)
|
||||||
|
fWantsNav = toggle;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
BArchivable *BControl::Instantiate(BMessage *archive)
|
BArchivable *BControl::Instantiate(BMessage *archive)
|
||||||
@@ -176,21 +177,23 @@ status_t BControl::Archive(BMessage *archive, bool deep) const
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BControl::WindowActivated(bool active)
|
void BControl::WindowActivated(bool active)
|
||||||
{
|
{
|
||||||
if (IsFocus())
|
|
||||||
{
|
|
||||||
Draw(Bounds());
|
|
||||||
Flush();
|
|
||||||
}
|
|
||||||
|
|
||||||
BView::WindowActivated(active);
|
BView::WindowActivated(active);
|
||||||
|
|
||||||
|
if (IsFocus())
|
||||||
|
Draw(Bounds());
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BControl::AttachedToWindow()
|
void BControl::AttachedToWindow()
|
||||||
{
|
{
|
||||||
if (Parent())
|
if (Parent())
|
||||||
SetViewColor(Parent()->ViewColor());
|
{
|
||||||
|
rgb_color color = Parent()->ViewColor();
|
||||||
|
|
||||||
if (Target() == NULL)
|
SetViewColor(color);
|
||||||
|
SetLowColor(color);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Messenger().IsValid())
|
||||||
BInvoker::SetTarget(BMessenger(Window(), NULL));
|
BInvoker::SetTarget(BMessenger(Window(), NULL));
|
||||||
|
|
||||||
BView::AttachedToWindow();
|
BView::AttachedToWindow();
|
||||||
@@ -198,89 +201,90 @@ void BControl::AttachedToWindow()
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BControl::MessageReceived(BMessage *message)
|
void BControl::MessageReceived(BMessage *message)
|
||||||
{
|
{
|
||||||
switch (message->what)
|
bool handled = false;
|
||||||
|
BMessage reply(B_REPLY);
|
||||||
|
|
||||||
|
if (message->what == B_GET_PROPERTY || message->what == B_SET_PROPERTY)
|
||||||
{
|
{
|
||||||
case B_CONTROL_INVOKED:
|
BPropertyInfo propInfo(prop_list);
|
||||||
Invoke();
|
BMessage specifier;
|
||||||
break;
|
int32 index;
|
||||||
|
int32 form;
|
||||||
|
const char *property;
|
||||||
|
|
||||||
case B_GET_PROPERTY:
|
if (message->GetCurrentSpecifier(&index, &specifier, &form, &property) == B_OK)
|
||||||
case B_SET_PROPERTY:
|
|
||||||
{
|
{
|
||||||
BPropertyInfo propInfo(prop_list);
|
if (strcmp(property, "Label") == 0)
|
||||||
BMessage specifier;
|
|
||||||
const char *property;
|
|
||||||
|
|
||||||
if (message->GetCurrentSpecifier(NULL, &specifier) != B_OK ||
|
|
||||||
specifier.FindString("property", &property) != B_OK)
|
|
||||||
return;
|
|
||||||
|
|
||||||
switch (propInfo.FindMatch(message, 0, &specifier, specifier.what, property))
|
|
||||||
{
|
{
|
||||||
case B_ERROR:
|
if (message->what == B_GET_PROPERTY)
|
||||||
{
|
{
|
||||||
BView::MessageReceived(message);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 0:
|
|
||||||
{
|
|
||||||
BMessage reply;
|
|
||||||
reply.AddBool("result", fEnabled);
|
|
||||||
reply.AddBool("error", B_OK);
|
|
||||||
message->SendReply(&reply);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 1:
|
|
||||||
{
|
|
||||||
bool enabled;
|
|
||||||
message->FindBool("data", &enabled);
|
|
||||||
SetEnabled(enabled);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 2:
|
|
||||||
{
|
|
||||||
BMessage reply;
|
|
||||||
reply.AddString("result", fLabel);
|
reply.AddString("result", fLabel);
|
||||||
reply.AddBool("error", B_OK);
|
handled = true;
|
||||||
message->SendReply(&reply);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
case 3:
|
else
|
||||||
{
|
{
|
||||||
const char *label;
|
const char *label;
|
||||||
message->FindString("data", &label);
|
|
||||||
SetLabel(label);
|
if (message->FindString("data", &label) == B_OK)
|
||||||
break;
|
{
|
||||||
}
|
SetLabel(label);
|
||||||
case 4:
|
reply.AddInt32("error", B_OK);
|
||||||
{
|
handled = true;
|
||||||
BMessage reply;
|
}
|
||||||
reply.AddInt32("result", fValue);
|
}
|
||||||
reply.AddBool("error", B_OK);
|
}
|
||||||
message->SendReply(&reply);
|
else if (strcmp(property, "Value") == 0)
|
||||||
break;
|
{
|
||||||
}
|
if (message->what == B_GET_PROPERTY)
|
||||||
case 5:
|
{
|
||||||
{
|
reply.AddInt32("result", fValue);
|
||||||
int32 value;
|
handled = true;
|
||||||
message->FindInt32("data", &value);
|
}
|
||||||
SetValue(value);
|
else
|
||||||
break;
|
{
|
||||||
|
int32 value;
|
||||||
|
|
||||||
|
if (message->FindInt32("data", &value) == B_OK)
|
||||||
|
{
|
||||||
|
SetValue(value);
|
||||||
|
reply.AddInt32("error", B_OK);
|
||||||
|
handled = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (strcmp(property, "Enabled") == 0)
|
||||||
|
{
|
||||||
|
if (message->what == B_GET_PROPERTY)
|
||||||
|
{
|
||||||
|
reply.AddBool("result", fEnabled);
|
||||||
|
handled = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
bool enabled;
|
||||||
|
|
||||||
|
if (message->FindBool("data", &enabled) == B_OK)
|
||||||
|
{
|
||||||
|
SetEnabled(enabled);
|
||||||
|
reply.AddInt32("error", B_OK);
|
||||||
|
handled = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
BView::MessageReceived(message);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (handled)
|
||||||
|
message->SendReply(&reply);
|
||||||
|
else
|
||||||
|
BView::MessageReceived(message);
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BControl::MakeFocus(bool focused)
|
void BControl::MakeFocus(bool focused)
|
||||||
{
|
{
|
||||||
|
if (focused == IsFocus())
|
||||||
|
return;
|
||||||
|
|
||||||
BView::MakeFocus(focused);
|
BView::MakeFocus(focused);
|
||||||
|
|
||||||
if(Window())
|
if(Window())
|
||||||
@@ -294,23 +298,17 @@ void BControl::MakeFocus(bool focused)
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BControl::KeyDown(const char *bytes, int32 numBytes)
|
void BControl::KeyDown(const char *bytes, int32 numBytes)
|
||||||
{
|
{
|
||||||
if (numBytes == 1)
|
if (*bytes == B_ENTER || *bytes == B_SPACE)
|
||||||
{
|
{
|
||||||
switch (bytes[0])
|
if (!fEnabled)
|
||||||
{
|
return;
|
||||||
case B_ENTER:
|
|
||||||
case B_SPACE:
|
|
||||||
if (Value())
|
|
||||||
SetValue(B_CONTROL_OFF);
|
|
||||||
else
|
|
||||||
SetValue(B_CONTROL_ON);
|
|
||||||
|
|
||||||
BInvoker::Invoke();
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
if (Value())
|
||||||
BView::KeyDown(bytes, numBytes);
|
SetValue(B_CONTROL_OFF);
|
||||||
}
|
else
|
||||||
|
SetValue(B_CONTROL_ON);
|
||||||
|
|
||||||
|
Invoke();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
BView::KeyDown(bytes, numBytes);
|
BView::KeyDown(bytes, numBytes);
|
||||||
@@ -338,13 +336,16 @@ void BControl::DetachedFromWindow()
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BControl::SetLabel(const char *string)
|
void BControl::SetLabel(const char *string)
|
||||||
{
|
{
|
||||||
if (strcmp(fLabel, string) == 0)
|
if (fLabel && string && strcmp(fLabel, string) == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (fLabel)
|
if (fLabel)
|
||||||
free(fLabel);
|
free(fLabel);
|
||||||
|
|
||||||
fLabel = strdup(string);
|
if (string)
|
||||||
|
fLabel = strdup(string);
|
||||||
|
else
|
||||||
|
fLabel = NULL;
|
||||||
|
|
||||||
Invalidate();
|
Invalidate();
|
||||||
}
|
}
|
||||||
@@ -399,8 +400,7 @@ bool BControl::IsEnabled() const
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BControl::GetPreferredSize(float *width, float *height)
|
void BControl::GetPreferredSize(float *width, float *height)
|
||||||
{
|
{
|
||||||
*width = 1.0f;
|
BView::GetPreferredSize(width, height);
|
||||||
*height = 1.0f;
|
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BControl::ResizeToPreferred()
|
void BControl::ResizeToPreferred()
|
||||||
@@ -410,22 +410,35 @@ void BControl::ResizeToPreferred()
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
status_t BControl::Invoke(BMessage *message)
|
status_t BControl::Invoke(BMessage *message)
|
||||||
{
|
{
|
||||||
if (message)
|
bool notify = false;
|
||||||
{
|
uint32 kind = InvokeKind(¬ify);
|
||||||
BMessage copy(*message);
|
|
||||||
copy.AddInt64("when", (int64)system_time());
|
|
||||||
copy.AddPointer("source", this);
|
|
||||||
return BInvoker::Invoke(©);
|
|
||||||
}
|
|
||||||
else if ( Message () )
|
|
||||||
{
|
|
||||||
BMessage copy (*Message());
|
|
||||||
copy.AddInt64 ("when", (int64)system_time());
|
|
||||||
copy.AddPointer ("source", this);
|
|
||||||
return BInvoker::Invoke(©);
|
|
||||||
}
|
|
||||||
|
|
||||||
return B_BAD_VALUE;
|
BMessage clone(kind);
|
||||||
|
status_t err = B_BAD_VALUE;
|
||||||
|
|
||||||
|
if (!message && !notify)
|
||||||
|
message = Message();
|
||||||
|
|
||||||
|
if (!message)
|
||||||
|
{
|
||||||
|
if (!IsWatched())
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
clone = *message;
|
||||||
|
|
||||||
|
clone.AddInt64("when", (int64)system_time());
|
||||||
|
clone.AddPointer("source", this);
|
||||||
|
clone.AddInt32("be:value", fValue);
|
||||||
|
clone.AddMessenger("be:sender", BMessenger(this));
|
||||||
|
|
||||||
|
if (message)
|
||||||
|
err = BInvoker::Invoke(&clone);
|
||||||
|
|
||||||
|
// TODO: assynchronous messaging
|
||||||
|
// SendNotices(kind, &clone);
|
||||||
|
|
||||||
|
return err;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
BHandler *BControl::ResolveSpecifier(BMessage *message, int32 index,
|
BHandler *BControl::ResolveSpecifier(BMessage *message, int32 index,
|
||||||
@@ -433,47 +446,20 @@ BHandler *BControl::ResolveSpecifier(BMessage *message, int32 index,
|
|||||||
const char *property)
|
const char *property)
|
||||||
{
|
{
|
||||||
BPropertyInfo propInfo(prop_list);
|
BPropertyInfo propInfo(prop_list);
|
||||||
BHandler *target = NULL;
|
|
||||||
|
|
||||||
switch (propInfo.FindMatch(message, 0, specifier, what, property))
|
if (propInfo.FindMatch(message, 0, specifier, what, property) < B_OK)
|
||||||
{
|
return BView::ResolveSpecifier(message, index, specifier, what,
|
||||||
case B_ERROR:
|
property);
|
||||||
break;
|
else
|
||||||
|
return this;
|
||||||
case 0:
|
|
||||||
case 1:
|
|
||||||
case 2:
|
|
||||||
case 3:
|
|
||||||
case 4:
|
|
||||||
case 5:
|
|
||||||
target = this;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!target)
|
|
||||||
target = BView::ResolveSpecifier(message, index, specifier, what,
|
|
||||||
property);
|
|
||||||
|
|
||||||
return target;
|
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
status_t BControl::GetSupportedSuites(BMessage *message)
|
status_t BControl::GetSupportedSuites(BMessage *message)
|
||||||
{
|
{
|
||||||
status_t err;
|
message->AddString("suites", "suite/vnd.Be-control");
|
||||||
|
|
||||||
if (message == NULL)
|
|
||||||
return B_BAD_VALUE;
|
|
||||||
|
|
||||||
err = message->AddString("suites", "suite/vnd.Be-control");
|
|
||||||
|
|
||||||
if (err != B_OK)
|
|
||||||
return err;
|
|
||||||
|
|
||||||
BPropertyInfo prop_info(prop_list);
|
BPropertyInfo prop_info(prop_list);
|
||||||
err = message->AddFlat("messages", &prop_info);
|
message->AddFlat("messages", &prop_info);
|
||||||
|
|
||||||
if (err != B_OK)
|
|
||||||
return err;
|
|
||||||
|
|
||||||
return BView::GetSupportedSuites(message);
|
return BView::GetSupportedSuites(message);
|
||||||
}
|
}
|
||||||
@@ -490,7 +476,7 @@ void BControl::AllDetached()
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
status_t BControl::Perform(perform_code d, void *arg)
|
status_t BControl::Perform(perform_code d, void *arg)
|
||||||
{
|
{
|
||||||
return B_ERROR;
|
return BView::Perform(d, arg);
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
bool BControl::IsFocusChanging() const
|
bool BControl::IsFocusChanging() const
|
||||||
@@ -526,7 +512,15 @@ BControl &BControl::operator=(const BControl &)
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BControl::InitData(BMessage *data)
|
void BControl::InitData(BMessage *data)
|
||||||
{
|
{
|
||||||
|
fLabel = NULL;
|
||||||
|
fValue = B_CONTROL_OFF;
|
||||||
|
fEnabled = true;
|
||||||
|
fFocusChanging = false;
|
||||||
|
fTracking = false;
|
||||||
|
fWantsNav = true;
|
||||||
|
|
||||||
|
if (data && data->HasString("_fname"))
|
||||||
|
SetFont(be_plain_font, B_FONT_FAMILY_AND_STYLE);
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user