Example #1
0
        public static void OnInsertTable(object sender, ExecutedRoutedEventArgs e)
        {
            RichTextEditor control     = (RichTextEditor)sender;
            RichTextBox    richTextBox = control.RichTextBox;

            if (!richTextBox.Selection.IsEmpty)
            {
                richTextBox.Selection.Text = String.Empty;
            }

            TextPointer insertionPosition = richTextBox.Selection.Start;
            Paragraph   paragraph         = insertionPosition.Paragraph;

            // Split current paragraph at insertion position
            //   insertionPosition = insertionPosition.InsertParagraphBreak();
            //   paragraph = insertionPosition.Paragraph;

            TablePropertiesDialog tablePropertiesDialog = new TablePropertiesDialog(null);

            tablePropertiesDialog.ShowDialog();
            if (true == tablePropertiesDialog.DialogResult)
            {
                //Table table = Helper.BuildTable(/*rows*/2, /*columns*/5);
                Table table = Helper.BuildTable(tablePropertiesDialog.Rows,
                                                tablePropertiesDialog.Columns,
                                                tablePropertiesDialog.TableBorderBrush,
                                                tablePropertiesDialog.TableBorderThickness,
                                                tablePropertiesDialog.TableCellWidth,
                                                tablePropertiesDialog.TableType);
                //table.LineHeight = tablePropertiesDialog.CellWidth;
                //table.Margin = new Thickness(30,30,30,30);
                paragraph.SiblingBlocks.InsertBefore(paragraph, table);
            }
        }
Example #2
0
        private static void OnEnterParagraphBreak(object sender, KeyEventArgs e)
        {
            RichTextEditor richEditor  = (RichTextEditor)sender;
            RichTextBox    richTextBox = richEditor.RichTextBox;

            if (richTextBox.Selection.Start.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.Text &&
                richTextBox.Selection.Start.GetPointerContext(LogicalDirection.Backward) == TextPointerContext.Text)
            {
                return; // Default handling of enter break will split parent Paragraph...
            }

            if (richTextBox.Selection.Start.Paragraph != null &&
                richTextBox.Selection.Start.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.ElementEnd)
            {
                // Caret is at end of paragraph content...

                Paragraph  paragraph  = richTextBox.Selection.Start.Paragraph;
                FontFamily fontFamily = paragraph.FontFamily;
                double     fontSize   = paragraph.FontSize;
                FontStyle  fontStyle  = paragraph.FontStyle;
                FontWeight fontWeight = paragraph.FontWeight;

                FontFamily arialFont = new FontFamily("Arial");

                if ((fontFamily.Equals(arialFont) && fontWeight == FontWeights.Bold) &&
                    (fontSize == 16 || (fontSize == 14 && fontStyle == FontStyles.Italic) || fontSize == 13))
                {
                    Paragraph newParagraph = new Paragraph(new Run());
                    paragraph.SiblingBlocks.InsertAfter(paragraph, newParagraph);
                    richTextBox.CaretPosition = newParagraph.ContentStart.GetInsertionPosition(LogicalDirection.Forward);
                    e.Handled = true;
                }
            }
        }
Example #3
0
        private static void subscript(RichTextEditor editor)
        {
            if (editor == null)
            {
                return;
            }

            RichTextBox richTextBox = editor.RichTextBox;

            if (richTextBox == null || richTextBox.Selection == null)
            {
                return;
            }

            var currentAlignment = richTextBox.Selection.GetPropertyValue(Inline.BaselineAlignmentProperty);

            if (currentAlignment == DependencyProperty.UnsetValue)
            {
                return;
            }

            BaselineAlignment newAlignment = ((BaselineAlignment)currentAlignment == BaselineAlignment.Subscript) ? BaselineAlignment.Baseline : BaselineAlignment.Subscript;

            richTextBox.Selection.ApplyPropertyValue(Inline.BaselineAlignmentProperty, newAlignment);
        }
Example #4
0
        public static void OnEditTableProperties(object sender, ExecutedRoutedEventArgs e)
        {
            RichTextEditor control     = (RichTextEditor)sender;
            RichTextBox    richTextBox = control.RichTextBox;

            TextPointer textPosition = richTextBox.Selection.Start;

            Table table = Helper.GetTableAncestor(textPosition);

            if (null != table)
            {
                TablePropertiesDialog tablePropertiesDialog = new TablePropertiesDialog(table);
                tablePropertiesDialog.ShowDialog();
                if (true == tablePropertiesDialog.DialogResult)
                {
                    Helper.UpdateTable(table,
                                       tablePropertiesDialog.Rows,
                                       tablePropertiesDialog.Columns,
                                       tablePropertiesDialog.TableBorderBrush,
                                       tablePropertiesDialog.TableBorderThickness,
                                       tablePropertiesDialog.TableCellWidth,
                                       tablePropertiesDialog.TableType);
                }
            }
        }
Example #5
0
        public void RichTextEditor_CreateDefaultProvider()
        {
            using (var httpRequest = new HttpSimulator().SimulateRequest())
            {
                //arrange
                var context     = new Mock <ISubtextContext>();
                var httpContext = new Mock <HttpContextBase>();
                httpContext.Setup(c => c.Request.ApplicationPath).Returns("path");
                context.Setup(c => c.UrlHelper).Returns(
                    new BlogUrlHelper(new RequestContext(httpContext.Object, new RouteData()), null));
                context.Setup(c => c.Blog).Returns(new Blog {
                    Host = "host"
                });
                var page = new SubtextPage {
                    SubtextContext = context.Object
                };
                var editor = new RichTextEditor {
                    Page = page
                };

                //act
                editor.InitControls(new EventArgs());

                //post
                var provider = editor.Provider;
                Assert.IsTrue(provider is FtbBlogEntryEditorProvider, "FtbBlogEntryEditorProvider is created by default.");
            }
        }
Example #6
0
        private static void editFraction(RichTextEditor editor)
        {
            RichTextBox richTextBox       = editor.RichTextBox;
            TextPointer insertionPosition = richTextBox.Selection.End;

            Image          image = Helper.GetImageAncestor(insertionPosition);
            FractionDialog dlg   = new FractionDialog();

            if (image != null)
            {
                dlg.FractionPart = editor.GetQuestionContentPart(image.Tag as string) as QuestionFractionPart;
            }

            if (dlg.ShowDialog().Value)
            {
                PictureCommands.InsertMathPicture(editor, dlg.FractionImage, dlg.FractionPart.PlaceHolder);
                if (image != null)
                {
                    foreach (var temp in editor.Parts)
                    {
                        if (temp.PlaceHolder == (image.Tag as string))
                        {
                            editor.Parts.Remove(temp);
                            break;
                        }
                    }
                }

                editor.Parts.Add(dlg.FractionPart);
            }
        }
Example #7
0
        public void RichTextEditor_CreatePlainText_IfPreferenceSet()
        {
            using (var httpRequest = new HttpSimulator().SimulateRequest())
            {
                //arrange
                var context     = new Mock <ISubtextContext>();
                var httpContext = new Mock <HttpContextBase>();
                httpContext.Setup(c => c.Request.ApplicationPath).Returns("path");
                context.Setup(c => c.UrlHelper).Returns(
                    new BlogUrlHelper(new RequestContext(httpContext.Object, new RouteData()), null));
                context.Setup(c => c.Blog).Returns(new Blog {
                    Host = "host"
                });
                var page = new SubtextPage {
                    SubtextContext = context.Object
                };
                var editor = new RichTextEditor {
                    Page = page
                };
                //set use plain text in user preferences
                Preferences.UsePlainHtmlEditor = true;

                //act
                editor.InitControls(new EventArgs());

                //post
                var provider = editor.Provider;
                Assert.IsTrue(provider is PlainTextBlogEntryEditorProvider, "PlainTextBlogEntryEditorProvider is created if it is selected in user preferences.");
            }
        }
Example #8
0
        private static void OnClearFormatting(object sender, ExecutedRoutedEventArgs e)
        {
            RichTextEditor control     = (RichTextEditor)sender;
            RichTextBox    richTextBox = control.RichTextBox;

            richTextBox.Selection.ClearAllProperties();
        }
Example #9
0
        public static void OnInsertRowsBelow(object sender, ExecutedRoutedEventArgs e)
        {
            RichTextEditor control           = (RichTextEditor)sender;
            RichTextBox    richTextBox       = control.RichTextBox;
            TextPointer    insertionPosition = richTextBox.Selection.Start;

            TableRow tableRow = Helper.GetTableRowAncestor(insertionPosition);

            if (tableRow == null)
            {
                return;
            }

            TableRowGroup tableRowGroup = tableRow.Parent as TableRowGroup;

            if (tableRowGroup == null)
            {
                return;
            }
            Table table = (Table)tableRowGroup.Parent;

            int      rowIndex    = tableRowGroup.Rows.IndexOf(tableRow);
            TableRow newTableRow = Helper.BuildTableRow(tableRow.Cells.Count,
                                                        (null != table ? table.BorderBrush : System.Windows.Media.Brushes.Black),
                                                        (null != table ? table.BorderThickness : new Thickness(0.5, 0.5, 0.5, 0.5)),
                                                        double.NaN);

            tableRowGroup.Rows.Insert(rowIndex + 1, newTableRow);
        }
        public void SetUp()
        {
            myEditor = new RichTextEditor();
            myEditor.AutoCorrection.Corrections.Clear();

            myAutoCorrections = new AutoCorrectionObserver();
            myEditor.AutoCorrection.Corrections.Add(myAutoCorrections);
        }
Example #11
0
        public static void OnInsertPicture(object sender, ExecutedRoutedEventArgs e)
        {
            RichTextEditor control     = (RichTextEditor)sender;
            RichTextBox    richTextBox = control.RichTextBox;

            //###
            TextPointer textPosition = richTextBox.Selection.Start;

            if (null != Helper.GetImageAncestor(textPosition))
            {
                PictureCommands.OnEditPictureProperties(sender, e);
                return;
            }
            //###

            if (!richTextBox.Selection.IsEmpty)
            {
                richTextBox.Selection.Text = String.Empty;
            }

            TextPointer insertionPosition = richTextBox.Selection.Start;


            ImagePropertiesDialog imageProperties = new ImagePropertiesDialog(null);

            imageProperties.ShowDialog();

            if (true == imageProperties.DialogResult)
            {
                try
                {
                    Paragraph paragraph = insertionPosition.Paragraph;

                    // Split current paragraph at insertion position
                    insertionPosition = insertionPosition.InsertParagraphBreak();
                    paragraph         = insertionPosition.Paragraph;
                    //paragraph.Inlines.Add("Some ");

                    //AcmBitmapImageHolder acmBitmapImageHolder = new AcmBitmapImageHolder(new Uri(@"http://www.cetelem.cz/images/cetelem2/cetelem_logo_cl_small.gif"));
                    AcmBitmapImageHolder acmBitmapImageHolder = new AcmBitmapImageHolder(new Uri(imageProperties.ImagePath));

                    //acmBitmapImageHolder.Image.Style= sender.
                    paragraph.Inlines.Add(acmBitmapImageHolder.Image);

                    if (!String.IsNullOrEmpty(imageProperties.ImageHyperlink))
                    {
                        //### Set hyperlink
                        acmBitmapImageHolder.Image.Tag = imageProperties.ImageHyperlink;
                        Hyperlink hyperlink = new Hyperlink(paragraph.Inlines.LastInline, insertionPosition);
                        hyperlink.NavigateUri = new Uri(imageProperties.ImageHyperlink);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(String.Format("{0} ({1}) :\n\r{2}", Res.txtLoadPictureFailed, imageProperties.ImageHyperlink, ex), Res.txtEditorName);
                }
            }
        }
Example #12
0
        private static void insertFraction(RichTextEditor editor)
        {
            FractionDialog dlg = new FractionDialog();

            if (dlg.ShowDialog().Value)
            {
                PictureCommands.InsertMathPicture(editor, dlg.FractionImage, dlg.FractionPart.PlaceHolder);
                editor.Parts.Add(dlg.FractionPart);
            }
        }
Example #13
0
        public static void OnCanExecuteTableCommand(object target, CanExecuteRoutedEventArgs e)
        {
            RichTextEditor control     = (RichTextEditor)target;
            RichTextBox    richTextBox = control.RichTextBox;

            e.CanExecute = false;
            if (Helper.HasAncestor(richTextBox.Selection.Start, typeof(TableCell)))
            {
                e.CanExecute = true;
            }
        }
Example #14
0
        private static void OnApplyNormalStyle(object sender, ExecutedRoutedEventArgs e)
        {
            RichTextEditor control   = (RichTextEditor)sender;
            Paragraph      paragraph = control.RichTextBox.Selection.Start.Paragraph;

            if (paragraph != null)
            {
                paragraph.FontFamily = new FontFamily("Verdana");
                paragraph.FontSize   = 11;
            }
        }
Example #15
0
        private static bool canEditFraction(RichTextEditor editor)
        {
            TextPointer insertionPosition = editor.RichTextBox.Selection.Start;

            // Disable pictures inside lists and hyperlinks
            if (Helper.HasAncestor(insertionPosition, typeof(List)) || Helper.HasAncestor(insertionPosition, typeof(Hyperlink)))
            {
                return(false);
            }

            return(true);
        }
Example #16
0
        private static void OnApplyHeading1Style(object sender, ExecutedRoutedEventArgs e)
        {
            RichTextEditor control   = (RichTextEditor)sender;
            Paragraph      paragraph = control.RichTextBox.Selection.Start.Paragraph;

            if (paragraph != null)
            {
                paragraph.FontFamily = new FontFamily("Arial");
                paragraph.FontSize   = 16;
                paragraph.FontWeight = FontWeights.Bold;
            }
        }
Example #17
0
        public static void OnDeleteRows(object sender, ExecutedRoutedEventArgs e)
        {
            RichTextEditor control     = (RichTextEditor)sender;
            RichTextBox    richTextBox = control.RichTextBox;

            TextPointer selectionStartPosition = richTextBox.Selection.Start;
            TableRow    startTableRow          = Helper.GetTableRowAncestor(selectionStartPosition);

            if (startTableRow == null)
            {
                return;
            }

            TableRowGroup startTableRowGroup = startTableRow.Parent as TableRowGroup;

            if (startTableRowGroup == null)
            {
                return;
            }

            int startRowIndex = startTableRowGroup.Rows.IndexOf(startTableRow);
            int endRowIndex   = startRowIndex;

            if (!richTextBox.Selection.IsEmpty)
            {
                TextPointer selectionEndPosition = richTextBox.Selection.End.GetNextInsertionPosition(LogicalDirection.Backward);
                TableRow    endTableRow          = Helper.GetTableRowAncestor(selectionEndPosition);
                if (endTableRow == null)
                {
                    return;
                }
                TableRowGroup endTableRowGroup = endTableRow.Parent as TableRowGroup;
                if (startTableRowGroup != endTableRowGroup)
                {
                    return;
                }
                endRowIndex = endTableRowGroup.Rows.IndexOf(endTableRow);
            }

            using (richTextBox.DeclareChangeBlock())
            {
                for (int i = startRowIndex; i <= endRowIndex; i++)
                {
                    startTableRowGroup.Rows.RemoveAt(i);
                }

                if (startTableRowGroup.Rows.Count == 0)
                {
                    Table table = startTableRowGroup.Parent as Table;
                    table.SiblingBlocks.Remove(table);
                }
            }
        }
Example #18
0
        public static void OnDeleteTable(object sender, ExecutedRoutedEventArgs e)
        {
            RichTextEditor control           = (RichTextEditor)sender;
            RichTextBox    richTextBox       = control.RichTextBox;
            TextPointer    insertionPosition = richTextBox.Selection.Start;

            Table table = Helper.GetTableAncestor(insertionPosition);

            if (table != null)
            {
                table.SiblingBlocks.Remove(table);
            }
        }
Example #19
0
        private static void OnCanExecuteInsertPicture(object target, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = true;

            RichTextEditor control           = (RichTextEditor)target;
            RichTextBox    richTextBox       = control.RichTextBox;
            TextPointer    insertionPosition = richTextBox.Selection.Start;

            // Disable pictures inside lists and hyperlinks
            if (Helper.HasAncestor(insertionPosition, typeof(List)) || Helper.HasAncestor(insertionPosition, typeof(Hyperlink)))
            {
                e.CanExecute = false;
            }
        }
Example #20
0
 public PlaceHolder()
 {
     this.Data         = new EPlaceHolder();
     visualChildren    = new VisualCollection(this);
     Background        = Brushes.Transparent;
     Loaded           += PlaceHolder_Loaded;
     SelectionChanged += PlaceHolder_SelectionChanged;
     btnVideo          = new PlaceHolderButton();
     btnImage          = new PlaceHolderButton();
     btnText           = new PlaceHolderButton();
     btnChart          = new PlaceHolderButton();
     text              = new RichTextEditor();
     this.Thickness    = 0;
     DashType          = Controls.Enums.DashType.DashDot;
 }
Example #21
0
    public MyApp()
    {
        VDividedBox box = new VDividedBox();

        box.setStyle("left", 10);
        box.setStyle("right", 10);
        box.setStyle("top", 30);
        box.setStyle("bottom", 10);
        addChild(box);

        RichTextEditor ed = new RichTextEditor();

        ed.percentWidth  = 100;
        ed.percentHeight = 100;
        box.addChild(ed);

        ed = new RichTextEditor();
        ed.percentWidth  = 100;
        ed.percentHeight = 100;
        box.addChild(ed);

        Button btn = ed.boldButton;

        Avm.Class klass = btn.getStyle("icon") as Avm.Class;
        if (klass != null)
        {
            BitmapAsset bmp = avm.CreateInstance(klass) as BitmapAsset;
            if (bmp != null)
            {
                if (bmp.bitmapData == null)
                {
                    Alert.show("Bad bitmapData");
                    return;
                }

                Sprite   sprite = new Sprite();
                Graphics g      = sprite.graphics;
                g.beginBitmapFill(bmp.bitmapData);
                g.drawRect(0, 0, 16, 16);
                g.endFill();
                addChild(sprite);
            }
            else
            {
                Alert.show("Icon class is not BitmapAsset");
            }
        }
    }
Example #22
0
        public static void OnProperties(object sender, ExecutedRoutedEventArgs e)
        {
            RichTextEditor control     = (RichTextEditor)sender;
            RichTextBox    richTextBox = control.RichTextBox;

            TextPointer textPosition = richTextBox.Selection.Start;

            if (null != Helper.GetImageAncestor(textPosition))
            {
                PictureCommands.EditPictureCommand.Execute(sender, null);
            }
            else if (null != Helper.GetTableAncestor(textPosition))
            {
                TableCommands.EditTablePropertiesCommand.Execute(sender, null);
            }
        }
Example #23
0
        private static bool canSubscript(RichTextEditor editor)
        {
            if (editor == null)
            {
                return(false);
            }

            RichTextBox richTextBox = editor.RichTextBox;

            if (richTextBox == null || richTextBox.Selection == null)
            {
                return(false);
            }

            return(true);
        }
Example #24
0
        public static void InsertMathPicture(RichTextEditor control, string imageFile, string tag)
        {
            RichTextBox richTextBox = control.RichTextBox;

            //###
            TextPointer textPosition = richTextBox.Selection.Start;

            //###

            if (!richTextBox.Selection.IsEmpty)
            {
                richTextBox.Selection.Text = String.Empty;
            }

            TextPointer insertionPosition = richTextBox.Selection.Start;

            try
            {
                Paragraph paragraph = insertionPosition.Paragraph;

                // Split current paragraph at insertion position
                //    insertionPosition = insertionPosition.InsertParagraphBreak();
                //    paragraph = insertionPosition.Paragraph;
                //paragraph.Inlines.Add("Some ");

                paragraph.Inlines.Add(new Run());

                AcmBitmapImageHolder acmBitmapImageHolder = new AcmBitmapImageHolder(new Uri(imageFile));

                //acmBitmapImageHolder.Image.Style= sender.
                paragraph.Inlines.Add(acmBitmapImageHolder.Image);
                paragraph.Inlines.LastInline.BaselineAlignment = BaselineAlignment.Center;

                if (!String.IsNullOrEmpty(imageFile))
                {
                    //### Set hyperlink
                    acmBitmapImageHolder.Image.Tag = tag;
                    //    Hyperlink hyperlink = new Hyperlink(paragraph.Inlines.LastInline, insertionPosition);
                    //    hyperlink.NavigateUri = new Uri(imageFile);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(String.Format("{0} ({1}) :\n\r{2}", Resources.txtLoadPictureFailed, imageFile, ex),
                                SoonLearning.TeachAppMaker.Properties.Resources.txtEditorName);
            }
        }
Example #25
0
        /// <summary>
        /// Handler for inserting of the picture
        /// </summary>
        public static void OnInsertLine(object sender, ExecutedRoutedEventArgs e)
        {
            RichTextEditor control     = (RichTextEditor)sender;
            RichTextBox    richTextBox = control.RichTextBox;

            if (!richTextBox.Selection.IsEmpty)
            {
                richTextBox.Selection.Text = String.Empty;
            }

            TextPointer insertionPosition = richTextBox.Selection.Start;
            Paragraph   paragraph         = insertionPosition.Paragraph;

            PathFigure myPathFigure = new PathFigure();

            myPathFigure.StartPoint = new Point(7, 1);

            LineSegment myLineSegment = new LineSegment();

            myLineSegment.Point = new Point(800, 1);

            PathSegmentCollection myPathSegmentCollection = new PathSegmentCollection();

            myPathSegmentCollection.Add(myLineSegment);

            myPathFigure.Segments = myPathSegmentCollection;

            PathFigureCollection myPathFigureCollection = new PathFigureCollection();

            myPathFigureCollection.Add(myPathFigure);

            PathGeometry myPathGeometry = new PathGeometry();

            myPathGeometry.Figures = myPathFigureCollection;

            System.Windows.Shapes.Path myPath = new System.Windows.Shapes.Path();
            myPath.Stroke          = Brushes.Black;
            myPath.StrokeThickness = 1;
            // myPath.Height = 1;
            myPath.Data = myPathGeometry;


            //<Path  Height="10" Fill="Black" Stretch="Fill" Stroke="Black" StrokeThickness="1" Visibility="Visible" Data="M7,34 L390,34" />
            paragraph.Inlines.Add(myPath);
        }
 private void CbRichTextAdvanceMode_Unchecked(object sender, RoutedEventArgs e)
 {
     SuperMessageBoxService.ShowWarning("Advanced Text", "Some content might be automatically removed.\r\n" +
                                        "Are you sure you want to continue?", "Yes", "No",
                                        () =>
     {
         IframePanel.Visibility   = Visibility.Collapsed;
         RawPanel.Visibility      = Visibility.Collapsed;
         DesignerPanel.Visibility = Visibility.Visible;
         DescriptionType          = NodeDescriptionType.Html;
         RichTextEditor.LoadHtml(HtmlEditor.Text);
     },
                                        () =>
     {
         CbRichTextAdvanceMode.Checked  -= CbRichTextAdvanceMode_Checked;
         CbRichTextAdvanceMode.IsChecked = true;
         CbRichTextAdvanceMode.Checked  += CbRichTextAdvanceMode_Checked;
     });
 }
Example #27
0
        private static void OnCanExecuteProps(object target, CanExecuteRoutedEventArgs e)
        {
            RichTextEditor control     = (RichTextEditor)target;
            RichTextBox    richTextBox = control.RichTextBox;

            TextPointer textPosition = richTextBox.Selection.Start;

            //TextRange txR = new TextRange(richTextBox.Selection.Start, richTextBox.Selection.End);
            //int iRes = richTextBox.Selection.Start.CompareTo(richTextBox.Selection.End);
            //bool bIsSelectedText = !String.IsNullOrEmpty((new TextRange(richTextBox.Selection.Start, richTextBox.Selection.End)).Text);

            if ((null != Helper.GetImageAncestor(textPosition) || null != Helper.GetTableAncestor(textPosition)))
            {
                e.CanExecute = true;
            }
            else
            {
                e.CanExecute = false;
            }
        }
Example #28
0
        private void InitializeHelpTextControl( )
        {
            if (_rtbHelpText != null)
            {
                return;
            }

            _rtbHelpText = new RichTextEditor();
            panHelpText.Controls.Add(_rtbHelpText);
            _rtbHelpText.Parent = panHelpText;
            _rtbHelpText.Dock   = DockStyle.Fill;
            _rtbHelpText.BringToFront();
            _rtbHelpText.ShowOpen                 = false;
            _rtbHelpText.ShowSave                 = false;
            _rtbHelpText.ShowInsertHyperlink      = false;
            _rtbHelpText.AcceptsTab               = true;
            _rtbHelpText.RichTextBox.DetectUrls   = true;
            _rtbHelpText.RichTextBox.TextChanged += new EventHandler(OnHelpTextChanged);
            _rtbHelpText.RichTextBox.LinkClicked += new LinkClickedEventHandler(RichTextBox_LinkClicked);
        }
Example #29
0
    public MyApp()
    {
        VDividedBox box = new VDividedBox();

        box.setStyle("left", 10);
        box.setStyle("right", 10);
        box.setStyle("top", 10);
        box.setStyle("bottom", 10);
        addChild(box);

        RichTextEditor ed = new RichTextEditor();

        ed.percentWidth  = 100;
        ed.percentHeight = 100;
        box.addChild(ed);

        ed = new RichTextEditor();
        ed.percentWidth  = 100;
        ed.percentHeight = 100;
        box.addChild(ed);
    }
Example #30
0
        private static void OnPrint(object sender, ExecutedRoutedEventArgs e)
        {
            RichTextEditor control     = (RichTextEditor)sender;
            RichTextBox    richTextBox = control.RichTextBox;

            // Serialize RichTextBox content into a stream in Xaml format. Note: XamlPackage format isn't supported in partial trust.
            TextRange    sourceDocument = new TextRange(richTextBox.Document.ContentStart, richTextBox.Document.ContentEnd);
            MemoryStream stream         = new MemoryStream();

            sourceDocument.Save(stream, DataFormats.Xaml);

            // Clone the source document's content into a new FlowDocument.
            FlowDocument flowDocumentCopy  = new FlowDocument();
            TextRange    copyDocumentRange = new TextRange(flowDocumentCopy.ContentStart, flowDocumentCopy.ContentEnd);

            copyDocumentRange.Load(stream, DataFormats.Xaml);

            // Creates a XpsDocumentWriter object, opens a Windows common print dialog and
            // returns a ref parameter that represents information about the dimensions of the media.
            PrintDocumentImageableArea ia        = null;
            XpsDocumentWriter          docWriter = PrintQueue.CreateXpsDocumentWriter(ref ia);

            if (docWriter != null && ia != null)
            {
                DocumentPaginator paginator = ((IDocumentPaginatorSource)flowDocumentCopy).DocumentPaginator;

                // Change the PageSize and PagePadding for the document to match the CanvasSize for the printer device.
                paginator.PageSize = new Size(ia.MediaSizeWidth, ia.MediaSizeHeight);
                Thickness pagePadding = flowDocumentCopy.PagePadding;
                flowDocumentCopy.PagePadding = new Thickness(
                    Math.Max(ia.OriginWidth, pagePadding.Left),
                    Math.Max(ia.OriginHeight, pagePadding.Top),
                    Math.Max(ia.MediaSizeWidth - (ia.OriginWidth + ia.ExtentWidth), pagePadding.Right),
                    Math.Max(ia.MediaSizeHeight - (ia.OriginHeight + ia.ExtentHeight), pagePadding.Bottom));
                flowDocumentCopy.ColumnWidth = double.PositiveInfinity;

                // Send DocumentPaginator to the printer.
                docWriter.Write(paginator);
            }
        }