1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
|
//////////////////////////////////////////////////////////////////////////
//
// pgAdmin III - PostgreSQL Tools
//
// Copyright (C) 2002 - 2014, The pgAdmin Development Team
// This software is released under the PostgreSQL Licence
//
// ctlProgressStatusBar.cpp - A status bar with progress indicator
//
//////////////////////////////////////////////////////////////////////////
#include "pgAdmin3.h"
// wxWindows headers
#include <wx/wx.h>
#include <wx/statusbr.h>
#include <wx/gauge.h>
// App headers
#include "ctl/ctlProgressStatusBar.h"
BEGIN_EVENT_TABLE(ctlProgressStatusBar, wxStatusBar)
EVT_SIZE(ctlProgressStatusBar::OnSize)
EVT_TIMER(wxID_ANY, ctlProgressStatusBar::OnTimer)
END_EVENT_TABLE()
const unsigned short ctlProgressStatusBar::ms_increment = 100;
const unsigned short ctlProgressStatusBar::ms_progressbar_width = 70;
const unsigned short ctlProgressStatusBar::ms_progressstatus_width = 130;
ctlProgressStatusBar::ctlProgressStatusBar(wxWindow *parent, bool showProgressInitially, bool autoProgressive, int max)
: wxStatusBar(parent, wxID_ANY), m_progressStopped(!showProgressInitially),
m_autoProgressive(autoProgressive), m_autoValIncrementing(true),
m_hr(0), m_min(0), m_sec(0), m_mil(0), m_val(0)
{
static int widths[] = { -1, ms_progressbar_width, ms_progressstatus_width};
int fields = 0;
if (max <= 0)
max = 100;
if (m_autoProgressive)
fields = 3;
else
fields = 2;
m_progress = new wxGauge(this, -1, max);
wxStatusBar::SetFieldsCount(fields);
wxStatusBar::SetStatusWidths(fields, widths);
m_timer.SetOwner(this->GetEventHandler());
if (!showProgressInitially)
{
m_progressStopped = true;
}
else
{
m_progressStopped = false;
if (m_autoProgressive)
{
m_timer.Start(ms_increment);
m_hr = 0;
m_min = 0;
m_sec = 0;
m_mil = 0;
}
}
// Dummy event to place the progressbar at right place
wxSizeEvent ev;
this->OnSize(ev);
}
ctlProgressStatusBar::~ctlProgressStatusBar()
{
if (m_timer.IsRunning())
{
m_timer.Stop();
}
}
void ctlProgressStatusBar::OnSize(wxSizeEvent &ev)
{
// We should have hide the progress bar
if (GetFieldsCount() <= ProgressBar_field)
return;
wxRect r;
GetFieldRect(ProgressBar_field, r);
m_progress->SetSize(r.x + 1, r.y + 1, r.width - 2, r.height - 2);
ev.Skip();
}
void ctlProgressStatusBar::OnTimer(wxTimerEvent &ev)
{
if (m_progressStopped || !m_autoProgressive)
{
m_timer.Stop();
return;
}
m_val = m_progress->GetValue();
int max = m_progress->GetRange();
if (m_val == max)
{
m_val -= 1;
m_autoValIncrementing = false;
}
else if (m_val == 0)
{
m_val = 1;
m_autoValIncrementing = true;
}
else if (m_autoValIncrementing)
{
m_val += 1;
}
else
{
m_val -= 1;
}
m_progress->SetValue(m_val);
m_mil += ms_increment;
if (m_mil >= 1000)
{
m_mil = m_mil - 1000;
m_sec += 1;
if (m_sec == 60)
{
m_sec = 0;
m_min += 1;
if (m_min == 60)
{
m_min = 0;
m_hr += 1;
}
}
}
wxStatusBar::SetStatusText(wxString::Format(_("%d:%02d:%02d.%03d"), m_hr, m_min, m_sec, m_mil), ProgressStatus_field);
}
void ctlProgressStatusBar::ShowProgress(bool restart)
{
if (m_progressStopped)
{
m_progressStopped = false;
if (!m_timer.IsRunning())
{
if (restart)
{
m_val = 0;
m_hr = m_min = m_sec = m_mil = 0;
}
m_progress->SetValue(m_val);
m_timer.Start(ms_increment);
}
}
}
void ctlProgressStatusBar::StopProgress()
{
if (m_timer.IsRunning())
m_timer.Stop();
m_progress->SetValue(0);
m_progressStopped = true;
}
void ctlProgressStatusBar::SetFieldsCount(int number, const int *widths)
{
m_progress->Show(number > ProgressBar_field);
wxStatusBar::SetFieldsCount( number, widths);
// Dummy Size event (to reposition the progress bar)
wxSizeEvent ev;
this->OnSize(ev);
}
void ctlProgressStatusBar::SetStatusWidths(int n, const int widths_field[])
{
wxStatusBar::SetStatusWidths( n, widths_field);
// Dummy Size event (to reposition the progress bar)
wxSizeEvent ev;
this->OnSize(ev);
}
|