private void Strokes_StrokesChanged(object sender, System.Windows.Ink.StrokeCollectionChangedEventArgs e)
 {
     if (e.Added.Count > 0)
     {
         tempList.Push(e.Added);
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Event handler associated with the stroke collection.
        /// </summary>
        /// <param name="sender">Stroke collection that was modified</param>
        /// <param name="args">Modification that occurred</param>
        /// <remarks>
        /// Update our _strokeInfos cache.  We get notified on StrokeCollection.StrokesChangedInternal which
        /// is raised first so we can assume we're the first delegate in the call chain
        /// </remarks>
        private void OnStrokesChanged(object sender, StrokeCollectionChangedEventArgs args)
        {
            System.Diagnostics.Debug.Assert((_strokes != null) && (_strokeInfos != null) && (_strokes == sender));

            StrokeCollection added   = args.Added;
            StrokeCollection removed = args.Removed;

            if (added.Count > 0)
            {
                int firstIndex = _strokes.IndexOf(added[0]);
                for (int i = 0; i < added.Count; i++)
                {
                    _strokeInfos.Insert(firstIndex, new StrokeInfo(added[i]));
                    firstIndex++;
                }
            }

            if (removed.Count > 0)
            {
                StrokeCollection localRemoved = new StrokeCollection(removed);
                //we have to assume that removed strokes can be in any order in _strokes
                for (int i = 0; i < _strokeInfos.Count && localRemoved.Count > 0;)
                {
                    bool found = false;
                    for (int j = 0; j < localRemoved.Count; j++)
                    {
                        if (localRemoved[j] == _strokeInfos[i].Stroke)
                        {
                            _strokeInfos.RemoveAt(i);
                            localRemoved.RemoveAt(j);

                            found = true;
                        }
                    }
                    //we didn't find a removed stroke at index i in _strokeInfos, so advance i
                    if (!found)
                    {
                        i++;
                    }
                }
            }

            //validate our cache
            if (_strokes.Count != _strokeInfos.Count)
            {
                Debug.Assert(false, "Benign assert.  IncrementalHitTester's _strokeInfos cache is out of sync, rebuilding.");
                RebuildStrokeInfoCache();
                return;
            }
            for (int i = 0; i < _strokeInfos.Count; i++)
            {
                if (_strokeInfos[i].Stroke != _strokes[i])
                {
                    Debug.Assert(false, "Benign assert.  IncrementalHitTester's _strokeInfos cache is out of sync, rebuilding.");
                    RebuildStrokeInfoCache();
                    return;
                }
            }
        }
Exemplo n.º 3
0
        private void Strokes_StrokesChanged(object sender, System.Windows.Ink.StrokeCollectionChangedEventArgs e)
        {
            if (handle)
            {
                _added   = e.Added;
                _removed = e.Removed;

                testiadded.Add(_added);
            }
        }
        // This function will invoke OnStrokesChanged method.
        //      addedStrokes    -   the collection which contains the added strokes during the previous op.
        //      removedStrokes  -   the collection which contains the removed strokes during the previous op.
        private void RaiseStrokesChanged(StrokeCollection addedStrokes, StrokeCollection removedStrokes, int index)
        {
            StrokeCollectionChangedEventArgs eventArgs =
                new StrokeCollectionChangedEventArgs(addedStrokes, removedStrokes, index);

            // Invoke OnPropertyChanged
            OnPropertyChanged(CountName);
            OnPropertyChanged(IndexerName);

            // Invoke OnStrokesChanged which will fire the StrokesChanged event AND the CollectionChanged event.
            OnStrokesChanged(eventArgs);
        }
Exemplo n.º 5
0
 private void Strokes_StrokesChanged(object sender, System.Windows.Ink.StrokeCollectionChangedEventArgs e)
 {
     if (handle)
     {
         addedStrokes.Push(e.Added);
         removedStrokes.Push(e.Removed);
         if (e.Added != null)
         {
             removedStrokes.Clear();
         }
     }
 }
        /// <summary>Method called on derived classes whenever a drawing attributes
        /// change has occurred in the stroke references in the collection</summary>
        /// <param name="e">The change information for the stroke collection</param>
        /// <remarks>StrokesChanged will not be called when drawing attributes or
        /// custom attributes are changed. Changes that trigger StrokesChanged
        /// include packets or points changing, modified tranforms, and stroke objects
        /// being added or removed from the collection.
        /// To ensure that events fire for event listeners, derived classes
        /// should call this method.</remarks>
        protected virtual void OnStrokesChanged(StrokeCollectionChangedEventArgs e)
        {
            if (null == e)
            {
                throw new ArgumentNullException("e", SR.Get(SRID.EventArgIsNull));
            }

            //raise our internal event first.  This is used by
            //our Renderer and IncrementalHitTester since if they can assume
            //they are the first in the delegate chain, they can be optimized
            //to not have to handle out of order events caused by 3rd party code
            //getting called first
            if (this.StrokesChangedInternal != null)
            {
                this.StrokesChangedInternal(this, e);
            }
            if (this.StrokesChanged != null)
            {
                this.StrokesChanged(this, e);
            }
            if (_collectionChanged != null)
            {
                //raise CollectionChanged.  We support the following
                //NotifyCollectionChangedActions
                NotifyCollectionChangedEventArgs args = null;
                if (this.Count == 0)
                {
                    //Reset
                    Debug.Assert(e.Removed.Count > 0);
                    args = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset);
                }
                else if (e.Added.Count == 0)
                {
                    //Remove
                    args = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, e.Removed, e.Index);
                }
                else if (e.Removed.Count == 0)
                {
                    //Add
                    args = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, e.Added, e.Index);
                }
                else
                {
                    //Replace
                    args = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Replace, e.Added, e.Removed, e.Index);
                }
                _collectionChanged(this, args);
            }
        }
Exemplo n.º 7
0
        private void StrokeCollection_StrokesChanged(object sender, System.Windows.Ink.StrokeCollectionChangedEventArgs e)
        {
            try
            {
                if (!_initialized)
                {
                    return;
                }

                RedrawSmallImage();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// StrokeCollectionChanged event handler
        /// </summary>
        private void OnStrokesChanged(object sender, StrokeCollectionChangedEventArgs eventArgs)
        {
            System.Diagnostics.Debug.Assert(sender == _strokes);

            // Read the args
            StrokeCollection added   = eventArgs.Added;
            StrokeCollection removed = eventArgs.Removed;

            // Add new strokes
            foreach (Stroke stroke in added)
            {
                // Verify that it's not a dupe
                if (_visuals.ContainsKey(stroke))
                {
                    throw new System.ArgumentException(SR.Get(SRID.DuplicateStrokeAdded));
                }

                // Create a visual for the new stroke and add it to the dictionary
                StrokeVisual visual = new StrokeVisual(stroke, this);
                _visuals.Add(stroke, visual);

                // Start listening on the stroke events
                StartListeningOnStrokeEvents(visual.Stroke);

                // Attach it to the visual tree
                AttachVisual(visual, false /*buildingStrokeCollection*/);
            }

            // Deal with removed strokes first
            foreach (Stroke stroke in removed)
            {
                // Verify that the event is in sync with the view
                StrokeVisual visual = null;
                if (_visuals.TryGetValue(stroke, out visual))
                {
                    // get rid of both the visual and the stroke
                    DetachVisual(visual);
                    StopListeningOnStrokeEvents(visual.Stroke);
                    _visuals.Remove(stroke);
                }
                else
                {
                    throw new System.ArgumentException(SR.Get(SRID.UnknownStroke3));
                }
            }
        }
        /// <summary>
        /// Our own internal listener for strokes changed.
        /// This is used so that if someone deletes or modifies a stroke
        /// we are currently displaying for selection, we can update our size
        /// </summary>
        private void OnStrokeCollectionChanged(object target, StrokeCollectionChangedEventArgs e)
        {
            // If the strokes only get added to the InkCanvas, we don't have to update our internal selected strokes.
            if ( e.Added.Count != 0 && e.Removed.Count == 0 )
            {
                return;
            }

            foreach (Stroke s in e.Removed)
            {
                if ( SelectedStrokes.Contains(s) )
                {
                    s.Invalidated -= new EventHandler(this.OnStrokeInvalidated);
                    s.IsSelected = false;

                    // Now remove the stroke from our private collection.
                    SelectedStrokes.Remove(s);
                }
            }

            // Mark the strokes change
            _areStrokesChanged = true;
            UpdateSelectionAdorner();
        }
Exemplo n.º 10
0
        /// <summary>
        /// StrokeCollectionChanged event handler
        /// </summary>
        private void OnStrokesChanged(object sender, StrokeCollectionChangedEventArgs eventArgs)
        {
            System.Diagnostics.Debug.Assert(sender == _strokes);

            // Read the args
            StrokeCollection added = eventArgs.Added;
            StrokeCollection removed = eventArgs.Removed;

            // Add new strokes
            foreach (Stroke stroke in added)
            {
                // Verify that it's not a dupe
                if (_visuals.ContainsKey(stroke))
                {
                    throw new System.ArgumentException(SR.Get(SRID.DuplicateStrokeAdded));
                }

                // Create a visual for the new stroke and add it to the dictionary
                StrokeVisual visual = new StrokeVisual(stroke, this);
                _visuals.Add(stroke, visual);

                // Start listening on the stroke events
                StartListeningOnStrokeEvents(visual.Stroke);

                // Attach it to the visual tree
                AttachVisual(visual, false/*buildingStrokeCollection*/);
            }

            // Deal with removed strokes first
            foreach (Stroke stroke in removed)
            {
                // Verify that the event is in [....] with the view
                StrokeVisual visual = null;
                if (_visuals.TryGetValue(stroke, out visual))
                {
                    // get rid of both the visual and the stroke
                    DetachVisual(visual);
                    StopListeningOnStrokeEvents(visual.Stroke);
                    _visuals.Remove(stroke);
                }
                else
                {
                    throw new System.ArgumentException(SR.Get(SRID.UnknownStroke3));
                }
            }
        }
 /// <summary>
 /// Change is not allowed.  We would override SetItem, InsertItem etc but
 /// they need to be sealed on StrokeCollection to prevent dupes from being added
 /// </summary>
 /// <param name="e"></param>
 protected override void OnStrokesChanged(StrokeCollectionChangedEventArgs e)
 {
     throw new NotSupportedException(SR.Get(SRID.StrokeCollectionIsReadOnly));
 }
Exemplo n.º 12
0
        private void OnStrokesChanged(object sender, StrokeCollectionChangedEventArgs e)
        {
            // Update the ink data of the ink analyzer.
            if (e.Removed.Count > 0)
            {
                foreach (Stroke stroke in e.Removed)
                {
                    //we're removing this stroke so we don't need to listen 
                    //to StylusPointsChanged anymore
                    stroke.StylusPointsChanged -= OnStrokeStylusPointsChanged;
                }
                circuitInkCanvas.InkAnalyzer.RemoveStrokes(e.Removed);


            }
            if (e.Added.Count > 0)
            {
                foreach (Stroke stroke in e.Added)
                {
                    //listen for StylusPointsChanged, which can happen
                    //during move and resize operations
                    stroke.StylusPointsChanged += OnStrokeStylusPointsChanged;
                }
                circuitInkCanvas.InkAnalyzer.AddStrokes(e.Added);
                circuitInkCanvas.InkAnalyzer.SetStrokesType(e.Added, StrokeType.Unspecified);
            }
            circuitInkCanvas.InkAnalyzer.BackgroundAnalyze();
        }
 protected virtual new void OnStrokesChanged(StrokeCollectionChangedEventArgs e)
 {
 }
Exemplo n.º 14
0
        /// <summary>
        /// Event handler associated with the stroke collection.
        /// </summary>
        /// <param name="sender">Stroke collection that was modified</param>
        /// <param name="args">Modification that occurred</param>
        /// <remarks>
        /// Update our _strokeInfos cache.  We get notified on StrokeCollection.StrokesChangedInternal which
        /// is raised first so we can assume we're the first delegate in the call chain
        /// </remarks>
        private void OnStrokesChanged(object sender, StrokeCollectionChangedEventArgs args)
        {
            System.Diagnostics.Debug.Assert((_strokes != null) && (_strokeInfos != null) && (_strokes == sender));

            StrokeCollection added = args.Added;
            StrokeCollection removed = args.Removed;

            if (added.Count > 0)
            {
                int firstIndex = _strokes.IndexOf(added[0]);
                for (int i = 0; i < added.Count; i++)
                {
                    _strokeInfos.Insert(firstIndex, new StrokeInfo(added[i]));
                    firstIndex++;
                }
            }

            if (removed.Count > 0)
            {
                StrokeCollection localRemoved = new StrokeCollection(removed);
                //we have to assume that removed strokes can be in any order in _strokes
                for (int i = 0; i < _strokeInfos.Count && localRemoved.Count > 0; )
                {
                    bool found = false;
                    for (int j = 0; j < localRemoved.Count; j++)
                    {
                        if (localRemoved[j] == _strokeInfos[i].Stroke)
                        {
                            _strokeInfos.RemoveAt(i);
                            localRemoved.RemoveAt(j);

                            found = true;
                        }
                    }
                    //we didn't find a removed stroke at index i in _strokeInfos, so advance i
                    if (!found)
                    {
                        i++;
                    }
                }
            }

            //validate our cache
            if (_strokes.Count != _strokeInfos.Count)
            {
                Debug.Assert(false, "Benign assert.  IncrementalHitTester's _strokeInfos cache is out of [....], rebuilding.");
                RebuildStrokeInfoCache();
                return;
            }
            for (int i = 0; i < _strokeInfos.Count; i++)
            {
                if (_strokeInfos[i].Stroke != _strokes[i])
                {
                    Debug.Assert(false, "Benign assert.  IncrementalHitTester's _strokeInfos cache is out of [....], rebuilding.");
                    RebuildStrokeInfoCache();
                    return;
                }
            }
        }
Exemplo n.º 15
0
        /// <summary>
        /// StrokeCollectionChanged event handler
        /// </summary>
        private void OnStrokesChanged(object sender, StrokeCollectionChangedEventArgs eventArgs)
        {
            System.Diagnostics.Debug.Assert(sender == this.Strokes);

            SetStrokeChangedHandlers(eventArgs.Added, eventArgs.Removed);
            OnStrokeChanged(this, EventArgs.Empty);
        }
Exemplo n.º 16
0
 private void Strokes_StrokesChanged(object sender, System.Windows.Ink.StrokeCollectionChangedEventArgs e)
 {
     this.InitStrokes(e.Added, false);
 }
Exemplo n.º 17
0
        void Strokes_StrokesChanged(object sender, StrokeCollectionChangedEventArgs e)
        {
            foreach (Stroke stroke in e.Added)
            {
                if (!graphAnalyzer.newStroke(stroke))
                {
                    inkAnalyzer.AddStroke(stroke);
                }

                AutocorrectHandleAddStroke(stroke);
            }

            double ymax = InkUtils.StrokeYMax(e.Added);
            if (ymax > MainInkCanvas.ActualHeight - 300.0)
                MainInkCanvas.Height = ymax + 800.0; 

            foreach (Stroke stroke in e.Removed)
            {
                graphAnalyzer.removeStroke(stroke);
                // If we erase a word and try to replace it with autocorrect
                // suggestions, there's no good way to define the behavior
                // so just hide the suggestions.
                suggestionsBox.Visibility = Visibility.Collapsed;

                inkAnalyzer.RemoveStroke(stroke);
            }
        }
Exemplo n.º 18
0
        /**
         * This method is called as you start drawing, for each change
         * */
        private void canvasStrokesChanged(object sender, StrokeCollectionChangedEventArgs e)
        {
            if (sender as StrokeCollection != null)
            {
                StrokeCollection strokes = (StrokeCollection)sender;

                for(int i=0; i<strokes.Count ; i++){
                    Console.WriteLine();
                    Stroke s = strokes[i];
                    //ensures we don't end up hooking our event handler multiple times :)
                    s.StylusPointsChanged -= new EventHandler(s_StylusPointsChanged);
                    s.StylusPointsChanged += new EventHandler(s_StylusPointsChanged);
                }
            }
        }