AmendHub

Download:

jcs

/

wikipedia

/

amendments

/

15

browser: Minor tweaks and fixes


jcs made amendment 15 over 2 years ago
--- browser.c Thu Aug 25 14:14:13 2022 +++ browser.c Thu Aug 25 15:58:37 2022 @@ -67,6 +67,15 @@ browser_idle(struct focusable *focusable, EventRecord input = xstrdup(*(te->hText), "browser te input"); HUnlock(te->hText); HUnlock(browser->input_te); + + HLock(browser->te); + te = *(browser->te); + if (te->teLength > 0) { + TESetText("", 0, browser->te); + InvalRect(&te->viewRect); + } + HUnlock(browser->te); + browser->wpr = wikipedia_fetch_article(browser, input); xfree(&input); browser->state = BROWSER_STATE_PROCESS_SEARCH; @@ -78,8 +87,16 @@ browser_idle(struct focusable *focusable, EventRecord break; } + SetCursor(*(GetCursor(watchCursor))); wikipedia_request_process(browser->wpr); break; + case BROWSER_STATE_SEARCH_DONE: + UpdateScrollbarForTE(browser->te_scroller, browser->te, false); + UpdtControl(browser->win, browser->win->visRgn); + progress(NULL); + SetCursor(&arrow); + browser->state = BROWSER_STATE_IDLE; + break; } } @@ -122,7 +139,7 @@ browser_init(void) bounds.top = PADDING; bounds.left = PADDING; bounds.right = browser->win->portRect.right - PADDING; - bounds.bottom = bounds.top + 18; + bounds.bottom = bounds.top + 16; te_bounds = bounds; InsetRect(&te_bounds, 2, 2); TextFont(geneva); @@ -392,18 +409,24 @@ browser_live_search(struct browser *browser) nresults = wikipedia_fetch_search_results(browser, input, &results); xfree(&input); - bounds.top = (*(browser->input_te))->viewRect.bottom + 1; - bounds.left = PADDING; - bounds.bottom = bounds.top + 70; - bounds.right = bounds.left + 200; + if (browser->search_results == NULL) { + bounds.top = (*(browser->input_te))->viewRect.bottom + 1; + bounds.left = PADDING; + bounds.bottom = bounds.top + 70; + bounds.right = bounds.left + + (((*(browser->input_te))->viewRect.right - + (*(browser->input_te))->viewRect.left) / 2); + + browser->search_results = LNew(&bounds, &data_bounds, cell_size, 0, + browser->win, false, false, false, true); + if (!browser->search_results) + panic("LNew failed"); + (*(browser->search_results))->selFlags = lOnlyOne; + LAddColumn(1, 0, browser->search_results); + } else { + LDelRow(0, 0, browser->search_results); + } - browser->search_results = LNew(&bounds, &data_bounds, cell_size, 0, - browser->win, false, false, false, true); - if (!browser->search_results) - panic("LNew failed"); - (*(browser->search_results))->selFlags = lOnlyOne; - LAddColumn(1, 0, browser->search_results); - for (n = 0; n < nresults; n++) { LAddRow(1, cell.v, browser->search_results); LSetCell(results[n], strlen(results[n]), cell, @@ -474,7 +497,7 @@ browser_print(struct browser *browser, const char *str RgnHandle savergn; Rect zerorect = { 0, 0, 0, 0 }; size_t n; - short line_height = 0; + short line_height = 0, was_len = 0; static unsigned short last_style = 0; if (scrp_rec_h == NULL) { @@ -564,6 +587,8 @@ te_overflow: DisposeRgn(savergn); no_overflow: + was_len = (*(browser->te))->teLength; + TESetSelect(SHRT_MAX, SHRT_MAX, browser->te); if ((last_style & STYLE_ITALIC) && !(style & STYLE_ITALIC)) TEStylInsert(" ", 1, scrp_rec_h, browser->te); @@ -571,9 +596,12 @@ no_overflow: progress(NULL); TEStylInsert(str, len, scrp_rec_h, browser->te); - SetCtlValue(browser->te_scroller, GetCtlMin(browser->te_scroller)); - UpdateScrollbarForTE(browser->te_scroller, browser->te, false); - UpdtControl(browser->win, browser->win->visRgn); + if (was_len == 0) { + SetCtlValue(browser->te_scroller, GetCtlMin(browser->te_scroller)); + UpdateScrollbarForTE(browser->te_scroller, browser->te, false); + UpdtControl(browser->win, browser->win->visRgn); + } + HUnlock(browser->te); last_style = style; --- browser.h Thu Aug 25 12:19:52 2022 +++ browser.h Thu Aug 25 15:57:24 2022 @@ -23,7 +23,8 @@ enum { BROWSER_STATE_IDLE, BROWSER_STATE_DO_SEARCH, - BROWSER_STATE_PROCESS_SEARCH + BROWSER_STATE_PROCESS_SEARCH, + BROWSER_STATE_SEARCH_DONE }; #define STYLE_BOLD (1 << 0) --- http.c Thu Aug 25 11:06:19 2022 +++ http.c Thu Aug 25 14:36:38 2022 @@ -147,7 +147,7 @@ http_get(const char *surl) req = xmalloczero(sizeof(struct http_request), "http_get"); req->url = url; - req->tcp_buf_size = (4 * 1500) + 1024; + req->tcp_buf_size = (4 * 1500) + sizeof(req->chunk); req->tcp_buf = xmalloc(req->tcp_buf_size, "http_get buf"); err = _TCPCreate(&req->tcp_iopb, &req->tcp_stream, (Ptr)req->tcp_buf, --- http.h Wed Aug 24 22:17:37 2022 +++ http.h Thu Aug 25 14:35:55 2022 @@ -40,7 +40,7 @@ struct http_request { char *message; - char chunk[1024]; + char chunk[2048]; size_t chunk_len; size_t chunk_off; };