opteditctrl.cpp

00001 
00002 // Name:        opteditctrl.cpp
00003 // Purpose:     wxOptionEditorCtrl
00004 // Author:      Francesco Montorsi
00005 // Modified by:
00006 // Created:     10/7/2006
00007 // RCS-ID:      $Id: opteditctrl.cpp,v 1.2 2007/02/01 20:11:27 frm Exp $
00008 // Copyright:   (c) Francesco Montorsi
00009 // Licence:     wxWindows licence
00011 
00012 // ============================================================================
00013 // declarations
00014 // ============================================================================
00015 
00016 // ----------------------------------------------------------------------------
00017 // headers
00018 // ----------------------------------------------------------------------------
00019 
00020 #include "wx/wxprec.h"
00021 
00022 #ifdef __BORLANDC__
00023     #pragma hdrstop
00024 #endif
00025 
00026 #include "guipm/opteditctrl.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 // ============================================================================
00041 // implementation
00042 // ============================================================================
00043 
00044 IMPLEMENT_DYNAMIC_CLASS( wxOptionEditorCtrl, wxPropertyGrid )
00045 DEFINE_EVENT_TYPE(wxEVT_COMMAND_OPTIONS_CHANGED)
00046 
00047 BEGIN_EVENT_TABLE( wxOptionEditorCtrl, wxPropertyGrid )
00048     EVT_PG_CHANGED(wxID_ANY, wxOptionEditorCtrl::OnOptionChanged)
00049 END_EVENT_TABLE()
00050 
00051 // ----------------------------------------------------------------------------
00052 // wxOptionEditorCtrl
00053 // ----------------------------------------------------------------------------
00054 
00055 bool wxOptionEditorCtrl::Create(wxWindow* parent, wxWindowID id,
00056                                 const wxPoint& pos, const wxSize& size,
00057                                 long style, const wxString& name)
00058 {
00059     long addstyle = wxSUNKEN_BORDER | wxPG_BOLD_MODIFIED |
00060                     wxPG_DESCRIPTION | wxPG_SPLITTER_AUTO_CENTER | wxPG_DEFAULT_STYLE;
00061     if (!wxPropertyGrid::Create(parent, id, pos, size, style|addstyle, name))
00062         return false;
00063 
00064     m_buildsys = wxPBST_INVALID;
00065     m_formats = wxGetFullPackageCompilerFormatList();
00066     m_stages = wxGetFullPackageBuildSystemStageList();
00067 
00068     return true;
00069 }
00070 
00071 /*
00072 bool wxOptionEditorCtrl::Load(wxConfigBase *p, const wxString &path)
00073 {
00074     Clear();
00075 
00076     int num = 0;
00077     if (!p->Read(path + wxT("/ComboStrNum"), &num))
00078         return false;
00079 
00080     wxString str;
00081     for (int i=0; i < num; i++)
00082         if (p->Read(path + wxString::Format(wxT("/ComboStr%d"), i), &str))
00083             Append(str);
00084     if (GetCount() > 0)
00085         Select(0);      // by default select first item
00086 
00087     // load was okay only if we could read all the saved strings
00088     return GetCount() == (size_t)num;
00089 }
00090 
00091 void wxOptionEditorCtrl::Save(wxConfigBase *p, const wxString &path) const
00092 {
00093     // order is important !
00094     for (size_t i=0; i < GetCount(); i++)
00095         p->Write(path + wxString::Format(wxT("/ComboStr%d"), i),
00096                  GetString(i));
00097     p->Write(path + wxT("/ComboStrNum"), (long)GetCount());
00098 }
00099 */
00100 
00101 bool wxOptionEditorCtrl::TransferDataToWindow()
00102 {
00103     // remove old options
00104     Clear();
00105 
00106     // add options related to this stage
00107     wxArrayString alreadyadded;
00108     for (size_t i=0; i<m_arr.GetCount(); i++)
00109     {
00110         if (!m_arr[i].GetCondition().IsValidForCurrentPlatform() ||
00111             (m_stages != 0 && !m_arr[i].GetCondition().IsValidForStages(m_stages)) ||
00112             (m_formats != 0 && !m_arr[i].GetCondition().IsValidForCompilers(m_formats)) ||
00113             (m_buildsys != wxPBST_INVALID && !m_arr[i].GetCondition().IsValidForBuildSys(m_buildsys)))
00114             continue;   // skip this
00115 
00116         // add option group if necessary
00117         if (alreadyadded.Index(m_arr[i].GetGroup()) == wxNOT_FOUND)
00118         {
00119             AppendCategory( m_arr[i].GetGroup() );
00120             alreadyadded.Add( m_arr[i].GetGroup() );
00121         }
00122         else
00123             SetCurrentCategory(m_arr[i].GetGroup());
00124 
00125         switch (m_arr[i].GetCategory())
00126         {
00127         case wxPCOC_LISTED_VALUES:
00128             {
00129                 if (m_arr[i].IsBoolean())
00130                 {
00131                     Append(wxBoolProperty( m_arr[i].GetName(), wxPG_LABEL,
00132                                            m_arr[i].GetBooleanValue() ));
00133                 }
00134                 else
00135                 {
00136                     // use values descriptions, if available
00137                     wxArrayString values = m_arr[i].GetAllowedValuesDescArray();
00138                     if (values.GetCount() == 0)
00139                         values = m_arr[i].GetAllowedValuesArray();
00140 
00141                     wxArrayInt temp;
00142                     for (size_t j=0; j < values.GetCount(); j++)
00143                         temp.Add(j);
00144 
00145                     Append(wxEnumProperty(m_arr[i].GetName(), wxPG_LABEL, values,
00146                                           temp, m_arr[i].GetValueIndex()) );
00147                 }
00148             }
00149             break;
00150 
00151         case wxPCOC_DIRECTORY:
00152             Append(wxDirProperty(m_arr[i].GetName(), wxPG_LABEL,
00153                                  m_arr[i].GetValue()));
00154             break;
00155 
00156         case wxPCOC_FILE:
00157             Append(wxFileProperty(m_arr[i].GetName(), wxPG_LABEL,
00158                                   m_arr[i].GetValue()));
00159             break;
00160 
00161         case wxPCOC_STRING:
00162             Append(wxStringProperty(m_arr[i].GetName(), wxPG_LABEL,
00163                                     m_arr[i].GetValue()));
00164             break;
00165 
00166         default:
00167             wxASSERT(0);
00168         }
00169     }
00170 
00171     if (!wxPropertyGrid::TransferDataToWindow())
00172         return false;
00173 
00174     Refresh();
00175     return true;
00176 }
00177 
00178 bool wxOptionEditorCtrl::TransferDataFromWindow()
00179 {
00180     if (!wxPropertyGrid::TransferDataFromWindow())
00181         return false;
00182 
00183     // do nothing: any change to the options in the control is
00184     // always automatically transferred to the m_arr variable
00185     // by OnOptionChanged() event handler
00186 
00187     return true;
00188 }
00189 
00190 
00191 
00192 // ----------------------------------------------------------------------------
00193 // wxOptionEditorCtrl - event handlers
00194 // ----------------------------------------------------------------------------
00195 
00196 void wxOptionEditorCtrl::OnOptionChanged(wxPropertyGridEvent &ev)
00197 {
00198     wxPackageCommandOption &opt =
00199         m_arr.ItemByName(ev.GetPropertyName());
00200     wxASSERT(opt.IsOk());
00201 
00202     // update option's value
00203     switch (opt.GetCategory())
00204     {
00205     case wxPCOC_LISTED_VALUES:
00206         if (opt.IsBoolean())
00207             opt.SetValue(ev.GetPropertyValueAsBool() == 1 ? wxT("1") : wxT("0"));
00208         else
00209             opt.SetValue(ev.GetPropertyValueAsString());
00210         break;
00211 
00212     default:
00213         opt.SetValue(ev.GetPropertyValueAsString());
00214         break;
00215     }
00216 
00217     m_arr.SetDirty(true);
00218 
00219     // send our event
00220     wxCommandEvent optchanged(wxEVT_COMMAND_OPTIONS_CHANGED, GetId());
00221     GetEventHandler()->AddPendingEvent(optchanged);
00222 }
00223 

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