/[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 48 by werner, Mon Oct 31 21:14:11 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 18  Line 18 
18   * along with WinPT; if not, write to the Free Software Foundation,   * along with WinPT; if not, write to the Free Software Foundation,
19   * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA   * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20   */   */
21    
22  #ifdef HAVE_CONFIG_H  #ifdef HAVE_CONFIG_H
23  #include <config.h>  #include <config.h>
24  #endif  #endif
25    
 #ifdef __MINGW32__  
 #include <w32api.h>  
 #define _WIN32_IE IE401  
 #endif  
   
 #include <stdio.h>  
26  #include <stdio.h>  #include <stdio.h>
27  #include <windows.h>  #include <windows.h>
28  #include <commctrl.h>  #include <commctrl.h>
# Line 43  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 98  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 124  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 187  listview_count_items( listview_ctrl_t ct Line 203  listview_count_items( listview_ctrl_t ct
203    
204    
205  int  int
206  listview_del_item( listview_ctrl_t ctx, int pos )  listview_del_column (listview_ctrl_t ctx, int pos)
207    {
208        ctx->cols--;
209        return ListView_DeleteColumn (ctx->ctrl, pos)? 0 : 1;
210    }
211    
212    
213    /* Delete a single item from @ctx at position @pos. */
214    int
215    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 297  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 319  listview_select_all (listview_ctrl_t ctx Line 361  listview_select_all (listview_ctrl_t ctx
361    
362    
363  void  void
364    listview_deselect_all (listview_ctrl_t ctx)
365    {
366        ListView_SetItemState (ctx->ctrl, -1, ~LVNI_SELECTED, LVNI_SELECTED);
367    }
368    
369    
370    void
371  listview_select_one (listview_ctrl_t ctx, int pos)  listview_select_one (listview_ctrl_t ctx, int pos)
372  {  {
373      ListView_SetItemState (ctx->ctrl, pos, LVIS_SELECTED|LVIS_FOCUSED, LVIS_FOCUSED|LVIS_SELECTED);      ListView_SetItemState (ctx->ctrl, pos, LVIS_SELECTED|LVIS_FOCUSED, LVIS_FOCUSED|LVIS_SELECTED);
# Line 350  listview_find (listview_ctrl_t ctx, cons Line 399  listview_find (listview_ctrl_t ctx, cons
399      return pos;      return pos;
400  }  }
401    
 /** Some functions to make the handling with TreeView Controls easier **/  
 int  
 treeview_add_item( HWND tree, HTREEITEM parent, const char *text )  
 {        
     TVINSERTSTRUCT tvis;  
           
     memset( &tvis, 0, sizeof tvis );  
     tvis.hParent = parent;  
     tvis.hInsertAfter = TVI_LAST;  
     tvis.item.mask = TVIF_TEXT;  
     tvis.item.pszText = (char *)text;  
     TreeView_InsertItem( tree, &tvis );  
402    
403      return 0;  void
404  } /* treeview_add_item */  listview_setview (listview_ctrl_t ctx, DWORD view)
405    {
406        DWORD style = GetWindowLong (ctx->ctrl, GWL_STYLE);
407        if ((style & LVS_TYPEMASK) != view)
408            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.48  
changed lines
  Added in v.181

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26