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

Contents of /trunk/Src/wptListView.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 20 - (show annotations)
Wed Jul 27 11:17:22 2005 UTC (19 years, 7 months ago) by twoaday
File size: 7736 byte(s)
2005-07-22  Timo Schulz  <twoaday@freakmail.de>
 
        * wptMainProc.cpp (winpt_main_proc): Take care for shutdown
        messages and make sure WinPT make a keyring backup in this case.
        * wptGPGME.cpp (keycache_reload): Do not rebuild the signature
        cache each time. Just do it on startup.
        * wptKeyManager.cpp (km_key_is_v3): Use new ATTR_VERSION.
        * wptKeyEditDlgs.cpp (keyedit_main_dlg_proc): Assume the v3 flag
        was set by the calling function.
        * wptKeyGenDlg.cpp (keygen_wizard_dlg_proc): Ask for backups.
        (keygen_dlg_proc): Only add the generated key to the keycache
        and do not reload the entire cache.
        * wptKeyManager.cpp (km_delete_keys): Store the number of keys
        because in each loop iteration it will be new calculated.
        * wptListView.cpp (listview_del_items): Likewise.
        * wptKeyManagerDlg.cpp (keymanager_dlg_proc): Directly add the
        generated key to the list instead of reloading the entire cache.
        * wptKeyEditDlgs.cpp (parse_preflist): Support fpr SHAnnn.


1 /* wptListView.cpp - Dynamic list view control
2 * Copyright (C) 2000-2004 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 #include <stdio.h>
23 #include <windows.h>
24 #include <commctrl.h>
25
26 #include "wptCommonCtl.h"
27 #include "wptW32API.h"
28 #include "wptVersion.h"
29 #include "wptErrors.h"
30 #include "wptTypes.h"
31 #include "wptGPG.h"
32 #include "wptKeylist.h"
33 #include "../resource.h"
34
35
36 int
37 listview_new( listview_ctrl_t *ctx )
38 {
39 struct listview_ctrl_s *c;
40
41 c = new struct listview_ctrl_s;
42 if( !c )
43 BUG( NULL );
44 c->cols = 0;
45 c->items = 0;
46 c->ctrl = NULL;
47 *ctx = c;
48 return 0;
49 } /* listview_new */
50
51
52 void
53 listview_release( listview_ctrl_t ctx )
54 {
55 if( ctx ) {
56 ctx->cols = 0;
57 ctx->ctrl = NULL;
58 ctx->items = 0;
59 delete ctx;
60 ctx = NULL;
61 }
62 } /* listview_release */
63
64
65 int
66 listview_add_column( listview_ctrl_t ctx, listview_column_t col )
67 {
68 int rc = 0;
69 LV_COLUMN lvc;
70
71 memset( &lvc, 0, sizeof lvc );
72 lvc.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;
73 lvc.pszText = col->fieldname;
74 lvc.cx = col->width;
75 lvc.fmt = LVCFMT_LEFT;
76 lvc.iSubItem = col->pos;
77 if( ListView_InsertColumn( ctx->ctrl, col->pos, &lvc ) == -1 )
78 rc = 1;
79 ctx->cols++;
80 return rc;
81 } /* listview_add_column */
82
83
84 int
85 listview_add_item_pos (listview_ctrl_t ctx, int pos)
86 {
87 int rc = 0;
88 LV_ITEM lvi;
89
90 memset (&lvi, 0, sizeof lvi);
91 lvi.iItem = pos;
92 rc = ListView_InsertItem (ctx->ctrl, &lvi);
93 if (rc == -1)
94 rc = 1;
95 ctx->items++;
96 return rc;
97 }
98
99
100 int
101 listview_add_item( listview_ctrl_t ctx, const char *text )
102 {
103 int rc = 0;
104 LV_ITEM lvi;
105
106 memset( &lvi, 0, sizeof lvi );
107 lvi.mask = LVIF_TEXT;
108 lvi.pszText = (char *)text;
109 rc = ListView_InsertItem( ctx->ctrl, &lvi );
110 if( rc == -1 )
111 rc = 1;
112 ctx->items++;
113 return rc;
114 } /* listview_add_item */
115
116
117 int
118 listview_add_item2( listview_ctrl_t ctx, const char * text, void * magic )
119 {
120 int rc = 0;
121 LV_ITEM lvi;
122
123 memset( &lvi, 0, sizeof lvi );
124 lvi.mask = LVIF_TEXT | LVIF_PARAM;
125 lvi.pszText = (char *)text;
126 lvi.lParam = (LPARAM)magic;
127 rc = ListView_InsertItem( ctx->ctrl, &lvi );
128 if( rc == -1 )
129 rc = 1;
130 ctx->items++;
131 return rc;
132 } /* listview_add_item2 */
133
134
135 void
136 listview_add_sub_item( listview_ctrl_t ctx, int pos, int col, const char *text )
137 {
138 ListView_SetItemText( ctx->ctrl, pos, col, (char *)text );
139 } /* listview_add_sub_item */
140
141
142 int
143 listview_count_items( listview_ctrl_t ctx, int curr_sel )
144 {
145 int n;
146
147 n = curr_sel? ListView_GetSelectedCount( ctx->ctrl ) :
148 ListView_GetItemCount( ctx->ctrl );
149 return n;
150 } /* listview_count_items */
151
152
153 int
154 listview_del_item( listview_ctrl_t ctx, int pos )
155 {
156 int rc = 0;
157
158 if( ListView_DeleteItem( ctx->ctrl, pos ) == -1 )
159 rc = 1;
160 return rc;
161 } /* listview_del_item */
162
163
164 int
165 listview_del_items( listview_ctrl_t ctx )
166 {
167 int i, n;
168
169 /* delete all selected entries */
170 n = listview_count_items (ctx, 0);
171 for( i = n; i > 0; i-- ) {
172 if ( listview_get_item_state( ctx, i ) )
173 listview_del_item( ctx, i );
174 }
175 return 0;
176 } /* listview_del_items */
177
178
179 int
180 listview_del_all( listview_ctrl_t ctx )
181 {
182 int rc = 0;
183
184 if( ListView_DeleteAllItems( ctx->ctrl ) == FALSE )
185 rc = 1;
186 return rc;
187 } /* listview_del_all */
188
189
190 int
191 listview_get_item_state( listview_ctrl_t ctx, int pos )
192 {
193 return ListView_GetItemState( ctx->ctrl, pos, LVIS_SELECTED );
194 } /* listview_get_item_state */
195
196
197 int
198 listview_sort_items( listview_ctrl_t ctx, int sortby, listview_cmp sort_cb )
199 {
200 HWND hheader;
201 HDITEM hdi;
202 int idx;
203
204 ListView_SortItems (ctx->ctrl, sort_cb, sortby);
205 hheader = ListView_GetHeader (ctx->ctrl);
206 if (!hheader)
207 return 0;
208
209 /* Remove image from all header fields */
210 memset (&hdi, 0, sizeof(hdi));
211
212 for (int i=0; i < 7; i++) {
213 hdi.mask = HDI_FORMAT;
214 Header_GetItem (hheader, i, &hdi);
215 hdi.fmt &= ~HDF_IMAGE;
216 Header_SetItem (hheader, i, &hdi);
217 }
218
219 switch (sortby & ~KEYLIST_SORT_DESC) {
220 case GPGME_ATTR_USERID: idx = 0; break;
221 case GPGME_ATTR_KEYID: idx = 1; break;
222 case GPGME_ATTR_IS_SECRET: idx = 2; break;
223 case GPGME_ATTR_LEN: idx = 3; break;
224 case GPGME_ATTR_VALIDITY: idx = 5; break;
225 case GPGME_ATTR_OTRUST: idx = 6; break;
226 case GPGME_ATTR_CREATED: idx = 7; break;
227 case GPGME_ATTR_ALGO: idx = 8; break;
228 default: idx = 0; break;
229 }
230
231 /* Set image to currently sorted field */
232 memset (&hdi, 0, sizeof(hdi));
233 hdi.mask = HDI_IMAGE | HDI_FORMAT;
234 Header_GetItem (hheader, idx, &hdi);
235 hdi.fmt |= HDF_IMAGE | HDF_BITMAP_ON_RIGHT;
236 hdi.iImage = imagelist_getindex((sortby & KEYLIST_SORT_DESC) ?
237 IMI_SORT_DOWNARROW : IMI_SORT_UPARROW);
238 Header_SetItem (hheader, idx, &hdi);
239 return 0;
240 } /* listview_sort_items */
241
242
243 int
244 listview_get_curr_pos( listview_ctrl_t ctx )
245 {
246 return ListView_GetNextItem( ctx->ctrl, -1, LVNI_SELECTED );
247 } /* listview_get_curr_pos */
248
249
250 int
251 listview_get_item_text (listview_ctrl_t ctx, int pos, int col, char *text,
252 int maxbytes)
253 {
254 if (pos == -1) {
255 pos = listview_get_curr_pos (ctx);
256 if (pos == -1)
257 return -1;
258 }
259 ListView_GetItemText (ctx->ctrl, pos, col, text, maxbytes);
260 return 0;
261 } /* listview_get_item_text */
262
263
264 void
265 listview_set_ext_style( listview_ctrl_t ctx )
266 {
267 ListView_SetExtendedListViewStyle( ctx->ctrl, LVS_EX_FULLROWSELECT );
268 } /* listview_set_ext_style */
269
270
271 int
272 listview_set_column_order( listview_ctrl_t ctx, int *array )
273 {
274 return ListView_SetColumnOrderArray( ctx->ctrl, ctx->cols, array );
275 } /* listview_set_column_order */
276
277
278 void
279 listview_select_all (listview_ctrl_t ctx)
280 {
281 ListView_SetItemState( ctx->ctrl, -1, LVIS_SELECTED, LVIS_SELECTED );
282 } /* listview_select_all */
283
284
285 void
286 listview_select_one (listview_ctrl_t ctx, int pos)
287 {
288 ListView_SetItemState (ctx->ctrl, pos, LVIS_SELECTED|LVIS_FOCUSED, LVIS_FOCUSED|LVIS_SELECTED);
289 }
290
291
292 int
293 listview_find (listview_ctrl_t ctx, const char * str)
294 {
295 LVFINDINFO inf;
296 int pos;
297
298 memset (&inf, 0, sizeof inf);
299 inf.flags = LVFI_STRING|LVFI_PARTIAL;
300 inf.psz = str;
301 pos = ListView_FindItem (ctx->ctrl, -1, &inf);
302 return pos;
303 }
304
305 /** Some functions to make the handling with TreeView Controls easier **/
306 int
307 treeview_add_item( HWND tree, HTREEITEM parent, const char *text )
308 {
309 TVINSERTSTRUCT tvis;
310
311 memset( &tvis, 0, sizeof tvis );
312 tvis.hParent = parent;
313 tvis.hInsertAfter = TVI_LAST;
314 tvis.item.mask = TVIF_TEXT;
315 tvis.item.pszText = (char *)text;
316 TreeView_InsertItem( tree, &tvis );
317
318 return 0;
319 } /* treeview_add_item */

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26