diff --git a/headers/os/interface/Slider.h b/headers/os/interface/Slider.h index 26be2073cf..266229e2c4 100644 --- a/headers/os/interface/Slider.h +++ b/headers/os/interface/Slider.h @@ -1,43 +1,18 @@ -//------------------------------------------------------------------------------ -// Copyright (c) 2001-2002, OpenBeOS -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// 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: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// 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 -// DEALINGS IN THE SOFTWARE. -// -// File Name: Slider.h -// Author: Marc Flerackers (mflerackers@androme.be) -// Description: BSlider creates and displays a sliding thumb control. -//------------------------------------------------------------------------------ - +/* + * Copyright 2001-2005, Haiku. + * Distributed under the terms of the MIT License. + * + * Authors: + * Marc Flerackers (mflerackers@androme.be) + */ #ifndef _SLIDER_H #define _SLIDER_H -// Standard Includes ----------------------------------------------------------- -// System Includes ------------------------------------------------------------- #include #include -// Project Includes ------------------------------------------------------------ -// Local Includes -------------------------------------------------------------- - -// Local Defines --------------------------------------------------------------- enum hash_mark_location { B_HASH_MARKS_NONE = 0, B_HASH_MARKS_TOP = 1, @@ -52,163 +27,148 @@ enum thumb_style { B_TRIANGLE_THUMB }; -// Globals --------------------------------------------------------------------- #define USE_OFF_SCREEN_VIEW 0 -// BSlider class --------------------------------------------------------------- + class BSlider : public BControl { -public: - BSlider(BRect frame, - const char *name, - const char *label, - BMessage *message, - int32 minValue, - int32 maxValue, - thumb_style thumbType = B_BLOCK_THUMB, - uint32 resizingMode = B_FOLLOW_LEFT | - B_FOLLOW_TOP, - uint32 flags = B_NAVIGABLE | B_WILL_DRAW | - B_FRAME_EVENTS); - BSlider(BRect frame, - const char *name, - const char *label, - BMessage *message, - int32 minValue, - int32 maxValue, - orientation posture /*= B_HORIZONTAL*/, - thumb_style thumbType = B_BLOCK_THUMB, - uint32 resizingMode = B_FOLLOW_LEFT | - B_FOLLOW_TOP, - uint32 flags = B_NAVIGABLE | B_WILL_DRAW | - B_FRAME_EVENTS); -virtual ~BSlider(); + public: + BSlider(BRect frame, const char *name, const char *label, + BMessage *message, int32 minValue, int32 maxValue, + thumb_style thumbType = B_BLOCK_THUMB, + uint32 resizingMode = B_FOLLOW_LEFT | B_FOLLOW_TOP, + uint32 flags = B_NAVIGABLE | B_WILL_DRAW | B_FRAME_EVENTS); - BSlider(BMessage *data); -static BArchivable *Instantiate(BMessage *data); -virtual status_t Archive(BMessage *data, bool deep = true) const; -virtual status_t Perform(perform_code d, void *arg); + BSlider(BRect frame, const char *name, const char *label, + BMessage *message, int32 minValue, int32 maxValue, + orientation posture, thumb_style thumbType = B_BLOCK_THUMB, + uint32 resizingMode = B_FOLLOW_LEFT | B_FOLLOW_TOP, + uint32 flags = B_NAVIGABLE | B_WILL_DRAW | B_FRAME_EVENTS); -virtual void WindowActivated(bool state); -virtual void AttachedToWindow(); -virtual void AllAttached(); -virtual void AllDetached(); -virtual void DetachedFromWindow(); + BSlider(BMessage *data); + virtual ~BSlider(); -virtual void MessageReceived(BMessage *msg); -virtual void FrameMoved(BPoint new_position); -virtual void FrameResized(float w,float h); -virtual void KeyDown(const char * bytes, int32 n); -virtual void MouseDown(BPoint); -virtual void MouseUp(BPoint pt); -virtual void MouseMoved(BPoint pt, uint32 c, const BMessage *m); -virtual void Pulse(); - -virtual void SetLabel(const char *label); -virtual void SetLimitLabels(const char *minLabel, - const char *maxLabel); + static BArchivable *Instantiate(BMessage *data); + virtual status_t Archive(BMessage *data, bool deep = true) const; + virtual status_t Perform(perform_code d, void *arg); + + virtual void WindowActivated(bool state); + virtual void AttachedToWindow(); + virtual void AllAttached(); + virtual void AllDetached(); + virtual void DetachedFromWindow(); + + virtual void MessageReceived(BMessage *msg); + virtual void FrameMoved(BPoint new_position); + virtual void FrameResized(float w,float h); + virtual void KeyDown(const char * bytes, int32 n); + virtual void MouseDown(BPoint); + virtual void MouseUp(BPoint pt); + virtual void MouseMoved(BPoint pt, uint32 c, const BMessage *m); + virtual void Pulse(); + + virtual void SetLabel(const char *label); + virtual void SetLimitLabels(const char *minLabel, + const char *maxLabel); const char* MinLimitLabel() const; const char* MaxLimitLabel() const; -virtual void SetValue(int32); -virtual int32 ValueForPoint(BPoint) const; -virtual void SetPosition(float); - float Position() const; -virtual void SetEnabled(bool on); - void GetLimits(int32 * minimum, int32 * maximum); + virtual void SetValue(int32); + virtual int32 ValueForPoint(BPoint) const; + virtual void SetPosition(float); + float Position() const; + virtual void SetEnabled(bool on); + void GetLimits(int32 * minimum, int32 * maximum); -virtual void Draw(BRect); -virtual void DrawSlider(); -virtual void DrawBar(); -virtual void DrawHashMarks(); -virtual void DrawThumb(); -virtual void DrawFocusMark(); -virtual void DrawText(); -virtual char* UpdateText() const; - -virtual BRect BarFrame() const; -virtual BRect HashMarksFrame() const; -virtual BRect ThumbFrame() const; + virtual void Draw(BRect); + virtual void DrawSlider(); + virtual void DrawBar(); + virtual void DrawHashMarks(); + virtual void DrawThumb(); + virtual void DrawFocusMark(); + virtual void DrawText(); + virtual char* UpdateText() const; -virtual void SetFlags(uint32 flags); -virtual void SetResizingMode(uint32 mode); + virtual BRect BarFrame() const; + virtual BRect HashMarksFrame() const; + virtual BRect ThumbFrame() const; -virtual void GetPreferredSize( float *width, float *height); -virtual void ResizeToPreferred(); - -virtual status_t Invoke(BMessage *msg=NULL); -virtual BHandler *ResolveSpecifier(BMessage *msg, - int32 index, - BMessage *specifier, - int32 form, - const char *property); -virtual status_t GetSupportedSuites(BMessage *data); - -virtual void SetModificationMessage(BMessage *message); - BMessage *ModificationMessage() const; - -virtual void SetSnoozeAmount(int32); - int32 SnoozeAmount() const; + virtual void SetFlags(uint32 flags); + virtual void SetResizingMode(uint32 mode); -virtual void SetKeyIncrementValue(int32 value); - int32 KeyIncrementValue() const; - -virtual void SetHashMarkCount(int32 count); - int32 HashMarkCount() const; + virtual void GetPreferredSize( float *width, float *height); + virtual void ResizeToPreferred(); -virtual void SetHashMarks(hash_mark_location where); + virtual status_t Invoke(BMessage *msg=NULL); + virtual BHandler* ResolveSpecifier(BMessage *msg, int32 index, + BMessage *specifier, int32 form, + const char *property); + virtual status_t GetSupportedSuites(BMessage* data); + + virtual void SetModificationMessage(BMessage *message); + BMessage* ModificationMessage() const; + + virtual void SetSnoozeAmount(int32); + int32 SnoozeAmount() const; + + virtual void SetKeyIncrementValue(int32 value); + int32 KeyIncrementValue() const; + + virtual void SetHashMarkCount(int32 count); + int32 HashMarkCount() const; + + virtual void SetHashMarks(hash_mark_location where); hash_mark_location HashMarks() const; -virtual void SetStyle(thumb_style s); - thumb_style Style() const; - -virtual void SetBarColor(rgb_color); - rgb_color BarColor() const; -virtual void UseFillColor(bool, const rgb_color* c=NULL); - bool FillColor(rgb_color*) const; - - BView* OffscreenView() const; - - orientation Orientation() const; -virtual void SetOrientation(orientation); + virtual void SetStyle(thumb_style s); + thumb_style Style() const; - float BarThickness() const; -virtual void SetBarThickness(float thickness); + virtual void SetBarColor(rgb_color); + rgb_color BarColor() const; + virtual void UseFillColor(bool, const rgb_color* c=NULL); + bool FillColor(rgb_color*) const; -virtual void SetFont(const BFont *font, uint32 properties = B_FONT_ALL); + BView* OffscreenView() const; + + orientation Orientation() const; + virtual void SetOrientation(orientation); + + float BarThickness() const; + virtual void SetBarThickness(float thickness); + + virtual void SetFont(const BFont *font, uint32 properties = B_FONT_ALL); + +#ifdef __HAIKU__ + virtual void SetLimits(int32 minimum, int32 maximum); // Was _ReservedSlider4() +#endif + + private: + void _DrawBlockThumb(); + void _DrawTriangleThumb(); + + BPoint _Location() const; + void _SetLocation(BPoint p); + + float _MinPosition() const; + float _MaxPosition() const; + bool _ConstrainPoint(BPoint point, BPoint compare) const; #ifndef __HAIKU__ -virtual void _ReservedSlider4(); -#else -virtual void SetLimits(int32 minimum, int32 maximum); // Was _ReservedSlider4() + virtual void _ReservedSlider4(); #endif -/*----- Private or reserved -----------------------------------------*/ -private: - void _DrawBlockThumb(); - void _DrawTriangleThumb(); + virtual void _ReservedSlider5(); + virtual void _ReservedSlider6(); + virtual void _ReservedSlider7(); + virtual void _ReservedSlider8(); + virtual void _ReservedSlider9(); + virtual void _ReservedSlider10(); + virtual void _ReservedSlider11(); + virtual void _ReservedSlider12(); - BPoint _Location() const; - void _SetLocation(BPoint p); + BSlider& operator=(const BSlider &); - float _MinPosition() const; - float _MaxPosition() const; - -//virtual void _ReservedSlider1(); -//virtual void _ReservedSlider2(); -//virtual void _ReservedSlider3(); -//virtual void _ReservedSlider4(); -virtual void _ReservedSlider5(); -virtual void _ReservedSlider6(); -virtual void _ReservedSlider7(); -virtual void _ReservedSlider8(); -virtual void _ReservedSlider9(); -virtual void _ReservedSlider10(); -virtual void _ReservedSlider11(); -virtual void _ReservedSlider12(); - - BSlider &operator=(const BSlider &); - - void _InitObject(); + void _InitObject(); + private: BMessage* fModificationMessage; int32 fSnoozeAmount; @@ -245,6 +205,5 @@ virtual void _ReservedSlider12(); uint32 _reserved[10]; #endif }; -//------------------------------------------------------------------------------ -#endif // _SLIDER_H +#endif // _SLIDER_H diff --git a/src/kits/interface/Slider.cpp b/src/kits/interface/Slider.cpp index 3dd83853f9..1c58acf672 100644 --- a/src/kits/interface/Slider.cpp +++ b/src/kits/interface/Slider.cpp @@ -9,6 +9,8 @@ */ +#include + #include #include @@ -37,7 +39,7 @@ _color_to_long_(rgb_color color) BSlider::BSlider(BRect frame, const char *name, const char *label, BMessage *message, int32 minValue, int32 maxValue, 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; @@ -65,15 +67,13 @@ BSlider::BSlider(BRect frame, const char *name, const char *label, BMessage *mes UseFillColor(false, NULL); _InitObject(); - - ResizeToPreferred(); } BSlider::BSlider(BRect frame, const char *name, const char *label, BMessage *message, int32 minValue, int32 maxValue, orientation posture, 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; @@ -101,8 +101,6 @@ BSlider::BSlider(BRect frame, const char *name, const char *label, BMessage *mes UseFillColor(false, NULL); _InitObject(); - - ResizeToPreferred(); } @@ -113,14 +111,9 @@ BSlider::~BSlider() delete fOffScreenBits; #endif - if (fModificationMessage) - delete fModificationMessage; - - if (fMinLimitStr) - free(fMinLimitStr); - - if (fMaxLimitStr) - free(fMaxLimitStr); + delete fModificationMessage; + free(fMinLimitStr); + free(fMaxLimitStr); } @@ -128,9 +121,8 @@ BSlider::BSlider(BMessage *archive) : BControl (archive) { fModificationMessage = NULL; - - if (archive->HasMessage("_mod_msg")) - { + + if (archive->HasMessage("_mod_msg")) { BMessage *message = new BMessage; archive->FindMessage("_mod_msg", message); @@ -146,13 +138,12 @@ BSlider::BSlider(BMessage *archive) if (archive->FindInt32("_fcolor", &color) == B_OK) { rgb_color fillColor = _long_to_color_(color); UseFillColor(true, &fillColor); - } - else + } else UseFillColor(false); int32 orient; - if(archive->FindInt32("_orient", &orient) == B_OK) + if (archive->FindInt32("_orient", &orient) == B_OK) fOrientation = (orientation)orient; else fOrientation = B_HORIZONTAL; @@ -181,19 +172,19 @@ BSlider::BSlider(BMessage *archive) int16 hashloc; - if(archive->FindInt16("_hashloc", &hashloc) == B_OK) + if (archive->FindInt16("_hashloc", &hashloc) == B_OK) fHashMarks = (hash_mark_location)hashloc; else fHashMarks = B_HASH_MARKS_NONE; int16 sstyle; - if(archive->FindInt16("_sstyle", &sstyle) == B_OK) + if (archive->FindInt16("_sstyle", &sstyle) == B_OK) fStyle = (thumb_style)sstyle; else fStyle = B_BLOCK_THUMB; - if(archive->FindInt32("_bcolor", &color) == B_OK) + if (archive->FindInt32("_bcolor", &color) == B_OK) SetBarColor(_long_to_color_(color)); else { if (Style() == B_BLOCK_THUMB) @@ -215,13 +206,28 @@ BSlider::BSlider(BMessage *archive) } +void +BSlider::_InitObject() +{ + fLocation.x = 0; + fLocation.y = 0; + fInitialLocation.x = 0; + fInitialLocation.y = 0; + +#if USE_OFF_SCREEN_VIEW + fOffScreenBits = NULL; + fOffScreenView = NULL; +#endif +} + + BArchivable* BSlider::Instantiate(BMessage *archive) { if (validate_instantiation(archive, "BSlider")) return new BSlider(archive); - else - return NULL; + + return NULL; } @@ -424,6 +430,33 @@ BSlider::KeyDown(const char *bytes, int32 numBytes) } +bool +BSlider::_ConstrainPoint(BPoint point, BPoint comparePoint) const +{ + if (fOrientation == B_HORIZONTAL) { + if (point.x != comparePoint.x) { + if (point.x < _MinPosition()) + point.x = _MinPosition(); + else if (point.x > _MaxPosition()) + point.x = _MaxPosition(); + + return true; + } + } else { + if (point.y != comparePoint.y) { + if (point.y > _MinPosition()) + point.y = _MinPosition(); + else if (point.y < _MaxPosition()) + point.y = _MaxPosition(); + + return true; + } + } + + return false; +} + + void BSlider::MouseDown(BPoint point) { @@ -433,25 +466,12 @@ BSlider::MouseDown(BPoint point) if (BarFrame().Contains(point) || ThumbFrame().Contains(point)) fInitialLocation = _Location(); - BPoint pt; uint32 buttons; + GetMouse(&point, &buttons, true); - GetMouse(&pt, &buttons, true); + _ConstrainPoint(point, fInitialLocation); + SetValue(ValueForPoint(point)); - if (fOrientation == B_HORIZONTAL) { - if (pt.x < _MinPosition()) - pt.x = _MinPosition(); - else if (pt.x > _MaxPosition()) - pt.x = _MaxPosition(); - } else { - if (pt.y > _MinPosition()) - pt.y = _MinPosition(); - else if (pt.y < _MaxPosition()) - pt.y = _MaxPosition(); - } - - SetValue(ValueForPoint(pt)); - //virtual InvokeNotify(ModificationMessage(), B_CONTROL_MODIFIED); if (Window()->Flags() & B_ASYNCHRONOUS_CONTROLS) { @@ -459,39 +479,16 @@ BSlider::MouseDown(BPoint point) SetMouseEventMask(B_POINTER_EVENTS, B_LOCK_WINDOW_FOCUS); } else { // synchronous mouse tracking - BPoint prevPt; - bool update; + BPoint prevPoint; while (buttons) { - prevPt = pt; - update = false; + prevPoint = point; snooze(SnoozeAmount()); - GetMouse(&pt, &buttons, true); + GetMouse(&point, &buttons, true); - if (fOrientation == B_HORIZONTAL) { - if (pt.x != prevPt.x) { - update = true; - - if (pt.x < _MinPosition()) - pt.x = _MinPosition(); - else if (pt.x > _MaxPosition()) - pt.x = _MaxPosition(); - } - } else { - if (pt.y != prevPt.y) { - update = true; - - if (pt.y > _MinPosition()) - pt.y = _MinPosition(); - else if (pt.y < _MaxPosition()) - pt.y = _MaxPosition(); - } - } - - if (update) { - SetValue(ValueForPoint(pt)); - //virtual + if (_ConstrainPoint(point, prevPoint)) { + SetValue(ValueForPoint(point)); InvokeNotify(ModificationMessage(), B_CONTROL_MODIFIED); } } @@ -521,38 +518,11 @@ void BSlider::MouseMoved(BPoint point, uint32 transit, const BMessage *message) { if (IsTracking()) { - BPoint loc = _Location(); - bool update = false; - - if (fOrientation == B_HORIZONTAL) { - if (point.x != loc.x) { - update = true; - - if (point.x < _MinPosition()) - point.x = _MinPosition(); - else if (point.x > _MaxPosition()) - point.x = _MaxPosition(); - } - } else { - if (point.y != loc.y) { - update = true; - - if (point.y < _MinPosition()) - point.y = _MinPosition(); - else if (point.y > _MaxPosition()) - point.y = _MaxPosition(); - } - } - - if (update) { + if (_ConstrainPoint(point, _Location())) { SetValue(ValueForPoint(point)); - //virtual - } - - if (_Location() != loc) InvokeNotify(ModificationMessage(), B_CONTROL_MODIFIED); - } - else + } + } else BControl::MouseMoved(point, transit, message); } @@ -654,13 +624,9 @@ BSlider::SetValue(int32 value) int32 BSlider::ValueForPoint(BPoint location) const { - if (fOrientation == B_HORIZONTAL) { - return (int32)((location.x - _MinPosition()) * (fMaxValue - fMinValue) / - (_MaxPosition() - _MinPosition())) + fMinValue; - } else { - return (int32)((location.y - _MinPosition()) * (fMaxValue - fMinValue) / - (_MaxPosition() - _MinPosition())) + fMinValue; - } + return (int32)(((fOrientation == B_HORIZONTAL ? location.x : location.y) + - _MinPosition()) + * (fMaxValue - fMinValue) / (_MaxPosition() - _MinPosition())) + fMinValue; } @@ -1021,24 +987,23 @@ BRect BSlider::BarFrame() const { BRect frame(Bounds()); - font_height fheight; - GetFontHeight(&fheight); + font_height fontHeight; + GetFontHeight(&fontHeight); - float textHeight = (float)ceil(fheight.ascent + fheight.descent); + float textHeight = (float)ceil(fontHeight.ascent + fontHeight.descent); if (fStyle == B_BLOCK_THUMB) { if (Orientation() == B_HORIZONTAL) { frame.left = 8.0f; frame.top = 6.0f + (Label() ? textHeight + 4.0f : 0.0f); frame.right -= 8.0f; - frame.bottom = frame.bottom - 6.0f - - (fMinLimitStr || fMaxLimitStr ? textHeight + 4.0f : 0.0f); + frame.bottom = frame.top + fBarThickness; } else { - frame.left = frame.Width() / 2.0f - 3; + frame.left = (frame.Width() - fBarThickness) / 2.0f; frame.top = 12.0f + (Label() ? textHeight : 0.0f) + (fMaxLimitStr ? textHeight : 0.0f); - frame.right = frame.left + 6; + frame.right = frame.left + fBarThickness; frame.bottom = frame.bottom - 8.0f - (fMinLimitStr ? textHeight + 4 : 0.0f); } @@ -1047,13 +1012,12 @@ BSlider::BarFrame() const frame.left = 7.0f; frame.top = 6.0f + (Label() ? textHeight + 4.0f : 0.0f); frame.right -= 7.0f; - frame.bottom = frame.bottom - 6.0f - - (fMinLimitStr || fMaxLimitStr ? textHeight + 4.0f : 0.0f); + frame.bottom = frame.top + fBarThickness; } else { - frame.left = frame.Width() / 2.0f - 3; + frame.left = (frame.Width() - fBarThickness) / 2.0f; frame.top = 11.0f + (Label() ? textHeight : 0.0f) + (fMaxLimitStr ? textHeight : 0.0f); - frame.right = frame.left + 6; + frame.right = frame.left + fBarThickness; frame.bottom = frame.bottom - 7.0f - (fMinLimitStr ? textHeight + 4 : 0.0f); } @@ -1100,25 +1064,24 @@ BSlider::ThumbFrame() const _MinPosition()) - 8.0f; frame.top = 2.0f + (Label() ? textHeight + 4.0f : 0.0f); frame.right = frame.left + 17.0f; - frame.bottom = frame.bottom - 3.0f - - (MinLimitLabel() || MaxLimitLabel() ? textHeight + 4.0f : 0.0f); + frame.bottom = frame.top + fBarThickness + 7.0f; } else { - frame.left = frame.Width() / 2.0f - 7; + frame.left = (frame.Width() - fBarThickness) / 2.0f - 4; frame.top = (float)floor(Position() * (_MaxPosition() - _MinPosition()) + _MinPosition()) - 8.0f; - frame.right = frame.left + 13; + frame.right = frame.left + fBarThickness + 7.0f; frame.bottom = frame.top + 17; } } else { if (Orientation() == B_HORIZONTAL) { frame.left = (float)floor(Position() * (_MaxPosition() - _MinPosition()) + _MinPosition()) - 6; - frame.top = 9.0f + (Label() ? textHeight + 4.0f : 0.0f); frame.right = frame.left + 12.0f; frame.bottom = frame.bottom - 2.0f - (MinLimitLabel() || MaxLimitLabel() ? textHeight + 4.0f : 0.0f); + frame.top = frame.bottom - 7.0f; } else { - frame.left = frame.Width() / 2.0f - 6; + frame.left = (frame.Width() - fBarThickness) / 2.0f - 3; frame.top = (float)floor(Position() * (_MaxPosition() - _MinPosition())) + _MinPosition() - 6.0f; frame.right = frame.left + 7; @@ -1145,38 +1108,81 @@ BSlider::SetResizingMode(uint32 mode) void -BSlider::GetPreferredSize(float *width, float *height) +BSlider::GetPreferredSize(float* _width, float* _height) { - font_height fheight; + font_height fontHeight; + GetFontHeight(&fontHeight); - GetFontHeight(&fheight); + int32 rows = 0; if (Orientation() == B_HORIZONTAL) { - *width = (Frame().Width() < 32.0f) ? 32.0f : Frame().Width(); - *height = 18.0f; - - if (Label()) - *height += (float)ceil(fheight.ascent + fheight.descent) + 4.0f; + *_width = Frame().Width(); + *_height = 12.0f + fBarThickness; + + float labelWidth = 0; + if (Label()) { + labelWidth = StringWidth(Label()); + rows++; + } + + float minWidth = 0; + if (MinLimitLabel()) + minWidth = StringWidth(MinLimitLabel()); + if (MaxLimitLabel()) { + // some space between the labels + if (MinLimitLabel()) + minWidth += 8.0f; + + minWidth += StringWidth(MaxLimitLabel()); + } + + if (minWidth > *_width) + *_width = minWidth; + if (labelWidth > *_width) + *_width = labelWidth; + if (*_width < 32.0f) + *_width = 32.0f; if (MinLimitLabel() || MaxLimitLabel()) - *height += (float)ceil(fheight.ascent + fheight.descent) + 4.0f; - } else { // B_VERTICAL - *width = (Frame().Width() < 18.0f) ? 18.0f : Frame().Width(); - *height = 32.0f; - - if (Label()) - *height += (float)ceil(fheight.ascent + fheight.descent) + 4.0f; + rows++; - if (MaxLimitLabel()) - *height += (float)ceil(fheight.ascent + fheight.descent) + 4.0f; + *_height += rows * ((float)ceil(fontHeight.ascent + fontHeight.descent) + 4.0f); + } else { + // B_VERTICAL + *_width = 12.0f + fBarThickness; + *_height = Frame().Height(); - if (MinLimitLabel()) - *height += (float)ceil(fheight.ascent + fheight.descent) + 4.0f; + // find largest label - if (Label() && (MaxLimitLabel())) - *height -= 4.0f; + float minWidth = 0; + if (Label()) { + minWidth = StringWidth(Label()); + rows++; + } + if (MinLimitLabel()) { + float width = StringWidth(MinLimitLabel()); + if (width > minWidth) + minWidth = width; + rows++; + } + if (MaxLimitLabel()) { + float width = StringWidth(MaxLimitLabel()); + if (width > minWidth) + minWidth = width; + rows++; + } - *height = (Frame().Height() < *height) ? *height : Frame().Height(); + if (minWidth > *_width) + *_width = minWidth; + + float minHeight = 32.0f + rows + * ((float)ceil(fontHeight.ascent + fontHeight.descent) + 4.0f); + + if (Label() && MaxLimitLabel()) + minHeight -= 4.0f; + + if (minHeight > *_height) + *_height = minHeight; } } @@ -1380,7 +1386,8 @@ BSlider::BarThickness() const void BSlider::SetBarThickness(float thickness) { - fBarThickness = thickness; + if (thickness >= 1.0f) + fBarThickness = thickness; } @@ -1673,18 +1680,3 @@ BSlider::operator=(const BSlider &) return *this; } - -void -BSlider::_InitObject() -{ - fLocation.x = 0; - fLocation.y = 0; - fInitialLocation.x = 0; - fInitialLocation.y = 0; - -#if USE_OFF_SCREEN_VIEW - fOffScreenBits = NULL; - fOffScreenView = NULL; -#endif -} -