Code: Select all
//---------------------------------------------------------------------------
//
// Name: components.h
// Author: Joel Low
// Created: 13/08/05 10:16
// Description: ClassTools Custom Components
//
//---------------------------------------------------------------------------
#ifndef __widget_components_h__
#define __widget_components_h__
class DLLIMPORT ctProgressBar : public wxPanel
{
public:
ctProgressBar(wxWindow* parent, wxWindowID id, int range, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxGA_HORIZONTAL, const wxValidator& validator = wxDefaultValidator, const wxString& name = "gauge", wxString format = "%d%%");
int GetBezelFace() const;
int GetRange() const;
int GetShadowWidth() const;
int GetValue() const;
bool IsVertical() const;
void SetBezelFace(int width);
void SetRange(int range);
void SetShadowWidth(int width);
void SetValue(int value);
void SetFormat(wxString format);
private:
wxGauge* gauge; //Gauge
wxString format; //Format of label
wxStaticText* label; //Label
};
#endif
Code: Select all
//---------------------------------------------------------------------------
//
// Name: ctprogressbar.cpp
// Author: Joel Low
// Created: 06/09/05 09:06
// Description: ClassTools progress bar with indicator
//
//---------------------------------------------------------------------------
#include "../components.h"
using namespace std;
ctProgressBar::ctProgressBar(wxWindow* parent, wxWindowID id, int range, const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator , const wxString& name, wxString format)
: wxPanel(parent, id, pos, size, 0)
{
//Create a sizer to control the way the control looks
wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
//Create the controls, selecting styles passed to the constructor
gauge = new wxGauge(this, wxID_ANY, range, wxDefaultPosition, size, style, validator, name);
label = new wxStaticText(this, wxID_ANY, wxString::Format(format, 0), wxDefaultPosition, wxSize(100, 17), wxALIGN_RIGHT);
//Then set the format of the label and some default values
SetValue(0);
SetRange(100);
SetFormat(format);
//Add the controls and call the sizer to fit according to size.
sizer->Add(gauge, 1, wxEXPAND | wxALIGN_TOP, 0);
sizer->Add(label, 0, wxEXPAND | wxALIGN_TOP, 0);
this->SetSizerAndFit(sizer);
}
//Set the format of the label. %d's will be replaced by the value of the gauge
void ctProgressBar::SetFormat(wxString format)
{
ctProgressBar::format = format;
SetValue(GetValue());
}
//All other functions here mirror that of wxGauge.
void ctProgressBar::SetValue(int pos)
{
gauge->SetValue(pos);
label->SetLabel(wxString::Format(format, pos));
}
int ctProgressBar::GetBezelFace() const
{
return gauge->GetBezelFace();
}
int ctProgressBar::GetRange() const
{
return gauge->GetRange();
}
int ctProgressBar::GetShadowWidth() const
{
return gauge->GetShadowWidth();
}
int ctProgressBar::GetValue() const
{
return gauge->GetValue();
}
bool ctProgressBar::IsVertical() const
{
return gauge->IsVertical();
}
void ctProgressBar::SetBezelFace(int width)
{
gauge->SetBezelFace(width);
}
void ctProgressBar::SetRange(int range)
{
gauge->SetRange(range);
}
void ctProgressBar::SetShadowWidth(int width)
{
gauge->SetShadowWidth(width);
}
Regards,
Joel