1 |
/* wptListView.cpp - Dynamic list view control |
/* wptListView.cpp - Dynamic list view control |
2 |
* Copyright (C) 2000-2006 Timo Schulz |
* Copyright (C) 2000-2007 Timo Schulz |
3 |
* Copyright (C) 2004 Andreas Jobs |
* Copyright (C) 2004 Andreas Jobs |
4 |
* |
* |
5 |
* This file is part of WinPT. |
* This file is part of WinPT. |
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 |
* General Public License for more details. |
* General Public License for more details. |
|
* |
|
|
* You should have received a copy of the GNU General Public License |
|
|
* along with WinPT; if not, write to the Free Software Foundation, |
|
|
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
16 |
*/ |
*/ |
|
|
|
17 |
#ifdef HAVE_CONFIG_H |
#ifdef HAVE_CONFIG_H |
18 |
#include <config.h> |
#include <config.h> |
19 |
#endif |
#endif |
41 |
c = new struct listview_ctrl_s; |
c = new struct listview_ctrl_s; |
42 |
if (!c) |
if (!c) |
43 |
BUG (NULL); |
BUG (NULL); |
44 |
c->cols = 0; |
memset (c, 0, sizeof *c); |
|
c->items = 0; |
|
45 |
c->ctrl = ctrl? ctrl : NULL; |
c->ctrl = ctrl? ctrl : NULL; |
46 |
c->hil = NULL; |
c->hil = NULL; |
|
c->ext_chkbox = 0; |
|
47 |
*ctx = c; |
*ctx = c; |
48 |
} |
} |
49 |
|
|
82 |
int rc = 0; |
int rc = 0; |
83 |
LV_COLUMN lvc; |
LV_COLUMN lvc; |
84 |
|
|
85 |
memset( &lvc, 0, sizeof lvc ); |
memset (&lvc, 0, sizeof lvc); |
86 |
lvc.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM; |
lvc.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM; |
87 |
lvc.pszText = col->fieldname; |
lvc.pszText = col->fieldname; |
88 |
lvc.cx = col->width; |
lvc.cx = col->width; |
89 |
lvc.fmt = LVCFMT_LEFT; |
lvc.fmt = LVCFMT_LEFT; |
90 |
lvc.iSubItem = col->pos; |
lvc.iSubItem = col->pos; |
91 |
if( ListView_InsertColumn (ctx->ctrl, col->pos, &lvc) == -1) |
if (ListView_InsertColumn (ctx->ctrl, col->pos, &lvc) == -1) |
92 |
rc = 1; |
rc = 1; |
93 |
ctx->cols++; |
ctx->cols++; |
94 |
return rc; |
return rc; |
289 |
|
|
290 |
int |
int |
291 |
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) |
292 |
{ |
{ |
|
HWND hheader; |
|
|
HDITEM hdi; |
|
|
int idx, sort_desc = 0; |
|
|
|
|
293 |
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); |
|
294 |
return 0; |
return 0; |
295 |
} |
} |
296 |
|
|
297 |
|
|
298 |
int |
int |
299 |
listview_get_curr_pos( listview_ctrl_t ctx ) |
listview_get_curr_pos (listview_ctrl_t ctx) |
300 |
{ |
{ |
301 |
return ListView_GetNextItem( ctx->ctrl, -1, LVNI_SELECTED ); |
return ListView_GetNextItem( ctx->ctrl, -1, LVNI_SELECTED ); |
302 |
} |
} |
384 |
/* We assume the first column contains text. */ |
/* We assume the first column contains text. */ |
385 |
n = listview_count_items (ctx, 0); |
n = listview_count_items (ctx, 0); |
386 |
for (i = 0; i < n; i++) { |
for (i = 0; i < n; i++) { |
387 |
listview_get_item_text (ctx, i, 0, buf, sizeof (buf)-1); |
listview_get_item_text (ctx, i, 0, buf, DIM (buf)-1); |
388 |
if (stristr (buf, str)) { |
if (stristr (buf, str)) { |
389 |
fnd = 1; |
fnd = 1; |
390 |
break; |
break; |
429 |
HIMAGELIST hil; |
HIMAGELIST hil; |
430 |
DWORD i; |
DWORD i; |
431 |
|
|
432 |
if (cx == 0 || cy == 0) |
if (cx <= 0 || cy <= 0) |
433 |
cx = cy = 16; |
cx = cy = 16; /* default size. */ |
434 |
|
|
435 |
hil = ImageList_Create (cx, cy, ILC_COLOR8|ILC_MASK, nicons, 1); |
hil = ImageList_Create (cx, cy, ILC_COLOR8|ILC_MASK, nicons, 1); |
436 |
ImageList_SetBkColor (hil, CLR_NONE); |
ImageList_SetBkColor (hil, CLR_NONE); |