Changeset 49:8b6ed0169471
- Timestamp:
- 02/02/08 20:29:42
(1 year ago)
- Author:
- Frank Benoit <benoit@tionex.de>
- branch:
- default
- Message:
ExpandItem?
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r47 |
r49 |
|
| 27 | 27 | DateTime |
|---|
| 28 | 28 | DirectoryDialog |
|---|
| | 29 | FileDialog |
|---|
| | 30 | FontDialog |
|---|
| 29 | 31 | |
|---|
| 30 | 32 | |
|---|
| 31 | 33 | |
|---|
| 32 | 34 | |
|---|
| | 35 | |
|---|
| r47 |
r49 |
|
| 4256 | 4256 | alias WINAPI.GetMessageTime GetMessageTime; |
|---|
| 4257 | 4257 | alias STDWIN.GetMetaRgn GetMetaRgn; |
|---|
| | 4258 | alias WINAPI.GetThemeTextExtent GetThemeTextExtent; |
|---|
| 4258 | 4259 | alias WINAPI.GetMessageW GetMessageW; |
|---|
| 4259 | 4260 | alias WINAPI.GetModuleFileNameA GetModuleFileNameA; |
|---|
| r38 |
r49 |
|
| 136 | 136 | WORD PRIMARYLANGID( |
|---|
| 137 | 137 | WORD lgid |
|---|
| | 138 | ); |
|---|
| | 139 | |
|---|
| | 140 | HRESULT GetThemeTextExtent( |
|---|
| | 141 | HTHEME hTheme, |
|---|
| | 142 | HDC hdc, |
|---|
| | 143 | int iPartId, |
|---|
| | 144 | int iStateId, |
|---|
| | 145 | LPCWSTR pszText, |
|---|
| | 146 | int iCharCount, |
|---|
| | 147 | DWORD dwTextFlags, |
|---|
| | 148 | LPCRECT pBoundingRect, |
|---|
| | 149 | LPRECT pExtentRect |
|---|
| 138 | 150 | ); |
|---|
| 139 | 151 | } |
|---|
| r47 |
r49 |
|
| 22 | 22 | import dwt.widgets.ExpandBar; |
|---|
| 23 | 23 | import dwt.widgets.Item; |
|---|
| 24 | | class ExpandItem : Item { |
|---|
| 25 | | public this (Widget parent, int style) { |
|---|
| 26 | | super (parent, style); |
|---|
| 27 | | } |
|---|
| 28 | | void redraw(bool); |
|---|
| 29 | | override void releaseWidget(); |
|---|
| 30 | | override void destroyWidget(); |
|---|
| 31 | | override void releaseHandle(); |
|---|
| 32 | | bool getExpanded(); |
|---|
| 33 | | void setControl(Control); |
|---|
| 34 | | void drawItem(GC, HTHEME, RECT*, bool); |
|---|
| 35 | | bool isHover(int, int); |
|---|
| 36 | | void setExpanded(bool); |
|---|
| 37 | | ExpandBar getParent(); |
|---|
| 38 | | void setBounds(int, int, int, int, bool, bool); |
|---|
| 39 | | int getHeight(); |
|---|
| 40 | | override void setText(char[]); |
|---|
| 41 | | Control getControl(); |
|---|
| 42 | | void setHeight(int); |
|---|
| 43 | | override void setImage(Image); |
|---|
| 44 | | int getPreferredWidth(HTHEME, HDC); |
|---|
| 45 | | int getHeaderHeight(); |
|---|
| 46 | | ExpandBar parent; |
|---|
| 47 | | Control control; |
|---|
| 48 | | bool expanded; |
|---|
| 49 | | bool hover; |
|---|
| 50 | | int x; |
|---|
| 51 | | int y; |
|---|
| 52 | | int width; |
|---|
| 53 | | int height; |
|---|
| 54 | | int imageHeight; |
|---|
| 55 | | int imageWidth; |
|---|
| 56 | | static int TEXT_INSET; |
|---|
| 57 | | static int BORDER; |
|---|
| 58 | | static int CHEVRON_SIZE; |
|---|
| 59 | | } |
|---|
| 60 | | |
|---|
| 61 | | /++ |
|---|
| | 24 | |
|---|
| 62 | 25 | import dwt.DWT; |
|---|
| 63 | 26 | import dwt.DWTException; |
|---|
| … | … | |
| 66 | 29 | import dwt.graphics.Rectangle; |
|---|
| 67 | 30 | import dwt.internal.win32.OS; |
|---|
| 68 | | import dwt.internal.win32.RECT; |
|---|
| 69 | | import dwt.internal.win32.TCHAR; |
|---|
| | 31 | |
|---|
| | 32 | import dwt.dwthelper.utils; |
|---|
| 70 | 33 | |
|---|
| 71 | 34 | /** |
|---|
| … | … | |
| 87 | 50 | * @since 3.2 |
|---|
| 88 | 51 | */ |
|---|
| 89 | | public class ExpandItem extends Item { |
|---|
| | 52 | public class ExpandItem : Item { |
|---|
| 90 | 53 | ExpandBar parent; |
|---|
| 91 | 54 | Control control; |
|---|
| … | … | |
| 93 | 56 | int x, y, width, height; |
|---|
| 94 | 57 | int imageHeight, imageWidth; |
|---|
| 95 | | static final int TEXT_INSET = 6; |
|---|
| 96 | | static final int BORDER = 1; |
|---|
| 97 | | static final int CHEVRON_SIZE = 24; |
|---|
| | 58 | static const int TEXT_INSET = 6; |
|---|
| | 59 | static const int BORDER = 1; |
|---|
| | 60 | static const int CHEVRON_SIZE = 24; |
|---|
| 98 | 61 | |
|---|
| 99 | 62 | /** |
|---|
| … | … | |
| 124 | 87 | * @see Widget#getStyle |
|---|
| 125 | 88 | */ |
|---|
| 126 | | public ExpandItem (ExpandBar parent, int style) { |
|---|
| | 89 | public this (ExpandBar parent, int style) { |
|---|
| 127 | 90 | this (parent, style, checkNull (parent).getItemCount ()); |
|---|
| 128 | 91 | } |
|---|
| … | … | |
| 158 | 121 | * @see Widget#getStyle |
|---|
| 159 | 122 | */ |
|---|
| 160 | | public ExpandItem (ExpandBar parent, int style, int index) { |
|---|
| | 123 | public this (ExpandBar parent, int style, int index) { |
|---|
| 161 | 124 | super (parent, style); |
|---|
| 162 | 125 | this.parent = parent; |
|---|
| … | … | |
| 169 | 132 | } |
|---|
| 170 | 133 | |
|---|
| 171 | | private void drawChevron (int hDC, RECT rect) { |
|---|
| 172 | | int oldBrush = OS.SelectObject (hDC, OS.GetSysColorBrush (OS.COLOR_BTNFACE)); |
|---|
| | 134 | private void drawChevron (HDC hDC, RECT* rect) { |
|---|
| | 135 | HBRUSH oldBrush = OS.SelectObject (hDC, OS.GetSysColorBrush (OS.COLOR_BTNFACE)); |
|---|
| 173 | 136 | OS.PatBlt (hDC, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, OS.PATCOPY); |
|---|
| 174 | 137 | OS.SelectObject (hDC, oldBrush); |
|---|
| … | … | |
| 177 | 140 | rect.right -= 4; |
|---|
| 178 | 141 | rect.bottom -= 4; |
|---|
| 179 | | int hPen = OS.CreatePen (OS.PS_SOLID, 1, parent.foreground); |
|---|
| 180 | | int oldPen = OS.SelectObject (hDC, hPen); |
|---|
| | 142 | HPEN hPen = OS.CreatePen (OS.PS_SOLID, 1, parent.foreground); |
|---|
| | 143 | HPEN oldPen = OS.SelectObject (hDC, hPen); |
|---|
| 181 | 144 | int [] polyline1, polyline2; |
|---|
| 182 | 145 | if (expanded) { |
|---|
| 183 | 146 | int px = rect.left + 5; |
|---|
| 184 | 147 | int py = rect.top + 7; |
|---|
| 185 | | polyline1 = new int [] { |
|---|
| | 148 | polyline1 = [ |
|---|
| 186 | 149 | px,py, px+1,py, px+1,py-1, px+2,py-1, px+2,py-2, px+3,py-2, px+3,py-3, |
|---|
| 187 | | px+3,py-2, px+4,py-2, px+4,py-1, px+5,py-1, px+5,py, px+7,py}; |
|---|
| | 150 | px+3,py-2, px+4,py-2, px+4,py-1, px+5,py-1, px+5,py, px+7,py]; |
|---|
| 188 | 151 | py += 4; |
|---|
| 189 | | polyline2 = new int [] { |
|---|
| | 152 | polyline2 = [ |
|---|
| 190 | 153 | px,py, px+1,py, px+1,py-1, px+2,py-1, px+2,py-2, px+3,py-2, px+3,py-3, |
|---|
| 191 | | px+3,py-2, px+4,py-2, px+4,py-1, px+5,py-1, px+5,py, px+7,py}; |
|---|
| | 154 | px+3,py-2, px+4,py-2, px+4,py-1, px+5,py-1, px+5,py, px+7,py]; |
|---|
| 192 | 155 | } else { |
|---|
| 193 | 156 | int px = rect.left + 5; |
|---|
| 194 | 157 | int py = rect.top + 4; |
|---|
| 195 | | polyline1 = new int[] { |
|---|
| | 158 | polyline1 = [ |
|---|
| 196 | 159 | px,py, px+1,py, px+1,py+1, px+2,py+1, px+2,py+2, px+3,py+2, px+3,py+3, |
|---|
| 197 | | px+3,py+2, px+4,py+2, px+4,py+1, px+5,py+1, px+5,py, px+7,py}; |
|---|
| | 160 | px+3,py+2, px+4,py+2, px+4,py+1, px+5,py+1, px+5,py, px+7,py]; |
|---|
| 198 | 161 | py += 4; |
|---|
| 199 | | polyline2 = new int [] { |
|---|
| | 162 | polyline2 = [ |
|---|
| 200 | 163 | px,py, px+1,py, px+1,py+1, px+2,py+1, px+2,py+2, px+3,py+2, px+3,py+3, |
|---|
| 201 | | px+3,py+2, px+4,py+2, px+4,py+1, px+5,py+1, px+5,py, px+7,py}; |
|---|
| 202 | | } |
|---|
| 203 | | OS.Polyline (hDC, polyline1, polyline1.length / 2); |
|---|
| 204 | | OS.Polyline (hDC, polyline2, polyline2.length / 2); |
|---|
| | 164 | px+3,py+2, px+4,py+2, px+4,py+1, px+5,py+1, px+5,py, px+7,py]; |
|---|
| | 165 | } |
|---|
| | 166 | OS.Polyline (hDC, cast(POINT*)polyline1.ptr, polyline1.length / 2); |
|---|
| | 167 | OS.Polyline (hDC, cast(POINT*)polyline2.ptr, polyline2.length / 2); |
|---|
| 205 | 168 | if (hover) { |
|---|
| 206 | | int whitePen = OS.CreatePen (OS.PS_SOLID, 1, OS.GetSysColor (OS.COLOR_3DHILIGHT)); |
|---|
| 207 | | int darkGrayPen = OS.CreatePen (OS.PS_SOLID, 1, OS.GetSysColor (OS.COLOR_3DSHADOW)); |
|---|
| | 169 | HPEN whitePen = OS.CreatePen (OS.PS_SOLID, 1, OS.GetSysColor (OS.COLOR_3DHILIGHT)); |
|---|
| | 170 | HPEN darkGrayPen = OS.CreatePen (OS.PS_SOLID, 1, OS.GetSysColor (OS.COLOR_3DSHADOW)); |
|---|
| 208 | 171 | OS.SelectObject (hDC, whitePen); |
|---|
| 209 | | int [] points1 = { |
|---|
| | 172 | int [] points1 = [ |
|---|
| 210 | 173 | rect.left, rect.bottom, |
|---|
| 211 | 174 | rect.left, rect.top, |
|---|
| 212 | | rect.right, rect.top}; |
|---|
| 213 | | OS.Polyline (hDC, points1, points1.length / 2); |
|---|
| | 175 | rect.right, rect.top]; |
|---|
| | 176 | OS.Polyline (hDC, cast(POINT*)points1.ptr, points1.length / 2); |
|---|
| 214 | 177 | OS.SelectObject (hDC, darkGrayPen); |
|---|
| 215 | | int [] points2 = { |
|---|
| | 178 | int [] points2 = [ |
|---|
| 216 | 179 | rect.right, rect.top, |
|---|
| 217 | 180 | rect.right, rect.bottom, |
|---|
| 218 | | rect.left, rect.bottom}; |
|---|
| 219 | | OS.Polyline (hDC, points2, points2.length / 2); |
|---|
| | 181 | rect.left, rect.bottom]; |
|---|
| | 182 | OS.Polyline (hDC, cast(POINT*)points2.ptr, points2.length / 2); |
|---|
| 220 | 183 | OS.SelectObject (hDC, oldPen); |
|---|
| 221 | 184 | OS.DeleteObject (whitePen); |
|---|
| … | … | |
| 228 | 191 | |
|---|
| 229 | 192 | void drawItem (GC gc, HTHEME hTheme, RECT* clipRect, bool drawFocus) { |
|---|
| 230 | | int hDC = gc.handle; |
|---|
| | 193 | auto hDC = gc.handle; |
|---|
| 231 | 194 | int headerHeight = parent.getBandHeight (); |
|---|
| 232 | | RECT rect = new RECT (); |
|---|
| 233 | | OS.SetRect (rect, x, y, x + width, y + headerHeight); |
|---|
| 234 | | if (hTheme !is 0) { |
|---|
| 235 | | OS.DrawThemeBackground (hTheme, hDC, OS.EBP_NORMALGROUPHEAD, 0, rect, clipRect); |
|---|
| | 195 | RECT rect; |
|---|
| | 196 | OS.SetRect (&rect, x, y, x + width, y + headerHeight); |
|---|
| | 197 | if (hTheme !is null) { |
|---|
| | 198 | OS.DrawThemeBackground (hTheme, hDC, OS.EBP_NORMALGROUPHEAD, 0, &rect, clipRect); |
|---|
| 236 | 199 | } else { |
|---|
| 237 | | int oldBrush = OS.SelectObject (hDC, OS.GetSysColorBrush (OS.COLOR_BTNFACE)); |
|---|
| | 200 | HBRUSH oldBrush = OS.SelectObject (hDC, OS.GetSysColorBrush (OS.COLOR_BTNFACE)); |
|---|
| 238 | 201 | OS.PatBlt (hDC, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, OS.PATCOPY); |
|---|
| 239 | 202 | OS.SelectObject (hDC, oldBrush); |
|---|
| … | … | |
| 248 | 211 | rect.left += imageWidth; |
|---|
| 249 | 212 | } |
|---|
| 250 | | if (text.length () > 0) { |
|---|
| | 213 | if (text.length > 0) { |
|---|
| 251 | 214 | rect.left += ExpandItem.TEXT_INSET; |
|---|
| 252 | | TCHAR buffer = new TCHAR (parent.getCodePage (), text, false); |
|---|
| 253 | | if (hTheme !is 0) { |
|---|
| 254 | | OS.DrawThemeText (hTheme, hDC, OS.EBP_NORMALGROUPHEAD, 0, buffer.chars, buffer.length(), OS.DT_VCENTER | OS.DT_SINGLELINE, 0, rect); |
|---|
| | 215 | TCHAR[] buffer = StrToTCHARs ( text/+, parent.getCodePage ()+/ ); |
|---|
| | 216 | if (hTheme !is null) { |
|---|
| | 217 | OS.DrawThemeText (hTheme, hDC, OS.EBP_NORMALGROUPHEAD, 0, buffer.ptr, buffer.length, OS.DT_VCENTER | OS.DT_SINGLELINE, 0, &rect); |
|---|
| 255 | 218 | } else { |
|---|
| 256 | 219 | int oldBkMode = OS.SetBkMode (hDC, OS.TRANSPARENT); |
|---|
| 257 | | OS.DrawText (hDC, buffer, buffer.length (), rect, OS.DT_VCENTER | OS.DT_SINGLELINE); |
|---|
| | 220 | OS.DrawText (hDC, buffer.ptr, buffer.length, &rect, OS.DT_VCENTER | OS.DT_SINGLELINE); |
|---|
| 258 | 221 | OS.SetBkMode (hDC, oldBkMode); |
|---|
| 259 | 222 | } |
|---|
| … | … | |
| 263 | 226 | rect.top = y + (headerHeight - chevronSize) / 2; |
|---|
| 264 | 227 | rect.bottom = rect.top + chevronSize; |
|---|
| 265 | | if (hTheme !is 0) { |
|---|
| | 228 | if (hTheme !is null) { |
|---|
| 266 | 229 | int partID = expanded ? OS.EBP_NORMALGROUPCOLLAPSE : OS.EBP_NORMALGROUPEXPAND; |
|---|
| 267 | 230 | int stateID = hover ? OS.EBNGC_HOT : OS.EBNGC_NORMAL; |
|---|
| 268 | | OS.DrawThemeBackground (hTheme, hDC, partID, stateID, rect, clipRect); |
|---|
| | 231 | OS.DrawThemeBackground (hTheme, hDC, partID, stateID, &rect, clipRect); |
|---|
| 269 | 232 | } else { |
|---|
| 270 | | drawChevron (hDC, rect); |
|---|
| | 233 | drawChevron (hDC, &rect); |
|---|
| 271 | 234 | } |
|---|
| 272 | 235 | if (drawFocus) { |
|---|
| 273 | | OS.SetRect (rect, x + 1, y + 1, x + width - 2, y + headerHeight - 2); |
|---|
| 274 | | OS.DrawFocusRect (hDC, rect); |
|---|
| | 236 | OS.SetRect (&rect, x + 1, y + 1, x + width - 2, y + headerHeight - 2); |
|---|
| | 237 | OS.DrawFocusRect (hDC, &rect); |
|---|
| 275 | 238 | } |
|---|
| 276 | 239 | if (expanded) { |
|---|
| 277 | 240 | if (!parent.isAppThemed ()) { |
|---|
| 278 | | int pen = OS.CreatePen (OS.PS_SOLID, 1, OS.GetSysColor (OS.COLOR_BTNFACE)); |
|---|
| 279 | | int oldPen = OS.SelectObject (hDC, pen); |
|---|
| 280 | | int [] points = { |
|---|
| | 241 | HPEN pen = OS.CreatePen (OS.PS_SOLID, 1, OS.GetSysColor (OS.COLOR_BTNFACE)); |
|---|
| | 242 | HPEN oldPen = OS.SelectObject (hDC, pen); |
|---|
| | 243 | int [] points = [ |
|---|
| 281 | 244 | x, y + headerHeight, |
|---|
| 282 | 245 | x, y + headerHeight + height, |
|---|
| 283 | 246 | x + width - 1, y + headerHeight + height, |
|---|
| 284 | | x + width - 1, y + headerHeight - 1}; |
|---|
| 285 | | OS.Polyline (hDC, points, points.length / 2); |
|---|
| | 247 | x + width - 1, y + headerHeight - 1]; |
|---|
| | 248 | OS.Polyline (hDC, cast(POINT*) points.ptr, points.length / 2); |
|---|
| 286 | 249 | OS.SelectObject (hDC, oldPen); |
|---|
| 287 | 250 | OS.DeleteObject (pen); |
|---|
| … | … | |
| 377 | 340 | width += ExpandItem.TEXT_INSET + imageWidth; |
|---|
| 378 | 341 | } |
|---|
| 379 | | if (text.length() > 0) { |
|---|
| 380 | | RECT rect = new RECT (); |
|---|
| 381 | | TCHAR buffer = new TCHAR (parent.getCodePage (), text, false); |
|---|
| 382 | | if (hTheme !is 0) { |
|---|
| 383 | | OS.GetThemeTextExtent (hTheme, hDC, OS.EBP_NORMALGROUPHEAD, 0, buffer.chars, buffer.length(), OS.DT_SINGLELINE, null, rect); |
|---|
| | 342 | if (text.length > 0) { |
|---|
| | 343 | RECT rect; |
|---|
| | 344 | TCHAR[] buffer = StrToTCHARs (/+parent.getCodePage (),+/ text); |
|---|
| | 345 | if (hTheme !is null) { |
|---|
| | 346 | OS.GetThemeTextExtent (hTheme, hDC, OS.EBP_NORMALGROUPHEAD, 0, buffer.ptr, buffer.length, OS.DT_SINGLELINE, null, &rect); |
|---|
| 384 | 347 | } else { |
|---|
| 385 | | OS.DrawText (hDC, buffer, buffer.length (), rect, OS.DT_CALCRECT); |
|---|
| | 348 | OS.DrawText (hDC, buffer.ptr, buffer.length, &rect, OS.DT_CALCRECT); |
|---|
| 386 | 349 | } |
|---|
| 387 | 350 | width += (rect.right - rect.left); |
|---|
| … | … | |
| 396 | 359 | |
|---|
| 397 | 360 | void redraw (bool all) { |
|---|
| 398 | | int parentHandle = parent.handle; |
|---|
| | 361 | auto parentHandle = parent.handle; |
|---|
| 399 | 362 | int headerHeight = parent.getBandHeight (); |
|---|
| 400 | | RECT rect = new RECT (); |
|---|
| | 363 | RECT rect; |
|---|
| 401 | 364 | int left = all ? x : x + width - headerHeight; |
|---|
| 402 | | OS.SetRect (rect, left, y, x + width, y + headerHeight); |
|---|
| 403 | | OS.InvalidateRect (parentHandle, rect, true); |
|---|
| | 365 | OS.SetRect (&rect, left, y, x + width, y + headerHeight); |
|---|
| | 366 | OS.InvalidateRect (parentHandle, &rect, true); |
|---|
| 404 | 367 | if (imageHeight > headerHeight) { |
|---|
| 405 | | OS.SetRect (rect, x + ExpandItem.TEXT_INSET, y + headerHeight - imageHeight, x + ExpandItem.TEXT_INSET + imageWidth, y); |
|---|
| 406 | | OS.InvalidateRect (parentHandle, rect, true); |
|---|
| | 368 | OS.SetRect (&rect, x + ExpandItem.TEXT_INSET, y + headerHeight - imageHeight, x + ExpandItem.TEXT_INSET + imageWidth, y); |
|---|
| | 369 | OS.InvalidateRect (parentHandle, &rect, true); |
|---|
| 407 | 370 | } |
|---|
| 408 | 371 | if (!parent.isAppThemed ()) { |
|---|
| 409 | | OS.SetRect (rect, x, y + headerHeight, x + width, y + headerHeight + height + 1); |
|---|
| 410 | | OS.InvalidateRect (parentHandle, rect, true); |
|---|
| | 372 | OS.SetRect (&rect, x, y + headerHeight, x + width, y + headerHeight + height + 1); |
|---|
| | 373 | OS.InvalidateRect (parentHandle, &rect, true); |
|---|
| 411 | 374 | } |
|---|
| 412 | 375 | } |
|---|
| … | … | |
| 535 | 498 | } |
|---|
| 536 | 499 | |
|---|
| 537 | | public void setText (String string) { |
|---|
| | 500 | public void setText (char[] string) { |
|---|
| 538 | 501 | super.setText (string); |
|---|
| 539 | 502 | redraw (true); |
|---|
| 540 | 503 | } |
|---|
| 541 | 504 | } |
|---|
| 542 | | ++/ |
|---|
| | 505 | |
|---|