builddlg.cpp

00001 
00002 // Name:        builddlg.cpp
00003 // Purpose:     wxPackageBuildDlg
00004 // Author:      Francesco Montorsi
00005 // Modified by:
00006 // Created:     Fri 23 Jun 2006 14:45:45 CEST
00007 // RCS-ID:      $Id: builddlg.cpp,v 1.4 2007/02/01 20:11:27 frm Exp $
00008 // Copyright:   (c) 2006 Francesco Montorsi
00009 // Licence:     wxWidgets license
00011 
00012 // For compilers that support precompilation, includes "wx/wx.h".
00013 #include "wx/wxprec.h"
00014 
00015 #ifdef __BORLANDC__
00016 #pragma hdrstop
00017 #endif
00018 
00019 #ifndef WX_PRECOMP
00020 #include "wx/wx.h"
00021 #endif
00022 
00023 #include "guipm/builddlg.h"
00024 #include "guipm/extcmdoptionspanel.h"
00025 #include "guipm/compilerpanel.h"
00026 
00027 
00028 // ----------------------------------------------------------------------------
00029 // wxPackageBuildDlg
00030 // ----------------------------------------------------------------------------
00031 
00032 IMPLEMENT_DYNAMIC_CLASS( wxPackageBuildDlg, wxDialog )
00033 BEGIN_EVENT_TABLE( wxPackageBuildDlg, wxDialog )
00034     EVT_NOTEBOOK_PAGE_CHANGED(wxID_ANY, wxPackageBuildDlg::OnPageChanged)
00035     EVT_BUTTON(wxID_OK, wxPackageBuildDlg::OnOK)
00036 END_EVENT_TABLE()
00037 
00038 wxPackageBuildDlg::wxPackageBuildDlg( )
00039 {
00040 }
00041 
00042 wxPackageBuildDlg::wxPackageBuildDlg( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
00043 {
00044     Create(parent, id, caption, pos, size, style);
00045 }
00046 
00047 bool wxPackageBuildDlg::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
00048 {
00049     m_pBuildOptPanel = NULL;
00050     m_pCompilerPanel = NULL;
00051 
00052     SetExtraStyle(GetExtraStyle()|wxWS_EX_BLOCK_EVENTS);
00053     wxDialog::Create( parent, id, caption, pos, size, style );
00054 
00055     CreateControls();
00056     if (GetSizer())
00057     {
00058 
00059         GetSizer()->SetSizeHints(this);
00060     }
00061     CentreOnScreen();
00062 
00063     return true;
00064 }
00065 
00066 void wxPackageBuildDlg::CreateControls()
00067 {
00069     wxPackageBuildDlg* itemDialog1 = this;
00070 
00071     wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
00072     itemDialog1->SetSizer(itemBoxSizer2);
00073 
00074     m_pNotebook = new wxNotebook( itemDialog1, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxNB_TOP );
00075 
00076     itemBoxSizer2->Add(m_pNotebook, 1, wxGROW|wxALL, 5);
00077 
00078     wxStdDialogButtonSizer* itemStdDialogButtonSizer4 = new wxStdDialogButtonSizer;
00079 
00080     itemBoxSizer2->Add(itemStdDialogButtonSizer4, 0, wxALIGN_RIGHT|wxALL, 5);
00081     wxButton* itemButton5 = new wxButton( itemDialog1, wxID_OK, _("&OK"), wxDefaultPosition, wxDefaultSize, 0 );
00082     itemStdDialogButtonSizer4->AddButton(itemButton5);
00083 
00084     wxButton* itemButton6 = new wxButton( itemDialog1, wxID_CANCEL, _("&Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
00085     itemStdDialogButtonSizer4->AddButton(itemButton6);
00086 
00087     itemStdDialogButtonSizer4->Realize();
00088 
00090 
00091     // build notebook tabs
00092     m_pBuildOptPanel = new wxExtCmdOptionsPanel( m_pNotebook, wxID_ANY, 
00093         wxDefaultPosition, wxDefaultSize, SYMBOL_WXEXTCMDOPTIONSPANEL_STYLE, GetTitle() );
00094     m_pNotebook->AddPage(m_pBuildOptPanel, _("Package options"));
00095 
00096     // add a static text above the usual compiler settings
00097     // (the text will be updated in SetPackage())
00098     wxPanel *panel = new wxPanel(m_pNotebook, wxID_ANY);
00099     wxSizer *sz = new wxBoxSizer(wxVERTICAL);
00100     m_pDescLabel = new wxStaticText(panel, wxID_ANY, wxT("DESCRIPTION HERE\nDESCRIPTION HERE\nDESCRIPTION HERE"));
00101     m_pCompilerPanel = new wxCompilerSettingsPanel(panel, wxID_ANY);
00102     sz->Add(m_pDescLabel, 0, wxGROW|wxALL, 5);
00103     sz->Add(m_pCompilerPanel, 1, wxGROW);
00104     panel->SetSizer(sz);
00105     sz->SetSizeHints(panel);
00106 
00107     m_pNotebook->AddPage(panel, _("Global compiler options"));
00108 }
00109 
00110 void wxPackageBuildDlg::SetPackage(const wxPackage &p)
00111 { 
00112     m_pBuildOptPanel->SetPackage(p, wxPBSS_BUILD);
00113     m_pCompilerPanel->SetPackage(p);
00114 
00115     // remember the current format (see OnPageChanged)
00116     m_last = p.GetCompilerSettings().GetSelFormat();
00117 
00118     wxString str;
00119     str.Printf(_("This package uses %s as build system.\nOnly the compilers it supports will be listed here.\nAlso note that changes to the compiler paths have global scope."),
00120 #ifdef __WXGTK20__
00121                wxString(wxT("<b>") + p.GetBuildSystemTypeStr() + wxT("</b>")).c_str()
00122 #else
00123                p.GetBuildSystemTypeStr().c_str()
00124 #endif
00125                );         
00126     m_pDescLabel->SetLabel(str);
00127 }
00128 
00129 
00130 // ----------------------------------------------------------------------------
00131 // wxPackageBuildDlg - event handlers
00132 // ----------------------------------------------------------------------------
00133 
00134 void wxPackageBuildDlg::OnPageChanged(wxNotebookEvent &WXUNUSED(ev))
00135 {
00136     if (!m_pCompilerPanel)
00137         return;     // still building the dialog!
00138 
00139     if (IsSelectedBuildOptPage())       // compiler panel => build options panel
00140     {
00141         m_pCompilerPanel->TransferDataFromWindow();
00142 
00143         wxPackage &pkg = m_pCompilerPanel->GetPackage();
00144         wxCompilerSettings &sett = pkg.GetCompilerSettings();
00145 
00146         // did the user update the currently selected compiler format
00147         // using the wxCompilerSettingsPanel panel ?
00148         if (m_last != sett.GetSelFormat())
00149         {
00150             wxStringHashMap h = sett.GetOptionsWithDefaults(pkg.GetBuildSystemType());
00151             wxString list;
00152             for( wxStringHashMap::iterator it = h.begin(); it != h.end(); ++it )
00153                 list += it->first + wxT(",");
00154             list.RemoveLast();
00155 
00156             wxLogMessage(_("You have changed the compiler to use. The options %s in the 'Package options' panel will be updated discarding any previous change..."),
00157                          list.c_str());
00158 
00159             // reset the package's options which belong to the "compiler"
00160             // group to their default value (so that the build option panel
00161             // will be forced to re-do substitutions and thus use the updated
00162             // selected compiler format):
00163             wxPackageCommandOptionArray &arr = pkg.GetBuildSysOptions();
00164             for (size_t i=0; i<arr.GetCount(); i++)
00165                 if (arr[i].GetGroup() == wxT("Compiler"))
00166                     arr[i].ResetToDefault();
00167 
00168             // very important:
00169             pkg.InvalidateCachedSubstHashMap();
00170 
00171             // update the 'compiler' presets of the options panel
00172             m_pBuildOptPanel->SetPackage(pkg, wxPBSS_BUILD);
00173             m_pBuildOptPanel->RefreshOptions();
00174 
00175             // also updates command (some keyword substitutions have changed)
00176             m_pBuildOptPanel->UpdateCommands();
00177 
00178             // update last selection
00179             m_last = sett.GetSelFormat();
00180         }
00181     }
00182     else            // build options panel => compiler panel
00183     {
00184         // move the updated package data from the build panel to the compiler panel:
00185 
00186         m_pBuildOptPanel->TransferDataFromWindow();
00187         m_pCompilerPanel->SetPackage(m_pBuildOptPanel->GetPackage());
00188     }
00189 }
00190 
00191 void wxPackageBuildDlg::OnOK(wxCommandEvent &ev)
00192 {
00193     m_pCompilerPanel->TransferDataFromWindow();
00194     m_pBuildOptPanel->TransferDataFromWindow();
00195 
00196     // let default event handler close this dialog
00197     ev.Skip();
00198 }
00199 

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