diff options
author | Silenio Quarti <silenio> | 2007-05-15 20:39:40 +0000 |
---|---|---|
committer | Silenio Quarti <silenio> | 2007-05-15 20:39:40 +0000 |
commit | 37ab1e4e2102278481686b7e60e6dfb0a4bf0c90 (patch) | |
tree | 17b103c8570ee485b680e9b3589d812aed200c0d | |
parent | 6bd6730e32669fbb2a0c33215b3d8035dce857ef (diff) | |
download | eclipse.platform.swt-37ab1e4e2102278481686b7e60e6dfb0a4bf0c90.tar.gz eclipse.platform.swt-37ab1e4e2102278481686b7e60e6dfb0a4bf0c90.tar.xz eclipse.platform.swt-37ab1e4e2102278481686b7e60e6dfb0a4bf0c90.zip |
173549 - Drawing round rectangles, DND and antialias vows
-rwxr-xr-x | bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/win32/org/eclipse/swt/dnd/DragSource.java | 101 | ||||
-rw-r--r--[-rwxr-xr-x] | bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/ImageList.java (renamed from bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ImageList.java) | 43 | ||||
-rwxr-xr-x | bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Button.java | 1 | ||||
-rwxr-xr-x | bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Menu.java | 1 | ||||
-rwxr-xr-x | bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TabFolder.java | 1 | ||||
-rwxr-xr-x | bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Table.java | 1 | ||||
-rwxr-xr-x | bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ToolBar.java | 1 | ||||
-rwxr-xr-x | bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ToolItem.java | 1 |
8 files changed, 66 insertions, 84 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/win32/org/eclipse/swt/dnd/DragSource.java b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/win32/org/eclipse/swt/dnd/DragSource.java index 0f5ba269c1..3d5ba116eb 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/win32/org/eclipse/swt/dnd/DragSource.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/win32/org/eclipse/swt/dnd/DragSource.java @@ -14,6 +14,7 @@ package org.eclipse.swt.dnd; import org.eclipse.swt.*; import org.eclipse.swt.graphics.*; import org.eclipse.swt.widgets.*; +import org.eclipse.swt.internal.*; import org.eclipse.swt.internal.ole.win32.*; import org.eclipse.swt.internal.win32.*; @@ -294,37 +295,35 @@ private void drag(Event dragEvent) { String key = "org.eclipse.swt.internal.win32.runMessagesInIdle"; //$NON-NLS-1$ Object oldValue = display.getData(key); display.setData(key, new Boolean(true)); - int imagelist = 0; + ImageList imagelist = null; Image image = event.image; if (image != null) { - imagelist = createImageList(image); - if (imagelist != 0) { - topControl = control.getShell(); - OS.ImageList_BeginDrag(imagelist, 0, 0, 0); - Point location = topControl.getLocation(); - /* - * Feature in Windows. When ImageList_DragEnter() is called, - * it takes a snapshot of the screen If a drag is started - * when another window is in front, then the snapshot will - * contain part of the other window, causing pixel corruption. - * The fix is to force all paints to be delivered before - * calling ImageList_DragEnter(). - */ - if (OS.IsWinCE) { - OS.UpdateWindow (topControl.handle); - } else { - int flags = OS.RDW_UPDATENOW | OS.RDW_ALLCHILDREN; - OS.RedrawWindow (topControl.handle, null, 0, flags); - } - OS.ImageList_DragEnter(topControl.handle, dragEvent.x - location.x, dragEvent.y - location.y); + imagelist = new ImageList(SWT.NONE); + imagelist.add(image); + topControl = control.getShell(); + OS.ImageList_BeginDrag(imagelist.getHandle(), 0, 0, 0); + Point location = topControl.getLocation(); + /* + * Feature in Windows. When ImageList_DragEnter() is called, + * it takes a snapshot of the screen If a drag is started + * when another window is in front, then the snapshot will + * contain part of the other window, causing pixel corruption. + * The fix is to force all paints to be delivered before + * calling ImageList_DragEnter(). + */ + if (OS.IsWinCE) { + OS.UpdateWindow (topControl.handle); + } else { + int flags = OS.RDW_UPDATENOW | OS.RDW_ALLCHILDREN; + OS.RedrawWindow (topControl.handle, null, 0, flags); } + OS.ImageList_DragEnter(topControl.handle, dragEvent.x - location.x, dragEvent.y - location.y); } int result = COM.DoDragDrop(iDataObject.getAddress(), iDropSource.getAddress(), operations, pdwEffect); - if (imagelist != 0) { + if (imagelist != null) { OS.ImageList_DragLeave(topControl.handle); OS.ImageList_EndDrag(); - OS.ImageList_Destroy(imagelist); - imagelist = 0; + imagelist.dispose(); topControl = null; } display.setData(key, oldValue); @@ -344,60 +343,6 @@ private void drag(Event dragEvent) { notifyListeners(DND.DragEnd,event); dataEffect = DND.DROP_NONE; } -int createImageList(Image image) { - int flags = OS.ILC_MASK; - if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ()) { - flags |= OS.ILC_COLOR32; - } else { - int hDC = OS.GetDC (0); - int bits = OS.GetDeviceCaps (hDC, OS.BITSPIXEL); - int planes = OS.GetDeviceCaps (hDC, OS.PLANES); - OS.ReleaseDC (0, hDC); - int depth = bits * planes; - switch (depth) { - case 4: flags |= OS.ILC_COLOR4; break; - case 8: flags |= OS.ILC_COLOR8; break; - case 16: flags |= OS.ILC_COLOR16; break; - case 24: flags |= OS.ILC_COLOR24; break; - case 32: flags |= OS.ILC_COLOR32; break; - default: flags |= OS.ILC_COLOR; break; - } - } - if ((control.getStyle() & SWT.RIGHT_TO_LEFT) != 0) flags |= OS.ILC_MIRROR; - Rectangle bounds = image.getBounds(); - int cx = bounds.width, cy = bounds.height; - int imageList = OS.ImageList_Create(cx, cy, flags, 0, 1); - int hImage = image.handle; - switch (image.type) { - case SWT.BITMAP: { - int background = control.getBackground().handle; - OS.ImageList_AddMasked(imageList, hImage, background); - break; - } - case SWT.ICON: { - int hDC = OS.GetDC(0); - int bitmap = OS.CreateCompatibleBitmap(hDC, cx, cy); - int hDC1 = OS.CreateCompatibleDC(hDC); - int hOldBitmap = OS.SelectObject(hDC1, bitmap); - int hIcon = OS.CopyImage(image.handle, OS.IMAGE_ICON, cx, cy, 0); - OS.DrawIconEx(hDC1, 0, 0, hIcon, 0, 0, 0, 0, OS.DI_NORMAL); - OS.DestroyIcon(hIcon); - OS.SelectObject(hDC1, hOldBitmap); - ImageData imageData = image.getImageData(); - int background = imageData.transparentPixel; - OS.ImageList_AddMasked(imageList, bitmap, background); - OS.DeleteObject(bitmap); - OS.DeleteDC (hDC1); - OS.ReleaseDC (0, hDC); - break; - } - default: { - OS.ImageList_Destroy(imageList); - imageList = 0; - } - } - return imageList; -} /* * EnumFormatEtc([in] dwDirection, [out] ppenumFormatetc) * Ownership of ppenumFormatetc transfers from callee to caller so reference count on ppenumFormatetc diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ImageList.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/ImageList.java index 6ae36e796d..dfb0c24785 100755..100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ImageList.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/ImageList.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. + * Copyright (c) 2000, 2007 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -8,14 +8,14 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.swt.widgets; +package org.eclipse.swt.internal; import org.eclipse.swt.internal.win32.*; import org.eclipse.swt.*; import org.eclipse.swt.graphics.*; -class ImageList { +public class ImageList { int handle, style, refCount; Image [] images; @@ -72,7 +72,7 @@ public int add (Image image) { return index; } -int addRef() { +public int addRef() { return ++refCount; } @@ -243,6 +243,37 @@ int copyWithAlpha (int hBitmap, int background, byte[] alphaData, int destWidth, return memDib; } +int createMaskFromAlpha (ImageData data, int destWidth, int destHeight) { + int srcWidth = data.width; + int srcHeight = data.height; + ImageData mask = ImageData.internal_new (srcWidth, srcHeight, 1, + new PaletteData(new RGB [] {new RGB (0, 0, 0), new RGB (0xff, 0xff, 0xff)}), + 2, null, 1, null, null, -1, -1, -1, 0, 0, 0, 0); + int ap = 0; + for (int y = 0; y < mask.height; y++) { + for (int x = 0; x < mask.width; x++) { + mask.setPixel (x, y, (data.alphaData [ap++] & 0xff) <= 127 ? 1 : 0); + } + } + int hMask = OS.CreateBitmap (srcWidth, srcHeight, 1, 1, mask.data); + if (srcWidth != destWidth || srcHeight != destHeight) { + int hdc = OS.GetDC (0); + int hdc1 = OS.CreateCompatibleDC (hdc); + OS.SelectObject (hdc1, hMask); + int hdc2 = OS.CreateCompatibleDC (hdc); + int hMask2 = OS.CreateBitmap (destWidth, destHeight, 1, 1, null); + OS.SelectObject (hdc2, hMask2); + if (!OS.IsWinCE) OS.SetStretchBltMode(hdc2, OS.COLORONCOLOR); + OS.StretchBlt (hdc2, 0, 0, destWidth, destHeight, hdc1, 0, 0, srcWidth, srcHeight, OS.SRCCOPY); + OS.DeleteDC (hdc1); + OS.DeleteDC (hdc2); + OS.ReleaseDC (0, hdc); + OS.DeleteObject(hMask); + hMask = hMask2; + } + return hMask; +} + int createMask (int hBitmap, int destWidth, int destHeight, int background, int transparentPixel) { BITMAP bm = new BITMAP (); OS.GetObject (hBitmap, BITMAP.sizeof, bm); @@ -352,7 +383,7 @@ public void remove (int index) { images [index] = null; } -int removeRef() { +public int removeRef() { return --refCount; } @@ -373,7 +404,7 @@ void set (int index, Image image, int count) { hBitmap = copyWithAlpha (hImage, -1, data.alphaData, cx [0], cy [0]); } else { hBitmap = copyBitmap (hImage, cx [0], cy [0]); - hMask = Display.createMaskFromAlpha (data, cx [0], cy [0]); + hMask = createMaskFromAlpha (data, cx [0], cy [0]); } break; case SWT.TRANSPARENCY_PIXEL: diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Button.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Button.java index 50a86a1e7f..e514a5bd88 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Button.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Button.java @@ -11,6 +11,7 @@ package org.eclipse.swt.widgets; +import org.eclipse.swt.internal.*; import org.eclipse.swt.internal.win32.*; import org.eclipse.swt.*; import org.eclipse.swt.graphics.*; diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Menu.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Menu.java index 2fd275f6e9..28d25c6c31 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Menu.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Menu.java @@ -11,6 +11,7 @@ package org.eclipse.swt.widgets; +import org.eclipse.swt.internal.*; import org.eclipse.swt.internal.win32.*; import org.eclipse.swt.*; import org.eclipse.swt.graphics.*; diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TabFolder.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TabFolder.java index 8659802c17..2681597955 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TabFolder.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TabFolder.java @@ -11,6 +11,7 @@ package org.eclipse.swt.widgets; +import org.eclipse.swt.internal.*; import org.eclipse.swt.internal.win32.*; import org.eclipse.swt.*; import org.eclipse.swt.graphics.*; diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Table.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Table.java index 9d5e997c3d..3760922549 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Table.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Table.java @@ -13,6 +13,7 @@ package org.eclipse.swt.widgets; //import java.util.*; +import org.eclipse.swt.internal.*; import org.eclipse.swt.internal.win32.*; import org.eclipse.swt.*; import org.eclipse.swt.graphics.*; diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ToolBar.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ToolBar.java index 4c3e81b320..0dee4126e6 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ToolBar.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ToolBar.java @@ -11,6 +11,7 @@ package org.eclipse.swt.widgets; +import org.eclipse.swt.internal.*; import org.eclipse.swt.internal.win32.*; import org.eclipse.swt.*; import org.eclipse.swt.graphics.*; diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ToolItem.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ToolItem.java index 9e954420c5..03a2fd2f08 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ToolItem.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ToolItem.java @@ -11,6 +11,7 @@ package org.eclipse.swt.widgets; +import org.eclipse.swt.internal.*; import org.eclipse.swt.internal.win32.*; import org.eclipse.swt.*; import org.eclipse.swt.graphics.*; |