AmendHub

Download:

jcs

/

subtext

/

amendments

/

59

settings: Add horizontal scrollbar to TextEdit, handle Cut/Copy/Paste


jcs made amendment 59 over 2 years ago
--- main.c Tue Jan 18 16:55:58 2022 +++ main.c Thu Jan 20 14:23:01 2022 @@ -32,7 +32,7 @@ struct db *db = NULL; struct focusable *cur_focusable = NULL; struct focusable *last_focusable = NULL; -void handle_menu(long menu_id); +short handle_menu(long menu_id); void update_menu(void); int @@ -102,9 +102,10 @@ main(void) case keyDown: case autoKey: key = event.message & charCodeMask; - if ((event.modifiers & cmdKey) != 0) - handle_menu(MenuKey(key)); - else if (cur_focusable && cur_focusable->key_down) + if ((event.modifiers & cmdKey) != 0 && + handle_menu(MenuKey(key)) == 1) + break; + if (cur_focusable && cur_focusable->key_down) cur_focusable->key_down(cur_focusable, &event); break; case mouseDown: @@ -136,6 +137,9 @@ main(void) last_focusable = fcur; } } + if (cur_focusable && cur_focusable->win == event_win && + cur_focusable->mouse_down) + cur_focusable->mouse_down(cur_focusable, &event); break; } break; @@ -182,9 +186,11 @@ main(void) return 0; } -void +short handle_menu(long menu_id) -{ +{ + short ret = 0; + switch (HiWord(menu_id)) { case APPLE_MENU_ID: switch (LoWord(menu_id)) { @@ -209,6 +215,8 @@ handle_menu(long menu_id) note("%s", vers_s); } else warnx("Can't find version number!"); + + ret = 1; break; } } @@ -217,9 +225,13 @@ handle_menu(long menu_id) switch (LoWord(menu_id)) { case FILE_MENU_QUIT_ID: quitting = 1; + ret = 1; break; } break; + case EDIT_MENU_ID: + /* let each focusable handle this */ + break; case BBS_MENU_ID: switch (LoWord(menu_id)) { case BBS_MENU_VIEWS_ID: @@ -232,10 +244,12 @@ handle_menu(long menu_id) console_init(); break; } + ret = 1; break; } HiliteMenu(0); + return ret; } void --- session.c Mon Jan 17 20:53:34 2022 +++ session.c Thu Jan 20 15:35:11 2022 @@ -492,7 +492,7 @@ login_bail: } #define EXPAND_TO_FIT(var, size, pos, len) { \ - if ((pos) >= ((size) - (len))) { \ + if (((pos) + (len)) >= (size)) { \ (size) += 1024; \ (var) = xrealloc((var), (size)); \ } \ @@ -572,7 +572,7 @@ session_load_view(struct session *session, short id, c { char curvar[64]; struct tm *now; - size_t retsize = 1024, retpos = 0; + size_t retsize, retpos; size_t vsize, vallen; short n, j, invar = 0, varlen = 0, valsize, count, pad; char *view; @@ -582,8 +582,10 @@ session_load_view(struct session *session, short id, c if (vsize == 0) return 0; + retsize = 0; retpos = 0; - + *ret = NULL; + for (n = 0; n < vsize; n++) { c = view[n]; --- settings.c Tue Jan 18 17:05:20 2022 +++ settings.c Fri Jan 21 14:53:22 2022 @@ -52,7 +52,9 @@ struct view_editor { WindowPtr win; size_t view_id; TEHandle te; - ControlHandle scroller; + ControlHandle vert_scroller; + ControlHandle horiz_scroller; + ControlHandle save_button; }; void view_editor_key_down(struct focusable *focusable, EventRecord *event); @@ -60,6 +62,7 @@ void view_editor_mouse_down(struct focusable *focusabl EventRecord *event); void view_editor_update(struct focusable *focusable, EventRecord *event); void view_editor_close(struct focusable *focusable, EventRecord *event); +void view_editor_save(struct focusable *focusable, EventRecord *event); void settings_edit(void) @@ -103,7 +106,7 @@ settings_edit(void) while (!done) { get_input: - ModalDialog(nil, &hit); + ModalDialog(ModalDialogFilter, &hit); switch (hit) { case OK: done = 1; @@ -167,17 +170,12 @@ view_editor_show(size_t id, char *title) struct view_editor *view_editor; Rect bounds, te_bounds; TextStyle style; - short width, height, fh, hit; + short width, height; size_t vsize; char *view = NULL; TEHandle te; short padding = 10; - bool done; - vsize = bile_read_alloc(db->bile, DB_TEXT_TYPE, id, &view); -// if (vsize == 0) -// return; - width = 480; height = 250; @@ -199,10 +197,20 @@ view_editor_show(size_t id, char *title) panic("Can't create window"); SetPort(view_editor->win); + /* add save button */ + TextFont(applFont); + TextSize(11); + bounds.left = view_editor->win->portRect.right - padding - 100; + bounds.right = bounds.left + 100; + bounds.bottom = view_editor->win->portRect.bottom - padding; + bounds.top = bounds.bottom - 20; + view_editor->save_button = NewControl(view_editor->win, &bounds, + "\pSave", true, 1, 1, 1, pushButProc, 0L); + + /* add text box */ + bounds.bottom = bounds.top - padding - SCROLLBAR_WIDTH; bounds.top = padding; bounds.left = padding; - fh = FontHeight(monaco, 9); - bounds.bottom = view_editor->win->portRect.bottom - padding; bounds.right = view_editor->win->portRect.right - SCROLLBAR_WIDTH - padding; te_bounds = bounds; @@ -214,18 +222,33 @@ view_editor_show(size_t id, char *title) style.tsSize = 9; TESetStyle(doFont | doSize, &style, false, view_editor->te); TEAutoView(true, view_editor->te); + TETabWidth = 8; TETabEnable(view_editor->te); + TEActivate(view_editor->te); - if (view) + vsize = bile_read_alloc(db->bile, DB_TEXT_TYPE, id, &view); + if (view) { + TESetText(view, vsize, view_editor->te); + HLock(view_editor->te); + InvalRect(&(*(view_editor->te))->viewRect); + HUnlock(view_editor->te); free(view); + } bounds.left = bounds.right; bounds.right += SCROLLBAR_WIDTH; bounds.bottom++; bounds.top--; - view_editor->scroller = NewControl(view_editor->win, &bounds, "\p", - true, 1, 1, 1, scrollBarProc, 0L); - + view_editor->vert_scroller = NewControl(view_editor->win, &bounds, + "\p", true, 1, 1, 1, scrollBarProc, 0L); + + bounds.left = (*(view_editor->te))->viewRect.left; + bounds.right = (*(view_editor->te))->viewRect.right; + bounds.top = (*(view_editor->te))->viewRect.bottom; + bounds.bottom = bounds.top + SCROLLBAR_WIDTH; + view_editor->horiz_scroller = NewControl(view_editor->win, &bounds, + "\p", true, 1, 1, 1, scrollBarProc, 0L); + focusable = xmalloczero(sizeof(struct focusable)); focusable->win = view_editor->win; focusable->cookie = view_editor; @@ -234,6 +257,11 @@ view_editor_show(size_t id, char *title) focusable->update = view_editor_update; focusable->close = view_editor_close; show_focusable(focusable); + + UpdateScrollbarForTE(view_editor->vert_scroller, view_editor->te, + false); + UpdateScrollbarForTE(view_editor->horiz_scroller, view_editor->te, + false); } void @@ -241,12 +269,27 @@ view_editor_key_down(struct focusable *focusable, Even { struct view_editor *view_editor = (struct view_editor *)focusable->cookie; - char k; + char k = (event->message & charCodeMask); - k = (event->message & charCodeMask); - TEKey(k, view_editor->te); - UpdateScrollbarForTE(view_editor->scroller, view_editor->te, + if ((event->modifiers & cmdKey) != 0) { + switch (k) { + case 'c': + TECut(view_editor->te); + break; + case 'v': + TEPaste(view_editor->te); + break; + case 'x': + TECut(view_editor->te); + break; + } + } else + TEKey(k, view_editor->te); + + UpdateScrollbarForTE(view_editor->vert_scroller, view_editor->te, false); + UpdateScrollbarForTE(view_editor->horiz_scroller, view_editor->te, + false); } void @@ -273,17 +316,20 @@ view_editor_mouse_down(struct focusable *focusable, Ev case inButton: TextFont(applFont); TextSize(11); - if (TrackControl(control, p, 0L)) - ; + if (TrackControl(control, p, 0L)) { + if (control == view_editor->save_button) + view_editor_save(focusable, NULL); + } break; case inUpButton: case inDownButton: case inPageUp: case inPageDown: - if (control == view_editor->scroller) - SetTrackControlTE(view_editor->te); - else + if (control != view_editor->vert_scroller && + control != view_editor->horiz_scroller) break; + + SetTrackControlTE(view_editor->te); TrackControl(control, p, TrackMouseDownInControl); break; case inThumb: @@ -293,9 +339,12 @@ view_editor_mouse_down(struct focusable *focusable, Ev adj = val - GetCtlValue(control); if (adj != 0) { val -= adj; - if (control == view_editor->scroller) + if (control == view_editor->vert_scroller) TEScroll(0, adj * TEGetHeight(0, 0, view_editor->te), view_editor->te); + else if (control == view_editor->horiz_scroller) + TEScroll(adj * TEGetWidth(0, view_editor->te), 0, + view_editor->te); SetCtlValue(control, val); } break; @@ -319,6 +368,26 @@ view_editor_update(struct focusable *focusable, EventR } void +view_editor_save(struct focusable *focusable, EventRecord *event) +{ + struct view_editor *view_editor = + (struct view_editor *)focusable->cookie; + size_t len, wlen; + + HLock(view_editor->te); + HLock((*(view_editor->te))->hText); + + len = (*(view_editor->te))->teLength; + wlen = bile_write(db->bile, DB_TEXT_TYPE, view_editor->view_id, + *(*(view_editor->te))->hText, len); + + HUnlock((*(view_editor->te))->hText); + HUnlock(view_editor->te); + + view_editor_close(focusable, event); +} + +void view_editor_close(struct focusable *focusable, EventRecord *event) { struct view_editor *view_editor = @@ -327,7 +396,8 @@ view_editor_close(struct focusable *focusable, EventRe close_focusable(focusable); DisposeWindow(view_editor->win); TEDispose(view_editor->te); - DisposHandle(view_editor->scroller); + DisposHandle(view_editor->vert_scroller); + DisposHandle(view_editor->horiz_scroller); free(focusable); free(view_editor); } --- subtext.h Tue Jan 18 16:55:36 2022 +++ subtext.h Fri Jan 21 14:53:33 2022 @@ -27,6 +27,11 @@ #define FILE_MENU_ID 129 #define FILE_MENU_QUIT_ID 1 +#define EDIT_MENU_ID 131 +#define EDIT_MENU_CUT_ID 1 +#define EDIT_MENU_COPY_ID 2 +#define EDIT_MENU_PASTE_ID 3 + #define BBS_MENU_ID 130 #define BBS_MENU_BOARDS_ID 1 #define BBS_MENU_FILES_ID 2