/* * Copyright (c) 2021 joshua stein * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include #include #include #include "amend.h" #include "browser.h" #include "repo.h" #include "util.h" void amendment_list_draw_cell(ListHandle theList, Cell theCell, short dataLen, Rect *cellRect, Boolean selected); pascal void amendment_list_ldef(short message, Boolean selected, Rect *cellRect, Cell theCell, short dataOffset, short dataLen, ListHandle theList) { switch (message) { case 0: /* init */ break; case 1: /* update */ /* FALLTHROUGH */ case 2: /* hilight */ amendment_list_draw_cell(theList, theCell, dataLen, cellRect, selected); break; case 3: /* close */ break; } } void amendment_list_draw_cell(ListHandle theList, Cell theCell, short dataLen, Rect *cellRect, Boolean selected) { static char initial_load_text[] = "[ Click to load earlier amendments ]"; Rect textRect; char tmp[50]; struct repo_amendment *amendment = NULL; struct tm *ttm = NULL; short len, height, width; LGetCell(&amendment, &dataLen, theCell, theList); textRect.left = cellRect->left; textRect.right = cellRect->right; textRect.top = cellRect->top; textRect.bottom = cellRect->bottom + 1; EraseRect(&textRect); InsetRect(&textRect, 4, 4); height = FontHeight(AMENDMENT_LIST_FONT, AMENDMENT_LIST_FONT_SIZE); TextFace(bold); TextFont(AMENDMENT_LIST_FONT); TextSize(AMENDMENT_LIST_FONT_SIZE); MoveTo(textRect.left, textRect.top + 6); if (amendment == NULL) { TextFace(bold); width = TextWidth(&initial_load_text, 0, strlen(initial_load_text)); MoveTo(textRect.left + ((textRect.right - textRect.left) / 2) - (width / 2), textRect.top + 12); DrawText(&initial_load_text, 0, strlen(initial_load_text)); return; } HLock(amendment->log); for (len = 1; len < amendment->log_len; len++) { if ((*(amendment->log))[len - 1] == '\r') break; } DrawText(*(amendment->log), 0, len); HUnlock(amendment->log); ttm = localtime(&amendment->date); snprintf(tmp, sizeof(tmp), "%04d-%02d-%02d %02d:%02d:%02d", ttm->tm_year + 1900, ttm->tm_mon + 1, ttm->tm_mday, ttm->tm_hour, ttm->tm_min, ttm->tm_sec); MoveTo(textRect.left, textRect.top + height + 6); TextFace(normal); DrawText(tmp, 0, strlen(tmp)); MoveTo(textRect.left + 140, textRect.top + height + 6); DrawText(amendment->author, 0, strlen(amendment->author)); snprintf(tmp, sizeof(tmp), "%d (+), %d (-)", amendment->adds, amendment->subs); MoveTo(textRect.left + 220, textRect.top + height + 6); DrawText(tmp, 0, strlen(tmp)); if (selected) InvertRect(cellRect); }