Made minigui use version win32_widgets, else custom_widgets else static assert false

Signed-off-by: WebFreak001 <janju007@web.de>
This commit is contained in:
WebFreak001 2017-04-02 20:18:42 +02:00
parent 05a893e9b9
commit 3c2e2b63da
1 changed files with 93 additions and 68 deletions

161
minigui.d
View File

@ -95,10 +95,11 @@ abstract class ComboboxBase : Widget {
parentWindow = parent.parentWindow; parentWindow = parent.parentWindow;
createWin32Window(this, "ComboBox", null, style); createWin32Window(this, "ComboBox", null, style);
} }
else else version(custom_widgets)
this(Widget parent = null) { this(Widget parent = null) {
super(parent); super(parent);
} }
else static assert(false);
private string[] options; private string[] options;
private int selection = -1; private int selection = -1;
@ -134,8 +135,9 @@ class DropDownSelection : ComboboxBase {
this(Widget parent = null) { this(Widget parent = null) {
version(win32_widgets) version(win32_widgets)
super(3 /* CBS_DROPDOWNLIST */, parent); super(3 /* CBS_DROPDOWNLIST */, parent);
else else version(custom_widgets)
super(parent); super(parent);
else static assert(false);
} }
} }
@ -147,8 +149,9 @@ class FreeEntrySelection : ComboboxBase {
this(Widget parent = null) { this(Widget parent = null) {
version(win32_widgets) version(win32_widgets)
super(2 /* CBS_DROPDOWN */, parent); super(2 /* CBS_DROPDOWN */, parent);
else else version(custom_widgets)
super(parent); super(parent);
else static assert(false);
} }
} }
@ -159,8 +162,9 @@ class ComboBox : ComboboxBase {
this(Widget parent = null) { this(Widget parent = null) {
version(win32_widgets) version(win32_widgets)
super(1 /* CBS_SIMPLE */, parent); super(1 /* CBS_SIMPLE */, parent);
else else version(custom_widgets)
super(parent); super(parent);
else static assert(false);
} }
override int minHeight() { return Window.lineHeight * 3; } override int minHeight() { return Window.lineHeight * 3; }
@ -262,8 +266,9 @@ version(Windows) {
//static if(UsingSimpledisplayX11) //static if(UsingSimpledisplayX11)
version(win32_widgets) {} version(win32_widgets) {}
else else version(custom_widgets)
enum windowBackgroundColor = Color(192, 192, 192); enum windowBackgroundColor = Color(192, 192, 192);
else static assert(false);
private const(char)* toStringzInternal(string s) { return (s ~ '\0').ptr; } private const(char)* toStringzInternal(string s) { return (s ~ '\0').ptr; }
private const(wchar)* toWstringzInternal(in char[] s) { private const(wchar)* toWstringzInternal(in char[] s) {
@ -1142,9 +1147,9 @@ class Window : Widget {
version(win32_widgets) { version(win32_widgets) {
if(recipient.hwnd !is null) if(recipient.hwnd !is null)
SetFocus(recipient.hwnd); SetFocus(recipient.hwnd);
} else { } else version(custom_widgets) {
focusedWidget = recipient; focusedWidget = recipient;
} } else static assert(false);
*/ */
skipNextChar = true; skipNextChar = true;
@ -1175,13 +1180,13 @@ class Window : Widget {
SelectObject(painter.impl.hdc, b); SelectObject(painter.impl.hdc, b);
}; };
} }
else else version(custom_widgets)
this.paint = (ScreenPainter painter) { this.paint = (ScreenPainter painter) {
painter.fillColor = windowBackgroundColor; painter.fillColor = windowBackgroundColor;
painter.outlineColor = windowBackgroundColor; painter.outlineColor = windowBackgroundColor;
painter.drawRectangle(Point(0, 0), this.width, this.height); painter.drawRectangle(Point(0, 0), this.width, this.height);
}; };
else static assert(false);
} }
this(int width = 500, int height = 500, string title = null) { this(int width = 500, int height = 500, string title = null) {
@ -1389,14 +1394,14 @@ class MainWindow : Window {
version(win32_widgets) { version(win32_widgets) {
SetMenu(parentWindow.win.impl.hwnd, m.handle); SetMenu(parentWindow.win.impl.hwnd, m.handle);
} else { } else version(custom_widgets) {
super.addChild(m, 0); super.addChild(m, 0);
// clientArea.y = menu.height; // clientArea.y = menu.height;
// clientArea.height = this.height - menu.height; // clientArea.height = this.height - menu.height;
recomputeChildLayout(); recomputeChildLayout();
} } else static assert(false);
return _menu; return _menu;
} }
@ -1435,10 +1440,10 @@ class ToolBar : Widget {
private const int idealHeight; private const int idealHeight;
override int minHeight() { return idealHeight; } override int minHeight() { return idealHeight; }
override int maxHeight() { return idealHeight; } override int maxHeight() { return idealHeight; }
} else { } else version(custom_widgets) {
override int minHeight() { return Window.lineHeight * 3/2; } override int minHeight() { return Window.lineHeight * 3/2; }
override int maxHeight() { return Window.lineHeight * 3/2; } override int maxHeight() { return Window.lineHeight * 3/2; }
} } else static assert(false);
override int heightStretchiness() { return 0; } override int heightStretchiness() { return 0; }
version(win32_widgets) version(win32_widgets)
@ -1482,10 +1487,10 @@ class ToolBar : Widget {
idealHeight = rect.bottom - rect.top + 10; // the +10 is a hack since the size right now doesn't look right on a real Windows XP box idealHeight = rect.bottom - rect.top + 10; // the +10 is a hack since the size right now doesn't look right on a real Windows XP box
assert(idealHeight); assert(idealHeight);
} else { } else version(custom_widgets) {
foreach(action; actions) foreach(action; actions)
addChild(new ToolButton(action)); addChild(new ToolButton(action));
} } else static assert(false);
} }
override void recomputeChildLayout() { override void recomputeChildLayout() {
@ -1504,7 +1509,8 @@ class ToolButton : Button {
tabStop = false; tabStop = false;
this.action = action; this.action = action;
version(win32_widgets) {} else { version(win32_widgets) {}
else version(custom_widgets) {
defaultEventHandlers["click"] = (Widget _this, Event event) { defaultEventHandlers["click"] = (Widget _this, Event event) {
foreach(handler; action.triggered) foreach(handler; action.triggered)
handler(); handler();
@ -1517,6 +1523,7 @@ class ToolButton : Button {
painter.drawText(Point(0, 0), action.label, Point(width, height), TextAlignment.Center | TextAlignment.VerticalCenter); painter.drawText(Point(0, 0), action.label, Point(width, height), TextAlignment.Center | TextAlignment.VerticalCenter);
}; };
} }
else static assert(false);
} }
Action action; Action action;
@ -1537,7 +1544,7 @@ class MenuBar : Widget {
handle = CreateMenu(); handle = CreateMenu();
tabStop = false; tabStop = false;
} }
} else { } else version(custom_widgets) {
this(Widget parent = null) { this(Widget parent = null) {
tabStop = false; // these are selected some other way tabStop = false; // these are selected some other way
super(parent); super(parent);
@ -1545,7 +1552,7 @@ class MenuBar : Widget {
draw3dFrame(this, painter, FrameStyle.risen); draw3dFrame(this, painter, FrameStyle.risen);
}; };
} }
} } else static assert(false);
MenuItem addItem(MenuItem item) { MenuItem addItem(MenuItem item) {
this.addChild(item); this.addChild(item);
@ -1564,11 +1571,11 @@ class MenuBar : Widget {
version(win32_widgets) { version(win32_widgets) {
AppendMenuA(handle, MF_STRING | MF_POPUP, cast(UINT) item.handle, toStringzInternal(item.label)); // XXX AppendMenuA(handle, MF_STRING | MF_POPUP, cast(UINT) item.handle, toStringzInternal(item.label)); // XXX
} else { } else version(custom_widgets) {
mbItem.defaultEventHandlers["click"] = (Widget e, Event ev) { mbItem.defaultEventHandlers["click"] = (Widget e, Event ev) {
item.popup(mbItem); item.popup(mbItem);
}; };
} } else static assert(false);
return item; return item;
} }
@ -1630,9 +1637,9 @@ class StatusBar : Widget {
pos[idx] = cpos; pos[idx] = cpos;
} }
SendMessageA(owner.hwnd, WM_USER + 4 /*SB_SETPARTS*/, owner.partsArray.length, cast(int) pos.ptr); SendMessageA(owner.hwnd, WM_USER + 4 /*SB_SETPARTS*/, owner.partsArray.length, cast(int) pos.ptr);
} else { } else version(custom_widgets) {
owner.redraw(); owner.redraw();
} } else static assert(false);
return p; return p;
} }
@ -1656,12 +1663,12 @@ class StatusBar : Widget {
version(win32_widgets) { version(win32_widgets) {
_content = s; _content = s;
SendMessageA(owner.hwnd, SB_SETTEXT, idx, cast(LPARAM) toStringzInternal(s)); SendMessageA(owner.hwnd, SB_SETTEXT, idx, cast(LPARAM) toStringzInternal(s));
} else { } else version(custom_widgets) {
if(_content != s) { if(_content != s) {
_content = s; _content = s;
owner.redraw(); owner.redraw();
} }
} } else static assert(false);
} }
} }
string simpleModeContent; string simpleModeContent;
@ -1680,7 +1687,7 @@ class StatusBar : Widget {
GetWindowRect(hwnd, &rect); GetWindowRect(hwnd, &rect);
idealHeight = rect.bottom - rect.top; idealHeight = rect.bottom - rect.top;
assert(idealHeight); assert(idealHeight);
} else { } else version(custom_widgets) {
this.paint = (ScreenPainter painter) { this.paint = (ScreenPainter painter) {
this.draw3dFrame(painter, FrameStyle.risen); this.draw3dFrame(painter, FrameStyle.risen);
int cpos = 0; int cpos = 0;
@ -1693,17 +1700,17 @@ class StatusBar : Widget {
remainingLength -= partWidth; remainingLength -= partWidth;
} }
}; };
} } else static assert(false);
} }
version(win32_widgets) { version(win32_widgets) {
private const int idealHeight; private const int idealHeight;
override int maxHeight() { return idealHeight; } override int maxHeight() { return idealHeight; }
override int minHeight() { return idealHeight; } override int minHeight() { return idealHeight; }
} else { } else version(custom_widgets) {
override int maxHeight() { return Window.lineHeight + 4; } override int maxHeight() { return Window.lineHeight + 4; }
override int minHeight() { return Window.lineHeight + 4; } override int minHeight() { return Window.lineHeight + 4; }
} } else static assert(false);
} }
/// Displays an in-progress indicator without known values /// Displays an in-progress indicator without known values
@ -1728,7 +1735,7 @@ class ProgressBar : Widget {
createWin32Window(this, "msctls_progress32", "", 0); createWin32Window(this, "msctls_progress32", "", 0);
tabStop = false; tabStop = false;
} }
else { else version(custom_widgets) {
this(Widget parent = null) { this(Widget parent = null) {
super(parent); super(parent);
max = 100; max = 100;
@ -1745,46 +1752,51 @@ class ProgressBar : Widget {
int max; int max;
int step; int step;
} }
else static assert(false);
void advanceOneStep() { void advanceOneStep() {
version(win32_widgets) version(win32_widgets)
SendMessageA(hwnd, PBM_STEPIT, 0, 0); SendMessageA(hwnd, PBM_STEPIT, 0, 0);
else else version(custom_widgets)
addToPosition(step); addToPosition(step);
else static assert(false);
} }
void setStepIncrement(int increment) { void setStepIncrement(int increment) {
version(win32_widgets) version(win32_widgets)
SendMessageA(hwnd, PBM_SETSTEP, increment, 0); SendMessageA(hwnd, PBM_SETSTEP, increment, 0);
else else version(custom_widgets)
step = increment; step = increment;
else static assert(false);
} }
void addToPosition(int amount) { void addToPosition(int amount) {
version(win32_widgets) version(win32_widgets)
SendMessageA(hwnd, PBM_DELTAPOS, amount, 0); SendMessageA(hwnd, PBM_DELTAPOS, amount, 0);
else { else version(custom_widgets)
setPosition(current + amount); setPosition(current + amount);
} else static assert(false);
} }
void setPosition(int pos) { void setPosition(int pos) {
version(win32_widgets) version(win32_widgets)
SendMessageA(hwnd, PBM_SETPOS, pos, 0); SendMessageA(hwnd, PBM_SETPOS, pos, 0);
else { else version(custom_widgets) {
current = pos; current = pos;
if(current > max) if(current > max)
current = max; current = max;
redraw(); redraw();
} }
else static assert(false);
} }
void setRange(ushort min, ushort max) { void setRange(ushort min, ushort max) {
version(win32_widgets) version(win32_widgets)
SendMessageA(hwnd, PBM_SETRANGE, 0, MAKELONG(min, max)); SendMessageA(hwnd, PBM_SETRANGE, 0, MAKELONG(min, max));
else { else version(custom_widgets) {
this.max = max; this.max = max;
} }
else static assert(false);
} }
override int minHeight() { return 10; } override int minHeight() { return 10; }
@ -1796,8 +1808,9 @@ class Fieldset : Widget {
// on X, it doesn't fix the clipping rectangle for it // on X, it doesn't fix the clipping rectangle for it
version(win32_widgets) version(win32_widgets)
override int paddingTop() { return Window.lineHeight; } override int paddingTop() { return Window.lineHeight; }
else else version(custom_widgets)
override int paddingTop() { return Window.lineHeight + 2; } override int paddingTop() { return Window.lineHeight + 2; }
else static assert(false);
override int paddingBottom() { return 6; } override int paddingBottom() { return 6; }
override int paddingLeft() { return 6; } override int paddingLeft() { return 6; }
override int paddingRight() { return 6; } override int paddingRight() { return 6; }
@ -1817,7 +1830,7 @@ class Fieldset : Widget {
createWin32Window(this, "button", legend, BS_GROUPBOX); createWin32Window(this, "button", legend, BS_GROUPBOX);
tabStop = false; tabStop = false;
} }
else else version(custom_widgets)
this(string legend, Widget parent = null) { this(string legend, Widget parent = null) {
super(parent); super(parent);
tabStop = false; tabStop = false;
@ -1843,6 +1856,7 @@ class Fieldset : Widget {
painter.drawText(Point(8, 0), legend); painter.drawText(Point(8, 0), legend);
}; };
} }
else static assert(false);
override int maxHeight() { override int maxHeight() {
auto m = paddingTop() + paddingBottom(); auto m = paddingTop() + paddingBottom();
@ -1873,7 +1887,8 @@ class Menu : Window {
parentWindow.releaseMouseCapture(); parentWindow.releaseMouseCapture();
} }
version(win32_widgets) {} else { version(win32_widgets) {}
else version(custom_widgets) {
SimpleWindow dropDown; SimpleWindow dropDown;
Widget menuParent; Widget menuParent;
void popup(Widget parent) { void popup(Widget parent) {
@ -1905,6 +1920,7 @@ class Menu : Window {
dropDown.show(); dropDown.show();
} }
} }
else static assert(false);
version(custom_widgets) version(custom_widgets)
void unpopup() { void unpopup() {
@ -1934,7 +1950,7 @@ class Menu : Window {
this.label = label; this.label = label;
handle = CreatePopupMenu(); handle = CreatePopupMenu();
} }
} else { } else version(custom_widgets) {
this(string label, Widget parent = null) { this(string label, Widget parent = null) {
if(dropDown) { if(dropDown) {
@ -1956,7 +1972,7 @@ class Menu : Window {
this.draw3dFrame(painter, FrameStyle.risen); this.draw3dFrame(painter, FrameStyle.risen);
}; };
} }
} } else static assert(false);
override int maxHeight() { return Window.lineHeight; } override int maxHeight() { return Window.lineHeight; }
override int minHeight() { return Window.lineHeight; } override int minHeight() { return Window.lineHeight; }
@ -1984,15 +2000,17 @@ class MenuItem : MouseActivatedWidget {
foreach(char ch; lbl) // FIXME foreach(char ch; lbl) // FIXME
if(ch != '&') // FIXME if(ch != '&') // FIXME
label ~= ch; // FIXME label ~= ch; // FIXME
version(win32_widgets) {} else version(win32_widgets) {}
this.paint = (ScreenPainter painter) { else version(custom_widgets)
if(isHovering) this.paint = (ScreenPainter painter) {
painter.outlineColor = Color.blue; if(isHovering)
else painter.outlineColor = Color.blue;
painter.outlineColor = Color.black; else
painter.fillColor = Color.transparent; painter.outlineColor = Color.black;
painter.drawText(Point(cast(MenuBar) this.parent ? 4 : 20, 2), label, Point(width, height), TextAlignment.Left); painter.fillColor = Color.transparent;
}; painter.drawText(Point(cast(MenuBar) this.parent ? 4 : 20, 2), label, Point(width, height), TextAlignment.Left);
};
else static assert(false);
tabStop = false; // these are selected some other way tabStop = false; // these are selected some other way
} }
@ -2030,7 +2048,7 @@ class MouseActivatedWidget : Widget {
super(parent); super(parent);
} }
} }
else else version(custom_widgets)
class MouseActivatedWidget : Widget { class MouseActivatedWidget : Widget {
bool isDepressed = false; bool isDepressed = false;
bool isHovering = false; bool isHovering = false;
@ -2098,6 +2116,7 @@ class MouseActivatedWidget : Widget {
}; };
} }
} }
else static assert(false);
/// ///
@ -2113,7 +2132,7 @@ class Checkbox : MouseActivatedWidget {
parentWindow = parent.parentWindow; parentWindow = parent.parentWindow;
createWin32Window(this, "button", label, BS_AUTOCHECKBOX); createWin32Window(this, "button", label, BS_AUTOCHECKBOX);
} }
else else version(custom_widgets)
this(string label, Widget parent = null) { this(string label, Widget parent = null) {
super(parent); super(parent);
@ -2157,6 +2176,7 @@ class Checkbox : MouseActivatedWidget {
redraw(); redraw();
}; };
} }
else static assert(false);
} }
/// ///
@ -2179,7 +2199,7 @@ class Radiobox : MouseActivatedWidget {
parentWindow = parent.parentWindow; parentWindow = parent.parentWindow;
createWin32Window(this, "button", label, BS_AUTORADIOBUTTON); createWin32Window(this, "button", label, BS_AUTORADIOBUTTON);
} }
else else version(custom_widgets)
this(string label, Widget parent = null) { this(string label, Widget parent = null) {
super(parent); super(parent);
height = 16; height = 16;
@ -2232,6 +2252,7 @@ class Radiobox : MouseActivatedWidget {
redraw(); redraw();
}; };
} }
else static assert(false);
} }
@ -2247,7 +2268,8 @@ class Button : MouseActivatedWidget {
event.dispatch(); event.dispatch();
} }
version(win32_widgets) {} else version(win32_widgets) {}
else version(custom_widgets)
Color currentButtonColor() { Color currentButtonColor() {
if(isHovering) { if(isHovering) {
return isDepressed ? depressedBgColor : hoverBgColor; return isDepressed ? depressedBgColor : hoverBgColor;
@ -2255,6 +2277,7 @@ class Button : MouseActivatedWidget {
return normalBgColor; return normalBgColor;
} }
else static assert(false);
version(win32_widgets) version(win32_widgets)
this(string label, Widget parent = null) { this(string label, Widget parent = null) {
@ -2266,8 +2289,7 @@ class Button : MouseActivatedWidget {
width = 50; width = 50;
height = 30; height = 30;
} }
else else version(custom_widgets)
this(string label, Widget parent = null) { this(string label, Widget parent = null) {
super(parent); super(parent);
normalBgColor = Color(192, 192, 192); normalBgColor = Color(192, 192, 192);
@ -2293,6 +2315,7 @@ class Button : MouseActivatedWidget {
} }
}; };
} }
else static assert(false);
override int minHeight() { return Window.lineHeight; } override int minHeight() { return Window.lineHeight; }
} }
@ -2363,14 +2386,14 @@ abstract class EditableTextWidget : Widget {
return buffer[0 .. l].idup; return buffer[0 .. l].idup;
else else
return null; return null;
} else { } else version(custom_widgets) {
return textLayout.getPlainText(); return textLayout.getPlainText();
} } else static assert(false);
} }
@property void content(string s) { @property void content(string s) {
version(win32_widgets) version(win32_widgets)
SetWindowTextA(hwnd, toStringzInternal(s)); SetWindowTextA(hwnd, toStringzInternal(s));
else { else version(custom_widgets) {
textLayout.clear(); textLayout.clear();
textLayout.addText(s); textLayout.addText(s);
textLayout.addText(ForegroundColor.red, s); textLayout.addText(ForegroundColor.red, s);
@ -2378,10 +2401,11 @@ abstract class EditableTextWidget : Widget {
textLayout.addText(" is the best!"); textLayout.addText(" is the best!");
redraw(); redraw();
} }
else static assert(false);
} }
version(win32_widgets) { /* will do it with Windows calls in the classes */ } version(win32_widgets) { /* will do it with Windows calls in the classes */ }
else { else version(custom_widgets) {
// FIXME // FIXME
Timer caratTimer; Timer caratTimer;
@ -2496,6 +2520,7 @@ abstract class EditableTextWidget : Widget {
cursor = XCreateFontCursor(XDisplayConnection.get(), 152 /* XC_xterm, a text input thingy */); cursor = XCreateFontCursor(XDisplayConnection.get(), 152 /* XC_xterm, a text input thingy */);
} }
} }
else static assert(false);
} }
/// ///
@ -2506,13 +2531,13 @@ class LineEdit : EditableTextWidget {
parentWindow = parent.parentWindow; parentWindow = parent.parentWindow;
createWin32Window(this, "edit", "", createWin32Window(this, "edit", "",
0, WS_EX_CLIENTEDGE);//|WS_HSCROLL|ES_AUTOHSCROLL); 0, WS_EX_CLIENTEDGE);//|WS_HSCROLL|ES_AUTOHSCROLL);
} else { } else version(custom_widgets) {
setupCustomTextEditing(); setupCustomTextEditing();
addEventListener("char", delegate(Widget _this, Event ev) { addEventListener("char", delegate(Widget _this, Event ev) {
if(ev.character == '\n') if(ev.character == '\n')
ev.preventDefault(); ev.preventDefault();
}); });
} } else static assert(false);
} }
override int maxHeight() { return Window.lineHeight + 4; } override int maxHeight() { return Window.lineHeight + 4; }
} }
@ -2525,9 +2550,9 @@ class TextEdit : EditableTextWidget {
parentWindow = parent.parentWindow; parentWindow = parent.parentWindow;
createWin32Window(this, "edit", "", createWin32Window(this, "edit", "",
0|WS_VSCROLL|WS_HSCROLL|ES_MULTILINE|ES_WANTRETURN|ES_AUTOHSCROLL|ES_AUTOVSCROLL, WS_EX_CLIENTEDGE); 0|WS_VSCROLL|WS_HSCROLL|ES_MULTILINE|ES_WANTRETURN|ES_AUTOHSCROLL|ES_AUTOVSCROLL, WS_EX_CLIENTEDGE);
} else { } else version(custom_widgets) {
setupCustomTextEditing(); setupCustomTextEditing();
} } else static assert(false);
} }
override int maxHeight() { return int.max; } override int maxHeight() { return int.max; }
override int heightStretchiness() { return 4; } override int heightStretchiness() { return 4; }