The MinGW.org Installation Manager Tool
リビジョン | c9be7426a933ebd82859d29f4980144108a61742 (tree) |
---|---|
日時 | 2013-06-14 00:55:23 |
作者 | Keith Marshall <keithmarshall@user...> |
コミッター | Keith Marshall |
Implement some GUI progress metering dialogue enhancements.
@@ -1,3 +1,31 @@ | ||
1 | +2013-06-13 Keith Marshall <keithmarshall@users.sourceforge.net> | |
2 | + | |
3 | + Implement some GUI progress metering dialogue enhancements. | |
4 | + | |
5 | + * src/pkgbase.h (pkgProgressMeter): Don't pre-empt private features | |
6 | + of derived progress metering classes; hence, we no longer need this... | |
7 | + (AppWindowMaker): ...as a forward class declaration; delete it. | |
8 | + | |
9 | + * src/guimain.rc (IDD_REPO_UPDATE): Resize, and adjust layout. | |
10 | + (IDD_PROGRESS_VAL, IDD_PROGRESS_MAX, IDD_PROGRESS_PCT): Add these | |
11 | + dialogue box progress counter display elements. | |
12 | + | |
13 | + * src/pkgbind.cpp (pkgRepository::GetPackageList): Adjust style of | |
14 | + progress status messages, to suit reporting via GUI dialogue box or | |
15 | + CLI console, as appropriate. | |
16 | + | |
17 | + * src/guiexec.cpp (ProgressMeterMaker): Redefine class, in terms of... | |
18 | + (PROGRESS_METER_CLASS): ...this new generic class name macro. | |
19 | + Reimplement private members, previously inherited from base class; | |
20 | + adjust class constructor to ensure that they are initialised. | |
21 | + Delete explicit destructor; a default destructor is now sufficient. | |
22 | + (ProgressMeterMaker::SetRange, ProgressMeterMaker::SetValue): | |
23 | + (ProgressMeterMaker::Annotate): Factor out; reimplement them... | |
24 | + | |
25 | + * src/pmihook.cpp: ...in this new file, as generalised methods of... | |
26 | + (PROGRESS_METER_CLASS): ...the class named by this macro. | |
27 | + (PROGRESS_METER_CLASS::PutVal): New private method; implement it. | |
28 | + | |
1 | 29 | 2013-05-31 Keith Marshall <keithmarshall@users.sourceforge.net> |
2 | 30 | |
3 | 31 | Avoid a potential macro definition conflict. |
@@ -43,20 +43,26 @@ | ||
43 | 43 | */ |
44 | 44 | EXTERN_C void dmh_setpty( HWND ); |
45 | 45 | |
46 | -class ProgressMeterMaker: public pkgProgressMeter | |
46 | +#define PROGRESS_METER_CLASS ProgressMeterMaker | |
47 | + | |
48 | +class PROGRESS_METER_CLASS: public pkgProgressMeter | |
47 | 49 | { |
48 | 50 | /* A locally defined class, supporting progress metering |
49 | 51 | * for package catalogue update and load operations. |
50 | 52 | */ |
51 | 53 | public: |
52 | - ProgressMeterMaker( HWND, HWND, AppWindowMaker * ); | |
54 | + PROGRESS_METER_CLASS( HWND, AppWindowMaker * ); | |
55 | + ~PROGRESS_METER_CLASS(){ referrer->DetachProgressMeter( this ); } | |
53 | 56 | |
54 | 57 | virtual int Annotate( const char *, ... ); |
55 | 58 | virtual void SetRange( int, int ); |
56 | 59 | virtual void SetValue( int ); |
57 | 60 | |
58 | - protected: | |
59 | - HWND message_line, progress_bar; | |
61 | + private: | |
62 | + AppWindowMaker *referrer; | |
63 | + HWND annotation, count, lim, frac, progress_bar; | |
64 | + void PutVal( HWND, const char *, ... ); | |
65 | + int total; | |
60 | 66 | }; |
61 | 67 | |
62 | 68 | inline |
@@ -82,55 +88,23 @@ inline void AppWindowMaker::DetachProgressMeter( pkgProgressMeter *meter ) | ||
82 | 88 | } |
83 | 89 | } |
84 | 90 | |
85 | -/* We need to provide a destructor for the abstract base class, from which | |
86 | - * our progress meters are derived; here is as good a place as any. | |
87 | - */ | |
88 | -pkgProgressMeter::~pkgProgressMeter(){ referrer->DetachProgressMeter( this ); } | |
89 | - | |
90 | 91 | /* We must also provide the implementation of our local progress meter class. |
91 | 92 | */ |
92 | -ProgressMeterMaker::ProgressMeterMaker | |
93 | -( HWND annotation, HWND indicator, AppWindowMaker *owner ): | |
94 | -pkgProgressMeter( owner ), message_line( annotation ), progress_bar( indicator ) | |
93 | +#define IDD( DLG, ITEM ) GetDlgItem( DLG, IDD_PROGRESS_##ITEM ) | |
94 | +PROGRESS_METER_CLASS::PROGRESS_METER_CLASS( HWND dlg, AppWindowMaker *owner ): | |
95 | +referrer( owner ), annotation( IDD( dlg, MSG ) ), progress_bar( IDD( dlg, BAR ) ), | |
96 | +count( IDD( dlg, VAL ) ), lim( IDD( dlg, MAX ) ), frac( IDD( dlg, PCT ) ) | |
95 | 97 | { |
96 | 98 | /* Constructor creates an instance of the progress meter class, attaching it |
97 | 99 | * to the main application window, with an initial metering range of 0..100%, |
98 | 100 | * and a starting indicated completion state of 0%. |
99 | 101 | */ |
100 | 102 | owner->AttachProgressMeter( this ); |
101 | - SetRange( 0, 100 ); | |
103 | + SetRange( 0, 1 ); SetValue( 0 ); | |
102 | 104 | SetValue( 0 ); |
103 | 105 | } |
104 | 106 | |
105 | -int ProgressMeterMaker::Annotate( const char *fmt, ... ) | |
106 | -{ | |
107 | - /* Method to add a printf() style annotation to the progress meter dialogue. | |
108 | - */ | |
109 | - va_list argv; | |
110 | - va_start( argv, fmt ); | |
111 | - char annotation[1 + vsnprintf( NULL, 0, fmt, argv )]; | |
112 | - int len = vsnprintf( annotation, sizeof( annotation ), fmt, argv ); | |
113 | - va_end( argv ); | |
114 | - | |
115 | - SendMessage( message_line, WM_SETTEXT, 0, (LPARAM)(annotation) ); | |
116 | - return len; | |
117 | -} | |
118 | - | |
119 | -void ProgressMeterMaker::SetRange( int min, int max ) | |
120 | -{ | |
121 | - /* Method to adjust the range of the progress meter, to represent any | |
122 | - * arbitrary range of discrete values, rather than percentage units. | |
123 | - */ | |
124 | - SendMessage( progress_bar, PBM_SETRANGE, 0, MAKELPARAM( min, max ) ); | |
125 | -} | |
126 | - | |
127 | -void ProgressMeterMaker::SetValue( int value ) | |
128 | -{ | |
129 | - /* Method to update the indicated completion state of a progress meter, | |
130 | - * to represent any arbitrary value within its assigned metering range. | |
131 | - */ | |
132 | - SendMessage( progress_bar, PBM_SETPOS, value, 0 ); | |
133 | -} | |
107 | +#include "pmihook.cpp" | |
134 | 108 | |
135 | 109 | /* Implementation of service routines, for loading the package catalogue |
136 | 110 | * from its defining collection of XML files. |
@@ -215,20 +189,18 @@ static void pkgInvokeInitDataLoad( void *window ) | ||
215 | 189 | * we subject it to progress metering, to ensure that the user is |
216 | 190 | * not left staring at an apparently hung, blank window. |
217 | 191 | */ |
218 | - HWND msg = GetDlgItem( (HWND)(window), IDD_PROGRESS_MSG ); | |
219 | - HWND dlg = GetDlgItem( (HWND)(window), IDD_PROGRESS_BAR ); | |
220 | 192 | AppWindowMaker *app = GetAppWindow( GetParent( (HWND)(window) )); |
221 | 193 | SendMessage( (HWND)(window), |
222 | 194 | WM_SETTEXT, 0, (LPARAM)("Loading Package Catalogue") |
223 | 195 | ); |
224 | - ProgressMeterMaker ui( msg, dlg, app ); | |
196 | + ProgressMeterMaker ui( (HWND)(window), app ); | |
225 | 197 | |
226 | 198 | /* For this activity, we request automatic dismissal of the dialogue, |
227 | 199 | * when loading has been completed; the user will have an opportunity |
228 | 200 | * to countermand this choice, if loading is delayed by the required |
229 | 201 | * download of any missing local catalogue file. |
230 | 202 | */ |
231 | - dlg = GetDlgItem( (HWND)(window), IDD_AUTO_CLOSE_OPTION ); | |
203 | + HWND dlg = GetDlgItem( (HWND)(window), IDD_AUTO_CLOSE_OPTION ); | |
232 | 204 | SendMessage( dlg, WM_SETTEXT, 0, |
233 | 205 | (LPARAM)("Close dialogue automatically, when loading is complete.") |
234 | 206 | ); |
@@ -267,10 +239,8 @@ static void pkgInvokeUpdate( void *window ) | ||
267 | 239 | * subject it to progress metering, to ensure that the user is |
268 | 240 | * not left staring at an apparently hung, blank window. |
269 | 241 | */ |
270 | - HWND msg = GetDlgItem( (HWND)(window), IDD_PROGRESS_MSG ); | |
271 | - HWND dlg = GetDlgItem( (HWND)(window), IDD_PROGRESS_BAR ); | |
272 | 242 | AppWindowMaker *app = GetAppWindow( GetParent( (HWND)(window) )); |
273 | - ProgressMeterMaker ui( msg, dlg, app ); | |
243 | + ProgressMeterMaker ui( (HWND)(window), app ); | |
274 | 244 | |
275 | 245 | /* After setting up the progress meter, we clear out any data |
276 | 246 | * which was previously loaded into the package list, reload it |
@@ -292,8 +262,8 @@ static void pkgInvokeUpdate( void *window ) | ||
292 | 262 | else |
293 | 263 | { /* ...otherwise, we activate the manual dismissal button... |
294 | 264 | */ |
295 | - if( (dlg = GetDlgItem( (HWND)(window), IDOK )) != NULL ) | |
296 | - EnableWindow( dlg, TRUE ); | |
265 | + HWND dlg = GetDlgItem( (HWND)(window), IDOK ); | |
266 | + if( dlg != NULL ) EnableWindow( dlg, TRUE ); | |
297 | 267 | |
298 | 268 | /* ...and notify the user that it must be clicked to continue. |
299 | 269 | */ |
@@ -151,25 +151,30 @@ ID_PKGSTATE_BROKEN ICON DISCARDABLE "state11.ico" | ||
151 | 151 | ID_PKGSTATE_REMOVE ICON DISCARDABLE "state12.ico" |
152 | 152 | ID_PKGSTATE_PURGE ICON DISCARDABLE "state13.ico" |
153 | 153 | |
154 | +#define SS_CTEXTBOX SS_SUNKEN | SS_CENTER | |
155 | +#define ES_VT100 ES_LEFT | ES_READONLY | ES_MULTILINE | ES_AUTOVSCROLL | |
156 | + | |
154 | 157 | /* Template for progress meter dialogue box. |
155 | 158 | */ |
156 | -IDD_REPO_UPDATE DIALOG DISCARDABLE 10, 20, 270, 60 | |
159 | +IDD_REPO_UPDATE DIALOG DISCARDABLE 10, 20, 270, 78 | |
157 | 160 | CAPTION "Update Package Catalogue" |
158 | 161 | STYLE DS_MODALFRAME | DS_SETFONT | WS_POPUP | WS_CAPTION | WS_DLGFRAME |
159 | 162 | FONT 10, "Verdana" |
160 | 163 | BEGIN |
161 | - GROUPBOX "Actions", IDD_CLOSE_OPTIONS, 5, 31, 260, 25 | |
162 | - DEFPUSHBUTTON "Close", IDOK, 219, 39, 40, 12, WS_GROUP | WS_DISABLED | |
164 | + GROUPBOX "Actions", IDD_CLOSE_OPTIONS, 5, 48, 260, 25 | |
165 | + DEFPUSHBUTTON "Close", IDOK, 219, 56, 40, 12, WS_GROUP | WS_DISABLED | |
163 | 166 | AUTOCHECKBOX "Close dialogue automatically, when update is complete.", \ |
164 | - IDD_AUTO_CLOSE_OPTION, 10, 41, 200, 11 | |
167 | + IDD_AUTO_CLOSE_OPTION, 10, 58, 200, 11 | |
168 | + CONTROL "", IDD_PROGRESS_VAL, "STATIC", SS_CTEXTBOX, 6, 19, 96, 10 | |
169 | + CTEXT "of", IDD_PROGRESS_TXT, 102, 19, 18, 10 | |
170 | + CONTROL "", IDD_PROGRESS_MAX, "STATIC", SS_CTEXTBOX, 120, 19, 96, 10 | |
171 | + CTEXT ":", IDD_PROGRESS_TXT, 213, 19, 10, 10 | |
172 | + CONTROL "", IDD_PROGRESS_PCT, "STATIC", SS_CTEXTBOX, 223, 19, 41, 10 | |
165 | 173 | CONTROL "", IDD_PROGRESS_BAR, PROGRESS_CLASS, WS_CHILD \ |
166 | - | PBS_SMOOTH, 6, 20, 258, 10 | |
174 | + | PBS_SMOOTH, 6, 34, 258, 10 | |
167 | 175 | LTEXT "", IDD_PROGRESS_MSG, 7, 6, 256, 12 |
168 | 176 | END |
169 | 177 | |
170 | -#define SS_CTEXTBOX SS_SUNKEN | SS_CENTER | |
171 | -#define ES_VT100 ES_LEFT | ES_READONLY | ES_MULTILINE | ES_AUTOVSCROLL | |
172 | - | |
173 | 178 | /* Template for dialogue requesting user confirmation of intent |
174 | 179 | * to proceed with scheduled change actions. |
175 | 180 | */ |
@@ -50,10 +50,6 @@ EXTERN_C int pkgPutEnv( int, char* ); | ||
50 | 50 | class pkgSpecs; |
51 | 51 | class pkgDirectory; |
52 | 52 | |
53 | -#ifndef GUIMAIN_H | |
54 | -class AppWindowMaker; | |
55 | -#endif | |
56 | - | |
57 | 53 | class pkgProgressMeter |
58 | 54 | { |
59 | 55 | /* An abstract base class, from which the controller class |
@@ -63,11 +59,6 @@ class pkgProgressMeter | ||
63 | 59 | virtual void SetValue( int ) = 0; |
64 | 60 | virtual void SetRange( int, int ) = 0; |
65 | 61 | virtual int Annotate( const char *, ... ) = 0; |
66 | - | |
67 | - protected: | |
68 | - AppWindowMaker *referrer; | |
69 | - pkgProgressMeter( AppWindowMaker *ref = NULL ): referrer( ref ){} | |
70 | - ~pkgProgressMeter(); | |
71 | 62 | }; |
72 | 63 | |
73 | 64 | class pkgXmlNode : public TiXmlElement |
@@ -104,8 +104,10 @@ void pkgRepository::GetPackageList( const char *dname ) | ||
104 | 104 | |
105 | 105 | /* Set up diagnostics for reporting catalogue loading progress. |
106 | 106 | */ |
107 | - const char *mode = force_update ? "Retaining" : "Loading"; | |
108 | - const char *fmt = "%s catalogue: %s.xml; (item %d of %d)\n"; | |
107 | + const char *mode = force_update ? "Checking" : "Loading"; | |
108 | + const char *fmt = (owner->ProgressMeter() == NULL) | |
109 | + ? "%s catalogue: %s.xml; (item %d of %d)\n" | |
110 | + : "%s catalogue: %s.xml\n"; | |
109 | 111 | |
110 | 112 | /* Check for a locally cached copy of the "package-list" file... |
111 | 113 | */ |
@@ -0,0 +1,78 @@ | ||
1 | +/* | |
2 | + * pmihook.cpp | |
3 | + * | |
4 | + * $Id$ | |
5 | + * | |
6 | + * Written by Keith Marshall <keithmarshall@users.sourceforge.net> | |
7 | + * Copyright (C) 2013, MinGW.org Project | |
8 | + * | |
9 | + * | |
10 | + * Implementation of the generic methods required by an "item counting" | |
11 | + * progress meter, such as used by the setup tool and GUI installer, when | |
12 | + * synchronising local catalogue files with the repository. This file is | |
13 | + * compiled by inclusion at point of use, after PROGRESS_METER_CLASS has | |
14 | + * been defined to appropriately identify the name of the class with | |
15 | + * which these methods are to be associated. | |
16 | + * | |
17 | + * | |
18 | + * This is free software. Permission is granted to copy, modify and | |
19 | + * redistribute this software, under the provisions of the GNU General | |
20 | + * Public License, Version 3, (or, at your option, any later version), | |
21 | + * as published by the Free Software Foundation; see the file COPYING | |
22 | + * for licensing details. | |
23 | + * | |
24 | + * Note, in particular, that this software is provided "as is", in the | |
25 | + * hope that it may prove useful, but WITHOUT WARRANTY OF ANY KIND; not | |
26 | + * even an implied WARRANTY OF MERCHANTABILITY, nor of FITNESS FOR ANY | |
27 | + * PARTICULAR PURPOSE. Under no circumstances will the author, or the | |
28 | + * MinGW Project, accept liability for any damages, however caused, | |
29 | + * arising from the use of this software. | |
30 | + * | |
31 | + */ | |
32 | +void PROGRESS_METER_CLASS::SetRange( int min, int max ) | |
33 | +{ | |
34 | + /* Method to adjust the range of the progress meter, to represent any | |
35 | + * arbitrary range of discrete values, rather than percentage units. | |
36 | + */ | |
37 | + SendMessage( progress_bar, PBM_SETRANGE, 0, MAKELPARAM( min, total = max ) ); | |
38 | +} | |
39 | + | |
40 | +void PROGRESS_METER_CLASS::SetValue( int value ) | |
41 | +{ | |
42 | + /* Method to update the indicated completion state of a progress meter, | |
43 | + * to represent any arbitrary value within its assigned metering range. | |
44 | + */ | |
45 | + const char *plural = "s"; | |
46 | + if( total == 1 ) ++plural; | |
47 | + PutVal( count, "Processed %d", value ); | |
48 | + PutVal( lim, "%d item%s", total, plural ); | |
49 | + SendMessage( progress_bar, PBM_SETPOS, value, 0 ); | |
50 | + PutVal( frac, "%d %%", (value * 100UL) / total ); | |
51 | +} | |
52 | + | |
53 | +int PROGRESS_METER_CLASS::Annotate( const char *fmt, ... ) | |
54 | +{ | |
55 | + /* Method to add a printf() style annotation to the progress meter dialogue. | |
56 | + */ | |
57 | + va_list argv; | |
58 | + va_start( argv, fmt ); | |
59 | + char text[1 + vsnprintf( NULL, 0, fmt, argv )]; | |
60 | + int len = vsnprintf( text, sizeof( text ), fmt, argv ); | |
61 | + va_end( argv ); | |
62 | + | |
63 | + SendMessage( annotation, WM_SETTEXT, 0, (LPARAM)(text) ); | |
64 | + return len; | |
65 | +}; | |
66 | + | |
67 | +void PROGRESS_METER_CLASS::PutVal( HWND viewport, const char *fmt, ... ) | |
68 | +{ | |
69 | + /* Private method, called by SetValue(), to display the numeric values | |
70 | + * of the progress counters, in their appropriate viewports. | |
71 | + */ | |
72 | + va_list argv; va_start( argv, fmt ); | |
73 | + char text[1 + vsnprintf( NULL, 0, fmt, argv )]; vsprintf( text, fmt, argv ); | |
74 | + SendMessage( viewport, WM_SETTEXT, 0, (LPARAM)(text) ); | |
75 | + va_end( argv ); | |
76 | +} | |
77 | + | |
78 | +/* $RCSfile$: end of file */ |