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 #ifndef __TYPES__
27 #define __TYPES__
28 
29 #include <vector>
30 #include <wx/string.h>
31 #include <map>
32 #include <boost/smart_ptr.hpp>
33 
34 #include "wx/wx.h"
35 
36 class ObjectType;
37 
38 typedef boost::shared_ptr<ObjectType> PObjectType;
39 typedef boost::weak_ptr<ObjectType> WPObjectType;
40 
41 /**
42  * Representa el tipo de objeto.
43  *
44  * Los tipos de objetos son necesarios para controlar las restricciones de
45  * ubicación de los objetos dentro del árbol. Dichas restricciones vendrán
46  * establecidas en el fichero objtypes.xml, y en principio se pueden definir
47  * tantos tipos de objetos como sean necesarios.
48  *
49  * Aunque el conjunto de tipos está pensado para que sea fácilmente modificable,
50  * actualmente, en el código hay muchas dependencias con los nombres de tipos
51  * concretos. Así que una modificación en el nombre de un tipo casi con toda
52  * seguridad causará fallos en el funcionamiento de la aplicación.
53  *
54  * @todo hay que eliminar las dependencias en el código con los nombres de los
55  *       tipos. Para ello lo mejor será definir una serie de atributos asociados
56  *       al tipo.
57  *       Por ejemplo, los objetos que sean "items" (objetos ficticios
58  *       que añaden ciertas propiedades al objeto que contiene como puede ser
59  *       un sizeritem), no deben aparecer en el "object tree" y deben mostrar
60  *       las propiedades junto con las del objeto que contiene en el "object
61  *       inspector". En ese caso, tanto el "object tree" como el
62  *        "object inspector" consultarán al tipo si éste tiene el
63  *       atributo item a true.
64  */
65 class ObjectType
66 {
67 public:
68 
69 	ObjectType(wxString name, int id, bool hidden = false, bool item = false);
70 
GetId()71 	int    GetId()
72 	{
73 		return m_id;
74 	}
GetName()75 	wxString GetName()
76 	{
77 		return m_name;
78 	}
79 	//bool   IsHidden()  { return m_hidden; }
IsItem()80 	bool   IsItem()
81 	{
82 		return m_item;
83 	}
84 
85 
86 	/**
87 	 * Añade el tipo de objeto a la lista de posibles hijos.
88 	 */
89 	void AddChildType(PObjectType type, int max = -1, int aui_max = -1);
90 
91 	/**
92 	 * Busca si el tipo pasado como parámetros está entre sus posibles
93 	 * hijos.
94 	 * @return numero máximo de ocurrencias del objeto como hijo.
95 	 *         -1 = numero ilimitado, 0 = ninguna
96 	 */
97 	int FindChildType(int type_id, bool aui);
98 	int FindChildType(PObjectType type, bool aui);
99 
100 	unsigned int GetChildTypeCount();
101 	PObjectType GetChildType(unsigned int idx);
102 
103 private:
104 	class ChildCount
105 	{
106 	public:
ChildCount(int m,int am)107 		ChildCount(int m, int am) : max(m), aui_max(am) {;}
108 		int max;
109 		int aui_max;
110 	};
111 
112 	/**
113 	 * Registro con los tipos de los hijos posibles y el número máximo
114 	 * de estos.
115 	 * @note vamos a usar smart-pointers de tipo "weak" ya que puede haber muchas
116 	 *       referencias cruzadas.
117 	 */
118 	typedef std::map<WPObjectType, ChildCount> ChildTypeMap;
119 
120 	int m_id;        /**< identificador numérico del tipo de objeto */
121 	wxString m_name;   /**< cadena de texto asociado al tipo */
122 	bool m_hidden;   /**< indica si está oculto en el ObjectTree */
123 	bool m_item;     /**< indica si es un "item". Los objetos contenidos en
124                      *  en un item, muestran las propiedades de éste junto
125                      *  con las propias del objeto.
126                      */
127 
128 	ChildTypeMap m_childTypes; /**< registro de posibles hijos */
129 };
130 
131 /**
132  * Tipos de propiedades.
133  */
134 typedef enum
135 {
136 	PT_ERROR,
137 	PT_BOOL,
138 	PT_TEXT,
139 	PT_INT,
140 	PT_UINT,
141 	PT_BITLIST,
142 	PT_INTLIST,
143 	PT_UINTLIST,
144 	PT_OPTION,
145 	PT_MACRO,
146 	PT_WXSTRING,
147 	PT_WXPOINT,
148 	PT_WXSIZE,
149 	PT_WXFONT,
150 	PT_WXCOLOUR,
151 	PT_WXPARENT,
152 	PT_PATH,
153 	PT_FILE,
154 	PT_BITMAP,
155 	PT_STRINGLIST,
156 	PT_FLOAT,
157 	PT_WXSTRING_I18N,
158 	PT_PARENT,
159 	PT_CLASS
160 } PropertyType;
161 /*
162 typedef enum
163 {
164   W_NO_WIDGET,
165   W_GENERIC,    // para el caso de que nuestro widget no esté incluido
166   W_BUTTON,
167   W_COMBO_BOX,
168   W_TEXT_CTRL,
169   W_STATIC_TEXT,
170   W_PANEL,
171   W_BOX_SIZER,
172   W_GRID_SIZER,
173   W_FLEX_GRID_SIZER,
174   W_CHECK_BOX,
175   W_SPACER,
176   W_SIZERITEM,
177   W_GRID,
178   W_STATIC_BITMAP
179   //W_PLUGIN
180 } WidgetType;
181 */
182 /**
183  * Lista de enteros.
184  */
185 class IntList
186 {
187 private:
188 	typedef std::vector<int> IntVector;
189 	IntVector m_ints;
190 	bool m_abs;
191 
192 public:
193 	IntList( bool absolute_value = false )
194 		:
m_abs(absolute_value)195 		m_abs( absolute_value )
196 	{
197 	}
198 
199 	IntList(wxString value, bool absolute_value = false );
200 
GetSize()201 	unsigned int GetSize()
202 	{
203 		return (unsigned int)m_ints.size();
204 	};
GetValue(unsigned int idx)205 	int GetValue(unsigned int idx)
206 	{
207 		return m_ints[idx];
208 	};
209 	void Add(int value);
210 	void DeleteList();
211 	void SetList(wxString str);
212 	wxString ToString();
213 };
214 
215 
216 #endif // __TYPES__
217