46 |
c = new struct listview_ctrl_s; |
c = new struct listview_ctrl_s; |
47 |
if (!c) |
if (!c) |
48 |
BUG (NULL); |
BUG (NULL); |
49 |
c->cols = 0; |
memset (c, 0, sizeof *c); |
|
c->items = 0; |
|
50 |
c->ctrl = ctrl? ctrl : NULL; |
c->ctrl = ctrl? ctrl : NULL; |
51 |
c->hil = NULL; |
c->hil = NULL; |
|
c->ext_chkbox = 0; |
|
52 |
*ctx = c; |
*ctx = c; |
53 |
} |
} |
54 |
|
|
87 |
int rc = 0; |
int rc = 0; |
88 |
LV_COLUMN lvc; |
LV_COLUMN lvc; |
89 |
|
|
90 |
memset( &lvc, 0, sizeof lvc ); |
memset (&lvc, 0, sizeof lvc); |
91 |
lvc.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM; |
lvc.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM; |
92 |
lvc.pszText = col->fieldname; |
lvc.pszText = col->fieldname; |
93 |
lvc.cx = col->width; |
lvc.cx = col->width; |
94 |
lvc.fmt = LVCFMT_LEFT; |
lvc.fmt = LVCFMT_LEFT; |
95 |
lvc.iSubItem = col->pos; |
lvc.iSubItem = col->pos; |
96 |
if( ListView_InsertColumn (ctx->ctrl, col->pos, &lvc) == -1) |
if (ListView_InsertColumn (ctx->ctrl, col->pos, &lvc) == -1) |
97 |
rc = 1; |
rc = 1; |
98 |
ctx->cols++; |
ctx->cols++; |
99 |
return rc; |
return rc; |
294 |
|
|
295 |
int |
int |
296 |
listview_sort_items (listview_ctrl_t ctx, int sortby, listview_cmp sort_cb) |
listview_sort_items (listview_ctrl_t ctx, int sortby, listview_cmp sort_cb) |
297 |
{ |
{ |
|
HWND hheader; |
|
|
HDITEM hdi; |
|
|
int idx, sort_desc = 0; |
|
|
|
|
298 |
ListView_SortItems (ctx->ctrl, sort_cb, sortby); |
ListView_SortItems (ctx->ctrl, sort_cb, sortby); |
|
hheader = ListView_GetHeader (ctx->ctrl); |
|
|
if (!hheader) |
|
|
return 0; |
|
|
|
|
|
/* Remove image from all header fields */ |
|
|
memset (&hdi, 0, sizeof(hdi)); |
|
|
|
|
|
for (int i=0; i < 7; i++) { |
|
|
hdi.mask = HDI_FORMAT; |
|
|
Header_GetItem (hheader, i, &hdi); |
|
|
hdi.fmt &= ~HDF_IMAGE; |
|
|
Header_SetItem (hheader, i, &hdi); |
|
|
} |
|
|
|
|
|
switch (sortby & ~KEYLIST_SORT_DESC) { |
|
|
case KEY_SORT_USERID: idx = 0; break; |
|
|
case KEY_SORT_KEYID: idx = 1; break; |
|
|
case KEY_SORT_IS_SECRET: idx = 2; break; |
|
|
case KEY_SORT_LEN: idx = 3; break; |
|
|
case KEY_SORT_VALIDITY: idx = 5; break; |
|
|
case KEY_SORT_OTRUST: idx = 6; break; |
|
|
case KEY_SORT_CREATED: idx = 7; break; |
|
|
case KEY_SORT_ALGO: idx = 8; break; |
|
|
default: idx = 0; break; |
|
|
} |
|
|
|
|
|
sort_desc = sortby & KEYLIST_SORT_DESC; |
|
|
/* Set image to currently sorted field */ |
|
|
memset (&hdi, 0, sizeof(hdi)); |
|
|
hdi.mask = HDI_IMAGE | HDI_FORMAT; |
|
|
Header_GetItem (hheader, idx, &hdi); |
|
|
hdi.fmt |= HDF_IMAGE | HDF_BITMAP_ON_RIGHT; |
|
|
if (!ctx->ext_chkbox) |
|
|
hdi.iImage = imagelist_getindex (sort_desc? IMI_SORT_DOWNARROW : |
|
|
IMI_SORT_UPARROW); |
|
|
else |
|
|
hdi.iImage = sort_desc? KEY_IMG_SORT_DOWN : KEY_IMG_SORT_UP; |
|
|
Header_SetItem (hheader, idx, &hdi); |
|
299 |
return 0; |
return 0; |
300 |
} |
} |
301 |
|
|
302 |
|
|
303 |
int |
int |
304 |
listview_get_curr_pos( listview_ctrl_t ctx ) |
listview_get_curr_pos (listview_ctrl_t ctx) |
305 |
{ |
{ |
306 |
return ListView_GetNextItem( ctx->ctrl, -1, LVNI_SELECTED ); |
return ListView_GetNextItem( ctx->ctrl, -1, LVNI_SELECTED ); |
307 |
} |
} |
434 |
HIMAGELIST hil; |
HIMAGELIST hil; |
435 |
DWORD i; |
DWORD i; |
436 |
|
|
437 |
if (cx == 0 || cy == 0) |
if (cx <= 0 || cy <= 0) |
438 |
cx = cy = 16; |
cx = cy = 16; /* default size. */ |
439 |
|
|
440 |
hil = ImageList_Create (cx, cy, ILC_COLOR8|ILC_MASK, nicons, 1); |
hil = ImageList_Create (cx, cy, ILC_COLOR8|ILC_MASK, nicons, 1); |
441 |
ImageList_SetBkColor (hil, CLR_NONE); |
ImageList_SetBkColor (hil, CLR_NONE); |