Split BSpinner into BAbstractSpinner and...
2 concrete classes which are currently implemented: * BSpinner (works on int32s) * BDecimalSpinner (works on doubles) In addition BAbstractSpinner now inherits from BControl instead of BView/BInvoker. This allowed for code simplification at the cost of needing to cast for the decimal version because SetValue(int32 value) comes from BControl. Also, add a spinner_button_style enum with 3 options: * SPINNER_BUTTON_HORIZONTAL_ARROWS * SPINNER_BUTTON_VERTICAL_ARROWS * SPINNER_BUTTON_PLUS_MINUS which sets the spinner arrows to either use horizontal arrows (left/right) vertical arrows, (up/down), or +/- symbols (the default). If the spinner button is using horizontal arrows you can decrement and increment the spinner value by pushing control+left/right, otherwise you can increment and decrement by pushing up or down. The reason for needing control is so that you can move the cursor in the textbox otherwise. Switch the 3 apps that are currently using BSpinners to use the integer variety in Deskbar preferences, WebPostive preferences, and Screen preferences.
This commit is contained in:
@@ -0,0 +1,168 @@
|
||||
/*
|
||||
* Copyright 2004 DarkWyrm <[email protected]>
|
||||
* Copyright 2013 FeemanLou
|
||||
* Copyright 2014-2015 Haiku, Inc. All rights reserved.
|
||||
*
|
||||
* Distributed under the terms of the MIT license.
|
||||
*
|
||||
* Originally written by DarkWyrm <[email protected]>
|
||||
* Updated by FreemanLou as part of Google GCI 2013
|
||||
*
|
||||
* Authors:
|
||||
* DarkWyrm, [email protected]
|
||||
* FeemanLou
|
||||
* John Scipione, [email protected]
|
||||
*/
|
||||
#ifndef _ABSTRACT_SPINNER_H
|
||||
#define _ABSTRACT_SPINNER_H
|
||||
|
||||
|
||||
#include <Control.h>
|
||||
|
||||
|
||||
typedef enum {
|
||||
SPINNER_BUTTON_HORIZONTAL_ARROWS,
|
||||
SPINNER_BUTTON_VERTICAL_ARROWS,
|
||||
SPINNER_BUTTON_PLUS_MINUS
|
||||
} spinner_button_style;
|
||||
|
||||
|
||||
class BTextView;
|
||||
class SpinnerButton;
|
||||
class SpinnerTextView;
|
||||
|
||||
|
||||
/*! BAbstractSpinner provides an input whose value can be nudged up or down
|
||||
by way of two small buttons on the right.
|
||||
*/
|
||||
class BAbstractSpinner : public BControl {
|
||||
public:
|
||||
BAbstractSpinner(BRect frame, const char* name,
|
||||
const char* label, BMessage* message,
|
||||
uint32 resizingMode = B_FOLLOW_LEFT | B_FOLLOW_TOP,
|
||||
uint32 flags = B_WILL_DRAW | B_NAVIGABLE);
|
||||
BAbstractSpinner(const char* name, const char* label,
|
||||
BMessage* message,
|
||||
uint32 flags = B_WILL_DRAW | B_NAVIGABLE);
|
||||
BAbstractSpinner(BMessage* data);
|
||||
virtual ~BAbstractSpinner();
|
||||
|
||||
static BArchivable* Instantiate(BMessage* data);
|
||||
virtual status_t Archive(BMessage* data, bool deep = true) const;
|
||||
|
||||
virtual status_t GetSupportedSuites(BMessage* message);
|
||||
virtual BHandler* ResolveSpecifier(BMessage* message, int32 index,
|
||||
BMessage* specifier, int32 form,
|
||||
const char* property);
|
||||
|
||||
virtual void AttachedToWindow();
|
||||
virtual void Draw(BRect updateRect);
|
||||
virtual void FrameResized(float width, float height);
|
||||
virtual void ValueChanged();
|
||||
|
||||
virtual void Decrement() = 0;
|
||||
virtual void Increment() = 0;
|
||||
virtual void MakeFocus(bool focus = true);
|
||||
virtual void ResizeToPreferred();
|
||||
virtual void SetFlags(uint32 flags);
|
||||
virtual void WindowActivated(bool active);
|
||||
|
||||
alignment Alignment() const { return fAlignment; };
|
||||
virtual void SetAlignment(alignment align);
|
||||
|
||||
spinner_button_style ButtonStyle() const { return fButtonStyle; };
|
||||
virtual void SetButtonStyle(spinner_button_style buttonStyle);
|
||||
|
||||
float Divider() const { return fDivider; };
|
||||
virtual void SetDivider(float position);
|
||||
|
||||
virtual void SetEnabled(bool enable);
|
||||
|
||||
virtual void SetLabel(const char* label);
|
||||
|
||||
virtual void SetValueFromText() = 0;
|
||||
|
||||
bool IsDecrementEnabled() const;
|
||||
virtual void SetDecrementEnabled(bool enable);
|
||||
|
||||
bool IsIncrementEnabled() const;
|
||||
virtual void SetIncrementEnabled(bool enable);
|
||||
|
||||
virtual BSize MinSize();
|
||||
virtual BSize MaxSize();
|
||||
virtual BSize PreferredSize();
|
||||
virtual BAlignment LayoutAlignment();
|
||||
|
||||
BLayoutItem* CreateLabelLayoutItem();
|
||||
BLayoutItem* CreateTextViewLayoutItem();
|
||||
|
||||
BTextView* TextView() const;
|
||||
|
||||
private:
|
||||
// FBC padding
|
||||
virtual void _ReservedAbstractSpinner20();
|
||||
virtual void _ReservedAbstractSpinner19();
|
||||
virtual void _ReservedAbstractSpinner18();
|
||||
virtual void _ReservedAbstractSpinner17();
|
||||
virtual void _ReservedAbstractSpinner16();
|
||||
virtual void _ReservedAbstractSpinner15();
|
||||
virtual void _ReservedAbstractSpinner14();
|
||||
virtual void _ReservedAbstractSpinner13();
|
||||
virtual void _ReservedAbstractSpinner12();
|
||||
virtual void _ReservedAbstractSpinner11();
|
||||
virtual void _ReservedAbstractSpinner10();
|
||||
virtual void _ReservedAbstractSpinner9();
|
||||
virtual void _ReservedAbstractSpinner8();
|
||||
virtual void _ReservedAbstractSpinner7();
|
||||
virtual void _ReservedAbstractSpinner6();
|
||||
virtual void _ReservedAbstractSpinner5();
|
||||
virtual void _ReservedAbstractSpinner4();
|
||||
virtual void _ReservedAbstractSpinner3();
|
||||
virtual void _ReservedAbstractSpinner2();
|
||||
virtual void _ReservedAbstractSpinner1();
|
||||
|
||||
protected:
|
||||
virtual status_t AllArchived(BMessage* into) const;
|
||||
virtual status_t AllUnarchived(const BMessage* from);
|
||||
|
||||
virtual void LayoutInvalidated(bool descendants);
|
||||
virtual void DoLayout();
|
||||
|
||||
private:
|
||||
class LabelLayoutItem;
|
||||
class TextViewLayoutItem;
|
||||
struct LayoutData;
|
||||
|
||||
friend class SpinnerButton;
|
||||
friend class SpinnerTextView;
|
||||
|
||||
friend class LabelLayoutItem;
|
||||
friend class TextViewLayoutItem;
|
||||
friend struct LayoutData;
|
||||
|
||||
void _DrawLabel(BRect updateRect);
|
||||
void _DrawTextView(BRect updateRect);
|
||||
void _InitObject();
|
||||
void _LayoutTextView();
|
||||
void _UpdateFrame();
|
||||
void _UpdateTextViewColors(bool enable);
|
||||
void _ValidateLayoutData();
|
||||
|
||||
BAbstractSpinner& operator=(const BAbstractSpinner& other);
|
||||
|
||||
alignment fAlignment;
|
||||
spinner_button_style fButtonStyle;
|
||||
float fDivider;
|
||||
|
||||
LayoutData* fLayoutData;
|
||||
|
||||
SpinnerTextView* fTextView;
|
||||
SpinnerButton* fIncrement;
|
||||
SpinnerButton* fDecrement;
|
||||
|
||||
// FBC padding
|
||||
uint32 _reserved[20];
|
||||
};
|
||||
|
||||
|
||||
#endif // _ABSTRACT_SPINNER_H
|
||||
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* Copyright 2015 Haiku, Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT license.
|
||||
*
|
||||
* Authors:
|
||||
* John Scipione, [email protected]
|
||||
*/
|
||||
#ifndef _DECIMAL_SPINNER_H
|
||||
#define _DECIMAL_SPINNER_H
|
||||
|
||||
|
||||
#include <Spinner.h>
|
||||
|
||||
|
||||
class BDecimalSpinner : public BAbstractSpinner {
|
||||
public:
|
||||
BDecimalSpinner(BRect frame, const char* name,
|
||||
const char* label, BMessage* message,
|
||||
uint32 resizingMode = B_FOLLOW_LEFT | B_FOLLOW_TOP,
|
||||
uint32 flags = B_WILL_DRAW | B_NAVIGABLE);
|
||||
BDecimalSpinner(const char* name, const char* label,
|
||||
BMessage* message,
|
||||
uint32 flags = B_WILL_DRAW | B_NAVIGABLE);
|
||||
BDecimalSpinner(BMessage* data);
|
||||
virtual ~BDecimalSpinner();
|
||||
|
||||
static BArchivable* Instantiate(BMessage* data);
|
||||
virtual status_t Archive(BMessage* data, bool deep = true) const;
|
||||
|
||||
virtual status_t GetSupportedSuites(BMessage* message);
|
||||
|
||||
virtual void AttachedToWindow();
|
||||
|
||||
virtual void Increment();
|
||||
virtual void Decrement();
|
||||
|
||||
virtual void SetEnabled(bool enable);
|
||||
|
||||
uint32 Precision() const { return fPrecision; };
|
||||
virtual void SetPrecision(uint32 precision) { fPrecision = precision; };
|
||||
|
||||
double MaxValue() const { return fMaxValue; }
|
||||
virtual void SetMaxValue(double max);
|
||||
|
||||
double MinValue() const { return fMinValue; }
|
||||
virtual void SetMinValue(double min);
|
||||
|
||||
void Range(double* min, double* max);
|
||||
virtual void SetRange(double min, double max);
|
||||
|
||||
double Step() const { return fStep; }
|
||||
virtual void SetStep(double step) { fStep = step; };
|
||||
|
||||
double Value() const { return fValue; };
|
||||
virtual void SetValue(int32 value);
|
||||
virtual void SetValue(double value);
|
||||
virtual void SetValueFromText();
|
||||
|
||||
private:
|
||||
// FBC padding
|
||||
virtual void _ReservedDecimalSpinner20();
|
||||
virtual void _ReservedDecimalSpinner19();
|
||||
virtual void _ReservedDecimalSpinner18();
|
||||
virtual void _ReservedDecimalSpinner17();
|
||||
virtual void _ReservedDecimalSpinner16();
|
||||
virtual void _ReservedDecimalSpinner15();
|
||||
virtual void _ReservedDecimalSpinner14();
|
||||
virtual void _ReservedDecimalSpinner13();
|
||||
virtual void _ReservedDecimalSpinner12();
|
||||
virtual void _ReservedDecimalSpinner11();
|
||||
virtual void _ReservedDecimalSpinner10();
|
||||
virtual void _ReservedDecimalSpinner9();
|
||||
virtual void _ReservedDecimalSpinner8();
|
||||
virtual void _ReservedDecimalSpinner7();
|
||||
virtual void _ReservedDecimalSpinner6();
|
||||
virtual void _ReservedDecimalSpinner5();
|
||||
virtual void _ReservedDecimalSpinner4();
|
||||
virtual void _ReservedDecimalSpinner3();
|
||||
virtual void _ReservedDecimalSpinner2();
|
||||
virtual void _ReservedDecimalSpinner1();
|
||||
|
||||
private:
|
||||
void _InitObject();
|
||||
|
||||
double fMinValue;
|
||||
double fMaxValue;
|
||||
double fStep;
|
||||
double fValue;
|
||||
uint32 fPrecision;
|
||||
|
||||
// FBC padding
|
||||
uint32 _reserved[20];
|
||||
};
|
||||
|
||||
|
||||
#endif // _DECIMAL_SPINNER_H
|
||||
@@ -1,35 +1,18 @@
|
||||
/*
|
||||
* Copyright 2004 DarkWyrm <[email protected]>
|
||||
* Copyright 2013 FeemanLou
|
||||
* Copyright 2014 Haiku, Inc. All rights reserved.
|
||||
*
|
||||
* Copyright 2015 Haiku, Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT license.
|
||||
*
|
||||
* Originally written by DarkWyrm <[email protected]>
|
||||
* Updated by FreemanLou as part of Google GCI 2013
|
||||
*
|
||||
* Authors:
|
||||
* DarkWyrm, [email protected]
|
||||
* FeemanLou
|
||||
* John Scipione, [email protected]
|
||||
*/
|
||||
#ifndef SPINNER_H
|
||||
#define SPINNER_H
|
||||
#ifndef _SPINNER_H
|
||||
#define _SPINNER_H
|
||||
|
||||
|
||||
#include <Invoker.h>
|
||||
#include <View.h>
|
||||
#include <AbstractSpinner.h>
|
||||
|
||||
|
||||
class BTextView;
|
||||
class SpinnerArrow;
|
||||
class SpinnerTextView;
|
||||
|
||||
|
||||
/*! BSpinner provides a numeric input whose value can be nudged up or down
|
||||
by way of two small buttons on the right.
|
||||
*/
|
||||
class BSpinner : public BView, public BInvoker {
|
||||
class BSpinner : public BAbstractSpinner {
|
||||
public:
|
||||
BSpinner(BRect frame, const char* name,
|
||||
const char* label, BMessage* message,
|
||||
@@ -44,69 +27,27 @@ public:
|
||||
static BArchivable* Instantiate(BMessage* data);
|
||||
virtual status_t Archive(BMessage* data, bool deep = true) const;
|
||||
|
||||
virtual void Increment();
|
||||
virtual void Decrement();
|
||||
|
||||
virtual status_t GetSupportedSuites(BMessage* message);
|
||||
virtual BHandler* ResolveSpecifier(BMessage* message, int32 index,
|
||||
BMessage* specifier, int32 form,
|
||||
const char* property);
|
||||
|
||||
virtual void AttachedToWindow();
|
||||
virtual void Draw(BRect updateRect);
|
||||
virtual void FrameResized(float width, float height);
|
||||
virtual void ValueChanged();
|
||||
|
||||
virtual void Decrement();
|
||||
virtual void Increment();
|
||||
virtual void MakeFocus(bool focus = true);
|
||||
virtual void ResizeToPreferred();
|
||||
virtual void SetFlags(uint32 flags);
|
||||
virtual void SetValueFromText();
|
||||
virtual void WindowActivated(bool active);
|
||||
|
||||
alignment Alignment() const { return fAlignment; };
|
||||
virtual void SetAlignment(alignment align);
|
||||
|
||||
float Divider() const { return fDivider; };
|
||||
virtual void SetDivider(float position);
|
||||
|
||||
bool IsEnabled() const { return fIsEnabled; };
|
||||
virtual void SetEnabled(bool enable);
|
||||
|
||||
const char* Label() const { return fLabel; };
|
||||
virtual void SetLabel(const char* text);
|
||||
int32 MaxValue() const { return fMaxValue; }
|
||||
virtual void SetMaxValue(int32 max);
|
||||
|
||||
uint32 Precision() const { return fPrecision; };
|
||||
virtual void SetPrecision(uint32 precision) { fPrecision = precision; };
|
||||
int32 MinValue() const { return fMinValue; }
|
||||
virtual void SetMinValue(int32 min);
|
||||
|
||||
double MaxValue() const { return fMaxValue; }
|
||||
virtual void SetMaxValue(double max);
|
||||
void Range(int32* min, int32* max);
|
||||
virtual void SetRange(int32 min, int32 max);
|
||||
|
||||
double MinValue() const { return fMinValue; }
|
||||
virtual void SetMinValue(double min);
|
||||
|
||||
void Range(double* min, double* max);
|
||||
virtual void SetRange(double min, double max);
|
||||
|
||||
double Step() const { return fStep; }
|
||||
virtual void SetStep(double step) { fStep = step; };
|
||||
|
||||
double Value() const { return fValue; };
|
||||
virtual void SetValue(double value);
|
||||
|
||||
bool IsDecrementEnabled() const;
|
||||
virtual void SetDecrementEnabled(bool enable);
|
||||
|
||||
bool IsIncrementEnabled() const;
|
||||
virtual void SetIncrementEnabled(bool enable);
|
||||
|
||||
virtual BSize MinSize();
|
||||
virtual BSize MaxSize();
|
||||
virtual BSize PreferredSize();
|
||||
virtual BAlignment LayoutAlignment();
|
||||
|
||||
BLayoutItem* CreateLabelLayoutItem();
|
||||
BLayoutItem* CreateTextViewLayoutItem();
|
||||
|
||||
BTextView* TextView() const;
|
||||
int32 Value() const { return fValue; };
|
||||
virtual void SetValue(int32 value);
|
||||
virtual void SetValueFromText();
|
||||
|
||||
private:
|
||||
// FBC padding
|
||||
@@ -131,54 +72,16 @@ private:
|
||||
virtual void _ReservedSpinner2();
|
||||
virtual void _ReservedSpinner1();
|
||||
|
||||
protected:
|
||||
virtual status_t AllArchived(BMessage* into) const;
|
||||
virtual status_t AllUnarchived(const BMessage* from);
|
||||
|
||||
virtual void LayoutInvalidated(bool descendants);
|
||||
virtual void DoLayout();
|
||||
|
||||
private:
|
||||
class LabelLayoutItem;
|
||||
class TextViewLayoutItem;
|
||||
struct LayoutData;
|
||||
|
||||
friend class SpinnerArrow;
|
||||
friend class SpinnerTextView;
|
||||
|
||||
friend class LabelLayoutItem;
|
||||
friend class TextViewLayoutItem;
|
||||
friend struct LayoutData;
|
||||
|
||||
void _DrawLabel(BRect updateRect);
|
||||
void _DrawTextView(BRect updateRect);
|
||||
void _InitObject();
|
||||
void _LayoutTextView();
|
||||
void _UpdateFrame();
|
||||
void _UpdateTextViewColors(bool enable);
|
||||
void _ValidateLayoutData();
|
||||
|
||||
BSpinner& operator=(const BSpinner& other);
|
||||
|
||||
alignment fAlignment;
|
||||
float fDivider;
|
||||
bool fIsEnabled;
|
||||
const char* fLabel;
|
||||
double fMinValue;
|
||||
double fMaxValue;
|
||||
double fStep;
|
||||
double fValue;
|
||||
uint32 fPrecision;
|
||||
|
||||
LayoutData* fLayoutData;
|
||||
|
||||
SpinnerTextView* fTextView;
|
||||
SpinnerArrow* fIncrement;
|
||||
SpinnerArrow* fDecrement;
|
||||
int32 fMinValue;
|
||||
int32 fMaxValue;
|
||||
int32 fValue;
|
||||
|
||||
// FBC padding
|
||||
uint32 _reserved[20];
|
||||
};
|
||||
|
||||
|
||||
#endif // SPINNER_H
|
||||
#endif // _SPINNER_H
|
||||
|
||||
Reference in New Issue
Block a user