Пример #1
0
        public override VisualLineElement ConstructElement(int offset)
        {
            var      nextChar = CurrentContext.Document.GetText(offset + 1, 1);
            CheckBox c        = new CheckBox();

            c.Cursor          = Cursors.Hand;
            c.Margin          = new Thickness(5, 0, 5, 0);
            c.Style           = _editor.CheckboxStyle;
            c.Focusable       = false;
            c.RenderTransform = new TranslateTransform(0, 3);

            int length = 2;

            if (nextChar != "]")
            {
                c.IsChecked = true;
                length     += 1;
            }
            c.Checked   += c_Checked;
            c.Unchecked += c_Checked;
            c.Tag        = offset;
            var element = new InlineObjectElement(length, c);

            return(element);
        }
        private InlineObjectElementWithText ConstructElements4Printing(int offset, InlineObjectElement mainUIElement)
        {
            Debug.Assert(mainUIElement != null);

            InlineObjectElementWithText inlineObject = new InlineObjectElementWithText(mainUIElement.DocumentLength, mainUIElement.Element);

            var line = Document.GetLineByOffset(offset);

            inlineObject.LeadingText  = GetLeadingText(Document, line, offset);
            inlineObject.TrailingText = GetTrailingText(Document, line, offset, mainUIElement.DocumentLength);

            return(inlineObject);
        }
        /// Constructs an element at the specified offset.
        /// May return null if no element can be constructed.
        public override VisualLineElement ConstructElement(int offset)
        {
            InlineObjectElement mainUIElement = ConstructMainElement(offset);

            if ((mainUIElement == null) || !IsPrinting)
            {
                return(mainUIElement);
            }
            else
            {
                return(ConstructElements4Printing(offset, mainUIElement));
            }
        }
Пример #4
0
        public override VisualLineElement ConstructElement(int offset)
        {
            _resizingTimer.Stop();
            var text        = CurrentContext.Document.GetText(offset, CurrentContext.VisualLine.LastDocumentLine.EndOffset - offset);
            var startOffset = "![image](".Length;
            var endOffset   = text.IndexOf(")");

            var   imageFile = text.Substring(startOffset, endOffset - startOffset);
            Image i         = new Image();

            i.Focusable = false;
            var b = _cache.GetImage(_editor.ImageFolder, imageFile);

            if (b != null)
            {
                i.Source = b;
            }
            i.Stretch             = Stretch.UniformToFill;
            i.StretchDirection    = StretchDirection.DownOnly;
            i.HorizontalAlignment = HorizontalAlignment.Left;
            i.VerticalAlignment   = VerticalAlignment.Top;
            i.Width = _editor.ActualWidth;
            System.Diagnostics.Debug.Print("Creating image: " + imageFile);
            //Binding widthBinding = new Binding();
            //widthBinding.FallbackValue = (double)200;
            //widthBinding.Source = _editor;
            //widthBinding.Mode = BindingMode.OneWay;
            //widthBinding.Path = new PropertyPath("ActualWidth");
            //widthBinding.IsAsync = true;
            //i.SetBinding(Image.WidthProperty, widthBinding);
            var images = _imagesToResize;

            images.Add(i);
            i.Unloaded += (s, e) => images.Remove(i);
            var element = new InlineObjectElement(endOffset + 1, i);

            _resizingTimer.Start();
            return(element);
        }