2015-05-29 13:56:11 -05:00
|
|
|
// 26 may 2015
|
2015-05-18 21:32:22 -05:00
|
|
|
#include "out/ui.h"
|
|
|
|
#include "uipriv.h"
|
2015-05-18 21:02:37 -05:00
|
|
|
|
2015-05-29 13:56:11 -05:00
|
|
|
struct controlBase {
|
2015-05-18 21:02:37 -05:00
|
|
|
uiControl *parent;
|
2015-05-29 13:56:11 -05:00
|
|
|
int hidden;
|
|
|
|
int disabled;
|
2015-05-18 21:02:37 -05:00
|
|
|
};
|
|
|
|
|
2015-05-29 13:56:11 -05:00
|
|
|
#define controlBase(c) ((struct controlBase *) (c->Internal))
|
2015-05-18 21:02:37 -05:00
|
|
|
|
2015-05-29 13:56:11 -05:00
|
|
|
static void controlBaseDestroy(uiControl *c)
|
2015-05-18 21:02:37 -05:00
|
|
|
{
|
2015-05-29 13:56:11 -05:00
|
|
|
struct controlBase *cb = controlBase(c);
|
2015-05-18 21:02:37 -05:00
|
|
|
|
2015-05-29 13:56:11 -05:00
|
|
|
if (cb->parent != NULL)
|
|
|
|
complain("attempt to destroy uiControl %p while it has a parent", c);
|
|
|
|
uiControlCommitDestroy(c);
|
|
|
|
uiFree(cb);
|
|
|
|
uiFree(c);
|
2015-05-18 21:02:37 -05:00
|
|
|
}
|
|
|
|
|
2015-05-29 13:56:11 -05:00
|
|
|
static uiControl *controlBaseParent(uiControl *c)
|
2015-05-18 21:02:37 -05:00
|
|
|
{
|
2015-05-29 13:56:11 -05:00
|
|
|
struct controlBase *cb = controlBase(c);
|
2015-05-18 21:02:37 -05:00
|
|
|
|
2015-05-29 13:56:11 -05:00
|
|
|
return cb->parent;
|
2015-05-18 21:02:37 -05:00
|
|
|
}
|
|
|
|
|
2015-05-29 13:56:11 -05:00
|
|
|
static void controlBaseSetParent(uiControl *c, uiControl *parent)
|
2015-05-18 21:02:37 -05:00
|
|
|
{
|
2015-05-29 13:56:11 -05:00
|
|
|
struct controlBase *cb = controlBase(c);
|
2015-05-18 21:02:37 -05:00
|
|
|
|
2015-05-29 13:56:11 -05:00
|
|
|
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;
|
|
|
|
uiControlCommitSetParent(c, parent);
|
|
|
|
// for situations such as where the old parent was disabled but the new one is not, etc.
|
|
|
|
uiControlUpdateState(c);
|
2015-05-18 21:02:37 -05:00
|
|
|
}
|
|
|
|
|
2015-05-29 13:56:11 -05:00
|
|
|
static void controlBaseQueueResize(uiControl *c)
|
2015-05-18 21:02:37 -05:00
|
|
|
{
|
|
|
|
queueResize(c);
|
|
|
|
}
|
|
|
|
|
2015-05-29 13:56:11 -05:00
|
|
|
static int controlBaseContainerVisible(uiControl *c)
|
2015-05-18 21:02:37 -05:00
|
|
|
{
|
2015-05-29 13:56:11 -05:00
|
|
|
struct controlBase *cb = controlBase(c);
|
2015-05-18 21:02:37 -05:00
|
|
|
|
2015-05-29 13:56:11 -05:00
|
|
|
if (cb->hidden)
|
|
|
|
return 0;
|
|
|
|
if (cb->parent == NULL)
|
|
|
|
return 1;
|
|
|
|
return uiControlContainerVisible(cb->parent);
|
2015-05-18 21:02:37 -05:00
|
|
|
}
|
|
|
|
|
2015-05-29 13:56:11 -05:00
|
|
|
static void controlBaseShow(uiControl *c)
|
2015-05-18 21:02:37 -05:00
|
|
|
{
|
2015-05-29 13:56:11 -05:00
|
|
|
struct controlBase *cb = controlBase(c);
|
2015-05-18 21:02:37 -05:00
|
|
|
|
2015-05-29 13:56:11 -05:00
|
|
|
cb->hidden = 0;
|
|
|
|
uiControlUpdateState(c);
|
2015-05-18 21:02:37 -05:00
|
|
|
}
|
|
|
|
|
2015-05-29 13:56:11 -05:00
|
|
|
static void controlBaseHide(uiControl *c)
|
2015-05-18 21:02:37 -05:00
|
|
|
{
|
2015-05-29 13:56:11 -05:00
|
|
|
struct controlBase *cb = controlBase(c);
|
2015-05-18 21:02:37 -05:00
|
|
|
|
2015-05-29 13:56:11 -05:00
|
|
|
cb->hidden = 1;
|
|
|
|
uiControlUpdateState(c);
|
2015-05-18 21:02:37 -05:00
|
|
|
}
|
|
|
|
|
2015-05-29 13:56:11 -05:00
|
|
|
static int controlBaseContainerEnabled(uiControl *c)
|
2015-05-18 21:02:37 -05:00
|
|
|
{
|
2015-05-29 13:56:11 -05:00
|
|
|
struct controlBase *cb = controlBase(c);
|
2015-05-18 21:02:37 -05:00
|
|
|
|
2015-05-29 13:56:11 -05:00
|
|
|
if (cb->disabled)
|
|
|
|
return 0;
|
|
|
|
if (cb->parent == NULL)
|
|
|
|
return 1;
|
|
|
|
return uiControlContainerEnabled(cb->parent);
|
2015-05-18 21:02:37 -05:00
|
|
|
}
|
|
|
|
|
2015-05-29 13:56:11 -05:00
|
|
|
static void controlBaseEnable(uiControl *c)
|
2015-05-18 21:02:37 -05:00
|
|
|
{
|
2015-05-29 13:56:11 -05:00
|
|
|
struct controlBase *cb = controlBase(c);
|
2015-05-18 21:02:37 -05:00
|
|
|
|
2015-05-29 13:56:11 -05:00
|
|
|
cb->disabled = 0;
|
|
|
|
uiControlUpdateState(c);
|
2015-05-18 21:02:37 -05:00
|
|
|
}
|
|
|
|
|
2015-05-29 13:56:11 -05:00
|
|
|
static void controlBaseDisable(uiControl *c)
|
2015-05-18 21:02:37 -05:00
|
|
|
{
|
2015-05-29 13:56:11 -05:00
|
|
|
struct controlBase *cb = controlBase(c);
|
2015-05-18 21:02:37 -05:00
|
|
|
|
2015-05-29 13:56:11 -05:00
|
|
|
cb->disabled = 1;
|
|
|
|
uiControlUpdateState(c);
|
2015-05-18 21:02:37 -05:00
|
|
|
}
|
|
|
|
|
2015-05-29 13:56:11 -05:00
|
|
|
static void controlBaseUpdateState(uiControl *c)
|
2015-05-18 21:02:37 -05:00
|
|
|
{
|
2015-05-29 13:56:11 -05:00
|
|
|
if (uiControlContainerVisible(c))
|
|
|
|
uiControlCommitShow(c);
|
|
|
|
else
|
|
|
|
uiControlCommitHide(c);
|
|
|
|
if (uiControlContainerEnabled(c))
|
|
|
|
uiControlCommitEnable(c);
|
|
|
|
else
|
|
|
|
uiControlCommitDisable(c);
|
|
|
|
uiControlContainerUpdateState(c);
|
2015-05-18 21:02:37 -05:00
|
|
|
}
|
|
|
|
|
2015-05-29 13:56:11 -05:00
|
|
|
static void controlBaseContainerUpdateState(uiControl *c)
|
2015-05-18 21:02:37 -05:00
|
|
|
{
|
2015-05-29 13:56:11 -05:00
|
|
|
// by default not a container; do nothing
|
2015-05-18 21:02:37 -05:00
|
|
|
}
|
|
|
|
|
2015-05-29 13:56:11 -05:00
|
|
|
uiControl *uiNewControl(uintmax_t type)
|
2015-05-18 21:02:37 -05:00
|
|
|
{
|
2015-05-29 13:56:11 -05:00
|
|
|
uiControl *c;
|
2015-05-18 21:02:37 -05:00
|
|
|
|
2015-05-29 13:56:11 -05:00
|
|
|
c = uiControl(newTyped(type));
|
|
|
|
uiControl(c)->Internal = uiNew(struct controlBase);
|
|
|
|
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;
|
|
|
|
uiControl(c)->ContainerEnabled = controlBaseContainerEnabled;
|
|
|
|
uiControl(c)->Enable = controlBaseEnable;
|
|
|
|
uiControl(c)->Disable = controlBaseDisable;
|
|
|
|
uiControl(c)->UpdateState = controlBaseUpdateState;
|
|
|
|
uiControl(c)->ContainerUpdateState = controlBaseContainerUpdateState;
|
|
|
|
return uiControl(c);
|
2015-05-18 21:02:37 -05:00
|
|
|
}
|