summaryrefslogtreecommitdiff
path: root/SkinEngine/src/skin_object.h
blob: 8d8c4661b8227d98d3d6dc142b7e7c7f31b2cb9a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#ifndef skin_object_h__
#define skin_object_h__

class CSkinObject: public ISkinElement
{
protected:
	// ganaral options
	TCHAR *m_id;
	ISkinDataSource *m_ds;
	ISkinElement *m_parent;

	// options from skin data
	int m_width, m_height;
	int m_stateMask;

	// dynamic parameters
	RECT m_rcPosition;

	// properties
	struct Property
	{
		enum { None, Text, Integer } m_type;
		TCHAR *m_key;
		union
		{
			TCHAR *m_valueText;
			int m_valueInt;
		};

		Property(const TCHAR *key, int value)
		{
			m_type = Integer;
			m_key = _tcsdup(key);
			m_valueInt = value;
		}
		Property(const TCHAR *key, const TCHAR *value)
		{
			m_type = Text;
			m_key = _tcsdup(key);
			m_valueText = _tcsdup(value);
		}
		~Property()
		{
			free(m_key);
			if (m_type == Text) free(m_valueText);
		}

		static int cmp(const Property *p1, const Property *p2)
		{
			return lstrcmp(p1->m_key, p2->m_key);
		}
	};
	OBJLIST<Property> m_properties;

public:
	CSkinObject(): m_id(0), m_ds(0), m_parent(0), m_properties(5, Property::cmp)
	{
	}
	virtual ~CSkinObject()
	{
		if (m_id) free(m_id);
	}

public:	// ISkinElement implementation
	virtual void SetParent(ISkinElement *parent);
	virtual void SetId(const TCHAR *id);
	virtual void SetDataSource(ISkinDataSource *ds);
	virtual void Destroy();

	virtual void LoadFromXml(HXML hXml);
	virtual void Measure(SkinRenderParams *params);
	virtual void Layout(SkinRenderParams *params);
	virtual void Paint(SkinRenderParams *params) = 0;

	virtual bool IsComplexObject();
	virtual ISkinElement *GetParent();
	virtual int GetChildCount();
	virtual ISkinElement *GetChild(int index);
	virtual bool AppendChild(ISkinElement *child);
	virtual bool InsertChild(ISkinElement *child, int index);
	virtual void RemoveChild(ISkinElement *child);

	virtual void SetPropText(const TCHAR *key, const TCHAR *value);
	virtual const TCHAR *GetPropText(const TCHAR *key, const TCHAR *value);
	virtual void SetPropInt(const TCHAR *key, int value);
	virtual void SetPropIntText(const TCHAR *key, const TCHAR *value);
	virtual int GetPropInt(const TCHAR *key);
};

#endif // skin_object_h__