1 #include <intuition/intuition.h>
2 #include <libraries/gadtools.h>
3 #include <graphics/gfx.h>
4 #include <graphics/gfxmacros.h>
5 #include <aros/asmcall.h>
6 #include <proto/exec.h>
7 #include <proto/intuition.h>
8 #include <proto/graphics.h>
9 #include <proto/gadtools.h>
10 #include <proto/alib.h>
17 #define SHOW_CHECKMARK 1
18 #define SHOW_SELECTFILL 0
24 struct IntuitionBase
*IntuitionBase
;
25 struct GfxBase
*GfxBase
;
26 struct Library
*GadToolsBase
;
31 struct Gadget
*gadlist
, *gad
, *lvgad
;
33 struct Node lvnode
[LVENTRIES
];
35 struct Hook myrenderhook
;
38 #define IS_SELECTED(node) (node->ln_Pri == 1)
39 #define DO_SELECT(node) node->ln_Pri = 1
40 #define DO_UNSELECT(node) node->ln_Pri = 0
42 static void cleanup(char *msg
)
44 if(msg
) printf("gtmultiselect: %s\n", msg
);
46 if (win
) CloseWindow(win
);
47 if (gadlist
) FreeGadgets(gadlist
);
49 if (greenpen
!= -1) ReleasePen(scr
->ViewPort
.ColorMap
, greenpen
);
51 if (vi
) FreeVisualInfo(vi
);
52 if (dri
) FreeScreenDrawInfo(scr
, dri
);
53 if (scr
) UnlockPubScreen(0, scr
);
55 if (GadToolsBase
) CloseLibrary(GadToolsBase
);
56 if (GfxBase
) CloseLibrary((struct Library
*)GfxBase
);
57 if (IntuitionBase
) CloseLibrary((struct Library
*)IntuitionBase
);
62 static void openlibs(void)
64 if (!(IntuitionBase
= (struct IntuitionBase
*)OpenLibrary("intuition.library", 39)))
66 cleanup("Can't open intuition.library!");
69 if (!(GfxBase
= (struct GfxBase
*)OpenLibrary("graphics.library", 39)))
71 cleanup("Can't open graphics.library!");
74 if (!(GadToolsBase
= OpenLibrary("gadtools.library", 39)))
76 cleanup("Can't open gadtools.library!");
80 static void getvisual(void)
82 if (!(scr
= LockPubScreen(0))) cleanup("Can't lock pub screen!");
83 if (!(dri
= GetScreenDrawInfo(scr
))) cleanup("Can't get drawinfo!");
84 if (!(vi
= GetVisualInfoA(scr
, NULL
))) cleanup("Can' get visualinfo!");
86 greenpen
= ObtainBestPen(scr
->ViewPort
.ColorMap
, 0, 0x76767676, 0, OBP_FailIfBad
, FALSE
, TAG_DONE
);
90 AROS_UFH3(IPTR
, MyRenderFunc
,
91 AROS_UFHA(struct Hook
*, hook
, A0
),
92 AROS_UFHA(struct Node
*, node
, A2
),
93 AROS_UFHA(struct LVDrawMsg
*, msg
, A1
)
100 if (msg
->lvdm_MethodID
== LV_DRAW
)
102 struct DrawInfo
*dri
= msg
->lvdm_DrawInfo
;
103 struct RastPort
*rp
= msg
->lvdm_RastPort
;
104 struct TextExtent te
;
107 WORD min_x
= msg
->lvdm_Bounds
.MinX
;
108 WORD min_y
= msg
->lvdm_Bounds
.MinY
;
109 WORD max_x
= msg
->lvdm_Bounds
.MaxX
;
110 WORD max_y
= msg
->lvdm_Bounds
.MaxY
;
115 if (msg
->lvdm_State
== LVR_SELECTED
)
117 if (IS_SELECTED(node
))
128 erasepen
= IS_SELECTED(node
) ? FILLPEN
: BACKGROUNDPEN
;
130 erasepen
= BACKGROUNDPEN
;
135 SetAPen(rp
, dri
->dri_Pens
[erasepen
]);
136 RectFill(rp
, min_x
, min_y
, max_x
, max_y
);
139 numfit
= TextFit(rp
, node
->ln_Name
, strlen(node
->ln_Name
),
140 &te
, NULL
, 1, max_x
- min_x
+ 1 - 16, max_y
- min_y
+ 1);
142 numfit
= TextFit(rp
, node
->ln_Name
, strlen(node
->ln_Name
),
143 &te
, NULL
, 1, max_x
- min_x
+ 1, max_y
- min_y
+ 1);
146 SetAPen(rp
, dri
->dri_Pens
[TEXTPEN
]);
150 Move(rp
, min_x
+ 16, min_y
+ rp
->Font
->tf_Baseline
);
152 Move(rp
, min_x
, min_y
+ rp
->Font
->tf_Baseline
);
154 Text(rp
, node
->ln_Name
, numfit
);
157 if (IS_SELECTED(node
))
162 height
= max_y
- min_y
+ 1;
164 max_x
= min_x
+ width
- 1;
166 SetAPen(rp
, greenpen
);
167 Move(rp
, min_x
, min_y
+ height
/ 3); Draw(rp
, min_x
, max_y
);
168 Move(rp
, min_x
+ 1, min_y
+ height
/ 3); Draw(rp
, min_x
+ 1, max_y
);
170 SetAPen(rp
, dri
->dri_Pens
[SHADOWPEN
]);
171 Move(rp
, min_x
+ 2, min_y
+ height
/ 3); Draw(rp
, min_x
+ 2, max_y
);
173 SetAPen(rp
, greenpen
);
174 Move(rp
, min_x
+ 1, max_y
); Draw(rp
, max_x
- 1, min_y
);
175 Move(rp
, min_x
+ 2, max_y
); Draw(rp
, max_x
, min_y
);
177 SetAPen(rp
, dri
->dri_Pens
[SHADOWPEN
]);
178 Move(rp
, min_x
+ 3, max_y
); Draw(rp
, max_x
+ 1, min_y
);
187 retval
= LVCB_UNKNOWN
;
195 static void makegadgets(void)
200 gad
= CreateContext(&gadlist
);
202 memset(&ng
, 0, sizeof(ng
));
204 ng
.ng_VisualInfo
= vi
;
205 ng
.ng_LeftEdge
= scr
->WBorLeft
+ 4;
206 ng
.ng_TopEdge
= scr
->WBorTop
+ scr
->Font
->ta_YSize
+ 1 + 4;
207 ng
.ng_Width
= WINWIDTH
- scr
->WBorRight
- scr
->WBorLeft
- 8;
208 ng
.ng_Height
= WINHEIGHT
- scr
->WBorTop
- scr
->Font
->ta_YSize
- 1 - scr
->WBorBottom
- 8;
211 for(i
= 0; i
< LVENTRIES
; i
++)
215 sprintf(s
, "Item %d", i
);
217 lvnode
[i
].ln_Name
= strdup(s
);
218 AddTail(&lvlist
, &lvnode
[i
]);
222 struct TagItem lv_tags
[] =
224 {GTLV_Labels
, (IPTR
)&lvlist
},
225 {GTLV_CallBack
, (IPTR
)&myrenderhook
},
226 {GTLV_ItemHeight
, dri
->dri_Font
->tf_YSize
+ 4 },
230 myrenderhook
.h_Entry
= AROS_ASMSYMNAME(MyRenderFunc
);
232 gad
= lvgad
= CreateGadgetA(LISTVIEW_KIND
, gad
, &ng
, lv_tags
);
235 if (!gad
) cleanup("Can't create gadgets!");
238 static void makewin(void)
240 win
= OpenWindowTags(0, WA_PubScreen
, (IPTR
)scr
,
244 WA_Height
, WINHEIGHT
,
245 WA_Title
, (IPTR
)"GadTools MultiSelect Listview",
246 WA_CloseGadget
, TRUE
,
248 WA_DepthGadget
, TRUE
,
249 WA_IDCMP
, IDCMP_CLOSEWINDOW
| LISTVIEWIDCMP
,
251 WA_Gadgets
, (IPTR
)gadlist
,
255 if (!win
) cleanup("Can't create parent window!");
257 GT_RefreshWindow(win
, NULL
);
260 static void handleall(void)
262 struct IntuiMessage
*imsg
;
267 WaitPort(win
->UserPort
);
268 while((imsg
= GT_GetIMsg(win
->UserPort
)))
272 case IDCMP_CLOSEWINDOW
: