1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // wxFormBuilder - A Visual Dialog Editor for wxWidgets.
4 // Copyright (C) 2005 José Antonio Hurtado
5 //
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
10 //
11 // This program 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.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19 //
20 // Written by
21 //   José Antonio Hurtado - joseantonio.hurtado@gmail.com
22 //   Juan Antonio Ortega  - jortegalalmolda@gmail.com
23 //
24 ///////////////////////////////////////////////////////////////////////////////
25 
26 #include "model/types.h"
27 #include <wx/tokenzr.h>
28 #include "utils/stringutils.h"
29 #include "utils/debug.h"
30 #include "utils/typeconv.h"
31 
32 #include <cstdlib>
33 
ObjectType(wxString name,int id,bool hidden,bool item)34 ObjectType::ObjectType(wxString name, int id, bool hidden, bool item)
35 {
36 	m_id = id;
37 	m_name = name;
38 	m_hidden = hidden;
39 	m_item = item;
40 }
41 
AddChildType(PObjectType type,int max,int aui_max)42 void ObjectType::AddChildType(PObjectType type, int max, int aui_max)
43 {
44 	/*assert(max != 0);
45 	assert(aui_max != 0);*/
46 	m_childTypes.insert(ChildTypeMap::value_type(type,ChildCount(max, aui_max)));
47 }
48 
FindChildType(int type_id,bool aui)49 int ObjectType::FindChildType(int type_id, bool aui)
50 {
51 	int max = 0;
52 	ChildTypeMap::iterator it;
53 	for (it = m_childTypes.begin(); it != m_childTypes.end() && max == 0; it++)
54 	{
55 		PObjectType type(it->first);
56 		if (type && type_id == type->GetId())
57 		{
58 			if( aui ) max = it->second.aui_max;
59 			else
60 				max = it->second.max;
61 		}
62 	}
63 	return max;
64 }
65 
FindChildType(PObjectType type,bool aui)66 int ObjectType::FindChildType(PObjectType type, bool aui)
67 {
68 	int type_id = type->GetId();
69 	return FindChildType(type_id, aui);
70 }
71 
GetChildTypeCount()72 unsigned int ObjectType::GetChildTypeCount()
73 {
74 	return (unsigned int)m_childTypes.size();
75 }
76 
GetChildType(unsigned int idx)77 PObjectType ObjectType::GetChildType(unsigned int idx)
78 {
79 	PObjectType result;
80 
81 	assert (idx < GetChildTypeCount());
82 
83 	unsigned int i = 0;
84 	ChildTypeMap::iterator it = m_childTypes.begin();
85 
86 	while (i < idx && it != m_childTypes.end())
87 	{
88 		i++;
89 		it++;
90 	}
91 
92 	if (i == idx)
93 		result = PObjectType(it->first);
94 
95 
96 	return result;
97 }
98 
99 ///////////////////////////////////////////////////////////////////////////////
100 
IntList(wxString value,bool absolute_value)101 IntList::IntList(wxString value, bool absolute_value )
102 	:
103 	m_abs( absolute_value )
104 {
105 	SetList(value);
106 }
107 
Add(int value)108 void IntList::Add(int value)
109 {
110 	m_ints.push_back( m_abs ? std::abs(value) : value );
111 }
112 
DeleteList()113 void IntList::DeleteList()
114 {
115 	m_ints.erase(m_ints.begin(), m_ints.end());
116 }
117 
SetList(wxString str)118 void IntList::SetList(wxString str)
119 {
120 	DeleteList();
121 	wxStringTokenizer tkz(str, wxT(","));
122 	while (tkz.HasMoreTokens())
123 	{
124 		long value;
125 		wxString token;
126 		token = tkz.GetNextToken();
127 		token.Trim(true);
128 		token.Trim(false);
129 
130 		if (token.ToLong(&value))
131 			Add((int)value);
132 	}
133 }
134 
ToString()135 wxString IntList::ToString()
136 {
137 	wxString result;
138 
139 	if (m_ints.size() > 0)
140 	{
141 		result = StringUtils::IntToStr(m_ints[0]);
142 
143 		for (unsigned int i=1; i< m_ints.size() ; i++)
144 			result = result + wxT(",") + StringUtils::IntToStr(m_ints[i]);
145 	}
146 
147 	return result;
148 }
149