public static void GetElementStyleSize(IWebClientControl wcc, out string widthStyle, out string heightStyle) { widthStyle = string.Empty; heightStyle = string.Empty; if (!(wcc is ICustomSize)) { Control c = wcc as Control; if (wcc.WidthType != SizeType.AutoSize) { if (wcc.WidthType == SizeType.Absolute) { widthStyle = string.Format(CultureInfo.InvariantCulture, "{0}px; ", c.Width); } else { widthStyle = string.Format(CultureInfo.InvariantCulture, "{0}%; ", wcc.WidthInPercent); } } // if (wcc.HeightType != SizeType.AutoSize) { if (wcc.HeightType == SizeType.Absolute) { heightStyle = string.Format(CultureInfo.InvariantCulture, "{0}px; ", c.Height); } else { heightStyle = string.Format(CultureInfo.InvariantCulture, "{0}%; ", wcc.HeightInPercent); } } } }
//======================================================================================================== #endregion #endregion #region private methods private void createControlWebContents(Control ct, XmlNode parentNode, int groupId) { XmlNode nodeNext = parentNode; IWebClientControl webc = ct as IWebClientControl; if (webc != null) { XmlNode nd = parentNode.OwnerDocument.CreateElement(webc.ElementName); parentNode.AppendChild(nd); XmlUtil.SetAttribute(nd, "id", webc.CodeName); webc.CreateHtmlContent(nd, EnumWebElementPositionType.Auto, groupId); WebPageCompilerUtility.CreateElementAnchor(webc, nd); _resourceFiles.AddRange(webc.GetResourceFiles()); Dictionary <string, string> hp = webc.HtmlParts; if (hp != null && hp.Count > 0) { foreach (KeyValuePair <string, string> kv in hp) { _htmlParts.Add(kv.Key, kv.Value); } } nodeNext = nd; } IWebPageLayout lt = ct as IWebPageLayout; if (lt == null) { foreach (Control c in ct.Controls) { createControlWebContents(c, nodeNext, groupId); } } }
public static void SetWebControlAttributes(IWebClientControl wcc, XmlNode node) { if (!string.IsNullOrEmpty(wcc.className)) { XmlUtil.SetAttribute(node, "class", wcc.className); } }
private void adjustWebControlZOrders(Control c, int n) { for (int i = 0; i < c.Controls.Count; i++) { IWebClientControl wc = c.Controls[i] as IWebClientControl; if (wc != null) { int zi = n - c.Controls.GetChildIndex(c.Controls[i], false); wc.zOrder = zi; } } n -= c.Controls.Count; for (int i = 0; i < c.Controls.Count; i++) { adjustWebControlZOrders(c.Controls[i], n); } }
public static void CreateJavaScript(IProperty SetProperty, string v, StringCollection sb, StringCollection parameters) { if (SetProperty.RootPointer != null && typeof(WebPage).IsAssignableFrom(SetProperty.RootPointer.BaseClassType)) { ClassPointer pp = SetProperty.PropertyOwner as ClassPointer; if (pp != null) { if (pp.ClassId != SetProperty.RootPointer.ClassId) { sb.Add(string.Format(CultureInfo.InvariantCulture, "JsonDataBinding.setPropertyByPageId({0},'{1}',{2});\r\n", pp.ClassId, SetProperty.Name, v)); return; } } } if (typeof(ProjectResources).Equals(SetProperty.Owner.ObjectInstance)) { if (string.CompareOrdinal(SetProperty.Name, "ProjectCultureName") == 0) { sb.Add(string.Format(CultureInfo.InvariantCulture, "JsonDataBinding.SwitchCulture({0});\r\n", v)); return; } } IWebClientComponent wcc = SetProperty.Owner.ObjectInstance as IWebClientComponent; if (wcc == null && SetProperty.Owner.ObjectInstance == null) { if (SetProperty.Owner.ObjectType != null) { if (SetProperty.Owner.ObjectType.GetInterface("IWebClientComponent") != null) { try { wcc = Activator.CreateInstance(SetProperty.Owner.ObjectType) as IWebClientComponent; if (wcc != null) { wcc.SetCodeName(SetProperty.Owner.CodeName); } } catch { } } } } if (wcc != null) { v = wcc.MapJavaScriptVallue(SetProperty.Name, v); } IWebClientPropertyCustomSetter wpcs = SetProperty.Owner.ObjectInstance as IWebClientPropertyCustomSetter; if (wpcs == null && SetProperty.Owner.ObjectInstance == null) { wpcs = wcc as IWebClientPropertyCustomSetter; } if (wpcs != null) { string ownerCode = SetProperty.Owner.GetJavaScriptReferenceCode(sb); if (wpcs.CreateSetPropertyJavaScript(ownerCode, SetProperty.Name, v, sb)) { return; } } if (string.CompareOrdinal("Font", SetProperty.Name) == 0) { IWebClientControl webc = SetProperty.Owner.ObjectInstance as IWebClientControl; if (webc != null) { sb.Add(string.Format(CultureInfo.InvariantCulture, "JsonDataBinding.setFont({0},{1});\r\n", WebPageCompilerUtility.JsCodeRef(webc.CodeName), WebPageCompilerUtility.GetFontJavascriptValues(v))); return; } } if (typeof(SessionVariableCollection).Equals(SetProperty.Owner.ObjectType)) { sb.Add(string.Format(CultureInfo.InvariantCulture, "JsonDataBinding.setSessionVariable('{0}',{1});\r\n", SetProperty.Name, v)); return; } if (typeof(LimnorWebApp).IsAssignableFrom(SetProperty.Owner.ObjectType)) { if (string.CompareOrdinal(SetProperty.Name, "GlobalVariableTimeout") == 0) { sb.Add(string.Format(CultureInfo.InvariantCulture, "JsonDataBinding.setSessionTimeout({0});\r\n", v)); return; } } string code = null; IWebClientPropertyHolder wcph = SetProperty.Owner.ObjectInstance as IWebClientPropertyHolder; if (wcph != null) { code = wcph.CreateSetPropertyJavaScript(SetProperty.Owner.CodeName, SetProperty.Name, v); if (!string.IsNullOrEmpty(code)) { sb.Add(code); } } IWebClientPropertySetter wcps = SetProperty.Owner.ObjectInstance as IWebClientPropertySetter; if (string.IsNullOrEmpty(code)) { if (wcps == null || !wcps.UseCustomSetter(SetProperty.Name)) { string left = SetProperty.GetJavaScriptReferenceCode(sb); if (left.EndsWith(".innerText", StringComparison.Ordinal)) { code = string.Format(CultureInfo.InvariantCulture, "JsonDataBinding.SetInnerText({0},{1});\r\n", left.Substring(0, left.Length - 10), v); } else if (left.StartsWith("JsonDataBinding.GetInnerText(", StringComparison.Ordinal)) { string oc = SetProperty.Owner.GetJavaScriptReferenceCode(sb); code = string.Format(CultureInfo.InvariantCulture, "JsonDataBinding.SetInnerText({0},{1});\r\n", oc, v); } else if (left.EndsWith(".Opacity", StringComparison.Ordinal)) { code = string.Format(CultureInfo.InvariantCulture, "JsonDataBinding.setOpacity({0},{1});\r\n", left.Substring(0, left.Length - ".Opacity".Length), v); } else if (left.StartsWith("JsonDataBinding.getOpacity(", StringComparison.Ordinal)) { string oc = SetProperty.Owner.GetJavaScriptReferenceCode(sb); code = string.Format(CultureInfo.InvariantCulture, "JsonDataBinding.setOpacity({0},{1});\r\n", oc, v); } else if (left.EndsWith(".style.display", StringComparison.Ordinal)) { code = string.Format(CultureInfo.InvariantCulture, "JsonDataBinding.setVisible({0},{1});\r\n", left.Substring(0, left.Length - ".style.display".Length), v); } else { if (wcc != null && v != null) { if (string.CompareOrdinal(SetProperty.Name, "Top") == 0 || string.CompareOrdinal(SetProperty.Name, "Left") == 0 || string.CompareOrdinal(SetProperty.Name, "Height") == 0 || string.CompareOrdinal(SetProperty.Name, "Width") == 0) { if (!v.EndsWith("px", StringComparison.Ordinal)) { code = string.Format(CultureInfo.InvariantCulture, "{0}=({1})+'px';\r\n", left, v); } } } if (code == null && SetProperty.Holder != null) { if (typeof(HtmlListBox).Equals(SetProperty.Holder.ObjectType) || typeof(HtmlDropDown).Equals(SetProperty.Holder.ObjectType)) { if (string.CompareOrdinal(SetProperty.Name, "SelectedValue") == 0 || string.CompareOrdinal(SetProperty.Name, "selectedValue") == 0) { code = string.Format(CultureInfo.InvariantCulture, "JsonDataBinding.SetSelectedListValue({0},{1});\r\n", SetProperty.Holder.GetJavaScriptReferenceCode(sb), v); } else if (string.CompareOrdinal(SetProperty.Name, "SelectedItem") == 0 || string.CompareOrdinal(SetProperty.Name, "selectedItem") == 0) { code = string.Format(CultureInfo.InvariantCulture, "JsonDataBinding.SetSelectedListText({0},{1});\r\n", SetProperty.Holder.GetJavaScriptReferenceCode(sb), v); } } } if (code == null) { code = string.Format(CultureInfo.InvariantCulture, "{0}={1};\r\n", left, v); } } if (!string.IsNullOrEmpty(code)) { sb.Add(code); } } } bool isCustomValue = false; if (string.CompareOrdinal("tag", SetProperty.Name) == 0) { isCustomValue = true; } else if (wcc != null) { WebClientValueCollection cvc = wcc.CustomValues; if (cvc != null) { if (cvc.ContainsKey(SetProperty.Name)) { isCustomValue = true; } } } if (isCustomValue) { string ownerCode = SetProperty.Owner.GetJavaScriptReferenceCode(sb); sb.Add(string.Format(CultureInfo.InvariantCulture, "{0}JsonDataBinding.onSetCustomValue({1},'{2}');\r\n", Indentation.GetIndent(), ownerCode, SetProperty.Name)); } if (wcps != null) { wcps.OnSetProperty(SetProperty.Name, v, sb); } }
public static void CreateElementPosition(Control c, StringBuilder sb, EnumWebElementPositionType positionType) { IWebClientControl wcc = c as IWebClientControl; if (wcc != null) { if (wcc.textAlign != EnumTextAlign.left) { sb.Append(string.Format(CultureInfo.InvariantCulture, "text-align:{0};", wcc.textAlign)); } // string widthStyle, heightStyle; GetElementStyleSize(wcc, out widthStyle, out heightStyle); if (!string.IsNullOrEmpty(widthStyle)) { sb.Append("width:"); sb.Append(widthStyle); } if (!string.IsNullOrEmpty(heightStyle)) { sb.Append("height:"); sb.Append(heightStyle); } // } IWebBox wb = c as IWebBox; if (wb != null) { if (wb.Box.BorderRadius > 0) { sb.Append("border-radius:"); sb.Append(wb.Box.BorderRadius.ToString(CultureInfo.InvariantCulture)); sb.Append("px;"); } if (wb.Box.BoxShadow > 0) { int bs = 1; if (wb.Box.BoxShadow > 2) { bs = wb.Box.BoxShadow / 2; } string cs; if (wb.Box.ShadowColor == Color.Empty) { cs = ObjectCreationCodeGen.GetColorString(Color.DarkGray); } else { cs = ObjectCreationCodeGen.GetColorString(wb.Box.ShadowColor); } sb.Append(string.Format(CultureInfo.InvariantCulture, "box-shadow:{0}px {0}px {1}px {2};", wb.Box.BoxShadow, bs, cs)); } if (wb.Box.GradientEndColor != Color.Empty || wb.Box.GradientStartColor != Color.Empty) { string c1; if (wb.Box.GradientStartColor != Color.Empty) { c1 = ObjectCreationCodeGen.GetColorString(wb.Box.GradientStartColor); } else { c1 = ObjectCreationCodeGen.GetColorString(Color.White); } string c2; if (wb.Box.GradientEndColor != Color.Empty) { c2 = ObjectCreationCodeGen.GetColorString(wb.Box.GradientEndColor); } else { c2 = ObjectCreationCodeGen.GetColorString(Color.White); } sb.Append(string.Format(CultureInfo.InvariantCulture, "background-image:-ms-linear-gradient({0}deg, {1}, {2});", wb.Box.GradientAngle, c1, c2)); sb.Append(string.Format(CultureInfo.InvariantCulture, "background-image:-o-linear-gradient({0}deg, {1}, {2});", wb.Box.GradientAngle, c1, c2)); sb.Append(string.Format(CultureInfo.InvariantCulture, "background-image:-moz-linear-gradient({0}deg, {1}, {2});", wb.Box.GradientAngle, c1, c2)); sb.Append(string.Format(CultureInfo.InvariantCulture, "background-image:-webkit-linear-gradient({0}deg, {1}, {2});", wb.Box.GradientAngle, c1, c2)); } } IScrollableWebControl sw = c as IScrollableWebControl; if (sw != null) { if (sw.Overflow != EnumOverflow.visible) { sb.Append(string.Format(CultureInfo.InvariantCulture, "overflow:{0};", sw.Overflow)); } } if (c.RightToLeft == RightToLeft.Yes) { sb.Append("direction:rtl;"); } if (positionType != EnumWebElementPositionType.Auto) { if (positionType == EnumWebElementPositionType.Absolute) { sb.Append("position: absolute; "); Point pointForm = c.Location; sb.Append("left:"); sb.Append(pointForm.X.ToString(CultureInfo.InvariantCulture)); sb.Append("px; "); sb.Append("top:"); sb.Append(pointForm.Y.ToString(CultureInfo.InvariantCulture)); sb.Append("px; "); } else if (positionType == EnumWebElementPositionType.Relative) { sb.Append("position: relative; "); sb.Append("left:"); sb.Append(c.Left.ToString(CultureInfo.InvariantCulture)); sb.Append("px; "); // sb.Append("top:"); sb.Append(c.Top.ToString(CultureInfo.InvariantCulture)); sb.Append("px; "); } else if (positionType == EnumWebElementPositionType.FloatLeft) { sb.Append("float:left; "); } else if (positionType == EnumWebElementPositionType.FloatRight) { sb.Append("float:right; "); } else if (positionType == EnumWebElementPositionType.FloatCenter) { sb.Append("float:center; "); } } IWebClientControl wc = c as IWebClientControl; if (wc != null) { if (wc.Opacity < 100) { sb.Append(string.Format(CultureInfo.InvariantCulture, "opacity:{0};filter:alpha(opacity={1}); ", ((double)wc.Opacity / (double)100).ToString("#.##", CultureInfo.InvariantCulture), wc.Opacity)); } } }
public static void CreateElementAnchor(IWebClientControl c, XmlNode node) { bool bUseAnchor = false; StringBuilder sb = new StringBuilder(); if ((c.PositionAnchor & AnchorStyles.Left) == AnchorStyles.Left) { sb.Append("left,"); } if ((c.PositionAnchor & AnchorStyles.Bottom) == AnchorStyles.Bottom) { sb.Append("bottom,"); bUseAnchor = true; } if ((c.PositionAnchor & AnchorStyles.Right) == AnchorStyles.Right) { sb.Append("right,"); bUseAnchor = true; } if ((c.PositionAnchor & AnchorStyles.Top) == AnchorStyles.Top) { sb.Append("top,"); } if (!bUseAnchor) { switch (c.PositionAlignment) { case ContentAlignment.BottomCenter: sb.Append("bottomcenter"); break; case ContentAlignment.BottomLeft: sb.Append("leftbottom"); break; case ContentAlignment.BottomRight: sb.Append("bottomright"); break; case ContentAlignment.MiddleCenter: sb.Append("center"); break; case ContentAlignment.MiddleLeft: sb.Append("leftcenter"); break; case ContentAlignment.MiddleRight: sb.Append("centerright"); break; case ContentAlignment.TopCenter: sb.Append("topcenter"); break; case ContentAlignment.TopRight: sb.Append("topright"); break; } } if (sb.Length > 0) { string anchor = sb.ToString(); if (string.CompareOrdinal(anchor, "left,top,") != 0) { XmlUtil.SetAttribute(node, "anchor", anchor); } } }
public static void CreateElementPosition(Control c, StringBuilder sb, EnumWebElementPositionType positionType) { IWebClientControl wcc = c as IWebClientControl; if (wcc != null) { if (wcc.textAlign != EnumTextAlign.left) { sb.Append(string.Format(CultureInfo.InvariantCulture, "text-align:{0};", wcc.textAlign)); } } IScrollableWebControl sw = c as IScrollableWebControl; if (sw != null) { if (sw.Overflow != EnumOverflow.visible) { sb.Append(string.Format(CultureInfo.InvariantCulture, "overflow:{0};", sw.Overflow)); } } if (c.RightToLeft == RightToLeft.Yes) { sb.Append("direction:rtl;"); } if (positionType != EnumWebElementPositionType.Auto) { if (positionType == EnumWebElementPositionType.Absolute) { sb.Append("position: absolute; "); //Form f = c.FindForm(); //if (f != null) //{ //Point pointScreen = c.PointToScreen(c.Location); //Point pointForm = f.PointToClient(pointScreen); Point pointForm = c.Location; sb.Append("left:"); sb.Append(pointForm.X.ToString(CultureInfo.InvariantCulture)); sb.Append("px; "); // sb.Append("top:"); sb.Append(pointForm.Y.ToString(CultureInfo.InvariantCulture)); sb.Append("px; "); //} } else if (positionType == EnumWebElementPositionType.Relative) { sb.Append("position: relative; "); sb.Append("left:"); sb.Append(c.Left.ToString(CultureInfo.InvariantCulture)); sb.Append("px; "); // sb.Append("top:"); sb.Append(c.Top.ToString(CultureInfo.InvariantCulture)); sb.Append("px; "); } else if (positionType == EnumWebElementPositionType.FloatLeft) { sb.Append("float:left; "); } else if (positionType == EnumWebElementPositionType.FloatRight) { sb.Append("float:right; "); } else if (positionType == EnumWebElementPositionType.FloatCenter) { sb.Append("float:center; "); } } IWebClientControl wc = c as IWebClientControl; if (wc != null) { if (wc.Opacity < 100) { sb.Append(string.Format(CultureInfo.InvariantCulture, "opacity:{0};filter:alpha(opacity={1}); ", ((double)wc.Opacity / (double)100).ToString("#.##", CultureInfo.InvariantCulture), wc.Opacity)); } } }