/[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 2 by twoaday, Mon Jan 31 11:02:21 2005 UTC revision 28 by twoaday, Thu Oct 20 12:35:59 2005 UTC
# Line 1  Line 1 
1  /* wptListView.cpp - Dynamic list view control  /* wptListView.cpp - Dynamic list view control
2   *      Copyright (C) 2000-2004 Timo Schulz   *      Copyright (C) 2000-2005 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  #include <stdio.h>  #include <stdio.h>
22  #include <windows.h>  #include <windows.h>
23  #include <commctrl.h>  #include <commctrl.h>
# Line 63  listview_release( listview_ctrl_t ctx ) Line 62  listview_release( listview_ctrl_t ctx )
62    
63    
64  int  int
65  listview_add_column( listview_ctrl_t ctx, listview_column_t col )  listview_add_column (listview_ctrl_t ctx, listview_column_t col)
66  {        {      
67      int rc = 0;      int rc = 0;
68      LV_COLUMN lvc;      LV_COLUMN lvc;
# Line 74  listview_add_column( listview_ctrl_t ctx Line 73  listview_add_column( listview_ctrl_t ctx
73      lvc.cx = col->width;      lvc.cx = col->width;
74      lvc.fmt = LVCFMT_LEFT;      lvc.fmt = LVCFMT_LEFT;
75      lvc.iSubItem = col->pos;      lvc.iSubItem = col->pos;
76      if( ListView_InsertColumn( ctx->ctrl, col->pos, &lvc ) == -1 )      if( ListView_InsertColumn (ctx->ctrl, col->pos, &lvc) == -1)
77          rc = 1;          rc = 1;
78      ctx->cols++;      ctx->cols++;
79      return rc;      return rc;
80  } /* listview_add_column */  } /* listview_add_column */
81    
82    
83    int
84    listview_add_item_pos (listview_ctrl_t ctx, int pos)
85    {
86        int rc = 0;
87        LV_ITEM lvi;
88    
89        memset (&lvi, 0, sizeof lvi);
90        lvi.iItem = pos;
91        rc = ListView_InsertItem (ctx->ctrl, &lvi);
92        if (rc == -1)
93            rc = 1;
94        ctx->items++;
95        return rc;
96    }
97    
98    
99  int  int
100  listview_add_item( listview_ctrl_t ctx, const char *text )  listview_add_item( listview_ctrl_t ctx, const char *text )
101  {  {
# Line 99  listview_add_item( listview_ctrl_t ctx, Line 114  listview_add_item( listview_ctrl_t ctx,
114    
115    
116  int  int
117  listview_add_item2( listview_ctrl_t ctx, const char * text, void * magic )  listview_add_item2 (listview_ctrl_t ctx, const char *text, void *magic)
118  {  {
119      int rc = 0;      int rc = 0;
120      LV_ITEM lvi;      LV_ITEM lvi;
# Line 116  listview_add_item2( listview_ctrl_t ctx, Line 131  listview_add_item2( listview_ctrl_t ctx,
131  } /* listview_add_item2 */  } /* listview_add_item2 */
132    
133    
134    void*
135    listview_get_item2 (listview_ctrl_t ctx, int pos)
136    {
137        LVITEM lvi;
138    
139        memset (&lvi, 0, sizeof lvi);
140        lvi.mask = LVIF_PARAM;
141        lvi.iItem = pos;
142        ListView_GetItem (ctx->ctrl, &lvi);
143        return (void*)lvi.lParam;
144    }
145    
146    int
147    listview_set_item2 (listview_ctrl_t ctx, int pos, void *magic)
148    {
149        LVITEM lvi;
150    
151        memset (&lvi, 0, sizeof (lvi));
152        lvi.mask = LVIF_PARAM;
153        lvi.iItem = pos;
154        lvi.lParam = (LPARAM)magic;
155        if (ListView_SetItem (ctx->ctrl, &lvi) == -1)
156            return 1;
157        return 0;
158    }
159    
160    
161  void  void
162  listview_add_sub_item( listview_ctrl_t ctx, int pos, int col, const char *text )  listview_add_sub_item( listview_ctrl_t ctx, int pos, int col, const char *text )
163  {        {      
# Line 148  listview_del_item( listview_ctrl_t ctx, Line 190  listview_del_item( listview_ctrl_t ctx,
190  int  int
191  listview_del_items( listview_ctrl_t ctx )  listview_del_items( listview_ctrl_t ctx )
192  {        {      
193      int n;      int i, n;
194    
195      /* delete all selected entries */      /* delete all selected entries */
196      for( n = 0;  n < listview_count_items( ctx, 0 ); n++ ) {      n = listview_count_items (ctx, 0);
197          if ( listview_get_item_state( ctx, n ) )      for( i = n;  i > 0; i-- ) {
198              listview_del_item( ctx, n );                  if ( listview_get_item_state( ctx, i ) )
199                listview_del_item( ctx, i );        
200      }      }
201      return 0;      return 0;
202  } /* listview_del_items */  } /* listview_del_items */
# Line 200  listview_sort_items( listview_ctrl_t ctx Line 243  listview_sort_items( listview_ctrl_t ctx
243      }      }
244    
245      switch (sortby & ~KEYLIST_SORT_DESC) {      switch (sortby & ~KEYLIST_SORT_DESC) {
246      case GPGME_ATTR_USERID:    idx = 0; break;      case KEY_SORT_USERID:    idx = 0; break;
247      case GPGME_ATTR_KEYID:     idx = 1; break;      case KEY_SORT_KEYID:     idx = 1; break;
248      case GPGME_ATTR_IS_SECRET: idx = 2; break;      case KEY_SORT_IS_SECRET: idx = 2; break;
249      case GPGME_ATTR_LEN:       idx = 3; break;      case KEY_SORT_LEN:       idx = 3; break;
250      case GPGME_ATTR_VALIDITY:  idx = 5; break;      case KEY_SORT_VALIDITY:  idx = 5; break;
251      case GPGME_ATTR_OTRUST:    idx = 6; break;      case KEY_SORT_OTRUST:    idx = 6; break;
252      case GPGME_ATTR_CREATED:   idx = 7; break;      case KEY_SORT_CREATED:   idx = 7; break;
253      case GPGME_ATTR_ALGO:      idx = 8; break;      case KEY_SORT_ALGO:      idx = 8; break;
254      default:                   idx = 0; break;      default:                 idx = 0; break;
255      }      }
256    
257      /* Set image to currently sorted field */      /* Set image to currently sorted field */
# Line 272  listview_select_one (listview_ctrl_t ctx Line 315  listview_select_one (listview_ctrl_t ctx
315  }  }
316    
317    
318    void
319    listview_scroll (listview_ctrl_t ctx, int oldpos, int newpos)
320    {    
321        const int size=14;
322        
323        if (oldpos == -1)
324            oldpos = 0;
325        //log_box ("debug", 0, "oldpos=%d newpos=%d diff=%d", oldpos, newpos, newpos-oldpos);
326        ListView_Scroll (ctx->ctrl, 0, (newpos-oldpos)*size);
327    }
328    
329    
330  int  int
331  listview_find (listview_ctrl_t ctx, const char * str)  listview_find (listview_ctrl_t ctx, const char * str)
332  {  {
333      LVFINDINFO inf;      LVFINDINFO inf;
334      int pos;      int pos;
335    
336      memset (&inf, 0, sizeof inf);      memset (&inf, 0, sizeof (inf));
337      inf.flags = LVFI_STRING|LVFI_PARTIAL;      inf.flags = LVFI_STRING|LVFI_PARTIAL;
338      inf.psz = str;      inf.psz = str;
339      pos = ListView_FindItem (ctx->ctrl, -1, &inf);      pos = ListView_FindItem (ctx->ctrl, -1, &inf);

Legend:
Removed from v.2  
changed lines
  Added in v.28

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26