2015-11-19 07:47:53 -06:00
|
|
|
// 18 november 2015
|
|
|
|
#include "uipriv_haiku.hpp"
|
|
|
|
|
2015-11-22 10:00:14 -06:00
|
|
|
// TODO any of this on api.haiku-os.org?
|
|
|
|
// TODO tracking events?
|
|
|
|
|
2015-11-19 07:47:53 -06:00
|
|
|
struct uiSlider {
|
|
|
|
uiHaikuControl c;
|
2015-11-22 10:00:14 -06:00
|
|
|
BSlider *slider;
|
|
|
|
void (*onChanged)(uiSlider *, void *);
|
|
|
|
void *onChangedData;
|
2015-11-19 07:47:53 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
uiHaikuDefineControl(
|
|
|
|
uiSlider, // type name
|
|
|
|
uiSliderType, // type function
|
2015-11-22 10:00:14 -06:00
|
|
|
slider // handle
|
2015-11-19 07:47:53 -06:00
|
|
|
)
|
|
|
|
|
2015-11-22 10:00:14 -06:00
|
|
|
#define mSliderChanged 0x6060FEFE
|
|
|
|
|
|
|
|
static void onChanged(BMessage *msg)
|
|
|
|
{
|
|
|
|
void *ss;
|
|
|
|
uiSlider *s;
|
|
|
|
|
|
|
|
// TODO error check
|
|
|
|
msg->FindPointer(mControlField, &ss);
|
|
|
|
s = uiSlider(ss);
|
|
|
|
(*(s->onChanged))(s, s->onChangedData);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void defaultOnChanged(uiSlider *s, void *data)
|
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
2015-11-19 07:47:53 -06:00
|
|
|
intmax_t uiSliderValue(uiSlider *s)
|
|
|
|
{
|
2015-11-22 10:00:14 -06:00
|
|
|
return s->slider->Value();
|
2015-11-19 07:47:53 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void uiSliderSetValue(uiSlider *s, intmax_t value)
|
|
|
|
{
|
2015-11-22 10:00:14 -06:00
|
|
|
// TODO does this trigger an event?
|
|
|
|
s->slider->SetValue(value);
|
2015-11-19 07:47:53 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void uiSliderOnChanged(uiSlider *s, void (*f)(uiSlider *s, void *data), void *data)
|
|
|
|
{
|
2015-11-22 10:00:14 -06:00
|
|
|
s->onChanged = f;
|
|
|
|
s->onChangedData = data;
|
2015-11-19 07:47:53 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
uiSlider *uiNewSlider(intmax_t min, intmax_t max)
|
|
|
|
{
|
|
|
|
uiSlider *s;
|
2015-11-22 10:00:14 -06:00
|
|
|
BMessage *msg;
|
2015-11-19 07:47:53 -06:00
|
|
|
|
|
|
|
s = (uiSlider *) uiNewControl(uiSliderType());
|
|
|
|
|
2015-11-22 10:00:14 -06:00
|
|
|
uiHaikuRegisterEventHandler(mSliderChanged, onChanged);
|
|
|
|
msg = new BMessage(mSliderChanged);
|
|
|
|
msg->AddPointer(mControlField, s);
|
|
|
|
|
|
|
|
s->slider = new BSlider(NULL, NULL, msg,
|
|
|
|
min, max, B_HORIZONTAL);
|
|
|
|
|
|
|
|
uiSliderOnChanged(s, defaultOnChanged, NULL);
|
2015-11-19 07:47:53 -06:00
|
|
|
|
|
|
|
uiHaikuFinishNewControl(s, uiSlider);
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|