[Monodevelop-patches-list] r1755 - trunk/MonoDevelop/src/Libraries/Gdl

commit-watcher at mono-cvs.ximian.com commit-watcher at mono-cvs.ximian.com
Sun Jun 13 13:24:20 EDT 2004


Author: jzwart
Date: 2004-06-13 13:24:20 -0400 (Sun, 13 Jun 2004)
New Revision: 1755

Modified:
   trunk/MonoDevelop/src/Libraries/Gdl/Dock.cs
   trunk/MonoDevelop/src/Libraries/Gdl/DockItem.cs
   trunk/MonoDevelop/src/Libraries/Gdl/DockMaster.cs
   trunk/MonoDevelop/src/Libraries/Gdl/DockPaned.cs
Log:
More DND bits.


Modified: trunk/MonoDevelop/src/Libraries/Gdl/Dock.cs
===================================================================
--- trunk/MonoDevelop/src/Libraries/Gdl/Dock.cs	2004-06-13 14:09:56 UTC (rev 1754)
+++ trunk/MonoDevelop/src/Libraries/Gdl/Dock.cs	2004-06-13 17:24:20 UTC (rev 1755)
@@ -8,6 +8,7 @@
 {
 	public class Dock : DockObject
 	{
+		private readonly float SplitRatio = 0.3f;
 		private DockObject root = null;
 		private bool floating;
 		private Widget window;
@@ -295,58 +296,80 @@
 		
 		public override bool OnDockRequest (int x, int y, ref DockRequest request)
 		{
+			bool mayDock = false;
+		
+			/* we get (x,y) in our allocation coordinates system */
+			
+			/* Get dock size. */
 			Gdk.Rectangle alloc = Allocation;
 			int bw = (int)BorderWidth;
-			int rel_x = x - alloc.X;
-			int rel_y = y - alloc.Y;
-			DockRequest my_request = null;
-			bool may_dock = false;
-			
-			if (request != null)
-				my_request = request;
+
+			/* Get coordinates relative to our allocation area. */
+			int relX = x - alloc.X;
+			int relY = y - alloc.Y;
+
+			DockRequest myRequest = new DockRequest (request);
+
+			/* Check if coordinates are in GdlDock widget. */
+			if (relX > 0 && relX < alloc.Width &&
+			    relY > 0 && relY < alloc.Height) {
+			    
+				/* It's inside our area. */
+				mayDock = true;
+
+				/* Set docking indicator rectangle to the Dock size. */
+				Gdk.Rectangle reqRect = new Gdk.Rectangle ();
+				reqRect.X = alloc.X + bw;
+				reqRect.Y = alloc.Y + bw;
+				reqRect.Width = alloc.Width - 2 * bw;
+				reqRect.Height = alloc.Height - 2 * bw;
+				myRequest.Rect = reqRect;
 				
-			if (rel_x > 0 && rel_x < alloc.Width && rel_y > 0 && rel_y < alloc.Height) {
-				may_dock = true;
-				Gdk.Rectangle req_rect = new Gdk.Rectangle ();
-				req_rect.X = alloc.X + bw;
-				req_rect.Y = alloc.Y + bw;
-				req_rect.Width = alloc.Width - 2 * bw;
-				req_rect.Height = alloc.Height - 2 * bw;
-				my_request.Rect = req_rect;
-				
+				/* If Dock has no root item yet, set the dock
+				   itself as possible target. */
 				if (root == null) {
-					my_request.Position = DockPlacement.Top;
-					my_request.Target = this;
+					myRequest.Position = DockPlacement.Top;
+					myRequest.Target = this;
 				} else {
-					my_request.Target = root;
+					myRequest.Target = root;
 					
-					if (rel_x < bw) {
-						my_request.Position = DockPlacement.Left;
-						req_rect.Width = (int)(req_rect.Width * 0.3);
-						my_request.Rect = req_rect;
-					} else if (rel_x > alloc.Width - bw) {
-						my_request.Position = DockPlacement.Right;
-						req_rect.X += (int)(req_rect.Width * (1 - 0.3));
-						req_rect.Width = (int)(req_rect.Width * 0.3);
-						my_request.Rect = req_rect;
-					} else if (rel_y < bw) {
-						my_request.Position = DockPlacement.Top;
-						req_rect.Height = (int)(req_rect.Height * 0.3);
-						my_request.Rect = req_rect;
-					} else if (rel_y > alloc.Height - bw) {
-						my_request.Position = DockPlacement.Bottom;
-						req_rect.Y += (int)(req_rect.Height * (1 - 0.3));
-						req_rect.Height = (int)(req_rect.Height * 0.3);
-						my_request.Rect = req_rect;
+					/* See if it's in the BorderWidth band. */
+					if (relX < bw) {
+						myRequest.Position = DockPlacement.Left;
+						reqRect.Width = (int)(reqRect.Width * SplitRatio);
+						myRequest.Rect = reqRect;
+					} else if (relX > alloc.Width - bw) {
+						myRequest.Position = DockPlacement.Right;
+						reqRect.X += (int)(reqRect.Width * (1 - SplitRatio));
+						reqRect.Width = (int)(reqRect.Width * SplitRatio);
+						myRequest.Rect = reqRect;
+					} else if (relY < bw) {
+						myRequest.Position = DockPlacement.Top;
+						reqRect.Height = (int)(reqRect.Height * SplitRatio);
+						myRequest.Rect = reqRect;
+					} else if (relY > alloc.Height - bw) {
+						myRequest.Position = DockPlacement.Bottom;
+						reqRect.Y += (int)(reqRect.Height * (1 - SplitRatio));
+						reqRect.Height = (int)(reqRect.Height * SplitRatio);
+						myRequest.Rect = reqRect;
 					} else {
-						may_dock = root.OnDockRequest (x, y, ref my_request);
+						/* Otherwise try our children. */
+						/* give them allocation coordinates
+						   (we are a NoWindow widget) */
+						mayDock = root.OnDockRequest (x, y, ref myRequest);
 					}
 				}
 			}
 			
-			if (may_dock && request != null)
-				request = my_request;
-			return may_dock;
+			if (mayDock && request != null) {
+				request.Applicant = myRequest.Applicant;
+				request.Target = myRequest.Target;
+				request.Position = myRequest.Position;
+				request.Rect = myRequest.Rect;
+				request.Extra = myRequest.Extra;
+			}
+			
+			return mayDock;
 		}
 		
 		public override void OnDocked (DockObject requestor, DockPlacement position, object data)

Modified: trunk/MonoDevelop/src/Libraries/Gdl/DockItem.cs
===================================================================
--- trunk/MonoDevelop/src/Libraries/Gdl/DockItem.cs	2004-06-13 14:09:56 UTC (rev 1754)
+++ trunk/MonoDevelop/src/Libraries/Gdl/DockItem.cs	2004-06-13 17:24:20 UTC (rev 1755)
@@ -9,7 +9,8 @@
 	public delegate void DockItemDragEndHandler (DockItem o, bool cancelled);
 	
 	public class DockItem : DockObject
-	{		
+	{
+		private readonly float SplitRatio = 0.4f;
 		private Widget child = null;
 		private DockItemBehavior behavior = DockItemBehavior.Normal;
 		private Orientation orientation = Orientation.Vertical;
@@ -559,75 +560,99 @@
 		
 		public override bool OnDockRequest (int x, int y, ref DockRequest request)
 		{
+			/* we get (x,y) in our allocation coordinates system */
+			
+			/* Get item's allocation. */
 			Gdk.Rectangle alloc = Allocation;
-			int rel_x = x - alloc.X;
-			int rel_y = y - alloc.Y;
+
+			/* Get coordinates relative to our window. */
+			int relX = x - alloc.X;
+			int relY = y - alloc.Y;
 			
-			if (rel_x > 0 && rel_x < alloc.Width && rel_y > 0 && rel_y < alloc.Width) {
+			/* Location is inside. */
+			if (relX > 0 && relX < alloc.Width &&
+			    relY > 0 && relY < alloc.Width) {
+				int divider = -1;
+
+				/* these are for calculating the extra docking parameter */
 				Requisition other = DockItem.PreferredSize ((DockItem)request.Applicant);
 				Requisition my = DockItem.PreferredSize (this);
-				int divider = 0;
-				float rx = (float) rel_x / alloc.Width;
-				float ry = (float) rel_y / alloc.Height;
 				
-				if (rx < 0.4) {
+				/* Calculate location in terms of the available space (0-100%). */
+				float rx = (float) relX / alloc.Width;
+				float ry = (float) relY / alloc.Height;
+				
+				/* Determine dock location. */
+				if (rx < SplitRatio) {
 					request.Position = DockPlacement.Left;
 					divider = other.Width;
-				} else if (rx > (1 - 0.4)) {
+				} else if (rx > (1 - SplitRatio)) {
 					request.Position = DockPlacement.Right;
 					rx = 1 - rx;
 					divider = Math.Max (0, my.Width - other.Width);
-				} else if (ry < 0.4 && ry < rx) {
+				} else if (ry < SplitRatio && ry < rx) {
 					request.Position = DockPlacement.Top;
 					divider = other.Height;
-				} else if (ry > (1 - 0.4) && (1 - ry) < rx) {
+				} else if (ry > (1 - SplitRatio) && (1 - ry) < rx) {
 					request.Position = DockPlacement.Bottom;
 					divider = Math.Max (0, my.Height - other.Height);
-				} else
+				} else {
 					request.Position = DockPlacement.Center;
+				}
 				
-				Gdk.Rectangle req_rect = new Gdk.Rectangle ();
-				req_rect.X = 0;
-				req_rect.Y = 0;
-				req_rect.Width = alloc.Width;
-				req_rect.Height = alloc.Height;
+				/* Reset rectangle coordinates to entire item. */
+				Gdk.Rectangle reqRect = new Gdk.Rectangle ();
+				reqRect.X = 0;
+				reqRect.Y = 0;
+				reqRect.Width = alloc.Width;
+				reqRect.Height = alloc.Height;
 				
+				/* Calculate docking indicator rectangle size for new locations.
+				   Only do this when we're not over the item's current location. */
 				if (request.Applicant != this) {
 					switch (request.Position) {
 					case DockPlacement.Top:
-						req_rect.Height = (int)(req_rect.Height * 0.4);
+						reqRect.Height = (int)(reqRect.Height * SplitRatio);
 						break;
 					case DockPlacement.Bottom:
-						req_rect.Y += (int)(req_rect.Height * (1 - 0.4));
-						req_rect.Height = (int)(req_rect.Height * 0.4);
+						reqRect.Y += (int)(reqRect.Height * (1 - SplitRatio));
+						reqRect.Height = (int)(reqRect.Height * SplitRatio);
 						break;
 					case DockPlacement.Left:
-						req_rect.Width = (int)(req_rect.Width * 0.4);
+						reqRect.Width = (int)(reqRect.Width * SplitRatio);
 						break;
 					case DockPlacement.Right:
-						req_rect.X += (int)(req_rect.Width * (1 - 0.4));
-						req_rect.Width = (int)(req_rect.Width * 0.4);
+						reqRect.X += (int)(reqRect.Width * (1 - SplitRatio));
+						reqRect.Width = (int)(reqRect.Width * SplitRatio);
 						break;
 					case DockPlacement.Center:
-						req_rect.X = (int)(req_rect.Width * 0.2);
-						req_rect.Y = (int)(req_rect.Height * 0.2);
-						req_rect.Width = (int)(req_rect.Width * (1 - 0.2)) - req_rect.X;
-						req_rect.Height = (int)(req_rect.Height * (1 - 0.2)) - req_rect.Y;
+						reqRect.X = (int)(reqRect.Width * SplitRatio / 2);
+						reqRect.Y = (int)(reqRect.Height * SplitRatio / 2);
+						reqRect.Width = (int)(reqRect.Width * (1 - SplitRatio / 2)) - reqRect.X;
+						reqRect.Height = (int)(reqRect.Height * (1 - SplitRatio / 2)) - reqRect.Y;
 						break;
 					default:
 						break;
 					}
 				}
 				
-				req_rect.X += alloc.X;
-				req_rect.Y += alloc.Y;
+				/* adjust returned coordinates so they are have the same
+				   origin as our window */
+				reqRect.X += alloc.X;
+				reqRect.Y += alloc.Y;
+				
+				/* Set possible target location and return true. */
 				request.Target = this;
-				request.Rect = req_rect;
+
+				/* fill-in other dock information */
+				request.Rect = reqRect;
 				if (request.Position != DockPlacement.Center && divider >= 0)
 					request.Extra = divider;
+
 				return true;
+			} else { /* No docking possible at this location. */
+				return false;
 			}
-			return false;
 		}
 		
 		public override void OnDocked (DockObject requestor, DockPlacement position, object data)

Modified: trunk/MonoDevelop/src/Libraries/Gdl/DockMaster.cs
===================================================================
--- trunk/MonoDevelop/src/Libraries/Gdl/DockMaster.cs	2004-06-13 14:09:56 UTC (rev 1754)
+++ trunk/MonoDevelop/src/Libraries/Gdl/DockMaster.cs	2004-06-13 17:24:20 UTC (rev 1755)
@@ -293,8 +293,6 @@
 		
 		private void OnDragMotion (DockItem item, int rootX, int rootY)
 		{
-			Console.WriteLine ("DockMaster.OnDragMotion");
-		
 			Dock dock = null;
 			int winX, winY;
 			int x, y;

Modified: trunk/MonoDevelop/src/Libraries/Gdl/DockPaned.cs
===================================================================
--- trunk/MonoDevelop/src/Libraries/Gdl/DockPaned.cs	2004-06-13 14:09:56 UTC (rev 1754)
+++ trunk/MonoDevelop/src/Libraries/Gdl/DockPaned.cs	2004-06-13 17:24:20 UTC (rev 1755)
@@ -7,6 +7,7 @@
 {
 	public class DockPaned : DockItem
 	{
+		private readonly float SplitRatio = 0.3f;
 		private bool positionChanged = false;
 
 		protected DockPaned (IntPtr raw) : base (raw) { }
@@ -146,5 +147,67 @@
 				requestor.DockObjectFlags |= DockObjectFlags.Attached;
 			}
 		}
+		
+		public override bool OnDockRequest (int x, int y, ref DockRequest request)
+		{
+			bool mayDock = false;
+
+			/* we get (x,y) in our allocation coordinates system */
+			
+			/* Get item's allocation. */
+			Gdk.Rectangle alloc = Allocation;
+			int bw = (int)BorderWidth;
+
+			/* Get coordinates relative to our window. */
+			int relX = x - alloc.X;
+			int relY = y - alloc.Y;
+			
+			DockRequest myRequest = new DockRequest (request);
+			
+			/* Location is inside. */
+			if (relX > 0 && relX < alloc.Width &&
+			    relY > 0 && relY < alloc.Width) {
+			    	int divider = -1;
+			    
+				/* It's inside our area. */
+				mayDock = true;
+
+				/* these are for calculating the extra docking parameter */
+				Requisition other = DockItem.PreferredSize ((DockItem)request.Applicant);
+				Requisition my = DockItem.PreferredSize (this);
+				
+				/* Set docking indicator rectangle to the Dock size. */
+				Gdk.Rectangle reqRect = new Gdk.Rectangle ();
+				reqRect.X = alloc.X + bw;
+				reqRect.Y = alloc.Y + bw;
+				reqRect.Width = alloc.Width - 2 * bw;
+				reqRect.Height = alloc.Height - 2 * bw;
+				myRequest.Rect = reqRect;
+				
+				myRequest.Target = this;
+
+				/* See if it's in the border_width band. */
+				if (relX < bw) {
+					myRequest.Position = DockPlacement.Left;
+					myRequest.Rect.Width = myRequest.Rect.Width * SplitRatio;
+					divider = other.Width;
+				} else if (relX > alloc->Width - bw) {
+					myRequest.Position = DockPlacement.Right;
+					myRequest.Rect.X += myRequest.Rect.Width * (1 - SplitRatio);
+					myRequest.Rect.Width *= SplitRatio;
+					divider = Math.Max (0, my.Width - other.Width);
+				} else if (relY < bw) {
+					myRequest.Position = DockPlacement.Top;
+					myRequest.Rect.Height *= SplitRatio;
+					divider = other.Height;
+				} else if (relY > alloc->Height - bw) {
+					myRequest.Position = DockPlacement.Bottom;
+					myRequest.Rect.Y += myRequest.Rect.Height * (1 - SplitRatio);
+					myRequest.Rect.Height *= SplitRatio;
+					divider = Math.Max (0, my.Height - other.Height);
+				} else { /* Otherwise try our children. */
+				}
+			}
+		}
 	}
 }




More information about the Monodevelop-patches-list mailing list