Restructured the uiMenu type system. Will apply to the backends soon.

This commit is contained in:
Pietro Gagliardi 2015-04-20 23:35:26 -04:00
parent b45be6e5ab
commit a1e720bc05
4 changed files with 22 additions and 50 deletions

View File

@ -19,7 +19,6 @@ endif
CFILES = \ CFILES = \
box.c \ box.c \
menu.c \
test.c test.c
HFILES = \ HFILES = \
ui.h \ ui.h \

19
menu.c
View File

@ -1,19 +0,0 @@
// 20 april 2015
#include "uipriv.h"
#if 0
TODO
// dummy items for various predefined menu identifiers
// these are so we can get a definite unique pointer value
static volatile char dummyQuit = 'q';
static volatile char dummyPreferences = 'p';
static volatile char dummyAbout = 'a';
static volatile char dummySeparator = 's';
const char *const uiMenuItemQuit = &dummyQuit;
const char *const uiMenuItemPreferences = &dummyPreferences;
const char *const uiMenuItemAbout = &dummyAbout;
const char *const uiMenuItemSeparator = &dummySeparator;
#endif

32
test.c
View File

@ -6,26 +6,26 @@
// TODO convert to using the new conversion macros // TODO convert to using the new conversion macros
// TODO why can't these be const? // TODO why can't these be const?
static uiMenuItem fileMenu[] = { static const uiMenuItem fileMenu[] = {
{ "New", uiMenuItemTypeCommand }, { uiMenuItemTypeCommand, "New" },
{ "Open", uiMenuItemTypeCommand }, { uiMenuItemTypeCommand, "Open" },
{ uiMenuItemQuit, uiMenuItemTypeCommand }, { uiMenuItemTypeQuit, NULL },
{ NULL, 0 }, { 0, NULL },
}; };
static uiMenuItem editMenu[] = { static const uiMenuItem editMenu[] = {
{ "Undo", uiMenuItemTypeCommand }, { uiMenuItemTypeCommand, "Undo" },
{ uiMenuItemSeparator, uiMenuItemTypeSeparator }, { uiMenuItemTypeSeparator, NULL },
{ "Check Me", uiMenuItemTypeCheckbox }, { uiMenuItemTypeCheckbox, "Check Me" },
{ "A&ccelerator T_est", uiMenuItemTypeCommand }, { uiMenuItemTypeCommand, "A&ccelerator T_est" },
{ uiMenuItemPreferences, uiMenuItemTypeCommand }, { uiMenuItemTypePreferences, NULL },
{ NULL, 0 }, { 0, NULL },
}; };
static uiMenuItem helpMenu[] = { static const uiMenuItem helpMenu[] = {
{ "Help", uiMenuItemTypeCommand }, { uiMenuItemTypeCommand, "Help" },
{ uiMenuItemAbout, uiMenuItemTypeCommand }, { uiMenuItemTypeAbout, NULL },
{ NULL, 0 }, { 0, NULL },
}; };
static uiMenu menu[] = { static uiMenu menu[] = {

20
ui.idl
View File

@ -143,28 +143,20 @@ struct Menu {
}; };
struct MenuItem { struct MenuItem {
field Name *const char;
field Type MenuItemType; field Type MenuItemType;
field Name *const char;
}; };
enum MenuItemType { enum MenuItemType {
End, // Name must be NULL; specicfy this as 0
Command, Command,
Checkbox, Checkbox,
Separator, Quit, // Name must be NULL
Preferences, // Name must be NULL
About, // Name must be NULL
Separator, // Name must be NULL
}; };
// TODO allow these to be specified directly in the IDL
/* TODO
raw "extern const char *const uiMenuItemQuit;";
raw "extern const char *const uiMenuItemPreferences;";
raw "extern const char *const uiMenuItemAbout;";
raw "extern const char *const uiMenuItemSeparator;";
*/
raw "#define uiMenuItemQuit ((char *)1)";
raw "#define uiMenuItemPreferences ((char *)2)";
raw "#define uiMenuItemAbout ((char *)3)";
raw "#define uiMenuItemSeparator ((char *)4)";
raw "#endif"; raw "#endif";
}; };