1 namespace gui::controls;
6 extern int __ecereVMethodID_class_OnGetString;
7 extern int __ecereVMethodID_class_OnGetDataFromString;
8 extern int __ecereVMethodID_class_OnCompare;
9 extern int __ecereVMethodID_class_OnSerialize;
10 extern int __ecereVMethodID_class_OnUnserialize;
11 extern int __ecereVMethodID_class_OnFree;
12 extern int __ecereVMethodID_class_OnEdit;
13 extern int __ecereVMethodID_class_OnCopy;
14 extern int __ecereVMethodID_class_OnDisplay;
15 extern int __ecereVMethodID_class_OnSaveEdit;
18 public class DataBox : CommonControl
37 virtual void SetData(any_object newData, bool closingDropDown)
39 //type._vTbl[__ecereVMethodID_class_OnCopy](type, data, newData);
43 if(type.type == normalClass || type.type == noHeadClass)
45 if(((void **)data)[0])
46 type._vTbl[__ecereVMethodID_class_OnFree](type, ((void **)data)[0]);
47 ((void **)data)[0] = newData;
51 // Free old data first
52 type._vTbl[__ecereVMethodID_class_OnFree](type, data);
53 type._vTbl[__ecereVMethodID_class_OnCopy](type, data, newData);
57 NotifyChanged(master, closingDropDown);
61 bool SaveData() // TODO: Clear this up, along with Saving DataBox
63 if(editor && type._vTbl[__ecereVMethodID_class_OnSaveEdit](type, data, editor, null))
66 NotifyChanged(master, false);
75 NotifyModified(master);
92 virtual bool Window::NotifyModified();
93 virtual bool Window::NotifyChanged(bool closingDropDown);
94 virtual void OnConfigure(Window editor);
101 if(type && (!readOnly || (autoSize && type._vTbl[__ecereVMethodID_class_OnEdit] == class(Instance)._vTbl[__ecereVMethodID_class_OnEdit])) &&
102 (type.type == normalClass || type.type == noHeadClass || data))
104 // IMPORTANT FIX: If keepEditor is true, we were passing editor rather than the editor's current master
105 editor = (Window)type._vTbl[__ecereVMethodID_class_OnEdit](type,
106 (type.type == normalClass || type.type == noHeadClass) ? (data ? (*(void **)data) : null) : data,
107 this, (keepEditor && editor) ? editor.master : this, 0, 0, clientSize.w, clientSize.h, fieldData);// null);
110 // editor.anchor = { 0, 0, 0, 0 };
111 editor.background = background;
112 editor.foreground = foreground;
113 editor.opacity = opacity;
116 PrintLn("DataBox::OnPostCreate -- autoSize == true");
118 if(eClass_IsDerived(editor._class, class(EditBox)))
120 ((EditBox)editor).readOnly = readOnly;
121 ((EditBox)editor).autoSize = autoSize;
126 // TODO: Should returning 0 from OnPostCreate cancel creation?
134 void OnRedraw(Surface surface)
138 char tempString[1024];
139 if(type._vTbl[__ecereVMethodID_class_OnDisplay] == class(Instance)._vTbl[__ecereVMethodID_class_OnDisplay])
144 if(type.type == noHeadClass || type.type == normalClass)
145 s = (String)type._vTbl[__ecereVMethodID_class_OnGetString](type, *(void **)this.data, tempString, fieldData, null);
147 s = (String)type._vTbl[__ecereVMethodID_class_OnGetString](type, this.data, tempString, fieldData, null);
149 stringValue = CopyString(s);
152 class(String)._vTbl[__ecereVMethodID_class_OnDisplay](class(String), stringValue, surface, 3, 1, clientSize.w, fieldData, type.defaultAlignment, 0);
156 if(type.type == noHeadClass || type.type == normalClass)
157 type._vTbl[__ecereVMethodID_class_OnDisplay](type, *(void **)this.data, surface, 3, 1, clientSize.w, fieldData, type.defaultAlignment, 0);
159 type._vTbl[__ecereVMethodID_class_OnDisplay](type, this.data, surface, 3, 1, clientSize.w, fieldData, type.defaultAlignment, 0);
167 CommonControl::OnDestroy();
170 void OnPosition(int x, int y, int width, int height)
173 editor.OnPosition(editor.position.x, editor.position.y, editor.size.w, editor.size.h);
176 bool OnKeyHit(Key key, unichar ch)
178 return editor ? editor.OnKeyHit(key, ch) : true;
181 bool OnKeyDown(Key key, unichar ch)
183 if((SmartKey)key == enter)
188 else if((SmartKey)key == escape)
193 return editor ? editor.OnKeyDown(key, ch) : true;
196 void OnChildResized(Window child, int x, int y, int w, int h)
198 if(!inAutoSize && autoSize == true)
201 clientSize = { w, h };
207 public class SavingDataBox : DataBox
209 class_property(icon) = "<:ecere>controls/dataBox.png";
211 bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool direct)
213 if(!active && editor && !editor.modalSlave)
221 bool OnKeyDown(Key key, unichar ch)
223 if((SmartKey)key == enter)
226 // Force Refresh on Enter if SaveData didn't do it
230 return DataBox::OnKeyDown(key, ch);