1 /*
2 * This file is part of wxSmith plugin for Code::Blocks Studio
3 * Copyright (C) 2006-2007 Bartlomiej Swiecki
4 *
5 * wxSmith is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * wxSmith is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with wxSmith. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * $Revision: 10682 $
19 * $Id: wxspositionsizeproperty.cpp 10682 2016-01-22 10:46:00Z mortenmacfly $
20 * $HeadURL: svn://svn.code.sf.net/p/codeblocks/code/branches/release-20.xx/src/plugins/contrib/wxSmith/wxwidgets/properties/wxspositionsizeproperty.cpp $
21 */
22
23 #include "wxspositionsizeproperty.h"
24
25 #include <globals.h>
26
27 // Helper macro for fetching variable
28 #define DEFVALUE wxsVARIABLE(Object,Offset,wxsPositionSizeData).IsDefault
29 #define XVALUE wxsVARIABLE(Object,Offset,wxsPositionSizeData).X
30 #define YVALUE wxsVARIABLE(Object,Offset,wxsPositionSizeData).Y
31 #define DUVALUE wxsVARIABLE(Object,Offset,wxsPositionSizeData).DialogUnits
32
33 namespace
34 {
35 // Helper values for compound property
36 enum
37 {
38 DEFIND = 1,
39 XIND,
40 YIND,
41 DUIND
42 };
43 }
44
GetPositionCode(wxsCoderContext * Context)45 wxString wxsPositionSizeData::GetPositionCode(wxsCoderContext* Context)
46 {
47 switch ( Context->m_Language )
48 {
49 case wxsCPP:
50 {
51 return IsDefault ?
52 _T("wxDefaultPosition") :
53 DialogUnits ?
54 wxString::Format(_T("wxDLG_UNIT(%s,wxPoint(%ld,%ld))"),Context->m_WindowParent.c_str(),X,Y) :
55 wxString::Format(_T("wxPoint(%ld,%ld)"),X,Y);
56 }
57
58 case wxsUnknownLanguage: // fall-through
59 default:
60 {
61 wxsCodeMarks::Unknown(_T("wxsPositionSizeData::GetPositionCode"),Context->m_Language);
62 }
63 }
64
65 return wxEmptyString;
66 }
67
GetSizeCode(wxsCoderContext * Context)68 wxString wxsPositionSizeData::GetSizeCode(wxsCoderContext* Context)
69 {
70 switch ( Context->m_Language )
71 {
72 case wxsCPP:
73 {
74 return IsDefault ?
75 _T("wxDefaultSize") :
76 DialogUnits ?
77 wxString::Format(_T("wxDLG_UNIT(%s,wxSize(%ld,%ld))"),Context->m_WindowParent.c_str(),X,Y) :
78 wxString::Format(_T("wxSize(%ld,%ld)"),X,Y);
79 }
80
81 case wxsUnknownLanguage: // fall-through
82 default:
83 {
84 wxsCodeMarks::Unknown(_T("wxsPositionSizeData::GetSizeCode"),Context->m_Language);
85 }
86 }
87
88 return wxEmptyString;
89 }
90
91
wxsPositionSizeProperty(const wxString & PGUseDefName,const wxString & _PGXName,const wxString & _PGYName,const wxString & _PGDUName,const wxString & _DataName,long _Offset,int _Priority)92 wxsPositionSizeProperty::wxsPositionSizeProperty(
93 const wxString& PGUseDefName,
94 const wxString& _PGXName,
95 const wxString& _PGYName,
96 const wxString& _PGDUName,
97 const wxString& _DataName,
98 long _Offset,
99 int _Priority):
100 wxsProperty(PGUseDefName,_DataName,_Priority),
101 PGXName(_PGXName),
102 PGYName(_PGYName),
103 PGDUName(_PGDUName),
104 Offset(_Offset)
105 {}
106
107
PGCreate(wxsPropertyContainer * Object,wxPropertyGridManager * Grid,wxPGId Parent)108 void wxsPositionSizeProperty::PGCreate(wxsPropertyContainer* Object,wxPropertyGridManager* Grid,wxPGId Parent)
109 {
110 wxPGId DefId = Grid->AppendIn(Parent,NEW_IN_WXPG14X wxBoolProperty(GetPGName(),wxPG_LABEL,DEFVALUE));
111 wxPGId XId = Grid->AppendIn(Parent,NEW_IN_WXPG14X wxIntProperty(PGXName,wxPG_LABEL,XVALUE));
112 wxPGId YId = Grid->AppendIn(Parent,NEW_IN_WXPG14X wxIntProperty(PGYName,wxPG_LABEL,YVALUE));
113 wxPGId DUId = Grid->AppendIn(Parent,NEW_IN_WXPG14X wxBoolProperty(PGDUName,wxPG_LABEL,DUVALUE));
114
115 Grid->SetPropertyAttribute(DefId,wxPG_BOOL_USE_CHECKBOX,1L,wxPG_RECURSE);
116 Grid->SetPropertyAttribute(DUId,wxPG_BOOL_USE_CHECKBOX,1L,wxPG_RECURSE);
117
118 PGRegister(Object,Grid,DefId,DEFIND);
119 PGRegister(Object,Grid,XId,XIND);
120 PGRegister(Object,Grid,YId,YIND);
121 PGRegister(Object,Grid,DUId,DUIND);
122
123 if ( DEFVALUE )
124 {
125 Grid->DisableProperty(XId);
126 Grid->DisableProperty(YId);
127 Grid->DisableProperty(DUId);
128 }
129 }
130
PGRead(wxsPropertyContainer * Object,wxPropertyGridManager * Grid,wxPGId Id,long Index)131 bool wxsPositionSizeProperty::PGRead(wxsPropertyContainer* Object,wxPropertyGridManager* Grid,wxPGId Id,long Index)
132 {
133 switch ( Index )
134 {
135 case DEFIND:
136 DEFVALUE = Grid->GetPropertyValue(Id).GetBool();
137 break;
138
139 case XIND:
140 XVALUE = Grid->GetPropertyValue(Id).GetLong();
141 break;
142
143 case YIND:
144 YVALUE = Grid->GetPropertyValue(Id).GetLong();
145 break;
146
147 case DUIND:
148 DUVALUE = Grid->GetPropertyValue(Id).GetBool();
149 break;
150
151 default:
152 break;
153 }
154
155 return true;
156 }
157
PGWrite(wxsPropertyContainer * Object,wxPropertyGridManager * Grid,wxPGId Id,long Index)158 bool wxsPositionSizeProperty::PGWrite(wxsPropertyContainer* Object,wxPropertyGridManager* Grid,wxPGId Id,long Index)
159 {
160 switch ( Index )
161 {
162 case DEFIND:
163 Grid->SetPropertyValue(Id,DEFVALUE);
164 break;
165
166 case XIND:
167 if ( DEFVALUE )
168 {
169 Grid->DisableProperty(Id);
170 }
171 else
172 {
173 Grid->EnableProperty(Id);
174 }
175 Grid->SetPropertyValue(Id,XVALUE);
176 break;
177
178 case YIND:
179 if ( DEFVALUE )
180 {
181 Grid->DisableProperty(Id);
182 }
183 else
184 {
185 Grid->EnableProperty(Id);
186 }
187 Grid->SetPropertyValue(Id,YVALUE);
188 break;
189
190 case DUIND:
191 if ( DEFVALUE )
192 {
193 Grid->DisableProperty(Id);
194 }
195 else
196 {
197 Grid->EnableProperty(Id);
198 }
199 Grid->SetPropertyValue(Id,DUVALUE);
200 break;
201
202 default:
203 break;
204 }
205 return true;
206 }
207
XmlRead(wxsPropertyContainer * Object,TiXmlElement * Element)208 bool wxsPositionSizeProperty::XmlRead(wxsPropertyContainer* Object,TiXmlElement* Element)
209 {
210 if ( !Element )
211 {
212 DEFVALUE = true;
213 XVALUE = -1;
214 YVALUE = -1;
215 DUVALUE = false;
216 return false;
217 }
218
219 const char* Text = Element->GetText();
220
221 // If no node or empty text, using default values
222 if ( !Text || !Text[0] )
223 {
224 DEFVALUE = true;
225 XVALUE = -1;
226 YVALUE = -1;
227 DUVALUE = false;
228 return false;
229 }
230 wxString Str = cbC2U(Text);
231
232 if ( Str[Str.Length()-1] == _T('d') )
233 {
234 DUVALUE = true;
235 Str.RemoveLast();
236 }
237 else
238 {
239 DUVALUE = false;
240 }
241
242 if ( !Str.BeforeFirst(_T(',')).ToLong(&XVALUE) ||
243 !Str.AfterLast(_T(',')).ToLong(&YVALUE) )
244 {
245 DEFVALUE = true;
246 XVALUE = -1;
247 YVALUE = -1;
248 DUVALUE = false;
249 return false;
250 }
251 DEFVALUE = false;
252
253 return true;
254 }
255
XmlWrite(wxsPropertyContainer * Object,TiXmlElement * Element)256 bool wxsPositionSizeProperty::XmlWrite(wxsPropertyContainer* Object,TiXmlElement* Element)
257 {
258 if ( !DEFVALUE )
259 {
260 wxString Str;
261 Str.Printf(_T("%ld,%ld%s"),XVALUE,YVALUE,DUVALUE ? _T("d") : wxEmptyString);
262 Element->InsertEndChild(TiXmlText(cbU2C(Str)));
263 return true;
264 }
265 return false;
266 }
267
PropStreamRead(wxsPropertyContainer * Object,wxsPropertyStream * Stream)268 bool wxsPositionSizeProperty::PropStreamRead(wxsPropertyContainer* Object,wxsPropertyStream* Stream)
269 {
270 bool Ret = true;
271 Stream->SubCategory(GetDataName());
272 if ( !Stream->GetBool(_T("default"),DEFVALUE,true) ) Ret = false;
273 if ( !DEFVALUE )
274 {
275 if ( !Stream->GetLong(_T("x"),XVALUE,-1) ) Ret = false;
276 if ( !Stream->GetLong(_T("y"),YVALUE,-1) ) Ret = false;
277 if ( !Stream->GetBool(_T("dialog_units"),DUVALUE,false) ) Ret = false;
278 }
279 Stream->PopCategory();
280 return Ret;
281 }
282
PropStreamWrite(wxsPropertyContainer * Object,wxsPropertyStream * Stream)283 bool wxsPositionSizeProperty::PropStreamWrite(wxsPropertyContainer* Object,wxsPropertyStream* Stream)
284 {
285 bool Ret = true;
286 Stream->SubCategory(GetDataName());
287 if ( !Stream->PutBool(_T("default"),DEFVALUE,true) ) Ret = false;
288 if ( !DEFVALUE )
289 {
290 if ( !Stream->PutLong(_T("x"),XVALUE,-1) ) Ret = false;
291 if ( !Stream->PutLong(_T("y"),YVALUE,-1) ) Ret = false;
292 if ( !Stream->PutBool(_T("dialog_units"),DUVALUE,false) ) Ret = false;
293 }
294 Stream->PopCategory();
295 return Ret;
296 }
297