コード例 #1
0
ファイル: PersonInfo.xaml.cs プロジェクト: ssickles/archive
        private void UserControl_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (this.Visibility == Visibility.Visible)
            {
                // Show the story, hide the editor
                StoryViewBorder.Visibility = Visibility.Visible;
                StoryEditBorder.Visibility = Visibility.Hidden;

                // Load the person story into the viewer
                LoadStoryText(StoryViewer.Document);

                // Display all text in constrast color to the StoryViewer background.
                TextRange textRange2 = new TextRange(StoryViewer.Document.ContentStart, StoryViewer.Document.ContentEnd);
                textRange2.Select(StoryViewer.Document.ContentStart, StoryViewer.Document.ContentEnd);
                textRange2.ApplyPropertyValue(TextElement.ForegroundProperty, FindResource("FlowDocumentFontColor"));

                // Hide the photo tags and photo edit buttons if there is no main photo.
                if (DisplayPhoto.Source == null)
                {
                    TagsStackPanel.Visibility = Visibility.Hidden;
                    PhotoButtonsDockPanel.Visibility = Visibility.Hidden;
                }

                // Workaround to get the StoryViewer to display the first page instead of the last page when first loaded
                StoryViewer.ViewingMode = FlowDocumentReaderViewingMode.Scroll;
                StoryViewer.ViewingMode = FlowDocumentReaderViewingMode.Page;
            }
        }
コード例 #2
0
 private void Paste_RequestNavigate(object sender, RequestNavigateEventArgs e)
 {
     TextPointer start = this._rtb.Document.ContentStart,
                 end = this._rtb.Document.ContentEnd;
     TextRange tr = new TextRange(start, end);
     tr.Select(start, end);
     MemoryStream ms;
     StringBuilder sb = new StringBuilder();
     foreach (String dataFormat in _listOfFormats)
     {
         if (tr.CanSave(dataFormat))
         {
             ms = new MemoryStream();
             tr.Save(ms, dataFormat);
             ms.Seek(0, SeekOrigin.Begin);
             sb.AppendLine(dataFormat);
             foreach (char c in ms.ToArray().Select<byte, char>((b) => (char)b))
             {
                 sb.Append(c);
             }
             sb.AppendLine();
         }
         //_tb.Text = sb.ToString();
     }
 }
コード例 #3
0
 /// <summary>
 /// The details of a person changed.
 /// </summary>
 public void OnSkinChanged()
 {
     // Display all text in constrast color to the StoryViewer background.
     TextRange textRange = new TextRange(StoryViewer.Document.ContentStart, StoryViewer.Document.ContentEnd);
     textRange.Select(StoryViewer.Document.ContentStart, StoryViewer.Document.ContentEnd);
     textRange.ApplyPropertyValue(TextElement.ForegroundProperty, FindResource("FlowDocumentFontColor"));
 }
コード例 #4
0
ファイル: UndoPaste.cs プロジェクト: fednep/UV-Outliner
        public override void Redo(RichTextBox edit)
        {
            FlowDocument document = edit.Document;
            __DataStream.Seek(0, SeekOrigin.Begin);
            TextRange whole = new TextRange(document.ContentStart, document.ContentEnd);

            TextPointer start = UndoHelpers.SafePositionAtOffset(document, document.ContentStart, __OffsetStart);
            TextPointer end = UndoHelpers.SafePositionAtOffset(document, document.ContentEnd, __OffsetEnd);

            whole.Select(start, end);
            whole.Load(__DataStream, DataFormats.Xaml);

            edit.CaretPosition = UndoHelpers.SafePositionAtOffset(document, document.ContentStart, __OffsetCursorPositionAfter);
        }
コード例 #5
0
 private void LoadPlainText(string text,ref FlowDocumentReader fdr)
 {
     fdr.Document.PageWidth=816;
     TextRange tr=
     new TextRange
     (
     fdr.Document.ContentStart,
     fdr.Document.ContentEnd
     )
     {
     Text=text
     };
     tr.Select
     (
     fdr.Document.ContentStart,
     fdr.Document.ContentStart
     );
 }
コード例 #6
0
ファイル: PersonInfo.xaml.cs プロジェクト: ssickles/archive
        private void UserControl_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (this.Visibility == Visibility.Visible)
            {
                // Load the person story into the viewer
                LoadStoryText(StoryViewer.Document);
                StoryViewBorder.Visibility = Visibility.Visible;

                // Display all text in constrast color to the StoryViewer background.
                TextRange textRange2 = new TextRange(StoryViewer.Document.ContentStart, StoryViewer.Document.ContentEnd);
                textRange2.Select(StoryViewer.Document.ContentStart, StoryViewer.Document.ContentEnd);
                textRange2.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.White);

                // Hide the Story Edit
                StoryEditBorder.Visibility = Visibility.Hidden;

                if (DisplayPhoto.Source == null)
                {
                    TagsStackPanel.Visibility = Visibility.Hidden;
                    PhotoButtonsDockPanel.Visibility = Visibility.Hidden;
                }
            }
        }
コード例 #7
0
 private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
 {
     TextPointer start = this._rtb.Document.ContentStart,
                 end = this._rtb.Document.ContentEnd;
     TextRange tr = new TextRange(start, end);
     tr.Select(start, end);
     if (tr.CanSave(DataFormats.Xaml))
     {
         FileInfo fi = new FileInfo("proba.xaml");
         if (fi.Exists)
             fi.Delete();
         FileStream fs = fi.Create();
         tr.Save(fs, DataFormats.Xaml);
         fs.Flush();
         fs.Close();
     }
 }
コード例 #8
0
        // Helper for PasteTextFragment
        private static void PasteMergeableTextFragment(TextElement fragment, TextRange range, TextPointer insertionPosition)
        {
            TextPointer fragmentStart;
            TextPointer fragmentEnd;

            if (fragment is Span)
            {
                // Split structure at insertion point in target
                insertionPosition = TextRangeEdit.SplitFormattingElements(insertionPosition, /*keepEmptyFormatting:*/false);
                Invariant.Assert(insertionPosition.Parent is Paragraph, "insertionPosition must be in a scope of a Paragraph after splitting formatting elements");

                // Move the whole Span into the insertion point
                fragment.RepositionWithContent(insertionPosition);

                // Store edge positions of inserted content
                fragmentStart = fragment.ElementStart;
                fragmentEnd = fragment.ElementEnd;

                // Remove wrapper from a tree
                fragment.Reposition(null, null);
                ValidateMergingPositions(typeof(Inline), fragmentStart, fragmentEnd);

                // Transfer inheritable contextual properties
                ApplyContextualProperties(fragmentStart, fragmentEnd, fragment);
            }
            else
            {
                // Correct leading nested List elements in the fragment
                CorrectLeadingNestedLists((Section)fragment);

                // Split a paragraph at insertion position
                bool needFirstParagraphMerging = SplitParagraphForPasting(ref insertionPosition);

                // Move the whole Section into the insertion point
                fragment.RepositionWithContent(insertionPosition);

                // Store edge positions of inserted content
                fragmentStart = fragment.ElementStart;
                fragmentEnd = fragment.ElementEnd.GetPositionAtOffset(0, LogicalDirection.Forward); // need forward orientation to stick with the following content during merge at fragmentStart position

                // And unwrap the root Section
                fragment.Reposition(null, null);
                ValidateMergingPositions(typeof(Block), fragmentStart, fragmentEnd);

                // Transfer inheritable contextual properties
                ApplyContextualProperties(fragmentStart, fragmentEnd, fragment);

                // Merge paragraphs on fragment boundaries
                if (needFirstParagraphMerging)
                {
                    MergeParagraphsAtPosition(fragmentStart, /*mergingOnFragmentStart:*/true);
                }

                // Get an indication that we need to merge last paragraph
                if (!((Section)fragment).HasTrailingParagraphBreakOnPaste)
                {
                    MergeParagraphsAtPosition(fragmentEnd, /*mergingOnFragmentStart:*/false);
                }
            }

            // 

            // For paragraph pasting move range end to the following paragraph, because
            // it must include an ending paragraph break (in case of no-merging)
            if (fragment is Section && ((Section)fragment).HasTrailingParagraphBreakOnPaste)
            {
                fragmentEnd = fragmentEnd.GetInsertionPosition(LogicalDirection.Forward);
            }

            // Select pasted content
            range.Select(fragmentStart, fragmentEnd);
        }
コード例 #9
0
        // Helper for PasteTextFragment
        private static void PasteNonMergeableTextFragment(TextElement fragment, TextRange range)
        {
            // We cannot split Hyperlink or other non-splittable inline ancestor.
            // Paste text content of fragment in such case.

            // Get text content to be pasted.
            string fragmentText = TextRangeBase.GetTextInternal(fragment.ElementStart, fragment.ElementEnd);

            // Paste text into our empty target range.
            // 
            range.Text = fragmentText;
            
            // Select pasted content
            range.Select(range.Start, range.End);
        }
コード例 #10
0
ファイル: MainWindow.xaml.cs プロジェクト: yas4891/MUTEX
        /// <summary>
        /// resets the colors for all of the text in the given text box
        /// </summary>
        /// <param name="box"></param>
        private static void ResetTextColor(RichTextBox box)
        {
            var textRange = new TextRange(box.Document.ContentStart, box.Document.ContentEnd);

            var startPos = GetPoint(box.Document.ContentStart, 0);

            textRange.Select(box.Document.ContentStart, box.Document.ContentEnd);
            textRange.ApplyPropertyValue(TextElement.ForegroundProperty,
                    new SolidColorBrush(Colors.Black));

            textRange.ApplyPropertyValue(TextElement.BackgroundProperty,
                    new SolidColorBrush(Colors.White));
        }
コード例 #11
0
ファイル: MainWindow.xaml.cs プロジェクト: yas4891/MUTEX
        private static void ColorizeText(RichTextBox box, int offset, int length)
        {
            var textRange = new TextRange(box.Document.ContentStart, box.Document.ContentEnd);

            var startPos = GetPoint(box.Document.ContentStart, offset);

            var endPos = GetPoint(box.Document.ContentStart, offset + length);
            Console.WriteLine("{0},offset from start:{1}, end: {2}", box.Name, box.Document.ContentStart.GetOffsetToPosition(startPos), endPos);

            textRange.Select(startPos, endPos);

            textRange.ApplyPropertyValue(TextElement.ForegroundProperty,
                    new SolidColorBrush(_ltForeground[_indexColorLookup % _ltForeground.Length]));

            textRange.ApplyPropertyValue(TextElement.BackgroundProperty,
                    new SolidColorBrush(_ltBackground[_indexColorLookup % _ltForeground.Length]));
        }
コード例 #12
0
 private void SaveText(ref FlowDocumentReader fdr)
 {
     string mask="Rich Text Format (*.rtf)|*.rtf|"+app.Language.TextDocument+" (*.txt)|*.txt|"+app.Language.AllFiles+" (*.*)|*.*";
     SaveFileDialog Save=CreateSaveDialog(mask,app.Language.Save);
     if(Save.ShowDialog(this).GetValueOrDefault())
     {
     FileStream file=SafeFileMethods.CreateFile(Save.FileName);
     if(file==null)
     {
     ShowNotification(app.Language.SaveTextError,Title,System.Windows.Forms.ToolTipIcon.Error);
     return;
     }
     TextRange tr=new TextRange(fdr.Document.ContentStart,fdr.Document.ContentEnd);
     tr.Select(fdr.Document.ContentStart,fdr.Document.ContentEnd);
     if(Save.FilterIndex>1)
     tr.Save(file,DataFormats.Text);
     else tr.Save(file,DataFormats.Rtf);
     tr.Select(fdr.Document.ContentStart,fdr.Document.ContentStart);
     file.Close();
     }
 }
コード例 #13
0
ファイル: PersonInfo.xaml.cs プロジェクト: ssickles/archive
        private void SaveStoryButton_Click(object sender, RoutedEventArgs e)
        {
            Person person = (Person)this.DataContext;

            if (person != null)
            {
                // Pass in a TextRange object to save the story     
                TextRange textRange = new TextRange(StoryRichTextBox.Document.ContentStart, StoryRichTextBox.Document.ContentEnd);
                person.Story = new Story();
                string storyFileName = new StringBuilder(person.Name).Append(" {").Append(person.Id).Append("}").Append(".rtf").ToString();
                person.Story.Save(textRange, storyFileName);

                // Display the rich text in the viewer
                LoadStoryText(StoryViewer.Document);

                // Display all text in constrast color to the StoryViewer background.
                TextRange textRange2 = new TextRange(StoryViewer.Document.ContentStart, StoryViewer.Document.ContentEnd);
                textRange2.Select(StoryViewer.Document.ContentStart, StoryViewer.Document.ContentEnd);
                textRange2.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.White);
            }

            StoryEditBorder.Visibility = Visibility.Hidden;
            StoryViewBorder.Visibility = Visibility.Visible;
        }
コード例 #14
0
ファイル: PersonInfo.xaml.cs プロジェクト: ssickles/archive
        private void SaveStoryButton_Click(object sender, RoutedEventArgs e)
        {
            Person person = (Person)this.DataContext;

            if (person != null)
            {
                // Pass in a TextRange object to save the story     
                TextRange textRange = new TextRange(StoryRichTextBox.Document.ContentStart, StoryRichTextBox.Document.ContentEnd);
                person.Story = new Story();
                string storyFileName = new StringBuilder(person.Name).Append(" {").Append(person.Id).Append("}").Append(".rtf").ToString();
                person.Story.Save(textRange, storyFileName);

                // Display the rich text in the viewer
                LoadStoryText(StoryViewer.Document);

                // Display all text in constrast color to the StoryViewer background.
                TextRange textRange2 = new TextRange(StoryViewer.Document.ContentStart, StoryViewer.Document.ContentEnd);
                textRange2.Select(StoryViewer.Document.ContentStart, StoryViewer.Document.ContentEnd);
                textRange2.ApplyPropertyValue(TextElement.ForegroundProperty, FindResource("FlowDocumentFontColor"));
            }

            // Switch to view mode
            StoryEditBorder.Visibility = Visibility.Hidden;
            StoryViewBorder.Visibility = Visibility.Visible;

            // Workaround to get the StoryViewer to display the first page instead of the last page when first loaded
            StoryViewer.ViewingMode = FlowDocumentReaderViewingMode.Scroll;
            StoryViewer.ViewingMode = FlowDocumentReaderViewingMode.Page;
        }
コード例 #15
0
        // ....................................................................
        // 
        // Cell editing
        //
        // ....................................................................
 
        /// <summary>
        /// Merges several cells horizontally. 
        /// </summary> 
        /// <param name="textRange">
        /// TextRange contining cells to be merged. 
        /// </param>
        /// <returns>
        /// TextRange containing resulted merged cell.
        /// Null in case if textRange cannot be merged. 
        /// </returns>
        internal static TextRange MergeCells(TextRange textRange) 
        { 
            Invariant.Assert(textRange != null, "null check: textRange");
 
            TableCell startCell;
            TableCell endCell;
            TableRow startRow;
            TableRow endRow; 
            TableRowGroup startRowGroup;
            TableRowGroup endRowGroup; 
            Table startTable; 
            Table endTable;
            if (!IdentifyTableElements(textRange.Start, textRange.End, /*includeCellAtMovingPosition:*/false, out startCell, out endCell, out startRow, out endRow, out startRowGroup, out endRowGroup, out startTable, out endTable)) 
            {
                return null;
            }
 
            if (startCell == null || endCell == null)
            { 
                return null; 
            }
 
            Invariant.Assert(startCell.Row.RowGroup == endCell.Row.RowGroup, "startCell and endCell must belong to the same RowGroup");
            Invariant.Assert(startCell.Row.Index <= endCell.Row.Index, "startCell.Row.Index must be <= endCell.Row.Index");
            Invariant.Assert(startCell.ColumnIndex <= endCell.ColumnIndex + endCell.ColumnSpan - 1, "startCell.ColumnIndex must be <= an index+span of an endCell");
 
            // Perform a merge
            TextRange result = MergeCellRange(startCell.Row.RowGroup, // 
                startCell.Row.Index, // topRow 
                endCell.Row.Index + endCell.RowSpan - 1, // bottomRow
                startCell.ColumnIndex, // leftColumn 
                endCell.ColumnIndex + endCell.ColumnSpan - 1); // rightColumn

            if (result != null)
            { 
                textRange.Select(textRange.Start, textRange.End);
            } 
 
            return result;
        } 
コード例 #16
0
        /// <summary> 
        /// Deletes the current or the next row depending on deletionDirection. 
        /// </summary>
        /// <param name="textRange"> 
        /// TextRange identifying rows to delete.
        /// </param>
        /// <returns>
        /// True if deletion was possible, false if the row was the last or not existed. 
        /// </returns>
        internal static bool DeleteRows(TextRange textRange) 
        { 
            // Parameter validation
            Invariant.Assert(textRange != null, "null check: textRange"); 

            TableRow startRow = GetTableRowFromPosition(textRange.Start);
            TableRow endRow = GetTableRowFromPosition(textRange.End);
 
            if (startRow == null || endRow == null || startRow.RowGroup != endRow.RowGroup)
            { 
                return false; 
            }
 
            TableRowCollection rows = startRow.RowGroup.Rows;
            int deletedRowsCount = endRow.Index - startRow.Index + 1;

            if (deletedRowsCount == rows.Count) 
            {
                // To delete all rows we need to delete the whole table 
                Table table= startRow.Table; 
                table.RepositionWithContent(null);
            } 
            else
            {
                bool lastRowDeleted = endRow.Index == rows.Count - 1;
 
                // Transfer spanned cells to the next row
                if (!lastRowDeleted) 
                { 
                    CorrectRowSpansOnDeleteRows(rows[endRow.Index + 1], deletedRowsCount);
                } 

                // Delete rows
                rows.RemoveRange(startRow.Index, endRow.Index - startRow.Index + 1);
                Invariant.Assert(rows.Count > 0); 

                // Correct bottom borders 
                CorrectBorders(rows); 
            }
 
            // Collapse a range to its start position
            textRange.Select(textRange.Start, textRange.Start);

            return true; 
        }
コード例 #17
0
 private void LoadText(string text,ref FlowDocumentReader fdr,string format)
 {
     fdr.Document.PageWidth=816;
     TextRange tr=
     new TextRange
     (
     fdr.Document.ContentStart,
     fdr.Document.ContentEnd
     );
     MemoryStream ms=
     new MemoryStream
     (
     Encoding.Default.GetBytes(text)
     );
     try
     {
     tr.Load(ms,format);
     }
     catch(ArgumentException)
     {
     tr.Text=string.Empty;
     ShowNotification
     (
     app.Language.LoadTextError,
     Title,
     System.Windows.Forms.ToolTipIcon.Error
     );
     }
     catch(Exception e)
     {
     tr.Text=string.Empty;
     ShowNotification
     (
     e.Message,
     Title,
     System.Windows.Forms.ToolTipIcon.Error
     );
     }
     tr.Select
     (
     fdr.Document.ContentStart,
     fdr.Document.ContentStart
     );
 }