Beispiel #1
0
        private void clipEntryListBox_DrawItem(object sender, DrawItemEventArgs e)
        {
            e.DrawBackground();

            if ((clipEntryListBox.Items.Count > 0) && (e.Index < clipEntryListBox.Items.Count))
            {
                ClipEntry item = (ClipEntry)clipEntryListBox.Items[e.Index];

                Color textColor  = System.Drawing.SystemColors.ControlText;
                Font  headerFont = new Font(this.Font, FontStyle.Bold);

                if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
                {
                    using (Pen p = new Pen(Color.Black, -1)) {
                        e.Graphics.DrawRectangle(p, e.Bounds.X, e.Bounds.Y, e.Bounds.Width - 30, e.Bounds.Height - 1);
                        e.Graphics.DrawRectangle(p, e.Bounds.Width - 28, e.Bounds.Y, 27, e.Bounds.Height - 1);
                    }

                    textColor = SystemColors.HighlightText;
                }

                if (!IconList.Images.Empty)
                {
                    IconList.Draw(e.Graphics, e.Bounds.Left + 1, (e.Bounds.Top + e.Bounds.Height / 6), (int)item.MessageType);
                }

                using (SolidBrush textBrush = new SolidBrush(textColor)) {
                    StringFormat strFormat = new StringFormat();
                    strFormat.Trimming = StringTrimming.EllipsisCharacter;

                    string textMessage = item.MessageText.Replace("\n", " ").Replace("\t", " ").Replace("  ", "");;

                    int textHeaderHeight  = e.Graphics.MeasureString(item.MessageHeader, headerFont).ToSize().Height;
                    int textMessageHeight = e.Graphics.MeasureString(textMessage, this.Font).ToSize().Height;

                    int textIndexHeight = e.Graphics.MeasureString((e.Index + 1).ToString(), headerFont).ToSize().Height;
                    int textIndexWidth  = e.Graphics.MeasureString((e.Index + 1).ToString(), headerFont).ToSize().Width;

                    Rectangle textHeaderRect = new Rectangle(e.Bounds.Left + IconList.ImageSize.Width + 7,
                                                             e.Bounds.Top + e.Bounds.Height / 6,
                                                             e.Bounds.Width - e.Bounds.Left - IconList.ImageSize.Width - 37,
                                                             textHeaderHeight);

                    Rectangle textMessageRect = new Rectangle(e.Bounds.Left + IconList.ImageSize.Width + 15,
                                                              textHeaderRect.Y + textHeaderRect.Height + 5,
                                                              e.Bounds.Width - e.Bounds.Left - IconList.ImageSize.Width - 45,
                                                              textMessageHeight);

                    Rectangle textIndex = new Rectangle(e.Bounds.Width - (textIndexWidth / 2) - 15,
                                                        e.Bounds.Top + (e.Bounds.Height - textIndexHeight) / 2,
                                                        15 + (textIndexWidth / 2), textIndexHeight);

                    e.Graphics.DrawString(item.MessageHeader, headerFont, textBrush, textHeaderRect, strFormat);
                    e.Graphics.DrawString(textMessage, this.Font, textBrush, textMessageRect, strFormat);
                    e.Graphics.DrawString((e.Index + 1).ToString(), headerFont, textBrush, textIndex);

                    strFormat.Dispose();
                }
            }
        }
Beispiel #2
0
        private void sendToPluginsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foreach (int i in clipEntryListBox.SelectedIndices)
            {
                ClipEntry clip = (ClipEntry)clipEntryListBox.Items[i];

                SendToPluginsAsFormat(clip.PluginData, clip.PrincipalFormat);
            }
        }
Beispiel #3
0
        private void clipPropertyToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (clipEntryListBox.SelectedItem != null)
            {
                ClipEntry    clip         = (ClipEntry)clipEntryListBox.SelectedItem;
                ItemProperty propertyForm = new ItemProperty(clip);

                propertyForm.Show();
            }
        }
Beispiel #4
0
        private void sendToClipboardToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try {
                if (clipEntryListBox.SelectedItems.Count == 1)
                {
                    clipEntryListBox.BeginUpdate();

                    ClipEntry clip = (ClipEntry)clipEntryListBox.SelectedItem;
                    clipEntryListBox.Items.RemoveAt(clipEntryListBox.SelectedIndex);

                    if (clip.MessageType == ClipEntryType.Special)
                    {
                        DataObject pasteObj = new DataObject();

                        foreach (string format in clip.Formats)
                        {
                            pasteObj.SetData(format, ((DataObject)clip.FormattedData).GetData(format));
                        }

                        Clipboard.SetDataObject(pasteObj);
                    }
                    else
                    {
                        Clipboard.SetDataObject(clip.FormattedData);
                    }

                    clipEntryListBox.EndUpdate();
                }
                else if (clipEntryListBox.SelectedItems.Count > 1)
                {
                    MessageBox.Show("Only one element can be copied to clipboard", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (ExternalException ee) {
                MessageBox.Show(ee.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (System.Threading.ThreadStateException tse) {
                MessageBox.Show(tse.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (ArgumentNullException) {
                MessageBox.Show("Error in sending the data to clipboard", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Beispiel #5
0
        private void editImageToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if ((clipEntryListBox.SelectedItem != null) && (!editFormOpen))
            {
                editingClip = (ClipEntry)clipEntryListBox.SelectedItem;

                if (editingClip.PrincipalFormat == DataFormats.Bitmap)
                {
                    EditForm editForm = new EditForm((Bitmap)editingClip.PluginData);

                    editForm.Show();
                    editFormOpen = true;

                    editForm.ImageSaved += new EditForm.SaveEventHandler(editForm_ImageSaved);
                    editForm.FormClosed += delegate {
                        editFormOpen = false;
                    };
                }
            }
        }
        public ItemProperty(ClipEntry clip)
        {
            InitializeComponent();

            clipTypePictureBox.Image = IconList.Images[(int)clip.MessageType];
            clipTypeLabel.Text       = clip.MessageHeader;

            switch (clip.MessageType)
            {
            case ClipEntryType.Rtf:
                htmlTableLayoutPanel.Visible  = false;
                imageTableLayoutPanel.Visible = false;
                filesTableLayoutPanel.Visible = false;

                rtfTextTableLayoutPanel.Visible = true;

                clipTextRichTextBox.Rtf = (string)clip.PluginData;
                textLengthLabel.Text    = "Length: " + clipTextRichTextBox.TextLength + " chars\nText's lines: " +
                                          clipTextRichTextBox.Lines.Length;

                break;

            case ClipEntryType.Text:
                htmlTableLayoutPanel.Visible  = false;
                imageTableLayoutPanel.Visible = false;
                filesTableLayoutPanel.Visible = false;

                rtfTextTableLayoutPanel.Visible = true;

                clipTextRichTextBox.Text = (string)clip.PluginData;
                textLengthLabel.Text     = "Length: " + clipTextRichTextBox.TextLength + " chars\nText's lines: " +
                                           clipTextRichTextBox.Lines.Length;

                break;

            case ClipEntryType.Html:
                imageTableLayoutPanel.Visible   = false;
                filesTableLayoutPanel.Visible   = false;
                rtfTextTableLayoutPanel.Visible = false;

                htmlTableLayoutPanel.Visible = true;

                string documentText = (string)clip.PluginData;

                int startHtml     = documentText.IndexOf("StartHTML:") + 10;
                int endHtml       = documentText.IndexOf("\r\nEndHTML:");
                int startFragment = documentText.IndexOf("\r\nStartFragment:");

                int start = int.Parse(documentText.Substring(startHtml, endHtml - startHtml));
                int end   = int.Parse(documentText.Substring(endHtml + 12, startFragment - endHtml - 12));

                webBrowser.DocumentText = documentText.Substring(start, end - start).Replace("?", "&nbsp");
                htmlPropertyLabel.Text  = "Length: " + clip.SecondaryPluginData.ToString().Length +
                                          "\nEncoding: " + webBrowser.Document.Encoding;

                break;

            case ClipEntryType.Bitmap:
                htmlTableLayoutPanel.Visible    = false;
                rtfTextTableLayoutPanel.Visible = false;
                filesTableLayoutPanel.Visible   = false;

                imageTableLayoutPanel.Visible = true;

                Image img = (Image)clip.PluginData;

                clipImagePictureBox.BackgroundImage = img;
                clipImagePropertyLabel.Text         = "Size: " + img.Width + "x" + img.Height +
                                                      "\nColor Depth: " + Image.GetPixelFormatSize(img.PixelFormat).ToString();

                if ((clipImagePictureBox.Width > clipImagePictureBox.BackgroundImage.Width) &&
                    (clipImagePictureBox.Height > clipImagePictureBox.BackgroundImage.Height))
                {
                    clipImagePictureBox.BackgroundImageLayout = ImageLayout.Center;
                }
                else
                {
                    clipImagePictureBox.BackgroundImageLayout = ImageLayout.Zoom;
                }

                break;

            case ClipEntryType.FileDrop:
                htmlTableLayoutPanel.Visible    = false;
                rtfTextTableLayoutPanel.Visible = false;
                imageTableLayoutPanel.Visible   = false;

                filesTableLayoutPanel.Visible = true;

                smallImageList.Images.Add(FileReader.GetFolderIcon(FileReader.IconSize.Small, FileReader.FolderType.Closed));
                largeImageList.Images.Add(FileReader.GetFolderIcon(FileReader.IconSize.Large, FileReader.FolderType.Closed));

                FileListManager fileListManager = new FileListManager(smallImageList, largeImageList);

                ArrayList dirs  = new ArrayList();
                ArrayList files = new ArrayList();

                string[] paths = (string[])clip.PluginData;

                foreach (string path in paths)
                {
                    if (Directory.Exists(path))
                    {
                        dirs.Add(path);
                    }
                    else if (File.Exists(path))
                    {
                        files.Add(path);
                    }
                }

                dirs.Sort();
                files.Sort();

                foreach (string dir in dirs)
                {
                    int relativePath = Directory.GetParent(dir).FullName.Length;

                    clipFileListView.Items.Add(new ListViewItem(new string[] { dir.Substring(relativePath + 1), "", "Folder",
                                                                               Directory.GetLastAccessTime(dir).ToString("g"),
                                                                               Directory.GetLastWriteTime(dir).ToString("g") }, 0));
                }

                foreach (string file in files)
                {
                    string relativeFile = Path.GetFileName(file);

                    FileInfo fileInfo = new FileInfo(file);

                    string fileLastAccess      = fileInfo.LastAccessTime.ToString("g");
                    string fileLastWrite       = fileInfo.LastWriteTime.ToString("g");
                    string fileDimension       = (fileInfo.Length / 1024).ToString();
                    string fileDimensionDotted = "";
                    int    dot = 0;

                    for (int i = fileDimension.Length - 3; i > 0; i = i - 3)
                    {
                        fileDimensionDotted = "." + fileDimension.Substring(i, 3) + fileDimensionDotted;
                        dot++;
                    }

                    fileDimensionDotted = fileDimension.Substring(0, fileDimension.Length - (dot * 3)) + fileDimensionDotted + " KB";

                    clipFileListView.Items.Add(new ListViewItem(new string[] { relativeFile, fileDimensionDotted,
                                                                               fileListManager.AddFileType(file), fileLastAccess,
                                                                               fileLastWrite }, fileListManager.AddFileIcon(file)));
                }

                clipFilesPropertyLabel.Text = "# Directory: " + dirs.Count + "\n# Files: " + files.Count;

                break;
            }
        }
Beispiel #7
0
        private void clipEntryListBox_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Middle)
            {
                if (clipEntryListBox.SelectedIndex > -1)
                {
                    ClipEntry clip = (ClipEntry)clipEntryListBox.Items[clipEntryListBox.SelectedIndex];

                    string formats = "";
                    foreach (string format in clip.Formats)
                    {
                        formats += format + "\n";
                    }

                    if (formats.LastIndexOf("\n") != -1)
                    {
                        formats = formats.Remove(formats.Length - 1);
                    }

                    toolTip.ToolTipTitle = "Formats of this Clip: " + clip.FormatNumber.ToString();
                    toolTip.SetToolTip(clipEntryListBox, formats);
                }
            }
            else if (e.Button == MouseButtons.Right)
            {
                int indexPointed = clipEntryListBox.IndexFromPoint(PointToClient(Control.MousePosition));

                if ((indexPointed > -1) && (clipEntryListBox.Items.Count > 0))
                {
                    ClipEntry clip = (ClipEntry)clipEntryListBox.Items[indexPointed];

                    sendToClipboardAsToolStripMenuItem.Enabled = false;
                    sendToPluginsAsToolStripMenuItem.Enabled   = false;

                    if ((clip.PrincipalFormat == DataFormats.Rtf) || (clip.PrincipalFormat == DataFormats.Html))
                    {
                        sendToClipboardAsToolStripMenuItem.Enabled = true;

                        if (plugins.LoadedPlugins.Count > 0)
                        {
                            sendToPluginsAsToolStripMenuItem.Enabled = true;
                        }
                    }

                    if (clip.PrincipalFormat == DataFormats.Bitmap)
                    {
                        editImageToolStripMenuItem.Enabled = true;
                    }
                    else
                    {
                        editImageToolStripMenuItem.Enabled = false;
                    }

                    if (clip.MessageType == ClipEntryType.Special)
                    {
                        clipPropertyToolStripMenuItem.Enabled = false;
                    }
                    else
                    {
                        clipPropertyToolStripMenuItem.Enabled = true;
                    }

                    clipListContextMenuStrip.Show(clipEntryListBox, PointToClient(Control.MousePosition));
                }
            }
        }
Beispiel #8
0
        private void ManageClipboardData()
        {
            try {
                lock (thisObject) {
                    IDataObject iData = Clipboard.GetDataObject();

                    if (iData.GetDataPresent(DataFormats.Html))
                    {
                        ClipEntry clip = new ClipEntry(ClipEntryType.Html, "HTML",
                                                       "Text Length: " + iData.GetData(DataFormats.Text).ToString().Length.ToString()
                                                       + " chars", iData.GetFormats(), iData, iData.GetData(DataFormats.Html),
                                                       DataFormats.Html, iData.GetData(DataFormats.Text));

                        bool entryPresent = false;
                        int  entryIndex   = -1;

                        foreach (object entry in clipEntryListBox.Items)
                        {
                            if ((((ClipEntry)entry).MessageText.Equals(clip.MessageText)) && (((ClipEntry)entry).MessageType.Equals(clip.MessageType)))
                            {
                                entryPresent = true;
                                entryIndex   = clipEntryListBox.Items.IndexOf(entry);
                            }
                        }

                        if (!entryPresent)
                        {
                            clipEntryListBox.Items.Insert(0, clip);
                        }
                        else
                        {
                            clipEntryListBox.Items.RemoveAt(entryIndex);
                            clipEntryListBox.Items.Insert(0, clip);
                        }
                    }
                    else if (iData.GetDataPresent(DataFormats.Rtf))
                    {
                        ClipEntry clip = new ClipEntry(ClipEntryType.Rtf, "Rich Text Format",
                                                       "Text Length: " + iData.GetData(DataFormats.Text).ToString().Length.ToString()
                                                       + " chars", iData.GetFormats(), iData, iData.GetData(DataFormats.Rtf),
                                                       DataFormats.Rtf, iData.GetData(DataFormats.Text));

                        bool entryPresent = false;
                        int  entryIndex   = -1;

                        foreach (object entry in clipEntryListBox.Items)
                        {
                            if ((((ClipEntry)entry).MessageText.Equals(clip.MessageText)) && (((ClipEntry)entry).MessageType.Equals(clip.MessageType)))
                            {
                                entryPresent = true;
                                entryIndex   = clipEntryListBox.Items.IndexOf(entry);
                            }
                        }

                        if (!entryPresent)
                        {
                            clipEntryListBox.Items.Insert(0, clip);
                        }
                        else
                        {
                            clipEntryListBox.Items.RemoveAt(entryIndex);
                            clipEntryListBox.Items.Insert(0, clip);
                        }
                    }
                    else if (iData.GetDataPresent(DataFormats.Text))
                    {
                        ClipEntry clip = new ClipEntry(ClipEntryType.Text, "Text", iData.GetData(DataFormats.Text).ToString(), iData.GetFormats(),
                                                       iData.GetData(DataFormats.Text), iData.GetData(DataFormats.Text), DataFormats.Text, null);

                        bool entryPresent = false;
                        int  entryIndex   = -1;

                        foreach (object entry in clipEntryListBox.Items)
                        {
                            if ((((ClipEntry)entry).MessageText.Equals(clip.MessageText)) && (((ClipEntry)entry).MessageType.Equals(clip.MessageType)))
                            {
                                entryPresent = true;
                                entryIndex   = clipEntryListBox.Items.IndexOf(entry);
                            }
                        }

                        if (!entryPresent)
                        {
                            clipEntryListBox.Items.Insert(0, clip);
                        }
                        else
                        {
                            clipEntryListBox.Items.RemoveAt(entryIndex);
                            clipEntryListBox.Items.Insert(0, clip);
                        }
                    }
                    else if (iData.GetDataPresent(DataFormats.FileDrop))
                    {
                        string[] files = (string[])iData.GetData(DataFormats.FileDrop);

                        ClipEntry clip = new ClipEntry(ClipEntryType.FileDrop, "Files", "Quantity: " + files.Length, iData.GetFormats(), iData,
                                                       iData.GetData(DataFormats.FileDrop), DataFormats.FileDrop, null);

                        bool entryPresent = false;
                        int  entryIndex   = -1;

                        foreach (object entry in clipEntryListBox.Items)
                        {
                            ClipEntry clipToCheck = (ClipEntry)entry;

                            if (clipToCheck.PrincipalFormat == DataFormats.FileDrop)
                            {
                                if (((string[])clipToCheck.PluginData).Length == files.Length)
                                {
                                    for (int i = 0; i < files.Length; i++)
                                    {
                                        entryPresent = true;

                                        if (((string[])clipToCheck.PluginData)[i] != files[i])
                                        {
                                            entryPresent = false;
                                            break;
                                        }
                                    }

                                    if (entryPresent)
                                    {
                                        entryIndex = clipEntryListBox.Items.IndexOf(entry);
                                    }
                                }
                            }
                        }

                        if (!entryPresent)
                        {
                            clipEntryListBox.Items.Insert(0, clip);
                        }
                        else
                        {
                            clipEntryListBox.Items.RemoveAt(entryIndex);
                            clipEntryListBox.Items.Insert(0, clip);
                        }
                    }
                    else if (iData.GetDataPresent(DataFormats.Bitmap))
                    {
                        Bitmap bmp         = (Bitmap)iData.GetData(DataFormats.Bitmap);
                        string messageText = "Size: " + bmp.Width + "x" + bmp.Height + " - Color Depth: " + Image.GetPixelFormatSize(bmp.PixelFormat).ToString();

                        ClipEntry clip = new ClipEntry(ClipEntryType.Bitmap, "Image", messageText, iData.GetFormats(), bmp,
                                                       iData.GetData(DataFormats.Bitmap), DataFormats.Bitmap, null);

                        clipEntryListBox.Items.Insert(0, clip);
                    }
                    else
                    {
                        if (iData.GetFormats().Length > 0)
                        {
                            clipEntryListBox.Items.Insert(0, new ClipEntry(ClipEntryType.Special, "Special", "Special Data",
                                                                           iData.GetFormats(), iData, null, null, null));
                        }
                    }
                }
            }
            catch (ExternalException ee) {
                MessageBox.Show(ee.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (System.Threading.ThreadStateException tse) {
                MessageBox.Show(tse.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (ArgumentException) {
                MessageBox.Show("Error in retrieving the data from the clipboard", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (NullReferenceException) {
                MessageBox.Show("Error in retrieving the data from the clipboard", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }