예제 #1
0
        protected virtual nfloat GetRowWidth(ICellHandler cell, int row, CGSize cellSize)
        {
            var item = DataViewHandler.GetItem(row);
            var val  = GetObjectValue(item);

            return(cell.GetPreferredSize(val, cellSize, row, item));
        }
예제 #2
0
파일: MacWindow.cs 프로젝트: CheckTech/Eto
        public override void SetContentSize(CGSize contentSize)
        {
            if (MinimumSize != Size.Empty)
            {
                contentSize.Width  = (nfloat)Math.Max(contentSize.Width, MinimumSize.Width);
                contentSize.Height = (nfloat)Math.Max(contentSize.Height, MinimumSize.Height);
            }

            if (Widget.Loaded)
            {
                var diffy = ClientSize.Height - (int)contentSize.Height;
                var diffx = ClientSize.Width - (int)contentSize.Width;
                var frame = Control.Frame;
                if (diffx < 0 || !setInitialSize)
                {
                    frame.Width -= diffx;
                }
                if (diffy < 0 || !setInitialSize)
                {
                    frame.Y      += diffy;
                    frame.Height -= diffy;
                }
                Control.SetFrame(frame, false, false);
            }
            else
            {
                Control.SetContentSize(contentSize);
            }
        }
예제 #3
0
        public override nfloat GetPreferredSize(object value, CGSize cellSize, NSCell cell)
        {
            cell.ObjectValue = value as NSObject;
            var size = cell.CellSizeForBounds(new CGRect(0, 0, nfloat.MaxValue, cellSize.Height)).Width;

            return(size);
        }
예제 #4
0
        public static NSImage ToNS(this Image image, int?size = null)
        {
            if (image == null)
            {
                return(null);
            }
            var source = image.Handler as IImageSource;

            if (source == null)
            {
                return(null);
            }
            var nsimage = source.GetImage();

            if (size != null)
            {
                var rep = nsimage.BestRepresentation(new CGRect(0, 0, size.Value, size.Value), null, null);
                if (rep.PixelsWide > size.Value || rep.PixelsHigh > size.Value)
                {
                    var max     = Math.Max(nsimage.Size.Width, nsimage.Size.Height);
                    var newsize = new CGSize((int)(size.Value * nsimage.Size.Width / max), (int)(size.Value * nsimage.Size.Height / max));
                    nsimage = nsimage.Resize(newsize);
                }
                else
                {
                    nsimage = new NSImage();
                    nsimage.AddRepresentation(rep);
                }
            }
            return(nsimage);
        }
예제 #5
0
        // not bound
        public static CGRect BoundingRect(this NSAttributedString str, CGSize size, NSStringDrawingOptions options)
        {
            CGRect rect;

            RectangleF_objc_msgSend_stret_SizeF_int(out rect, str.Handle, selBoundingRectWithSize, size, (int)options);
            return(rect);
        }
예제 #6
0
 public override void SetFrameSize(CGSize newSize)
 {
     base.SetFrameSize(newSize);
     if (setBezel)
     {
         Handler.SetBezel();
     }
 }
예제 #7
0
        public override nfloat GetPreferredSize(object value, CGSize cellSize, NSCell cell)
        {
            var font  = cell.Font ?? NSFont.BoldSystemFontOfSize(NSFont.SystemFontSize);
            var str   = new NSString(Convert.ToString(value));
            var attrs = NSDictionary.FromObjectAndKey(font, NSStringAttributeKey.Font);

            return((float)str.StringSize(attrs).Width + 8);             // for border
        }
예제 #8
0
 public nfloat GetPreferredSize(object value, CGSize cellSize, int row, object dataItem)
 {
     if (copy == null)
     {
         copy = Control.Copy() as NSCell;
     }
     ColumnHandler.DataViewHandler.OnCellFormatting(ColumnHandler.Widget, dataItem, row, copy);
     return(GetPreferredSize(value, cellSize, copy));
 }
예제 #9
0
 public override void SetFrameSize(CGSize newSize)
 {
     if (((SliderHandler)Handler).Orientation == Orientation.Horizontal && newSize.Width < newSize.Height)
     {
         // prevent slider from flipping to vertical orientation when resized
         newSize.Height = newSize.Width;
     }
     base.SetFrameSize(newSize);
 }
예제 #10
0
        public override void SetFrameSize(CGSize newSize)
        {
            base.SetFrameSize(newSize);

            if (!autoSized)
            {
                autoSized = Handler.AutoSizeColumns();
            }
        }
예제 #11
0
        public override nfloat GetPreferredWidth(object value, CGSize cellSize, int row, object dataItem)
        {
            var img = value as Image;

            if (img != null)
            {
                return(cellSize.Height / img.Size.Height * img.Size.Width);
            }
            return(16);
        }
예제 #12
0
        public override nfloat GetPreferredSize(object value, CGSize cellSize, NSCell cell)
        {
            var img = value as Image;

            if (img != null)
            {
                return((float)(cellSize.Height / (float)img.Size.Height * (float)img.Size.Width));
            }
            return(16);
        }
예제 #13
0
        public override nfloat GetPreferredWidth(object value, CGSize cellSize, int row, object dataItem)
        {
            var args = new MacCellFormatArgs(ColumnHandler.Widget, dataItem, row, field);

            ColumnHandler.DataViewHandler.Callback.OnCellFormatting(ColumnHandler.DataViewHandler.Widget, args);

            field.Font        = args.Font.ToNS() ?? NSFont.BoldSystemFontOfSize(NSFont.SystemFontSize);
            field.ObjectValue = value as NSObject;
            return(field.Cell.CellSizeForBounds(new CGRect(0, 0, nfloat.MaxValue, cellSize.Height)).Width);
        }
예제 #14
0
            public override void SetFrameSize(CGSize newSize)
            {
                base.SetFrameSize(newSize);
                var views    = Subviews;
                var text     = views[0];
                var splitter = views[1];
                var offset   = (newSize.Height - text.Frame.Height) / 2;

                text.SetFrameOrigin(new CGPoint(0, offset));
                text.SetFrameSize(new CGSize((float)(newSize.Width - splitter.Frame.Width), (float)text.Frame.Height));
                offset = (newSize.Height - splitter.Frame.Height) / 2;
                splitter.SetFrameOrigin(new CGPoint(newSize.Width - splitter.Frame.Width, offset));
            }
예제 #15
0
		public static NSImage Resize(this NSImage image, CGSize newsize, ImageInterpolation interpolation = ImageInterpolation.Default)
		{
			var newimage = new NSImage(newsize);
			var newrep = new NSBitmapImageRep(IntPtr.Zero, (nint)newsize.Width, (nint)newsize.Height, 8, 4, true, false, NSColorSpace.DeviceRGB, 4 * (nint)newsize.Width, 32);
			newimage.AddRepresentation(newrep);

			var graphics = NSGraphicsContext.FromBitmap(newrep);
			NSGraphicsContext.GlobalSaveGraphicsState();
			NSGraphicsContext.CurrentContext = graphics;
			graphics.GraphicsPort.InterpolationQuality = interpolation.ToCG();
			image.DrawInRect(new CGRect(CGPoint.Empty, newimage.Size), new CGRect(CGPoint.Empty, image.Size), NSCompositingOperation.SourceOver, 1f);
			NSGraphicsContext.GlobalRestoreGraphicsState();
			return newimage;
		}
예제 #16
0
파일: MacView.cs 프로젝트: CheckTech/Eto
        static void SetFrameSizeAction(IntPtr sender, IntPtr sel, CGSize size)
        {
            var obj = Runtime.GetNSObject(sender);

            Messaging.void_objc_msgSendSuper_SizeF(obj.SuperHandle, sel, size);

            var handler = GetHandler(obj) as IMacViewHandler;

            if (handler != null)
            {
                handler.OnSizeChanged(EventArgs.Empty);
                handler.Callback.OnSizeChanged(handler.Widget, EventArgs.Empty);
            }
        }
예제 #17
0
            void SetPattern()
            {
                sectionSize = new CGSize((EndPoint.X - StartPoint.X) + 1, (EndPoint.Y - StartPoint.Y) + 1);
                if (Wrap == GradientWrapMode.Reflect)
                {
                    tileSize = new CGSize(sectionSize.Width * 4, sectionSize.Height * 4);
                }
                else
                {
                    tileSize = new CGSize(sectionSize.Width * 2, sectionSize.Height * 2);
                }
                var rect = new CGRect(StartPoint, tileSize);
                var t    = CGAffineTransform.Multiply(transform, viewTransform);

                pattern = new CGPattern(rect, t, rect.Width, rect.Height, CGPatternTiling.NoDistortion, true, DrawPattern);
            }
예제 #18
0
        public static NSImage Resize(this NSImage image, CGSize newsize, ImageInterpolation interpolation = ImageInterpolation.Default)
        {
            var newimage = new NSImage(newsize);
            var newrep   = new NSBitmapImageRep(IntPtr.Zero, (nint)newsize.Width, (nint)newsize.Height, 8, 4, true, false, NSColorSpace.DeviceRGB, 4 * (nint)newsize.Width, 32);

            newimage.AddRepresentation(newrep);

            var graphics = NSGraphicsContext.FromBitmap(newrep);

            NSGraphicsContext.GlobalSaveGraphicsState();
            NSGraphicsContext.CurrentContext           = graphics;
            graphics.GraphicsPort.InterpolationQuality = interpolation.ToCG();
            image.DrawInRect(new CGRect(CGPoint.Empty, newimage.Size), new CGRect(CGPoint.Empty, image.Size), NSCompositingOperation.SourceOver, 1f);
            NSGraphicsContext.GlobalRestoreGraphicsState();
            return(newimage);
        }
예제 #19
0
 public override void SetContentSize(CGSize contentSize)
 {
     if (MinimumSize != Size.Empty)
     {
         contentSize.Width  = (nfloat)Math.Max(contentSize.Width, MinimumSize.Width);
         contentSize.Height = (nfloat)Math.Max(contentSize.Height, MinimumSize.Height);
     }
     if (ExpandContentWidth)
     {
         contentSize.Width = (nfloat)Math.Max(ClientSize.Width, contentSize.Width);
     }
     if (ExpandContentHeight)
     {
         contentSize.Height = (nfloat)Math.Max(ClientSize.Height, contentSize.Height);
     }
     InternalSetFrameSize(contentSize);
 }
예제 #20
0
 public override void SetContentSize(CGSize contentSize)
 {
     base.SetContentSize(contentSize);
     if (MinimumSize != Size.Empty)
     {
         contentSize.Width  = (nfloat)Math.Max(contentSize.Width, MinimumSize.Width);
         contentSize.Height = (nfloat)Math.Max(contentSize.Height, MinimumSize.Height);
     }
     if (Widget.Content != null)
     {
         var child = Widget.Content.Handler as IMacContainer;
         if (child != null)
         {
             child.SetContentSize(contentSize);
         }
     }
 }
예제 #21
0
 public EtoTextView(ITextAreaHandler handler)
 {
     Delegate = new EtoTextAreaDelegate {
         Handler = handler
     };
     AutoresizingMask      = NSViewResizingMask.WidthSizable | NSViewResizingMask.HeightSizable;
     HorizontallyResizable = true;
     VerticallyResizable   = true;
     Editable = true;
     RichText = false;
     AllowsDocumentBackgroundColorChange = false;
     Selectable = true;
     AllowsUndo = true;
     MinSize    = CGSize.Empty;
     MaxSize    = new CGSize(float.MaxValue, float.MaxValue);
     TextContainer.WidthTracksTextView = true;
 }
예제 #22
0
        public override nfloat GetPreferredSize(object value, CGSize cellSize, NSCell cell)
        {
            var val = value as MacImageData;

            if (val == null)
            {
                return(0);
            }

            var font  = cell.Font ?? NSFont.BoldSystemFontOfSize(NSFont.SystemFontSize);
            var str   = val.Text;
            var attrs = NSDictionary.FromObjectAndKey(font, NSAttributedString.FontAttributeName);

            var size = str.StringSize(attrs).Width + 4 + 16 + MacImageListItemCell.ImagePadding * 2;             // for border + image

            return((float)size);
        }
예제 #23
0
        public override nfloat GetPreferredWidth(object value, CGSize cellSize, int row, object dataItem)
        {
            var args = new MacCellFormatArgs(ColumnHandler.Widget, dataItem, row, field);

            ColumnHandler.DataViewHandler.Callback.OnCellFormatting(ColumnHandler.DataViewHandler.Widget, args);

            field.Font = defaultFont;
            if (args.FontSet)
            {
                field.Font = args.Font.ToNS();
            }
            if (field.Title != menu.Title)
            {
                field.Menu = menu.Copy() as NSMenu;
            }
            field.ObjectValue = value as NSObject;
            return(field.Cell.CellSizeForBounds(new CGRect(0, 0, nfloat.MaxValue, cellSize.Height)).Width);
        }
예제 #24
0
        void InternalSetFrameSize(CGSize size)
        {
            var view = ContentControl;

            if (!view.IsFlipped)
            {
                var ctl = Content.GetContainerView();
                if (ctl != null)
                {
                    var clientHeight = Control.DocumentVisibleRect.Size.Height;
                    ctl.Frame   = new CGRect(new CGPoint(0, (nfloat)Math.Max(0, clientHeight - size.Height)), size);
                    size.Height = (nfloat)Math.Max(clientHeight, size.Height);
                }
            }
            if (size != view.Frame.Size)
            {
                view.SetFrameSize(size);
            }
        }
예제 #25
0
        public override nfloat GetPreferredWidth(object value, CGSize cellSize, int row, object dataItem)
        {
            var     args       = new CellEventArgs(row, dataItem, CellStates.None);
            var     identifier = Callback.OnGetIdentifier(Widget, args) ?? string.Empty;
            Control widthCell;

            if (!widthCells.TryGetValue(identifier, out widthCell))
            {
                widthCell = Callback.OnCreateCell(Widget, args);
                if (widthCell == null)
                {
                    return(Callback.OnGetPreferredWidth(Widget, args));
                }
                widthCell.ToNative(true);
                widthCells.Add(identifier, widthCell);
            }
            Callback.OnConfigureCell(Widget, args, widthCell);

            var result = widthCell.GetPreferredSize(SizeF.MaxValue).Width;

            widthCell.DataContext = null;
            return(result);
            //return Callback.OnGetPreferredWidth(Widget, new CellEventArgs(row, dataItem, CellStates.None));
        }
예제 #26
0
 public static SizeF ToEto(this CGSize point)
 {
     return(new SizeF((float)point.Width, (float)point.Height));
 }
예제 #27
0
		public static extern void void_objc_msgSendSuper_SizeF(IntPtr receiver, IntPtr selector, CGSize arg1);
예제 #28
0
		public override void LayoutChildren()
		{
			if (!Widget.Loaded || views == null || NeedsQueue())
				return;
			var heights = new float[views.GetLength(0)];
			var widths = new float[views.GetLength(1)];
			var controlFrame = ContentControl.Frame;
			float totalxpadding = Padding.Horizontal + Spacing.Width * (widths.Length - 1);
			float totalypadding = Padding.Vertical + Spacing.Height * (heights.Length - 1);
			var totalx = (float)controlFrame.Width - totalxpadding;
			var totaly = (float)controlFrame.Height - totalypadding;
			var requiredx = totalxpadding;
			var requiredy = totalypadding;
			var numx = 0;
			var numy = 0;

			for (int y = 0; y < heights.Length; y++)
			{
				heights[y] = 0;
				if (yscaling[y] || lastyscale == y)
					numy++;
			}
			for (int x = 0; x < widths.Length; x++)
			{
				widths[x] = 0;
				if (xscaling[x] || lastxscale == x)
					numx++;
			}

			var availableSize = Size.Max(Size.Empty, Control.Frame.Size.ToEtoSize() - new Size((int)requiredx, (int)requiredy));
			for (int y = 0; y < heights.Length; y++)
				for (int x = 0; x < widths.Length; x++)
				{
					var view = views[y, x];
					if (view != null && view.Visible)
					{
						var size = view.GetPreferredSize(availableSize);
						if (!xscaling[x] && lastxscale != x && widths[x] < size.Width)
						{
							requiredx += size.Width - widths[x];
							widths[x] = size.Width;
						}
						if (!yscaling[y] && lastyscale != y && heights[y] < size.Height)
						{
							requiredy += size.Height - heights[y];
							heights[y] = size.Height;
						}
					}
				}
			if (controlFrame.Width < requiredx)
			{
				totalx = requiredx - totalxpadding;
			}
			if (controlFrame.Height < requiredy)
			{
				totaly = requiredy - totalypadding;
			}

			for (int y = 0; y < heights.Length; y++)
				if (!yscaling[y] && lastyscale != y)
					totaly -= heights[y];
			for (int x = 0; x < widths.Length; x++)
				if (!xscaling[x] && lastxscale != x)
					totalx -= widths[x];

			var chunkx = (numx > 0) ? (float)Math.Truncate(Math.Max(totalx, 0) / numx) : totalx;
			var chunky = (numy > 0) ? (float)Math.Truncate(Math.Max(totaly, 0) / numy) : totaly;

#if OSX
			bool flipped = Control.IsFlipped;
#elif IOS
			bool flipped = !Control.Layer.GeometryFlipped;
#endif
			float starty = Padding.Top;
			for (int x = 0; x < widths.Length; x++)
			{
				if (xscaling[x] || lastxscale == x)
				{
					widths[x] = Math.Min(chunkx, totalx);
					totalx -= chunkx;
				}
			}

			for (int y = 0; y < heights.Length; y++)
			{
				if (yscaling[y] || lastyscale == y)
				{
					heights[y] = Math.Min(chunky, totaly);
					totaly -= chunky;
				}
				float startx = Padding.Left;
				for (int x = 0; x < widths.Length; x++)
				{
					var view = views[y, x];
					if (view != null && view.Visible)
					{
						var nsview = view.GetContainerView();
						var frame = nsview.Frame;
						var oldframe = frame;
						frame.Width = widths[x];
						frame.Height = heights[y];
						frame.X = Math.Max(0, startx);
						frame.Y = flipped ? starty : controlFrame.Height - starty - frame.Height;
						if (frame != oldframe)
							nsview.Frame = frame;
						else if (oldframe.Right > oldFrameSize.Width || oldframe.Bottom > oldFrameSize.Height
						         || frame.Right > oldFrameSize.Width || frame.Bottom > oldFrameSize.Height)
							nsview.SetNeedsDisplay();
						//Console.WriteLine("*** x:{2} y:{3} view: {0} size: {1} totalx:{4} totaly:{5}", view, view.Size, x, y, totalx, totaly);
					}
					startx += widths[x] + Spacing.Width;
				}
				starty += heights[y] + Spacing.Height;
			}
			oldFrameSize = controlFrame.Size;
		}
예제 #29
0
파일: MacExtensions.cs 프로젝트: mhusen/Eto
		// not bound
		public static CGRect BoundingRect(this NSAttributedString str, CGSize size, NSStringDrawingOptions options)
		{
			CGRect rect;
			Messaging.RectangleF_objc_msgSend_stret_SizeF_int(out rect, str.Handle, selBoundingRectWithSize, size, (int)options);
			return rect;
		}
예제 #30
0
 public override nfloat GetPreferredSize(object value, CGSize cellSize, NSCell cell)
 {
     return(25);
 }
예제 #31
0
		public static NSImage ToNS(this Image image, int? size = null)
		{
			if (image == null)
				return null;
			var source = image.Handler as IImageSource;
			if (source == null)
				return null;
			var nsimage = source.GetImage();

			if (size != null)
			{
				var rep = nsimage.BestRepresentation(new CGRect(0, 0, size.Value, size.Value), null, null);
				if (rep.PixelsWide > size.Value || rep.PixelsHigh > size.Value)
				{
					var max = Math.Max(nsimage.Size.Width, nsimage.Size.Height);
					var newsize = new CGSize((int)(size.Value * nsimage.Size.Width / max), (int)(size.Value * nsimage.Size.Height / max));
					nsimage = nsimage.Resize(newsize);
				}
				else
				{
					nsimage = new NSImage();
					nsimage.AddRepresentation(rep);
				}
			}
			return nsimage;
		}
예제 #32
0
 public abstract nfloat GetPreferredSize(object value, CGSize cellSize, NSCell cell);
예제 #33
0
		static extern void RectangleF_objc_msgSend_stret_SizeF_int(out CGRect retval, IntPtr receiver, IntPtr selector, CGSize arg1, nint arg2);
예제 #34
0
 public override void SetContentSize(CGSize contentSize)
 {
     Control.SetFrameFromContentFrame(new CGRect(0, 0, contentSize.Width, contentSize.Height));
 }
예제 #35
0
 public static System.Drawing.SizeF ToSD(this CGSize size)
 {
     return(new System.Drawing.SizeF((float)size.Width, (float)size.Height));
 }
예제 #36
0
 public static Size ToEtoSize(this CGSize size)
 {
     return(new Size((int)size.Width, (int)size.Height));
 }