2015-11-19 07:47:53 -06:00
|
|
|
// 18 november 2015
|
|
|
|
#include "uipriv_haiku.hpp"
|
|
|
|
|
|
|
|
struct uiButton {
|
|
|
|
uiHaikuControl c;
|
2015-11-19 16:11:35 -06:00
|
|
|
BButton *button;
|
|
|
|
void (*onClicked)(uiButton *, void *);
|
|
|
|
void *onClickedData;
|
2015-11-19 07:47:53 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
uiHaikuDefineControl(
|
|
|
|
uiButton, // type name
|
|
|
|
uiButtonType, // type function
|
2015-11-19 16:11:35 -06:00
|
|
|
button // handle
|
2015-11-19 07:47:53 -06:00
|
|
|
)
|
|
|
|
|
2015-11-19 16:11:35 -06:00
|
|
|
#define mButtonClicked 0x4E754E75
|
|
|
|
|
2015-11-20 10:45:04 -06:00
|
|
|
static void onClicked(BMessage *msg)
|
|
|
|
{
|
|
|
|
void *bb;
|
|
|
|
uiButton *b;
|
|
|
|
|
|
|
|
// TODO error check
|
|
|
|
msg->FindPointer(mControlField, &bb);
|
|
|
|
b = uiButton(bb);
|
|
|
|
(*(b->onClicked))(b, b->onClickedData);
|
|
|
|
}
|
|
|
|
|
2015-11-19 16:11:35 -06:00
|
|
|
static void defaultOnClicked(uiButton *b, void *data)
|
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
2015-11-19 07:47:53 -06:00
|
|
|
char *uiButtonText(uiButton *b)
|
|
|
|
{
|
2015-11-19 16:11:35 -06:00
|
|
|
return uiHaikuStrdupText(b->button->Label());
|
2015-11-19 07:47:53 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void uiButtonSetText(uiButton *b, const char *text)
|
|
|
|
{
|
2015-11-19 16:11:35 -06:00
|
|
|
b->button->SetLabel(text);
|
2015-11-19 07:47:53 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void uiButtonOnClicked(uiButton *b, void (*f)(uiButton *b, void *data), void *data)
|
|
|
|
{
|
2015-11-19 16:11:35 -06:00
|
|
|
b->onClicked = f;
|
|
|
|
b->onClickedData = data;
|
2015-11-19 07:47:53 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
uiButton *uiNewButton(const char *text)
|
|
|
|
{
|
|
|
|
uiButton *b;
|
2015-11-20 10:45:04 -06:00
|
|
|
BMessage *msg;
|
2015-11-19 07:47:53 -06:00
|
|
|
|
|
|
|
b = (uiButton *) uiNewControl(uiButtonType());
|
|
|
|
|
2015-11-20 10:45:04 -06:00
|
|
|
uiHaikuRegisterEventHandler(mButtonClicked, onClicked);
|
|
|
|
msg = new BMessage(mButtonClicked);
|
|
|
|
msg->AddPointer(mControlField, b);
|
|
|
|
|
|
|
|
b->button = new BButton(text, msg);
|
2015-11-19 16:11:35 -06:00
|
|
|
|
|
|
|
uiButtonOnClicked(b, defaultOnClicked, NULL);
|
2015-11-19 07:47:53 -06:00
|
|
|
|
|
|
|
uiHaikuFinishNewControl(b, uiButton);
|
|
|
|
|
|
|
|
return b;
|
|
|
|
}
|