public void RemoveLayerOverlay(Layer layer, DocumentLayerOverlay overlay, RectInt32?invalidateRect) { DocumentLayerOverlay overlay2; Validate.Begin().IsNotNull <Layer>(layer, "layer").IsNotNull <DocumentLayerOverlay>(overlay, "overlay").Check(); base.VerifyAccess(); if (!this.overlays.TryGetValue(layer, out overlay2)) { throw new KeyNotFoundException(); } if (overlay2 != overlay) { throw new InvalidOperationException(); } this.overlays.Remove(layer); this.documentRenderer.RemoveLayerOverlay(layer); overlay.Cancel(); if (invalidateRect.HasValue) { if (invalidateRect.Value.HasPositiveArea) { layer.Invalidate(invalidateRect.Value); } } else { layer.Invalidate(overlay.AffectedBounds); } }
public void ReplaceLayerOverlay(Layer layer, DocumentLayerOverlay oldOverlay, DocumentLayerOverlay newOverlay, RectInt32?invalidateRect) { DocumentLayerOverlay overlay; base.VerifyAccess(); if ((oldOverlay == null) && (newOverlay == null)) { throw new ArgumentNullException(); } this.overlays.TryGetValue(layer, out overlay); if (overlay != oldOverlay) { throw new InvalidOperationException(); } if ((oldOverlay == null) && (newOverlay != null)) { this.SetLayerOverlay(layer, newOverlay, invalidateRect); } else if (newOverlay == null) { this.RemoveLayerOverlay(layer, overlay, invalidateRect); } else { if (newOverlay.IsCancellationRequested) { throw new InvalidOperationException("Cannot set an overlay which is already cancelled"); } this.overlays[layer] = newOverlay; this.documentRenderer.ReplaceLayerOverlay(layer, newOverlay); oldOverlay.Cancel(); if (invalidateRect.HasValue) { if (invalidateRect.Value.HasPositiveArea) { layer.Invalidate(invalidateRect.Value); } } else { RectInt32?nullable = (oldOverlay == null) ? null : new RectInt32?(oldOverlay.AffectedBounds); RectInt32?nullable2 = (newOverlay == null) ? null : new RectInt32?(newOverlay.AffectedBounds); RectInt32?nullable3 = RectInt32Util.Union(nullable, nullable2); if (nullable3.HasValue && nullable3.Value.HasPositiveArea) { layer.Invalidate(nullable3.Value); } } } }