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)
130 if(style == yesNoCancel)
131 *w = Max(*w, Max(totalWidth, 208) + 24);
133 *w = Max(*w, Max(totalWidth, 144) + 24);
135 *h = Max(*h, Max(totalHeight, 33) + 40);
139 void OnRedraw(Surface surface)
142 int y = (clientSize.h - 33 - totalHeight) / 2;
143 for(line = lines.first; line; line = line.next)
145 surface.WriteText((clientSize.w - totalWidth) / 2, y, line.string, line.len);
150 bool OnLoadGraphics()
155 for(line = lines.first; line; line = line.next)
159 display.FontExtent(fontObject, " ", 1, (int *)&size.w, (int *)&size.h);
161 display.FontExtent(fontObject, line.string, strlen(line.string), (int *)&size.w, (int *)&size.h);
164 totalWidth = Max(totalWidth, size.w);
165 totalHeight += size.h;
173 for(line = lines.first; line; line = line.next)