Exemple #1
0
        private void adxieContextMenuCommandItem1_OnClick(object sender, object eventObject)
        {
            Type t = typeof(DownloadManager);
            int index = this.Bars.IndexOf(t.FullName);
            if (index >= 0)
            {
                AddinExpress.IE.ADXIEBarItem item = this.Bars[index];
                if (item.BarObj == null)
                {
                    object g = t.GUID.ToString("B");
                    object bShow = true;
                    object dummy = null;
                    IEApp.ShowBrowserBar(ref g, ref bShow, ref dummy);
                }
                else
                {
                    DownloadManager dm =
                        item.BarObj as DownloadManager;
                    if (dm != null)
                    {
                        if (!dm.Visible)
                        {
                            object g = t.GUID.ToString("B");
                            object bShow = true;
                            object dummy = null;
                            IEApp.ShowBrowserBar(ref g, ref bShow, ref dummy);
                        }
                    }
                }

                if (item.BarObj is DownloadManager)
                {
                    DownloadManager dm =
                        item.BarObj as DownloadManager;
                    if (dm.Visible)
                    {
                        if (dm.Links.Enabled)
                        {
                            if (eventObject is mshtml.IHTMLSelectionObject)
                            {
                                mshtml.IHTMLSelectionObject selection =
                                    eventObject as mshtml.IHTMLSelectionObject;

                                mshtml.IHTMLTxtRange textRange = selection.createRange() as mshtml.IHTMLTxtRange;
                                if (textRange != null &&
                                    ((!String.IsNullOrEmpty(textRange.text)) && (!String.IsNullOrEmpty(textRange.htmlText))))
                                {
                                    bool linksFound = false;
                                    string text = textRange.text;
                                    string htmlText = textRange.htmlText;

                                    mshtml.HTMLDocument doc =
                                        new mshtml.HTMLDocument();
                                    doc.open("text/html", "replace", null, null);
                                    doc.GetType().InvokeMember(
                                        "write", BindingFlags.InvokeMethod, null, doc, new object[] { htmlText });

                                    if (doc.images.length > 0)
                                    {
                                        object attr;
                                        string src = String.Empty;

                                        foreach (mshtml.IHTMLElement element in doc.images)
                                        {
                                            src = String.Empty;
                                            attr = element.getAttribute("src", 0);

                                            if (attr is String)
                                                src = (string)attr;
                                            if (String.IsNullOrEmpty(src))
                                                src = (string)element.getAttribute("href", 0);
                                            if (!String.IsNullOrEmpty(src))
                                            {
                                                if (src.StartsWith("http:"))
                                                {
                                                    string file = String.Empty;
                                                    try
                                                    {
                                                        file = Path.GetFileName(src);
                                                    }
                                                    catch
                                                    {
                                                    }
                                                    if (!String.IsNullOrEmpty(file))
                                                    {
                                                        linksFound = true;
                                                        dm.AddItem(file, src);
                                                    }
                                                }
                                            }
                                        }
                                    }

                                    if (doc.links.length > 0)
                                    {
                                        string src = String.Empty;

                                        foreach (mshtml.IHTMLAnchorElement element in doc.links)
                                        {
                                            src = element.href;
                                            if (!String.IsNullOrEmpty(src))
                                            {
                                                if (src.StartsWith("http:"))
                                                {
                                                    string file = String.Empty;
                                                    try
                                                    {
                                                        file = Path.GetFileName(src);
                                                    }
                                                    catch
                                                    {
                                                    }
                                                    if (!String.IsNullOrEmpty(file))
                                                    {
                                                        linksFound = true;
                                                        dm.AddItem(file, src);
                                                    }
                                                }
                                            }
                                        }
                                    }

                                    if (!linksFound)
                                        MessageBox.Show(this, "There are not valid links in the selection.", "Download Manager Example", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                }
                            }
                            else
                            {
                                string src = String.Empty;

                                if (eventObject is mshtml.IHTMLAnchorElement)
                                {
                                    mshtml.IHTMLAnchorElement element =
                                        eventObject as mshtml.IHTMLAnchorElement;
                                    src = element.href;
                                }
                                else if (eventObject is mshtml.IHTMLImgElement)
                                {
                                    mshtml.IHTMLImgElement element =
                                        eventObject as mshtml.IHTMLImgElement;
                                    src = element.href;
                                }

                                if (!String.IsNullOrEmpty(src))
                                {
                                    if (src.StartsWith("http:"))
                                    {
                                        string file = String.Empty;
                                        try
                                        {
                                            file = Path.GetFileName(src);
                                        }
                                        catch
                                        {
                                        }

                                        if (!String.IsNullOrEmpty(file))
                                        {
                                            dm.AddItem(file, src);
                                            return;
                                        }
                                    }

                                    MessageBox.Show(this, "The link is not valid.", "Download Manager Example", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                }
                            }
                        }
                    }
                }
            }
        }
Exemple #2
0
            private mshtml.HTMLDocument CreateHTMLDoc(string htmlText)
            {
                mshtml.HTMLDocument cloneDoc = null;

                cloneDoc = new mshtml.HTMLDocument();
                cloneDoc.open("text/html", "replace", null, null);
                cloneDoc.GetType().InvokeMember(
                    "write", BindingFlags.InvokeMethod, null, cloneDoc, new object[] { htmlText });

                return cloneDoc;
            }
Exemple #3
0
        private void Links_DragDrop(object sender, DragEventArgs e)
        {
            string html;
            bool linksFound = false;
            int startHtml = -1, endHtml = -1;

            IDataObject data = e.Data;
            if (data.GetDataPresent("HTML Format"))
            {
                html = (string)data.GetData("HTML Format");

                int index = html.IndexOf("StartHTML:");
                if (index > 0)
                {
                    startHtml = Convert.ToInt32(html.Substring(index + 10, 9));

                    index = html.IndexOf("EndHTML:");
                    if (index > 0)
                    {
                        endHtml = Convert.ToInt32(html.Substring(index + 8, 9));
                    }
                }

                if (startHtml != -1 && endHtml != -1)
                {
                    html = html.Substring(startHtml, endHtml - startHtml);
                    index = html.IndexOf("<HTML>");
                    if (index > 0)
                    {
                        html = html.Remove(0, index);
                        startHtml = html.IndexOf("<HEAD>");
                        if (startHtml > 0)
                        {
                            endHtml = html.IndexOf("</HEAD>");
                            if (endHtml > 0)
                            {
                                html = html.Remove(startHtml, (endHtml - startHtml) + 7);
                            }
                        }
                    }

                    mshtml.HTMLDocument doc =
                        new mshtml.HTMLDocument();
                    doc.open("text/html", "replace", null, null);
                    doc.GetType().InvokeMember(
                        "write", BindingFlags.InvokeMethod, null, doc, new object[] { html } );

                    if (doc.images.length > 0)
                    {
                        object attr;
                        string src = String.Empty;

                        foreach (mshtml.IHTMLElement element in doc.images)
                        {
                            src = String.Empty;
                            attr = element.getAttribute("src", 0);

                            if (attr is String)
                                src = (string)attr;
                            if (String.IsNullOrEmpty(src))
                                src = (string)element.getAttribute("href", 0);
                            if (!String.IsNullOrEmpty(src))
                            {
                                if (src.StartsWith("http:"))
                                {
                                    string file = String.Empty;
                                    try
                                    {
                                        file = Path.GetFileName(src);
                                    }
                                    catch
                                    {
                                    }
                                    if (!String.IsNullOrEmpty(file))
                                    {
                                        linksFound = true;
                                        AddItem(file, src);
                                    }
                                }
                            }
                        }
                    }

                    if (doc.links.length > 0)
                    {
                        string src = String.Empty;

                        foreach (mshtml.IHTMLAnchorElement element in doc.links)
                        {
                            src = element.href;
                            if (!String.IsNullOrEmpty(src))
                            {
                                if (src.StartsWith("http:"))
                                {
                                    string file = String.Empty;
                                    try
                                    {
                                        file = Path.GetFileName(src);
                                    }
                                    catch
                                    {
                                    }
                                    if (!String.IsNullOrEmpty(file))
                                    {
                                        linksFound = true;
                                        AddItem(file, src);
                                    }
                                }
                            }
                        }
                    }

                    if (!linksFound)
                        MessageBox.Show(this, "There are not valid links in the selection.", "Download Manager Example", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
        }