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

Annotation of /trunk/Src/wptProgressDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 48 - (hide annotations)
Mon Oct 31 21:14:11 2005 UTC (19 years, 4 months ago) by werner
File size: 3853 byte(s)
More changes.  Compiles again but there are at least gettext issues with
w32-gettext.c.  I can't get a gpg-error build with ENABLE_NLS.

1 werner 36 /* wptProgressDlg.cpp - Support for the GPG progress status
2     * Copyright (C) 2003, 2004, 2005 Timo Schulz
3     *
4     * This file is part of WinPT.
5     *
6     * WinPT is free software; you can redistribute it and/or modify
7     * it under the terms of the GNU General Public License as published by
8     * the Free Software Foundation; either version 2 of the License, or
9     * (at your option) any later version.
10     *
11     * WinPT is distributed in the hope that it will be useful,
12     * but WITHOUT ANY WARRANTY; without even the implied warranty of
13     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     * GNU General Public License for more details.
15     *
16     * You should have received a copy of the GNU General Public License
17     * along with WinPT; if not, write to the Free Software Foundation,
18     * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
19     */
20    
21     #ifdef HAVE_CONFIG_H
22     #include <config.h>
23     #endif
24    
25     #include <windows.h>
26     #include <commctrl.h>
27    
28 werner 47 #include "resource.h"
29 werner 36 #include "wptGPG.h"
30     #include "wptTypes.h"
31     #include "wptCommonCtl.h"
32     #include "wptW32API.h"
33     #include "wptContext.h"
34     #include "wptVersion.h"
35     #include "wptErrors.h"
36    
37     /* Handle to the dialog window. */
38     static HWND progress_dlg = NULL;
39    
40    
41     /* Dialog procedure to show the progress of an operation. */
42     static BOOL CALLBACK
43     progress_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
44     {
45     static progress_filter_s * pfx = NULL;
46    
47     switch (msg) {
48     case WM_INITDIALOG:
49     pfx = (struct progress_filter_s *)lparam;
50     if (!pfx)
51     BUG (0);
52     progress_dlg = dlg;
53     pfx->dlg = dlg;
54     SendDlgItemMessage (dlg, IDC_PROGRESS_BAR,
55     PBM_SETRANGE, 0, MAKELPARAM (0, 100));
56     SetDlgItemInt (pfx->dlg, IDC_PROGRESS_TOTAL, pfx->total, FALSE);
57     SetDlgItemInt (pfx->dlg, IDC_PROGRESS_CURR, pfx->curr, FALSE);
58     SetDlgItemText (pfx->dlg, IDC_PROGRESS_WHAT, pfx->what);
59     center_window2 (dlg, NULL, HWND_TOPMOST);
60     center_window (dlg, NULL);
61     SetForegroundWindow (dlg);
62     return TRUE;
63     }
64     return FALSE;
65     }
66    
67    
68     /* Thread to start the progress dialog.
69     @opaque contains the context for the dialog. */
70     static DWORD WINAPI
71     progress_cb_thread (void *opaque)
72     {
73     struct progress_filter_s *pfx = (struct progress_filter_s *)opaque;
74    
75     DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_PROGRESS,
76     pfx? pfx->hwnd : GetActiveWindow (),
77     progress_dlg_proc, (LPARAM)opaque);
78     ExitThread (0);
79     return TRUE;
80     }
81    
82    
83     /* Close the progress dialog (if still open) and close all handles in @pfx. */
84     void
85     progress_cleanup (progress_filter_s *pfx)
86     {
87     EndDialog (progress_dlg, TRUE);
88     if (!pfx)
89     return;
90     if (pfx->dlg) {
91     EndDialog (pfx->dlg, TRUE);
92     pfx->dlg = NULL;
93     }
94     if (pfx->thread_hd) {
95     CloseHandle (pfx->thread_hd);
96     pfx->thread_hd = NULL;
97     }
98     pfx->curr = 0;
99     pfx->total = 0;
100     pfx->error = 0;
101     memset (pfx, 0, sizeof *pfx); /*XXX: does this really work? */
102     }
103    
104    
105     /* Generic callback for operations with a progress bar. */
106     void
107     progress_callback (void *opaque, const char *what, int type, int off, int max)
108     {
109     struct progress_filter_s *pfx = (struct progress_filter_s *)opaque;
110     DWORD tid;
111    
112     log_debug ("progress enter %d %d\r\n", off, max);
113     if (!pfx || pfx->error)
114     return;
115     if (what)
116     pfx->what = what;
117     pfx->curr = off;
118     pfx->total = max;
119     if (!off && !pfx->thread_hd) {
120     pfx->thread_hd = CreateThread (NULL, 0, progress_cb_thread, (void *)pfx, 0, &tid);
121     if (!pfx->thread_hd) {
122     msg_box (NULL, _("Could not create progress thread."), _("WinPT"), MB_ERR);
123     pfx->error = 1;
124     return;
125     }
126     log_debug ("progress_callback: started thread %08lX\r\n", tid);
127     }
128     else if (pfx->dlg != NULL) {
129     size_t n = pfx->curr * 100 / pfx->total;
130     SendDlgItemMessage (pfx->dlg, IDC_PROGRESS_BAR, PBM_SETPOS, (WPARAM)n, 0);
131     SetDlgItemInt (pfx->dlg, IDC_PROGRESS_CURR, pfx->curr, FALSE);
132     }
133     if (off >= max) {
134     progress_cleanup (pfx);
135     }
136     }

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26