Mercurial > projects > dwt-win
diff dwt/graphics/GC.d @ 213:36f5cb12e1a2
Update to SWT 3.4M7
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sat, 17 May 2008 17:34:28 +0200 |
parents | ab60f3309436 |
children | 4436505b216f |
line wrap: on
line diff
--- a/dwt/graphics/GC.d Mon May 05 00:12:38 2008 +0200 +++ b/dwt/graphics/GC.d Sat May 17 17:34:28 2008 +0200 @@ -73,6 +73,8 @@ public final class GC : Resource { + alias Resource.init_ init_; + /** * the handle to the OS device context * (Warning: This field is platform dependent) @@ -181,7 +183,7 @@ if (device is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); this.device = data.device = device; init_ (drawable, data, hDC); - if (device.tracking) device.new_Object(this); + init_(); } static int checkStyle(int style) { @@ -263,7 +265,7 @@ default: } if (dashes !is null) { - Gdip.Pen_SetDashPattern(pen, dashes, dashes.length); + Gdip.Pen_SetDashPattern(pen, dashes.ptr, dashes.length); Gdip.Pen_SetDashStyle(pen, Gdip.DashStyleCustom); Gdip.Pen_SetDashOffset(pen, dashOffset); } else { @@ -323,25 +325,26 @@ } } if ((state & FONT) !is 0) { - OS.SelectObject(handle, data.hFont); - auto font = createGdipFont(handle, data.hFont); + Font font = data.font; + OS.SelectObject(handle, font.handle); + auto gdipFont = createGdipFont(handle, font.handle); if (data.gdipFont !is null) Gdip.Font_delete(data.gdipFont); - data.gdipFont = font; + data.gdipFont = gdipFont; } if ((state & DRAW_OFFSET) !is 0) { data.gdipXOffset = data.gdipYOffset = 0; auto matrix = Gdip.Matrix_new(1, 0, 0, 1, 0, 0); - float[6] elements; + float[2] point; point[0]=1.0; point[1]=1.0; Gdip.Graphics_GetTransform(gdipGraphics, matrix); - Gdip.Matrix_GetElements(matrix, elements ); + Gdip.Matrix_TransformPoints(matrix, cast(Gdip.PointF*)point.ptr, 1); Gdip.Matrix_delete(matrix); - float scaling = elements[0]; + float scaling = point[0]; if (scaling < 0) scaling = -scaling; float penWidth = data.lineWidth * scaling; if (penWidth is 0 || (cast(int)penWidth % 2) is 1) { data.gdipXOffset = 0.5f / scaling; } - scaling = elements[3]; + scaling = point[1]; if (scaling < 0) scaling = -scaling; penWidth = data.lineWidth * scaling; if (penWidth is 0 || (cast(int)penWidth % 2) is 1) { @@ -439,7 +442,8 @@ OS.SetTextColor(handle, data.foreground); } if ((state & FONT) !is 0) { - OS.SelectObject(handle, data.hFont); + Font font = data.font; + OS.SelectObject(handle, font.handle); } } @@ -627,11 +631,12 @@ * <li>ERROR_THREAD_INVALID_ACCESS if not called from the thread that created the drawable</li> * </ul> */ -override public void dispose() { - if (handle is null) return; - if (data.device.isDisposed()) return; - +void destroy() { + bool gdip = data.gdipGraphics !is null; disposeGdip(); + if (gdip && (data.style & DWT.MIRRORED) !is 0) { + OS.SetLayout(handle, OS.GetLayout(handle) | OS.LAYOUT_RTL); + } /* Select stock pen and brush objects and free resources */ if (data.hPen !is null) { @@ -661,14 +666,11 @@ /* * Dispose the HDC. */ - Device device = data.device; if (drawable !is null) drawable.internal_dispose_GC(handle, data); drawable = null; handle = null; data.image = null; data.ps = null; - if (device.tracking) device.dispose_Object(this); - data.device = null; data = null; } @@ -816,6 +818,7 @@ public void drawFocus (int x, int y, int width, int height) { if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); if ((data.uiState & OS.UISF_HIDEFOCUS) !is 0) return; + data.focusDrawn = true; HDC hdc = handle; int state = 0; auto gdipGraphics = data.gdipGraphics; @@ -837,13 +840,11 @@ Gdip.Graphics_GetTransform(gdipGraphics, matrix); if (!Gdip.Matrix_IsIdentity(matrix)) { gotElements = true; - Gdip.Matrix_GetElements(matrix, lpXform); + Gdip.Matrix_GetElements(matrix, lpXform.ptr); } Gdip.Matrix_delete(matrix); hdc = Gdip.Graphics_GetHDC(gdipGraphics); state = OS.SaveDC(hdc); - OS.SetBkColor(hdc, data.background); - OS.SetTextColor(hdc, data.foreground); if (gotElements) { OS.SetGraphicsMode(hdc, OS.GM_ADVANCED); OS.SetWorldTransform(hdc, cast(XFORM*)lpXform.ptr); @@ -853,12 +854,16 @@ OS.DeleteObject(clipRgn); } } + OS.SetBkColor(hdc, 0xFFFFFF); + OS.SetTextColor(hdc, 0x000000); RECT rect; OS.SetRect(&rect, x, y, x + width, y + height); OS.DrawFocusRect(hdc, &rect); if (gdipGraphics !is null) { OS.RestoreDC(hdc, state); Gdip.Graphics_ReleaseHDC(gdipGraphics, hdc); + } else { + data.state &= ~(BACKGROUND_TEXT | FOREGROUND_TEXT); } } @@ -934,7 +939,7 @@ void drawImage(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, bool simple) { if (data.gdipGraphics !is null) { //TODO - cache bitmap - int[] gdipImage = srcImage.createGdipImage(); + int /*long*/ [] gdipImage = srcImage.createGdipImage(); auto img = cast(Gdip.Image) gdipImage[0]; int imgWidth = Gdip.Image_GetWidth(img); int imgHeight = Gdip.Image_GetHeight(img); @@ -1426,7 +1431,8 @@ } auto srcHdc = OS.CreateCompatibleDC(handle); auto oldSrcBitmap = OS.SelectObject(srcHdc, srcColor); - auto destHdc = handle, x = destX, y = destY; + auto destHdc = handle; + int x = destX, y = destY; HDC tempHdc; HBITMAP tempBitmap; HBITMAP oldTempBitmap; @@ -1806,7 +1812,7 @@ auto gdipGraphics = data.gdipGraphics; if (gdipGraphics !is null) { Gdip.Graphics_TranslateTransform(gdipGraphics, data.gdipXOffset, data.gdipYOffset, Gdip.MatrixOrderPrepend); - Gdip.Graphics_DrawPolygon(gdipGraphics, data.gdipPen, cast(Gdip.Point[])pointArray, pointArray.length/2); + Gdip.Graphics_DrawPolygon(gdipGraphics, data.gdipPen, cast(Gdip.Point*)pointArray.ptr, pointArray.length/2); Gdip.Graphics_TranslateTransform(gdipGraphics, -data.gdipXOffset, -data.gdipYOffset, Gdip.MatrixOrderPrepend); return; } @@ -1851,7 +1857,7 @@ auto gdipGraphics = data.gdipGraphics; if (gdipGraphics !is null) { Gdip.Graphics_TranslateTransform(gdipGraphics, data.gdipXOffset, data.gdipYOffset, Gdip.MatrixOrderPrepend); - Gdip.Graphics_DrawLines(gdipGraphics, data.gdipPen, cast(Gdip.Point[])pointArray, pointArray.length / 2); + Gdip.Graphics_DrawLines(gdipGraphics, data.gdipPen, cast(Gdip.Point*)pointArray.ptr, pointArray.length / 2); Gdip.Graphics_TranslateTransform(gdipGraphics, -data.gdipXOffset, -data.gdipYOffset, Gdip.MatrixOrderPrepend); return; } @@ -1898,6 +1904,14 @@ checkGC(DRAW); auto gdipGraphics = data.gdipGraphics; if (gdipGraphics !is null) { + if (width < 0) { + x = x + width; + width = -width; + } + if (height < 0) { + y = y + height; + height = -height; + } Gdip.Graphics_TranslateTransform(gdipGraphics, data.gdipXOffset, data.gdipYOffset, Gdip.MatrixOrderPrepend); Gdip.Graphics_DrawRectangle(gdipGraphics, data.gdipPen, x, y, width, height); Gdip.Graphics_TranslateTransform(gdipGraphics, -data.gdipXOffset, -data.gdipYOffset, Gdip.MatrixOrderPrepend); @@ -2036,29 +2050,33 @@ nah = 0 - nah; Gdip.Graphics_TranslateTransform(gdipGraphics, data.gdipXOffset, data.gdipYOffset, Gdip.MatrixOrderPrepend); - auto path = Gdip.GraphicsPath_new(Gdip.FillModeAlternate); - if (path is null) DWT.error(DWT.ERROR_NO_HANDLES); - if (nw > naw) { - if (nh > nah) { - Gdip.GraphicsPath_AddArc(path, nx + nw - naw, ny, naw, nah, 0, -90); - Gdip.GraphicsPath_AddArc(path, nx, ny, naw, nah, -90, -90); - Gdip.GraphicsPath_AddArc(path, nx, ny + nh - nah, naw, nah, -180, -90); - Gdip.GraphicsPath_AddArc(path, nx + nw - naw, ny + nh - nah, naw, nah, -270, -90); + if (naw is 0 || nah is 0) { + Gdip.Graphics_DrawRectangle(gdipGraphics, data.gdipPen, x, y, width, height); + } else { + auto path = Gdip.GraphicsPath_new(Gdip.FillModeAlternate); + if (path is null) DWT.error(DWT.ERROR_NO_HANDLES); + if (nw > naw) { + if (nh > nah) { + Gdip.GraphicsPath_AddArc(path, nx + nw - naw, ny, naw, nah, 0, -90); + Gdip.GraphicsPath_AddArc(path, nx, ny, naw, nah, -90, -90); + Gdip.GraphicsPath_AddArc(path, nx, ny + nh - nah, naw, nah, -180, -90); + Gdip.GraphicsPath_AddArc(path, nx + nw - naw, ny + nh - nah, naw, nah, -270, -90); + } else { + Gdip.GraphicsPath_AddArc(path, nx + nw - naw, ny, naw, nh, -270, -180); + Gdip.GraphicsPath_AddArc(path, nx, ny, naw, nh, -90, -180); + } } else { - Gdip.GraphicsPath_AddArc(path, nx + nw - naw, ny, naw, nh, -270, -180); - Gdip.GraphicsPath_AddArc(path, nx, ny, naw, nh, -90, -180); + if (nh > nah) { + Gdip.GraphicsPath_AddArc(path, nx, ny, nw, nah, 0, -180); + Gdip.GraphicsPath_AddArc(path, nx, ny + nh - nah, nw, nah, -180, -180); + } else { + Gdip.GraphicsPath_AddArc(path, nx, ny, nw, nh, 0, 360); + } } - } else { - if (nh > nah) { - Gdip.GraphicsPath_AddArc(path, nx, ny, nw, nah, 0, -180); - Gdip.GraphicsPath_AddArc(path, nx, ny + nh - nah, nw, nah, -180, -180); - } else { - Gdip.GraphicsPath_AddArc(path, nx, ny, nw, nh, 0, 360); - } + Gdip.GraphicsPath_CloseFigure(path); + Gdip.Graphics_DrawPath(gdipGraphics, pen, path); + Gdip.GraphicsPath_delete(path); } - Gdip.GraphicsPath_CloseFigure(path); - Gdip.Graphics_DrawPath(gdipGraphics, pen, path); - Gdip.GraphicsPath_delete(path); Gdip.Graphics_TranslateTransform(gdipGraphics, -data.gdipXOffset, -data.gdipYOffset, Gdip.MatrixOrderPrepend); } @@ -2316,7 +2334,7 @@ if ((data.style & DWT.MIRRORED) !is 0) formatFlags |= Gdip.StringFormatFlagsDirectionRightToLeft; Gdip.StringFormat_SetFormatFlags(format, formatFlags); float[] tabs = (flags & DWT.DRAW_TAB) !is 0 ? [ cast(float) measureSpace(data.gdipFont, format) * 8] : new float[1]; - Gdip.StringFormat_SetTabStops(format, 0, tabs.length, tabs); + Gdip.StringFormat_SetTabStops(format, 0, tabs.length, tabs.ptr); int hotkeyPrefix = (flags & DWT.DRAW_MNEMONIC) !is 0 ? Gdip.HotkeyPrefixShow : Gdip.HotkeyPrefixNone; if ((flags & DWT.DRAW_MNEMONIC) !is 0 && (data.uiState & OS.UISF_HIDEACCEL) !is 0) hotkeyPrefix = Gdip.HotkeyPrefixHide; Gdip.StringFormat_SetHotkeyPrefix(format, hotkeyPrefix); @@ -2768,7 +2786,7 @@ checkGC(FILL); if (data.gdipGraphics !is null) { int mode = OS.GetPolyFillMode(handle) is OS.WINDING ? Gdip.FillModeWinding : Gdip.FillModeAlternate; - Gdip.Graphics_FillPolygon(data.gdipGraphics, data.gdipBrush, cast(Gdip.Point[])pointArray, pointArray.length / 2, mode); + Gdip.Graphics_FillPolygon(data.gdipGraphics, data.gdipBrush, cast(Gdip.Point*)pointArray.ptr, pointArray.length / 2, mode); return; } if ((data.style & DWT.MIRRORED) !is 0) { @@ -2803,6 +2821,14 @@ if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); checkGC(FILL); if (data.gdipGraphics !is null) { + if (width < 0) { + x = x + width; + width = -width; + } + if (height < 0) { + y = y + height; + height = -height; + } Gdip.Graphics_FillRectangle(data.gdipGraphics, data.gdipBrush, x, y, width, height); return; } @@ -2886,29 +2912,33 @@ if (nah < 0) nah = 0 - nah; - auto path = Gdip.GraphicsPath_new(Gdip.FillModeAlternate); - if (path is null) DWT.error(DWT.ERROR_NO_HANDLES); - if (nw > naw) { - if (nh > nah) { - Gdip.GraphicsPath_AddArc(path, nx + nw - naw, ny, naw, nah, 0, -90); - Gdip.GraphicsPath_AddArc(path, nx, ny, naw, nah, -90, -90); - Gdip.GraphicsPath_AddArc(path, nx, ny + nh - nah, naw, nah, -180, -90); - Gdip.GraphicsPath_AddArc(path, nx + nw - naw, ny + nh - nah, naw, nah, -270, -90); + if (naw is 0 || nah is 0) { + Gdip.Graphics_FillRectangle(data.gdipGraphics, data.gdipBrush, x, y, width, height); + } else { + auto path = Gdip.GraphicsPath_new(Gdip.FillModeAlternate); + if (path is null) DWT.error(DWT.ERROR_NO_HANDLES); + if (nw > naw) { + if (nh > nah) { + Gdip.GraphicsPath_AddArc(path, nx + nw - naw, ny, naw, nah, 0, -90); + Gdip.GraphicsPath_AddArc(path, nx, ny, naw, nah, -90, -90); + Gdip.GraphicsPath_AddArc(path, nx, ny + nh - nah, naw, nah, -180, -90); + Gdip.GraphicsPath_AddArc(path, nx + nw - naw, ny + nh - nah, naw, nah, -270, -90); + } else { + Gdip.GraphicsPath_AddArc(path, nx + nw - naw, ny, naw, nh, -270, -180); + Gdip.GraphicsPath_AddArc(path, nx, ny, naw, nh, -90, -180); + } } else { - Gdip.GraphicsPath_AddArc(path, nx + nw - naw, ny, naw, nh, -270, -180); - Gdip.GraphicsPath_AddArc(path, nx, ny, naw, nh, -90, -180); + if (nh > nah) { + Gdip.GraphicsPath_AddArc(path, nx, ny, nw, nah, 0, -180); + Gdip.GraphicsPath_AddArc(path, nx, ny + nh - nah, nw, nah, -180, -180); + } else { + Gdip.GraphicsPath_AddArc(path, nx, ny, nw, nh, 0, 360); + } } - } else { - if (nh > nah) { - Gdip.GraphicsPath_AddArc(path, nx, ny, nw, nah, 0, -180); - Gdip.GraphicsPath_AddArc(path, nx, ny + nh - nah, nw, nah, -180, -180); - } else { - Gdip.GraphicsPath_AddArc(path, nx, ny, nw, nh, 0, 360); - } + Gdip.GraphicsPath_CloseFigure(path); + Gdip.Graphics_FillPath(gdipGraphics, brush, path); + Gdip.GraphicsPath_delete(path); } - Gdip.GraphicsPath_CloseFigure(path); - Gdip.Graphics_FillPath(gdipGraphics, brush, path); - Gdip.GraphicsPath_delete(path); } void flush () { @@ -3269,7 +3299,7 @@ */ public Font getFont () { if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); - return Font.win32_new(data.device, data.hFont); + return data.font; } /** @@ -3666,15 +3696,34 @@ Gdip.Matrix identity() { if ((data.style & DWT.MIRRORED) !is 0) { int width = 0; - Image image = data.image; - if (image !is null) { + int technology = OS.GetDeviceCaps(handle, OS.TECHNOLOGY); + if (technology is OS.DT_RASPRINTER) { + width = OS.GetDeviceCaps(handle, OS.PHYSICALWIDTH); + } else { + Image image = data.image; + if (image !is null) { BITMAP bm; OS.GetObject(image.handle, BITMAP.sizeof, &bm); - width = bm.bmWidth; - } else if (data.hwnd !is null) { - RECT rect; - OS.GetClientRect(data.hwnd, &rect); - width = rect.right - rect.left; + width = bm.bmWidth; + } else { + HWND hwnd; + static if( OS.IsWinCE ){ + hwnd = data.hwnd; + } + else{ + hwnd = OS.WindowFromDC(handle); + } + if (hwnd !is null) { + RECT rect; + OS.GetClientRect(hwnd, &rect); + width = rect.right - rect.left; + } else { + auto hBitmap = OS.GetCurrentObject(handle, OS.OBJ_BITMAP); + BITMAP bm; + OS.GetObject(hBitmap, BITMAP.sizeof, &bm); + width = bm.bmWidth; + } + } } POINT pt; static if (!OS.IsWinCE) OS.GetWindowOrgEx (handle, &pt); @@ -3697,11 +3746,11 @@ data.background = OS.GetBkColor(hDC); } data.state &= ~(NULL_BRUSH | NULL_PEN); - auto hFont = data.hFont; - if (hFont !is null && hFont !is cast(HFONT)-1 ) { + Font font = data.font; + if (font !is null) { data.state &= ~FONT; } else { - data.hFont = OS.GetCurrentObject(hDC, OS.OBJ_FONT); + data.font = Font.win32_new(device, OS.GetCurrentObject(hDC, OS.OBJ_FONT)); } auto hPalette = data.device.hPalette; if (hPalette !is null) { @@ -3763,8 +3812,16 @@ */ public bool isClipped() { if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); + auto gdipGraphics = data.gdipGraphics; + if (gdipGraphics !is null) { + auto rgn = Gdip.Region_new(); + Gdip.Graphics_GetClip(data.gdipGraphics, rgn); + bool isInfinite = Gdip.Region_IsInfinite(rgn, gdipGraphics) !is 0; + Gdip.Region_delete(rgn); + return !isInfinite; + } auto region = OS.CreateRectRgn(0, 0, 0, 0); - auto result = OS.GetClipRgn(handle, region); + int result = OS.GetClipRgn(handle, region); OS.DeleteObject(region); return result > 0; } @@ -4068,7 +4125,7 @@ initGdip(); int mode = OS.GetPolyFillMode(handle) is OS.WINDING ? Gdip.FillModeWinding : Gdip.FillModeAlternate; Gdip.GraphicsPath_SetFillMode(path.handle, mode); - Gdip.Graphics_SetClip(data.gdipGraphics, path.handle); + Gdip.Graphics_SetClipPath(data.gdipGraphics, path.handle); } } @@ -4163,7 +4220,7 @@ public void setFont (Font font) { if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); if (font !is null && font.isDisposed()) DWT.error(DWT.ERROR_INVALID_ARGUMENT); - data.hFont = font !is null ? font.handle : data.device.systemFont; + data.font = font !is null ? font : data.device.systemFont; data.state &= ~FONT; } @@ -4327,7 +4384,7 @@ DWT.error(DWT.ERROR_INVALID_ARGUMENT); } } - int cap = attributes.join; + int cap = attributes.cap; if (cap !is data.lineCap) { mask |= LINE_CAP; switch (cap) { @@ -4800,7 +4857,7 @@ if ((data.style & DWT.MIRRORED) !is 0) formatFlags |= Gdip.StringFormatFlagsDirectionRightToLeft; Gdip.StringFormat_SetFormatFlags(format, formatFlags); float[] tabs = (flags & DWT.DRAW_TAB) !is 0 ? [measureSpace(data.gdipFont, format) * 8] : new float[1]; - Gdip.StringFormat_SetTabStops(format, 0, tabs.length, tabs); + Gdip.StringFormat_SetTabStops(format, 0, tabs.length, tabs.ptr); Gdip.StringFormat_SetHotkeyPrefix(format, (flags & DWT.DRAW_MNEMONIC) !is 0 ? Gdip.HotkeyPrefixShow : Gdip.HotkeyPrefixNone); Gdip.Graphics_MeasureString(data.gdipGraphics, buffer, length_, data.gdipFont, pt, format, bounds); Gdip.StringFormat_delete(format); @@ -4876,6 +4933,13 @@ public static GC win32_new(HDC hDC, GCData data) { GC gc = new GC(); gc.device = data.device; + data.style |= DWT.LEFT_TO_RIGHT; + if (OS.WIN32_VERSION >= OS.VERSION (4, 10)) { + int flags = OS.GetLayout (hDC); + if ((flags & OS.LAYOUT_RTL) !is 0) { + data.style |= DWT.RIGHT_TO_LEFT | DWT.MIRRORED; + } + } gc.init_(null, data, hDC); return gc; }