/[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 129 by twoaday, Fri Dec 30 13:56:10 2005 UTC revision 181 by twoaday, Tue Mar 14 11:01:22 2006 UTC
# Line 1  Line 1 
1  /* wptListView.cpp - Dynamic list view control  /* wptListView.cpp - Dynamic list view control
2   *      Copyright (C) 2000-2005 Timo Schulz   *      Copyright (C) 2000-2006 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.
# Line 38  Line 38 
38    
39    
40  int  int
41  listview_new( listview_ctrl_t *ctx )  listview_new (listview_ctrl_t *ctx)
42  {  {
43      struct listview_ctrl_s *c;      struct listview_ctrl_s *c;
44    
45      c = new struct listview_ctrl_s;      c = new struct listview_ctrl_s;
46      if( !c )      if (!c)
47          BUG( NULL );          BUG (NULL);
48      c->cols = 0;      c->cols = 0;
49      c->items = 0;      c->items = 0;
50      c->ctrl = NULL;          c->ctrl = NULL;
51        c->hil = NULL;
52        c->ext_chkbox = 0;
53      *ctx = c;      *ctx = c;
54      return 0;      return 0;
55  } /* listview_new */  }
56    
57    
58  void  void
59  listview_release( listview_ctrl_t ctx )  listview_release (listview_ctrl_t ctx)
60  {  {
61      if( ctx ) {      if (!ctx)
62          ctx->cols = 0;          return;
63          ctx->ctrl = NULL;  
64          ctx->items = 0;      ctx->cols = 0;
65          delete ctx;      ctx->ctrl = NULL;
66          ctx = NULL;      ctx->items = 0;
67      }      if (ctx->hil)
68            ImageList_Destroy (ctx->hil);
69        delete ctx;
70  } /* listview_release */  } /* listview_release */
71    
72    
# Line 93  listview_add_item_pos (listview_ctrl_t c Line 97  listview_add_item_pos (listview_ctrl_t c
97    
98      memset (&lvi, 0, sizeof lvi);      memset (&lvi, 0, sizeof lvi);
99      lvi.iItem = pos;      lvi.iItem = pos;
100      rc = ListView_InsertItem (ctx->ctrl, &lvi);      if (ListView_InsertItem (ctx->ctrl, &lvi) != pos)
101      if (rc == -1)          rc = -1;
         rc = 1;  
102      ctx->items++;      ctx->items++;
103      return rc;      return rc;
104  }  }
# Line 119  listview_add_item( listview_ctrl_t ctx, Line 122  listview_add_item( listview_ctrl_t ctx,
122    
123    
124  int  int
125  listview_add_item2 (listview_ctrl_t ctx, const char *text, void *magic)  listview_add_item_image (listview_ctrl_t ctx, const char *text, int image)
126  {  {
127      int rc = 0;      int rc = 0;
128      LV_ITEM lvi;      LV_ITEM lvi;
129    
130      memset( &lvi, 0, sizeof lvi );      memset( &lvi, 0, sizeof lvi );
131        lvi.mask = LVIF_TEXT | LVIF_IMAGE;
132        lvi.pszText = (char *)text;
133        lvi.iImage = image;
134        rc = ListView_InsertItem (ctx->ctrl, &lvi);
135        if (rc == -1)
136            rc = 1;
137        ctx->items++;
138        return rc;
139    }
140    
141    
142    int
143    listview_add_item2 (listview_ctrl_t ctx, const char *text, void *magic)
144    {
145        int rc = 0;
146        LVITEM lvi;
147    
148        memset (&lvi, 0, sizeof (lvi));
149      lvi.mask = LVIF_TEXT | LVIF_PARAM;      lvi.mask = LVIF_TEXT | LVIF_PARAM;
150      lvi.pszText = (char *)text;      lvi.pszText = (char *)text;
151      lvi.lParam = (LPARAM)magic;      lvi.lParam = (LPARAM)magic;
152      rc = ListView_InsertItem( ctx->ctrl, &lvi );      rc = ListView_InsertItem (ctx->ctrl, &lvi);
153      if( rc == -1 )      if (rc == -1)
154          rc = 1;          rc = 1;
155      ctx->items++;      ctx->items++;
156      return rc;      return rc;
# Line 189  listview_del_column (listview_ctrl_t ctx Line 210  listview_del_column (listview_ctrl_t ctx
210  }  }
211    
212    
213    /* Delete a single item from @ctx at position @pos. */
214  int  int
215  listview_del_item( listview_ctrl_t ctx, int pos )  listview_del_item (listview_ctrl_t ctx, int pos)
216  {  {
217      int rc = 0;      int rc = 0;
218    
219      if( ListView_DeleteItem( ctx->ctrl, pos ) == -1 )      if (ListView_DeleteItem (ctx->ctrl, pos) == -1)
220          rc = 1;          rc = 1;
221      return rc;      return rc;
222  } /* listview_del_item */  }
223    
224    
225    /* Delete all selected items in @ctx. */
226  int  int
227  listview_del_items( listview_ctrl_t ctx )  listview_del_sel_items (listview_ctrl_t ctx)
228  {        {      
229      int i, n;      int i, n;
230    
     /* delete all selected entries */  
231      n = listview_count_items (ctx, 0);      n = listview_count_items (ctx, 0);
232      for( i = n;  i > 0; i-- ) {      for (i = n;  i > -1; i--) {
233          if ( listview_get_item_state( ctx, i ) )          if (listview_get_item_state (ctx, i))
234              listview_del_item( ctx, i );                      listview_del_item (ctx, i);
235      }      }
236      return 0;      return 0;
237  } /* listview_del_items */  }
238    
239    
240  int  int
241  listview_del_all( listview_ctrl_t ctx )  listview_del_all_items (listview_ctrl_t ctx)
242  {        {      
243      int rc = 0;      int rc = 0;
244    
245      if( ListView_DeleteAllItems( ctx->ctrl ) == FALSE )      if (ListView_DeleteAllItems (ctx->ctrl) == FALSE)
246          rc = 1;          rc = 1;
247      return rc;      return rc;
248  } /* listview_del_all */  }
249    
250    
251    /* Return if the given element is selected or if the ext
252       style is used, if the checkbox is activated. */
253  int  int
254  listview_get_item_state( listview_ctrl_t ctx, int pos )  listview_get_item_state (listview_ctrl_t ctx, int pos)
255  {        {
256      return ListView_GetItemState( ctx->ctrl, pos, LVIS_SELECTED );      int ret;
257  } /* listview_get_item_state */      if (ctx->ext_chkbox)
258            ret = ListView_GetCheckState (ctx->ctrl, pos);
259        else
260            ret = ListView_GetItemState (ctx->ctrl, pos, LVIS_SELECTED);
261        return ret;
262    }
263    
264    
265  int  int
# Line 300  listview_get_item_text (listview_ctrl_t Line 329  listview_get_item_text (listview_ctrl_t
329  } /* listview_get_item_text */  } /* listview_get_item_text */
330    
331    
332    /* Use extended style with checkboxes for each item. */
333  void  void
334  listview_set_ext_style( listview_ctrl_t ctx )  listview_set_chkbox_style (listview_ctrl_t ctx)
335    {
336        ListView_SetExtendedListViewStyle (ctx->ctrl, LVS_EX_CHECKBOXES);
337        ctx->ext_chkbox = 1;
338    }
339    
340    
341    /* Use extended style to select the entire row. */
342    void
343    listview_set_ext_style (listview_ctrl_t ctx)
344  {        {      
345      ListView_SetExtendedListViewStyle( ctx->ctrl, LVS_EX_FULLROWSELECT );      ListView_SetExtendedListViewStyle (ctx->ctrl, LVS_EX_FULLROWSELECT);
346  } /* listview_set_ext_style */  }
347    
348    
349  int  int
# Line 368  listview_setview (listview_ctrl_t ctx, D Line 407  listview_setview (listview_ctrl_t ctx, D
407      if ((style & LVS_TYPEMASK) != view)      if ((style & LVS_TYPEMASK) != view)
408          SetWindowLong (ctx->ctrl, GWL_STYLE, (style & ~LVS_TYPEMASK) | view);          SetWindowLong (ctx->ctrl, GWL_STYLE, (style & ~LVS_TYPEMASK) | view);
409  }  }
410    
411    
412    void
413    listview_set_image_list (listview_ctrl_t ctx, int cx, int cy,
414                             HICON *ico, DWORD nicons)
415    {
416        HIMAGELIST hil;
417        DWORD i;
418    
419        if (cx == 0 || cy == 0)
420            cx = cy = 16;
421    
422        hil = ImageList_Create (cx, cy, ILC_COLOR8|ILC_MASK, nicons, 1);
423        ImageList_SetBkColor (hil, CLR_NONE);
424        for (i=0; i < nicons; i++)
425            ImageList_AddIcon (hil, ico[i]);    
426        ListView_SetImageList (ctx->ctrl, hil, LVSIL_SMALL);    
427    }
428        

Legend:
Removed from v.129  
changed lines
  Added in v.181

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26