AmendHub

Download:

jcs

/

amend

/

amendments

/

49

util: Move ask() DITL into here to avoid the need for a resource


jcs made amendment 49 over 2 years ago
--- util.c Mon Jan 17 15:29:55 2022 +++ util.c Wed Jan 19 16:02:32 2022 @@ -40,6 +40,21 @@ static char alert_ditl[] = { }; static Handle alert_ditl_h = NULL; +/* DITL with a Yes button (1), No button (2), text (3), and icon (4) */ +static char ask_ditl[] = { + 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, + 0x00, 0xE6, 0x00, 0x5A, 0x01, 0x20, 0x04, 0x03, + 0x59, 0x65, 0x73, 0x21, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x46, 0x00, 0xA0, 0x00, 0x5A, 0x00, 0xDA, + 0x04, 0x02, 0x4E, 0x6F, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x0A, 0x00, 0x32, 0x00, 0x41, 0x01, 0x22, + 0x08, 0x02, 0x5E, 0x30, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x0A, 0x00, 0x0A, 0x00, 0x2A, 0x00, 0x2A, + 0xA0, 0x02, 0x00, 0x01 +}; +static Handle ask_ditl_h = NULL; + +/* DITL with just a text view */ static char progress_ditl[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x1E, 0x00, 0x32, 0x01, 0x3B, 0x08, 0x02, @@ -323,22 +338,49 @@ note(const char *format, ...) short ask(const char *format, ...) { - size_t len; - short ret; - WindowPtr win; + Rect bounds, irect; + short height, width, hit; + WindowPtr win, dialog; + OSType itype; + Handle ihandle; va_list ap; GetPort(&win); va_start(ap, format); - len = vsnprintf(err_str, ERROR_STRING_SIZE, format, ap); + vsnprintf(err_str, ERROR_STRING_SIZE, format, ap); va_end(ap); - ParamText(CtoPstr(err_str), "\p", "\p", "\p"); - ret = StopAlert(ASK_ALERT_ID, nil); + width = 300; + height = 100; + bounds.left = (screenBits.bounds.right - width) / 2; + bounds.right = bounds.left + width; + bounds.top = GetMBarHeight() + + ((screenBits.bounds.bottom - height) / 2.5); + bounds.bottom = bounds.top + height; + ParamText(CtoPstr(err_str), "\p", "\p", "\p"); + + ask_ditl_h = xNewHandle(sizeof(ask_ditl)); + HLock(ask_ditl_h); + memcpy(*ask_ditl_h, ask_ditl, sizeof(ask_ditl)); + HUnlock(ask_ditl_h); + + dialog = NewDialog(nil, &bounds, "\p", false, dBoxProc, + (WindowPtr)-1L, false, 0, ask_ditl_h); + + ShowWindow(dialog); + for (;;) { + ModalDialog(0, &hit); + if (hit == 1 || hit == 2) + break; + } + DisposDialog(dialog); + DisposHandle(alert_ditl_h); + SetPort(win); - return ret; + + return (hit == 1); } void