4 * Progress bar control.
6 * Portable Windows Library
8 * Copyright (c) 1993-1998 Equivalence Pty. Ltd.
10 * The contents of this file are subject to the Mozilla Public License
11 * Version 1.0 (the "License"); you may not use this file except in
12 * compliance with the License. You may obtain a copy of the License at
13 * http://www.mozilla.org/MPL/
15 * Software distributed under the License is distributed on an "AS IS"
16 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17 * the License for the specific language governing rights and limitations
20 * The Original Code is Portable Windows Library.
22 * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
24 * Portions are Copyright (C) 1993 Free Software Foundation, Inc.
25 * All Rights Reserved.
27 * Contributor(s): ______________________________________.
30 * Revision 1.6 1998/12/20 09:14:42 robertj
31 * Added pragma implementation for GNU compiler.
33 * Revision 1.5 1998/11/30 04:52:16 robertj
34 * New directory structure
36 * Revision 1.4 1998/09/23 06:29:40 robertj
37 * Added open source copyright license.
42 #pragma implementation "progress.h"
47 #include <pwclib/progress.h>
49 PProgressMeter::PProgressMeter(PInteractor
* parent
,
53 : PControl(parent
, PNotifier(), NULL
),
57 showPercent(percentFlag
)
59 SetDimensions(100, 12, LocalCoords
);
60 SetForegroundColour(PColour::Blue
);
61 SetBackgroundColour(owner
->GetButtonBkColour());
64 PProgressMeter::PProgressMeter(PInteractorLayout
* parent
,
66 const PNotifier
& notify
,
68 : PControl(parent
, ctlID
, notify
, valuePtr
),
74 SetForegroundColour(PColour::Blue
);
75 SetBackgroundColour(owner
->GetButtonBkColour());
78 void PProgressMeter::SetValue(unsigned newValue
, BOOL update
)
80 unsigned int v
= PMAX(minimum
, PMIN(maximum
, newValue
));
89 unsigned PProgressMeter::GetValue() const
94 unsigned PProgressMeter::GetMin() const
99 void PProgressMeter::SetMin(unsigned newMin
)
104 unsigned PProgressMeter::GetMax() const
109 void PProgressMeter::SetMax(unsigned newMax
)
114 void PProgressMeter::OnRedraw(PCanvas
& canvas
)
116 PRect
bounds(GetDrawingBounds(LocalCoords
));
118 PColour fg
= GetForegroundColour();
119 PColour bg
= GetBackgroundColour();
121 canvas
.SetFillFgColour(PColour::Clear
);
122 canvas
.DrawBevelledRect(bounds
, FALSE
, TRUE
);
123 bounds
.Inflate(-1, -1);
125 PORDINATE pos
= bounds
.Left() +
126 (bounds
.Width() * (value
- minimum
)) / (maximum
- minimum
);
127 PRect
done(bounds
), notDone(bounds
);
130 notDone
.SetLeft(PMIN(notDone
.Right(), pos
));
132 canvas
.SetFillFgColour(bg
);
133 canvas
.FillRect(notDone
);
134 canvas
.SetFillFgColour(fg
);
135 canvas
.FillRect(done
);
138 unsigned long percentage
= (100 * (value
- minimum
)) / (maximum
- minimum
);
139 PString
str(PString::Printf
, "%i%%", percentage
);
141 canvas
.SetTextBkColour(PColour::Clear
);
144 canvas
.SetClipRect(done
);
145 canvas
.SetTextFgColour(bg
);
146 canvas
.DrawString(bounds
, str
, PCanvas::Centred
| PCanvas::CentreVertical
);
149 canvas
.SetClipRect(notDone
);
150 canvas
.SetTextFgColour(fg
);
151 canvas
.DrawString(bounds
, str
, PCanvas::Centred
| PCanvas::CentreVertical
);