public void EndTextMode(bool changeText) { AnnRichTextObject obj = _targetObject as AnnRichTextObject; IsEditingText = false; if (_tb != null) { if (!changeText) { _tb.Rtf = obj.Rtf; } obj.Rtf = _tb.Rtf; if (_tb.Parent != null) { if (_toolBar != null) { _toolBar.Closing -= new System.ComponentModel.CancelEventHandler(_toolBar_Closing); _toolBar.Dispose(); _toolBar = null; } _tb.Parent.Controls.Remove(_tb); } } }
public override bool OnPointerDoubleClick(AnnContainer sender, AnnPointerEventArgs e) { AnnRichTextObject obj = TargetObject as AnnRichTextObject; _richTextEditor.ShowRichTextDialog(obj); return(false); }
void automation_ToolTip(object sender, AnnToolTipEventArgs e) { if (e.AnnotationObject != null) { AnnTextObject text = e.AnnotationObject as AnnTextObject; string toolTipText = string.Empty; if (text != null) { toolTipText = text.Text; } else { AnnPolyRulerObject ruler = e.AnnotationObject as AnnPolyRulerObject; if (ruler != null) { if (ruler.MeasurementUnit == AnnUnit.Pixel) { LeadLengthD lengthInUnits = ruler.GetRulerLength(1); double lengthInPixels = Automation.Container.Mapper.LengthFromContainerCoordinates(lengthInUnits, AnnFixedStateOperations.Scrolling | AnnFixedStateOperations.Zooming); toolTipText = string.Format("{0} {1}", Math.Round(lengthInPixels, 2), ruler.UnitsAbbreviation[AnnUnit.Pixel]); } else { toolTipText = ruler.GetRulerLengthAsString(Automation.Container.Mapper.CalibrationScale); } } else { AnnRichTextObject richText = e.AnnotationObject as AnnRichTextObject; if (richText != null) { toolTipText = richText.ToString(); } else { AnnStickyNoteObject stickyNote = e.AnnotationObject as AnnStickyNoteObject; if (stickyNote != null) { toolTipText = stickyNote.Metadata[AnnObject.ContentMetadataKey]; } else { AnnAutomationObject annAutomationObject = MainForm.ManagerHelper.AutomationManager.FindObjectById(e.AnnotationObject.Id); toolTipText = annAutomationObject.Name; } } } } MainForm.ManagerHelper.SetToolTip(_viewer, toolTipText); } else { MainForm.ManagerHelper.SetToolTip(null, string.Empty); } }
public void ShowRichTextDialog(AnnRichTextObject richTextObject) { if ((richTextObject != null) && !richTextObject.IsLocked && !richTextObject.Bounds.IsEmpty) { _tb = new RichTextBox(); _tb.Multiline = true; _tb.HideSelection = false; _tb.Rtf = richTextObject.Rtf; LeadRectD bounds = _container.Mapper.RectFromContainerCoordinates(richTextObject.Bounds, richTextObject.FixedStateOperations); bounds.Inflate(20, 20); _tb.Location = new Point((int)bounds.X, (int)bounds.Y); _tb.Size = new Size((int)bounds.Width, (int)bounds.Height); _tb.LostFocus += new EventHandler(tb_LostFocus); _tb.KeyDown += new KeyEventHandler(tb_KeyDown); _tb.MouseDown += new MouseEventHandler(tb_MouseDown); _toolBar = new RichTextMenu(_tb); _toolBar.Location = new Point(200, 200); _toolBar.Closing += new System.ComponentModel.CancelEventHandler(_toolBar_Closing); _toolBar.Show(_tb.Parent); var imageViewerAutomationControl = _owner as ImageViewerAutomationControl; if (imageViewerAutomationControl != null) { imageViewerAutomationControl.ImageViewer.Controls.Add(_tb); } _tb.Focus(); _tb.SelectAll(); IsEditingText = true; } }
public AnnRichDrawDesigner(IAnnAutomationControl automationControl, AnnContainer container, AnnRichTextObject annRichTextObject) : base(automationControl, container, annRichTextObject) { _richTextEditor = new RichTextBoxEditor(automationControl, TargetObject, container); }
public override void Render(AnnContainerMapper mapper, AnnObject annObject) { if (mapper == null) { ExceptionHelper.ArgumentNullException("mapper"); } if (annObject == null) { ExceptionHelper.ArgumentNullException("annObject"); } base.Render(mapper, annObject); AnnRichTextObject annRichTextObject = annObject as AnnRichTextObject; if (annRichTextObject != null && !String.IsNullOrEmpty(annRichTextObject.Rtf)) { AnnWinFormsRenderingEngine engine = RenderingEngine as AnnWinFormsRenderingEngine; if (engine != null && engine.Context != null) { AnnRectangleObject tempRect = new AnnRectangleObject(); tempRect.Points.Clear(); foreach (LeadPointD pt in GetRenderPoints(mapper, annRichTextObject)) { tempRect.Points.Add(pt); } double rotation = tempRect.Angle; if (rotation == 180) { rotation = 0; } LeadRectD boundsPixels = tempRect.Rect.Clone(); AnnContainerMapper identityMapper = mapper.Clone(); identityMapper.UpdateTransform(LeadMatrix.Identity); identityMapper.MapResolutions(mapper.SourceDpiX, mapper.SourceDpiY, mapper.SourceDpiX, mapper.SourceDpiY); boundsPixels = identityMapper.RectFromContainerCoordinates(boundsPixels, annRichTextObject.FixedStateOperations); if (tempRect.Stroke != null) { boundsPixels.Inflate(-tempRect.Stroke.StrokeThickness.Value, -tempRect.Stroke.StrokeThickness.Value); } string rtf = annRichTextObject.Rtf; IntPtr hemfDC; if (_richTextBox == null) { _richTextBox = new InternalRichTextEdit(); } try { _richTextBox.Rtf = rtf; } catch { using (RichTextBox richTextBox = new RichTextBox()) { richTextBox.Text = rtf; annRichTextObject.Rtf = richTextBox.Rtf; _richTextBox.Rtf = richTextBox.Rtf; } } Graphics graphics = engine.Context; double dpiX = 96; double dpiY = 96; _richTextBox.Location = new Point((int)boundsPixels.Location.X, (int)boundsPixels.Location.Y); _richTextBox.Size = new Size((int)boundsPixels.Size.Width, (int)boundsPixels.Size.Height); IntPtr hdc = graphics.GetHdc(); Win32.RECT rc = new Win32.RECT(); rc.left = _richTextBox.ClientRectangle.Left; rc.top = _richTextBox.ClientRectangle.Top; rc.right = (int)boundsPixels.Width; rc.bottom = (int)boundsPixels.Height; int iWidthMM = SafeNativeMethods.GetDeviceCaps(hdc, Win32.HORZSIZE); int iHeightMM = SafeNativeMethods.GetDeviceCaps(hdc, Win32.VERTSIZE); int iWidthPels = SafeNativeMethods.GetDeviceCaps(hdc, Win32.HORZRES); int iHeightPels = SafeNativeMethods.GetDeviceCaps(hdc, Win32.VERTRES); rc.left = (rc.left * iWidthMM * 100) / iWidthPels; rc.top = (rc.top * iHeightMM * 100) / iHeightPels; rc.right = (rc.right * iWidthMM * 100) / iWidthPels; rc.bottom = (rc.bottom * iHeightMM * 100) / iHeightPels; hemfDC = SafeNativeMethods.CreateEnhMetaFile(hdc, null, ref rc, null); Win32.RECT emfRect = new Win32.RECT(); emfRect.right = (int)boundsPixels.Width; emfRect.bottom = (int)boundsPixels.Height; IntPtr brush = SafeNativeMethods.GetStockObject(5); SafeNativeMethods.SetBkMode(hemfDC, 1); SafeNativeMethods.FillRect(hemfDC, ref emfRect, brush); SafeNativeMethods.DeleteObject(brush); Print(_richTextBox, _richTextBox.ClientRectangle, hemfDC, (int)dpiX, (int)dpiY, false); IntPtr hemf = SafeNativeMethods.CloseEnhMetaFile(hemfDC); using (Metafile metaFile = new Metafile(hemf, true)) { graphics.ReleaseHdc(); GraphicsState state = graphics.Save(); //the mapper transform dosent contain dpi effect so we will add dpi effect . LeadMatrix matrix = mapper.Transform; //add dpi effect to the transform matrix.Scale((float)(mapper.TargetDpiX / mapper.SourceDpiX), (float)(mapper.TargetDpiY / mapper.SourceDpiY)); if ((annRichTextObject.FixedStateOperations & AnnFixedStateOperations.Scrolling) == AnnFixedStateOperations.Scrolling) { matrix.Translate(-matrix.OffsetX, -matrix.OffsetY); } if ((annRichTextObject.FixedStateOperations & AnnFixedStateOperations.Zooming) == AnnFixedStateOperations.Zooming) { double offsetX = matrix.OffsetX; double offsetY = matrix.OffsetY; double scaleX = 1.0; double scaleY = 1.0; if (matrix.M11 != 0 && matrix.M22 != 0) { scaleX = 1.0 / Math.Abs(matrix.M11); scaleY = 1.0 / Math.Abs(matrix.M22); } matrix.Scale(scaleX, scaleY); } using (Matrix transform = new Matrix((float)matrix.M11, (float)matrix.M12, (float)matrix.M21, (float)matrix.M22, (float)matrix.OffsetX, (float)matrix.OffsetY)) { graphics.MultiplyTransform(transform); graphics.DrawImage(metaFile, new Point((int)boundsPixels.Left, (int)boundsPixels.Top)); } graphics.Restore(state); } } //EndDraw(graphics, gState); } }