* Added layout friendly constructor

* Use constructor lists for initializing members
* Simplified initial SetBarColor()
* Update the offscreen view with ViewColor() and LowColor(), someone might
  have changed it after AttachedToWindow() was called.
* Cleanup here and there


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26440 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus
2008-07-16 13:46:05 +00:00
parent c5134b4758
commit cdcfa5945d
2 changed files with 158 additions and 136 deletions
+7 -1
View File
@@ -45,6 +45,11 @@ class BSlider : public BControl {
uint32 resizingMode = B_FOLLOW_LEFT | B_FOLLOW_TOP, uint32 resizingMode = B_FOLLOW_LEFT | B_FOLLOW_TOP,
uint32 flags = B_NAVIGABLE | B_WILL_DRAW | B_FRAME_EVENTS); uint32 flags = B_NAVIGABLE | B_WILL_DRAW | B_FRAME_EVENTS);
BSlider(const char *name, const char *label,
BMessage *message, int32 minValue, int32 maxValue,
orientation posture, thumb_style thumbType = B_BLOCK_THUMB,
uint32 flags = B_NAVIGABLE | B_WILL_DRAW | B_FRAME_EVENTS);
BSlider(BMessage *data); BSlider(BMessage *data);
virtual ~BSlider(); virtual ~BSlider();
@@ -135,7 +140,8 @@ class BSlider : public BControl {
float BarThickness() const; float BarThickness() const;
virtual void SetBarThickness(float thickness); virtual void SetBarThickness(float thickness);
virtual void SetFont(const BFont *font, uint32 properties = B_FONT_ALL); virtual void SetFont(const BFont *font,
uint32 properties = B_FONT_ALL);
virtual void SetLimits(int32 minimum, int32 maximum); virtual void SetLimits(int32 minimum, int32 maximum);
+88 -72
View File
@@ -23,32 +23,30 @@
#include <Slider.h> #include <Slider.h>
BSlider::BSlider(BRect frame, const char *name, const char *label, BMessage *message, BSlider::BSlider(BRect frame, const char* name, const char* label,
int32 minValue, int32 maxValue, thumb_style thumbType, BMessage* message, int32 minValue, int32 maxValue,
uint32 resizingMode, uint32 flags) thumb_style thumbType, uint32 resizingMode, uint32 flags)
: BControl(frame, name, label, message, resizingMode, flags) : BControl(frame, name, label, message, resizingMode, flags),
fModificationMessage(NULL),
fSnoozeAmount(20000),
fMinLimitLabel(NULL),
fMaxLimitLabel(NULL),
fMinValue(minValue),
fMaxValue(maxValue),
fKeyIncrementValue(1),
fHashMarkCount(0),
fHashMarks(B_HASH_MARKS_NONE),
fStyle(thumbType),
fOrientation(B_HORIZONTAL),
fBarThickness(6.0)
{ {
fModificationMessage = NULL;
fSnoozeAmount = 20000;
fOrientation = B_HORIZONTAL;
fBarThickness = 6.0f;
fMinLimitLabel = NULL;
fMaxLimitLabel = NULL;
fMinValue = minValue;
fMaxValue = maxValue;
fKeyIncrementValue = 1;
fHashMarkCount = 0;
fHashMarks = B_HASH_MARKS_NONE;
fStyle = thumbType;
if (Style() == B_BLOCK_THUMB) {
SetBarColor(tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), SetBarColor(tint_color(ui_color(B_PANEL_BACKGROUND_COLOR),
B_DARKEN_4_TINT)); B_DARKEN_4_TINT));
} else {
SetBarColor(tint_color(ui_color(B_PANEL_BACKGROUND_COLOR),
B_DARKEN_4_TINT));
}
UseFillColor(false, NULL); UseFillColor(false, NULL);
@@ -57,29 +55,61 @@ BSlider::BSlider(BRect frame, const char *name, const char *label, BMessage *mes
} }
BSlider::BSlider(BRect frame, const char *name, const char *label, BMessage *message, BSlider::BSlider(BRect frame, const char *name, const char *label,
int32 minValue, int32 maxValue, orientation posture, BMessage *message, int32 minValue, int32 maxValue,
thumb_style thumbType, uint32 resizingMode, uint32 flags) orientation posture, thumb_style thumbType, uint32 resizingMode,
: BControl(frame, name, label, message, resizingMode, flags) uint32 flags)
: BControl(frame, name, label, message, resizingMode, flags),
fModificationMessage(NULL),
fSnoozeAmount(20000),
fMinLimitLabel(NULL),
fMaxLimitLabel(NULL),
fMinValue(minValue),
fMaxValue(maxValue),
fKeyIncrementValue(1),
fHashMarkCount(0),
fHashMarks(B_HASH_MARKS_NONE),
fStyle(thumbType),
fOrientation(posture),
fBarThickness(6.0)
{ {
fModificationMessage = NULL;
fSnoozeAmount = 20000;
fOrientation = posture;
fBarThickness = 6.0f;
fMinLimitLabel = NULL;
fMaxLimitLabel = NULL;
fMinValue = minValue;
fMaxValue = maxValue;
fKeyIncrementValue = 1;
fHashMarkCount = 0;
fHashMarks = B_HASH_MARKS_NONE;
fStyle = thumbType;
if (Style() == B_BLOCK_THUMB)
SetBarColor(tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), SetBarColor(tint_color(ui_color(B_PANEL_BACKGROUND_COLOR),
B_DARKEN_4_TINT)); B_DARKEN_4_TINT));
else
UseFillColor(false, NULL);
_InitObject();
SetValue(0);
}
BSlider::BSlider(const char *name, const char *label, BMessage *message,
int32 minValue, int32 maxValue, orientation posture,
thumb_style thumbType, uint32 flags)
: BControl(name, label, message, flags),
fModificationMessage(NULL),
fSnoozeAmount(20000),
fMinLimitLabel(NULL),
fMaxLimitLabel(NULL),
fMinValue(minValue),
fMaxValue(maxValue),
fKeyIncrementValue(1),
fHashMarkCount(0),
fHashMarks(B_HASH_MARKS_NONE),
fStyle(thumbType),
fOrientation(posture),
fBarThickness(6.0)
{
SetBarColor(tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), SetBarColor(tint_color(ui_color(B_PANEL_BACKGROUND_COLOR),
B_DARKEN_4_TINT)); B_DARKEN_4_TINT));
@@ -96,7 +126,7 @@ BSlider::BSlider(BMessage *archive)
fModificationMessage = NULL; fModificationMessage = NULL;
if (archive->HasMessage("_mod_msg")) { if (archive->HasMessage("_mod_msg")) {
BMessage *message = new BMessage; BMessage* message = new BMessage;
archive->FindMessage("_mod_msg", message); archive->FindMessage("_mod_msg", message);
@@ -107,14 +137,12 @@ 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);
int32 orient; int32 orient;
if (archive->FindInt32("_orient", &orient) == B_OK) if (archive->FindInt32("_orient", &orient) == B_OK)
fOrientation = (orientation)orient; fOrientation = (orientation)orient;
else else
@@ -123,7 +151,8 @@ BSlider::BSlider(BMessage *archive)
fMinLimitLabel = NULL; fMinLimitLabel = NULL;
fMaxLimitLabel = NULL; fMaxLimitLabel = NULL;
const char *minlbl = NULL, *maxlbl = NULL; const char* minlbl = NULL;
const char* maxlbl = NULL;
archive->FindString("_minlbl", &minlbl); archive->FindString("_minlbl", &minlbl);
archive->FindString("_maxlbl", &maxlbl); archive->FindString("_maxlbl", &maxlbl);
@@ -143,32 +172,22 @@ BSlider::BSlider(BMessage *archive)
fHashMarkCount = 11; fHashMarkCount = 11;
int16 hashloc; int16 hashloc;
if (archive->FindInt16("_hashloc", &hashloc) == B_OK) if (archive->FindInt16("_hashloc", &hashloc) == B_OK)
fHashMarks = (hash_mark_location)hashloc; fHashMarks = (hash_mark_location)hashloc;
else else
fHashMarks = B_HASH_MARKS_NONE; fHashMarks = B_HASH_MARKS_NONE;
int16 sstyle; int16 sstyle;
if (archive->FindInt16("_sstyle", &sstyle) == B_OK) if (archive->FindInt16("_sstyle", &sstyle) == B_OK)
fStyle = (thumb_style)sstyle; fStyle = (thumb_style)sstyle;
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);
SetBarColor(color); SetBarColor(color);
else {
if (Style() == B_BLOCK_THUMB)
SetBarColor(tint_color(ui_color(B_PANEL_BACKGROUND_COLOR),
B_DARKEN_4_TINT));
else
SetBarColor(tint_color(ui_color(B_PANEL_BACKGROUND_COLOR),
B_DARKEN_4_TINT));
}
float bthickness; float bthickness;
if (archive->FindFloat("_bthickness", &bthickness) == B_OK) if (archive->FindFloat("_bthickness", &bthickness) == B_OK)
fBarThickness = bthickness; fBarThickness = bthickness;
else else
@@ -181,7 +200,6 @@ BSlider::BSlider(BMessage *archive)
BSlider::~BSlider() BSlider::~BSlider()
{ {
#if USE_OFF_SCREEN_VIEW #if USE_OFF_SCREEN_VIEW
if (fOffScreenBits)
delete fOffScreenBits; delete fOffScreenBits;
#endif #endif
@@ -558,18 +576,13 @@ BSlider::SetLabel(const char *label)
void void
BSlider::SetLimitLabels(const char *minLabel, const char *maxLabel) BSlider::SetLimitLabels(const char *minLabel, const char *maxLabel)
{ {
if (minLabel) {
free(fMinLimitLabel); free(fMinLimitLabel);
fMinLimitLabel = strdup(minLabel); fMinLimitLabel = minLabel ? strdup(minLabel) : NULL;
}
if (maxLabel) {
free(fMaxLimitLabel); free(fMaxLimitLabel);
fMaxLimitLabel = strdup(maxLabel); fMaxLimitLabel = maxLabel ? strdup(maxLabel) : NULL;
}
// TODO: Auto resizing?!? I would not want this as an app programmer! InvalidateLayout();
ResizeToPreferred();
Invalidate(); Invalidate();
} }
@@ -596,7 +609,9 @@ BSlider::SetValue(int32 value)
if (value > fMaxValue) if (value > fMaxValue)
value = fMaxValue; value = fMaxValue;
if (value != Value()) { if (value == Value())
return;
BPoint loc; BPoint loc;
float range = (float)(fMaxValue - fMinValue); float range = (float)(fMaxValue - fMinValue);
if (range == 0) if (range == 0)
@@ -664,7 +679,6 @@ BSlider::SetValue(int32 value)
rect.OffsetBy(Bounds().Width(), 0); rect.OffsetBy(Bounds().Width(), 0);
Invalidate(rect); Invalidate(rect);
} }
}
} }
@@ -740,6 +754,8 @@ BSlider::Draw(BRect updateRect)
return; return;
if (fOffScreenBits->Lock()) { if (fOffScreenBits->Lock()) {
fOffScreenView->SetViewColor(ViewColor());
fOffScreenView->SetLowColor(ViewColor());
#endif #endif
if (background.Frame().IsValid()) if (background.Frame().IsValid())