Mercurial > projects > dwt-win
diff dwt/widgets/Table.d @ 246:fd9c62a2998e
Updater SWT 3.4M7 to 3.4
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Tue, 01 Jul 2008 10:15:59 +0200 |
parents | ecb80b2a89e1 |
children | b3dbd786541a |
line wrap: on
line diff
--- a/dwt/widgets/Table.d Tue Jul 01 08:58:50 2008 +0200 +++ b/dwt/widgets/Table.d Tue Jul 01 10:15:59 2008 +0200 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2007 IBM Corporation and others. + * Copyright (c) 2000, 2008 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 @@ -23,6 +23,7 @@ import dwt.graphics.Point; import dwt.graphics.Rectangle; import dwt.internal.ImageList; +import dwt.internal.win32.BITMAPINFOHEADER; import dwt.internal.win32.OS; import dwt.widgets.Composite; @@ -82,6 +83,10 @@ * </p><p> * IMPORTANT: This class is <em>not</em> intended to be subclassed. * </p> + * + * @see <a href="http://www.eclipse.org/swt/snippets/#table">Table, TableItem, TableColumn snippets</a> + * @see <a href="http://www.eclipse.org/swt/examples.php">DWT Example: ControlExample</a> + * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> */ public class Table : Composite { @@ -112,8 +117,9 @@ static const int HEADER_EXTRA = 3; static const int VISTA_EXTRA = 2; static const int EXPLORER_EXTRA = 2; - static final int H_SCROLL_LIMIT = 32; - static final int V_SCROLL_LIMIT = 16; + static const int H_SCROLL_LIMIT = 32; + static const int V_SCROLL_LIMIT = 16; + static const int DRAG_IMAGE_SIZE = 301; static const bool EXPLORER_THEME = true; private static /+const+/ WNDPROC TableProc; static const TCHAR[] TableClass = OS.WC_LISTVIEW; @@ -5427,16 +5433,89 @@ } if (msg is Display.DI_GETDRAGIMAGE) { /* - * Bug in Windows. For some reason, DI_GETDRAGIMAGE + * Bug in Windows. On Vista, for some reason, DI_GETDRAGIMAGE * returns an image that does not contain strings. - * The fix is to disable the table window proc. * - * NOTE: This only happens on Vista. + * Bug in Windows. For custom draw control the window origin the + * in HDC is wrong. + * + * The fix for both cases is to create the image using PrintWindow(). */ - if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 0)) return 0; - //TEMPORARY CODE - if (hooks (DWT.EraseItem) || hooks (DWT.PaintItem)) return 0; -// if (getSelectionCount () !is 1) return 0; + if ((!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 0)) || hooks (DWT.EraseItem) || hooks (DWT.PaintItem)) { + int topIndex = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETTOPINDEX, 0, 0); + int selection = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETNEXTITEM, topIndex - 1, OS.LVNI_SELECTED); + if (selection is -1) return 0; + POINT mousePos = new POINT (); + OS.POINTSTOPOINT (mousePos, OS.GetMessagePos ()); + OS.MapWindowPoints(0, handle, mousePos, 1); + RECT clientRect = new RECT (); + OS.GetClientRect (handle, clientRect); + TableItem item = _getItem (selection); + RECT rect = item.getBounds (selection, 0, true, true, true); + if ((style & DWT.FULL_SELECTION) !is 0) { + int width = DRAG_IMAGE_SIZE; + rect.left = Math.max (clientRect.left, mousePos.x - width / 2); + if (clientRect.right > rect.left + width) { + rect.right = rect.left + width; + } else { + rect.right = clientRect.right; + rect.left = Math.max (clientRect.left, rect.right - width); + } + } + int /*long*/ hRgn = OS.CreateRectRgn (rect.left, rect.top, rect.right, rect.bottom); + while ((selection = (int)/*64*/OS.SendMessage (handle, OS.LVM_GETNEXTITEM, selection, OS.LVNI_SELECTED)) !is -1) { + if (rect.bottom - rect.top > DRAG_IMAGE_SIZE) break; + if (rect.bottom > clientRect.bottom) break; + RECT itemRect = item.getBounds (selection, 0, true, true, true); + int /*long*/ rectRgn = OS.CreateRectRgn (rect.left, itemRect.top, rect.right, itemRect.bottom); + OS.CombineRgn (hRgn, hRgn, rectRgn, OS.RGN_OR); + OS.DeleteObject (rectRgn); + rect.bottom = itemRect.bottom; + } + OS.GetRgnBox (hRgn, rect); + + /* Create resources */ + int /*long*/ hdc = OS.GetDC (handle); + int /*long*/ memHdc = OS.CreateCompatibleDC (hdc); + BITMAPINFOHEADER bmiHeader = new BITMAPINFOHEADER (); + bmiHeader.biSize = BITMAPINFOHEADER.sizeof; + bmiHeader.biWidth = rect.right - rect.left; + bmiHeader.biHeight = -(rect.bottom - rect.top); + bmiHeader.biPlanes = 1; + bmiHeader.biBitCount = 32; + bmiHeader.biCompression = OS.BI_RGB; + byte [] bmi = new byte [BITMAPINFOHEADER.sizeof]; + OS.MoveMemory (bmi, bmiHeader, BITMAPINFOHEADER.sizeof); + int /*long*/ [] pBits = new int /*long*/ [1]; + int /*long*/ memDib = OS.CreateDIBSection (0, bmi, OS.DIB_RGB_COLORS, pBits, 0, 0); + if (memDib is 0) DWT.error (DWT.ERROR_NO_HANDLES); + int /*long*/ oldMemBitmap = OS.SelectObject (memHdc, memDib); + int colorKey = 0x0000FD; + POINT pt = new POINT(); + OS.SetWindowOrgEx (memHdc, rect.left, rect.top, pt); + OS.FillRect (memHdc, rect, findBrush (colorKey, OS.BS_SOLID)); + OS.OffsetRgn (hRgn, -rect.left, -rect.top); + OS.SelectClipRgn (memHdc, hRgn); + OS.PrintWindow (handle, memHdc, 0); + OS.SetWindowOrgEx (memHdc, pt.x, pt.y, null); + OS.SelectObject (memHdc, oldMemBitmap); + OS.DeleteDC (memHdc); + OS.ReleaseDC (0, hdc); + OS.DeleteObject (hRgn); + + SHDRAGIMAGE shdi = new SHDRAGIMAGE (); + shdi.hbmpDragImage = memDib; + shdi.crColorKey = colorKey; + shdi.sizeDragImage.cx = bmiHeader.biWidth; + shdi.sizeDragImage.cy = -bmiHeader.biHeight; + shdi.ptOffset.x = mousePos.x - rect.left; + shdi.ptOffset.y = mousePos.y - rect.top; + if ((style & DWT.MIRRORED) !is 0) { + shdi.ptOffset.x = shdi.sizeDragImage.cx - shdi.ptOffset.x; + } + OS.MoveMemory (lParam, shdi, SHDRAGIMAGE.sizeof); + return 1; + } } return super.windowProc (hwnd, msg, wParam, lParam); }