2 ** $Id: ListViewHooks.c,v 1.3 2000/01/12 21:18:07 bernie Exp $
4 ** Copyright (C) 1996,97 Bernardo Innocenti
6 ** Use 4 chars wide TABs to read this file
8 ** Internal drawing and browsing hooks the listview class
11 #define USE_BUILTIN_MATH
12 #define INTUI_V36_NAMES_ONLY
14 #define CLIB_ALIB_PROTOS_H /* Avoid dupe defs of boopsi funcs */
16 #include <exec/types.h>
17 #include <intuition/intuition.h>
18 #include <intuition/intuitionbase.h>
19 #include <graphics/gfxbase.h>
20 #include <graphics/gfxmacros.h>
22 #include <proto/intuition.h>
23 #include <proto/graphics.h>
29 #define LV_GADTOOLS_STUFF
30 #include <gadgets/ListViewClass.h>
32 #include <CompilerSpecific.h>
33 #include <DebugMacros.h>
37 /* Definitions for builtin List hook */
39 APTR HOOKCALL ListGetItem(
40 REG(a0, struct Hook *hook),
41 REG(a1, struct Node *node),
42 REG(a2, struct lvGetItem *lvgi));
43 APTR HOOKCALL ListGetNext(
44 REG(a0, struct Hook *hook),
45 REG(a1, struct Node *node),
46 REG(a2, struct lvGetNext *lvgn));
47 APTR HOOKCALL ListGetPrev(
48 REG(a0, struct Hook *hook),
49 REG(a1, struct Node *node),
50 REG(a2, struct lvGetPrev *lvgp));
51 ULONG HOOKCALL ListStringDrawItem(
52 REG(a0, struct Hook *hook),
53 REG(a1, struct Node *node),
54 REG(a2, struct lvDrawItem *lvdi));
55 ULONG HOOKCALL ListImageDrawItem(
56 REG(a0, struct Hook *hook),
57 REG(a1, struct Node *node),
58 REG(a2, struct lvDrawItem *lvdi));
61 /* Definitions for builtin Array hook */
63 APTR HOOKCALL ArrayGetItem(
64 REG(a0, struct Hook *hook),
65 REG(a1, STRPTR *item),
66 REG(a2, struct lvGetItem *lvgi));
67 ULONG HOOKCALL StringDrawItem(
68 REG(a0, struct Hook *hook),
70 REG(a2, struct lvDrawItem *lvdi));
71 ULONG HOOKCALL ImageDrawItem(
72 REG(a0, struct Hook *hook),
73 REG(a1, struct Image *img),
74 REG(a2, struct lvDrawItem *lvdi));
78 APTR HOOKCALL ListGetItem(
79 UNUSED(REG(a0, struct Hook *hook)),
80 REG(a1, struct Node *node),
81 REG(a2, struct lvGetItem *lvg))
87 node = ((struct List *)(lvg->lvgi_Items))->lh_Head;
89 /* Warning: no sanity check is made against
90 * list being shorter than expected!
92 for (i = 0; i < lvg->lvgi_Number; i++)
94 ASSERT_VALID_PTR(node)
103 APTR HOOKCALL ListGetNext(
104 UNUSED(REG(a0, struct Hook *hook)),
105 REG(a1, struct Node *node),
106 UNUSED(REG(a2, struct lvGetItem *lvg)))
108 ASSERT_VALID_PTR(node)
109 ASSERT_VALID_PTR(lvg)
111 return (APTR)(node->ln_Succ->ln_Succ ? node->ln_Succ : NULL);
116 APTR HOOKCALL ListGetPrev(
117 UNUSED(REG(a0, struct Hook *hook)),
118 REG(a1, struct Node *node),
119 UNUSED(REG(a2, struct lvGetItem *lvg)))
121 ASSERT_VALID_PTR(node)
122 ASSERT_VALID_PTR(lvg)
124 return (APTR)(node->ln_Pred->ln_Pred ? node->ln_Pred : NULL);
129 ULONG HOOKCALL ListStringDrawItem(
130 REG(a0, struct Hook *hook),
131 REG(a1, struct Node *node),
132 REG(a2, struct lvDrawItem *lvdi))
134 ASSERT_VALID_PTR(node)
135 ASSERT_VALID_PTR(lvdi)
137 return StringDrawItem(hook, node->ln_Name, lvdi);
142 ULONG HOOKCALL ListImageDrawItem(
143 REG(a0, struct Hook *hook),
144 REG(a1, struct Node *node),
145 REG(a2, struct lvDrawItem *lvdi))
147 ASSERT_VALID_PTR(node)
148 ASSERT_VALID_PTR(lvdi)
150 return ImageDrawItem(hook, (struct Image *)node->ln_Name, lvdi);
155 APTR HOOKCALL ArrayGetItem(
156 UNUSED(REG(a0, struct Hook *hook)),
157 UNUSED(REG(a1, STRPTR *item)),
158 REG(a2, struct lvGetItem *lvg))
160 ASSERT_VALID_PTR(lvg)
161 ASSERT_VALID_PTR(lvg->lvgi_Items)
163 return (APTR)(((STRPTR *)lvg->lvgi_Items)[lvg->lvgi_Number]);
168 ULONG HOOKCALL StringDrawItem(
169 UNUSED(REG(a0, struct Hook *hook)),
171 REG(a2, struct lvDrawItem *lvdi))
176 ASSERT_VALID_PTR(lvdi)
177 rp = lvdi->lvdi_RastPort;
179 ASSERT_VALID_PTR_OR_NULL(str)
182 /* Move to the leftmost pixel of the rectangle
183 * to have the following RectFill() clear all the line
185 Move(rp, lvdi->lvdi_Bounds.MinX, 0);
188 struct TextExtent textent;
190 if (lvdi->lvdi_State == LVR_NORMAL)
192 SetABPenDrMd(rp, lvdi->lvdi_DrawInfo->dri_Pens[TEXTPEN],
193 lvdi->lvdi_DrawInfo->dri_Pens[BACKGROUNDPEN],
198 SetABPenDrMd(rp, lvdi->lvdi_DrawInfo->dri_Pens[FILLTEXTPEN],
199 lvdi->lvdi_DrawInfo->dri_Pens[FILLPEN],
203 Move(rp, lvdi->lvdi_Bounds.MinX, lvdi->lvdi_Bounds.MinY + rp->Font->tf_Baseline);
207 if (!(lvdi->lvdi_Flags & LVF_CLIPPED))
209 /* Calculate how much text will fit in the listview width */
210 len = TextFit(rp, str, len, &textent, NULL, 1,
211 lvdi->lvdi_Bounds.MaxX - lvdi->lvdi_Bounds.MinX + 1,
212 lvdi->lvdi_Bounds.MaxY - lvdi->lvdi_Bounds.MinY + 1);
217 /* Text() will move the pen X position to
218 * lvdi->lvdi_Bounds.MinX + textent.te_Width.
222 /* Now clear the rest of the row. rp->cp_x is updated by Text() to the
223 * next character to print.
225 SetAPen(rp, lvdi->lvdi_DrawInfo->dri_Pens[(lvdi->lvdi_State == LVR_NORMAL) ?
226 BACKGROUNDPEN : FILLPEN]);
227 RectFill(rp, rp->cp_x,
228 lvdi->lvdi_Bounds.MinY,
229 lvdi->lvdi_Bounds.MaxX,
230 lvdi->lvdi_Bounds.MaxY);
238 ULONG HOOKCALL ImageDrawItem(
239 UNUSED(REG(a0, struct Hook *hook)),
240 REG(a1, struct Image *img),
241 REG(a2, struct lvDrawItem *lvdi))
246 ASSERT_VALID_PTR_OR_NULL(img)
247 ASSERT_VALID_PTR(lvdi)
248 rp = lvdi->lvdi_RastPort;
252 /* Move to the leftmost pixel of the item rectangle
253 * to have the following RectFill() clear all the line
255 left = lvdi->lvdi_Bounds.MinX;
258 DrawImageState(rp, img,
259 lvdi->lvdi_Bounds.MinX, lvdi->lvdi_Bounds.MinY,
260 lvdi->lvdi_State, lvdi->lvdi_DrawInfo);
262 left = lvdi->lvdi_Bounds.MinX + img->Width;
265 /* Now clear the rest of the row. rp->cp_x is updated by Text() to the
266 * next character to print.
268 SetAPen(rp, lvdi->lvdi_DrawInfo->dri_Pens[(lvdi->lvdi_State == LVR_NORMAL) ?
269 BACKGROUNDPEN : FILLPEN]);
271 lvdi->lvdi_Bounds.MinY,
272 lvdi->lvdi_Bounds.MaxX,
273 lvdi->lvdi_Bounds.MaxY);