Beispiel #1
0
 /// <summary>
 /// Gets the native Mac NSView that contains the Eto.Forms control.
 /// </summary>
 /// <remarks>
 /// Note for some controls, this will not be the 'main' native control.
 /// For example, a GridView on OS X will return a NSScrollView instead of a NSTableView, since the table view
 /// itself does not scroll.
 ///
 /// When you intend on using the control inside an existing native application, set <paramref name="attach"/> to
 /// true so that it can prepare for attaching to the native application by sending OnPreLoad/Load/LoadComplete events.
 /// </remarks>
 /// <returns>The native control that can be used to add this control to an existing application.</returns>
 /// <param name="control">Control to get the native control for.</param>
 /// <param name="attach">If set to <c>true</c> the control is to be attached to an existing application, or <c>false</c> to get the native control directly.</param>
 public static NSView ToNative(this Control control, bool attach = false)
 {
     if (control == null)
     {
         return(null);
     }
     if (attach && !control.Loaded)
     {
         control.AttachNative();
     }
     return(control.GetContainerView());
 }
Beispiel #2
0
 /// <summary>
 /// Gets the native Mac NSView that contains the Eto.Forms control.
 /// </summary>
 /// <remarks>
 /// Note for some controls, this will not be the 'main' native control.
 /// For example, a GridView on OS X will return a NSScrollView instead of a NSTableView, since the table view
 /// itself does not scroll.
 ///
 /// When you intend on using the control inside an existing native application, set <paramref name="attach"/> to
 /// true so that it can prepare for attaching to the native application by sending OnPreLoad/Load/LoadComplete events.
 /// </remarks>
 /// <returns>The native control that can be used to add this control to an existing application.</returns>
 /// <param name="control">Control to get the native control for.</param>
 /// <param name="attach">If set to <c>true</c> the control is to be attached to an existing application, or <c>false</c> to get the native control directly.</param>
 public static NSView ToNative(this Control control, bool attach = false)
 {
     if (attach && !control.Loaded)
     {
         control.AttachNative();
         var macControl = control.GetMacControl();
         if (macControl != null && macControl.AutoSize)
         {
             macControl.ContainerControl.SetFrameSize(macControl.GetPreferredSize(SizeF.MaxValue).ToSD());
         }
     }
     return(control.GetContainerView());
 }
Beispiel #3
0
        /// <summary>
        /// Gets the native Mac NSView that contains the Eto.Forms control.
        /// </summary>
        /// <remarks>
        /// Note for some controls, this will not be the 'main' native control.
        /// For example, a GridView on OS X will return a NSScrollView instead of a NSTableView, since the table view
        /// itself does not scroll.
        ///
        /// When you intend on using the control inside an existing native application, set <paramref name="attach"/> to
        /// true so that it can prepare for attaching to the native application by sending OnPreLoad/Load/LoadComplete events.
        /// </remarks>
        /// <returns>The native control that can be used to add this control to an existing application.</returns>
        /// <param name="control">Control to get the native control for.</param>
        /// <param name="attach">If set to <c>true</c> the control is to be attached to an existing application, or <c>false</c> to get the native control directly.</param>
        public static NSView ToNative(this Control control, bool attach = false)
        {
            if (control == null)
            {
                return(null);
            }
            if (attach && !control.Loaded)
            {
                control.AttachNative();
                var macView = control.GetMacViewHandler();

                macView?.SetAlignmentFrameSize(macView.GetPreferredSize(SizeF.PositiveInfinity).ToNS());
            }
            return(control.GetContainerView());
        }
		public static void AddSubview (this Control control, Control subView, bool useRoot = false)
		{
			var parentController = control.GetViewController (false);
			if (parentController != null) {
				parentController.AddChildViewController (subView.GetViewController ());
				return;
			}
			if (useRoot) {
				var window = control.GetContainerView () as UIWindow;
				if (window != null) {
					window.RootViewController = subView.GetViewController ();
					return;
				}
			}
			var parentView = control.GetContentView ();
			if (parentView != null) {
				parentView.AddSubview (subView.GetContainerView ());
				return;
			}

			throw new EtoException("Coult not add subview to parent");
		}
		public void Remove(Control child)
		{
			for (int y = 0; y < views.GetLength(0); y++)
				for (int x = 0; x < views.GetLength(1); x++)
				{
					if (object.ReferenceEquals(views[y, x], child))
					{
						var view = child.GetContainerView();
						view.RemoveFromSuperview();
						views[y, x] = null;
						if (Widget.Loaded)
							LayoutParent();
						return;
					}
				}
		}
		public void Add(Control child, int x, int y)
		{
			var current = views[y, x];
			if (current != null)
			{
				var currentView = current.GetContainerView();
				if (currentView != null)
					currentView.RemoveFromSuperview();
			}
			views[y, x] = child;
			if (child != null)
			{
				var view = child.GetContainerView();
				if (Widget.Loaded)
					LayoutParent();
				Control.AddSubview(view);
			}
			else if (Widget.Loaded)
				LayoutParent();
		}