summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSilenio Quarti <silenio>2006-03-20 20:23:50 +0000
committerSilenio Quarti <silenio>2006-03-20 20:23:50 +0000
commit8aec71c6494fc7005fd705025c1598018aa78fdd (patch)
tree697d1b8e37cefc62e430ac6bdd25ce0d46c04e03
parent642c99978dc17bd02e442edba68d88ae6a941ded (diff)
downloadeclipse.platform.swt-8aec71c6494fc7005fd705025c1598018aa78fdd.tar.gz
eclipse.platform.swt-8aec71c6494fc7005fd705025c1598018aa78fdd.tar.xz
eclipse.platform.swt-8aec71c6494fc7005fd705025c1598018aa78fdd.zip
owner draw tree/table
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Table.java38
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/TableItem.java32
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Tree.java59
3 files changed, 82 insertions, 47 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Table.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Table.java
index 7a3547fa44..49407764e4 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Table.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Table.java
@@ -1025,10 +1025,11 @@ int drawItemProc (int browser, int id, int property, int itemState, int theRect,
gc.setClipping (region);
gc.setFont (font);
}
- boolean draw = true;
- boolean selected = (itemState & (OS.kDataBrowserItemIsSelected | OS.kDataBrowserItemIsDragTarget)) != 0, wasSelected = selected;
- boolean itemBg = item.background != null || (item.cellBackground != null && item.cellBackground [columnIndex] != null);
- if (selected && ((style & SWT.FULL_SELECTION) != 0 || columnIndex == 0)) {
+ int drawState = SWT.FOREGROUND;
+ if (item.background != null || (item.cellBackground != null && item.cellBackground [columnIndex] != null)) drawState |= SWT.BACKGROUND;
+ if ((itemState & (OS.kDataBrowserItemIsSelected | OS.kDataBrowserItemIsDragTarget)) != 0) drawState |= SWT.SELECTED;
+ boolean wasSelected = (drawState & SWT.SELECTED) != 0;
+ if ((drawState & SWT.SELECTED) != 0 && ((style & SWT.FULL_SELECTION) != 0 || columnIndex == 0)) {
gc.setBackground (display.getSystemColor (SWT.COLOR_LIST_SELECTION));
gc.setForeground (display.getSystemColor (SWT.COLOR_LIST_SELECTION_TEXT));
} else {
@@ -1044,14 +1045,12 @@ int drawItemProc (int browser, int id, int property, int itemState, int theRect,
event.y = itemY;
event.width = itemWidth;
event.height = itemHeight;
- if (selected) event.detail |= SWT.SELECTED;
- if (itemBg) event.detail |= SWT.BACKGROUND;
+ event.detail = drawState;
sendEvent (SWT.EraseItem, event);
- draw = event.doit;
- selected = (event.detail & SWT.SELECTED) != 0;
+ drawState = event.detail;
gc.setClipping (region);
gc.setFont (font);
- if (selected && ((style & SWT.FULL_SELECTION) != 0 || columnIndex == 0)) {
+ if ((drawState & SWT.SELECTED) != 0 && ((style & SWT.FULL_SELECTION) != 0 || columnIndex == 0)) {
gc.setBackground (display.getSystemColor (SWT.COLOR_LIST_SELECTION));
gc.setForeground (display.getSystemColor (SWT.COLOR_LIST_SELECTION_TEXT));
} else {
@@ -1065,26 +1064,24 @@ int drawItemProc (int browser, int id, int property, int itemState, int theRect,
if ((column.style & SWT.RIGHT) != 0) x += width - contentWidth;
}
int stringX = x;
- boolean drawBackground = itemBg;
if (image != null) stringX += this.imageBounds.width + gap;
- if (selected && ((style & SWT.FULL_SELECTION) != 0 || columnIndex == 0)) {
+ if ((drawState & SWT.SELECTED) != 0 && ((style & SWT.FULL_SELECTION) != 0 || columnIndex == 0)) {
if ((style & SWT.HIDE_SELECTION) == 0 || hasFocus ()) {
if ((style & SWT.FULL_SELECTION) != 0) {
gc.fillRectangle (itemX, itemY, itemWidth, itemHeight - 1);
- drawBackground = false;
+ drawState &= ~SWT.BACKGROUND;
} else if (columnIndex == 0) {
gc.fillRectangle (stringX - 1, y, extent.x + 2, itemHeight - 1);
- drawBackground = false;
+ drawState &= ~SWT.BACKGROUND;
}
} else {
- //TODO - funny thing
- if (itemBg) gc.setBackground (background);
+ if ((drawState & SWT.BACKGROUND) != 0) gc.setBackground (background);
}
}
- if (draw) {
- if (drawBackground) {
- gc.fillRectangle (itemX, itemY, itemWidth, itemHeight);
- }
+ if ((drawState & SWT.BACKGROUND) != 0) {
+ gc.fillRectangle (itemX, itemY, itemWidth, itemHeight);
+ }
+ if ((drawState & SWT.FOREGROUND) != 0) {
if (image != null) {
int imageX = x, imageY = y + (height - this.imageBounds.height) / 2;
gc.drawImage (image, 0, 0, imageBounds.width, imageBounds.height, imageX, imageY, this.imageBounds.width, this.imageBounds.height);
@@ -1100,8 +1097,7 @@ int drawItemProc (int browser, int id, int property, int itemState, int theRect,
event.y = y;
event.width = paintWidth;
event.height = itemHeight;
- if (selected) event.detail |= SWT.SELECTED;
- if (itemBg) event.detail |= SWT.BACKGROUND;
+ event.detail = drawState;
sendEvent (SWT.PaintItem, event);
}
OS.CGContextRestoreGState (gc.handle);
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/TableItem.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/TableItem.java
index 5a184377f6..58119fb33a 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/TableItem.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/TableItem.java
@@ -211,6 +211,38 @@ public Color getBackground (int index) {
return cellBackground [index];
}
+public Rectangle getBounds () {
+ checkWidget ();
+ if (!parent.checkData (this, true)) error (SWT.ERROR_WIDGET_DISPOSED);
+ Rect rect = new Rect();
+ int itemIndex = parent.indexOf (this);
+ int id = itemIndex + 1;
+ int columnId = parent.columnCount == 0 ? parent.column_id : parent.columns [0].id;
+ if (OS.GetDataBrowserItemPartBounds (parent.handle, id, columnId, OS.kDataBrowserPropertyContentPart, rect) != OS.noErr) {
+ return new Rectangle (0, 0, 0, 0);
+ }
+ int x = rect.left, y = rect.top;
+ int width = 0;
+ if (image != null) {
+ Rectangle bounds = image.getBounds ();
+ x += bounds.width + 2;
+ }
+ GC gc = new GC (parent);
+ Point extent = gc.stringExtent (text);
+ gc.dispose ();
+ width += extent.x;
+ if (parent.columnCount > 0) {
+ width = Math.min (width, rect.right - x);
+ }
+ int height = rect.bottom - rect.top;
+ if (!OS.HIVIEW) {
+ OS.GetControlBounds (parent.handle, rect);
+ x -= rect.left;
+ y -= rect.top;
+ }
+ return new Rectangle (x, y, width, height);
+}
+
/**
* Returns a rectangle describing the receiver's size and location
* relative to its parent at a column in the table.
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Tree.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Tree.java
index bb95f1589d..5a39e00979 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Tree.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Tree.java
@@ -1008,7 +1008,9 @@ int drawItemProc (int browser, int id, int property, int itemState, int theRect,
Color background = item.getBackground (columnIndex);
Color foreground = item.getForeground (columnIndex);
Image image = item.getImage (columnIndex);
- String text = item.getText (columnIndex);
+ String text = item.getText (columnIndex);
+ gc.setClipping (region);
+ gc.setFont (font);
Point extent = gc.stringExtent (text);
int contentWidth = extent.x;
Rectangle imageBounds = null;
@@ -1019,8 +1021,6 @@ int drawItemProc (int browser, int id, int property, int itemState, int theRect,
contentWidth += this.imageBounds.width + gap;
}
int paintWidth = contentWidth;
- gc.setClipping (region);
- gc.setFont (font);
if (hooks (SWT.MeasureItem)) {
Event event = new Event ();
event.item = item;
@@ -1041,9 +1041,11 @@ int drawItemProc (int browser, int id, int property, int itemState, int theRect,
gc.setClipping (region);
gc.setFont (font);
}
- boolean draw = true;
- boolean selected = (itemState & (OS.kDataBrowserItemIsSelected | OS.kDataBrowserItemIsDragTarget)) != 0, wasSelected = selected;
- if (selected) {
+ int drawState = SWT.FOREGROUND;
+ if (item.background != null || (item.cellBackground != null && item.cellBackground [columnIndex] != null)) drawState |= SWT.BACKGROUND;
+ if ((itemState & (OS.kDataBrowserItemIsSelected | OS.kDataBrowserItemIsDragTarget)) != 0) drawState |= SWT.SELECTED;
+ boolean wasSelected = (drawState & SWT.SELECTED) != 0;
+ if ((drawState & SWT.SELECTED) != 0 && ((style & SWT.FULL_SELECTION) != 0 || columnIndex == 0)) {
gc.setBackground (display.getSystemColor (SWT.COLOR_LIST_SELECTION));
gc.setForeground (display.getSystemColor (SWT.COLOR_LIST_SELECTION_TEXT));
} else {
@@ -1059,13 +1061,12 @@ int drawItemProc (int browser, int id, int property, int itemState, int theRect,
event.y = itemY;
event.width = itemWidth;
event.height = itemHeight;
- if (selected) event.detail |= SWT.SELECTED;
+ event.detail = drawState;
sendEvent (SWT.EraseItem, event);
- draw = event.doit;
- selected = (event.detail & SWT.SELECTED) != 0;
+ drawState = event.detail;
gc.setClipping (region);
gc.setFont (font);
- if (selected) {
+ if ((drawState & SWT.SELECTED) != 0 && ((style & SWT.FULL_SELECTION) != 0 || columnIndex == 0)) {
gc.setBackground (display.getSystemColor (SWT.COLOR_LIST_SELECTION));
gc.setForeground (display.getSystemColor (SWT.COLOR_LIST_SELECTION_TEXT));
} else {
@@ -1073,27 +1074,33 @@ int drawItemProc (int browser, int id, int property, int itemState, int theRect,
if (!wasSelected) gc.setForeground (foreground);
}
}
- if (draw) {
- if (columnCount != 0) {
- TreeColumn column = columns [columnIndex];
- if ((column.style & SWT.CENTER) != 0) x += (width - contentWidth) / 2;
- if ((column.style & SWT.RIGHT) != 0) x += width - contentWidth;
- }
- int stringX = x, imageX = x;
- if (image != null) stringX += this.imageBounds.width + gap;
- if (selected && ((style & SWT.HIDE_SELECTION) == 0 || hasFocus ())) {
+ if (columnCount != 0) {
+ TreeColumn column = columns [columnIndex];
+ if ((column.style & SWT.CENTER) != 0) x += (width - contentWidth) / 2;
+ if ((column.style & SWT.RIGHT) != 0) x += width - contentWidth;
+ }
+ int stringX = x;
+ if (image != null) stringX += this.imageBounds.width + gap;
+ if ((drawState & SWT.SELECTED) != 0 && ((style & SWT.FULL_SELECTION) != 0 || columnIndex == 0)) {
+ if ((style & SWT.HIDE_SELECTION) == 0 || hasFocus ()) {
if ((style & SWT.FULL_SELECTION) != 0) {
gc.fillRectangle (itemX, itemY, itemWidth, itemHeight - 1);
+ drawState &= ~SWT.BACKGROUND;
} else if (columnIndex == 0) {
gc.fillRectangle (stringX - 1, y, extent.x + 2, itemHeight - 1);
+ drawState &= ~SWT.BACKGROUND;
}
- } else {
- if (item.background != null || (item.cellBackground != null && item.cellBackground [columnIndex] != null)) {
- gc.fillRectangle (itemX, itemY, itemWidth, itemHeight);
- }
- }
+ } else {
+ if ((drawState & SWT.BACKGROUND) != 0) gc.setBackground (background);
+ }
+ }
+ if ((drawState & SWT.BACKGROUND) != 0) {
+ gc.fillRectangle (itemX, itemY, itemWidth, itemHeight);
+ }
+ if ((drawState & SWT.FOREGROUND) != 0) {
if (image != null) {
- gc.drawImage (image, 0, 0, imageBounds.width, imageBounds.height, imageX, y + (height - this.imageBounds.height) / 2, this.imageBounds.width, this.imageBounds.height);
+ int imageX = x, imageY = y + (height - this.imageBounds.height) / 2;
+ gc.drawImage (image, 0, 0, imageBounds.width, imageBounds.height, imageX, imageY, this.imageBounds.width, this.imageBounds.height);
}
gc.drawString (text, stringX, y + (height - extent.y) / 2, true);
}
@@ -1106,7 +1113,7 @@ int drawItemProc (int browser, int id, int property, int itemState, int theRect,
event.y = y;
event.width = paintWidth;
event.height = itemHeight;
- if (selected) event.detail |= SWT.SELECTED;
+ event.detail = drawState;
sendEvent (SWT.PaintItem, event);
}
OS.CGContextRestoreGState (gc.handle);