Beispiel #1
0
        public bool Contains(int x, int y, Atk.CoordType coordType)
        {
            int x_extents, y_extents, w, h;

            GetExtents(out x_extents, out y_extents, out w, out h, coordType);
            Rectangle extents = new Xwt.Rectangle(x_extents, y_extents, w, h);

            return(extents.Contains(x, y));
        }
Beispiel #2
0
 public void Show(Position arrowPosition, Widget referenceWidget, Xwt.Rectangle positionRect)
 {
     if (content == null)
     {
         throw new InvalidOperationException("A child widget source must be set before running the Popover");
     }
     Backend.Show(arrowPosition, referenceWidget, positionRect, content);
     shown = true;
 }
Beispiel #3
0
        public override void DrawImage(object backend, ImageDescription img, Xwt.Rectangle srcRect, Xwt.Rectangle destRect)
        {
            var ctx = (VectorBackend)backend;

            ctx.Commands.Add(DrawingCommand.DrawImage2);
            ctx.Images.Add(img);
            ctx.Rectangles.Add(srcRect);
            ctx.Rectangles.Add(destRect);
        }
Beispiel #4
0
        protected override void OnSizeAllocated(Gdk.Rectangle allocation)
        {
            if (NudgeHorizontal || NudgeVertical)
            {
                int x, y;
                this.GetPosition(out x, out y);
                int       oldY = y, oldX = x;
                const int edgeGap = 2;

//				int w = allocation.Width;
//
//				if (fitWidthToScreen && (x + w >= screenW - edgeGap)) {
//					int fittedWidth = screenW - x - edgeGap;
//					if (fittedWidth < minFittedWidth) {
//						x -= (minFittedWidth - fittedWidth);
//						fittedWidth = minFittedWidth;
//					}
//					LimitWidth (fittedWidth);
//				}

                Xwt.Rectangle geometry = DesktopService.GetUsableMonitorGeometry(Screen.Number, Screen.GetMonitorAtPoint(x, y));
                int           left     = (int)geometry.Left;
                int           top      = (int)geometry.Top;
                int           width    = (int)geometry.Width;
                int           height   = (int)geometry.Height;
                if (NudgeHorizontal)
                {
                    if (allocation.Width <= geometry.Width && x + allocation.Width >= geometry.Left + geometry.Width - edgeGap)
                    {
                        x = left + (width - allocation.Width - edgeGap);
                    }
                    if (x <= left + edgeGap)
                    {
                        x = left + edgeGap;
                    }
                }

                if (NudgeVertical)
                {
                    if (allocation.Height <= geometry.Height && y + allocation.Height >= geometry.Top + geometry.Height - edgeGap)
                    {
                        y = top + (height - allocation.Height - edgeGap);
                    }
                    if (y <= top + edgeGap)
                    {
                        y = top + edgeGap;
                    }
                }

                if (y != oldY || x != oldX)
                {
                    Move(x, y);
                }
            }

            base.OnSizeAllocated(allocation);
        }
Beispiel #5
0
        public void Show(Xwt.Popover.Position orientation, Xwt.Widget reference, Xwt.Rectangle positionRect, Widget child)
        {
            popover.Content         = (Gtk.Widget)((WidgetBackend)Toolkit.GetBackend(child)).NativeWidget;
            popover.ArrowPosition   = orientation;
            popover.BackgroundColor = BackgroundColor.ToCairoColor();
            popover.Padding         = frontend.Padding;

            var parent = (WindowFrameBackend)Toolkit.GetBackend(reference.ParentWindow);

            if (popover.TransientFor != parent.Window)
            {
                if (popover.TransientFor != null)
                {
                    popover.TransientFor.FocusInEvent -= HandleParentFocusInEvent;
                }
                popover.TransientFor = parent.Window;
                popover.TransientFor.FocusInEvent += HandleParentFocusInEvent;
            }

            popover.Hidden += (o, args) => sink.OnClosed();

            var screenBounds = reference.ScreenBounds;

            if (positionRect == Rectangle.Zero)
            {
                positionRect = new Rectangle(Point.Zero, screenBounds.Size);
            }
            positionRect = positionRect.Offset(screenBounds.Location);
            var position = new Point(positionRect.Center.X, popover.ArrowPosition == Popover.Position.Top ? positionRect.Bottom : positionRect.Top);

            popover.Show();
            popover.Present();
            popover.GrabFocus();
            int w, h;

            popover.GetSize(out w, out h);
            if (popover.ArrowPosition == Popover.Position.Top)
            {
                popover.Move((int)position.X - w / 2, (int)position.Y);
            }
            else
            {
                popover.Move((int)position.X - w / 2, (int)position.Y - h);
            }
            popover.SizeAllocated += (o, args) => {
                if (popover.ArrowPosition == Popover.Position.Top)
                {
                    popover.Move((int)position.X - args.Allocation.Width / 2, (int)position.Y);
                }
                else
                {
                    popover.Move((int)position.X - args.Allocation.Width / 2, (int)position.Y - args.Allocation.Height);
                }
                popover.GrabFocus();
            };
        }
Beispiel #6
0
        internal void ShowPopup(Xwt.Widget widget, Xwt.Rectangle caret, PopupPosition position)
        {
            xwtParent            = widget;
            this.currentCaret    = new Gdk.Rectangle((int)caret.X, (int)caret.Y, (int)caret.Width, (int)caret.Height);
            Theme.TargetPosition = position;
            var pos = GtkUtil.GetSceenBounds(widget);

            targetWindowOrigin = new Point((int)pos.X, (int)pos.Y);
            RepositionWindow();
        }
Beispiel #7
0
        internal async void UpdateParameterInfoLocation()
        {
            var isCompletionWindowVisible = (CompletionWindowManager.Wnd?.Visible ?? false);
            var ctx        = Widget.CurrentCodeCompletionContext;
            var lineHeight = (int)Ext.Editor.LineHeight;
            var geometry   = Xwt.MessageDialog.RootWindow.Screen.VisibleBounds;
            var cmg        = ParameterInformationWindowManager.CurrentMethodGroup;

            int cparam = Ext != null ? await Ext.GetCurrentParameterIndex(cmg.MethodProvider.ApplicableSpan.Start) : 0;

            var lastW = (int)Width;
            var lastH = (int)Height;

            int X, Y;

            X = cmg.CompletionContext.TriggerXCoord;
            if (isCompletionWindowVisible)
            {
                // place above
                Y = ctx.TriggerYCoord - lineHeight - (int)lastH - 10;
            }
            else
            {
                // place below
                Y = ctx.TriggerYCoord;
            }

            if (X + lastW > geometry.Right)
            {
                X = (int)geometry.Right - (int)lastW;
            }
            if (Y < geometry.Top)
            {
                Y = ctx.TriggerYCoord;
            }
            if (Y + lastH > geometry.Bottom)
            {
                Y = Y - lineHeight - (int)lastH - 4;
            }

            if (isCompletionWindowVisible)
            {
                var completionWindow = new Xwt.Rectangle(CompletionWindowManager.X, CompletionWindowManager.Y - lineHeight, CompletionWindowManager.Wnd.Allocation.Width, CompletionWindowManager.Wnd.Allocation.Height + lineHeight * 2);
                if (completionWindow.IntersectsWith(new Xwt.Rectangle(X, Y, lastW, lastH)))
                {
                    X = (int)completionWindow.X;
                    Y = (int)completionWindow.Y - (int)lastH - 6;
                    if (Y < 0)
                    {
                        Y = (int)completionWindow.Bottom + 6;
                    }
                }
            }
            Location = new Xwt.Point(X, Y);
        }
        Gdk.Size GetIdealSize()
        {
            Gdk.Size retVal = new Gdk.Size();
            int      ox, oy;

            GetPosition(out ox, out oy);
            Xwt.Rectangle geometry  = DesktopService.GetUsableMonitorGeometry(Screen.Number, Screen.GetMonitorAtPoint(ox, oy));
            int           maxHeight = (int)geometry.Height * 4 / 5;
            double        startY    = yMargin + ChildAllocation.Y;
            double        y         = startY;

            calculatedItems = 0;
            foreach (var result in results)
            {
                var dataSrc = result.Item2;
                if (dataSrc.Count == 0)
                {
                    continue;
                }

                for (int i = 0; i < maxItems && i < dataSrc.Count; i++)
                {
                    layout.SetMarkup(GetRowMarkup(dataSrc[i]));
                    int w, h;
                    layout.GetPixelSize(out w, out h);
                    if (y + h + itemSeparatorHeight > maxHeight)
                    {
                        break;
                    }
                    y += h + itemSeparatorHeight;
                    calculatedItems++;
                }
            }
            retVal.Width = Math.Min((int)geometry.Width * 4 / 5, 480);
            if (Math.Abs(y - startY) < 1)
            {
                layout.SetMarkup(GettextCatalog.GetString("No matches"));
                int w, h;
                layout.GetPixelSize(out w, out h);
                var realHeight = h + itemSeparatorHeight + 4;
                y += realHeight;
            }
            else
            {
                y -= itemSeparatorHeight;
            }

            var calculatedHeight = Math.Min(
                maxHeight,
                (int)y + yMargin + results.Count(res => res.Item2.Count > 0) * categorySeparatorHeight
                );

            retVal.Height = calculatedHeight;
            return(retVal);
        }
        static async void PositionParameterInfoWindow(Rectangle allocation)
        {
            lastW = allocation.Width;
            lastH = allocation.Height;
            var isCompletionWindowVisible = wasCompletionWindowVisible = (CompletionWindowManager.Wnd?.Visible ?? false);
            var ctx    = window.Widget.CurrentCodeCompletionContext;
            int cparam = window.Ext != null ? await window.Ext.GetCurrentParameterIndex(currentMethodGroup.MethodProvider.StartOffset) : 0;

            X = currentMethodGroup.CompletionContext.TriggerXCoord;
            if (isCompletionWindowVisible)
            {
                // place above
                Y = ctx.TriggerYCoord - ctx.TriggerTextHeight - allocation.Height - 10;
            }
            else
            {
                // place below
                Y = ctx.TriggerYCoord;
            }

            var geometry = DesktopService.GetUsableMonitorGeometry(window.Screen.Number, window.Screen.GetMonitorAtPoint(X, Y));

            window.ShowParameterInfo(currentMethodGroup.MethodProvider, currentMethodGroup.CurrentOverload, cparam - 1, (int)geometry.Width);

            if (X + allocation.Width > geometry.Right)
            {
                X = (int)geometry.Right - allocation.Width;
            }
            if (Y < geometry.Top)
            {
                Y = ctx.TriggerYCoord;
            }
            if (wasAbove || Y + allocation.Height > geometry.Bottom)
            {
                Y        = Y - ctx.TriggerTextHeight - allocation.Height - 4;
                wasAbove = true;
            }

            if (isCompletionWindowVisible)
            {
                var completionWindow = new Xwt.Rectangle(CompletionWindowManager.X, CompletionWindowManager.Y, CompletionWindowManager.Wnd.Allocation.Width, CompletionWindowManager.Wnd.Allocation.Height);
                if (completionWindow.IntersectsWith(new Xwt.Rectangle(X, Y, allocation.Width, allocation.Height)))
                {
                    X = (int)completionWindow.X;
                    Y = (int)completionWindow.Y - allocation.Height - 6;
                    if (Y < 0)
                    {
                        Y = (int)completionWindow.Bottom + 6;
                    }
                }
            }

            window.Move(X, Y);
        }
        async void RequestPopup(Xwt.Rectangle rect)
        {
            var token = popupSrc.Token;

            diff = await Task.Run(async delegate {
                try {
                    foreach (var op in await codeAction.GetPreviewOperationsAsync(token))
                    {
                        var ac = op as ApplyChangesOperation;
                        if (ac == null)
                        {
                            continue;
                        }
                        var changedDocument = ac.ChangedSolution.GetDocument(documentContext.AnalysisDocument.Id);

                        changedTextDocument = TextEditorFactory.CreateNewDocument(new StringTextSource((await changedDocument.GetTextAsync(token)).ToString()), editor.FileName);
                        try {
                            var list = new List <DiffHunk> (editor.GetDiff(changedTextDocument, new DiffOptions(false, true)));
                            if (list.Count > 0)
                            {
                                return(list);
                            }
                        } catch (Exception e) {
                            LoggingService.LogError("Error while getting preview list diff.", e);
                        }
                    }
                } catch (OperationCanceledException) {}
                return(new List <DiffHunk> ());
            });

            if (diff.Count > 0 && !token.IsCancellationRequested)
            {
                var pos = PopupPosition.Left;
                if (Platform.IsMac)
                {
                    var screenRect = GtkUtil.ToScreenCoordinates(IdeApp.Workbench.RootWindow, IdeApp.Workbench.RootWindow.GdkWindow, rect.ToGdkRectangle());
                    var geometry   = Screen.GetUsableMonitorGeometry(Screen.GetMonitorAtPoint(screenRect.X, screenRect.Y));
                    var request    = SizeRequest();
                    if (screenRect.X - geometry.X < request.Width)
                    {
                        pos = PopupPosition.Top;
                        if (geometry.Bottom - screenRect.Bottom < request.Height)
                        {
                            pos = PopupPosition.Bottom;
                        }
                    }
                    else
                    {
                        pos = PopupPosition.Right;
                    }
                }
                ShowPopup(rect, pos);
            }
        }
Beispiel #11
0
        private void ProcessPage(Xwt.Drawing.Context g, IEnumerable p)
        {
            foreach (PageItem pi in p)
            {

                if (pi is PageTextHtml)
                {   // PageTextHtml is actually a composite object (just like a page) 
                    ProcessHtml(pi as PageTextHtml, g);
                    continue;
                }

                if (pi is PageLine)
                {
                    PageLine pl = pi as PageLine;
               
                    Xwt.Drawing.Color bcolorleft = XwtColor.SystemColorToXwtColor(pl.SI.BColorLeft);

                    DrawLine(bcolorleft, pl.SI.BStyleLeft, pl.SI.BWidthLeft,
                        g, PixelsX(pl.X), PixelsY(pl.Y), PixelsX(pl.X2), PixelsY(pl.Y2)
                    );
                    continue;
                }

                Xwt.Rectangle rect = new Xwt.Rectangle(PixelsX(pi.X), PixelsY(pi.Y), PixelsX(pi.W), PixelsY(pi.H));
            

                if (pi.SI.BackgroundImage != null)
                {
                    // put out any background image 
                    PageImage i = pi.SI.BackgroundImage;
                    DrawImage(i, g, rect);
                    continue;
                }

                if (pi is PageText)
                {
                    PageText pt = pi as PageText;
                    DrawString(pt, g, rect);
                }

                if (pi is PageImage)
                {
                    PageImage i = pi as PageImage;
                    DrawImage(i, g, rect);
                }

                if (pi is PageRectangle)
                {
                    //DrawBackground(g, rect, pi.SI);
                }
               
                DrawBorder(pi, g, rect);
            }
        }
Beispiel #12
0
        private void ProcessPage(Xwt.Drawing.Context g, IEnumerable p)
        {
            foreach (PageItem pi in p)
            {
                if (pi is PageTextHtml)
                {   // PageTextHtml is actually a composite object (just like a page)
                    ProcessHtml(pi as PageTextHtml, g);
                    continue;
                }

                if (pi is PageLine)
                {
                    PageLine pl = pi as PageLine;

                    Xwt.Drawing.Color bcolorleft = XwtColor.SystemColorToXwtColor(pl.SI.BColorLeft);

                    DrawLine(bcolorleft, pl.SI.BStyleLeft, pl.SI.BWidthLeft,
                             g, PixelsX(pl.X), PixelsY(pl.Y), PixelsX(pl.X2), PixelsY(pl.Y2)
                             );
                    continue;
                }

                Xwt.Rectangle rect = new Xwt.Rectangle(PixelsX(pi.X), PixelsY(pi.Y), PixelsX(pi.W), PixelsY(pi.H));


                if (pi.SI.BackgroundImage != null)
                {
                    // put out any background image
                    PageImage i = pi.SI.BackgroundImage;
                    DrawImage(i, g, rect);
                    continue;
                }

                if (pi is PageText)
                {
                    PageText pt = pi as PageText;
                    DrawString(pt, g, rect);
                }

                if (pi is PageImage)
                {
                    PageImage i = pi as PageImage;
                    DrawImage(i, g, rect);
                }

                if (pi is PageRectangle)
                {
                    //DrawBackground(g, rect, pi.SI);
                }

                DrawBorder(pi, g, rect);
            }
        }
Beispiel #13
0
            Xwt.Rectangle RecalibrateChildRectangle(Xwt.Rectangle bounds)
            {
                switch (arrowPosition)
                {
                case Xwt.Popover.Position.Top:
                    return(new Rectangle(bounds.X, bounds.Y + arrowPadding, bounds.Width, bounds.Height - arrowPadding));

                case Xwt.Popover.Position.Bottom:
                    return(new Rectangle(bounds.X, bounds.Y, bounds.Width, bounds.Height - arrowPadding));
                }
                return(bounds);
            }
Beispiel #14
0
            protected override bool OnExposeEvent(Gdk.EventExpose evnt)
            {
                int w, h;

                this.GdkWindow.GetSize(out w, out h);
                var bounds          = new Xwt.Rectangle(0.5, 0.5, w - 1, h - 1);
                var backgroundColor = Xwt.Drawing.Color.FromBytes(230, 230, 230, 230);
                var black           = Xwt.Drawing.Color.FromBytes(60, 60, 60);

                using (Context ctx = Gdk.CairoHelper.Create(this.GdkWindow)) {
                    // We clear the surface with a transparent color if possible
                    if (supportAlpha)
                    {
                        ctx.Color = new Color(1.0, 1.0, 1.0, 0.0);
                    }
                    else
                    {
                        ctx.Color = new Color(1.0, 1.0, 1.0);
                    }
                    ctx.Operator = Operator.Source;
                    ctx.Paint();

                    var calibratedRect = RecalibrateChildRectangle(bounds);
                    // Fill it with one round rectangle
                    RoundRectangle(ctx, calibratedRect, radius);
                    ctx.LineWidth = 1;
                    ctx.Color     = new Color(black.Red, black.Green, black.Blue, black.Alpha);
                    ctx.StrokePreserve();
                    ctx.Color = new Color(backgroundColor.Red, backgroundColor.Green, backgroundColor.Blue, backgroundColor.Alpha);
                    ctx.Fill();

                    // Triangle
                    // We first begin by positionning ourselves at the top-center or bottom center of the previous rectangle
                    var arrowX = bounds.Center.X;
                    var arrowY = arrowPosition == Xwt.Popover.Position.Top ? calibratedRect.Top + ctx.LineWidth : calibratedRect.Bottom - ctx.LineWidth;
                    ctx.NewPath();
                    ctx.MoveTo(arrowX, arrowY);
                    // We draw the rectangle path
                    DrawTriangle(ctx);
                    // We use it
                    ctx.Color = new Color(black.Red, black.Green, black.Blue, black.Alpha);
                    ctx.StrokePreserve();
                    ctx.ClosePath();
                    ctx.Color = new Color(backgroundColor.Red, backgroundColor.Green, backgroundColor.Blue, backgroundColor.Alpha);
                    ctx.Fill();
                }

                base.OnExposeEvent(evnt);
                return(false);
            }
Beispiel #15
0
        protected internal override void DrawBackground(Context cr, Xwt.Rectangle area, DocumentLine line, int lineNumber, double x, double y, double height)
        {
            if (line == null)
            {
                return;
            }

            if (lineNumber == editor.Caret.Line)
            {
                cr.SetColor(editor.Options.ColorScheme.LineMarker.Color);
                cr.Rectangle(x, y, editor.GetWidth(), height);
                cr.Fill();
            }

            var style          = SyntaxModeService.DefaultColorStyle;
            var selectionStyle = editor.HasFocus ? style.SelectedText : style.SelectedInactiveText;

            var selectionSegment = GetSegmentForLine(editor.Selection, line);

            if (selectionSegment != null)
            {
                int logicalStartColumn = selectionSegment.Value.Offset - line.Offset;
                int visualStartColumn  = line.GetVisualColumn(editor, logicalStartColumn);

                if (selectionSegment.Value.Offset == line.Offset)
                {
                    visualStartColumn = 0;
                }

                int logicalEndColumn = selectionSegment.Value.EndOffset - line.Offset;
                int visualEndColumn  = line.GetVisualColumn(editor, logicalEndColumn);

                if (editor.Selection.EndOffset != selectionSegment.Value.EndOffset && visualEndColumn > 0)
                {
                    visualEndColumn--;
                }

                if (editor.Selection.Contains(line.EndOffset))
                {
                    ++visualEndColumn;
                }

                cr.SetColor(selectionStyle.Background);
                double startX = x + visualStartColumn * CharWidth;
                double endX   = x + visualEndColumn * CharWidth;
                cr.Rectangle(startX, y, endX - startX, LineHeight);
                cr.Fill();
            }
        }
Beispiel #16
0
            protected override bool OnDrawn(Context cr)
            {
                int w, h;

                this.GdkWindow.GetSize(out w, out h);

                // We clear the surface with a transparent color if possible
                if (supportAlpha)
                {
                    cr.SetSourceRGBA(1.0, 1.0, 1.0, 0.0);
                }
                else
                {
                    cr.SetSourceRGB(1.0, 1.0, 1.0);
                }
                cr.Operator = Operator.Source;
                cr.Paint();

                cr.LineWidth = GtkWorkarounds.GetScaleFactor(Content) > 1 ? 2 : 1;
                var bounds         = new Xwt.Rectangle(cr.LineWidth / 2, cr.LineWidth / 2, w - cr.LineWidth, h - cr.LineWidth);
                var calibratedRect = RecalibrateChildRectangle(bounds);

                // Fill it with one round rectangle
                RoundRectangle(cr, calibratedRect, radius);

                // Triangle
                // We first begin by positionning ourselves at the top-center or bottom center of the previous rectangle
                var arrowX = bounds.Center.X + arrowDelta;
                var arrowY = arrowPosition == Xwt.Popover.Position.Top ? calibratedRect.Top + cr.LineWidth : calibratedRect.Bottom;

                cr.MoveTo(arrowX, arrowY);
                // We draw the rectangle path
                DrawTriangle(cr);

                // We use it
                if (supportAlpha)
                {
                    cr.SetSourceRGBA(0.0, 0.0, 0.0, 0.2);
                }
                else
                {
                    cr.SetSourceRGB(238d / 255d, 238d / 255d, 238d / 255d);
                }
                cr.StrokePreserve();
                cr.SetSourceRGBA(BackgroundColor.R, BackgroundColor.G, BackgroundColor.B, BackgroundColor.A);
                cr.Fill();

                return(base.OnDrawn(cr));
            }
Beispiel #17
0
 private void DrawImage(PageImage pi, Xwt.Drawing.Context g, Xwt.Rectangle r)
 {
     System.IO.MemoryStream ms = new System.IO.MemoryStream(pi.ImageData);
     Xwt.Drawing.Image      im = null;
     try
     {
         im = Xwt.Drawing.Image.FromStream(ms);
         DrawImageSized(pi, im, g, r);
     }
     finally
     {
         if (im != null)
         {
             im.Dispose();
         }
     }
 }
        void Reposition(bool force)
        {
            X = CodeCompletionContext.TriggerXCoord - TextOffset;
            Y = CodeCompletionContext.TriggerYCoord;

            int w, h;

            GetSize(out w, out h);

            if (!force && previousHeight != h && previousWidth != w)
            {
                return;
            }

            // Note: we add back the TextOffset here in case X and X+TextOffset are on different monitors.
            Xwt.Rectangle geometry = DesktopService.GetUsableMonitorGeometry(Screen.Number, Screen.GetMonitorAtPoint(X + TextOffset, Y));

            previousHeight = h;
            previousWidth  = w;

            if (X + w > geometry.Right)
            {
                X = (int)geometry.Right - w;
            }
            else if (X < geometry.Left)
            {
                X = (int)geometry.Left;
            }

            if (Y + h > geometry.Bottom || yPosition == WindowPositonY.Top)
            {
                // Put the completion-list window *above* the cursor
                Y         = Y - CodeCompletionContext.TriggerTextHeight - h;
                yPosition = WindowPositonY.Top;
            }
            else
            {
                yPosition = WindowPositonY.Bottom;
            }

            curXPos = X;
            curYPos = Y;
            Move(X, Y);
            UpdateDeclarationView();
        }
Beispiel #19
0
 protected override void OnDraw(Xwt.Drawing.Context ctx, Xwt.Rectangle dirtyRect)
 {
     base.OnDraw(ctx, dirtyRect);
     if (image != null)
     {
         ctx.DrawImage(image, 0, 0);
         if (filler != null)
         {
             int    fillCount = (int)Math.Ceiling((Bounds.Width - image.Width) / filler.Width);
             double x         = image.Width;
             while ((fillCount--) > 0)
             {
                 ctx.DrawImage(filler, x, 0);
                 x += filler.Width;
             }
         }
     }
 }
Beispiel #20
0
        protected internal override void Draw(Context cr, Xwt.Rectangle area, DocumentLine line, int lineNumber, double x, double y, double height)
        {
            if (lineNumber <= editor.Document.LineCount)
            {
                TextLayout layout;
                if (!layoutDict.TryGetValue(lineNumber, out layout))
                {
                    layout      = new TextLayout();
                    layout.Font = editor.Options.EditorFont;
                    layout.Text = lineNumber.ToString();

                    layoutDict[lineNumber] = layout;
                }

                cr.SetColor(Colors.Black);
                cr.DrawTextLayout(layout, x + leftPadding, y);
            }
        }
Beispiel #21
0
            protected override bool OnDrawn(Context cr)
            {
                int w, h;

                this.GdkWindow.GetSize(out w, out h);
                var bounds = new Xwt.Rectangle(0.5, 0.5, w - 1, h - 1);
                var black  = Xwt.Drawing.Color.FromBytes(0xaa, 0xaa, 0xaa);

                // We clear the surface with a transparent color if possible
                if (supportAlpha)
                {
                    cr.SetSourceRGBA(1.0, 1.0, 1.0, 0.0);
                }
                else
                {
                    cr.SetSourceRGB(1.0, 1.0, 1.0);
                }
                cr.Operator = Operator.Source;
                cr.Paint();

                var calibratedRect = RecalibrateChildRectangle(bounds);

                // Fill it with one round rectangle
                RoundRectangle(cr, calibratedRect, radius);
                cr.LineWidth = .5;

                // Triangle
                // We first begin by positionning ourselves at the top-center or bottom center of the previous rectangle
                var arrowX = bounds.Center.X;
                var arrowY = arrowPosition == Xwt.Popover.Position.Top ? calibratedRect.Top + cr.LineWidth : calibratedRect.Bottom;

                cr.MoveTo(arrowX, arrowY);
                // We draw the rectangle path
                DrawTriangle(cr);

                // We use it
                cr.SetSourceRGBA(black.Red, black.Green, black.Blue, black.Alpha);
                cr.StrokePreserve();
                cr.SetSourceRGBA(BackgroundColor.R, BackgroundColor.G, BackgroundColor.B, BackgroundColor.A);
                cr.Fill();

                return(base.OnDrawn(cr));
            }
Beispiel #22
0
        private void DrawBorder(PageItem pi, Xwt.Drawing.Context g, Xwt.Rectangle r)
        {
            if (r.Height <= 0 || r.Width <= 0)      // no bounding box to use
            {
                return;
            }

            double    right  = r.X + r.Width;
            double    bottom = r.Y + r.Height;
            StyleInfo si     = pi.SI;


            Xwt.Drawing.Color ec = XwtColor.SystemColorToXwtColor(si.BackgroundGradientEndColor);

            DrawLine(XwtColor.SystemColorToXwtColor(si.BColorTop), si.BStyleTop, si.BWidthTop, g, r.X, r.Y, right, r.Y);
            DrawLine(XwtColor.SystemColorToXwtColor(si.BColorRight), si.BStyleRight, si.BWidthRight, g, right, r.Y, right, bottom);
            DrawLine(XwtColor.SystemColorToXwtColor(si.BColorLeft), si.BStyleLeft, si.BWidthLeft, g, r.X, r.Y, r.X, bottom);
            DrawLine(XwtColor.SystemColorToXwtColor(si.BColorBottom), si.BStyleBottom, si.BWidthBottom, g, r.X, bottom, right, bottom);
        }
Beispiel #23
0
        internal protected override void Draw(Xwt.Drawing.Context cr, Xwt.Rectangle area, DocumentLine lineSegment, int line, double x, double y, double lineHeight)
        {
            var  marker         = lineSegment != null ? (MarginMarker)lineSegment.Markers.FirstOrDefault(m => m is MarginMarker && ((MarginMarker)m).CanDraw(this)) : null;
            bool drawBackground = true;

            if (marker != null && marker.CanDrawBackground(this))
            {
                drawBackground = !marker.DrawBackground(editor, cr, new MarginDrawMetrics(this, area, lineSegment, line, x, y, lineHeight));
            }

            if (drawBackground)
            {
                DrawMarginBackground(cr, line, x, y, lineHeight);
            }

            if (marker != null && marker.CanDrawForeground(this))
            {
                marker.DrawForeground(editor, cr, new MarginDrawMetrics(this, area, lineSegment, line, x, y, lineHeight));
            }
        }
Beispiel #24
0
        void PositionWidget(Gtk.Widget widget)
        {
            if (!(widget is Gtk.Window))
            {
                return;
            }
            int ox, oy;

            ParentWindow.GetOrigin(out ox, out oy);
            int w;
            int itemXPosition = GetHoverXPosition(out w);
            int dx            = ox + this.Allocation.X + itemXPosition;
            int dy            = oy + this.Allocation.Bottom;

            var req = widget.SizeRequest();

            Xwt.Rectangle geometry  = IdeServices.DesktopService.GetUsableMonitorGeometry(Screen.Number, Screen.GetMonitorAtPoint(dx, dy));
            int           geomWidth = (int)geometry.Width;
            int           geomLeft  = (int)geometry.Left;
            int           geomRight = (int)geometry.Right;
            int           width     = System.Math.Max(req.Width, w);

            if (width >= geomWidth - spacing * 2)
            {
                width = geomWidth - spacing * 2;
                dx    = geomLeft + spacing;
            }
            widget.WidthRequest = width;
            if (dy + req.Height > geometry.Bottom)
            {
                dy = oy + this.Allocation.Y - req.Height;
            }
            if (dx + width > geomRight)
            {
                dx = geomRight - width;
            }
            (widget as Gtk.Window).Move(dx, dy);
            (widget as Gtk.Window).Resize(width, req.Height);
            widget.GrabFocus();
        }
Beispiel #25
0
        public void Show(Xwt.Popover.Position orientation, Xwt.Widget reference, Xwt.Rectangle positionRect, Widget child)
        {
            ActualPosition = orientation;
            Border.Child   = (System.Windows.FrameworkElement)Context.Toolkit.GetNativeWidget(child);
            NativeWidget.CustomPopupPlacementCallback = (popupSize, targetSize, offset) => {
                System.Windows.Point location;
                if (ActualPosition == Popover.Position.Top)
                {
                    location = new System.Windows.Point(positionRect.Left, positionRect.Bottom);
                }
                else
                {
                    location = new System.Windows.Point(positionRect.Left, positionRect.Top - popupSize.Height);
                }

                return(new[] {
                    new System.Windows.Controls.Primitives.CustomPopupPlacement(location, System.Windows.Controls.Primitives.PopupPrimaryAxis.Horizontal)
                });
            };
            NativeWidget.PlacementTarget = (System.Windows.FrameworkElement)Context.Toolkit.GetNativeWidget(reference);
            NativeWidget.IsOpen          = true;
        }
Beispiel #26
0
        public void Show(Xwt.Popover.Position orientation, Xwt.Widget reference, Xwt.Rectangle positionRect, Widget child)
        {
            ActualPosition = orientation;
            SetupBorderMargin();
            Border.Child = (System.Windows.FrameworkElement)Context.Toolkit.GetNativeWidget(child);
            NativeWidget.CustomPopupPlacementCallback = (popupSize, targetSize, offset) => {
                System.Windows.Point location;
                if (ActualPosition == Popover.Position.Top)
                {
                    location = new System.Windows.Point(positionRect.Left - popupSize.Width / 2,
                                                        positionRect.Height > 0 ? positionRect.Bottom : targetSize.Height);
                }
                else
                {
                    location = new System.Windows.Point(positionRect.Left - popupSize.Width / 2,
                                                        positionRect.Top - popupSize.Height);
                }

                return(new[] {
                    new System.Windows.Controls.Primitives.CustomPopupPlacement(location, System.Windows.Controls.Primitives.PopupPrimaryAxis.Horizontal)
                });
            };
            NativeWidget.PlacementTarget = (System.Windows.FrameworkElement)Context.Toolkit.GetNativeWidget(reference);
            NativeWidget.IsOpen          = true;

            // Popups are special in that the automation properties need to be set on the PopupRoot, which only exists when the popup is shown
            // See https://social.msdn.microsoft.com/Forums/vstudio/en-US/d4ba12c8-7a87-478e-b064-5620f929a0cf/how-to-set-automationid-and-name-for-popup?forum=wpf
            var accessibleBackend = (AccessibleBackend)Toolkit.GetBackend(Frontend.Accessible);

            if (accessibleBackend != null)
            {
                FrameworkElement popupRoot = GetPopupRoot();
                if (popupRoot != null)
                {
                    accessibleBackend.InitAutomationProperties(popupRoot);
                }
            }
        }
Beispiel #27
0
        public void Show(Xwt.Popover.Position orientation, Xwt.Widget reference, Xwt.Rectangle positionRect, Widget child)
        {
            var parent = reference.ParentWindow;

            popover = new PopoverWindow((Gtk.Widget)((WidgetBackend)Xwt.Engine.WidgetRegistry.GetBackend(child)).NativeWidget, orientation);
            popover.SetPadding(frontend.Padding);
            popover.TransientFor      = ((WindowFrameBackend)Xwt.Engine.WidgetRegistry.GetBackend(parent)).Window;
            popover.DestroyWithParent = true;
            popover.Hidden           += (o, args) => {
                popover.ReleaseInnerWidget();
                sink.OnClosed();
                popover.Destroy();
            };

            var position = new Point(reference.ScreenBounds.Center.X, popover.ArrowPosition == Popover.Position.Top ? reference.ScreenBounds.Bottom : reference.ScreenBounds.Top);

            popover.ShowAll();
            popover.GrabFocus();
            int w, h;

            popover.GetSize(out w, out h);
            popover.Move((int)position.X - w / 2, (int)position.Y);
            popover.SizeAllocated += (o, args) => { popover.Move((int)position.X - args.Allocation.Width / 2, (int)position.Y); popover.GrabFocus(); };
        }
Beispiel #28
0
        public static PopupWindow Show(Widget reference, Xwt.Rectangle positionRect, Widget child)
        {
            var popup    = new PopupWindow(child);
            var topLevel = (Window)reference.Toplevel;

            popup.DestroyWithParent = true;

            popup.BorderWidth = topLevel.BorderWidth;

            // bounds of reference widget in screen coordinates
            var referenceBounds = Xwt.Rectangle.Zero;

            // position of popup
            Func <Xwt.Point> calcPosition = () => {
                referenceBounds = new Xwt.Rectangle(
                    GtkBackendHelper.ConvertToScreenCoordinates(reference, Xwt.Point.Zero),
                    new Xwt.Size(reference.Allocation.Width, reference.Allocation.Height));

                if (positionRect == Xwt.Rectangle.Zero)
                {
                    positionRect = new Xwt.Rectangle(Xwt.Point.Zero, referenceBounds.Size);
                }
                positionRect = positionRect.Offset(referenceBounds.Location);
                return(new Xwt.Point(positionRect.X, positionRect.Bottom));
            };

            var popupPosition = calcPosition();

            if (child == null)
            {
                popup.SetSizeRequest((int)referenceBounds.Width, (int)referenceBounds.Height);
            }
            else
            {
                popup.DefaultWidth = 10;
                child.ShowAll();
            }
            var topLevelPos = GtkBackendHelper.ConvertToScreenCoordinates(topLevel, Xwt.Point.Zero);

            popup.TransientPosition = popupPosition.Offset(-topLevelPos.X, -topLevelPos.Y);
            Gtk.SizeAllocatedHandler sizeAllocated = (o, args) => {
                popup.Move((int)popupPosition.X, (int)popupPosition.Y);
                popup.GrabFocus();
            };
            popup.SizeAllocated += sizeAllocated;

            topLevel.AddEvents((int)Gdk.EventMask.StructureMask);

            topLevel.ConfigureEvent -= popup.TopLevelConfigureEvent;
            topLevel.ConfigureEvent += popup.TopLevelConfigureEvent;

            // if the mouse is moved in toplevel-window:
            Gtk.MotionNotifyEventHandler topLevelMotion = (s, args) => {
                if (topLevel == null)
                {
                    return;
                }

                topLevelPos = GtkBackendHelper.ConvertToScreenCoordinates(topLevel, Xwt.Point.Zero);
                var referencePos = GtkBackendHelper.ConvertToScreenCoordinates(reference, Xwt.Point.Zero);

                // take args in sceen coordinates:
                var motionPos = new Xwt.Point(args.Event.XRoot, args.Event.YRoot);//topLevelPos.Offset (args.Event.X, args.Event.Y);

                var tolerance = popup.Tolerance;
                var popupSize = new Xwt.Size(popup.Allocation.Width, popup.Allocation.Height);

                // var refBounds = new Xwt.Rectangle (refPos, screenBounds.Size);
                var motionBounds = new Xwt.Rectangle(
                    referencePos.X - tolerance.Left,
                    referencePos.Y - tolerance.Top,
                    popupSize.Width + tolerance.HorizontalSpacing,
                    popupSize.Height + tolerance.VerticalSpacing);

                // TODO: hide if other event than move-event occurs outside of popup window
                // TODO: something is wrong with referencepos; maybe ConvertToScreenCoordinates has an error

                if (!motionBounds.Contains(motionPos))
                {
                    popup.HideAll();
                }
            };
            topLevel.MotionNotifyEvent += topLevelMotion;

            //ClientEvent: a message has been received from another application.

            popup.ShowAll();

            popup.Hidden += (o, args) => {
                topLevel.ConfigureEvent    -= popup.TopLevelConfigureEvent;
                topLevel.MotionNotifyEvent -= topLevelMotion;
                popup.ReleaseInnerWidget();
                popup.Destroy();
            };
            return(popup);
        }
Beispiel #29
0
            protected override bool OnExposeEvent(Gdk.EventExpose evnt)
            {
                int w, h;
                this.GdkWindow.GetSize (out w, out h);
                var bounds = new Xwt.Rectangle (0.5, 0.5, w - 1, h - 1);
                var backgroundColor = Xwt.Drawing.Color.FromBytes (230, 230, 230, 230);
                var black = Xwt.Drawing.Color.FromBytes (60, 60, 60);

                using (Context ctx = Gdk.CairoHelper.Create (this.GdkWindow)) {
                    // We clear the surface with a transparent color if possible
                    if (supportAlpha)
                        ctx.Color = new Color (1.0, 1.0, 1.0, 0.0);
                    else
                        ctx.Color = new Color (1.0, 1.0, 1.0);
                    ctx.Operator = Operator.Source;
                    ctx.Paint ();

                    var calibratedRect = RecalibrateChildRectangle (bounds);
                    // Fill it with one round rectangle
                    RoundRectangle (ctx, calibratedRect, radius);
                    ctx.LineWidth = 1;
                    ctx.Color = new Color (black.Red, black.Green, black.Blue, black.Alpha);
                    ctx.StrokePreserve ();
                    ctx.Color = new Color (backgroundColor.Red, backgroundColor.Green, backgroundColor.Blue, backgroundColor.Alpha);
                    ctx.Fill ();

                    // Triangle
                    // We first begin by positionning ourselves at the top-center or bottom center of the previous rectangle
                    var arrowX = bounds.Center.X;
                    var arrowY = arrowPosition == Xwt.Popover.Position.Top ? calibratedRect.Top + ctx.LineWidth : calibratedRect.Bottom - ctx.LineWidth;
                    ctx.NewPath ();
                    ctx.MoveTo (arrowX, arrowY);
                    // We draw the rectangle path
                    DrawTriangle (ctx);
                    // We use it
                    ctx.Color = new Color (black.Red, black.Green, black.Blue, black.Alpha);
                    ctx.StrokePreserve ();
                    ctx.ClosePath ();
                    ctx.Color = new Color (backgroundColor.Red, backgroundColor.Green, backgroundColor.Blue, backgroundColor.Alpha);
                    ctx.Fill ();
                }

                base.OnExposeEvent (evnt);
                return false;
            }
Beispiel #30
0
 public static void ShowPreviewTooltip(Ide.Editor.TextEditor editor, CodeAction fix, Xwt.Rectangle rect)
 {
     HidePreviewTooltip();
     currentPreviewWindow = new RefactoringPreviewTooltipWindow(editor, fix);
     currentPreviewWindow.RequestPopup(rect);
 }
Beispiel #31
0
        private void DrawBackground(Xwt.Drawing.Context g, Xwt.Rectangle rect, StyleInfo si)
        {
            //            LinearGradientBrush linGrBrush = null;
            //            SolidBrush sb = null;
            if (si.BackgroundColor.IsEmpty)
            {
                return;
            }

            g.Save();

            Xwt.Drawing.Color c = XwtColor.SystemColorToXwtColor(si.BackgroundColor);

            Xwt.Drawing.Gradient gradient = null;

            if (si.BackgroundGradientType != BackgroundGradientTypeEnum.None &&
                !si.BackgroundGradientEndColor.IsEmpty)
            {
                Xwt.Drawing.Color ec = XwtColor.SystemColorToXwtColor(si.BackgroundGradientEndColor);

                switch (si.BackgroundGradientType)
                {
                case BackgroundGradientTypeEnum.LeftRight:
                    //                            linGrBrush = new LinearGradientBrush(rect, c, ec, LinearGradientMode.Horizontal);
                    gradient = new Xwt.Drawing.LinearGradient(rect.X, rect.Y, rect.X + rect.Width, rect.Y);
                    break;

                case BackgroundGradientTypeEnum.TopBottom:
                    //                            linGrBrush = new LinearGradientBrush(rect, c, ec, LinearGradientMode.Vertical);
                    gradient = new Xwt.Drawing.LinearGradient(rect.X, rect.Y, rect.X, rect.Y + rect.Height);
                    break;

                case BackgroundGradientTypeEnum.Center:
                    //                            linGrBrush = new LinearGradientBrush(rect, c, ec, LinearGradientMode.Horizontal);
                    throw new NotSupportedException();

                //                            break;
                case BackgroundGradientTypeEnum.DiagonalLeft:
                    //                            linGrBrush = new LinearGradientBrush(rect, c, ec, LinearGradientMode.ForwardDiagonal);
                    gradient = new Xwt.Drawing.LinearGradient(rect.X, rect.Y, rect.X + rect.Width, rect.Y + rect.Height);
                    break;

                case BackgroundGradientTypeEnum.DiagonalRight:
                    //                            linGrBrush = new LinearGradientBrush(rect, c, ec, LinearGradientMode.BackwardDiagonal);
                    gradient = new Xwt.Drawing.LinearGradient(rect.X + rect.Width, rect.Y + rect.Height, rect.X, rect.Y);
                    break;

                case BackgroundGradientTypeEnum.HorizontalCenter:
                    //                            linGrBrush = new LinearGradientBrush(rect, c, ec, LinearGradientMode.Horizontal);
                    throw new NotSupportedException();

                //							break;
                case BackgroundGradientTypeEnum.VerticalCenter:
                    //                            linGrBrush = new LinearGradientBrush(rect, c, ec, LinearGradientMode.Vertical);
                    throw new NotSupportedException();

                //							break;
                default:
                    break;
                }

                gradient.AddColorStop(0, c);
                gradient.AddColorStop(1, ec);
            }

            if (gradient != null)
            {
                // TODO: Fix
                //g.FillRectangle(rect, gradient);
            }
            else if (!si.BackgroundColor.IsEmpty)
            {
                // TODO: Fix
                //g.FillRectangle(rect, c);
            }
            g.Restore();
        }
		static async void PositionParameterInfoWindow (Rectangle allocation)
		{
			lastW = allocation.Width;
			lastH = allocation.Height;
			var isCompletionWindowVisible = wasCompletionWindowVisible = (CompletionWindowManager.Wnd?.Visible ?? false);
			var ctx = window.Widget.CurrentCodeCompletionContext;
			int cparam = window.Ext != null ? await window.Ext.GetCurrentParameterIndex (currentMethodGroup.MethodProvider.StartOffset) : 0;

			X = currentMethodGroup.CompletionContext.TriggerXCoord;
			if (isCompletionWindowVisible) {
				// place above
				Y = ctx.TriggerYCoord - ctx.TriggerTextHeight - allocation.Height - 10;
			} else {
				// place below
				Y = ctx.TriggerYCoord;
			}

			var geometry = DesktopService.GetUsableMonitorGeometry (window.Screen.Number, window.Screen.GetMonitorAtPoint (X, Y));

			window.ShowParameterInfo (currentMethodGroup.MethodProvider, currentMethodGroup.CurrentOverload, cparam - 1, (int)geometry.Width);

			if (X + allocation.Width > geometry.Right)
				X = (int)geometry.Right - allocation.Width;
			if (Y < geometry.Top)
				Y = ctx.TriggerYCoord;
			if (wasAbove || Y + allocation.Height > geometry.Bottom) {
				Y = Y - ctx.TriggerTextHeight - allocation.Height - 4;
				wasAbove = true;
			}

			if (isCompletionWindowVisible) {
				var completionWindow = new Xwt.Rectangle (CompletionWindowManager.X, CompletionWindowManager.Y, CompletionWindowManager.Wnd.Allocation.Width, CompletionWindowManager.Wnd.Allocation.Height);
				if (completionWindow.IntersectsWith (new Xwt.Rectangle (X, Y, allocation.Width, allocation.Height))) {
					X = (int) completionWindow.X;
					Y = (int)completionWindow.Y - allocation.Height - 6;
					if (Y < 0)
						Y = (int)completionWindow.Bottom + 6;
				}
			}

			window.Move (X, Y);
		}		
Beispiel #33
0
        private void DrawImageSized(PageImage pi, Xwt.Drawing.Image im, Xwt.Drawing.Context g, Xwt.Rectangle r)
        {
            double height, width;      // some work variables
            StyleInfo si = pi.SI;

            Xwt.Rectangle r2 = new Xwt.Rectangle(r.X + PixelsX(si.PaddingLeft),
                                                      r.Y + PixelsY(si.PaddingTop),
                                                      r.Width - PixelsX(si.PaddingLeft + si.PaddingRight),
                                                      r.Height - PixelsY(si.PaddingTop + si.PaddingBottom));

            Xwt.Rectangle ir;   // int work rectangle
            switch (pi.Sizing)
            {
                case ImageSizingEnum.AutoSize:

                    float imwidth = PixelsX( (float)im.Size.Width);
                    float imheight = PixelsX( (float)im.Size.Height);
                    ir = new Xwt.Rectangle(Convert.ToInt32(r2.X), Convert.ToInt32(r2.Y),
                                                    imwidth, imheight);

                    im.Scale((int)r2.Width, (int)r2.Height);
                    g.DrawImage(im, ir);

                    break;
                case ImageSizingEnum.Clip:
                    g.Save();
                    g.Rectangle(r2);
                    g.Clip();

                    ir = new Xwt.Rectangle(Convert.ToInt32(r2.X), Convert.ToInt32(r2.Y),
                                                    im.Size.Width, im.Size.Height);

                    g.DrawImage(im, ir);
                    g.Restore();
                    break;
                case ImageSizingEnum.FitProportional:
                    double ratioIm = (float)im.Size.Height / (float)im.Size.Width;
                    double ratioR = r2.Height / r2.Width;
                    height = r2.Height;
                    width = r2.Width;
                    if (ratioIm > ratioR)
                    {
                        // this means the rectangle width must be corrected
                        width = height * (1 / ratioIm);
                    }
                    else if (ratioIm < ratioR)
                    {
                        // this means the ractangle height must be corrected
                        height = width * ratioIm;
                    }
                    r2 = new Xwt.Rectangle(r2.X, r2.Y, width, height);
                    g.DrawImage(im, r2);
                    break;
                case ImageSizingEnum.Fit:
                default:
                    g.DrawImage(im, r2);
                    break;
            }
        }
Beispiel #34
0
        private void DrawString(PageText pt, Xwt.Drawing.Context g, Xwt.Rectangle r)
        {
            StyleInfo si = pt.SI;
            string s = pt.Text;
            g.Save();
            layout = new Xwt.Drawing.TextLayout(g);
            layout.Font = g.Font;

            float fontsize = (si.FontSize * 72 / 96);

            layout.Font.WithFamily(si.GetFontFamily().Name);
            layout.Font.WithPixelSize(fontsize * PixelsX(1));

            if (si.FontStyle == FontStyleEnum.Italic)
                layout.Font.WithStyle(Xwt.Drawing.FontStyle.Italic);

            switch (si.FontWeight)
            {
                case FontWeightEnum.Bold:
                case FontWeightEnum.Bolder:
                case FontWeightEnum.W500:
                case FontWeightEnum.W600:
                case FontWeightEnum.W700:
                case FontWeightEnum.W800:
                case FontWeightEnum.W900:
                    layout.Font.WithWeight(Xwt.Drawing.FontWeight.Bold);
                    break;
            }

            // TODO: Fix Alignment
            //switch (si.TextAlign)
            //{
            //    case TextAlignEnum.Right:
            //        layout.Alignment = Pango.Alignment.Right;
            //        break;
            //    case TextAlignEnum.Center:
            //        layout.Alignment = Pango.Alignment.Center;
            //        break;
            //    case TextAlignEnum.Left:
            //    default:
            //        layout.Alignment = Pango.Alignment.Left;
            //        break;
            //}

            // TODO: Fix with
            //layout.Width = Pango.Units.FromPixels((int)(r.Width - si.PaddingLeft - si.PaddingRight - 2));

            layout.Text = s;

            //Xwt.Rectangle logical;
               // Xwt.Rectangle ink;

            // TODO: Fix
            //layout.GetExtents(out ink, out logical);
            double height = 12; // logical.Height / Pango.Scale.PangoScale;

            double y = 0;
            switch (si.VerticalAlign)
            {
                case VerticalAlignEnum.Top:
                    y = r.Y + si.PaddingTop;
                    break;
                case VerticalAlignEnum.Middle:
                    y = r.Y + (r.Height - height) / 2;
                    break;
                case VerticalAlignEnum.Bottom:
                    y = r.Y + (r.Height - height) - si.PaddingBottom;
                    break;
            }

            // draw the background
            DrawBackground(g, r, si);

            Xwt.Rectangle box = new Xwt.Rectangle(
                                   r.X + si.PaddingLeft + 1,
                                   y,
                                   r.Width,
                                   r.Height);

            Xwt.Drawing.Color sicolor = XwtColor.SystemColorToXwtColor(si.Color);
            g.SetColor(sicolor);

            g.MoveTo(box.X, box.Y);
            g.DrawTextLayout(layout, box.X, box.Y);
            g.Restore();
        }
Beispiel #35
0
			protected override bool OnDrawn (Context cr)
			{
				int w, h;
				this.GdkWindow.GetSize (out w, out h);
				var bounds = new Xwt.Rectangle (0.5, 0.5, w - 1, h - 1);
				var black = Xwt.Drawing.Color.FromBytes (0xee, 0xee, 0xee);
				
				// We clear the surface with a transparent color if possible
				if (supportAlpha)
					cr.SetSourceRGBA (1.0, 1.0, 1.0, 0.0);
				else
					cr.SetSourceRGB (1.0, 1.0, 1.0);
				cr.Operator = Operator.Source;
				cr.Paint ();
				
				var calibratedRect = RecalibrateChildRectangle (bounds);
				// Fill it with one round rectangle
				RoundRectangle (cr, calibratedRect, radius);
				cr.LineWidth = 1;
				
				// Triangle
				// We first begin by positionning ourselves at the top-center or bottom center of the previous rectangle
				var arrowX = bounds.Center.X + arrowDelta;
				var arrowY = arrowPosition == Xwt.Popover.Position.Top ? calibratedRect.Top + cr.LineWidth : calibratedRect.Bottom;
				cr.MoveTo (arrowX, arrowY);
				// We draw the rectangle path
				DrawTriangle (cr);

				// We use it
				cr.SetSourceRGBA (black.Red, black.Green, black.Blue, black.Alpha);
				cr.StrokePreserve ();
				cr.SetSourceRGBA (BackgroundColor.R, BackgroundColor.G, BackgroundColor.B, BackgroundColor.A);
				cr.Fill ();

				return base.OnDrawn (cr);
			}
Beispiel #36
0
        private void DrawString(PageText pt, Xwt.Drawing.Context g, Xwt.Rectangle r)
        {
            StyleInfo si = pt.SI;
            string    s  = pt.Text;

            g.Save();
            layout      = new Xwt.Drawing.TextLayout(g);
            layout.Font = g.Font;


            float fontsize = (si.FontSize * 72 / 96);

            layout.Font.WithFamily(si.GetFontFamily().Name);
            layout.Font.WithPixelSize(fontsize * PixelsX(1));

            if (si.FontStyle == FontStyleEnum.Italic)
            {
                layout.Font.WithStyle(Xwt.Drawing.FontStyle.Italic);
            }

            switch (si.FontWeight)
            {
            case FontWeightEnum.Bold:
            case FontWeightEnum.Bolder:
            case FontWeightEnum.W500:
            case FontWeightEnum.W600:
            case FontWeightEnum.W700:
            case FontWeightEnum.W800:
            case FontWeightEnum.W900:
                layout.Font.WithWeight(Xwt.Drawing.FontWeight.Bold);
                break;
            }

            // TODO: Fix Alignment
            //switch (si.TextAlign)
            //{
            //    case TextAlignEnum.Right:
            //        layout.Alignment = Pango.Alignment.Right;
            //        break;
            //    case TextAlignEnum.Center:
            //        layout.Alignment = Pango.Alignment.Center;
            //        break;
            //    case TextAlignEnum.Left:
            //    default:
            //        layout.Alignment = Pango.Alignment.Left;
            //        break;
            //}

            // TODO: Fix with
            //layout.Width = Pango.Units.FromPixels((int)(r.Width - si.PaddingLeft - si.PaddingRight - 2));

            layout.Text = s;



            //Xwt.Rectangle logical;
            // Xwt.Rectangle ink;

            // TODO: Fix
            //layout.GetExtents(out ink, out logical);
            double height = 12; // logical.Height / Pango.Scale.PangoScale;

            double y = 0;

            switch (si.VerticalAlign)
            {
            case VerticalAlignEnum.Top:
                y = r.Y + si.PaddingTop;
                break;

            case VerticalAlignEnum.Middle:
                y = r.Y + (r.Height - height) / 2;
                break;

            case VerticalAlignEnum.Bottom:
                y = r.Y + (r.Height - height) - si.PaddingBottom;
                break;
            }

            // draw the background
            DrawBackground(g, r, si);

            Xwt.Rectangle box = new Xwt.Rectangle(
                r.X + si.PaddingLeft + 1,
                y,
                r.Width,
                r.Height);

            Xwt.Drawing.Color sicolor = XwtColor.SystemColorToXwtColor(si.Color);
            g.SetColor(sicolor);

            g.MoveTo(box.X, box.Y);
            g.DrawTextLayout(layout, box.X, box.Y);
            g.Restore();
        }