Bug 446534 - [10.10] Table/tree with column headers visible has issues
on OS X 10.10 Yosemite - fixes remaining issues with Control Example
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Table.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Table.java
index e40a289..1de3279 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Table.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Table.java
@@ -79,7 +79,7 @@
 	Rectangle imageBounds;
 	
 	/* Used to control drop feedback when FEEDBACK_SCROLL is set/not set */
-	boolean shouldScroll = true;
+	boolean shouldScroll = true, fixOrigin;
 
 	static int NEXT_ID;
 
@@ -1169,6 +1169,10 @@
 
 void drawRect(long /*int*/ id, long /*int*/ sel, NSRect rect) {
 	fixScrollWidth = false;
+	if (fixOrigin) {
+		fixOrigin = false;
+		fixTableOrigin();
+	}
 	super.drawRect(id, sel, rect);
 	if (isDisposed ()) return;
 	if (fixScrollWidth) {
@@ -2440,20 +2444,23 @@
 	((NSTableView) view).setBackgroundColor (nsColor);
 }
 
-void setBounds(int x, int y, int width, int height, boolean move, boolean resize) {
+void fixTableOrigin () {
 	/*
 	 * Bug on OSX 10.10: The scrollview's content view and the table's header view have the same origin. 
 	 * This causes the first row of the NSTableView to be hidden by header view.
 	 * Set the origin of NSTableView so that it is positioned below the header view.
 	 */
-	super.setBounds (x, y, width, height, move, resize);
 	NSTableView tableView = (NSTableView) view;
-	if ((tableView.headerView() != null) && (OS.VERSION_MMB >= OS.VERSION_MMB(10, 10, 0))) {
-		NSPoint pt = new NSPoint();
-		NSRect headerRect = headerView.frame();
-		pt.y = headerRect.y + headerRect.height;
-		view.setFrameOrigin(pt);
-		view.setNeedsDisplay(true);
+	if ((OS.VERSION_MMB >= OS.VERSION_MMB (10, 10, 0))) {
+		NSPoint pt = new NSPoint ();
+		NSRect headerRect = headerView.frame ();
+		if (tableView.headerView () != null) {
+			pt.y = headerRect.y + headerRect.height;
+		} else {
+			pt.y = 0;
+		}
+		view.setFrameOrigin (pt);
+		view.setNeedsDisplay (true);
 	}
 }
 
@@ -2555,6 +2562,7 @@
  */
 public void setHeaderVisible (boolean show) {
 	checkWidget ();
+	fixOrigin = true;
 	((NSTableView)view).setHeaderView (show ? headerView : null);
 	scrollView.tile();
 }
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 05bec32..de931fc 100644
--- 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
@@ -90,7 +90,7 @@
 	boolean insertBefore;
 	
 	/* Used to control drop feedback when DND.FEEDBACK_EXPAND and DND.FEEDBACK_SCROLL is set/not set */
-	boolean shouldExpand = true, shouldScroll = true;
+	boolean shouldExpand = true, shouldScroll = true, fixOrigin;
 
 	static int NEXT_ID;
 
@@ -1244,6 +1244,15 @@
 	}
 }
 
+@Override
+void drawRect (long /*int*/ id, long /*int*/ sel, NSRect /*int*/ rect) {
+	if (fixOrigin) {
+		fixOrigin = false;
+		fixTreeOrigin ();
+	}
+	super.drawRect (id, sel, rect);
+}
+
 void drawWithExpansionFrame_inView (long /*int*/ id, long /*int*/ sel, NSRect cellFrame, long /*int*/ view) {
 	drawExpansion = true;
 	super.drawWithExpansionFrame_inView(id, sel, cellFrame, view);
@@ -2705,20 +2714,23 @@
 	((NSTableView) view).setBackgroundColor (nsColor);
 }
 
-void setBounds(int x, int y, int width, int height, boolean move, boolean resize) {
+void fixTreeOrigin () {
 	/*
 	 * Bug on OSX 10.10: The scrollview's content view and the tree's header view have the same origin. 
 	 * This causes the first row of the NSOutlineView to be hidden by header view.
 	 * Set the origin of NSOutlineView so that it is positioned below the header view.
 	 */
-	super.setBounds (x, y, width, height, move, resize);
 	NSOutlineView widget = (NSOutlineView) view;
-	if ((widget.headerView() != null) && (OS.VERSION_MMB >= OS.VERSION_MMB(10, 10, 0))) {
+	if (OS.VERSION_MMB >= OS.VERSION_MMB (10, 10, 0)) {
 		NSPoint pt = new NSPoint();
-		NSRect headerRect = headerView.frame();
-		pt.y = headerRect.y + headerRect.height;
-		view.setFrameOrigin(pt);
-		view.setNeedsDisplay(true);
+		NSRect headerRect = headerView.frame ();
+		if (widget.headerView() != null) {
+			pt.y = headerRect.y + headerRect.height;
+		} else {
+			pt.y = 0;
+		}
+		view.setFrameOrigin (pt);
+		view.setNeedsDisplay (true);
 	}
 }
 
@@ -2823,6 +2835,7 @@
  */
 public void setHeaderVisible (boolean show) {
 	checkWidget ();
+	fixOrigin = true;
 	((NSOutlineView) view).setHeaderView (show ? headerView : null);
 	scrollView.tile();
 }