00001
00002
00003
00004
00005
00006
00007
00008
00009
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "wx/wxprec.h"
00021
00022 #ifdef __BORLANDC__
00023 #pragma hdrstop
00024 #endif
00025
00026 #include "guipkg/optlistctrl.h"
00027
00028 #ifndef WX_PRECOMP
00029 #include "wx/log.h"
00030 #include "wx/combobox.h"
00031 #include "wx/dcclient.h"
00032 #include "wx/settings.h"
00033 #endif
00034
00035 #include "wx/config.h"
00036 #include "wxp/package.h"
00037
00038
00039
00040 #define NUMCOLUMNS 3
00041
00042
00043
00044
00045
00046
00047
00048
00049 IMPLEMENT_DYNAMIC_CLASS( wxOptionListCtrl, wxTreeListCtrl )
00050 DEFINE_EVENT_TYPE(wxEVT_COMMAND_OPTION_DCLICK)
00051 BEGIN_EVENT_TABLE( wxOptionListCtrl, wxTreeListCtrl )
00052 EVT_TREE_ITEM_ACTIVATED( wxID_ANY, wxOptionListCtrl::OnItemActivated )
00053 END_EVENT_TABLE()
00054
00055
00056
00057
00058
00059 bool wxOptionListCtrl::Create(wxWindow* parent, wxWindowID id,
00060 const wxPoint& pos, const wxSize& size,
00061 long WXUNUSED(style), const wxString& name)
00062 {
00063 if (!wxTreeListCtrl::Create(parent, id, pos, size,
00064 wxTR_HAS_BUTTONS|wxTR_HIDE_ROOT|wxTR_NO_LINES|wxTR_FULL_ROW_HIGHLIGHT,
00065 wxDefaultValidator, name))
00066 return false;
00067
00068 m_buildsys = wxPBST_INVALID;
00069 m_formats = wxGetFullPackageCompilerFormatList();
00070 m_stages = wxGetFullPackageBuildSystemStageList();
00071
00072 AddColumn(wxT("Name"), 150, wxALIGN_LEFT);
00073 AddColumn(wxT("Allowed values"), 100, wxALIGN_CENTER);
00074 AddColumn(wxT("Default"), 100, wxALIGN_CENTER);
00075
00076 #if NUMCOLUMNS >= 3
00077 AddColumn(wxT("Stages"), 100, wxALIGN_CENTER);
00078 #endif
00079 #if NUMCOLUMNS >= 4
00080 AddColumn(wxT("Formats"), 100, wxALIGN_RIGHT);
00081 #endif
00082 return true;
00083 }
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115 bool wxOptionListCtrl::TransferDataToWindow()
00116 {
00117 if (!wxTreeListCtrl::TransferDataToWindow())
00118 return false;
00119
00120
00121 DeleteRoot();
00122
00123
00124 wxTreeItemId root = AddRoot(wxT("Options"));
00125
00126
00127 wxArrayString alreadyadded;
00128 wxArrayTreeItemIds groupsid;
00129 wxString str;
00130 for (size_t i=0; i<m_arr.GetCount(); i++)
00131 {
00132
00133
00134 if ((m_stages != 0 && !m_arr[i].GetCondition().IsValidForStages(m_stages)) ||
00135 (m_formats != 0 && !m_arr[i].GetCondition().IsValidForCompilers(m_formats)) ||
00136 (m_buildsys != wxPBST_INVALID && !m_arr[i].GetCondition().IsValidForBuildSys(m_buildsys)))
00137 continue;
00138
00139
00140 wxTreeItemId id;
00141 if (alreadyadded.Index(m_arr[i].GetGroup()) == wxNOT_FOUND)
00142 {
00143 id = AppendItem( root, m_arr[i].GetGroup() );
00144 alreadyadded.Add( m_arr[i].GetGroup() );
00145 groupsid.Add( id );
00146 }
00147 else
00148 {
00149 int idx = alreadyadded.Index(m_arr[i].GetGroup());
00150 wxASSERT(idx != wxNOT_FOUND);
00151 id = groupsid[idx];
00152 }
00153
00154
00155 wxTreeItemId item = AppendItem(id, m_arr[i].GetName());
00156
00157
00158 str = m_arr[i].GetAllowedValues();
00159 str.Replace(wxT(","), wxT(", "));
00160 SetItemText(item, 1, str);
00161
00162
00163 SetItemText(item, 2, m_arr[i].GetDefaultValue());
00164
00165 #if NUMCOLUMNS >= 3
00166
00167 if (m_arr[i].GetCondition().GetStages() ==
00168 wxGetFullPackageBuildSystemStageList())
00169 str = wxT("All");
00170 else
00171 {
00172 str = m_arr[i].GetCondition().GetStagesStr();
00173 str.Replace(wxT(","), wxT(", "));
00174 }
00175
00176 SetItemText(item, 3, str);
00177 #endif
00178
00179 #if NUMCOLUMNS >= 4
00180
00181 if (m_arr[i].GetCondition().GetFormats() ==
00182 wxGetFullPackageCompilerFormatList())
00183 str = wxT("All");
00184 else
00185 {
00186 str = m_arr[i].GetCondition().GetFormatsStr();
00187 str.Replace(wxT(","), wxT(", "));
00188 }
00189
00190 SetItemText(item, 4, str);
00191 #endif
00192 }
00193
00194 ExpandAll(GetRootItem());
00195 Refresh();
00196 return true;
00197 }
00198
00199 bool wxOptionListCtrl::TransferDataFromWindow()
00200 {
00201 if (!wxTreeListCtrl::TransferDataFromWindow())
00202 return false;
00203
00204
00205
00206
00207 return true;
00208 }
00209
00210 void wxOptionListCtrl::DeleteSelected()
00211 {
00212 int n = m_arr.IndexByName(GetSelectedOptName());
00213 wxASSERT(n != wxNOT_FOUND);
00214
00215
00216 m_arr.RemoveAt(n);
00217
00218
00219
00220
00221 TransferDataToWindow();
00222 }
00223
00224 wxString wxOptionListCtrl::GetSelectedOptName() const
00225 {
00226 wxASSERT(GetSelection().IsOk());
00227
00228
00229 if (GetItemParent(GetSelection()) == GetRootItem())
00230 return wxEmptyString;
00231
00232
00233 return GetItemText(GetSelection(), 0);
00234 }
00235
00236
00237
00238
00239
00240
00241 void wxOptionListCtrl::OnItemActivated(wxTreeEvent &ev)
00242 {
00243
00244 if (GetItemParent(ev.GetItem()) == GetRootItem())
00245 return;
00246
00247 wxCommandEvent optdclick(wxEVT_COMMAND_OPTION_DCLICK, GetId());
00248
00249
00250 optdclick.SetString(GetItemText(ev.GetItem(), 0));
00251 GetEventHandler()->AddPendingEvent(optdclick);
00252 }