| 1 |
/* |
| 2 |
* Copyright (c) 2021 joshua stein <jcs@jcs.org> |
| 3 |
* |
| 4 |
* Permission to use, copy, modify, and distribute this software for any |
| 5 |
* purpose with or without fee is hereby granted, provided that the above |
| 6 |
* copyright notice and this permission notice appear in all copies. |
| 7 |
* |
| 8 |
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 9 |
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 10 |
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 11 |
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 12 |
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 13 |
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 14 |
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 15 |
*/ |
| 16 |
|
| 17 |
#include <string.h> |
| 18 |
#include <stdio.h> |
| 19 |
#include <time.h> |
| 20 |
#include "amend.h" |
| 21 |
#include "browser.h" |
| 22 |
#include "repo.h" |
| 23 |
#include "util.h" |
| 24 |
|
| 25 |
void amendment_list_draw_cell(ListHandle theList, Cell theCell, |
| 26 |
short dataLen, Rect *cellRect, Boolean selected); |
| 27 |
|
| 28 |
pascal void |
| 29 |
amendment_list_ldef(short message, Boolean selected, Rect *cellRect, |
| 30 |
Cell theCell, short dataOffset, short dataLen, ListHandle theList) |
| 31 |
{ |
| 32 |
switch (message) { |
| 33 |
case 0: |
| 34 |
/* init */ |
| 35 |
break; |
| 36 |
case 1: |
| 37 |
/* update */ |
| 38 |
/* FALLTHROUGH */ |
| 39 |
case 2: |
| 40 |
/* hilight */ |
| 41 |
amendment_list_draw_cell(theList, theCell, dataLen, cellRect, |
| 42 |
selected); |
| 43 |
break; |
| 44 |
case 3: |
| 45 |
/* close */ |
| 46 |
break; |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
void |
| 51 |
amendment_list_draw_cell(ListHandle theList, Cell theCell, short dataLen, |
| 52 |
Rect *cellRect, Boolean selected) |
| 53 |
{ |
| 54 |
static char initial_load_text[] = |
| 55 |
"[ Click to load earlier amendments ]"; |
| 56 |
Rect textRect; |
| 57 |
char tmp[50]; |
| 58 |
struct repo_amendment *amendment = NULL; |
| 59 |
struct tm *ttm = NULL; |
| 60 |
short len, height, width; |
| 61 |
|
| 62 |
LGetCell(&amendment, &dataLen, theCell, theList); |
| 63 |
|
| 64 |
textRect.left = cellRect->left; |
| 65 |
textRect.right = cellRect->right; |
| 66 |
textRect.top = cellRect->top; |
| 67 |
textRect.bottom = cellRect->bottom + 1; |
| 68 |
EraseRect(&textRect); |
| 69 |
InsetRect(&textRect, 4, 4); |
| 70 |
|
| 71 |
height = FontHeight(AMENDMENT_LIST_FONT, AMENDMENT_LIST_FONT_SIZE); |
| 72 |
TextFace(bold); |
| 73 |
TextFont(AMENDMENT_LIST_FONT); |
| 74 |
TextSize(AMENDMENT_LIST_FONT_SIZE); |
| 75 |
MoveTo(textRect.left, textRect.top + 6); |
| 76 |
|
| 77 |
if (amendment == NULL) { |
| 78 |
TextFace(bold); |
| 79 |
width = TextWidth(&initial_load_text, 0, |
| 80 |
strlen(initial_load_text)); |
| 81 |
MoveTo(textRect.left + ((textRect.right - textRect.left) / 2) - |
| 82 |
(width / 2), textRect.top + 12); |
| 83 |
DrawText(&initial_load_text, 0, strlen(initial_load_text)); |
| 84 |
return; |
| 85 |
} |
| 86 |
|
| 87 |
HLock(amendment->log); |
| 88 |
for (len = 1; len < amendment->log_len; len++) { |
| 89 |
if ((*(amendment->log))[len - 1] == '\r') |
| 90 |
break; |
| 91 |
} |
| 92 |
DrawText(*(amendment->log), 0, len); |
| 93 |
HUnlock(amendment->log); |
| 94 |
|
| 95 |
ttm = localtime(&amendment->date); |
| 96 |
snprintf(tmp, sizeof(tmp), "%04d-%02d-%02d %02d:%02d:%02d", |
| 97 |
ttm->tm_year + 1900, ttm->tm_mon + 1, ttm->tm_mday, |
| 98 |
ttm->tm_hour, ttm->tm_min, ttm->tm_sec); |
| 99 |
MoveTo(textRect.left, textRect.top + height + 6); |
| 100 |
TextFace(normal); |
| 101 |
DrawText(tmp, 0, strlen(tmp)); |
| 102 |
|
| 103 |
MoveTo(textRect.left + 140, textRect.top + height + 6); |
| 104 |
DrawText(amendment->author, 0, strlen(amendment->author)); |
| 105 |
|
| 106 |
snprintf(tmp, sizeof(tmp), "%d (+), %d (-)", |
| 107 |
amendment->adds, amendment->subs); |
| 108 |
MoveTo(textRect.left + 220, textRect.top + height + 6); |
| 109 |
DrawText(tmp, 0, strlen(tmp)); |
| 110 |
|
| 111 |
if (selected) |
| 112 |
InvertRect(cellRect); |
| 113 |
} |