1
/** \file wxseditenumproperty.cpp
3
* This file is part of wxSmith plugin for Code::Blocks Studio
4
* Copyright (C) 2010 Gary Harris.
6
* wxSmith is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 3 of the License, or
9
* (at your option) any later version.
11
* wxSmith is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with wxSmith. If not, see <http://www.gnu.org/licenses/>.
19
* This code was taken from the wxSmithImage plug-in, copyright Ron Collins
20
* and released under the GPL.
23
#include "wxseditenumproperty.h"
27
// Helper macro for fetching variable
28
#define VALUE wxsVARIABLE(Object,Offset,wxString)
30
wxsEditEnumProperty::wxsEditEnumProperty(const wxString &PGName,
31
const wxString &DataName,
33
const wxChar **_Names,
35
const wxString &_Default,
39
wxsProperty(PGName, DataName, Priority),
42
XmlStoreEmpty(_XmlStoreEmpty),
43
UpdateEnteries(_UpdateEnteries),
45
UseNamesInXml(_UseNamesInXml)
49
// the calling routine only needs the returned value as a string
50
// the list of long Values[] is useless to the calling routine
51
// so, let us hope that we have enough Values[] here
53
for(i = 0; i < 512; i++) Values[i] = i;
56
/*! \brief Register the control with a property grid.
58
* \param Object wxsPropertyContainer*
59
* \param Grid wxPropertyGridManager*
60
* \param Parent wxPGId
64
void wxsEditEnumProperty::PGCreate(wxsPropertyContainer *Object, wxPropertyGridManager *Grid, wxPGId Parent)
66
wxPGChoices PGC(Names, Values);
68
PGRegister(Object, Grid, Grid->AppendIn(Parent, NEW_IN_WXPG14X wxEditEnumProperty(GetPGName(), wxPG_LABEL, PGC, VALUE)));
71
/*! \brief Read a property value.
73
* \param Object wxsPropertyContainer*
74
* \param Grid wxPropertyGridManager*
80
* Updated by Cryogen to use the item name rather than the enumerator value under wxPropertyGrid 1.4.
82
bool wxsEditEnumProperty::PGRead(wxsPropertyContainer *Object, wxPropertyGridManager *Grid, wxPGId Id, long Index)
84
VALUE = Grid->GetPropertyValueAsString(Id);
85
VALUE.Replace(_T("\\n"), _T("\n"));
90
/*! \brief Write a property value.
92
* \param Object wxsPropertyContainer*
93
* \param Grid wxPropertyGridManager*
99
bool wxsEditEnumProperty::PGWrite(wxsPropertyContainer *Object, wxPropertyGridManager *Grid, wxPGId Id, long Index)
101
wxString Fixed = VALUE;
103
Fixed.Replace(_T("\n"), _T("\\n"));
104
if ( UpdateEnteries )
106
#if wxCHECK_VERSION(2, 9, 0)
107
wxPGChoices choices = Grid->GetGrid()->GetSelection()->GetChoices();
108
choices.Set(Names,Values);
110
Grid->GetPropertyChoices(Id).Set(Names,Values);
113
Grid->SetPropertyValue(Id, Fixed);
117
/*! \brief Read XML data.
119
* \param Object wxsPropertyContainer*
120
* \param Element TiXmlElement*
124
bool wxsEditEnumProperty::XmlRead(wxsPropertyContainer *Object, TiXmlElement *Element)
131
// TODO: Use proper encoding
132
wxString Base = cbC2U(Element->GetText());
134
for(const wxChar *Ch = Base.c_str(); *Ch; Ch++)
144
Result << _T('&') << *Ch;
147
else if(*Ch == _T('\\'))
164
Result << _T('\\') << *Ch;
177
/*! \brief Write XML data.
179
* \param Object wxsPropertyContainer*
180
* \param Element TiXmlElement*
184
bool wxsEditEnumProperty::XmlWrite(wxsPropertyContainer *Object, TiXmlElement *Element)
186
if(XmlStoreEmpty || (VALUE != Default))
188
wxString Base = VALUE;
190
for(const wxChar *Ch = Base.c_str(); *Ch; Ch++)
196
break; // TODO: This is NOT compatible with xrc file when there's no version entry or version is less than 2.3.0.1
197
//case _T('&'): Result << _T('_'); break; // We could leave this to be translated into & but this looks nicer ;)
199
Result << _T("\\\\");
201
// We could handle \n and \r here too but this is not necessary since XRC loading
202
// routines also handle \n and \r chars
207
// TODO: Use proper encoding
208
Element->InsertEndChild(TiXmlText(cbU2C(Result)));
214
/*! \brief Read from a property stream.
216
* \param Object wxsPropertyContainer*
217
* \param Stream wxsPropertyStream*
221
bool wxsEditEnumProperty::PropStreamRead(wxsPropertyContainer *Object, wxsPropertyStream *Stream)
223
return Stream->GetString(GetDataName(), VALUE, Default);
226
/*! \brief Write to a property stream.
228
* \param Object wxsPropertyContainer*
229
* \param Stream wxsPropertyStream*
233
bool wxsEditEnumProperty::PropStreamWrite(wxsPropertyContainer *Object, wxsPropertyStream *Stream)
235
return Stream->PutString(GetDataName(), VALUE, Default);