/// <summary> /// Gets the font of the selected text: decoration, size, font family, etc. /// </summary> /// <returns>The font as Font object</returns> public Font GetSelectedTextFont() { IHTMLStyle selectedFont = this.GetSelectedTextStyle(); if (selectedFont != null) { string family = selectedFont.fontFamily; string size = "12"; if (selectedFont.fontSize != null) { size = selectedFont.fontSize.Split('p')[0]; } FontStyle style = 0; if (selectedFont.fontWeight == "bold") { style = style | FontStyle.Bold; } if (selectedFont.fontStyle == "italic") { style = style | FontStyle.Italic; } if (selectedFont.textDecorationLineThrough) { style = style | FontStyle.Strikeout; } if (selectedFont.textDecorationUnderline) { style = style | FontStyle.Underline; } return(new Font(family, float.Parse(size), style, GraphicsUnit.Point)); } return(null); }
private void TimelineStart(object sender, EventArgs e) { TimelineBase startTimeline = (TimelineBase)sender; Debug.Assert(null != startTimeline); if (null != startTimeline.Target) { IHTMLElement iElement = (IHTMLElement)startTimeline.Target.DomElement; IHTMLStyle iStyle = iElement.style; iStyle.display = string.Empty; iStyle = null; iElement = null; } //foreach ( var timeline in m_listTimelines ) //{ // if ( !timeline.IsStop && // !string.IsNullOrEmpty(timeline.TargetName) && // timeline.TargetName.Equals( startTimeline.TargetName, StringComparison.OrdinalIgnoreCase ) ) // { // timeline.Cancel(); // break; // } //} }
public virtual void SetSharedElementStyle(string value) { if (sharedElement != null) { IHTMLStyle sharedStyle = sharedElement.GetStyle(); sharedStyle.SetCssText(value); } }
internal static object GetAttributeValue(string attributeName, IHTMLStyle style) { if (attributeName.IndexOf(Char.Parse("-")) > 0) { attributeName = attributeName.Replace("-", ""); } return(style.getAttribute(attributeName, 0)); }
private void ClearFontSize(IHTMLElement element) { IHTMLStyle style = element.style as IHTMLStyle; style.fontSize = ""; foreach (IHTMLElement childElem in (element.children as IHTMLElementCollection)) { ClearFontSize(childElem); } }
private void HighLightingText(HTMLDocument document, IHTMLDOMNode node, string keyword, int cnt) { // nodeType = 3:text节点 if (node.nodeType == 3) { string nodeText = node.nodeValue.ToString(); // 如果找到了关键字 if (nodeText.Contains(keyword)) { IHTMLDOMNode parentNode = node.parentNode; // 将关键字作为分隔符,将文本分离,并逐个添加到原text节点的父节点 string[] result = nodeText.Split(new string[] { keyword }, StringSplitOptions.None); for (int i = 0; i < result.Length - 1; i++) { if (result[i] != "") { IHTMLDOMNode txtNode = document.createTextNode(option[cnt] + result[i] + option[cnt]); parentNode.insertBefore(txtNode, node); } IHTMLDOMNode orgNode = document.createTextNode(option[cnt] + keyword + option[cnt]); IHTMLDOMNode hilightedNode = (IHTMLDOMNode)document.createElement("SPAN"); IHTMLStyle style = ((IHTMLElement)hilightedNode).style; style.color = "black"; style.backgroundColor = color[cnt]; hilightedNode.appendChild(orgNode); parentNode.insertBefore(hilightedNode, node); } if (result[result.Length - 1] != "") { IHTMLDOMNode postNode = document.createTextNode(option[cnt] + result[result.Length - 1] + option[cnt]); parentNode.insertBefore(postNode, node); } parentNode.removeChild(node); } // End of nodeText.Contains(keyword) } else { // 如果不是text节点,则递归搜索其子节点 IHTMLDOMChildrenCollection childNodes = node.childNodes as IHTMLDOMChildrenCollection; foreach (IHTMLDOMNode n in childNodes) { HighLightingText(document, n, keyword, cnt); } } }
/// <include file='doc\StyleBuilderForm.uex' path='docs/doc[@for="StyleBuilderForm.InitStyle"]/*' /> /// <devdoc> /// <para>[To be supplied.]</para> /// </devdoc> protected void InitStyle() { string styleValue = null; editingStyle = new IStyleBuilderStyle[1]; switch (styleType) { case STYLE_TYPE_STRING: if (preview != null) { IHTMLRuleStyle parseStyle = preview.GetParseStyleRule(); if (parseStyle != null) { styleValue = (string)styleObject; parseStyle.SetCssText(styleValue); editingStyle[0] = new CSSRuleStyle(parseStyle); } } break; case STYLE_TYPE_INLINESTYLE: { IHTMLStyle style = (IHTMLStyle)styleObject; styleValue = style.GetCssText(); editingStyle[0] = new CSSInlineStyle(style); } break; case STYLE_TYPE_RULESTYLE: { IHTMLRuleStyle style = (IHTMLRuleStyle)styleObject; styleValue = style.GetCssText(); editingStyle[0] = new CSSRuleStyle(style); } break; } if (styleValue != null) { preview.SetSharedElementStyle(styleValue); } }
private bool IsElementVisible(System.Windows.Forms.HtmlElement argElement) { Debug.Assert(null != argElement); bool Result = true; try { IHTMLElement iElement = (IHTMLElement)argElement.DomElement; IHTMLStyle iStyle = iElement.style; if (!string.IsNullOrEmpty(iStyle.display) && iStyle.display.Equals("none", StringComparison.OrdinalIgnoreCase)) { Result = false; } else { Result = true; } iElement = null; iStyle = null; } catch (System.Exception ex) { Trace.Write(ex.Message); return(true); } //if (!string.IsNullOrEmpty(argElement.Style)) //{ // string style = argElement.Style; // style = style.ToLowerInvariant(); // int index = style.IndexOf(HtmlRender.s_hideStyle); // if (-1 != index) // { // Result = false; // } //} return(Result); }
internal static object GetStyleAttributeValue(string attributeName, IHTMLStyle style) { attributeName = UtilityClass.TurnStyleAttributeIntoProperty(attributeName); return(style.getAttribute(attributeName, 0)); }
public virtual bool SetPropertyValue(string argProperty, object argValue) { //Debug.Assert(null != m_ihostedElement); if (null == m_ihostedElement) { return(false); } try { switch (argProperty) { case UIPropertyKey.s_ClearContent: { if (m_ihostedElement.TagName.Equals("input", StringComparison.OrdinalIgnoreCase)) { m_ihostedElement.SetAttribute("value", ""); } else { m_ihostedElement.InnerHtml = ""; m_ihostedElement.InnerText = ""; } } break; case UIPropertyKey.s_ValueKey: case UIPropertyKey.s_ContentKey: { //if (null == argValue) //{ // return false; //} //if (0 == string.Compare(m_ihostedElement.TagName, "input", true)) if (null != argValue) { string contentValue = null; if (m_ihostedElement.TagName.Equals("input", StringComparison.OrdinalIgnoreCase)) { contentValue = argValue is string?(string)argValue : argValue.ToString(); m_ihostedElement.SetAttribute("value", contentValue); } else if (argValue is double || argValue is Single) { contentValue = ((double)argValue).ToString("F"); m_ihostedElement.InnerText = contentValue; } else { contentValue = argValue is string?(string)argValue : argValue.ToString(); m_ihostedElement.InnerHtml = contentValue; } m_parent.NotifyPropertyChanged(HostedElement.Id, UIPropertyKey.s_ContentKey, contentValue); } else { if (m_ihostedElement.TagName.Equals("input", StringComparison.OrdinalIgnoreCase)) { //如果绑定池为null,则取defaultValue值,如果不为空,显示defaultValue,如果为空,显示"" by lsjie5 var defaultValue = m_ihostedElement.GetAttribute("defaultValue"); if (string.IsNullOrEmpty(defaultValue)) { m_ihostedElement.SetAttribute("value", ""); } else { m_ihostedElement.SetAttribute("value", defaultValue); } } else { //如果绑定池为null,则取defaultValue值,如果不为空,显示defaultValue,如果为空,显示"" by lsjie5 var defaultValue = m_ihostedElement.GetAttribute("defaultValue"); if (string.IsNullOrEmpty(defaultValue)) { m_ihostedElement.InnerHtml = ""; m_ihostedElement.InnerText = ""; } else { m_ihostedElement.InnerHtml = defaultValue; } } } } break; case UIPropertyKey.s_NameKey: { if (null == argValue || !(argValue is string)) { return(false); } m_ihostedElement.Id = (string)argValue; m_parent.NotifyPropertyChanged(HostedElement.Id, UIPropertyKey.s_NameKey, m_ihostedElement.Id); } break; case UIPropertyKey.s_tagKey: { if (null == argValue) { return(false); } if (argValue is string) { m_ihostedElement.SetAttribute(HtmlRender.s_tagAttri, (string)argValue); } else { m_ihostedElement.SetAttribute(HtmlRender.s_tagAttri, argValue.ToString()); } m_parent.NotifyPropertyChanged(HostedElement.Id, UIPropertyKey.s_NameKey, (string)argValue); } break; case UIPropertyKey.s_VisibleKey: { if (null == argValue) { return(false); } bool visible = true; if (argValue is string) { int temp = 0; if (!int.TryParse((string)argValue, out temp)) { return(false); } visible = temp == 0 ? false : true; } else if (argValue is bool) { visible = (bool)argValue; } else { return(false); } if (false == visible) { IHTMLElement element = (IHTMLElement)m_ihostedElement.DomElement; IHTMLStyle iStyle = element.style; if (null != iStyle) { if (!string.Equals(iStyle.display, "none", StringComparison.OrdinalIgnoreCase)) { m_oldDisplayState = iStyle.display; iStyle.display = "none"; } iStyle = null; } else { m_oldDisplayState = string.Empty; m_ihostedElement.SetAttribute("style", "display:none"); } element = null; //if (!string.IsNullOrEmpty(m_ihostedElement.Style)) //{ // int index = m_ihostedElement.Style.ToLowerInvariant().IndexOf(HtmlRender.s_hideStyle); // if (-1 == index) // { // m_ihostedElement.Style += HtmlRender.s_hideStyle; // } //} //else //{ // m_ihostedElement.Style = HtmlRender.s_hideStyle; //} } else { IHTMLElement element = (IHTMLElement)m_ihostedElement.DomElement; IHTMLStyle iStyle = element.style; if (null != iStyle) { iStyle.display = m_oldDisplayState; m_oldDisplayState = string.Empty; } element = null; // m_ihostedElement.Style = ""; //if (!string.IsNullOrEmpty (m_ihostedElement.Style)) //{ // int index = m_ihostedElement.Style.ToLowerInvariant().IndexOf(Page4Html.s_hideStyle); // if (-1 != index) // { // m_ihostedElement.Style = null; // } //} } m_parent.NotifyPropertyChanged(HostedElement.Id, UIPropertyKey.s_VisibleKey, visible ? "1" : "0"); } break; case UIPropertyKey.s_EnableKey: { if (null == argValue) { return(false); } bool enable = true; if (argValue is string) { int temp = 0; if (!int.TryParse((string)argValue, out temp)) { return(false); } enable = temp == 0 ? false : true; } else if (argValue is bool) { enable = (bool)argValue; } else { return(false); } if (m_ihostedElement.Enabled != enable) { m_ihostedElement.Enabled = enable; m_parent.NotifyPropertyChanged(HostedElement.Id, UIPropertyKey.s_EnableKey, enable ? "1" : "0"); } } break; default: { return(false); } } } catch (System.Exception ex) { Trace.Write(ex.Message); // LogProcessorService.Log.UIService.LogError(string.Format("Failed to set property[{0}] value of the element[{1}]", argProperty, m_ihostedElement.Id), ex); return(false); } return(true); }
/// <summary> /// Initializes a new instance of the <see cref="Style"/> class. /// </summary> /// <param name="style">The underlying <see cref="IHTMLStyle"/>.</param> public Style(IHTMLStyle style) { this.style = style; }
/////////////////////////////////////////////////////////////////////////// // IStyleBuilderPage Implementation and StyleBuilderPage Overrides /// <include file='doc\ListsStylePage.uex' path='docs/doc[@for="ListsStylePage.ActivatePage"]/*' /> /// <devdoc> /// The page is now the currently active page in the StyleBuilder. /// Be sure to call super.activatePage, so that the page is made visible. /// </devdoc> protected override void ActivatePage() { base.ActivatePage(); // initialize the preview IStyleBuilderPreview preview = null; if (Site != null) { preview = (IStyleBuilderPreview)Site.GetService(typeof(IStyleBuilderPreview)); } if (preview != null) { try { IHTMLElement listsPreviewElem = null; IHTMLElement listItemElem = null; IHTMLElement previewElem = preview.GetPreviewElement(); previewElem.SetInnerHTML(PREVIEW_TEMPLATE); listsPreviewElem = preview.GetElement(PREVIEW_ELEM_ID); if (listsPreviewElem != null) { previewStyle = listsPreviewElem.GetStyle(); } listItemElem = preview.GetElement(PREVIEW_LISTITEM1_ID); if (listItemElem != null) { listItemElem.SetInnerHTML(SR.GetString(SR.LstSP_PreviewText_1)); } listItemElem = preview.GetElement(PREVIEW_LISTITEM2_ID); if (listItemElem != null) { listItemElem.SetInnerHTML(SR.GetString(SR.LstSP_PreviewText_2)); } } catch (Exception) { previewStyle = null; return; } Debug.Assert(previewStyle != null, "Expected to have non-null cached style reference"); // Setup the font from the shared element to reflect settings in the font page try { IHTMLElement sharedElem = preview.GetSharedElement(); IHTMLStyle sharedStyle; string fontValue; if (sharedElem != null) { sharedStyle = sharedElem.GetStyle(); previewStyle.SetTextDecoration(sharedStyle.GetTextDecoration()); previewStyle.SetTextTransform(sharedStyle.GetTextTransform()); fontValue = sharedStyle.GetFont(); if ((fontValue != null) && (fontValue.Length != 0)) { previewStyle.SetFont(fontValue); } else { previewStyle.RemoveAttribute("font", 1); previewStyle.SetFontFamily(sharedStyle.GetFontFamily()); object o = sharedStyle.GetFontSize(); if (o != null) { previewStyle.SetFontSize(o); } previewStyle.SetFontObject(sharedStyle.GetFontObject()); previewStyle.SetFontStyle(sharedStyle.GetFontStyle()); previewStyle.SetFontWeight(sharedStyle.GetFontWeight()); } } } catch (Exception) { } // update initial preview UpdateBulletStylePreview(); UpdateBulletImagePreview(); UpdateBulletPositionPreview(); } }
public __TreeView() { this.InternalElement.style.backgroundColor = "yellow"; // for svg renderer we would want full view? this.InternalElement.style.overflow = IStyle.OverflowEnum.auto; // can it work for shadow elements too? // need it only once? // what triggers it? this.InternalAtAfterVisibleChanged += delegate { // Uncaught Error: fault at IHTMLStyle.StyleSheet var style = new IHTMLStyle { }.AttachTo(InternalElement); // dont want to see it in svg render // yes this seems to do the trick. style.style.display = IStyle.DisplayEnum.none; var selector = "." + typeof(__TreeNode).Name + ">.Header:hover"; Console.WriteLine(new { selector }); // we need to wait until attached to document? //var rule = style.StyleSheet.AddRule("." + typeof(__TreeNode).Name + ":hover"); new IStyle(style[selector]) { textDecoration = "underline", cursor = IStyle.CursorEnum.pointer, backgroundColor = "blue", color = "white" }; // Content // level1 //new IStyle(style["." + typeof(__TreeNode).Name + ">.Content"]) //{ // textIndent = "2em" //}; // level2 //new IStyle(style["." + typeof(__TreeNode).Name + " ." + typeof(__TreeNode).Name + ">.Content"]) //{ // textIndent = "4em" //}; }; this.Nodes = new __TreeNodeCollection { that__TreeView = this }; //this.InternalElement[].click // will we get the same font in svg render? this.InternalSetDefaultFont(); }
private string GetStyleValue() { IHTMLStyle style = node.style; return(style == null || style.cssText == null ? "" : style.cssText.ToLower()); }
public void SetSelectionFontSize(float size) { try { //get selected range IHTMLTxtRange range = htmlDoc.selection.createRange() as IHTMLTxtRange; //range could be null if selection type is not text if (range == null) { return; } //expand to a word if nothing selected if (string.IsNullOrEmpty(range.htmlText)) { range.expand("word"); if (string.IsNullOrEmpty(range.htmlText)) { return; //return if still null } } //get the parent of selected range IHTMLElement elem = range.parentElement() as IHTMLElement; //check if selected range contains parent element bool isElement = !elem.tagName.Equals("BODY") && ((range.text == null && elem.outerText == null) || (range.text != null && range.text.Equals(elem.outerText))); if (isElement) { //clear font size for all children foreach (var c in (elem.children as IHTMLElementCollection)) { ClearFontSize(c as IHTMLElement); } //set font size for the element IHTMLStyle style = elem.style as IHTMLStyle; style.fontSize = size + "pt"; } else { //clear font size for all elements inside the selection var body = htmlDoc.body as IHTMLBodyElement; foreach (IHTMLElement childElem in (elem.children as IHTMLElementCollection)) { IHTMLTxtRange r = body.createTextRange() as IHTMLTxtRange; r.moveToElementText(childElem); if (range.inRange(r)) { ClearFontSize(childElem); } } //set font size by surrounding with span range.pasteHTML("<span style='font-size:" + size + "pt'>" + range.htmlText + "</span>"); } } catch (Exception e) { System.Diagnostics.Trace.WriteLine(DateTime.Now.ToString() + ": NoteEdiitor.SetFontSize" + e.Message); System.Diagnostics.Trace.WriteLine(e.StackTrace); } }
internal static object GetAttributeValue(string attributeName, IHTMLStyle style) { if (attributeName.IndexOf(Char.Parse("-")) > 0) { attributeName = attributeName.Replace("-", ""); } return style.getAttribute(attributeName, 0); }
/// <include file='doc\ListsStylePage.uex' path='docs/doc[@for="ListsStylePage.DeactivatePage"]/*' /> /// <devdoc> /// The page is being deactivated, either because the dialog is closing, or /// some other page is replacing it as the active page. /// </devdoc> protected override bool DeactivatePage(bool closing, bool validate) { previewStyle = null; return(base.DeactivatePage(closing, validate)); }
/////////////////////////////////////////////////////////////////////////// // Constructor /// <include file='doc\CSSInlineStyle.uex' path='docs/doc[@for="CSSInlineStyle.CSSInlineStyle"]/*' /> /// <devdoc> /// Creates a new CSSInlineStyle wrapping the specified style /// </devdoc> public CSSInlineStyle(IHTMLStyle style) { Debug.Assert(style != null, "Null style used for CSSInlineStyle"); this.style = style; }
/// <summary> /// Handle the DocumentComplete event. /// </summary> /// <param name="pDisp"> /// The pDisp is an an object implemented the interface InternetExplorer. /// By default, this object is the same as the ieInstance, but if the page /// contains many frames, each frame has its own document. /// </param> void IeInstance_DocumentComplete(object pDisp, ref object URL) { if (ieInstance == null) { return; } // get the url string url = URL as string; if (string.IsNullOrEmpty(url) || url.Equals(@"about:Tabs", StringComparison.OrdinalIgnoreCase) || url.Equals("about:blank", StringComparison.OrdinalIgnoreCase)) { return; } // http://borderstylo.com/posts/115-browser-wars-2-dot-0-the-plug-in SHDocVw.WebBrowser browser = (SHDocVw.WebBrowser)ieInstance; if (browser.ReadyState != SHDocVw.tagREADYSTATE.READYSTATE_COMPLETE) { return; } // Set the handler of the document in InternetExplorer. NativeMethods.ICustomDoc customDoc = (NativeMethods.ICustomDoc)ieInstance.Document; customDoc.SetUIHandler(openImageDocHostUIHandler); // sets the document this.document = (HTMLDocument)ieInstance.Document; try { if (this.document.url.Contains(@"thousandpass") || this.document.url.Contains(@"1000pass.com")) { // Mark the add_on as installed! IHTMLElement div1000pass_add_on = this.document.getElementById("1000pass_add_on"); div1000pass_add_on.className = @"installed"; IHTMLElement div1000pass_add_on_version = this.document.getElementById("1000pass_add_on_version"); div1000pass_add_on_version.innerText = VERSION; // Try to save the token string token = div1000pass_add_on.getAttribute("token").ToString(); if (!String.IsNullOrEmpty(token)) { Utils.WriteToFile(Utils.TokenFileName, token); } foreach (IHTMLElement htmlElement in document.getElementsByTagName("IMG")) { if (htmlElement.className == "remote_site_logo") { IHTMLStyle htmlStyle = (IHTMLStyle)htmlElement.style; htmlStyle.cursor = "pointer"; DHTMLEventHandler Handler = new DHTMLEventHandler((IHTMLDocument2)ieInstance.Document); Handler.Handler += new DHTMLEvent(Logo_OnClick); htmlElement.onclick = Handler; htmlElement.setAttribute("alreadyopened", "false", 0); } } } else { // Must run on a thread to guaranty the page has finished loading (js loading) // http://stackoverflow.com/questions/3514945/running-a-javascript-function-in-an-instance-of-internetexplorer System.Threading.ThreadPool.QueueUserWorkItem((o) => { System.Threading.Thread.Sleep(500); try { Thread aThread = new Thread(bind); aThread.SetApartmentState(ApartmentState.STA); aThread.Start(); } catch (Exception ee) { Utils.l(ee); } }, browser); } } catch (Exception e) { Utils.l(e); } }