home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Garbo
/
Garbo.cdr
/
mac
/
source
/
luschsrc.sit
/
list.c
< prev
next >
Wrap
Text File
|
1990-05-23
|
3KB
|
152 lines
/********************************************************************************
* list.c
*
* List Window Management Package
*
* Written by Paco Xander Nathan
* ⌐1990, Motorola Inc. Public domain source code.
********************************************************************************/
#include "applic.h"
#include "window.h"
#include "list.h"
#include "test.h"
#include "gnosis.h"
/* Create a new window info handle with a list item
*/
WindowPtr
ListWindow (windID, top, left, isActive)
register short windID;
register short top, left;
register Boolean isActive;
{
register WindowPtr theWindow;
register InfoPtr infoPtr;
register ListHandle listHdl;
static Rect cellBounds = { 0, 0, 1, 3 };
static Cell cellSize = { (FONTSIZE * 3 / 2), 40 };
static Cell theCell = { 0, 0 };
GrafPtr savePort;
if (theWindow = WindAllocate(windID, isActive)) {
GetPort(&savePort);
SetPort(theWindow);
/* Set the font attributes and create the List handle
*/
TextFont(FONTNUM);
TextSize(FONTSIZE);
TextFace(0);
TextMode(srcOr);
infoPtr = (InfoPtr) GetWRefCon(theWindow);
SetRect(&(infoPtr->offset), top, left, 20, 20);
infoPtr->kind = wkList;
if (listHdl = infoPtr->item.list = LNew(&(infoPtr->offset), &cellBounds, cellSize, 0, theWindow, TRUE, FALSE, FALSE, TRUE)) {
/* Place a prompt in the first cell
*/
HLock(listHdl);
(*listHdl)->selFlags |= lOnlyOne;
(*listHdl)->listFlags |= lDoVAutoScroll;
HUnlock(listHdl);
/* Finally, adjust the window rect dimensions
*/
ListAdjust(theWindow);
}
SetPort(savePort);
}
return theWindow;
}
/* Resize the list view rect for a list window
*/
void
ListAdjust (theWindow)
register WindowPtr theWindow;
{
register InfoPtr infoPtr = (InfoPtr) GetWRefCon(theWindow);
register Rect view;
GrafPtr savePort;
Cell cellSize;
GetPort(&savePort);
SetPort(theWindow);
/* Resize the list
*/
view = theWindow->portRect;
LSize(view.right - view.left - 15, view.bottom - view.top, infoPtr->item.list);
/* Reset the cell size
*/
SetPt(&cellSize, (view.right - view.left - 15) / 2, FONTSIZE * 3 / 2);
LCellSize(cellSize, infoPtr->item.list);
SetPort(savePort);
}
/* Draw an application window - switch on particular window to draw all the fancy
* bells and whistles
*/
void
ListDraw (theWindow, fullDraw)
register WindowPtr theWindow;
register Boolean fullDraw;
{
register InfoPtr infoPtr = (InfoPtr) GetWRefCon(theWindow);
register ListHandle listHdl = infoPtr->item.list;
if (fullDraw)
LUpdate(theWindow->visRgn, listHdl);
}
/* Handle a click inside a list window
*/
void
ListContent (theWindow, theMods, thePoint)
register WindowPtr theWindow;
register short theMods;
register Point thePoint;
{
register InfoPtr infoPtr = (InfoPtr) GetWRefCon(theWindow);
register ListHandle listHdl = infoPtr->item.list;
register Boolean dblClick;
register Rect *view;
register long last;
Cell theCell;
/* Let the ListMgr scroll, select, etc., and test for double click
*/
dblClick = LClick(thePoint, theMods, listHdl);
HLock(listHdl);
view = &((*listHdl)->rView);
HUnlock(listHdl);
/* Find out if its inside a cell
*/
if (PtInRect(thePoint, view)) {
last = LLastClick(listHdl);
theCell.v = HiWord(last);
theCell.h = LoWord(last);
if (theWindow == wPtrGnos)
GnosClick(theCell, dblClick);
}
else {
/* Possible scrolling, make sure to redraw non-ListMgr features
*/
InvalRect(view);
}
}