private void textBox_TextChanged(object sender, TextChangedEventArgs e) { if (suppressUpdate) { return; } CustomRangeStart rangeStart = this.radRichTextBox.Document.EnumerateChildrenOfType <CustomRangeStart>().FirstOrDefault(); if (rangeStart != null) { CustomRangeEnd rangeEnd = (CustomRangeEnd)rangeStart.End; DocumentPosition start = new DocumentPosition(this.radRichTextBox.Document); start.MoveToInline(rangeStart); DocumentPosition end = new DocumentPosition(this.radRichTextBox.Document); end.MoveToInline(rangeEnd); DocumentSelection selection = this.radRichTextBox.Document.Selection;// new DocumentSelection(this.radRichTextBox.Document); selection.SetSelectionStart(start); selection.AddSelectionEnd(end); this.radRichTextBox.Insert(this.textBox.Text); } }
protected virtual void DocumentSelection_RowUpdated(PXCache cache, PXRowUpdatedEventArgs e) { ARRegister documentAsRegister = e.Row as ARRegister; if (documentAsRegister != null && documentAsRegister.Voided == false && documentAsRegister.Scheduled == false) { ARReleaseProcess.UpdateARBalances(this, documentAsRegister, -documentAsRegister.OrigDocAmt); documentAsRegister.Scheduled = true; documentAsRegister.ScheduleID = Schedule_Header.Current.ScheduleID; ARReleaseProcess.UpdateARBalances(this, documentAsRegister, documentAsRegister.OrigDocAmt); } DocumentSelection document = e.Row as DocumentSelection; if (document != null && !string.IsNullOrWhiteSpace(document.DocType) && !string.IsNullOrWhiteSpace(document.RefNbr) && PXSelectorAttribute.Select <DocumentSelection.refNbr>(cache, document) == null) { cache.RaiseExceptionHandling <DocumentSelection.refNbr>( document, document.RefNbr, new PXSetPropertyException(AP.Messages.ReferenceNotValid)); Document_Detail.Cache.Remove(document); } }
protected override void OnMouseUp(Gtk.DrawingArea canvas, Gtk.ButtonReleaseEventArgs args, Cairo.PointD point) { Document doc = PintaCore.Workspace.ActiveDocument; ImageSurface surf = doc.SelectionLayer.Surface; using (Context g = new Context(surf)) { if (path != null) { g.AppendPath(path); (path as IDisposable).Dispose(); path = null; } g.FillRule = FillRule.EvenOdd; g.ClosePath(); doc.Selection.SelectionPath = g.CopyPath(); } doc.Selection.SelectionPolygons.Clear(); doc.Selection.SelectionPolygons.Add(lasso_polygon.ToList()); SelectionModeHandler.PerformSelectionMode(combine_mode, DocumentSelection.ConvertToPolygonSet(doc.Selection.SelectionPolygons)); doc.Workspace.Invalidate(); if (hist != null) { doc.History.PushNewItem(hist); hist = null; } lasso_polygon.Clear(); is_drawing = false; }
/// <summary> /// Removes all application records associated with the specified /// document. This is required in order to prevent stuck application /// records after a document becomes scheduled. /// </summary> private void RemoveApplications(DocumentSelection document) { ARInvoiceEntry invoiceEntry = PXGraph.CreateInstance <ARInvoiceEntry>(); ARInvoice documentAsInvoice = PXSelect < ARInvoice, Where < ARInvoice.docType, Equal <Required <ARInvoice.docType> >, And <ARInvoice.refNbr, Equal <Required <ARInvoice.refNbr> > > > > .Select(invoiceEntry, document.DocType, document.RefNbr); invoiceEntry.Document.Current = documentAsInvoice; invoiceEntry.Adjustments .Select() .RowCast <ARAdjust2>() .Where(application => application.Released != true) .ForEach(application => invoiceEntry.Adjustments.Delete(application)); invoiceEntry.Adjustments_1 .Select() .RowCast <ARAdjust>() .Where(application => application.Released != true) .ForEach(application => invoiceEntry.Adjustments_1.Delete(application)); invoiceEntry.Save.Press(); }
private void UpdateTextBoxText() { string textInRange; CustomRangeStart rangeStart = this.radRichTextBox.Document.EnumerateChildrenOfType<CustomRangeStart>().FirstOrDefault(); if (rangeStart != null) { CustomRangeEnd rangeEnd = (CustomRangeEnd)rangeStart.End; DocumentPosition start = new DocumentPosition(this.radRichTextBox.Document); start.MoveToInline(rangeStart); DocumentPosition end = new DocumentPosition(this.radRichTextBox.Document); end.MoveToInline(rangeEnd); DocumentSelection selection = new DocumentSelection(this.radRichTextBox.Document); selection.SetSelectionStart(start); selection.AddSelectionEnd(end); string text = selection.GetSelectedText(); textInRange = text; } else { textInRange = string.Empty; } this.suppressUpdate = true; this.textBox.Text = textInRange; this.suppressUpdate = false; }
protected virtual void DocumentSelection_RowInserted(PXCache cache, PXRowInsertedEventArgs e) { DocumentSelection document = (DocumentSelection)e.Row; if (document != null && !String.IsNullOrWhiteSpace(document.DocType) && !String.IsNullOrWhiteSpace(document.RefNbr)) { document = PXSelectReadonly < DocumentSelection, Where < DocumentSelection.docType, Equal <Required <DocumentSelection.docType> >, And <DocumentSelection.refNbr, Equal <Required <DocumentSelection.refNbr> > > > > .Select(this, document.DocType, document.RefNbr); if (document != null) { Document_Detail.Delete(document); Document_Detail.Update(document); } else { document = (DocumentSelection)e.Row; Document_Detail.Delete(document); cache.RaiseExceptionHandling <DocumentSelection.refNbr>(document, document.RefNbr, new PXSetPropertyException(AP.Messages.ReferenceNotValid)); } } }
protected override void OnMouseMove(object o, MotionNotifyEventArgs args, Cairo.PointD point) { Document doc = PintaCore.Workspace.ActiveDocument; if (!is_drawing) { CheckHandlerCursor(point.X, point.Y); if (!isResizing) { return; } } else { double x = Utility.Clamp(point.X, 0, doc.ImageSize.Width - 1); double y = Utility.Clamp(point.Y, 0, doc.ImageSize.Height - 1); shape_end = new PointD(x, y); ReDraw(args.Event.State); } if (doc.Selection != null) { doc.selHandler.PerformSelectionMode(DocumentSelection.ConvertToPolygonSet(doc.Selection.SelectionPolygons)); PintaCore.Workspace.Invalidate(); } }
/// <inheritdoc /> public override bool Activate(DocumentSelection cursor, CaretMovementMode movementMode, SelectionMode mode) { // first we try to move the cursor directly var caret = cursor.Start; var next = caret.MoveForward(); // try a simply to move the cursor forwards if (next.IsValid) { cursor.MoveTo(next, mode); return(true); } // try get the block backward to get a cursor that looks at the beginning of that block var block = caret.Block?.Parent.GetBlockTo(BlockDirection.Forward, caret.Block) as ContentBlock; if (block != null) { cursor.MoveTo(block.GetCaretAtStart(), mode); return(true); } // we couldn't do it return(false); }
/// <summary> Default constructor. </summary> public DocumentCursorView(DocumentSelection cursor) { _cursor = cursor; _cursor.CursorMoved += HandleCaretChanged; // selection _selectionPointCollection = new PointCollection(8) { new Point(0, 0), new Point(0, 50), new Point(50, 50), new Point(50, 0), new Point(0, 0), new Point(0, 50), new Point(50, 50), new Point(50, 0), }; _selectionPolygon = new Polygon { Fill = new SolidColorBrush() { Color = Color.FromArgb(128, 128, 128, 128) }, Points = _selectionPointCollection }; // caret _caretPointsCollection = new PointCollection(4) { new Point(0, 0), new Point(1, 0), new Point(1, 30), new Point(0, 30), }; _caretRect = new Polygon() { Fill = new SolidColorBrush() { Color = Colors.Black, }, Points = _caretPointsCollection, }; Children.Add(_selectionPolygon); Children.Add(_caretRect); _caretWidth = SystemInformation.CaretWidth; _blinkTimer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(SystemInformation.CaretBlinkTime) }; _blinkTimer.Tick += OnBlinkTimerTick; _blinkTimer.Start(); IsEnabledChanged += HandleEnabledChanged; }
protected override void OnStartTransform() { base.OnStartTransform(); Document doc = PintaCore.Workspace.ActiveDocument; // If there is no selection, select the whole image. if (doc.Selection.SelectionPolygons.Count == 0) { doc.Selection.CreateRectangleSelection( new Cairo.Rectangle(0, 0, doc.ImageSize.Width, doc.ImageSize.Height)); } original_selection = doc.Selection.Clone(); original_transform.InitMatrix(doc.SelectionLayer.Transform); hist = new MovePixelsHistoryItem(Icon, Name, doc); hist.TakeSnapshot(!doc.ShowSelectionLayer); if (!doc.ShowSelectionLayer) { // Copy the selection to the temp layer doc.CreateSelectionLayer(); doc.ShowSelectionLayer = true; //Use same BlendMode, Opacity and Visibility for SelectionLayer doc.SelectionLayer.BlendMode = doc.CurrentUserLayer.BlendMode; doc.SelectionLayer.Opacity = doc.CurrentUserLayer.Opacity; doc.SelectionLayer.Hidden = doc.CurrentUserLayer.Hidden; using (Cairo.Context g = new Cairo.Context(doc.SelectionLayer.Surface)) { g.AppendPath(doc.Selection.SelectionPath); g.FillRule = FillRule.EvenOdd; g.SetSource(doc.CurrentUserLayer.Surface); g.Clip(); g.Paint(); } Cairo.ImageSurface surf = doc.CurrentUserLayer.Surface; using (Cairo.Context g = new Cairo.Context(surf)) { g.AppendPath(doc.Selection.SelectionPath); g.FillRule = FillRule.EvenOdd; if (is_alt_pressed) { g.Operator = Cairo.Operator.Clear; } else { g.Operator = Operator.Source; g.SetSourceColor(PintaCore.Palette.SecondaryColor); } g.Fill(); } } PintaCore.Workspace.Invalidate(); }
/// <summary> Default constructor. </summary> public DocumentEditorContext(DocumentOwner owner) { Document = owner; var cursor = ((ContentBlock)Document.Root.FirstBlock).GetCaretAtStart(); Selection = new DocumentSelection(Document, cursor); CaretMovementMode = new CaretMovementMode(); UndoStack = new ActionStack(this, new StandardMergePolicy()); }
protected virtual void DocumentSelection_RowPersisting(PXCache sender, PXRowPersistingEventArgs e) { DocumentSelection document = e.Row as DocumentSelection; if (document == null) { return; } RemoveApplications(document); }
protected override void OnStartTransform() { base.OnStartTransform(); Document doc = PintaCore.Workspace.ActiveDocument; original_selection = doc.Selection.Clone(); hist = new SelectionHistoryItem(Icon, Name); hist.TakeSnapshot(); }
protected virtual void DocumentSelection_RowSelected(PXCache sender, PXRowSelectedEventArgs e) { DocumentSelection document = e.Row as DocumentSelection; if (document == null) { return; } PXUIFieldAttribute.SetEnabled <DocumentSelection.docType>(sender, document, document.Scheduled != true); PXUIFieldAttribute.SetEnabled <DocumentSelection.refNbr>(sender, document, document.Scheduled != true); }
/// <inheritdoc /> public override bool Activate(DocumentSelection cursor, CaretMovementMode movementMode, SelectionMode mode) { var textCaret = cursor.Start.As <TextCaret>(); double desiredPosition = UpdateMovementMode(movementMode, textCaret); var contentView = textCaret.Block.GetViewOrNull <ITextBlockView>(); if (contentView == null) { return(false); } var currentLine = contentView.GetLineFor(textCaret); var nextLine = currentLine.Next; if (nextLine != null) { // TODO what if it's invalid (maybe only if the line couldn't be found?) var caret = nextLine.FindClosestTo(desiredPosition); if (!caret.IsValid) { return(false); } cursor.MoveTo(caret, mode); return(true); } var currentBlock = textCaret.Block; var nextBlock = currentBlock.Parent.GetBlockTo(BlockDirection.Bottom, currentBlock); if (nextBlock != null) { if (nextBlock.GetViewOrNull <IBlockView>() is IBlockView nextBlockView) { var newCursor = nextBlockView.GetCaretFromTop(movementMode); cursor.MoveTo(newCursor, mode); return(true); } else { return(false); } } // TODO work the way up the document // we couldn't do it return(false); }
/// <summary> /// Finalize re-editable text (if applicable). /// </summary> public void FinalizeText() { //If this is true, don't finalize any text - this is used to prevent the code from looping recursively. if (!ignoreCloneFinalizations) { //Only bother finalizing text if editing. if (CurrentTextEngine.State != TextMode.Unchanged) { //Start ignoring any Surface.Clone calls from this point on (so that it doesn't start to loop). ignoreCloneFinalizations = true; Document doc = PintaCore.Workspace.ActiveDocument; //Create a backup of everything before redrawing the text and etc. Cairo.ImageSurface oldTextSurface = doc.CurrentUserLayer.TextLayer.Layer.Surface.Clone(); Cairo.ImageSurface oldUserSurface = doc.CurrentUserLayer.Surface.Clone(); TextEngine oldTextEngine = CurrentTextEngine.Clone(); //Draw the text onto the UserLayer (without the cursor) rather than the TextLayer. RedrawText(false, false); //Clear the TextLayer. doc.CurrentUserLayer.TextLayer.Layer.Clear(); //Clear the text and its boundaries. CurrentTextEngine.Clear(); CurrentTextBounds = Gdk.Rectangle.Zero; //Create a new TextHistoryItem so that the finalization of the text can be undone. Construct //it on the spot so that it is more memory efficient if the changes are small. TextHistoryItem hist = new TextHistoryItem(Icon, FinalizeName, oldTextSurface, oldUserSurface, oldTextEngine, doc.CurrentUserLayer); //Add the new TextHistoryItem. doc.History.PushNewItem(hist); //Stop ignoring any Surface.Clone calls from this point on. ignoreCloneFinalizations = false; //Now that the text has been finalized, change its state. CurrentTextEngine.State = TextMode.Unchanged; if (selection != null) { selection.Dispose(); selection = null; } } } }
protected override void OnFillRegionComputed(Document document, Point[][] polygonSet) { var undoAction = new SelectionHistoryItem(Icon, Name); undoAction.TakeSnapshot(); document.PreviousSelection.Dispose(); document.PreviousSelection = document.Selection.Clone(); document.Selection.SelectionPolygons.Clear(); SelectionModeHandler.PerformSelectionMode(combine_mode, DocumentSelection.ConvertToPolygons(polygonSet)); document.History.PushNewItem(undoAction); document.Workspace.Invalidate(); }
protected override void OnUpdateTransform(Matrix transform) { base.OnUpdateTransform(transform); List <List <IntPoint> > newSelectionPolygons = DocumentSelection.Transform(original_selection, transform); Document doc = PintaCore.Workspace.ActiveDocument; doc.Selection.SelectionClipper.Clear(); doc.Selection.SelectionPolygons = newSelectionPolygons; doc.Selection.MarkDirty(); doc.ShowSelection = true; PintaCore.Workspace.Invalidate(); }
/// <inheritdoc/> public override bool Activate(DocumentSelection cursor, CaretMovementMode movementMode, SelectionMode mode) { var textCaret = cursor.Start.As <TextCaret>(); movementMode.SetModeToHome(); var contentView = textCaret.Block.GetViewOrNull <ITextBlockView>(); if (contentView == null) { return(false); } textCaret = contentView.GetLineFor(textCaret).FindClosestTo(0); cursor.MoveTo(textCaret, mode); return(true); }
protected override void OnMouseMove(object o, Gtk.MotionNotifyEventArgs args, Cairo.PointD point) { Document doc = PintaCore.Workspace.ActiveDocument; if (!is_drawing) { return; } double x = Utility.Clamp(point.X, 0, doc.ImageSize.Width - 1); double y = Utility.Clamp(point.Y, 0, doc.ImageSize.Height - 1); doc.ShowSelection = true; ImageSurface surf = doc.SelectionLayer.Surface; using (Context g = new Context(surf)) { g.Antialias = Antialias.Subpixel; if (path != null) { g.AppendPath(path); (path as IDisposable).Dispose(); } else { g.MoveTo(x, y); } g.LineTo(x, y); lasso_polygon.Add(new IntPoint((long)x, (long)y)); path = g.CopyPath(); g.FillRule = FillRule.EvenOdd; g.ClosePath(); doc.Selection.SelectionPath = g.CopyPath(); } doc.Selection.SelectionPolygons.Clear(); doc.Selection.SelectionPolygons.Add(lasso_polygon.ToList()); SelectionModeHandler.PerformSelectionMode(combine_mode, DocumentSelection.ConvertToPolygonSet(doc.Selection.SelectionPolygons)); doc.Workspace.Invalidate(); }
/// <summary> /// Removes all application records associated with the specified /// document. This is required in order to prevent stuck application /// records after a document becomes scheduled. /// </summary> private void RemoveApplications(DocumentSelection document) { ARInvoiceEntry invoiceEntry = PXGraph.CreateInstance <ARInvoiceEntry>(); ARInvoice documentAsInvoice = PXSelect < ARInvoice, Where < ARInvoice.docType, Equal <Required <ARInvoice.docType> >, And <ARInvoice.refNbr, Equal <Required <ARInvoice.refNbr> > > > > .Select(invoiceEntry, document.DocType, document.RefNbr); invoiceEntry.Document.Current = documentAsInvoice; //Removing aggregates on curyAdjdWOAmt and curyAdjdAmt fields to avoid excessive update of ARInvoice record invoiceEntry.Adjustments.Cache.Adjust <PXFormulaAttribute>().For <ARAdjust2.curyAdjdWOAmt>(a => { if (a.Aggregate.IsIn(typeof(SumCalc <ARPayment.curyWOAmt>), typeof(SumCalc <AR.ARInvoice.curyBalanceWOTotal>))) { a.Aggregate = null; } }); invoiceEntry.Adjustments.Cache.Adjust <PXFormulaAttribute>().For <ARAdjust2.curyAdjdAmt>(a => { if (a.Aggregate == typeof(SumCalc <AR.ARInvoice.curyPaymentTotal>)) { a.Aggregate = null; } }); invoiceEntry.Adjustments .Select() .RowCast <ARAdjust2>() .Where(application => application.Released != true) .ForEach(application => invoiceEntry.Adjustments.Delete(application)); invoiceEntry.Adjustments_1 .Select() .RowCast <ARAdjust>() .Where(application => application.Released != true) .ForEach(application => invoiceEntry.Adjustments_1.Delete(application)); invoiceEntry.Save.Press(); }
protected override void OnUpdateTransform(Matrix transform) { base.OnUpdateTransform(transform); List <List <IntPoint> > newSelectionPolygons = DocumentSelection.Transform(original_selection, transform); Document doc = PintaCore.Workspace.ActiveDocument; doc.Selection.SelectionClipper.Clear(); doc.Selection.SelectionPolygons = newSelectionPolygons; using (var g = new Cairo.Context(doc.CurrentUserLayer.Surface)) { doc.Selection.SelectionPath = g.CreatePolygonPath(DocumentSelection.ConvertToPolygonSet(newSelectionPolygons)); g.FillRule = FillRule.EvenOdd; g.AppendPath(doc.Selection.SelectionPath); } doc.ShowSelection = true; PintaCore.Workspace.Invalidate(); }
protected override void OnFinishTransform(Matrix transform) { base.OnFinishTransform(transform); // Also transform the base selection used for the various select modes. var doc = PintaCore.Workspace.ActiveDocument; using (var prev_selection = doc.PreviousSelection) doc.PreviousSelection = prev_selection.Transform(transform); if (hist != null) { PintaCore.History.PushNewItem(hist); } hist = null; original_selection.Dispose(); original_selection = null; original_transform.InitIdentity(); }
private void StartEditing() { is_editing = true; if (selection == null) { selection = PintaCore.Workspace.ActiveDocument.Selection.Clone(); } //Start ignoring any Surface.Clone calls from this point on (so that it doesn't start to loop). ignoreCloneFinalizations = true; //Store the previous state of the current UserLayer's and TextLayer's ImageSurfaces. user_undo_surface = PintaCore.Workspace.ActiveDocument.CurrentUserLayer.Surface.Clone(); text_undo_surface = PintaCore.Workspace.ActiveDocument.CurrentUserLayer.TextLayer.Surface.Clone(); undo_engine = CurrentTextEngine.Clone(); //Stop ignoring any Surface.Clone calls from this point on. ignoreCloneFinalizations = false; }
protected override void OnMouseUp(DrawingArea canvas, ButtonReleaseEventArgs args, Cairo.PointD point) { Document doc = PintaCore.Workspace.ActiveDocument; // If the user didn't move the mouse, they want to deselect int tolerance = 0; if (Math.Abs(reset_origin.X - args.Event.X) <= tolerance && Math.Abs(reset_origin.Y - args.Event.Y) <= tolerance) { PintaCore.Actions.Edit.Deselect.Activate(); if (hist != null) { hist.Dispose(); hist = null; } doc.ToolLayer.Clear(); } else { ReDraw(args.Event.State); if (doc.Selection != null) { SelectionModeHandler.PerformSelectionMode(combine_mode, DocumentSelection.ConvertToPolygonSet(doc.Selection.SelectionPolygons)); doc.Selection.selEnd = shape_end; PintaCore.Workspace.Invalidate(); } if (hist != null) { doc.History.PushNewItem(hist); hist = null; } } is_drawing = false; active_control = null; // Update the mouse cursor. CheckHandlerCursor(point); }
protected override void OnMouseUp(DrawingArea canvas, ButtonReleaseEventArgs args, Cairo.PointD point) { Document doc = PintaCore.Workspace.ActiveDocument; // If the user didn't move the mouse, they want to deselect int tolerance = 0; if (Math.Abs(reset_origin.X - args.Event.X) <= tolerance && Math.Abs(reset_origin.Y - args.Event.Y) <= tolerance) { PintaCore.Actions.Edit.Deselect.Activate(); hist.Dispose(); hist = null; handler_active = false; doc.ToolLayer.Clear(); } else { ReDraw(args.Event.State); if (doc.Selection != null) { doc.selHandler.PerformSelectionMode(DocumentSelection.ConvertToPolygonSet(doc.Selection.SelectionPolygons)); PintaCore.Workspace.Invalidate(); } if (hist != null) { doc.History.PushNewItem(hist); } handler_active = true; hist.Dispose(); hist = null; } is_drawing = false; isResizing = false; }
protected override void OnMouseMove(object o, MotionNotifyEventArgs args, Cairo.PointD point) { Document doc = PintaCore.Workspace.ActiveDocument; if (!is_drawing) { CheckHandlerCursor(point); return; } double x = Utility.Clamp(point.X, 0, doc.ImageSize.Width - 1); double y = Utility.Clamp(point.Y, 0, doc.ImageSize.Height - 1); controls[active_control.Value].HandleMouseMove(x, y, args.Event.State); ReDraw(args.Event.State); if (doc.Selection != null) { SelectionModeHandler.PerformSelectionMode(combine_mode, DocumentSelection.ConvertToPolygonSet(doc.Selection.SelectionPolygons)); PintaCore.Workspace.Invalidate(); } }
private void UpdateTextBoxText() { string textInRange; CustomRangeStart rangeStart = this.radRichTextBox.Document.EnumerateChildrenOfType <CustomRangeStart>().FirstOrDefault(); if (rangeStart != null) { CustomRangeEnd rangeEnd = (CustomRangeEnd)rangeStart.End; DocumentPosition start = new DocumentPosition(this.radRichTextBox.Document); start.MoveToInline(rangeStart); DocumentPosition end = new DocumentPosition(this.radRichTextBox.Document); end.MoveToInline(rangeEnd); DocumentSelection selection = new DocumentSelection(this.radRichTextBox.Document); selection.SetSelectionStart(start); selection.AddSelectionEnd(end); string text = selection.GetSelectedText(); textInRange = text; } else { textInRange = string.Empty; } this.suppressUpdate = true; this.textBox.Text = textInRange; this.suppressUpdate = false; }
protected override void OnMouseDown(DrawingArea canvas, ButtonPressEventArgs args, Cairo.PointD point) { ctrlKey = (args.Event.State & ModifierType.ControlMask) != 0; //Store the mouse position. Point pt = point.ToGdkPoint(); // Grab focus so we can get keystrokes PintaCore.Chrome.Canvas.GrabFocus(); if (selection != null) { selection.Dispose(); } selection = PintaCore.Workspace.ActiveDocument.Selection.Clone(); // A right click allows you to move the text around if (args.Event.Button == 3) { //The user is dragging text with the right mouse button held down, so track the mouse as it moves. tracking = true; //Remember the position of the mouse before the text is dragged. startMouseXY = point; startClickPoint = clickPoint; //Change the cursor to indicate that the text is being dragged. SetCursor(cursor_hand); return; } // The user clicked the left mouse button if (args.Event.Button == 1) { // If the user is [editing or holding down Ctrl] and clicked //within the text, move the cursor to the click location if ((is_editing || ctrlKey) && CurrentTextBounds.ContainsCorrect(pt)) { StartEditing(); //Change the position of the cursor to where the mouse clicked. TextPosition p = CurrentTextLayout.PointToTextPosition(pt); CurrentTextEngine.SetCursorPosition(p, true); //Redraw the text with the new cursor position. RedrawText(true, true); return; } // We're already editing and the user clicked outside the text, // commit the user's work, and start a new edit switch (CurrentTextEngine.State) { // We were editing, save and stop case TextMode.Uncommitted: StopEditing(true); break; // We were editing, but nothing had been // keyed. Stop editing. case TextMode.Unchanged: StopEditing(false); break; } if (ctrlKey) { //Go through every UserLayer. foreach (UserLayer ul in PintaCore.Workspace.ActiveDocument.UserLayers) { //Check each UserLayer's editable text boundaries to see if they contain the mouse position. if (ul.textBounds.ContainsCorrect(pt)) { //The mouse clicked on editable text. //Change the current UserLayer to the Layer that contains the text that was clicked on. PintaCore.Workspace.ActiveDocument.SetCurrentUserLayer(ul); //The user is editing text now. is_editing = true; //Set the cursor in the editable text where the mouse was clicked. TextPosition p = CurrentTextLayout.PointToTextPosition(pt); CurrentTextEngine.SetCursorPosition(p, true); //Redraw the editable text with the cursor. RedrawText(true, true); //Don't check any more UserLayers - stop at the first UserLayer that has editable text containing the mouse position. return; } } } else { if (CurrentTextEngine.State == TextMode.NotFinalized) { //The user is making a new text and the old text hasn't been finalized yet. FinalizeText(); } if (!is_editing) { // Start editing at the cursor location clickPoint = pt; CurrentTextEngine.Clear(); clickPoint.Offset(0, -CurrentTextLayout.FontHeight / 2); CurrentTextEngine.Origin = clickPoint; StartEditing(); RedrawText(true, true); } } } }
protected override void OnFillRegionComputed(Point[][] polygonSet) { Document doc = PintaCore.Workspace.ActiveDocument; SelectionHistoryItem undoAction = new SelectionHistoryItem(this.Icon, this.Name); undoAction.TakeSnapshot(); //Convert Pinta's passed in Polygon Set to a Clipper Polygon collection. List <List <IntPoint> > newPolygons = DocumentSelection.ConvertToPolygons(polygonSet); using (Context g = new Context(PintaCore.Layers.CurrentLayer.Surface)) { //Make sure time isn't wasted if the CombineMode is Replace - Replace is much simpler than the other 4 selection modes. if (combineMode == CombineMode.Replace) { //Clear any previously stored Polygons. doc.Selection.SelectionPolygons.Clear(); //Set the resulting selection path to the new selection path. doc.Selection.SelectionPolygons = newPolygons; doc.Selection.SelectionPath = g.CreatePolygonPath(polygonSet); } else { List <List <IntPoint> > resultingPolygons = new List <List <IntPoint> >(); //Specify the Clipper Subject (the previous Polygons) and the Clipper Clip (the new Polygons). //Note: for Union, ignore the Clipper Library instructions - the new polygon(s) should be Clips, not Subjects! doc.Selection.SelectionClipper.AddPolygons(doc.Selection.SelectionPolygons, PolyType.ptSubject); doc.Selection.SelectionClipper.AddPolygons(newPolygons, PolyType.ptClip); switch (combineMode) { case CombineMode.Xor: //Xor means "Combine both Polygon sets, but leave out any areas of intersection between the two." doc.Selection.SelectionClipper.Execute(ClipType.ctXor, resultingPolygons); break; case CombineMode.Exclude: //Exclude == Difference //Exclude/Difference means "Subtract any overlapping areas of the new Polygon set from the old Polygon set." doc.Selection.SelectionClipper.Execute(ClipType.ctDifference, resultingPolygons); break; case CombineMode.Intersect: //Intersect means "Leave only the overlapping areas between the new and old Polygon sets." doc.Selection.SelectionClipper.Execute(ClipType.ctIntersection, resultingPolygons); break; default: //Default should only be *CombineMode.Union*, but just in case... //Union means "Combine both Polygon sets, and keep any overlapping areas as well." doc.Selection.SelectionClipper.Execute(ClipType.ctUnion, resultingPolygons); break; } //After using Clipper, it has to be cleared so there are no conflicts with its next usage. doc.Selection.SelectionClipper.Clear(); //Set the resulting selection path to the calculated ("clipped") selection path. doc.Selection.SelectionPolygons = resultingPolygons; doc.Selection.SelectionPath = g.CreatePolygonPath(DocumentSelection.ConvertToPolygonSet(resultingPolygons)); } } doc.History.PushNewItem(undoAction); doc.Workspace.Invalidate(); }
private string ExportAnnotationRangeFragment(RadDocument document, string semanticRangeName) { RecipeRangeStart semanticRangestart = null; RecipeRangeEnd semanticRangeEnd = null; foreach (RecipeRangeStart rangeStart in document.GetAnnotationMarkersOfType<RecipeRangeStart>()) { if (rangeStart.Name == semanticRangeName) { semanticRangestart = rangeStart; semanticRangeEnd = (RecipeRangeEnd)rangeStart.End; } } if (semanticRangestart != null && semanticRangeEnd != null) { DocumentPosition startPosition = new DocumentPosition(document); startPosition.MoveToInline((InlineLayoutBox)semanticRangestart.FirstLayoutBox, 0); DocumentPosition endPosition = new DocumentPosition(document); endPosition.MoveToInline((InlineLayoutBox)semanticRangeEnd.FirstLayoutBox, 0); DocumentSelection selection = new DocumentSelection(document); selection.SetSelectionStart(startPosition); selection.AddSelectionEnd(endPosition); DocumentFragment fragment = new DocumentFragment(selection); RadDocument fragmentDocument = fragment.ToDocument(); HtmlFormatProvider htmlFormatProvider = new HtmlFormatProvider(); htmlFormatProvider.ExportSettings = new HtmlExportSettings(); htmlFormatProvider.ExportSettings.DocumentExportLevel = DocumentExportLevel.Fragment; htmlFormatProvider.ExportSettings.StylesExportMode = StylesExportMode.Inline; htmlFormatProvider.ExportSettings.StyleRepositoryExportMode = StyleRepositoryExportMode.DontExportStyles; return htmlFormatProvider.Export(fragmentDocument); } return string.Empty; }
private string GetCurrentWord() { DocumentPosition pos = new DocumentPosition(this.Document.CaretPosition); pos.MoveToCurrentWordStart(); DocumentSelection selection = new DocumentSelection(this.Document); selection.AddSelectionStart(pos); pos.MoveToCurrentWordEnd(); selection.AddSelectionEnd(pos); return selection.GetSelectedText().Trim(); }
/// <summary> Activates the given command, acting on the given caret. </summary> /// <param name="cursor"> The caret on which to act. </param> /// <param name="movementMode"> The current caret mode. </param> /// <param name="mode"></param> /// <param name="shouldExtend"> How the caret should be moved. </returns> public abstract bool Activate(DocumentSelection cursor, CaretMovementMode movementMode, SelectionMode mode);