jcs
/wallops
/amendments
/3
util: Add gestalt_machine_type, fix ModalDialogFilter
jcs made amendment 3 over 2 years ago
--- util.c Tue Feb 1 12:57:23 2022
+++ util.c Wed Feb 2 09:29:51 2022
@@ -18,7 +18,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-
+#include <GestaltEqu.h>
#include "util.h"
/* ALRT resources */
@@ -847,6 +847,54 @@ FSReadLine(short frefnum, char *buf, size_t buflen)
/*
+ * Gestalt functions
+ */
+char *
+gestalt_machine_type(void)
+{
+ short error;
+ long resp;
+
+ error = Gestalt(gestaltMachineType, &resp);
+ if (error)
+ return NULL;
+ switch (resp) {
+ case gestaltClassic:
+ return "Macintosh 128K";
+ case gestaltMacXL:
+ return "Macintosh XL";
+ case gestaltMac512KE:
+ return "Macintosh 512Ke";
+ case gestaltMacPlus:
+ return "Macintosh Plus";
+ case gestaltMacSE:
+ return "Macintosh SE";
+ case gestaltMacII:
+ return "Macintosh II";
+ case gestaltMacIIx:
+ return "Macintosh IIx";
+ case gestaltMacIIcx:
+ return "Macintosh IIcx";
+ case gestaltMacSE030:
+ return "Macintosh SE/30";
+ case gestaltPortable:
+ return "Macintosh Portable";
+ case gestaltMacIIci:
+ return "Macintosh IIci";
+ case gestaltMacIIfx:
+ return "Macintosh IIfx";
+ case gestaltMacClassic:
+ return "Macintosh Classic";
+ case gestaltMacIIsi:
+ return "Macintosh IIsi";
+ case gestaltMacLC:
+ return "Macintosh LC";
+ }
+
+ return NULL;
+}
+
+/*
* General Mac-specific GUI functions
*/
@@ -981,7 +1029,13 @@ UpdateScrollbarForTE(ControlHandle control, TEHandle t
}
}
}
- SetCtlMax(control, max);
+
+ /*
+ * Avoid SetCtlMax because it will redraw and then SetCtlValue will
+ * redraw again, which can cause a jump if we're trying to keep the
+ * scrollbar position in the same place (like at the bottom).
+ */
+ (*control)->contrlMax = max;
SetCtlValue(control, val);
HUnlock(te);
@@ -1057,13 +1111,20 @@ TrackMouseDownInControl(ControlHandle control, short p
pascal bool
ModalDialogFilter(DialogPtr dlg, EventRecord *event, short *hit)
{
+ WindowPtr event_win;
+ short event_in;
char key;
switch (event->what) {
- case inGoAway:
- if (TrackGoAway(dlg, event->where)) {
- *hit = -1;
- return true;
+ case mouseDown:
+ event_in = FindWindow(event->where, &event_win);
+
+ switch (event_in) {
+ case inGoAway:
+ if (TrackGoAway(dlg, event->where)) {
+ *hit = -1;
+ return true;
+ }
}
break;
case keyDown:
--- util.h Sat Jan 29 16:52:36 2022
+++ util.h Wed Feb 2 09:19:50 2022
@@ -70,20 +70,20 @@ typedef struct stat {
unsigned char st_flags;
};
-void *xmalloc(size_t);
-void *xmalloczero(size_t);
-void *xcalloc(size_t, size_t);
-void *xrealloc(void *src, size_t size);
-void *xmallocarray(size_t nmemb, size_t size);
-void *xreallocarray(void *, size_t, size_t);
-char *xstrdup(const char *);
+void * xmalloc(size_t);
+void * xmalloczero(size_t);
+void * xcalloc(size_t, size_t);
+void * xrealloc(void *src, size_t size);
+void * xmallocarray(size_t nmemb, size_t size);
+void * xreallocarray(void *, size_t, size_t);
+char * xstrdup(const char *);
short getline(char *str, size_t len, char **ret);
size_t strlcpy(char *dst, const char *src, size_t dsize);
size_t strlcat(char *dst, const char *src, size_t dsize);
-const char *ordinal(unsigned short n);
+const char * ordinal(unsigned short n);
long strpos_quoted(char *str, char c);
-char *OSTypeToString(OSType type);
+char * OSTypeToString(OSType type);
unsigned long xorshift32(void);
@@ -100,18 +100,19 @@ void progress(char *format, ...);
Handle xNewHandle(size_t size);
Handle xGetResource(ResType type, short id);
StringHandle xGetString(short id);
-char *xGetStringAsChar(short id);
+char * xGetStringAsChar(short id);
long xGetStringAsLong(short id);
void xSetHandleSize(Handle h, Size s);
-short getpath(short vRefNum, Str255 fileName, Str255 *ret,
- bool include_file);
+short getpath(short vRefNum, Str255 fileName, Str255 *ret, bool include_file);
bool FIsDir(Str255 path);
short stat(char *path, struct stat *sb);
short FStat(Str255 path, struct stat *sb);
OSErr copy_file(Str255 source, Str255 dest, bool overwrite);
OSErr copy_file_contents(short source_ref, short dest_ref);
OSErr FSReadLine(short frefnum, char *buf, size_t buflen);
+
+char * gestalt_machine_type(void);
short FontHeight(short font_id, short size);
void DrawGrowIconOnly(WindowPtr win);