From 354c2ccc8cf6bb6d7ad5685ac2958d62e2e81723 Mon Sep 17 00:00:00 2001 From: "Adam D. Ruppe" Date: Wed, 12 Dec 2018 15:53:24 -0500 Subject: [PATCH] more osx foundation --- minigui.d | 28 +++++++++++++++++++++++----- simpledisplay.d | 30 ++++++++++++++++++++++-------- 2 files changed, 45 insertions(+), 13 deletions(-) diff --git a/minigui.d b/minigui.d index 6abf1fb..d645b07 100644 --- a/minigui.d +++ b/minigui.d @@ -1,11 +1,15 @@ // http://msdn.microsoft.com/en-us/library/windows/desktop/bb775498%28v=vs.85%29.aspx +// FIXME: clear the corner of scrollbars if they pop up + // minigui needs to have a stdout redirection for gui mode on windows writeln // I kinda wanna do state reacting. sort of. idk tho // need a viewer widget that works like a web page - arrows scroll down consistently +// I want a nanovega widget, and a svg widget with some kind of event handlers attached to the inside. + // FIXME: the menus should be a bit more discoverable, at least a single click to open the others instead of two. // and help info about menu items. // and search in menus? @@ -47,7 +51,7 @@ on Windows and does its own thing on Linux (Mac is not currently supported but may be later, and should use native controls) to keep size down. The Linux appearance is similar to Windows 95 and avoids using images to maintain network - efficiency on remote X connections. + efficiency on remote X connections, though you can customize that. minigui's only required dependencies are [arsd.simpledisplay] and [arsd.color]. @@ -2024,7 +2028,7 @@ class ScrollableWidget : Widget { /// void verticalScrollTo(int pos) { scrollOrigin_.y = pos; - if(scrollOrigin_.y + viewportHeight > contentHeight) + if(pos == int.max || (scrollOrigin_.y + viewportHeight > contentHeight)) scrollOrigin_.y = contentHeight - viewportHeight; if(scrollOrigin_.y < 0) @@ -2050,7 +2054,7 @@ class ScrollableWidget : Widget { /// void horizontalScrollTo(int pos) { scrollOrigin_.x = pos; - if(scrollOrigin_.x + viewportWidth > contentWidth) + if(pos == int.max || (scrollOrigin_.x + viewportWidth > contentWidth)) scrollOrigin_.x = contentWidth - viewportWidth; if(scrollOrigin_.x < 0) @@ -5562,8 +5566,22 @@ abstract class EditableTextWidget : EditableTextWidgetParent { auto cbb = textLayout.contentBoundingBox(); setContentSize(cbb.width, cbb.height); - } else - content = content ~ txt; + } else version(win32_widgets) { + // get the current selection + DWORD StartPos, EndPos; + SendMessageW( hwnd, EM_GETSEL, cast(WPARAM)(&StartPos), cast(WPARAM)(&EndPos) ); + + // move the caret to the end of the text + int outLength = GetWindowTextLengthW( hwndOutput ); + SendMessageW( hwnd, EM_SETSEL, outLength, outLength ); + + // insert the text at the new caret position + WCharzBuffer bfr = WCharzBuffer(txt, WindowsStringConversionFlags.convertNewLines); + SendMessageW( hwnd, EM_REPLACESEL, TRUE, txt ); + + // restore the previous selection + SendMessageW( hwnd, EM_SETSEL, StartPos, EndPos ); + } else static assert(0); } version(custom_widgets) diff --git a/simpledisplay.d b/simpledisplay.d index 7529ff2..7ab6158 100644 --- a/simpledisplay.d +++ b/simpledisplay.d @@ -979,6 +979,14 @@ version(FreeBSD) version(Solaris) version = X11; + +void featureNotImplemented()() { + version(allow_unimplemented_features) + throw new NotYetImplementedException(); + else + static assert(0); +} + // these are so the static asserts don't trigger unless you want to // add support to it for an OS version(Windows) @@ -1163,7 +1171,7 @@ TrueColorImage trueColorImageFromNativeHandle(NativeWindowHandle handle, int wid } else version(Windows) { // I just need to BitBlt that shit... BUT WAIT IT IS ALREADY IN A DIB!!!!!!! - } else static assert(0); + } else featureNotImplemented(); return null; } @@ -1303,7 +1311,7 @@ class SimpleWindow : CapableOfHandlingNativeEvent, CapableOfBeingDrawnUpon { display = XDisplayConnection.get(); // get initial display to not segfault } else version(OSXCocoa) throw new NotYetImplementedException(); - else static assert(0); + else featureNotImplemented(); // FIXME: set the size correctly _width = 1; _height = 1; @@ -1989,7 +1997,7 @@ class SimpleWindow : CapableOfHandlingNativeEvent, CapableOfBeingDrawnUpon { } else version(Windows) { impl.currentCursor = ch; SetCursor(ch); // redraw without waiting for mouse movement to update - } else static assert(0); + } else featureNotImplemented(); } } @@ -2577,7 +2585,7 @@ static struct GenericCursor { case GenericCursorType.SizeWe: osId = 108 /* XC_sb_h_double_arrow */; break; } - } else static assert(0); + } else featureNotImplemented(); mc = new MouseCursor(osId); } @@ -3975,7 +3983,7 @@ class Timer { ev.data.fd = fd; ep.epoll_ctl(epollFd, ep.EPOLL_CTL_ADD, fd, &ev); } - } else static assert(0); + } else featureNotImplemented(); } /// Stop and destroy the timer object. @@ -4007,7 +4015,7 @@ class Timer { mapping.remove(fd); fd = -1; } - } else static assert(0); + } else featureNotImplemented(); } ~this() { @@ -4041,7 +4049,7 @@ class Timer { unix.read(fd, &val, val.sizeof); // gotta clear the pipe } else version(Windows) { - } else static assert(0); + } else featureNotImplemented(); onPulse(); } @@ -13605,6 +13613,9 @@ mixin template ExperimentalTextComponent() { if(selectionStart is selectionEnd) return; // no selection + if(selectionStart.inlineElement is null) return; + if(selectionEnd.inlineElement is null) return; + assert(selectionStart.inlineElement !is null); assert(selectionEnd.inlineElement !is null); @@ -13809,6 +13820,9 @@ mixin template ExperimentalTextComponent() { if(selectionStart is selectionEnd) return; + if(selectionStart.inlineElement is null) return; + if(selectionEnd.inlineElement is null) return; + assert(selectionStart.inlineElement !is null); assert(selectionEnd.inlineElement !is null); @@ -14081,7 +14095,7 @@ enum _NET_WM_STATE_ADD = 1; enum _NET_WM_STATE_REMOVE = 0; enum _NET_WM_STATE_TOGGLE = 2; -/// X-specific +/// X-specific. Use [SimpleWindow.requestAttention] instead for most casesl void demandAttention(SimpleWindow window, bool needs = true) { auto display = XDisplayConnection.get(); auto atom = XInternAtom(display, "_NET_WM_STATE_DEMANDS_ATTENTION", true);