/[winpt]/trunk/Src/wptListView.cpp
ViewVC logotype

Diff of /trunk/Src/wptListView.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 193 by twoaday, Sat Apr 1 12:36:35 2006 UTC revision 273 by twoaday, Fri Dec 8 10:22:17 2006 UTC
# Line 34  Line 34 
34  #include "wptTypes.h"  #include "wptTypes.h"
35  #include "wptGPG.h"  #include "wptGPG.h"
36  #include "wptKeylist.h"  #include "wptKeylist.h"
37    #include "wptUTF8.h"
38  #include "resource.h"  #include "resource.h"
39    
40    
41  int  void
42  listview_new (listview_ctrl_t *ctx)  listview_new (listview_ctrl_t *ctx, HWND ctrl)
43  {  {
44      struct listview_ctrl_s *c;      struct listview_ctrl_s *c;
45    
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);
50      c->items = 0;      c->ctrl = ctrl? ctrl : NULL;
     c->ctrl = NULL;  
51      c->hil = NULL;      c->hil = NULL;
     c->ext_chkbox = 0;  
52      *ctx = c;      *ctx = c;
     return 0;  
53  }  }
54    
55    
# Line 89  listview_add_column (listview_ctrl_t ctx Line 87  listview_add_column (listview_ctrl_t ctx
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;
100  } /* listview_add_column */  }
101    
102    
103  int  int
# Line 118  listview_add_item_pos (listview_ctrl_t c Line 116  listview_add_item_pos (listview_ctrl_t c
116    
117    
118  int  int
119  listview_add_item( listview_ctrl_t ctx, const char *text )  listview_add_item (listview_ctrl_t ctx, const char *text)
120  {  {
121      int rc = 0;      int rc = 0;
122      LV_ITEM lvi;      LV_ITEM lvi;
123    
124      memset( &lvi, 0, sizeof lvi );      memset (&lvi, 0, sizeof lvi);
125      lvi.mask = LVIF_TEXT;      lvi.mask = LVIF_TEXT;
126      lvi.pszText = (char *)text;      lvi.pszText = (char *)text;
127      rc = ListView_InsertItem( ctx->ctrl, &lvi );      rc = ListView_InsertItem (ctx->ctrl, &lvi);
128      if( rc == -1 )      if( rc == -1 )
129          rc = 1;          rc = 1;
130      ctx->items++;      ctx->items++;
131      return rc;      return rc;
132  } /* listview_add_item */  }
133    
134    
135  int  int
# Line 167  listview_add_item2 (listview_ctrl_t ctx, Line 165  listview_add_item2 (listview_ctrl_t ctx,
165          rc = 1;          rc = 1;
166      ctx->items++;      ctx->items++;
167      return rc;      return rc;
168  } /* listview_add_item2 */  }
169    
170    
171  void*  void*
# Line 182  listview_get_item2 (listview_ctrl_t ctx, Line 180  listview_get_item2 (listview_ctrl_t ctx,
180      return (void*)lvi.lParam;      return (void*)lvi.lParam;
181  }  }
182    
183    
184  int  int
185  listview_set_item2 (listview_ctrl_t ctx, int pos, void *magic)  listview_set_item2 (listview_ctrl_t ctx, int pos, void *magic)
186  {  {
# Line 198  listview_set_item2 (listview_ctrl_t ctx, Line 197  listview_set_item2 (listview_ctrl_t ctx,
197    
198    
199  void  void
200  listview_add_sub_item( listview_ctrl_t ctx, int pos, int col, const char *text )  listview_add_sub_item (listview_ctrl_t ctx, int pos, int col, const char *text)
201  {        {
202      ListView_SetItemText( ctx->ctrl, pos, col, (char *)text );      ListView_SetItemText (ctx->ctrl, pos, col, (char*)text);
203  } /* listview_add_sub_item */  }
204    
205    
206  int  int
# Line 212  listview_count_items( listview_ctrl_t ct Line 211  listview_count_items( listview_ctrl_t ct
211      n = curr_sel? ListView_GetSelectedCount( ctx->ctrl ) :          n = curr_sel? ListView_GetSelectedCount( ctx->ctrl ) :    
212                    ListView_GetItemCount( ctx->ctrl );                    ListView_GetItemCount( ctx->ctrl );
213      return n;      return n;
214  } /* listview_count_items */  }
215    
216    
217  int  int
# Line 294  listview_get_item_state (listview_ctrl_t Line 293  listview_get_item_state (listview_ctrl_t
293    
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;  
   
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;  
     }  
   
     /* 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;  
     hdi.iImage = imagelist_getindex((sortby & KEYLIST_SORT_DESC) ?  
                                     IMI_SORT_DOWNARROW : IMI_SORT_UPARROW);  
     Header_SetItem (hheader, idx, &hdi);  
299      return 0;      return 0;
300  } /* listview_sort_items */  }
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  } /* listview_get_curr_pos */  }
308    
309    
310  int  int
# Line 357  listview_get_item_text (listview_ctrl_t Line 318  listview_get_item_text (listview_ctrl_t
318      }      }
319      ListView_GetItemText (ctx->ctrl, pos, col, text, maxbytes);      ListView_GetItemText (ctx->ctrl, pos, col, text, maxbytes);
320      return 0;      return 0;
321  } /* listview_get_item_text */  }
322    
323    
324  /* Use extended style with checkboxes for each item. */  /* Use extended style with checkboxes for each item. */
# Line 381  int Line 342  int
342  listview_set_column_order( listview_ctrl_t ctx, int *array )  listview_set_column_order( listview_ctrl_t ctx, int *array )
343  {        {      
344      return ListView_SetColumnOrderArray( ctx->ctrl, ctx->cols, array );      return ListView_SetColumnOrderArray( ctx->ctrl, ctx->cols, array );
345  } /* listview_set_column_order */  }
346    
347    
348  void  void
349  listview_select_all (listview_ctrl_t ctx)  listview_select_all (listview_ctrl_t ctx)
350  {        {      
351      ListView_SetItemState( ctx->ctrl, -1, LVIS_SELECTED, LVIS_SELECTED );      ListView_SetItemState( ctx->ctrl, -1, LVIS_SELECTED, LVIS_SELECTED );
352  } /* listview_select_all */  }
353    
354    
355  void  void
# Line 401  listview_deselect_all (listview_ctrl_t c Line 362  listview_deselect_all (listview_ctrl_t c
362  void  void
363  listview_select_one (listview_ctrl_t ctx, int pos)  listview_select_one (listview_ctrl_t ctx, int pos)
364  {  {
365      ListView_SetItemState (ctx->ctrl, pos, LVIS_SELECTED|LVIS_FOCUSED, LVIS_FOCUSED|LVIS_SELECTED);      ListView_SetItemState (ctx->ctrl, pos, LVIS_SELECTED|LVIS_FOCUSED,
366                                                LVIS_FOCUSED|LVIS_SELECTED);
367  }  }
368    
369    
# Line 412  listview_scroll (listview_ctrl_t ctx, in Line 374  listview_scroll (listview_ctrl_t ctx, in
374            
375      if (oldpos == -1)      if (oldpos == -1)
376          oldpos = 0;          oldpos = 0;
377      //log_box ("debug", 0, "oldpos=%d newpos=%d diff=%d", oldpos, newpos, newpos-oldpos);      //log_box ("debug", 0, "oldpos=%d newpos=%d diff=%d",
378                    //oldpos, newpos, newpos-oldpos);
379      ListView_Scroll (ctx->ctrl, 0, (newpos-oldpos)*size);      ListView_Scroll (ctx->ctrl, 0, (newpos-oldpos)*size);
380  }  }
381    
382    
383    static int
384    listview_find_substr (listview_ctrl_t ctx, const char *str)
385    {
386        char buf[256];
387        int i, n, fnd = 0;
388    
389        /* We assume the first column contains text. */
390        n = listview_count_items (ctx, 0);
391        for (i = 0; i < n; i++) {
392            listview_get_item_text (ctx, i, 0, buf, sizeof (buf)-1);
393            if (stristr (buf, str)) {
394                fnd = 1;
395                break;
396            }
397        }
398        if (!fnd)
399            i = -1; /* not found */
400        return i;
401    }
402    
403    
404  int  int
405  listview_find (listview_ctrl_t ctx, const char * str)  listview_find (listview_ctrl_t ctx, const char *str, int substr)
406  {  {
407      LVFINDINFO inf;      LVFINDINFO inf;
408      int pos;      int pos;
409    
410        /* XXX: allow to make a substring search. */
411      memset (&inf, 0, sizeof (inf));      memset (&inf, 0, sizeof (inf));
412      inf.flags = LVFI_STRING|LVFI_PARTIAL;      inf.flags = LVFI_STRING|LVFI_PARTIAL;
413      inf.psz = str;      inf.psz = str;
414      pos = ListView_FindItem (ctx->ctrl, -1, &inf);      pos = ListView_FindItem (ctx->ctrl, -1, &inf);
415        if (pos == -1 && substr)
416            pos = listview_find_substr (ctx, str);
417      return pos;      return pos;
418  }  }
419    
# Line 447  listview_set_image_list (listview_ctrl_t Line 434  listview_set_image_list (listview_ctrl_t
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);
# Line 456  listview_set_image_list (listview_ctrl_t Line 443  listview_set_image_list (listview_ctrl_t
443          ImageList_AddIcon (hil, ico[i]);              ImageList_AddIcon (hil, ico[i]);    
444      ListView_SetImageList (ctx->ctrl, hil, LVSIL_SMALL);          ListView_SetImageList (ctx->ctrl, hil, LVSIL_SMALL);    
445  }  }
       

Legend:
Removed from v.193  
changed lines
  Added in v.273

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26