My favorites | Sign in
Project Home Downloads Source
Checkout   Browse   Changes    
 
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#ifndef FORM_EDITOR_PROPERTIES__PROPERTIES_EDITOR_H
#define FORM_EDITOR_PROPERTIES__PROPERTIES_EDITOR_H

#include "Property.h"
#include "PropertyCaller.h"
#include <ExpandFrame/ExpandFrame.h>
#include <FormEditorCommon/FormEditorCommon.h>

#define LAYOUTFILE <FormEditorProperties/FormEditorProperties.lay>
#include <CtrlCore/lay.h>

template <class T>
class PropertiesWindowBase : public WithPropertiesLayout<TopWindow>
{
typedef PropertiesWindowBase CLASSNAME;

protected:
T* GetProperties() { return _Properties; }
virtual void Cancel();
virtual void Load();
virtual void Save();

public:
PropertiesWindowBase(T* p);
virtual ~PropertiesWindowBase();
virtual String GetObjectWidgetClass() const { return String(); }
virtual int Execute();

private:
T* _Properties;
Array<StaticRect> _Panes;
};

template <class T>
PropertiesWindowBase<T>::PropertiesWindowBase(T* p)
{
CtrlLayoutOKCancel(*this, t_("Properties"));
ToolWindow().Sizeable();
_Properties = p;
_Properties->InitProperties();
Load();
}

template <class T>
PropertiesWindowBase<T>::~PropertiesWindowBase()
{
_Properties->ClearProperties();
}

template <class T>
int PropertiesWindowBase<T>::Execute()
{
if (!_Properties->GetProperties().GetCount())
{
PromptOK(t_("No properties for object!"));
return IDCANCEL;
}
int r = WithPropertiesLayout<TopWindow>::Execute();
r == IDOK ? Save() : Cancel();
return r;
}

template <class T>
void PropertiesWindowBase<T>::Load()
{
Vector<String> groups = _Properties->GetPropertiesGroups();
propGroups.Clear();
_Panes.Clear();

for (int i = 0; i < groups.GetCount(); ++i)
{
if (groups[i].IsEmpty())
groups[i] = t_("Others");
Array<Property*> gProps = _Properties->GetPropertiesByGroup(groups[i]);
StaticRect& pane = _Panes.Add();
int paneCY = 10;
for (int j = 0; j < gProps.GetCount(); ++j)
{
gProps[j]->ToPane(pane, paneCY, 5);
}
paneCY += 15;
propGroups.AddExpander(pane, true, paneCY).SetTitle(groups[i]);
}
}

template <class T>
void PropertiesWindowBase<T>::Save()
{
Array<Property>& props = _Properties->GetProperties();
for (int i = 0; i < props.GetCount(); ++i)
if (props[i].IsChanged())
props[i].Apply();
Break();
}

template <class T>
void PropertiesWindowBase<T>::Cancel()
{
Array<Property>& props = _Properties->GetProperties();
for (int i = 0; i < props.GetCount(); ++i)
if (props[i].IsChanged())
props[i].Restore();
Break();
}

template <class T>
class PropertiesWindowHistory
{
class HChangeProperty : public IHistoryItem
{
String _Name;
Value _Last;
Value _Next;
int _Prop;
T* _Ptr;

public:
HChangeProperty(T* obj, String name, int prop, Value last, Value v)
: _Ptr(obj), _Name(name), _Prop(prop), _Last(last), _Next(v) {}
virtual ~HChangeProperty() {}

virtual String GetDesc() const;
virtual void Undo();
virtual void Do();
};

public:
PropertiesWindowHistory(T* p) : _Properties(p) {}

private:
T* _Properties;

protected:
virtual void Save();
};

template <class T>
void PropertiesWindowHistory<T>::Save()
{
Array<Property>& props = _Properties->GetProperties();
for (int i = 0; i < props.GetCount(); ++i)
if (props[i].IsChanged())
{
T* c = _Properties->GetObject();
if (!c) continue;
Value v;
props[i].Get(v, Vector<Value>());
c->AddToHistory(new HChangeProperty(c, props[i].MetaString("Name"),
i, props[i].GetLast(), v));
}
}

// History: Property changes
template <class T>
void PropertiesWindowHistory<T>::HChangeProperty::Do()
{
if (!_Ptr) return;
_Ptr->InitProperties();
Property& prop = _Ptr->GetProperties()[_Prop];
prop.Set(Vector<Value>() << _Next);
_Ptr->ClearProperties();
}

template <class T>
void PropertiesWindowHistory<T>::HChangeProperty::Undo()
{
if (!_Ptr) return;
_Ptr->InitProperties();
Property& prop = _Ptr->GetProperties()[_Prop];
prop.Set(Vector<Value>() << _Last);
_Ptr->ClearProperties();
}

template <class T>
String PropertiesWindowHistory<T>::HChangeProperty::GetDesc() const
{
if (!_Ptr) return String(t_("Unable to change the property: NULL-pointer."));
return NFormat(t_("Property of the object (type \"%s\"), named \"%s\", changed to: \"%s\""),
_Ptr->GetObjectWidgetClass(), _Name, _Next.ToString());
}

template <class T>
class PropertiesWindow : public PropertiesWindowBase<T>, public PropertiesWindowHistory<T>
{
public:
PropertiesWindow(T* p) : PropertiesWindowBase<T>(p), PropertiesWindowHistory<T>(p)
{ _useHistory = false; }
virtual ~PropertiesWindow() {}

virtual void Save()
{
PropertiesWindowBase<T>::Save();

if (_useHistory)
PropertiesWindowHistory<T>::Save();
}

bool UseHistory(bool flag = true) { _useHistory = flag; }

private:
bool _useHistory;
};

#endif

Change log

r4180 by Sc0rch on Nov 17, 2011   Diff
MapRender: First release
(FormEditorCommon, FormEditorProperties,
Map, MapBG, MapCommon, MapEditor,
MapRenderTest.
Go to: 
Project members, sign in to write a code review

Older revisions

All revisions of this file

File info

Size: 4894 bytes, 204 lines
Powered by Google Project Hosting