Example #1
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);
        }
Example #2
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 #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 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 #6
0
        private static void OnClearFormatting(object sender, ExecutedRoutedEventArgs e)
        {
            RichTextEditor control     = (RichTextEditor)sender;
            RichTextBox    richTextBox = control.RichTextBox;

            richTextBox.Selection.ClearAllProperties();
        }
Example #7
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 #8
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 #9
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 #10
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 #11
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 #12
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 #13
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 #14
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 #15
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.Assessment.Player.Properties.Resources.txtEditorName);
            }
        }
Example #16
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);
        }
Example #17
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 #18
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);
            }
        }
Example #19
0
        private static void insertBlank(RichTextEditor editor)
        {
            if (editor == null)
            {
                return;
            }

            RichTextBox richTextBox = editor.RichTextBox;

            if (richTextBox == null)
            {
                return;
            }

            TextPointer insertionPosition = richTextBox.Selection.Start;

            if (insertionPosition == null)
            {
                return;
            }

            QuestionBlank blank = new QuestionBlank();
            var           query = from temp in editor.Parts
                                  where temp is QuestionBlank
                                  select temp;

            TextBox blankTb = new TextBox();

            blankTb.Text          = string.Format("çİş{0}", query.Count());
            blankTb.IsReadOnly    = true;
            blankTb.Tag           = blank.PlaceHolder;
            blankTb.TextAlignment = TextAlignment.Center;
            blankTb.Width         = 100;
            insertionPosition.Paragraph.Inlines.Add(blankTb);
            insertionPosition.Paragraph.Inlines.LastInline.BaselineAlignment = BaselineAlignment.Center;

            editor.Parts.Add(blank);
        }
Example #20
0
        public static void OnInsertColumnsToLeft(object sender, ExecutedRoutedEventArgs e)
        {
            RichTextEditor control           = (RichTextEditor)sender;
            RichTextBox    richTextBox       = control.RichTextBox;
            TextPointer    insertionPosition = richTextBox.Selection.Start;

            TableCell tableCell = Helper.GetTableCellAncestor(insertionPosition);

            if (tableCell == null)
            {
                return;
            }

            TableRow tableRow = tableCell.Parent as TableRow;

            if (tableRow == null)
            {
                return;
            }

            TableRowGroup tableRowGroup = tableRow.Parent as TableRowGroup;

            if (tableRowGroup == null)
            {
                return;
            }

            int columnIndex = tableRow.Cells.IndexOf(tableCell);

            using (richTextBox.DeclareChangeBlock())
            {
                foreach (TableRow row in tableRowGroup.Rows)
                {
                    TableCell newTableCell = Helper.BuildTableCell(tableCell.BorderBrush, tableCell.BorderThickness, double.NaN);
                    row.Cells.Insert(columnIndex, newTableCell);
                }
            }
        }
Example #21
0
        /// <summary>
        /// Handler for editing of the picture
        /// </summary>
        public static void OnEditPictureProperties(object sender, ExecutedRoutedEventArgs e)
        {
            RichTextEditor control           = (RichTextEditor)sender;
            RichTextBox    richTextBox       = control.RichTextBox;
            TextPointer    insertionPosition = richTextBox.Selection.Start;

            Image             image             = Helper.GetImageAncestor(insertionPosition);
            InlineUIContainer inlineUIContainer = Helper.GetInlineUIContainer(insertionPosition);

            if (image != null)
            {
                ImagePropertiesDialog imageProperties = new ImagePropertiesDialog(image);
                imageProperties.ShowDialog();
                if (true == imageProperties.DialogResult)
                {
                    try
                    {
                        if (imageProperties.PictureSourceChanged)
                        {
                            AcmBitmapImageHolder acmBitmapImageHolder = new AcmBitmapImageHolder(image, new Uri(imageProperties.ImagePath));
                        }
                        if (!String.IsNullOrEmpty(imageProperties.ImageHyperlink))
                        {
                            //### Set hyperlink
                            image.Tag = imageProperties.ImageHyperlink;
                            Hyperlink hyperlink = new Hyperlink(inlineUIContainer, insertionPosition);
                            hyperlink.NavigateUri = new Uri(imageProperties.ImageHyperlink);
                        }
                        //    control.OnRichTextBox_TextChanged(control, null);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(String.Format("{0} ({1}) :\n\r{2}", SoonLearning.Assessment.Player.Properties.Resources.txtLoadPictureFailed, imageProperties.ImageHyperlink, ex), SoonLearning.Assessment.Player.Properties.Resources.txtEditorName);
                    }
                }
            }
        }
Example #22
0
        public static void OnDeleteColumns(object sender, ExecutedRoutedEventArgs e)
        {
            RichTextEditor control     = (RichTextEditor)sender;
            RichTextBox    richTextBox = control.RichTextBox;

            TextPointer selectionStartPosition = richTextBox.Selection.Start;
            TableCell   startTableCell         = Helper.GetTableCellAncestor(selectionStartPosition);

            if (startTableCell == null)
            {
                return;
            }

            TableRow startTableRow = startTableCell.Parent as TableRow;

            if (startTableRow == null)
            {
                return;
            }

            TableRowGroup startTableRowGroup = startTableRow.Parent as TableRowGroup;

            if (startTableRowGroup == null)
            {
                return;
            }

            int startColumnIndex = startTableRow.Cells.IndexOf(startTableCell);
            int endColumnIndex   = startColumnIndex;

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

            using (richTextBox.DeclareChangeBlock())
            {
                for (int i = 0; i < startTableRowGroup.Rows.Count; i++)
                {
                    for (int j = startColumnIndex; j <= endColumnIndex; j++)
                    {
                        TableCellCollection cells        = startTableRowGroup.Rows[i].Cells;
                        TableCell           cellToDelete = cells[startColumnIndex];
                        cells.Remove(cellToDelete);
                    }
                }

                if (startTableRow.Cells.Count == 0)
                {
                    Table table = startTableRowGroup.Parent as Table;
                    table.SiblingBlocks.Remove(table);
                }
            }
        }
Example #23
0
 private static bool canInsertBlank(RichTextEditor editor)
 {
     return(true);
 }
Example #24
0
        /// <summary>
        /// Handler for inserting of the hyperlink
        /// </summary>
        public static void OnInsertHyperlink(object sender, ExecutedRoutedEventArgs e)
        {
            RichTextEditor control     = (RichTextEditor)sender;
            RichTextBox    richTextBox = control.RichTextBox;


            if (richTextBox.Selection.IsEmpty)
            {
                return;
            }

            TextPointer insertionPosition = richTextBox.Selection.Start;
            Paragraph   paragraph         = insertionPosition.Paragraph;
            Hyperlink   hyperlink         = null;

            Image             image             = Helper.GetImageAncestor(insertionPosition);
            InlineUIContainer inlineUIContainer = Helper.GetInlineUIContainer(insertionPosition);

            if (image != null)
            {
                OnEditPictureProperties(sender, e);
                return;
            }

            //textRange.Text
            //### Detect existing hyperlink
            //hyperlink = GetHyperlinkAncestor(insertionPosition);
            TextRange textRange = richTextBox.Selection;

            foreach (Inline inline in paragraph.Inlines)
            {
                //if (inline is Hyperlink && ((Hyperlink)inline).Tag is TextPointerPaar)
                if (inline is Hyperlink)
                {
                    hyperlink = (Hyperlink)inline;
                    TextRange textRangeHyper = new TextRange(hyperlink.ElementStart, hyperlink.ElementEnd);

                    //if (0 == richTextBox.Selection.Start.CompareTo(((TextPointerPaar)hyperlink.Tag).Start) && 0 == richTextBox.Selection.End.CompareTo(((TextPointerPaar)hyperlink.Tag).End))
                    if (textRange.Text == textRangeHyper.Text)
                    {
                        break;
                    }
                    else
                    {
                        hyperlink = null;
                    }
                }
            }

            HyperlinkPropertiesDialog hyperlinkPropertiesDlg = new HyperlinkPropertiesDialog(hyperlink);

            hyperlinkPropertiesDlg.ShowDialog();

            if (true == hyperlinkPropertiesDlg.DialogResult)
            {
                try
                {
                    Uri uri = new Uri(hyperlinkPropertiesDlg.NavigateUri);
                    if (null == hyperlink)
                    {
                        hyperlink = new Hyperlink(richTextBox.Selection.Start, richTextBox.Selection.End);
                        //hyperlink.Tag = new TextPointerPaar(richTextBox.Selection.Start,richTextBox.Selection.End);
                    }
                    hyperlink.NavigateUri = uri;

                    /*
                     * if (String.IsNullOrEmpty(hyperlinkPropertiesDlg.HyperlinkDesc))
                     * {
                     *  hyperlink.ToolTip = null;
                     * }
                     * else
                     * {
                     *  ToolTip toolTip = new ToolTip();
                     *  toolTip.Content = hyperlinkPropertiesDlg.HyperlinkDesc;
                     *  hyperlink.ToolTip = toolTip;
                     * }*/
                }
                catch (Exception ex)
                {
                    MessageBox.Show(String.Format("{0} ({1}) :\n\r{2}", SoonLearning.Assessment.Player.Properties.Resources.txtLoadHyperlinkFailed, hyperlinkPropertiesDlg.NavigateUri, ex), SoonLearning.Assessment.Player.Properties.Resources.txtEditorName);
                }
            }

            //paragraph.Inlines.Add(hyperlink);
        }
        private static void IsReadOnlyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            RichTextEditor editor = d as RichTextEditor;

            editor.ReadOnlyChanged((bool)e.NewValue);
        }
Example #26
0
        public static void OnInsertPicture(object sender, ExecutedRoutedEventArgs e)
        {
            RichTextEditor control     = (RichTextEditor)sender;
            RichTextBox    richTextBox = control.RichTextBox;

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

            Image image = Helper.GetImageAncestor(textPosition);

            if (null != image)
            {
                if (image.Tag is string)
                {
                    string tag = image.Tag as string;
                    if (!tag.StartsWith("_$FRACTION_"))
                    {
                        PictureCommands.OnEditPictureProperties(sender, e);
                        return;
                    }
                }
                else
                {
                    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);
                    paragraph.Inlines.LastInline.BaselineAlignment = BaselineAlignment.Center;

                    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}", SoonLearning.Assessment.Player.Properties.Resources.txtLoadPictureFailed, imageProperties.ImageHyperlink, ex),
                                    SoonLearning.Assessment.Player.Properties.Resources.txtEditorName);
                }
            }
        }