Switch synchronous and asynchronous mouse tracking code as it was wrongly placed. Style changes.

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@10517 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stefano Ceccherini
2004-12-23 12:13:56 +00:00
parent b88dbb0c84
commit bc6981cc74
+138 -131
View File
@@ -23,70 +23,64 @@
// Author: Marc Flerackers ([email protected]) // Author: Marc Flerackers ([email protected])
// Description: BCheckBox displays an on/off control. // Description: BCheckBox displays an on/off control.
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Standard Includes -----------------------------------------------------------
// System Includes -------------------------------------------------------------
#include <CheckBox.h> #include <CheckBox.h>
#include <Window.h> #include <Window.h>
#include <Errors.h>
// Project Includes ------------------------------------------------------------
// Local Includes --------------------------------------------------------------
// Local Defines ---------------------------------------------------------------
// Globals ---------------------------------------------------------------------
//------------------------------------------------------------------------------
BCheckBox::BCheckBox(BRect frame, const char *name, const char *label, BCheckBox::BCheckBox(BRect frame, const char *name, const char *label,
BMessage *message, uint32 resizingMode, uint32 flags) BMessage *message, uint32 resizingMode, uint32 flags)
: BControl(frame, name, label, message, resizingMode, flags), : BControl(frame, name, label, message, resizingMode, flags),
fOutlined(false) fOutlined(false)
{ {
// Resize to minimum height if needed // Resize to minimum height if needed
font_height fh; font_height fontHeight;
GetFontHeight(&fh); GetFontHeight(&fontHeight);
float minHeight = (float)ceil(6.0f + fh.ascent + fh.descent); float minHeight = (float)ceil(6.0f + fontHeight.ascent + fontHeight.descent);
if (Bounds().Height() < minHeight) if (Bounds().Height() < minHeight)
ResizeTo(Bounds().Width(), minHeight); ResizeTo(Bounds().Width(), minHeight);
} }
//------------------------------------------------------------------------------
BCheckBox::~BCheckBox() BCheckBox::~BCheckBox()
{ {
} }
//------------------------------------------------------------------------------
BCheckBox::BCheckBox(BMessage *archive) BCheckBox::BCheckBox(BMessage *archive)
: BControl(archive), : BControl(archive),
fOutlined(false) fOutlined(false)
{ {
} }
//------------------------------------------------------------------------------
BArchivable *BCheckBox::Instantiate(BMessage *archive)
BArchivable *
BCheckBox::Instantiate(BMessage *archive)
{ {
if (validate_instantiation(archive, "BCheckBox")) if (validate_instantiation(archive, "BCheckBox"))
return new BCheckBox(archive); return new BCheckBox(archive);
else else
return NULL; return NULL;
} }
//------------------------------------------------------------------------------
status_t BCheckBox::Archive(BMessage *archive, bool deep) const
status_t
BCheckBox::Archive(BMessage *archive, bool deep) const
{ {
return BControl::Archive(archive,deep); return BControl::Archive(archive,deep);
} }
//------------------------------------------------------------------------------
void BCheckBox::Draw(BRect updateRect)
void
BCheckBox::Draw(BRect updateRect)
{ {
font_height fh; font_height fontHeight;
GetFontHeight(&fh); GetFontHeight(&fontHeight);
// If the focus is changing, just redraw the focus indicator // If the focus is changing, just redraw the focus indicator
if (IsFocusChanging()) if (IsFocusChanging()) {
{ float x = (float)ceil(10.0f + fontHeight.ascent);
float x = (float)ceil(10.0f + fh.ascent); float y = 5.0f + (float)ceil(fontHeight.ascent);
float y = 5.0f + (float)ceil(fh.ascent);
if (IsFocus()) if (IsFocus())
SetHighColor(ui_color(B_KEYBOARD_NAVIGATION_COLOR)); SetHighColor(ui_color(B_KEYBOARD_NAVIGATION_COLOR));
@@ -107,18 +101,16 @@ void BCheckBox::Draw(BRect updateRect)
darken4 = tint_color(no_tint, B_DARKEN_4_TINT), darken4 = tint_color(no_tint, B_DARKEN_4_TINT),
darkenmax = tint_color(no_tint, B_DARKEN_MAX_TINT); darkenmax = tint_color(no_tint, B_DARKEN_MAX_TINT);
BRect rect(1.0f, 3.0f, (float)ceil(3.0f + fh.ascent), BRect rect(1.0f, 3.0f, (float)ceil(3.0f + fontHeight.ascent),
(float)ceil(5.0f + fh.ascent)); (float)ceil(5.0f + fontHeight.ascent));
if (IsEnabled()) if (IsEnabled()) {
{
// Filling // Filling
SetHighColor(lightenmax); SetHighColor(lightenmax);
FillRect(rect); FillRect(rect);
// Box // Box
if (fOutlined) if (fOutlined) {
{
SetHighColor(darken3); SetHighColor(darken3);
StrokeRect(rect); StrokeRect(rect);
@@ -136,9 +128,7 @@ void BCheckBox::Draw(BRect updateRect)
BPoint(rect.right, rect.top), darken4); BPoint(rect.right, rect.top), darken4);
EndLineArray(); EndLineArray();
} } else {
else
{
BeginLineArray(6); BeginLineArray(6);
AddLine(BPoint(rect.left, rect.bottom), AddLine(BPoint(rect.left, rect.bottom),
@@ -159,8 +149,7 @@ void BCheckBox::Draw(BRect updateRect)
} }
// Checkmark // Checkmark
if (Value() == B_CONTROL_ON) if (Value() == B_CONTROL_ON) {
{
rect.InsetBy(2,2); rect.InsetBy(2,2);
SetHighColor(ui_color(B_KEYBOARD_NAVIGATION_COLOR)); SetHighColor(ui_color(B_KEYBOARD_NAVIGATION_COLOR));
@@ -174,21 +163,18 @@ void BCheckBox::Draw(BRect updateRect)
// Label // Label
SetHighColor(darkenmax); SetHighColor(darkenmax);
DrawString(Label(), BPoint((float)ceil(10.0f + fh.ascent), DrawString(Label(), BPoint((float)ceil(10.0f + fontHeight.ascent),
3.0f + (float)ceil(fh.ascent))); 3.0f + (float)ceil(fontHeight.ascent)));
// Focus // Focus
if (IsFocus()) if (IsFocus()) {
{ float x = (float)ceil(10.0f + fontHeight.ascent);
float x = (float)ceil(10.0f + fh.ascent); float y = 5.0f + (float)ceil(fontHeight.ascent);
float y = 5.0f + (float)ceil(fh.ascent);
SetHighColor(ui_color(B_KEYBOARD_NAVIGATION_COLOR)); SetHighColor(ui_color(B_KEYBOARD_NAVIGATION_COLOR));
StrokeLine(BPoint(x, y), BPoint(x + StringWidth(Label()), y)); StrokeLine(BPoint(x, y), BPoint(x + StringWidth(Label()), y));
} }
} } else {
else
{
// Filling // Filling
SetHighColor(lighten1); SetHighColor(lighten1);
FillRect(rect); FillRect(rect);
@@ -213,8 +199,7 @@ void BCheckBox::Draw(BRect updateRect)
EndLineArray(); EndLineArray();
// Checkmark // Checkmark
if (Value() == B_CONTROL_ON) if (Value() == B_CONTROL_ON) {
{
rect.InsetBy(2, 2); rect.InsetBy(2, 2);
SetHighColor(tint_color(ui_color(B_KEYBOARD_NAVIGATION_COLOR), SetHighColor(tint_color(ui_color(B_KEYBOARD_NAVIGATION_COLOR),
@@ -229,17 +214,21 @@ void BCheckBox::Draw(BRect updateRect)
// Label // Label
SetHighColor(tint_color(no_tint, B_DISABLED_LABEL_TINT)); SetHighColor(tint_color(no_tint, B_DISABLED_LABEL_TINT));
DrawString(Label(), BPoint((float)ceil(10.0f + fh.ascent), DrawString(Label(), BPoint((float)ceil(10.0f + fontHeight.ascent),
3.0f + (float)ceil(fh.ascent))); 3.0f + (float)ceil(fontHeight.ascent)));
} }
} }
//------------------------------------------------------------------------------
void BCheckBox::AttachedToWindow()
void
BCheckBox::AttachedToWindow()
{ {
BControl::AttachedToWindow(); BControl::AttachedToWindow();
} }
//------------------------------------------------------------------------------
void BCheckBox::MouseDown(BPoint point)
void
BCheckBox::MouseDown(BPoint point)
{ {
if (!IsEnabled()) if (!IsEnabled())
return; return;
@@ -248,91 +237,89 @@ void BCheckBox::MouseDown(BPoint point)
Draw(Bounds()); Draw(Bounds());
Flush(); Flush();
if (Window()->Flags() & B_ASYNCHRONOUS_CONTROLS) if (Window()->Flags() & B_ASYNCHRONOUS_CONTROLS) {
{ SetTracking(true);
SetMouseEventMask(B_POINTER_EVENTS, B_LOCK_WINDOW_FOCUS);
} else {
BRect bounds = Bounds(); BRect bounds = Bounds();
uint32 buttons; uint32 buttons;
do do {
{
snooze(40000); snooze(40000);
GetMouse(&point, &buttons, true); GetMouse(&point, &buttons, true);
bool inside = bounds.Contains(point); bool inside = bounds.Contains(point);
if (fOutlined != inside) if (fOutlined != inside) {
{
fOutlined = inside; fOutlined = inside;
Draw(Bounds()); Draw(Bounds());
Flush(); Flush();
} }
} while (buttons != 0); } while (buttons != 0);
if (fOutlined) if (fOutlined) {
{
fOutlined = false; fOutlined = false;
SetValue(!Value()); SetValue(!Value());
Invoke(); Invoke();
} } else {
else
{
Draw(Bounds()); Draw(Bounds());
Flush(); Flush();
} }
} }
else
{
SetTracking(true);
SetMouseEventMask(B_POINTER_EVENTS, B_LOCK_WINDOW_FOCUS);
}
} }
//------------------------------------------------------------------------------
void BCheckBox::MessageReceived(BMessage *message)
void
BCheckBox::MessageReceived(BMessage *message)
{ {
BControl::MessageReceived(message); BControl::MessageReceived(message);
} }
//------------------------------------------------------------------------------
void BCheckBox::WindowActivated(bool active)
void
BCheckBox::WindowActivated(bool active)
{ {
BControl::WindowActivated(active); BControl::WindowActivated(active);
} }
//------------------------------------------------------------------------------
void BCheckBox::KeyDown(const char *bytes, int32 numBytes)
void
BCheckBox::KeyDown(const char *bytes, int32 numBytes)
{ {
BControl::KeyDown(bytes, numBytes); BControl::KeyDown(bytes, numBytes);
} }
//------------------------------------------------------------------------------
void BCheckBox::MouseUp(BPoint point)
void
BCheckBox::MouseUp(BPoint point)
{ {
if (!IsTracking()) if (!IsTracking())
return; return;
bool inside = Bounds().Contains(point); bool inside = Bounds().Contains(point);
if (fOutlined != inside) if (fOutlined != inside) {
{
fOutlined = inside; fOutlined = inside;
Draw(Bounds()); Draw(Bounds());
Flush(); Flush();
} }
if (fOutlined) if (fOutlined) {
{
fOutlined = false; fOutlined = false;
SetValue(!Value()); SetValue(!Value());
Invoke(); Invoke();
} } else {
else
{
Draw(Bounds()); Draw(Bounds());
Flush(); Flush();
} }
SetTracking(false); SetTracking(false);
} }
//------------------------------------------------------------------------------
void BCheckBox::MouseMoved(BPoint point, uint32 transit,
void
BCheckBox::MouseMoved(BPoint point, uint32 transit,
const BMessage *message) const BMessage *message)
{ {
if (!IsTracking()) if (!IsTracking())
@@ -340,25 +327,30 @@ void BCheckBox::MouseMoved(BPoint point, uint32 transit,
bool inside = Bounds().Contains(point); bool inside = Bounds().Contains(point);
if (fOutlined != inside) if (fOutlined != inside) {
{
fOutlined = inside; fOutlined = inside;
Draw(Bounds()); Draw(Bounds());
Flush(); Flush();
} }
} }
//------------------------------------------------------------------------------
void BCheckBox::DetachedFromWindow()
void
BCheckBox::DetachedFromWindow()
{ {
BControl::DetachedFromWindow(); BControl::DetachedFromWindow();
} }
//------------------------------------------------------------------------------
void BCheckBox::SetValue(int32 value)
void
BCheckBox::SetValue(int32 value)
{ {
BControl::SetValue(value); BControl::SetValue(value);
} }
//------------------------------------------------------------------------------
void BCheckBox::GetPreferredSize(float *width, float *height)
void
BCheckBox::GetPreferredSize(float *width, float *height)
{ {
font_height fh; font_height fh;
GetFontHeight(&fh); GetFontHeight(&fh);
@@ -371,72 +363,87 @@ void BCheckBox::GetPreferredSize(float *width, float *height)
*width = (float)ceil(*width); *width = (float)ceil(*width);
} }
//------------------------------------------------------------------------------
void BCheckBox::ResizeToPreferred()
void
BCheckBox::ResizeToPreferred()
{ {
BControl::ResizeToPreferred(); BControl::ResizeToPreferred();
} }
//------------------------------------------------------------------------------
status_t BCheckBox::Invoke(BMessage *message)
status_t
BCheckBox::Invoke(BMessage *message)
{ {
return BControl::Invoke(message); return BControl::Invoke(message);
} }
//------------------------------------------------------------------------------
void BCheckBox::FrameMoved(BPoint newLocation)
void
BCheckBox::FrameMoved(BPoint newLocation)
{ {
BControl::FrameMoved(newLocation); BControl::FrameMoved(newLocation);
} }
//------------------------------------------------------------------------------
void BCheckBox::FrameResized(float width, float height)
void
BCheckBox::FrameResized(float width, float height)
{ {
BControl::FrameResized(width, height); BControl::FrameResized(width, height);
} }
//------------------------------------------------------------------------------
BHandler *BCheckBox::ResolveSpecifier(BMessage *message, int32 index,
BHandler *
BCheckBox::ResolveSpecifier(BMessage *message, int32 index,
BMessage *specifier, int32 what, BMessage *specifier, int32 what,
const char *property) const char *property)
{ {
return BControl::ResolveSpecifier(message, index, specifier, what, property); return BControl::ResolveSpecifier(message, index, specifier, what, property);
} }
//------------------------------------------------------------------------------
status_t BCheckBox::GetSupportedSuites(BMessage *message)
status_t
BCheckBox::GetSupportedSuites(BMessage *message)
{ {
return BControl::GetSupportedSuites(message); return BControl::GetSupportedSuites(message);
} }
//------------------------------------------------------------------------------
void BCheckBox::MakeFocus(bool focused)
void
BCheckBox::MakeFocus(bool focused)
{ {
BControl::MakeFocus(focused); BControl::MakeFocus(focused);
} }
//------------------------------------------------------------------------------
void BCheckBox::AllAttached()
void
BCheckBox::AllAttached()
{ {
BControl::AllAttached(); BControl::AllAttached();
} }
//------------------------------------------------------------------------------
void BCheckBox::AllDetached()
void
BCheckBox::AllDetached()
{ {
BControl::AllDetached(); BControl::AllDetached();
} }
//------------------------------------------------------------------------------
status_t BCheckBox::Perform(perform_code d, void *arg)
status_t
BCheckBox::Perform(perform_code d, void *arg)
{ {
return BControl::Perform(d, arg); return BControl::Perform(d, arg);
} }
//------------------------------------------------------------------------------
void BCheckBox::_ReservedCheckBox1() {} void BCheckBox::_ReservedCheckBox1() {}
void BCheckBox::_ReservedCheckBox2() {} void BCheckBox::_ReservedCheckBox2() {}
void BCheckBox::_ReservedCheckBox3() {} void BCheckBox::_ReservedCheckBox3() {}
//------------------------------------------------------------------------------
BCheckBox &BCheckBox::operator=(const BCheckBox &)
BCheckBox &
BCheckBox::operator=(const BCheckBox &)
{ {
return *this; return *this;
} }
//------------------------------------------------------------------------------
/*
* $Log $
*
* $Id $
*
*/