jcs
/amend
/amendments
/97
util: Add a mechanism for centering SF{Get,Put}File dialogs
jcs made amendment 97 over 2 years ago
--- browser.c Tue Sep 6 14:12:25 2022
+++ browser.c Tue Sep 6 14:40:59 2022
@@ -420,7 +420,6 @@ void
browser_discard_changes(struct browser *browser)
{
char buf[256], filename[256];
- Point pt = { 75, 100 };
struct repo_file *file;
short *selected = NULL;
short nselected = 0, i, error;
@@ -436,7 +435,7 @@ browser_discard_changes(struct browser *browser)
strlcpy(filename, file->filename, sizeof(filename));
CtoPstr(filename);
- SFPutFile(pt, buf, filename, NULL, &reply);
+ SFPutFile(centered_sf_dialog(), buf, filename, NULL, &reply);
if (!reply.good)
break;
@@ -450,7 +449,6 @@ browser_discard_changes(struct browser *browser)
void
browser_export_patch(struct browser *browser)
{
- Point pt = { 75, 100 };
Cell selected = { 0 };
struct repo_amendment *amendment;
short error, len;
@@ -462,7 +460,7 @@ browser_export_patch(struct browser *browser)
len = sizeof(Ptr);
LGetCell(&amendment, &len, selected, browser->amendment_list);
- SFPutFile(pt, "\pSave patch as:", NULL, NULL, &reply);
+ SFPutFile(centered_sf_dialog(), "\pSave patch as:", NULL, NULL, &reply);
if (!reply.good)
return;
@@ -472,10 +470,9 @@ browser_export_patch(struct browser *browser)
void
browser_apply_patch(struct browser *browser)
{
- Point pt = { 75, 100 };
SFReply reply;
- SFGetFile(pt, NULL, NULL, -1, NULL, NULL, &reply);
+ SFGetFile(centered_sf_dialog(), NULL, NULL, -1, NULL, NULL, &reply);
if (!reply.good)
return;
--- repo.c Wed Aug 31 22:03:43 2022
+++ repo.c Tue Sep 6 14:42:10 2022
@@ -39,18 +39,18 @@ pascal Boolean repo_add_file_filter(struct FileParam *
struct repo *
repo_open(AppFile *file)
{
- Point pt = { 75, 100 };
SFReply reply;
SFTypeList types;
struct bile *bile;
-
+
if (file) {
reply.vRefNum = file->vRefNum;
memcpy(reply.fName, file->fName, sizeof(reply.fName));
} else {
types[0] = REPO_TYPE;
- SFGetFile(pt, NULL, NULL, 1, &types, NULL, &reply);
+ SFGetFile(centered_sf_dialog(), NULL, NULL, 1, &types,
+ NULL, &reply);
if (!reply.good)
return NULL;
}
@@ -76,12 +76,12 @@ repo_open(AppFile *file)
struct repo *
repo_create(void)
{
- Point pt = { 75, 100 };
SFReply reply;
struct bile *bile;
short error, fh, i;
- SFPutFile(pt, "\pCreate new repository:", "\p", NULL, &reply);
+ SFPutFile(centered_sf_dialog(), "\pCreate new repository:",
+ "\p", NULL, &reply);
if (!reply.good)
return NULL;
@@ -469,7 +469,6 @@ repo_add_file_filter(struct FileParam *pbp)
struct repo_file *
repo_add_file(struct repo *repo)
{
- Point pt = { 75, 100 };
CInfoPBRec pb;
WDPBRec wdir = { 0 };
SFReply reply;
@@ -492,7 +491,8 @@ repo_add_file(struct repo *repo)
repo_add_file_filter_repo = repo;
repo_add_file_filter_repo_dir = wdir.ioWDDirID;
- SFGetFile(pt, "\p", repo_add_file_filter, -1, 0, NULL, &reply);
+ SFGetFile(centered_sf_dialog(), "\p", repo_add_file_filter,
+ -1, 0, NULL, &reply);
if (!reply.good)
return NULL;
--- util.c Tue Sep 6 14:15:09 2022
+++ util.c Tue Sep 6 15:21:37 2022
@@ -628,9 +628,24 @@ center_in_screen(short width, short height, bool title
b->bottom = b->top + height;
}
+Point
+centered_sf_dialog(void)
+{
+ Point p;
+ Rect r;
+
+ center_in_screen(364, 216, false, &r);
+ p.h = r.left;
+ p.v = r.top;
+
+ return p;
+}
+
+
/*
* General Mac-specific non-GUI functions
*/
+
static unsigned long _xorshift_state = 0;
unsigned long
xorshift32(void)
--- util.h Tue Sep 6 14:11:43 2022
+++ util.h Tue Sep 6 14:40:32 2022
@@ -117,6 +117,7 @@ short ask(const char *format, ...);
void progress(char *format, ...);
void window_rect(WindowPtr win, Rect *ret);
void center_in_screen(short width, short height, bool titlebar, Rect *b);
+Point centered_sf_dialog(void);
Handle xNewHandle(size_t size);
Handle xGetResource(ResType type, short id);