Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[platform-swt-dev] mac os x port: native Tree patches


Hi,
I implemented the grayed property in Tree/TreeItem from carbon2.

What I did:
1. Added the boolean field "grayed" to "TreeItem" and implemented the methods "get/setGrayed" 2. Extended functionality of "Tree´s" "itemDataProc" so that it sets the grayed property correctly and sends corresponding events. 3. Adjusted "Tree´s" "itemNotification" due to strange behaviour when the twistie or the checkbox was doubleClicked. -> The behavior now is not to send a "SWT.DefaultSelection" event after twistie or checkbox have been hit twice.
4. Added three constants to "OS".
5. Tested against Junit Tests. -> Didn´t get worse because of new functionality.
6. Tested in slefhosted eclipse.		-> see above.

Here are the files:


Index: OS.java
===================================================================
RCS file: /home/eclipse/org.eclipse.swt/Eclipse SWT PI/carbon/org/eclipse/swt/internal/carbon/OS.java,v
retrieving revision 1.66
diff -u -r1.66 OS.java
--- OS.java	19 Dec 2002 22:17:28 -0000	1.66
+++ OS.java	29 Dec 2002 00:41:02 -0000
@@ -170,6 +170,8 @@
 	public static final int kDataBrowserNoItem = 0;
 	public static final int kDataBrowserOrderIncreasing = 1;
 	public static final int kDataBrowserPropertyEnclosingPart = 0;
+	public static final int kDataBrowserPropertyDisclosurePart = ('d'<<24) + ('i'<<16) + ('s'<<8) + 'c';
+	public static final int kDataBrowserPropertyCheckboxPart = ('c'<<24) + ('h'<<16) + ('b'<<8) + 'x';
 	public static final int kDataBrowserPropertyIsMutable = 1 << 0;
 	public static final int kDataBrowserRevealOnly = 0;
 	public static final int kDataBrowserRevealAndCenterInView = 1 << 0;
@@ -404,6 +406,7 @@
 	public static final int kThemeBrushListViewBackground = 10; 
 	public static final int kThemeButtonOff = 0;
 	public static final int kThemeButtonOn = 1;
+	public static final int kThemeButtonMixed = 2;
 	public static final int kThemeCheckBox = 1;
 	public static final int kThemeCrossCursor = 5;
 	public static final int kThemeCurrentPortFont = 200;
Index: TreeItem.java
===================================================================
RCS file: /home/eclipse/org.eclipse.swt/Eclipse SWT/carbon2/org/eclipse/swt/widgets/TreeItem.java,v
retrieving revision 1.1
diff -u -r1.1 TreeItem.java
--- TreeItem.java	12 Dec 2002 13:48:19 -0000	1.1
+++ TreeItem.java	29 Dec 2002 00:30:48 -0000
@@ -18,6 +18,7 @@
 	TreeItem parentItem;
 	int id, index = -1;
 	boolean checked;
+	boolean grayed;
 	Color foreground, background;
 
 public TreeItem (Tree parent, int style) {
@@ -110,8 +111,7 @@
 public boolean getGrayed () {
 	checkWidget ();
 	if ((parent.style & SWT.CHECK) == 0) return false;
-	//NOT DONE
-	return false;
+	return grayed;
 }
 
 public int getItemCount () {
@@ -186,7 +186,8 @@
 public void setGrayed (boolean grayed) {
 	checkWidget ();
 	if ((parent.style & SWT.CHECK) == 0) return;
-	//NOT DONE
+	this.grayed = grayed;
+	redraw();
 }
 
 public void setImage (Image image) {
Index: Tree.java
===================================================================
RCS file: /home/eclipse/org.eclipse.swt/Eclipse SWT/carbon2/org/eclipse/swt/widgets/Tree.java,v
retrieving revision 1.2
diff -u -r1.2 Tree.java
--- Tree.java	12 Dec 2002 22:04:58 -0000	1.2
+++ Tree.java	29 Dec 2002 00:24:25 -0000
@@ -25,6 +25,7 @@
 	boolean ignoreSelect, ignoreExpand;
 	static final int CHECK_COLUMN_ID = 1024;
 	static final int COLUMN_ID = 1025;
+	private org.eclipse.swt.internal.carbon.Point mouseClickLocation;
 
 public Tree (Composite parent, int style) {
 	super (parent, checkStyle (style));
@@ -156,6 +157,7 @@
 		if (items [i] != null && items [i].parentItem == parentItem) count++;
 	}
 	if (index == -1) index = count;
+	if (index > count) error(SWT.ERROR_INVALID_ARGUMENT); 
 	item.index = index;
 	for (int i=0; i<items.length; i++) {
 		if (items [i] != null && items [i].parentItem == parentItem) {
@@ -456,13 +458,24 @@
 			if (setValue != 0) {
 				short [] theData = new short [1];
 				OS.GetDataBrowserItemDataButtonValue (itemData, theData);
-				item.checked = theData [0] == OS.kThemeButtonOn;
+				if (theData[0]==0){		  //  theData [0] == OS.kThemeButtonOff
+					item.checked = false;
+					item.grayed  = false;
+				}
+				else if (theData[0]==1){  //  theData [0] == OS.kThemeButtonOn
+					item.checked = true;
+					item.grayed  = false;
+				}
+				else if (theData[0] >= 2){  //  theData [0] == OS.kThemeButtonOn | OS.kThemeButtonMixed
+					item.checked = false;
+					item.grayed  = true;
+				}
 				Event event = new Event ();
 				event.item = item;
 				event.detail = SWT.CHECK;
 				postEvent (SWT.Selection, event);
 			} else {
-				short theData = (short)(item.checked ? OS.kThemeButtonOn : OS.kThemeButtonOff);
+				short theData = (short)(item.grayed ? 2 :  item.checked ? OS.kThemeButtonOn : OS.kThemeButtonOff);
 				OS.SetDataBrowserItemDataButtonValue (itemData, theData);
 			}
 			break;
@@ -481,6 +494,7 @@
 			for (int i=0; i<items.length; i++) {
 				if (items [i] != null && items [i].parentItem == item) {
 					OS.SetDataBrowserItemDataBooleanValue (itemData, true);
+					break;
 				}
 			}
 			break;
@@ -528,9 +542,21 @@
 			break;
 		}	
 		case OS.kDataBrowserItemDoubleClicked: {
-			Event event = new Event ();
-			event.item = item;
-			postEvent (SWT.DefaultSelection, event);
+			boolean processDoubleClick = false;
+			org.eclipse.swt.internal.carbon.Rect rect = new org.eclipse.swt.internal.carbon.Rect();
+			OS.GetDataBrowserItemPartBounds(handle, item.id, Tree.COLUMN_ID, 
+					OS.kDataBrowserPropertyDisclosurePart, rect);
+			processDoubleClick = (mouseClickLocation.h < rect.left || mouseClickLocation.h > rect.right);
+			if((style & SWT.MULTI) != 0 && !processDoubleClick)  {
+				OS.GetDataBrowserItemPartBounds(handle, item.id, Tree.CHECK_COLUMN_ID, 
+						OS.kDataBrowserPropertyCheckboxPart, rect);
+				processDoubleClick = (mouseClickLocation.h < rect.left || mouseClickLocation.h > rect.right);
+			}
+			if(processDoubleClick) {
+				Event event = new Event ();
+				event.item = item;
+				postEvent (SWT.DefaultSelection, event);
+			}
 			break;
 		}
 		case OS.kDataBrowserContainerClosed: {
@@ -557,6 +583,7 @@
 				}
 			}
 			OS.AddDataBrowserItems (handle, id, ids.length, ids, 0);
+			item.redraw();
 			break;
 		}
 	}
@@ -575,8 +602,22 @@
 }
 
 int kEventMouseDown (int nextHandler, int theEvent, int userData) {
-	int result = super.kEventMouseDown (nextHandler, theEvent, userData);
+	int result = -1;
+	
+	/* store Location of mouseClick for processing in itemNotification*/ 	
+	int sizeof = org.eclipse.swt.internal.carbon.Point.sizeof;
+	mouseClickLocation = new org.eclipse.swt.internal.carbon.Point ();
+	OS.GetEventParameter (theEvent, OS.kEventParamMouseLocation, OS.typeQDPoint, null, sizeof, null, mouseClickLocation);
+	int [] theWindow = new int [1];
+	int part = OS.FindWindow (mouseClickLocation, theWindow);
+	Rect windowRect = new Rect ();
+	OS.GetWindowBounds (theWindow [0], (short) OS.kWindowContentRgn, windowRect);
+	mouseClickLocation.h = (short) (mouseClickLocation.h - windowRect.left);
+	mouseClickLocation.v = (short) (mouseClickLocation.v - windowRect.top);
+
+	result = super.kEventMouseDown (nextHandler, theEvent, userData);
 	if (result == OS.noErr) return result;
+	
 	/*
 	* Feature in the Macintosh.  For some reason, when the user
 	* clicks on the data browser, focus is assigned, then lost



Hope this helps
martin

Back to the top