progress.cxx
上传用户:hzhsqp
上传日期:2007-01-06
资源大小:1600k
文件大小:4k
- /*
- * progress.cxx
- *
- * Progress bar control.
- *
- * Portable Windows Library
- *
- * Copyright (c) 1993-1998 Equivalence Pty. Ltd.
- *
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.0 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is Portable Windows Library.
- *
- * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
- *
- * Portions are Copyright (C) 1993 Free Software Foundation, Inc.
- * All Rights Reserved.
- *
- * Contributor(s): ______________________________________.
- *
- * $Log: progress.cxx,v $
- * Revision 1.6 1998/12/20 09:14:42 robertj
- * Added pragma implementation for GNU compiler.
- *
- * Revision 1.5 1998/11/30 04:52:16 robertj
- * New directory structure
- *
- * Revision 1.4 1998/09/23 06:29:40 robertj
- * Added open source copyright license.
- *
- */
- #ifdef __GNUC__
- #pragma implementation "progress.h"
- #endif
- #include <pwlib.h>
- #include <pwclib/progress.h>
- PProgressMeter::PProgressMeter(PInteractor * parent,
- unsigned theMin,
- unsigned theMax,
- BOOL percentFlag)
- : PControl(parent, PNotifier(), NULL),
- minimum(theMin),
- maximum(theMax),
- value(0),
- showPercent(percentFlag)
- {
- SetDimensions(100, 12, LocalCoords);
- SetForegroundColour(PColour::Blue);
- SetBackgroundColour(owner->GetButtonBkColour());
- }
- PProgressMeter::PProgressMeter(PInteractorLayout * parent,
- PRESOURCE_ID ctlID,
- const PNotifier & notify,
- void * valuePtr)
- : PControl(parent, ctlID, notify, valuePtr),
- minimum(0),
- maximum(100),
- value(0),
- showPercent(TRUE)
- {
- SetForegroundColour(PColour::Blue);
- SetBackgroundColour(owner->GetButtonBkColour());
- }
- void PProgressMeter::SetValue(unsigned newValue, BOOL update)
- {
- unsigned int v = PMAX(minimum, PMIN(maximum, newValue));
- if (v != value) {
- value = v;
- Invalidate();
- if (update)
- Update();
- }
- }
- unsigned PProgressMeter::GetValue() const
- {
- return value;
- }
- unsigned PProgressMeter::GetMin() const
- {
- return minimum;
- }
- void PProgressMeter::SetMin(unsigned newMin)
- {
- minimum = newMin;
- }
- unsigned PProgressMeter::GetMax() const
- {
- return maximum;
- }
- void PProgressMeter::SetMax(unsigned newMax)
- {
- maximum = newMax;
- }
- void PProgressMeter::OnRedraw(PCanvas & canvas)
- {
- PRect bounds(GetDrawingBounds(LocalCoords));
- PColour fg = GetForegroundColour();
- PColour bg = GetBackgroundColour();
- canvas.SetFillFgColour(PColour::Clear);
- canvas.DrawBevelledRect(bounds, FALSE, TRUE);
- bounds.Inflate(-1, -1);
- PORDINATE pos = bounds.Left() +
- (bounds.Width() * (value - minimum)) / (maximum - minimum);
- PRect done(bounds), notDone(bounds);
- done.SetRight(pos);
- notDone.SetLeft(PMIN(notDone.Right(), pos));
- canvas.SetFillFgColour(bg);
- canvas.FillRect(notDone);
- canvas.SetFillFgColour(fg);
- canvas.FillRect(done);
- if (showPercent) {
- unsigned long percentage = (100 * (value - minimum)) / (maximum - minimum);
- PString str(PString::Printf, "%i%%", percentage);
- canvas.SetTextBkColour(PColour::Clear);
- // draw left side
- canvas.SetClipRect(done);
- canvas.SetTextFgColour(bg);
- canvas.DrawString(bounds, str, PCanvas::Centred | PCanvas::CentreVertical);
- // draw right side
- canvas.SetClipRect(notDone);
- canvas.SetTextFgColour(fg);
- canvas.DrawString(bounds, str, PCanvas::Centred | PCanvas::CentreVertical);
- }
- }