Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GrammaticalOptimization/WpfTestSvgSample/PrintPreviewWindow.xaml.cs @ 13857

Last change on this file since 13857 was 12762, checked in by aballeit, 9 years ago

#2283 GUI updates, Tree-chart, MCTS Version 2 (prune leaves)

File size: 4.3 KB
Line 
1using System;
2using System.IO;
3using System.IO.Packaging;
4using System.IO.Compression;
5using System.Linq;
6using System.Text;
7using System.ComponentModel;
8using System.Collections.Generic;
9
10using System.Windows;
11using System.Windows.Controls;
12using System.Windows.Data;
13using System.Windows.Documents;
14using System.Windows.Input;
15using System.Windows.Media;
16using System.Windows.Media.Imaging;
17using System.Windows.Shapes;
18using System.Windows.Xps.Packaging;
19
20namespace WpfTestSvgSample
21{
22    /// <summary>
23    /// Interaction logic for PrintPreviewWindow.xaml
24    /// </summary>
25    public partial class PrintPreviewWindow : Window
26    {
27        #region Private Fields
28
29        private string      _fileName;
30        private Package     _xpsDocPackage;
31        private XpsDocument _xpsDocument;
32
33        #endregion
34
35        #region Constructors and Destructor
36
37        public PrintPreviewWindow()
38        {
39            InitializeComponent();
40
41            this.Loaded += new RoutedEventHandler(OnWindowLoaded);
42            this.Unloaded += new RoutedEventHandler(OnWindowUnloaded);
43
44            this.Closed += new EventHandler(OnWindowClosed);
45            this.Closing += new CancelEventHandler(OnWindowClosing);
46        }
47
48        #endregion
49
50        #region Public Methods
51
52        public void LoadDocument(XpsDocument document, Package package, string sourceFileName)
53        {
54            if (document == null)
55            {
56                return;
57            }
58
59            try
60            {
61                if (_xpsDocument != null)
62                {
63                    _xpsDocument.Close();
64                    _xpsDocument = null;
65                }
66
67                if (_xpsDocPackage != null)
68                {
69                    _xpsDocPackage.Close();
70                    _xpsDocPackage = null;
71                }
72
73                if (!String.IsNullOrEmpty(_fileName))
74                {
75                    PackageStore.RemovePackage(new Uri(_fileName));
76                }
77            }
78            catch
79            {
80            }
81
82            _xpsDocument   = document;
83            _xpsDocPackage = package;
84            _fileName      = sourceFileName;
85
86            docViewer.Document = _xpsDocument.GetFixedDocumentSequence();
87        }
88
89        #endregion
90
91        #region Private Methods
92
93        private void OnWindowLoaded(object sender, RoutedEventArgs e)
94        {
95            ContentControl findToolbar = docViewer.Template.FindName(
96                "PART_FindToolBarHost", docViewer) as ContentControl;
97            if (findToolbar != null)
98            {
99                findToolbar.Visibility = Visibility.Collapsed;
100            }
101        }
102
103        private void OnWindowUnloaded(object sender, RoutedEventArgs e)
104        {
105            try
106            {
107                docViewer.Document = null;
108
109                if (_xpsDocument != null)
110                {
111                    _xpsDocument.Close();
112                    _xpsDocument = null;
113                }
114
115                if (_xpsDocPackage != null)
116                {
117                    _xpsDocPackage.Close();
118                    _xpsDocPackage = null;
119                }
120
121                if (!String.IsNullOrEmpty(_fileName))
122                {
123                    PackageStore.RemovePackage(new Uri(_fileName));
124                }
125            }
126            catch
127            {
128            }
129        }
130
131        private void OnWindowClosing(object sender, CancelEventArgs e)
132        {
133            try
134            {
135                docViewer.Document = null;
136
137                if (_xpsDocument != null)
138                {
139                    _xpsDocument.Close();
140                    _xpsDocument = null;
141                }
142
143                if (_xpsDocPackage != null)
144                {
145                    _xpsDocPackage.Close();
146                    _xpsDocPackage = null;
147                }
148
149                if (!String.IsNullOrEmpty(_fileName))
150                {
151                    PackageStore.RemovePackage(new Uri(_fileName));
152                }
153            }
154            catch
155            {
156            }
157        }
158
159        private void OnWindowClosed(object sender, EventArgs e)
160        {
161        }
162
163        #endregion
164    }
165}
Note: See TracBrowser for help on using the repository browser.