diff options
author | Steve Northover <steve> | 2006-03-20 19:48:31 +0000 |
---|---|---|
committer | Steve Northover <steve> | 2006-03-20 19:48:31 +0000 |
commit | 527998c9e4be5c58a908b0f0d6081466df8efc7f (patch) | |
tree | 26040b3b5044187626048c5ff8bd36a07e3b116b | |
parent | 30da8be87bc22b7280e4efbcaf1c8144d67dba2a (diff) | |
download | eclipse.platform.swt-527998c9e4be5c58a908b0f0d6081466df8efc7f.tar.gz eclipse.platform.swt-527998c9e4be5c58a908b0f0d6081466df8efc7f.tar.xz eclipse.platform.swt-527998c9e4be5c58a908b0f0d6081466df8efc7f.zip |
support SWT.FOREGROUND and SWT.BACKGROUND
3 files changed, 181 insertions, 89 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Table.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Table.java index 023e07b885..05d18811c1 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Table.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Table.java @@ -48,10 +48,10 @@ public class Table extends Composite { ImageList imageList, headerImageList; TableItem currentItem; TableColumn sortColumn; - boolean customDraw, dragStarted, fixScrollWidth, tipRequested; + boolean ignoreItemHeight, ignoreDraw, ignoreDrawSelection, ignoreDrawBackground; + boolean customDraw, dragStarted, fixScrollWidth, tipRequested, wasSelected, wasResized; boolean ignoreActivate, ignoreSelect, ignoreShrink, ignoreResize, ignoreColumnMove, ignoreColumnResize; - boolean wasSelected, wasResized, ignoreItemHeight, ignoreDraw, ignoreDrawSelected; - int headerToolTipHandle, itemHeight, lastIndexOf, lastWidth, sortDirection, resizeCount, textColor; + int headerToolTipHandle, itemHeight, lastIndexOf, lastWidth, sortDirection, resizeCount, selectionForeground; static /*final*/ int HeaderProc; static final int INSET = 4; static final int GRID_WIDTH = 1; @@ -430,8 +430,8 @@ LRESULT CDDS_SUBITEMPOSTPAINT (int wParam, int lParam) { LRESULT CDDS_SUBITEMPREPAINT (int wParam, int lParam) { int code = OS.CDRF_DODEFAULT; - textColor = -1; - ignoreDraw = ignoreDrawSelected = false; + selectionForeground = -1; + ignoreDraw = ignoreDrawSelection = ignoreDrawBackground = false; NMLVCUSTOMDRAW nmcd = new NMLVCUSTOMDRAW (); OS.MoveMemory (nmcd, lParam, NMLVCUSTOMDRAW.sizeof); /* @@ -463,7 +463,7 @@ LRESULT CDDS_SUBITEMPREPAINT (int wParam, int lParam) { if (clrText == -1) clrText = item.foreground; int clrTextBk = item.cellBackground != null ? item.cellBackground [nmcd.iSubItem] : -1; if (clrTextBk == -1) clrTextBk = item.background; - if (textColor != -1) clrText = textColor; + if (selectionForeground != -1) clrText = selectionForeground; /* * Bug in Windows. When the table has the extended style * LVS_EX_FULLROWSELECT and LVM_SETBKCOLOR is used with @@ -472,8 +472,8 @@ LRESULT CDDS_SUBITEMPREPAINT (int wParam, int lParam) { * image. The fix is emulate LVS_EX_FULLROWSELECT by * drawing the selection. */ - if (OS.IsWindowVisible (handle)) { - if (!ignoreDrawSelected && (style & SWT.FULL_SELECTION) != 0) { + if (OS.IsWindowVisible (handle) && OS.IsWindowEnabled (handle)) { + if (!ignoreDrawSelection && (style & SWT.FULL_SELECTION) != 0) { int bits = OS.SendMessage (handle, OS.LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0); if ((bits & OS.LVS_EX_FULLROWSELECT) == 0) { /* @@ -536,7 +536,7 @@ LRESULT CDDS_SUBITEMPREPAINT (int wParam, int lParam) { nmcd.clrText = clrText == -1 ? getForegroundPixel () : clrText; if (clrTextBk == -1) { nmcd.clrTextBk = OS.CLR_NONE; - if (textColor == -1) { + if (selectionForeground == -1) { Control control = findBackgroundControl (); if (control == null) control = this; if (control.backgroundImage == null) { @@ -544,27 +544,28 @@ LRESULT CDDS_SUBITEMPREPAINT (int wParam, int lParam) { } } } else { - nmcd.clrTextBk = textColor != -1 ? OS.CLR_NONE : clrTextBk; + nmcd.clrTextBk = selectionForeground != -1 ? OS.CLR_NONE : clrTextBk; } OS.MoveMemory (lParam, nmcd, NMLVCUSTOMDRAW.sizeof); } code |= OS.CDRF_NEWFONT; } - /* - * Feature in Windows. When the table is disabled, it draws - * with a gray background but does not gray the text. The fix - * is to explicitly gray the text. - */ - if (!OS.IsWindowEnabled (handle)) { - nmcd.clrText = OS.GetSysColor (OS.COLOR_GRAYTEXT); - if (findImageControl () != null) { - nmcd.clrTextBk = OS.CLR_NONE; - } else { - nmcd.clrTextBk = OS.GetSysColor (OS.COLOR_3DFACE); - } - OS.MoveMemory (lParam, nmcd, NMLVCUSTOMDRAW.sizeof); - code |= OS.CDRF_NEWFONT; + } + /* + * Feature in Windows. When the table is disabled, it draws + * with a gray background but does not gray the text. The fix + * is to explicitly gray the text. + */ + if (!OS.IsWindowEnabled (handle)) { + nmcd.clrText = OS.GetSysColor (OS.COLOR_GRAYTEXT); + if (findImageControl () != null) { + nmcd.clrTextBk = OS.CLR_NONE; + } else { + nmcd.clrTextBk = OS.GetSysColor (OS.COLOR_3DFACE); } + nmcd.uItemState &= ~OS.CDIS_SELECTED; + OS.MoveMemory (lParam, nmcd, NMLVCUSTOMDRAW.sizeof); + code |= OS.CDRF_NEWFONT; } return new LRESULT (code); } @@ -2746,21 +2747,25 @@ void sendEraseItemEvent (TableItem item, NMLVCUSTOMDRAW nmcd, int lParam) { GCData data = new GCData (); data.device = display; int clrSelectionBk = -1; + boolean drawSelected = false, drawBackground = false; if (OS.IsWindowEnabled (handle)) { if (selected && (nmcd.iSubItem == 0 || (style & SWT.FULL_SELECTION) != 0)) { if (OS.GetFocus () == handle) { + drawSelected = true; data.foreground = OS.GetSysColor (OS.COLOR_HIGHLIGHTTEXT); data.background = clrSelectionBk = OS.GetSysColor (OS.COLOR_HIGHLIGHT); } else { + drawSelected = (style & SWT.HIDE_SELECTION) == 0; data.foreground = OS.GetTextColor (hDC); data.background = clrSelectionBk = OS.GetSysColor (OS.COLOR_3DFACE); } } else { data.foreground = clrText != -1 ? clrText : OS.GetTextColor (hDC); data.background = clrTextBk != -1 ? clrTextBk : OS.GetBkColor (hDC); + drawBackground = clrTextBk != -1; } } else { - data.foreground = OS.GetTextColor (hDC); + data.foreground = OS.GetSysColor (OS.COLOR_GRAYTEXT); data.background = OS.GetSysColor (OS.COLOR_3DFACE); if (selected) clrSelectionBk = data.background; } @@ -2774,10 +2779,17 @@ void sendEraseItemEvent (TableItem item, NMLVCUSTOMDRAW nmcd, int lParam) { event.item = item; event.gc = gc; event.index = nmcd.iSubItem; + event.detail |= SWT.FOREGROUND; if ((nmcd.uItemState & OS.CDIS_FOCUS) != 0) { - event.detail |= SWT.FOCUSED; + if (nmcd.iSubItem == 0 || (style & SWT.FULL_SELECTION) != 0) { + if (handle == OS.GetFocus ()) { + int uiState = OS.SendMessage (handle, OS.WM_QUERYUISTATE, 0, 0); + if ((uiState & OS.UISF_HIDEFOCUS) == 0) event.detail |= SWT.FOCUSED; + } + } } - if (selected) event.detail |= SWT.SELECTED; + if (drawSelected) event.detail |= SWT.SELECTED; + if (drawBackground) event.detail |= SWT.BACKGROUND; event.x = cellRect.left; event.y = cellRect.top; event.width = cellRect.right - cellRect.left; @@ -2789,26 +2801,33 @@ void sendEraseItemEvent (TableItem item, NMLVCUSTOMDRAW nmcd, int lParam) { gc.dispose (); OS.RestoreDC (hDC, nSavedDC); if (isDisposed () || item.isDisposed ()) return; - if (selected) { - if ((event.detail & SWT.SELECTED) == 0) { - ignoreDrawSelected = true; + ignoreDraw = (event.detail & SWT.FOREGROUND) == 0; + ignoreDrawSelection = (event.detail & SWT.SELECTED) == 0; + ignoreDrawBackground = (event.detail & SWT.BACKGROUND) == 0; + if (drawSelected) { + if (ignoreDrawSelection) { if (nmcd.iSubItem == 0 || (style & SWT.FULL_SELECTION) != 0) { - textColor = clrSelectionText; + selectionForeground = clrSelectionText; } - nmcd.uItemState &= ~OS.CDIS_SELECTED; + nmcd.uItemState &= ~(OS.CDIS_SELECTED | OS.CDIS_FOCUS); OS.MoveMemory (lParam, nmcd, NMLVCUSTOMDRAW.sizeof); } } else { - if ((event.detail & SWT.SELECTED) != 0) { + if (ignoreDrawSelection) { nmcd.uItemState |= OS.CDIS_SELECTED; OS.MoveMemory (lParam, nmcd, NMLVCUSTOMDRAW.sizeof); } } - ignoreDraw = !event.doit; if (ignoreDraw) { - boolean fullText = (style & SWT.FULL_SELECTION) != 0; + int hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0); + boolean firstColumn = nmcd.iSubItem == OS.SendMessage (hwndHeader, OS.HDM_ORDERTOINDEX, 0, 0); + boolean fullText = (style & SWT.FULL_SELECTION) != 0 || !firstColumn; RECT clipRect = item.getBounds (nmcd.dwItemSpec, nmcd.iSubItem, true, true, fullText, false, hDC); - if (!ignoreDrawSelected && clrSelectionBk != -1) { + if (!ignoreDrawBackground && drawBackground) { + RECT backgroundRect = item.getBounds (nmcd.dwItemSpec, nmcd.iSubItem, true, false, true, false, hDC); + fillBackground (hDC, clrTextBk, backgroundRect); + } + if (!ignoreDrawSelection && clrSelectionBk != -1) { RECT textRect = item.getBounds (nmcd.dwItemSpec, nmcd.iSubItem, true, false, fullText, false, hDC); fillBackground (hDC, clrSelectionBk, textRect); } @@ -2961,14 +2980,16 @@ void sendPaintItemEvent (TableItem item, NMLVCUSTOMDRAW nmcd) { lvItem.stateMask = OS.LVIS_SELECTED; lvItem.iItem = nmcd.dwItemSpec; int result = OS.SendMessage (handle, OS.LVM_GETITEM, 0, lvItem); - boolean drawBackground = false; boolean selected = result != 0 && (lvItem.state & OS.LVIS_SELECTED) != 0; + boolean drawSelected = false, drawBackground = false; if (OS.IsWindowEnabled (handle)) { if (selected && (nmcd.iSubItem == 0 || (style & SWT.FULL_SELECTION) != 0)) { if (OS.GetFocus () == handle) { - data.foreground = textColor != -1 ? textColor : OS.GetSysColor (OS.COLOR_HIGHLIGHTTEXT); + drawSelected = true; + data.foreground = selectionForeground != -1 ? selectionForeground : OS.GetSysColor (OS.COLOR_HIGHLIGHTTEXT); data.background = OS.GetSysColor (OS.COLOR_HIGHLIGHT); } else { + drawSelected = (style & SWT.HIDE_SELECTION) == 0; data.foreground = OS.GetTextColor (hDC); data.background = OS.GetSysColor (OS.COLOR_3DFACE); } @@ -2982,7 +3003,7 @@ void sendPaintItemEvent (TableItem item, NMLVCUSTOMDRAW nmcd) { drawBackground = clrTextBk != -1; } } else { - data.foreground = OS.GetTextColor (hDC); + data.foreground = OS.GetSysColor (OS.COLOR_GRAYTEXT); data.background = OS.GetSysColor (OS.COLOR_3DFACE); } data.hPen = OS.CreatePen (OS.PS_SOLID, 0, data.foreground); @@ -2994,10 +3015,16 @@ void sendPaintItemEvent (TableItem item, NMLVCUSTOMDRAW nmcd) { event.item = item; event.gc = gc; event.index = nmcd.iSubItem; + event.detail |= SWT.FOREGROUND; if ((nmcd.uItemState & OS.CDIS_FOCUS) != 0) { - event.detail |= SWT.FOCUSED; + if (nmcd.iSubItem == 0 || (style & SWT.FULL_SELECTION) != 0) { + if (handle == OS.GetFocus ()) { + int uiState = OS.SendMessage (handle, OS.WM_QUERYUISTATE, 0, 0); + if ((uiState & OS.UISF_HIDEFOCUS) == 0) event.detail |= SWT.FOCUSED; + } + } } - if (selected) event.detail |= SWT.SELECTED; + if (drawSelected) event.detail |= SWT.SELECTED; if (drawBackground) event.detail |= SWT.BACKGROUND; event.x = itemRect.left; event.y = itemRect.top; diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TableItem.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TableItem.java index c9dcd99a60..a145748ff8 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TableItem.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/TableItem.java @@ -193,7 +193,7 @@ public Color getBackground (int index) { * * @since 3.1 */ -/*public*/ Rectangle getBounds () { +public Rectangle getBounds () { checkWidget(); if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED); int itemIndex = parent.indexOf (this); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Tree.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Tree.java index 2db3b78473..13d6c869de 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Tree.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Tree.java @@ -52,8 +52,8 @@ public class Tree extends Composite { boolean ignoreSelect, ignoreExpand, ignoreDeselect, ignoreResize; boolean lockSelection, oldSelected, newSelected, ignoreColumnMove; boolean linesVisible, customDraw, printClient, painted; - boolean ignoreDraw, ignoreDrawSelected, ignoreItemHeight; - int scrollWidth, headerToolTipHandle, textColor; + boolean ignoreItemHeight, ignoreDraw, ignoreDrawSelection, ignoreDrawBackground; + int scrollWidth, headerToolTipHandle, selectionForeground; static final int INSET = 3; static final int GRID_WIDTH = 1; static final int SORT_WIDTH = 10; @@ -310,7 +310,7 @@ LRESULT CDDS_ITEMPOSTPAINT (int wParam, int lParam) { */ if (nmcd.left >= nmcd.right || nmcd.top >= nmcd.bottom) return null; if (!OS.IsWindowVisible (handle)) return null; - if (findImageControl () != null || ignoreDrawSelected) { + if (findImageControl () != null || ignoreDrawSelection) { OS.SetBkMode (hDC, OS.TRANSPARENT); } boolean selected = false; @@ -406,13 +406,13 @@ LRESULT CDDS_ITEMPOSTPAINT (int wParam, int lParam) { RECT rect = new RECT (); if ((style & SWT.FULL_SELECTION) != 0) { OS.SetRect (rect, width, nmcd.top, nmcd.right, nmcd.bottom); - if ((selected || findImageControl () == null) && !ignoreDraw && !ignoreDrawSelected) { + if ((selected || findImageControl () == null) && !ignoreDrawSelection && !ignoreDrawBackground) { fillBackground (hDC, OS.GetBkColor (hDC), rect); } } } if (x + width > clientRect.left) { - RECT rect = new RECT (); + RECT rect = new RECT (), backgroundRect = null; boolean drawItem = true, drawText = true, drawImage = true, drawBackground = false; if (i == 0) { drawItem = drawImage = drawText = false; @@ -424,23 +424,30 @@ LRESULT CDDS_ITEMPOSTPAINT (int wParam, int lParam) { rect.bottom++; } } - if (selected && !ignoreDraw && !ignoreDrawSelected) { + if (selected && !ignoreDrawSelection && !ignoreDrawBackground) { fillBackground (hDC, OS.GetBkColor (hDC), rect); drawBackground = false; } + backgroundRect = rect; if (hooks (SWT.EraseItem)) { drawItem = drawText = drawImage = true; rect = item.getBounds (index, true, true, false, false, true, hDC); + if ((style & SWT.FULL_SELECTION) != 0) { + backgroundRect = rect; + } else { + backgroundRect = item.getBounds (index, true, false, false, false, true, hDC); + } } } else { - textColor = -1; - ignoreDraw = ignoreDrawSelected = false; + selectionForeground = -1; + ignoreDraw = ignoreDrawSelection = ignoreDrawBackground = false; OS.SetRect (rect, x, nmcd.top, x + width, nmcd.bottom - gridWidth); + backgroundRect = rect; } int clrText = -1, clrTextBk = -1; int hFont = item.cellFont != null ? item.cellFont [index] : -1; if (hFont == -1) hFont = item.font; - if (textColor != -1) clrText = textColor; + if (selectionForeground != -1) clrText = selectionForeground; if (OS.IsWindowEnabled (handle)) { boolean drawForeground = false; if (selected) { @@ -494,8 +501,12 @@ LRESULT CDDS_ITEMPOSTPAINT (int wParam, int lParam) { int nSavedDC = OS.SaveDC (hDC); GCData data = new GCData (); data.device = display; - data.foreground = clrText != -1 ? clrText : OS.GetTextColor (hDC); - data.background = clrTextBk != -1 ? clrTextBk : OS.GetBkColor (hDC); + data.foreground = OS.GetTextColor (hDC); + data.background = OS.GetBkColor (hDC); + if (!selected) { + if (clrText != -1) data.foreground = clrText; + if (clrTextBk != -1) data.background = clrTextBk; + } data.hPen = OS.CreatePen (OS.PS_SOLID, 0, data.foreground); data.hBrush = OS.CreateSolidBrush (data.background); data.hFont = hFont; @@ -504,8 +515,17 @@ LRESULT CDDS_ITEMPOSTPAINT (int wParam, int lParam) { event.item = item; event.index = index; event.gc = gc; - if (selected) event.detail |= SWT.SELECTED; - if ((nmcd.uItemState & OS.CDIS_FOCUS) != 0) event.detail |= SWT.FOCUSED; + event.detail |= SWT.FOREGROUND; + if (clrTextBk != -1) event.detail |= SWT.BACKGROUND; + if (selected && (style & SWT.FULL_SELECTION) != 0) event.detail |= SWT.SELECTED; + if ((nmcd.uItemState & OS.CDIS_FOCUS) != 0) { + if (/*nmcd.iSubItem == 0 ||*/ (style & SWT.FULL_SELECTION) != 0) { + if (handle == OS.GetFocus ()) { + int uiState = OS.SendMessage (handle, OS.WM_QUERYUISTATE, 0, 0); + if ((uiState & OS.UISF_HIDEFOCUS) == 0) event.detail |= SWT.FOCUSED; + } + } + } event.x = cellRect.left; event.y = cellRect.top; event.width = cellRect.right - cellRect.left; @@ -517,21 +537,22 @@ LRESULT CDDS_ITEMPOSTPAINT (int wParam, int lParam) { gc.dispose (); OS.RestoreDC (hDC, nSavedDC); if (isDisposed () || item.isDisposed ()) break; - ignoreDraw = !event.doit; - if ((event.detail & SWT.SELECTED) != 0) { + ignoreDraw = (event.detail & SWT.FOREGROUND) == 0; + ignoreDrawSelection = (event.detail & SWT.SELECTED) == 0; + ignoreDrawBackground = (event.detail & SWT.BACKGROUND) == 0; + if (!ignoreDrawSelection) { if (!selected) { - textColor = OS.GetSysColor (OS.COLOR_HIGHLIGHTTEXT); + selectionForeground = OS.GetSysColor (OS.COLOR_HIGHLIGHTTEXT); } } else { - if (selected) textColor = newTextClr; - ignoreDrawSelected = true; + if (selected) selectionForeground = newTextClr; } } - if (textColor != -1) clrText = textColor; + if (selectionForeground != -1) clrText = selectionForeground; } - if (!ignoreDraw && !ignoreDrawSelected) { + if (!ignoreDrawBackground) { if (clrTextBk != -1) { - if (drawBackground) fillBackground (hDC, clrTextBk, rect); + if (drawBackground) fillBackground (hDC, clrTextBk, backgroundRect); } else { Control control = findImageControl (); if (control != null) { @@ -539,16 +560,18 @@ LRESULT CDDS_ITEMPOSTPAINT (int wParam, int lParam) { int right = Math.min (rect.right, width); OS.SetRect (rect, rect.left, rect.top, right, rect.bottom); if (drawBackground) fillImageBackground (hDC, control, rect); - if (handle == OS.GetFocus ()) { - int uiState = OS.SendMessage (handle, OS.WM_QUERYUISTATE, 0, 0); - if ((uiState & OS.UISF_HIDEFOCUS) == 0) { - int hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_CARET, 0); - if (hItem == item.handle) { - if ((style & SWT.FULL_SELECTION) != 0) { - focusRect = new RECT (); - OS.SetRect (focusRect, nmcd.left, nmcd.top, nmcd.right, nmcd.bottom); - } else { - focusRect = item.getBounds (index, true, false, false, false, true, hDC); + if (!ignoreDrawSelection) { + if (handle == OS.GetFocus ()) { + int uiState = OS.SendMessage (handle, OS.WM_QUERYUISTATE, 0, 0); + if ((uiState & OS.UISF_HIDEFOCUS) == 0) { + int hItem = OS.SendMessage (handle, OS.TVM_GETNEXTITEM, OS.TVGN_CARET, 0); + if (hItem == item.handle) { + if ((style & SWT.FULL_SELECTION) != 0) { + focusRect = new RECT (); + OS.SetRect (focusRect, nmcd.left, nmcd.top, nmcd.right, nmcd.bottom); + } else { + focusRect = item.getBounds (index, true, false, false, false, true, hDC); + } } } } @@ -626,15 +649,19 @@ LRESULT CDDS_ITEMPOSTPAINT (int wParam, int lParam) { } } } - if (textColor != -1) clrText = textColor; + if (selectionForeground != -1) clrText = selectionForeground; if (hooks (SWT.PaintItem)) { RECT itemRect = item.getBounds (index, true, true, false, false, false, hDC); int nSavedDC = OS.SaveDC (hDC); GCData data = new GCData (); data.device = display; data.hFont = hFont; - data.foreground = clrText != -1 ? clrText : OS.GetTextColor (hDC); - data.background = clrTextBk != -1 ? clrTextBk : OS.GetBkColor (hDC); + data.foreground = OS.GetTextColor (hDC); + data.background = OS.GetBkColor (hDC); + if (!selected) { + if (clrText != -1) data.foreground = clrText; + if (clrTextBk != -1) data.background = clrTextBk; + } data.hPen = OS.CreatePen (OS.PS_SOLID, 0, data.foreground); data.hBrush = OS.CreateSolidBrush (data.background); OS.SelectObject (hDC, data.hPen); @@ -644,9 +671,19 @@ LRESULT CDDS_ITEMPOSTPAINT (int wParam, int lParam) { event.item = item; event.index = index; event.gc = gc; - if (selected) event.detail |= SWT.SELECTED; - if ((nmcd.uItemState & OS.CDIS_FOCUS) != 0) event.detail |= SWT.FOCUSED; + event.detail |= SWT.FOREGROUND; if (clrTextBk != -1) event.detail |= SWT.BACKGROUND; + if (selected && (i == 0 /*nmcd.iSubItem == 0*/ || (style & SWT.FULL_SELECTION) != 0)) { + event.detail |= SWT.SELECTED; + } + if ((nmcd.uItemState & OS.CDIS_FOCUS) != 0) { + if (i == 0 /*nmcd.iSubItem == 0*/ || (style & SWT.FULL_SELECTION) != 0) { + if (handle == OS.GetFocus ()) { + int uiState = OS.SendMessage (handle, OS.WM_QUERYUISTATE, 0, 0); + if ((uiState & OS.UISF_HIDEFOCUS) == 0) event.detail |= SWT.FOCUSED; + } + } + } event.x = itemRect.left; event.y = itemRect.top; event.width = itemRect.right - itemRect.left; @@ -816,18 +853,27 @@ LRESULT CDDS_ITEMPREPAINT (int wParam, int lParam) { ignoreItemHeight = true; } } - textColor = -1; - ignoreDraw = ignoreDrawSelected = false; + selectionForeground = -1; + ignoreDraw = ignoreDrawSelection = ignoreDrawBackground = false; if (hooks (SWT.EraseItem)) { RECT rect = new RECT (); OS.SetRect (rect, nmcd.left, nmcd.top, nmcd.right, nmcd.bottom); drawBackground (hDC, rect); - RECT cellRect = item.getBounds (index, true, true, true, true, true, hDC); + RECT cellRect = null; + if ((style & SWT.FULL_SELECTION) != 0 && count == 0) { + cellRect = item.getBounds (index, true, true, true, true, true, hDC); + } else { + cellRect = item.getBounds (index, true, true, false, false, true, hDC); + } int nSavedDC = OS.SaveDC (hDC); GCData data = new GCData (); data.device = display; - data.foreground = clrText != -1 ? clrText : OS.GetTextColor (hDC); - data.background = clrTextBk != -1 ? clrTextBk : OS.GetBkColor (hDC); + data.foreground = OS.GetTextColor (hDC); + data.background = OS.GetBkColor (hDC); + if (!selected) { + if (clrText != -1) data.foreground = clrText; + if (clrTextBk != -1) data.background = clrTextBk; + } data.hPen = OS.CreatePen (OS.PS_SOLID, 0, data.foreground); data.hBrush = OS.CreateSolidBrush (data.background); if (hFont != -1) data.hFont = hFont; @@ -838,8 +884,17 @@ LRESULT CDDS_ITEMPREPAINT (int wParam, int lParam) { event.index = index; event.item = item; event.gc = gc; + event.detail |= SWT.FOREGROUND; + if (clrTextBk != -1) event.detail |= SWT.BACKGROUND; if (selected) event.detail |= SWT.SELECTED; - if ((nmcd.uItemState & OS.CDIS_FOCUS) != 0) event.detail |= SWT.FOCUSED; + if ((nmcd.uItemState & OS.CDIS_FOCUS) != 0) { + if (/*nmcd.iSubItem == 0 ||*/ (style & SWT.FULL_SELECTION) != 0) { + if (handle == OS.GetFocus ()) { + int uiState = OS.SendMessage (handle, OS.WM_QUERYUISTATE, 0, 0); + if ((uiState & OS.UISF_HIDEFOCUS) == 0) event.detail |= SWT.FOCUSED; + } + } + } event.x = cellRect.left; event.y = cellRect.top; event.width = cellRect.right - cellRect.left; @@ -851,10 +906,20 @@ LRESULT CDDS_ITEMPREPAINT (int wParam, int lParam) { gc.dispose (); OS.RestoreDC (hDC, nSavedDC); if (isDisposed () || item.isDisposed ()) return null; - ignoreDraw = !event.doit; - if ((event.detail & SWT.SELECTED) != 0) { + ignoreDraw = (event.detail & SWT.FOREGROUND) == 0; + ignoreDrawSelection = (event.detail & SWT.SELECTED) == 0; + ignoreDrawBackground = (event.detail & SWT.BACKGROUND) == 0; + if (!selected && !ignoreDrawBackground && clrTextBk != -1) { + if ((style & SWT.FULL_SELECTION) != 0 && count == 0) { + fillBackground (hDC, clrTextBk, rect); + } else { + RECT backgroundRect = item.getBounds (index, true, false, true, false, true, hDC); + fillBackground (hDC, clrTextBk, backgroundRect); + } + } + if (!ignoreDrawSelection) { if (!selected) { - textColor = clrText = OS.GetSysColor (OS.COLOR_HIGHLIGHTTEXT); + selectionForeground = clrText = OS.GetSysColor (OS.COLOR_HIGHLIGHTTEXT); } /* * Feature in Windows. When the tree has the style @@ -871,8 +936,8 @@ LRESULT CDDS_ITEMPREPAINT (int wParam, int lParam) { } } else { if (selected) { - textColor = clrText = newTextClr; - ignoreDrawSelected = true; + selectionForeground = clrText = newTextClr; + ignoreDrawSelection = true; } } RECT itemRect = item.getBounds (index, true, true, false, false, false, hDC); |