Esempio n. 1
0
        private void CleanUp()
        {
            /* Collapse this stuff since it is going to be released */
            xaml_ThumbGrid.Visibility = System.Windows.Visibility.Collapsed;

            /* Clear out everything */
            if (m_docPages != null && m_docPages.Count > 0)
            {
                m_docPages.Clear();
            }
            if (m_pageType != null && m_pageType.Count > 0)
            {
                m_pageType.Clear();
            }
            if (m_thumbnails != null && m_thumbnails.Count > 0)
            {
                m_thumbnails.Clear();
            }
            if (m_toppage_pos != null && m_toppage_pos.Count > 0)
            {
                m_toppage_pos.Clear();
            }
            if (m_list_thumb != null && m_list_thumb.Count > 0)
            {
                m_list_thumb.Clear();
            }
            if (m_images_rendered != null && m_images_rendered.Count > 0)
            {
                m_images_rendered.Clear();
            }
            if (m_page_sizes != null && m_page_sizes.Count > 0)
            {
                m_page_sizes.Clear();
            }

            m_currfile = null;
            m_origfile = null;
            m_numpages = -1;
            m_doc_type_has_page_access = true;
            m_document_type            = doc_t.UNKNOWN;
            m_origfile = null;
            CleanUpTempFiles();
            xaml_TotalPages.Text = "/ 0";
            xaml_currPage.Text   = "0";
            CloseExtraWindows(false);

            m_ghostscript.PageRenderedCallBack -= new GSNET.PageRendered(gsPageRendered);
            m_ghostscript.DisplayDeviceClose();
            m_ghostscript.DisplayDeviceOpen();
            m_viewer_state = ViewerState_t.NO_FILE;

            /* Set vertical scroll to top position */
            Decorator    border       = VisualTreeHelper.GetChild(xaml_PageList, 0) as Decorator;
            ScrollViewer scrollViewer = border.Child as ScrollViewer;

            scrollViewer.ScrollToVerticalOffset(0);
            return;
        }
        private void CleanUp()
        {
            m_init_done = false;

            /* Collapse this stuff since it is going to be released */
            xaml_ThumbGrid.Visibility = System.Windows.Visibility.Collapsed;

            /* Clear out everything */
            if (m_docPages != null && m_docPages.Count > 0)
            {
                m_docPages.Clear();
            }
            if (m_pageType != null && m_pageType.Count > 0)
            {
                m_pageType.Clear();
            }
            if (m_thumbnails != null && m_thumbnails.Count > 0)
            {
                m_thumbnails.Clear();
            }
            if (m_toppage_pos != null && m_toppage_pos.Count > 0)
            {
                m_toppage_pos.Clear();
            }
            if (m_list_thumb != null && m_list_thumb.Count > 0)
            {
                m_list_thumb.Clear();
            }
            if (m_images_rendered != null && m_images_rendered.Count > 0)
            {
                m_images_rendered.Clear();
            }
            if (m_page_sizes != null && m_page_sizes.Count > 0)
            {
                m_page_sizes.Clear();
            }

            m_currfile      = null;
            m_origfile      = null;
            m_numpages      = -1;
            m_file_open     = false;
            m_firstime      = true;
            m_document_type = doc_t.UNKNOWN;
            m_origfile      = null;
            CleanUpTempFiles();
            m_file_open          = false;
            m_busy_render        = true;
            xaml_TotalPages.Text = "/ 0";
            xaml_currPage.Text   = "0";
            CloseExtraWindows(false);

            return;
        }
        public MainWindow()
        {
            InitializeComponent();
            this.Closing += new System.ComponentModel.CancelEventHandler(Window_Closing);

            /* Set up ghostscript calls for progress update */
            m_ghostscript = new ghostsharp();
            m_ghostscript.gsUpdateMain     += new ghostsharp.gsCallBackMain(gsProgress);
            m_ghostscript.gsIOUpdateMain   += new ghostsharp.gsIOCallBackMain(gsIO);
            m_ghostscript.gsDLLProblemMain += new ghostsharp.gsDLLProblem(gsDLL);

            m_currpage = 0;
            m_gsoutput = new gsOutput();
            m_gsoutput.Activate();
            m_tempfiles       = new List <TempFile>();
            m_thumbnails      = new List <DocPage>();
            m_docPages        = new Pages();
            m_pageType        = new List <Page_Content_t>();
            m_page_sizes      = new List <pagesizes_t>();
            m_file_open       = false;
            m_document_type   = doc_t.UNKNOWN;
            m_doczoom         = 1.0;
            m_init_done       = false;
            m_busy_render     = true;
            m_validZoom       = true;
            m_firstime        = true;
            m_list_thumb      = new List <idata_t>();
            m_images_rendered = new List <idata_t>();
            m_busy_rendering  = false;
            m_aa        = true;
            m_aa_change = false;

            xaml_PageList.AddHandler(Grid.DragOverEvent, new System.Windows.DragEventHandler(Grid_DragOver), true);
            xaml_PageList.AddHandler(Grid.DropEvent, new System.Windows.DragEventHandler(Grid_Drop), true);

            /* For case of opening another file */
            string[] arguments = Environment.GetCommandLineArgs();
            if (arguments.Length > 1)
            {
                string filePath = arguments[1];
                ProcessFile(filePath);
            }
        }
Esempio n. 4
0
        public void ProcessFile(String FileName)
        {
            /* Before we even get started check for issues */
            /* First check if file exists and is available */
            if (!System.IO.File.Exists(FileName))
            {
                ShowMessage(NotifyType_t.MESS_STATUS, "File not found!");
                return;
            }
            if (m_viewer_state == ViewerState_t.DOC_OPEN)
            {
                /* In this case, we want to go ahead and launch a new process
                 * handing it the filename */
                /* We need to get the location */
                string path = System.Reflection.Assembly.GetExecutingAssembly().CodeBase;
                try
                {
                    string Arguments = FileName + " open";
                    Process.Start(path, Arguments);
                }
                catch (InvalidOperationException)
                {
                    Console.WriteLine("InvalidOperationException");
                }
                catch (Win32Exception)
                {
                    Console.WriteLine("Win32 Exception: There was an error in opening the associated file. ");
                }
                return;
            }
            else if (m_viewer_state != ViewerState_t.NO_FILE)
            {
                return;
            }

            m_viewer_state = ViewerState_t.OPENING;

            /* If we have a ps or eps file then launch the distiller first
             * and then we will get a temp pdf file which we will open.  This is done
             * to demo both methods of doing callbacks from gs worker thread.  Either
             * progress as we distill the stream for PS or page by page for PDF */
            string extension = System.IO.Path.GetExtension(FileName);

            /* We are doing this based on the extension but should do
             * it based upon the content */
            switch (extension.ToUpper())
            {
            case ".PS":
                m_document_type = doc_t.PS;
                break;

            case ".EPS":
                m_document_type = doc_t.EPS;
                break;

            case ".PDF":
                m_document_type = doc_t.PDF;
                break;

            case ".XPS":
                m_document_type = doc_t.XPS;
                break;

            case ".OXPS":
                m_document_type = doc_t.XPS;
                break;

            case ".BIN":
                m_document_type = doc_t.PCL;
                break;

            case ".PNG":
                m_document_type = doc_t.PNG;
                break;

            case ".JPG":
                m_document_type = doc_t.JPG;
                break;

            case ".TIF":
                m_document_type = doc_t.TIF;
                break;

            default:
            {
                m_document_type = doc_t.UNKNOWN;
                ShowMessage(NotifyType_t.MESS_STATUS, "Unknown File Type");
                m_viewer_state = ViewerState_t.NO_FILE;
                return;
            }
            }
            if (m_document_type == doc_t.PCL ||
                m_document_type == doc_t.XPS ||
                m_document_type == doc_t.PS)
            {
                MessageBoxResult result = MessageBox.Show("Would you like to distill this file?", "ghostnet", MessageBoxButton.YesNoCancel);
                switch (result)
                {
                case MessageBoxResult.Yes:
                    xaml_DistillProgress.Value = 0;
                    m_viewer_state             = ViewerState_t.DISTILLING;
                    if (m_ghostscript.DistillPS(FileName, Constants.DEFAULT_GS_RES) == gsStatus.GS_BUSY)
                    {
                        ShowMessage(NotifyType_t.MESS_STATUS, "GS currently busy");
                        return;
                    }
                    xaml_DistillName.Text         = "Distilling";
                    xaml_CancelDistill.Visibility = System.Windows.Visibility.Visible;
                    xaml_DistillName.FontWeight   = FontWeights.Bold;
                    xaml_DistillGrid.Visibility   = System.Windows.Visibility.Visible;
                    return;

                case MessageBoxResult.No:
                    //m_doc_type_has_page_access = false;
                    break;

                case MessageBoxResult.Cancel:
                    m_viewer_state = ViewerState_t.NO_FILE;
                    return;
                }
            }
            m_currfile = FileName;
            RenderThumbs();
            return;
        }
Esempio n. 5
0
        public MainWindow()
        {
            InitializeComponent();
            this.Closing += new System.ComponentModel.CancelEventHandler(Window_Closing);

            /* Set up ghostscript calls for progress update */
            m_ghostscript = new GSNET();
            m_ghostscript.ProgressCallBack   += new GSNET.Progress(gsProgress);
            m_ghostscript.StdIOCallBack      += new GSNET.StdIO(gsIO);
            m_ghostscript.DLLProblemCallBack += new GSNET.DLLProblem(gsDLL);
            m_ghostscript.DisplayDeviceOpen();

            m_currpage = 0;
            m_gsoutput = new gsOutput();
            m_gsoutput.Activate();
            m_tempfiles                = new List <TempFile>();
            m_thumbnails               = new List <DocPage>();
            m_docPages                 = new Pages();
            m_pageType                 = new List <Page_Content_t>();
            m_page_sizes               = new List <pagesizes_t>();
            m_document_type            = doc_t.UNKNOWN;
            m_doczoom                  = 1.0;
            m_viewer_state             = ViewerState_t.NO_FILE;
            m_validZoom                = true;
            m_doc_type_has_page_access = true;
            m_list_thumb               = new List <idata_t>();
            m_images_rendered          = new List <idata_t>();
            m_aa = true;

            xaml_PageList.AddHandler(Grid.DragOverEvent, new System.Windows.DragEventHandler(Grid_DragOver), true);
            xaml_PageList.AddHandler(Grid.DropEvent, new System.Windows.DragEventHandler(Grid_Drop), true);


            /* For case of opening another file, or launching a print process */
            string[] arguments = Environment.GetCommandLineArgs();
            if (arguments.Length == 3)
            {
                string filePath = arguments[1];
                string job      = arguments[2];

                if (String.Equals(job, "open"))
                {
                    ProcessFile(filePath);
                }
            }
            else if (arguments.Length == 5)
            {
                string filePath = arguments[1];
                string job      = arguments[2];

                try
                {
                    m_currpage = Int32.Parse(arguments[3]);
                    m_numpages = Int32.Parse(arguments[4]);
                }
                catch (FormatException)
                {
                    Console.WriteLine("Failure to parse print page info");
                    Close();
                }

                /* Keep main window hidden if we are doing a print process */
                this.IsVisibleChanged += new System.Windows.DependencyPropertyChangedEventHandler(WindowVisible);
                m_viewer_state         = ViewerState_t.PRINTING;
                Print(filePath);
            }
        }