/[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 236 by twoaday, Wed Jun 28 06:59:30 2006 UTC revision 241 by twoaday, Thu Jun 29 11:15:55 2006 UTC
# 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 298  listview_sort_items (listview_ctrl_t ctx Line 299  listview_sort_items (listview_ctrl_t ctx
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      if (!ctx->ext_chkbox)      if (!ctx->ext_chkbox)
338          hdi.iImage = imagelist_getindex((sortby & KEYLIST_SORT_DESC) ?          hdi.iImage = imagelist_getindex (sort_desc? IMI_SORT_DOWNARROW :
339                                          IMI_SORT_DOWNARROW : IMI_SORT_UPARROW);                                                      IMI_SORT_UPARROW);
340      else      else
341          hdi.iImage = (sortby & KEYLIST_SORT_DESC)? 2 : 3;          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 404  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 415  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;
# Line 431  listview_find (listview_ctrl_t ctx, cons Line 456  listview_find (listview_ctrl_t ctx, cons
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.236  
changed lines
  Added in v.241

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26