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/presetspanel.h"
00025 #include "guipm/opteditctrl.h"
00026 #include "wxp/package.h"
00027 #include "wxp/wxp.h"
00028
00029
00030
00031
00032
00033
00034
00035 IMPLEMENT_DYNAMIC_CLASS( wxPackagePresetsPanel, wxPanel )
00036 BEGIN_EVENT_TABLE( wxPackagePresetsPanel, wxPanel )
00037 EVT_BUTTON( ID_PRESETS_RESET,
00038 wxPackagePresetsPanel::OnResetToDefaults)
00039 EVT_CHOICE( ID_PRESETS_PRESETCHOICE,
00040 wxPackagePresetsPanel::OnPresetChanged)
00041 EVT_OPTIONS_CHANGED( ID_PRESETS_OPTIONS,
00042 wxPackagePresetsPanel::OnOptionChanged)
00043 END_EVENT_TABLE()
00044
00045 wxPackagePresetsPanel::wxPackagePresetsPanel( )
00046 {
00047 }
00048
00049 wxPackagePresetsPanel::wxPackagePresetsPanel( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
00050 {
00051 Create(parent, id, pos, size, style);
00052 }
00053
00054 bool wxPackagePresetsPanel::Create( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
00055 {
00057 m_pPresetChoice = NULL;
00059
00061 SetExtraStyle(GetExtraStyle()|wxWS_EX_BLOCK_EVENTS);
00062 wxPanel::Create( parent, id, pos, size, style );
00063
00064 CreateControls();
00065 if (GetSizer())
00066 {
00067 GetSizer()->SetSizeHints(this);
00068 }
00069 Centre();
00071 return true;
00072 }
00073
00074 void wxPackagePresetsPanel::CreateControls()
00075 {
00076 m_pOptionsList = new wxOptionEditorCtrl(this, ID_PRESETS_OPTIONS);
00077
00079 wxPackagePresetsPanel* itemPanel1 = this;
00080
00081 wxStaticBox* itemStaticBoxSizer2Static = new wxStaticBox(itemPanel1, wxID_ANY, _("Default option values"));
00082 wxStaticBoxSizer* itemStaticBoxSizer2 = new wxStaticBoxSizer(itemStaticBoxSizer2Static, wxVERTICAL);
00083 itemPanel1->SetSizer(itemStaticBoxSizer2);
00084
00085 wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxHORIZONTAL);
00086 itemStaticBoxSizer2->Add(itemBoxSizer3, 0, wxGROW, 5);
00087
00088 wxStaticText* itemStaticText4 = new wxStaticText( itemPanel1, wxID_STATIC, _("Shows option set:"), wxDefaultPosition, wxDefaultSize, 0 );
00089 itemBoxSizer3->Add(itemStaticText4, 0, wxALIGN_CENTER_VERTICAL|wxALL|wxADJUST_MINSIZE, 5);
00090
00091 wxString* m_pPresetChoiceStrings = NULL;
00092 m_pPresetChoice = new wxChoice( itemPanel1, ID_PRESETS_PRESETCHOICE, wxDefaultPosition, wxDefaultSize, 0, m_pPresetChoiceStrings, 0 );
00093 itemBoxSizer3->Add(m_pPresetChoice, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5);
00094
00095 wxButton* itemButton6 = new wxButton( itemPanel1, ID_PRESETS_RESET, _("Reset to defaults"), wxDefaultPosition, wxDefaultSize, 0 );
00096 itemBoxSizer3->Add(itemButton6, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
00097
00098 wxWindow* itemWindow7 = (wxWindow*) FindWindow(ID_PRESETS_OPTIONS);
00099 wxASSERT( itemWindow7 != NULL );
00100 itemStaticBoxSizer2->Add(itemWindow7, 1, wxGROW|wxALL, 5);
00101
00103
00104
00105 m_optHashmap = wxPresetXMLDescriptor::s_hashmapOptions;
00106 wxPackageCommandOptionArrayHashMap::iterator it;
00107 for( it = m_optHashmap.begin(); it != m_optHashmap.end(); ++it )
00108 {
00109
00110
00111
00112 m_pPresetChoice->Append(it->first, new wxStringClientData(it->first));
00113 }
00114
00115
00116 if (m_pPresetChoice->GetCount() > 0)
00117 m_pPresetChoice->SetSelection(0);
00118
00119 UpdatePresetChoiceStrings();
00120
00121 wxCommandEvent fake;
00122 OnPresetChanged(fake);
00123 }
00124
00125 bool wxPackagePresetsPanel::ShowToolTips()
00126 {
00127 return true;
00128 }
00129
00130 bool wxPackagePresetsPanel::TransferDataFromWindow()
00131 {
00132
00133 if (!m_strCurPresetSelection.empty())
00134 m_optHashmap[m_strCurPresetSelection] = m_pOptionsList->GetOptions();
00135
00136 return true;
00137 }
00138
00139 wxString wxPackagePresetsPanel::GetPresetName(unsigned int n) const
00140 {
00141
00142 return ((wxStringClientData*)m_pPresetChoice->GetClientObject(n))->GetData();
00143 }
00144
00145 void wxPackagePresetsPanel::UpdatePresetChoiceStrings()
00146 {
00147
00148 int n = m_pPresetChoice->GetSelection();
00149
00150 for (size_t i=0; i<m_pPresetChoice->GetCount(); i++)
00151 {
00152 wxString name = GetPresetName(i);
00153 if (m_optHashmap[name].IsDirty())
00154 name += wxT(" *");
00155
00156 m_pPresetChoice->SetString(i, name);
00157 }
00158
00159 m_pPresetChoice->SetSelection(n);
00160 }
00161
00162 void wxPackagePresetsPanel::ApplySettings()
00163 {
00164 TransferDataFromWindow();
00165 wxPresetXMLDescriptor::s_hashmapOptions = m_optHashmap;
00166 }
00167
00168
00169
00170
00171
00172
00173
00174 void wxPackagePresetsPanel::OnPresetChanged(wxCommandEvent &WXUNUSED(ev))
00175 {
00176
00177 TransferDataFromWindow();
00178
00179
00180 m_strCurPresetSelection = GetPresetName(m_pPresetChoice->GetSelection());
00181 const wxPackageCommandOptionArray &arr = m_optHashmap[m_strCurPresetSelection];
00182
00183
00184 m_pOptionsList->Clear();
00185 m_pOptionsList->SetOptions(arr);
00186 m_pOptionsList->Refresh();
00187 }
00188
00189 void wxPackagePresetsPanel::OnResetToDefaults(wxCommandEvent &ev)
00190 {
00191 int reply = wxMessageBox(
00192 wxString::Format(_T("Are you sure you want to reset to the default values all the options for the '%s' preset ?"),
00193 m_strCurPresetSelection.c_str()), _T("Warning"), wxYES_NO|wxICON_QUESTION);
00194
00195 if (reply == wxYES)
00196 {
00197 m_optHashmap[m_strCurPresetSelection].ResetToDefaults();
00198 m_optHashmap[m_strCurPresetSelection].SetDirty();
00199 UpdatePresetChoiceStrings();
00200
00201
00202
00203
00204 m_strCurPresetSelection.Empty();
00205 OnPresetChanged(ev);
00206 }
00207 }
00208
00209 void wxPackagePresetsPanel::OnOptionChanged(wxCommandEvent &WXUNUSED(ev))
00210 {
00211
00212 m_optHashmap[m_strCurPresetSelection].SetDirty();
00213 UpdatePresetChoiceStrings();
00214 }
00215