summaryrefslogtreecommitdiffstats
path: root/src/mac/kconfig/ldef.c
blob: 2b3569b1cf188a71a2edac1a3010e38c0db5144e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/*
 * Copyright 1991-1994 by The University of Texas at Austin
 * All rights reserved.
 *
 * For infomation contact:
 * Rick Watson
 * University of Texas
 * Computation Center, COM 1
 * Austin, TX 78712
 * r.watson@utexas.edu
 * 512-471-3241
 */

/*
 * LDEF to draw text with tabs to specific offsets
 *
 * The offset is set when a tab (9) is encountered.
 * The format is <tab>nnn; where nnn is the decimal offset 
 * from the beginning of the line.
 */
 
#include <Controls.h>
#include <Errors.h>
#include <Fonts.h>
#include <Lists.h>
#include <OSEvents.h>
#include <OSUtils.h>
#include <Packages.h>
#include <QuickDraw.h>
#include <String.h>
#include <Strings.h>
#include <SysEqu.h>
#include <Traps.h>
#include <ToolUtils.h>

/* constants for spacing */

#define kLeftOffset	2
#define kTopOffset	0
#define kIconSpace	2

/* prototypes */

void DrawSICN(Ptr theSICN,short left,short top,GrafPtr drawPort);

/* main LDEF entry point */

pascal void	main(short lMessage, Boolean lSelect, Rect *lRect, Cell lCell,
			     short lDataOffset, short lDataLen, ListHandle lHandle)
{
	FontInfo fontInfo;						/* font information (ascent/descent/etc) */
	ListPtr listPtr;						/* pointer to store dereferenced list */
	SignedByte hStateList, hStateCells;		/* state variables for HGetState/SetState */
	Ptr cellData;							/* points to start of cell data for list */
	short leftDraw,topDraw;					/* left/top offsets from topleft of cell */
	unsigned char *cp, *cp1, *lim;
	unsigned short w; 
	int savefont, savesize;
	GrafPtr current;
	
	#pragma unused (lCell)
	
	/* lock and dereference list mgr handles */
	
	GetPort(&current);
	savefont = current->txFont;
	savesize = current->txSize;
	TextFont(geneva);
	TextSize(9);

	hStateList = HGetState((Handle)lHandle);
	HLock((Handle)lHandle);
	listPtr = *lHandle;
	hStateCells = HGetState(listPtr->cells);
	HLock(listPtr->cells);
	cellData = *(listPtr->cells);
	
	switch (lMessage) {
	  case lInitMsg:
	  	/* we don't need any initialization */
	  	break;

	  case lDrawMsg:
		EraseRect(lRect);
		
	  	if (lDataLen > 0) {
	  	
	  		/* determine starting point for drawing */
	  		
	  		leftDraw =	lRect->left+listPtr->indent.h+kLeftOffset;
	  		/* topDraw =	lRect->top+listPtr->indent.v+kTopOffset; */
	  		topDraw =	lRect->top+kTopOffset;
	  			  		
			GetFontInfo(&fontInfo);

			/*
			 * break text at tabs, setting offset when a tab is encountered.
			 */
			cp = &cellData[lDataOffset];
			lim = &cellData[lDataOffset + lDataLen];
			cp1 = cp;
			w = 0;
			while (cp <= lim) {
				if ((*cp == 9) || (cp >= lim)) {			/* draw previous */
					MoveTo(leftDraw + w, topDraw + fontInfo.ascent);
					if (cp - cp1)
						DrawText(cp1, 0, cp - cp1);
				}
				if (cp >= lim)
					break;
				if (*cp++ == 9) {
					/*
					 * Decode offset
					 */
					w = 0;
					while (cp < lim) {
						if ((*cp >= '0') && (*cp <= '9')) {
							w *= 10;
							w += (*cp - '0');
						}
						if (*cp++ == ';')
							break;
					}
					cp1 = cp;
				}
			}
	  	}

		if (!lSelect)
	  		break;
		
	  case lHiliteMsg:
	  	/* do hilite color */
	  	BitClr((Ptr)HiliteMode,pHiliteBit);
	  	InvertRect(lRect);
	  	break;

	  case lCloseMsg:
	  	break;
	}
	
	TextFont(savefont);
	TextSize(savesize);

	HSetState(listPtr->cells, hStateCells);
	HSetState((Handle)lHandle, hStateList);
}

#ifdef notdef
/* this procedure draws a small icon using CopyBits */

void DrawSICN(Ptr theSICN,short left,short top,GrafPtr drawPort)
{
	BitMap iconMap;
	Rect destRect;

	iconMap.baseAddr = theSICN;
	iconMap.rowBytes = 2;
	SetRect(&iconMap.bounds,0,0,16,16);
	SetRect(&destRect,0,0,16,16);
	OffsetRect(&destRect,left,top);
	CopyBits(&iconMap,&drawPort->portBits,&iconMap.bounds,&destRect,
			srcCopy,nil);
}
#endif