extcmddlg.cpp

00001 
00002 // Name:        extcmddlg.cpp
00003 // Purpose:     wxExtCmdWizard
00004 // Author:      Julian Smart, Francesco Montorsi
00005 // Modified by:
00006 // Created:     15/06/2006 21:23:11
00007 // RCS-ID:      $Id: extcmddlg.cpp,v 1.2 2007/01/01 20:06:21 frm Exp $
00008 // Copyright:   (c) 2004 Francesco Montorsi
00009 // Licence:     wxWidgets license
00011 
00012 
00013 // For compilers that support precompilation, includes "wx/wx.h".
00014 #include "wx/wxprec.h"
00015 
00016 #ifdef __BORLANDC__
00017 #pragma hdrstop
00018 #endif
00019 
00020 #ifndef WX_PRECOMP
00021 #include "wx/wx.h"
00022 #endif
00023 
00024 #include "guipm/extcmddlg.h"
00025 
00026 
00027 // ----------------------------------------------------------------------------
00028 // wxExtCmdWizard
00029 // ----------------------------------------------------------------------------
00030 
00031 IMPLEMENT_DYNAMIC_CLASS( wxExtCmdWizard, wxWizard )
00032 BEGIN_EVENT_TABLE( wxExtCmdWizard, wxWizard )
00033     EVT_BUTTON(wxID_FORWARD, wxExtCmdWizard::OnNext)
00034 
00035     EVT_WIZARD_PAGE_CHANGED(wxID_ANY, wxExtCmdWizard::OnPageChanged)
00036     EVT_PROGRESS_END(wxID_ANY, wxExtCmdWizard::OnProgressPanelEnd)
00037 
00038 END_EVENT_TABLE()
00039 
00040 
00041 wxExtCmdWizard::wxExtCmdWizard( )
00042 {
00043 }
00044 
00045 wxExtCmdWizard::wxExtCmdWizard( wxWindow* parent, wxWindowID id, const wxString &title, const wxPoint& pos )
00046 {
00047     Create(parent, id, title, pos);
00048 }
00049 
00050 bool wxExtCmdWizard::Create( wxWindow* parent, wxWindowID id, const wxString &title, const wxPoint& pos )
00051 {
00052     SetExtraStyle(GetExtraStyle()|wxWIZARD_EX_HELPBUTTON);
00053     wxBitmap wizardBitmap(wxNullBitmap);
00054     wxWizard::Create( parent, id, title, wizardBitmap, pos, wxDEFAULT_DIALOG_STYLE|wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxCLOSE_BOX );
00055 
00056     CreateControls();
00057 
00058     return true;
00059 }
00060 
00061 void wxExtCmdWizard::CreateControls()
00062 {
00063     m_pPage1 = new wxExtCmdWizardPage1( this, GetTitle() );
00064     GetPageAreaSizer()->Add(m_pPage1);
00065 
00066     m_pPage2 = new wxExtCmdWizardPage2( this, GetTitle() );
00067     GetPageAreaSizer()->Add(m_pPage2);
00068 
00069     wxWizardPageSimple::Chain(m_pPage1, m_pPage2);
00070 
00071     // make this wizard a little bigger
00072     //wxSize size = GetPageAreaSizer()->GetMinSize();
00073     //GetPageAreaSizer()->SetMinSize(wxSize(size.GetWidth()*2, size.GetHeight()));
00074 }
00075 
00076 bool wxExtCmdWizard::Run()
00077 {
00078     wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
00079     while (node)
00080     {
00081         wxWizardPage* startPage = wxDynamicCast(node->GetData(), wxWizardPage);
00082         if (startPage) return RunWizard(startPage);
00083         node = node->GetNext();
00084     }
00085     return false;
00086 }
00087 
00088 void wxExtCmdWizard::Set(const wxPackage &p, wxPackageBuildSystemStage stage)
00089 {
00090     // by now set the commands and their options only in the first
00091     // page as that page allows the user to modify them.
00092     // We'll pass them to page #2 once the user clicks 'next'
00093     m_pPage1->GetPanel()->SetPackage(p, stage);
00094 }
00095 
00096 void wxExtCmdWizard::Start()
00097 {
00098     wxButton *btn = wxStaticCast(FindWindowById(wxID_FORWARD, this), wxButton);
00099     wxButton *cancel = wxStaticCast(FindWindowById(wxID_CANCEL, this), wxButton);
00100     wxButton *back = wxStaticCast(FindWindowById(wxID_BACKWARD, this), wxButton);
00101 
00102     m_pPage2->GetPanel()->Start();
00103 
00104     btn->SetLabel(ID_EXTCMD_STOPLABEL);
00105     cancel->Enable(false);
00106     back->Enable(false);
00107 }
00108 
00109 void wxExtCmdWizard::Stop()
00110 {
00111     wxButton *btn = wxStaticCast(FindWindowById(wxID_FORWARD, this), wxButton);
00112     wxButton *cancel = wxStaticCast(FindWindowById(wxID_CANCEL, this), wxButton);
00113     wxButton *back = wxStaticCast(FindWindowById(wxID_BACKWARD, this), wxButton);
00114 
00115     m_pPage2->GetPanel()->Stop();
00116 
00117     btn->SetLabel(ID_EXTCMD_STARTLABEL);
00118     cancel->Enable(true);
00119     back->Enable(true);
00120 }
00121 
00122 void wxExtCmdWizard::OnNext(wxCommandEvent &ev)
00123 {
00124     if (GetCurrentPage() == m_pPage1)
00125     {
00126         wxExtCmdOptionsPanel *opt = m_pPage1->GetPanel();
00127         wxASSERT(opt);
00128 
00129         // pass the user-edited options from page1 to page2
00130         m_pPage2->GetPanel()->SetStage(opt->GetPackageBuildSystemStage());
00131         m_pPage2->GetPanel()->SetPackage(opt->GetPackage());
00132         ev.Skip();  // let wxWizard handle this event !
00133         return;
00134     }
00135 
00136     wxASSERT(GetCurrentPage() == m_pPage2);
00137     wxButton *btn = wxStaticCast(FindWindowById(wxID_FORWARD, this), wxButton);
00138     if (btn->GetLabel() == ID_EXTCMD_STARTLABEL)
00139         Start();
00140     else
00141         Stop();
00142 }
00143 
00144 void wxExtCmdWizard::OnPageChanged(wxWizardEvent &)
00145 {
00146     if (GetCurrentPage() == m_pPage2)
00147     {
00148         // change the label to something best-suited for us
00149         wxButton *btn = wxStaticCast(FindWindowById(wxID_FORWARD, this), wxButton);
00150         btn->SetLabel(ID_EXTCMD_STARTLABEL);
00151     }
00152 }
00153 
00154 void wxExtCmdWizard::OnProgressPanelEnd(wxCommandEvent &)
00155 {
00156     Stop();
00157 }
00158 
00159 
00160 
00161 
00162 // ----------------------------------------------------------------------------
00163 // wxExtCmdWizardPage1
00164 // ----------------------------------------------------------------------------
00165 
00166 IMPLEMENT_DYNAMIC_CLASS( wxExtCmdWizardPage1, wxWizardPageSimple )
00167 BEGIN_EVENT_TABLE( wxExtCmdWizardPage1, wxWizardPageSimple )
00168 END_EVENT_TABLE()
00169 
00170 
00171 wxExtCmdWizardPage1::wxExtCmdWizardPage1( )
00172 {
00173 }
00174 
00175 wxExtCmdWizardPage1::wxExtCmdWizardPage1( wxWizard* parent, const wxString &name )
00176 {
00177     Create( parent, name );
00178 }
00179 
00180 bool wxExtCmdWizardPage1::Create( wxWizard* parent, const wxString &name )
00181 {
00182     wxBitmap wizardBitmap(wxNullBitmap);
00183     wxWizardPageSimple::Create( parent, NULL, NULL, wizardBitmap );
00184     SetName(name);
00185 
00186     CreateControls();
00187 
00188     return true;
00189 }
00190 
00191 void wxExtCmdWizardPage1::CreateControls()
00192 {
00193     wxBoxSizer *sz = new wxBoxSizer(wxVERTICAL);
00194 
00195     // build the panel with our same name
00196     m_pPanel = new wxExtCmdOptionsPanel(this, wxID_ANY, wxDefaultPosition,
00197                                          wxDefaultSize, SYMBOL_WXEXTCMDOPTIONSPANEL_STYLE,
00198                                          GetName());
00199     sz->Add(m_pPanel, 1, wxGROW);
00200     SetSizer(sz);
00201     GetSizer()->SetSizeHints(this);
00202 }
00203 
00204 
00205 
00206 
00207 // ----------------------------------------------------------------------------
00208 // wxExtCmdWizardPage2
00209 // ----------------------------------------------------------------------------
00210 
00211 IMPLEMENT_DYNAMIC_CLASS( wxExtCmdWizardPage2, wxWizardPageSimple )
00212 BEGIN_EVENT_TABLE( wxExtCmdWizardPage2, wxWizardPageSimple )
00213 END_EVENT_TABLE()
00214 
00215 wxExtCmdWizardPage2::wxExtCmdWizardPage2( )
00216 {
00217 }
00218 
00219 wxExtCmdWizardPage2::wxExtCmdWizardPage2( wxWizard* parent, const wxString &name )
00220 {
00221     Create( parent, name );
00222 }
00223 
00224 bool wxExtCmdWizardPage2::Create( wxWizard* parent, const wxString &name )
00225 {
00226     wxBitmap wizardBitmap(wxNullBitmap);
00227     wxWizardPageSimple::Create( parent, NULL, NULL, wizardBitmap );
00228     SetName(name);
00229 
00230     CreateControls();
00231 
00232     return true;
00233 }
00234 
00235 void wxExtCmdWizardPage2::CreateControls()
00236 {
00237     wxBoxSizer *sz = new wxBoxSizer(wxVERTICAL);
00238 
00239     // build the panel with our same name
00240     m_pPanel = new wxExtCmdProgressPanel(this, wxID_ANY, wxDefaultPosition,
00241                                          wxDefaultSize, SYMBOL_WXEXTCMDPROGRESSPANEL_STYLE,
00242                                          GetName());
00243     sz->Add(m_pPanel, 1, wxGROW);
00244     SetSizer(sz);
00245     GetSizer()->SetSizeHints(this);
00246 }

Generated on Thu Feb 1 22:14:30 2007 for wxWidgets Package Manager by  doxygen 1.5.1-p1