2015-11-19 07:47:53 -06:00
|
|
|
// 18 november 2015
|
|
|
|
#include "uipriv_haiku.hpp"
|
|
|
|
|
2015-11-19 16:26:40 -06:00
|
|
|
// TODOs
|
|
|
|
// - checkbox text isn't aligned with the checkbox
|
|
|
|
|
2015-11-19 07:47:53 -06:00
|
|
|
struct uiCheckbox {
|
|
|
|
uiHaikuControl c;
|
2015-11-19 16:26:40 -06:00
|
|
|
BCheckBox *checkbox;
|
|
|
|
void (*onToggled)(uiCheckbox *, void *);
|
|
|
|
void *onToggledData;
|
2015-11-19 07:47:53 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
uiHaikuDefineControl(
|
|
|
|
uiCheckbox, // type name
|
|
|
|
uiCheckboxType, // type function
|
2015-11-19 16:26:40 -06:00
|
|
|
checkbox // handle
|
2015-11-19 07:47:53 -06:00
|
|
|
)
|
|
|
|
|
2015-11-19 16:26:40 -06:00
|
|
|
#define mCheckboxToggled 0x4E714E71
|
|
|
|
|
|
|
|
static void defaultOnToggled(uiCheckbox *c, void *data)
|
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
2015-11-19 07:47:53 -06:00
|
|
|
char *uiCheckboxText(uiCheckbox *c)
|
|
|
|
{
|
2015-11-19 16:26:40 -06:00
|
|
|
// TODO not on api.haiku-os.org? or is this not right?
|
|
|
|
return uiHaikuStrdupText(c->checkbox->Label());
|
2015-11-19 07:47:53 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void uiCheckboxSetText(uiCheckbox *c, const char *text)
|
|
|
|
{
|
2015-11-19 16:26:40 -06:00
|
|
|
// TODO not on api.haiku-os.org? or is this not right?
|
|
|
|
c->checkbox->SetLabel(text);
|
2015-11-19 07:47:53 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void uiCheckboxOnToggled(uiCheckbox *c, void (*f)(uiCheckbox *c, void *data), void *data)
|
|
|
|
{
|
2015-11-19 16:26:40 -06:00
|
|
|
c->onToggled = f;
|
|
|
|
c->onToggledData = data;
|
2015-11-19 07:47:53 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
int uiCheckboxChecked(uiCheckbox *c)
|
|
|
|
{
|
2015-11-19 16:26:40 -06:00
|
|
|
return c->checkbox->Value() != B_CONTROL_OFF;
|
2015-11-19 07:47:53 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void uiCheckboxSetChecked(uiCheckbox *c, int checked)
|
|
|
|
{
|
2015-11-19 16:26:40 -06:00
|
|
|
int32 value;
|
|
|
|
|
|
|
|
value = B_CONTROL_OFF;
|
|
|
|
if (checked)
|
|
|
|
value = B_CONTROL_ON;
|
|
|
|
// TODO does this trigger an event?
|
|
|
|
c->checkbox->SetValue(value);
|
2015-11-19 07:47:53 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
uiCheckbox *uiNewCheckbox(const char *text)
|
|
|
|
{
|
|
|
|
uiCheckbox *c;
|
|
|
|
|
|
|
|
c = (uiCheckbox *) uiNewControl(uiCheckboxType());
|
|
|
|
|
2015-11-19 16:26:40 -06:00
|
|
|
c->checkbox = new BCheckBox(text, new BMessage(mCheckboxToggled));
|
|
|
|
|
|
|
|
uiCheckboxOnToggled(c, defaultOnToggled, NULL);
|
2015-11-19 07:47:53 -06:00
|
|
|
|
|
|
|
uiHaikuFinishNewControl(c, uiCheckbox);
|
|
|
|
|
|
|
|
return c;
|
|
|
|
}
|