Mercurial > projects > dwt-win
changeset 74:ecfb28edd2e1
TreeColumn
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Tue, 05 Feb 2008 00:15:31 +0100 |
parents | 42fc35b18200 |
children | f824f1836871 |
files | dwt/widgets/Tree.d dwt/widgets/TreeColumn.d |
diffstat | 2 files changed, 90 insertions(+), 85 deletions(-) [+] |
line wrap: on
line diff
--- a/dwt/widgets/Tree.d Tue Feb 05 00:02:38 2008 +0100 +++ b/dwt/widgets/Tree.d Tue Feb 05 00:15:31 2008 +0100 @@ -114,7 +114,8 @@ bool linesVisible, customDraw, printClient, painted, ignoreItemHeight; bool ignoreCustomDraw, ignoreDrawForeground, ignoreDrawBackground, ignoreDrawFocus; bool ignoreDrawSelection, ignoreDrawHot, ignoreFullSelection, explorerTheme; - int scrollWidth, itemToolTipHandle, headerToolTipHandle, selectionForeground; + int scrollWidth, itemToolTipHandle, selectionForeground; + HANDLE headerToolTipHandle; static const int INSET = 3; static const int GRID_WIDTH = 1; static const int SORT_WIDTH = 10;
--- a/dwt/widgets/TreeColumn.d Tue Feb 05 00:02:38 2008 +0100 +++ b/dwt/widgets/TreeColumn.d Tue Feb 05 00:15:31 2008 +0100 @@ -26,6 +26,9 @@ import dwt.widgets.Item; import dwt.widgets.Widget; import dwt.widgets.Tree; +import dwt.widgets.TreeItem; +import dwt.widgets.TypedListener; +import dwt.widgets.Event; import dwt.dwthelper.utils; @@ -316,11 +319,11 @@ checkWidget (); int index = parent.indexOf (this); if (index is -1) return 0; - int hwndHeader = parent.hwndHeader; - if (hwndHeader is 0) return 0; - HDITEM hdItem = new HDITEM (); + auto hwndHeader = parent.hwndHeader; + if (hwndHeader is null) return 0; + HDITEM hdItem; hdItem.mask = OS.HDI_WIDTH; - OS.SendMessage (hwndHeader, OS.HDM_GETITEM, index, hdItem); + OS.SendMessage (hwndHeader, OS.HDM_GETITEM, index, &hdItem); return hdItem.cxy; } @@ -340,26 +343,27 @@ int index = parent.indexOf (this); if (index is -1) return; int columnWidth = 0; - int hwnd = parent.handle, hwndHeader = parent.hwndHeader; - RECT headerRect = new RECT (); - OS.SendMessage (hwndHeader, OS.HDM_GETITEMRECT, index, headerRect); - int hDC = OS.GetDC (hwnd); - int oldFont = 0, newFont = OS.SendMessage (hwnd, OS.WM_GETFONT, 0, 0); - if (newFont !is 0) oldFont = OS.SelectObject (hDC, newFont); - TVITEM tvItem = new TVITEM (); + auto hwnd = parent.handle; + auto hwndHeader = parent.hwndHeader; + RECT headerRect; + OS.SendMessage (hwndHeader, OS.HDM_GETITEMRECT, index, &headerRect); + auto hDC = OS.GetDC (hwnd); + HFONT oldFont, newFont = cast(HFONT) OS.SendMessage (hwnd, OS.WM_GETFONT, 0, 0); + if (newFont !is null) oldFont = OS.SelectObject (hDC, newFont); + TVITEM tvItem; tvItem.mask = OS.TVIF_HANDLE | OS.TVIF_PARAM; - tvItem.hItem = OS.SendMessage (hwnd, OS.TVM_GETNEXTITEM, OS.TVGN_ROOT, 0); - while (tvItem.hItem !is 0) { - OS.SendMessage (hwnd, OS.TVM_GETITEM, 0, tvItem); + tvItem.hItem = cast(HANDLE) OS.SendMessage (hwnd, OS.TVM_GETNEXTITEM, OS.TVGN_ROOT, 0); + while (tvItem.hItem !is null) { + OS.SendMessage (hwnd, OS.TVM_GETITEM, 0, cast(int) &tvItem); TreeItem item = tvItem.lParam !is -1 ? parent.items [tvItem.lParam] : null; if (item !is null) { - int hFont = item.cellFont !is null ? item.cellFont [index] : -1; - if (hFont is -1) hFont = item.font; - if (hFont !is -1) hFont = OS.SelectObject (hDC, hFont); + auto hFont = item.cellFont !is null ? item.cellFont [index] : cast(HFONT)-1; + if (hFont is cast(HFONT)-1) hFont = item.font; + if (hFont !is cast(HFONT)-1) hFont = OS.SelectObject (hDC, hFont); RECT itemRect = item.getBounds (index, true, true, false, false, false, hDC); - if (hFont !is -1) OS.SelectObject (hDC, hFont); + if (hFont !is cast(HFONT)-1) OS.SelectObject (hDC, hFont); if (parent.hooks (DWT.MeasureItem)) { - int nSavedDC = OS.SaveDC (hDC); + auto nSavedDC = OS.SaveDC (hDC); GCData data = new GCData (); data.device = display; data.hFont = hFont; @@ -383,12 +387,12 @@ } columnWidth = Math.max (columnWidth, itemRect.right - headerRect.left); } - tvItem.hItem = OS.SendMessage (hwnd, OS.TVM_GETNEXTITEM, OS.TVGN_NEXTVISIBLE, tvItem.hItem); + tvItem.hItem = cast(HANDLE) OS.SendMessage (hwnd, OS.TVM_GETNEXTITEM, OS.TVGN_NEXTVISIBLE, tvItem.hItem); } - RECT rect = new RECT (); + RECT rect; int flags = OS.DT_CALCRECT | OS.DT_NOPREFIX; - TCHAR buffer = new TCHAR (parent.getCodePage (), text, false); - OS.DrawText (hDC, buffer, buffer.length (), rect, flags); + TCHAR[] buffer = StrToTCHARs (parent.getCodePage (), text, false); + OS.DrawText (hDC, buffer.ptr, buffer.length, &rect, flags); int headerWidth = rect.right - rect.left + Tree.HEADER_MARGIN; if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ()) headerWidth += Tree.HEADER_EXTRA; if (image !is null || parent.sortColumn is this) { @@ -407,14 +411,14 @@ headerWidth += bounds.width; } int margin = 0; - if (hwndHeader !is 0 && OS.COMCTL32_VERSION >= OS.VERSION (5, 80)) { + if (hwndHeader !is null && OS.COMCTL32_VERSION >= OS.VERSION (5, 80)) { margin = OS.SendMessage (hwndHeader, OS.HDM_GETBITMAPMARGIN, 0, 0); } else { margin = OS.GetSystemMetrics (OS.SM_CXEDGE) * 3; } headerWidth += margin * 2; } - if (newFont !is 0) OS.SelectObject (hDC, oldFont); + if (newFont !is null) OS.SelectObject (hDC, oldFont); OS.ReleaseDC (hwnd, hDC); int gridWidth = parent.linesVisible ? Tree.GRID_WIDTH : 0; setWidth (Math.max (headerWidth, columnWidth + gridWidth)); @@ -501,25 +505,25 @@ if (index is -1 || index is 0) return; style &= ~(DWT.LEFT | DWT.RIGHT | DWT.CENTER); style |= alignment & (DWT.LEFT | DWT.RIGHT | DWT.CENTER); - int hwndHeader = parent.hwndHeader; - if (hwndHeader is 0) return; - HDITEM hdItem = new HDITEM (); + auto hwndHeader = parent.hwndHeader; + if (hwndHeader is null) return; + HDITEM hdItem; hdItem.mask = OS.HDI_FORMAT | OS.HDI_IMAGE; - OS.SendMessage (hwndHeader, OS.HDM_GETITEM, index, hdItem); + OS.SendMessage (hwndHeader, OS.HDM_GETITEM, index, &hdItem); hdItem.fmt &= ~OS.HDF_JUSTIFYMASK; if ((style & DWT.LEFT) is DWT.LEFT) hdItem.fmt |= OS.HDF_LEFT; if ((style & DWT.CENTER) is DWT.CENTER) hdItem.fmt |= OS.HDF_CENTER; if ((style & DWT.RIGHT) is DWT.RIGHT) hdItem.fmt |= OS.HDF_RIGHT; - OS.SendMessage (hwndHeader, OS.HDM_SETITEM, index, hdItem); + OS.SendMessage (hwndHeader, OS.HDM_SETITEM, index, &hdItem); if (index !is 0) { - int hwnd = parent.handle; + auto hwnd = parent.handle; parent.forceResize (); - RECT rect = new RECT (), headerRect = new RECT (); - OS.GetClientRect (hwnd, rect); - OS.SendMessage (hwndHeader, OS.HDM_GETITEMRECT, index, headerRect); + RECT rect, headerRect; + OS.GetClientRect (hwnd, &rect); + OS.SendMessage (hwndHeader, OS.HDM_GETITEMRECT, index, &headerRect); rect.left = headerRect.left; rect.right = headerRect.right; - OS.InvalidateRect (hwnd, rect, true); + OS.InvalidateRect (hwnd, &rect, true); } } @@ -537,11 +541,11 @@ void setImage (Image image, bool sort, bool right) { int index = parent.indexOf (this); if (index is -1) return; - int hwndHeader = parent.hwndHeader; - if (hwndHeader is 0) return; - HDITEM hdItem = new HDITEM (); + auto hwndHeader = parent.hwndHeader; + if (hwndHeader is null) return; + HDITEM hdItem; hdItem.mask = OS.HDI_FORMAT | OS.HDI_IMAGE | OS.HDI_BITMAP; - OS.SendMessage (hwndHeader, OS.HDM_GETITEM, index, hdItem); + OS.SendMessage (hwndHeader, OS.HDM_GETITEM, index, &hdItem); hdItem.fmt &= ~OS.HDF_BITMAP_ON_RIGHT; if (image !is null) { if (sort) { @@ -560,7 +564,7 @@ hdItem.mask &= ~(OS.HDI_IMAGE | OS.HDI_BITMAP); hdItem.fmt &= ~(OS.HDF_IMAGE | OS.HDF_BITMAP); } - OS.SendMessage (hwndHeader, OS.HDM_SETITEM, index, hdItem); + OS.SendMessage (hwndHeader, OS.HDM_SETITEM, index, &hdItem); } /** @@ -608,13 +612,13 @@ void setSortDirection (int direction) { if (OS.COMCTL32_MAJOR >= 6) { - int hwndHeader = parent.hwndHeader; - if (hwndHeader !is 0) { + auto hwndHeader = parent.hwndHeader; + if (hwndHeader !is null) { int index = parent.indexOf (this); if (index is -1) return; - HDITEM hdItem = new HDITEM (); + HDITEM hdItem; hdItem.mask = OS.HDI_FORMAT | OS.HDI_IMAGE; - OS.SendMessage (hwndHeader, OS.HDM_GETITEM, index, hdItem); + OS.SendMessage (hwndHeader, OS.HDM_GETITEM, index, &hdItem); switch (direction) { case DWT.UP: hdItem.fmt &= ~(OS.HDF_IMAGE | OS.HDF_SORTDOWN); @@ -634,16 +638,16 @@ } break; } - OS.SendMessage (hwndHeader, OS.HDM_SETITEM, index, hdItem); + OS.SendMessage (hwndHeader, OS.HDM_SETITEM, index, &hdItem); if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ()) { - int hwnd = parent.handle; + auto hwnd = parent.handle; parent.forceResize (); - RECT rect = new RECT (), headerRect = new RECT (); - OS.GetClientRect (hwnd, rect); - OS.SendMessage (hwndHeader, OS.HDM_GETITEMRECT, index, headerRect); + RECT rect, headerRect; + OS.GetClientRect (hwnd, &rect); + OS.SendMessage (hwndHeader, OS.HDM_GETITEMRECT, index, &headerRect); rect.left = headerRect.left; rect.right = headerRect.right; - OS.InvalidateRect (hwnd, rect, true); + OS.InvalidateRect (hwnd, &rect, true); } } } else { @@ -662,7 +666,7 @@ override public void setText (char[] string) { checkWidget (); if (string is null) error (DWT.ERROR_NULL_ARGUMENT); - if (string.equals (text)) return; + if (string==/*eq*/text) return; int index = parent.indexOf (this); if (index is -1) return; super.setText (string); @@ -674,18 +678,18 @@ * mnemonic characters and replace doubled mnemonics * with spaces. */ - int hHeap = OS.GetProcessHeap (); - TCHAR buffer = new TCHAR (parent.getCodePage (), fixMnemonic (string), true); - int byteCount = buffer.length () * TCHAR.sizeof; - int pszText = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount); - OS.MoveMemory (pszText, buffer, byteCount); - int hwndHeader = parent.hwndHeader; - if (hwndHeader is 0) return; - HDITEM hdItem = new HDITEM (); + auto hHeap = OS.GetProcessHeap (); + TCHAR[] buffer = StrToTCHARs (parent.getCodePage (), fixMnemonic (string), true); + int byteCount = buffer.length * TCHAR.sizeof; + auto pszText = cast(TCHAR*) OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount); + OS.MoveMemory (pszText, buffer.ptr, byteCount); + auto hwndHeader = parent.hwndHeader; + if (hwndHeader is null) return; + HDITEM hdItem; hdItem.mask = OS.HDI_TEXT; hdItem.pszText = pszText; - int result = OS.SendMessage (hwndHeader, OS.HDM_SETITEM, index, hdItem); - if (pszText !is 0) OS.HeapFree (hHeap, 0, pszText); + int result = OS.SendMessage (hwndHeader, OS.HDM_SETITEM, index, &hdItem); + if (pszText !is null) OS.HeapFree (hHeap, 0, pszText); if (result is 0) error (DWT.ERROR_CANNOT_SET_TEXT); } @@ -705,8 +709,8 @@ public void setToolTipText (char[] string) { checkWidget(); toolTipText = string; - int hwndHeaderToolTip = parent.headerToolTipHandle; - if (hwndHeaderToolTip is 0) { + auto hwndHeaderToolTip = parent.headerToolTipHandle; + if (hwndHeaderToolTip is null) { parent.createHeaderToolTips (); parent.updateHeaderToolTips (); } @@ -727,38 +731,38 @@ if (width < 0) return; int index = parent.indexOf (this); if (index is -1) return; - int hwndHeader = parent.hwndHeader; - if (hwndHeader is 0) return; - HDITEM hdItem = new HDITEM (); + auto hwndHeader = parent.hwndHeader; + if (hwndHeader is null) return; + HDITEM hdItem; hdItem.mask = OS.HDI_WIDTH; hdItem.cxy = width; - OS.SendMessage (hwndHeader, OS.HDM_SETITEM, index, hdItem); - RECT headerRect = new RECT (); - OS.SendMessage (hwndHeader, OS.HDM_GETITEMRECT, index, headerRect); + OS.SendMessage (hwndHeader, OS.HDM_SETITEM, index, &hdItem); + RECT headerRect; + OS.SendMessage (hwndHeader, OS.HDM_GETITEMRECT, index, &headerRect); parent.forceResize (); - int hwnd = parent.handle; - RECT rect = new RECT (); - OS.GetClientRect (hwnd, rect); + auto hwnd = parent.handle; + RECT rect; + OS.GetClientRect (hwnd, &rect); rect.left = headerRect.left; - OS.InvalidateRect (hwnd, rect, true); + OS.InvalidateRect (hwnd, &rect, true); parent.setScrollWidth (); } void updateToolTip (int index) { - int hwndHeaderToolTip = parent.headerToolTipHandle; - if (hwndHeaderToolTip !is 0) { - int hwndHeader = parent.hwndHeader; - RECT rect = new RECT (); - if (OS.SendMessage (hwndHeader, OS.HDM_GETITEMRECT, index, rect) !is 0) { - TOOLINFO lpti = new TOOLINFO (); + auto hwndHeaderToolTip = parent.headerToolTipHandle; + if (hwndHeaderToolTip !is null) { + auto hwndHeader = parent.hwndHeader; + RECT rect; + if (OS.SendMessage (hwndHeader, OS.HDM_GETITEMRECT, index, &rect) !is 0) { + TOOLINFO lpti; lpti.cbSize = TOOLINFO.sizeof; lpti.hwnd = hwndHeader; lpti.uId = id; - lpti.left = rect.left; - lpti.top = rect.top; - lpti.right = rect.right; - lpti.bottom = rect.bottom; - OS.SendMessage (hwndHeaderToolTip, OS.TTM_NEWTOOLRECT, 0, lpti); + lpti.rect.left = rect.left; + lpti.rect.top = rect.top; + lpti.rect.right = rect.right; + lpti.rect.bottom = rect.bottom; + OS.SendMessage (hwndHeaderToolTip, OS.TTM_NEWTOOLRECT, 0, cast(int) &lpti); } } }