AmendHub

Download:

jcs

/

wifi_da

/

amendments

/

7

util: Add some DA-specific tweaks


jcs made amendment 7 about 1 year ago
--- util.c Wed Aug 30 18:01:45 2023 +++ util.c Fri Oct 20 20:53:42 2023 @@ -84,6 +84,8 @@ static DialogPtr progress_dialog = NULL; static TEHandle track_control_te = NULL; +static DCtlPtr _da_dce = NULL; + enum { STOP_ALERT, CAUTION_ALERT, @@ -99,8 +101,10 @@ void vwarn(short alert_func, const char *format, va_li */ void -util_init(void) +util_init(DCtlPtr da_dce) { + _da_dce = da_dce; + alert_ditl_h = xNewHandle(sizeof(alert_ditl)); if (alert_ditl_h == NULL) ExitToShell(); @@ -438,7 +442,7 @@ vwarn(short alert_func, const char *format, va_list ap ihandle = GetIcon(noteIcon); break; case APPICON_ALERT: - ihandle = GetResource('ICN#', APPICON_ICN_ID); + ihandle = GetResource('ICN#', OwnedResourceID(APPICON_ICN_ID)); if (ihandle) break; default: @@ -662,12 +666,21 @@ window_rect(WindowPtr win, Rect *ret) void center_in_screen(short width, short height, bool titlebar, Rect *b) { - b->left = ((screenBits.bounds.right - screenBits.bounds.left) / 2) - + GrafPtr tport; + Rect bounds; + + /* screenBits is not available from a DA */ + tport = (GrafPtr)NewPtr(sizeof(GrafPort)); + OpenPort(tport); + + b->left = ((tport->portRect.right - tport->portRect.left) / 2) - (width / 2); - b->top = ((screenBits.bounds.bottom - screenBits.bounds.top) / 2) - + b->top = ((tport->portRect.bottom - tport->portRect.top) / 2) - (height / 2) + (titlebar ? GetMBarHeight() : 0); b->right = b->left + width; b->bottom = b->top + height; + + ClosePort(tport); } Point @@ -697,6 +710,18 @@ centered_sfput_dialog(void) } /* + * DA-specific functions + */ +long +OwnedResourceID(long n) +{ + if (_da_dce) + return (0xc000 + ((~(_da_dce->dCtlRefNum)) << 5) + n); + + return n; +} + +/* * General Mac-specific non-GUI functions */ @@ -1702,7 +1727,7 @@ strndup(const char *str, size_t maxlen) ; len = (size_t)(cp - str); - copy = malloc(len + 1); + copy = NewPtr(len + 1); if (copy != NULL) { (void)memcpy(copy, str, len); copy[len] = '\0'; --- util.h Mon Mar 27 21:33:13 2023 +++ util.h Fri Oct 20 19:25:42 2023 @@ -78,7 +78,7 @@ struct stat { unsigned char st_flags; }; -void util_init(void); +void util_init(DCtlPtr da_dce); void * xmalloc(size_t); void xfree(void *ptrptr); @@ -98,6 +98,8 @@ const char * ordinal(unsigned short n); size_t rtrim(char *str, char *chars); long strpos_quoted(char *str, char c); char * OSTypeToString(OSType type); + +long OwnedResourceID(long n); unsigned long xorshift32(void);