Uncommented beaudio code
[pwlib.git] / src / pwclib / progress.cxx
blobf8c4042b99bfedc23114679c011cae7699687ab1
1 /*
2 * progress.cxx
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
18 * under the License.
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): ______________________________________.
29 * $Log$
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.
41 #ifdef __GNUC__
42 #pragma implementation "progress.h"
43 #endif
45 #include <pwlib.h>
47 #include <pwclib/progress.h>
49 PProgressMeter::PProgressMeter(PInteractor * parent,
50 unsigned theMin,
51 unsigned theMax,
52 BOOL percentFlag)
53 : PControl(parent, PNotifier(), NULL),
54 minimum(theMin),
55 maximum(theMax),
56 value(0),
57 showPercent(percentFlag)
59 SetDimensions(100, 12, LocalCoords);
60 SetForegroundColour(PColour::Blue);
61 SetBackgroundColour(owner->GetButtonBkColour());
64 PProgressMeter::PProgressMeter(PInteractorLayout * parent,
65 PRESOURCE_ID ctlID,
66 const PNotifier & notify,
67 void * valuePtr)
68 : PControl(parent, ctlID, notify, valuePtr),
69 minimum(0),
70 maximum(100),
71 value(0),
72 showPercent(TRUE)
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));
81 if (v != value) {
82 value = v;
83 Invalidate();
84 if (update)
85 Update();
89 unsigned PProgressMeter::GetValue() const
91 return value;
94 unsigned PProgressMeter::GetMin() const
96 return minimum;
99 void PProgressMeter::SetMin(unsigned newMin)
101 minimum = newMin;
104 unsigned PProgressMeter::GetMax() const
106 return maximum;
109 void PProgressMeter::SetMax(unsigned newMax)
111 maximum = 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);
129 done.SetRight(pos);
130 notDone.SetLeft(PMIN(notDone.Right(), pos));
132 canvas.SetFillFgColour(bg);
133 canvas.FillRect(notDone);
134 canvas.SetFillFgColour(fg);
135 canvas.FillRect(done);
137 if (showPercent) {
138 unsigned long percentage = (100 * (value - minimum)) / (maximum - minimum);
139 PString str(PString::Printf, "%i%%", percentage);
141 canvas.SetTextBkColour(PColour::Clear);
143 // draw left side
144 canvas.SetClipRect(done);
145 canvas.SetTextFgColour(bg);
146 canvas.DrawString(bounds, str, PCanvas::Centred | PCanvas::CentreVertical);
148 // draw right side
149 canvas.SetClipRect(notDone);
150 canvas.SetTextFgColour(fg);
151 canvas.DrawString(bounds, str, PCanvas::Centred | PCanvas::CentreVertical);