From 9f9032c2bbdc7b16657a035a77b9236e67006200 Mon Sep 17 00:00:00 2001 From: "Rich O." Date: Sun, 1 Nov 2026 15:19:50 -0500 Subject: [PATCH] palm-client: rowlist, a callback-drawn scrolling list for the new screens Fixed-height rows drawn by a callback in a gadget area with a scroll bar; section rows can be marked unselectable. Taps highlight like a Palm list and report the row; the hard up/down buttons and the scroll bar page it. Events are forwarded by the form rather than FrmSetGadgetHandler, so it doesn't depend on Palm OS 3.5's gadget extensions. --- palm-client/Makefile | 2 +- palm-client/src/ui/rowlist.c | 144 +++++++++++++++++++++++++++++++++++ palm-client/src/ui/rowlist.h | 43 +++++++++++ 3 files changed, 188 insertions(+), 1 deletion(-) create mode 100644 palm-client/src/ui/rowlist.c create mode 100644 palm-client/src/ui/rowlist.h diff --git a/palm-client/Makefile b/palm-client/Makefile index a3eeab7..0305967 100644 --- a/palm-client/Makefile +++ b/palm-client/Makefile @@ -10,7 +10,7 @@ APP = visormesh NAME = VisorMesh CREATOR = VMsh -SRCS = src/main.c src/protocol.c src/transport_srm.c src/session.c src/settings.c src/presets.c src/contacts.c src/contacts_form.c src/preview_form.c src/ui/draw.c src/ui/text.c src/ui/fontmetrics.c src/ports.c +SRCS = src/main.c src/protocol.c src/transport_srm.c src/session.c src/settings.c src/presets.c src/contacts.c src/contacts_form.c src/preview_form.c src/ui/draw.c src/ui/text.c src/ui/rowlist.c src/ui/fontmetrics.c src/ports.c OBJS = $(SRCS:src/%.c=build/%.o) CC = m68k-palmos-gcc diff --git a/palm-client/src/ui/rowlist.c b/palm-client/src/ui/rowlist.c new file mode 100644 index 0000000..250a5c9 --- /dev/null +++ b/palm-client/src/ui/rowlist.c @@ -0,0 +1,144 @@ +#include +#include "rowlist.h" + +static void GetBounds(const RowList *list, RectangleType *r) +{ + FormType *form = FrmGetActiveForm(); + + FrmGetObjectBounds(form, FrmGetObjectIndex(form, list->gadgetId), r); +} + +static UInt16 MaxTop(const RowList *list) +{ + UInt16 visible = RowListVisibleRows(list); + + return list->count > visible ? list->count - visible : 0; +} + +void RowListInit(RowList *list, UInt16 gadgetId, UInt16 scrollId, Coord rowH, + RowDrawFn draw, RowSelectableFn selectable, void *ctx) +{ + list->gadgetId = gadgetId; + list->scrollId = scrollId; + list->rowH = rowH; + list->count = 0; + list->top = 0; + list->draw = draw; + list->selectable = selectable; + list->ctx = ctx; +} + +UInt16 RowListVisibleRows(const RowList *list) +{ + RectangleType r; + + GetBounds(list, &r); + return (UInt16)(r.extent.y / list->rowH); +} + +void RowListSetCount(RowList *list, UInt16 count) +{ + list->count = count; + if (list->top > MaxTop(list)) + list->top = MaxTop(list); +} + +void RowListScrollTo(RowList *list, UInt16 top) +{ + list->top = top > MaxTop(list) ? MaxTop(list) : top; +} + +void RowListScrollToEnd(RowList *list) +{ + list->top = MaxTop(list); +} + +static void UpdateScrollBar(const RowList *list) +{ + FormType *form = FrmGetActiveForm(); + ScrollBarType *bar = FrmGetObjectPtr(form, FrmGetObjectIndex(form, list->scrollId)); + UInt16 visible = RowListVisibleRows(list); + + SclSetScrollBar(bar, (Int16)list->top, 0, (Int16)MaxTop(list), (Int16)(visible ? visible - 1 : 1)); +} + +void RowListDraw(RowList *list) +{ + RectangleType area, row; + UInt16 i, visible = RowListVisibleRows(list); + + GetBounds(list, &area); + WinEraseRectangle(&area, 0); + for (i = 0; i < visible && list->top + i < list->count; i++) { + RctSetRectangle(&row, area.topLeft.x, area.topLeft.y + i * list->rowH, area.extent.x, list->rowH); + list->draw(list->top + i, &row, list->ctx); + } + UpdateScrollBar(list); +} + +static void Scroll(RowList *list, Int16 delta) +{ + Int16 top = (Int16)list->top + delta; + + if (top < 0) + top = 0; + RowListScrollTo(list, (UInt16)top); + RowListDraw(list); +} + +Boolean RowListHandleEvent(RowList *list, EventType *event, Int16 *tapped) +{ + RectangleType area, rowR; + UInt16 row, visible; + Boolean penDown, inRow; + Coord x, y; + + switch (event->eType) { + case sclRepeatEvent: + if (event->data.sclRepeat.scrollBarID != list->scrollId) + return false; + list->top = (UInt16)event->data.sclRepeat.newValue; + RowListDraw(list); + return false; /* let the scroll bar keep tracking */ + + case keyDownEvent: + visible = RowListVisibleRows(list); + if (event->data.keyDown.chr == pageUpChr) { + Scroll(list, -(Int16)(visible > 1 ? visible - 1 : 1)); + return true; + } + if (event->data.keyDown.chr == pageDownChr) { + Scroll(list, (Int16)(visible > 1 ? visible - 1 : 1)); + return true; + } + return false; + + case penDownEvent: + GetBounds(list, &area); + if (!RctPtInRectangle(event->screenX, event->screenY, &area)) + return false; + row = list->top + (UInt16)((event->screenY - area.topLeft.y) / list->rowH); + if (row >= list->count || (list->selectable && !list->selectable(row, list->ctx))) + return true; + /* highlight while the pen is down on the row, like a Palm list */ + RctSetRectangle(&rowR, area.topLeft.x, area.topLeft.y + (row - list->top) * list->rowH, + area.extent.x, list->rowH); + WinInvertRectangle(&rowR, 0); + inRow = true; + do { + EvtGetPen(&x, &y, &penDown); + if (RctPtInRectangle(x, y, &rowR) != inRow) { + inRow = !inRow; + WinInvertRectangle(&rowR, 0); + } + } while (penDown); + if (inRow) { + WinInvertRectangle(&rowR, 0); + *tapped = (Int16)row; + } + return true; + + default: + return false; + } +} diff --git a/palm-client/src/ui/rowlist.h b/palm-client/src/ui/rowlist.h new file mode 100644 index 0000000..9b23dc3 --- /dev/null +++ b/palm-client/src/ui/rowlist.h @@ -0,0 +1,43 @@ +/* + * A scrolling list of fixed-height rows drawn by a callback, in a form's + * gadget area with a scroll bar beside it. Used by every list screen: rows + * can be section headers (not selectable) or items. The hard up/down buttons + * page it. The form forwards its events with RowListHandleEvent. + */ +#ifndef VM_ROWLIST_H +#define VM_ROWLIST_H + +#include + +typedef void (*RowDrawFn)(UInt16 row, const RectangleType *bounds, void *ctx); +typedef Boolean (*RowSelectableFn)(UInt16 row, void *ctx); + +typedef struct { + UInt16 gadgetId; + UInt16 scrollId; + Coord rowH; + UInt16 count; + UInt16 top; /* first visible row */ + RowDrawFn draw; + RowSelectableFn selectable; /* NULL = every row can be tapped */ + void *ctx; +} RowList; + +void RowListInit(RowList *list, UInt16 gadgetId, UInt16 scrollId, Coord rowH, + RowDrawFn draw, RowSelectableFn selectable, void *ctx); +/* Changes the row count, keeping the scroll position where it can. */ +void RowListSetCount(RowList *list, UInt16 count); +UInt16 RowListVisibleRows(const RowList *list); +void RowListScrollTo(RowList *list, UInt16 top); +void RowListScrollToEnd(RowList *list); +/* Redraws the visible rows and updates the scroll bar. */ +void RowListDraw(RowList *list); + +/* + * Handles pen taps in the list, scroll-bar moves and the page buttons. Returns + * true if it used the event; a tap on a selectable row also sets *tapped to the + * row (and returns true), otherwise *tapped is left alone. + */ +Boolean RowListHandleEvent(RowList *list, EventType *event, Int16 *tapped); + +#endif