OSDN Git Service

Ignore spin wait requests with no designated referrer.
[mingw/mingw-get.git] / src / pmihook.cpp
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 */