2 * Copyright 2015 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT license.
6 * John Scipione, jscipione@gmail.com
15 #include <PropertyInfo.h>
20 static property_info sProperties
[] = {
23 { B_GET_PROPERTY
, 0 },
24 { B_DIRECT_SPECIFIER
, 0 },
25 "Returns the maximum value of the spinner.",
31 { B_SET_PROPERTY
, 0 },
32 { B_DIRECT_SPECIFIER
, 0},
33 "Sets the maximum value of the spinner.",
40 { B_GET_PROPERTY
, 0 },
41 { B_DIRECT_SPECIFIER
, 0 },
42 "Returns the minimum value of the spinner.",
48 { B_SET_PROPERTY
, 0 },
49 { B_DIRECT_SPECIFIER
, 0},
50 "Sets the minimum value of the spinner.",
57 { B_GET_PROPERTY
, 0 },
58 { B_DIRECT_SPECIFIER
, 0 },
59 "Returns the value of the spinner.",
65 { B_SET_PROPERTY
, 0 },
66 { B_DIRECT_SPECIFIER
, 0},
67 "Sets the value of the spinner.",
76 // #pragma mark - BSpinner
79 BSpinner::BSpinner(BRect frame
, const char* name
, const char* label
,
80 BMessage
* message
, uint32 resizingMode
, uint32 flags
)
82 BAbstractSpinner(frame
, name
, label
, message
, resizingMode
, flags
)
88 BSpinner::BSpinner(const char* name
, const char* label
,
89 BMessage
* message
, uint32 flags
)
91 BAbstractSpinner(name
, label
, message
, flags
)
97 BSpinner::BSpinner(BMessage
* data
)
99 BAbstractSpinner(data
)
103 if (data
->FindInt32("_min", &fMinValue
) != B_OK
)
104 fMinValue
= INT32_MIN
;
106 if (data
->FindInt32("_max", &fMaxValue
) != B_OK
)
107 fMaxValue
= INT32_MAX
;
109 if (data
->FindInt32("_val", &fValue
) != B_OK
)
114 BSpinner::~BSpinner()
120 BSpinner::Instantiate(BMessage
* data
)
122 if (validate_instantiation(data
, "Spinner"))
123 return new BSpinner(data
);
130 BSpinner::Archive(BMessage
* data
, bool deep
) const
132 status_t status
= BAbstractSpinner::Archive(data
, deep
);
133 data
->AddString("class", "Spinner");
136 status
= data
->AddInt32("_min", fMinValue
);
139 status
= data
->AddInt32("_max", fMaxValue
);
142 status
= data
->AddInt32("_val", fValue
);
149 BSpinner::GetSupportedSuites(BMessage
* message
)
151 message
->AddString("suites", "suite/vnd.Haiku-intenger-spinner");
153 BPropertyInfo
prop_info(sProperties
);
154 message
->AddFlat("messages", &prop_info
);
156 return BView::GetSupportedSuites(message
);
161 BSpinner::AttachedToWindow()
165 BAbstractSpinner::AttachedToWindow();
170 BSpinner::Decrement()
172 SetValue(Value() - 1);
177 BSpinner::Increment()
179 SetValue(Value() + 1);
184 BSpinner::SetEnabled(bool enable
)
186 if (IsEnabled() == enable
)
189 SetIncrementEnabled(enable
&& Value() < fMaxValue
);
190 SetDecrementEnabled(enable
&& Value() > fMinValue
);
192 BAbstractSpinner::SetEnabled(enable
);
197 BSpinner::SetMinValue(int32 min
)
200 if (fValue
< fMinValue
)
206 BSpinner::SetMaxValue(int32 max
)
209 if (fValue
> fMaxValue
)
215 BSpinner::Range(int32
* min
, int32
* max
)
223 BSpinner::SetRange(int32 min
, int32 max
)
231 BSpinner::SetValue(int32 value
)
234 if (value
< fMinValue
)
236 else if (value
> fMaxValue
)
239 // update the text view
241 valueString
<< value
;
242 TextView()->SetText(valueString
.String());
244 // update the up and down arrows
245 SetIncrementEnabled(IsEnabled() && value
< fMaxValue
);
246 SetDecrementEnabled(IsEnabled() && value
> fMinValue
);
260 BSpinner::SetValueFromText()
262 SetValue(atol(TextView()->Text()));
266 // #pragma mark - BSpinner private methods
270 BSpinner::_InitObject()
272 fMinValue
= INT32_MIN
;
273 fMaxValue
= INT32_MAX
;
276 TextView()->SetAlignment(B_ALIGN_RIGHT
);
277 for (uint32 c
= 0; c
<= 42; c
++)
278 TextView()->DisallowChar(c
);
280 TextView()->DisallowChar(',');
282 for (uint32 c
= 46; c
<= 47; c
++)
283 TextView()->DisallowChar(c
);
285 for (uint32 c
= 58; c
<= 127; c
++)
286 TextView()->DisallowChar(c
);
292 void BSpinner::_ReservedSpinner20() {}
293 void BSpinner::_ReservedSpinner19() {}
294 void BSpinner::_ReservedSpinner18() {}
295 void BSpinner::_ReservedSpinner17() {}
296 void BSpinner::_ReservedSpinner16() {}
297 void BSpinner::_ReservedSpinner15() {}
298 void BSpinner::_ReservedSpinner14() {}
299 void BSpinner::_ReservedSpinner13() {}
300 void BSpinner::_ReservedSpinner12() {}
301 void BSpinner::_ReservedSpinner11() {}
302 void BSpinner::_ReservedSpinner10() {}
303 void BSpinner::_ReservedSpinner9() {}
304 void BSpinner::_ReservedSpinner8() {}
305 void BSpinner::_ReservedSpinner7() {}
306 void BSpinner::_ReservedSpinner6() {}
307 void BSpinner::_ReservedSpinner5() {}
308 void BSpinner::_ReservedSpinner4() {}
309 void BSpinner::_ReservedSpinner3() {}
310 void BSpinner::_ReservedSpinner2() {}
311 void BSpinner::_ReservedSpinner1() {}