Lots of fixes, geometry calculations updated, added buffered BSlider support

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@2540 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Marc Flerackers
2003-01-23 15:11:19 +00:00
parent ac6f7aa850
commit 8ce46bc32b
+396 -389
View File
@@ -1,389 +1,396 @@
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Copyright (c) 2001-2002, OpenBeOS // Copyright (c) 2001-2002, OpenBeOS
// //
// Permission is hereby granted, free of charge, to any person obtaining a // Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"), // copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation // to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, // the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the // and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions: // Software is furnished to do so, subject to the following conditions:
// //
// The above copyright notice and this permission notice shall be included in // The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software. // all copies or substantial portions of the Software.
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
// //
// File Name: CheckBox.cpp // File Name: CheckBox.cpp
// 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 ----------------------------------------------------------- // Standard Includes -----------------------------------------------------------
// System Includes ------------------------------------------------------------- // System Includes -------------------------------------------------------------
#include <CheckBox.h> #include <CheckBox.h>
#include <Errors.h> #include <Errors.h>
// Project Includes ------------------------------------------------------------ // Project Includes ------------------------------------------------------------
// Local Includes -------------------------------------------------------------- // Local Includes --------------------------------------------------------------
// Local Defines --------------------------------------------------------------- // Local Defines ---------------------------------------------------------------
// Globals --------------------------------------------------------------------- // 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
if (Bounds().Height() < 18.0f) font_height fh;
ResizeTo(Bounds().Width(), 18.0f); GetFontHeight(&fh);
} float minHeight = 6.0f + (float)ceil(fh.ascent + fh.descent);
//------------------------------------------------------------------------------ if (Bounds().Height() < minHeight)
BCheckBox::~BCheckBox() ResizeTo(Bounds().Width(), minHeight);
{ }
//------------------------------------------------------------------------------
} BCheckBox::~BCheckBox()
//------------------------------------------------------------------------------ {
BCheckBox::BCheckBox(BMessage *archive)
: BControl(archive) }
{ //------------------------------------------------------------------------------
fOutlined = false; BCheckBox::BCheckBox(BMessage *archive)
} : BControl(archive),
//------------------------------------------------------------------------------ fOutlined(false)
BArchivable *BCheckBox::Instantiate(BMessage *archive) {
{ }
if (validate_instantiation(archive, "BCheckBox")) //------------------------------------------------------------------------------
return new BCheckBox(archive); BArchivable *BCheckBox::Instantiate(BMessage *archive)
else {
return NULL; if (validate_instantiation(archive, "BCheckBox"))
} return new BCheckBox(archive);
//------------------------------------------------------------------------------ else
status_t BCheckBox::Archive(BMessage *archive, bool deep) const return NULL;
{ }
return BControl::Archive(archive,deep); //------------------------------------------------------------------------------
} status_t BCheckBox::Archive(BMessage *archive, bool deep) const
//------------------------------------------------------------------------------ {
void BCheckBox::Draw(BRect updateRect) return BControl::Archive(archive,deep);
{ }
rgb_color no_tint = ui_color(B_PANEL_BACKGROUND_COLOR), //------------------------------------------------------------------------------
lighten1 = tint_color(no_tint, B_LIGHTEN_1_TINT), void BCheckBox::Draw(BRect updateRect)
lightenmax = tint_color(no_tint, B_LIGHTEN_MAX_TINT), {
darken1 = tint_color(no_tint, B_DARKEN_1_TINT), font_height fh;
darken2 = tint_color(no_tint, B_DARKEN_2_TINT), GetFontHeight(&fh);
darken3 = tint_color(no_tint, B_DARKEN_3_TINT),
darken4 = tint_color(no_tint, B_DARKEN_4_TINT), // If the focus is changing, just redraw the focus indicator
darkenmax = tint_color(no_tint, B_DARKEN_MAX_TINT); if (IsFocusChanging())
{
BRect rect(1.0, 3.0, 13.0, 15.0); float x = ceil(10.0f + fh.ascent);
float y = 5.0f + ceil(fh.ascent);
if (IsEnabled())
{ if (IsFocus())
// Filling SetHighColor(ui_color(B_KEYBOARD_NAVIGATION_COLOR));
SetHighColor(lightenmax); else
FillRect(rect); SetHighColor(ui_color(B_PANEL_BACKGROUND_COLOR));
// Box StrokeLine(BPoint(x, y), BPoint(x + StringWidth(Label()), y));
if (fOutlined)
{ return;
SetHighColor(darken3); }
StrokeRect(rect);
rgb_color no_tint = ui_color(B_PANEL_BACKGROUND_COLOR),
rect.InsetBy(1,1); lighten1 = tint_color(no_tint, B_LIGHTEN_1_TINT),
lightenmax = tint_color(no_tint, B_LIGHTEN_MAX_TINT),
BeginLineArray(6); darken1 = tint_color(no_tint, B_DARKEN_1_TINT),
darken2 = tint_color(no_tint, B_DARKEN_2_TINT),
AddLine(BPoint(rect.left, rect.bottom), darken3 = tint_color(no_tint, B_DARKEN_3_TINT),
BPoint(rect.left, rect.top), darken2); darken4 = tint_color(no_tint, B_DARKEN_4_TINT),
AddLine(BPoint(rect.left, rect.top), darkenmax = tint_color(no_tint, B_DARKEN_MAX_TINT);
BPoint(rect.right, rect.top), darken2);
AddLine(BPoint(rect.left, rect.bottom), BRect rect(1.0f, 3.0f, ceil(3.0f + fh.ascent), ceil(5.0f + fh.ascent));
BPoint(rect.right, rect.bottom), darken4);
AddLine(BPoint(rect.right, rect.bottom), if (IsEnabled())
BPoint(rect.right, rect.top), darken4); {
// Filling
EndLineArray(); SetHighColor(lightenmax);
} FillRect(rect);
else
{ // Box
BeginLineArray(6); if (fOutlined)
{
AddLine(BPoint(rect.left, rect.bottom), SetHighColor(darken3);
BPoint(rect.left, rect.top), darken1); StrokeRect(rect);
AddLine(BPoint(rect.left, rect.top),
BPoint(rect.right, rect.top), darken1); rect.InsetBy(1,1);
rect.InsetBy(1,1);
AddLine(BPoint(rect.left, rect.bottom), BeginLineArray(6);
BPoint(rect.left, rect.top), darken4);
AddLine(BPoint(rect.left, rect.top), AddLine(BPoint(rect.left, rect.bottom),
BPoint(rect.right, rect.top), darken4); BPoint(rect.left, rect.top), darken2);
AddLine(BPoint(rect.left + 1.0f, rect.bottom), AddLine(BPoint(rect.left, rect.top),
BPoint(rect.right, rect.bottom), no_tint); BPoint(rect.right, rect.top), darken2);
AddLine(BPoint(rect.right, rect.bottom), AddLine(BPoint(rect.left, rect.bottom),
BPoint(rect.right, rect.top + 1.0f), no_tint); BPoint(rect.right, rect.bottom), darken4);
AddLine(BPoint(rect.right, rect.bottom),
EndLineArray(); BPoint(rect.right, rect.top), darken4);
}
EndLineArray();
// Checkmark }
if (Value() == B_CONTROL_ON) else
{ {
rect.InsetBy(2,2); BeginLineArray(6);
SetHighColor(ui_color(B_KEYBOARD_NAVIGATION_COLOR)); AddLine(BPoint(rect.left, rect.bottom),
SetPenSize(2); BPoint(rect.left, rect.top), darken1);
StrokeLine(BPoint(rect.left, rect.top), AddLine(BPoint(rect.left, rect.top),
BPoint(rect.right, rect.bottom)); BPoint(rect.right, rect.top), darken1);
StrokeLine(BPoint(rect.left, rect.bottom), rect.InsetBy(1,1);
BPoint(rect.right, rect.top)); AddLine(BPoint(rect.left, rect.bottom),
SetPenSize(1); BPoint(rect.left, rect.top), darken4);
} AddLine(BPoint(rect.left, rect.top),
BPoint(rect.right, rect.top), darken4);
// Label AddLine(BPoint(rect.left + 1.0f, rect.bottom),
BFont font; BPoint(rect.right, rect.bottom), no_tint);
GetFont(&font); AddLine(BPoint(rect.right, rect.bottom),
font_height fh; BPoint(rect.right, rect.top + 1.0f), no_tint);
font.GetHeight(&fh);
EndLineArray();
SetHighColor(darkenmax); }
DrawString(Label(), BPoint(20.0f, 8.0f + (float)ceil(fh.ascent / 2.0f)));
// Checkmark
// Focus if (Value() == B_CONTROL_ON)
if (IsFocus()) {
{ rect.InsetBy(2,2);
float h = 8.0f + (float)ceil(fh.ascent / 2.0f) + 2.0f;
SetHighColor(ui_color(B_KEYBOARD_NAVIGATION_COLOR));
SetHighColor(ui_color(B_KEYBOARD_NAVIGATION_COLOR)); SetPenSize(2);
StrokeLine(BPoint(20.0f, h), BPoint(20.0f + StringWidth(Label()), h)); StrokeLine(BPoint(rect.left, rect.top),
} BPoint(rect.right, rect.bottom));
} StrokeLine(BPoint(rect.left, rect.bottom),
else BPoint(rect.right, rect.top));
{ SetPenSize(1);
// Filling }
SetHighColor(lighten1);
FillRect(rect); // Label
SetHighColor(darkenmax);
// Box DrawString(Label(), BPoint(ceil(10.0f + fh.ascent),
BeginLineArray(6); 3.0f + ceil(fh.ascent)));
AddLine(BPoint(rect.left, rect.bottom), // Focus
BPoint(rect.left, rect.top), no_tint); if (IsFocus())
AddLine(BPoint(rect.left, rect.top), {
BPoint(rect.right, rect.top), no_tint); float x = ceil(10.0f + fh.ascent);
rect.InsetBy(1,1); float y = 5.0f + ceil(fh.ascent);
AddLine(BPoint(rect.left, rect.bottom),
BPoint(rect.left, rect.top), darken2); SetHighColor(ui_color(B_KEYBOARD_NAVIGATION_COLOR));
AddLine(BPoint(rect.left, rect.top), StrokeLine(BPoint(x, y), BPoint(x + StringWidth(Label()), y));
BPoint(rect.right, rect.top), darken2); }
AddLine(BPoint(rect.left + 1.0f, rect.bottom), }
BPoint(rect.right, rect.bottom), darken1); else
AddLine(BPoint(rect.right, rect.bottom), {
BPoint(rect.right, rect.top + 1.0f), darken1); // Filling
SetHighColor(lighten1);
EndLineArray(); FillRect(rect);
// Checkmark // Box
if (Value() == B_CONTROL_ON) BeginLineArray(6);
{
rect.InsetBy(2, 2); AddLine(BPoint(rect.left, rect.bottom),
BPoint(rect.left, rect.top), no_tint);
SetHighColor(tint_color(ui_color(B_KEYBOARD_NAVIGATION_COLOR), AddLine(BPoint(rect.left, rect.top),
B_DISABLED_MARK_TINT)); BPoint(rect.right, rect.top), no_tint);
SetPenSize(2); rect.InsetBy(1,1);
StrokeLine(BPoint(rect.left, rect.top), AddLine(BPoint(rect.left, rect.bottom),
BPoint(rect.right, rect.bottom)); BPoint(rect.left, rect.top), darken2);
StrokeLine(BPoint(rect.left, rect.bottom), AddLine(BPoint(rect.left, rect.top),
BPoint(rect.right, rect.top)); BPoint(rect.right, rect.top), darken2);
SetPenSize(1); AddLine(BPoint(rect.left + 1.0f, rect.bottom),
} BPoint(rect.right, rect.bottom), darken1);
AddLine(BPoint(rect.right, rect.bottom),
// Label BPoint(rect.right, rect.top + 1.0f), darken1);
BFont font;
GetFont(&font); EndLineArray();
font_height fh;
font.GetHeight(&fh); // Checkmark
if (Value() == B_CONTROL_ON)
SetHighColor(tint_color(no_tint, B_DISABLED_LABEL_TINT)); {
DrawString(Label(), BPoint(20.0f, 8.0f + (float)ceil(fh.ascent / 2.0f))); rect.InsetBy(2, 2);
}
} SetHighColor(tint_color(ui_color(B_KEYBOARD_NAVIGATION_COLOR),
//------------------------------------------------------------------------------ B_DISABLED_MARK_TINT));
void BCheckBox::AttachedToWindow() SetPenSize(2);
{ StrokeLine(BPoint(rect.left, rect.top),
BControl::AttachedToWindow(); BPoint(rect.right, rect.bottom));
} StrokeLine(BPoint(rect.left, rect.bottom),
//------------------------------------------------------------------------------ BPoint(rect.right, rect.top));
void BCheckBox::MouseDown(BPoint point) SetPenSize(1);
{ }
if (!IsEnabled())
{ // Label
BControl::MouseDown(point); SetHighColor(tint_color(no_tint, B_DISABLED_LABEL_TINT));
return; DrawString(Label(), BPoint(ceil(10.0f + fh.ascent),
} 3.0f + ceil(fh.ascent)));
}
SetMouseEventMask(B_POINTER_EVENTS, B_NO_POINTER_HISTORY | }
B_SUSPEND_VIEW_FOCUS); //------------------------------------------------------------------------------
void BCheckBox::AttachedToWindow()
fOutlined = true; {
SetTracking(true); BControl::AttachedToWindow();
Invalidate(); }
} //------------------------------------------------------------------------------
//------------------------------------------------------------------------------ void BCheckBox::MouseDown(BPoint point)
void BCheckBox::MessageReceived(BMessage *message) {
{ if (!IsEnabled())
BControl::MessageReceived(message); {
} BControl::MouseDown(point);
//------------------------------------------------------------------------------ return;
void BCheckBox::WindowActivated(bool active) }
{
BControl::WindowActivated(active); SetMouseEventMask(B_POINTER_EVENTS, B_NO_POINTER_HISTORY |
} B_SUSPEND_VIEW_FOCUS);
//------------------------------------------------------------------------------
void BCheckBox::KeyDown(const char *bytes, int32 numBytes) fOutlined = true;
{ SetTracking(true);
// if (*((int*)bytes) == VK_RETURN || *((int*)bytes) == VK_SPACE) Invalidate();
// SetValue(Value() ? 0 : 1); }
// else //------------------------------------------------------------------------------
// { void BCheckBox::MessageReceived(BMessage *message)
// SetValue(0); {
BControl::KeyDown(bytes, numBytes); BControl::MessageReceived(message);
// } }
} //------------------------------------------------------------------------------
//------------------------------------------------------------------------------ void BCheckBox::WindowActivated(bool active)
void BCheckBox::MouseUp(BPoint point) {
{ BControl::WindowActivated(active);
if (IsEnabled() && IsTracking()) }
{ //------------------------------------------------------------------------------
fOutlined = false; void BCheckBox::KeyDown(const char *bytes, int32 numBytes)
{
if (Bounds().Contains(point)) BControl::KeyDown(bytes, numBytes);
{ }
if (Value() == B_CONTROL_OFF) //------------------------------------------------------------------------------
SetValue(B_CONTROL_ON); void BCheckBox::MouseUp(BPoint point)
else {
SetValue(B_CONTROL_OFF); if (IsEnabled() && IsTracking())
{
BControl::Invoke(); fOutlined = false;
}
SetTracking(false); if (Bounds().Contains(point))
} {
else if (Value() == B_CONTROL_OFF)
{ SetValue(B_CONTROL_ON);
BControl::MouseUp(point); else
return; SetValue(B_CONTROL_OFF);
}
} BControl::Invoke();
//------------------------------------------------------------------------------ }
void BCheckBox::MouseMoved(BPoint point, uint32 transit, const BMessage *message) SetTracking(false);
{ }
if (IsEnabled() && IsTracking()) else
{ {
if (transit == B_EXITED_VIEW) BControl::MouseUp(point);
fOutlined = false; return;
else if (transit == B_ENTERED_VIEW) }
fOutlined = true; }
//------------------------------------------------------------------------------
Invalidate(); void BCheckBox::MouseMoved(BPoint point, uint32 transit, const BMessage *message)
} {
else if (IsEnabled() && IsTracking())
BControl::MouseMoved(point, transit, message); {
} if (transit == B_EXITED_VIEW)
//------------------------------------------------------------------------------ fOutlined = false;
void BCheckBox::DetachedFromWindow() else if (transit == B_ENTERED_VIEW)
{ fOutlined = true;
BControl::DetachedFromWindow();
} Invalidate();
//------------------------------------------------------------------------------ }
void BCheckBox::SetValue(int32 value) else
{ BControl::MouseMoved(point, transit, message);
BControl::SetValue(value); }
} //------------------------------------------------------------------------------
//------------------------------------------------------------------------------ void BCheckBox::DetachedFromWindow()
void BCheckBox::GetPreferredSize(float *width, float *height) {
{ BControl::DetachedFromWindow();
font_height fh; }
GetFontHeight(&fh); //------------------------------------------------------------------------------
void BCheckBox::SetValue(int32 value)
*height = (float)ceil(fh.ascent + fh.descent + fh.leading) + 6.0f; {
*width = 22.0f + (float)ceil(StringWidth(Label())); BControl::SetValue(value);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void BCheckBox::ResizeToPreferred() void BCheckBox::GetPreferredSize(float *width, float *height)
{ {
float widht, height; font_height fh;
GetPreferredSize(&widht, &height); GetFontHeight(&fh);
BView::ResizeTo(widht,height);
} *height = 6.0f + (float)ceil(fh.ascent + fh.descent);
//------------------------------------------------------------------------------ *width = 12.0f + (float)ceil(fh.ascent) + (float)ceil(StringWidth(Label()));
status_t BCheckBox::Invoke(BMessage *message) }
{ //------------------------------------------------------------------------------
return BControl::Invoke(message); void BCheckBox::ResizeToPreferred()
} {
//------------------------------------------------------------------------------ BControl::ResizeToPreferred();
void BCheckBox::FrameMoved(BPoint newLocation) }
{ //------------------------------------------------------------------------------
BControl::FrameMoved(newLocation); status_t BCheckBox::Invoke(BMessage *message)
} {
//------------------------------------------------------------------------------ return BControl::Invoke(message);
void BCheckBox::FrameResized(float width, float height) }
{ //------------------------------------------------------------------------------
BControl::FrameResized(width, height); void BCheckBox::FrameMoved(BPoint newLocation)
} {
//------------------------------------------------------------------------------ BControl::FrameMoved(newLocation);
BHandler *BCheckBox::ResolveSpecifier(BMessage *message, int32 index, }
BMessage *specifier, int32 what, //------------------------------------------------------------------------------
const char *property) void BCheckBox::FrameResized(float width, float height)
{ {
return BControl::ResolveSpecifier(message, index, specifier, what, property); BControl::FrameResized(width, height);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
status_t BCheckBox::GetSupportedSuites(BMessage *message) BHandler *BCheckBox::ResolveSpecifier(BMessage *message, int32 index,
{ BMessage *specifier, int32 what,
return BControl::GetSupportedSuites(message); const char *property)
} {
//------------------------------------------------------------------------------ return BControl::ResolveSpecifier(message, index, specifier, what, property);
void BCheckBox::MakeFocus(bool focused) }
{ //------------------------------------------------------------------------------
BControl::MakeFocus(focused); status_t BCheckBox::GetSupportedSuites(BMessage *message)
} {
//------------------------------------------------------------------------------ return BControl::GetSupportedSuites(message);
void BCheckBox::AllAttached() }
{ //------------------------------------------------------------------------------
BControl::AllAttached(); void BCheckBox::MakeFocus(bool focused)
} {
//------------------------------------------------------------------------------ BControl::MakeFocus(focused);
void BCheckBox::AllDetached() }
{ //------------------------------------------------------------------------------
BControl::AllDetached(); void BCheckBox::AllAttached()
} {
//------------------------------------------------------------------------------ BControl::AllAttached();
status_t BCheckBox::Perform(perform_code d, void *arg) }
{ //------------------------------------------------------------------------------
return B_ERROR; void BCheckBox::AllDetached()
} {
//------------------------------------------------------------------------------ BControl::AllDetached();
void BCheckBox::_ReservedCheckBox1() {} }
void BCheckBox::_ReservedCheckBox2() {} //------------------------------------------------------------------------------
void BCheckBox::_ReservedCheckBox3() {} status_t BCheckBox::Perform(perform_code d, void *arg)
//------------------------------------------------------------------------------ {
BCheckBox &BCheckBox::operator=(const BCheckBox &) return B_ERROR;
{ }
return *this; //------------------------------------------------------------------------------
} void BCheckBox::_ReservedCheckBox1() {}
//------------------------------------------------------------------------------ void BCheckBox::_ReservedCheckBox2() {}
void BCheckBox::_ReservedCheckBox3() {}
/* //------------------------------------------------------------------------------
* $Log $ BCheckBox &BCheckBox::operator=(const BCheckBox &)
* {
* $Id $ return *this;
* }
*/ //------------------------------------------------------------------------------
/*
* $Log $
*
* $Id $
*
*/