49 |
c->items = 0; |
c->items = 0; |
50 |
c->ctrl = NULL; |
c->ctrl = NULL; |
51 |
c->hil = NULL; |
c->hil = NULL; |
52 |
|
c->ext_chkbox = 0; |
53 |
*ctx = c; |
*ctx = c; |
54 |
return 0; |
return 0; |
55 |
} /* listview_new */ |
} |
56 |
|
|
57 |
|
|
58 |
void |
void |
143 |
listview_add_item2 (listview_ctrl_t ctx, const char *text, void *magic) |
listview_add_item2 (listview_ctrl_t ctx, const char *text, void *magic) |
144 |
{ |
{ |
145 |
int rc = 0; |
int rc = 0; |
146 |
LV_ITEM lvi; |
LVITEM lvi; |
147 |
|
|
148 |
memset( &lvi, 0, sizeof lvi ); |
memset (&lvi, 0, sizeof (lvi)); |
149 |
lvi.mask = LVIF_TEXT | LVIF_PARAM; |
lvi.mask = LVIF_TEXT | LVIF_PARAM; |
150 |
lvi.pszText = (char *)text; |
lvi.pszText = (char *)text; |
151 |
lvi.lParam = (LPARAM)magic; |
lvi.lParam = (LPARAM)magic; |
152 |
rc = ListView_InsertItem( ctx->ctrl, &lvi ); |
rc = ListView_InsertItem (ctx->ctrl, &lvi); |
153 |
if( rc == -1 ) |
if (rc == -1) |
154 |
rc = 1; |
rc = 1; |
155 |
ctx->items++; |
ctx->items++; |
156 |
return rc; |
return rc; |
210 |
} |
} |
211 |
|
|
212 |
|
|
213 |
|
/* Delete a single item from @ctx at position @pos. */ |
214 |
int |
int |
215 |
listview_del_item( listview_ctrl_t ctx, int pos ) |
listview_del_item (listview_ctrl_t ctx, int pos) |
216 |
{ |
{ |
217 |
int rc = 0; |
int rc = 0; |
218 |
|
|
219 |
if( ListView_DeleteItem( ctx->ctrl, pos ) == -1 ) |
if (ListView_DeleteItem (ctx->ctrl, pos) == -1) |
220 |
rc = 1; |
rc = 1; |
221 |
return rc; |
return rc; |
222 |
} /* listview_del_item */ |
} |
223 |
|
|
224 |
|
|
225 |
|
/* Delete all selected items in @ctx. */ |
226 |
int |
int |
227 |
listview_del_items( listview_ctrl_t ctx ) |
listview_del_sel_items (listview_ctrl_t ctx) |
228 |
{ |
{ |
229 |
int i, n; |
int i, n; |
230 |
|
|
|
/* delete all selected entries */ |
|
231 |
n = listview_count_items (ctx, 0); |
n = listview_count_items (ctx, 0); |
232 |
for( i = n; i > 0; i-- ) { |
for (i = n; i > -1; i--) { |
233 |
if ( listview_get_item_state( ctx, i ) ) |
if (listview_get_item_state (ctx, i)) |
234 |
listview_del_item( ctx, i ); |
listview_del_item (ctx, i); |
235 |
} |
} |
236 |
return 0; |
return 0; |
237 |
} /* listview_del_items */ |
} |
238 |
|
|
239 |
|
|
240 |
int |
int |
241 |
listview_del_all( listview_ctrl_t ctx ) |
listview_del_all_items (listview_ctrl_t ctx) |
242 |
{ |
{ |
243 |
int rc = 0; |
int rc = 0; |
244 |
|
|
245 |
if( ListView_DeleteAllItems( ctx->ctrl ) == FALSE ) |
if (ListView_DeleteAllItems (ctx->ctrl) == FALSE) |
246 |
rc = 1; |
rc = 1; |
247 |
return rc; |
return rc; |
248 |
} /* listview_del_all */ |
} |
249 |
|
|
250 |
|
|
251 |
|
/* Return if the given element is selected or if the ext |
252 |
|
style is used, if the checkbox is activated. */ |
253 |
int |
int |
254 |
listview_get_item_state( listview_ctrl_t ctx, int pos ) |
listview_get_item_state (listview_ctrl_t ctx, int pos) |
255 |
{ |
{ |
256 |
return ListView_GetItemState( ctx->ctrl, pos, LVIS_SELECTED ); |
int ret; |
257 |
} /* listview_get_item_state */ |
if (ctx->ext_chkbox) |
258 |
|
ret = ListView_GetCheckState (ctx->ctrl, pos); |
259 |
|
else |
260 |
|
ret = ListView_GetItemState (ctx->ctrl, pos, LVIS_SELECTED); |
261 |
|
return ret; |
262 |
|
} |
263 |
|
|
264 |
|
|
265 |
int |
int |
329 |
} /* listview_get_item_text */ |
} /* listview_get_item_text */ |
330 |
|
|
331 |
|
|
332 |
|
/* Use extended style with checkboxes for each item. */ |
333 |
|
void |
334 |
|
listview_set_chkbox_style (listview_ctrl_t ctx) |
335 |
|
{ |
336 |
|
ListView_SetExtendedListViewStyle (ctx->ctrl, LVS_EX_CHECKBOXES); |
337 |
|
ctx->ext_chkbox = 1; |
338 |
|
} |
339 |
|
|
340 |
|
|
341 |
|
/* Use extended style to select the entire row. */ |
342 |
void |
void |
343 |
listview_set_ext_style( listview_ctrl_t ctx ) |
listview_set_ext_style (listview_ctrl_t ctx) |
344 |
{ |
{ |
345 |
ListView_SetExtendedListViewStyle( ctx->ctrl, LVS_EX_FULLROWSELECT ); |
ListView_SetExtendedListViewStyle (ctx->ctrl, LVS_EX_FULLROWSELECT); |
346 |
} /* listview_set_ext_style */ |
} |
347 |
|
|
348 |
|
|
349 |
int |
int |
415 |
HIMAGELIST hil; |
HIMAGELIST hil; |
416 |
DWORD i; |
DWORD i; |
417 |
|
|
418 |
hil = ImageList_Create (16, 16, ILC_COLOR16, nicons, 1); |
hil = ImageList_Create (16, 16, ILC_COLOR8|ILC_MASK, nicons, 1); |
419 |
|
ImageList_SetBkColor (hil, CLR_NONE); |
420 |
for (i=0; i < nicons; i++) |
for (i=0; i < nicons; i++) |
421 |
ImageList_AddIcon (hil, ico[i]); |
ImageList_AddIcon (hil, ico[i]); |
422 |
ListView_SetImageList (ctx->ctrl, hil, LVSIL_SMALL); |
ListView_SetImageList (ctx->ctrl, hil, LVSIL_SMALL); |
423 |
} |
} |
424 |
|
|