jcs
/amend
/amendments
/100
util: Sync upstream, use new about box code
jcs made amendment 100 over 2 years ago
--- main.c Tue Sep 6 13:38:23 2022
+++ main.c Tue Sep 6 19:12:14 2022
@@ -205,30 +205,9 @@ handle_menu(long menu_id)
switch (menu) {
case APPLE_MENU_ID:
switch (item) {
- case APPLE_MENU_ABOUT_ID: {
- VersRecHndl vers;
- char vers_s[255];
- char short_vers[255] = { 0 };
- short vlen;
-
- if ((vers = (VersRecHndl)GetResource('vers', 1))) {
- /*
- * vers "long version string" is a pascal string after the
- * short version pascal string
- */
- HLock(vers);
- vlen = (*vers)->shortVersion[0];
- memcpy(short_vers, (*vers)->shortVersion + vlen + 1,
- sizeof((*vers)->shortVersion) - vlen - 1);
- PtoCstr(short_vers);
- snprintf(vers_s, sizeof(vers_s), "%s %s", PROGRAM_NAME,
- short_vers);
- ReleaseResource(vers);
- note("%s", vers_s);
- } else
- warnx("Can't find version number!");
+ case APPLE_MENU_ABOUT_ID:
+ about(PROGRAM_NAME);
break;
- }
default: {
Str255 da;
GrafPtr save_port;
--- util.c Tue Sep 6 15:57:57 2022
+++ util.c Tue Sep 6 19:08:22 2022
@@ -35,29 +35,31 @@
static char err_str[ERROR_STRING_SIZE];
/* basic DITL with an ok button (1), text area (2), and icon (3) */
+#define ALERT_DITL_OK 1
#define ALERT_DITL_ICON 3
static const char alert_ditl[] = {
- 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46,
- 0x00, 0xE6, 0x00, 0x5A, 0x01, 0x20, 0x04, 0x02,
- 0x4F, 0x4B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A,
- 0x00, 0x32, 0x00, 0x40, 0x01, 0x21, 0x08, 0x02,
- 0x5E, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A,
- 0x00, 0x0A, 0x00, 0x2A, 0x00, 0x2A, 0xA0, 0x02,
- 0x00, 0x02
+ 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4E,
+ 0x00, 0xFA, 0x00, 0x64, 0x01, 0x34, 0x04, 0x02,
+ 0x4F, 0x4B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0D,
+ 0x00, 0x4E, 0x00, 0x41, 0x01, 0x36, 0x08, 0x02,
+ 0x5E, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0D,
+ 0x00, 0x17, 0x00, 0x2D, 0x00, 0x37, 0xA0, 0x02,
+ 0x00, 0x01
};
static Handle alert_ditl_h = NULL;
+/* ICN# to show for APPICON_ALERT */
+#define APPICON_ICN_ID 128
+
/* DITL with a Yes button (1), No button (2), text (3), and icon (4) */
static const 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
+ 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4E,
+ 0x00, 0xFA, 0x00, 0x64, 0x01, 0x34, 0x04, 0x02,
+ 0x4F, 0x4B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0D,
+ 0x00, 0x4E, 0x00, 0x41, 0x01, 0x36, 0x08, 0x02,
+ 0x5E, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0D,
+ 0x00, 0x17, 0x00, 0x2D, 0x00, 0x37, 0xA0, 0x02,
+ 0x00, 0x01
};
static Handle ask_ditl_h = NULL;
@@ -75,7 +77,8 @@ static TEHandle track_control_te = NULL;
enum {
STOP_ALERT,
CAUTION_ALERT,
- NOTE_ALERT
+ NOTE_ALERT,
+ APPICON_ALERT
};
/*
@@ -440,21 +443,21 @@ void
vwarn(short alert_func, const char *format, va_list ap)
{
Rect bounds;
- short hit;
+ short hit, itype;
WindowPtr win, dialog;
-
+ Handle ihandle;
+ Rect irect;
+
GetPort(&win);
vsnprintf(err_str, ERROR_STRING_SIZE, format, ap);
ParamText(CtoPstr(err_str), "\p", "\p", "\p");
- center_in_screen(300, 100, false, &bounds);
+ center_in_screen(320, 110, false, &bounds);
dialog = NewDialog(nil, &bounds, "\p", false, dBoxProc,
(WindowPtr)-1L, false, 0, alert_ditl_h);
-#if 0
- /* XXX: why doesn't changing this work? */
GetDItem(dialog, ALERT_DITL_ICON, &itype, &ihandle, &irect);
switch (alert_func) {
case CAUTION_ALERT:
@@ -463,19 +466,23 @@ vwarn(short alert_func, const char *format, va_list ap
case NOTE_ALERT:
ihandle = GetIcon(noteIcon);
break;
+ case APPICON_ALERT:
+ ihandle = GetResource('ICN#', APPICON_ICN_ID);
+ if (ihandle)
+ break;
default:
ihandle = GetIcon(stopIcon);
}
- ihandle = GetIcon(cautionIcon);
SetDItem(dialog, ALERT_DITL_ICON, itype, ihandle, &irect);
-#endif
-
+
ShowWindow(dialog);
+
for (;;) {
ModalDialog(0, &hit);
if (hit == ok)
break;
}
+ ReleaseResource(ihandle);
DisposDialog(dialog);
/*
@@ -548,6 +555,16 @@ note(const char *format, ...)
va_end(ap);
}
+void
+appicon_note(const char *format, ...)
+{
+ va_list ap;
+
+ va_start(ap, format);
+ vwarn(APPICON_ALERT, format, ap);
+ va_end(ap);
+}
+
short
ask(const char *format, ...)
{
@@ -585,6 +602,38 @@ ask(const char *format, ...)
SetPort(win);
return (hit == 1);
+}
+
+void
+about(char *program_name)
+{
+ VersRecHndl vers;
+ char vers_s[255];
+ char short_vers[255] = { 0 };
+ short vlen, n;
+
+ if ((vers = (VersRecHndl)GetResource('vers', 1))) {
+ /*
+ * vers "long version string" is a pascal string after the
+ * short version pascal string
+ */
+ HLock(vers);
+ vlen = (*vers)->shortVersion[0];
+ memcpy(short_vers, (*vers)->shortVersion + vlen + 1,
+ sizeof((*vers)->shortVersion) - vlen - 1);
+ PtoCstr(short_vers);
+ snprintf(vers_s, sizeof(vers_s), "%s %s", program_name,
+ short_vers);
+ for (n = 0; n < sizeof(vers_s); n++) {
+ if (vers_s[n] == '©') {
+ vers_s[n - 1] = '\r';
+ break;
+ }
+ }
+ ReleaseResource(vers);
+ appicon_note("%s", vers_s);
+ } else
+ warnx("Can't find version number!");
}
void
--- util.h Tue Sep 6 15:53:02 2022
+++ util.h Tue Sep 6 19:12:28 2022
@@ -112,9 +112,11 @@ void err(short ret, const char *format, ...);
void warnx(const char *format, ...);
void warn(const char *format, ...);
void note(const char *format, ...);
+void appicon_note(const char *format, ...);
short ask(const char *format, ...);
#define ASK_YES 1
#define ASK_NO 2
+void about(char *program_name);
void progress(char *format, ...);
void window_rect(WindowPtr win, Rect *ret);
void center_in_screen(short width, short height, bool titlebar, Rect *b);