/[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 133 by twoaday, Mon Jan 9 09:15:29 2006 UTC revision 193 by twoaday, Sat Apr 1 12:36:35 2006 UTC
# Line 49  listview_new (listview_ctrl_t *ctx) Line 49  listview_new (listview_ctrl_t *ctx)
49      c->items = 0;      c->items = 0;
50      c->ctrl = NULL;      c->ctrl = NULL;
51      c->hil = NULL;      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
# Line 66  listview_release (listview_ctrl_t ctx) Line 67  listview_release (listview_ctrl_t ctx)
67      if (ctx->hil)      if (ctx->hil)
68          ImageList_Destroy (ctx->hil);          ImageList_Destroy (ctx->hil);
69      delete ctx;      delete ctx;
70  } /* listview_release */  }
71    
72    
73    int
74    listview_set_column_width (listview_ctrl_t ctx, int col, int width)
75    {
76        LVCOLUMN lvc;
77    
78        memset (&lvc, 0, sizeof (lvc));
79        lvc.mask = LVCF_WIDTH;
80        lvc.cx = width;
81        ListView_SetColumn (ctx->ctrl, col, &lvc);
82        return 0;
83    }
84    
85    
86  int  int
# Line 142  int Line 156  int
156  listview_add_item2 (listview_ctrl_t ctx, const char *text, void *magic)  listview_add_item2 (listview_ctrl_t ctx, const char *text, void *magic)
157  {  {
158      int rc = 0;      int rc = 0;
159      LV_ITEM lvi;      LVITEM lvi;
160    
161      memset( &lvi, 0, sizeof lvi );      memset (&lvi, 0, sizeof (lvi));
162      lvi.mask = LVIF_TEXT | LVIF_PARAM;      lvi.mask = LVIF_TEXT | LVIF_PARAM;
163      lvi.pszText = (char *)text;      lvi.pszText = (char *)text;
164      lvi.lParam = (LPARAM)magic;      lvi.lParam = (LPARAM)magic;
165      rc = ListView_InsertItem( ctx->ctrl, &lvi );      rc = ListView_InsertItem (ctx->ctrl, &lvi);
166      if( rc == -1 )      if (rc == -1)
167          rc = 1;          rc = 1;
168      ctx->items++;      ctx->items++;
169      return rc;      return rc;
# Line 209  listview_del_column (listview_ctrl_t ctx Line 223  listview_del_column (listview_ctrl_t ctx
223  }  }
224    
225    
226    /* Delete a single item from @ctx at position @pos. */
227  int  int
228  listview_del_item( listview_ctrl_t ctx, int pos )  listview_del_item (listview_ctrl_t ctx, int pos)
229  {  {
230      int rc = 0;      int rc = 0;
231    
232      if( ListView_DeleteItem( ctx->ctrl, pos ) == -1 )      if (ListView_DeleteItem (ctx->ctrl, pos) == -1)
233          rc = 1;          rc = 1;
234      return rc;      return rc;
235  } /* listview_del_item */  }
236    
237    
238    /* Delete all selected items in @ctx. */
239  int  int
240  listview_del_items( listview_ctrl_t ctx )  listview_del_sel_items (listview_ctrl_t ctx)
241  {        {      
242      int i, n;      int i, n;
243    
     /* delete all selected entries */  
244      n = listview_count_items (ctx, 0);      n = listview_count_items (ctx, 0);
245      for( i = n;  i > 0; i-- ) {      for (i = n;  i > -1; i--) {
246          if ( listview_get_item_state( ctx, i ) )          if (listview_get_item_state (ctx, i))
247              listview_del_item( ctx, i );                      listview_del_item (ctx, i);
248      }      }
249      return 0;      return 0;
250  } /* listview_del_items */  }
251    
252    
253  int  int
254  listview_del_all( listview_ctrl_t ctx )  listview_del_all_items (listview_ctrl_t ctx)
255  {        {      
256      int rc = 0;      int rc = 0;
257    
258      if( ListView_DeleteAllItems( ctx->ctrl ) == FALSE )      if (ListView_DeleteAllItems (ctx->ctrl) == FALSE)
259          rc = 1;          rc = 1;
260      return rc;      return rc;
261  } /* listview_del_all */  }
262    
263    
264    /* Return the index of the selected item.
265       Support both selections and checkboxes. */
266  int  int
267  listview_get_item_state( listview_ctrl_t ctx, int pos )  listview_get_selected_item (listview_ctrl_t lv)
268  {        {
269      return ListView_GetItemState( ctx->ctrl, pos, LVIS_SELECTED );      int pos, i;
270  } /* listview_get_item_state */      
271        pos = listview_get_curr_pos (lv);
272        if (pos != -1)
273            return pos;
274        for (i=0; i < listview_count_items (lv, 0); i++) {
275            if (listview_get_item_state (lv, i))
276                return i;
277        }
278        return -1;
279    }
280    
281    
282    /* Return if the given element is selected or if the ext
283       style is used, if the checkbox is activated. */
284    int
285    listview_get_item_state (listview_ctrl_t ctx, int pos)
286    {
287        int ret;
288        if (ctx->ext_chkbox)
289            ret = ListView_GetCheckState (ctx->ctrl, pos);
290        else
291            ret = ListView_GetItemState (ctx->ctrl, pos, LVIS_SELECTED);
292        return ret;
293    }
294    
295    
296  int  int
# Line 320  listview_get_item_text (listview_ctrl_t Line 360  listview_get_item_text (listview_ctrl_t
360  } /* listview_get_item_text */  } /* listview_get_item_text */
361    
362    
363    /* Use extended style with checkboxes for each item. */
364  void  void
365  listview_set_ext_style( listview_ctrl_t ctx )  listview_set_chkbox_style (listview_ctrl_t ctx)
366    {
367        ListView_SetExtendedListViewStyle (ctx->ctrl, LVS_EX_CHECKBOXES);
368        ctx->ext_chkbox = 1;
369    }
370    
371    
372    /* Use extended style to select the entire row. */
373    void
374    listview_set_ext_style (listview_ctrl_t ctx)
375  {        {      
376      ListView_SetExtendedListViewStyle( ctx->ctrl, LVS_EX_FULLROWSELECT );      ListView_SetExtendedListViewStyle (ctx->ctrl, LVS_EX_FULLROWSELECT);
377  } /* listview_set_ext_style */  }
378    
379    
380  int  int
# Line 391  listview_setview (listview_ctrl_t ctx, D Line 441  listview_setview (listview_ctrl_t ctx, D
441    
442    
443  void  void
444  listview_set_image_list (listview_ctrl_t ctx, HICON *ico, DWORD nicons)  listview_set_image_list (listview_ctrl_t ctx, int cx, int cy,
445                             HICON *ico, DWORD nicons)
446  {  {
447      HIMAGELIST hil;      HIMAGELIST hil;
448      DWORD i;      DWORD i;
449    
450      hil = ImageList_Create (16, 16, ILC_COLOR16, nicons, 1);      if (cx == 0 || cy == 0)
451            cx = cy = 16;
452    
453        hil = ImageList_Create (cx, cy, ILC_COLOR8|ILC_MASK, nicons, 1);
454        ImageList_SetBkColor (hil, CLR_NONE);
455      for (i=0; i < nicons; i++)      for (i=0; i < nicons; i++)
456          ImageList_AddIcon (hil, ico[i]);          ImageList_AddIcon (hil, ico[i]);    
457      ListView_SetImageList (ctx->ctrl, hil, LVSIL_SMALL);      ListView_SetImageList (ctx->ctrl, hil, LVSIL_SMALL);    
458  }  }
459            

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26