More work.

This commit is contained in:
Pietro Gagliardi 2015-05-29 11:56:47 -04:00
parent 75caa33278
commit 9baad2ce88
4 changed files with 287 additions and 9 deletions

View File

@ -42,6 +42,11 @@ static void controlBaseSetParent(uiControl *c, uiControl *parent)
uiControlUpdateState(c);
}
static void controlBaseQueueResize(uiControl *c)
{
queueResize(c);
}
static int controlBaseContainerVisible(uiControl *c)
{
struct controlBase *cb = controlBase(c);
@ -121,6 +126,7 @@ void uiMakeControl(uiControl *c, uintmax_t type)
uiControl(c)->Destroy = controlBaseDestroy;
uiControl(c)->Parent = controlBaseParent;
uiControl(c)->SetParent = controlBaseSetParent;
uiControl(c)->QueueResize = controlBaseQueueResize;
uiControl(c)->ContainerVisible = controlBaseContainerVisible;
uiControl(c)->Show = controlBaseShow;
uiControl(c)->Hide = controlBaseHide;

218
redo/objimpl/ui.idl Normal file
View File

@ -0,0 +1,218 @@
// 6 april 2015
// This is not an IDL file for the conventional RPC or Microsoft IDLs.
// Instead, this is for a custom IDL of my own creation.
// You can find it at github.com/andlabs/pgidl
package ui {
raw "#include <stddef.h>";
raw "#include <stdint.h>";
raw "#ifndef _UI_EXTERN";
raw "#define _UI_EXTERN extern";
raw "#endif";
struct InitOptions {
field Size size_t;
};
func Init(options *InitOptions) *const char;
func Uninit(void);
func FreeInitError(err *const char);
func Main(void);
func Quit(void);
func OnShouldQuit(f *func(data *void) int, data *void);
func FreeText(text *char);
func RegisterType(name *const char, parent uintmax_t) uintmax_t;
func IsA(p *void, type uintmax_t, fail int) *void;
struct Typed {
field Type uintmax_t;
};
raw "#define uiTyped(this) ((uiTyped *) (this))";
raw "typedef struct uiSizingSys uiSizingSys;";
struct Sizing {
field XPadding intmax_t;
field YPadding intmax_t;
field Sys *uiSizingSys;
};
raw "typedef struct uiControlSysFuncParams uiControlSysFuncParams;";
raw "#define uiControlSysFuncNop 0";
interface Control {
field Internal *void; // for use by ui only
func Destroy(void);
func Handle(void) uintptr_t;
func Parent(void) *Control;
func SetParent(c *Control);
func PreferredSize(d *Sizing, width *intmax_t, height *intmax_t);
func Resize(x intmax_t, y intmax_t, width intmax_t, height intmax_t, d *Sizing);
func QueueResize(void);
func Sizing(void) *Sizing;
func ContainerVisible(void) int;
func Show(void);
func Hide(void);
func ContainerEnabled(void) int;
func Enable(void);
func Disable(void);
func UpdateState(void);
func SysFunc(p *uiControlSysFuncParams);
func StartZOrder(p *uiControlSysFuncParams) int;
func CommitDestroy(void);
func CommitSetParent(uiControl *);
func CommitShow(void);
func CommitHide(void);
func CommitEnable(void);
func CommitDisable(void);
func ContainerUpdateState(void);
};
func FreeSizing(d *Sizing);
func MakeContainer(c *Control);
interface Window from Control {
func Title(void) *char;
func SetTitle(title *const char);
func OnClosing(f *func(w *Window, data *void) int, data *void);
func SetChild(c *Control);
func Margined(void) int;
func SetMargined(margined int);
func ResizeChild(void);
};
func NewWindow(title *const char, width int, height int, hasMenubar int) *Window;
interface Button from Control {
func Text(void) *char;
func SetText(text *const char);
func OnClicked(f *func(b *Button, data *void), data *void);
};
func NewButton(text *const char) *Button;
interface Box from Control {
func Append(c *Control, stretchy int);
func Delete(index uintmax_t);
func Padded(void) int;
func SetPadded(padded int);
};
func NewHorizontalBox(void) *Box;
func NewVerticalBox(void) *Box;
interface Entry from Control {
func Text(void) *char;
func SetText(text *const char);
func OnChanged(f *func(e *Entry, data *void), data *void);
func ReadOnly(void) int;
func SetReadOnly(readonly int);
};
func NewEntry(void) *Entry;
interface Checkbox from Control {
func Text(void) *char;
func SetText(text *const char);
func OnToggled(f *func(c *Checkbox, data *void), data *void);
func Checked(void) int;
func SetChecked(checked int);
};
func NewCheckbox(text *const char) *Checkbox;
interface Label from Control {
func Text(void) *char;
func SetText(text *const char);
};
func NewLabel(text *const char) *Label;
interface Tab from Control {
func Append(name *const char, c *Control);
func InsertAt(name *const char, before uintmax_t, c *Control);
func Delete(index uintmax_t);
func NumPages(void) uintmax_t;
func Margined(page uintmax_t) int;
func SetMargined(page uintmax_t, margined int);
};
func NewTab(void) *Tab;
interface Group from Control {
// TODO text and settext
func SetChild(c *Control);
// TODO margined and setmargined
};
func NewGroup(text *const char) *Group;
// spinbox/slider rules:
// setting value outside of range will automatically clamp
// initial value is minimum
// TODO what happens if max > min? max == min?
interface Spinbox from Control {
func Value(void) intmax_t;
func SetValue(value intmax_t);
func OnChanged(f *func(s *Spinbox, data *void), data *void);
};
func NewSpinbox(min intmax_t, max intmax_t) *Spinbox;
interface ProgressBar from Control {
// TODO Value()
func SetValue(n int);
};
func NewProgressBar(void) *ProgressBar;
interface Slider from Control {
func Value(void) intmax_t;
func SetValue(value intmax_t);
func OnChanged(f *func(s *Slider, data *void), data *void);
};
func NewSlider(min intmax_t, max intmax_t) *Slider;
interface Separator from Control {
};
func NewHorizontalSeparator(void) *Separator;
interface Combobox from Control {
func Append(text *const char);
};
func NewCombobox(void) *Combobox;
func NewEditableCombobox(void) *Combobox;
interface RadioButtons from Control {
func Append(text *const char);
};
func NewRadioButtons(void) *RadioButtons;
interface DateTimePicker from Control {
};
func NewDateTimePicker(void) *DateTimePicker;
func NewDatePicker(void) *DateTimePicker;
func NewTimePicker(void) *DateTimePicker;
interface Menu {
func AppendItem(name *const char) *MenuItem;
func AppendCheckItem(name *const char) *MenuItem;
func AppendQuitItem(void) *MenuItem;
func AppendPreferencesItem(void) *MenuItem;
func AppendAboutItem(void) *MenuItem;
func AppendSeparator(void);
};
func NewMenu(name *const char) *Menu;
interface MenuItem {
func Enable(void);
func Disable(void);
func OnClicked(f *func(sender *MenuItem, window *Window, data *void), data *void);
func Checked(void) int;
func SetChecked(checked int);
};
func OpenFile(void) *char;
func SaveFile(void) *char;
func MsgBox(title *const char, description *const char);
func MsgBoxError(title *const char, description *const char);
};

34
redo/objimpl/uipriv.h Normal file
View File

@ -0,0 +1,34 @@
// 6 april 2015
#include <stdlib.h>
#define uthash_fatal(msg) complain("uthash failed: %s", (msg))
#define uthash_malloc(sz) uiAlloc((sz), "(uthash internal)")
#define uthash_free(ptr,sz) uiFree((ptr))
#include "uthash/uthash.h"
extern uiInitOptions options;
extern void *uiAlloc(size_t, const char *);
#define uiNew(T) ((T *) uiAlloc(sizeof (T), #T))
extern void *uiRealloc(void *, size_t, const char *);
extern void uiFree(void *);
extern void complain(const char *, ...);
extern void queueResize(uiControl *);
// ptrarray.c
struct ptrArray {
void **ptrs;
uintmax_t len;
uintmax_t cap;
};
struct ptrArray *newPtrArray(void);
void ptrArrayDestroy(struct ptrArray *);
void ptrArrayAppend(struct ptrArray *, void *);
void ptrArrayInsertAt(struct ptrArray *, uintmax_t, void *);
void ptrArrayDelete(struct ptrArray *, uintmax_t);
#define ptrArrayIndex(p, T, i) ((T) ((p)->ptrs[(i)]))
// shouldquit.c
int shouldQuit(void);

View File

@ -11,7 +11,7 @@ void uiWindowsUtilDestroy(HWND hwnd)
logLastError("error destroying window in uiWindowsUtilDestroyWindow()");
}
void uiWindowsSingleHWNDControlCommitDestroy(uiControl *c)
static void singleHWNDCommitDestroy(uiControl *c)
{
uiWindowsUtilDestroy(HWND(c));
}
@ -27,19 +27,39 @@ void uiWindowsUtilSetParent(HWND hwnd, uiControl *parent)
logLastError("error changing window parent in uiWindowsUtilSetParent()");
}
void uiWindowsSingleHWNDControlCommitSetParent(uiControl *c, uiControl *parent)
static void singleHWNDCommitSetParent(uiControl *c, uiControl *parent)
{
uiWindowsUtilSetParent(HWND(c), parent);
}
// TODO resizing
void uiWindowsUtilResize(HWND hwnd, intmax_t x, intmax_t y, intmax_t width, intmax_t height, uiSizing *d)
{
moveWindow(hwnd, x, y, width, height, d);
}
static void singleHWNDResize(HWND hwnd, intmax_t x, intmax_t y, intmax_t width, intmax_t height, uiSizing *d)
{
uiWindowsUtilResize(HWND(c), x, y, width, height, d);
}
// TODO queue resize
uiSizing *uiWindowsUtilSizing(HWND hwnd)
{
xxxxxTODOxxxxxx
}
static uiSizing *singleHWNDSizing(uiControl *c)
{
return uiWindowsUtilSizing(HWND(c));
}
void uiWIndowsUtilShow(HWND hwnd)
{
ShowWindow(hwnd, SW_SHOW);
}
void uiWindowsSingleHWNDControlCommitShow(uiControl *c)
static void singleHWNDCommitShow(uiControl *c)
{
uiWindowsUtilShow(HWND(c));
}
@ -49,7 +69,7 @@ void uiWindowsUtilHide(HWND hwnd)
ShowWindow(hwnd, SW_HIDE);
}
void uiWindowsSingleHWNDControlCommitHide(uiControl *c)
static void singleHWNDCommitHide(uiControl *c)
{
uiWindowsUtilHide(HWND(c));
}
@ -59,7 +79,7 @@ void uiWIndowsUtilEnable(HWND hwnd)
EnableWindow(hwnd, TRUE);
}
void uiWindowsSingleHWNDControlCommitEnable(uiControl *c)
static void singleHWNDCommitEnable(uiControl *c)
{
uiWindowsUtilEnable(HWND(c));
}
@ -69,7 +89,7 @@ void uiWindowsUtilDisable(HWND hwnd)
EnableWindow(hwnd, FALSE);
}
void uiWindowsSingleHWNDControlCommitDisable(uiControl *c)
static void singleHWNDCommitDisable(uiControl *c)
{
uiWindowsUtilDisable(HWND(c));
}
@ -91,7 +111,7 @@ void uiWindowsUtilSysFunc(HWND hwnd, uiControlSysFuncParams *p)
complain("unknown uiControlSysFunc() function %d in uiWindowsUtilSysFunc()", p->Func);
}
void uiWindowsSingleHWNDControlSysFunc(uiControl *c, uiControlSysFuncParams *p)
static void singleHWNDSysFunc(uiControl *c, uiControlSysFuncParams *p)
{
uiWindowsUtilSysFunc(HWND(c), p);
}
@ -107,7 +127,7 @@ void uiWindowsUtilStartZOrder(HWND hwnd, uiControlSysFuncParams *p)
p->InsertAfter = insertAfter;
}
void uiWindowsSingleHWNDControlStartZOrder(uiControl *c, uiControlSysFuncParams *p)
static void singleHWNDStartZOrder(uiControl *c, uiControlSysFuncParams *p)
{
uiWindowsUtilStartZOrder(HWND(c), p);
}