Beispiel #1
0
        private void OnResize()
        {
            if (!this.AllowResize)
            {
                return;
            }
            Interop.IHTMLStyle style1 = this._element.GetStyle();
            int width  = style1.GetPixelWidth();
            int height = style1.GetPixelHeight();

            if (height == 0)
            {
                height = this._element.GetOffsetHeight();
            }
            if (width == 0)
            {
                width = this._element.GetOffsetWidth();
            }
            if ((height != 0) || (width != 0))
            {
                //style1.RemoveAttribute("width", 0);
                //style1.RemoveAttribute("height", 0);
                //System.Web.UI.WebControls.WebControl control1 = this._behavior.Control as System.Web.UI.WebControls.WebControl;
                if (this._control != null)
                {
                    if (height != this._oldHeight)
                    {
                        this._control.Height = System.Web.UI.WebControls.Unit.Pixel(height);
                    }
                    if (width != this._oldWidth)
                    {
                        this._control.Width = System.Web.UI.WebControls.Unit.Pixel(width);
                    }
                }
                this._oldHeight = height;
                this._oldWidth  = width;
                IComponentChangeService service1 = (IComponentChangeService)this._editor.ServiceProvider.GetService(typeof(IComponentChangeService));
                if (service1 != null)
                {
                    service1.OnComponentChanged(this._control, null, null, null);
                }
                //if (!this.Designer.ReadOnly)
                {
                    style1.SetWidth(width);
                    style1.SetHeight(height);
                }
                //((Interop.IHTMLElement2)_element).GetRuntimeStyle().SetOverflow("visible");
                //_behavior.OnContentSave();
            }
        }
 /// <summary>
 /// Convenience method for checking if the specified element has a design time lock
 /// </summary>
 /// <param name="elem"></param>
 /// <returns></returns>
 private bool IsElementLocked(Interop.IHTMLElement elem)
 {
     object[] attribute = new object[1];
     elem.GetAttribute(DesignTimeLockAttribute, 0, attribute);
     if (attribute[0] == null)
     {
         Interop.IHTMLStyle style = elem.GetStyle();
         attribute[0] = style.GetAttribute(DesignTimeLockAttribute, 0);
     }
     if ((attribute[0] == null) || !(attribute[0] is string))
     {
         return(false);
     }
     return(true);
 }
Beispiel #3
0
        /// <summary>
        /// Return style attribute for element.
        /// </summary>
        /// <param name="element"></param>
        /// <param name="styleName"></param>
        /// <returns></returns>
        public string GetStyleAttribute(Interop.IHTMLElement element, string styleName)
        {
            Interop.IHTMLStyle style = (Interop.IHTMLStyle)element.GetStyle();
            object             o     = style.GetAttribute(styleName.Replace("-", String.Empty), 0);

            if (o == null)
            {
                return(String.Empty);
            }
            else
            {
                string styleText = o.ToString();
                return(styleText);
            }
        }
Beispiel #4
0
 /// <summary>
 /// Connects the specified control and its underlying element to the event sink.
 /// </summary>
 /// <param name="element">Underlying element of control.</param>
 /// <param name="editor">Reference to editor control.</param>
 public void Connect(Interop.IHTMLElement element, IHtmlEditor editor)
 {
     this._editor   = editor;
     this._designer = (ControlDesigner)this._behavior.Designer;
     try
     {
         this._element         = element;
         this._elementStyle    = this._element.GetStyle();
         this._runTimeStyle    = ((Interop.IHTMLElement2) this._element).GetRuntimeStyle();
         this._eventSinkCookie = new ConnectionPointCookie(this._element, this, typeof(Interop.IHTMLElementEvents));
     }
     catch (Exception)
     {
     }
     EventsEnabled = true;
 }
Beispiel #5
0
 private void OnMoveEnd()
 {
     if (this._elementMoving)
     {
         this._elementMoving = false;
         if (this._elementLocked)
         {
             Interop.IHTMLStyle style1 = this._element.GetStyle();
             if (style1 != null)
             {
                 style1.SetTop(this._elementLockedTop);
                 style1.SetLeft(this._elementLockedLeft);
             }
             this._elementLocked = false;
         }
         DocumentEventArgs e = new DocumentEventArgs(_eventobj, _control);
         _control.OnMoveEnd(e);
     }
 }
 /// <summary>
 /// Toggle the design time lock state of the selected items
 /// </summary>
 public void ToggleLock()
 {
     //Switch the lock on each item
     foreach (Interop.IHTMLElement elem in _items)
     {
         Interop.IHTMLStyle style = elem.GetStyle();
         if (IsElementLocked(elem))
         {
             //We need to remove attributes off the element and the style because of a bug in Trident
             elem.RemoveAttribute(DesignTimeLockAttribute, 0);
             style.RemoveAttribute(DesignTimeLockAttribute, 0);
         }
         else
         {
             //We need to add attributes to the element and the style because of a bug in Trident
             elem.SetAttribute(DesignTimeLockAttribute, "true", 0);
             style.SetAttribute(DesignTimeLockAttribute, "true", 0);
         }
     }
 }
Beispiel #7
0
 public InlineStyle(Interop.IHTMLStyle style)
 {
     this._style = style;
 }
Beispiel #8
0
        /// <summary>
        /// Creates the viewlink document.
        /// </summary>
        private void CreateControlView()
        {
            Interop.IHTMLDocument2 originDocument = (Interop.IHTMLDocument2)Element.GetDocument();
            Interop.IHTMLElement   htmlElement    = originDocument.CreateElement("HTML");
            Interop.IHTMLElement   headElement    = originDocument.CreateElement("HEAD");
            Interop.IHTMLElement   bodyElement    = originDocument.CreateElement("BODY");
            ((Interop.IHTMLElement2)htmlElement).InsertAdjacentElement("beforeBegin", headElement);
            ((Interop.IHTMLElement2)htmlElement).InsertAdjacentElement("afterBegin", bodyElement);
            _viewElement = bodyElement;
            _viewElement.SetAttribute("tabIndex", 1000, 0);
            baseDocument = (Interop.IHTMLDocument)_viewElement.GetDocument();
            try
            {
                elementDefaults = ((Interop.IElementBehaviorSiteOM2)_behaviorSite).GetDefaults();
            }
            catch
            {
                throw new ApplicationException("Wrong usage - acces to not properly attached master element");
            }
            XmlElementDesigner elementDesigner = Designer as XmlElementDesigner;

            if (_control == null || elementDesigner == null)
            {
                _viewElement.SetInnerHTML(String.Format(@"<div style=""border:dotted 1px red;background:Silver;width:220px;height:40px""><b>Error</b>:&nbsp;Element does not have a Designer attached (Element {0}:{1})</div>",
                                                        ((Interop.IHTMLElement2)_element).GetScopeName(),
                                                        _element.GetTagName()));
                ((Interop.IHTMLDocument2)baseDocument).SetDesignMode("Off");
                elementDefaults.SetViewLink(baseDocument);
                return;
            }
            else
            {
                _viewElement.SetInnerHTML(elementDesigner.GetDesignTimeHtml());
                elementDefaults.SetViewLink(baseDocument);
            }
            //done, set reference
            _control.ViewElementDefaults = elementDefaults;
            // end commands do basic document
            if (elementDesigner.DisableEditFocus)
            {
                //System.Threading.ThreadPool.QueueUserWorkItem(ExecuteCommand, (int)Interop.IDM.DISABLE_EDITFOCUS_UI);
            }

            // get viewlink specific properties from control element
            elementDefaults.SetFrozen(elementDesigner.FrozenEvents);    // true = event handler returns only master; false = event returns designtime html
            ((Interop.IHTMLElement3)_viewElement).contentEditable = InheritedDesignModeEnabled(_control.ContentEditable) ? "true" : "false";
            elementDefaults.SetViewMasterTab(elementDesigner.ViewMasterTab);
            elementDefaults.SetTabStop(elementDesigner.TabStop);
            elementDefaults.SetCanHaveHTML(elementDesigner.CanHaveHtml);
            elementDefaults.SetIsMultiLine(true);

            Interop.IHTMLStyle style        = ((Interop.IHTMLElement2)_viewElement).GetRuntimeStyle();
            ElementStyle       runtimeStyle = new ElementStyle(style);

            elementDesigner.SetRuntimeStyle(runtimeStyle);
            // assure that we don't see any unexpected scrollbars during resize operations
            ((Interop.IHTMLElement2)_element).GetRuntimeStyle().SetOverflow("hidden");
            object w = ((Interop.IHTMLElement)_element).GetStyle().GetWidth();

            elementDesigner.OnSetComponentDefaults();
            try
            {
                Interop.IHTMLDocument2 baseDocument2 = (Interop.IHTMLDocument2)baseDocument;
                int numSheets = 0;
                Interop.IHTMLStyleSheetsCollection baseDocumentStylesheets = originDocument.GetStyleSheets();
                if (baseDocumentStylesheets != null)
                {
                    numSheets = baseDocumentStylesheets.Length;
                }
                for (int j = 0; j < numSheets; j++)
                {
                    object local = j;
                    Interop.IHTMLStyleSheet sheetItem = (Interop.IHTMLStyleSheet)baseDocumentStylesheets.Item(local);
                    if (sheetItem != null)
                    {
                        int k = 0;
                        Interop.IHTMLStyleSheetRulesCollection rules = sheetItem.GetRules();
                        if (rules != null)
                        {
                            k = rules.GetLength();
                        }
                        if (k != 0)
                        {
                            Interop.IHTMLStyleSheet newSheet = baseDocument2.CreateStyleSheet(String.Empty, 0);
                            for (int i2 = 0; i2 < k; i2++)
                            {
                                Interop.IHTMLStyleSheetRule newRule = rules.Item(i2);
                                if (newRule != null)
                                {
                                    string selector = newRule.GetSelectorText();
                                    string content  = newRule.GetStyle().cssText;
                                    newSheet.AddRule(selector, content, i2);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
            }
            // once we have the viewlink created, establish a backlink
            elementDesigner.AssociatedViewLink = this;
        }
Beispiel #9
0
 protected override void OnInitialActivated(EventArgs e)
 {
     base.OnInitialActivated(e);
     this._preview.LoadHtml("<html>\r\n              <body style=\"border: none; margin: 0; padding: 0; overflow: hidden\">\r\n                <div id=\"divPreview\" style=\"height: 100%; width: 100%; overflow: auto; padding: 1px\"></div>\r\n                <div style=\"display:none\"><span id=\"spanParse\"></span></div>\r\n              </body>\r\n              </html>", this._baseUrl);
     Application.DoEvents();
     if (this._cssTextMode)
     {
         try
         {
             Element elementByID = this._preview.GetElementByID("spanParse");
             if (elementByID != null)
             {
                 this._parseStyle = elementByID.Peer.GetStyle();
             }
             if (this._cssText.Length != 0)
             {
                 this._parseStyle.SetCssText(this._cssText);
             }
             this._style = new InlineStyle(this._parseStyle);
         }
         catch (Exception)
         {
         }
         if (this._style == null)
         {
             ((IMxUIService) this.GetService(typeof(IMxUIService))).ReportError("Unable to process the initial style string.", "StyleBuilder", false);
             base.BeginInvoke(new MethodInvoker(this.AbortDialog));
             return;
         }
     }
     IStyle[] styles = new IStyle[] { this._style };
     foreach (CssAttribute attribute in this._attributeList)
     {
         attribute.Load(styles);
     }
     this._groupList.Items.AddRange(new ListViewItem[] { new GroupViewListViewItem(this._editingGroups[0]), new GroupViewListViewItem(this._editingGroups[1]) });
     this._groupList.Items[0].Selected = true;
 }
Beispiel #10
0
 public void SendToBack()
 {
     this.SynchronizeSelection();
     if (this.SelectionType == EditorSelectionType.ElementSelection)
     {
         if (this._items.Count > 1)
         {
             int num = this._minZIndex;
             int count = this._items.Count;
             Interop.IHTMLStyle[] styleArray = new Interop.IHTMLStyle[count];
             int[] numArray = new int[count];
             for (int i = 0; i < count; i++)
             {
                 styleArray[i] = ((Interop.IHTMLElement) this._items[i]).GetStyle();
                 numArray[i] = (int) styleArray[i].GetZIndex();
                 if (numArray[i] > num)
                 {
                     num = numArray[i];
                 }
             }
             int num4 = num - (this._minZIndex - 1);
             BatchedUndoUnit unit = this._editor.OpenBatchUndo("Align Left");
             try
             {
                 for (int j = 0; j < count; j++)
                 {
                     int p = numArray[j] - num4;
                     if (numArray[j] == this._maxZIndex)
                     {
                         this._maxZIndex--;
                     }
                     styleArray[j].SetZIndex(p);
                     if (p < this._minZIndex)
                     {
                         this._minZIndex = p;
                     }
                 }
                 return;
             }
             catch
             {
                 return;
             }
             finally
             {
                 unit.Close();
             }
         }
         Interop.IHTMLElement element2 = (Interop.IHTMLElement) this._items[0];
         object zIndex = element2.GetStyle().GetZIndex();
         if ((zIndex != null) && !(zIndex is DBNull))
         {
             if (((int) zIndex) == this._minZIndex)
             {
                 return;
             }
             if (((int) zIndex) == this._maxZIndex)
             {
                 this._maxZIndex--;
             }
         }
         element2.GetStyle().SetZIndex(--this._minZIndex);
     }
 }
Beispiel #11
0
 /// <summary>
 /// Set style attribute for this element.
 /// </summary>
 /// <param name="element"></param>
 /// <param name="styleName"></param>
 /// <param name="styleText"></param>
 public void SetStyleAttribute(Interop.IHTMLElement element, string styleName, string styleText)
 {
     Interop.IHTMLStyle style = (Interop.IHTMLStyle)element.GetStyle();
     style.SetAttribute(styleName.Replace("-", String.Empty), styleText, 0);
 }