示例#1
0
        /// <summary>
        /// Opens a powerpoint file.
        /// </summary>
        /// <param name="filename">The file to open.</param>
        /// <param name="rect">The rectangle of the area on the screen, where to show the PowerPoint Viewer.</param>
        /// <param name="generateThumbnails">Whether thumbnails should be generated.</param>
        /// <param name="openHidden">Whether the PowerPoint Viewer should be opened hidden (outside of the visible screen).</param>
        /// <param name="thumbnailWidth">If set, defines the size of the generated thumbnails.</param>
        /// <returns>
        /// A <see cref="PowerpointViewerDocument"/> that manages the status of the PowerPoint Viewer instance.
        /// </returns>
        /// <exception cref="InvalidOperationException">PowerPoint Viewer could not be found (maybe it's not installed).</exception>
        /// <exception cref="FileNotFoundException">The file to open could not be found.</exception>
        /// <exception cref="DllNotFoundException">pptviewlib.dll could not be found.</exception>
        /// <exception cref="PowerpointViewerOpenException">Something went wrong in pptviewlib.dll</exception>
        public static PowerpointViewerDocument Open(string filename, Rectangle rect, bool generateThumbnails = true, bool openHidden = false, int thumbnailWidth = 0)
        {
            if (!IsAvailable)
            {
                throw new InvalidOperationException("Can't open a file: PowerPoint Viewer could not be found.");
            }

            var file = new FileInfo(filename);

            if (!file.Exists)
            {
                throw new FileNotFoundException(file.FullName);
            }

            PowerpointViewerDocument doc = new PowerpointViewerDocument(file.FullName, rect, generateThumbnails, openHidden, thumbnailWidth);

            return(doc);
        }
        /// <summary>
        /// Opens a powerpoint file.
        /// </summary>
        /// <param name="filename">The file to open.</param>
        /// <param name="rect">The rectangle of the area on the screen, where to show the PowerPoint Viewer.</param>
        /// <param name="generateThumbnails">Whether thumbnails should be generated.</param>
        /// <param name="openHidden">Whether the PowerPoint Viewer should be opened hidden (outside of the visible screen).</param>
        /// <param name="thumbnailWidth">If set, defines the size of the generated thumbnails.</param>
        /// <returns>
        /// A <see cref="PowerpointViewerDocument"/> that manages the status of the PowerPoint Viewer instance.
        /// </returns>
        /// <exception cref="InvalidOperationException">PowerPoint Viewer could not be found (maybe it's not installed).</exception>
        /// <exception cref="FileNotFoundException">The file to open could not be found.</exception>
        /// <exception cref="DllNotFoundException">pptviewlib.dll could not be found.</exception>
        /// <exception cref="PowerpointViewerOpenException">Something went wrong in pptviewlib.dll</exception>
        public static PowerpointViewerDocument Open(string filename, Rectangle rect, bool generateThumbnails = true, bool openHidden = false, int thumbnailWidth = 0)
        {
            if (!IsAvailable)
                throw new InvalidOperationException("Can't open a file: PowerPoint Viewer could not be found.");

            var file = new FileInfo(filename);

            if (!file.Exists)
                throw new FileNotFoundException(file.FullName);

            PowerpointViewerDocument doc = new PowerpointViewerDocument(file.FullName, rect, generateThumbnails, openHidden, thumbnailWidth);
            return doc;
        }
        private void PerformLoad()
        {
            if (File == null)
                throw new InvalidOperationException("file has not been set");

            try
            {
                doc = PowerpointViewerController.Open(this.File.FullName, new Rectangle(Area.WindowLocation.X, Area.WindowLocation.Y, Area.WindowSize.Width, Area.WindowSize.Height), openHidden: true, thumbnailWidth: 200);
                doc.Error += (sender, args) =>
                {
                    if (!doc.HasLoaded)
                    {
                        Controller.Dispatcher.Invoke(new Action(() => OnLoaded(false)));
                    }
                    else
                    {
                        base.OnClosedExternally();
                    }
                };

                doc.Loaded += (sender, args) =>
                {
                    Controller.Dispatcher.Invoke(new Action(() =>
                    {
                        if (!isClosing)
                        {
                            WordsLive.Presentation.Wpf.Interop.RemoveFromAeroPeek(doc.WindowHandle);
                            if (showOnLoaded)
                            {
                                doc.Move(Area.WindowLocation.X, Area.WindowLocation.Y);
                                isShown = true;
                            }
                            OnLoaded(true);
                            Controller.FocusMainWindow(true);
                        }
                        else
                        {
                            doc.Close();
                        }
                    }));
                };

                doc.Closed += (sender, args) =>
                {
                    if (!isClosing)
                        base.OnClosedExternally();
                };

                doc.SlideChanged += (sender, args) =>
                {
                    base.OnSlideIndexChanged();
                };

                doc.HiddenSlide += (sender, args) =>
                {
                    Controller.Dispatcher.Invoke(new Action(() =>
                    {
                        if (!hasShownHiddenWarning)
                        {
                            MessageBox.Show(Resource.slideErrorMsgHiddenSlides, Resource.slideErrorMsgHiddenSlidesTitle, MessageBoxButton.OK, MessageBoxImage.Warning);
                            hasShownHiddenWarning = true;
                        }
                    }));
                };

                LoadPreviewProvider();
            }
            catch (PowerpointViewerController.PowerpointViewerOpenException)
            {
                Controller.Dispatcher.Invoke(new Action(() =>
                {
                    OnLoaded(false);
                }));
            }
        }
示例#4
0
 private void listBoxDocuments_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (listBoxDocuments.SelectedIndex == -1)
         activeDocument = null;
     else
         activeDocument = openDocuments[listBoxDocuments.SelectedIndex];
     UpdateStats();
 }
示例#5
0
        private void buttonOpen_Click(object sender, EventArgs e)
        {
            int x = int.Parse(textBoxX.Text);
            int y = int.Parse(textBoxY.Text);
            int width = int.Parse(textBoxWidth.Text);
            int height = int.Parse(textBoxHeight.Text);
            string filename = textBoxFilename.Text;

            if (string.IsNullOrEmpty(filename))
                return;

            Rectangle rect = new Rectangle(x, y, width, height);
            try
            {
                activeDocument = PowerpointViewerController.Open(filename, rect, thumbnailWidth: 200);
                activeDocument.Loaded += new EventHandler(activeDocument_Loaded);
                activeDocument.SlideChanged += new EventHandler(activeDocument_SlideChanged);
                activeDocument.Closed += new EventHandler(activeDocument_Closed);
                activeDocument.HiddenSlide += new EventHandler(activeDocument_HiddenSlide);
                openDocuments.Add(activeDocument);
                listBoxDocuments.SelectedIndex = listBoxDocuments.Items.Add("Document #" + (counter++));
                this.UpdateStats();
                SetForegroundWindow(this.Handle);
            }
            catch (PowerpointViewerController.PowerpointViewerOpenException)
            {
                MessageBox.Show("Loading failed.");
            }
        }
示例#6
0
 private void buttonClose_Click(object sender, EventArgs e)
 {
     if (activeDocument == null)
         return;
     activeDocument.Close();
     activeDocument = null;
 }