home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Garbo
/
Garbo.cdr
/
mac
/
source
/
netnwscd.sit
/
CGroupList.c
< prev
next >
Wrap
Text File
|
1990-10-16
|
4KB
|
193 lines
/*
* CGroupList
*
* SUPERCLASS = CListWind
* Copyright ⌐ Tom Bereiter, 1990
*/
#include <Commands.h>
#include <CBartender.h>
#include "CArticleList.h"
#include "CGroupList.h"
#define WINDnogoaway 501 /* Resource ID for WIND template with no 'go away' */
#define cmdSubsGroups 1040L
#define cmdAllGroups 1041L
#define cmdAddGroup 1042L
#define cmdDelGroup 1043L
extern CBartender *gBartender;
extern short gClicks; /* Click counter, = 1 single click */
char subsmsg[]="Subscribed News Groups";
char allmsg[]="All News Groups";
void CGroupList::IGroupList(void)
{
CListWind::IListWind(WINDnogoaway, subsmsg, 80, 24);
ReDo();
}
void CGroupList::DoCommand(long theCommand)
{
Boolean wantActive = TRUE;
Boolean remove = FALSE;
bitmap_t *bm;
grp_t *gp;
char *msg;
int i;
switch (theCommand) {
case cmdSubsGroups:
wantActive = FALSE;
/* FALL THROUGH */
case cmdAllGroups:
if (allActive != wantActive) {
allActive = wantActive;
msg = allActive ? allmsg : subsmsg;
CtoPstr(msg);
itsWindow->SetTitle((StringPtr)msg);
PtoCstr(msg);
ReDo();
}
break;
case cmdDelGroup:
if (!allActive) {
bm = itsPane->GetSelect(nsgrps);
for (i=0,gp=grp_head; i<nsgrps; i++,gp=gp->next)
if (Btst(bm, i)) {
gp->flags = G_INACT;
rm_sgrp(gp);
itsPane->DelLine(i, 1);
}
DisposPtr(bm);
break;
}
remove = TRUE;
/* FALL THROUGH */
case cmdAddGroup:
bm = itsPane->GetSelect(ngrps);
for (i=0; i<ngrps; i++)
if (Btst(bm, i)) {
gp = &grps[i];
if (remove) {
gp->flags = G_INACT;
rm_sgrp(gp);
}
else {
gp->flags = G_SUB;
gp->subindex = 32000; /* a big number */
add_sgrp(gp);
}
ReDoLine(gp);
}
DisposPtr(bm);
break;
default:
inherited::DoCommand(theCommand);
break;
}
}
void CGroupList::UpdateMenus()
{
inherited::UpdateMenus();
gBartender->DisableCmd(cmdClose);
gBartender->EnableCmd(cmdSubsGroups);
gBartender->CheckMarkCmd(cmdSubsGroups, !allActive);
gBartender->EnableCmd(cmdAllGroups);
gBartender->CheckMarkCmd(cmdAllGroups, allActive);
if (allActive)
gBartender->EnableCmd(cmdAddGroup);
gBartender->EnableCmd(cmdDelGroup);
}
void CGroupList::Dawdle(long *maxSleep)
{
}
void CGroupList::ReDo()
{
grp_t *gp;
char buf[100];
int i;
Enab(0);
if (allActive) {
for (gp=grps; gp < &grps[ngrps]; gp++) {
mkgline(gp, TRUE, buf);
itsPane->AddLine(buf);
}
}
else {
for (gp=grp_head; gp; gp=gp->next) {
mkgline(gp, FALSE, buf);
itsPane->AddLine(buf);
}
}
Enab(1);
}
void CGroupList::ReDoLine(grp_t *line_gp)
{
grp_t *gp;
int n;
char buf[100];
if (allActive)
n = line_gp - grps;
else {
for (gp=grp_head,n=0; gp; gp=gp->next,n++)
if (gp == line_gp)
break;
}
mkgline(line_gp, allActive, buf);
itsPane->SetLine(n, buf);
}
mkgline(grp_t *gp, Boolean all, char *buf)
{
char c;
c = (all && (gp->flags & G_SUB)) ? '+' : ' ';
sprintf(buf,"%5ld %c %.90s", gp->unread, c, gp->gname);
}
void CGroupList::ClickLine(int line)
{
grp_t *gp;
int n;
CArticleList *al;
if (line < 0 || line >= ngrps)
return;
if (gClicks == 2 && lastclickline == line) {
if (allActive)
gp = &grps[line];
else {
for (gp=grp_head,n=0; gp; gp=gp->next,n++)
if (n == line)
break;
}
/* build article headers */
al = new(CArticleList);
al->IArticleList(this, gp);
al->TmpMsg("reading headings...");
igroup(gp);
ReDoLine(gp); /* may have changed */
al->ReDo();
}
lastclickline = line;
}