/[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 208 by twoaday, Mon May 1 12:22:18 2006 UTC revision 273 by twoaday, Fri Dec 8 10:22:17 2006 UTC
# Line 46  listview_new (listview_ctrl_t *ctx, HWND Line 46  listview_new (listview_ctrl_t *ctx, HWND
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    
# 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;
# 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++;
# 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 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  }  }
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  }  }
# 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;
# Line 428  listview_find (listview_ctrl_t ctx, cons Line 412  listview_find (listview_ctrl_t ctx, cons
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 448  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);

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26