1 #ifdef BUILDING_ECERE_COM
2 namespace gui::controls;
7 public import static "ecere"
14 static void DrawStipple(Surface surface, Size clientSize)
18 int x2 = clientSize.w - 1;
19 int y2 = clientSize.h - 1;
20 if((x2 - x1) & 1) x2--;
21 if((y2 - y1) & 1) y2--;
23 surface.LineStipple(0x5555);
24 surface.Rectangle(x1, y1, x2, y2);
25 surface.LineStipple(0);
28 public class SelectorBar : Stacker
30 direction = horizontal;
31 background = formColor;
33 //isActiveClient = true;
35 clientSize = { h = 40 };
40 this, anchor = { left = 8, top = 12 }, labeledWindow = this;
42 void OnRedraw(Surface surface)
44 Label::OnRedraw(surface);
45 if(labeledWindow.active)
46 DrawStipple(surface, clientSize);
55 void Select(SelectorButton button)
57 button.checked = true;
60 button.NotifyClicked(button.master, button, 0, 0, 0);
61 MakeControlVisible(button);
64 void AddButton(SelectorButton button)
70 void RemoveButton(SelectorButton button)
72 Iterator<Window> it { controls };
75 if(button == (SelectorButton)it.data)
77 IteratorPointer toRemove = it.pointer;
78 if(it.Next() || (it.Prev() && it.Prev()))
80 SelectorButton newSelection = (SelectorButton)it.data;
81 newSelection.checked = true;
82 newSelection.NotifyClicked(newSelection.master, newSelection, 0, 0, 0);
90 SelectorButton FindButtonByID(int64 id)
92 SelectorButton button = null;
93 Iterator<Window> it { controls };
97 if(eClass_IsDerived(b._class, class(SelectorButton)) && b.id == id)
99 button = (SelectorButton)b;
108 OnResize(clientSize.w, clientSize.h);
112 property SelectorButton selectedButton
116 SelectorButton button = null;
117 Iterator<Window> it { controls };
121 if(eClass_IsDerived(w._class, class(SelectorButton)))
123 SelectorButton b = (SelectorButton)w;
126 button = (SelectorButton)b;
141 public class SelectorButton : Button
143 bevelOver = true, isRadio = true, bitmap = null, minClientSize = { 44, 22 }; isRemote = true;
150 if(parent && eClass_IsDerived(parent._class, class(SelectorBar)))
152 SelectorBar parent = (SelectorBar)this.parent;
155 parent.childrenCycle.Move(cycle, null);
157 /* Currently, it could be done this way outside libecere:
158 if(parent.controls.count)
160 parent.controls.lastIterator.data.Activate();
165 parent.AddButton(this);
173 else if(parent && eClass_IsDerived(parent._class, class(SelectorBar)))
176 SelectorBar selector = (SelectorBar)parent;
177 for(b = (SelectorButton)parent.firstChild; b; b = (SelectorButton)b.next)
179 if(b.nonClient) continue;
180 if(eClass_IsDerived(b._class, class(SelectorButton)) && b != this)
183 font = { font.faceName, font.size, bold = true };
184 // this should not be required: the font change should resize the control and Stacker should adapt automatically
186 selector.OnResize(selector.clientSize.w, selector.clientSize.h);
187 selector.MakeControlVisible(this);
191 bool OnLeftButtonDown(int x, int y, Modifiers mods)
195 result = Button::OnLeftButtonDown(x, y, mods);
196 if(focusHolder && !checked)
197 focusHolder.Activate();
202 public class EditableSelectorButton : SelectorButton
207 bool OnKeyDown(Key key, unichar ch)
209 if(key == f2 && !editBox)
214 NotifyClicked(master, this, 0, 0, 0);
216 OnLeftButtonDown(0, 0, 0);
219 return SelectorButton::OnKeyDown(key, ch);
222 bool OnLeftButtonDown(int x, int y, Modifiers mods)
225 if(renameable && checked && !editBox)
229 this, anchor = { 2, 2, 2, 2 }, /*opacity = 0, */borderStyle = 0, textHorzScroll = true;
231 bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool direct)
233 EditBox::OnActivate(active, previous, goOnWithActivation, direct);
234 if(!active && !destroyed)
236 ((EditableSelectorButton)master).editBox = null;
239 if(master && ((EditableSelectorButton)master).focusHolder)
240 ((EditableSelectorButton)master).focusHolder.Activate();
246 bool NotifyModified(EditBox editBox)
248 char * oldName = CopyString(text);
249 char * newName = CopyString(editBox.contents);
251 if(OnRename(master, this, &oldName, &newName))
253 SelectorBar selector = (SelectorBar)parent;
256 selector.MakeControlVisible(this);
262 //OnLeavingEdit();? //master.someControl.Activate();
264 focusHolder.Activate();
269 bool OnKeyDown(Key key, unichar ch)
271 if((SmartKey)key == enter || key == escape)
275 EditableSelectorButton button = (EditableSelectorButton)master;
277 button.editBox.SetModified(false);
283 return EditBox::OnKeyDown(key, ch);
287 editBox.contents = text;
289 editBox.SetModified(false);
292 return Button::OnLeftButtonDown(x, y, mods);
296 property bool renameable
298 set { renameable = value; }
299 get { return renameable; }
301 property EditBox editBox { get { return editBox; } }
303 virtual bool Window::OnRename(EditableSelectorButton button, char ** oldName, char ** newName);