Started work on the GTK+ controls.

This commit is contained in:
Pietro Gagliardi 2015-06-11 19:07:06 -04:00
parent 930c4e6883
commit 49aca6141e
14 changed files with 884 additions and 0 deletions

66
redo/unix/button.c Normal file
View File

@ -0,0 +1,66 @@
// 10 june 2015
#include "uipriv_unix.h"
struct button {
uiButton b;
GtkWidget *widget;
void (*onClicked)(uiButton *, void *);
void *onClickedData;
};
uiDefineControlType(uiButton, uiTypeButton, struct button)
static uintptr_t buttonHandle(uiControl *c)
{
struct button *b = (struct button *) c;
return (uintptr_t) (b->widget);
}
static void defaultOnClicked(uiButton *b, void *data)
{
// do nothing
}
static char *buttonText(uiButton *bb)
{
struct button *b = (struct button *) bb;
return PUT_CODE_HERE;
}
static void buttonSetText(uiButton *bb, const char *text)
{
struct button *b = (struct button *) bb;
PUT_CODE_HERE;
// changing the text might necessitate a change in the button's size
uiControlQueueResize(uiControl(b));
}
static void buttonOnClicked(uiButton *bb, void (*f)(uiButton *, void *), void *data)
{
struct button *b = (struct button *) bb;
b->onClicked = f;
b->onClickedData = data;
}
uiButton *uiNewButton(const char *text)
{
struct button *b;
b = (struct button *) MAKE_CONTROL_INSTANCE(uiTypeButton());
PUT_CODE_HERE;
b->onClicked = defaultOnClicked;
uiControl(b)->Handle = buttonHandle;
uiButton(b)->Text = buttonText;
uiButton(b)->SetText = buttonSetText;
uiButton(b)->OnClicked = buttonOnClicked;
return uiButton(b);
}

83
redo/unix/checkbox.c Normal file
View File

@ -0,0 +1,83 @@
// 10 june 2015
#include "uipriv_unix.h"
struct checkbox {
uiCheckbox c;
GtkWidget *widget;
void (*onToggled)(uiCheckbox *, void *);
void *onToggledData;
};
uiDefineControlType(uiCheckbox, uiTypeCheckbox, struct checkbox)
static uintptr_t checkboxHandle(uiControl *cc)
{
struct checkbox *c = (struct checkbox *) cc;
return (uintptr_t) (c->widget);
}
static void defaultOnToggled(uiCheckbox *c, void *data)
{
// do nothing
}
static char *checkboxText(uiCheckbox *cc)
{
struct checkbox *c = (struct checkbox *) cc;
return PUT_CODE_HERE;
}
static void checkboxSetText(uiCheckbox *cc, const char *text)
{
struct checkbox *c = (struct checkbox *) cc;
PUT_CODE_HERE;
// changing the text might necessitate a change in the checkbox's size
uiControlQueueResize(uiControl(c));
}
static void checkboxOnToggled(uiCheckbox *cc, void (*f)(uiCheckbox *, void *), void *data)
{
struct checkbox *c = (struct checkbox *) cc;
c->onToggled = f;
c->onToggledData = data;
}
static int checkboxChecked(uiCheckbox *cc)
{
struct checkbox *c = (struct checkbox *) cc;
return PUT_CODE_HERE;
}
static void checkboxSetChecked(uiCheckbox *cc, int checked)
{
struct checkbox *c = (struct checkbox *) cc;
PUT_CODE_HERE;
}
uiCheckbox *uiNewCheckbox(const char *text)
{
struct checkbox *c;
WCHAR *wtext;
c = (struct checkbox *) MAKE_CONTROL_INSTANCE(uiTypeCheckbox());
PUT_CODE_HERE;
c->onToggled = defaultOnToggled;
uiControl(c)->Handle = checkboxHandle;
uiCheckbox(c)->Text = checkboxText;
uiCheckbox(c)->SetText = checkboxSetText;
uiCheckbox(c)->OnToggled = checkboxOnToggled;
uiCheckbox(c)->Checked = checkboxChecked;
uiCheckbox(c)->SetChecked = checkboxSetChecked;
return uiCheckbox(c);
}

48
redo/unix/combobox.c Normal file
View File

@ -0,0 +1,48 @@
// 11 june 2015
#include "uipriv_unix.h"
struct combobox {
uiCombobox c;
GtkWidget *widget;
};
uiDefineControlType(uiCombobox, uiTypeCombobox, struct combobox)
static uintptr_t comboboxHandle(uiControl *cc)
{
struct combobox *c = (struct combobox *) cc;
return (uintptr_t) (c->widget);
}
static void comboboxAppend(uiCombobox *cc, const char *text)
{
struct combobox *c = (struct combobox *) cc;
PUT_CODE_HERE;
}
static uiCombobox *finishNewCombobox(OSTHING OSARG)
{
struct combobox *c;
c = (struct combobox *) MAKE_CONTROL_INSTANCE(uiTypeCombobox());
PUT_CODE_HERE;
uiControl(c)->Handle = comboboxHandle;
uiCombobox(c)->Append = comboboxAppend;
return uiCombobox(c);
}
uiCombobox *uiNewCombobox(void)
{
return finishNewCombobox(OSARGNONEDITABLE);
}
uiCombobox *uiNewEditableCombobox(void)
{
return finishNewCombobox(OSARGEDITABLE);
}

View File

@ -0,0 +1,44 @@
// 11 june 2015
#include "uipriv_unix.h"
struct datetimepicker {
uiDateTimePicker d;
GtkWidget *widget;
};
uiDefineControlType(uiDateTimePicker, uiTypeDateTimePicker, struct datetimepicker)
static uintptr_t datetimepickerHandle(uiControl *c)
{
struct datetimepicker *d = (struct datetimepicker *) c;
return (uintptr_t) (d->widget);
}
uiDateTimePicker *finishNewDateTimePicker(OSTHING OSARG)
{
struct datetimepicker *d;
d = (struct datetimepicker *) MAKE_CONTROL_INSTANCE(uiTypeDateTimePicker());
PUT_CODE_HERE;
uiControl(d)->Handle = datetimepickerHandle;
return uiDateTimePicker(d);
}
uiDateTimePicker *uiNewDateTimePicker(void)
{
return finishNewDateTimePicker(OSARGDATETIME);
}
uiDateTimePicker *uiNewDatePicker(void)
{
return finishNewDateTimePicker(OSARGDATEONLY);
}
uiDateTimePicker *uiNewTimePicker(void)
{
return finishNewDateTimePicker(OSARGTIMEONLY);
}

82
redo/unix/entry.c Normal file
View File

@ -0,0 +1,82 @@
// 11 june 2015
#include "uipriv_unix.h"
struct entry {
uiEntry e;
GtkWidget *widget;
void (*onChanged)(uiEntry *, void *);
void *onChangedData;
};
uiDefineControlType(uiEntry, uiTypeEntry, struct entry)
static uintptr_t entryHandle(uiControl *c)
{
struct entry *e = (struct entry *) c;
return (uintptr_t) (e->widget);
}
static void defaultOnChanged(uiEntry *e, void *data)
{
// do nothing
}
static char *entryText(uiEntry *ee)
{
struct entry *e = (struct entry *) ee;
return PUT_CODE_HERE;
}
static void entrySetText(uiEntry *ee, const char *text)
{
struct entry *e = (struct entry *) ee;
PUT_CODE_HERE;
// don't queue the control for resize; entry sizes are independent of their contents
}
static void entryOnChanged(uiEntry *ee, void (*f)(uiEntry *, void *), void *data)
{
struct entry *e = (struct entry *) ee;
e->onChanged = f;
e->onChangedData = data;
}
static int entryReadOnly(uiEntry *ee)
{
struct entry *e = (struct entry *) ee;
return PUT_CODE_HERE;
}
static void entrySetReadOnly(uiEntry *ee, int readonly)
{
struct entry *e = (struct entry *) ee;
WPARAM ro;
PUT_CODE_HERE;
}
uiEntry *uiNewEntry(void)
{
struct entry *e;
e = (struct entry *) MAKE_CONTROL_INSTANCE(uiTypeEntry());
PUT_CODE_HERE;
e->onChanged = defaultOnChanged;
uiControl(e)->Handle = entryHandle;
uiEntry(e)->Text = entryText;
uiEntry(e)->SetText = entrySetText;
uiEntry(e)->OnChanged = entryOnChanged;
uiEntry(e)->ReadOnly = entryReadOnly;
uiEntry(e)->SetReadOnly = entrySetReadOnly;
return uiEntry(e);
}

90
redo/unix/group.c Normal file
View File

@ -0,0 +1,90 @@
// 11 june 2015
#include "uipriv_unix.h"
struct group {
uiGroup g;
GtkWidget *widget;
uiControl *child;
int margined;
};
uiDefineControlType(uiGroup, uiTypeGroup, struct group)
static uintptr_t groupHandle(uiControl *c)
{
struct group *g = (struct group *) c;
return (uintptr_t) (g->widget);
}
static void groupContainerUpdateState(uiControl *c)
{
struct group *g = (struct group *) c;
if (g->child != NULL)
uiControlUpdateState(g->child);
}
static char *groupTitle(uiGroup *gg)
{
struct group *g = (struct group *) gg;
return PUT_CODE_HERE;
}
static void groupSetTitle(uiGroup *gg, const char *text)
{
struct group *g = (struct group *) gg;
PUT_CODE_HERE;
// changing the text might necessitate a change in the groupbox's size
uiControlQueueResize(uiControl(g));
}
static void groupSetChild(uiGroup *gg, uiControl *child)
{
struct group *g = (struct group *) gg;
if (g->child != NULL)
uiControlSetParent(g->child, NULL);
g->child = child;
if (g->child != NULL) {
uiControlSetParent(g->child, uiControl(g));
uiControlQueueResize(g->child);
}
}
static int groupMargined(uiGroup *gg)
{
struct group *g = (struct group *) gg;
return g->margined;
}
static void groupSetMargined(uiGroup *gg, int margined)
{
struct group *g = (struct group *) gg;
g->margined = margined;
uiControlQueueResize(uiControl(g));
}
uiGroup *uiNewGroup(const char *text)
{
struct group *g;
g = (struct group *) MAKE_CONTROL_INSTANCE(uiTypeGroup());
PUT_CODE_HERE;
uiControl(g)->Handle = groupHandle;
uiControl(g)->ContainerUpdateState = groupContainerUpdateState;
uiGroup(g)->Title = groupTitle;
uiGroup(g)->SetTitle = groupSetTitle;
uiGroup(g)->SetChild = groupSetChild;
uiGroup(g)->Margined = groupMargined;
uiGroup(g)->SetMargined = groupSetMargined;
return uiGroup(g);
}

48
redo/unix/label.c Normal file
View File

@ -0,0 +1,48 @@
// 11 june 2015
#include "uipriv_unix.h"
struct label {
uiLabel l;
GtkWidget *widget;
};
uiDefineControlType(uiLabel, uiTypeLabel, struct label)
static uintptr_t labelHandle(uiControl *c)
{
struct label *l = (struct label *) c;
return (uintptr_t) (l->widget);
}
static char *labelText(uiLabel *ll)
{
struct label *l = (struct label *) ll;
return PUT_CODE_HERE;
}
static void labelSetText(uiLabel *ll, const char *text)
{
struct label *l = (struct label *) ll;
PUT_CODE_HERE;
// changing the text might necessitate a change in the label's size
uiControlQueueResize(uiControl(l));
}
uiLabel *uiNewLabel(const char *text)
{
struct label *l;
l = (struct label *) MAKE_CONTROL_INSTANCE(uiTypeLabel());
PUT_CODE_HERE;
uiControl(l)->Handle = labelHandle;
uiLabel(l)->Text = labelText;
uiLabel(l)->SetText = labelSetText;
return uiLabel(l);
}

40
redo/unix/progressbar.c Normal file
View File

@ -0,0 +1,40 @@
// 11 june 2015
#include "uipriv_unix.h"
struct progressbar {
uiProgressBar p;
GtkWidget *widget;
};
uiDefineControlType(uiProgressBar, uiTypeProgressBar, struct progressbar)
static uintptr_t progressbarHandle(uiControl *c)
{
struct progressbar *p = (struct progressbar *) c;
return (uintptr_t) (p->widget);
}
static void progressbarSetValue(uiProgressBar *pp, int value)
{
struct progressbar *p = (struct progressbar *) pp;
if (value < 0 || value > 100)
complain("value %d out of range in progressbarSetValue()", value);
PUT_CODE_HERE;
}
uiProgressBar *uiNewProgressBar(void)
{
struct progressbar *p;
p = (struct progressbar *) MAKE_CONTROL_INSTANCE(uiTypeProgressBar());
PUT_CODE_HERE;
uiControl(p)->Handle = progressbarHandle;
uiProgressBar(p)->SetValue = progressbarSetValue;
return uiProgressBar(p);
}

36
redo/unix/radiobuttons.c Normal file
View File

@ -0,0 +1,36 @@
// 11 june 2015
#include "uipriv_unix.h"
struct radiobuttons {
uiRadioButtons r;
};
uiDefineControlType(uiRadioButtons, uiTypeRadioButtons, struct radiobuttons)
static uintptr_t radiobuttonsHandle(uiControl *c)
{
return 0;
}
static void radiobuttonsAppend(uiRadioButtons *rr, const char *text)
{
struct radiobuttons *r = (struct radiobuttons *) rr;
PUT_CODE_HERE;
uiControlQueueResize(uiControl(r));
}
uiRadioButtons *uiNewRadioButtons(void)
{
struct radiobuttons *r;
r = (struct radiobuttons *) MAKE_CONTROL_INSTANCE(uiTypeRadioButtons());
PUT_CODE_HERE;
uiControl(r)->Handle = radiobuttonsHandle;
uiRadioButtons(r)->Append = radiobuttonsAppend;
return uiRadioButtons(r);
}

29
redo/unix/separator.c Normal file
View File

@ -0,0 +1,29 @@
// 11 june 2015
#include "uipriv_unix.h"
struct separator {
uiSeparator s;
GtkWidget *widget;
};
uiDefineControlType(uiSeparator, uiTypeSeparator, struct separator)
static uintptr_t separatorHandle(uiControl *c)
{
struct separator *s = (struct separator *) c;
return (uintptr_t) (s->widget);
}
uiSeparator *uiNewHorizontalSeparator(void)
{
struct separator *s;
s = (struct separator *) MAKE_CONTROL_INSTANCE(uiTypeSeparator());
PUT_CODE_HERE;
uiControl(s)->Handle = separatorHandle;
return uiSeparator(s);
}

64
redo/unix/slider.c Normal file
View File

@ -0,0 +1,64 @@
// 11 june 2015
#include "uipriv_unix.h"
struct slider {
uiSlider s;
GtkWidget *widget;
void (*onChanged)(uiSlider *, void *);
void *onChangedData;
};
uiDefineControlType(uiSlider, uiTypeSlider, struct slider)
static uintptr_t sliderHandle(uiControl *c)
{
struct slider *s = (struct slider *) c;
return (uintptr_t) (s->widget);
}
static void defaultOnChanged(uiSlider *s, void *data)
{
// do nothing
}
static intmax_t sliderValue(uiSlider *ss)
{
struct slider *s = (struct slider *) ss;
return PUT_CODE_HERE;
}
static void sliderSetValue(uiSlider *ss, intmax_t value)
{
struct slider *s = (struct slider *) ss;
PUT_CODE_HERE;
}
static void sliderOnChanged(uiSlider *ss, void (*f)(uiSlider *, void *), void *data)
{
struct slider *s = (struct slider *) ss;
s->onChanged = f;
s->onChangedData = data;
}
uiSlider *uiNewSlider(intmax_t min, intmax_t max)
{
struct slider *s;
s = (struct slider *) MAKE_CONTROL_INSTANCE(uiTypeSlider());
PUT_CODE_HERE;
s->onChanged = defaultOnChanged;
uiControl(s)->Handle = sliderHandle;
uiSlider(s)->Value = sliderValue;
uiSlider(s)->SetValue = sliderSetValue;
uiSlider(s)->OnChanged = sliderOnChanged;
return uiSlider(s);
}

64
redo/unix/spinbox.c Normal file
View File

@ -0,0 +1,64 @@
// 11 june 2015
#include "uipriv_unix.h"
struct spinbox {
uiSpinbox s;
};
uiDefineControlType(uiSpinbox, uiTypeSpinbox, struct spinbox)
static uintptr_t spinboxHandle(uiControl *c)
{
struct spinbox *s = (struct spinbox *) c;
return PUT_CODE_HERE;
}
static void defaultOnChanged(uiSpinbox *s, void *data)
{
// do nothing
}
static intmax_t spinboxValue(uiSpinbox *ss)
{
struct spinbox *s = (struct spinbox *) ss;
return PUT_CODE_HERE;
}
static void spinboxSetValue(uiSpinbox *ss, intmax_t value)
{
struct spinbox *s = (struct spinbox *) ss;
PUT_CODE_HERE;
}
static void spinboxOnChanged(uiSpinbox *ss, void (*f)(uiSpinbox *, void *), void *data)
{
struct spinbox *s = (struct spinbox *) ss;
s->onChanged = f;
s->onChangedData = data;
}
uiSpinbox *uiNewSpinbox(intmax_t min, intmax_t max)
{
struct spinbox *s;
if (min >= max)
complain("error: min >= max in uiNewSpinbox()");
s = (struct spinbox *) MAKE_CONTROL_INSTANCE(uiTypeSpinbox());
PUT_CODE_HERE;
s->onChanged = defaultOnChanged;
uiControl(s)->Handle = spinboxHandle;
uiSpinbox(s)->Value = spinboxValue;
uiSpinbox(s)->SetValue = spinboxSetValue;
uiSpinbox(s)->OnChanged = spinboxOnChanged;
return uiSpinbox(s);
}

78
redo/unix/tab.c Normal file
View File

@ -0,0 +1,78 @@
// 11 june 2015
#include "uipriv_unix.h"
struct tab {
uiTab t;
GtkWidget *widget;
};
uiDefineControlType(uiTab, uiTypeTab, struct tab)
static uintptr_t tabHandle(uiControl *c)
{
struct tab *t = (struct tab *) c;
return (uintptr_t) (t->widget);
}
static void tabAppend(uiTab *tt, const char *name, uiControl *child)
{
struct tab *t = (struct tab *) tt;
uiTabInsertAt(tt, name, PUT_CODE_HERE, child);
}
static void tabInsertAt(uiTab *tt, const char *name, uintmax_t n, uiControl *child)
{
struct tab *t = (struct tab *) tt;
PUT_CODE_HERE;
}
static void tabDelete(uiTab *tt, uintmax_t n)
{
struct tab *t = (struct tab *) tt;
PUT_CODE_HERE;
}
static uintmax_t tabNumPages(uiTab *tt)
{
struct tab *t = (struct tab *) tt;
return PUT_CODE_HERE;
}
static int tabMargined(uiTab *tt, uintmax_t n)
{
struct tab *t = (struct tab *) tt;
return PUT_CODE_HERE;
}
static void tabSetMargined(uiTab *tt, uintmax_t n, int margined)
{
struct tab *t = (struct tab *) tt;
PUT_CODE_HERE;
}
uiTab *uiNewTab(void)
{
struct tab *t;
t = (struct tab *) MAKE_CONTROL_INSTANCE(uiTypeTab());
PUT_CODE_HERE;
uiControl(t)->Handle = tabHandle;
uiTab(t)->Append = tabAppend;
uiTab(t)->InsertAt = tabInsertAt;
uiTab(t)->Delete = tabDelete;
uiTab(t)->NumPages = tabNumPages;
uiTab(t)->Margined = tabMargined;
uiTab(t)->SetMargined = tabSetMargined;
return uiTab(t);
}

112
redo/unix/window.c Normal file
View File

@ -0,0 +1,112 @@
// 11 june 2015
#include "uipriv_unix.h"
struct window {
uiWindow w;
GtkWidget *widget;
uiControl *child;
int (*onClosing)(uiWindow *, void *);
void *onClosingData;
int margined;
};
uiDefineControlType(uiWindow, uiTypeWindow, struct window)
static uintptr_t windowHandle(uiControl *c)
{
struct window *w = (struct window *) c;
return (uintptr_t) (w->widget);
}
static void windowContainerUpdateState(uiControl *c)
{
struct window *w = (struct window *) c;
if (w->child != NULL)
uiControlUpdateState(w->child);
}
static char *windowTitle(uiWindow *ww)
{
struct window *w = (struct window *) ww;
return PUT_CODE_HERE;
}
static void windowSetTitle(uiWindow *ww, const char *title)
{
struct window *w = (struct window *) ww;
PUT_CODE_HERE;
// don't queue resize; the caption isn't part of what affects layout and sizing of the client area (it'll be ellipsized if too long)
}
static void windowOnClosing(uiWindow *ww, int (*f)(uiWindow *, void *), void *data)
{
struct window *w = (struct window *) ww;
w->onClosing = f;
w->onClosingData = data;
}
static void windowSetChild(uiWindow *ww, uiControl *child)
{
struct window *w = (struct window *) ww;
if (w->child != NULL)
uiControlSetParent(w->child, NULL);
w->child = child;
if (w->child != NULL) {
uiControlSetParent(w->child, uiControl(w));
uiControlQueueResize(w->child);
}
}
static int windowMargined(uiWindow *ww)
{
struct window *w = (struct window *) ww;
return w->margined;
}
static void windowSetMargined(uiWindow *ww, int margined)
{
struct window *w = (struct window *) ww;
w->margined = margined;
uiControlQueueResize(uiControl(w));
}
static void windowResizeChild(uiWindow *ww)
{
struct window *w = (struct window *) ww;
if (w->child == NULL)
return;
PUT_CODE_HERE;
}
uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar)
{
struct window *w;
w = (struct window *) MAKE_CONTROL_INSTANCE(uiTypeWindow());
PUT_CODE_HERE;
w->onClosing = defaultOnClosing;
uiControl(w)->Handle = windowHandle;
uiControl(w)->ContainerUpdateState = windowContainerUpdateState;
uiWindow(w)->Title = windowTitle;
uiWindow(w)->SetTitle = windowSetTitle;
uiWindow(w)->OnClosing = windowOnClosing;
uiWindow(w)->SetChild = windowSetChild;
uiWindow(w)->Margined = windowMargined;
uiWindow(w)->SetMargined = windowSetMargined;
uiWindow(w)->ResizeChild = windowResizeChild;
return uiWindow(w);
}