jcs
/subtext
/amendments
/288
logger: Add support for resizing window
This was the hard way of fixing the problem of clicking the scrollbar
down arrow and it not generating a mouse down event because it was
where the grow control is expected to be.
jcs made amendment 288 over 2 years ago
--- focusable.h Thu Apr 14 14:09:20 2022
+++ focusable.h Fri Nov 18 13:30:48 2022
@@ -28,6 +28,7 @@ struct focusable {
void (*update)(struct focusable *focusable, EventRecord *event);
void (*key_down)(struct focusable *focusable, EventRecord *event);
void (*mouse_down)(struct focusable *focusable, EventRecord *event);
+ void (*resize)(struct focusable *focusable, EventRecord *event);
bool (*menu)(struct focusable *focusable, short menu, short item);
void (*close)(struct focusable *focusable, EventRecord *event);
void (*suspend)(struct focusable *focusable, EventRecord *event);
--- logger.c Tue Oct 4 22:04:36 2022
+++ logger.c Fri Nov 18 14:18:20 2022
@@ -27,10 +27,11 @@ struct logger *logger = NULL;
void logger_layout(bool init, Rect *init_bounds);
void logger_key_down(struct focusable *focusable, EventRecord *event);
void logger_mouse_down(struct focusable *focusable, EventRecord *event);
+void logger_resize(struct focusable *focusable, EventRecord *event);
void logger_update(struct focusable *focusable, EventRecord *event);
void logger_resume(struct focusable *focusable, EventRecord *event);
bool logger_quit(struct focusable *focusable);
-void logger_flush_buffer(void);
+void logger_flush_buffer(bool force);
void
logger_init(void)
@@ -55,6 +56,7 @@ logger_init(void)
documentProc, (WindowPtr)-1L, false, 0);
if (!logger->win)
panic("Can't create logger window");
+ logger_update_title();
SetPort(logger->win);
@@ -70,6 +72,7 @@ logger_init(void)
focusable->win = logger->win;
focusable->cookie = logger;
focusable->mouse_down = logger_mouse_down;
+ focusable->resize = logger_resize;
focusable->update = logger_update;
focusable->quit = logger_quit;
focusable->resume = logger_resume;
@@ -77,6 +80,7 @@ logger_init(void)
logger->focusable = focusable;
DrawControls(logger->win);
+ DrawGrowIconOnly(logger->win);
}
void
@@ -91,8 +95,8 @@ logger_layout(bool init, Rect *init_bounds)
/* messages scrollbar */
bounds.top = -1;
- bounds.right = win_bounds.right - win_bounds.left;
- bounds.bottom = win_bounds.bottom - win_bounds.top;
+ bounds.right = win_bounds.right - win_bounds.left + 1;
+ bounds.bottom = win_bounds.bottom - win_bounds.top - 14;
bounds.left = bounds.right - SCROLLBAR_WIDTH;
if (init)
logger->messages_scroller = NewControl(logger->win, &bounds,
@@ -104,6 +108,7 @@ logger_layout(bool init, Rect *init_bounds)
bounds.right = (*(logger->messages_scroller))->contrlRect.left;
bounds.left = 0;
bounds.top = 0;
+ bounds.bottom = win_bounds.bottom - win_bounds.top;
if (init) {
inset_bounds = bounds;
InsetRect(&inset_bounds, 4, 4);
@@ -115,9 +120,14 @@ logger_layout(bool init, Rect *init_bounds)
InsetRect(&bounds, 4, 4);
(*(logger->messages_te))->destRect = bounds;
TECalText(logger->messages_te);
+ TEUpdate(&(*(logger->messages_te))->viewRect, logger->messages_te);
}
- InvalRect(logger->win->visRgn);
+ DrawControls(logger->win);
+ DrawGrowIconOnly(logger->win);
+
+ if (!init)
+ logger_flush_buffer(true);
}
void
@@ -164,6 +174,7 @@ logger_update(struct focusable *focusable, EventRecord
TEUpdate(&(*(logger->messages_te))->viewRect, logger->messages_te);
DrawControls(logger->win);
+ DrawGrowIconOnly(logger->win);
break;
case activateEvt:
if (event->modifiers & activeFlag) {
@@ -258,6 +269,25 @@ logger_mouse_down(struct focusable *focusable, EventRe
}
}
+void
+logger_resize(struct focusable *focusable, EventRecord *event)
+{
+ Rect bounds;
+ long newsize, width, height;
+
+ bounds.left = 100;
+ bounds.top = 100;
+ bounds.right = screenBits.bounds.right;
+ bounds.bottom = screenBits.bounds.bottom;
+
+ newsize = GrowWindow(focusable->win, event->where, &bounds);
+
+ height = HiWord(newsize);
+ width = LoWord(newsize);
+ SizeWindow(focusable->win, width, height, true);
+ logger_layout(false, NULL);
+}
+
size_t
logger_printf(const char *format, ...)
{
@@ -298,17 +328,17 @@ logger_vprintf(const char *format, va_list ap)
}
if (logger->buffered_logs_len + len > LOGGER_BUFFERED_LOG_SIZE)
- logger_flush_buffer();
+ logger_flush_buffer(false);
len = strlcat(logger->buffered_logs, buf, LOGGER_BUFFERED_LOG_SIZE);
logger->buffered_logs_len = MIN(len, LOGGER_BUFFERED_LOG_SIZE);
if (logger->autoflush)
- logger_flush_buffer();
+ logger_flush_buffer(false);
}
void
-logger_flush_buffer(void)
+logger_flush_buffer(bool force)
{
RgnHandle savergn;
Rect zerorect = { 0, 0, 0, 0 };
@@ -316,7 +346,7 @@ logger_flush_buffer(void)
short line_height = 0, new_lines = 1, n;
char *buf;
- if (!logger || logger->buffered_logs_len == 0)
+ if (!logger || (logger->buffered_logs_len == 0 && !force))
return;
for (n = 0; n < logger->buffered_logs_len; n++) {
--- main.c Wed Nov 9 09:58:42 2022
+++ main.c Fri Nov 18 14:24:04 2022
@@ -117,7 +117,7 @@ main(void)
telnet_init();
if (db->config.modem_port)
serial_init();
-
+
blanker_last_blank = Time;
while (!quitting) {
@@ -181,6 +181,15 @@ main(void)
case inDrag:
SelectWindow(event_win);
DragWindow(event_win, event.where, &screenBits.bounds);
+ break;
+ case inGrow:
+ found_focusable = find_focusable(event_win);
+ if (event_win != FrontWindow()) {
+ if (found_focusable)
+ show_focusable(found_focusable);
+ }
+ if (found_focusable && found_focusable->resize)
+ found_focusable->resize(found_focusable, &event);
break;
case inGoAway:
if (TrackGoAway(event_win, event.where)) {