00001
00002
00003
00004
00005
00006
00007
00008
00009
00011
00012
00013
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/extcmdoptionspanel.h"
00025 #include "guipm/opteditctrl.h"
00026 #include "guipm/smartmsgdlg.h"
00027 #include "guipm/wxbuildpropdlg.h"
00028
00029 #include "guicmn/commandlistbox.h"
00030
00031
00032
00033
00034
00035
00036 IMPLEMENT_DYNAMIC_CLASS( wxExtCmdOptionsPanel, wxPanel )
00037 BEGIN_EVENT_TABLE( wxExtCmdOptionsPanel, wxPanel )
00038 EVT_OPTIONS_CHANGED(ID_EXTCMD_OPTIONS, wxExtCmdOptionsPanel::OnOptionChanged)
00039 EVT_CHOICE(ID_EXTCMD_WXBUILD, wxExtCmdOptionsPanel::OnWxBuildChanged)
00040 EVT_CHOICE(ID_EXTCMD_TARGET, wxExtCmdOptionsPanel::OnTargetChanged)
00041 EVT_CHECKBOX(ID_EXTCMD_ONLYCHANGED, wxExtCmdOptionsPanel::OnOnlyChanged)
00042
00043 EVT_BUTTON(ID_EXTCMD_RESET, wxExtCmdOptionsPanel::OnReset)
00044 EVT_BUTTON(ID_EXTCMD_EDIT, wxExtCmdOptionsPanel::OnEditWxBuild)
00045
00046 EVT_UPDATE_UI(wxID_ANY, wxExtCmdOptionsPanel::OnUpdateUI)
00047 END_EVENT_TABLE()
00048
00049
00050 wxExtCmdOptionsPanel::wxExtCmdOptionsPanel( )
00051 {
00052 }
00053
00054 wxExtCmdOptionsPanel::wxExtCmdOptionsPanel( wxWindow* parent, wxWindowID id,
00055 const wxPoint& pos, const wxSize& size,
00056 long style, const wxString &name )
00057 {
00058 Create(parent, id, pos, size, style, name);
00059 }
00060
00061 bool wxExtCmdOptionsPanel::Create( wxWindow* parent, wxWindowID id, const wxPoint& pos,
00062 const wxSize& size, long style, const wxString &name )
00063 {
00064 wxPanel::Create( parent, id, pos, size, style, name );
00065
00066 CreateControls();
00067 GetSizer()->SetSizeHints(this);
00068
00069 GetSizer()->Fit(this);
00070 Centre();
00071
00072 return true;
00073 }
00074
00075 void wxExtCmdOptionsPanel::CreateControls()
00076 {
00077
00078 m_pOptionsList = new wxOptionEditorCtrl(this, ID_EXTCMD_OPTIONS);
00079 m_pCommandList = new wxCommandListBox(this, ID_EXTCMD_COMMANDS);
00080
00082 wxExtCmdOptionsPanel* itemPanel1 = this;
00083
00084 wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
00085 itemPanel1->SetSizer(itemBoxSizer2);
00086
00087 wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxHORIZONTAL);
00088 itemBoxSizer2->Add(itemBoxSizer3, 0, wxGROW|wxTOP, 5);
00089
00090 m_pLabel1 = new wxStaticText( itemPanel1, wxID_STATIC, _("%STAGE% options:"), wxDefaultPosition, wxDefaultSize, 0 );
00091 itemBoxSizer3->Add(m_pLabel1, 1, wxALIGN_BOTTOM|wxALL|wxADJUST_MINSIZE, 5);
00092
00093 wxButton* itemButton5 = new wxButton( itemPanel1, ID_EXTCMD_RESET, _("Reset to defaults"), wxDefaultPosition, wxDefaultSize, 0 );
00094 itemBoxSizer3->Add(itemButton5, 0, wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT|wxTOP, 5);
00095
00096 wxWindow* itemWindow6 = (wxWindow*) FindWindow(ID_EXTCMD_OPTIONS);
00097 wxASSERT( itemWindow6 != NULL );
00098 itemBoxSizer2->Add(itemWindow6, 5, wxGROW|wxALL, 5);
00099
00100 wxBoxSizer* itemBoxSizer7 = new wxBoxSizer(wxHORIZONTAL);
00101 itemBoxSizer2->Add(itemBoxSizer7, 0, wxGROW, 5);
00102
00103 wxStaticText* itemStaticText8 = new wxStaticText( itemPanel1, wxID_STATIC, _("wxWidgets build to use:"), wxDefaultPosition, wxDefaultSize, 0 );
00104 itemBoxSizer7->Add(itemStaticText8, 0, wxALIGN_CENTER_VERTICAL|wxALL|wxADJUST_MINSIZE, 5);
00105
00106 wxString* m_pSelBuildStrings = NULL;
00107 m_pSelBuild = new wxChoice( itemPanel1, ID_EXTCMD_WXBUILD, wxDefaultPosition, wxDefaultSize, 0, m_pSelBuildStrings, 0 );
00108 itemBoxSizer7->Add(m_pSelBuild, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5);
00109
00110 wxButton* itemButton10 = new wxButton( itemPanel1, ID_EXTCMD_EDIT, _("Edit..."), wxDefaultPosition, wxDefaultSize, 0 );
00111 itemBoxSizer7->Add(itemButton10, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
00112
00113 wxBoxSizer* itemBoxSizer11 = new wxBoxSizer(wxHORIZONTAL);
00114 itemBoxSizer2->Add(itemBoxSizer11, 0, wxGROW|wxTOP, 5);
00115
00116 wxStaticText* itemStaticText12 = new wxStaticText( itemPanel1, wxID_STATIC, _("Target:"), wxDefaultPosition, wxDefaultSize, 0 );
00117 itemBoxSizer11->Add(itemStaticText12, 0, wxALIGN_CENTER_VERTICAL|wxALL|wxADJUST_MINSIZE, 5);
00118
00119 wxString* m_pTargetListStrings = NULL;
00120 m_pTargetList = new wxChoice( itemPanel1, ID_EXTCMD_TARGET, wxDefaultPosition, wxDefaultSize, 0, m_pTargetListStrings, 0 );
00121 itemBoxSizer11->Add(m_pTargetList, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5);
00122
00123 wxBoxSizer* itemBoxSizer14 = new wxBoxSizer(wxHORIZONTAL);
00124 itemBoxSizer2->Add(itemBoxSizer14, 0, wxGROW|wxTOP, 5);
00125
00126 m_pLabel2 = new wxStaticText( itemPanel1, wxID_STATIC, _("%STAGE% commands:"), wxDefaultPosition, wxDefaultSize, 0 );
00127 itemBoxSizer14->Add(m_pLabel2, 1, wxALIGN_CENTER_VERTICAL|wxALL|wxADJUST_MINSIZE, 5);
00128
00129 m_pOnlyChangedBox = new wxCheckBox( itemPanel1, ID_EXTCMD_ONLYCHANGED, _("Show only options with non-default values"), wxDefaultPosition, wxDefaultSize, 0 );
00130 m_pOnlyChangedBox->SetValue(true);
00131 itemBoxSizer14->Add(m_pOnlyChangedBox, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
00132
00133 m_pCommandList = (wxCommandListBox*) FindWindow(ID_EXTCMD_COMMANDS);
00134 wxASSERT( m_pCommandList != NULL );
00135 itemBoxSizer2->Add(m_pCommandList, 4, wxGROW|wxALL, 5);
00136
00138
00139 m_stage = wxPBSS_INVALID;
00140
00141
00142 wxFont fnt(*wxNORMAL_FONT);
00143 fnt.SetWeight( wxFONTWEIGHT_BOLD);
00144 m_pCommandList->SetFont(fnt);
00145
00146
00147 InitWxBuildList();
00148
00149 if (m_pSelBuild->GetCount() == 0)
00150 m_pSelBuild->Append(_T("No wxWidgets builds defined!"), (void*)1);
00151
00152 m_pSelBuild->Select(0);
00153 SelectWxBuild(0);
00154 }
00155
00156 void wxExtCmdOptionsPanel::InitWxBuildList()
00157 {
00158 m_pSelBuild->Clear();
00159 for (size_t i=0; i<wxWidgetsBuildArray::s_arrWxBuilds.GetCount(); i++)
00160 m_pSelBuild->Append(wxWidgetsBuildArray::s_arrWxBuilds[i].GetUserFriendlyName(), (void*)2);
00161 }
00162
00163 void wxExtCmdOptionsPanel::SetPackage(const wxPackage &p,
00164 wxPackageBuildSystemStage stage)
00165 {
00166
00167 m_pkg = p;
00168 m_stage = stage;
00169
00170
00171 m_pLabel1->SetLabel(wxPackageBuildSystemStage2String(m_stage) + wxT(" options:"));
00172 m_pLabel2->SetLabel(wxPackageBuildSystemStage2String(m_stage) + wxT(" commands:"));
00173
00174
00175 m_pOptionsList->SetOptions(m_pkg.GetSubstBuildSysOptions());
00176 m_pOptionsList->SetCompilerFormats(m_pkg.GetCompilerSettings().GetSelFormat());
00177 m_pOptionsList->SetBuildSystemType(m_pkg.GetBuildSystemType());
00178 m_pOptionsList->SetStages(m_stage);
00179
00180
00181 UpdateCommands();
00182
00183
00184 m_pTargetList->Clear();
00185 for (size_t i=0; i<m_cmd.GetTargets().GetCount(); i++)
00186 m_pTargetList->Append(m_cmd.GetTargets().Item(i));
00187
00188
00189 if (m_pTargetList->GetCount() > 0)
00190 m_pTargetList->Select(0);
00191
00192
00193 SelectWxBuild(0);
00194 }
00195
00196 void wxExtCmdOptionsPanel::UpdateCommands()
00197 {
00198 if (m_stage == wxPBSS_INVALID)
00199 return;
00200
00201 wxPackageCondition cond;
00202 long flags = 0;
00203 if (m_pOnlyChangedBox->GetValue())
00204 flags |= wxPKGCMD_ONLY_CHANGED;
00205 else
00206 {
00207
00208
00209
00210 cond.SetBuildSystems(m_pkg.GetBuildSystemType());
00211 cond.SetPlatforms(wxPackageCondition::GetCurrentPlatform());
00212 cond.SetStages(m_stage);
00213 cond.SetFormats(m_pkg.GetCompilerSettings().GetSelFormat());
00214
00215 flags |= wxPKGCMD_ONLY_MATCHING_CONDITION;
00216 }
00217
00218
00219 m_pkg.InvalidateCachedSubstHashMap();
00220
00221
00222 m_cmd = m_pkg.GetSubstCmdForStage(m_stage, flags, cond);
00223
00224
00225 m_cmd = m_cmd.GetValidCommandsFor(m_pkg);
00226
00227
00228 m_pCommandList->Clear();
00229 for (size_t j=0, i=0; i<m_cmd.GetCount(); i++)
00230 m_pCommandList->Append(m_cmd[i]);
00231 m_pCommandList->RefreshAll();
00232 }
00233
00234 bool wxExtCmdOptionsPanel::TransferDataFromWindow()
00235 {
00236
00237 m_pkg.SetBuildSysOptions(m_pOptionsList->GetOptions());
00238
00239 return wxPanel::TransferDataFromWindow();
00240 }
00241
00242 void wxExtCmdOptionsPanel::SelectWxBuild(size_t sel)
00243 {
00244 m_selWxBuild = sel;
00245
00246 if ((int)m_pSelBuild->GetClientData(m_selWxBuild) == 1)
00247 return;
00248
00249 wxWidgetsBuildArray::s_arrWxBuilds[m_selWxBuild].
00250 UpdateOptions(m_pkg.GetBuildSysOptions());
00251 m_pOptionsList->SetOptions(m_pkg.GetSubstBuildSysOptions());
00252 UpdateCommands();
00253 }
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263 void wxExtCmdOptionsPanel::OnOptionChanged(wxCommandEvent &WXUNUSED(ev))
00264 {
00265 TransferDataFromWindow();
00266
00267
00268 UpdateCommands();
00269 }
00270
00271 void wxExtCmdOptionsPanel::OnWxBuildChanged(wxCommandEvent &WXUNUSED(ev))
00272 {
00273 int newsel = m_pSelBuild->GetSelection();
00274 if (newsel == m_selWxBuild)
00275 return;
00276
00277 wxArrayString specialopt = wxWidgetsBuild::GetSpecialOptionNames();
00278
00279
00280 TransferDataFromWindow();
00281
00282
00283 int reply =
00284 wxSmartLogYesNoQuestion(
00285 wxT("changewxbuild"),
00286 wxT("You have changed the wxWidgets build to use. This requires to change the values of the following options:\n\n%s\n\ndiscarding any previous value. Proceed?"),
00287 wxArray2String(specialopt).c_str());
00288
00289 if (reply == wxID_NO)
00290 {
00291
00292 m_pSelBuild->Select(m_selWxBuild);
00293 return;
00294 }
00295
00296
00297 SelectWxBuild(newsel);
00298 }
00299
00300 void wxExtCmdOptionsPanel::OnTargetChanged(wxCommandEvent &ev)
00301 {
00302 wxPackageCommandArray &cmd = m_pkg.GetCmdForStage(m_stage);
00303 cmd.SetSelectedTarget(ev.GetSelection());
00304 }
00305
00306 void wxExtCmdOptionsPanel::OnOnlyChanged(wxCommandEvent &WXUNUSED(ev))
00307 {
00308 UpdateCommands();
00309 }
00310
00311 void wxExtCmdOptionsPanel::OnReset(wxCommandEvent &WXUNUSED(ev))
00312 {
00313 int reply = wxMessageBox(
00314 wxString::Format(_T("Are you sure you want to reset to the default values all the options for the '%s' package ?"),
00315 m_pkg.GetName().c_str()), _T("Warning"), wxYES_NO|wxICON_QUESTION);
00316
00317 if (reply == wxYES)
00318 {
00319 m_pOptionsList->GetOptions().ResetToDefaults();
00320 m_pOptionsList->TransferDataToWindow();
00321 TransferDataFromWindow();
00322 UpdateCommands();
00323
00324 m_pSelBuild->Select(0);
00325 SelectWxBuild(0);
00326 }
00327 }
00328
00329 void wxExtCmdOptionsPanel::OnEditWxBuild(wxCommandEvent &WXUNUSED(ev))
00330 {
00331 wxPackageWXBuildPropDlg dlg(this);
00332 size_t n = m_pSelBuild->GetSelection();
00333
00334 bool editExisting = (int)m_pSelBuild->GetClientData(n) != 1;
00335 if (editExisting)
00336 dlg.SetBuild(wxWidgetsBuildArray::s_arrWxBuilds[n]);
00337
00338 if (dlg.ShowModal() == wxID_OK)
00339 {
00340 int toselect;
00341 if (editExisting)
00342 {
00343 wxWidgetsBuildArray::s_arrWxBuilds[n] = dlg.GetBuild();
00344 toselect = n;
00345 }
00346 else
00347 {
00348 wxWidgetsBuildArray::s_arrWxBuilds.Add(dlg.GetBuild());
00349 toselect = wxWidgetsBuildArray::s_arrWxBuilds.GetCount() - 1;
00350 }
00351
00352 InitWxBuildList();
00353 m_pSelBuild->Select(toselect);
00354 SelectWxBuild(toselect);
00355 }
00356 }
00357
00358 void wxExtCmdOptionsPanel::OnUpdateUI(wxUpdateUIEvent &)
00359 {
00360 FindWindowById(ID_EXTCMD_EDIT, this)->Enable(m_pSelBuild->GetSelection() != wxNOT_FOUND);
00361 }
00362