/[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 28 by twoaday, Thu Oct 20 12:35:59 2005 UTC revision 236 by twoaday, Wed Jun 28 06:59:30 2006 UTC
# Line 1  Line 1 
 /* wptListView.cpp - Dynamic list view control  
  *      Copyright (C) 2000-2005 Timo Schulz  
  *      Copyright (C) 2004 Andreas Jobs  
  *  
  * This file is part of WinPT.  
  *  
  * WinPT is free software; you can redistribute it and/or  
  * modify it under the terms of the GNU General Public License  
  * as published by the Free Software Foundation; either version 2  
  * of the License, or (at your option) any later version.  
  *    
  * WinPT is distributed in the hope that it will be useful,  
  * but WITHOUT ANY WARRANTY; without even the implied warranty of  
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU  
  * General Public License for more details.  
  *  
  * You should have received a copy of the GNU General Public License  
  * along with WinPT; if not, write to the Free Software Foundation,  
  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA  
  */  
 #include <stdio.h>  
 #include <windows.h>  
 #include <commctrl.h>  
   
 #include "wptCommonCtl.h"  
 #include "wptW32API.h"  
 #include "wptVersion.h"  
 #include "wptErrors.h"  
 #include "wptTypes.h"  
 #include "wptGPG.h"  
 #include "wptKeylist.h"  
 #include "../resource.h"  
   
   
 int  
 listview_new( listview_ctrl_t *ctx )  
 {  
     struct listview_ctrl_s *c;  
   
     c = new struct listview_ctrl_s;  
     if( !c )  
         BUG( NULL );  
     c->cols = 0;  
     c->items = 0;  
     c->ctrl = NULL;      
     *ctx = c;  
     return 0;  
 } /* listview_new */  
   
   
 void  
 listview_release( listview_ctrl_t ctx )  
 {  
     if( ctx ) {  
         ctx->cols = 0;  
         ctx->ctrl = NULL;  
         ctx->items = 0;  
         delete ctx;  
         ctx = NULL;  
     }  
 } /* listview_release */  
   
   
 int  
 listview_add_column (listview_ctrl_t ctx, listview_column_t col)  
 {        
     int rc = 0;  
     LV_COLUMN lvc;  
   
     memset( &lvc, 0, sizeof lvc );  
     lvc.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;  
     lvc.pszText = col->fieldname;  
     lvc.cx = col->width;  
     lvc.fmt = LVCFMT_LEFT;  
     lvc.iSubItem = col->pos;  
     if( ListView_InsertColumn (ctx->ctrl, col->pos, &lvc) == -1)  
         rc = 1;  
     ctx->cols++;  
     return rc;  
 } /* listview_add_column */  
   
   
 int  
 listview_add_item_pos (listview_ctrl_t ctx, int pos)  
 {  
     int rc = 0;  
     LV_ITEM lvi;  
   
     memset (&lvi, 0, sizeof lvi);  
     lvi.iItem = pos;  
     rc = ListView_InsertItem (ctx->ctrl, &lvi);  
     if (rc == -1)  
         rc = 1;  
     ctx->items++;  
     return rc;  
 }  
   
   
 int  
 listview_add_item( listview_ctrl_t ctx, const char *text )  
 {  
     int rc = 0;  
     LV_ITEM lvi;  
   
     memset( &lvi, 0, sizeof lvi );  
     lvi.mask = LVIF_TEXT;  
     lvi.pszText = (char *)text;  
     rc = ListView_InsertItem( ctx->ctrl, &lvi );  
     if( rc == -1 )  
         rc = 1;  
     ctx->items++;  
     return rc;  
 } /* listview_add_item */  
   
   
 int  
 listview_add_item2 (listview_ctrl_t ctx, const char *text, void *magic)  
 {  
     int rc = 0;  
     LV_ITEM lvi;  
   
     memset( &lvi, 0, sizeof lvi );  
     lvi.mask = LVIF_TEXT | LVIF_PARAM;  
     lvi.pszText = (char *)text;  
     lvi.lParam = (LPARAM)magic;  
     rc = ListView_InsertItem( ctx->ctrl, &lvi );  
     if( rc == -1 )  
         rc = 1;  
     ctx->items++;  
     return rc;  
 } /* listview_add_item2 */  
   
   
 void*  
 listview_get_item2 (listview_ctrl_t ctx, int pos)  
 {  
     LVITEM lvi;  
   
     memset (&lvi, 0, sizeof lvi);  
     lvi.mask = LVIF_PARAM;  
     lvi.iItem = pos;  
     ListView_GetItem (ctx->ctrl, &lvi);  
     return (void*)lvi.lParam;  
 }  
   
 int  
 listview_set_item2 (listview_ctrl_t ctx, int pos, void *magic)  
 {  
     LVITEM lvi;  
   
     memset (&lvi, 0, sizeof (lvi));  
     lvi.mask = LVIF_PARAM;  
     lvi.iItem = pos;  
     lvi.lParam = (LPARAM)magic;  
     if (ListView_SetItem (ctx->ctrl, &lvi) == -1)  
         return 1;  
     return 0;  
 }  
   
   
 void  
 listview_add_sub_item( listview_ctrl_t ctx, int pos, int col, const char *text )  
 {        
     ListView_SetItemText( ctx->ctrl, pos, col, (char *)text );  
 } /* listview_add_sub_item */  
   
   
 int  
 listview_count_items( listview_ctrl_t ctx, int curr_sel )  
 {        
     int n;  
   
     n = curr_sel? ListView_GetSelectedCount( ctx->ctrl ) :      
                   ListView_GetItemCount( ctx->ctrl );  
     return n;  
 } /* listview_count_items */  
   
   
 int  
 listview_del_item( listview_ctrl_t ctx, int pos )  
 {  
     int rc = 0;  
   
     if( ListView_DeleteItem( ctx->ctrl, pos ) == -1 )  
         rc = 1;  
     return rc;  
 } /* listview_del_item */  
   
   
 int  
 listview_del_items( listview_ctrl_t ctx )  
 {        
     int i, n;  
   
     /* delete all selected entries */  
     n = listview_count_items (ctx, 0);  
     for( i = n;  i > 0; i-- ) {  
         if ( listview_get_item_state( ctx, i ) )  
             listview_del_item( ctx, i );          
     }  
     return 0;  
 } /* listview_del_items */  
   
   
 int  
 listview_del_all( listview_ctrl_t ctx )  
 {        
     int rc = 0;  
   
     if( ListView_DeleteAllItems( ctx->ctrl ) == FALSE )  
         rc = 1;  
     return rc;  
 } /* listview_del_all */  
   
   
 int  
 listview_get_item_state( listview_ctrl_t ctx, int pos )  
 {        
     return ListView_GetItemState( ctx->ctrl, pos, LVIS_SELECTED );  
 } /* listview_get_item_state */  
   
   
 int  
 listview_sort_items( listview_ctrl_t ctx, int sortby, listview_cmp sort_cb )  
 {        
     HWND hheader;  
     HDITEM hdi;  
     int idx;  
   
     ListView_SortItems (ctx->ctrl, sort_cb, sortby);  
     hheader = ListView_GetHeader (ctx->ctrl);  
     if (!hheader)  
         return 0;  
   
     /* Remove image from all header fields */  
     memset (&hdi, 0, sizeof(hdi));  
   
     for (int i=0; i < 7; i++) {  
         hdi.mask = HDI_FORMAT;  
         Header_GetItem (hheader, i, &hdi);  
         hdi.fmt &= ~HDF_IMAGE;  
         Header_SetItem (hheader, i, &hdi);  
     }  
   
     switch (sortby & ~KEYLIST_SORT_DESC) {  
     case KEY_SORT_USERID:    idx = 0; break;  
     case KEY_SORT_KEYID:     idx = 1; break;  
     case KEY_SORT_IS_SECRET: idx = 2; break;  
     case KEY_SORT_LEN:       idx = 3; break;  
     case KEY_SORT_VALIDITY:  idx = 5; break;  
     case KEY_SORT_OTRUST:    idx = 6; break;  
     case KEY_SORT_CREATED:   idx = 7; break;  
     case KEY_SORT_ALGO:      idx = 8; break;  
     default:                 idx = 0; break;  
     }  
   
     /* Set image to currently sorted field */  
     memset (&hdi, 0, sizeof(hdi));  
     hdi.mask = HDI_IMAGE | HDI_FORMAT;  
     Header_GetItem (hheader, idx, &hdi);  
     hdi.fmt |= HDF_IMAGE | HDF_BITMAP_ON_RIGHT;  
     hdi.iImage = imagelist_getindex((sortby & KEYLIST_SORT_DESC) ?  
                                     IMI_SORT_DOWNARROW : IMI_SORT_UPARROW);  
     Header_SetItem (hheader, idx, &hdi);  
     return 0;  
 } /* listview_sort_items */  
   
   
 int  
 listview_get_curr_pos( listview_ctrl_t ctx )  
 {        
     return ListView_GetNextItem( ctx->ctrl, -1, LVNI_SELECTED );  
 } /* listview_get_curr_pos */  
   
   
 int  
 listview_get_item_text (listview_ctrl_t ctx, int pos, int col, char *text,  
                         int maxbytes)  
 {  
     if (pos == -1) {  
         pos = listview_get_curr_pos (ctx);  
         if (pos == -1)  
             return -1;  
     }  
     ListView_GetItemText (ctx->ctrl, pos, col, text, maxbytes);  
     return 0;  
 } /* listview_get_item_text */  
   
   
 void  
 listview_set_ext_style( listview_ctrl_t ctx )  
 {        
     ListView_SetExtendedListViewStyle( ctx->ctrl, LVS_EX_FULLROWSELECT );  
 } /* listview_set_ext_style */  
   
   
 int  
 listview_set_column_order( listview_ctrl_t ctx, int *array )  
 {        
     return ListView_SetColumnOrderArray( ctx->ctrl, ctx->cols, array );  
 } /* listview_set_column_order */  
   
   
 void  
 listview_select_all (listview_ctrl_t ctx)  
 {        
     ListView_SetItemState( ctx->ctrl, -1, LVIS_SELECTED, LVIS_SELECTED );  
 } /* listview_select_all */  
   
   
 void  
 listview_select_one (listview_ctrl_t ctx, int pos)  
 {  
     ListView_SetItemState (ctx->ctrl, pos, LVIS_SELECTED|LVIS_FOCUSED, LVIS_FOCUSED|LVIS_SELECTED);  
 }  
   
   
 void  
 listview_scroll (listview_ctrl_t ctx, int oldpos, int newpos)  
 {      
     const int size=14;  
       
     if (oldpos == -1)  
         oldpos = 0;  
     //log_box ("debug", 0, "oldpos=%d newpos=%d diff=%d", oldpos, newpos, newpos-oldpos);  
     ListView_Scroll (ctx->ctrl, 0, (newpos-oldpos)*size);  
 }  
   
   
 int  
 listview_find (listview_ctrl_t ctx, const char * str)  
 {  
     LVFINDINFO inf;  
     int pos;  
   
     memset (&inf, 0, sizeof (inf));  
     inf.flags = LVFI_STRING|LVFI_PARTIAL;  
     inf.psz = str;  
     pos = ListView_FindItem (ctx->ctrl, -1, &inf);  
     return pos;  
 }  
   
 /** 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 );  
   
     return 0;  
 } /* treeview_add_item */  
1    /* wptListView.cpp - Dynamic list view control
2     *      Copyright (C) 2000-2006 Timo Schulz
3     *      Copyright (C) 2004 Andreas Jobs
4     *
5     * This file is part of WinPT.
6     *
7     * WinPT is free software; you can redistribute it and/or
8     * modify it under the terms of the GNU General Public License
9     * as published by the Free Software Foundation; either version 2
10     * of the License, or (at your option) any later version.
11     *  
12     * WinPT is distributed in the hope that it will be useful,
13     * but WITHOUT ANY WARRANTY; without even the implied warranty of
14     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15     * General Public License for more details.
16     *
17     * You should have received a copy of the GNU General Public License
18     * along with WinPT; if not, write to the Free Software Foundation,
19     * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20     */
21    
22    #ifdef HAVE_CONFIG_H
23    #include <config.h>
24    #endif
25    
26    #include <stdio.h>
27    #include <windows.h>
28    #include <commctrl.h>
29    
30    #include "wptCommonCtl.h"
31    #include "wptW32API.h"
32    #include "wptVersion.h"
33    #include "wptErrors.h"
34    #include "wptTypes.h"
35    #include "wptGPG.h"
36    #include "wptKeylist.h"
37    #include "wptUTF8.h"
38    #include "resource.h"
39    
40    
41    void
42    listview_new (listview_ctrl_t *ctx, HWND ctrl)
43    {
44        struct listview_ctrl_s *c;
45    
46        c = new struct listview_ctrl_s;
47        if (!c)
48            BUG (NULL);
49        c->cols = 0;
50        c->items = 0;
51        c->ctrl = ctrl? ctrl : NULL;
52        c->hil = NULL;
53        c->ext_chkbox = 0;
54        *ctx = c;
55    }
56    
57    
58    void
59    listview_release (listview_ctrl_t ctx)
60    {
61        if (!ctx)
62            return;
63    
64        ctx->cols = 0;
65        ctx->ctrl = NULL;
66        ctx->items = 0;
67        if (ctx->hil)
68            ImageList_Destroy (ctx->hil);
69        delete ctx;
70    }
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
87    listview_add_column (listview_ctrl_t ctx, listview_column_t col)
88    {      
89        int rc = 0;
90        LV_COLUMN lvc;
91    
92        memset( &lvc, 0, sizeof lvc );
93        lvc.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;
94        lvc.pszText = col->fieldname;
95        lvc.cx = col->width;
96        lvc.fmt = LVCFMT_LEFT;
97        lvc.iSubItem = col->pos;
98        if( ListView_InsertColumn (ctx->ctrl, col->pos, &lvc) == -1)
99            rc = 1;
100        ctx->cols++;
101        return rc;
102    }
103    
104    
105    int
106    listview_add_item_pos (listview_ctrl_t ctx, int pos)
107    {
108        int rc = 0;
109        LV_ITEM lvi;
110    
111        memset (&lvi, 0, sizeof lvi);
112        lvi.iItem = pos;
113        if (ListView_InsertItem (ctx->ctrl, &lvi) != pos)
114            rc = -1;
115        ctx->items++;
116        return rc;
117    }
118    
119    
120    int
121    listview_add_item( listview_ctrl_t ctx, const char *text )
122    {
123        int rc = 0;
124        LV_ITEM lvi;
125    
126        memset( &lvi, 0, sizeof lvi );
127        lvi.mask = LVIF_TEXT;
128        lvi.pszText = (char *)text;
129        rc = ListView_InsertItem( ctx->ctrl, &lvi );
130        if( rc == -1 )
131            rc = 1;
132        ctx->items++;
133        return rc;
134    }
135    
136    
137    int
138    listview_add_item_image (listview_ctrl_t ctx, const char *text, int image)
139    {
140        int rc = 0;
141        LV_ITEM lvi;
142    
143        memset( &lvi, 0, sizeof lvi );
144        lvi.mask = LVIF_TEXT | LVIF_IMAGE;
145        lvi.pszText = (char *)text;
146        lvi.iImage = image;
147        rc = ListView_InsertItem (ctx->ctrl, &lvi);
148        if (rc == -1)
149            rc = 1;
150        ctx->items++;
151        return rc;
152    }
153    
154    
155    int
156    listview_add_item2 (listview_ctrl_t ctx, const char *text, void *magic)
157    {
158        int rc = 0;
159        LVITEM lvi;
160    
161        memset (&lvi, 0, sizeof (lvi));
162        lvi.mask = LVIF_TEXT | LVIF_PARAM;
163        lvi.pszText = (char *)text;
164        lvi.lParam = (LPARAM)magic;
165        rc = ListView_InsertItem (ctx->ctrl, &lvi);
166        if (rc == -1)
167            rc = 1;
168        ctx->items++;
169        return rc;
170    }
171    
172    
173    void*
174    listview_get_item2 (listview_ctrl_t ctx, int pos)
175    {
176        LVITEM lvi;
177    
178        memset (&lvi, 0, sizeof lvi);
179        lvi.mask = LVIF_PARAM;
180        lvi.iItem = pos;
181        ListView_GetItem (ctx->ctrl, &lvi);
182        return (void*)lvi.lParam;
183    }
184    
185    int
186    listview_set_item2 (listview_ctrl_t ctx, int pos, void *magic)
187    {
188        LVITEM lvi;
189    
190        memset (&lvi, 0, sizeof (lvi));
191        lvi.mask = LVIF_PARAM;
192        lvi.iItem = pos;
193        lvi.lParam = (LPARAM)magic;
194        if (ListView_SetItem (ctx->ctrl, &lvi) == -1)
195            return 1;
196        return 0;
197    }
198    
199    
200    void
201    listview_add_sub_item (listview_ctrl_t ctx, int pos, int col, const char *text)
202    {
203        ListView_SetItemText (ctx->ctrl, pos, col, (char*)text);
204    }
205    
206    
207    int
208    listview_count_items( listview_ctrl_t ctx, int curr_sel )
209    {      
210        int n;
211    
212        n = curr_sel? ListView_GetSelectedCount( ctx->ctrl ) :    
213                      ListView_GetItemCount( ctx->ctrl );
214        return n;
215    }
216    
217    
218    int
219    listview_del_column (listview_ctrl_t ctx, int pos)
220    {
221        ctx->cols--;
222        return ListView_DeleteColumn (ctx->ctrl, pos)? 0 : 1;
223    }
224    
225    
226    /* Delete a single item from @ctx at position @pos. */
227    int
228    listview_del_item (listview_ctrl_t ctx, int pos)
229    {
230        int rc = 0;
231    
232        if (ListView_DeleteItem (ctx->ctrl, pos) == -1)
233            rc = 1;
234        return rc;
235    }
236    
237    
238    /* Delete all selected items in @ctx. */
239    int
240    listview_del_sel_items (listview_ctrl_t ctx)
241    {      
242        int i, n;
243    
244        n = listview_count_items (ctx, 0);
245        for (i = n;  i > -1; i--) {
246            if (listview_get_item_state (ctx, i))
247                listview_del_item (ctx, i);
248        }
249        return 0;
250    }
251    
252    
253    int
254    listview_del_all_items (listview_ctrl_t ctx)
255    {      
256        int rc = 0;
257    
258        if (ListView_DeleteAllItems (ctx->ctrl) == FALSE)
259            rc = 1;
260        return rc;
261    }
262    
263    
264    /* Return the index of the selected item.
265       Support both selections and checkboxes. */
266    int
267    listview_get_selected_item (listview_ctrl_t lv)
268    {
269        int pos, i;
270        
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
297    listview_sort_items (listview_ctrl_t ctx, int sortby, listview_cmp sort_cb)
298    {      
299        HWND hheader;
300        HDITEM hdi;
301        int idx;
302    
303        ListView_SortItems (ctx->ctrl, sort_cb, sortby);
304        hheader = ListView_GetHeader (ctx->ctrl);
305        if (!hheader)
306            return 0;
307    
308        /* Remove image from all header fields */
309        memset (&hdi, 0, sizeof(hdi));
310    
311        for (int i=0; i < 7; i++) {
312            hdi.mask = HDI_FORMAT;
313            Header_GetItem (hheader, i, &hdi);
314            hdi.fmt &= ~HDF_IMAGE;
315            Header_SetItem (hheader, i, &hdi);
316        }
317    
318        switch (sortby & ~KEYLIST_SORT_DESC) {
319        case KEY_SORT_USERID:    idx = 0; break;
320        case KEY_SORT_KEYID:     idx = 1; break;
321        case KEY_SORT_IS_SECRET: idx = 2; break;
322        case KEY_SORT_LEN:       idx = 3; break;
323        case KEY_SORT_VALIDITY:  idx = 5; break;
324        case KEY_SORT_OTRUST:    idx = 6; break;
325        case KEY_SORT_CREATED:   idx = 7; break;
326        case KEY_SORT_ALGO:      idx = 8; break;
327        default:                 idx = 0; break;
328        }
329    
330        /* Set image to currently sorted field */
331        memset (&hdi, 0, sizeof(hdi));
332        hdi.mask = HDI_IMAGE | HDI_FORMAT;
333        Header_GetItem (hheader, idx, &hdi);  
334        hdi.fmt |= HDF_IMAGE | HDF_BITMAP_ON_RIGHT;
335        if (!ctx->ext_chkbox)
336            hdi.iImage = imagelist_getindex((sortby & KEYLIST_SORT_DESC) ?
337                                            IMI_SORT_DOWNARROW : IMI_SORT_UPARROW);
338        else
339            hdi.iImage = (sortby & KEYLIST_SORT_DESC)? 2 : 3;
340        Header_SetItem (hheader, idx, &hdi);
341        return 0;
342    }
343    
344    
345    int
346    listview_get_curr_pos( listview_ctrl_t ctx )
347    {      
348        return ListView_GetNextItem( ctx->ctrl, -1, LVNI_SELECTED );
349    }
350    
351    
352    int
353    listview_get_item_text (listview_ctrl_t ctx, int pos, int col, char *text,
354                            int maxbytes)
355    {
356        if (pos == -1) {
357            pos = listview_get_curr_pos (ctx);
358            if (pos == -1)
359                return -1;
360        }
361        ListView_GetItemText (ctx->ctrl, pos, col, text, maxbytes);
362        return 0;
363    }
364    
365    
366    /* Use extended style with checkboxes for each item. */
367    void
368    listview_set_chkbox_style (listview_ctrl_t ctx)
369    {
370        ListView_SetExtendedListViewStyle (ctx->ctrl, LVS_EX_CHECKBOXES);
371        ctx->ext_chkbox = 1;
372    }
373    
374    
375    /* Use extended style to select the entire row. */
376    void
377    listview_set_ext_style (listview_ctrl_t ctx)
378    {      
379        ListView_SetExtendedListViewStyle (ctx->ctrl, LVS_EX_FULLROWSELECT);
380    }
381    
382    
383    int
384    listview_set_column_order( listview_ctrl_t ctx, int *array )
385    {      
386        return ListView_SetColumnOrderArray( ctx->ctrl, ctx->cols, array );
387    }
388    
389    
390    void
391    listview_select_all (listview_ctrl_t ctx)
392    {      
393        ListView_SetItemState( ctx->ctrl, -1, LVIS_SELECTED, LVIS_SELECTED );
394    }
395    
396    
397    void
398    listview_deselect_all (listview_ctrl_t ctx)
399    {
400        ListView_SetItemState (ctx->ctrl, -1, ~LVNI_SELECTED, LVNI_SELECTED);
401    }
402    
403    
404    void
405    listview_select_one (listview_ctrl_t ctx, int pos)
406    {
407        ListView_SetItemState (ctx->ctrl, pos, LVIS_SELECTED|LVIS_FOCUSED, LVIS_FOCUSED|LVIS_SELECTED);
408    }
409    
410    
411    void
412    listview_scroll (listview_ctrl_t ctx, int oldpos, int newpos)
413    {    
414        const int size=14;
415        
416        if (oldpos == -1)
417            oldpos = 0;
418        //log_box ("debug", 0, "oldpos=%d newpos=%d diff=%d", oldpos, newpos, newpos-oldpos);
419        ListView_Scroll (ctx->ctrl, 0, (newpos-oldpos)*size);
420    }
421    
422    
423    int
424    listview_find (listview_ctrl_t ctx, const char *str)
425    {
426        LVFINDINFO inf;
427        int pos;
428    
429        /* XXX: allow to make a substring search. */
430        memset (&inf, 0, sizeof (inf));
431        inf.flags = LVFI_STRING|LVFI_PARTIAL;
432        inf.psz = str;
433        pos = ListView_FindItem (ctx->ctrl, -1, &inf);
434        return pos;
435    }
436    
437    
438    void
439    listview_setview (listview_ctrl_t ctx, DWORD view)
440    {
441        DWORD style = GetWindowLong (ctx->ctrl, GWL_STYLE);
442        if ((style & LVS_TYPEMASK) != view)
443            SetWindowLong (ctx->ctrl, GWL_STYLE, (style & ~LVS_TYPEMASK) | view);
444    }
445    
446    
447    void
448    listview_set_image_list (listview_ctrl_t ctx, int cx, int cy,
449                             HICON *ico, DWORD nicons)
450    {
451        HIMAGELIST hil;
452        DWORD i;
453    
454        if (cx == 0 || cy == 0)
455            cx = cy = 16;
456    
457        hil = ImageList_Create (cx, cy, ILC_COLOR8|ILC_MASK, nicons, 1);
458        ImageList_SetBkColor (hil, CLR_NONE);
459        for (i=0; i < nicons; i++)
460            ImageList_AddIcon (hil, ico[i]);    
461        ListView_SetImageList (ctx->ctrl, hil, LVSIL_SMALL);    
462    }

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26