jcs
/wallops
/amendments
/36
main: Center connection dialog on the screen
jcs made amendment 36 over 2 years ago
--- main.c Tue Sep 6 13:36:23 2022
+++ main.c Tue Sep 6 16:30:52 2022
@@ -225,6 +225,7 @@ show_connect_dialog(void)
{
Str255 txt, server, ports, nick, ident, realname, channel, password;
StringHandle h;
+ DialogTHndl dlgh;
DialogPtr dlg;
Handle ihandle;
Rect irect;
@@ -232,9 +233,17 @@ show_connect_dialog(void)
long port;
short hit, itype, ret;
+ /* center dialog in screen */
+ dlgh = (DialogTHndl)xGetResource('DLOG', CONNECT_DLOG_ID);
+ HLock(dlgh);
+ center_in_screen((**dlgh).boundsRect.right - (**dlgh).boundsRect.left,
+ (**dlgh).boundsRect.bottom - (**dlgh).boundsRect.top,
+ true, &(**dlgh).boundsRect);
+ HUnlock(dlgh);
+
if ((dlg = GetNewDialog(CONNECT_DLOG_ID, nil, (WindowPtr)-1)) == NULL)
panic("Can't find connection DLOG %d", CONNECT_DLOG_ID);
-
+
for (n = 0; n < nitems(config_fields); n++) {
struct config_field *cf = &config_fields[n];
short sval;
@@ -276,6 +285,7 @@ get_input:
switch (hit) {
case -1:
DisposeDialog(dlg);
+ ReleaseResource(dlgh);
return;
case OK:
goto verify;
@@ -362,6 +372,7 @@ verify:
PasswordDialogFieldFinish();
DisposeDialog(dlg);
+ ReleaseResource(dlgh);
chatter_init((char *)&server, port, (char *)&password, (char *)&nick,
(char *)&ident, (char *)&realname, (char *)&channel);
--- util.c Tue Sep 6 12:34:51 2022
+++ util.c Tue Sep 6 15:57:57 2022
@@ -321,6 +321,7 @@ xstrndup(const char *str, size_t maxlen, char *note)
return copy;
}
+
/*
* String functions
*/
@@ -649,9 +650,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)
@@ -1200,12 +1216,14 @@ TEGetWidth(short off, TEHandle te)
#define ceildiv(a,b) ((a / b) + (!!(a % b)))
void
-UpdateScrollbarForTE(ControlHandle control, TEHandle te, bool reset)
+UpdateScrollbarForTE(GrafPtr win, ControlHandle control, TEHandle te, bool reset)
{
size_t vlines, telines;
TERec *ter;
+ RgnHandle rgn;
short fheight, fwidth, max, val, per_line, horiz, max_chars, n;
+ HLock(control);
HLock(te);
ter = *te;
@@ -1275,7 +1293,13 @@ UpdateScrollbarForTE(ControlHandle control, TEHandle t
(*control)->contrlMax = max;
SetCtlValue(control, val);
+ rgn = NewRgn();
+ RectRgn(rgn, &(*control)->contrlRect);
+ UpdtControl(win, rgn);
+ CloseRgn(rgn);
+
HUnlock(te);
+ HUnlock(control);
}
void
@@ -1665,7 +1689,7 @@ strsep(char **stringp, const char *delim)
}
return (NULL);
}
-
+
static struct format {
unsigned leftJustify : 1;
unsigned forceSign : 1;
--- util.h Tue Sep 6 12:34:32 2022
+++ util.h Tue Sep 6 15:53:02 2022
@@ -118,6 +118,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);
@@ -140,7 +141,8 @@ char * get_version(bool long_version);
short FontHeight(short font_id, short size);
void DrawGrowIconOnly(WindowPtr win);
short TEGetWidth(short off, TEHandle te);
-void UpdateScrollbarForTE(ControlHandle scroller, TEHandle te, bool reset);
+void UpdateScrollbarForTE(GrafPtr win, ControlHandle scroller, TEHandle te,
+ bool reset);
void SetTrackControlTE(TEHandle te);
pascal void TrackMouseDownInControl(ControlHandle control, short part);
pascal bool ModalDialogFilter(DialogPtr dlg, EventRecord *event,
@@ -160,6 +162,5 @@ char * strndup(const char *str, size_t maxlen);
char * strsep(char **stringp, const char *delim);
int snprintf(char *s, size_t size, const char *fmt, ...);
int vsnprintf(char *s, size_t size, const char *fmt, void *p);
-
#endif