This commit is contained in:
Adam D. Ruppe 2015-10-23 11:00:26 -04:00
parent 756d775d89
commit fcdd3123c0
4 changed files with 112 additions and 6 deletions

View File

@ -1127,3 +1127,10 @@ struct Size {
int width;
int height;
}
struct Rectangle {
int left;
int top;
int right;
int bottom;
}

2
dom.d
View File

@ -75,8 +75,6 @@ import std.string;
// the reason this is separated is so I can plug it into D->JS as well, which uses a different base Element class
import arsd.dom;
mixin template DomConvenienceFunctions() {
/// Calls getElementById, but throws instead of returning null if the element is not found. You can also ask for a specific subclass of Element to dynamically cast to, which also throws if it cannot be done.

View File

@ -147,6 +147,9 @@ class DataView : Widget {
public import simpledisplay;
version(Windows)
import core.sys.windows.windows;
// this is a hack to call the original window procedure on native win32 widgets if our event listener thing prevents default.
private bool lastDefaultPrevented;
@ -188,8 +191,10 @@ version(Windows) {
Single select, multi select, organization, drag+drop
*/
static if(UsingSimpledisplayX11)
enum windowBackgroundColor = Color(220, 220, 220);
//static if(UsingSimpledisplayX11)
version(win32_widgets) {}
else
enum windowBackgroundColor = Color(220, 220, 220);
private const(char)* toStringzInternal(string s) { return (s ~ '\0').ptr; }
private const(wchar)* toWstringzInternal(in char[] s) {
@ -483,6 +488,17 @@ version(win32_widgets) {
(*te).parentWindow.focusedWidget = lol;
}
if(iMessage == WM_CTLCOLORBTN || iMessage == WM_CTLCOLORSTATIC) {
SetBkMode(cast(HDC) wParam, TRANSPARENT);
return cast(typeof(return))
//GetStockObject(NULL_BRUSH);
// this is the window background color...
GetSysColorBrush(COLOR_3DFACE);
}
auto pos = getChildPositionRelativeToParentOrigin(*te);
lastDefaultPrevented = false;
// try {import std.stdio; writeln(typeid(*te)); } catch(Exception e) {}
@ -525,7 +541,7 @@ version(win32_widgets) {
}
}
version(Windows)
version(win32_widgets)
extern(Windows) BOOL childHandler(HWND hwnd, LPARAM lparam) {
if(hwnd is null || hwnd in Widget.nativeMapping)
return true;
@ -702,6 +718,14 @@ class Widget {
void delegate(ScreenPainter painter) paint;
ScreenPainter draw() {
int x = this.x, y = this.y;
auto parent = this.parent;
while(parent) {
x += parent.x;
y += parent.y;
parent = parent.parent;
}
auto painter = parentWindow.win.draw();
painter.originX = x;
painter.originY = y;
@ -914,7 +938,7 @@ class Window : Widget {
if(recipient !is null) {
// import std.stdio; writeln(typeid(recipient));
version(Windows) {
version(win32_widgets) {
if(recipient.hwnd !is null)
SetFocus(recipient.hwnd);
} else {
@ -1530,6 +1554,8 @@ class ProgressBar : Widget {
}
class Fieldset : Widget {
// FIXME: on Windows,it doesn't draw the background on the label
// on X, it doesn't fix the clipping rectangle for it
version(win32_widgets)
override int paddingTop() { return Window.lineHeight; }
else
@ -2089,6 +2115,13 @@ class TextEdit : Widget {
painter.drawText(Point(4, 4), content, Point(width - 4, height - 4));
};
caratTimer = new Timer(500, {
auto painter = this.draw();
painter.pen = Pen(Color.white, 1);
painter.rasterOp = RasterOp.xor;
painter.drawLine(Point(16, 0), Point(16, 16));
});
defaultEventHandlers["click"] = delegate (Widget _this, Event ev) {
this.focus();
};
@ -2127,6 +2160,12 @@ class TextEdit : Widget {
assert(parentWindow !is null);
parentWindow.focusedWidget = this;
}
version(win32_widgets) {
} else {
Timer caratTimer;
}
}

View File

@ -3,6 +3,20 @@
// subsystem too, use `-L/subsystem:windows -L/entry:mainCRTStartup`
/*
FIXME:
Text layout needs a lot of work. Plain drawText is useful but too
limited. It will need some kind of text context thing which it will
update and you can pass it on and get more details out of it.
It will need a bounding box, a current cursor location that is updated
as drawing continues, and various changable facts (which can also be
changed on the painter i guess) like font, color, size, background,
etc.
We can also fetch the carat location from it somehow.
Should prolly be an overload of drawText
blink taskbar / demand attention cross platform. FlashWindow and demandAttention
WS_EX_NOACTIVATE
@ -2224,6 +2238,41 @@ struct ScreenPainter {
impl.drawText(upperLeft.x, upperLeft.y, lowerRight.x, lowerRight.y, text, alignment);
}
static struct TextDrawingContext {
Point boundingBoxUpperLeft;
Point boundingBoxLowerRight;
Point currentLocation;
Point lastDrewUpperLeft;
Point lastDrewLowerRight;
// how do i do right aligned rich text?
// i kinda want to do a pre-made drawing then right align
// draw the whole block.
//
// That's exactly the diff: inline vs block stuff.
// I need to get coordinates of an inline section out too,
// not just a bounding box, but a series of bounding boxes
// should be ok. Consider what's needed to detect a click
// on a link in the middle of a paragraph breaking a line.
//
// Generally, we should be able to get the rectangles of
// any portion we draw.
//
// It also needs to tell what text is left if it overflows
// out of the box, so we can do stuff like float images around
// it. It should not attempt to draw a letter that would be
// clipped.
//
// I might also turn off word wrap stuff.
}
void drawText(TextDrawingContext context, string text, uint alignment = 0) {
// FIXME
}
/// Drawing an individual pixel is slow. Avoid it if possible.
void drawPixel(Point where) {
transform(where);
@ -3622,6 +3671,12 @@ version(Windows) {
//case WM_ERASEBKGND:
// no need since we double buffer
//break;
case WM_CTLCOLORBTN:
case WM_CTLCOLORSTATIC:
SetBkMode(cast(HDC) wParam, TRANSPARENT);
return cast(typeof(return)) //GetStockObject(NULL_BRUSH);
GetSysColorBrush(COLOR_3DFACE);
break;
case WM_PAINT: {
BITMAP bm;
PAINTSTRUCT ps;
@ -3860,6 +3915,8 @@ version(X11) {
void dispose() {
auto buffer = this.window.impl.buffer;
this.rasterOp = RasterOp.normal;
// FIXME: this.window.width/height is probably wrong
// src x,y then dest x, y
@ -4361,6 +4418,7 @@ version(X11) {
// FIXME: windowType and customizationFlags
try
final switch(windowType) {
case WindowTypes.normal:
setNetWMWindowType(GetAtom!"_NET_WM_WINDOW_TYPE_NORMAL"(display));
@ -4411,6 +4469,10 @@ version(X11) {
break;
+/
}
catch(Exception e) {
// XInternAtom failed, prolly a WM
// that doesn't support these things
}