00001 /* 00002 * wxChecksums 00003 * Copyright (C) 2003-2004 Julien Couot 00004 * 00005 * Based on the wxProgressDialog class provided in wxWidgets written by 00006 * Karsten Ballüder. 00007 * 00008 * This program is free software; you can redistribute it and/or 00009 * modify it under the terms of the GNU General Public License 00010 * as published by the Free Software Foundation; either version 2 00011 * of the License, or (at your option) any later version. 00012 * 00013 * This program is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU General Public License 00019 * along with this program; if not, write to the Free Software 00020 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00021 */ 00022 00023 /** 00024 * \file dlgProgress.hpp 00025 * Progress dialog. 00026 */ 00027 00028 #ifndef INC_DLGPROGRESS_HPP 00029 #define INC_DLGPROGRESS_HPP 00030 00031 //--------------------------------------------------------------------------- 00032 // For compilers that support precompilation, includes "wx.h". 00033 #include <wx/wxprec.h> 00034 00035 #ifdef __BORLANDC__ 00036 #pragma hdrstop 00037 #endif 00038 00039 #ifndef WX_PRECOMP 00040 // Include your minimal set of headers here, or wx.h 00041 #include <wx/wx.h> 00042 #endif 00043 //--------------------------------------------------------------------------- 00044 00045 00046 /** 00047 * Progress dialog which shows a moving progress bar. 00048 * Taken from wxWidgets. 00049 */ 00050 class dlgProgress : public wxDialog 00051 { 00052 public: 00053 // Creates and displays dialog 00054 dlgProgress(const wxString& title, const wxString& message, 00055 int maximum = 100, wxWindow* parent = NULL, 00056 int style = wxPD_APP_MODAL | wxPD_AUTO_HIDE); 00057 00058 // Destructor. 00059 virtual ~dlgProgress(); 00060 00061 // Creates and initializes the controls of the dialog. 00062 void createControls(const wxString& message = wxEmptyString); 00063 00064 protected: 00065 wxWindowDisabler* winDisabler; ///< Disable all others windows (for wxPD_APP_MODAL case). 00066 wxGauge* gauProgress; ///< Progress bar. 00067 wxStaticText* lblMessage; ///< The message displayed. 00068 wxStaticText* lblElapsed; ///< Elapsed time. 00069 wxStaticText* lblEstimated; ///< Estimated time. 00070 wxStaticText* lblRemaining; ///< Remaining time. 00071 wxButton* btnCancel; ///< Cancel and close button. 00072 wxButton* btnPause; ///< Pause button 00073 00074 // Processes button Cancel. 00075 void btnCancelClick(wxCommandEvent& event); 00076 // Processes button Pause. 00077 void btnPauseClick(wxCommandEvent& event); 00078 00079 // Event handler to respond to system close events. 00080 void FrameClose(wxCloseEvent& event); 00081 00082 00083 /// Controls IDs 00084 enum 00085 { 00086 BTN_PAUSE 00087 }; 00088 00089 DECLARE_EVENT_TABLE() 00090 00091 protected: 00092 // Must be called to reenable the other windows temporarily disabled while 00093 // the dialog was shown. 00094 void ReenableOtherWindows(); 00095 00096 /// Continue processing or not (return value for Update()). 00097 enum State 00098 { 00099 Uncancelable = -1, // dialog can't be canceled 00100 Paused, // paused, can be cancelled 00101 Canceled, // can be cancelled and, in fact, was 00102 Continue, // can be cancelled but wasn't 00103 Finished // finished, waiting to be removed from screen 00104 } state; 00105 00106 wxWindow* ctrParentTop; ///< Parent top level window (may be NULL). 00107 unsigned long timeStart; ///< Time when the dialog was created. 00108 int maximum; ///< The maximum value 00109 #if defined(__WXMSW__ ) || defined(__WXPM__) 00110 // The factor we use to always keep the value in 16 bit range as the native 00111 // control only supports ranges from 0 to 65,535. 00112 size_t factor; ///< The factor we use to always keep the value in 16 bit range. 00113 #endif // __WXMSW__ 00114 00115 private: 00116 /// Virtual function hiding supression. 00117 virtual void Update() { wxDialog::Update(); } 00118 00119 public: 00120 // Updates the status bar to the new value. 00121 bool Update(int value, const wxString& newmsg = wxEmptyString); 00122 00123 // Can be called to continue after the cancel button has been pressed. 00124 void Resume(); 00125 00126 // Shows the dialog. 00127 bool Show(bool show = true); 00128 00129 // Is the user has clicked on Pause ? 00130 bool isPaused() const; 00131 00132 protected: 00133 // Update the label to show the given time (in seconds). 00134 void SetTimeLabel(unsigned long val, wxStaticText* label); 00135 00136 private: 00137 DECLARE_DYNAMIC_CLASS(dlgProgress) 00138 00139 /// Default constructor. Don't use it. 00140 dlgProgress::dlgProgress() : wxDialog() {} 00141 }; 00142 //--------------------------------------------------------------------------- 00143 00144 #endif // INC_DLGPROGRESS_HPP