Started merging back the uiControl base code.
This commit is contained in:
parent
2cd336903d
commit
705f81d7e4
|
@ -0,0 +1,121 @@
|
||||||
|
// 26 may 2015
|
||||||
|
#include "ui.h"
|
||||||
|
#include "uipriv.h"
|
||||||
|
|
||||||
|
struct controlBase {
|
||||||
|
uiControl *parent;
|
||||||
|
int hidden;
|
||||||
|
int disabled;
|
||||||
|
};
|
||||||
|
|
||||||
|
static uintmax_t type_uiControl = 0;
|
||||||
|
|
||||||
|
uintmax_t uiTypeControl(void)
|
||||||
|
{
|
||||||
|
if (type_uiControl == 0)
|
||||||
|
type_uiControl = uiRegisterType("uiControl", 0, sizeof (uiControl));
|
||||||
|
return type_uiControl;
|
||||||
|
}
|
||||||
|
|
||||||
|
#define controlBase(c) ((struct controlBase *) (c->Internal))
|
||||||
|
|
||||||
|
void uiControlDestroy(uiControl *c)
|
||||||
|
{
|
||||||
|
struct controlBase *cb = controlBase(c);
|
||||||
|
|
||||||
|
if (cb->parent != NULL)
|
||||||
|
complain("attempt to destroy uiControl %p while it has a parent", c);
|
||||||
|
(*(c->CommitDestroy))(c);
|
||||||
|
uiFree(cb);
|
||||||
|
uiFree(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void controlUpdateState(uiControl *);
|
||||||
|
|
||||||
|
void uiControlSetParent(uiControl *c, uiControl *parent)
|
||||||
|
{
|
||||||
|
struct controlBase *cb = controlBase(c);
|
||||||
|
|
||||||
|
if (parent != NULL && cb->parent != NULL)
|
||||||
|
complain("attempt to reparent uiControl %p (has parent %p, attempt to give parent %p)", c, cb->parent, parent);
|
||||||
|
if (parent == NULL && cb->parent == NULL)
|
||||||
|
complain("attempt to double unparent uiControl %p", c);
|
||||||
|
cb->parent = parent;
|
||||||
|
// for situations such as where the old parent was disabled but the new one is not, etc.
|
||||||
|
controlUpdateState(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int controlContainerVisible(uiControl *c)
|
||||||
|
{
|
||||||
|
struct controlBase *cb = controlBase(c);
|
||||||
|
|
||||||
|
if (cb->hidden)
|
||||||
|
return 0;
|
||||||
|
if (cb->parent == NULL)
|
||||||
|
return 1;
|
||||||
|
return controlContainerVisible(cb->parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
void uiControlShow(uiControl *c)
|
||||||
|
{
|
||||||
|
struct controlBase *cb = controlBase(c);
|
||||||
|
|
||||||
|
cb->hidden = 0;
|
||||||
|
controlUpdateState(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
void uiControlHide(uiControl *c)
|
||||||
|
{
|
||||||
|
struct controlBase *cb = controlBase(c);
|
||||||
|
|
||||||
|
cb->hidden = 1;
|
||||||
|
controlUpdateState(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int controlContainerEnabled(uiControl *c)
|
||||||
|
{
|
||||||
|
struct controlBase *cb = controlBase(c);
|
||||||
|
|
||||||
|
if (cb->disabled)
|
||||||
|
return 0;
|
||||||
|
if (cb->parent == NULL)
|
||||||
|
return 1;
|
||||||
|
return controlContainerEnabled(cb->parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
void uiControlEnable(uiControl *c)
|
||||||
|
{
|
||||||
|
struct controlBase *cb = controlBase(c);
|
||||||
|
|
||||||
|
cb->disabled = 0;
|
||||||
|
controlUpdateState(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
void uiControlDisable(uiControl *c)
|
||||||
|
{
|
||||||
|
struct controlBase *cb = controlBase(c);
|
||||||
|
|
||||||
|
cb->disabled = 1;
|
||||||
|
controlUpdateState(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void controlUpdateState(uiControl *c)
|
||||||
|
{
|
||||||
|
if (uiControlContainerVisible(c))
|
||||||
|
osCommitShow(c);
|
||||||
|
else
|
||||||
|
osCommitHide(c);
|
||||||
|
if (uiControlContainerEnabled(c))
|
||||||
|
osCommitEnable(c);
|
||||||
|
else
|
||||||
|
osCommitDisable(c);
|
||||||
|
(*(c->ContainerUpdateState))(c);
|
||||||
|
// and queue a resize, just in case we showed/hid something
|
||||||
|
//TODO uiControlQueueResize(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO should this be public?
|
||||||
|
uiControl *uiNewControl(uintmax_t type)
|
||||||
|
{
|
||||||
|
return uiControl(newTyped(type));
|
||||||
|
}
|
|
@ -79,7 +79,7 @@ void uiButtonSetText(uiButton *b, const char *text)
|
||||||
{
|
{
|
||||||
[b->button setTitle:toNSString(text)];
|
[b->button setTitle:toNSString(text)];
|
||||||
// this may result in the size of the button changing
|
// this may result in the size of the button changing
|
||||||
uiControlQueueResize(uiControl(b));
|
//TODO uiControlQueueResize(uiControl(b));
|
||||||
}
|
}
|
||||||
|
|
||||||
void uiButtonOnClicked(uiButton *b, void (*f)(uiButton *, void *), void *data)
|
void uiButtonOnClicked(uiButton *b, void (*f)(uiButton *, void *), void *data)
|
||||||
|
|
|
@ -79,7 +79,7 @@ void uiCheckboxSetText(uiCheckbox *c, const char *text)
|
||||||
{
|
{
|
||||||
[c->button setTitle:toNSString(text)];
|
[c->button setTitle:toNSString(text)];
|
||||||
// this may result in the size of the checkbox changing
|
// this may result in the size of the checkbox changing
|
||||||
uiControlQueueResize(uiControl(c));
|
//TODO uiControlQueueResize(uiControl(c));
|
||||||
}
|
}
|
||||||
|
|
||||||
void uiCheckboxOnToggled(uiCheckbox *c, void (*f)(uiCheckbox *, void *), void *data)
|
void uiCheckboxOnToggled(uiCheckbox *c, void (*f)(uiCheckbox *, void *), void *data)
|
||||||
|
|
|
@ -26,7 +26,7 @@ void uiGroupSetTitle(uiGroup *g, const char *text)
|
||||||
{
|
{
|
||||||
// TODO
|
// TODO
|
||||||
// changing the text might necessitate a change in the groupbox's size
|
// changing the text might necessitate a change in the groupbox's size
|
||||||
uiControlQueueResize(uiControl(g));
|
//TODO uiControlQueueResize(uiControl(g));
|
||||||
}
|
}
|
||||||
|
|
||||||
void uiGroupSetChild(uiGroup *g, uiControl *child)
|
void uiGroupSetChild(uiGroup *g, uiControl *child)
|
||||||
|
@ -37,7 +37,7 @@ void uiGroupSetChild(uiGroup *g, uiControl *child)
|
||||||
g->child = child;
|
g->child = child;
|
||||||
if (g->child != NULL) {
|
if (g->child != NULL) {
|
||||||
uiControlSetParent(g->child, uiControl(g));
|
uiControlSetParent(g->child, uiControl(g));
|
||||||
uiControlQueueResize(g->child);
|
//TODO uiControlQueueResize(g->child);
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ void uiGroupSetMargined(uiGroup *g, int margined)
|
||||||
{
|
{
|
||||||
g->margined = margined;
|
g->margined = margined;
|
||||||
// TODO
|
// TODO
|
||||||
uiControlQueueResize(uiControl(g));
|
//TODO uiControlQueueResize(uiControl(g));
|
||||||
}
|
}
|
||||||
|
|
||||||
uiGroup *uiNewGroup(const char *title)
|
uiGroup *uiNewGroup(const char *title)
|
||||||
|
|
|
@ -21,7 +21,7 @@ void uiLabelSetText(uiLabel *l, const char *text)
|
||||||
{
|
{
|
||||||
[l->textfield setStringValue:toNSString(text)];
|
[l->textfield setStringValue:toNSString(text)];
|
||||||
// changing the text might necessitate a change in the label's size
|
// changing the text might necessitate a change in the label's size
|
||||||
uiControlQueueResize(uiControl(l));
|
//TODO uiControlQueueResize(uiControl(l));
|
||||||
}
|
}
|
||||||
|
|
||||||
uiLabel *uiNewLabel(const char *text)
|
uiLabel *uiNewLabel(const char *text)
|
||||||
|
|
|
@ -15,7 +15,7 @@ uiDarwinDefineControl(
|
||||||
void uiRadioButtonsAppend(uiRadioButtons *r, const char *text)
|
void uiRadioButtonsAppend(uiRadioButtons *r, const char *text)
|
||||||
{
|
{
|
||||||
// TODO
|
// TODO
|
||||||
uiControlQueueResize(uiControl(r));
|
//TODO uiControlQueueResize(uiControl(r));
|
||||||
}
|
}
|
||||||
|
|
||||||
uiRadioButtons *uiNewRadioButtons(void)
|
uiRadioButtons *uiNewRadioButtons(void)
|
||||||
|
|
|
@ -53,14 +53,16 @@ struct uiControl {
|
||||||
void *Internal; // for use by libui only
|
void *Internal; // for use by libui only
|
||||||
void (*CommitDestroy)(uiControl *);
|
void (*CommitDestroy)(uiControl *);
|
||||||
uintptr_t (*Handle)(uiControl *);
|
uintptr_t (*Handle)(uiControl *);
|
||||||
void (*CommitShow)(uiControl *); // TODO are all of these still needed?
|
void (*ContainerUpdateState)(uiControl *);
|
||||||
void (*CommitHide)(uiControl *);
|
|
||||||
void (*CommitEnable)(uiControl *);
|
|
||||||
void (*CommitDisable)(uiControl *);
|
|
||||||
void (*ContainerUpdateState)(uiControl *); // TODO still needed?
|
|
||||||
};
|
};
|
||||||
_UI_EXTERN uintmax_t uiControlType(void);
|
_UI_EXTERN uintmax_t uiControlType(void);
|
||||||
#define uiControl(this) ((uiControl *) uiIsA((this), uiControlType(), 1))
|
#define uiControl(this) ((uiControl *) uiIsA((this), uiControlType(), 1))
|
||||||
|
_UI_EXTERN void uiControlDestroy(uiControl *);
|
||||||
|
_UI_EXTERN void uiControlSetParent(uiControl *, uiControl *);
|
||||||
|
_UI_EXTERN void uiControlShow(uiControl *);
|
||||||
|
_UI_EXTERN void uiControlHide(uiControl *);
|
||||||
|
_UI_EXTERN void uiControlEnable(uiControl *);
|
||||||
|
_UI_EXTERN void uiControlDisable(uiControl *);
|
||||||
|
|
||||||
/* TODO
|
/* TODO
|
||||||
func NewControl(type uintmax_t) *Control;
|
func NewControl(type uintmax_t) *Control;
|
||||||
|
|
|
@ -25,6 +25,10 @@ This file assumes that you have imported <Cocoa/Cocoa.h> and "ui.h" beforehand.
|
||||||
static uintptr_t _ ## type ## Handle(uiControl *c) \
|
static uintptr_t _ ## type ## Handle(uiControl *c) \
|
||||||
{ \
|
{ \
|
||||||
return type(c)->handlefield; \
|
return type(c)->handlefield; \
|
||||||
|
} \
|
||||||
|
static void _ ## type ## ContainerUpdateState(uiControl *c) \
|
||||||
|
{ \
|
||||||
|
/* do nothing */ \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define uiDarwinDefineControl(type, typefn, handlefield) \
|
#define uiDarwinDefineControl(type, typefn, handlefield) \
|
||||||
|
@ -33,6 +37,7 @@ This file assumes that you have imported <Cocoa/Cocoa.h> and "ui.h" beforehand.
|
||||||
#define uiDarwinFinishNewControl(variable, type) \
|
#define uiDarwinFinishNewControl(variable, type) \
|
||||||
type(variable)->CommitDestroy = _ ## type ## CommitDestroy; \
|
type(variable)->CommitDestroy = _ ## type ## CommitDestroy; \
|
||||||
type(variable)->Handle = _ ## type ## Handle; \
|
type(variable)->Handle = _ ## type ## Handle; \
|
||||||
|
type(variable)->ContainerUpdateState = _ ## type ## ContainerUpdateState; \
|
||||||
uiDarwinFinishControl(uiControl(variable));
|
uiDarwinFinishControl(uiControl(variable));
|
||||||
|
|
||||||
// This is a function used to set up a control.
|
// This is a function used to set up a control.
|
||||||
|
|
Loading…
Reference in New Issue