예제 #1
0
 void UpdateButton(DialogButton btn, Gtk.Button b)
 {
     if (!string.IsNullOrEmpty(btn.Label) && btn.Image == null)
     {
         b.Label = btn.Label;
     }
     else if (string.IsNullOrEmpty(btn.Label) && btn.Image != null)
     {
         var pix = (Gdk.Pixbuf)WidgetRegistry.GetBackend(btn.Image);
         b.Image = new Gtk.Image(pix);
     }
     else if (!string.IsNullOrEmpty(btn.Label))
     {
         Gtk.Box box = new Gtk.HBox(false, 3);
         var     pix = (Gdk.Pixbuf)WidgetRegistry.GetBackend(btn.Image);
         box.PackStart(new Gtk.Image(pix), false, false, 0);
         box.PackStart(new Gtk.Label(btn.Label), true, true, 0);
         b.Image = box;
     }
     if (btn.Visible)
     {
         b.ShowAll();
     }
     else
     {
         b.Hide();
     }
     b.Sensitive = btn.Sensitive;
 }
예제 #2
0
        static bool PerformDragOperation(IntPtr sender, IntPtr sel, IntPtr dragInfo)
        {
            IViewObject <T> ob = Runtime.GetNSObject(sender) as IViewObject <T>;

            if (ob == null)
            {
                return(false);
            }

            var backend = (ViewBackend <T, S>)WidgetRegistry.GetBackend(ob.Frontend);

            NSDraggingInfo di  = new NSDraggingInfo(dragInfo);
            var            pos = new Point(di.DraggingLocation.X, di.DraggingLocation.Y);

            if ((backend.currentEvents & WidgetEvent.DragDrop) != 0)
            {
                TransferDataStore store = new TransferDataStore();
                FillDataStore(store, di.DraggingPasteboard, ob.View.RegisteredDragTypes());
                var args = new DragEventArgs(pos, store, ConvertAction(di.DraggingSourceOperationMask));
                Toolkit.Invoke(delegate {
                    backend.eventSink.OnDragDrop(args);
                });
                return(args.Success);
            }
            else
            {
                return(false);
            }
        }
예제 #3
0
        public Command Run(WindowFrame transientFor, MessageDescription message)
        {
            GtkAlertDialog alertDialog = new GtkAlertDialog(message);

            alertDialog.FocusButton(message.DefaultButton);
            var wb  = (IGtkWidgetBackend)WidgetRegistry.GetBackend(transientFor);
            var win = wb != null ? (Gtk.Window)wb.Widget : null;

            MessageService.ShowCustomDialog(alertDialog, win);
            if (alertDialog.ApplyToAll)
            {
                ApplyToAll = true;
            }
            var res = alertDialog.ResultButton;

            if (res == null)
            {
                // If the dialog is closed clicking the close window button we may have no result.
                // In that case, try to find a cancelling button
                if (message.Buttons.Contains(Command.Cancel))
                {
                    return(Command.Cancel);
                }
                else if (message.Buttons.Contains(Command.No))
                {
                    return(Command.No);
                }
                else if (message.Buttons.Contains(Command.Close))
                {
                    return(Command.Close);
                }
            }
            return(res);
        }
예제 #4
0
 /// <summary>
 /// Shows the dialog.
 /// </summary>
 public bool Run(WindowFrame parentWindow)
 {
     try {
         running = true;
         Backend.Initialize(filters, multiselect, initialFileName);
         if (!string.IsNullOrEmpty(currentFolder))
         {
             Backend.CurrentFolder = currentFolder;
         }
         if (activeFilter != null)
         {
             Backend.ActiveFilter = activeFilter;
         }
         if (!string.IsNullOrEmpty(title))
         {
             Backend.Title = title;
         }
         return(Backend.Run((IWindowFrameBackend)WidgetRegistry.GetBackend(parentWindow)));
     } finally {
         currentFolder = Backend.CurrentFolder;
         activeFilter  = Backend.ActiveFilter;
         fileName      = Backend.FileName;
         fileNames     = Backend.FileNames;
         currentFolder = Backend.CurrentFolder;
         running       = false;
         Backend.Cleanup();
     }
 }
예제 #5
0
        public void SetFont(object backend, Xwt.Drawing.Font font)
        {
            LayoutInfo li = (LayoutInfo)backend;

            li.Font = (NSFont)WidgetRegistry.GetBackend(font);
            UpdateInfo(li);
        }
예제 #6
0
파일: Dialog.cs 프로젝트: d5nguyenvan/xwt
 public Command Run(WindowFrame parent)
 {
     Toolkit.InvokePlatformCode(delegate {
         Backend.RunLoop((IWindowFrameBackend)WidgetRegistry.GetBackend(parent));
     });
     return(resultCommand);
 }
예제 #7
0
 internal static FrameworkElement CreateCellRenderer(TreeNode node, CellView view)
 {
     if (view is TextCellView)
     {
         DataField     field = ((TextCellView)view).TextField;
         int           index = field.Index;
         SWC.TextBlock label = new SWC.TextBlock();
         label.Text    = (node.Values[index] ?? "null").ToString();
         label.Padding = new Thickness(2);
         return(label);
     }
     else if (view is ImageCellView)
     {
         DataField       field     = ((ImageCellView)view).ImageField;
         int             index     = field.Index;
         SWM.ImageSource image     = (SWM.ImageSource)WidgetRegistry.GetBackend(node.Values[index]);
         SWC.Image       imageCtrl = new SWC.Image
         {
             Source = image,
             Width  = image.Width,
             Height = image.Height
         };
         return(imageCtrl);
     }
     throw new NotImplementedException();
 }
예제 #8
0
        public override void DrawTextLayout(object backend, TextLayout layout, double x, double y)
        {
            Pango.Layout        pl  = (Pango.Layout)WidgetRegistry.GetBackend(layout);
            CairoContextBackend ctx = (CairoContextBackend)backend;

            ctx.Context.MoveTo(x, y);
            if (layout.Height <= 0)
            {
                Pango.CairoHelper.ShowLayout(ctx.Context, pl);
            }
            else
            {
                var    lc    = pl.LineCount;
                var    scale = Pango.Scale.PangoScale;
                double h     = 0;
                for (int i = 0; i < lc; i++)
                {
                    var line = pl.Lines [i];
                    var ext  = new Pango.Rectangle();
                    var extl = new Pango.Rectangle();
                    line.GetExtents(ref ext, ref extl);
                    h += (extl.Height / scale);
                    if (h > layout.Height)
                    {
                        break;
                    }
                    ctx.Context.MoveTo(x, y + h);
                    Pango.CairoHelper.ShowLayoutLine(ctx.Context, line);
                }
            }
        }
예제 #9
0
        public object Create(Context context)
        {
            GtkContext c  = (GtkContext)WidgetRegistry.GetBackend(context);
            var        pl = Pango.CairoHelper.CreateLayout(c.Context);

            return(pl);
        }
예제 #10
0
        public Command Run(WindowFrame transientFor, MessageDescription message)
        {
            this.icon    = GetIcon(message.Icon);
            this.buttons = ConvertButtons(message.Buttons);
            if (message.SecondaryText == null)
            {
                message.SecondaryText = String.Empty;
            }
            else
            {
                message.Text          = message.Text + "\r\n\r\n" + message.SecondaryText;
                message.SecondaryText = String.Empty;
            }

            var wb = (WindowFrameBackend)WidgetRegistry.GetBackend(transientFor);

            if (wb != null)
            {
                this.dialogResult = MessageBox.Show(wb.Window, message.Text, message.SecondaryText,
                                                    this.buttons, this.icon, this.defaultResult, this.options);
            }
            else
            {
                this.dialogResult = MessageBox.Show(message.Text, message.SecondaryText, this.buttons,
                                                    this.icon, this.defaultResult, this.options);
            }

            return(ConvertResultToCommand(this.dialogResult));
        }
예제 #11
0
        static bool PrepareForDragOperation(IntPtr sender, IntPtr sel, IntPtr dragInfo)
        {
            IViewObject <T> ob = Runtime.GetNSObject(sender) as IViewObject <T>;

            if (ob == null)
            {
                return(false);
            }

            var backend = (ViewBackend <T, S>)WidgetRegistry.GetBackend(ob.Frontend);

            NSDraggingInfo di    = new NSDraggingInfo(dragInfo);
            var            types = di.DraggingPasteboard.Types.Select(t => ToXwtDragType(t)).ToArray();
            var            pos   = new Point(di.DraggingLocation.X, di.DraggingLocation.Y);

            if ((backend.currentEvents & WidgetEvent.DragDropCheck) != 0)
            {
                var  args = new DragCheckEventArgs(pos, types, ConvertAction(di.DraggingSourceOperationMask));
                bool res  = Toolkit.Invoke(delegate {
                    backend.eventSink.OnDragDropCheck(args);
                });
                if (args.Result == DragDropResult.Canceled || !res)
                {
                    return(false);
                }
            }
            return(true);
        }
예제 #12
0
        public virtual void DrawTextLayout(object backend, TextLayout layout, double x, double y)
        {
            Cairo.Context ctx = ((CairoContextBackend)backend).Context;
            var           lb  = WidgetRegistry.GetBackend(layout);

            CairoTextLayoutBackendHandler.Draw(ctx, lb, x, y);
        }
예제 #13
0
        public object Create(Context context)
        {
            CairoContextBackend c = (CairoContextBackend)WidgetRegistry.GetBackend(context);
            LayoutBackend       b = new LayoutBackend();

            b.Context = c;
            return(b);
        }
예제 #14
0
        public void DrawTextLayout(object backend, TextLayout layout, double x, double y)
        {
            Pango.Layout pl  = (Pango.Layout)WidgetRegistry.GetBackend(layout);
            GtkContext   ctx = (GtkContext)backend;

            ctx.Context.MoveTo(x, y);
            Pango.CairoHelper.ShowLayout(ctx.Context, pl);
        }
예제 #15
0
        public void DrawTextLayout(object backend, TextLayout layout, double x, double y)
        {
            Pango.Layout pl  = (Pango.Layout)WidgetRegistry.GetBackend(layout);
            GtkContext   ctx = (GtkContext)backend;

            Gdk.GC gc = ctx.Widget.Style.BlackGC;
            ctx.Widget.GdkWindow.DrawLayout(gc, (int)x, (int)y, pl);
        }
예제 #16
0
        public void Fill(ICellSource source, object pos)
        {
            Image img = (Image)source.GetValue(pos, cellView.ImageField.Index);

            if (img != null)
            {
                ObjectValue = (NSImage)WidgetRegistry.GetBackend(img);
            }
        }
예제 #17
0
        static void DraggingExited(IntPtr sender, IntPtr sel, IntPtr dragInfo)
        {
            IViewObject <T> ob = Runtime.GetNSObject(sender) as IViewObject <T>;

            if (ob != null)
            {
                var backend = (ViewBackend <T, S>)WidgetRegistry.GetBackend(ob.Frontend);
                backend.eventSink.OnDragLeave(EventArgs.Empty);
            }
        }
예제 #18
0
        void MarkDestroyed(Widget w)
        {
            var bk = (WidgetBackend)WidgetRegistry.GetBackend(w);

            bk.destroyed = true;
            foreach (var c in w.Surface.Children)
            {
                MarkDestroyed(c);
            }
        }
예제 #19
0
        public void UpdateLabel(NotebookTab tab, string hint)
        {
            IWidgetBackend widget = (IWidgetBackend)WidgetRegistry.GetBackend(tab.Child);
            var            v      = GetWidget(widget);
            var            t      = FindTab(v);

            if (t != null)
            {
                t.Label = tab.Label;
            }
        }
예제 #20
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            Image image = value as Image;

            if (image == null)
            {
                return(null);
            }

            return(WidgetRegistry.GetBackend(image));
        }
예제 #21
0
 public void SetPattern(object backend, Pattern p)
 {
     Cairo.Context ctx = ((GtkContext)backend).Context;
     if (p != null)
     {
         ctx.Pattern = (Cairo.Pattern)WidgetRegistry.GetBackend(p);
     }
     else
     {
         ctx.Pattern = null;
     }
 }
예제 #22
0
        static NSDragOperation DraggingUpdated(IntPtr sender, IntPtr sel, IntPtr dragInfo)
        {
            IViewObject <T> ob = Runtime.GetNSObject(sender) as IViewObject <T>;

            if (ob == null)
            {
                return(NSDragOperation.None);
            }
            var backend = (ViewBackend <T, S>)WidgetRegistry.GetBackend(ob.Frontend);

            NSDraggingInfo di    = new NSDraggingInfo(dragInfo);
            var            types = di.DraggingPasteboard.Types.Select(t => ToXwtDragType(t)).ToArray();
            var            pos   = new Point(di.DraggingLocation.X, di.DraggingLocation.Y);

            if ((backend.currentEvents & WidgetEvent.DragOverCheck) != 0)
            {
                var args = new DragOverCheckEventArgs(pos, types, ConvertAction(di.DraggingSourceOperationMask));
                Toolkit.Invoke(delegate {
                    backend.eventSink.OnDragOverCheck(args);
                });
                if (args.AllowedAction == DragDropAction.None)
                {
                    return(NSDragOperation.None);
                }
                if (args.AllowedAction != DragDropAction.Default)
                {
                    return(ConvertAction(args.AllowedAction));
                }
            }

            if ((backend.currentEvents & WidgetEvent.DragOver) != 0)
            {
                TransferDataStore store = new TransferDataStore();
                FillDataStore(store, di.DraggingPasteboard, ob.View.RegisteredDragTypes());
                var args = new DragOverEventArgs(pos, store, ConvertAction(di.DraggingSourceOperationMask));
                Toolkit.Invoke(delegate {
                    backend.eventSink.OnDragOver(args);
                });
                if (args.AllowedAction == DragDropAction.None)
                {
                    return(NSDragOperation.None);
                }
                if (args.AllowedAction != DragDropAction.Default)
                {
                    return(ConvertAction(args.AllowedAction));
                }
            }

            return(di.DraggingSourceOperationMask);
        }
예제 #23
0
        /// <summary>
        /// Shows the dialog.
        /// </summary>
        public bool Run(WindowFrame parentWindow)
        {
            var backend = WidgetRegistry.CreateBackend <ISelectColorDialogBackend> (GetType());

            try {
                if (color != Colors.Transparent)
                {
                    backend.Color = color;
                }
                return(backend.Run((IWindowFrameBackend)WidgetRegistry.GetBackend(parentWindow), title, supportsAlpha));
            } finally {
                color = backend.Color;
                backend.Dispose();
            }
        }
예제 #24
0
 public void SetValue(Gtk.TreeIter it, int column, object value)
 {
     if (value is string)
     {
         store.SetValue(it, column, (string)value);
     }
     else if (value is Image)
     {
         store.SetValue(it, column, (Gdk.Pixbuf)WidgetRegistry.GetBackend(value));
     }
     else
     {
         store.SetValue(it, column, value ?? DBNull.Value);
     }
 }
예제 #25
0
        public void DrawImage(object backend, Image img, double x, double y, double alpha)
        {
            Gdk.Pixbuf pb  = (Gdk.Pixbuf)WidgetRegistry.GetBackend(img);
            GtkContext ctx = (GtkContext)backend;

            Gdk.CairoHelper.SetSourcePixbuf(ctx.Context, pb, x, y);
            if (alpha == 1)
            {
                ctx.Context.Paint();
            }
            else
            {
                ctx.Context.PaintWithAlpha(alpha);
            }
        }
예제 #26
0
        public override object GetNativeParentWindow(Widget w)
        {
            var backend = (IWpfWidgetBackend)WidgetRegistry.GetBackend(w);

            FrameworkElement e = backend.Widget;

            while ((e = e.Parent as FrameworkElement) != null)
            {
                if (e is System.Windows.Window)
                {
                    return(e);
                }
            }

            return(null);
        }
예제 #27
0
        public object CreateContext(Widget w)
        {
            GtkContext ctx = new GtkContext();
            var        b   = (IGtkWidgetBackend)WidgetRegistry.GetBackend(w);

            if (!b.Widget.IsRealized)
            {
                Cairo.Surface sf = new Cairo.ImageSurface(Cairo.Format.ARGB32, 1, 1);
                Cairo.Context c  = new Cairo.Context(sf);
                ctx.Context     = c;
                ctx.TempSurface = sf;
            }
            else
            {
                ctx.Context = Gdk.CairoHelper.Create(b.Widget.GdkWindow);
            }
            return(ctx);
        }
예제 #28
0
        public void Fill(object backend)
        {
            ContextInfo ctx = (ContextInfo)backend;

            if (ctx.Pattern is Gradient)
            {
                GradientInfo gr = (GradientInfo)WidgetRegistry.GetBackend(ctx.Pattern);
                NSGradient   g  = new NSGradient(gr.Colors.ToArray(), gr.Stops.ToArray());
                g.DrawInBezierPath(ctx.Path, 0f);
            }
            else
            {
                ctx.Path.Fill();
            }
            ctx.Pattern = null;
            ctx.Path.Dispose();
            ctx.Path = new NSBezierPath();
        }
예제 #29
0
 public void SetValue(Gtk.TreeIter it, int column, object value)
 {
     if (types [column] == typeof(ObjectWrapper) && value != null)
     {
         store.SetValue(it, column, new ObjectWrapper(value));
     }
     else if (value is string)
     {
         store.SetValue(it, column, (string)value);
     }
     else if (value is Image)
     {
         store.SetValue(it, column, (Gdk.Pixbuf)WidgetRegistry.GetBackend(value));
     }
     else
     {
         store.SetValue(it, column, value ?? DBNull.Value);
     }
 }
예제 #30
0
 public static void SetSelectionData(Gtk.SelectionData data, string atomType, object val)
 {
     if (val == null)
     {
         return;
     }
     if (val is string)
     {
         data.Text = (string)val;
     }
     else if (val is Xwt.Drawing.Image)
     {
         data.SetPixbuf((Gdk.Pixbuf)WidgetRegistry.GetBackend(val));
     }
     else
     {
         var at = Gdk.Atom.Intern(atomType, false);
         data.Set(at, 0, TransferDataSource.SerializeValue(val));
     }
 }