Started cleaning out the toplevel (the old redo/).
This commit is contained in:
parent
8213eac2d7
commit
e1efbb1b8f
|
@ -1,14 +0,0 @@
|
|||
# 22 april 2015
|
||||
|
||||
testCFILES = \
|
||||
test/main.c \
|
||||
test/menus.c \
|
||||
test/page1.c \
|
||||
test/page2.c \
|
||||
test/page3.c \
|
||||
test/page4.c \
|
||||
test/page5.c \
|
||||
test/spaced.c
|
||||
|
||||
testHFILES = \
|
||||
test/test.h
|
110
test/main.c
110
test/main.c
|
@ -1,110 +0,0 @@
|
|||
// 22 april 2015
|
||||
#include "test.h"
|
||||
|
||||
void die(const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
fprintf(stderr, "[test program] ");
|
||||
vfprintf(stderr, fmt, ap);
|
||||
fprintf(stderr, "\n");
|
||||
va_end(ap);
|
||||
abort();
|
||||
}
|
||||
|
||||
int onClosing(uiWindow *w, void *data)
|
||||
{
|
||||
printf("in onClosing()\n");
|
||||
uiQuit();
|
||||
return 1;
|
||||
}
|
||||
|
||||
int onShouldQuit(void *data)
|
||||
{
|
||||
printf("in onShouldQuit()\n");
|
||||
if (uiMenuItemChecked(shouldQuitItem)) {
|
||||
uiControlDestroy(uiControl(data));
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
uiBox *mainBox;
|
||||
uiTab *mainTab;
|
||||
|
||||
uiBox *(*newhbox)(void);
|
||||
uiBox *(*newvbox)(void);
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
uiInitOptions o;
|
||||
int i;
|
||||
const char *err;
|
||||
uiWindow *w;
|
||||
uiBox *page2, *page3, *page4, *page5;
|
||||
int nomenus = 0;
|
||||
|
||||
newhbox = uiNewHorizontalBox;
|
||||
newvbox = uiNewVerticalBox;
|
||||
|
||||
memset(&o, 0, sizeof (uiInitOptions));
|
||||
for (i = 1; i < argc; i++)
|
||||
if (strcmp(argv[i], "nomenus") == 0)
|
||||
nomenus = 1;
|
||||
else if (strcmp(argv[i], "swaphv") == 0) {
|
||||
newhbox = uiNewVerticalBox;
|
||||
newvbox = uiNewHorizontalBox;
|
||||
} else {
|
||||
fprintf(stderr, "%s: unrecognized option %s\n", argv[0], argv[i]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
err = uiInit(&o);
|
||||
if (err != NULL) {
|
||||
fprintf(stderr, "error initializing ui: %s\n", err);
|
||||
uiFreeInitError(err);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!nomenus)
|
||||
initMenus();
|
||||
|
||||
w = newWindow("Main Window", 320, 240, 1);
|
||||
uiWindowOnClosing(w, onClosing, NULL);
|
||||
printf("main window %p\n", w);
|
||||
|
||||
uiOnShouldQuit(onShouldQuit, w);
|
||||
|
||||
mainBox = newHorizontalBox();
|
||||
uiWindowSetChild(w, uiControl(mainBox));
|
||||
|
||||
mainTab = newTab();
|
||||
uiBoxAppend(mainBox, uiControl(mainTab), 1);
|
||||
|
||||
// page 1 uses page 2's uiGroup
|
||||
page2 = makePage2();
|
||||
|
||||
makePage1(w);
|
||||
uiTabAppend(mainTab, "Page 1", uiControl(page1));
|
||||
|
||||
uiTabAppend(mainTab, "Page 2", uiControl(page2));
|
||||
|
||||
uiTabAppend(mainTab, "Empty Page", uiControl(uiNewHorizontalBox()));
|
||||
|
||||
page3 = makePage3();
|
||||
uiTabAppend(mainTab, "Page 3", uiControl(page3));
|
||||
|
||||
page4 = makePage4();
|
||||
uiTabAppend(mainTab, "Page 4", uiControl(page4));
|
||||
|
||||
page5 = makePage5();
|
||||
uiTabAppend(mainTab, "Page 5", uiControl(page5));
|
||||
|
||||
uiControlShow(uiControl(w));
|
||||
uiMain();
|
||||
printf("after uiMain()\n");
|
||||
uiUninit();
|
||||
printf("after uiUninit()\n");
|
||||
return 0;
|
||||
}
|
112
test/menus.c
112
test/menus.c
|
@ -1,112 +0,0 @@
|
|||
// 23 april 2015
|
||||
#include "test.h"
|
||||
|
||||
uiMenu *fileMenu;
|
||||
uiMenuItem *newItem;
|
||||
uiMenuItem *openItem;
|
||||
uiMenuItem *shouldQuitItem;
|
||||
uiMenuItem *quitItem;
|
||||
uiMenu *editMenu;
|
||||
uiMenuItem *undoItem;
|
||||
uiMenuItem *checkItem;
|
||||
uiMenuItem *accelItem;
|
||||
uiMenuItem *prefsItem;
|
||||
uiMenu *testMenu;
|
||||
uiMenuItem *enabledItem;
|
||||
uiMenuItem *enableThisItem;
|
||||
uiMenuItem *forceCheckedItem;
|
||||
uiMenuItem *forceUncheckedItem;
|
||||
uiMenuItem *whatWindowItem;
|
||||
uiMenu *moreTestsMenu;
|
||||
uiMenuItem *quitEnabledItem;
|
||||
uiMenuItem *prefsEnabledItem;
|
||||
uiMenuItem *aboutEnabledItem;
|
||||
uiMenuItem *checkEnabledItem;
|
||||
uiMenu *multiMenu;
|
||||
uiMenu *helpMenu;
|
||||
uiMenuItem *helpItem;
|
||||
uiMenuItem *aboutItem;
|
||||
|
||||
static void enableItemTest(uiMenuItem *item, uiWindow *w, void *data)
|
||||
{
|
||||
if (uiMenuItemChecked(item))
|
||||
uiMenuItemEnable(uiMenuItem(data));
|
||||
else
|
||||
uiMenuItemDisable(uiMenuItem(data));
|
||||
}
|
||||
|
||||
static void forceOn(uiMenuItem *item, uiWindow *w, void *data)
|
||||
{
|
||||
uiMenuItemSetChecked(enabledItem, 1);
|
||||
}
|
||||
|
||||
static void forceOff(uiMenuItem *item, uiWindow *w, void *data)
|
||||
{
|
||||
uiMenuItemSetChecked(enabledItem, 0);
|
||||
}
|
||||
|
||||
static void whatWindow(uiMenuItem *item, uiWindow *w, void *data)
|
||||
{
|
||||
printf("menu item clicked on window %p\n", w);
|
||||
}
|
||||
|
||||
void initMenus(void)
|
||||
{
|
||||
fileMenu = uiNewMenu("File");
|
||||
newItem = uiMenuAppendItem(fileMenu, "New");
|
||||
openItem = uiMenuAppendItem(fileMenu, "Open");
|
||||
uiMenuAppendSeparator(fileMenu);
|
||||
shouldQuitItem = uiMenuAppendCheckItem(fileMenu, "Should Quit");
|
||||
quitItem = uiMenuAppendQuitItem(fileMenu);
|
||||
|
||||
editMenu = uiNewMenu("Edit");
|
||||
undoItem = uiMenuAppendItem(editMenu, "Undo");
|
||||
uiMenuItemDisable(undoItem);
|
||||
uiMenuAppendSeparator(editMenu);
|
||||
checkItem = uiMenuAppendCheckItem(editMenu, "Check Me\tTest");
|
||||
accelItem = uiMenuAppendItem(editMenu, "A&ccele&&rator T_es__t");
|
||||
prefsItem = uiMenuAppendPreferencesItem(editMenu);
|
||||
|
||||
testMenu = uiNewMenu("Test");
|
||||
enabledItem = uiMenuAppendCheckItem(testMenu, "Enable Below Item");
|
||||
uiMenuItemSetChecked(enabledItem, 1);
|
||||
enableThisItem = uiMenuAppendItem(testMenu, "This Will Be Enabled");
|
||||
uiMenuItemOnClicked(enabledItem, enableItemTest, enableThisItem);
|
||||
forceCheckedItem = uiMenuAppendItem(testMenu, "Force Above Checked");
|
||||
uiMenuItemOnClicked(forceCheckedItem, forceOn, NULL);
|
||||
forceUncheckedItem = uiMenuAppendItem(testMenu, "Force Above Unchecked");
|
||||
uiMenuItemOnClicked(forceUncheckedItem, forceOff, NULL);
|
||||
uiMenuAppendSeparator(testMenu);
|
||||
whatWindowItem = uiMenuAppendItem(testMenu, "What Window?");
|
||||
uiMenuItemOnClicked(whatWindowItem, whatWindow, NULL);
|
||||
|
||||
moreTestsMenu = uiNewMenu("More Tests");
|
||||
quitEnabledItem = uiMenuAppendCheckItem(moreTestsMenu, "Quit Item Enabled");
|
||||
uiMenuItemSetChecked(quitEnabledItem, 1);
|
||||
prefsEnabledItem = uiMenuAppendCheckItem(moreTestsMenu, "Preferences Item Enabled");
|
||||
uiMenuItemSetChecked(prefsEnabledItem, 1);
|
||||
aboutEnabledItem = uiMenuAppendCheckItem(moreTestsMenu, "About Item Enabled");
|
||||
uiMenuItemSetChecked(aboutEnabledItem, 1);
|
||||
uiMenuAppendSeparator(moreTestsMenu);
|
||||
checkEnabledItem = uiMenuAppendCheckItem(moreTestsMenu, "Check Me Item Enabled");
|
||||
uiMenuItemSetChecked(checkEnabledItem, 1);
|
||||
|
||||
multiMenu = uiNewMenu("Multi");
|
||||
uiMenuAppendSeparator(multiMenu);
|
||||
uiMenuAppendSeparator(multiMenu);
|
||||
uiMenuAppendItem(multiMenu, "Item");
|
||||
uiMenuAppendSeparator(multiMenu);
|
||||
uiMenuAppendSeparator(multiMenu);
|
||||
uiMenuAppendItem(multiMenu, "Item");
|
||||
uiMenuAppendSeparator(multiMenu);
|
||||
uiMenuAppendSeparator(multiMenu);
|
||||
|
||||
helpMenu = uiNewMenu("Help");
|
||||
helpItem = uiMenuAppendItem(helpMenu, "Help");
|
||||
aboutItem = uiMenuAppendAboutItem(helpMenu);
|
||||
|
||||
uiMenuItemOnClicked(quitEnabledItem, enableItemTest, quitItem);
|
||||
uiMenuItemOnClicked(prefsEnabledItem, enableItemTest, prefsItem);
|
||||
uiMenuItemOnClicked(aboutEnabledItem, enableItemTest, aboutItem);
|
||||
uiMenuItemOnClicked(checkEnabledItem, enableItemTest, checkItem);
|
||||
}
|
171
test/page1.c
171
test/page1.c
|
@ -1,171 +0,0 @@
|
|||
// 29 april 2015
|
||||
#include "test.h"
|
||||
|
||||
static uiEntry *entry;
|
||||
static uiCheckbox *spaced;
|
||||
|
||||
#define TEXT(name, type, getter, setter) \
|
||||
static void get ## name ## Text(uiButton *b, void *data) \
|
||||
{ \
|
||||
char *text; \
|
||||
text = getter(type(data)); \
|
||||
uiEntrySetText(entry, text); \
|
||||
uiFreeText(text); \
|
||||
} \
|
||||
static void set ## name ## Text(uiButton *b, void *data) \
|
||||
{ \
|
||||
char *text; \
|
||||
text = uiEntryText(entry); \
|
||||
setter(type(data), text); \
|
||||
uiFreeText(text); \
|
||||
}
|
||||
TEXT(Window, uiWindow, uiWindowTitle, uiWindowSetTitle)
|
||||
TEXT(Button, uiButton, uiButtonText, uiButtonSetText)
|
||||
TEXT(Checkbox, uiCheckbox, uiCheckboxText, uiCheckboxSetText)
|
||||
TEXT(Label, uiLabel, uiLabelText, uiLabelSetText)
|
||||
TEXT(Group, uiGroup, uiGroupTitle, uiGroupSetTitle)
|
||||
|
||||
static void onChanged(uiEntry *e, void *data)
|
||||
{
|
||||
printf("onChanged()\n");
|
||||
}
|
||||
|
||||
static void toggleSpaced(uiCheckbox *c, void *data)
|
||||
{
|
||||
setSpaced(uiCheckboxChecked(spaced));
|
||||
}
|
||||
|
||||
static void forceSpaced(uiButton *b, void *data)
|
||||
{
|
||||
uiCheckboxSetChecked(spaced, data != NULL);
|
||||
}
|
||||
|
||||
static void showSpaced(uiButton *b, void *data)
|
||||
{
|
||||
char s[12];
|
||||
|
||||
querySpaced(s);
|
||||
uiEntrySetText(entry, s);
|
||||
}
|
||||
|
||||
#define SHED(method, Method) \
|
||||
static void method ## Control(uiButton *b, void *data) \
|
||||
{ \
|
||||
uiControl ## Method(uiControl(data)); \
|
||||
}
|
||||
SHED(show, Show)
|
||||
SHED(hide, Hide)
|
||||
SHED(enable, Enable)
|
||||
SHED(disable, Disable)
|
||||
|
||||
uiBox *page1;
|
||||
|
||||
void makePage1(uiWindow *w)
|
||||
{
|
||||
uiButton *getButton, *setButton;
|
||||
uiBox *hbox;
|
||||
uiBox *testBox;
|
||||
uiLabel *label;
|
||||
|
||||
page1 = newVerticalBox();
|
||||
|
||||
entry = uiNewEntry();
|
||||
uiEntryOnChanged(entry, onChanged, NULL);
|
||||
uiBoxAppend(page1, uiControl(entry), 0);
|
||||
|
||||
spaced = uiNewCheckbox("Spaced");
|
||||
uiCheckboxOnToggled(spaced, toggleSpaced, NULL);
|
||||
label = uiNewLabel("Label");
|
||||
|
||||
hbox = newHorizontalBox();
|
||||
getButton = uiNewButton("Get Window Text");
|
||||
uiButtonOnClicked(getButton, getWindowText, w);
|
||||
setButton = uiNewButton("Set Window Text");
|
||||
uiButtonOnClicked(setButton, setWindowText, w);
|
||||
uiBoxAppend(hbox, uiControl(getButton), 1);
|
||||
uiBoxAppend(hbox, uiControl(setButton), 1);
|
||||
uiBoxAppend(page1, uiControl(hbox), 0);
|
||||
|
||||
hbox = newHorizontalBox();
|
||||
getButton = uiNewButton("Get Button Text");
|
||||
uiButtonOnClicked(getButton, getButtonText, getButton);
|
||||
setButton = uiNewButton("Set Button Text");
|
||||
uiButtonOnClicked(setButton, setButtonText, getButton);
|
||||
uiBoxAppend(hbox, uiControl(getButton), 1);
|
||||
uiBoxAppend(hbox, uiControl(setButton), 1);
|
||||
uiBoxAppend(page1, uiControl(hbox), 0);
|
||||
|
||||
hbox = newHorizontalBox();
|
||||
getButton = uiNewButton("Get Checkbox Text");
|
||||
uiButtonOnClicked(getButton, getCheckboxText, spaced);
|
||||
setButton = uiNewButton("Set Checkbox Text");
|
||||
uiButtonOnClicked(setButton, setCheckboxText, spaced);
|
||||
uiBoxAppend(hbox, uiControl(getButton), 1);
|
||||
uiBoxAppend(hbox, uiControl(setButton), 1);
|
||||
uiBoxAppend(page1, uiControl(hbox), 0);
|
||||
|
||||
hbox = newHorizontalBox();
|
||||
getButton = uiNewButton("Get Label Text");
|
||||
uiButtonOnClicked(getButton, getLabelText, label);
|
||||
setButton = uiNewButton("Set Label Text");
|
||||
uiButtonOnClicked(setButton, setLabelText, label);
|
||||
uiBoxAppend(hbox, uiControl(getButton), 1);
|
||||
uiBoxAppend(hbox, uiControl(setButton), 1);
|
||||
uiBoxAppend(page1, uiControl(hbox), 0);
|
||||
|
||||
hbox = newHorizontalBox();
|
||||
getButton = uiNewButton("Get Group Text");
|
||||
uiButtonOnClicked(getButton, getGroupText, page2group);
|
||||
setButton = uiNewButton("Set Group Text");
|
||||
uiButtonOnClicked(setButton, setGroupText, page2group);
|
||||
uiBoxAppend(hbox, uiControl(getButton), 1);
|
||||
uiBoxAppend(hbox, uiControl(setButton), 1);
|
||||
uiBoxAppend(page1, uiControl(hbox), 0);
|
||||
|
||||
hbox = newHorizontalBox();
|
||||
uiBoxAppend(hbox, uiControl(spaced), 1);
|
||||
getButton = uiNewButton("On");
|
||||
uiButtonOnClicked(getButton, forceSpaced, getButton);
|
||||
uiBoxAppend(hbox, uiControl(getButton), 0);
|
||||
getButton = uiNewButton("Off");
|
||||
uiButtonOnClicked(getButton, forceSpaced, NULL);
|
||||
uiBoxAppend(hbox, uiControl(getButton), 0);
|
||||
getButton = uiNewButton("Show");
|
||||
uiButtonOnClicked(getButton, showSpaced, NULL);
|
||||
uiBoxAppend(hbox, uiControl(getButton), 0);
|
||||
uiBoxAppend(page1, uiControl(hbox), 0);
|
||||
|
||||
testBox = newHorizontalBox();
|
||||
setButton = uiNewButton("Button");
|
||||
uiBoxAppend(testBox, uiControl(setButton), 1);
|
||||
getButton = uiNewButton("Show");
|
||||
uiButtonOnClicked(getButton, showControl, setButton);
|
||||
uiBoxAppend(testBox, uiControl(getButton), 0);
|
||||
getButton = uiNewButton("Hide");
|
||||
uiButtonOnClicked(getButton, hideControl, setButton);
|
||||
uiBoxAppend(testBox, uiControl(getButton), 0);
|
||||
getButton = uiNewButton("Enable");
|
||||
uiButtonOnClicked(getButton, enableControl, setButton);
|
||||
uiBoxAppend(testBox, uiControl(getButton), 0);
|
||||
getButton = uiNewButton("Disable");
|
||||
uiButtonOnClicked(getButton, disableControl, setButton);
|
||||
uiBoxAppend(testBox, uiControl(getButton), 0);
|
||||
uiBoxAppend(page1, uiControl(testBox), 0);
|
||||
|
||||
hbox = newHorizontalBox();
|
||||
getButton = uiNewButton("Show Box");
|
||||
uiButtonOnClicked(getButton, showControl, testBox);
|
||||
uiBoxAppend(hbox, uiControl(getButton), 1);
|
||||
getButton = uiNewButton("Hide Box");
|
||||
uiButtonOnClicked(getButton, hideControl, testBox);
|
||||
uiBoxAppend(hbox, uiControl(getButton), 1);
|
||||
getButton = uiNewButton("Enable Box");
|
||||
uiButtonOnClicked(getButton, enableControl, testBox);
|
||||
uiBoxAppend(hbox, uiControl(getButton), 1);
|
||||
getButton = uiNewButton("Disable Box");
|
||||
uiButtonOnClicked(getButton, disableControl, testBox);
|
||||
uiBoxAppend(hbox, uiControl(getButton), 1);
|
||||
uiBoxAppend(page1, uiControl(hbox), 0);
|
||||
|
||||
uiBoxAppend(page1, uiControl(label), 0);
|
||||
}
|
202
test/page2.c
202
test/page2.c
|
@ -1,202 +0,0 @@
|
|||
// 29 april 2015
|
||||
#include "test.h"
|
||||
|
||||
uiGroup *page2group;
|
||||
|
||||
static uiLabel *movingLabel;
|
||||
static uiBox *movingBoxes[2];
|
||||
static int movingCurrent;
|
||||
|
||||
static void moveLabel(uiButton *b, void *data)
|
||||
{
|
||||
int from, to;
|
||||
|
||||
from = movingCurrent;
|
||||
to = 0;
|
||||
if (from == 0)
|
||||
to = 1;
|
||||
uiBoxDelete(movingBoxes[from], 0);
|
||||
uiBoxAppend(movingBoxes[to], uiControl(movingLabel), 0);
|
||||
movingCurrent = to;
|
||||
}
|
||||
|
||||
static int moveBack;
|
||||
#define moveOutText "Move Page 1 Out"
|
||||
#define moveBackText "Move Page 1 Back"
|
||||
|
||||
static void movePage1(uiButton *b, void *data)
|
||||
{
|
||||
if (moveBack) {
|
||||
uiBoxDelete(mainBox, 1);
|
||||
uiTabInsertAt(mainTab, "Page 1", 0, uiControl(page1));
|
||||
uiButtonSetText(b, moveOutText);
|
||||
moveBack = 0;
|
||||
return;
|
||||
}
|
||||
uiTabDelete(mainTab, 0);
|
||||
uiBoxAppend(mainBox, uiControl(page1), 1);
|
||||
uiButtonSetText(b, moveBackText);
|
||||
moveBack = 1;
|
||||
}
|
||||
|
||||
static void openAnotherWindow(uiButton *b, void *data)
|
||||
{
|
||||
uiControlShow(uiControl(uiNewWindow("Another Window", 100, 100, data != NULL)));
|
||||
}
|
||||
|
||||
static void openAnotherDisabledWindow(uiButton *b, void *data)
|
||||
{
|
||||
uiWindow *w;
|
||||
|
||||
w = uiNewWindow("Another Window", 100, 100, data != NULL);
|
||||
uiControlDisable(uiControl(w));
|
||||
uiControlShow(uiControl(w));
|
||||
}
|
||||
|
||||
#define SHED(method, Method) \
|
||||
static void method ## Control(uiButton *b, void *data) \
|
||||
{ \
|
||||
uiControl ## Method(uiControl(data)); \
|
||||
}
|
||||
SHED(show, Show)
|
||||
SHED(enable, Enable)
|
||||
SHED(disable, Disable)
|
||||
|
||||
static void echoReadOnlyText(uiEntry *e, void *data)
|
||||
{
|
||||
char *text;
|
||||
|
||||
text = uiEntryText(e);
|
||||
uiEntrySetText(uiEntry(data), text);
|
||||
uiFreeText(text);
|
||||
}
|
||||
|
||||
uiBox *makePage2(void)
|
||||
{
|
||||
uiBox *page2;
|
||||
uiBox *hbox;
|
||||
uiGroup *group;
|
||||
uiBox *vbox;
|
||||
uiButton *button;
|
||||
uiBox *nestedBox;
|
||||
uiBox *innerhbox;
|
||||
uiBox *innerhbox2;
|
||||
uiBox *innerhbox3;
|
||||
uiTab *disabledTab;
|
||||
uiEntry *entry;
|
||||
uiEntry *readonly;
|
||||
uiButton *button2;
|
||||
|
||||
page2 = newVerticalBox();
|
||||
|
||||
group = newGroup("Moving Label");
|
||||
page2group = group;
|
||||
uiBoxAppend(page2, uiControl(group), 0);
|
||||
vbox = newVerticalBox();
|
||||
uiGroupSetChild(group, uiControl(vbox));
|
||||
|
||||
hbox = newHorizontalBox();
|
||||
button = uiNewButton("Move the Label!");
|
||||
uiButtonOnClicked(button, moveLabel, NULL);
|
||||
uiBoxAppend(hbox, uiControl(button), 1);
|
||||
// have a blank label for space
|
||||
uiBoxAppend(hbox, uiControl(uiNewLabel("")), 1);
|
||||
uiBoxAppend(vbox, uiControl(hbox), 0);
|
||||
|
||||
hbox = newHorizontalBox();
|
||||
movingBoxes[0] = newVerticalBox();
|
||||
uiBoxAppend(hbox, uiControl(movingBoxes[0]), 1);
|
||||
movingBoxes[1] = newVerticalBox();
|
||||
uiBoxAppend(hbox, uiControl(movingBoxes[1]), 1);
|
||||
uiBoxAppend(vbox, uiControl(hbox), 0);
|
||||
|
||||
movingCurrent = 0;
|
||||
movingLabel = uiNewLabel("This label moves!");
|
||||
uiBoxAppend(movingBoxes[movingCurrent], uiControl(movingLabel), 0);
|
||||
|
||||
hbox = newHorizontalBox();
|
||||
button = uiNewButton(moveOutText);
|
||||
uiButtonOnClicked(button, movePage1, NULL);
|
||||
uiBoxAppend(hbox, uiControl(button), 0);
|
||||
uiBoxAppend(page2, uiControl(hbox), 0);
|
||||
moveBack = 0;
|
||||
|
||||
hbox = newHorizontalBox();
|
||||
uiBoxAppend(hbox, uiControl(uiNewLabel("Label Alignment Test")), 0);
|
||||
button = uiNewButton("Open Menued Window");
|
||||
uiButtonOnClicked(button, openAnotherWindow, button);
|
||||
uiBoxAppend(hbox, uiControl(button), 0);
|
||||
button = uiNewButton("Open Menuless Window");
|
||||
uiButtonOnClicked(button, openAnotherWindow, NULL);
|
||||
uiBoxAppend(hbox, uiControl(button), 0);
|
||||
button = uiNewButton("Disabled Menued");
|
||||
uiButtonOnClicked(button, openAnotherDisabledWindow, button);
|
||||
uiBoxAppend(hbox, uiControl(button), 0);
|
||||
button = uiNewButton("Disabled Menuless");
|
||||
uiButtonOnClicked(button, openAnotherDisabledWindow, NULL);
|
||||
uiBoxAppend(hbox, uiControl(button), 0);
|
||||
uiBoxAppend(page2, uiControl(hbox), 0);
|
||||
|
||||
nestedBox = newHorizontalBox();
|
||||
innerhbox = newHorizontalBox();
|
||||
uiBoxAppend(innerhbox, uiControl(uiNewButton("These")), 0);
|
||||
button = uiNewButton("buttons");
|
||||
uiControlDisable(uiControl(button));
|
||||
uiBoxAppend(innerhbox, uiControl(button), 0);
|
||||
uiBoxAppend(nestedBox, uiControl(innerhbox), 0);
|
||||
innerhbox = newHorizontalBox();
|
||||
uiBoxAppend(innerhbox, uiControl(uiNewButton("are")), 0);
|
||||
innerhbox2 = newHorizontalBox();
|
||||
button = uiNewButton("in");
|
||||
uiControlDisable(uiControl(button));
|
||||
uiBoxAppend(innerhbox2, uiControl(button), 0);
|
||||
uiBoxAppend(innerhbox, uiControl(innerhbox2), 0);
|
||||
uiBoxAppend(nestedBox, uiControl(innerhbox), 0);
|
||||
innerhbox = newHorizontalBox();
|
||||
innerhbox2 = newHorizontalBox();
|
||||
uiBoxAppend(innerhbox2, uiControl(uiNewButton("nested")), 0);
|
||||
innerhbox3 = newHorizontalBox();
|
||||
button = uiNewButton("boxes");
|
||||
uiControlDisable(uiControl(button));
|
||||
uiBoxAppend(innerhbox3, uiControl(button), 0);
|
||||
uiBoxAppend(innerhbox2, uiControl(innerhbox3), 0);
|
||||
uiBoxAppend(innerhbox, uiControl(innerhbox2), 0);
|
||||
uiBoxAppend(nestedBox, uiControl(innerhbox), 0);
|
||||
uiBoxAppend(page2, uiControl(nestedBox), 0);
|
||||
|
||||
hbox = newHorizontalBox();
|
||||
button = uiNewButton("Enable Nested Box");
|
||||
uiButtonOnClicked(button, enableControl, nestedBox);
|
||||
uiBoxAppend(hbox, uiControl(button), 0);
|
||||
button = uiNewButton("Disable Nested Box");
|
||||
uiButtonOnClicked(button, disableControl, nestedBox);
|
||||
uiBoxAppend(hbox, uiControl(button), 0);
|
||||
uiBoxAppend(page2, uiControl(hbox), 0);
|
||||
|
||||
disabledTab = newTab();
|
||||
uiTabAppend(disabledTab, "Disabled", uiControl(uiNewButton("Button")));
|
||||
uiTabAppend(disabledTab, "Tab", uiControl(uiNewLabel("Label")));
|
||||
uiControlDisable(uiControl(disabledTab));
|
||||
uiBoxAppend(page2, uiControl(disabledTab), 1);
|
||||
|
||||
entry = uiNewEntry();
|
||||
readonly = uiNewEntry();
|
||||
uiEntryOnChanged(entry, echoReadOnlyText, readonly);
|
||||
uiEntrySetText(readonly, "If you can see this, uiEntryReadOnly() isn't working properly.");
|
||||
uiEntrySetReadOnly(readonly, 1);
|
||||
if (uiEntryReadOnly(readonly))
|
||||
uiEntrySetText(readonly, "");
|
||||
uiBoxAppend(page2, uiControl(entry), 0);
|
||||
uiBoxAppend(page2, uiControl(readonly), 0);
|
||||
|
||||
hbox = newHorizontalBox();
|
||||
button = uiNewButton("Show Button 2");
|
||||
button2 = uiNewButton("Button 2");
|
||||
uiButtonOnClicked(button, showControl, button2);
|
||||
uiControlHide(uiControl(button2));
|
||||
uiBoxAppend(hbox, uiControl(button), 1);
|
||||
uiBoxAppend(hbox, uiControl(button2), 0);
|
||||
uiBoxAppend(page2, uiControl(hbox), 0);
|
||||
|
||||
return page2;
|
||||
}
|
69
test/page3.c
69
test/page3.c
|
@ -1,69 +0,0 @@
|
|||
// 7 may 2015
|
||||
#include "test.h"
|
||||
|
||||
static uiBox *makeSet(int omit, int hidden, int stretch)
|
||||
{
|
||||
uiBox *hbox;
|
||||
uiButton *buttons[4];
|
||||
|
||||
// don't use newHorizontalBox()
|
||||
// the point of this test is to test hidden controls and padded
|
||||
hbox = (*newhbox)();
|
||||
uiBoxSetPadded(hbox, 1);
|
||||
if (omit != 0) {
|
||||
buttons[0] = uiNewButton("First");
|
||||
uiBoxAppend(hbox, uiControl(buttons[0]), stretch);
|
||||
}
|
||||
if (omit != 1) {
|
||||
buttons[1] = uiNewButton("Second");
|
||||
uiBoxAppend(hbox, uiControl(buttons[1]), stretch);
|
||||
}
|
||||
if (omit != 2) {
|
||||
buttons[2] = uiNewButton("Third");
|
||||
uiBoxAppend(hbox, uiControl(buttons[2]), stretch);
|
||||
}
|
||||
if (omit != 3) {
|
||||
buttons[3] = uiNewButton("Fourth");
|
||||
uiBoxAppend(hbox, uiControl(buttons[3]), stretch);
|
||||
}
|
||||
if (hidden != -1)
|
||||
uiControlHide(uiControl(buttons[hidden]));
|
||||
return hbox;
|
||||
}
|
||||
|
||||
uiBox *makePage3(void)
|
||||
{
|
||||
uiBox *page3;
|
||||
uiBox *hbox;
|
||||
uiBox *hbox2;
|
||||
uiBox *vbox;
|
||||
int hidden;
|
||||
|
||||
page3 = newVerticalBox();
|
||||
|
||||
// first the non-stretchy type
|
||||
for (hidden = 0; hidden < 4; hidden++) {
|
||||
// these two must stay unpadded as well, otherwise the test isn't meaningful
|
||||
hbox2 = (*newhbox)();
|
||||
vbox = (*newvbox)();
|
||||
// reference set
|
||||
hbox = makeSet(hidden, -1, 0);
|
||||
uiBoxAppend(vbox, uiControl(hbox), 0);
|
||||
// real thing
|
||||
hbox = makeSet(-1, hidden, 0);
|
||||
uiBoxAppend(vbox, uiControl(hbox), 0);
|
||||
// pack vbox in
|
||||
uiBoxAppend(hbox2, uiControl(vbox), 0);
|
||||
// and have a button in there for showing right margins
|
||||
uiBoxAppend(hbox2, uiControl(uiNewButton("Right Margin Test")), 1);
|
||||
uiBoxAppend(page3, uiControl(hbox2), 0);
|
||||
}
|
||||
|
||||
// then the stretchy type
|
||||
for (hidden = 0; hidden < 4; hidden++) {
|
||||
hbox = makeSet(-1, hidden, 1);
|
||||
uiBoxAppend(page3, uiControl(hbox), 0);
|
||||
}
|
||||
|
||||
return page3;
|
||||
}
|
120
test/page4.c
120
test/page4.c
|
@ -1,120 +0,0 @@
|
|||
// 19 may 2015
|
||||
#include "test.h"
|
||||
|
||||
static uiSpinbox *spinbox;
|
||||
static uiSlider *slider;
|
||||
static uiProgressBar *pbar;
|
||||
|
||||
#define CHANGED(what) \
|
||||
static void on ## what ## Changed(ui ## what *this, void *data) \
|
||||
{ \
|
||||
uintmax_t value; \
|
||||
printf("on %s changed\n", #what); \
|
||||
value = ui ## what ## Value(this); \
|
||||
uiSpinboxSetValue(spinbox, value); \
|
||||
uiSliderSetValue(slider, value); \
|
||||
uiProgressBarSetValue(pbar, value); \
|
||||
}
|
||||
CHANGED(Spinbox)
|
||||
CHANGED(Slider)
|
||||
|
||||
#define SETTOO(what, name, n) \
|
||||
static void set ## what ## Too ## name(uiButton *this, void *data) \
|
||||
{ \
|
||||
ui ## what ## SetValue(ui ## what(data), n); \
|
||||
}
|
||||
SETTOO(Spinbox, Low, -80)
|
||||
SETTOO(Spinbox, High, 80)
|
||||
SETTOO(Slider, Low, -80)
|
||||
SETTOO(Slider, High, 80)
|
||||
|
||||
static uiCombobox *cbox;
|
||||
static uiCombobox *editable;
|
||||
static uiRadioButtons *rb;
|
||||
|
||||
static void appendCBRB(uiButton *b, void *data)
|
||||
{
|
||||
uiComboboxAppend(cbox, "New Item");
|
||||
uiComboboxAppend(editable, "New Item");
|
||||
uiRadioButtonsAppend(rb, "New Item");
|
||||
}
|
||||
|
||||
uiBox *makePage4(void)
|
||||
{
|
||||
uiBox *page4;
|
||||
uiBox *hbox;
|
||||
uiSpinbox *xsb;
|
||||
uiButton *b;
|
||||
uiSlider *xsl;
|
||||
|
||||
page4 = newVerticalBox();
|
||||
|
||||
spinbox = uiNewSpinbox(0, 100);
|
||||
uiSpinboxOnChanged(spinbox, onSpinboxChanged, NULL);
|
||||
uiBoxAppend(page4, uiControl(spinbox), 0);
|
||||
|
||||
slider = uiNewSlider(0, 100);
|
||||
uiSliderOnChanged(slider, onSliderChanged, NULL);
|
||||
uiBoxAppend(page4, uiControl(slider), 0);
|
||||
|
||||
pbar = uiNewProgressBar();
|
||||
uiBoxAppend(page4, uiControl(pbar), 0);
|
||||
|
||||
uiBoxAppend(page4, uiControl(uiNewHorizontalSeparator()), 0);
|
||||
|
||||
hbox = newHorizontalBox();
|
||||
xsb = uiNewSpinbox(-40, 40);
|
||||
uiBoxAppend(hbox, uiControl(xsb), 0);
|
||||
b = uiNewButton("Bad Low");
|
||||
uiButtonOnClicked(b, setSpinboxTooLow, xsb);
|
||||
uiBoxAppend(hbox, uiControl(b), 0);
|
||||
b = uiNewButton("Bad High");
|
||||
uiButtonOnClicked(b, setSpinboxTooHigh, xsb);
|
||||
uiBoxAppend(hbox, uiControl(b), 0);
|
||||
uiBoxAppend(page4, uiControl(hbox), 0);
|
||||
|
||||
hbox = newHorizontalBox();
|
||||
xsl = uiNewSlider(-40, 40);
|
||||
uiBoxAppend(hbox, uiControl(xsl), 0);
|
||||
b = uiNewButton("Bad Low");
|
||||
uiButtonOnClicked(b, setSliderTooLow, xsl);
|
||||
uiBoxAppend(hbox, uiControl(b), 0);
|
||||
b = uiNewButton("Bad High");
|
||||
uiButtonOnClicked(b, setSliderTooHigh, xsl);
|
||||
uiBoxAppend(hbox, uiControl(b), 0);
|
||||
uiBoxAppend(page4, uiControl(hbox), 0);
|
||||
|
||||
uiBoxAppend(page4, uiControl(uiNewHorizontalSeparator()), 0);
|
||||
|
||||
cbox = uiNewCombobox();
|
||||
uiComboboxAppend(cbox, "Item 1");
|
||||
uiComboboxAppend(cbox, "Item 2");
|
||||
uiComboboxAppend(cbox, "Item 3");
|
||||
uiBoxAppend(page4, uiControl(cbox), 0);
|
||||
|
||||
editable = uiNewEditableCombobox();
|
||||
uiComboboxAppend(editable, "Editable Item 1");
|
||||
uiComboboxAppend(editable, "Editable Item 2");
|
||||
uiComboboxAppend(editable, "Editable Item 3");
|
||||
uiBoxAppend(page4, uiControl(editable), 0);
|
||||
|
||||
rb = uiNewRadioButtons();
|
||||
uiRadioButtonsAppend(rb, "Item 1");
|
||||
uiRadioButtonsAppend(rb, "Item 2");
|
||||
uiRadioButtonsAppend(rb, "Item 3");
|
||||
uiBoxAppend(page4, uiControl(rb), 0);
|
||||
|
||||
hbox = newHorizontalBox();
|
||||
b = uiNewButton("Append");
|
||||
uiButtonOnClicked(b, appendCBRB, NULL);
|
||||
uiBoxAppend(hbox, uiControl(b), 0);
|
||||
uiBoxAppend(page4, uiControl(hbox), 0);
|
||||
|
||||
uiBoxAppend(page4, uiControl(uiNewHorizontalSeparator()), 0);
|
||||
|
||||
uiBoxAppend(page4, uiControl(uiNewDateTimePicker()), 0);
|
||||
uiBoxAppend(page4, uiControl(uiNewDatePicker()), 0);
|
||||
uiBoxAppend(page4, uiControl(uiNewTimePicker()), 0);
|
||||
|
||||
return page4;
|
||||
}
|
95
test/page5.c
95
test/page5.c
|
@ -1,95 +0,0 @@
|
|||
// 22 may 2015
|
||||
#include "test.h"
|
||||
|
||||
static void openFile(uiButton *b, void *data)
|
||||
{
|
||||
char *fn;
|
||||
|
||||
fn = uiOpenFile();
|
||||
if (fn == NULL)
|
||||
uiLabelSetText(uiLabel(data), "(cancelled)");
|
||||
else {
|
||||
uiLabelSetText(uiLabel(data), fn);
|
||||
uiFreeText(fn);
|
||||
}
|
||||
}
|
||||
|
||||
static void saveFile(uiButton *b, void *data)
|
||||
{
|
||||
char *fn;
|
||||
|
||||
fn = uiSaveFile();
|
||||
if (fn == NULL)
|
||||
uiLabelSetText(uiLabel(data), "(cancelled)");
|
||||
else {
|
||||
uiLabelSetText(uiLabel(data), fn);
|
||||
uiFreeText(fn);
|
||||
}
|
||||
}
|
||||
|
||||
static uiEntry *title, *description;
|
||||
|
||||
static void msgBox(uiButton *b, void *data)
|
||||
{
|
||||
char *t, *d;
|
||||
|
||||
t = uiEntryText(title);
|
||||
d = uiEntryText(description);
|
||||
uiMsgBox(t, d);
|
||||
uiFreeText(d);
|
||||
uiFreeText(t);
|
||||
}
|
||||
|
||||
static void msgBoxError(uiButton *b, void *data)
|
||||
{
|
||||
char *t, *d;
|
||||
|
||||
t = uiEntryText(title);
|
||||
d = uiEntryText(description);
|
||||
uiMsgBoxError(t, d);
|
||||
uiFreeText(d);
|
||||
uiFreeText(t);
|
||||
}
|
||||
|
||||
uiBox *makePage5(void)
|
||||
{
|
||||
uiBox *page5;
|
||||
uiBox *hbox;
|
||||
uiButton *button;
|
||||
uiLabel *label;
|
||||
|
||||
page5 = newVerticalBox();
|
||||
|
||||
#define D(n, f) \
|
||||
hbox = newHorizontalBox(); \
|
||||
button = uiNewButton(n); \
|
||||
label = uiNewLabel(""); \
|
||||
uiButtonOnClicked(button, f, label); \
|
||||
uiBoxAppend(hbox, uiControl(button), 0); \
|
||||
uiBoxAppend(hbox, uiControl(label), 0); \
|
||||
uiBoxAppend(page5, uiControl(hbox), 0);
|
||||
|
||||
D("Open File", openFile);
|
||||
D("Save File", saveFile);
|
||||
|
||||
title = uiNewEntry();
|
||||
uiEntrySetText(title, "Title");
|
||||
description = uiNewEntry();
|
||||
uiEntrySetText(description, "Description");
|
||||
|
||||
hbox = newHorizontalBox();
|
||||
button = uiNewButton("Message Box");
|
||||
uiButtonOnClicked(button, msgBox, NULL);
|
||||
uiBoxAppend(hbox, uiControl(button), 0);
|
||||
uiBoxAppend(hbox, uiControl(title), 0);
|
||||
uiBoxAppend(page5, uiControl(hbox), 0);
|
||||
|
||||
hbox = newHorizontalBox();
|
||||
button = uiNewButton("Error Box");
|
||||
uiButtonOnClicked(button, msgBoxError, NULL);
|
||||
uiBoxAppend(hbox, uiControl(button), 0);
|
||||
uiBoxAppend(hbox, uiControl(description), 0);
|
||||
uiBoxAppend(page5, uiControl(hbox), 0);
|
||||
|
||||
return page5;
|
||||
}
|
149
test/spaced.c
149
test/spaced.c
|
@ -1,149 +0,0 @@
|
|||
// 22 april 2015
|
||||
#include "test.h"
|
||||
|
||||
struct thing {
|
||||
void *ptr;
|
||||
int type;
|
||||
};
|
||||
|
||||
static struct thing *things = NULL;
|
||||
static uintmax_t len = 0;
|
||||
static uintmax_t cap = 0;
|
||||
|
||||
#define grow 32
|
||||
|
||||
static void *append(void *thing, int type)
|
||||
{
|
||||
if (len >= cap) {
|
||||
cap += grow;
|
||||
things = (struct thing *) realloc(things, cap * sizeof (struct thing));
|
||||
if (things == NULL)
|
||||
die("reallocating things array in test/spaced.c append()");
|
||||
}
|
||||
things[len].ptr = thing;
|
||||
things[len].type = type;
|
||||
len++;
|
||||
return things[len - 1].ptr;
|
||||
}
|
||||
|
||||
enum types {
|
||||
window,
|
||||
box,
|
||||
tab,
|
||||
group,
|
||||
};
|
||||
|
||||
void setSpaced(int spaced)
|
||||
{
|
||||
uintmax_t i;
|
||||
void *p;
|
||||
uintmax_t j, n;
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
p = things[i].ptr;
|
||||
switch (things[i].type) {
|
||||
case window:
|
||||
uiWindowSetMargined(uiWindow(p), spaced);
|
||||
break;
|
||||
case box:
|
||||
uiBoxSetPadded(uiBox(p), spaced);
|
||||
break;
|
||||
case tab:
|
||||
n = uiTabNumPages(uiTab(p));
|
||||
for (j = 0; j < n; j++)
|
||||
uiTabSetMargined(uiTab(p), j, spaced);
|
||||
break;
|
||||
case group:
|
||||
uiGroupSetMargined(uiGroup(p), spaced);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void querySpaced(char out[12]) // more than enough
|
||||
{
|
||||
int m = 0;
|
||||
int p = 0;
|
||||
uintmax_t i;
|
||||
void *pp;
|
||||
uintmax_t j, n;
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
pp = things[i].ptr;
|
||||
switch (things[i].type) {
|
||||
case window:
|
||||
if (uiWindowMargined(uiWindow(pp)))
|
||||
m++;
|
||||
break;
|
||||
case box:
|
||||
p = uiBoxPadded(uiBox(pp));
|
||||
break;
|
||||
case tab:
|
||||
n = uiTabNumPages(uiTab(pp));
|
||||
for (j = 0; j < n; j++)
|
||||
if (uiTabMargined(uiTab(pp), j))
|
||||
m++;
|
||||
break;
|
||||
case group:
|
||||
if (uiGroupMargined(uiGroup(pp)))
|
||||
m++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
out[0] = 'm';
|
||||
out[1] = ' ';
|
||||
out[2] = '0' + m;
|
||||
out[3] = ' ';
|
||||
out[4] = 'p';
|
||||
out[5] = ' ';
|
||||
out[6] = '0';
|
||||
if (p)
|
||||
out[6] = '1';
|
||||
out[7] = '\0';
|
||||
}
|
||||
|
||||
uiWindow *newWindow(const char *title, int width, int height, int hasMenubar)
|
||||
{
|
||||
uiWindow *w;
|
||||
|
||||
w = uiNewWindow(title, width, height, hasMenubar);
|
||||
append(w, window);
|
||||
return w;
|
||||
}
|
||||
|
||||
uiBox *newHorizontalBox(void)
|
||||
{
|
||||
uiBox *b;
|
||||
|
||||
b = (*newhbox)();
|
||||
append(b, box);
|
||||
return b;
|
||||
}
|
||||
|
||||
uiBox *newVerticalBox(void)
|
||||
{
|
||||
uiBox *b;
|
||||
|
||||
b = (*newvbox)();
|
||||
append(b, box);
|
||||
return b;
|
||||
}
|
||||
|
||||
uiTab *newTab(void)
|
||||
{
|
||||
uiTab *t;
|
||||
|
||||
t = uiNewTab();
|
||||
append(t, tab);
|
||||
return t;
|
||||
}
|
||||
|
||||
uiGroup *newGroup(const char *text)
|
||||
{
|
||||
uiGroup *g;
|
||||
|
||||
g = uiNewGroup(text);
|
||||
append(g, group);
|
||||
return g;
|
||||
}
|
44
test/test.h
44
test/test.h
|
@ -1,44 +0,0 @@
|
|||
// 22 april 2015
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include "../out/ui.h"
|
||||
|
||||
// main.c
|
||||
extern void die(const char *, ...);
|
||||
extern uiBox *mainBox;
|
||||
extern uiTab *mainTab;
|
||||
extern uiBox *(*newhbox)(void);
|
||||
extern uiBox *(*newvbox)(void);
|
||||
|
||||
// spaced.c
|
||||
extern void setSpaced(int);
|
||||
extern void querySpaced(char[12]);
|
||||
extern uiWindow *newWindow(const char *title, int width, int height, int hasMenubar);
|
||||
extern uiBox *newHorizontalBox(void);
|
||||
extern uiBox *newVerticalBox(void);
|
||||
extern uiTab *newTab(void);
|
||||
extern uiGroup *newGroup(const char *);
|
||||
|
||||
// menus.c
|
||||
extern uiMenuItem *shouldQuitItem;
|
||||
extern void initMenus(void);
|
||||
|
||||
// page1.c
|
||||
extern uiBox *page1;
|
||||
extern void makePage1(uiWindow *);
|
||||
|
||||
// page2.c
|
||||
extern uiGroup *page2group;
|
||||
extern uiBox *makePage2(void);
|
||||
|
||||
// page3.c
|
||||
extern uiBox *makePage3(void);
|
||||
|
||||
// page4.c
|
||||
extern uiBox *makePage4(void);
|
||||
|
||||
// page5.c
|
||||
extern uiBox *makePage5(void);
|
199
tools/idl2h.go
199
tools/idl2h.go
|
@ -1,199 +0,0 @@
|
|||
// 15 april 2015
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"flag"
|
||||
"github.com/andlabs/pgidl"
|
||||
)
|
||||
|
||||
var extern = flag.String("extern", "extern", "name for extern")
|
||||
var guard = flag.String("guard", "", "#define name for include guards")
|
||||
|
||||
var pkgtypes = map[string]string{}
|
||||
|
||||
func typedecl(t *pgidl.Type, name string) string {
|
||||
if t == nil {
|
||||
return "void " + name
|
||||
}
|
||||
if t.IsFuncPtr {
|
||||
return cfuncptrdecl(t.FuncType, name)
|
||||
}
|
||||
s := t.Name + " "
|
||||
if pkgtypes[t.Name] != "" {
|
||||
s = pkgtypes[t.Name] + " "
|
||||
}
|
||||
for i := uint(0); i < t.NumPtrs; i++ {
|
||||
s += "*"
|
||||
}
|
||||
return s + name
|
||||
}
|
||||
|
||||
func arglist(a []*pgidl.Arg) string {
|
||||
if len(a) == 0 {
|
||||
return "void"
|
||||
}
|
||||
s := typedecl(a[0].Type, a[0].Name)
|
||||
for i := 1; i < len(a); i++ {
|
||||
s += ", " + typedecl(a[i].Type, a[i].Name)
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
func cfuncdecl(f *pgidl.Func, name string) string {
|
||||
fd := name + "(" + arglist(f.Args) + ")"
|
||||
return *extern + " " + typedecl(f.Ret, fd) + ";"
|
||||
}
|
||||
|
||||
func cfuncptrdecl(f *pgidl.Func, name string) string {
|
||||
name = "(*" + name + ")"
|
||||
fd := name + "(" + arglist(f.Args) + ")"
|
||||
return typedecl(f.Ret, fd)
|
||||
}
|
||||
|
||||
func cmethodmacro(f *pgidl.Func, typename string) string {
|
||||
s := "#define " + typename + f.Name + "("
|
||||
first := true
|
||||
for _, a := range f.Args {
|
||||
if !first {
|
||||
s += ", "
|
||||
}
|
||||
s += a.Name
|
||||
first = false
|
||||
}
|
||||
s += ") ("
|
||||
s += "(*((this)->" + f.Name + "))"
|
||||
s += "("
|
||||
first = true
|
||||
for _, a := range f.Args {
|
||||
if !first {
|
||||
s += ", "
|
||||
}
|
||||
s += "(" + a.Name + ")"
|
||||
first = false
|
||||
}
|
||||
s += ")"
|
||||
s += ")"
|
||||
return s
|
||||
}
|
||||
|
||||
func genpkgfunc(f *pgidl.Func, prefix string) {
|
||||
fmt.Printf("%s\n", cfuncdecl(f, prefix + f.Name))
|
||||
}
|
||||
|
||||
func genstruct(s *pgidl.Struct, prefix string) {
|
||||
fmt.Printf("struct %s%s {\n", prefix, s.Name)
|
||||
for _, f := range s.Fields {
|
||||
fmt.Printf("\t%s;\n", typedecl(f.Type, f.Name))
|
||||
}
|
||||
fmt.Printf("};\n")
|
||||
}
|
||||
|
||||
func geniface(i *pgidl.Interface, prefix string) {
|
||||
fmt.Printf("struct %s%s {\n", prefix, i.Name)
|
||||
if i.From != "" {
|
||||
fmt.Printf("\t%s%s base;\n", prefix, i.From)
|
||||
} else {
|
||||
fmt.Printf("\tuintmax_t Type;\n")
|
||||
}
|
||||
for _, f := range i.Fields {
|
||||
fmt.Printf("\t%s;\n", typedecl(f.Type, f.Name))
|
||||
}
|
||||
for _, m := range i.Methods {
|
||||
// hack our this pointer in
|
||||
m.Args = append([]*pgidl.Arg{
|
||||
&pgidl.Arg{
|
||||
Name: "this",
|
||||
Type: &pgidl.Type{
|
||||
Name: prefix + i.Name,
|
||||
NumPtrs: 1,
|
||||
},
|
||||
},
|
||||
}, m.Args...)
|
||||
fmt.Printf("\t%s;\n", cfuncptrdecl(m, m.Name))
|
||||
fmt.Printf("%s\n", cmethodmacro(m, prefix + i.Name))
|
||||
}
|
||||
fmt.Printf("};\n")
|
||||
fmt.Printf("%s uintmax_t %sType%s(void);\n",
|
||||
*extern,
|
||||
prefix, i.Name)
|
||||
fmt.Printf("#define %s%s(this) ((%s%s *) %sIsA((this), %sType%s(), 1))\n",
|
||||
prefix, i.Name,
|
||||
prefix, i.Name,
|
||||
prefix,
|
||||
prefix, i.Name)
|
||||
fmt.Printf("#define %sIs%s(this) (%sIsA((this), %sType%s(), 0) != NULL)\n",
|
||||
prefix, i.Name,
|
||||
prefix,
|
||||
prefix, i.Name)
|
||||
}
|
||||
|
||||
func genenum(e *pgidl.Enum, prefix string) {
|
||||
fmt.Printf("enum %s%s {\n", prefix, e.Name)
|
||||
for _, m := range e.Members {
|
||||
fmt.Printf("\t%s%s%s,\n", prefix, e.Name, m)
|
||||
}
|
||||
fmt.Printf("};\n")
|
||||
}
|
||||
|
||||
func genpkg(p *pgidl.Package) {
|
||||
for _, s := range p.Structs {
|
||||
fmt.Printf("typedef struct %s%s %s%s;\n",
|
||||
p.Name, s.Name,
|
||||
p.Name, s.Name)
|
||||
pkgtypes[s.Name] = p.Name + s.Name
|
||||
}
|
||||
for _, i := range p.Interfaces {
|
||||
fmt.Printf("typedef struct %s%s %s%s;\n",
|
||||
p.Name, i.Name,
|
||||
p.Name, i.Name)
|
||||
pkgtypes[i.Name] = p.Name + i.Name
|
||||
}
|
||||
for _, e := range p.Enums {
|
||||
fmt.Printf("typedef enum %s%s %s%s;\n",
|
||||
p.Name, e.Name,
|
||||
p.Name, e.Name)
|
||||
pkgtypes[e.Name] = p.Name + e.Name
|
||||
}
|
||||
// apparently we have to fully define C enumerations before we can use them...
|
||||
for _, e := range p.Enums {
|
||||
genenum(e, p.Name)
|
||||
}
|
||||
for _, o := range p.Order {
|
||||
switch o.Which {
|
||||
case pgidl.Funcs:
|
||||
genpkgfunc(p.Funcs[o.Index], p.Name)
|
||||
case pgidl.Structs:
|
||||
genstruct(p.Structs[o.Index], p.Name)
|
||||
case pgidl.Interfaces:
|
||||
geniface(p.Interfaces[o.Index], p.Name)
|
||||
case pgidl.Raws:
|
||||
fmt.Printf("%s\n", p.Raws[o.Index])
|
||||
case pgidl.Enums:
|
||||
// we did them already; see above
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
idl, errs := pgidl.Parse(os.Stdin, "<stdin>")
|
||||
if len(errs) != 0 {
|
||||
for _, e := range errs {
|
||||
fmt.Fprintf(os.Stderr, "%s\n", e)
|
||||
}
|
||||
os.Exit(1)
|
||||
}
|
||||
fmt.Printf("// generated by idl2h; do not edit\n")
|
||||
if *guard != "" {
|
||||
fmt.Printf("#ifndef %s\n", *guard)
|
||||
fmt.Printf("#define %s\n", *guard)
|
||||
}
|
||||
for _, p := range idl {
|
||||
genpkg(p)
|
||||
}
|
||||
if *guard != "" {
|
||||
fmt.Printf("#endif\n")
|
||||
}
|
||||
}
|
229
ui.idl
229
ui.idl
|
@ -1,229 +0,0 @@
|
|||
// 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, size size_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;
|
||||
};
|
||||
|
||||
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 StartZOrder(void) uintptr_t;
|
||||
func SetZOrder(param uintptr_t) uintptr_t;
|
||||
func HasTabStops(void) int;
|
||||
func CommitDestroy(void);
|
||||
func CommitSetParent(parent *uiControl);
|
||||
func CommitShow(void);
|
||||
func CommitHide(void);
|
||||
func CommitEnable(void);
|
||||
func CommitDisable(void);
|
||||
func ContainerUpdateState(void);
|
||||
};
|
||||
|
||||
func NewControl(type uintmax_t) *Control;
|
||||
|
||||
raw "#define uiDefineControlType(typename, funcname, realtype) \\";
|
||||
raw " static uintmax_t type_ ## typename = 0; \\";
|
||||
raw " uintmax_t funcname(void) \\";
|
||||
raw " { \\";
|
||||
raw " if (type_ ## typename == 0) \\";
|
||||
raw " type_ ## typename = uiRegisterType(#typename, uiTypeControl(), sizeof (realtype)); \\";
|
||||
raw " return type_ ## typename; \\";
|
||||
raw " }";
|
||||
|
||||
func FreeSizing(d *Sizing);
|
||||
|
||||
func MakeContainer(c *Control) uintptr_t;
|
||||
|
||||
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 {
|
||||
func Title(void) *char;
|
||||
func SetTitle(title *const char);
|
||||
func SetChild(c *Control);
|
||||
func Margined(void) int;
|
||||
func SetMargined(margined int);
|
||||
};
|
||||
func NewGroup(text *const char) *Group;
|
||||
|
||||
// spinbox/slider rules:
|
||||
// setting value outside of range will automatically clamp
|
||||
// initial value is minimum
|
||||
// complaint if min >= max?
|
||||
|
||||
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);
|
||||
|
||||
};
|
Loading…
Reference in New Issue