/[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 200 by twoaday, Mon Apr 17 09:12:50 2006 UTC revision 241 by twoaday, Thu Jun 29 11:15:55 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    
# Line 47  listview_new (listview_ctrl_t *ctx) Line 48  listview_new (listview_ctrl_t *ctx)
48          BUG (NULL);          BUG (NULL);
49      c->cols = 0;      c->cols = 0;
50      c->items = 0;      c->items = 0;
51      c->ctrl = NULL;      c->ctrl = ctrl? ctrl : NULL;
52      c->hil = NULL;      c->hil = NULL;
53      c->ext_chkbox = 0;      c->ext_chkbox = 0;
54      *ctx = c;      *ctx = c;
     return 0;  
55  }  }
56    
57    
# Line 118  listview_add_item_pos (listview_ctrl_t c Line 118  listview_add_item_pos (listview_ctrl_t c
118    
119    
120  int  int
121  listview_add_item( listview_ctrl_t ctx, const char *text )  listview_add_item (listview_ctrl_t ctx, const char *text)
122  {  {
123      int rc = 0;      int rc = 0;
124      LV_ITEM lvi;      LV_ITEM lvi;
125    
126      memset( &lvi, 0, sizeof lvi );      memset (&lvi, 0, sizeof lvi);
127      lvi.mask = LVIF_TEXT;      lvi.mask = LVIF_TEXT;
128      lvi.pszText = (char *)text;      lvi.pszText = (char *)text;
129      rc = ListView_InsertItem( ctx->ctrl, &lvi );      rc = ListView_InsertItem (ctx->ctrl, &lvi);
130      if( rc == -1 )      if( rc == -1 )
131          rc = 1;          rc = 1;
132      ctx->items++;      ctx->items++;
# Line 182  listview_get_item2 (listview_ctrl_t ctx, Line 182  listview_get_item2 (listview_ctrl_t ctx,
182      return (void*)lvi.lParam;      return (void*)lvi.lParam;
183  }  }
184    
185    
186  int  int
187  listview_set_item2 (listview_ctrl_t ctx, int pos, void *magic)  listview_set_item2 (listview_ctrl_t ctx, int pos, void *magic)
188  {  {
# Line 198  listview_set_item2 (listview_ctrl_t ctx, Line 199  listview_set_item2 (listview_ctrl_t ctx,
199    
200    
201  void  void
202  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)
203  {        {
204      ListView_SetItemText( ctx->ctrl, pos, col, (char *)text );      ListView_SetItemText (ctx->ctrl, pos, col, (char*)text);
205  }  }
206    
207    
# Line 294  listview_get_item_state (listview_ctrl_t Line 295  listview_get_item_state (listview_ctrl_t
295    
296    
297  int  int
298  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)
299  {        {      
300      HWND hheader;      HWND hheader;
301      HDITEM hdi;      HDITEM hdi;
302      int idx;      int idx, sort_desc = 0;
303    
304      ListView_SortItems (ctx->ctrl, sort_cb, sortby);      ListView_SortItems (ctx->ctrl, sort_cb, sortby);
305      hheader = ListView_GetHeader (ctx->ctrl);      hheader = ListView_GetHeader (ctx->ctrl);
# Line 327  listview_sort_items( listview_ctrl_t ctx Line 328  listview_sort_items( listview_ctrl_t ctx
328      default:                 idx = 0; break;      default:                 idx = 0; break;
329      }      }
330    
331        sort_desc = sortby & KEYLIST_SORT_DESC;
332      /* Set image to currently sorted field */      /* Set image to currently sorted field */
333      memset (&hdi, 0, sizeof(hdi));      memset (&hdi, 0, sizeof(hdi));
334      hdi.mask = HDI_IMAGE | HDI_FORMAT;      hdi.mask = HDI_IMAGE | HDI_FORMAT;
335      Header_GetItem (hheader, idx, &hdi);      Header_GetItem (hheader, idx, &hdi);  
336      hdi.fmt |= HDF_IMAGE | HDF_BITMAP_ON_RIGHT;      hdi.fmt |= HDF_IMAGE | HDF_BITMAP_ON_RIGHT;
337      hdi.iImage = imagelist_getindex((sortby & KEYLIST_SORT_DESC) ?      if (!ctx->ext_chkbox)
338                                      IMI_SORT_DOWNARROW : IMI_SORT_UPARROW);          hdi.iImage = imagelist_getindex (sort_desc? IMI_SORT_DOWNARROW :
339                                                        IMI_SORT_UPARROW);
340        else
341            hdi.iImage = sort_desc? KEY_IMG_SORT_DOWN : KEY_IMG_SORT_UP;
342      Header_SetItem (hheader, idx, &hdi);      Header_SetItem (hheader, idx, &hdi);
343      return 0;      return 0;
344  }  }
# Line 401  listview_deselect_all (listview_ctrl_t c Line 406  listview_deselect_all (listview_ctrl_t c
406  void  void
407  listview_select_one (listview_ctrl_t ctx, int pos)  listview_select_one (listview_ctrl_t ctx, int pos)
408  {  {
409      ListView_SetItemState (ctx->ctrl, pos, LVIS_SELECTED|LVIS_FOCUSED, LVIS_FOCUSED|LVIS_SELECTED);      ListView_SetItemState (ctx->ctrl, pos, LVIS_SELECTED|LVIS_FOCUSED,
410                                                LVIS_FOCUSED|LVIS_SELECTED);
411  }  }
412    
413    
# Line 412  listview_scroll (listview_ctrl_t ctx, in Line 418  listview_scroll (listview_ctrl_t ctx, in
418            
419      if (oldpos == -1)      if (oldpos == -1)
420          oldpos = 0;          oldpos = 0;
421      //log_box ("debug", 0, "oldpos=%d newpos=%d diff=%d", oldpos, newpos, newpos-oldpos);      //log_box ("debug", 0, "oldpos=%d newpos=%d diff=%d",
422                    //oldpos, newpos, newpos-oldpos);
423      ListView_Scroll (ctx->ctrl, 0, (newpos-oldpos)*size);      ListView_Scroll (ctx->ctrl, 0, (newpos-oldpos)*size);
424  }  }
425    
426    
427    static int
428    listview_find_substr (listview_ctrl_t ctx, const char *str)
429    {
430        char buf[256];
431        int i, n, fnd = 0;
432    
433        /* We assume the first column contains text. */
434        n = listview_count_items (ctx, 0);
435        for (i = 0; i < n; i++) {
436            listview_get_item_text (ctx, i, 0, buf, sizeof (buf)-1);
437            if (stristr (buf, str)) {
438                fnd = 1;
439                break;
440            }
441        }
442        if (!fnd)
443            i = -1; /* not found */
444        return i;
445    }
446    
447    
448  int  int
449  listview_find (listview_ctrl_t ctx, const char * str)  listview_find (listview_ctrl_t ctx, const char *str, int substr)
450  {  {
451      LVFINDINFO inf;      LVFINDINFO inf;
452      int pos;      int pos;
453    
454        /* XXX: allow to make a substring search. */
455      memset (&inf, 0, sizeof (inf));      memset (&inf, 0, sizeof (inf));
456      inf.flags = LVFI_STRING|LVFI_PARTIAL;      inf.flags = LVFI_STRING|LVFI_PARTIAL;
457      inf.psz = str;      inf.psz = str;
458      pos = ListView_FindItem (ctx->ctrl, -1, &inf);      pos = ListView_FindItem (ctx->ctrl, -1, &inf);
459        if (pos == -1 && substr)
460            pos = listview_find_substr (ctx, str);
461      return pos;      return pos;
462  }  }
463    

Legend:
Removed from v.200  
changed lines
  Added in v.241

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26