Exemplo n.º 1
0
		public static CellViewBackend CreateCellRenderer (ApplicationContext actx, Widget widget, ICellRendererTarget col, object target, ICellViewFrontend view)
		{
			CellViewBackend crd;

			if (view is ITextCellViewFrontend) {
				crd = new CustomCellRendererText ();
			}
			else if (view is ICheckBoxCellViewFrontend) {
				crd = new CustomCellRendererToggle ();
			}
			else if (view is IImageCellViewFrontend) {
				crd = new CustomCellRendererImage ();
			}
			else if (view is ICanvasCellViewFrontend) {
				crd = new CustomCellRenderer ();
			}
			else
				throw new NotSupportedException ("Unknown cell view type: " + view.GetType ());

			crd.Initialize (view, col, target);
			col.PackStart (target, crd.CellRenderer, false);
			col.SetCellDataFunc (target, crd.CellRenderer, (cellLayout, cell, treeModel, iter) => crd.LoadData (treeModel, iter));
			view.AttachBackend (widget, crd);
			return crd;
		}
Exemplo n.º 2
0
 public CustomImage(ApplicationContext actx, ImageDrawCallback drawCallback)
 {
     this.actx = actx;
     this.drawCallback = drawCallback;
     imgRep = new NSCustomImageRep (new Selector ("drawIt:"), this);
     AddRepresentation (imgRep);
 }
Exemplo n.º 3
0
		internal static FrameworkElementFactory CreateBoundColumnTemplate (ApplicationContext ctx, Widget parent, CellViewCollection views, string dataPath = ".")
		{
			if (views.Count == 1)
                return CreateBoundCellRenderer(ctx, parent, views[0], dataPath);
			
			FrameworkElementFactory container = new FrameworkElementFactory (typeof (StackPanel));
			container.SetValue (StackPanel.OrientationProperty, System.Windows.Controls.Orientation.Horizontal);

			foreach (CellView view in views) {
				var factory = CreateBoundCellRenderer(ctx, parent, view, dataPath);

				factory.SetValue(FrameworkElement.MarginProperty, CellMargins);

				if (view.VisibleField != null)
				{
					var binding = new Binding(dataPath + "[" + view.VisibleField.Index + "]");
					binding.Converter = new BooleanToVisibilityConverter();
					factory.SetBinding(UIElement.VisibilityProperty, binding);
				}
				else if (!view.Visible)
					factory.SetValue(UIElement.VisibilityProperty, Visibility.Collapsed);

				container.AppendChild(factory);
			}

			return container;
		}
Exemplo n.º 4
0
 public static Gtk.CellRenderer CreateCellRenderer(ApplicationContext actx, ICellRendererTarget col, object target, ICellViewFrontend view, Gtk.TreeModel model)
 {
     if (view is ITextCellViewFrontend) {
         var cr = new CustomCellRendererText ((ITextCellViewFrontend)view);
         col.PackStart (target, cr, false);
         col.SetCellDataFunc (target, cr, (cell_layout, cell, treeModel, iter) => cr.LoadData (treeModel, iter));
         return cr;
     }
     else if (view is ICheckBoxCellViewFrontend) {
         CustomCellRendererToggle cr = new CustomCellRendererToggle ((ICheckBoxCellViewFrontend)view);
         col.PackStart (target, cr, false);
         col.SetCellDataFunc (target, cr, (cellLayout, cell, treeModel, iter) => cr.LoadData (treeModel, iter));
         return cr;
     }
     else if (view is IImageCellViewFrontend) {
         CustomCellRendererImage cr = new CustomCellRendererImage (actx, (IImageCellViewFrontend)view);
         col.PackStart (target, cr, false);
         col.SetCellDataFunc (target, cr, (cellLayout, cell, treeModel, iter) => cr.LoadData (treeModel, iter));
         return cr;
     }
     else if (view is ICanvasCellViewFrontend) {
         var cr = new CustomCellRenderer ((ICanvasCellViewFrontend) view);
         col.PackStart (target, cr, false);
         col.SetCellDataFunc (target, cr, (cellLayout, cell, treeModel, iter) => cr.LoadData (treeModel, iter));
         return cr;
     }
     throw new NotSupportedException ("Unknown cell view type: " + view.GetType ());
 }
Exemplo n.º 5
0
		public static NSCell CreateCell (ApplicationContext context, NSTableView table, ICellSource source, ICollection<CellView> cells, int column)
		{
			CompositeCell c = new CompositeCell (context, Orientation.Horizontal, source);
			foreach (var cell in cells)
				c.AddCell ((ICellRenderer) CreateCell (table, c, cell, column));
			return c;
		}
Exemplo n.º 6
0
		public ScrollControlBackend (ApplicationContext appContext, NSScrollView scrollView, bool vertical)
		{
			this.vertical = vertical;
			this.scrollView = scrollView;
			this.appContext = appContext;
			lastValue = Value;
		}
Exemplo n.º 7
0
		public CompositeCell (ApplicationContext context, Orientation dir, ICellSource source)
		{
			if (source == null)
				throw new ArgumentNullException ("source");
			direction = dir;
			this.context = context;
			this.source = source;
		}
Exemplo n.º 8
0
		public override void InitializeBackend (object frontend, ApplicationContext context)
		{
			base.InitializeBackend (frontend, context);

			buttonBox = new HBox () {
				Spacing = 0,
				Margin = 0
			};
			buttonBoxView = ((ViewBackend)buttonBox.GetBackend ()).Widget;
			ContentView.AddSubview (buttonBoxView);
		}
Exemplo n.º 9
0
		public static Gtk.Widget CreateCellRenderer (ApplicationContext actx, ICollection<CellView> views)
		{
			if (views.Count == 1) {
				Gtk.HBox box = new Gtk.HBox ();
				foreach (var v in views)
					box.PackStart (CreateCellRenderer (actx, v), false, false, 0);
				box.ShowAll ();
				return box;
			}
			else
				return CreateCellRenderer (actx, views.First ());
		}
Exemplo n.º 10
0
		internal static FrameworkElementFactory CreateBoundColumnTemplate (ApplicationContext ctx, Widget parent, CellViewCollection views, string dataPath = ".")
		{
			if (views.Count == 1)
                return CreateBoundCellRenderer(ctx, parent, views[0], dataPath);
			
			FrameworkElementFactory container = new FrameworkElementFactory (typeof (StackPanel));
			container.SetValue (StackPanel.OrientationProperty, System.Windows.Controls.Orientation.Horizontal);

			foreach (CellView view in views) {
                container.AppendChild(CreateBoundCellRenderer(ctx, parent, view, dataPath));
			}

			return container;
		}
Exemplo n.º 11
0
        public override void InitializeBackend(object frontend, ApplicationContext context)
        {
            base.InitializeBackend (frontend, context);

            mainBox = new VBox () {
                Spacing = 0,
                Margin = 0
            };
            buttonBox = new HBox () {
                Spacing = 0,
                Margin = 0
            };
            mainBox.PackEnd (buttonBox);
            base.SetChild ((IWidgetBackend) Toolkit.GetBackend (mainBox));
        }
Exemplo n.º 12
0
		public MacMenuButton (IMenuButtonEventSink eventSink, ApplicationContext context)
		{
			this.eventSink = eventSink;
			this.context = context;

			PullsDown = true;
			Activated += delegate {
				context.InvokeUserCode (delegate {
					eventSink.OnClicked ();
				});
			};

			NSNotificationCenter.DefaultCenter.AddObserver ("NSPopUpButtonWillPopUpNotification", CreateMenu, this);
			AddItem ("");
		}
Exemplo n.º 13
0
Arquivo: Util.cs Projeto: m13253/xwt
		public static bool GetSelectionData (ApplicationContext context, Gtk.SelectionData data, TransferDataStore target)
		{
			TransferDataType type = Util.AtomToType (data.Target.Name);
			if (type == null || data.Length <= 0)
				return false;

			if (type == TransferDataType.Text)
				target.AddText (data.Text);
			else if (data.TargetsIncludeImage (false))
				target.AddImage (context.Toolkit.WrapImage (data.Pixbuf));
			else if (type == TransferDataType.Uri) {
				var uris = System.Text.Encoding.UTF8.GetString (data.Data).Split ('\n').Where (u => !string.IsNullOrEmpty(u)).Select (u => new Uri (u)).ToArray ();
				target.AddUris (uris);
			}
			else
				target.AddValue (type, data.Data);
			return true;
		}
Exemplo n.º 14
0
		void ICopiableObject.CopyFrom (object other)
		{
			var ob = (CompositeCell)other;
			context = ob.context;
			source = ob.source;
			val = ob.val;
			tablePosition = ob.tablePosition;
			direction = ob.direction;
			trackingCell = ob.trackingCell;
			cells = new List<ICellRenderer> ();
			foreach (var c in ob.cells) {
				var copy = (ICellRenderer) Activator.CreateInstance (c.GetType ());
				copy.CopyFrom (c);
				AddCell (copy);
			}
			if (tablePosition != null)
				Fill ();
		}
Exemplo n.º 15
0
 public Cairo.Pattern GetPattern(ApplicationContext actx, double scaleFactor)
 {
     if (pattern == null || currentScaleFactor != scaleFactor) {
         if (pattern != null)
             pattern.Dispose ();
         Gdk.Pixbuf pb = ((GtkImage)Image.Backend).GetBestFrame (actx, scaleFactor, Image.Size.Width, Image.Size.Height, false);
         var imgs = new Cairo.ImageSurface (Cairo.Format.ARGB32, (int)(Image.Size.Width * scaleFactor), (int)(Image.Size.Height * scaleFactor));
         var ic = new Cairo.Context (imgs);
         ic.Scale ((double)imgs.Width / (double)pb.Width, (double)imgs.Height / (double)pb.Height);
         Gdk.CairoHelper.SetSourcePixbuf (ic, pb, 0, 0);
         ic.Paint ();
         imgs.Flush ();
         ((IDisposable)ic).Dispose ();
         pattern = new Cairo.SurfacePattern (imgs);
         pattern.Extend = Cairo.Extend.Repeat;
         var cm = new Cairo.Matrix ();
         cm.Scale (scaleFactor, scaleFactor);
         pattern.Matrix = cm;
         currentScaleFactor = scaleFactor;
     }
     return pattern;
 }
Exemplo n.º 16
0
 public ImageBox()
 {
     this.actx = ToolkitEngineBackend.GetToolkitBackend<WPFEngine> ().ApplicationContext;
 }
Exemplo n.º 17
0
 public ImageBox(ApplicationContext actx)
 {
     this.actx = actx;
 }
Exemplo n.º 18
0
 public ImageSource GetBestFrame(ApplicationContext actx, double scaleFactor, double width, double height, bool forceExactSize)
 {
     var f = FindFrame (width, height, scaleFactor);
     if (f == null || (forceExactSize && (Math.Abs (f.Width - width * scaleFactor) > 0.01 || Math.Abs (f.Height - height * scaleFactor) > 0.01)))
         return RenderFrame (actx, scaleFactor, width, height);
     else
         return f;
 }
Exemplo n.º 19
0
        ImageSource RenderFrame(ApplicationContext actx, double scaleFactor, double width, double height)
        {
            ImageDescription idesc = new ImageDescription () {
                Alpha = 1,
                Size = new Size (width, height)
            };
            SWM.DrawingVisual visual = new SWM.DrawingVisual ();
            using (SWM.DrawingContext ctx = visual.RenderOpen ()) {
                ctx.PushTransform (new ScaleTransform (scaleFactor, scaleFactor));
                Draw (actx, ctx, scaleFactor, 0, 0, idesc);
                ctx.Pop ();
            }

            SWMI.RenderTargetBitmap bmp = new SWMI.RenderTargetBitmap ((int)(width * scaleFactor), (int)(height * scaleFactor), 96, 96, PixelFormats.Pbgra32);
            bmp.Render (visual);

            var f = new ImageFrame (bmp, width, height);
            AddFrame (f);
            return bmp;
        }
Exemplo n.º 20
0
        public void Draw(ApplicationContext actx, SWM.DrawingContext dc, double scaleFactor, double x, double y, ImageDescription idesc)
        {
            if (drawCallback != null) {
                DrawingContext c = new DrawingContext (dc, scaleFactor);
                actx.InvokeUserCode (delegate {
                    drawCallback (c, new Rectangle (x, y, idesc.Size.Width, idesc.Size.Height), idesc, actx.Toolkit);
                });
            }
            else {
                if (idesc.Alpha < 1)
                    dc.PushOpacity (idesc.Alpha);

                var f = GetBestFrame (actx, scaleFactor, idesc.Size.Width, idesc.Size.Height, false);
                var bmpImage = f as BitmapSource;

                // When an image is a single bitmap that doesn't have the same intrinsic size as the drawing size, dc.DrawImage makes a very poor job of down/up scaling it.
                // Thus we handle this manually by using a TransformedBitmap to handle the conversion in a better way when it's needed.

                var scaledWidth = idesc.Size.Width * scaleFactor;
                var scaledHeight = idesc.Size.Height * scaleFactor;
                if (bmpImage != null && (Math.Abs (bmpImage.PixelHeight - scaledHeight) > 0.001 || Math.Abs (bmpImage.PixelWidth - scaledWidth) > 0.001))
                    f = new TransformedBitmap (bmpImage, new ScaleTransform (scaledWidth / bmpImage.PixelWidth, scaledHeight / bmpImage.PixelHeight));

                dc.DrawImage (f, new Rect (x, y, idesc.Size.Width, idesc.Size.Height));

                if (idesc.Alpha < 1)
                    dc.Pop ();
            }
        }
Exemplo n.º 21
0
 public ImageSource GetBestFrame(ApplicationContext actx, Visual w, double width, double height, bool forceExactSize)
 {
     return GetBestFrame (actx, w.GetScaleFactor (), width, height, forceExactSize);
 }
Exemplo n.º 22
0
		void IBackend.InitializeBackend (object frontend, ApplicationContext context)
		{
			this.frontend = (WindowFrame) frontend;
			ApplicationContext = context;
		}
Exemplo n.º 23
0
		public GtkAlertDialog (ApplicationContext actx, MessageDescription message)
		{
			this.actx = actx;
			Init ();
			this.buttons = message.Buttons.ToArray ();

			string primaryText = String.Empty;
			string secondaryText = String.Empty;

			if (string.IsNullOrEmpty (message.Text)) {
				if (!string.IsNullOrEmpty (message.SecondaryText))
					primaryText = message.SecondaryText;
			} else {
				primaryText = message.Text;
				secondaryText = message.SecondaryText;
			}

			if (message.Icon == StockIcons.Information)
				base.MessageType = MessageType.Info;
			else if (message.Icon == StockIcons.Question)
				base.MessageType = MessageType.Question;
			else if (message.Icon == StockIcons.Warning)
				base.MessageType = MessageType.Warning;
			else if (message.Icon == StockIcons.Error)
				base.MessageType = MessageType.Error;
			else {
				var icon = message.Icon.ToImageDescription (actx);
				image.Image = icon.WithDefaultSize (Gtk.IconSize.Dialog);
				base.Image = image;
			}

			StringBuilder markup = new StringBuilder (@"<span weight=""bold"" size=""larger"">");
			markup.Append (GLib.Markup.EscapeText (primaryText));
			markup.Append ("</span>");

			base.Markup = markup.ToString ();
			if (!String.IsNullOrEmpty (secondaryText)) {
				base.SecondaryText = GLib.Markup.EscapeText (secondaryText);
				base.SecondaryUseMarkup = true;
			}
			
			foreach (Command button in message.Buttons) {
				Gtk.Button newButton = (Gtk.Button)base.AddButton (button.Label, button.ToResponseType());
				newButton.UseUnderline = true;
				newButton.UseStock     = button.IsStockButton;
				if (button.Icon != null) {
					var icon = button.Icon.ToImageDescription (actx);
					newButton.Image = new ImageBox (actx, icon.WithDefaultSize (Gtk.IconSize.Button));
				}
				newButton.Clicked += ButtonClicked;
			}
			
			foreach (var op in message.Options) {
				Gtk.CheckButton check = new Gtk.CheckButton (op.Text);
				check.Active = op.Value;
				this.AddContent (check, false, false, 0);
				check.Toggled += delegate {
					message.SetOptionValue (op.Id, check.Active);
				};
			}
			
			if (message.AllowApplyToAll) {
				Gtk.CheckButton check = new Gtk.CheckButton ("Apply to all");
				this.AddContent (check, false, false, 0);
				check.Toggled += delegate {
					ApplyToAll = check.Active;
				};
			}
			
			//don't show this yet, let the consumer decide when
			this.Child.ShowAll ();
		}
Exemplo n.º 24
0
		NSTrackingArea trackingArea;	// Captures Mouse Entered, Exited, and Moved events

		public WidgetView (IWidgetEventSink eventSink, ApplicationContext context)
		{
			this.context = context;
			this.eventSink = eventSink;
		}
Exemplo n.º 25
0
 public virtual void Initialize(ApplicationContext actx)
 {
     Context = actx;
 }
Exemplo n.º 26
0
		public GtkAlertDialog (ApplicationContext actx, MessageDescription message)
		{
			this.actx = actx;
			Init ();
			this.buttons = message.Buttons.ToArray ();
			
			string primaryText;
			string secondaryText;
			
			if (string.IsNullOrEmpty (message.SecondaryText)) {
				secondaryText = message.Text;
				primaryText = null;
			} else {
				primaryText = message.Text;
				secondaryText = message.SecondaryText;
			}

			var icon = message.Icon.ToImageDescription (actx);
			image.Image = icon.WithDefaultSize (Gtk.IconSize.Dialog);
			
			StringBuilder markup = new StringBuilder (@"<span weight=""bold"" size=""larger"">");
			markup.Append (GLib.Markup.EscapeText (primaryText));
			markup.Append ("</span>");
			if (!String.IsNullOrEmpty (secondaryText)) {
				if (!String.IsNullOrEmpty (primaryText)) {
					markup.AppendLine ();
					markup.AppendLine ();
				}
				markup.Append (GLib.Markup.EscapeText (secondaryText));
			}
			label.Markup = markup.ToString ();
			label.Selectable = true;
			label.CanFocus = false;
			
			foreach (Command button in message.Buttons) {
				Gtk.Button newButton = new Gtk.Button ();
				newButton.Label        = button.Label;
				newButton.UseUnderline = true;
				newButton.UseStock     = button.IsStockButton;
				if (button.Icon != null) {
					icon = button.Icon.ToImageDescription (actx);
					newButton.Image = new ImageBox (actx, icon.WithDefaultSize (Gtk.IconSize.Button));
				}
				newButton.Clicked += ButtonClicked;
				ActionArea.Add (newButton);
			}
			
			foreach (var op in message.Options) {
				CheckButton check = new CheckButton (op.Text);
				check.Active = op.Value;
				labelsBox.PackStart (check, false, false, 0);
				check.Toggled += delegate {
					message.SetOptionValue (op.Id, check.Active);
				};
			}
			
			if (message.AllowApplyToAll) {
				CheckButton check = new CheckButton ("Apply to all");
				labelsBox.PackStart (check, false, false, 0);
				check.Toggled += delegate {
					ApplyToAll = check.Active;
				};
			}
			
			//don't show this yet, let the consumer decide when
			this.Child.ShowAll ();
		}
Exemplo n.º 27
0
 public void Initialize(ApplicationContext actx)
 {
 }
Exemplo n.º 28
0
 public void InitializeBackend(object frontend, ApplicationContext context)
 {
     ApplicationContext = context;
 }
Exemplo n.º 29
0
		public void InitializeBackend (object frontend, ApplicationContext context)
		{
			this.frontend = (Popover) frontend;
		}
Exemplo n.º 30
0
		public ImagePattern (ApplicationContext actx, ImageDescription im)
		{
			this.actx = actx;
			this.image = im;
		}