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"
28
// Helper macro for fetching variable
29
#define VALUE wxsVARIABLE(Object,Offset,wxString)
31
wxsEditEnumProperty::wxsEditEnumProperty(const wxString &PGName,
32
const wxString &DataName,
34
const wxChar **_Names,
36
const wxString &_Default,
40
wxsProperty(PGName, DataName, Priority),
43
XmlStoreEmpty(_XmlStoreEmpty),
44
UpdateEntries(_UpdateEntries),
46
UseNamesInXml(_UseNamesInXml)
50
// the calling routine only needs the returned value as a string
51
// the list of long Values[] is useless to the calling routine
52
// so, let us hope that we have enough Values[] here
54
for(i = 0; i < 512; i++) Values[i] = i;
57
/*! \brief Register the control with a property grid.
59
* \param Object wxsPropertyContainer*
60
* \param Grid wxPropertyGridManager*
61
* \param Parent wxPGId
65
void wxsEditEnumProperty::PGCreate(wxsPropertyContainer *Object, wxPropertyGridManager *Grid, wxPGId Parent)
67
wxPGChoices PGC(Names, Values);
69
PGRegister(Object, Grid, Grid->AppendIn(Parent, NEW_IN_WXPG14X wxEditEnumProperty(GetPGName(), wxPG_LABEL, PGC, VALUE)));
72
/*! \brief Read a property value.
74
* \param Object wxsPropertyContainer*
75
* \param Grid wxPropertyGridManager*
81
* Updated by Cryogen to use the item name rather than the enumerator value under wxPropertyGrid 1.4.
83
bool wxsEditEnumProperty::PGRead(cb_unused wxsPropertyContainer *Object,
84
wxPropertyGridManager *Grid, wxPGId Id,
87
VALUE = Grid->GetPropertyValueAsString(Id);
88
VALUE.Replace(_T("\\n"), _T("\n"));
93
/*! \brief Write a property value.
95
* \param Object wxsPropertyContainer*
96
* \param Grid wxPropertyGridManager*
102
bool wxsEditEnumProperty::PGWrite(cb_unused wxsPropertyContainer *Object,
103
wxPropertyGridManager *Grid, wxPGId Id,
104
cb_unused long Index)
106
wxString Fixed = VALUE;
108
Fixed.Replace(_T("\n"), _T("\\n"));
111
#if wxCHECK_VERSION(2, 9, 0)
112
wxPGChoices(Id->GetChoices()).Set(Names,Values);
114
Grid->GetPropertyChoices(Id).Set(Names,Values);
117
Grid->SetPropertyValue(Id, Fixed);
121
/*! \brief Read XML data.
123
* \param Object wxsPropertyContainer*
124
* \param Element TiXmlElement*
128
bool wxsEditEnumProperty::XmlRead(cb_unused wxsPropertyContainer *Object,
129
TiXmlElement *Element)
136
// TODO: Use proper encoding
137
wxString Base = cbC2U(Element->GetText());
139
for(const wxChar *Ch = Base.c_str(); *Ch; Ch++)
149
Result << _T('&') << *Ch;
152
else if(*Ch == _T('\\'))
169
Result << _T('\\') << *Ch;
182
/*! \brief Write XML data.
184
* \param Object wxsPropertyContainer*
185
* \param Element TiXmlElement*
189
bool wxsEditEnumProperty::XmlWrite(cb_unused wxsPropertyContainer *Object,
190
TiXmlElement *Element)
192
if(XmlStoreEmpty || (VALUE != Default))
194
wxString Base = VALUE;
196
for(const wxChar *Ch = Base.c_str(); *Ch; Ch++)
202
break; // TODO: This is NOT compatible with xrc file when there's no version entry or version is less than 2.3.0.1
203
//case _T('&'): Result << _T('_'); break; // We could leave this to be translated into & but this looks nicer ;)
205
Result << _T("\\\\");
207
// We could handle \n and \r here too but this is not necessary since XRC loading
208
// routines also handle \n and \r chars
213
// TODO: Use proper encoding
214
Element->InsertEndChild(TiXmlText(cbU2C(Result)));
220
/*! \brief Read from a property stream.
222
* \param Object wxsPropertyContainer*
223
* \param Stream wxsPropertyStream*
227
bool wxsEditEnumProperty::PropStreamRead(cb_unused wxsPropertyContainer *Object,
228
wxsPropertyStream *Stream)
230
return Stream->GetString(GetDataName(), VALUE, Default);
233
/*! \brief Write to a property stream.
235
* \param Object wxsPropertyContainer*
236
* \param Stream wxsPropertyStream*
240
bool wxsEditEnumProperty::PropStreamWrite(cb_unused wxsPropertyContainer *Object,
241
wxsPropertyStream *Stream)
243
return Stream->PutString(GetDataName(), VALUE, Default);