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

Annotation of /trunk/Src/wptProgressDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 47 - (hide annotations)
Mon Oct 31 14:04:59 2005 UTC (19 years, 4 months ago) by werner
File size: 3874 byte(s)
Minor changes; compiles now but gettext is still missing.

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 <windows.h>
27     #include <commctrl.h>
28    
29 werner 47 #include "resource.h"
30 werner 36 #include "wptGPG.h"
31     #include "wptTypes.h"
32     #include "wptCommonCtl.h"
33     #include "wptW32API.h"
34     #include "wptContext.h"
35     #include "wptVersion.h"
36     #include "wptErrors.h"
37    
38     /* Handle to the dialog window. */
39     static HWND progress_dlg = NULL;
40    
41    
42     /* Dialog procedure to show the progress of an operation. */
43     static BOOL CALLBACK
44     progress_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
45     {
46     static progress_filter_s * pfx = NULL;
47    
48     switch (msg) {
49     case WM_INITDIALOG:
50     pfx = (struct progress_filter_s *)lparam;
51     if (!pfx)
52     BUG (0);
53     progress_dlg = dlg;
54     pfx->dlg = dlg;
55     SendDlgItemMessage (dlg, IDC_PROGRESS_BAR,
56     PBM_SETRANGE, 0, MAKELPARAM (0, 100));
57     SetDlgItemInt (pfx->dlg, IDC_PROGRESS_TOTAL, pfx->total, FALSE);
58     SetDlgItemInt (pfx->dlg, IDC_PROGRESS_CURR, pfx->curr, FALSE);
59     SetDlgItemText (pfx->dlg, IDC_PROGRESS_WHAT, pfx->what);
60     center_window2 (dlg, NULL, HWND_TOPMOST);
61     center_window (dlg, NULL);
62     SetForegroundWindow (dlg);
63     return TRUE;
64     }
65     return FALSE;
66     }
67    
68    
69     /* Thread to start the progress dialog.
70     @opaque contains the context for the dialog. */
71     static DWORD WINAPI
72     progress_cb_thread (void *opaque)
73     {
74     struct progress_filter_s *pfx = (struct progress_filter_s *)opaque;
75    
76     DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_PROGRESS,
77     pfx? pfx->hwnd : GetActiveWindow (),
78     progress_dlg_proc, (LPARAM)opaque);
79     ExitThread (0);
80     return TRUE;
81     }
82    
83    
84     /* Close the progress dialog (if still open) and close all handles in @pfx. */
85     void
86     progress_cleanup (progress_filter_s *pfx)
87     {
88     EndDialog (progress_dlg, TRUE);
89     if (!pfx)
90     return;
91     if (pfx->dlg) {
92     EndDialog (pfx->dlg, TRUE);
93     pfx->dlg = NULL;
94     }
95     if (pfx->thread_hd) {
96     CloseHandle (pfx->thread_hd);
97     pfx->thread_hd = NULL;
98     }
99     pfx->curr = 0;
100     pfx->total = 0;
101     pfx->error = 0;
102     memset (pfx, 0, sizeof *pfx); /*XXX: does this really work? */
103     }
104    
105    
106     /* Generic callback for operations with a progress bar. */
107     void
108     progress_callback (void *opaque, const char *what, int type, int off, int max)
109     {
110     struct progress_filter_s *pfx = (struct progress_filter_s *)opaque;
111     DWORD tid;
112    
113     log_debug ("progress enter %d %d\r\n", off, max);
114     if (!pfx || pfx->error)
115     return;
116     if (what)
117     pfx->what = what;
118     pfx->curr = off;
119     pfx->total = max;
120     if (!off && !pfx->thread_hd) {
121     pfx->thread_hd = CreateThread (NULL, 0, progress_cb_thread, (void *)pfx, 0, &tid);
122     if (!pfx->thread_hd) {
123     msg_box (NULL, _("Could not create progress thread."), _("WinPT"), MB_ERR);
124     pfx->error = 1;
125     return;
126     }
127     log_debug ("progress_callback: started thread %08lX\r\n", tid);
128     }
129     else if (pfx->dlg != NULL) {
130     size_t n = pfx->curr * 100 / pfx->total;
131     SendDlgItemMessage (pfx->dlg, IDC_PROGRESS_BAR, PBM_SETPOS, (WPARAM)n, 0);
132     SetDlgItemInt (pfx->dlg, IDC_PROGRESS_CURR, pfx->curr, FALSE);
133     }
134     if (off >= max) {
135     progress_cleanup (pfx);
136     }
137     }

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26