diff --git a/pgadmin/ctl/ctlProgressStatusBar.cpp b/pgadmin/ctl/ctlProgressStatusBar.cpp new file mode 100644 index 0000000..1981229 --- /dev/null +++ b/pgadmin/ctl/ctlProgressStatusBar.cpp @@ -0,0 +1,177 @@ +////////////////////////////////////////////////////////////////////////// +// +// pgAdmin III - PostgreSQL Tools +// +// Copyright (C) 2002 - 2013, 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 +#include +#include + +// 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[] = {ms_progressbar_width, -1, ms_progressstatus_width}; + int fields = 0; + + if (max <= 0) + max = 100; + + if (m_autoProgressive) + fields = 3; + else + fields = 2; + + wxStatusBar::SetFieldsCount(fields); + wxStatusBar::SetStatusWidths(fields, widths); + + m_progress = new wxGauge(this, -1, max); + 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; + } + } +} + +ctlProgressStatusBar::~ctlProgressStatusBar() +{ + if (m_timer.IsRunning()) + { + m_timer.Stop(); + } +} + + +void ctlProgressStatusBar::OnSize(wxSizeEvent &ev) +{ + 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; +} + + diff --git a/pgadmin/ctl/module.mk b/pgadmin/ctl/module.mk index 0e9a1e7..81b58cc 100644 --- a/pgadmin/ctl/module.mk +++ b/pgadmin/ctl/module.mk @@ -24,6 +24,7 @@ pgadmin3_SOURCES += \ ctl/ctlSeclabelPanel.cpp \ ctl/ctlSecurityPanel.cpp \ ctl/ctlTree.cpp \ + ctl/ctlProgressStatusBar.cpp \ ctl/explainCanvas.cpp \ ctl/explainShape.cpp \ ctl/timespin.cpp \ diff --git a/pgadmin/debugger/frmDebugger.cpp b/pgadmin/debugger/frmDebugger.cpp index c56fc67..faba15f 100644 --- a/pgadmin/debugger/frmDebugger.cpp +++ b/pgadmin/debugger/frmDebugger.cpp @@ -21,6 +21,7 @@ #include "ctl/ctlMenuToolbar.h" #include "ctl/ctlSQLBox.h" #include "ctl/ctlAuiNotebook.h" +#include "ctl/ctlProgressStatusBar.h" #include "debugger/dbgController.h" #include "debugger/ctlTabWindow.h" #include "debugger/frmDebugger.h" @@ -58,7 +59,6 @@ BEGIN_EVENT_TABLE(frmDebugger, pgFrame) EVT_MENU(MNU_CONTENTS, frmDebugger::OnContents) EVT_MENU(MNU_HELP, frmDebugger::OnHelp) - EVT_TIMER(ID_TIMER, frmDebugger::OnTimer) END_EVENT_TABLE() //////////////////////////////////////////////////////////////////////////////// @@ -71,7 +71,7 @@ frmDebugger::frmDebugger(frmMain *_parent, dbgController *_controller, const wxString &_title) : pgFrame(_parent, _title), m_menuBar(NULL), m_toolBar(NULL), m_viewMenu(NULL), m_debugMenu(NULL), m_statusBar(NULL), m_parent(_parent), m_controller(_controller), m_stackWindow(NULL), - m_tabWindow(NULL), m_codeViewer(NULL), m_progressBar(NULL), m_timer(this, ID_TIMER) + m_tabWindow(NULL), m_codeViewer(NULL) { dlgName = wxT("frmDebugger"); RestorePosition(100, 100, 600, 500, 450, 300); @@ -282,10 +282,6 @@ void frmDebugger::EnableToolsAndMenus(bool enable) m_debugMenu->Enable(MENU_ID_CLEAR_ALL_BREAK, enable); m_debugMenu->Enable(MENU_ID_STOP, enable); } - if ((!m_controller || m_controller->IsTerminated())) - { - m_timer.Stop(); - } } @@ -590,7 +586,7 @@ void frmDebugger::OnPositionStc(wxStyledTextEvent &event) strPos.Printf(_("Ln %d Col %d Ch %d"), m_codeViewer->LineFromPosition(pos) + 1, m_codeViewer->GetColumn(pos) + 1, pos + 1); - GetStatusBar()->SetStatusText(strPos, 2); + GetStatusBar()->SetStatusText(strPos, 3); } } @@ -696,12 +692,14 @@ ctlMenuToolbar *frmDebugger::SetupToolBar(void) // This function initializes the status bar (we don't have one at the moment // so this function simply returns) // -wxStatusBar *frmDebugger::SetupStatusBar(void) +ctlProgressStatusBar *frmDebugger::SetupStatusBar(void) { - wxStatusBar *bar = CreateStatusBar(3, wxST_SIZEGRIP); - int widths[] = { 0, -1, 130 }; + ctlProgressStatusBar *bar = new ctlProgressStatusBar(this, false); + int widths[] = { ctlProgressStatusBar::ms_progressbar_width, -1, ctlProgressStatusBar::ms_progressstatus_width, 190}; - bar->SetStatusWidths(3, widths); + bar->SetFieldsCount(4); + bar->SetStatusWidths(4, widths); + this->SetStatusBar(bar); return(bar); } @@ -791,9 +789,6 @@ wxMenuBar *frmDebugger::SetupMenuBar(void) void frmDebugger::OnClose(wxCloseEvent &_ev) { - bool wasTimerRunning = m_timer.IsRunning(); - m_timer.Stop(); - if (!m_controller->CanRestart() && _ev.CanVeto()) { if (wxMessageBox( @@ -801,17 +796,11 @@ void frmDebugger::OnClose(wxCloseEvent &_ev) _("Close debugger"), wxICON_QUESTION | wxYES_NO) != wxYES) { _ev.Veto(); - if (wasTimerRunning) - { - m_timer.Start(500); - } return; } } - m_timer.Stop(); - m_controller->CloseDebugger(); _ev.Skip(); @@ -1015,20 +1004,7 @@ void frmDebugger::LaunchWaitingDialog(const wxString &msg) m_statusTxt = strStatus; m_statusBar->SetStatusText(strStatus, 1); - - // NOTE: the waiting-dialog takes forever to appear running a remote X session so you can disable it by defining the following env. variable - if(getenv("SUPPRESS_WAIT_DIALOG")) - { - m_progressBar = NULL; - } - else - { - m_progressBar = - new wxProgressDialog(_("Waiting for target"), strStatus, 100, this, - wxPD_SMOOTH | wxPD_CAN_ABORT | wxPD_ELAPSED_TIME ); - - m_timer.Start(500); // 2 clock ticks per second - } + m_statusBar->ShowProgress(); } @@ -1039,22 +1015,5 @@ void frmDebugger::CloseProgressBar() m_statusBar->SetStatusText(m_statusTxt + wxT(" Done"), 1); m_statusTxt = wxT(""); } - if (m_progressBar) - { - m_progressBar->Close(); - delete m_progressBar; - m_progressBar = NULL; - } -} - - -void frmDebugger::OnTimer(wxTimerEvent &_ev) -{ - if (m_progressBar) - { - if (m_progressBar->Pulse() == false) - { - Close(); - } - } + m_statusBar->StopProgress(); } diff --git a/pgadmin/include/ctl/ctlProgressStatusBar.h b/pgadmin/include/ctl/ctlProgressStatusBar.h new file mode 100644 index 0000000..391dfa9 --- /dev/null +++ b/pgadmin/include/ctl/ctlProgressStatusBar.h @@ -0,0 +1,59 @@ +////////////////////////////////////////////////////////////////////////// +// +// pgAdmin III - PostgreSQL Tools +// +// Copyright (C) 2002 - 2013, The pgAdmin Development Team +// This software is released under the PostgreSQL Licence +// +// ctlProgressStatusBar.h - Status bar indicating the current progress +// +////////////////////////////////////////////////////////////////////////// +// +#ifndef CTLPROGRESS_STATUSBAR_H +#define CTLPROGRESS_STATUSBAR_H + +// wxWindows headers +#include +#include +#include + +class ctlProgressStatusBar : public wxStatusBar +{ +public: + ctlProgressStatusBar(wxWindow *parent, bool showProgressInitially = true, bool autoProgressive = true, int max = -1); + virtual ~ctlProgressStatusBar(); + + void ShowProgress(bool restart = true); + void StopProgress(); + void SetProgress(int val); + + static const unsigned short ms_increment, + ms_progressbar_width, + ms_progressstatus_width; + +protected: + void OnTimer(wxTimerEvent &WXUNUSED(event)); + void OnSize(wxSizeEvent &ev); + + wxGauge *m_progress; + wxTimer m_timer; + + bool m_progressStopped; + bool m_autoProgressive; + bool m_autoValIncrementing; + + int m_hr, m_min, m_sec, m_mil; + int m_val; + + enum + { + ProgressBar_field, + Status_field, + ProgressStatus_field, + Max_Field + }; + + DECLARE_EVENT_TABLE() +}; + +#endif // CTLPROGRESS_STATUSBAR_H diff --git a/pgadmin/include/ctl/module.mk b/pgadmin/include/ctl/module.mk index 4328e92..59370c7 100644 --- a/pgadmin/include/ctl/module.mk +++ b/pgadmin/include/ctl/module.mk @@ -23,6 +23,7 @@ pgadmin3_SOURCES += \ include/ctl/ctlSQLBox.h \ include/ctl/ctlSQLGrid.h \ include/ctl/ctlSQLResult.h \ + include/ctl/ctlProgressStatusBar.h \ include/ctl/ctlTree.h \ include/ctl/explainCanvas.h \ include/ctl/timespin.h \ diff --git a/pgadmin/include/debugger/frmDebugger.h b/pgadmin/include/debugger/frmDebugger.h index 3c3237a..1aa1e37 100644 --- a/pgadmin/include/debugger/frmDebugger.h +++ b/pgadmin/include/debugger/frmDebugger.h @@ -26,6 +26,8 @@ #include #include +#include "ctl/ctlProgressStatusBar.h" + // // This number MUST be incremented if changing any of the default perspectives // @@ -111,7 +113,7 @@ private: wxMenuBar *SetupMenuBar( void ); ctlMenuToolbar *SetupToolBar( void ); - wxStatusBar *SetupStatusBar( void ); + ctlProgressStatusBar *SetupStatusBar( void ); enum { @@ -132,7 +134,7 @@ private: wxAuiManager m_manager; // Frame's status bar - wxStatusBar *m_statusBar; + ctlProgressStatusBar *m_statusBar; // Main Frame frmMain *m_parent; // Debugger Controller @@ -144,19 +146,12 @@ private: ctlTabWindow *m_tabWindow; // Function Code Viewer ctlSQLBox *m_codeViewer; - // Timer - wxTimer m_timer; - // "Waiting for target" dialog - wxProgressDialog *m_progressBar; // Operation Status wxString m_statusTxt; DECLARE_EVENT_TABLE() - // Idle processor - void OnTimer(wxTimerEvent &_ev); - void OnExecute(wxCommandEvent &_ev); void OnDebugCommand(wxCommandEvent &_ev); void OnSelectFrame(wxCommandEvent &_ev); diff --git a/pgadmin/pgAdmin3.vcxproj b/pgadmin/pgAdmin3.vcxproj index e3c34ec..2b5566d 100644 --- a/pgadmin/pgAdmin3.vcxproj +++ b/pgadmin/pgAdmin3.vcxproj @@ -734,6 +734,7 @@ + @@ -2821,6 +2822,7 @@ + @@ -3531,4 +3533,4 @@ - \ No newline at end of file + diff --git a/pgadmin/pgAdmin3.vcxproj.filters b/pgadmin/pgAdmin3.vcxproj.filters index 96aa377..1fc4929 100644 --- a/pgadmin/pgAdmin3.vcxproj.filters +++ b/pgadmin/pgAdmin3.vcxproj.filters @@ -316,6 +316,9 @@ ctl + + ctl + ctl @@ -2288,6 +2291,9 @@ include\ctl + + include\ctl + include\ctl @@ -4428,4 +4434,4 @@ - \ No newline at end of file +