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 <graphics/gfxbase.h>
19 #include <graphics/gfxmacros.h>
21 #include <proto/intuition.h>
22 #include <proto/graphics.h>
28 #include "CompilerSpecific.h"
31 #define LV_GADTOOLS_STUFF
32 #include "ListViewClass.h"
36 /* Definitions for builtin List hook */
38 APTR HOOKCALL ListGetItem (
39 REG(a0, struct Hook *hook),
40 REG(a1, struct Node *node),
41 REG(a2, struct lvGetItem *lvgi));
42 APTR HOOKCALL ListGetNext (
43 REG(a0, struct Hook *hook),
44 REG(a1, struct Node *node),
45 REG(a2, struct lvGetNext *lvgn));
46 APTR HOOKCALL ListGetPrev (
47 REG(a0, struct Hook *hook),
48 REG(a1, struct Node *node),
49 REG(a2, struct lvGetPrev *lvgp));
50 ULONG HOOKCALL ListStringDrawItem (
51 REG(a0, struct Hook *hook),
52 REG(a1, struct Node *node),
53 REG(a2, struct lvDrawItem *lvdi));
54 ULONG HOOKCALL ListImageDrawItem (
55 REG(a0, struct Hook *hook),
56 REG(a1, struct Node *node),
57 REG(a2, struct lvDrawItem *lvdi));
60 /* Definitions for builtin Array hook */
62 APTR HOOKCALL ArrayGetItem (
63 REG(a0, struct Hook *hook),
64 REG(a1, STRPTR *item),
65 REG(a2, struct lvGetItem *lvgi));
66 ULONG HOOKCALL StringDrawItem (
67 REG(a0, struct Hook *hook),
69 REG(a2, struct lvDrawItem *lvdi));
70 ULONG HOOKCALL ImageDrawItem (
71 REG(a0, struct Hook *hook),
72 REG(a1, struct Image *img),
73 REG(a2, struct lvDrawItem *lvdi));
77 APTR HOOKCALL ListGetItem (
78 REG(a0, struct Hook *hook),
79 REG(a1, struct Node *node),
80 REG(a2, struct lvGetItem *lvg))
86 node = ((struct List *)(lvg->lvgi_Items))->lh_Head;
88 /* Warning: no sanity check is made against
89 * list being shorter than expected!
91 for (i = 0; i < lvg->lvgi_Number; i++)
102 APTR HOOKCALL ListGetNext (
103 REG(a0, struct Hook *hook),
104 REG(a1, struct Node *node),
105 REG(a2, struct lvGetItem *lvg))
107 ASSERT_VALIDNO0(node)
110 return (APTR)(node->ln_Succ->ln_Succ ? node->ln_Succ : NULL);
115 APTR HOOKCALL ListGetPrev (
116 REG(a0, struct Hook *hook),
117 REG(a1, struct Node *node),
118 REG(a2, struct lvGetItem *lvg))
120 ASSERT_VALIDNO0(node)
123 return (APTR)(node->ln_Pred->ln_Pred ? node->ln_Pred : NULL);
128 ULONG HOOKCALL ListStringDrawItem (
129 REG(a0, struct Hook *hook),
130 REG(a1, struct Node *node),
131 REG(a2, struct lvDrawItem *lvdi))
133 ASSERT_VALIDNO0(node)
134 ASSERT_VALIDNO0(lvdi)
136 return StringDrawItem (hook, node->ln_Name, lvdi);
141 ULONG HOOKCALL ListImageDrawItem (
142 REG(a0, struct Hook *hook),
143 REG(a1, struct Node *node),
144 REG(a2, struct lvDrawItem *lvdi))
146 ASSERT_VALIDNO0(node)
147 ASSERT_VALIDNO0(lvdi)
149 return ImageDrawItem (hook, (struct Image *)node->ln_Name, lvdi);
154 APTR HOOKCALL ArrayGetItem (
155 REG(a0, struct Hook *hook),
156 REG(a1, STRPTR *item),
157 REG(a2, struct lvGetItem *lvg))
160 ASSERT_VALIDNO0(lvg->lvgi_Items)
162 return (APTR)(((STRPTR *)lvg->lvgi_Items)[lvg->lvgi_Number]);
167 ULONG HOOKCALL StringDrawItem (
168 REG(a0, struct Hook *hook),
170 REG(a2, struct lvDrawItem *lvdi))
175 ASSERT_VALIDNO0(lvdi)
176 rp = lvdi->lvdi_RastPort;
181 /* Move to the leftmost pixel of the rectangle
182 * to have the following RectFill() clear all the line
184 Move (rp, lvdi->lvdi_Bounds.MinX, 0);
187 struct TextExtent textent;
189 if (lvdi->lvdi_State == LVR_NORMAL)
192 if (GfxBase->LibNode.lib_Version < 39)
194 SetAPen (rp, lvdi->lvdi_DrawInfo->dri_Pens[TEXTPEN]);
195 SetBPen (rp, lvdi->lvdi_DrawInfo->dri_Pens[BACKGROUNDPEN]);
199 #endif /* !OS30_ONLY */
200 SetABPenDrMd (rp, lvdi->lvdi_DrawInfo->dri_Pens[TEXTPEN],
201 lvdi->lvdi_DrawInfo->dri_Pens[BACKGROUNDPEN],
207 if (GfxBase->LibNode.lib_Version < 39)
209 SetAPen (rp, lvdi->lvdi_DrawInfo->dri_Pens[FILLTEXTPEN]);
210 SetBPen (rp, lvdi->lvdi_DrawInfo->dri_Pens[FILLPEN]);
214 #endif /* !OS30_ONLY */
215 SetABPenDrMd (rp, lvdi->lvdi_DrawInfo->dri_Pens[FILLTEXTPEN],
216 lvdi->lvdi_DrawInfo->dri_Pens[FILLPEN],
220 Move (rp, lvdi->lvdi_Bounds.MinX, lvdi->lvdi_Bounds.MinY + rp->Font->tf_Baseline);
224 if (!(lvdi->lvdi_Flags & LVF_CLIPPED))
226 /* Calculate how much text will fit in the listview width */
227 len = TextFit (rp, str, len, &textent, NULL, 1,
228 lvdi->lvdi_Bounds.MaxX - lvdi->lvdi_Bounds.MinX + 1,
229 lvdi->lvdi_Bounds.MaxY - lvdi->lvdi_Bounds.MinY + 1);
234 /* Text() will move the pen X position to
235 * lvdi->lvdi_Bounds.MinX + textent.te_Width.
239 /* Now clear the rest of the row. rp->cp_x is updated by Text() to the
240 * next character to print.
242 SetAPen (rp, lvdi->lvdi_DrawInfo->dri_Pens[(lvdi->lvdi_State == LVR_NORMAL) ?
243 BACKGROUNDPEN : FILLPEN]);
244 RectFill (rp, rp->cp_x,
245 lvdi->lvdi_Bounds.MinY,
246 lvdi->lvdi_Bounds.MaxX,
247 lvdi->lvdi_Bounds.MaxY);
255 ULONG HOOKCALL ImageDrawItem (
256 REG(a0, struct Hook *hook),
257 REG(a1, struct Image *img),
258 REG(a2, struct lvDrawItem *lvdi))
264 ASSERT_VALIDNO0(lvdi)
265 rp = lvdi->lvdi_RastPort;
269 /* Move to the leftmost pixel of the item rectangle
270 * to have the following RectFill() clear all the line
272 left = lvdi->lvdi_Bounds.MinX;
275 DrawImageState (rp, img,
276 lvdi->lvdi_Bounds.MinX, lvdi->lvdi_Bounds.MinY,
277 lvdi->lvdi_State, lvdi->lvdi_DrawInfo);
279 left = lvdi->lvdi_Bounds.MinX + img->Width;
282 /* Now clear the rest of the row. rp->cp_x is updated by Text() to the
283 * next character to print.
285 SetAPen (rp, lvdi->lvdi_DrawInfo->dri_Pens[(lvdi->lvdi_State == LVR_NORMAL) ?
286 BACKGROUNDPEN : FILLPEN]);
288 lvdi->lvdi_Bounds.MinY,
289 lvdi->lvdi_Bounds.MaxX,
290 lvdi->lvdi_Bounds.MaxY);