This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
deb-goldedplus/golded3/geview.cpp

676 lines
18 KiB
C++
Raw Normal View History

2000-02-25 11:04:07 +00:00
// ------------------------------------------------------------------
// GoldED+
// Copyright (C) 1990-1999 Odinn Sorensen
// Copyright (C) 1999-2000 Alexander S. Aganichev
// ------------------------------------------------------------------
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston,
// MA 02111-1307 USA
// ------------------------------------------------------------------
// $Id$
// ------------------------------------------------------------------
// Message viewer class implementation.
// ------------------------------------------------------------------
2005-10-11 01:54:40 +00:00
#include <golded.h>
#include <gutlos.h>
#if defined(__USE_ALLOCA__)
#include <malloc.h>
#endif
2000-02-25 11:04:07 +00:00
// ------------------------------------------------------------------
GMsgHeaderView::GMsgHeaderView() {
alive = false;
at_row = at_column = width = height = 0;
border_type = gwindow::bordertype_none;
window_color = from_color = to_color = subject_color = BLUE|_LGREY;
location_color = BLUE|_LGREY;
2000-02-25 11:04:07 +00:00
title_color = highlight_color = RED|_LGREY;
border_color = YELLOW|_LGREY;
}
// ------------------------------------------------------------------
GMsgHeaderView::~GMsgHeaderView() {
Destroy();
}
// ------------------------------------------------------------------
void GMsgHeaderView::Create() {
alive = true;
window.openxy(
at_row,
at_column,
height,
width,
border_type,
border_color,
window_color
);
}
// ------------------------------------------------------------------
void GMsgHeaderView::Destroy() {
if(alive)
window.close();
else
alive = false;
}
// ------------------------------------------------------------------
void GMsgHeaderView::Use(Area *areaptr, GMsg *msgptr) {
area = areaptr;
msg = msgptr;
}
2000-02-25 11:04:07 +00:00
// ------------------------------------------------------------------
void GMsgHeaderView::Paint() {
2001-03-03 13:16:14 +00:00
ISub buf;
2000-02-25 11:04:07 +00:00
int namewidth = CFG->disphdrnodeset.pos - CFG->disphdrnameset.pos;
int nodewidth = CFG->disphdrdateset.pos - CFG->disphdrnodeset.pos;
2001-03-03 13:16:14 +00:00
int datewidth = MinV(width - CFG->disphdrdateset.pos, CFG->disphdrdateset.len);
2000-02-25 11:04:07 +00:00
2001-03-03 13:16:14 +00:00
#if defined(GUTLOS_FUNCS)
g_set_ostitle_name(struplow(strtmp(area->echoid())), 0);
#endif
2000-02-25 11:04:07 +00:00
// Generate top line fields
2001-03-03 13:16:14 +00:00
char buf1[16];
2000-02-25 11:04:07 +00:00
if((CFG->dispareano == ALWAYS) or (CFG->dispareano and area->board()))
2001-03-03 13:16:14 +00:00
sprintf(buf1, "[%u] ", area->board());
2000-02-25 11:04:07 +00:00
else
2001-03-03 13:16:14 +00:00
*buf1 = NUL;
2005-10-11 01:54:40 +00:00
#if defined(__USE_ALLOCA__)
char *top = (char*)alloca(width+1);
#else
2001-03-03 13:16:14 +00:00
__extension__ char top[width+1];
#endif
2001-03-03 13:16:14 +00:00
strxmerge(top, width+1, " ", buf1, strtrim(strtmp(area->desc())), " (",
area->isinternet() ? area->Internetaddress() : area->Aka().addr.make_string(buf),
") ", NULL);
int desclen = strlen(top);
window.printc(0, 0, border_color|ACSET, _box_table(W_BHEAD, 1));
window.prints(0, 1, title_color, top);
2000-02-25 11:04:07 +00:00
if(msg->areakludgeid)
2001-03-03 13:16:14 +00:00
strxmerge(top, width+1, " ", area->echoid(), " (", msg->areakludgeid, ") ", NULL);
2000-02-25 11:04:07 +00:00
else
2001-03-03 13:16:14 +00:00
strxmerge(top, width+1, " ", area->echoid(), " ", NULL);
2000-02-25 11:04:07 +00:00
2001-03-03 13:16:14 +00:00
int taglen = strlen(top);
2000-02-25 11:04:07 +00:00
2001-03-03 13:16:14 +00:00
if((width - (desclen + taglen + 2)) > 0)
window.fill(0, desclen+1, 0, width-(taglen+1)-1, _box_table(W_BHEAD, 1), border_color|ACSET);
window.prints(0, width-taglen-1, title_color, top);
window.printc(0, width-1, border_color|ACSET, _box_table(W_BHEAD, 1));
2000-02-25 11:04:07 +00:00
// Generate message attributes string
2001-03-03 13:16:14 +00:00
bool attrsgenerated = false;
MakeAttrStr(buf, width-CFG->disphdrnodeset.pos, &msg->attr);
if(*buf) {
attrsgenerated = true;
strsetsz(buf, width-CFG->disphdrnodeset.pos);
window.prints(1, CFG->disphdrnodeset.pos, window_color, buf);
2000-02-25 11:04:07 +00:00
}
// Generate message number and reply links string
2001-03-03 13:16:14 +00:00
char* ptr = buf;
2000-02-25 11:04:07 +00:00
int list_max = msg->link.list_max();
ulong* replies = (ulong*)throw_calloc(list_max+1, sizeof(ulong));
ulong replyto, replynext;
if(CFG->switches.get(disprealmsgno)) {
2005-10-07 12:41:11 +00:00
ptr += sprintf(ptr, " %-5.5s: #%u [%u]", LNG->Msg, msg->msgno, area->Msgn.Count()+(msg->attr.nwm() ? 1 : 0));
2000-02-25 11:04:07 +00:00
replyto = msg->link.to();
replies[0] = msg->link.first();
replynext = msg->link.next();
for(int replyn=1; replyn<list_max+1; replyn++)
replies[replyn] = msg->link.list(replyn-1);
}
else {
uint active = area->Msgn.Count() + (msg->attr.nwm() ? 1 : 0);
ptr += sprintf(ptr, " %-5.5s: %u %s %u", LNG->Msg, msg->attr.nwm() ? active : area->Msgn.ToReln(msg->msgno), LNG->of, active);
replyto = area->Msgn.ToReln(msg->link.to());
replies[0] = area->Msgn.ToReln(msg->link.first());
replynext = area->Msgn.ToReln(msg->link.next());
for(int replyn=1; replyn<list_max+1; replyn++)
replies[replyn] = area->Msgn.ToReln(msg->link.list(replyn-1));
}
if(replyto)
ptr += sprintf(ptr, " -%lu", replyto);
2001-03-03 13:16:14 +00:00
for(int replyn=0,plus=0; (replyn<(list_max+1)) and (not attrsgenerated or ((ptr-buf)<CFG->disphdrnodeset.pos)); replyn++)
2000-02-25 11:04:07 +00:00
if(replies[replyn])
ptr += sprintf(ptr, " %s%lu", (plus++?"":"+"), replies[replyn]);
2001-03-03 13:16:14 +00:00
if(replynext and (not attrsgenerated or ((ptr-buf)<CFG->disphdrnodeset.pos)))
2000-02-25 11:04:07 +00:00
sprintf(ptr, " *%lu", replynext);
2001-03-03 13:16:14 +00:00
throw_free(replies);
strsetsz(buf, attrsgenerated ? CFG->disphdrnodeset.pos : width);
window.prints(1, 0, window_color, buf);
// Get marks
if(area->bookmark == msg->msgno)
window.prints(1, 5, highlight_color, "\x11");
if(area->Mark.Count() and area->Mark.Find(msg->msgno))
window.prints(1, 7, highlight_color, "\x10");
// Generate from info
bool nodegenerated = false;
if(not area->isinternet()) {
if(area->isecho() or not (*msg->ifrom and (*msg->realby or *msg->iorig))) {
// Generate orig node data
if(msg->orig.net)
msg->orig.make_string(buf);
else
*buf = NUL;
nodegenerated = true;
strsetsz(buf, nodewidth);
window.prints(2, CFG->disphdrnodeset.pos, from_color, buf);
2000-02-25 11:04:07 +00:00
}
}
2001-03-03 20:35:09 +00:00
if((not area->isecho() or area->isnewsgroup()) and *msg->ifrom and *msg->realby)
2001-03-03 13:16:14 +00:00
strxmerge(buf, (namewidth+nodewidth), msg->realby, " <", msg->iorig, ">", NULL);
2001-03-03 20:35:09 +00:00
else if((not area->isecho() or area->isnewsgroup()) and *msg->ifrom and *msg->iorig)
2001-03-03 13:16:14 +00:00
strxcpy(buf, msg->iorig, (namewidth+nodewidth));
2000-02-25 11:04:07 +00:00
else
2001-03-03 13:16:14 +00:00
strxcpy(buf, msg->By(), (namewidth+nodewidth));
strsetsz(buf, nodegenerated ? namewidth : (namewidth+nodewidth));
2000-02-25 11:04:07 +00:00
2001-03-03 13:16:14 +00:00
window.prints(2, 0, window_color, LNG->From);
window.prints(2, CFG->disphdrnameset.pos, ((msg->foundwhere&GFIND_FROM) or msg->attr.fmu() or (msg->attr.loc() and CFG->switches.get(displocalhigh))) ? highlight_color : from_color, buf);
if(datewidth > 0) {
if(msg->written)
strftimei(buf, datewidth, LNG->DateTimeFmt, gmtime(&msg->written));
else
*buf = NUL;
strsetsz(buf, datewidth);
window.prints(2, CFG->disphdrdateset.pos, from_color, buf);
}
2000-02-25 11:04:07 +00:00
// Generate dest node data
2001-03-03 13:16:14 +00:00
nodegenerated = false;
if(not area->isinternet()) {
2001-03-03 20:35:09 +00:00
if(not (*msg->ito and (*msg->realto or *msg->idest))) {
2001-03-03 13:16:14 +00:00
if(msg->dest.net and area->isnet()) {
msg->dest.make_string(buf);
if(msg->odest.net) {
if((msg->odest.net != msg->dest.net) or (msg->odest.node != msg->dest.node)) {
sprintf(buf+strlen(buf), " %s %u/%u", LNG->Via, msg->odest.net, msg->odest.node);
}
}
nodegenerated = true;
strsetsz(buf, nodewidth);
window.prints(3, CFG->disphdrnodeset.pos, to_color, buf);
2000-02-25 11:04:07 +00:00
}
}
}
2001-03-03 20:35:09 +00:00
if((not area->isecho() or area->isnewsgroup()) and *msg->ito and *msg->realto)
2001-03-03 13:16:14 +00:00
strxmerge(buf, (namewidth+nodewidth), msg->realto, " <", msg->idest, ">", NULL);
2001-03-03 20:35:09 +00:00
else if((not area->isecho() or area->isnewsgroup()) and *msg->ito and *msg->idest)
2001-03-03 13:16:14 +00:00
strxcpy(buf, msg->idest, (namewidth+nodewidth));
else
strxcpy(buf, msg->To(), (namewidth+nodewidth));
strsetsz(buf, nodegenerated ? namewidth : (namewidth+nodewidth));
2000-02-25 11:04:07 +00:00
window.prints(3, 0, window_color, LNG->To);
2001-03-03 13:16:14 +00:00
window.prints(3, CFG->disphdrnameset.pos, ((msg->foundwhere&GFIND_TO) or msg->attr.tou()) ? highlight_color : to_color, buf);
if(datewidth > 0) {
if(msg->arrived)
strftimei(buf, datewidth, LNG->DateTimeFmt, gmtime(&msg->arrived));
else
*buf = NUL;
strsetsz(buf, datewidth);
window.prints(3, CFG->disphdrdateset.pos, to_color, buf);
2000-02-25 11:04:07 +00:00
}
2001-03-03 13:16:14 +00:00
// Generate subjectline
strxcpy(buf, (msg->attr.att() or msg->attr.frq() or msg->attr.urq()) ? LNG->File : LNG->Subj, 10);
int lngsubjlen = strlen(buf);
window.prints(4, 0, window_color, buf);
strxcpy(buf, msg->re, width-lngsubjlen);
strsetsz(buf, width-lngsubjlen);
window.prints(4, lngsubjlen, (msg->foundwhere&GFIND_SUBJECT) ? highlight_color : subject_color, buf);
// Generate bottom line
window.fill(5, 0, 5, width-1, _box_table(W_BHEAD, 1), border_color|ACSET);
2000-02-25 11:04:07 +00:00
// Calculate attach file sizes
if(msg->attr.att()) {
if(CFG->dispattachsize) {
char buf2[GMAXPATH];
int begpos = strlen(LNG->File);
strcpy(buf, msg->re);
char* ptr = strtok(buf, " ");
while(ptr) {
if(*ptr == '^')
ptr++;
2000-12-19 15:05:42 +00:00
if((isalpha(*ptr) and (ptr[1] == ':')) or (ptr[0] == '\\') or (ptr[0] == '/'))
2000-02-25 11:04:07 +00:00
strcpy(buf2, ptr);
else
sprintf(buf2, "%s%s", CFG->inboundpath, ptr);
long sz = GetFilesize(MapPath(buf2));
if(sz == -1)
2001-03-03 13:16:14 +00:00
sprintf(buf1, " %s ", LNG->n_a);
2000-02-25 11:04:07 +00:00
else {
switch(CFG->dispattachsize) {
case ATTACH_BYTES:
2001-03-03 13:16:14 +00:00
sprintf(buf1, " %li ", sz);
2000-02-25 11:04:07 +00:00
break;
case ATTACH_KBYTES:
2001-03-03 13:16:14 +00:00
sprintf(buf1, " %lik ", (sz+512L)/1024L);
2000-02-25 11:04:07 +00:00
break;
}
}
2001-03-03 13:16:14 +00:00
window.prints(5, begpos+int(ptr-buf)-1, title_color, buf1);
2000-02-25 11:04:07 +00:00
ptr = strtok(NULL, " ");
}
}
}
if(CFG->dispmsgsize and msg->txt and not _in_editor) {
uint len = strlen(msg->txt);
switch(CFG->dispmsgsize) {
case DISPMSGSIZE_BYTES:
2001-03-03 13:16:14 +00:00
sprintf(buf1, "%u", len);
2000-02-25 11:04:07 +00:00
break;
case DISPMSGSIZE_KBYTES:
2001-03-03 13:16:14 +00:00
sprintf(buf1, "%uk", (len+512)/1024);
2000-02-25 11:04:07 +00:00
break;
2001-03-03 13:16:14 +00:00
case DISPMSGSIZE_LINES:
sprintf(buf1, "%u", msg->lines);
2000-02-25 11:04:07 +00:00
break;
default:
2001-03-03 13:16:14 +00:00
*buf1 = NUL;
2000-02-25 11:04:07 +00:00
}
2001-03-03 13:16:14 +00:00
if(*buf1)
window.prints(5, 1, title_color, buf1);
2000-02-25 11:04:07 +00:00
}
if (CFG->disphdrlocation && !_in_editor)
{
std::string loc;
LookupNodeLocation(msg, loc, LOOK_CITY1);
if (loc.length()) loc = " " + loc;
if (AA->isnet())
{
std::string loc2;
LookupNodeLocation(msg, loc2, LOOK_CITY2);
if (loc.length()) loc += CFG->locationdelimiter + loc2;
}
if (loc.length())
{
loc += " ";
int pos = window.width() - loc.length() - 1;
window.prints(5, pos, location_color, loc.c_str());
}
}
2000-02-25 11:04:07 +00:00
}
// ------------------------------------------------------------------
GMsgBodyView::GMsgBodyView() {
alive = false;
scrollbar_visible = false;
at_row = at_column = width = height = visible_width = 0;
border_type = gwindow::bordertype_none;
window_color = BLACK|_LGREY;
highlight_color = WHITE|_RED;
scrollbar_color = DGREY|_LGREY;
border_color = YELLOW|_LGREY;
}
// ------------------------------------------------------------------
GMsgBodyView::~GMsgBodyView() {
Destroy();
}
// ------------------------------------------------------------------
void GMsgBodyView::Create() {
alive = true;
window.openxy(
at_row,
at_column,
height,
width,
border_type,
border_color,
window_color,
scrollbar_color
);
2000-03-22 17:59:18 +00:00
dummy_line.txt = "";
2000-02-25 11:04:07 +00:00
dummy_line.type = 0;
dummy_line.color = window_color;
visible_width = width - (CFG->switches.get(disppagebar) ? 1 : 0);
}
// ------------------------------------------------------------------
void GMsgBodyView::Destroy() {
if(alive)
window.close();
else
alive = false;
}
// ------------------------------------------------------------------
void GMsgBodyView::Use(Area *areaptr, GMsg *msgptr, int startline) {
area = areaptr;
msg = msgptr;
// Find the first highlighted line and go to it
if(msg->foundwhere & GFIND_BODY) {
for(startline=0; startline<msg->lines; startline++) {
if(msg->line[startline]->type & GLINE_HIGH)
break;
}
// Adjust position in window
startline -= height / 3;
if(startline < 0)
startline = 0;
else if((startline + height - 1) >= msg->lines)
startline = msg->lines - height;
}
if(startline >= msg->lines)
startline = msg->lines - 1;
if(startline < 0)
startline = 0;
upperline = startline;
lowerline = upperline + height - 1;
can_pagedown = lowerline < (msg->lines-1);
scrollbar_visible = CFG->switches.get(disppagebar) ? (msg->lines > height) : false;
visible_width = scrollbar_visible ? width-1 : width;
window.set_scrollbar_color(scrollbar_visible ? scrollbar_color : -1);
}
2000-02-25 11:04:07 +00:00
// ------------------------------------------------------------------
void GMsgBodyView::PaintLine(int row, Line *line) {
// Calculate effective coordinates for vputs
int vrow = gwin.active->srow + row;
2000-03-22 17:59:18 +00:00
uint llen = line->txt.length();
2000-02-25 11:04:07 +00:00
int color = (line->type & GLINE_HIGH) ? highlight_color : line->color;
// Trim line if it longer than should be. This actually happens in very rare
// cases, but always when hex dump displayed.
if(llen > visible_width) {
llen = visible_width;
2000-03-22 17:59:18 +00:00
line->txt.erase(llen);
2000-02-25 11:04:07 +00:00
}
// Print it
if(not SearchHighlight(line, vrow, visible_width, highlight_color)) {
2000-03-22 17:59:18 +00:00
if(line->type & GLINE_ORIG and strneql(line->txt.c_str(), " * Origin: ", 11)) {
2000-02-25 11:04:07 +00:00
vputs(vrow, 0, color, " * Origin: ");
StyleCodeHighlight(line->txt.c_str()+11, vrow, 11, not AA->attr().hex() and AA->adat->hidestylies, color);
2000-02-25 11:04:07 +00:00
}
else
StyleCodeHighlight(line->txt.c_str(), vrow, 0, not AA->attr().hex() and AA->adat->hidestylies, color);
int tlen = strlen(line->txt.c_str());
vputns(vrow, tlen, color, "", visible_width-tlen);
2000-02-25 11:04:07 +00:00
}
else
2000-03-22 17:59:18 +00:00
vputns(vrow, 0, color, line->txt.c_str(), visible_width);
2000-02-25 11:04:07 +00:00
}
// ------------------------------------------------------------------
void GMsgBodyView::Paint() {
window.activate_quick();
2000-02-25 11:04:07 +00:00
Line* dummy_index = NULL;
Line** line_index = msg->line ? (msg->line + upperline) : &dummy_index;
for(int row=0; row<height; row++)
PaintLine(row, *line_index ? *line_index++ : &dummy_line);
UpdateScrollbar();
}
// ------------------------------------------------------------------
int GMsgBodyView::Top(int redraw) {
if(redraw or (msg->lines > height)) {
can_pagedown = true;
upperline = 0;
lowerline = height - 1;
Paint();
return true;
}
2000-02-25 11:04:07 +00:00
return false;
}
// ------------------------------------------------------------------
int GMsgBodyView::Bottom() {
2000-02-25 11:04:07 +00:00
if(msg->lines > height) {
if(msg->lines <= height) {
can_pagedown = true;
upperline = 0;
}
else {
can_pagedown = false;
upperline = msg->lines - height;
}
lowerline = upperline + height - 1;
Paint();
return true;
}
2000-02-25 11:04:07 +00:00
return false;
}
// ------------------------------------------------------------------
int GMsgBodyView::PageUp() {
if(msg->lines > height) {
can_pagedown = true;
if(upperline) {
upperline -= height - 1;
if(upperline < 0)
upperline = 0;
lowerline = upperline + height - 1;
Paint();
return true;
}
}
2000-02-25 11:04:07 +00:00
return false;
}
// ------------------------------------------------------------------
int GMsgBodyView::PageDown() {
if(msg->lines > height) {
if(can_pagedown) {
if(lowerline < msg->lines-1) {
lowerline += height - 1;
if(lowerline >= msg->lines-1)
can_pagedown = false;
upperline = lowerline - height + 1;
Paint();
return true;
}
}
}
2000-02-25 11:04:07 +00:00
return false;
}
// ------------------------------------------------------------------
int GMsgBodyView::LineUp() {
2000-02-25 11:04:07 +00:00
if(msg->lines > height) {
if(upperline) {
window.scroll_down();
upperline--;
lowerline--;
#ifdef GOLD_MOUSE
gmou.HideCursor();
#endif
PaintLine(0, msg->line[upperline]);
#ifdef GOLD_MOUSE
gmou.ShowCursor();
#endif
can_pagedown = lowerline < (msg->lines-1);
UpdateScrollbar();
return true;
}
}
return false;
}
// ------------------------------------------------------------------
int GMsgBodyView::LineDown() {
if(msg->lines > height) {
if(lowerline < (msg->lines-1)) {
window.scroll_up();
upperline++;
lowerline++;
#ifdef GOLD_MOUSE
gmou.HideCursor();
#endif
PaintLine(height-1, msg->line[lowerline]);
#ifdef GOLD_MOUSE
gmou.ShowCursor();
#endif
can_pagedown = lowerline < (msg->lines-1);
UpdateScrollbar();
return true;
}
}
return false;
}
// ------------------------------------------------------------------
int GMsgBodyView::Continue() {
2000-02-25 11:04:07 +00:00
if(can_pagedown)
return PageDown();
2000-02-25 11:04:07 +00:00
return false;
}
// ------------------------------------------------------------------
int GMsgBodyView::ThumbTrack(int pos) {
return ThumbPosition(pos);
}
// ------------------------------------------------------------------
int GMsgBodyView::ThumbPosition(int pos) {
2000-02-25 11:04:07 +00:00
upperline = pos;
lowerline = upperline + height - 1;
can_pagedown = lowerline < (msg->lines-1);
Paint();
return true;
}
// ------------------------------------------------------------------
void GMsgBodyView::UpdateScrollbar() {
if(CFG->switches.get(disppagebar) and scrollbar_visible)
window.vscrollbar(msg->lines, msg->lines-height, upperline);
}
// ------------------------------------------------------------------
2000-06-16 23:30:48 +00:00
void GMsgBodyView::prints(int wrow, int wcol, int atr, const char* str) {
2000-02-25 11:04:07 +00:00
vputs(wrow, wcol, atr, str);
}
// ------------------------------------------------------------------