libui/redo/unix/radiobuttons.c

61 lines
1.6 KiB
C
Raw Normal View History

2015-06-11 18:07:06 -05:00
// 11 june 2015
#include "uipriv_unix.h"
// on GTK+ a uiRadioButtons is a GtkBox with each of the GtkRadioButtons as children
2015-06-11 18:07:06 -05:00
struct radiobuttons {
uiRadioButtons r;
GtkWidget *boxWidget;
2015-07-01 11:39:05 -05:00
GtkContainer *boxContainer;
GtkBox *box;
2015-07-01 11:39:05 -05:00
GPtrArray *buttons;
2015-06-11 18:07:06 -05:00
};
uiDefineControlType(uiRadioButtons, uiTypeRadioButtons, struct radiobuttons)
2015-07-01 11:39:05 -05:00
// TODO destroy
2015-06-29 19:41:41 -05:00
// TODO note that the handle of a uiRadioButtons is undefined (or at least highly platform-dependent and unreliable)
2015-06-11 18:07:06 -05:00
static uintptr_t radiobuttonsHandle(uiControl *c)
{
2015-06-29 19:37:55 -05:00
struct radiobuttons *r = (struct radiobuttons *) c;
return (uintptr_t) (r->boxWidget);
2015-06-11 18:07:06 -05:00
}
static void radiobuttonsAppend(uiRadioButtons *rr, const char *text)
{
struct radiobuttons *r = (struct radiobuttons *) rr;
2015-07-01 11:39:05 -05:00
GtkWidget *rb;
GtkRadioButton *previous;
previous = NULL;
if (r->buttons->len > 0)
previous = GTK_RADIO_BUTTON(g_ptr_array_index(r->buttons, 0));
rb = gtk_radio_button_new_with_label_from_widget(previous, text);
gtk_container_add(r->boxContainer, rb);
g_ptr_array_add(r->buttons, rb);
gtk_widget_show(rb);
2015-06-11 18:07:06 -05:00
uiControlQueueResize(uiControl(r));
}
uiRadioButtons *uiNewRadioButtons(void)
{
struct radiobuttons *r;
r = (struct radiobuttons *) uiNewControl(uiTypeRadioButtons());
2015-06-11 18:07:06 -05:00
r->boxWidget = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
2015-07-01 11:39:05 -05:00
r->boxContainer = GTK_CONTAINER(r->boxWidget);
r->box = GTK_BOX(r->boxWidget);
uiUnixMakeSingleWidgetControl(uiControl(r), r->boxWidget);
2015-06-11 18:07:06 -05:00
2015-07-01 11:39:05 -05:00
r->buttons = g_ptr_array_new();
2015-06-11 18:07:06 -05:00
uiControl(r)->Handle = radiobuttonsHandle;
uiRadioButtons(r)->Append = radiobuttonsAppend;
return uiRadioButtons(r);
}