home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Garbo
/
Garbo.cdr
/
mac
/
source
/
netnwscd.sit
/
CListWind.c
< prev
next >
Wrap
Text File
|
1990-10-21
|
5KB
|
296 lines
/*
* CListWind
*
* SUPERCLASS = CDirector
* Copyright ⌐ Tom Bereiter, 1990
*/
#include <CApplication.h>
#include <CBartender.h>
#include <Commands.h>
#include <CDesktop.h>
#include <CColorWindow.h>
#include <CStaticText.h>
#include <CDecorator.h>
#include "CListWind.h"
#include "bits.h"
/*** Global Variables ***/
extern CApplication *gApplication; /* Application object */
extern CBartender *gBartender;
extern CDesktop *gDesktop; /* The visible Desktop */
extern RgnHandle gUtilRgn; /* Utility region */
extern CDecorator *gDecorator;
#define cmdSelectAll 1070L
/*
* IListWind
*
* Initialize a ListWInd object
*/
void CListWind::IListWind(
int windresid, char *title, int width, int length)
{
Rect margin;
FontInfo fi;
int h,v;
CDirector::IDirector(gApplication); /* Initialize superclass */
itsWindow = new(CColorWindow); /* Create the basic window */
itsWindow->IWindow(windresid, FALSE, gDesktop, this);
/* set sizes */
SetPort(itsWindow->macPort);
TextFont(monaco); /* adjust font so calculations work */
TextSize(9);
GetFontInfo(&fi);
h = (fi.widMax * width) + 15; /* width plus scroll width */
v = ((fi.ascent + fi.descent) * length) + 15; /* length plus scroll width */
itsWindow->ChangeSize(h,v);
itsPane = new(CLList);
itsGopher = itsPane;
itsPane->ILList(itsWindow, this, 0, 0, 0, 0, sizELASTIC, sizELASTIC);
itsPane->FitToEnclosure(TRUE, TRUE);
#ifdef MYCLASSMODS
gDecorator->PlaceNewWindow(itsWindow, FALSE);
#else
gDecorator->PlaceNewWindow(itsWindow);
#endif
CtoPstr(title);
itsWindow->SetTitle((StringPtr)title);
PtoCstr(title);
itsWindow->Select();
}
void CListWind::Dispose()
{
inherited::Dispose();
}
void CListWind::DoCommand(long theCommand)
{
switch (theCommand) {
case cmdSelectAll:
{
Cell theCell;
theCell.h = 0;
for (theCell.v=0; theCell.v < itsPane->nrows; theCell.v++)
LSetSelect(TRUE, theCell, itsPane->listH);
}
break;
default:
inherited::DoCommand(theCommand);
break;
}
}
void CListWind::UpdateMenus()
{
inherited::UpdateMenus();
gBartender->EnableCmd(cmdSelectAll);
}
void CListWind::ClickLine(int line)
{
}
void CListWind::Enab(Boolean enab)
{
LDoDraw(enab, itsPane->listH);
if (enab == 0) {
itsPane->nrows = 0;
LDelRow(0, 1, itsPane->listH);
}
else
itsPane->Refresh();
}
/*
* display a temporary message (i.e. won't be refreshed)
*/
void CListWind::TmpMsg(char *msg) {
Rect r;
itsPane->GetFrame(&r);
r.left += 10;
r.right -= 32;
r.top += 40;
r.bottom = r.top + 80;
itsPane->Prepare();
TextBox(msg, strlen(msg), &r, teJustLeft);
}
/* -------------- --------------- */
void CLList::ILList(
CView *anEnclosure,
CBureaucrat *aSupervisor,
short aWidth,
short aHeight,
short aHEncl,
short aVEncl,
SizingOption aHSizing,
SizingOption aVSizing)
{
Point cellpt;
WindowPtr w;
Rect r, db;
inherited::IPane(anEnclosure, aSupervisor, aWidth, aHeight,
aHEncl, aVEncl, aHSizing, aVSizing);
wantsClicks = TRUE;
cellpt.h = 0;
cellpt.v = 0;
SetRect(&db, 0,0, 1,0);
r = macPort->portRect;
r.right -= 15; /* room for scroll */
listH = LNew(&r, &db, cellpt, 0, macPort, FALSE,TRUE, TRUE,TRUE);
/* LAddColumn(1, 0, listH); */
LDoDraw(TRUE, listH);
}
void CLList::Dispose()
{
LDispose(listH);
inherited::Dispose();
}
void CLList::Draw(Rect *area)
{
RectRgn(gUtilRgn, area);
LUpdate(gUtilRgn, listH);
DrawGrowIcon(macPort);
}
void CLList::Activate()
{
inherited::Activate();
Prepare();
LActivate(TRUE, listH);
}
void CLList::Deactivate()
{
Prepare();
LActivate(FALSE, listH);
inherited::Deactivate();
}
void CLList::DoClick(
Point hitPt,
short modifierKeys,
long when)
{
Rect r;
long x;
extern pascal long LLastClick();
LClick(hitPt, modifierKeys, listH);
r = macPort->portRect;
if (hitPt.h < r.right - 16 && hitPt.v < r.bottom - 16) { /* within fields */
x = HiWord( LLastClick(listH) );
if (x >= 0)
((CListWind *)itsSupervisor)->ClickLine(x);
}
}
void CLList::DoKeyDown(
char theChar,
Byte keyCode,
EventRecord *macEvent)
{
switch(theChar) {
case '\b':
itsSupervisor->DoCommand(cmdClear);
break;
}
}
bitmap_t * CLList::GetSelect(long len)
{
bitmap_t *bm;
Cell theCell;
int i;
bm = bmalloc(len);
theCell.h = theCell.v = 0;
while (LGetSelect(TRUE, &theCell, listH) && theCell.v < len) {
Bset(bm, theCell.v);
theCell.v++;
}
return (bm);
}
void CLList::ChangeSize(
register Rect *delta, /* Movement for each side */
Boolean redraw) /* Redraw Pane or not? */
{
Rect r;
inherited::ChangeSize(delta, redraw);
r = macPort->portRect;
r.bottom -= 15;
r.right -= 15; /* room for scroll */
Prepare();
LSize(r.right-r.left, r.bottom-r.top, listH);
}
void CLList::AddLine(char *line)
{
Cell cellpt;
Prepare();
LAddRow(1, nrows, listH);
cellpt.h = 0;
cellpt.v = nrows++;
LSetCell(line, strlen(line), cellpt, listH);
}
void CLList::DelLine(int line, int count)
{
gDesktop->UpdateWindows(); /* hack to keep list display current */
Prepare();
LDelRow(count, line, listH);
nrows -= count;
}
void CLList::SetLine(int line, char *txt)
{
Cell cellpt;
gDesktop->UpdateWindows(); /* hack to keep list display current */
Prepare();
cellpt.h = 0;
cellpt.v = line;
LSetCell(txt, strlen(txt), cellpt, listH);
}
void CLList::SelectLine(int line)
{
Cell cellpt;
Prepare();
cellpt.h = 0;
cellpt.v = line;
if (cellpt.v >= nrows)
cellpt.v = nrows-1;
LSetSelect(TRUE, cellpt, listH);
}