Пример #1
0
        public PDFTextSentenceLayer(PDFRendererControlStats pdf_renderer_control_stats, int page)
        {
            this.pdf_renderer_control_stats = pdf_renderer_control_stats;
            this.page = page;

            InitializeComponent();

            Focusable = true;
            KeyboardNavigation.SetDirectionalNavigation(this, KeyboardNavigationMode.Once);

            Background = Brushes.Transparent;
            Cursor     = Cursors.IBeam;

            SizeChanged += PDFTextSentenceLayer_SizeChanged;

            drag_area_tracker = new DragAreaTracker(this, false);
            drag_area_tracker.OnDragStarted    += drag_area_tracker_OnDragStarted;
            drag_area_tracker.OnDragInProgress += drag_area_tracker_OnDragInProgress;
            drag_area_tracker.OnDragComplete   += drag_area_tracker_OnDragComplete;

            text_selection_manager = new TextSelectionManager();

            PreviewMouseDown     += PDFTextSentenceLayer_PreviewMouseDown;
            PreviewKeyDown       += PDFTextLayer_PreviewKeyDown;
            RequestBringIntoView += PDFTextSentenceLayer_RequestBringIntoView;

            text_layer_selection_mode = TextLayerSelectionMode.Sentence;
        }
        public PDFTextSentenceLayer(PDFRendererControl pdf_renderer_control, int page)
        {
            WPFDoEvents.AssertThisCodeIsRunningInTheUIThread();

            this.pdf_renderer_control = new WeakReference <PDFRendererControl>(pdf_renderer_control);
            this.page = page;

            InitializeComponent();

            Focusable = true;
            KeyboardNavigation.SetDirectionalNavigation(this, KeyboardNavigationMode.Once);

            Background = Brushes.Transparent;
            Cursor     = Cursors.IBeam;

            SizeChanged += PDFTextSentenceLayer_SizeChanged;

            drag_area_tracker = new DragAreaTracker(this, false);
            drag_area_tracker.OnDragStarted    += drag_area_tracker_OnDragStarted;
            drag_area_tracker.OnDragInProgress += drag_area_tracker_OnDragInProgress;
            drag_area_tracker.OnDragComplete   += drag_area_tracker_OnDragComplete;

            text_selection_manager = new TextSelectionManager();

            PreviewMouseDown     += PDFTextSentenceLayer_PreviewMouseDown;
            PreviewKeyDown       += PDFTextLayer_PreviewKeyDown;
            RequestBringIntoView += PDFTextSentenceLayer_RequestBringIntoView;

            text_layer_selection_mode = TextLayerSelectionMode.Sentence;

            //Unloaded += PDFTextSentenceLayer_Unloaded;
            Dispatcher.ShutdownStarted += Dispatcher_ShutdownStarted;
        }
Пример #3
0
        protected virtual void Dispose(bool disposing)
        {
            Logging.Debug("PDFTextSentenceLayer::Dispose({0}) @{1}", disposing, dispose_count);

            try
            {
                if (null != drag_area_tracker)
                {
                    WPFDoEvents.InvokeInUIThread(() =>
                    {
                        try
                        {
                            foreach (var el in Children)
                            {
                                IDisposable node = el as IDisposable;
                                if (null != node)
                                {
                                    node.Dispose();
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            Logging.Error(ex);
                        }

                        try
                        {
                            ClearChildren();
                            Children.Clear();
                        }
                        catch (Exception ex)
                        {
                            Logging.Error(ex);
                        }

                        drag_area_tracker.OnDragStarted    -= drag_area_tracker_OnDragStarted;
                        drag_area_tracker.OnDragInProgress -= drag_area_tracker_OnDragInProgress;
                        drag_area_tracker.OnDragComplete   -= drag_area_tracker_OnDragComplete;
                    }, Dispatcher);
                }

                // Clear the references for sanity's sake
                pdf_renderer_control_stats = null;
                drag_area_tracker          = null;
                text_selection_manager     = null;

                DataContext = null;
            }
            catch (Exception ex)
            {
                Logging.Error(ex);
            }

            ++dispose_count;

            //base.Dispose(disposing);     // parent only throws an exception (intentionally), so depart from best practices and don't call base.Dispose(bool)
        }
        protected virtual void Dispose(bool disposing)
        {
            Logging.Debug("PDFTextSentenceLayer::Dispose({0}) @{1}", disposing, dispose_count);

            WPFDoEvents.InvokeInUIThread(() =>
            {
                WPFDoEvents.SafeExec(() =>
                {
                    if (dispose_count == 0)
                    {
                        foreach (var el in Children)
                        {
                            IDisposable node = el as IDisposable;
                            if (null != node)
                            {
                                node.Dispose();
                            }
                        }
                    }
                });

                WPFDoEvents.SafeExec(() =>
                {
                    ClearChildren();
                    Children.Clear();
                });

                WPFDoEvents.SafeExec(() =>
                {
                    if (drag_area_tracker != null)
                    {
                        drag_area_tracker.OnDragStarted    -= drag_area_tracker_OnDragStarted;
                        drag_area_tracker.OnDragInProgress -= drag_area_tracker_OnDragInProgress;
                        drag_area_tracker.OnDragComplete   -= drag_area_tracker_OnDragComplete;
                    }

                    Dispatcher.ShutdownStarted -= Dispatcher_ShutdownStarted;
                });

                WPFDoEvents.SafeExec(() =>
                {
                    // Clear the references for sanity's sake
                    pdf_renderer_control   = null;
                    drag_area_tracker      = null;
                    text_selection_manager = null;
                });

                WPFDoEvents.SafeExec(() =>
                {
                    DataContext = null;
                });

                ++dispose_count;

                //base.Dispose(disposing);     // parent only throws an exception (intentionally), so depart from best practices and don't call base.Dispose(bool)
            });
        }