Mercurial > projects > dwt-win
diff dwt/widgets/TreeItem.d @ 213:36f5cb12e1a2
Update to SWT 3.4M7
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sat, 17 May 2008 17:34:28 +0200 |
parents | ab60f3309436 |
children | c749c13479ef |
line wrap: on
line diff
--- a/dwt/widgets/TreeItem.d Mon May 05 00:12:38 2008 +0200 +++ b/dwt/widgets/TreeItem.d Sat May 17 17:34:28 2008 +0200 @@ -58,11 +58,11 @@ Tree parent; String [] strings; Image [] images; + Font font; + Font [] cellFont; bool cached; int background = -1, foreground = -1; - HFONT font = cast(HFONT)-1; int [] cellBackground, cellForeground; - HFONT[] cellFont; /** * Constructs a new instance of this class given its parent @@ -258,7 +258,7 @@ OS.SendMessage (hwnd, OS.TVM_SETITEM, 0, &tvItem); } background = foreground = -1; - HFONT font = cast(HFONT)-1; + font = null; cellBackground = cellForeground = null; cellFont = null; if ((parent.style & DWT.VIRTUAL) !is 0) cached = false; @@ -340,6 +340,12 @@ releaseHandle (); } +HFONT fontHandle (int index) { + if (cellFont !is null && cellFont [index] !is null) return cellFont [index].handle; + if (font !is null) return font.handle; + return cast(HFONT)-1; +} + /** * Returns the receiver's background color. * @@ -444,14 +450,13 @@ int columnCount = 0; auto hwndHeader = parent.hwndHeader; if (hwndHeader !is null) { - columnCount = OS.SendMessage (hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0); + columnCount = parent.columnCount; firstColumn = index is OS.SendMessage (hwndHeader, OS.HDM_ORDERTOINDEX, 0, 0); } RECT rect; if (firstColumn) { - rect.left = cast(int) handle; bool full = columnCount is 0 && getText && getImage && fullText && fullImage; - if (OS.SendMessage (hwnd, OS.TVM_GETITEMRECT, full ? 0 : 1, cast(int)&rect) is 0) { + if (!OS.TreeView_GetItemRect (hwnd, handle, &rect, !full)) { return RECT.init; } if (getImage && !fullImage) { @@ -474,7 +479,7 @@ headerRect.right = parent.scrollWidth; if (headerRect.right is 0) headerRect = rect; } - if (fullText) rect.right = headerRect.right; + if (fullText && clip) rect.right = headerRect.right; if (fullImage) rect.left = headerRect.left; if (clip && headerRect.right < rect.right) { rect.right = headerRect.right; @@ -487,12 +492,11 @@ if (OS.SendMessage (hwndHeader, OS.HDM_GETITEMRECT, index, cast(int) &headerRect) is 0) { return RECT.init; } - rect.left = cast(int)handle; - if (OS.SendMessage (hwnd, OS.TVM_GETITEMRECT, 0, cast(int) &rect) is 0) { + if (!OS.TreeView_GetItemRect (hwnd, handle, &rect, false)) { return RECT.init; } rect.left = headerRect.left; - if (fullText && getImage) { + if (fullText && getImage && clip) { rect.right = headerRect.right; } else { rect.right = headerRect.left; @@ -507,7 +511,7 @@ rect.right += size.x; } if (getText) { - if (fullText) { + if (fullText && clip) { rect.left = rect.right + Tree.INSET; rect.right = headerRect.right; } else { @@ -520,8 +524,7 @@ HFONT hFont; if (hDC is null) { hNewDC = OS.GetDC (hwnd); - hFont = cellFont !is null ? cellFont [index] : cast(HFONT)-1; - if (hFont is cast(HFONT)-1) hFont = font; + hFont = fontHandle (index); if (hFont is cast(HFONT)-1) hFont = cast(HFONT) OS.SendMessage (hwnd, OS.WM_GETFONT, 0, 0); hFont = OS.SelectObject (hNewDC, hFont); } @@ -627,7 +630,7 @@ public Font getFont () { checkWidget (); if (!parent.checkData (this, true)) error (DWT.ERROR_WIDGET_DISPOSED); - return font is cast(HFONT)-1 ? parent.getFont () : Font.win32_new (display, font); + return font !is null ? font : parent.getFont (); } /** @@ -649,8 +652,8 @@ if (!parent.checkData (this, true)) error (DWT.ERROR_WIDGET_DISPOSED); int count = Math.max (1, parent.getColumnCount ()); if (0 > index || index > count -1) return getFont (); - auto hFont = (cellFont !is null) ? cellFont [index] : font; - return hFont is cast(HFONT)-1 ? getFont () : Font.win32_new (display, hFont); + if (cellFont is null || cellFont [index] is null) return getFont (); + return cellFont [index]; } /** @@ -976,8 +979,6 @@ if (parent.currentItem is this || parent.drawCount !is 0) return; auto hwnd = parent.handle; if (!OS.IsWindowVisible (hwnd)) return; - RECT rect; - rect.left = cast(int)handle; /* * When there are no columns and the tree is not * full selection, redraw only the text. This is @@ -985,17 +986,15 @@ */ bool full = (parent.style & (DWT.FULL_SELECTION | DWT.VIRTUAL)) !is 0; if (!full) { - auto hwndHeader = parent.hwndHeader; - if (hwndHeader !is null) { - full = OS.SendMessage (hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0) !is 0; - } + full = parent.columnCount !is 0; if (!full) { if (parent.hooks (DWT.EraseItem) || parent.hooks (DWT.PaintItem)) { full = true; } } } - if (OS.SendMessage (hwnd, OS.TVM_GETITEMRECT, full ? 0 : 1, cast(int) &rect) !is 0) { + RECT rect; + if (OS.TreeView_GetItemRect (hwnd, handle, &rect, !full)) { OS.InvalidateRect (hwnd, &rect, true); } } @@ -1178,8 +1177,7 @@ if ((parent.style & DWT.VIRTUAL) !is 0) { if (parent.currentItem is this && OS.IsWindowVisible (hwnd)) { RECT rect; - rect.left = cast(int) handle; - if (OS.SendMessage (hwnd, OS.TVM_GETITEMRECT, 0, cast(int) &rect) !is 0) { + if (OS.TreeView_GetItemRect (hwnd, handle, &rect, false)) { OS.InvalidateRect (hwnd, &rect, true); } } @@ -1238,20 +1236,17 @@ */ RECT oldRect; RECT [] rects = null; - SCROLLINFO oldInfo; - bool oldInfoNull = true; + SCROLLINFO* oldInfo; int count = 0; HANDLE hBottomItem; bool redraw = false, noScroll = true; HANDLE hTopItem = cast(HANDLE) OS.SendMessage (hwnd, OS.TVM_GETNEXTITEM, OS.TVGN_FIRSTVISIBLE, 0); if (noScroll && hTopItem !is null) { - //oldInfo = new SCROLLINFO (); - oldInfoNull = false; + oldInfo = new SCROLLINFO (); oldInfo.cbSize = SCROLLINFO.sizeof; oldInfo.fMask = OS.SIF_ALL; - if (!OS.GetScrollInfo (hwnd, OS.SB_HORZ, &oldInfo)) { - //oldInfo = null; - oldInfoNull = true; + if (!OS.GetScrollInfo (hwnd, OS.SB_HORZ, oldInfo)) { + oldInfo = null; } if (parent.drawCount is 0 && OS.IsWindowVisible (hwnd)) { bool noAnimate = true; @@ -1261,8 +1256,7 @@ int index = 0; while (hItem !is null && (noAnimate || hItem !is handle) && index < count) { RECT rect; - rect.left = cast(int) hItem; - if (OS.SendMessage (hwnd, OS.TVM_GETITEMRECT, 1, cast(int) &rect) !is 0) { + if (OS.TreeView_GetItemRect (hwnd, hItem, &rect, true)) { rects [index++] = rect; } hItem = cast(HANDLE) OS.SendMessage (hwnd, OS.TVM_GETNEXTITEM, OS.TVGN_NEXTVISIBLE, cast(int) &hItem); @@ -1312,10 +1306,8 @@ bool collapsed = false; if (!expanded) { RECT rect; - rect.left = cast(int)hTopItem; - while (hTopItem !is null && OS.SendMessage (hwnd, OS.TVM_GETITEMRECT, 0, cast(int) &rect) is 0) { - rect.left = OS.SendMessage (hwnd, OS.TVM_GETNEXTITEM, OS.TVGN_PARENT, hTopItem); - hTopItem = cast(HANDLE) rect.left; + while (hTopItem !is null && !OS.TreeView_GetItemRect (hwnd, hTopItem, &rect, false)) { + hTopItem = cast(HANDLE) OS.SendMessage (hwnd, OS.TVM_GETNEXTITEM, OS.TVGN_PARENT, hTopItem); collapsed = true; } } @@ -1324,13 +1316,13 @@ OS.SendMessage (hwnd, OS.TVM_SELECTITEM, OS.TVGN_FIRSTVISIBLE, hTopItem); scrolled = hTopItem !is cast(HANDLE) OS.SendMessage (hwnd, OS.TVM_GETNEXTITEM, OS.TVGN_FIRSTVISIBLE, 0); } - if (!collapsed && !scrolled && !oldInfoNull ) { + if (!collapsed && !scrolled && oldInfo !is null ) { SCROLLINFO newInfo; newInfo.cbSize = SCROLLINFO.sizeof; newInfo.fMask = OS.SIF_ALL; if (OS.GetScrollInfo (hwnd, OS.SB_HORZ, &newInfo)) { if (oldInfo.nPos !is newInfo.nPos) { - int lParam = OS.SB_THUMBPOSITION | ((oldInfo.nPos << 16) & 0xFFFF0000); + int /*long*/ lParam = OS.MAKELPARAM (OS.SB_THUMBPOSITION, oldInfo.nPos); OS.SendMessage (hwnd, OS.WM_HSCROLL, lParam, 0); } } @@ -1345,8 +1337,7 @@ int index = 0; while (hItem !is null && index < count) { RECT rect; - rect.left = cast(int) hItem; - if (OS.SendMessage (hwnd, OS.TVM_GETITEMRECT, 1, cast(int) &rect) !is 0) { + if (OS.TreeView_GetItemRect (hwnd, hItem, &rect, true)) { if (!OS.EqualRect (&rect, & rects [index])) { break; } @@ -1376,8 +1367,7 @@ } if (handle is hBottomItem) { RECT rect; - rect.left = cast(int) hBottomItem; - if (OS.SendMessage (hwnd, OS.TVM_GETITEMRECT, 0, cast(int)&rect) !is 0) { + if (OS.TreeView_GetItemRect (hwnd, hBottomItem, &rect, false)) { OS.InvalidateRect (hwnd, &rect, true); } } @@ -1427,13 +1417,11 @@ if (font !is null && font.isDisposed ()) { DWT.error (DWT.ERROR_INVALID_ARGUMENT); } - HFONT hFont = cast(HFONT)-1; - if (font !is null) { - parent.customDraw = true; - hFont = font.handle; - } - if (this.font is hFont) return; - this.font = hFont; + Font oldFont = this.font; + if (oldFont is font) return; + this.font = font; + if (oldFont !is null && oldFont.opEquals (font)) return; + if (font !is null) parent.customDraw = true; if ((parent.style & DWT.VIRTUAL) !is 0) cached = true; /* * Bug in Windows. When the font is changed for an item, @@ -1479,19 +1467,15 @@ } int count = Math.max (1, parent.getColumnCount ()); if (0 > index || index > count - 1) return; - HFONT hFont = cast(HFONT)-1; - if (font !is null) { - parent.customDraw = true; - hFont = font.handle; + if (cellFont is null) { + if (font is null) return; + cellFont = new Font [count]; } - if (cellFont is null) { - cellFont = new HFONT [count]; - for (int i = 0; i < count; i++) { - cellFont [i] = cast(HFONT) -1; - } - } - if (cellFont [index] is hFont) return; - cellFont [index] = hFont; + Font oldFont = cellFont [index]; + if (oldFont is font) return; + cellFont [index] = font; + if (oldFont !is null && oldFont.opEquals (font)) return; + if (font !is null) parent.customDraw = true; if ((parent.style & DWT.VIRTUAL) !is 0) cached = true; /* * Bug in Windows. When the font is changed for an item, @@ -1633,8 +1617,7 @@ if ((parent.style & DWT.VIRTUAL) !is 0) { if (parent.currentItem is this && OS.IsWindowVisible (hwnd)) { RECT rect; - rect.left = cast(int)handle; - if (OS.SendMessage (hwnd, OS.TVM_GETITEMRECT, 0, cast(int)&rect) !is 0) { + if (OS.TreeView_GetItemRect (hwnd, handle, &rect, false)) { OS.InvalidateRect (hwnd, &rect, true); } }