Download
jcs
/amend
/commit_list.c
(View History)
jcs *: Lots of little fixes and dead variable removal | Latest amendment: 110 on 2023-02-06 |
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 "browser.h" |
21 | #include "repo.h" |
22 | #include "util.h" |
23 | |
24 | #define LIST_FONT geneva |
25 | #define LIST_FONT_SIZE 9 |
26 | |
27 | void amendment_list_draw_cell(ListHandle theList, Cell theCell, |
28 | short dataLen, Rect *cellRect, Boolean selected); |
29 | |
30 | pascal void |
31 | amendment_list_ldef(short message, Boolean selected, Rect *cellRect, |
32 | Cell theCell, short dataOffset, short dataLen, ListHandle theList) |
33 | { |
34 | switch (message) { |
35 | case 0: |
36 | /* init */ |
37 | break; |
38 | case 1: |
39 | /* update */ |
40 | /* FALLTHROUGH */ |
41 | case 2: |
42 | /* hilight */ |
43 | amendment_list_draw_cell(theList, theCell, dataLen, cellRect, |
44 | selected); |
45 | break; |
46 | case 3: |
47 | /* close */ |
48 | break; |
49 | } |
50 | } |
51 | |
52 | void |
53 | amendment_list_draw_cell(ListHandle theList, Cell theCell, short dataLen, |
54 | Rect *cellRect, Boolean selected) |
55 | { |
56 | Rect textRect; |
57 | char tmp[50]; |
58 | struct repo_amendment *amendment = NULL; |
59 | struct tm *ttm = NULL; |
60 | short len, height; |
61 | |
62 | LGetCell(&amendment, &dataLen, theCell, theList); |
63 | if (amendment == NULL) |
64 | /* XXX: why does this happen? */ |
65 | return; |
66 | |
67 | textRect.left = cellRect->left; |
68 | textRect.right = cellRect->right; |
69 | textRect.top = cellRect->top; |
70 | textRect.bottom = cellRect->bottom + 1; |
71 | EraseRect(&textRect); |
72 | InsetRect(&textRect, 4, 4); |
73 | |
74 | height = FontHeight(LIST_FONT, LIST_FONT_SIZE); |
75 | TextFace(bold); |
76 | TextFont(LIST_FONT); |
77 | TextSize(LIST_FONT_SIZE); |
78 | MoveTo(textRect.left, textRect.top + 6); |
79 | |
80 | HLock(amendment->log); |
81 | for (len = 1; len < amendment->log_len; len++) { |
82 | if ((*(amendment->log))[len - 1] == '\r') |
83 | break; |
84 | } |
85 | DrawText(*(amendment->log), 0, len); |
86 | HUnlock(amendment->log); |
87 | |
88 | ttm = localtime(&amendment->date); |
89 | snprintf(tmp, sizeof(tmp), "%04d-%02d-%02d %02d:%02d:%02d", |
90 | ttm->tm_year + 1900, ttm->tm_mon + 1, ttm->tm_mday, |
91 | ttm->tm_hour, ttm->tm_min, ttm->tm_sec); |
92 | MoveTo(textRect.left, textRect.top + height + 6); |
93 | TextFace(normal); |
94 | DrawText(tmp, 0, strlen(tmp)); |
95 | |
96 | MoveTo(textRect.left + 140, textRect.top + height + 6); |
97 | DrawText(amendment->author, 0, strlen(amendment->author)); |
98 | |
99 | snprintf(tmp, sizeof(tmp), "%d (+), %d (-)", |
100 | amendment->adds, amendment->subs); |
101 | MoveTo(textRect.left + 220, textRect.top + height + 6); |
102 | DrawText(tmp, 0, strlen(tmp)); |
103 | |
104 | if (selected) |
105 | InvertRect(cellRect); |
106 | } |