Slider: Style fixes

Pointer style
Newlines
Indentation
Compare against NULL or 0 explicitly
use single floating point precision for float literals (i.e. use 0.0f)
This commit is contained in:
John Scipione
2016-03-22 12:00:36 -07:00
parent 5f6a4730cb
commit 8be1a5f082
2 changed files with 167 additions and 136 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2001-2015, Haiku, Inc. All rights reserved. * Copyright 2001-2016 Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#ifndef _SLIDER_H #ifndef _SLIDER_H
+166 -135
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2001-2015 Haiku, Inc. * Copyright 2001-2016 Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
@@ -30,10 +30,12 @@
#define USE_OFF_SCREEN_VIEW 0 #define USE_OFF_SCREEN_VIEW 0
BSlider::BSlider(BRect frame, const char* name, const char* label, BSlider::BSlider(
BMessage* message, int32 minValue, int32 maxValue, BRect frame, const char* name, const char* label, BMessage* message,
thumb_style thumbType, uint32 resizingMode, uint32 flags) int32 minValue, int32 maxValue, thumb_style thumbType, uint32 resizingMode,
: BControl(frame, name, label, message, resizingMode, flags), uint32 flags)
:
BControl(frame, name, label, message, resizingMode, flags),
fModificationMessage(NULL), fModificationMessage(NULL),
fSnoozeAmount(20000), fSnoozeAmount(20000),
@@ -59,11 +61,11 @@ BSlider::BSlider(BRect frame, const char* name, const char* label,
} }
BSlider::BSlider(BRect frame, const char *name, const char *label, BSlider::BSlider(BRect frame, const char* name, const char* label,
BMessage *message, int32 minValue, int32 maxValue, BMessage* message, int32 minValue, int32 maxValue, orientation posture,
orientation posture, thumb_style thumbType, uint32 resizingMode, thumb_style thumbType, uint32 resizingMode, uint32 flags)
uint32 flags) :
: BControl(frame, name, label, message, resizingMode, flags), BControl(frame, name, label, message, resizingMode, flags),
fModificationMessage(NULL), fModificationMessage(NULL),
fSnoozeAmount(20000), fSnoozeAmount(20000),
@@ -89,10 +91,11 @@ BSlider::BSlider(BRect frame, const char *name, const char *label,
} }
BSlider::BSlider(const char *name, const char *label, BMessage *message, BSlider::BSlider(const char* name, const char* label, BMessage* message,
int32 minValue, int32 maxValue, orientation posture, int32 minValue, int32 maxValue, orientation posture, thumb_style thumbType,
thumb_style thumbType, uint32 flags) uint32 flags)
: BControl(name, label, message, flags), :
BControl(name, label, message, flags),
fModificationMessage(NULL), fModificationMessage(NULL),
fSnoozeAmount(20000), fSnoozeAmount(20000),
@@ -118,8 +121,9 @@ BSlider::BSlider(const char *name, const char *label, BMessage *message,
} }
BSlider::BSlider(BMessage *archive) BSlider::BSlider(BMessage* archive)
: BControl(archive) :
BControl(archive)
{ {
fModificationMessage = NULL; fModificationMessage = NULL;
@@ -135,7 +139,7 @@ BSlider::BSlider(BMessage *archive)
SetSnoozeAmount(20000); SetSnoozeAmount(20000);
rgb_color color; rgb_color color;
if (archive->FindInt32("_fcolor", (int32 *)&color) == B_OK) if (archive->FindInt32("_fcolor", (int32*)&color) == B_OK)
UseFillColor(true, &color); UseFillColor(true, &color);
else else
UseFillColor(false); UseFillColor(false);
@@ -181,7 +185,7 @@ BSlider::BSlider(BMessage *archive)
else else
fStyle = B_BLOCK_THUMB; fStyle = B_BLOCK_THUMB;
if (archive->FindInt32("_bcolor", (int32 *)&color) != B_OK) if (archive->FindInt32("_bcolor", (int32*)&color) != B_OK)
color = tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), B_DARKEN_4_TINT); color = tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), B_DARKEN_4_TINT);
SetBarColor(color); SetBarColor(color);
@@ -242,7 +246,7 @@ BSlider::_InitObject()
BArchivable* BArchivable*
BSlider::Instantiate(BMessage *archive) BSlider::Instantiate(BMessage* archive)
{ {
if (validate_instantiation(archive, "BSlider")) if (validate_instantiation(archive, "BSlider"))
return new BSlider(archive); return new BSlider(archive);
@@ -252,7 +256,7 @@ BSlider::Instantiate(BMessage *archive)
status_t status_t
BSlider::Archive(BMessage *archive, bool deep) const BSlider::Archive(BMessage* archive, bool deep) const
{ {
status_t ret = BControl::Archive(archive, deep); status_t ret = BControl::Archive(archive, deep);
@@ -261,33 +265,40 @@ BSlider::Archive(BMessage *archive, bool deep) const
if (ret == B_OK) if (ret == B_OK)
ret = archive->AddInt32("_sdelay", fSnoozeAmount); ret = archive->AddInt32("_sdelay", fSnoozeAmount);
if (ret == B_OK) if (ret == B_OK)
ret = archive->AddInt32("_bcolor", (const uint32 &)fBarColor); ret = archive->AddInt32("_bcolor", (const uint32&)fBarColor);
if (FillColor(NULL) && ret == B_OK) if (FillColor(NULL) && ret == B_OK)
ret = archive->AddInt32("_fcolor", (const uint32 &)fFillColor); ret = archive->AddInt32("_fcolor", (const uint32&)fFillColor);
if (ret == B_OK && fMinLimitLabel) if (ret == B_OK && fMinLimitLabel != NULL)
ret = archive->AddString("_minlbl", fMinLimitLabel); ret = archive->AddString("_minlbl", fMinLimitLabel);
if (ret == B_OK && fMaxLimitLabel) if (ret == B_OK && fMaxLimitLabel != NULL)
ret = archive->AddString("_maxlbl", fMaxLimitLabel); ret = archive->AddString("_maxlbl", fMaxLimitLabel);
if (ret == B_OK) if (ret == B_OK)
ret = archive->AddInt32("_min", fMinValue); ret = archive->AddInt32("_min", fMinValue);
if (ret == B_OK) if (ret == B_OK)
ret = archive->AddInt32("_max", fMaxValue); ret = archive->AddInt32("_max", fMaxValue);
if (ret == B_OK) if (ret == B_OK)
ret = archive->AddInt32("_incrementvalue", fKeyIncrementValue); ret = archive->AddInt32("_incrementvalue", fKeyIncrementValue);
if (ret == B_OK) if (ret == B_OK)
ret = archive->AddInt32("_hashcount", fHashMarkCount); ret = archive->AddInt32("_hashcount", fHashMarkCount);
if (ret == B_OK) if (ret == B_OK)
ret = archive->AddInt16("_hashloc", fHashMarks); ret = archive->AddInt16("_hashloc", fHashMarks);
if (ret == B_OK) if (ret == B_OK)
ret = archive->AddInt16("_sstyle", fStyle); ret = archive->AddInt16("_sstyle", fStyle);
if (ret == B_OK) if (ret == B_OK)
ret = archive->AddInt32("_orient", fOrientation); ret = archive->AddInt32("_orient", fOrientation);
if (ret == B_OK) if (ret == B_OK)
ret = archive->AddFloat("_bthickness", fBarThickness); ret = archive->AddFloat("_bthickness", fBarThickness);
@@ -300,25 +311,28 @@ BSlider::Perform(perform_code code, void* _data)
{ {
switch (code) { switch (code) {
case PERFORM_CODE_MIN_SIZE: case PERFORM_CODE_MIN_SIZE:
((perform_data_min_size*)_data)->return_value ((perform_data_min_size*)_data)->return_value = BSlider::MinSize();
= BSlider::MinSize();
return B_OK; return B_OK;
case PERFORM_CODE_MAX_SIZE: case PERFORM_CODE_MAX_SIZE:
((perform_data_max_size*)_data)->return_value ((perform_data_max_size*)_data)->return_value = BSlider::MaxSize();
= BSlider::MaxSize();
return B_OK; return B_OK;
case PERFORM_CODE_PREFERRED_SIZE: case PERFORM_CODE_PREFERRED_SIZE:
((perform_data_preferred_size*)_data)->return_value ((perform_data_preferred_size*)_data)->return_value
= BSlider::PreferredSize(); = BSlider::PreferredSize();
return B_OK; return B_OK;
case PERFORM_CODE_LAYOUT_ALIGNMENT: case PERFORM_CODE_LAYOUT_ALIGNMENT:
((perform_data_layout_alignment*)_data)->return_value ((perform_data_layout_alignment*)_data)->return_value
= BSlider::LayoutAlignment(); = BSlider::LayoutAlignment();
return B_OK; return B_OK;
case PERFORM_CODE_HAS_HEIGHT_FOR_WIDTH: case PERFORM_CODE_HAS_HEIGHT_FOR_WIDTH:
((perform_data_has_height_for_width*)_data)->return_value ((perform_data_has_height_for_width*)_data)->return_value
= BSlider::HasHeightForWidth(); = BSlider::HasHeightForWidth();
return B_OK; return B_OK;
case PERFORM_CODE_GET_HEIGHT_FOR_WIDTH: case PERFORM_CODE_GET_HEIGHT_FOR_WIDTH:
{ {
perform_data_get_height_for_width* data perform_data_get_height_for_width* data
@@ -327,12 +341,14 @@ BSlider::Perform(perform_code code, void* _data)
&data->preferred); &data->preferred);
return B_OK; return B_OK;
} }
case PERFORM_CODE_SET_LAYOUT: case PERFORM_CODE_SET_LAYOUT:
{ {
perform_data_set_layout* data = (perform_data_set_layout*)_data; perform_data_set_layout* data = (perform_data_set_layout*)_data;
BSlider::SetLayout(data->layout); BSlider::SetLayout(data->layout);
return B_OK; return B_OK;
} }
case PERFORM_CODE_LAYOUT_INVALIDATED: case PERFORM_CODE_LAYOUT_INVALIDATED:
{ {
perform_data_layout_invalidated* data perform_data_layout_invalidated* data
@@ -340,11 +356,13 @@ BSlider::Perform(perform_code code, void* _data)
BSlider::LayoutInvalidated(data->descendants); BSlider::LayoutInvalidated(data->descendants);
return B_OK; return B_OK;
} }
case PERFORM_CODE_DO_LAYOUT: case PERFORM_CODE_DO_LAYOUT:
{ {
BSlider::DoLayout(); BSlider::DoLayout();
return B_OK; return B_OK;
} }
case PERFORM_CODE_SET_ICON: case PERFORM_CODE_SET_ICON:
{ {
perform_data_set_icon* data = (perform_data_set_icon*)_data; perform_data_set_icon* data = (perform_data_set_icon*)_data;
@@ -392,12 +410,13 @@ BSlider::AttachedToWindow()
BControl::AttachedToWindow(); BControl::AttachedToWindow();
BView* view = OffscreenView(); BView* view = OffscreenView();
if (view && view->LockLooper()) { if (view != NULL && view->LockLooper()) {
view->SetViewColor(B_TRANSPARENT_COLOR); view->SetViewColor(B_TRANSPARENT_COLOR);
if (LowUIColor() != B_NO_COLOR) if (LowUIColor() != B_NO_COLOR)
view->SetLowUIColor(LowUIColor()); view->SetLowUIColor(LowUIColor());
else else
view->SetLowColor(LowColor()); view->SetLowColor(LowColor());
view->UnlockLooper(); view->UnlockLooper();
} }
@@ -446,9 +465,9 @@ BSlider::DetachedFromWindow()
void void
BSlider::MessageReceived(BMessage *msg) BSlider::MessageReceived(BMessage* message)
{ {
BControl::MessageReceived(msg); BControl::MessageReceived(message);
} }
@@ -486,7 +505,7 @@ BSlider::FrameResized(float w,float h)
void void
BSlider::KeyDown(const char *bytes, int32 numBytes) BSlider::KeyDown(const char* bytes, int32 numBytes)
{ {
if (!IsEnabled() || IsHidden()) if (!IsEnabled() || IsHidden())
return; return;
@@ -507,6 +526,7 @@ BSlider::KeyDown(const char *bytes, int32 numBytes)
case B_HOME: case B_HOME:
newValue = fMinValue; newValue = fMinValue;
break; break;
case B_END: case B_END:
newValue = fMaxValue; newValue = fMaxValue;
break; break;
@@ -518,6 +538,7 @@ BSlider::KeyDown(const char *bytes, int32 numBytes)
if (newValue < fMinValue) if (newValue < fMinValue)
newValue = fMinValue; newValue = fMinValue;
if (newValue > fMaxValue) if (newValue > fMaxValue)
newValue = fMaxValue; newValue = fMaxValue;
@@ -529,7 +550,7 @@ BSlider::KeyDown(const char *bytes, int32 numBytes)
} }
void void
BSlider::KeyUp(const char *bytes, int32 numBytes) BSlider::KeyUp(const char* bytes, int32 numBytes)
{ {
if (fInitialLocation != _Location()) { if (fInitialLocation != _Location()) {
// The last KeyDown event triggered the modification message or no // The last KeyDown event triggered the modification message or no
@@ -594,7 +615,8 @@ BSlider::MouseDown(BPoint point)
if (Window()->Flags() & B_ASYNCHRONOUS_CONTROLS) { if (Window()->Flags() & B_ASYNCHRONOUS_CONTROLS) {
SetTracking(true); SetTracking(true);
SetMouseEventMask(B_POINTER_EVENTS, B_LOCK_WINDOW_FOCUS | B_NO_POINTER_HISTORY); SetMouseEventMask(B_POINTER_EVENTS,
B_LOCK_WINDOW_FOCUS | B_NO_POINTER_HISTORY);
} else { } else {
// synchronous mouse tracking // synchronous mouse tracking
BPoint prevPoint; BPoint prevPoint;
@@ -633,7 +655,7 @@ BSlider::MouseUp(BPoint point)
void void
BSlider::MouseMoved(BPoint point, uint32 transit, const BMessage *message) BSlider::MouseMoved(BPoint point, uint32 transit, const BMessage* message)
{ {
if (IsTracking()) { if (IsTracking()) {
if (_ConstrainPoint(point, _Location())) { if (_ConstrainPoint(point, _Location())) {
@@ -656,14 +678,14 @@ BSlider::Pulse()
void void
BSlider::SetLabel(const char *label) BSlider::SetLabel(const char* label)
{ {
BControl::SetLabel(label); BControl::SetLabel(label);
} }
void void
BSlider::SetLimitLabels(const char *minLabel, const char *maxLabel) BSlider::SetLimitLabels(const char* minLabel, const char* maxLabel)
{ {
free(fMinLimitLabel); free(fMinLimitLabel);
fMinLimitLabel = minLabel ? strdup(minLabel) : NULL; fMinLimitLabel = minLabel ? strdup(minLabel) : NULL;
@@ -702,6 +724,7 @@ BSlider::SetValue(int32 value)
{ {
if (value < fMinValue) if (value < fMinValue)
value = fMinValue; value = fMinValue;
if (value > fMaxValue) if (value > fMaxValue)
value = fMaxValue; value = fMaxValue;
@@ -761,10 +784,12 @@ BSlider::ValueForPoint(BPoint location) const
if (position < min) if (position < min)
position = min; position = min;
if (position > max) if (position > max)
position = max; position = max;
return (int32)roundf(((position - min) * (fMaxValue - fMinValue) / (max - min)) + fMinValue); return (int32)roundf(((position - min) * (fMaxValue - fMinValue)
/ (max - min)) + fMinValue);
} }
@@ -799,10 +824,11 @@ BSlider::SetEnabled(bool on)
void void
BSlider::GetLimits(int32 *minimum, int32 *maximum) const BSlider::GetLimits(int32* minimum, int32* maximum) const
{ {
if (minimum != NULL) if (minimum != NULL)
*minimum = fMinValue; *minimum = fMinValue;
if (maximum != NULL) if (maximum != NULL)
*maximum = fMaxValue; *maximum = fMaxValue;
} }
@@ -818,7 +844,7 @@ BSlider::Draw(BRect updateRect)
BRegion background(updateRect); BRegion background(updateRect);
background.Exclude(BarFrame()); background.Exclude(BarFrame());
bool drawBackground = true; bool drawBackground = true;
if (Parent() && (Parent()->Flags() & B_DRAW_ON_CHILDREN) != 0) { if (Parent() != NULL && (Parent()->Flags() & B_DRAW_ON_CHILDREN) != 0) {
// This view is embedded somewhere, most likely the Tracker Desktop // This view is embedded somewhere, most likely the Tracker Desktop
// shelf. // shelf.
drawBackground = false; drawBackground = false;
@@ -851,8 +877,9 @@ BSlider::DrawSlider()
{ {
if (LockLooper()) { if (LockLooper()) {
#if USE_OFF_SCREEN_VIEW #if USE_OFF_SCREEN_VIEW
if (!fOffScreenBits) if (fOffScreenBits == NULL)
return; return;
if (fOffScreenBits->Lock()) { if (fOffScreenBits->Lock()) {
#endif #endif
DrawBar(); DrawBar();
@@ -877,7 +904,7 @@ void
BSlider::DrawBar() BSlider::DrawBar()
{ {
BRect frame = BarFrame(); BRect frame = BarFrame();
BView *view = OffscreenView(); BView* view = OffscreenView();
if (be_control_look != NULL) { if (be_control_look != NULL) {
uint32 flags = be_control_look->Flags(this); uint32 flags = be_control_look->Flags(this);
@@ -974,31 +1001,31 @@ BSlider::DrawBar()
view->SetHighColor(darken1); view->SetHighColor(darken1);
view->StrokeLine(BPoint(frame.left, frame.top), view->StrokeLine(BPoint(frame.left, frame.top),
BPoint(frame.left + 1.0f, frame.top)); BPoint(frame.left + 1.0f, frame.top));
view->StrokeLine(BPoint(frame.left, frame.bottom), view->StrokeLine(BPoint(frame.left, frame.bottom),
BPoint(frame.left + 1.0f, frame.bottom)); BPoint(frame.left + 1.0f, frame.bottom));
view->StrokeLine(BPoint(frame.right - 1.0f, frame.top), view->StrokeLine(BPoint(frame.right - 1.0f, frame.top),
BPoint(frame.right, frame.top)); BPoint(frame.right, frame.top));
view->SetHighColor(darken2); view->SetHighColor(darken2);
view->StrokeLine(BPoint(frame.left + 1.0f, frame.top), view->StrokeLine(BPoint(frame.left + 1.0f, frame.top),
BPoint(frame.right - 1.0f, frame.top)); BPoint(frame.right - 1.0f, frame.top));
view->StrokeLine(BPoint(frame.left, frame.bottom - 1.0f), view->StrokeLine(BPoint(frame.left, frame.bottom - 1.0f),
BPoint(frame.left, frame.top + 1.0f)); BPoint(frame.left, frame.top + 1.0f));
view->SetHighColor(lightenmax); view->SetHighColor(lightenmax);
view->StrokeLine(BPoint(frame.left + 1.0f, frame.bottom), view->StrokeLine(BPoint(frame.left + 1.0f, frame.bottom),
BPoint(frame.right, frame.bottom)); BPoint(frame.right, frame.bottom));
view->StrokeLine(BPoint(frame.right, frame.bottom - 1.0f), view->StrokeLine(BPoint(frame.right, frame.bottom - 1.0f),
BPoint(frame.right, frame.top + 1.0f)); BPoint(frame.right, frame.top + 1.0f));
frame.InsetBy(1.0f, 1.0f); frame.InsetBy(1.0f, 1.0f);
view->SetHighColor(darkenmax); view->SetHighColor(darkenmax);
view->StrokeLine(BPoint(frame.left, frame.bottom), view->StrokeLine(BPoint(frame.left, frame.bottom),
BPoint(frame.left, frame.top)); BPoint(frame.left, frame.top));
view->StrokeLine(BPoint(frame.left + 1.0f, frame.top), view->StrokeLine(BPoint(frame.left + 1.0f, frame.top),
BPoint(frame.right, frame.top)); BPoint(frame.right, frame.top));
if (Style() == B_BLOCK_THUMB) if (Style() == B_BLOCK_THUMB)
PopState(); PopState();
@@ -1040,8 +1067,7 @@ BSlider::DrawHashMarks()
// fHashMarks != B_HASH_MARKS_NONE // fHashMarks != B_HASH_MARKS_NONE
float factor = (_MaxPosition() - pos) / (hashMarkCount - 1); float factor = (_MaxPosition() - pos) / (hashMarkCount - 1);
if (fHashMarks & B_HASH_MARKS_TOP) { if ((fHashMarks & B_HASH_MARKS_TOP) != 0) {
view->BeginLineArray(hashMarkCount * 2); view->BeginLineArray(hashMarkCount * 2);
if (fOrientation == B_HORIZONTAL) { if (fOrientation == B_HORIZONTAL) {
@@ -1069,8 +1095,7 @@ BSlider::DrawHashMarks()
pos = _MinPosition(); pos = _MinPosition();
if (fHashMarks & B_HASH_MARKS_BOTTOM) { if ((fHashMarks & B_HASH_MARKS_BOTTOM) != 0) {
view->BeginLineArray(hashMarkCount * 2); view->BeginLineArray(hashMarkCount * 2);
if (fOrientation == B_HORIZONTAL) { if (fOrientation == B_HORIZONTAL) {
@@ -1140,16 +1165,15 @@ void
BSlider::DrawText() BSlider::DrawText()
{ {
BRect bounds(Bounds()); BRect bounds(Bounds());
BView *view = OffscreenView(); BView* view = OffscreenView();
rgb_color base = LowColor(); rgb_color base = LowColor();
uint32 flags = 0; uint32 flags = 0;
if (be_control_look == NULL) { if (be_control_look == NULL) {
if (IsEnabled()) { if (IsEnabled())
view->SetHighColor(0, 0, 0); view->SetHighColor(0, 0, 0);
} else { else
view->SetHighColor(tint_color(LowColor(), B_DISABLED_LABEL_TINT)); view->SetHighColor(tint_color(LowColor(), B_DISABLED_LABEL_TINT));
}
} else { } else {
flags = be_control_look->Flags(this); flags = be_control_look->Flags(this);
@@ -1161,7 +1185,7 @@ BSlider::DrawText()
font_height fontHeight; font_height fontHeight;
GetFontHeight(&fontHeight); GetFontHeight(&fontHeight);
if (Orientation() == B_HORIZONTAL) { if (Orientation() == B_HORIZONTAL) {
if (Label()) { if (Label() != NULL) {
if (be_control_look == NULL) { if (be_control_look == NULL) {
view->DrawString(Label(), view->DrawString(Label(),
BPoint(0.0, ceilf(fontHeight.ascent))); BPoint(0.0, ceilf(fontHeight.ascent)));
@@ -1183,7 +1207,7 @@ BSlider::DrawText()
} }
} }
if (fMinLimitLabel) { if (fMinLimitLabel != NULL) {
if (be_control_look == NULL) { if (be_control_look == NULL) {
view->DrawString(fMinLimitLabel, BPoint(0.0, bounds.bottom view->DrawString(fMinLimitLabel, BPoint(0.0, bounds.bottom
- fontHeight.descent)); - fontHeight.descent));
@@ -1193,7 +1217,7 @@ BSlider::DrawText()
} }
} }
if (fMaxLimitLabel) { if (fMaxLimitLabel != NULL) {
if (be_control_look == NULL) { if (be_control_look == NULL) {
view->DrawString(fMaxLimitLabel, BPoint(bounds.right view->DrawString(fMaxLimitLabel, BPoint(bounds.right
- StringWidth(fMaxLimitLabel), bounds.bottom - StringWidth(fMaxLimitLabel), bounds.bottom
@@ -1209,7 +1233,7 @@ BSlider::DrawText()
+ ceilf(fontHeight.leading); + ceilf(fontHeight.leading);
float baseLine = ceilf(fontHeight.ascent); float baseLine = ceilf(fontHeight.ascent);
if (Label()) { if (Label() != NULL) {
if (be_control_look == NULL) { if (be_control_look == NULL) {
view->DrawString(Label(), BPoint((bounds.Width() view->DrawString(Label(), BPoint((bounds.Width()
- StringWidth(Label())) / 2.0, baseLine)); - StringWidth(Label())) / 2.0, baseLine));
@@ -1221,7 +1245,7 @@ BSlider::DrawText()
baseLine += lineHeight; baseLine += lineHeight;
} }
if (fMaxLimitLabel) { if (fMaxLimitLabel != NULL) {
if (be_control_look == NULL) { if (be_control_look == NULL) {
view->DrawString(fMaxLimitLabel, BPoint((bounds.Width() view->DrawString(fMaxLimitLabel, BPoint((bounds.Width()
- StringWidth(fMaxLimitLabel)) / 2.0, baseLine)); - StringWidth(fMaxLimitLabel)) / 2.0, baseLine));
@@ -1234,7 +1258,7 @@ BSlider::DrawText()
baseLine = bounds.bottom - ceilf(fontHeight.descent); baseLine = bounds.bottom - ceilf(fontHeight.descent);
if (fMinLimitLabel) { if (fMinLimitLabel != NULL) {
if (be_control_look == NULL) { if (be_control_look == NULL) {
view->DrawString(fMinLimitLabel, BPoint((bounds.Width() view->DrawString(fMinLimitLabel, BPoint((bounds.Width()
- StringWidth(fMinLimitLabel)) / 2.0, baseLine)); - StringWidth(fMinLimitLabel)) / 2.0, baseLine));
@@ -1301,8 +1325,9 @@ BSlider::UpdateTextChanged()
if (!updateTextOnOff) { if (!updateTextOnOff) {
invalid.left = (invalid.left + invalid.right - width) / 2; invalid.left = (invalid.left + invalid.right - width) / 2;
invalid.right = invalid.left + width; invalid.right = invalid.left + width;
if (fMinLimitLabel) if (fMinLimitLabel != NULL)
invalid.bottom -= lineHeight; invalid.bottom -= lineHeight;
invalid.top = invalid.bottom - height; invalid.top = invalid.bottom - height;
} }
} }
@@ -1341,9 +1366,10 @@ BSlider::BarFrame() const
} else { } else {
frame.left = floorf((frame.Width() - fBarThickness) / 2.0); frame.left = floorf((frame.Width() - fBarThickness) / 2.0);
frame.top = thumbInset; frame.top = thumbInset;
if (Label()) if (Label() != NULL)
frame.top += textHeight; frame.top += textHeight;
if (fMaxLimitLabel) {
if (fMaxLimitLabel != NULL) {
frame.top += textHeight; frame.top += textHeight;
if (Label()) if (Label())
frame.top += leading; frame.top += leading;
@@ -1351,11 +1377,12 @@ BSlider::BarFrame() const
frame.right = frame.left + fBarThickness; frame.right = frame.left + fBarThickness;
frame.bottom = frame.bottom - thumbInset; frame.bottom = frame.bottom - thumbInset;
if (fMinLimitLabel) if (fMinLimitLabel != NULL)
frame.bottom -= textHeight; frame.bottom -= textHeight;
if (fUpdateText) {
if (fUpdateText != NULL) {
frame.bottom -= textHeight; frame.bottom -= textHeight;
if (fMinLimitLabel) if (fMinLimitLabel != NULL)
frame.bottom -= leading; frame.bottom -= leading;
} }
} }
@@ -1488,7 +1515,7 @@ BSlider::Invoke(BMessage* message)
BHandler* BHandler*
BSlider::ResolveSpecifier(BMessage* message, int32 index, BMessage* specifier, BSlider::ResolveSpecifier(BMessage* message, int32 index, BMessage* specifier,
int32 command, const char *property) int32 command, const char* property)
{ {
return BControl::ResolveSpecifier(message, index, specifier, command, return BControl::ResolveSpecifier(message, index, specifier, command,
property); property);
@@ -1701,7 +1728,7 @@ BSlider::SetBarThickness(float thickness)
void void
BSlider::SetFont(const BFont *font, uint32 properties) BSlider::SetFont(const BFont* font, uint32 properties)
{ {
BControl::SetFont(font, properties); BControl::SetFont(font, properties);
@@ -1729,9 +1756,8 @@ BSlider::SetLimits(int32 minimum, int32 maximum)
value = max_c(minimum, value); value = max_c(minimum, value);
value = min_c(maximum, value); value = min_c(maximum, value);
if (value != Value()) { if (value != Value())
SetValue(value); SetValue(value);
}
} }
} }
@@ -1748,6 +1774,7 @@ BSlider::MaxUpdateTextWidth()
// in case the derived class uses a fixed buffer, the contents // in case the derived class uses a fixed buffer, the contents
// should be reset for the old value // should be reset for the old value
UpdateText(); UpdateText();
return width; return width;
} }
@@ -1758,8 +1785,7 @@ BSlider::MaxUpdateTextWidth()
BSize BSize
BSlider::MinSize() BSlider::MinSize()
{ {
return BLayoutUtils::ComposeSize(ExplicitMinSize(), return BLayoutUtils::ComposeSize(ExplicitMinSize(), _ValidateMinSize());
_ValidateMinSize());
} }
@@ -1771,6 +1797,7 @@ BSlider::MaxSize()
maxSize.width = B_SIZE_UNLIMITED; maxSize.width = B_SIZE_UNLIMITED;
else else
maxSize.height = B_SIZE_UNLIMITED; maxSize.height = B_SIZE_UNLIMITED;
return BLayoutUtils::ComposeSize(ExplicitMaxSize(), maxSize); return BLayoutUtils::ComposeSize(ExplicitMaxSize(), maxSize);
} }
@@ -1804,11 +1831,12 @@ BSlider::LayoutInvalidated(bool descendants)
// #pragma mark - private // #pragma mark - private
void void
BSlider::_DrawBlockThumb() BSlider::_DrawBlockThumb()
{ {
BRect frame = ThumbFrame(); BRect frame = ThumbFrame();
BView *view = OffscreenView(); BView* view = OffscreenView();
if (be_control_look != NULL) { if (be_control_look != NULL) {
rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR); rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR);
@@ -1840,101 +1868,102 @@ BSlider::_DrawBlockThumb()
} }
// blank background for shadow // blank background for shadow
// ToDo: this also draws over the hash marks (though it's not *that* noticeable) // ToDo: this also draws over the hash marks
// (though it's not *that* noticeable)
view->SetHighColor(no_tint); view->SetHighColor(no_tint);
view->StrokeLine(BPoint(frame.left, frame.top), view->StrokeLine(BPoint(frame.left, frame.top),
BPoint(frame.left, frame.top)); BPoint(frame.left, frame.top));
BRect barFrame = BarFrame(); BRect barFrame = BarFrame();
if (barFrame.right >= frame.right) { if (barFrame.right >= frame.right) {
// leave out barFrame from shadow background clearing // leave out barFrame from shadow background clearing
view->StrokeLine(BPoint(frame.right, frame.top), view->StrokeLine(BPoint(frame.right, frame.top),
BPoint(frame.right, barFrame.top - 1.0f)); BPoint(frame.right, barFrame.top - 1.0f));
view->StrokeLine(BPoint(frame.right, barFrame.bottom + 1.0f), view->StrokeLine(BPoint(frame.right, barFrame.bottom + 1.0f),
BPoint(frame.right, frame.bottom)); BPoint(frame.right, frame.bottom));
} else { } else {
view->StrokeLine(BPoint(frame.right, frame.top), view->StrokeLine(BPoint(frame.right, frame.top),
BPoint(frame.right, frame.bottom)); BPoint(frame.right, frame.bottom));
} }
view->StrokeLine(BPoint(frame.left, frame.bottom), view->StrokeLine(BPoint(frame.left, frame.bottom),
BPoint(frame.right - 1.0f, frame.bottom)); BPoint(frame.right - 1.0f, frame.bottom));
view->StrokeLine(BPoint(frame.left, frame.bottom - 1.0f), view->StrokeLine(BPoint(frame.left, frame.bottom - 1.0f),
BPoint(frame.left, frame.bottom - 1.0f)); BPoint(frame.left, frame.bottom - 1.0f));
view->StrokeLine(BPoint(frame.right - 1.0f, frame.top), view->StrokeLine(BPoint(frame.right - 1.0f, frame.top),
BPoint(frame.right - 1.0f, frame.top)); BPoint(frame.right - 1.0f, frame.top));
// Outline (top, left) // outline (top, left)
view->SetHighColor(darken3); view->SetHighColor(darken3);
view->StrokeLine(BPoint(frame.left, frame.bottom - 2.0f), view->StrokeLine(BPoint(frame.left, frame.bottom - 2.0f),
BPoint(frame.left, frame.top + 1.0f)); BPoint(frame.left, frame.top + 1.0f));
view->StrokeLine(BPoint(frame.left + 1.0f, frame.top), view->StrokeLine(BPoint(frame.left + 1.0f, frame.top),
BPoint(frame.right - 2.0f, frame.top)); BPoint(frame.right - 2.0f, frame.top));
// Shadow // shadow
view->SetHighColor(0, 0, 0, IsEnabled() ? 100 : 50); view->SetHighColor(0, 0, 0, IsEnabled() ? 100 : 50);
view->SetDrawingMode(B_OP_ALPHA); view->SetDrawingMode(B_OP_ALPHA);
view->StrokeLine(BPoint(frame.right, frame.top + 2.0f), view->StrokeLine(BPoint(frame.right, frame.top + 2.0f),
BPoint(frame.right, frame.bottom - 1.0f)); BPoint(frame.right, frame.bottom - 1.0f));
view->StrokeLine(BPoint(frame.left + 2.0f, frame.bottom), view->StrokeLine(BPoint(frame.left + 2.0f, frame.bottom),
BPoint(frame.right - 1.0f, frame.bottom)); BPoint(frame.right - 1.0f, frame.bottom));
view->SetDrawingMode(B_OP_COPY); view->SetDrawingMode(B_OP_COPY);
view->SetHighColor(darken3); view->SetHighColor(darken3);
view->StrokeLine(BPoint(frame.right - 1.0f, frame.bottom - 1.0f), view->StrokeLine(BPoint(frame.right - 1.0f, frame.bottom - 1.0f),
BPoint(frame.right - 1.0f, frame.bottom - 1.0f)); BPoint(frame.right - 1.0f, frame.bottom - 1.0f));
// first bevel
// First bevel
frame.InsetBy(1.0f, 1.0f); frame.InsetBy(1.0f, 1.0f);
view->SetHighColor(darkenmax); view->SetHighColor(darkenmax);
view->StrokeLine(BPoint(frame.left, frame.bottom), view->StrokeLine(BPoint(frame.left, frame.bottom),
BPoint(frame.right - 1.0f, frame.bottom)); BPoint(frame.right - 1.0f, frame.bottom));
view->StrokeLine(BPoint(frame.right, frame.bottom - 1.0f), view->StrokeLine(BPoint(frame.right, frame.bottom - 1.0f),
BPoint(frame.right, frame.top)); BPoint(frame.right, frame.top));
view->SetHighColor(lighten2); view->SetHighColor(lighten2);
view->StrokeLine(BPoint(frame.left, frame.top), view->StrokeLine(BPoint(frame.left, frame.top),
BPoint(frame.left, frame.bottom - 1.0f)); BPoint(frame.left, frame.bottom - 1.0f));
view->StrokeLine(BPoint(frame.left + 1.0f, frame.top), view->StrokeLine(BPoint(frame.left + 1.0f, frame.top),
BPoint(frame.right - 1.0f, frame.top)); BPoint(frame.right - 1.0f, frame.top));
frame.InsetBy(1.0f, 1.0f); frame.InsetBy(1.0f, 1.0f);
view->FillRect(BRect(frame.left, frame.top, frame.right - 1.0f, frame.bottom - 1.0f)); view->FillRect(BRect(frame.left, frame.top, frame.right - 1.0f,
frame.bottom - 1.0f));
// Second bevel and center dots // second bevel and center dots
view->SetHighColor(darken2); view->SetHighColor(darken2);
view->StrokeLine(BPoint(frame.left, frame.bottom), view->StrokeLine(BPoint(frame.left, frame.bottom),
BPoint(frame.right, frame.bottom)); Point(frame.right, frame.bottom));
view->StrokeLine(BPoint(frame.right, frame.bottom - 1.0f), view->StrokeLine(BPoint(frame.right, frame.bottom - 1.0f),
BPoint(frame.right, frame.top)); Point(frame.right, frame.top));
if (Orientation() == B_HORIZONTAL) { if (Orientation() == B_HORIZONTAL) {
view->StrokeLine(BPoint(frame.left + 6.0f, frame.top + 2.0f), view->StrokeLine(BPoint(frame.left + 6.0f, frame.top + 2.0f),
BPoint(frame.left + 6.0f, frame.top + 2.0f)); Point(frame.left + 6.0f, frame.top + 2.0f));
view->StrokeLine(BPoint(frame.left + 6.0f, frame.top + 4.0f), view->StrokeLine(BPoint(frame.left + 6.0f, frame.top + 4.0f),
BPoint(frame.left + 6.0f, frame.top + 4.0f)); Point(frame.left + 6.0f, frame.top + 4.0f));
view->StrokeLine(BPoint(frame.left + 6.0f, frame.top + 6.0f), view->StrokeLine(BPoint(frame.left + 6.0f, frame.top + 6.0f),
BPoint(frame.left + 6.0f, frame.top + 6.0f)); BPoint(frame.left + 6.0f, frame.top + 6.0f));
} else { } else {
view->StrokeLine(BPoint(frame.left + 2.0f, frame.top + 6.0f), view->StrokeLine(BPoint(frame.left + 2.0f, frame.top + 6.0f),
BPoint(frame.left + 2.0f, frame.top + 6.0f)); BPoint(frame.left + 2.0f, frame.top + 6.0f));
view->StrokeLine(BPoint(frame.left + 4.0f, frame.top + 6.0f), view->StrokeLine(BPoint(frame.left + 4.0f, frame.top + 6.0f),
BPoint(frame.left + 4.0f, frame.top + 6.0f)); BPoint(frame.left + 4.0f, frame.top + 6.0f));
view->StrokeLine(BPoint(frame.left + 6.0f, frame.top + 6.0f), view->StrokeLine(BPoint(frame.left + 6.0f, frame.top + 6.0f),
BPoint(frame.left + 6.0f, frame.top + 6.0f)); BPoint(frame.left + 6.0f, frame.top + 6.0f));
} }
frame.InsetBy(1.0f, 1.0f); frame.InsetBy(1.0f, 1.0f);
// Third bevel // third bevel
view->SetHighColor(lighten1); view->SetHighColor(lighten1);
view->StrokeLine(BPoint(frame.left, frame.bottom), view->StrokeLine(BPoint(frame.left, frame.bottom),
BPoint(frame.right, frame.bottom)); BPoint(frame.right, frame.bottom));
view->StrokeLine(BPoint(frame.right, frame.bottom - 1.0f), view->StrokeLine(BPoint(frame.right, frame.bottom - 1.0f),
BPoint(frame.right, frame.top)); BPoint(frame.right, frame.top));
} }
@@ -1942,7 +1971,7 @@ void
BSlider::_DrawTriangleThumb() BSlider::_DrawTriangleThumb()
{ {
BRect frame = ThumbFrame(); BRect frame = ThumbFrame();
BView *view = OffscreenView(); BView* view = OffscreenView();
if (be_control_look != NULL) { if (be_control_look != NULL) {
rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR); rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR);
@@ -2106,36 +2135,38 @@ BSlider::_ValidateMinSize()
font_height fontHeight; font_height fontHeight;
GetFontHeight(&fontHeight); GetFontHeight(&fontHeight);
float width = 0.0; float width = 0.0f;
float height = 0.0; float height = 0.0f;
if (fMaxUpdateTextWidth < 0.0) if (fMaxUpdateTextWidth < 0.0f)
fMaxUpdateTextWidth = MaxUpdateTextWidth(); fMaxUpdateTextWidth = MaxUpdateTextWidth();
if (Orientation() == B_HORIZONTAL) { if (Orientation() == B_HORIZONTAL) {
height = 12.0 + fBarThickness; height = 12.0f + fBarThickness;
int32 rows = 0; int32 rows = 0;
float labelWidth = 0; float labelWidth = 0;
int32 labelRows = 0; int32 labelRows = 0;
float labelSpacing = StringWidth("M") * 2; float labelSpacing = StringWidth("M") * 2;
if (Label()) { if (Label() != NULL) {
labelWidth = StringWidth(Label()); labelWidth = StringWidth(Label());
labelRows = 1; labelRows = 1;
} }
if (fMaxUpdateTextWidth > 0.0) { if (fMaxUpdateTextWidth > 0.0f) {
if (labelWidth > 0) if (labelWidth > 0)
labelWidth += labelSpacing; labelWidth += labelSpacing;
labelWidth += fMaxUpdateTextWidth; labelWidth += fMaxUpdateTextWidth;
labelRows = 1; labelRows = 1;
} }
rows += labelRows; rows += labelRows;
if (MinLimitLabel()) if (MinLimitLabel() != NULL)
width = StringWidth(MinLimitLabel()); width = StringWidth(MinLimitLabel());
if (MaxLimitLabel()) {
if (MaxLimitLabel() != NULL) {
// some space between the labels // some space between the labels
if (MinLimitLabel()) if (MinLimitLabel() != NULL)
width += labelSpacing; width += labelSpacing;
width += StringWidth(MaxLimitLabel()); width += StringWidth(MaxLimitLabel());
@@ -2143,8 +2174,9 @@ BSlider::_ValidateMinSize()
if (labelWidth > width) if (labelWidth > width)
width = labelWidth; width = labelWidth;
if (width < 32.0)
width = 32.0; if (width < 32.0f)
width = 32.0f;
if (MinLimitLabel() || MaxLimitLabel()) if (MinLimitLabel() || MaxLimitLabel())
rows++; rows++;
@@ -2153,8 +2185,8 @@ BSlider::_ValidateMinSize()
+ ceilf(fontHeight.descent) + 4.0); + ceilf(fontHeight.descent) + 4.0);
} else { } else {
// B_VERTICAL // B_VERTICAL
width = 12.0 + fBarThickness; width = 12.0f + fBarThickness;
height = 32.0; height = 32.0f;
float lineHeightNoLeading = ceilf(fontHeight.ascent) float lineHeightNoLeading = ceilf(fontHeight.ascent)
+ ceilf(fontHeight.descent); + ceilf(fontHeight.descent);
@@ -2162,19 +2194,19 @@ BSlider::_ValidateMinSize()
// find largest label // find largest label
float labelWidth = 0; float labelWidth = 0;
if (Label()) { if (Label() != NULL) {
labelWidth = StringWidth(Label()); labelWidth = StringWidth(Label());
height += lineHeightNoLeading; height += lineHeightNoLeading;
} }
if (MaxLimitLabel()) { if (MaxLimitLabel() != NULL) {
labelWidth = max_c(labelWidth, StringWidth(MaxLimitLabel())); labelWidth = max_c(labelWidth, StringWidth(MaxLimitLabel()));
height += Label() ? lineHeight : lineHeightNoLeading; height += Label() ? lineHeight : lineHeightNoLeading;
} }
if (MinLimitLabel()) { if (MinLimitLabel() != NULL) {
labelWidth = max_c(labelWidth, StringWidth(MinLimitLabel())); labelWidth = max_c(labelWidth, StringWidth(MinLimitLabel()));
height += lineHeightNoLeading; height += lineHeightNoLeading;
} }
if (fMaxUpdateTextWidth > 0.0) { if (fMaxUpdateTextWidth > 0.0f) {
labelWidth = max_c(labelWidth, fMaxUpdateTextWidth); labelWidth = max_c(labelWidth, fMaxUpdateTextWidth);
height += MinLimitLabel() ? lineHeight : lineHeightNoLeading; height += MinLimitLabel() ? lineHeight : lineHeightNoLeading;
} }
@@ -2202,8 +2234,8 @@ void BSlider::_ReservedSlider11() {}
void BSlider::_ReservedSlider12() {} void BSlider::_ReservedSlider12() {}
BSlider & BSlider&
BSlider::operator=(const BSlider &) BSlider::operator=(const BSlider&)
{ {
return *this; return *this;
} }
@@ -2222,13 +2254,13 @@ GetLimits__7BSliderPlT1(BSlider* slider, int32* minimum, int32* maximum)
extern "C" void extern "C" void
_ReservedSlider4__7BSlider(BSlider *slider, int32 minimum, int32 maximum) _ReservedSlider4__7BSlider(BSlider* slider, int32 minimum, int32 maximum)
{ {
slider->BSlider::SetLimits(minimum, maximum); slider->BSlider::SetLimits(minimum, maximum);
} }
extern "C" float extern "C" float
_ReservedSlider5__7BSlider(BSlider *slider) _ReservedSlider5__7BSlider(BSlider* slider)
{ {
return slider->BSlider::MaxUpdateTextWidth(); return slider->BSlider::MaxUpdateTextWidth();
} }
@@ -2268,4 +2300,3 @@ B_IF_GCC_2(InvalidateLayout__7BSliderb, _ZN7BSlider16InvalidateLayoutEb)(
view->Perform(PERFORM_CODE_LAYOUT_INVALIDATED, &data); view->Perform(PERFORM_CODE_LAYOUT_INVALIDATED, &data);
} }