1 namespace gui::controls;
5 default extern int __ecereVMethodID_class_OnGetDataFromString;
6 default static void _workAround()
9 a.OnGetDataFromString(0);
12 public class FilePath : String
14 Window OnEdit(DataBox dataBox, DataBox obsolete, int x, int y, int w, int h, void * userData)
18 dataBox, borderStyle = 0, anchor = { 0, 0, 0, 0 },
20 browseDialog = userData ? (FileDialog)userData : { type = open, text = "Select a file..." };
27 bool OnSaveEdit(PathBox pathBox, void * object)
30 if(pathBox.modifiedDocument)
33 changed = _class._vTbl[__ecereVMethodID_class_OnGetDataFromString](_class, &this, pathBox.systemPath);
38 int OnCompare(DirPath b)
40 return fstrcmp(this, b);
44 public class DirPath : FilePath
46 Window OnEdit(DataBox dataBox, DataBox obsolete, int x, int y, int w, int h, void * userData)
50 dataBox, borderStyle = 0, anchor = { 0, 0, 0, 0 },
51 typeExpected = directory;
52 browseDialog = userData ? (FileDialog)userData : { type = selectDir, text = "Select a folder..." };
60 public enum PathTypeExpected { none, any, directory, file };
62 public class PathBox : CommonControl
65 clientSize = { 64, 18 };
67 #if defined(__WIN32__)
74 PathTypeExpected typeExpected;
75 FileDialog browseDialog;
76 #if defined(__WIN32__)
77 char path[MAX_LOCATION];
80 BitmapResource file { "<:ecere>mimeTypes/file.png", transparent = true, alphaBlend = true };
81 BitmapResource brokenFile { "<:ecere>mimeTypes/brokenFile.png", transparent = true, alphaBlend = true };
82 BitmapResource folder { "<:ecere>places/folder.png", transparent = true, alphaBlend = true };
83 BitmapResource brokenFolder { "<:ecere>places/brokenFolder.png", transparent = true, alphaBlend = true };
87 this/*, size = { 318, 94 }*/, anchor = { left = 1, vert = 0 };
94 public property EditBox editBox { get { return editBox; } }
97 this/*, size = { 290, 22 }*/, position = { 1, 1 }, anchor = { left = 1, top = 1, right = 1 };
100 void NotifyUpdate(EditBox editBox)
103 modifiedDocument = true;
105 bool NotifyModified(EditBox editBox)
107 return NotifyModified(master, this);
110 bool OnKeyDown(Key key, unichar ch)
113 ((PathBox)parent).browse.NotifyClicked(parent, ((PathBox)parent).browse, 0, 0, (Modifiers)null);
114 return EditBox::OnKeyDown(key, ch);
118 // For chaining popup-key event
119 bool OnKeyHit(Key key, unichar ch)
121 return editBox.OnKeyHit(key, ch);
126 this, size = { w = 26 }, anchor = { top = 0, right = 0, bottom = 0 };
132 bool NotifyClicked(Button button, int x, int y, Modifiers mods)
136 /* We need a reinterpret cast :) Easy eC compiler introduction contribution! :)
137 DataBox dataBox = reinterpret(master);
138 ListBox lb = dataBox ? reinterpret(dataBox.parent) : null;
139 DirectoriesBox dirBox = lb ? reinterpret(lb.parent) : null;
141 DataBox dataBox = eClass_IsDerived(master._class, class(DataBox)) ? (DataBox)master : null;
142 ListBox lb = ((dataBox && eClass_IsDerived(dataBox.parent._class, class(ListBox))) ? (ListBox)dataBox.parent : null;
143 DirectoriesBox dirBox = ((lb && eClass_IsDerived(lb.parent._class, class(DirectoriesBox))) ? (DirectoriesBox)lb.parent : null;
144 char * browsePath = CopyString(editBox.contents);
145 char fileName[MAX_LOCATION];
149 GetLastDirectory(browsePath, fileName);
150 StripLastDirectory(browsePath, browsePath);
154 char filePath[MAX_LOCATION];
156 LocateModule(null, filePath);
157 StripLastDirectory(filePath, filePath);
158 browsePath = CopyString(filePath);
161 while(browsePath[0] && !FileExists(browsePath).isDirectory)
163 char temp[MAX_LOCATION];
164 GetLastDirectory(browsePath, temp);
165 PathCat(temp, fileName);
166 strcpy(fileName, temp);
167 StripLastDirectory(browsePath, browsePath);
169 browseDialog.filePath = fileName;
170 browseDialog.currentDirectory = browsePath;
172 browseDialog.master = rootWindow;
174 // THIS PART WAS MISSING IN THE PathBox/DirectoriesBox INTEGRATION AND WAS CRUCIAL
175 if(dirBox) dirBox.browsing = true;
176 if(browseDialog.Modal())
178 PathBox pathBox = dataBox ? (PathBox)dataBox.editor : this;
179 pathBox.modifiedDocument = true;
180 pathBox.property::path = browseDialog.filePath;
184 pathBox.editBox.SelectAll();
185 if(lb) lb.StopEditing(true);
186 pathBox.NotifyModified(pathBox.master, this);
188 if(dirBox) dirBox.browsing = false;
196 void CheckFileExists()
198 if(typeExpected != none)
200 BitmapResource icon = null;
201 FileAttribs exists = FileExists(editBox.contents);
206 // TODO: improvements, add drive, etc, also find a better solution/icon for expect any and file doesn't exist
207 icon = exists ? exists.isFile ? file : exists.isDirectory ? folder : null : null;
210 icon = exists && exists.isDirectory ? folder : brokenFolder;
213 icon = exists && exists.isFile ? file : brokenFile;
217 picture.image = icon;
221 void OnRedraw(Surface surface)
225 surface.SetBackground(activeBorder);
226 surface.Area(0, 0, clientSize.w, clientSize.h);
229 Window::OnRedraw(surface);
238 property PathTypeExpected typeExpected
242 if(value != typeExpected)
244 if(value == none || typeExpected == none)
246 bool withIcon = value != none;
247 picture.visible = withIcon;
248 editBox.anchor.left = withIcon ? 18 : 1;
251 typeExpected = value;
252 if(browseDialog && browseDialog.type == open && typeExpected == directory)
253 browseDialog.type = selectDir;
258 property FileDialog browseDialog
263 browseDialog = value;
267 if(browseDialog.type == open && typeExpected == directory)
268 browseDialog.type = selectDir;
269 if(!strcmp(browseDialog.text, "Select a file...") && text)
271 char temp[1024] = "Select ";
274 browseDialog.text = temp;
277 browse.visible = browseDialog ? true : false;
278 editBox.anchor.right = browseDialog ? 26 : 1;
282 void Home() { editBox.Home(); }
283 void End() { editBox.End(); }
285 void SelectAll() { editBox.SelectAll(); }
286 void Deselect() { editBox.Deselect(); }
292 char path[MAX_LOCATION];
293 GetSystemPathBuffer(path, value);
294 editBox.contents = path;
299 get { return editBox.contents; }
301 property String slashPath { get { return GetSlashPathBuffer (path, editBox.contents); } };
302 property String systemPath { get { return GetSystemPathBuffer(path, editBox.contents); } };
304 virtual bool Window::NotifyModified(PathBox pathBox);
308 FileDialog browseFileDialog { type = selectDir, text = "Select directory" };
310 public class DirectoriesBox : CommonControl
318 virtual bool OnChangedDir(char ** directory)
322 virtual bool OnPrepareBrowseDir(char ** directory)
326 virtual bool OnBrowsedDir(char ** directory)
331 watch(foreground) { list.foreground = foreground; };
332 watch(background) { list.background = background; };
334 property Array<String> strings
343 char temp[MAX_LOCATION];
344 list.AddString(GetSystemPathBuffer(temp, s));
348 list.currentRow = list.firstRow;
349 list.modifiedDocument = false;
353 Array<String> array { };
355 for(row = list.firstRow; row; row = row.next)
357 String string = row.string;
358 if(string && string[0])
359 array.Add(CopyUnixPath(string));
365 virtual bool Window::NotifyModified(DirectoriesBox dirsBox);
367 bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool direct)
369 // Browsing was not being set, fixed by introducing dependency to this class to PathBox
370 if(!active && !browsing)
372 list.StopEditing(true);
373 if(list.modifiedDocument)
375 NotifyModified(master, this);
376 list.modifiedDocument = false;
377 modifiedDocument = true;
385 parent = this, bevelOver = true, inactive = true;
386 position = { 265, 0 }, size = { 22, 22 };
387 anchor = { top = 0, right = 77 };
388 hotKey = plus, bitmap = BitmapResource { fileName = "<:ecere>actions/listAdd.png", alphaBlend = true };
389 bool NotifyClicked(Button button, int x, int y, Modifiers mods)
391 list.StopEditing(true);
392 list.lastRow.Edit(null);
393 list.modifiedDocument = true;
399 parent = this, bevelOver = true, inactive = true;
400 position = { 290, 0 }, size = { 22, 22 };
401 anchor = { top = 0, right = 54 };
402 hotKey = del, bitmap = BitmapResource { fileName = "<:ecere>actions/listRemove.png", alphaBlend = true };
403 bool NotifyClicked(Button button, int x, int y, Modifiers mods)
405 list.StopEditing(true);
406 if(list.currentRow != list.lastRow)
408 list.DeleteRow(null);
409 list.modifiedDocument = true;
416 parent = this, bevelOver = true, inactive = true;
417 position = { 315, 0 }, size = { 22, 22 };
418 anchor = { top = 0, right = 31 };
419 hotKey = ctrlUp, bitmap = BitmapResource { fileName = "<:ecere>actions/goUp.png", alphaBlend = true };
420 bool NotifyClicked(Button button, int x, int y, Modifiers mods)
422 if(list.currentRow != list.lastRow)
424 DataRow current = list.currentRow, row;
427 row = current.previous;
432 list.modifiedDocument = true;
441 parent = this, bevelOver = true, inactive = true;
442 position = { 340, 0 }, size = { 22, 22 };
443 anchor = { top = 0, right = 8 };
444 hotKey = ctrlDown, bitmap = BitmapResource { fileName = "<:ecere>actions/goDown.png", alphaBlend = true };
445 bool NotifyClicked(Button button, int x, int y, Modifiers mods)
447 DataRow current = list.currentRow, row;
451 if(row && row != list.lastRow)
454 list.modifiedDocument = true;
462 this, moveRows = true, hasVertScroll = true, dontHideScroll = true;
463 borderStyle = deep, position = { 0, 22 }, size = { 300, 60 };
464 anchor = { left = 0, top = 22, right = 0, bottom = 0 };
466 bool OnRightButtonDown(int x, int y, Modifiers mods)
468 return parent.OnRightButtonDown(x + position.x + parent.clientStart.x, y + position.y + parent.clientStart.y, mods);
471 bool NotifyChanged(ListBox listBox, DataRow row)
473 char * directory = listBox.GetData(null);
474 if(directory && directory[0])
476 char * dir = CopyString(directory);
477 if(OnChangedDir(&dir))
479 listBox.SetData(null, dir);
480 listBox.modifiedDocument = true;
481 if(listBox.currentRow == listBox.lastRow && listBox.lastRow.string)
483 DataRow r = listBox.lastRow;
485 listBox.currentRow = listBox.AddString("");
490 else if(listBox.currentRow != listBox.lastRow)
492 listBox.DeleteRow(null);
493 listBox.modifiedDocument = true;
498 bool NotifyEditDone(ListBox listBox, DataRow row)
503 bool NotifyKeyDown(ListBox listBox, DataRow row, Key key, unichar ch)
507 listBox.StopEditing(true);
508 if(listBox.currentRow != listBox.lastRow)
509 listBox.DeleteRow(null);
515 bool NotifyMove(ListBox listBox, DataRow row, Modifiers mods)
517 if(listBox.currentRow == listBox.lastRow)
519 else if(row == listBox.lastRow)
521 if(listBox.currentRow == row.previous)
523 listBox.currentRow.Move(row.previous);
529 bool NotifyReclick(ListBox listBox, DataRow row, Modifiers mods)
535 DataField dirField { dataType = class(DirPath), editable = true, userData = browseFileDialog };
539 list.AddField(dirField);
541 list.modifiedDocument = false;