/[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 77 by twoaday, Mon Nov 14 15:01:01 2005 UTC revision 133 by twoaday, Mon Jan 9 09:15:29 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
# Line 37  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      *ctx = c;      *ctx = c;
53      return 0;      return 0;
54  } /* listview_new */  } /* listview_new */
55    
56    
57  void  void
58  listview_release( listview_ctrl_t ctx )  listview_release (listview_ctrl_t ctx)
59  {  {
60      if( ctx ) {      if (!ctx)
61          ctx->cols = 0;          return;
62          ctx->ctrl = NULL;  
63          ctx->items = 0;      ctx->cols = 0;
64          delete ctx;      ctx->ctrl = NULL;
65          ctx = NULL;      ctx->items = 0;
66      }      if (ctx->hil)
67            ImageList_Destroy (ctx->hil);
68        delete ctx;
69  } /* listview_release */  } /* listview_release */
70    
71    
# Line 92  listview_add_item_pos (listview_ctrl_t c Line 96  listview_add_item_pos (listview_ctrl_t c
96    
97      memset (&lvi, 0, sizeof lvi);      memset (&lvi, 0, sizeof lvi);
98      lvi.iItem = pos;      lvi.iItem = pos;
99      rc = ListView_InsertItem (ctx->ctrl, &lvi);      if (ListView_InsertItem (ctx->ctrl, &lvi) != pos)
100      if (rc == -1)          rc = -1;
         rc = 1;  
101      ctx->items++;      ctx->items++;
102      return rc;      return rc;
103  }  }
# Line 118  listview_add_item( listview_ctrl_t ctx, Line 121  listview_add_item( listview_ctrl_t ctx,
121    
122    
123  int  int
124    listview_add_item_image (listview_ctrl_t ctx, const char *text, int image)
125    {
126        int rc = 0;
127        LV_ITEM lvi;
128    
129        memset( &lvi, 0, sizeof lvi );
130        lvi.mask = LVIF_TEXT | LVIF_IMAGE;
131        lvi.pszText = (char *)text;
132        lvi.iImage = image;
133        rc = ListView_InsertItem (ctx->ctrl, &lvi);
134        if (rc == -1)
135            rc = 1;
136        ctx->items++;
137        return rc;
138    }
139    
140    
141    int
142  listview_add_item2 (listview_ctrl_t ctx, const char *text, void *magic)  listview_add_item2 (listview_ctrl_t ctx, const char *text, void *magic)
143  {  {
144      int rc = 0;      int rc = 0;
# Line 181  listview_count_items( listview_ctrl_t ct Line 202  listview_count_items( listview_ctrl_t ct
202    
203    
204  int  int
205    listview_del_column (listview_ctrl_t ctx, int pos)
206    {
207        ctx->cols--;
208        return ListView_DeleteColumn (ctx->ctrl, pos)? 0 : 1;
209    }
210    
211    
212    int
213  listview_del_item( listview_ctrl_t ctx, int pos )  listview_del_item( listview_ctrl_t ctx, int pos )
214  {  {
215      int rc = 0;      int rc = 0;
# Line 351  listview_find (listview_ctrl_t ctx, cons Line 380  listview_find (listview_ctrl_t ctx, cons
380      return pos;      return pos;
381  }  }
382    
 /** 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 );  
383    
384      return 0;  void
385  } /* treeview_add_item */  listview_setview (listview_ctrl_t ctx, DWORD view)
386    {
387        DWORD style = GetWindowLong (ctx->ctrl, GWL_STYLE);
388        if ((style & LVS_TYPEMASK) != view)
389            SetWindowLong (ctx->ctrl, GWL_STYLE, (style & ~LVS_TYPEMASK) | view);
390    }
391    
392    
393    void
394    listview_set_image_list (listview_ctrl_t ctx, HICON *ico, DWORD nicons)
395    {
396        HIMAGELIST hil;
397        DWORD i;
398    
399        hil = ImageList_Create (16, 16, ILC_COLOR16, nicons, 1);
400        for (i=0; i < nicons; i++)
401            ImageList_AddIcon (hil, ico[i]);
402        ListView_SetImageList (ctx->ctrl, hil, LVSIL_SMALL);
403    }
404        

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26