summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGrant Gayed <ggayed>2008-06-17 20:51:39 +0000
committerGrant Gayed <ggayed>2008-06-17 20:51:39 +0000
commit96ead799b163f69c971718d08e432a475bbcdbbc (patch)
tree867830d8796d6deecd718d3cb098a2f311f2124d
parente31d17ab01c6499c992488bb2508d677cae42d4c (diff)
downloadeclipse.platform.swt-96ead799b163f69c971718d08e432a475bbcdbbc.tar.gz
eclipse.platform.swt-96ead799b163f69c971718d08e432a475bbcdbbc.tar.xz
eclipse.platform.swt-96ead799b163f69c971718d08e432a475bbcdbbc.zip
tree column pack
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Tree.java7
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/TreeColumn.java22
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/TreeItem.java63
3 files changed, 58 insertions, 34 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Tree.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Tree.java
index b965d2ee2a..c91e9df1b0 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Tree.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Tree.java
@@ -82,6 +82,7 @@ public class Tree extends Composite {
TreeColumn sortColumn;
int columnCount;
int sortDirection;
+ float levelIndent;
boolean ignoreExpand, ignoreSelect;
/**
@@ -419,6 +420,7 @@ void createHandle () {
cell.setLeaf(true);
firstColumn.setDataCell(cell);
cell.release();
+ levelIndent = widget.indentationPerLevel();
scrollView = scrollWidget;
view = widget;
@@ -967,6 +969,11 @@ public boolean getHeaderVisible () {
return ((NSTableView)view).headerView() != null;
}
+int getInsetWidth () {
+ //TODO - wrong
+ return 20;
+}
+
/**
* Returns the item at the given, zero-relative index in the
* receiver. Throws an exception if the index is out of range.
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/TreeColumn.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/TreeColumn.java
index 29749886ee..cc09d9687f 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/TreeColumn.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/TreeColumn.java
@@ -324,16 +324,18 @@ public int getWidth () {
*/
public void pack () {
checkWidget ();
-// GC gc = new GC (parent);
-// int width = gc.stringExtent (text).x;
- //TODO extra header
-// int index = parent.indexOf (this);
-// width = Math.max (width, calculateWidth (parent.childIds, index, gc, width));
-//
-// gc.dispose ();
-// setWidth (width + parent.getInsetWidth (id, true));
- //TODO this only takes care of the header
- nsColumn.sizeToFit();
+ GC gc = new GC (parent);
+ int width = gc.stringExtent (text).x;
+ //TODO header extra
+ int index = parent.indexOf (this);
+ for (int i=0; i<parent.itemCount; i++) {
+ TreeItem item = parent.items [i];
+ if (item != null && item.cached) {
+ width = Math.max (width, item.calculateWidth (index, gc, true));
+ }
+ }
+ gc.dispose ();
+ setWidth (width + parent.getInsetWidth ());
}
void releaseHandle () {
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/TreeItem.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/TreeItem.java
index 6d06587b53..2356b7c7e8 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/TreeItem.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/TreeItem.java
@@ -221,31 +221,46 @@ static int checkIndex (int index) {
return index;
}
-int calculateWidth (int index, GC gc) {
- if (index == 0 && width != -1) return width;
+int calculateWidth (int index, GC gc, boolean recurse) {
int width = 0;
- Image image = getImage (index);
- String text = getText (index);
- gc.setFont (getFont (index));
-// if (image != null) width += image.getBounds ().width + parent.getGap ();
- if (text != null && text.length () > 0) width += gc.stringExtent (text).x;
-// if (parent.hooks (SWT.MeasureItem)) {
-// Event event = new Event ();
-// event.item = this;
-// event.index = index;
-// event.gc = gc;
-// short [] height = new short [1];
-// OS.GetDataBrowserTableViewRowHeight (parent.handle, height);
-// event.width = width;
-// event.height = height [0];
-// parent.sendEvent (SWT.MeasureItem, event);
-// if (parent.itemHeight < event.height) {
-// parent.itemHeight = event.height;
-// OS.SetDataBrowserTableViewRowHeight (parent.handle, (short) event.height);
-// }
-// width = event.width;
-// }
- if (index == 0) this.width = width;
+ if (index == 0 && this.width != -1) {
+ width = this.width;
+ } else {
+ Image image = getImage (index);
+ String text = getText (index);
+ gc.setFont (getFont (index));
+ // if (image != null) width += image.getBounds ().width + parent.getGap ();
+ if (text != null && text.length () > 0) width += gc.stringExtent (text).x;
+ // if (parent.hooks (SWT.MeasureItem)) {
+ // Event event = new Event ();
+ // event.item = this;
+ // event.index = index;
+ // event.gc = gc;
+ // short [] height = new short [1];
+ // OS.GetDataBrowserTableViewRowHeight (parent.handle, height);
+ // event.width = width;
+ // event.height = height [0];
+ // parent.sendEvent (SWT.MeasureItem, event);
+ // if (parent.itemHeight < event.height) {
+ // parent.itemHeight = event.height;
+ // OS.SetDataBrowserTableViewRowHeight (parent.handle, (short) event.height);
+ // }
+ // width = event.width;
+ // }
+ if (index == 0) {
+ int level = ((NSOutlineView)parent.view).levelForItem(handle);
+ width += parent.levelIndent * level;
+ this.width = width;
+ }
+ }
+ if (recurse && expanded) {
+ for (int i = 0; i < items.length; i++) {
+ TreeItem item = items [i];
+ if (item != null && item.cached) {
+ width = Math.max(width, item.calculateWidth(index, gc, recurse));
+ }
+ }
+ }
return width;
}