/[winpt]/trunk/Src/wptListView.cpp
ViewVC logotype

Annotation of /trunk/Src/wptListView.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 129 - (hide annotations)
Fri Dec 30 13:56:10 2005 UTC (19 years, 2 months ago) by twoaday
File size: 8311 byte(s)
2005-12-27  Timo Schulz  <ts@g10code.com>
                                                                                
        * wptListView.cpp (listview_set_view): New.
        (listview_del_column): New.
        * wptW32API.cpp (get_locale_date): New.
        (get_menu_state): New.
        (force_foreground_window): New.
        * wptVerifyList.cpp (strtimestamp): Support for
        locale date formats.
        * wptGPGUtil.cpp (gpg_revoke_cert): Handle bad
        passphrases.
        * wptKeyEditCB.cpp (editkey_command_handler): Immediately
        return when a bad passphrase was submitted.
        * wptKeyRevokersDlg.cpp (keyrevokers_dlg_proc): Change
        column order.
        * wptKeylist.cpp (keylist_upd_col): New.
        * wptKeyManagerDlg.cpp (update_ui_items): Deactivate
        'Revocation' for public keys.
        (translate_menu_strings): s/Revoke/Revoke Cert.
        (modify_listview_columns): New.


1 werner 36 /* wptListView.cpp - Dynamic list view control
2     * Copyright (C) 2000-2005 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 twoaday 129
22 werner 36 #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 werner 47 #include "resource.h"
38 werner 36
39    
40     int
41     listview_new( listview_ctrl_t *ctx )
42     {
43     struct listview_ctrl_s *c;
44    
45     c = new struct listview_ctrl_s;
46     if( !c )
47     BUG( NULL );
48     c->cols = 0;
49     c->items = 0;
50     c->ctrl = NULL;
51     *ctx = c;
52     return 0;
53     } /* listview_new */
54    
55    
56     void
57     listview_release( listview_ctrl_t ctx )
58     {
59     if( ctx ) {
60     ctx->cols = 0;
61     ctx->ctrl = NULL;
62     ctx->items = 0;
63     delete ctx;
64     ctx = NULL;
65     }
66     } /* listview_release */
67    
68    
69     int
70     listview_add_column (listview_ctrl_t ctx, listview_column_t col)
71     {
72     int rc = 0;
73     LV_COLUMN lvc;
74    
75     memset( &lvc, 0, sizeof lvc );
76     lvc.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;
77     lvc.pszText = col->fieldname;
78     lvc.cx = col->width;
79     lvc.fmt = LVCFMT_LEFT;
80     lvc.iSubItem = col->pos;
81     if( ListView_InsertColumn (ctx->ctrl, col->pos, &lvc) == -1)
82     rc = 1;
83     ctx->cols++;
84     return rc;
85     } /* listview_add_column */
86    
87    
88     int
89     listview_add_item_pos (listview_ctrl_t ctx, int pos)
90     {
91     int rc = 0;
92     LV_ITEM lvi;
93    
94     memset (&lvi, 0, sizeof lvi);
95     lvi.iItem = pos;
96     rc = ListView_InsertItem (ctx->ctrl, &lvi);
97     if (rc == -1)
98     rc = 1;
99     ctx->items++;
100     return rc;
101     }
102    
103    
104     int
105     listview_add_item( listview_ctrl_t ctx, const char *text )
106     {
107     int rc = 0;
108     LV_ITEM lvi;
109    
110     memset( &lvi, 0, sizeof lvi );
111     lvi.mask = LVIF_TEXT;
112     lvi.pszText = (char *)text;
113     rc = ListView_InsertItem( ctx->ctrl, &lvi );
114     if( rc == -1 )
115     rc = 1;
116     ctx->items++;
117     return rc;
118     } /* listview_add_item */
119    
120    
121     int
122     listview_add_item2 (listview_ctrl_t ctx, const char *text, void *magic)
123     {
124     int rc = 0;
125     LV_ITEM lvi;
126    
127     memset( &lvi, 0, sizeof lvi );
128     lvi.mask = LVIF_TEXT | LVIF_PARAM;
129     lvi.pszText = (char *)text;
130     lvi.lParam = (LPARAM)magic;
131     rc = ListView_InsertItem( ctx->ctrl, &lvi );
132     if( rc == -1 )
133     rc = 1;
134     ctx->items++;
135     return rc;
136     } /* listview_add_item2 */
137    
138    
139     void*
140     listview_get_item2 (listview_ctrl_t ctx, int pos)
141     {
142     LVITEM lvi;
143    
144     memset (&lvi, 0, sizeof lvi);
145     lvi.mask = LVIF_PARAM;
146     lvi.iItem = pos;
147     ListView_GetItem (ctx->ctrl, &lvi);
148     return (void*)lvi.lParam;
149     }
150    
151     int
152     listview_set_item2 (listview_ctrl_t ctx, int pos, void *magic)
153     {
154     LVITEM lvi;
155    
156     memset (&lvi, 0, sizeof (lvi));
157     lvi.mask = LVIF_PARAM;
158     lvi.iItem = pos;
159     lvi.lParam = (LPARAM)magic;
160     if (ListView_SetItem (ctx->ctrl, &lvi) == -1)
161     return 1;
162     return 0;
163     }
164    
165    
166     void
167     listview_add_sub_item( listview_ctrl_t ctx, int pos, int col, const char *text )
168     {
169     ListView_SetItemText( ctx->ctrl, pos, col, (char *)text );
170     } /* listview_add_sub_item */
171    
172    
173     int
174     listview_count_items( listview_ctrl_t ctx, int curr_sel )
175     {
176     int n;
177    
178     n = curr_sel? ListView_GetSelectedCount( ctx->ctrl ) :
179     ListView_GetItemCount( ctx->ctrl );
180     return n;
181     } /* listview_count_items */
182    
183    
184     int
185 twoaday 129 listview_del_column (listview_ctrl_t ctx, int pos)
186     {
187     ctx->cols--;
188     return ListView_DeleteColumn (ctx->ctrl, pos)? 0 : 1;
189     }
190    
191    
192     int
193 werner 36 listview_del_item( listview_ctrl_t ctx, int pos )
194     {
195     int rc = 0;
196    
197     if( ListView_DeleteItem( ctx->ctrl, pos ) == -1 )
198     rc = 1;
199     return rc;
200     } /* listview_del_item */
201    
202    
203     int
204     listview_del_items( listview_ctrl_t ctx )
205     {
206     int i, n;
207    
208     /* delete all selected entries */
209     n = listview_count_items (ctx, 0);
210     for( i = n; i > 0; i-- ) {
211     if ( listview_get_item_state( ctx, i ) )
212     listview_del_item( ctx, i );
213     }
214     return 0;
215     } /* listview_del_items */
216    
217    
218     int
219     listview_del_all( listview_ctrl_t ctx )
220     {
221     int rc = 0;
222    
223     if( ListView_DeleteAllItems( ctx->ctrl ) == FALSE )
224     rc = 1;
225     return rc;
226     } /* listview_del_all */
227    
228    
229     int
230     listview_get_item_state( listview_ctrl_t ctx, int pos )
231     {
232     return ListView_GetItemState( ctx->ctrl, pos, LVIS_SELECTED );
233     } /* listview_get_item_state */
234    
235    
236     int
237     listview_sort_items( listview_ctrl_t ctx, int sortby, listview_cmp sort_cb )
238     {
239     HWND hheader;
240     HDITEM hdi;
241     int idx;
242    
243     ListView_SortItems (ctx->ctrl, sort_cb, sortby);
244     hheader = ListView_GetHeader (ctx->ctrl);
245     if (!hheader)
246     return 0;
247    
248     /* Remove image from all header fields */
249     memset (&hdi, 0, sizeof(hdi));
250    
251     for (int i=0; i < 7; i++) {
252     hdi.mask = HDI_FORMAT;
253     Header_GetItem (hheader, i, &hdi);
254     hdi.fmt &= ~HDF_IMAGE;
255     Header_SetItem (hheader, i, &hdi);
256     }
257    
258     switch (sortby & ~KEYLIST_SORT_DESC) {
259     case KEY_SORT_USERID: idx = 0; break;
260     case KEY_SORT_KEYID: idx = 1; break;
261     case KEY_SORT_IS_SECRET: idx = 2; break;
262     case KEY_SORT_LEN: idx = 3; break;
263     case KEY_SORT_VALIDITY: idx = 5; break;
264     case KEY_SORT_OTRUST: idx = 6; break;
265     case KEY_SORT_CREATED: idx = 7; break;
266     case KEY_SORT_ALGO: idx = 8; break;
267     default: idx = 0; break;
268     }
269    
270     /* Set image to currently sorted field */
271     memset (&hdi, 0, sizeof(hdi));
272     hdi.mask = HDI_IMAGE | HDI_FORMAT;
273     Header_GetItem (hheader, idx, &hdi);
274     hdi.fmt |= HDF_IMAGE | HDF_BITMAP_ON_RIGHT;
275     hdi.iImage = imagelist_getindex((sortby & KEYLIST_SORT_DESC) ?
276     IMI_SORT_DOWNARROW : IMI_SORT_UPARROW);
277     Header_SetItem (hheader, idx, &hdi);
278     return 0;
279     } /* listview_sort_items */
280    
281    
282     int
283     listview_get_curr_pos( listview_ctrl_t ctx )
284     {
285     return ListView_GetNextItem( ctx->ctrl, -1, LVNI_SELECTED );
286     } /* listview_get_curr_pos */
287    
288    
289     int
290     listview_get_item_text (listview_ctrl_t ctx, int pos, int col, char *text,
291     int maxbytes)
292     {
293     if (pos == -1) {
294     pos = listview_get_curr_pos (ctx);
295     if (pos == -1)
296     return -1;
297     }
298     ListView_GetItemText (ctx->ctrl, pos, col, text, maxbytes);
299     return 0;
300     } /* listview_get_item_text */
301    
302    
303     void
304     listview_set_ext_style( listview_ctrl_t ctx )
305     {
306     ListView_SetExtendedListViewStyle( ctx->ctrl, LVS_EX_FULLROWSELECT );
307     } /* listview_set_ext_style */
308    
309    
310     int
311     listview_set_column_order( listview_ctrl_t ctx, int *array )
312     {
313     return ListView_SetColumnOrderArray( ctx->ctrl, ctx->cols, array );
314     } /* listview_set_column_order */
315    
316    
317     void
318     listview_select_all (listview_ctrl_t ctx)
319     {
320     ListView_SetItemState( ctx->ctrl, -1, LVIS_SELECTED, LVIS_SELECTED );
321     } /* listview_select_all */
322    
323    
324     void
325 twoaday 77 listview_deselect_all (listview_ctrl_t ctx)
326     {
327     ListView_SetItemState (ctx->ctrl, -1, ~LVNI_SELECTED, LVNI_SELECTED);
328     }
329    
330    
331     void
332 werner 36 listview_select_one (listview_ctrl_t ctx, int pos)
333     {
334     ListView_SetItemState (ctx->ctrl, pos, LVIS_SELECTED|LVIS_FOCUSED, LVIS_FOCUSED|LVIS_SELECTED);
335     }
336    
337    
338     void
339     listview_scroll (listview_ctrl_t ctx, int oldpos, int newpos)
340     {
341     const int size=14;
342    
343     if (oldpos == -1)
344     oldpos = 0;
345     //log_box ("debug", 0, "oldpos=%d newpos=%d diff=%d", oldpos, newpos, newpos-oldpos);
346     ListView_Scroll (ctx->ctrl, 0, (newpos-oldpos)*size);
347     }
348    
349    
350     int
351     listview_find (listview_ctrl_t ctx, const char * str)
352     {
353     LVFINDINFO inf;
354     int pos;
355    
356     memset (&inf, 0, sizeof (inf));
357     inf.flags = LVFI_STRING|LVFI_PARTIAL;
358     inf.psz = str;
359     pos = ListView_FindItem (ctx->ctrl, -1, &inf);
360     return pos;
361     }
362    
363 twoaday 129
364     void
365     listview_setview (listview_ctrl_t ctx, DWORD view)
366     {
367     DWORD style = GetWindowLong (ctx->ctrl, GWL_STYLE);
368     if ((style & LVS_TYPEMASK) != view)
369     SetWindowLong (ctx->ctrl, GWL_STYLE, (style & ~LVS_TYPEMASK) | view);
370     }

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26