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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
void DropEdge_Write(Value);

class PopUpTable : public ArrayCtrl {
public:
virtual void LeftUp(Point p, dword keyflags);
virtual bool Key(dword key, int);

protected:
void PopupDeactivate();
void PopupCancelMode();

struct Popup : Ctrl {
PopUpTable *table;

virtual void Deactivate() { table->PopupDeactivate(); }
virtual void CancelMode() { table->PopupCancelMode(); }
};

int droplines;
int inpopup;
bool open;
One<Popup> popup;

void DoClose();

public:
void PopUp(Ctrl *owner, int x, int top, int bottom, int width);
void PopUp(Ctrl *owner, int width);
void PopUp(Ctrl *owner);

Callback WhenCancel;
Callback WhenSelect;

PopUpTable& SetDropLines(int _droplines) { droplines = _droplines; return *this; }

void Normal();

PopUpTable();
virtual ~PopUpTable();
};

class DropList : public MultiButton, public Convert {
public:
virtual void MouseWheel(Point p, int zdelta, dword keyflags);
virtual bool Key(dword key, int);
virtual void SetData(const Value& data);
virtual Value GetData() const;

virtual Value Format(const Value& q) const;

private:
PopUpTable list;
Index<Value> key;
Value value;
int dropwidth;
const Convert *valueconvert;
const Display *valuedisplay;
bool displayall;
bool dropfocus;
bool notnull;
bool alwaysdrop;

void Select();
void Cancel();
void Change(int q);
void EnableDrop(bool b = true) { MainButton().Enable(b || alwaysdrop); }
void Sync();

typedef DropList CLASSNAME;

public:
typedef MultiButton::Style Style;

Callback WhenDrop;

DropList& Add(const Value& key, const Value& value);
DropList& Add(const Value& value) { return Add(value, value); }
void Remove(int i);
void ClearList();
void Clear();

DropList& AddSeparator();

void Drop();

const Value& operator=(const Value& v) { SetData(v); return v; }
operator Value() const { return GetData(); }

void SetIndex(int i) { SetData(GetKey(i)); }
int GetIndex() const { return FindKey(value); }
void GoBegin() { if(GetCount()) SetIndex(0); }
void GoEnd() { if(GetCount()) SetIndex(GetCount() - 1); }

bool HasKey(const Value& k) const { return FindKey(k) >= 0; }
int FindKey(const Value& k) const;
int Find(const Value& k) const { return FindKey(k); }
int FindValue(const Value& v) const { return list.Find(v); }

int GetCount() const { return key.GetCount(); }
void Trim(int n);
const Value& GetKey(int i) const { return key[i]; }

Value GetValue(int i) const { return list.Get(i, 0); }
Value GetValue() const;
void SetValue(int i, const Value& v);
void SetValue(const Value& v);
Value operator[](int i) const { return GetValue(i); }

void Adjust();
void Adjust(const Value& k);

const PopUpTable& GetList() const { return list; }
PopUpTable& ListObject() { return list; }

DropList& SetDropLines(int d) { list.SetDropLines(d); return *this; }
DropList& SetConvert(const Convert& cv);
DropList& SetDisplay(int i, const Display& d);
DropList& SetDisplay(const Display& d);
DropList& SetLineCy(int lcy) { list.SetLineCy(lcy); return *this; }
DropList& SetDisplay(const Display& d, int lcy);
DropList& ValueDisplay(const Display& d);
DropList& DisplayAll(bool b = true) { displayall = b; return *this; }
DropList& DropFocus(bool b = true) { dropfocus = b; return *this; }
DropList& NoDropFocus() { return DropFocus(false); }
DropList& AlwaysDrop(bool e = true);
DropList& SetStyle(const Style& s) { MultiButton::SetStyle(s); return *this; }
DropList& NotNull(bool b = true) { notnull = b; return *this; }
DropList& DropWidth(int w) { dropwidth = w; return *this; }
DropList& DropWidthZ(int w) { dropwidth = HorzLayoutZoom(w); return *this; }

DropList& SetScrollBarStyle(const ScrollBar::Style& s) { list.SetScrollBarStyle(s); return *this; }

DropList();
virtual ~DropList();
};

void Add(DropList& list, const VectorMap<Value, Value>& values);
void Add(MapConvert& convert, const VectorMap<Value, Value>& values);
void Add(DropList& list, const MapConvert& convert);

class DropChoice : public MultiButtonFrame {
public:
virtual void Serialize(Stream& s); //empty

protected:
PopUpTable list;
Ctrl *owner;
bool appending;
bool dropfocus;
bool always_drop;

void Select();
void Drop();
void EnableDrop(bool b);
void PseudoPush();
int dropwidth;

typedef DropChoice CLASSNAME;

public:
Callback WhenDrop;
Callback WhenSelect;

bool DoKey(dword key);

void Clear();
void Add(const Value& data);
void SerializeList(Stream& s);

int GetCount() const { return list.GetCount(); }
Value Get(int i) const { return list.Get(i, 0); }

void AddHistory(const Value& data, int max = 12);

void AddTo(Ctrl& _owner) { MultiButtonFrame::AddTo(_owner); owner = &_owner; }
bool IsActive() const { return IsOpen(); }

Value Get() const;
int GetIndex() const;

DropChoice& SetDisplay(int i, const Display& d) { list.SetDisplay(i, 0, d); return *this; }
DropChoice& SetDisplay(const Display& d) { list.ColumnAt(0).SetDisplay(d); return *this; }
DropChoice& SetLineCy(int lcy) { list.SetLineCy(lcy); return *this; }
DropChoice& SetDisplay(const Display& d, int lcy) { SetDisplay(d); SetLineCy(lcy); return *this; }
DropChoice& SetConvert(const Convert& d) { list.ColumnAt(0).SetConvert(d); return *this; }
DropChoice& SetDropLines(int n) { list.SetDropLines(n); return *this; }
DropChoice& Appending() { appending = true; return *this; }
DropChoice& AlwaysDrop(bool e = true);
DropChoice& NoDropFocus() { dropfocus = false; return *this; }

DropChoice& DropWidth(int w) { dropwidth = w; return *this; }
DropChoice& DropWidthZ(int w) { dropwidth = HorzLayoutZoom(w); return *this; }


DropChoice& SetScrollBarStyle(const ScrollBar::Style& s) { list.SetScrollBarStyle(s); return *this; }

DropChoice();

static bool DataSelect(Ctrl& owner, DropChoice& drop, const String& appends);
};

template <class T>
class WithDropChoice : public T {
public:
virtual bool Key(dword key, int repcnt);
virtual void MouseEnter(Point p, dword keyflags);
virtual void MouseLeave();
virtual void GotFocus();
virtual void LostFocus();


protected:
DropChoice select;
String appends;

void DoWhenSelect();
void DoWhenDrop() { WhenDrop(); }

public:
Callback WhenDrop;
Callback WhenSelect;

void ClearList() { select.Clear(); }
void AddList(const Value& data) { select.Add(data); }
void SerializeList(Stream& s) { select.SerializeList(s); }

int GetCount() const { return select.GetCount(); }
Value Get(int i) const { return select.Get(i); }

void AddHistory(int max = 12) { select.AddHistory(this->GetData(), max); }

MultiButton::SubButton& AddButton() { return select.AddButton(); }
int GetButtonCount() const { return select.GetButtonCount(); }
MultiButton::SubButton& GetButton(int i) { return select.GetButton(i); }
Rect GetPushScreenRect() const { return select.GetPushScreenRect(); }

const MultiButton::Style& StyleDefault() { return select.StyleFrame(); }
WithDropChoice& SetStyle(const MultiButton::Style& s) { select.SetStyle(s); return *this; }

WithDropChoice& Dropping(bool b = true) { select.Show(b); return *this; }
WithDropChoice& NoDropping() { return Dropping(false); }
WithDropChoice& NoDropFocus() { select.NoDropFocus(); return *this; }
WithDropChoice& Appending(const String& s = ", ") { appends = s; select.Appending(); return *this; }
WithDropChoice& SetDropLines(int n) { select.SetDropLines(n); return *this; }
WithDropChoice& SetDisplay(int i, const Display& d) { select.SetDisplay(i, d); return *this; }
WithDropChoice& SetDisplay(const Display& d) { select.SetDisplay(d); return *this; }
WithDropChoice& SetLineCy(int lcy) { select.SetLineCy(lcy); return *this; }
WithDropChoice& SetDisplay(const Display& d, int lcy) { select.SetDisplay(d, lcy); return *this; }
WithDropChoice& SetConvert(const Convert& d) { select.SetConvert(d); return *this; }
WithDropChoice& AlwaysDrop(bool b = true) { select.AlwaysDrop(b); return *this; }

WithDropChoice& DropWidth(int w) { select.DropWidth(w); return *this; }
WithDropChoice& DropWidthZ(int w) { select.DropWidthZ(w); return *this; }

WithDropChoice();
};

template <class T>
WithDropChoice<T>::WithDropChoice() {
select.AddTo(*this);
select.WhenDrop = callback(this, &WithDropChoice::DoWhenDrop);
select.WhenSelect = callback(this, &WithDropChoice::DoWhenSelect);
appends = String::GetVoid();
SetStyle(StyleDefault());
}

template <class T>
bool WithDropChoice<T>::Key(dword key, int repcnt) {
return select.DoKey(key) || T::Key(key, repcnt);
}

template <class T>
void WithDropChoice<T>::MouseEnter(Point p, dword keyflags)
{
select.Refresh();
T::MouseEnter(p, keyflags);
}

template <class T>
void WithDropChoice<T>::MouseLeave()
{
select.Refresh();
T::MouseLeave();
}

template <class T>
void WithDropChoice<T>::GotFocus()
{
select.Refresh();
T::GotFocus();
}

template <class T>
void WithDropChoice<T>::LostFocus()
{
select.Refresh();
T::LostFocus();
}

template <class T>
void WithDropChoice<T>::DoWhenSelect() {
if(DropChoice::DataSelect(*this, select, appends)) {
this->SetFocus();
WhenSelect();
}
}

Change log

r4307 by cxl on Dec 16, 2011   Diff
*CtrlLib: Fixed ColorPopUp issue in X11
Go to: 
Project members, sign in to write a code review

Older revisions

r3221 by cxl on Feb 18, 2011   Diff
CtrlLib: PopUpTable refactored to
improve animation
r2086 by cxl on Feb 16, 2010   Diff
CtrlLib: WithDropChoice serialization
fix
r1565 by cxl on Sep 7, 2009   Diff
CtrlLib: DropChoice SetConvert
All revisions of this file

File info

Size: 10858 bytes, 306 lines

File properties

svn:eol-style
native
Powered by Google Project Hosting