ProgressStatusBar.cpp

Go to the documentation of this file.
00001 // -*- c-basic-offset: 4 -*-
00002 
00011 /*
00012  *  This program is free software; you can redistribute it and/or
00013  *  modify it under the terms of the GNU General Public
00014  *  License as published by the Free Software Foundation; either
00015  *  version 2 of the License, or (at your option) any later version.
00016  *
00017  *  This software is distributed in the hope that it will be useful,
00018  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00019  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00020  *  General Public License for more details.
00021  *
00022  *  You should have received a copy of the GNU General Public
00023  *  License along with this software. If not, see
00024  *  <http://www.gnu.org/licenses/>.
00025  *
00026  */
00027 
00028 #include "ProgressStatusBar.h"
00029 
00030 // Event table
00031 BEGIN_EVENT_TABLE(ProgressStatusBar, wxStatusBar)
00032 EVT_SIZE(ProgressStatusBar::OnSize)
00033 END_EVENT_TABLE()
00034 
00035 ProgressStatusBar::ProgressStatusBar(wxWindow *parent, wxWindowID id, long style, const wxString &name) : wxStatusBar(parent, id, style, name)
00036 {
00037     m_progress = new wxGauge(this, -1, 100, wxDefaultPosition, wxDefaultSize, wxGA_HORIZONTAL);
00038     SetProgress(-1);
00039 }
00040 
00041 ProgressStatusBar::~ProgressStatusBar()
00042 {
00043     if (m_progress)
00044     {
00045         delete m_progress;
00046     };
00047 }
00048 
00049 void ProgressStatusBar::OnSize(wxSizeEvent& event)
00050 {
00051     if (GetFieldsCount() > 0)
00052     {
00053         wxRect r;
00054         GetFieldRect(GetFieldsCount() - 1, r);
00055         r.Deflate(2, 2);
00056         m_progress->SetSize(r);
00057     };
00058 }
00059 
00060 void ProgressStatusBar::SetProgress(int progress)
00061 {
00062     m_progressValue = progress;
00063     m_progress->Show(m_progressValue >= 0);
00064     // SetValue expects values >=0 and < max value, but we are using -1 to indicate that progress bar is hidden
00065     m_progress->SetValue(m_progressValue < 0 ? 0 : m_progressValue);
00066 };
00067 
00068 int ProgressStatusBar::GetProgress()
00069 {
00070     return m_progressValue;
00071 };

Generated on 23 Jan 2018 for Hugintrunk by  doxygen 1.4.7