Added some basic messageboxes.

This commit is contained in:
Pietro Gagliardi 2015-05-23 15:07:16 -04:00
parent 13a4e3f4e5
commit bcad0080b2
3 changed files with 79 additions and 0 deletions

View File

@ -27,6 +27,30 @@ static void saveFile(uiButton *b, void *data)
}
}
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;
@ -49,5 +73,24 @@ uiBox *makePage5(void)
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;
}

View File

@ -207,5 +207,7 @@ interface MenuItem {
func OpenFile(void) *char;
func SaveFile(void) *char;
func MsgBox(title *const char, description *const char);
func MsgBoxError(title *const char, description *const char);
};

View File

@ -74,3 +74,37 @@ char *uiSaveFile(void)
endDialogHelper(dialogHelper);
return toUTF8(wfilename);
}
// TODO migrate to task dialogs when making Vista-only
static void msgbox(const char *title, const char *description, UINT flags)
{
WCHAR *wtitle, *wdescription;
WCHAR *wtext;
int n;
HWND dialogHelper;
wtitle = toUTF16(title);
wdescription = toUTF16(description);
n = _scwprintf(L"%s\n\n%s", wtitle, wdescription);
wtext = (WCHAR *) uiAlloc((n + 1) * sizeof (WCHAR), "WCHAR[]");
snwprintf(wtext, n + 1, L"%s\n\n%s", wtitle, wdescription);
dialogHelper = beginDialogHelper();
if (MessageBoxW(dialogHelper, wtext, NULL, flags) == 0)
logLastError("error showing message box in msgbox()");
endDialogHelper(dialogHelper);
uiFree(wtext);
uiFree(wdescription);
uiFree(wtitle);
}
void uiMsgBox(const char *title, const char *description)
{
msgbox(title, description, MB_OK);
}
void uiMsgBoxError(const char *title, const char *description)
{
msgbox(title, description, MB_OK | MB_ICONERROR);
}