Exemplo n.º 1
0
        protected override void DoDragDrop(IHTMLEventObj pIEventObj)
        {
            IHTMLElement element = pIEventObj.srcElement;

            // Make sure the element is an image.
            IHTMLImgElement imgElement = element as IHTMLImgElement;

            if (imgElement == null)
            {
                return;
            }

            // We'll need to uniquely identify this image when its inserted at a new spot.
            string oldElementId = element.id;

            element.id = Guid.NewGuid().ToString();

            IDataObject dataObject = SmartContentDataObject.CreateFrom(element, EditorContext.EditorId);

            // do the drag and drop
            using (new Undo(EditorContext))
            {
                EditorContext.DoDragDrop(dataObject, DragDropEffects.Move);
            }

            // Revert back to the old id after drag/drop is done.
            element.id = oldElementId;
        }
Exemplo n.º 2
0
        // If onmouseup is canceled and onclick is not we'll fall back on OnCanceledClick case.
        private void OnHtmlMouseUp(object sender, EventArgs e)
        {
            // Reset any previous mouse up package.
            this.recLastMouseUpPackage = null;

            // On www.xero.com the source element we get on click event is messed up I don't know why.
            // Just keep the source recorder package we correctly get on mouseup event and use it with onclick event.
            if (this.IsRecording && (this.ClickAction != null))
            {
                HtmlHandler  htmlHandler = (HtmlHandler)sender;
                IHTMLElement htmlSource  = [email protected];

                if (!IsValidForClickRec(htmlSource))
                {
                    return;
                }

                // For non <img> elements take a parent anchor. Example: a <b> inside an <a>. Skip anchor with names (page bookmarks).
                IHTMLImgElement imgElem = htmlSource as IHTMLImgElement;
                if (imgElem == null)
                {
                    IElement sourceElement = this.twebstCore.AttachToNativeElement(htmlSource);
                    IElement parentAnchor  = sourceElement.FindParentElement("a", "name="); // A parent anchor without a name.

                    if (parentAnchor != null)
                    {
                        htmlSource = parentAnchor.nativeElement;
                    }
                }

                this.recLastMouseUpPackage = RecEventArgs.CreateRecEvent(htmlSource, twebstBrowser);
            }
        }
        /// <summary>
        /// 获取验证码
        /// </summary>
        /// <param name="wbMail"></param>
        /// <param name="Src"></param>
        /// <param name="Alt"></param>
        /// <returns></returns>
        public static int GetPicIndex(WebBrowser wbMail, string Src, string Alt)
        {
            int imgnum = -1;

            for (int i = 0; i < wbMail.Document.Images.Count; i++)
            {
                                                                   //获取所有的Image元素
                {
                    IHTMLImgElement img = (IHTMLImgElement)wbMail.Document.Images[i].DomElement;

                    if (Alt == "")
                    {
                        if (img.src.Contains(Src))
                        {
                            return(i);
                        }
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(img.alt))
                        {
                            if (img.alt.Contains(Alt))
                            {
                                return(i);
                            }
                        }
                    }
                }
            }
            return(imgnum);
        }
        /// <summary>
        /// Forces a reload of the image's properties. This is useful for refreshing the form when the image
        /// properties have been changed externally.
        /// </summary>
        public void RefreshImage()
        {
            // update selected image (null if none is selected)
            _selectedImage = _editorContext.SelectedImage;

            // update display
            EditContextActivated = SelectionIsImage;
        }
Exemplo n.º 5
0
		private static void Transform( IHTMLImgElement img )
		{
			if ( img.src != null )
			{
				// replace the local link to the sf logo to the online version tied to our project counter
				if ( img.src.IndexOf( "sf.gif" ) > -1 )
					img.src = "http://sourceforge.net/sflogo.php?group_id=36057&amp;type=5";
				else
					img.src = TransformLocalLink( img.src );
			}
		}
        /// <summary>
        /// Forces a reload of the image's properties. This is useful for refreshing the form when the image
        /// properties have been changed externally.
        /// </summary>
        private void RefreshImage()
        {
            // update selected image (null if none is selected)
            _selectedImage = _editorContext.SelectedImage;

            // refresh the view
            if (SelectionIsImage)
            {
                ImagePropertyHandler.RefreshView();
            }
        }
Exemplo n.º 7
0
        public static Image CopyImageAlt(WebBrowser webBrowser, HtmlElement elem)
        {
            IHTMLImgElement         img    = (IHTMLImgElement)elem.DomElement;
            IHTMLElementRenderFixed render = (IHTMLElementRenderFixed)img;

            Bitmap   bmp = new Bitmap(elem.OffsetRectangle.Width, elem.OffsetRectangle.Height);
            Graphics g   = Graphics.FromImage(bmp);
            IntPtr   hdc = g.GetHdc();

            render.DrawToDC(hdc);
            g.ReleaseHdc(hdc);
            return(bmp);
        }
Exemplo n.º 8
0
        /// <summary>
        /// 使用该方法获取图片时,可能无法获取到图片的原始尺寸,只能获取其在网页中所显示的尺寸,因此可能会被缩小或放大过了。
        /// </summary>
        /// <param name="imgTag">img元素</param>
        /// <returns>图片</returns>
        public static Bitmap 通过区域截屏技术获取图片(this HtmlElement imgTag)
        {
            IHTMLImgElement         img    = (IHTMLImgElement)imgTag.DomElement;
            IHTMLElementRenderFixed render = (IHTMLElementRenderFixed)img;

            Bitmap   bmp = new Bitmap(imgTag.OffsetRectangle.Width, imgTag.OffsetRectangle.Height);
            Graphics g   = Graphics.FromImage(bmp);
            IntPtr   hdc = g.GetHdc();

            render.DrawToDC(hdc);
            g.ReleaseHdc(hdc);

            return(bmp);
        }
Exemplo n.º 9
0
        public Bitmap GetImage(string id)
        {
            HtmlElement             e      = webBrowser.Document.GetElementById(id);
            IHTMLImgElement         img    = (IHTMLImgElement)e.DomElement;
            IHTMLElementRenderFixed render = (IHTMLElementRenderFixed)img;

            Bitmap   bmp = new Bitmap(e.OffsetRectangle.Width, e.OffsetRectangle.Height);
            Graphics g   = Graphics.FromImage(bmp);
            IntPtr   hdc = g.GetHdc();

            render.DrawToDC(hdc);
            g.ReleaseHdc(hdc);
            return(bmp);
        }
Exemplo n.º 10
0
        public Bitmap GetImage(IHTMLImgElement img)
        {
            IHTMLElementRenderFixed render = (IHTMLElementRenderFixed)img;

            Bitmap bmp = new Bitmap(img.width, img.height);

            Graphics g   = Graphics.FromImage(bmp);
            IntPtr   hdc = g.GetHdc();

            render.DrawToDC(hdc);
            g.ReleaseHdc(hdc);

            return(bmp);
        }
Exemplo n.º 11
0
        public static bool IsImageElement(SUIHtmlControlBase ctrl)
        {
            bool itis = false;

            try
            {
                IHTMLImgElement span = ctrl.HtmlElement as mshtml.IHTMLImgElement;
                itis = true;
            }
            catch
            {
                itis = false;
            }
            return(itis);
        }
Exemplo n.º 12
0
        public void RefreshView()
        {
            _propertyEditingContext.ImagePropertyChanged -= new ImagePropertyEventHandler(imageProperties_ImagePropertyChanged);

            IHTMLImgElement imgElement = ImgElement as IHTMLImgElement;

            if (imgElement != null)
            {
                _propertyEditingContext.ImagePropertiesInfo = GetImagePropertiesInfo(imgElement, _editorContext);
            }
            else
            {
                _propertyEditingContext.ImagePropertiesInfo = null;
            }

            _propertyEditingContext.ImagePropertyChanged += new ImagePropertyEventHandler(imageProperties_ImagePropertyChanged);
        }
Exemplo n.º 13
0
        // 画像の場所を取得
        private string GetImageSource(HtmlDocument doc)
        {
            HTMLDivElement  d = null;
            IHTMLImgElement i = null;

            var result =
                from elem in doc.GetElementsByTagName("div").OfType <HtmlElement>()
                let div = d = elem.DomElement as HTMLDivElement
                              where div != null && div.className == "photo-detail"
                              let img = i = div.firstChild as IHTMLImgElement
                                            where img != null && img.src.ToLower().EndsWith(".jpg")
                                            select img.src;

            if (d != null)
            {
                Marshal.FinalReleaseComObject(d);
            }
            if (i != null)
            {
                Marshal.FinalReleaseComObject(i);
            }

            return(result.FirstOrDefault());

            //foreach (HtmlElement elem in doc.GetElementsByTagName("div"))
            //{
            //    var div = elem.DomElement as HTMLDivElement;
            //    if (div != null && div.className == "photo-detail")
            //    {
            //        var img = div.firstChild as IHTMLImgElement;
            //        if (img != null && img.src.ToLower().EndsWith("jpg"))
            //        {
            //            string src = img.src;
            //            Marshal.FinalReleaseComObject(img);
            //            Marshal.FinalReleaseComObject(div);
            //            return src;
            //        }
            //        Marshal.FinalReleaseComObject(div);
            //    }
            //}
            //return string.Empty;
        }
Exemplo n.º 14
0
        /// <summary>
        /// Inserts an image in the document
        /// </summary>
        /// <param name="src">The source of the image (file path or URL)</param>
        /// <param name="id">The ID of the image</param>
        /// <param name="border">The border size</param>
        /// <param name="altText">Alternative text</param>
        /// <param name="width">Width of the image</param>
        /// <param name="height">Height of the image</param>
        public void InsertImage(string src, string id, int border = 0, string altText = null,
                                int width = 0, int height = 0)
        {
            if (src == null)
            {
                throw new ArgumentNullException("You must specify the image source!");
            }
            if (id == null)
            {
                throw new ArgumentNullException("You must specify the image ID!");
            }

            IHTMLTxtRange selection = this.document.selection.createRange() as IHTMLTxtRange;

            selection.pasteHTML("<img src=\"" + src + "\" id=\"" + id + "\" style=\"position:absolute\" />");

            IHTMLImgElement image = GetElementById(id) as IHTMLImgElement;

            if (border != 0)
            {
                (image as IHTMLElement).style.border = border.ToString() + "px solid #000000";
            }
            if (altText != null)
            {
                image.alt = altText;
            }
            if (width != 0)
            {
                (image as IHTMLElement).style.width = width.ToString();
            }
            if (height != 0)
            {
                (image as IHTMLElement).style.height = height.ToString();
            }

            imagePaths.Add(src);
            MakeInsertedElementMovable();
        }
Exemplo n.º 15
0
        private void Timer_Tick(object sender, EventArgs e)
        {
            try
            {
                timer.Enabled = false;
                if (webBrowser.Document != null && (webBrowser.ReadyState == WebBrowserReadyState.Complete || webBrowser.ReadyState == WebBrowserReadyState.Interactive))
                {
                    HtmlElementCollection elements = webBrowser.Document.GetElementsByTagName("img");
                    if (elements != null && elements.Count > 0)
                    {
                        //Monitor.Enter(lockObject);
                        IHTMLImgElement         img    = (IHTMLImgElement)elements[0].DomElement;
                        IHTMLElementRenderFixed render = (IHTMLElementRenderFixed)img;
                        Bitmap   bitmap = new Bitmap(img.width, img.height);
                        Graphics g      = Graphics.FromImage(bitmap);
                        IntPtr   hdc    = g.GetHdc();
                        render.DrawToDC(hdc);
                        g.ReleaseHdc(hdc);

                        using (MemoryStream memoryStream = new MemoryStream())
                        {
                            bitmap.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Jpeg);
                            this.CaptureImage = memoryStream.ToArray();
                        }
                    }
                }
            }
            catch (Exception exc)
            {
                Logger.E(exc);
            }
            finally
            {
                //Monitor.Exit(lockObject);
                webBrowser.Refresh();
                timer.Enabled = true;
            }
        }
Exemplo n.º 16
0
        /// <summary>
        /// Sets the new size of the image (not including the border)
        /// </summary>
        /// <param name="size"></param>
        /// <param name="sizeName"></param>
        public void SetImageSize(Size size, ImageSizeName?sizeName)
        {
            IHTMLImgElement imgElement = (IHTMLImgElement)ImgElement;

            ImageBorderMargin borderMargin = BorderMargin;
            // The next line is a little bit tortured, but
            // I'm trying to introduce the concept of "calculated image size"
            // for more complex border calculations without breaking any
            // existing logic.
            Size sizeWithBorder = ImageSize.Equals(size)
                ? ImageSizeWithBorder : borderMargin.CalculateImageSize(size);

            if (imgElement.width != sizeWithBorder.Width || imgElement.height != sizeWithBorder.Height)
            {
                imgElement.width  = sizeWithBorder.Width;
                imgElement.height = sizeWithBorder.Height;
            }

            //remember the size offsets which are added by CSS margins/padding
            Settings.SetInt(IMAGE_WIDTH_OFFSET, imgElement.width - sizeWithBorder.Width);
            Settings.SetInt(IMAGE_HEIGHT_OFFSET, imgElement.height - sizeWithBorder.Height);

            if (sizeName != null)
            {
                ImageSizeName = sizeName.Value;
            }

            //Initialize the saved aspect ratio if it has no value
            //OR update it if the ratio has been changed
            Size targetSize = TargetAspectRatioSize;

            if (targetSize.Width == -1 ||
                (size.Width != Math.Round((targetSize.Width * (float)size.Height) / targetSize.Height) &&
                 size.Height != Math.Round((targetSize.Height * (float)size.Width) / targetSize.Width)))
            {
                TargetAspectRatioSize = size;
            }
        }
Exemplo n.º 17
0
 public SUIHtmlImage(SUIHtmlDocument _doc, IHTMLElement _element)
     : base(_doc, _element)
 {
     imageElement = (IHTMLImgElement)_element;
 }
Exemplo n.º 18
0
        public Bitmap GetImage(IHTMLImgElement img)
        {
            IHTMLElementRenderFixed render = (IHTMLElementRenderFixed)img;

            Bitmap bmp = new Bitmap(img.width, img.height);

            Graphics g = Graphics.FromImage(bmp);
            IntPtr hdc = g.GetHdc();
            render.DrawToDC(hdc);
            g.ReleaseHdc(hdc);

            return bmp;
        }
        /// <summary>
        /// Forces a reload of the image's properties. This is useful for refreshing the form when the image
        /// properties have been changed externally.
        /// </summary>
        public void RefreshImage()
        {
            // update selected image (null if none is selected)
            _selectedImage = _editorContext.SelectedImage ;

            // update display
            EditContextActivated = SelectionIsImage ;
        }
Exemplo n.º 20
0
 public SUIHtmlImage(SUIHtmlControlBase ctrl)
     : base(ctrl)
 {
     imageElement = (IHTMLImgElement)ctrl.HtmlElement;
 }
        /// <summary>
        /// Forces a reload of the image's properties. This is useful for refreshing the form when the image
        /// properties have been changed externally.
        /// </summary>
        private void RefreshImage()
        {
            // update selected image (null if none is selected)
            _selectedImage = _editorContext.SelectedImage ;

            // refresh the view
            if ( SelectionIsImage )
                ImagePropertyHandler.RefreshView();
        }
        /// <summary>
        /// Loads document information into the Tree
        /// Uses each node.Tag to store information
        /// </summary>
        /// <param name="pWB">An instance of csExWB.cEXWB</param>
        public void LoadDocumentInfo(csExWB.cEXWB pWB)
        {
            treeDocInfo.Nodes.Clear();
            txtDocInfo.Clear();
            IHTMLDocument2 doc2 = null;

            //First fill in the main document information
            TreeNode root = treeDocInfo.Nodes.Add("Main Document");

            TreeNode node    = root.Nodes.Add("HTML");
            TreeNode subnode = node.Nodes.Add("Title");

            subnode.Tag = pWB.GetTitle(true);
            doc2        = (IHTMLDocument2)pWB.WebbrowserObject.Document;
            subnode     = node.Nodes.Add("URL");
            subnode.Tag = doc2.url;
            subnode     = node.Nodes.Add("Domain");
            subnode.Tag = doc2.domain;
            subnode     = node.Nodes.Add("Protocol");
            subnode.Tag = doc2.protocol;
            subnode     = node.Nodes.Add("Cookie");
            subnode.Tag = doc2.cookie;
            subnode     = node.Nodes.Add("Referrer");
            subnode.Tag = doc2.referrer;
            subnode     = node.Nodes.Add("Last Modified");
            subnode.Tag = doc2.lastModified;
            subnode     = node.Nodes.Add("Source");
            subnode.Tag = pWB.GetSource(true);
            subnode     = node.Nodes.Add("Text");
            subnode.Tag = pWB.GetText(true);

            //or pWB.GetImages(true);
            IHTMLElementCollection elems = (IHTMLElementCollection)doc2.images;

            subnode = node.Nodes.Add("Images");
            IHTMLImgElement img = null;
            string          str = string.Empty;

            foreach (IHTMLElement elem in elems)
            {
                if (elem != null)
                {
                    img  = (IHTMLImgElement)elem;
                    str += Environment.NewLine + img.src;
                }
            }
            subnode.Tag = str;

            //
            //Other collections
            //

            //elems = (IHTMLElementCollection)doc2.anchors;
            //subnode = node.Nodes.Add("Links");

            //elems = (IHTMLElementCollection)doc2.scripts;
            //subnode = node.Nodes.Add("Java Scripts");

            //IHTMLMetaElement meta = null;
            //IHTMLElementCollection col = (IHTMLElementCollection)pWB.GetElementsByTagName(true, "meta");
            //foreach (IHTMLElement elem in col)
            //{
            //    meta = (IHTMLMetaElement)elem;
            //    if (meta != null)
            //    {
            //        AllForms.m_frmLog.AppendToLog("\r\nhttpEquiv=" + meta.httpEquiv + "\r\nname=" + meta.name +
            //            "\r\nurl=" + meta.url + "\r\ncharset=" + meta.charset + "\r\ncontent=" + meta.content);
            //    }
            //    meta = null;
            //}

            //If frameset, we add the frames
            if (pWB.IsFrameset())
            {
                TreeNode            framenode = root.Nodes.Add("FRAMES");
                List <IWebBrowser2> frames    = pWB.GetFrames();
                foreach (IWebBrowser2 wb in frames)
                {
                    node        = framenode.Nodes.Add("HTML");
                    subnode     = node.Nodes.Add("Title");
                    subnode.Tag = pWB.GetTitle(wb);
                    doc2        = (IHTMLDocument2)wb.Document;
                    subnode     = node.Nodes.Add("URL");
                    subnode.Tag = doc2.url;
                    subnode     = node.Nodes.Add("Domain");
                    subnode.Tag = doc2.domain;
                    subnode     = node.Nodes.Add("Protocol");
                    subnode.Tag = doc2.protocol;
                    subnode     = node.Nodes.Add("Cookie");
                    subnode.Tag = doc2.cookie;
                    subnode     = node.Nodes.Add("Referrer");
                    subnode.Tag = doc2.referrer;
                    subnode     = node.Nodes.Add("Last Modified");
                    subnode.Tag = doc2.lastModified;
                    subnode     = node.Nodes.Add("Source");
                    subnode.Tag = pWB.GetSource(wb);
                    subnode     = node.Nodes.Add("Text");
                    subnode.Tag = pWB.GetText(wb);
                }
            }

            //Expand the root
            root.Expand();
        }
Exemplo n.º 23
0
        public static ImagePropertiesInfo GetImagePropertiesInfo(IHTMLImgElement imgElement, IBlogPostImageEditingContext editorContext)
        {
            IHTMLElement      imgHtmlElement = (IHTMLElement)imgElement;
            string            imgSrc         = imgHtmlElement.getAttribute("src", 2) as string;
            BlogPostImageData imageData      = null;

            try
            {
                imageData = BlogPostImageDataList.LookupImageDataByInlineUri(editorContext.ImageList, new Uri(imgSrc));
            }
            catch (UriFormatException)
            {
                //this URI is probably relative web URL, so extract the image src letting the
                //DOM fill in the full URL for us based on the base URL.
                imgSrc = imgHtmlElement.getAttribute("src", 0) as string;
            }

            ImagePropertiesInfo info;

            if (imageData != null && imageData.GetImageSourceFile() != null)
            {
                //clone the image data to the sidebar doesn't change it (required for preserving image undo/redo state)
                imageData = (BlogPostImageData)imageData.Clone();
                //this is an attached local image
                info            = new BlogPostImagePropertiesInfo(imageData, new ImageDecoratorsList(editorContext.DecoratorsManager, imageData.ImageDecoratorSettings));
                info.ImgElement = imgHtmlElement;
            }
            else
            {
                //this is not an attached local image, so treat as a web image
                ImageDecoratorsList remoteImageDecoratorsList = new ImageDecoratorsList(editorContext.DecoratorsManager, new BlogPostSettingsBag());
                remoteImageDecoratorsList.AddDecorator(editorContext.DecoratorsManager.GetDefaultRemoteImageDecorators());

                //The source image size is unknown, so calculate the actual image size by removing
                //the size attributes, checking the size, and then placing the size attributes back
                string oldHeight = imgHtmlElement.getAttribute("height", 2) as string;
                string oldWidth  = imgHtmlElement.getAttribute("width", 2) as string;
                imgHtmlElement.removeAttribute("width", 0);
                imgHtmlElement.removeAttribute("height", 0);
                int width  = imgElement.width;
                int height = imgElement.height;

                if (!String.IsNullOrEmpty(oldHeight))
                {
                    imgHtmlElement.setAttribute("height", oldHeight, 0);
                }
                if (!String.IsNullOrEmpty(oldWidth))
                {
                    imgHtmlElement.setAttribute("width", oldWidth, 0);
                }

                info            = new ImagePropertiesInfo(new Uri(imgSrc), new Size(width, height), remoteImageDecoratorsList);
                info.ImgElement = imgHtmlElement;

                // Sets the correct inline image size and image size name for the remote image.
                if (!String.IsNullOrEmpty(oldWidth) && !String.IsNullOrEmpty(oldHeight))
                {
                    int inlineWidth, inlineHeight;
                    if (Int32.TryParse(oldWidth, NumberStyles.Integer, CultureInfo.InvariantCulture, out inlineWidth) &&
                        Int32.TryParse(oldHeight, NumberStyles.Integer, CultureInfo.InvariantCulture, out inlineHeight))
                    {
                        info.InlineImageSize = new Size(inlineWidth, inlineHeight);
                    }
                }

                // Sets the correct border style for the remote image.
                if (new HtmlBorderDecoratorSettings(imgHtmlElement).InheritBorder)
                {
                    if (!info.ImageDecorators.ContainsDecorator(HtmlBorderDecorator.Id))
                    {
                        info.ImageDecorators.AddDecorator(HtmlBorderDecorator.Id);
                    }
                }
                else if (new NoBorderDecoratorSettings(imgHtmlElement).NoBorder)
                {
                    if (!info.ImageDecorators.ContainsDecorator(NoBorderDecorator.Id))
                    {
                        info.ImageDecorators.AddDecorator(NoBorderDecorator.Id);
                    }
                }
            }

            //transfer image data properties
            if (imageData != null)
            {
                info.UploadSettings  = imageData.UploadInfo.Settings;
                info.UploadServiceId = imageData.UploadInfo.ImageServiceId;
                if (info.UploadServiceId == null)
                {
                    info.UploadServiceId = editorContext.ImageServiceId;
                }
            }

            return(info);
        }
Exemplo n.º 24
0
        //<img border="2" src="file:///C:/csEXWB/csEXWB.gif" align="center" hspace="2" vspace="2" alt="hello there" lowsrc="file:///C:/Desktop/blank.gif" width="600" height="463">
        public bool AppendImage(string src, string width, string height, string border, string alignment, string alt, string hspace, string vspace, string lowsrc)
        {
            if (m_pDoc2 == null)
            {
                return(false);
            }
            IHTMLElement elem = m_pDoc2.createElement("img") as IHTMLElement;

            if (elem == null)
            {
                return(false);
            }

            IHTMLImgElement imgelem = elem as IHTMLImgElement;

            if (imgelem == null)
            {
                return(false);
            }

            if (!string.IsNullOrEmpty(src))
            {
                imgelem.src = src;
            }
            if (!string.IsNullOrEmpty(width))
            {
                imgelem.width = int.Parse(width);
            }
            if (!string.IsNullOrEmpty(height))
            {
                imgelem.height = int.Parse(height);
            }
            if (!string.IsNullOrEmpty(border))
            {
                imgelem.border = border;
            }
            if (!string.IsNullOrEmpty(alignment))
            {
                imgelem.align = alignment;
            }
            if (!string.IsNullOrEmpty(hspace))
            {
                imgelem.hspace = int.Parse(hspace);
            }
            if (!string.IsNullOrEmpty(vspace))
            {
                imgelem.vspace = int.Parse(vspace);
            }
            if (!string.IsNullOrEmpty(alt))
            {
                imgelem.alt = alt;
            }
            if (!string.IsNullOrEmpty(lowsrc))
            {
                imgelem.lowsrc = lowsrc;
            }

            //Append to body DOM collection
            IHTMLDOMNode nd   = (IHTMLDOMNode)elem;
            IHTMLDOMNode body = (IHTMLDOMNode)m_pDoc2.body;

            return(body.appendChild(nd) != null);
        }
Exemplo n.º 25
0
        private void _normalHtmlContentEditor_SelectedImageResized(Size newImgElementSize, Size originalImgElementSize, bool preserveRatio, IHTMLImgElement image)
        {
            Size newBorderlessImageSize;
            ImagePropertiesInfo imageInfo = ImageEditingPropertyHandler.GetImagePropertiesInfo(image, this); ;

            //Note: In this resize context, the user resized the image in the editor to an explicit size.
            //The user expectation in this scenario is that the entire image (including the border) should fit
            //inside the new size.  To meet this expectation, we need to reduce the size of the image by the
            //border size so that the updated image (including borders) will fit inside of the size the user resized to.
            ImageBorderMargin borderMargin = imageInfo.InlineImageBorderMargin;
            if (preserveRatio)
            {
                //when preserving the image's aspect ratio during resize, don't include the border margins in the scaled
                //size calculation since this will distort the image.
                Size originalBorderlessSize = new Size(originalImgElementSize.Width - borderMargin.Width, originalImgElementSize.Height - borderMargin.Height);
                Size borderlessNewMaxSize = borderMargin.ReverseCalculateImageSize(newImgElementSize);

                newBorderlessImageSize = ImageUtils.GetScaledImageSize(borderlessNewMaxSize.Width, borderlessNewMaxSize.Height, originalBorderlessSize);
            }
            else
            {
                newBorderlessImageSize = borderMargin.ReverseCalculateImageSize(newImgElementSize);
            }

            PictureEditingManager.UpdateInlineImageSize(newBorderlessImageSize, ImageDecoratorInvocationSource.Resize, (HtmlEditorControl)_currentEditor);
        }
Exemplo n.º 26
0
        private void CreateHtmlTemplate(XmlWriter writer, IHTMLDOMNode htmlNode, IEnumerable <ControlBase> formControls, bool analyseParagraph = true)
        {
            //Element
            if (htmlNode.nodeType == 1)
            {
#if DEBUG
                if (analyseParagraph)
                {
                    Debug.WriteLine(string.Format("Current HTML Node:{0}.", htmlNode.nodeName));
                }
                else
                {
                    Debug.WriteLine(string.Format("Current HTML Element:{0}, analysed.", htmlNode.nodeName));
                }
#endif
                if (htmlNode is IHTMLParaElement && analyseParagraph)
                {
                    ProcessParagraphTag(writer, htmlNode, formControls);

                    return;
                }

                if (htmlNode is IHTMLObjectElement)
                {
                    IHTMLElement objElement = htmlNode as IHTMLElement;

                    ControlBase formControl = formControls.Single(c => c.ObjectId.Is(objElement.id));

                    SetDataBindingsForControl(formControl);

                    //Write control template
                    formControl.WriteToXslTemplate(writer);

                    return;
                }

                if (htmlNode is IHTMLAnchorElement)
                {
                    PartBookmark bookmark = ParseToPartBookmark(htmlNode as IHTMLElement);

                    if (bookmark != null)
                    {
                        string result = GenerateXslForBookmark(bookmark);

                        writer.WriteRaw(result);

                        return;
                    }
                }

                if (htmlNode is IHTMLImgElement)
                {
                    IHTMLImgElement image = htmlNode as IHTMLImgElement;

                    if (!string.IsNullOrEmpty(image.src))
                    {
                        string[] tempArray = image.src.Split(':');

                        string src = tempArray.Length == 2 ? tempArray[1] : image.src;

                        src = string.Format(@"{0}\{1}", Path.GetDirectoryName(_htmlFileName), src.Replace('/', '\\'));

                        image.src = GetBase64ImageSrc(src);
                    }
                }

                WriteStartHTMLElement(writer, htmlNode);

                if (htmlNode is IHTMLBodyElement)
                {
                    writer.WriteStartHtmlFormElement(Form_Method, Form_Action);

                    writer.WriteXslHtmlHiddenElement(Hidden_Url_Name, Hidden_Url_Value);
                    writer.WriteXslHtmlHiddenElement(Hidden_Object_Name, Hidden_Object_Value);
                }

                if (htmlNode is IHTMLStyleElement)
                {
                    IHTMLElement element = htmlNode as IHTMLElement;
                    writer.WriteString(element.innerHTML);
                    writer.WriteString(WartermarkStyle);
                }

                //Other tags
                foreach (IHTMLDOMNode child in htmlNode.childNodes)
                {
                    CreateHtmlTemplate(writer, child, formControls);
                }

                WriteEndHTMLElement(writer, htmlNode);
            }
            else
            {
                //Text or something else

                Debug.WriteLine(string.Format("Current HTML Node:{0}.", htmlNode.nodeName));

                //Text
                if (htmlNode.nodeType == 3)
                {
                    if (!IsRedundantSpaceNode(htmlNode))
                    {
                        writer.WriteString(htmlNode.nodeValue);
                    }
                }
            }
        }
        public static ImagePropertiesInfo GetImagePropertiesInfo(IHTMLImgElement imgElement, IBlogPostImageEditingContext editorContext)
        {
            IHTMLElement imgHtmlElement = (IHTMLElement)imgElement;
            string imgSrc = imgHtmlElement.getAttribute("src", 2) as string;
            BlogPostImageData imageData = null;
            try
            {
                imageData = BlogPostImageDataList.LookupImageDataByInlineUri(editorContext.ImageList, new Uri(imgSrc));
            }
            catch (UriFormatException)
            {
                //this URI is probably relative web URL, so extract the image src letting the
                //DOM fill in the full URL for us based on the base URL.
                imgSrc = imgHtmlElement.getAttribute("src", 0) as string;
            }

            ImagePropertiesInfo info;
            if (imageData != null && imageData.GetImageSourceFile() != null)
            {
                //clone the image data to the sidebar doesn't change it (required for preserving image undo/redo state)
                imageData = (BlogPostImageData)imageData.Clone();
                //this is an attached local image
                info = new BlogPostImagePropertiesInfo(imageData, new ImageDecoratorsList(editorContext.DecoratorsManager, imageData.ImageDecoratorSettings));
                info.ImgElement = imgHtmlElement;
            }
            else
            {
                //this is not an attached local image, so treat as a web image
                ImageDecoratorsList remoteImageDecoratorsList = new ImageDecoratorsList(editorContext.DecoratorsManager, new BlogPostSettingsBag());
                remoteImageDecoratorsList.AddDecorator(editorContext.DecoratorsManager.GetDefaultRemoteImageDecorators());

                //The source image size is unknown, so calculate the actual image size by removing
                //the size attributes, checking the size, and then placing the size attributes back
                string oldHeight = imgHtmlElement.getAttribute("height", 2) as string;
                string oldWidth = imgHtmlElement.getAttribute("width", 2) as string;
                imgHtmlElement.removeAttribute("width", 0);
                imgHtmlElement.removeAttribute("height", 0);
                int width = imgElement.width;
                int height = imgElement.height;

                if (!String.IsNullOrEmpty(oldHeight))
                    imgHtmlElement.setAttribute("height", oldHeight, 0);
                if (!String.IsNullOrEmpty(oldWidth))
                    imgHtmlElement.setAttribute("width", oldWidth, 0);
                Uri infoUri;
                if (Uri.TryCreate(imgSrc, UriKind.Absolute, out infoUri))
                {
                    info = new ImagePropertiesInfo(infoUri, new Size(width, height), remoteImageDecoratorsList);
                }
                else
                {
                    info = new ImagePropertiesInfo(new Uri("http://www.example.com"), new Size(width, height), remoteImageDecoratorsList);
                }
                info.ImgElement = imgHtmlElement;

                // Sets the correct inline image size and image size name for the remote image.
                if (!String.IsNullOrEmpty(oldWidth) && !String.IsNullOrEmpty(oldHeight))
                {
                    int inlineWidth, inlineHeight;
                    if (Int32.TryParse(oldWidth, NumberStyles.Integer, CultureInfo.InvariantCulture, out inlineWidth) &&
                        Int32.TryParse(oldHeight, NumberStyles.Integer, CultureInfo.InvariantCulture, out inlineHeight))
                    {
                        info.InlineImageSize = new Size(inlineWidth, inlineHeight);
                    }
                }

                // Sets the correct border style for the remote image.
                if (new HtmlBorderDecoratorSettings(imgHtmlElement).InheritBorder)
                {
                    if (!info.ImageDecorators.ContainsDecorator(HtmlBorderDecorator.Id))
                        info.ImageDecorators.AddDecorator(HtmlBorderDecorator.Id);
                }
                else if (new NoBorderDecoratorSettings(imgHtmlElement).NoBorder)
                {
                    if (!info.ImageDecorators.ContainsDecorator(NoBorderDecorator.Id))
                        info.ImageDecorators.AddDecorator(NoBorderDecorator.Id);
                }
            }

            //transfer image data properties
            if (imageData != null)
            {
                info.UploadSettings = imageData.UploadInfo.Settings;
                info.UploadServiceId = imageData.UploadInfo.ImageServiceId;
                if (info.UploadServiceId == null)
                {
                    info.UploadServiceId = editorContext.ImageServiceId;
                }
            }

            return info;
        }
Exemplo n.º 28
0
 public SUIHtmlImage(SUIHtmlControlBase ctrl)
     : base(ctrl)
 {
     imageElement = (IHTMLImgElement)ctrl.HtmlElement;
 }
Exemplo n.º 29
0
 public SUIHtmlImage(SUIHtmlDocument _doc, IHTMLElement _element)
     : base(_doc, _element)
 {
     imageElement = (IHTMLImgElement)_element;
 }
Exemplo n.º 30
0
        // Detects the alignment of an element, which could be an image or smart content div
        internal ImgAlignment GetAlignmentFromHtml()
        {
            // Try and see if this is an img, if it is we will be able to read
            // the align attribute right off of it.
            IHTMLImgElement image = (_element as IHTMLImgElement);

            if (image != null)
            {
                // Check and see if the align attribute has been set
                string align = image.align;
                if (align != null)
                {
                    align = align.ToLower(CultureInfo.InvariantCulture).Trim();

                    // If it has been, then just check to see what type
                    // of alignment has already been set.
                    switch (align)
                    {
                    case "left":
                        return(ImgAlignment.LEFT);

                    case "right":
                        return(ImgAlignment.RIGHT);

                    case "top":
                        return(ImgAlignment.TOP);

                    case "bottom":
                        return(ImgAlignment.BOTTOM);

                    case "middle":
                        return(ImgAlignment.MIDDLE);

                    case "absmiddle":
                        return(ImgAlignment.ABSMIDDLE);

                    case "baseline":
                        return(ImgAlignment.BASELINE);

                    case "texttop":
                        return(ImgAlignment.TEXTTOP);
                    }
                }
            }

            // Check to see if the element has a float right on it
            if (_element.style.styleFloat == "right")
            {
                return(ImgAlignment.RIGHT);
            }
            // Check to see if the element has a float left
            if (_element.style.styleFloat == "left")
            {
                return(ImgAlignment.LEFT);
            }

            if ((_element.style.styleFloat == "none" || String.IsNullOrEmpty(_element.style.styleFloat)) && _element.style.display == "block" && _element.style.marginLeft as string == "auto" && _element.style.marginRight as string == "auto")
            {
                return(ImgAlignment.CENTER);
            }

            IHTMLElement centeringNode = FindCenteringNode();

            if (centeringNode != null)
            {
                if (IsCenteringNode(centeringNode))
                {
                    return(ImgAlignment.CENTER);
                }
            }

            // We didnt find anything, so no alignment could be found.
            return(ImgAlignment.NONE);
        }