libui/haiku/button.cpp

70 lines
1.3 KiB
C++
Raw Normal View History

// 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;
};
uiHaikuDefineControl(
uiButton, // type name
uiButtonType, // type function
2015-11-19 16:11:35 -06:00
button // handle
)
2015-11-19 16:11:35 -06:00
#define mButtonClicked 0x4E754E75
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
}
char *uiButtonText(uiButton *b)
{
2015-11-19 16:11:35 -06:00
return uiHaikuStrdupText(b->button->Label());
}
void uiButtonSetText(uiButton *b, const char *text)
{
2015-11-19 16:11:35 -06:00
b->button->SetLabel(text);
}
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;
}
uiButton *uiNewButton(const char *text)
{
uiButton *b;
BMessage *msg;
b = (uiButton *) uiNewControl(uiButtonType());
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);
uiHaikuFinishNewControl(b, uiButton);
return b;
}