/// <include file='doc\HtmlLabelAdapter.uex' path='docs/doc[@for="HtmlLabelAdapter.Render"]/*' /> public override void Render(HtmlMobileTextWriter writer) { writer.EnterStyle(Style); if( (writer.BeforeFirstControlWritten) && (Device.RequiresLeadingPageBreak) && (String.IsNullOrEmpty(Control.Text) || WhiteSpace(Control.Text) ) ) { writer.WriteBreak(); } else { writer.WriteText(Control.Text, true); } writer.ExitStyle(Style, Control.BreakAfter); }
public override void Render(HtmlMobileTextWriter writer) { writer.EnterStyle(Style); if ((writer.BeforeFirstControlWritten) && (Device.RequiresLeadingPageBreak) && ((Control.Text == String.Empty) || WhiteSpace(Control.Text))) { writer.WriteBreak(); } else { writer.WriteText(Control.Text, true); } writer.ExitStyle(Style, Control.BreakAfter); }
/// <include file='doc\ChtmlSelectionListAdapter.uex' path='docs/doc[@for="ChtmlSelectionListAdapter.Render"]/*' /> public override void Render(HtmlMobileTextWriter writer) { ListSelectType selectType = Control.SelectType; if (selectType == ListSelectType.MultiSelectListBox && Device.SupportsSelectMultiple == false) { // Render occurs after SaveViewState. Here we make a temp // change which is not persisted to the view state. Control.SelectType = selectType = ListSelectType.CheckBox; } if (!Device.RequiresUniqueHtmlCheckboxNames || selectType != ListSelectType.CheckBox) { base.Render(writer); } else { MobileListItemCollection items = Control.Items; if (items.Count == 0) { return; } writer.EnterStyle(Style); bool writeBreak = false; foreach (MobileListItem item in items) { int index = items.IndexOf(item); if(writeBreak) { writer.WriteBreak(); } writer.Write("<input type=\"checkbox\" name=\""); if(Device.RequiresAttributeColonSubstitution) { writer.Write(Control.UniqueID.Replace(':', ',')); } else { writer.Write(Control.UniqueID); } writer.Write(Constants.SelectionListSpecialCharacter); writer.Write(index); writer.Write("\" value=\""); if (!String.IsNullOrEmpty(Control.Form.Action)) { writer.WriteEncodedText(item.Value); } else { writer.Write(item.Index.ToString(CultureInfo.InvariantCulture)); } if (item.Selected && Device.SupportsUncheck) { writer.Write("\" checked>"); } else { writer.Write("\">"); } writer.WriteText(item.Text, true); writeBreak = true; } writer.ExitStyle(Style, Control.BreakAfter); } }
/// <include file='doc\HtmlSelectionListAdapter.uex' path='docs/doc[@for="HtmlSelectionListAdapter.Render"]/*' /> public override void Render(HtmlMobileTextWriter writer) { MobileListItemCollection items = Control.Items; ListSelectType selectType = Control.SelectType; if (items.Count == 0 && selectType != ListSelectType.ListBox && selectType != ListSelectType.MultiSelectListBox) { return; } int selectedIndex = Control.SelectedIndex; String renderName; if (Device.RequiresAttributeColonSubstitution) { renderName = Control.UniqueID.Replace(':', ','); } else { renderName = Control.UniqueID; } switch (selectType) { case ListSelectType.DropDown: case ListSelectType.ListBox: case ListSelectType.MultiSelectListBox: if (items.Count == 0 && !Device.CanRenderEmptySelects) { break; } writer.EnterLayout(Style); writer.WriteBeginTag("select"); if (selectType == ListSelectType.MultiSelectListBox) { writer.Write(" multiple"); } if (selectType == ListSelectType.ListBox || selectType == ListSelectType.MultiSelectListBox) { writer.WriteAttribute("size", Control.Rows.ToString(CultureInfo.InvariantCulture)); } writer.WriteAttribute("name", renderName); writer.Write(">"); for (int itemIndex = 0; itemIndex < items.Count; itemIndex++) { MobileListItem item = items[itemIndex]; writer.WriteBeginTag("option"); WriteItemValueAttribute(writer, itemIndex, item.Value); if (item.Selected && (Control.IsMultiSelect || itemIndex == selectedIndex)) { writer.Write(" selected>"); } else { writer.Write(">"); } writer.WriteEncodedText(item.Text); writer.WriteLine(""); } writer.Write("</select>"); if (Device.HidesRightAlignedMultiselectScrollbars && selectType == ListSelectType.MultiSelectListBox) { // nested if for perf if ((Alignment)Style[Style.AlignmentKey, true] == Alignment.Right) { writer.Write(" "); } } writer.WriteLine(""); if (!Page.DesignMode) { writer.ExitLayout(Style, Control.BreakAfter); } else { writer.ExitLayout(Style, false); } break; case ListSelectType.Radio: case ListSelectType.CheckBox: String selectTypeString = (selectType == ListSelectType.Radio) ? "radio" : "checkbox"; Alignment alignment = (Alignment)Style[Style.AlignmentKey, true]; if (!Device.Tables || alignment == Alignment.Left || alignment == Alignment.NotSet) { writer.EnterStyle(Style); bool breakAfter = false; for (int itemIndex = 0; itemIndex < items.Count; itemIndex++) { if (breakAfter) { writer.WriteBreak(); } MobileListItem item = items[itemIndex]; writer.WriteBeginTag("input"); writer.WriteAttribute("type", selectTypeString); writer.WriteAttribute("name", renderName); WriteItemValueAttribute(writer, itemIndex, item.Value); if (item.Selected && (Control.IsMultiSelect || itemIndex == selectedIndex) && Device.SupportsUncheck) { writer.Write(" checked>"); } else { writer.Write(">"); } writer.WriteEncodedText(item.Text); breakAfter = true; } writer.ExitStyle(Style, Control.BreakAfter); } else // Device supports tables and alignment is non default. { Wrapping wrapping = (Wrapping)Style[Style.WrappingKey, true]; bool nowrap = (wrapping == Wrapping.NoWrap); writer.EnterLayout(Style); writer.WriteFullBeginTag("table"); writer.BeginStyleContext(); for (int itemIndex = 0; itemIndex < items.Count; itemIndex++) { MobileListItem item = items[itemIndex]; writer.WriteFullBeginTag("tr"); writer.WriteBeginTag("td"); if (nowrap) { writer.WriteAttribute("nowrap", "true"); } writer.Write(">"); writer.WriteBeginTag("input"); writer.WriteAttribute("type", selectTypeString); writer.WriteAttribute("name", renderName); WriteItemValueAttribute(writer, itemIndex, item.Value); if (item.Selected && (Control.IsMultiSelect || itemIndex == selectedIndex) && Device.SupportsUncheck) { writer.Write(" checked>"); } else { writer.Write(">"); } writer.MarkStyleContext(); writer.EnterFormat(Style); writer.WriteEncodedText(item.Text); writer.ExitFormat(Style); writer.UnMarkStyleContext(); writer.WriteEndTag("td"); writer.WriteEndTag("tr"); } writer.WriteEndTag("table"); writer.EndStyleContext(); writer.ExitFormat(Style, Control.BreakAfter); } break; } }
/// <include file='doc\ChtmlSelectionListAdapter.uex' path='docs/doc[@for="ChtmlSelectionListAdapter.Render"]/*' /> public override void Render(HtmlMobileTextWriter writer) { ListSelectType selectType = Control.SelectType; if (selectType == ListSelectType.MultiSelectListBox && Device.SupportsSelectMultiple == false) { // Render occurs after SaveViewState. Here we make a temp // change which is not persisted to the view state. Control.SelectType = selectType = ListSelectType.CheckBox; } if (!Device.RequiresUniqueHtmlCheckboxNames || selectType != ListSelectType.CheckBox) { base.Render(writer); } else { MobileListItemCollection items = Control.Items; if (items.Count == 0) { return; } writer.EnterStyle(Style); bool writeBreak = false; foreach (MobileListItem item in items) { int index = items.IndexOf(item); if (writeBreak) { writer.WriteBreak(); } writer.Write("<input type=\"checkbox\" name=\""); if (Device.RequiresAttributeColonSubstitution) { writer.Write(Control.UniqueID.Replace(':', ',')); } else { writer.Write(Control.UniqueID); } writer.Write(Constants.SelectionListSpecialCharacter); writer.Write(index); writer.Write("\" value=\""); if (!String.IsNullOrEmpty(Control.Form.Action)) { writer.WriteEncodedText(item.Value); } else { writer.Write(item.Index.ToString(CultureInfo.InvariantCulture)); } if (item.Selected && Device.SupportsUncheck) { writer.Write("\" checked>"); } else { writer.Write("\">"); } writer.WriteText(item.Text, true); writeBreak = true; } writer.ExitStyle(Style, Control.BreakAfter); } }
/// <include file='doc\ChtmlCalendarAdapter.uex' path='docs/doc[@for="ChtmlCalendarAdapter.Render"]/*' /> public override void Render(HtmlMobileTextWriter writer) { ArrayList arr; DateTime tempDate; DateTimeFormatInfo currentDateTimeInfo = DateTimeFormatInfo.CurrentInfo; String abbreviatedMonthDayPattern = AbbreviateMonthPattern(currentDateTimeInfo.MonthDayPattern); _threadCalendar = currentDateTimeInfo.Calendar; bool breakAfter = false; writer.EnterStyle(Style); Debug.Assert(NotSecondaryUI == NotSecondaryUIInit); switch (SecondaryUIMode) { case FirstPrompt: String promptText = Control.CalendarEntryText; if (String.IsNullOrEmpty(promptText)) { promptText = SR.GetString(SR.CalendarAdapterFirstPrompt); } // Link to input option selection screen RenderPostBackEventAsAnchor(writer, OptionPrompt.ToString(CultureInfo.InvariantCulture), promptText); // We should honor BreakAfter property here as the first // UI is shown with other controls on the same form. // For other secondary UI, it is not necessary. if (Control.BreakAfter) { breakAfter = true; } break; // Render the first secondary page that provides differnt // options to select a date. case OptionPrompt: writer.Write(SR.GetString(SR.CalendarAdapterOptionPrompt)); writer.WriteBreak(); arr = new ArrayList(); // Option to select the default date arr.Add(Control.VisibleDate.ToString( currentDateTimeInfo.ShortDatePattern, CultureInfo.CurrentCulture)); // Option to another page that can enter a date by typing arr.Add(SR.GetString(SR.CalendarAdapterOptionType)); // Options to a set of pages for selecting a date, a week // or a month by picking month/year, week and day // accordingly. Available options are determined by // SelectionMode. arr.Add(SR.GetString(SR.CalendarAdapterOptionChooseDate)); if (Control.SelectionMode == CalendarSelectionMode.DayWeek || Control.SelectionMode == CalendarSelectionMode.DayWeekMonth) { arr.Add(SR.GetString(SR.CalendarAdapterOptionChooseWeek)); if (Control.SelectionMode == CalendarSelectionMode.DayWeekMonth) { arr.Add(SR.GetString(SR.CalendarAdapterOptionChooseMonth)); } } DataBindAndRender(writer, _optionList, arr); break; // Render a title and textbox to capture a date entered by user case TypeDate: if (_textBoxErrorMessage != null) { writer.Write(_textBoxErrorMessage); writer.WriteBreak(); } if (_selectList.Visible) { writer.Write(SR.GetString(SR.CalendarAdapterOptionEra)); writer.WriteBreak(); _selectList.RenderControl(writer); } String numericDateFormat = GetNumericDateFormat(); writer.Write(SR.GetString(SR.CalendarAdapterOptionType)); writer.Write(":"); writer.WriteBreak(); writer.Write("("); writer.Write(numericDateFormat.ToUpper(CultureInfo.InvariantCulture)); writer.Write(")"); if (!_selectList.Visible) { writer.Write(GetEra(Control.VisibleDate)); } writer.WriteBreak(); _textBox.Numeric = true; _textBox.Size = numericDateFormat.Length; _textBox.MaxLength = numericDateFormat.Length; _textBox.Text = Control.VisibleDate.ToString(numericDateFormat, CultureInfo.InvariantCulture); _textBox.Visible = true; _textBox.RenderControl(writer); // Command button for sending the textbox value back to the server _command.Text = GetDefaultLabel(OKLabel); _command.Visible = true; _command.RenderControl(writer); break; // Render a paged list for choosing a month case ChooseMonth: writer.Write(SR.GetString(SR.CalendarAdapterOptionChooseMonth)); writer.Write(":"); writer.WriteBreak(); tempDate = Control.VisibleDate; String abbreviatedYearMonthPattern = AbbreviateMonthPattern(currentDateTimeInfo.YearMonthPattern); // This is to be consistent with ASP.NET Calendar control // on handling YearMonthPattern: // Some cultures have a comma in their YearMonthPattern, // which does not look right in a calendar. Here we // strip the comma off. int indexComma = abbreviatedYearMonthPattern.IndexOf(','); if (indexComma >= 0) { abbreviatedYearMonthPattern = abbreviatedYearMonthPattern.Remove(indexComma, 1); } arr = new ArrayList(); for (int i = 0; i < _monthsToDisplay; i++) { arr.Add(tempDate.ToString(abbreviatedYearMonthPattern, CultureInfo.CurrentCulture)); tempDate = _threadCalendar.AddMonths(tempDate, 1); } arr.Add(GetDefaultLabel(NextLabel)); arr.Add(GetDefaultLabel(PreviousLabel)); DataBindAndRender(writer, _monthList, arr); break; // Based on the month selected in case ChooseMonth above, render a list of // availabe weeks of the month. case ChooseWeek: String monthFormat = (GetNumericDateFormat()[0] == 'y') ? "yyyy/M" : "M/yyyy"; writer.Write(SR.GetString(SR.CalendarAdapterOptionChooseWeek)); writer.Write(" ("); writer.Write(Control.VisibleDate.ToString(monthFormat, CultureInfo.CurrentCulture)); writer.Write("):"); writer.WriteBreak(); // List weeks of days of the selected month. May include // days from the previous and the next month to fill out // all six week choices. This is consistent with the // ASP.NET Calendar control. // Note that the event handling code of this list control // should be implemented according to the index content // generated here. tempDate = FirstCalendarDay(Control.VisibleDate); arr = new ArrayList(); String weekDisplay; for (int i = 0; i < 6; i++) { weekDisplay = tempDate.ToString(abbreviatedMonthDayPattern, CultureInfo.CurrentCulture); weekDisplay += DaySeparator; tempDate = _threadCalendar.AddDays(tempDate, 6); weekDisplay += tempDate.ToString(abbreviatedMonthDayPattern, CultureInfo.CurrentCulture); arr.Add(weekDisplay); tempDate = _threadCalendar.AddDays(tempDate, 1); } DataBindAndRender(writer, _weekList, arr); break; // Based on the month and week selected in case ChooseMonth and ChooseWeek above, // render a list of the dates in the week. case ChooseDay: writer.Write(SR.GetString(SR.CalendarAdapterOptionChooseDate)); writer.Write(":"); writer.WriteBreak(); tempDate = Control.VisibleDate; arr = new ArrayList(); String date; String dayName; StringBuilder dayDisplay = new StringBuilder(); bool dayNameFirst = (GetNumericDateFormat()[0] != 'y'); for (int i = 0; i < 7; i++) { date = tempDate.ToString(abbreviatedMonthDayPattern, CultureInfo.CurrentCulture); if (Control.ShowDayHeader) { // Use the short format for displaying day name dayName = GetAbbreviatedDayName(tempDate); dayDisplay.Length = 0; if (dayNameFirst) { dayDisplay.Append(dayName); dayDisplay.Append(Space); dayDisplay.Append(date); } else { dayDisplay.Append(date); dayDisplay.Append(Space); dayDisplay.Append(dayName); } arr.Add(dayDisplay.ToString()); } else { arr.Add(date); } tempDate = _threadCalendar.AddDays(tempDate, 1); } DataBindAndRender(writer, _dayList, arr); break; default: Debug.Assert(false, "Unexpected Secondary UI Mode"); break; } writer.ExitStyle(Style, breakAfter); }
private void RenderItemDetailsWithoutTableTags(HtmlMobileTextWriter writer, ObjectListItem item) { Style style = this.Style; Style labelStyle = Control.LabelStyle; Style subCommandStyle = Control.CommandStyle; writer.EnterStyle(labelStyle); writer.WriteText(item[Control.LabelFieldIndex], true); writer.ExitStyle(labelStyle, true); IObjectListFieldCollection fields = Control.AllFields; int fieldIndex = 0; bool boldInStyle = (style.Font.Bold == BooleanOption.True) ? true : false; writer.EnterStyle(style); foreach (ObjectListField field in fields) { if (field.Visible) { if (!boldInStyle) { writer.Write("<b>"); } writer.WriteText(field.Title + ":", true); if (!boldInStyle) { writer.Write("</b>"); } writer.Write(" "); writer.WriteText(item[fieldIndex], true); writer.WriteBreak(); } fieldIndex++; } writer.ExitStyle(style); BooleanOption cachedItalic = subCommandStyle.Font.Italic; subCommandStyle.Font.Italic = BooleanOption.False; writer.EnterStyle(subCommandStyle); writer.Write("[ "); writer.ExitStyle(subCommandStyle); subCommandStyle.Font.Italic = cachedItalic; writer.EnterStyle(subCommandStyle); ObjectListCommandCollection commands = Control.Commands; foreach (ObjectListCommand command in commands) { RenderPostBackEventAsAnchor(writer, command.Name, command.Text, subCommandStyle); writer.Write(" | "); } String backCommandText = Control.BackCommandText.Length == 0 ? GetDefaultLabel(BackLabel) : Control.BackCommandText; RenderPostBackEventAsAnchor(writer, BackToList, backCommandText, subCommandStyle); writer.ExitStyle(subCommandStyle); subCommandStyle.Font.Italic = BooleanOption.False; writer.EnterStyle(subCommandStyle); writer.Write(" ]"); writer.ExitStyle(subCommandStyle, Control.BreakAfter); subCommandStyle.Font.Italic = cachedItalic; }
private void RenderItemsListWithoutTableTags(HtmlMobileTextWriter writer) { int startIndex = Control.FirstVisibleItemIndex; int pageSize = Control.VisibleItemCount; ObjectListItemCollection items = Control.Items; IObjectListFieldCollection allFields = Control.AllFields; int count = allFields.Count; int nextStartIndex = startIndex + pageSize; int labelFieldIndex = Control.LabelFieldIndex; Style style = this.Style; Style labelStyle = Control.LabelStyle; writer.EnterStyle(labelStyle); writer.WriteText(Control.AllFields[labelFieldIndex].Title, true); writer.ExitStyle(labelStyle, true); bool hasDefaultCommand = HasDefaultCommand(); bool onlyHasDefaultCommand = OnlyHasDefaultCommand(); bool requiresDetailsScreen = !onlyHasDefaultCommand && HasCommands(); // if there is > 1 visible field, need a details screen for (int visibleFields = 0, i = 0; !requiresDetailsScreen && i < count; i++) { visibleFields += allFields[i].Visible ? 1 : 0; requiresDetailsScreen = requiresDetailsScreen || visibleFields > 1; } bool itemRequiresHyperlink = requiresDetailsScreen || hasDefaultCommand; bool itemRequiresMoreButton = requiresDetailsScreen && hasDefaultCommand; Style subCommandStyle = Control.CommandStyle; subCommandStyle.Alignment = style.Alignment; subCommandStyle.Wrapping = style.Wrapping; writer.EnterStyle(style); for (int i = startIndex; i < nextStartIndex; i++) { ObjectListItem item = items[i]; if (itemRequiresHyperlink) { RenderPostBackEventAsAnchor(writer, hasDefaultCommand ? item.Index.ToString(CultureInfo.InvariantCulture) : String.Format(CultureInfo.InvariantCulture, ShowMoreFormat, item.Index), item[labelFieldIndex]); } else { writer.WriteText(item[labelFieldIndex], true); } if (itemRequiresMoreButton) { BooleanOption cachedItalic = subCommandStyle.Font.Italic; subCommandStyle.Font.Italic = BooleanOption.False; writer.EnterFormat(subCommandStyle); writer.Write(" ["); writer.ExitFormat(subCommandStyle); subCommandStyle.Font.Italic = cachedItalic; writer.EnterFormat(subCommandStyle); String moreText = Control.MoreText.Length == 0 ? GetDefaultLabel(MoreLabel) : Control.MoreText; writer.WriteBeginTag("a"); RenderPostBackEventAsAttribute(writer, "href", String.Format(CultureInfo.InvariantCulture, ShowMoreFormat, item.Index)); writer.Write(">"); writer.WriteText(moreText, true); writer.WriteEndTag("a"); writer.ExitFormat(subCommandStyle); subCommandStyle.Font.Italic = BooleanOption.False; writer.EnterFormat(subCommandStyle); writer.Write("]"); writer.ExitFormat(subCommandStyle); subCommandStyle.Font.Italic = cachedItalic; } if(i < (nextStartIndex - 1)) { writer.WriteBreak(); } } writer.ExitStyle(style, Control.BreakAfter); }
public override void Render(HtmlMobileTextWriter writer) { writer.EnterStyle(Style); IPanelPane activePane = Control.ActivePane; writer.Write("[ "); int index = 0; foreach (IPanelPane child in Control.Controls) { if (!((Control) child).Visible) { index++; continue; } if (index > 0) { writer.Write(" | "); } if (child == activePane) { writer.Write("<b>"); writer.WriteText(child.Title, true); writer.Write("</b>"); } else { writer.WriteBeginTag("a"); RenderPostBackEventAsAttribute(writer, "href", index.ToString()); writer.Write(">"); writer.WriteText(child.Title, true); writer.WriteEndTag("a"); } index++; } writer.Write(" ]"); writer.WriteBreak(); ((Control) activePane).RenderControl(writer); writer.ExitStyle(Style); }
/// <include file='doc\HtmlCalendarAdapter.uex' path='docs/doc[@for="HtmlCalendarAdapter.Render"]/*' /> public override void Render(HtmlMobileTextWriter writer) { System.Web.UI.WebControls.WebControl webCalendar = Control.WebCalendar; Style.ApplyTo(webCalendar); // Delegate the rendering effort to the child Web Calendar // control for HTML browser webCalendar.Visible = true; // There is no explicit property for alignment on WebForms // Calendar, so we need some special code to set it. writer.EnterLayout(Style); writer.EnsureStyle(); Alignment align = (Alignment) Style[Style.AlignmentKey, true]; if (!Device.SupportsDivAlign) { webCalendar.Attributes["align"] = align.ToString(); } if (Device.SupportsCss) { // Target device supports CSS - simply delegate the rendering // to the underlying Web Calendar control webCalendar.RenderControl(writer); } else { // Insert bgcolor attributes in cells that correspond to selected dates StringWriter sw = new StringWriter(CultureInfo.InvariantCulture); HtmlTextWriter tmpWriter = new HtmlTextWriter(sw); webCalendar.RenderControl(tmpWriter); String webCalendarHtml = sw.ToString(); int index = 0, indexLastTable = 0; // Search for offset of last <table> tag in the Web Calendar HTML. // That table contains the various days. do { index = webCalendarHtml.IndexOf(_selectedDateSearchTableTag, index, StringComparison.Ordinal); if (index >= 0) { indexLastTable = index; index += 5; } } while (index >= 0); index = LocateNextSelectedDate(webCalendarHtml, indexLastTable); if (index >= 0) { // Determine the background color of the containing Form control HtmlControlAdapter formAdapter = (HtmlControlAdapter) Control.Form.Adapter; Color backColor = (Color)formAdapter.Style[Style.BackColorKey, true]; int deltaR = System.Math.Abs(backColor.R - 0xC0); int deltaG = System.Math.Abs(backColor.G - 0xC0); int deltaB = System.Math.Abs(backColor.B - 0xC0); // Determine the distance between Silver and the Form's background color int bgColorDistance = deltaR * deltaR + deltaG * deltaG + deltaB * deltaB; // Choose Silver or White depending on that distance String selectedDateBGColor = String.Format(CultureInfo.CurrentCulture, "bgcolor=\"{0}\" ", bgColorDistance < _bgColorDistanceTreshold ? "White" : "Silver"); while (index >= 0) { // Insert the bgcolor attribute for each selected date cell webCalendarHtml = webCalendarHtml.Insert(index + _bgColorInsertionPointInPattern, selectedDateBGColor); index = LocateNextSelectedDate(webCalendarHtml, index + _bgColorInsertionPointInPattern); } } // Use the HTML after insertions writer.Write(webCalendarHtml); } if(Control.BreakAfter) { writer.WriteBreak(); } writer.ExitLayout(Style); }
/// <include file='doc\HtmlSelectionListAdapter.uex' path='docs/doc[@for="HtmlSelectionListAdapter.Render"]/*' /> public override void Render(HtmlMobileTextWriter writer) { MobileListItemCollection items = Control.Items; ListSelectType selectType = Control.SelectType; if (items.Count == 0 && selectType != ListSelectType.ListBox && selectType != ListSelectType.MultiSelectListBox) { return; } int selectedIndex = Control.SelectedIndex; String renderName; if(Device.RequiresAttributeColonSubstitution) { renderName = Control.UniqueID.Replace(':', ','); } else { renderName = Control.UniqueID; } switch(selectType) { case ListSelectType.DropDown: case ListSelectType.ListBox: case ListSelectType.MultiSelectListBox: if (items.Count == 0 && !Device.CanRenderEmptySelects) { break; } writer.EnterLayout(Style); writer.WriteBeginTag("select"); if (selectType == ListSelectType.MultiSelectListBox) { writer.Write(" multiple"); } if (selectType == ListSelectType.ListBox || selectType == ListSelectType.MultiSelectListBox) { writer.WriteAttribute("size", Control.Rows.ToString(CultureInfo.InvariantCulture)); } writer.WriteAttribute("name", renderName); writer.Write(">"); for(int itemIndex = 0; itemIndex < items.Count; itemIndex++) { MobileListItem item = items[itemIndex]; writer.WriteBeginTag("option"); WriteItemValueAttribute(writer, itemIndex, item.Value); if (item.Selected && (Control.IsMultiSelect || itemIndex == selectedIndex)) { writer.Write(" selected>"); } else { writer.Write(">"); } writer.WriteEncodedText(item.Text); writer.WriteLine(""); } writer.Write("</select>"); if(Device.HidesRightAlignedMultiselectScrollbars && selectType == ListSelectType.MultiSelectListBox) { // nested if for perf if((Alignment)Style[Style.AlignmentKey, true] == Alignment.Right) { writer.Write(" "); } } writer.WriteLine(""); if (!Page.DesignMode) { writer.ExitLayout(Style, Control.BreakAfter); } else { writer.ExitLayout(Style, false); } break; case ListSelectType.Radio: case ListSelectType.CheckBox: String selectTypeString = (selectType == ListSelectType.Radio) ? "radio" : "checkbox"; Alignment alignment = (Alignment)Style[Style.AlignmentKey, true]; if(!Device.Tables || alignment == Alignment.Left || alignment == Alignment.NotSet) { writer.EnterStyle(Style); bool breakAfter = false; for(int itemIndex = 0; itemIndex < items.Count; itemIndex++) { if(breakAfter) { writer.WriteBreak(); } MobileListItem item = items[itemIndex]; writer.WriteBeginTag("input"); writer.WriteAttribute("type", selectTypeString); writer.WriteAttribute("name", renderName); WriteItemValueAttribute(writer, itemIndex, item.Value); if (item.Selected && (Control.IsMultiSelect || itemIndex == selectedIndex) && Device.SupportsUncheck) { writer.Write(" checked>"); } else { writer.Write(">"); } writer.WriteEncodedText(item.Text); breakAfter = true; } writer.ExitStyle(Style, Control.BreakAfter); } else // Device supports tables and alignment is non default. { Wrapping wrapping = (Wrapping) Style[Style.WrappingKey , true]; bool nowrap = (wrapping == Wrapping.NoWrap); writer.EnterLayout(Style); writer.WriteFullBeginTag("table"); writer.BeginStyleContext(); for(int itemIndex = 0; itemIndex < items.Count; itemIndex++) { MobileListItem item = items[itemIndex]; writer.WriteFullBeginTag("tr"); writer.WriteBeginTag("td"); if(nowrap) { writer.WriteAttribute("nowrap","true"); } writer.Write(">"); writer.WriteBeginTag("input"); writer.WriteAttribute("type", selectTypeString); writer.WriteAttribute("name", renderName); WriteItemValueAttribute(writer, itemIndex, item.Value); if (item.Selected && (Control.IsMultiSelect || itemIndex == selectedIndex) && Device.SupportsUncheck) { writer.Write(" checked>"); } else { writer.Write(">"); } writer.MarkStyleContext(); writer.EnterFormat(Style); writer.WriteEncodedText(item.Text); writer.ExitFormat(Style); writer.UnMarkStyleContext(); writer.WriteEndTag("td"); writer.WriteEndTag("tr"); } writer.WriteEndTag("table"); writer.EndStyleContext(); writer.ExitFormat(Style, Control.BreakAfter); } break; } }
internal void Transition(WriterStyle newStyle, bool captureOutput) { HtmlMobileTextWriter tempWriter = _writer; try { if (!captureOutput) { tempWriter = _writer; _writer = new HtmlMobileTextWriter( new HtmlTextWriter(new StringWriter(CultureInfo.InvariantCulture)), tempWriter.Device); } if (_inTransition) { return; } else { _inTransition = true; } if (Count == 0) { while (_tagsWritten.Count > 0) { CloseTag(); } _inTransition = false; return; } //close italic if target format !italic if ((_current.Italic && !newStyle.Italic) && (_writer.RenderItalic)) { while (_current.Italic) { CloseTag(); } } //close bold if target format !bold if ((_current.Bold && !newStyle.Bold) && (_writer.RenderBold)) { while (_current.Bold) { CloseTag(); } } //if the target FontColor is Color.Empty, then we need to //close all open color tags if ( (newStyle.FontColor == Color.Empty) && (_current.FontColor != Color.Empty) && (_writer.RenderFontColor)) { while (_current.FontColor != Color.Empty) { CloseTag(); } } //if the target FontName is String.Empty, then we need to //close all open name tags if ( (newStyle.FontName != null && newStyle.FontName.Length == 0) && (_current.FontName == null || _current.FontName.Length > 0) && (_writer.RenderFontName)) { while (_current.FontName == null || _current.FontName.Length > 0) { CloseTag(); } } //close the font if it is of the same or a later generation //and differs bool newFont = FontChange(newStyle); if (newFont) { while (FontLevel >= Count) { CloseTag(); } } //if the new wrapping is Wrap, and the current is NoWrap //the outer NoWrap must be removed if ( (newStyle.Wrapping == Wrapping.Wrap) && (_current.Wrapping == Wrapping.NoWrap) && (_writer.RenderDivNoWrap)) { while (_current.Wrapping != Wrapping.Wrap) { CloseTag(); } } //if the alignment differs for the same generation, close any divs at this level if ((newStyle.Alignment != _current.Alignment) && (_writer.RenderDivAlign)) { while (DivLevel >= Count) { CloseTag(); } } //determine if we will be opening a div before writing any break bool newDiv = DivChange(newStyle); //an opening div will function as a logical break if ((BreakPending) && (!(newDiv))) { ((HtmlMobileTextWriter)_writer).WriteBreak(); BreakPending = false; } if (newDiv) { while (_current.Bold || _current.Italic || (FontLevel == Count)) { CloseTag(); } } newFont = FontChange(newStyle); newDiv = DivChange(newStyle); //open div if (newDiv && newStyle.Layout) { DivStyleTag div = new DivStyleTag(Count); BreakPending = false; if ( ((_writer.BeforeFirstControlWritten) || (_writer.InputWritten)) && (_writer.Device.Type == _pocketPC) && (_writer.Device.MinorVersion == 0) && (_writer.Device.MajorVersion == 4) && (newStyle.Alignment != _current.Alignment)) { _writer.WriteBreak(); _writer.InputWritten = false; } _writer.WriteBeginTag("div"); DivLevel = Count; if (newStyle.Wrapping == Wrapping.NoWrap) { if (_writer.RenderDivNoWrap) { _writer.Write(" nowrap"); } div.Wrapping = Wrapping.NoWrap; _current.Wrapping = Wrapping.NoWrap; } else { div.Wrapping = Wrapping.Wrap; _current.Wrapping = Wrapping.Wrap; } if (newStyle.Alignment != _current.Alignment) { if (_writer.RenderDivAlign) { _writer.WriteAttribute( "align", Enum.GetName(typeof(Alignment), newStyle.Alignment)); } _current.Alignment = newStyle.Alignment; div.Alignment = newStyle.Alignment; div.AlignmentWritten = true; } _tagsWritten.Push(div); _writer.Write(">"); } //open font if (newFont && newStyle.Format) { FontStyleTag fontTag = new FontStyleTag(Count); _writer.WriteBeginTag("font"); if (_current.FontSize != newStyle.FontSize) { String relativeSize; if (newStyle.FontSize == FontSize.Large) { relativeSize = ( ((HtmlMobileTextWriter)_writer).Device.Type == _pocketPC) ? "+2" : "+1"; _current.FontSize = FontSize.Large; fontTag.FontSize = FontSize.Large; } else if (newStyle.FontSize == FontSize.Small) { relativeSize = "-1"; _current.FontSize = FontSize.Small; fontTag.FontSize = FontSize.Small; } else //(newStyle.FontSize == FontSize.Normal) { relativeSize = "+0"; _current.FontSize = FontSize.Normal; fontTag.FontSize = FontSize.Normal; } if (_writer.RenderFontSize) { _writer.WriteAttribute("size", relativeSize); } } if (_current.FontColor != newStyle.FontColor) { if (_writer.RenderFontColor) { _writer.WriteAttribute( "color", ColorTranslator.ToHtml(newStyle.FontColor)); } _current.FontColor = newStyle.FontColor; fontTag.Color = newStyle.FontColor; } if (_current.FontName != newStyle.FontName) { if (_writer.RenderFontName) { _writer.WriteAttribute("face", newStyle.FontName); } _current.FontName = newStyle.FontName; fontTag.Name = newStyle.FontName; } _writer.Write(">"); _tagsWritten.Push(fontTag); FontLevel = Count; } //open bold if (newStyle.Format) { if (newStyle.Bold && !_current.Bold && _writer.RenderBold) { _writer.WriteFullBeginTag("b"); _current.Bold = true; _tagsWritten.Push(new BoldStyleTag(Count)); } //open italic if (newStyle.Italic && !_current.Italic && _writer.RenderItalic) { _writer.WriteFullBeginTag("i"); _current.Italic = true; _tagsWritten.Push(new ItalicStyleTag(Count)); } } _inTransition = false; } finally { _writer = tempWriter; } }
public override void Render(HtmlMobileTextWriter writer) { System.Web.UI.WebControls.WebControl webCalendar = Control.WebCalendar; Style.ApplyTo(webCalendar); // Delegate the rendering effort to the child Web Calendar // control for HTML browser webCalendar.Visible = true; // There is no explicit property for alignment on WebForms // Calendar, so we need some special code to set it. writer.EnterLayout(Style); writer.EnsureStyle(); Alignment align = (Alignment)Style[Style.AlignmentKey, true]; if (!Device.SupportsDivAlign) { webCalendar.Attributes["align"] = align.ToString(); } if (Device.SupportsCss) { // Target device supports CSS - simply delegate the rendering // to the underlying Web Calendar control webCalendar.RenderControl(writer); } else { // Insert bgcolor attributes in cells that correspond to selected dates StringWriter sw = new StringWriter(); HtmlTextWriter tmpWriter = new HtmlTextWriter(sw); webCalendar.RenderControl(tmpWriter); String webCalendarHtml = sw.ToString(); int index = 0, indexLastTable = 0; // Search for offset of last <table> tag in the Web Calendar HTML. // That table contains the various days. do { index = webCalendarHtml.IndexOf(_selectedDateSearchTableTag, index); if (index >= 0) { indexLastTable = index; index += 5; } }while (index >= 0); index = LocateNextSelectedDate(webCalendarHtml, indexLastTable); if (index >= 0) { // Determine the background color of the containing Form control HtmlControlAdapter formAdapter = (HtmlControlAdapter)Control.Form.Adapter; Color backColor = (Color)formAdapter.Style[Style.BackColorKey, true]; int deltaR = System.Math.Abs(backColor.R - 0xC0); int deltaG = System.Math.Abs(backColor.G - 0xC0); int deltaB = System.Math.Abs(backColor.B - 0xC0); // Determine the distance between Silver and the Form's background color int bgColorDistance = deltaR * deltaR + deltaG * deltaG + deltaB * deltaB; // Choose Silver or White depending on that distance String selectedDateBGColor = String.Format("bgcolor=\"{0}\" ", bgColorDistance < _bgColorDistanceTreshold ? "White" : "Silver"); while (index >= 0) { // Insert the bgcolor attribute for each selected date cell webCalendarHtml = webCalendarHtml.Insert(index + _bgColorInsertionPointInPattern, selectedDateBGColor); index = LocateNextSelectedDate(webCalendarHtml, index + _bgColorInsertionPointInPattern); } } // Use the HTML after insertions writer.Write(webCalendarHtml); } if (Control.BreakAfter) { writer.WriteBreak(); } writer.ExitLayout(Style); }
//********************************************************************* // // HtmlTabbedPanelAdapter.Render Method // // Renders the control. The TabbedPanel is rendered as one or more // rows of tabs that the user can click on to move between tabs. // //********************************************************************* public override void Render(HtmlMobileTextWriter writer) { IPanelPane activePane = Control.ActivePane; int tabsPerRow = Control.TabsPerRow; PanelPaneCollection panes = Control.Panes; int paneCount = panes.Count; // Figure out the number of visible panes. int[] visiblePanes = new int[paneCount]; int visiblePaneCount = 0; for (int i = 0; i < paneCount; i++) { if (((Control) panes[i]).Visible) { visiblePanes[visiblePaneCount++] = i; } } // Calculate how many rows are necessary. int rows = (visiblePaneCount + tabsPerRow - 1)/tabsPerRow; // make sure tabsPerRow doesn't exceed the number of visible panes tabsPerRow = (Control.TabsPerRow > visiblePaneCount) ? visiblePaneCount : Control.TabsPerRow; // Open the table. writer.WriteBeginTag("table"); writer.WriteAttribute("cellspacing", "0"); writer.WriteAttribute("cellpadding", "2"); writer.WriteAttribute("border", "0"); writer.WriteLine(">"); for (int row = rows - 1; row >= 0; row--) { writer.WriteFullBeginTag("tr"); writer.WriteLine(); for (int col = 0; col < tabsPerRow; col++) { writer.WriteBeginTag("td"); writer.WriteAttribute("width", "0"); writer.Write(">"); writer.WriteEndTag("td"); int i = row*tabsPerRow + col; if (row > 0 && i >= visiblePaneCount) { writer.WriteFullBeginTag("td"); writer.WriteEndTag("td"); continue; } int index = visiblePanes[i]; IPanelPane child = panes[index]; if (child == activePane) { writer.WriteBeginTag("td"); writer.WriteAttribute("bgcolor", GetColorString(Control.ActiveTabColor, "#333333")); writer.Write(">"); writer.WriteBeginTag("font"); writer.WriteAttribute("face", "Verdana"); writer.WriteAttribute("size", "-2"); writer.WriteAttribute("color", GetColorString(Control.ActiveTabTextColor, "#000000")); writer.Write(">"); writer.WriteFullBeginTag("b"); writer.Write(" "); writer.WriteText(child.Title, true); writer.Write(" "); writer.WriteEndTag("b"); writer.WriteEndTag("font"); writer.WriteEndTag("td"); writer.WriteLine(); } else { writer.WriteBeginTag("td"); writer.WriteAttribute("bgcolor", GetColorString(Control.TabColor, "#cccccc")); writer.Write(">"); writer.WriteBeginTag("font"); writer.WriteAttribute("face", "Verdana"); writer.WriteAttribute("size", "-2"); writer.WriteAttribute("color", GetColorString(Control.TabTextColor, "#000000")); writer.Write(">"); writer.Write(" "); writer.WriteBeginTag("a"); RenderPostBackEventAsAttribute(writer, "href", index.ToString()); writer.Write(">"); writer.WriteText(child.Title, true); writer.WriteEndTag("a"); writer.Write(" "); writer.WriteEndTag("font"); writer.WriteEndTag("td"); writer.WriteLine(); } } writer.WriteEndTag("tr"); writer.WriteLine(); if (row > 0) { writer.WriteFullBeginTag("tr"); writer.WriteBeginTag("td"); writer.WriteAttribute("height", "1"); writer.Write(">"); writer.WriteEndTag("td"); writer.WriteEndTag("tr"); writer.WriteLine(); } } writer.WriteEndTag("table"); writer.WriteLine(); writer.WriteBeginTag("table"); writer.WriteAttribute("width", "100%"); writer.WriteAttribute("height", "2"); writer.WriteAttribute("border", "0"); writer.WriteAttribute("cellspacing", "0"); writer.WriteAttribute("bgcolor", "#000000"); writer.Write(">"); writer.WriteFullBeginTag("tr"); writer.WriteFullBeginTag("td"); writer.WriteEndTag("td"); writer.WriteEndTag("tr"); writer.WriteEndTag("table"); writer.WriteBreak(); ((Control) activePane).RenderControl(writer); }
//********************************************************************* // // HtmlLinkCommandAdapter.Render Method // // The Render method performs rendering of the LinkCommand control. // //********************************************************************* public override void Render(HtmlMobileTextWriter writer) { // Render a postback event as an anchor. RenderPostBackEventAsAnchor(writer, null, Control.Text); // Write a break, if necessary. writer.WriteBreak(); }
private void RenderItemsListWithoutTableTags(HtmlMobileTextWriter writer) { int startIndex = Control.FirstVisibleItemIndex; int pageSize = Control.VisibleItemCount; ObjectListItemCollection items = Control.Items; IObjectListFieldCollection allFields = Control.AllFields; int count = allFields.Count; int nextStartIndex = startIndex + pageSize; int labelFieldIndex = Control.LabelFieldIndex; Style style = this.Style; Style labelStyle = Control.LabelStyle; writer.EnterStyle(labelStyle); writer.WriteText(Control.AllFields[labelFieldIndex].Title, true); writer.ExitStyle(labelStyle, true); bool hasDefaultCommand = HasDefaultCommand(); bool onlyHasDefaultCommand = OnlyHasDefaultCommand(); bool requiresDetailsScreen = !onlyHasDefaultCommand && HasCommands(); // if there is > 1 visible field, need a details screen for (int visibleFields = 0, i = 0; !requiresDetailsScreen && i < count; i++) { visibleFields += allFields[i].Visible ? 1 : 0; requiresDetailsScreen = requiresDetailsScreen || visibleFields > 1; } bool itemRequiresHyperlink = requiresDetailsScreen || hasDefaultCommand; bool itemRequiresMoreButton = requiresDetailsScreen && hasDefaultCommand; Style subCommandStyle = Control.CommandStyle; subCommandStyle.Alignment = style.Alignment; subCommandStyle.Wrapping = style.Wrapping; writer.EnterStyle(style); for (int i = startIndex; i < nextStartIndex; i++) { ObjectListItem item = items[i]; if (itemRequiresHyperlink) { RenderPostBackEventAsAnchor(writer, hasDefaultCommand ? item.Index.ToString(CultureInfo.InvariantCulture) : String.Format(CultureInfo.InvariantCulture, ShowMoreFormat, item.Index), item[labelFieldIndex]); } else { writer.WriteText(item[labelFieldIndex], true); } if (itemRequiresMoreButton) { BooleanOption cachedItalic = subCommandStyle.Font.Italic; subCommandStyle.Font.Italic = BooleanOption.False; writer.EnterFormat(subCommandStyle); writer.Write(" ["); writer.ExitFormat(subCommandStyle); subCommandStyle.Font.Italic = cachedItalic; writer.EnterFormat(subCommandStyle); String moreText = Control.MoreText.Length == 0 ? GetDefaultLabel(MoreLabel) : Control.MoreText; writer.WriteBeginTag("a"); RenderPostBackEventAsAttribute(writer, "href", String.Format(CultureInfo.InvariantCulture, ShowMoreFormat, item.Index)); writer.Write(">"); writer.WriteText(moreText, true); writer.WriteEndTag("a"); writer.ExitFormat(subCommandStyle); subCommandStyle.Font.Italic = BooleanOption.False; writer.EnterFormat(subCommandStyle); writer.Write("]"); writer.ExitFormat(subCommandStyle); subCommandStyle.Font.Italic = cachedItalic; } if (i < (nextStartIndex - 1)) { writer.WriteBreak(); } } writer.ExitStyle(style, Control.BreakAfter); }
private void RenderItemDetailsWithoutTableTags(HtmlMobileTextWriter writer, ObjectListItem item) { Style style1 = base.Style; Style style2 = Control.LabelStyle; Style style3 = Control.CommandStyle; writer.EnterStyle(style2); writer.WriteText(item[Control.LabelFieldIndex], true); writer.ExitStyle(style2, true); IObjectListFieldCollection iObjectListFieldCollection = Control.AllFields; int i = 0; bool flag = style1.Font.Bold == BooleanOption.True; writer.EnterStyle(style1); IEnumerator iEnumerator = iObjectListFieldCollection.GetEnumerator(); while (iEnumerator.MoveNext()) { ObjectListField objectListField = (ObjectListField)iEnumerator.Current; if (objectListField.Visible) { if (!flag) { writer.Write("<b>"); } writer.WriteText(String.Concat(objectListField.Title, ":"), true); if (!flag) { writer.Write("</b>"); } writer.Write(" "); if (objectListField.Name == "CALL") { writer.WriteText(HtmlcheckPhonenumber(item[i]), true); } else if (objectListField.Name == "MAIL") { writer.WriteText(HtmlMail(item[i]), true); } else { writer.WriteText(item[i], true); } writer.WriteBreak(); } i++; } writer.ExitStyle(style1); BooleanOption booleanOption = style3.Font.Italic; style3.Font.Italic = BooleanOption.False; writer.EnterStyle(style3); writer.Write("[ "); writer.ExitStyle(style3); style3.Font.Italic = booleanOption; writer.EnterStyle(style3); iEnumerator = Control.Commands.GetEnumerator(); while (iEnumerator.MoveNext()) { ObjectListCommand objectListCommand = (ObjectListCommand)iEnumerator.Current; RenderPostBackEventAsAnchor(writer, objectListCommand.Name, objectListCommand.Text, style3); writer.Write(" | "); } string str = (Control.BackCommandText != String.Empty) ? Control.BackCommandText : base.GetDefaultLabel(ControlAdapter.BackLabel); RenderPostBackEventAsAnchor(writer, BackToList, str, style3); writer.ExitStyle(style3); style3.Font.Italic = BooleanOption.False; writer.EnterStyle(style3); writer.Write(" ]"); writer.ExitStyle(style3, Control.BreakAfter); style3.Font.Italic = booleanOption; }