2015-04-06 11:20:51 -05:00
|
|
|
// 6 april 2015
|
|
|
|
#include "ui.h"
|
|
|
|
#include <stdio.h>
|
2015-04-09 21:38:11 -05:00
|
|
|
#include <string.h>
|
2015-04-06 11:20:51 -05:00
|
|
|
|
|
|
|
int onClosing(uiWindow *w, void *data)
|
|
|
|
{
|
|
|
|
printf("in closing!\n");
|
|
|
|
uiQuit();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2015-04-08 20:25:30 -05:00
|
|
|
uiControl *e;
|
|
|
|
|
|
|
|
static void getWindowText(uiControl *b, void *data)
|
|
|
|
{
|
|
|
|
char *text;
|
|
|
|
|
|
|
|
text = uiWindowTitle((uiWindow *) data);
|
|
|
|
uiEntrySetText(e, text);
|
|
|
|
uiFreeText(text);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void setWindowText(uiControl *b, void *data)
|
|
|
|
{
|
|
|
|
char *text;
|
|
|
|
|
|
|
|
text = uiEntryText(e);
|
|
|
|
uiWindowSetTitle((uiWindow *) data, text);
|
|
|
|
uiFreeText(text);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void getButtonText(uiControl *b, void *data)
|
2015-04-07 18:11:21 -05:00
|
|
|
{
|
2015-04-08 20:25:30 -05:00
|
|
|
char *text;
|
|
|
|
|
|
|
|
text = uiButtonText((uiControl *) data);
|
|
|
|
uiEntrySetText(e, text);
|
|
|
|
uiFreeText(text);
|
2015-04-07 18:11:21 -05:00
|
|
|
}
|
|
|
|
|
2015-04-08 20:25:30 -05:00
|
|
|
static void setButtonText(uiControl *b, void *data)
|
2015-04-07 03:02:21 -05:00
|
|
|
{
|
2015-04-08 20:25:30 -05:00
|
|
|
char *text;
|
|
|
|
|
|
|
|
text = uiEntryText(e);
|
|
|
|
uiButtonSetText((uiControl *) data, text);
|
|
|
|
uiFreeText(text);
|
2015-04-07 03:02:21 -05:00
|
|
|
}
|
|
|
|
|
2015-04-09 11:14:18 -05:00
|
|
|
static void getCheckboxText(uiControl *b, void *data)
|
|
|
|
{
|
|
|
|
char *text;
|
|
|
|
|
|
|
|
text = uiCheckboxText((uiControl *) data);
|
|
|
|
uiEntrySetText(e, text);
|
|
|
|
uiFreeText(text);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void setCheckboxText(uiControl *b, void *data)
|
|
|
|
{
|
|
|
|
char *text;
|
|
|
|
|
|
|
|
text = uiEntryText(e);
|
|
|
|
uiCheckboxSetText((uiControl *) data, text);
|
|
|
|
uiFreeText(text);
|
|
|
|
}
|
|
|
|
|
2015-04-09 12:42:42 -05:00
|
|
|
uiWindow *w;
|
2015-04-12 00:01:56 -05:00
|
|
|
#define nStacks 9
|
2015-04-09 14:59:40 -05:00
|
|
|
uiControl *stacks[nStacks];
|
2015-04-09 11:26:59 -05:00
|
|
|
uiControl *spaced;
|
|
|
|
|
2015-04-09 12:42:42 -05:00
|
|
|
static void setSpaced(int spaced)
|
2015-04-09 11:26:59 -05:00
|
|
|
{
|
2015-04-09 14:59:40 -05:00
|
|
|
int i;
|
|
|
|
|
2015-04-09 12:42:42 -05:00
|
|
|
uiWindowSetMargined(w, spaced);
|
2015-04-09 14:59:40 -05:00
|
|
|
for (i = 0; i < nStacks; i++)
|
|
|
|
uiStackSetPadded(stacks[i], spaced);
|
2015-04-09 12:42:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void toggleSpaced(uiControl *c, void *data)
|
|
|
|
{
|
|
|
|
int s = uiCheckboxChecked(spaced);
|
|
|
|
|
|
|
|
printf("toggled %d\n", s);
|
|
|
|
setSpaced(s);
|
2015-04-09 11:52:34 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// these will also be used to test if setting checks will trigger events
|
|
|
|
static void forceSpacedOn(uiControl *c, void *data)
|
|
|
|
{
|
|
|
|
uiCheckboxSetChecked(spaced, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void forceSpacedOff(uiControl *c, void *data)
|
|
|
|
{
|
|
|
|
uiCheckboxSetChecked(spaced, 0);
|
2015-04-09 11:26:59 -05:00
|
|
|
}
|
2015-04-09 11:14:18 -05:00
|
|
|
|
2015-04-09 19:04:18 -05:00
|
|
|
static void showSpaced(uiControl *c, void *data)
|
|
|
|
{
|
|
|
|
char msg[] = { 'm', ' ', '0', ' ', 'p', ' ', '0', '\0' };
|
|
|
|
|
2015-04-09 20:11:56 -05:00
|
|
|
if (uiWindowMargined(w))
|
|
|
|
msg[2] = '1';
|
2015-04-09 19:04:18 -05:00
|
|
|
if (uiStackPadded(stacks[0]))
|
|
|
|
msg[6] = '1';
|
|
|
|
uiEntrySetText(e, msg);
|
|
|
|
}
|
|
|
|
|
2015-04-11 13:12:12 -05:00
|
|
|
static void showControl(uiControl *c, void *data)
|
|
|
|
{
|
|
|
|
uiControlShow((uiControl *) data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void hideControl(uiControl *c, void *data)
|
|
|
|
{
|
|
|
|
uiControlHide((uiControl *) data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void enableControl(uiControl *c, void *data)
|
|
|
|
{
|
|
|
|
uiControlEnable((uiControl *) data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void disableControl(uiControl *c, void *data)
|
|
|
|
{
|
|
|
|
uiControlDisable((uiControl *) data);
|
|
|
|
}
|
|
|
|
|
2015-04-11 20:53:49 -05:00
|
|
|
static void getLabelText(uiControl *b, void *data)
|
|
|
|
{
|
|
|
|
char *text;
|
|
|
|
|
|
|
|
text = uiLabelText((uiControl *) data);
|
|
|
|
uiEntrySetText(e, text);
|
|
|
|
uiFreeText(text);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void setLabelText(uiControl *b, void *data)
|
|
|
|
{
|
|
|
|
char *text;
|
|
|
|
|
|
|
|
text = uiEntryText(e);
|
|
|
|
uiLabelSetText((uiControl *) data, text);
|
|
|
|
uiFreeText(text);
|
|
|
|
}
|
|
|
|
|
2015-04-07 18:11:21 -05:00
|
|
|
int main(int argc, char *argv[])
|
2015-04-06 11:20:51 -05:00
|
|
|
{
|
2015-04-09 21:38:11 -05:00
|
|
|
uiInitOptions o;
|
|
|
|
int i;
|
2015-04-10 15:54:06 -05:00
|
|
|
const char *err;
|
2015-04-08 20:25:30 -05:00
|
|
|
uiControl *getButton, *setButton;
|
2015-04-11 20:53:49 -05:00
|
|
|
uiControl *label;
|
2015-04-11 23:30:44 -05:00
|
|
|
uiControl *tab;
|
|
|
|
int page2stack;
|
2015-04-06 11:20:51 -05:00
|
|
|
|
2015-04-09 21:38:11 -05:00
|
|
|
memset(&o, 0, sizeof (uiInitOptions));
|
|
|
|
for (i = 1; i < argc; i++)
|
|
|
|
if (strcmp(argv[i], "leaks") == 0)
|
|
|
|
o.debugLogAllocations = 1;
|
|
|
|
else {
|
|
|
|
fprintf(stderr, "%s: unrecognized option %s\n", argv[0], argv[i]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = uiInit(&o);
|
2015-04-06 11:20:51 -05:00
|
|
|
if (err != NULL) {
|
2015-04-10 15:54:06 -05:00
|
|
|
fprintf(stderr, "error initializing ui: %s\n", err);
|
|
|
|
uiFreeInitError(err);
|
2015-04-06 11:20:51 -05:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
w = uiNewWindow("Hello", 320, 240);
|
|
|
|
uiWindowOnClosing(w, onClosing, NULL);
|
|
|
|
|
2015-04-09 11:14:18 -05:00
|
|
|
stacks[0] = uiNewVerticalStack();
|
2015-04-08 20:25:30 -05:00
|
|
|
|
2015-04-08 22:28:47 -05:00
|
|
|
e = uiNewEntry();
|
2015-04-09 11:14:18 -05:00
|
|
|
uiStackAdd(stacks[0], e, 0);
|
2015-04-07 18:11:21 -05:00
|
|
|
|
2015-04-11 21:33:23 -05:00
|
|
|
i = 1;
|
|
|
|
|
|
|
|
stacks[i] = uiNewHorizontalStack();
|
2015-04-08 20:25:30 -05:00
|
|
|
getButton = uiNewButton("Get Window Text");
|
2015-04-09 01:43:49 -05:00
|
|
|
uiButtonOnClicked(getButton, getWindowText, w);
|
2015-04-08 20:25:30 -05:00
|
|
|
setButton = uiNewButton("Set Window Text");
|
2015-04-09 01:43:49 -05:00
|
|
|
uiButtonOnClicked(setButton, setWindowText, w);
|
2015-04-11 21:33:23 -05:00
|
|
|
uiStackAdd(stacks[i], getButton, 1);
|
|
|
|
uiStackAdd(stacks[i], setButton, 1);
|
|
|
|
uiStackAdd(stacks[0], stacks[i], 0);
|
|
|
|
i++;
|
2015-04-07 18:11:21 -05:00
|
|
|
|
2015-04-11 21:33:23 -05:00
|
|
|
stacks[i] = uiNewHorizontalStack();
|
2015-04-08 22:28:47 -05:00
|
|
|
getButton = uiNewButton("Get Button Text");
|
2015-04-09 01:43:49 -05:00
|
|
|
uiButtonOnClicked(getButton, getButtonText, getButton);
|
2015-04-08 22:28:47 -05:00
|
|
|
setButton = uiNewButton("Set Button Text");
|
2015-04-09 01:43:49 -05:00
|
|
|
uiButtonOnClicked(setButton, setButtonText, getButton);
|
2015-04-11 21:33:23 -05:00
|
|
|
uiStackAdd(stacks[i], getButton, 1);
|
|
|
|
uiStackAdd(stacks[i], setButton, 1);
|
|
|
|
uiStackAdd(stacks[0], stacks[i], 0);
|
|
|
|
i++;
|
2015-04-09 11:14:18 -05:00
|
|
|
|
2015-04-09 11:26:59 -05:00
|
|
|
// this will also be used to make sure tab stops work properly when inserted out of creation order, especially on Windows
|
2015-04-09 11:14:18 -05:00
|
|
|
spaced = uiNewCheckbox("Spaced");
|
2015-04-09 12:42:42 -05:00
|
|
|
uiCheckboxOnToggled(spaced, toggleSpaced, NULL);
|
2015-04-09 11:14:18 -05:00
|
|
|
|
2015-04-11 21:33:23 -05:00
|
|
|
stacks[i] = uiNewHorizontalStack();
|
2015-04-09 11:14:18 -05:00
|
|
|
getButton = uiNewButton("Get Checkbox Text");
|
|
|
|
uiButtonOnClicked(getButton, getCheckboxText, spaced);
|
|
|
|
setButton = uiNewButton("Set Checkbox Text");
|
|
|
|
uiButtonOnClicked(setButton, setCheckboxText, spaced);
|
2015-04-11 21:33:23 -05:00
|
|
|
uiStackAdd(stacks[i], getButton, 1);
|
|
|
|
uiStackAdd(stacks[i], setButton, 1);
|
|
|
|
uiStackAdd(stacks[0], stacks[i], 0);
|
|
|
|
i++;
|
2015-04-09 11:14:18 -05:00
|
|
|
|
2015-04-11 20:53:49 -05:00
|
|
|
label = uiNewLabel("Label");
|
2015-04-11 21:33:23 -05:00
|
|
|
|
2015-04-11 20:53:49 -05:00
|
|
|
stacks[i] = uiNewHorizontalStack();
|
|
|
|
getButton = uiNewButton("Get Label Text");
|
|
|
|
uiButtonOnClicked(getButton, getLabelText, label);
|
|
|
|
setButton = uiNewButton("Set Label Text");
|
|
|
|
uiButtonOnClicked(setButton, setLabelText, label);
|
|
|
|
uiStackAdd(stacks[i], getButton, 1);
|
|
|
|
uiStackAdd(stacks[i], setButton, 1);
|
|
|
|
uiStackAdd(stacks[0], stacks[i], 0);
|
|
|
|
i++;
|
2015-04-11 21:33:23 -05:00
|
|
|
|
|
|
|
stacks[i] = uiNewHorizontalStack();
|
|
|
|
uiStackAdd(stacks[i], spaced, 1);
|
2015-04-09 11:52:34 -05:00
|
|
|
getButton = uiNewButton("On");
|
|
|
|
uiButtonOnClicked(getButton, forceSpacedOn, NULL);
|
|
|
|
setButton = uiNewButton("Off");
|
|
|
|
uiButtonOnClicked(setButton, forceSpacedOff, NULL);
|
2015-04-11 21:33:23 -05:00
|
|
|
uiStackAdd(stacks[i], getButton, 0);
|
|
|
|
uiStackAdd(stacks[i], setButton, 0);
|
2015-04-09 19:04:18 -05:00
|
|
|
setButton = uiNewButton("Show");
|
|
|
|
uiButtonOnClicked(setButton, showSpaced, NULL);
|
2015-04-11 21:33:23 -05:00
|
|
|
uiStackAdd(stacks[i], setButton, 0);
|
|
|
|
uiStackAdd(stacks[0], stacks[i], 0);
|
|
|
|
i++;
|
2015-04-07 03:02:21 -05:00
|
|
|
|
2015-04-11 21:33:23 -05:00
|
|
|
stacks[i] = uiNewHorizontalStack();
|
2015-04-11 13:12:12 -05:00
|
|
|
getButton = uiNewButton("Button");
|
2015-04-11 21:33:23 -05:00
|
|
|
uiStackAdd(stacks[i], getButton, 1);
|
2015-04-11 13:12:12 -05:00
|
|
|
setButton = uiNewButton("Show");
|
|
|
|
uiButtonOnClicked(setButton, showControl, getButton);
|
2015-04-11 21:33:23 -05:00
|
|
|
uiStackAdd(stacks[i], setButton, 0);
|
2015-04-11 13:12:12 -05:00
|
|
|
setButton = uiNewButton("Hide");
|
|
|
|
uiButtonOnClicked(setButton, hideControl, getButton);
|
2015-04-11 21:33:23 -05:00
|
|
|
uiStackAdd(stacks[i], setButton, 0);
|
2015-04-11 13:12:12 -05:00
|
|
|
setButton = uiNewButton("Enable");
|
|
|
|
uiButtonOnClicked(setButton, enableControl, getButton);
|
2015-04-11 21:33:23 -05:00
|
|
|
uiStackAdd(stacks[i], setButton, 0);
|
2015-04-11 13:12:12 -05:00
|
|
|
setButton = uiNewButton("Disable");
|
|
|
|
uiButtonOnClicked(setButton, disableControl, getButton);
|
2015-04-11 21:33:23 -05:00
|
|
|
uiStackAdd(stacks[i], setButton, 0);
|
|
|
|
uiStackAdd(stacks[0], stacks[i], 0);
|
|
|
|
i++;
|
2015-04-11 13:12:12 -05:00
|
|
|
|
2015-04-11 21:33:23 -05:00
|
|
|
stacks[i] = uiNewHorizontalStack();
|
2015-04-11 13:12:12 -05:00
|
|
|
setButton = uiNewButton("Show Stack");
|
2015-04-11 21:33:23 -05:00
|
|
|
uiButtonOnClicked(setButton, showControl, stacks[i - 1]);
|
|
|
|
uiStackAdd(stacks[i], setButton, 1);
|
2015-04-11 13:12:12 -05:00
|
|
|
setButton = uiNewButton("Hide Stack");
|
2015-04-11 21:33:23 -05:00
|
|
|
uiButtonOnClicked(setButton, hideControl, stacks[i - 1]);
|
|
|
|
uiStackAdd(stacks[i], setButton, 1);
|
2015-04-11 13:12:12 -05:00
|
|
|
setButton = uiNewButton("Enable Stack");
|
2015-04-11 21:33:23 -05:00
|
|
|
uiButtonOnClicked(setButton, enableControl, stacks[i - 1]);
|
|
|
|
uiStackAdd(stacks[i], setButton, 1);
|
2015-04-11 13:12:12 -05:00
|
|
|
setButton = uiNewButton("Disable Stack");
|
2015-04-11 21:33:23 -05:00
|
|
|
uiButtonOnClicked(setButton, disableControl, stacks[i - 1]);
|
|
|
|
uiStackAdd(stacks[i], setButton, 1);
|
|
|
|
uiStackAdd(stacks[0], stacks[i], 0);
|
|
|
|
i++;
|
2015-04-11 13:12:12 -05:00
|
|
|
|
2015-04-11 20:53:49 -05:00
|
|
|
uiStackAdd(stacks[0], label, 0);
|
|
|
|
|
2015-04-11 23:30:44 -05:00
|
|
|
tab = uiNewTab();
|
|
|
|
uiWindowSetChild(w, tab);
|
|
|
|
uiTabAddPage(tab, "Page 1", stacks[0]);
|
|
|
|
|
|
|
|
page2stack = i;
|
|
|
|
stacks[i] = uiNewVerticalStack();
|
|
|
|
uiTabAddPage(tab, "Page 2", stacks[i]);
|
|
|
|
i++;
|
|
|
|
|
2015-04-11 21:33:23 -05:00
|
|
|
if (i != nStacks) {
|
2015-04-12 00:01:56 -05:00
|
|
|
fprintf(stderr, "forgot to update nStacks (expected %d)\n", i);
|
2015-04-11 21:33:23 -05:00
|
|
|
return 1;
|
|
|
|
}
|
2015-04-07 13:13:42 -05:00
|
|
|
uiWindowShow(w);
|
2015-04-06 11:20:51 -05:00
|
|
|
uiMain();
|
2015-04-06 19:01:14 -05:00
|
|
|
printf("after uiMain()\n");
|
2015-04-06 11:20:51 -05:00
|
|
|
return 0;
|
|
|
|
}
|