/// <summary>
        /// Insert the given text into this RichTextBox at the current CaretPosition, replacing any already-selected text.
        /// </summary>
        /// <param name="richTextBox">The RichTextBox to insert the new text into</param>
        /// <param name="sTextToInsert">The text to insert into this RichTextBox</param>
        public static void InsertText(this System.Windows.Controls.RichTextBox richTextBox, string sTextToInsert)
        {
            if (!String.IsNullOrEmpty(sTextToInsert))
            {
                //TODO
#if !SILVERLIGHT
                richTextBox.BeginChange();
                if (richTextBox.Selection.Text != string.Empty)
                {
                    richTextBox.Selection.Text = string.Empty;
                }
                TextPointer tp = richTextBox.CaretPosition.GetPositionAtOffset(0, LogicalDirection.Forward);
                richTextBox.CaretPosition.InsertTextInRun(sTextToInsert);
                richTextBox.CaretPosition = tp;
                richTextBox.EndChange();
                Keyboard.Focus(richTextBox);
#endif
            }
        }
Example #2
0
	public void InsertBlockLayer (DataSet FormatierDataSet, DataRow BlockRow, Grid TextGrid, DataRow ContentRow,
				double OriginalWidth, double OriginalHeight)
		{
		double WidthPercentage = MaxPercentage;
		if ((!Convert.IsDBNull (BlockRow ["MaxPositionRight"]))
			&& (!Convert.IsDBNull (BlockRow ["MinPositionLeft"])))
					WidthPercentage = Convert.ToDouble (BlockRow ["MaxPositionRight"]) -
		                         Convert.ToDouble (BlockRow ["MinPositionLeft"]);
		else
			{
			if (!Convert.IsDBNull (BlockRow ["MaxPositionRight"]))
				WidthPercentage = Convert.ToDouble (BlockRow ["MaxPositionRight"]);
			if (!Convert.IsDBNull (BlockRow ["MinPositionLeft"]))
				WidthPercentage = MaxPercentage - Convert.ToDouble (BlockRow ["MinPositionLeft"]);
			}

		double HeightPercentage = MaxPercentage;
		if ((!Convert.IsDBNull (BlockRow ["MaxPositionBottom"]))
			&& (!Convert.IsDBNull (BlockRow ["MinPositionTop"])))
					HeightPercentage = Convert.ToDouble (BlockRow ["MaxPositionBottom"]) -
		                         Convert.ToDouble (BlockRow ["MinPositionTop"]);
		else
			{
			if (!Convert.IsDBNull (BlockRow ["MaxPositionBottom"]))
				HeightPercentage = Convert.ToDouble (BlockRow ["MaxPositionBottom"]);
			if (!Convert.IsDBNull (BlockRow ["MinPositionTop"]))
				HeightPercentage = MaxPercentage - Convert.ToDouble (BlockRow ["MinPositionTop"]);
			}
		double LeftPercentage = 0;
		if (!Convert.IsDBNull (BlockRow ["MinPositionLeft"]))
			LeftPercentage = Convert.ToDouble (BlockRow ["MinPositionLeft"]);
		double TopPercentage = 0;
		if (!Convert.IsDBNull (BlockRow ["MinPositionTop"]))
			TopPercentage = Convert.ToDouble (BlockRow ["MinPositionTop"]);

		double BlockRotation = 0;
		if (!Convert.IsDBNull (BlockRow ["BlockRotation"]))
			BlockRotation = Convert.ToDouble (BlockRow ["BlockRotation"]);
		Grid ElementGrid = CreateGrid
			(new int [] { (int)(LeftPercentage * 100),
		                        (int) (WidthPercentage * 100), 
		                        (int)((MaxPercentage - LeftPercentage - WidthPercentage) * 100) },
			new int [] {(int)(TopPercentage * 100),
		                        (int) (HeightPercentage * 100),
		                        (int)((MaxPercentage - TopPercentage - HeightPercentage) * 100) });
		TextGrid.Children.Add (ElementGrid);
		BrushConverter BRConverter = new BrushConverter ();
		DataRow [] TextsInBlock = FormatierDataSet.Tables ["TextDefinitions"].Select ("BlockID = '"
			+ BlockRow ["ID"].ToString () + "'", "TextPlayingOrder");
		String BlockType = BlockRow ["BlockType"].ToString ();

		if (BlockType == "Text")
			{
			RichTextBox TextBlockFrame = new RichTextBox ();
			FlowDocument Document = new FlowDocument ();
			TextBlockFrame.Document = Document;
			TextBlockFrame.UndoLimit = 0;
			TextBlockFrame.BeginInit ();
			TextBlockFrame.BeginChange ();
			TextBlockFrame.Background = (Brush)BRConverter.ConvertFromString ("Transparent");
			if (!ShowTextFrames)
				{
				TextBlockFrame.BorderBrush = (Brush)BRConverter.ConvertFromString ("Transparent");
				TextBlockFrame.BorderThickness = new Thickness (0);
				}
			TextBlockFrame.Visibility = Visibility.Visible;
			ElementGrid.Children.Add (TextBlockFrame);
			Grid.SetRow (TextBlockFrame, 1);
			Grid.SetColumn (TextBlockFrame, 1);
			TextBlockFrame.Height = ((HeightPercentage) * OriginalHeight) / 100;


			foreach (DataRow DescriptionRow in TextsInBlock)
				{
				try
					{
					InsertTextLayer (DescriptionRow, Document, ContentRow,
									 OriginalWidth, OriginalHeight, OriginalHeight * 0.85);
					}
				catch (Exception Excp)
					{
					throw new Exception ("Fehler bei InsertTextLayer:\r\n" + Excp.ToString());
					}
				}
			TextBlockFrame.EndChange ();
			TextBlockFrame.EndInit ();	
			
			InsertDisposeableElement (TextBlockFrame);
			}

		if (BlockType == "RTF")
			{
			RichTextBox TextBlockFrame = new RichTextBox ();
			TextBlockFrame.UndoLimit = 0;
			TextBlockFrame.BeginInit ();
			TextBlockFrame.BeginChange ();
			TextBlockFrame.Background = (Brush)BRConverter.ConvertFromString ("Transparent");
			if (!ShowTextFrames)
				{
				TextBlockFrame.BorderBrush = (Brush)BRConverter.ConvertFromString ("Transparent");
				TextBlockFrame.BorderThickness = new Thickness (0);
				}
			TextBlockFrame.Visibility = Visibility.Visible;
			ElementGrid.Children.Add (TextBlockFrame);
			Grid.SetRow (TextBlockFrame, 1);
			Grid.SetColumn (TextBlockFrame, 1);
			TextBlockFrame.Height = ((HeightPercentage) * OriginalHeight) / 100;


			foreach (DataRow DescriptionRow in TextsInBlock)
				{
				try
					{
					InsertRTFLayer (DescriptionRow, TextBlockFrame, ContentRow,
									 OriginalWidth, OriginalHeight, OriginalHeight * 0.85);
					}
				catch (Exception Excp)
					{
					throw new Exception ("Fehler bei InsertRTFLayer:\r\n" + Excp.ToString());
					}
				}
			TextBlockFrame.EndChange ();
			TextBlockFrame.EndInit ();

			InsertDisposeableElement (TextBlockFrame);
			}

	
		if (BlockType == "WebFormat")
			{
			WebBrowser WebContent = new WebBrowser ();
			ElementGrid.Children.Add (WebContent);
			Grid.SetRow (WebContent, 1);
			Grid.SetColumn (WebContent, 1);
			WebContent.Height = ((HeightPercentage) * OriginalHeight) / 100;

			foreach (DataRow DescriptionRow in TextsInBlock)
				{
				InsertWebLayer (DescriptionRow, WebContent, ContentRow,
								 OriginalWidth, OriginalHeight, OriginalHeight * 0.85);
				}
			}
		
		if ((BlockType.IndexOf ('.') != -1)
			&& (BlockType.IndexOf (',') != -1))
			{
			Grid UserControlParent = new Grid ();
			ElementGrid.Children.Add (UserControlParent);
			Grid.SetRow (UserControlParent, 1);
			Grid.SetColumn (UserControlParent, 1);
			UserControlParent.Height = ((HeightPercentage) * OriginalHeight) / 100;
			InsertUserControlLayout (BlockType, UserControlParent, FormatierDataSet, BlockRow, ContentRow,
									 TextsInBlock, OriginalWidth, OriginalHeight);
			}

		ElementGrid.UpdateLayout ();
		System.Windows.Media.RotateTransform TransformParameter = new System.Windows.Media.RotateTransform (BlockRotation);
		ElementGrid.RenderTransform = TransformParameter;
		}
        /// <summary>
        /// 
        /// </summary>
        /// <param name="textBox"></param>
        /// <param name="paragraph"></param>
        /// <param name="inlines"></param>
        /// <param name="cursorNeighboutingElement"></param>
        private void ReAssignInlinesInParagraph(RichTextBox textBox, Paragraph paragraph, LinkedList<Inline> inlines, TextElement cursorNeighboutingElement)
        {
            textBox.BeginChange();
            paragraph.Inlines.Clear();
            paragraph.Inlines.AddRange(inlines);

            if (cursorNeighboutingElement != null) {
                textBox.CaretPosition = cursorNeighboutingElement.ContentEnd;
            }

            textBox.EndChange();
        }