diff --git a/redo/test/page5.c b/redo/test/page5.c index 761c0e2a..b0e02a20 100644 --- a/redo/test/page5.c +++ b/redo/test/page5.c @@ -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; } diff --git a/redo/ui.idl b/redo/ui.idl index 3abe76c6..dee8bd39 100644 --- a/redo/ui.idl +++ b/redo/ui.idl @@ -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); }; diff --git a/redo/windows/stddialogs.c b/redo/windows/stddialogs.c index 88c6e540..f6f4a01b 100644 --- a/redo/windows/stddialogs.c +++ b/redo/windows/stddialogs.c @@ -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); +}