Пример #1
0
        internal void InsertThumbnail(Image image, string slideTitle, int index, Guid tag)
        {
            lock (this)
            {
                if (index < 0 || picBoxes.Count < index)
                {
                    throw new ArgumentOutOfRangeException("Index must be within the collection.");
                }

                Image thumb = CreateSlideThumbnail(pbSize, image, slideTitle);

                ThumbnailListViewItem item = new ThumbnailListViewItem();
                item.thumbnail = thumb;
                item.tag       = tag;

                this.items.Insert(index, item);

                PictureBox pb = new PictureBox();
                pb.SizeMode    = PictureBoxSizeMode.StretchImage;
                pb.Click      += new EventHandler(PictureBoxClick);
                pb.MouseEnter += new EventHandler(PictureBoxMouseEnter);
                pb.MouseLeave += new EventHandler(PictureBoxMouseLeave);
                pb.Image       = thumb;
                pb.Size        = pbSize;

                this.Controls.Add(pb);
                picBoxes.Insert(index, pb);

                #region Add picture box at the appropriate place
                if (picBoxes.Count == 1)  // this is the first picBox in the arr
                {
                    // place it at "0,0" (so to speak)
                    ArrangeSlides();  // this should do that without causing problems
                }
                else // not the only one.  Easy enough
                {
                    // place picBox @ location of the previous one at this location
                    // move all picBoxes at & after this one down "one" spot

                    // <cough>... now we play the double-pointer iteration game.
                    PictureBox crnt;
                    if (index != 0)
                    {
                        crnt = (PictureBox)picBoxes[index - 1];
                    }
                    else
                    {
                        crnt = null;
                    }

                    PictureBox next = pb;
                    for (int cnt = index + 1; cnt < picBoxes.Count; ++cnt)
                    {
                        crnt = next;
                        next = (PictureBox)picBoxes[cnt];

                        crnt.Location = next.Location;
                    }

                    // finally we set the last one to a new location
                    int xLoc, yLoc;
                    if (horizontalMode)
                    {
                        xLoc = crnt.Right + 2 * AutoScrollMargin.Width + constNumberSpace;
                        yLoc = (this.Height - pbSize.Height - constScrollBarWidth) / 2;
                    }
                    else
                    {
                        xLoc = constNumberSpace + (this.Width - pbSize.Width - constScrollBarWidth) / 2;
                        yLoc = crnt.Bottom + 2 * AutoScrollMargin.Height;
                    }

                    next.Location = new Point(xLoc, yLoc);
                }
                #endregion

                this.Invalidate();
            }
        }
Пример #2
0
        internal void InsertThumbnail( Image image, string slideTitle, int index, Guid tag )
        {
            lock (this)
            {
                if( index < 0 || picBoxes.Count < index )
                    throw new ArgumentOutOfRangeException(Strings.IndexMustBeWithinTheCollection);

                Image thumb = CreateSlideThumbnail( pbSize, image, slideTitle );

                ThumbnailListViewItem item = new ThumbnailListViewItem();
                item.thumbnail = thumb;
                item.tag = tag;

                this.items.Insert(index, item);
            
                PictureBox pb = new PictureBox();
                pb.SizeMode = PictureBoxSizeMode.StretchImage;
                pb.Click += new EventHandler(PictureBoxClick);
                pb.MouseEnter += new EventHandler(PictureBoxMouseEnter);
                pb.MouseLeave += new EventHandler(PictureBoxMouseLeave);
                pb.Image = thumb;
                pb.Size = pbSize;

                this.Controls.Add(pb);
                picBoxes.Insert(index, pb);

                #region Add picture box at the appropriate place
                if( picBoxes.Count == 1 ) // this is the first picBox in the arr
                {
                    // place it at "0,0" (so to speak)
                    ArrangeSlides();  // this should do that without causing problems
                }
                else // not the only one.  Easy enough
                {
                    // place picBox @ location of the previous one at this location
                    // move all picBoxes at & after this one down "one" spot

                    // <cough>... now we play the double-pointer iteration game.
                    PictureBox crnt;
                    if( index != 0 )
                        crnt = (PictureBox)picBoxes[index-1];
                    else
                        crnt = null;

                    PictureBox next = pb;
                    for( int cnt = index+1; cnt < picBoxes.Count; ++cnt )
                    {
                        crnt = next;
                        next = (PictureBox)picBoxes[cnt];

                        crnt.Location = next.Location;
                    }

                    // finally we set the last one to a new location
                    int xLoc, yLoc;
                    if( horizontalMode )
                    {
                        xLoc = crnt.Right + 2*AutoScrollMargin.Width + constNumberSpace;
                        yLoc = (this.Height - pbSize.Height - constScrollBarWidth) / 2;
                    }
                    else
                    {
                        xLoc = constNumberSpace + (this.Width - pbSize.Width - constScrollBarWidth) / 2;
                        yLoc = crnt.Bottom + 2*AutoScrollMargin.Height;
                    }

                    next.Location = new Point(xLoc, yLoc);
                }
                #endregion

                this.Invalidate();
            }
        }
        // Pri2: All the code in this region is temporary

        // The code in this region allows to request remote capability to open a 
        // rtd file located in the same place than the one open by the initiator

        // The Open Remote menu has to be explicitely activated using the 
        // application configuration key
        // MSR.LST.ConferenceXP.Capability.Presentation.OpenRemote

        /// <summary>
        /// Menu item miOpenRemote_Click event handler. Open a remote rtd file.
        /// When you open a file using this menu, the exact same rtd file has to be
        /// at at the same location on every remote machine 
        /// </summary>
        /// <param name="sender">The event sender object</param>
        /// <param name="e">The event arguments</param>
        private void miOpenRemote_Click(object sender, System.EventArgs e)
        {
            System.Windows.Forms.OpenFileDialog cdlg = new OpenFileDialog();
            cdlg.Filter = "RTDocument files (*.rtd)|*.rtd" ;
            DialogResult dr = cdlg.ShowDialog();

            try
            {
                if (dr == DialogResult.OK)
                {
                    string fileName = cdlg.FileName;

                    if (System.IO.Path.GetExtension(fileName).ToLower(CultureInfo.InvariantCulture) == ".rtd")
                    {
                        // Open a RTD file
                        lock(this)
                        {
                            rtDocument = LoadRtdFile(fileName);
                        }
                        if (rtDocument == null)
                        {
                            return;
                        }
                    } 
                    else
                    {
                        RtlAwareMessageBox.Show(this, string.Format(CultureInfo.CurrentCulture, 
                            Strings.ErrorInOpeningFileType, fileName), string.Empty, MessageBoxButtons.OK, 
                            MessageBoxIcon.None, MessageBoxDefaultButton.Button1, (MessageBoxOptions)0);
                        return;
                    }

                    Log(string.Format(CultureInfo.CurrentCulture, "rtDocID = {0}", 
                        rtDocument.Identifier.ToString()));

                    // Update the title bar of the form 
                    // with the document name followed by the capability name
                    this.Text = rtDocument.Metadata.Title + " - " + this.presentationCapability.Name;

                    // Clean up the screen
                    DeleteAllStrokes();

                    Log("On open doc: info before creating RTDocHelper,");
                    DisplayRTDocumentOnlyStructureInfo();
                    rtDocumentHelper = new RTDocumentHelper(this.presentationCapability, rtDocument);

                    Log("Structure Info on open after creating RTDocHelper,");
                    DisplayRTDocumentStructureInfo();

                    #region Populate thumbnails
                    ArrayList thumbnails = new ArrayList();

                    using (Bitmap bp = new Bitmap( thumbnailsView.ImageSize.Width, thumbnailsView.ImageSize.Height, 
                               System.Drawing.Imaging.PixelFormat.Format24bppRgb))
                    {
                        using (Graphics g = Graphics.FromImage(bp))
                        {
                            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;

                            foreach( TOCNode tn in rtDocument.Organization.TableOfContents )
                            {
                                Page p = (Page)tn.Resource;

                                ThumbnailListView.CreateSlideThumbnail( thumbnailsView.ImageSize,
                                    p.Image, g, tn.Title );

                                ThumbnailListViewItem item = new ThumbnailListViewItem();
                                item.thumbnail = ((Bitmap)bp.Clone());
                                item.tag = tn.Identifier;
                                thumbnails.Add(item);
                            }
                        }
                    }

                    thumbnailsView.Items = (ThumbnailListViewItem[])thumbnails.ToArray(typeof(ThumbnailListViewItem));
                    #endregion

                    // Initialize the index on the first slide
                    index = 0;

                    // Show the current page
                    statusBar.SetMaxPage( 1, rtDocument.Organization.TableOfContents.Count );
                    ShowPage(rtDocument.Organization.TableOfContents[index].Identifier);

                    // Send a message to request the remote users to open the rtd file
                    // fileName
                    SendRemoteFileOpen(fileName);

                    // Update the Backward/Forward buttons (push the navigation button in the 
                    // direction(s)that you cannot move anymore)
                    UpdateNavigationButtonState();

                    // Display the current page on the sender and viewer
                    UpdateCurrentPage();
                }
            }
            catch(Exception ex) 
            {
                RtlAwareMessageBox.Show(this, string.Format(CultureInfo.CurrentCulture, Strings.ErrorInOpening, 
                    cdlg.FileName, ex.Message.ToString()), string.Empty, MessageBoxButtons.OK, MessageBoxIcon.None, 
                    MessageBoxDefaultButton.Button1, (MessageBoxOptions)0);
                return;
            }
        }
        /// <summary>
        /// Open a file in local rtd file name.
        /// </summary>
        /// <param name="fileName">filename (path + filename)</param>
        // Pri3: There is a lot of duplication of code between openLocalFile
        // and miOpenRemote_Click method that could be written just once
        // If this code is going to stay in long term we should change that
        private void openLocalFile(string fileName)
        {
            try
            {
                // Open a RTD file
                lock(this)
                {
                    rtDocument = LoadRtdFile(fileName);
                }
                if (rtDocument == null)
                {
                    return;
                }

                // Update the title bar of the form 
                // with the document name followed by the capability name
                this.Text = rtDocument.Metadata.Title + " - " + this.presentationCapability.Name;

                DisplayRTDocumentOnlyStructureInfo();
                rtDocumentHelper = new RTDocumentHelper(this.presentationCapability, rtDocument);

                DisplayRTDocumentStructureInfo();

                #region Populate thumbnails
                ArrayList thumbnails = new ArrayList();

                using (Bitmap bp = new Bitmap( thumbnailsView.ImageSize.Width, thumbnailsView.ImageSize.Height, 
                           System.Drawing.Imaging.PixelFormat.Format24bppRgb))
                {
                    using (Graphics g = Graphics.FromImage(bp))
                    {
                        g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                        g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;

                        foreach( TOCNode tn in rtDocument.Organization.TableOfContents )
                        {
                            Page p = (Page)tn.Resource;

                            ThumbnailListView.CreateSlideThumbnail( thumbnailsView.ImageSize,
                                p.Image, g, tn.Title );

                            ThumbnailListViewItem item = new ThumbnailListViewItem();
                            item.thumbnail = ((Bitmap)bp.Clone());
                            item.tag = tn.Identifier;
                            thumbnails.Add(item);
                        }
                    }
                }

                thumbnailsView.Items = (ThumbnailListViewItem[])thumbnails.ToArray(typeof(ThumbnailListViewItem));
                #endregion

                // Initialize the index on the first slide
                index = 0;

                // Show the current page
                statusBar.SetMaxPage( 1, rtDocument.Organization.TableOfContents.Count );
                ShowPage(rtDocument.Organization.TableOfContents[index].Identifier);

                // Display the current page on the sender and viewer
                UpdateCurrentPage();
                UpdateNavigationButtonState();
            }
            catch(Exception ex) 
            {
                RtlAwareMessageBox.Show(this, string.Format(CultureInfo.CurrentCulture, Strings.ErrorInOpening, 
                    fileName,ex.Message.ToString()), string.Empty, MessageBoxButtons.OK, MessageBoxIcon.None, 
                    MessageBoxDefaultButton.Button1, (MessageBoxOptions)0);
                return;
            }
        }
        /// <summary>
        /// This method allows the initiator to open a .ppt or .rtd file.
        /// After the file is open, all the slides are sent to the client(s) and the
        /// client(s) are positionned to the same page than the initiator.
        /// </summary>
        /// <remarks>If you open a .ppt file, a corresponding .rtd file is automatically 
        /// created with the same name and saved in the same folder. If there is an 
        /// existing .rtd file with the same name in  this folder, it will be overwrited</remarks>
        /// <param name="fileMenu">This parameter is for extensibility. The only value so far
        /// is OpenSlideDeck</param>
        private void openFile()
        {
            System.Windows.Forms.OpenFileDialog cdlg = new OpenFileDialog();
            cdlg.Filter = "All Presentation Documents (*.ppt, *.pptx, *.rtd)|" +
                "*.ppt;*.pptx;*.rtd|PowerPoint document files (*.ppt,*.pptx)|*.ppt;*.pptx|RTDocument files (*.rtd)|*.rtd" ;
            DialogResult dr = cdlg.ShowDialog();

            try
            {
                if (dr == DialogResult.OK)
                {
                    string fileName = cdlg.FileName;
                    string extension = System.IO.Path.GetExtension(fileName).ToLower(CultureInfo.InvariantCulture);

                    if (extension == ".ppt" || extension == ".pptx")
                    {
                        #region Open a PPT file
                        lock(this)
                        {
                            statusBar.SetWaitStatusMessage(Strings.ImportingPowerpointDocument);

                            rtDocument = PPTConversion.PPT2RTDocument(fileName);

                            // Autosave the PPT document a RTD document in the same directory as PPT
                            string outFileName = fileName.Substring(0, 
                                fileName.Length - extension.Length) + ".rtd";

                            FileStream fs = new FileStream(outFileName, FileMode.Create);
                            BinaryFormatter bf = new BinaryFormatter();
                            bf.Serialize(fs, rtDocument);
                            fs.Close();

                            statusBar.SetReadyStatusMessage();
                        }
                        #endregion
                    }
                    else if (extension == ".rtd")
                    {
                        #region Open a RTD file
                        lock(this)
                        {
                            BinaryFormatter myBinaryFormat = new BinaryFormatter();
                            try 
                            {
                                FileStream myInputStream = System.IO.File.OpenRead(fileName);
                                rtDocument = (RTDocument) myBinaryFormat.Deserialize(myInputStream);
                            }
                            catch (Exception)
                            {
                                RtlAwareMessageBox.Show(this, string.Format(CultureInfo.CurrentCulture, 
                                    Strings.ErrorInOpeningVersion, fileName), string.Empty, MessageBoxButtons.OK, 
                                    MessageBoxIcon.None, MessageBoxDefaultButton.Button1, (MessageBoxOptions)0);
                                return;
                            }
                        }
                        #endregion
                    } 
                    else
                    {
                        RtlAwareMessageBox.Show(this, string.Format(CultureInfo.CurrentCulture, 
                            Strings.ErrorInOpeningFileType, fileName), string.Empty, MessageBoxButtons.OK, 
                            MessageBoxIcon.None, MessageBoxDefaultButton.Button1, (MessageBoxOptions)0);
                        return;
                    }

                    Log(string.Format(CultureInfo.CurrentCulture, "rtDocID = {0}", rtDocument.Identifier.ToString()));

                    // Update the title bar of the form 
                    // with the document name followed by the capability name
                    this.Text = rtDocument.Metadata.Title + " - " + this.presentationCapability.Name;

                    // Clean up the screen
                    DeleteAllStrokes();

                    Log("On open doc: info before creating RTDocHelper,");
                    DisplayRTDocumentOnlyStructureInfo();
                    rtDocumentHelper = new RTDocumentHelper(this.presentationCapability, rtDocument);

                    Log("Structure Info on open after creating RTDocHelper,");
                    DisplayRTDocumentStructureInfo();

                    #region Populate thumbnails
                    ArrayList thumbnails = new ArrayList();

                    using (Bitmap bp = new Bitmap( thumbnailsView.ImageSize.Width, thumbnailsView.ImageSize.Height, 
                               System.Drawing.Imaging.PixelFormat.Format24bppRgb))
                    {
                        using (Graphics g = Graphics.FromImage(bp))
                        {
                            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;

                            foreach( TOCNode tn in rtDocument.Organization.TableOfContents )
                            {
                                Page p = (Page)tn.Resource;

                                ThumbnailListView.CreateSlideThumbnail( thumbnailsView.ImageSize,
                                    p.Image, g, tn.Title );

                                ThumbnailListViewItem item = new ThumbnailListViewItem();
                                item.thumbnail = ((Bitmap)bp.Clone());
                                item.tag = tn.Identifier;
                                thumbnails.Add(item);
                            }
                        }
                    }

                    thumbnailsView.Items = (ThumbnailListViewItem[])thumbnails.ToArray(typeof(ThumbnailListViewItem));
                    #endregion

                    // Initialize the index on the first slide
                    index = 0;

                    // Show the current page
                    statusBar.SetMaxPage( 1, rtDocument.Organization.TableOfContents.Count );
                    ShowPage(rtDocument.Organization.TableOfContents[index].Identifier);

                    if( presentationCapability.IsSender )
                    {
                        EnableSlideSend(false);
                        statusBar.StatusMessage = Strings.SendingSlides;

                        rtDocumentHelper.BeginSendAllSlides(new AsyncCallback(SlidesSent), null);
                    }

                    // Update the Backward/Forward buttons (push the navigation button in the 
                    // direction(s)that you cannot move anymore)
                    UpdateNavigationButtonState();
                }
            }
            catch(Exception ex) 
            {
                RtlAwareMessageBox.Show(this, string.Format(CultureInfo.CurrentCulture, Strings.ErrorInOpening, 
                    cdlg.FileName, ex.Message.ToString()), string.Empty, MessageBoxButtons.OK, MessageBoxIcon.None, 
                    MessageBoxDefaultButton.Button1, (MessageBoxOptions)0);
                return;
            }
        }