comparison dwt/dnd/TreeDragSourceEffect.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.TreeDragSourceEffect; 13 module dwt.dnd.TreeDragSourceEffect;
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.Tree; 22 import dwt.widgets.Tree;
21 import dwt.widgets.TreeItem; 23 import dwt.widgets.TreeItem;
84 } 86 }
85 87
86 Image getDragSourceImage(DragSourceEvent event) { 88 Image getDragSourceImage(DragSourceEvent event) {
87 if (dragSourceImage !is null) dragSourceImage.dispose(); 89 if (dragSourceImage !is null) dragSourceImage.dispose();
88 dragSourceImage = null; 90 dragSourceImage = null;
91 if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (5, 1)) {
92 SHDRAGIMAGE shdi;
93 int DI_GETDRAGIMAGE = OS.RegisterWindowMessage ("ShellGetDragImage"w.ptr); //$NON-NLS-1$
94 if (OS.SendMessage (control.handle, DI_GETDRAGIMAGE, 0, &shdi) !is 0) {
95 event.x += shdi.ptOffset.x;
96 event.y += shdi.ptOffset.y;
97 auto hImage = shdi.hbmpDragImage;
98 if (hImage !is null) {
99 BITMAP bm;
100 OS.GetObject (hImage, BITMAP.sizeof, &bm);
101 int srcWidth = bm.bmWidth;
102 int srcHeight = bm.bmHeight;
103
104 /* Create resources */
105 auto hdc = OS.GetDC (null);
106 auto srcHdc = OS.CreateCompatibleDC (hdc);
107 auto oldSrcBitmap = OS.SelectObject (srcHdc, hImage);
108 auto memHdc = OS.CreateCompatibleDC (hdc);
109 BITMAPINFOHEADER bmiHeader;
110 bmiHeader.biSize = BITMAPINFOHEADER.sizeof;
111 bmiHeader.biWidth = srcWidth;
112 bmiHeader.biHeight = -srcHeight;
113 bmiHeader.biPlanes = 1;
114 bmiHeader.biBitCount = 32;
115 bmiHeader.biCompression = OS.BI_RGB;
116 void* pBits;
117 auto memDib = OS.CreateDIBSection (null, cast(BITMAPINFO*)&bmiHeader, OS.DIB_RGB_COLORS, &pBits, null, 0);
118 if (memDib is null) DWT.error (DWT.ERROR_NO_HANDLES);
119 auto oldMemBitmap = OS.SelectObject (memHdc, memDib);
120
121 BITMAP dibBM;
122 OS.GetObject (memDib, BITMAP.sizeof, &dibBM);
123 int sizeInBytes = dibBM.bmWidthBytes * dibBM.bmHeight;
124
125 /* Get the foreground pixels */
126 OS.BitBlt (memHdc, 0, 0, srcWidth, srcHeight, srcHdc, 0, 0, OS.SRCCOPY);
127 byte[] srcData = (cast(byte*)dibBM.bmBits)[ 0 .. sizeInBytes ];
128
129 PaletteData palette = new PaletteData(0xFF00, 0xFF0000, 0xFF000000);
130 ImageData data = new ImageData(srcWidth, srcHeight, bm.bmBitsPixel, palette, bm.bmWidthBytes, srcData);
131 data.transparentPixel = shdi.crColorKey << 8;
132 dragSourceImage = new Image (control.getDisplay (), data);
133 OS.SelectObject (memHdc, oldMemBitmap);
134 OS.DeleteDC (memHdc);
135 OS.DeleteObject (memDib);
136 OS.SelectObject (srcHdc, oldSrcBitmap);
137 OS.DeleteDC (srcHdc);
138 OS.ReleaseDC (null, hdc);
139 return dragSourceImage;
140 }
141 }
142 return null;
143 }
144
89 Tree tree = cast(Tree) control; 145 Tree tree = cast(Tree) control;
146 //TEMPORARY CODE
147 if (tree.isListening (DWT.EraseItem) || tree.isListening (DWT.PaintItem)) return null;
90 TreeItem[] selection = tree.getSelection(); 148 TreeItem[] selection = tree.getSelection();
91 if (selection.length is 0) return null; 149 if (selection.length is 0) return null;
92 int treeImageList = OS.SendMessage (tree.handle, OS.TVM_GETIMAGELIST, OS.TVSIL_NORMAL, 0); 150 auto treeImageList = OS.SendMessage (tree.handle, OS.TVM_GETIMAGELIST, OS.TVSIL_NORMAL, 0);
93 if (treeImageList !is 0) { 151 if (treeImageList !is 0) {
94 int count = Math.min(selection.length, 10); 152 int count = Math.min(selection.length, 10);
95 Rectangle bounds = selection[0].getBounds(0); 153 Rectangle bounds = selection[0].getBounds(0);
96 for (int i = 1; i < count; i++) { 154 for (int i = 1; i < count; i++) {
97 bounds = bounds.makeUnion(selection[i].getBounds(0)); 155 bounds = bounds.makeUnion(selection[i].getBounds(0));