Mercurial > projects > dwt-win
comparison dwt/dnd/TableDragSourceEffect.d @ 213:36f5cb12e1a2
Update to SWT 3.4M7
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sat, 17 May 2008 17:34:28 +0200 |
parents | 3afcd4ddcf90 |
children | fd9c62a2998e |
comparison
equal
deleted
inserted
replaced
212:ab60f3309436 | 213:36f5cb12e1a2 |
---|---|
12 *******************************************************************************/ | 12 *******************************************************************************/ |
13 module dwt.dnd.TableDragSourceEffect; | 13 module dwt.dnd.TableDragSourceEffect; |
14 | 14 |
15 import dwt.DWT; | 15 import dwt.DWT; |
16 import dwt.graphics.Image; | 16 import dwt.graphics.Image; |
17 import dwt.graphics.ImageData; | |
18 import dwt.graphics.PaletteData; | |
17 import dwt.graphics.Rectangle; | 19 import dwt.graphics.Rectangle; |
18 import dwt.internal.win32.OS; | 20 import dwt.internal.win32.OS; |
19 import dwt.widgets.Display; | 21 import dwt.widgets.Display; |
20 import dwt.widgets.Table; | 22 import dwt.widgets.Table; |
21 import dwt.widgets.TableItem; | 23 import dwt.widgets.TableItem; |
85 } | 87 } |
86 | 88 |
87 Image getDragSourceImage(DragSourceEvent event) { | 89 Image getDragSourceImage(DragSourceEvent event) { |
88 if (dragSourceImage !is null) dragSourceImage.dispose(); | 90 if (dragSourceImage !is null) dragSourceImage.dispose(); |
89 dragSourceImage = null; | 91 dragSourceImage = null; |
92 if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (5, 1)) { | |
93 SHDRAGIMAGE shdi; | |
94 int DI_GETDRAGIMAGE = OS.RegisterWindowMessage ( "ShellGetDragImage"w.ptr ); //$NON-NLS-1$ | |
95 if (OS.SendMessage (control.handle, DI_GETDRAGIMAGE, 0, &shdi) !is 0) { | |
96 event.x += shdi.ptOffset.x; | |
97 event.y += shdi.ptOffset.y; | |
98 auto hImage = shdi.hbmpDragImage; | |
99 if (hImage !is null) { | |
100 BITMAP bm; | |
101 OS.GetObject (hImage, BITMAP.sizeof, &bm); | |
102 int srcWidth = bm.bmWidth; | |
103 int srcHeight = bm.bmHeight; | |
104 | |
105 /* Create resources */ | |
106 auto hdc = OS.GetDC (null); | |
107 auto srcHdc = OS.CreateCompatibleDC (hdc); | |
108 auto oldSrcBitmap = OS.SelectObject (srcHdc, hImage); | |
109 auto memHdc = OS.CreateCompatibleDC (hdc); | |
110 BITMAPINFOHEADER bmiHeader; | |
111 bmiHeader.biSize = BITMAPINFOHEADER.sizeof; | |
112 bmiHeader.biWidth = srcWidth; | |
113 bmiHeader.biHeight = -srcHeight; | |
114 bmiHeader.biPlanes = 1; | |
115 bmiHeader.biBitCount = 32; | |
116 bmiHeader.biCompression = OS.BI_RGB; | |
117 void* pBits; | |
118 auto memDib = OS.CreateDIBSection (null, cast(BITMAPINFO*)&bmiHeader, OS.DIB_RGB_COLORS, &pBits, null, 0); | |
119 if (memDib is null) DWT.error (DWT.ERROR_NO_HANDLES); | |
120 auto oldMemBitmap = OS.SelectObject (memHdc, memDib); | |
121 | |
122 BITMAP dibBM; | |
123 OS.GetObject (memDib, BITMAP.sizeof, &dibBM); | |
124 int sizeInBytes = dibBM.bmWidthBytes * dibBM.bmHeight; | |
125 | |
126 /* Get the foreground pixels */ | |
127 OS.BitBlt (memHdc, 0, 0, srcWidth, srcHeight, srcHdc, 0, 0, OS.SRCCOPY); | |
128 //byte[] srcData = new byte [sizeInBytes]; | |
129 //OS.MoveMemory (srcData, dibBM.bmBits, sizeInBytes); | |
130 byte[] srcData = (cast(byte*) dibBM.bmBits)[ 0 .. BITMAPINFOHEADER.sizeof ]; | |
131 | |
132 byte[] alphaData = new byte[srcWidth * srcHeight]; | |
133 int spinc = dibBM.bmWidthBytes - srcWidth * 4; | |
134 int ap = 0, sp = 3; | |
135 for (int y = 0; y < srcHeight; ++y) { | |
136 for (int x = 0; x < srcWidth; ++x) { | |
137 alphaData [ap++] = srcData [sp]; | |
138 sp += 4; | |
139 } | |
140 sp += spinc; | |
141 } | |
142 PaletteData palette = new PaletteData(0xFF00, 0xFF0000, 0xFF000000); | |
143 ImageData data = new ImageData(srcWidth, srcHeight, bm.bmBitsPixel, palette, bm.bmWidthBytes, srcData); | |
144 data.alphaData = alphaData; | |
145 data.transparentPixel = shdi.crColorKey; | |
146 dragSourceImage = new Image(control.getDisplay(), data); | |
147 OS.SelectObject (memHdc, oldMemBitmap); | |
148 OS.DeleteDC (memHdc); | |
149 OS.DeleteObject (memDib); | |
150 OS.SelectObject (srcHdc, oldSrcBitmap); | |
151 OS.DeleteDC (srcHdc); | |
152 OS.ReleaseDC (null, hdc); | |
153 return dragSourceImage; | |
154 } | |
155 } | |
156 return null; | |
157 } | |
90 Table table = cast(Table) control; | 158 Table table = cast(Table) control; |
159 //TEMPORARY CODE | |
160 if (table.isListening (DWT.EraseItem) || table.isListening (DWT.PaintItem)) return null; | |
91 TableItem[] selection = table.getSelection(); | 161 TableItem[] selection = table.getSelection(); |
92 if (selection.length is 0) return null; | 162 if (selection.length is 0) return null; |
93 int tableImageList = OS.SendMessage (table.handle, OS.LVM_GETIMAGELIST, OS.LVSIL_SMALL, 0); | 163 int /*long*/ tableImageList = OS.SendMessage (table.handle, OS.LVM_GETIMAGELIST, OS.LVSIL_SMALL, 0); |
94 if (tableImageList !is 0) { | 164 if (tableImageList !is 0) { |
95 int count = Math.min(selection.length, 10); | 165 int count = Math.min(selection.length, 10); |
96 Rectangle bounds = selection[0].getBounds(0); | 166 Rectangle bounds = selection[0].getBounds(0); |
97 for (int i = 1; i < count; i++) { | 167 for (int i = 1; i < count; i++) { |
98 bounds = bounds.makeUnion(selection[i].getBounds(0)); | 168 bounds = bounds.makeUnion(selection[i].getBounds(0)); |