Exemplo n.º 1
0
        /// <include file='doc\WmlFormAdapter.uex' path='docs/doc[@for="WmlFormAdapter.RenderPager"]/*' />
        protected virtual void RenderPager(WmlMobileTextWriter writer)
        {
            PagerStyle pagerStyle = Control.PagerStyle;
            int pageCount = Control.PageCount;
            if (pageCount <= 1)
            {
                return;
            }
            int page = Control.CurrentPage;

            writer.EnterStyle(pagerStyle);
            if (page < pageCount)
            {
                String nextPageText = pagerStyle.GetNextPageText(page);
                RenderPostBackEvent(writer, 
                                    (page + 1).ToString(CultureInfo.InvariantCulture), 
                                    writer.IsValidSoftkeyLabel(nextPageText) ? nextPageText 
                                                                             : GetDefaultLabel(NextLabel),
                                    true,
                                    nextPageText, 
                                    true);
            }

            if (page > 1)
            {
                String prevPageText = pagerStyle.GetPreviousPageText(page);
                RenderPostBackEvent(writer, 
                                    (page - 1).ToString(CultureInfo.InvariantCulture), 
                                    writer.IsValidSoftkeyLabel(prevPageText) ? prevPageText
                                                                             : GetDefaultLabel(PreviousLabel),
                                    true,
                                    prevPageText, 
                                    true);
            }
            writer.ExitStyle(pagerStyle);
        }
        /// <include file='doc\WmlObjectListAdapter.uex' path='docs/doc[@for="WmlObjectListAdapter.RenderItemDetails"]/*' />
        protected virtual void RenderItemDetails(WmlMobileTextWriter writer, ObjectListItem item)
        {
            String backCommandText = Control.BackCommandText.Length == 0 ?
                GetDefaultLabel(BackLabel) :
                Control.BackCommandText;
            String softkeyLabel = backCommandText.Length <= Device.MaximumSoftkeyLabelLength ?
                backCommandText :
                null;

            Style labelStyle = Control.LabelStyle;
            writer.EnterStyle(labelStyle);
            writer.RenderText(item[Control.LabelFieldIndex], true);
            writer.ExitStyle(labelStyle);

            writer.EnterStyle(Style);
            IObjectListFieldCollection fields = Control.AllFields;
            int fieldIndex = 0;
            foreach (ObjectListField field in fields)
            {
                if (field.Visible)
                {
                    String displayText = String.Format(CultureInfo.InvariantCulture, "{0}: {1}", field.Title, item[fieldIndex]);
                    writer.RenderText(displayText, true);
                }
                fieldIndex++;
            }
            RenderPostBackEvent(writer, _backToList, softkeyLabel, true, backCommandText, true);
            writer.ExitStyle(Style);
        }
        /// <include file='doc\WmlCalendarAdapter.uex' path='docs/doc[@for="WmlCalendarAdapter.Render"]/*' />
        public override void Render(WmlMobileTextWriter writer)
        {
            ArrayList arr;
            DateTime tempDate;
            DateTimeFormatInfo currentDateTimeInfo = DateTimeFormatInfo.CurrentInfo;
            String abbreviatedMonthDayPattern = AbbreviateMonthPattern(currentDateTimeInfo.MonthDayPattern);
            _threadCalendar = currentDateTimeInfo.Calendar;

            // RendersWmlSelectsAsMenuCards is true means the list control will be
            // rendered as select/option tags, where the break tag before
            // them will become an extra line which doesn't like good.
            bool addBreakBeforeListControl = Device.RendersWmlSelectsAsMenuCards;

            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
                    RenderPostBackEvent(writer,
                                        OptionPrompt.ToString(CultureInfo.InvariantCulture),
                                        GetDefaultLabel(GoLabel),
                                        true,
                                        promptText,
                                        true);
                    break;

                // Render the first secondary page that provides differnt
                // options to select a date.
                case OptionPrompt:
                    writer.RenderText(SR.GetString(SR.CalendarAdapterOptionPrompt),
                                      !addBreakBeforeListControl);

                    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.RenderText(_textBoxErrorMessage, true);
                    }

                    if (_selectList.Visible)
                    {
                        writer.RenderText(SR.GetString(SR.CalendarAdapterOptionEra), true);
                        _selectList.RenderControl(writer);
                    }

                    String numericDateFormat = GetNumericDateFormat();

                    writer.RenderText(SR.GetString(SR.CalendarAdapterOptionType) + ":", true);
                    writer.RenderText("(");
                    writer.RenderText(numericDateFormat.ToUpper(CultureInfo.InvariantCulture));
                    writer.RenderText(")");

                    if (!_selectList.Visible)
                    {
                        writer.RenderText(GetEra(Control.VisibleDate));
                    }
                    writer.RenderText(String.Empty, true);

                    _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);

                    String okLabel = GetDefaultLabel(OKLabel);

                    // accept softkey for sending the textbox value back to the server
                    RenderPostBackEvent(writer, 
                                        TypeDateDone.ToString(CultureInfo.InvariantCulture),
                                        okLabel,
                                        true,
                                        okLabel,
                                        true,
                                        WmlPostFieldType.Raw);
                    break;

                // Render a paged list for choosing a month
                case ChooseMonth:
                {
                    String displayText = String.Format(CultureInfo.CurrentCulture, "{0}:", SR.GetString(SR.CalendarAdapterOptionChooseMonth));
                    writer.RenderText(displayText, !addBreakBeforeListControl);

                    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";
                    String displayText = String.Format(CultureInfo.CurrentCulture, "{0} ({1}):",
                                                       SR.GetString(SR.CalendarAdapterOptionChooseWeek),
                                                       Control.VisibleDate.ToString(monthFormat, CultureInfo.CurrentCulture));
                    writer.RenderText(displayText, !addBreakBeforeListControl);

                    // 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:
                {
                    String displayText = String.Format(CultureInfo.CurrentCulture, "{0}:", SR.GetString(SR.CalendarAdapterOptionChooseDate));
                    writer.RenderText(displayText, !addBreakBeforeListControl);

                    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);
        }
        /// <include file='doc\WmlObjectListAdapter.uex' path='docs/doc[@for="WmlObjectListAdapter.RenderItemMenu"]/*' />
        protected virtual void RenderItemMenu(WmlMobileTextWriter writer, ObjectListItem item)
        {
            bool requiresDetails = HasItemDetails();

            String detailsCommandText = Control.DetailsCommandText.Length == 0 ?
                SR.GetString(SR.WmlObjectListAdapterDetails) :
                Control.DetailsCommandText;
            String softkeyLabel = detailsCommandText.Length <= Device.MaximumSoftkeyLabelLength ?
                detailsCommandText :
                null;
            Style commandStyle = Control.CommandStyle;
            if (commandStyle.Alignment == Alignment.NotSet)
            {
                commandStyle.Alignment = Alignment.Left;
            }
            writer.EnterStyle(commandStyle);
            if (requiresDetails)
            {
                RenderPostBackEvent(writer, _showDetails,
                        softkeyLabel, true, detailsCommandText, true, WmlPostFieldType.Raw);
            }

            ObjectListCommandCollection commands = Control.Commands;
            foreach (ObjectListCommand command in commands)
            {
                RenderPostBackEvent(writer, command.Name, 
                    GetDefaultLabel(GoLabel), false, command.Text, true, WmlPostFieldType.Raw);
            }
            writer.ExitStyle(commandStyle);
        }