1 namespace gui::dialogs;
5 static class MsgLine : struct
12 public enum MessageBoxType { ok, yesNo, okCancel, yesNoCancel };
13 public class MessageBox : Window
15 background = formColor;
18 nativeDecorations = true;
21 property MessageBoxType type { set { style = value; } };
22 property char * contents
29 int len = strlen(value);
32 for(c = 0; c <= len; c++)
34 if(c == len || value[c] == '\n')
41 line.string = new char[line.len+1];
42 CopyBytes(line.string, value + start, line.len);
43 line.string[line.len] = '\0';
55 int totalWidth, totalHeight, lineHeight;
62 bool ButtonActivate(Window control, bool active, Window previous)
64 control.isDefault = true;
75 this, text = $"No", anchor = { horz = 40, bottom = 7 }, size = { 64 }, id = DialogResult::no, hotKey = n;
76 NotifyClicked = ButtonCloseDialog, NotifyActivate = ButtonActivate;
81 this, isDefault = true, text = $"Yes", anchor = { horz = -40, bottom = 7 }, size = { 64 }, id = DialogResult::yes, hotKey = y;
82 NotifyClicked = ButtonCloseDialog, NotifyActivate = ButtonActivate;
88 this, text = $"Cancel", anchor = { horz = 40, bottom = 7 }, size = { 64 }, id = DialogResult::cancel, hotKey = escape;
89 NotifyClicked = ButtonCloseDialog, NotifyActivate = ButtonActivate;
94 this, isDefault = true, text = $"OK", anchor = { horz = -40, bottom = 7 }, size = { 64 }, id = DialogResult::ok, hotKey = o;
95 NotifyClicked = ButtonCloseDialog, NotifyActivate = ButtonActivate;
101 this, text = $"No", anchor = { bottom = 7 }, size = { 64 }, id = DialogResult::no, hotKey = n;
102 NotifyClicked = ButtonCloseDialog, NotifyActivate = ButtonActivate;
107 this, text = $"Cancel", anchor = { horz = 72, bottom = 7 }, size = { 64 }, id = DialogResult::cancel, hotKey = escape;
108 NotifyClicked = ButtonCloseDialog, NotifyActivate = ButtonActivate;
113 this, isDefault = true, text = $"Yes", anchor = { horz = -72, bottom = 7 }, size = { 64 }, id = DialogResult::yes, hotKey = y;
114 NotifyClicked = ButtonCloseDialog, NotifyActivate = ButtonActivate;
120 this, isDefault = true, text = $"OK", anchor = { bottom = 7 }, size = { 64 }, id = DialogResult::ok, hotKey = o;
121 NotifyClicked = ButtonCloseDialog, NotifyActivate = ButtonActivate;
128 bool OnResizing(int *w, int *h)
132 if(style == yesNoCancel)
133 *w = Max(*w, Max(totalWidth, 208) + 24);
135 *w = Max(*w, Max(totalWidth, 144) + 24);
137 *h = Max(*h, Max(totalHeight, 33) + 40);
141 void OnRedraw(Surface surface)
144 int y = (clientSize.h - 33 - totalHeight) / 2;
145 for(line = lines.first; line; line = line.next)
147 surface.WriteText((clientSize.w - totalWidth) / 2, y, line.string, line.len);
152 bool OnLoadGraphics()
155 // This is to set minimum client size on X11
156 // Ideally OnLoadGraphics/OnResizing could be called prior to root window creation...
157 Display display = this.display;
158 Font fontObject = this.fontObject;
159 if(!display) display = master.display;
160 if(!fontObject) fontObject = master.fontObject;
163 for(line = lines.first; line; line = line.next)
167 display.FontExtent(fontObject, " ", 1, (int *)&size.w, (int *)&size.h);
169 display.FontExtent(fontObject, line.string, strlen(line.string), (int *)&size.w, (int *)&size.h);
172 totalWidth = Max(totalWidth, size.w);
173 totalHeight += size.h;
181 for(line = lines.first; line; line = line.next)