1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365
|
//------------------------------------------------------------------------------
// <copyright file="HtmlMobileTextWriter.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
using System;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Web;
using System.Web.Mobile;
using System.Web.UI;
using System.Web.UI.MobileControls;
using System.Collections;
using System.Diagnostics;
using System.Security.Permissions;
#if COMPILING_FOR_SHIPPED_SOURCE
namespace System.Web.UI.MobileControls.ShippedAdapterSource
#else
namespace System.Web.UI.MobileControls.Adapters
#endif
{
/*
* HtmlMobileTextWriter class.
*/
/// <include file='doc\HtmlMobileTextWriter.uex' path='docs/doc[@for="HtmlMobileTextWriter"]/*' />
[AspNetHostingPermission(SecurityAction.LinkDemand, Level=AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermission(SecurityAction.InheritanceDemand, Level=AspNetHostingPermissionLevel.Minimal)]
[Obsolete("The System.Web.Mobile.dll assembly has been deprecated and should no longer be used. For information about how to develop ASP.NET mobile applications, see http://go.microsoft.com/fwlink/?LinkId=157231.")]
public class HtmlMobileTextWriter : MobileTextWriter
{
private bool _shouldEnsureStyle = true;
// mobile device type constants (should be defined somewhere else eventually)
internal WriterState _currentState;
/// <include file='doc\HtmlMobileTextWriter.uex' path='docs/doc[@for="HtmlMobileTextWriter.HtmlMobileTextWriter"]/*' />
public HtmlMobileTextWriter(TextWriter writer, MobileCapabilities device)
: base(writer, device)
{
RenderBold = device.SupportsBold;
RenderItalic = device.SupportsItalic;
RenderFontSize = device.SupportsFontSize;
RenderFontName = device.SupportsFontName;
RenderFontColor = device.SupportsFontColor;
RenderBodyColor = device.SupportsBodyColor;
RenderDivAlign = device.SupportsDivAlign;
RenderDivNoWrap = device.SupportsDivNoWrap;
RequiresNoBreakInFormatting = device.RequiresNoBreakInFormatting;
_currentState = new WriterState(this);
}
/*
* the following TextWriter methods are overridden to
* first call EnsureStyle before delegating to the base
* class implementation
*/
/// <include file='doc\HtmlMobileTextWriter.uex' path='docs/doc[@for="HtmlMobileTextWriter.WriteBeginTag"]/*' />
public override void WriteBeginTag(String tag)
{
EnsureStyle();
base.WriteBeginTag(tag);
}
/// <include file='doc\HtmlMobileTextWriter.uex' path='docs/doc[@for="HtmlMobileTextWriter.WriteFullBeginTag"]/*' />
public override void WriteFullBeginTag(String tag)
{
EnsureStyle();
base.WriteFullBeginTag(tag);
}
/// <include file='doc\HtmlMobileTextWriter.uex' path='docs/doc[@for="HtmlMobileTextWriter.Write"]/*' />
public override void Write(char c)
{
EnsureStyle();
base.Write(c);
}
/// <include file='doc\HtmlMobileTextWriter.uex' path='docs/doc[@for="HtmlMobileTextWriter.Write1"]/*' />
public override void Write(String text)
{
EnsureStyle();
base.Write(text);
}
/// <include file='doc\HtmlMobileTextWriter.uex' path='docs/doc[@for="HtmlMobileTextWriter.WriteEncodedText"]/*' />
public override void WriteEncodedText(String text)
{
EnsureStyle();
if(Device["supportsCharacterEntityEncoding"] != "false") {
base.WriteEncodedText(text);
return;
}
if (null == text || text.Length == 0) {
return;
}
int length = text.Length;
int start = -1;
for(int pos = 0; pos < length; pos++) {
int ch = text[pos];
if(ch > 160 && ch < 256) {
if(start != -1) {
base.WriteEncodedText(text.Substring(start, pos - start));
start = -1;
}
base.Write(text[pos]);
}
else {
if(start == -1) {
start = pos;
}
}
}
if(start != -1) {
if(start == 0) {
base.WriteEncodedText(text);
}
else {
base.WriteEncodedText(text.Substring(start, length - start));
}
}
}
/// <include file='doc\HtmlMobileTextWriter.uex' path='docs/doc[@for="HtmlMobileTextWriter.WriteLine"]/*' />
public override void WriteLine(String text)
{
EnsureStyle();
base.WriteLine(text);
}
/// <include file='doc\HtmlMobileTextWriter.uex' path='docs/doc[@for="HtmlMobileTextWriter.WriteBreak"]/*' />
public new void WriteBreak()
{
//Do not EnsureStyle for the break
base.WriteLine("<br>");
}
/// <include file='doc\HtmlMobileTextWriter.uex' path='docs/doc[@for="HtmlMobileTextWriter.EnterLayout"]/*' />
public override void EnterLayout(Style style)
{
WriterStyle writerStyle = new WriterStyle(style);
writerStyle.Format = false;
EnterStyle(writerStyle);
}
/// <include file='doc\HtmlMobileTextWriter.uex' path='docs/doc[@for="HtmlMobileTextWriter.ExitLayout"]/*' />
public override void ExitLayout(Style style, bool breakAfter)
{
ExitStyle(style, breakAfter);
}
/// <include file='doc\HtmlMobileTextWriter.uex' path='docs/doc[@for="HtmlMobileTextWriter.ExitLayout1"]/*' />
public override void ExitLayout(Style style)
{
ExitStyle(style, false);
}
/// <include file='doc\HtmlMobileTextWriter.uex' path='docs/doc[@for="HtmlMobileTextWriter.MarkStyleContext"]/*' />
protected internal void MarkStyleContext()
{
_shouldEnsureStyle = true;
_currentState.MarkStyleContext();
}
/// <include file='doc\HtmlMobileTextWriter.uex' path='docs/doc[@for="HtmlMobileTextWriter.UnMarkStyleContext"]/*' />
protected internal void UnMarkStyleContext()
{
_shouldEnsureStyle = true;
_currentState.UnMarkStyleContext();
}
/// <include file='doc\HtmlMobileTextWriter.uex' path='docs/doc[@for="HtmlMobileTextWriter.EnterFormat"]/*' />
public override void EnterFormat(Style style)
{
WriterStyle writerStyle = new WriterStyle(style);
writerStyle.Layout = false;
EnterStyle(writerStyle);
}
/// <include file='doc\HtmlMobileTextWriter.uex' path='docs/doc[@for="HtmlMobileTextWriter.ExitFormat"]/*' />
public override void ExitFormat(Style style)
{
ExitStyle(style);
}
/// <include file='doc\HtmlMobileTextWriter.uex' path='docs/doc[@for="HtmlMobileTextWriter.ExitFormat1"]/*' />
public override void ExitFormat(Style style, bool breakAfter)
{
ExitStyle(style, breakAfter);
}
/// <include file='doc\HtmlMobileTextWriter.uex' path='docs/doc[@for="HtmlMobileTextWriter.BeginStyleContext"]/*' />
public void BeginStyleContext()
{
if(_currentState.BreakPending)
{
WriteBreak();
_currentState.BreakPending = false;
}
_currentState.PushState();
EnterStyle(new WriterStyle());
}
/// <include file='doc\HtmlMobileTextWriter.uex' path='docs/doc[@for="HtmlMobileTextWriter.EndStyleContext"]/*' />
public void EndStyleContext()
{
if(_currentState.BreakPending)
{
WriteBreak();
_currentState.BreakPending = false;
}
_currentState.PopState();
_currentState.Pop();
_currentState.Transition(new WriterStyle());
}
/* all calls to Enter... converge to this */
private void EnterStyle(WriterStyle style)
{
_currentState.Push(style);
}
/// <include file='doc\HtmlMobileTextWriter.uex' path='docs/doc[@for="HtmlMobileTextWriter.EnterStyle"]/*' />
public new void EnterStyle(Style style)
{
EnterStyle(new WriterStyle(style));
}
/// <include file='doc\HtmlMobileTextWriter.uex' path='docs/doc[@for="HtmlMobileTextWriter.ExitStyle"]/*' />
public new void ExitStyle(Style style)
{
ExitStyle(style, false);
}
internal bool ShouldEnsureStyle
{
get
{
return _shouldEnsureStyle;
}
set
{
_shouldEnsureStyle = value;
}
}
/*
all calls to Exit... converge to this
*/
/// <include file='doc\HtmlMobileTextWriter.uex' path='docs/doc[@for="HtmlMobileTextWriter.ExitStyle1"]/*' />
public void ExitStyle(Style style, bool breakAfter)
{
_currentState.Pop();
if((_currentState.BreakPending) && (_currentState.Count > 0))
{
EnsureStyle();
}
_currentState.BreakPending = breakAfter;
if((_currentState.Count == 0) || (RequiresNoBreakInFormatting))
{
_currentState.Transition(new WriterStyle());
}
InputWritten = false;
}
internal bool _inputWritten = false;
internal bool InputWritten
{
get { return _inputWritten; }
set { _inputWritten = value; }
}
internal void EnsureStyle()
{
if (_shouldEnsureStyle)
{
if(_currentState.Count > 0)
{
_currentState.Transition(_currentState.Peek());
}
_shouldEnsureStyle = false;
}
if(BeforeFirstControlWritten)
{
BeforeFirstControlWritten = false;
}
}
/// <include file='doc\HtmlMobileTextWriter.uex' path='docs/doc[@for="HtmlMobileTextWriter.WriteText"]/*' />
public void WriteText(String text, bool encodeText)
{
if(text != null && text.Length == 0)
{
return;
}
EnsureStyle();
if (encodeText)
{
WriteEncodedText(text);
}
else
{
Write(text);
}
}
/// <include file='doc\HtmlMobileTextWriter.uex' path='docs/doc[@for="HtmlMobileTextWriter.WriteUrlParameter"]/*' />
public void WriteUrlParameter(String name, String value)
{
WriteEncodedUrlParameter(name);
Write("=");
WriteEncodedUrlParameter(value);
}
/// <include file='doc\HtmlMobileTextWriter.uex' path='docs/doc[@for="HtmlMobileTextWriter.WriteHiddenField"]/*' />
public void WriteHiddenField(String name, String value)
{
WriteBeginTag("input");
WriteAttribute("type", "hidden");
WriteAttribute("name", name);
WriteAttribute("value", value, true);
Write(">\r\n");
}
// AUI 2285
private bool _beforeFirstControlWritten = true;
internal bool BeforeFirstControlWritten
{
get
{
return _beforeFirstControlWritten;
}
set
{
_beforeFirstControlWritten = value;
}
}
private bool _maintainState = true;
internal bool MaintainState
{
get
{
return _maintainState;
}
set
{
_maintainState = value;
}
}
/// <include file='doc\HtmlMobileTextWriter.uex' path='docs/doc[@for="HtmlMobileTextWriter.RenderBold"]/*' />
protected internal bool RenderBold
{
get
{
return _renderBold;
}
set
{
_renderBold = value;
}
}
/// <include file='doc\HtmlMobileTextWriter.uex' path='docs/doc[@for="HtmlMobileTextWriter.RenderItalic"]/*' />
protected internal bool RenderItalic
{
get
{
return _renderItalic;
}
set
{
_renderItalic = value;
}
}
/// <include file='doc\HtmlMobileTextWriter.uex' path='docs/doc[@for="HtmlMobileTextWriter.RenderFontSize"]/*' />
protected internal bool RenderFontSize
{
get
{
return _renderFontSize;
}
set
{
_renderFontSize = value;
}
}
/// <include file='doc\HtmlMobileTextWriter.uex' path='docs/doc[@for="HtmlMobileTextWriter.RenderFontName"]/*' />
protected internal bool RenderFontName
{
get
{
return _renderFontName;
}
set
{
_renderFontName = value;
}
}
/// <include file='doc\HtmlMobileTextWriter.uex' path='docs/doc[@for="HtmlMobileTextWriter.RenderFontColor"]/*' />
protected internal bool RenderFontColor
{
get
{
return _renderFontColor;
}
set
{
_renderFontColor = value;
}
}
/// <include file='doc\HtmlMobileTextWriter.uex' path='docs/doc[@for="HtmlMobileTextWriter.RenderBodyColor"]/*' />
protected internal bool RenderBodyColor
{
get
{
return _renderBodyColor;
}
set
{
_renderBodyColor = value;
}
}
/// <include file='doc\HtmlMobileTextWriter.uex' path='docs/doc[@for="HtmlMobileTextWriter.RenderDivAlign"]/*' />
protected internal bool RenderDivAlign
{
get
{
return _renderDivAlign;
}
set
{
_renderDivAlign = value;
}
}
/// <include file='doc\HtmlMobileTextWriter.uex' path='docs/doc[@for="HtmlMobileTextWriter.RenderDivNoWrap"]/*' />
protected internal bool RenderDivNoWrap
{
get
{
return _renderDivNoWrap;
}
set
{
_renderDivNoWrap = value;
}
}
/// <include file='doc\HtmlMobileTextWriter.uex' path='docs/doc[@for="HtmlMobileTextWriter.RequiresNoBreakInFormatting"]/*' />
protected internal bool RequiresNoBreakInFormatting
{
get
{
return _requiresNoBreakInFormatting;
}
set
{
_requiresNoBreakInFormatting = value;
}
}
private bool _renderBold = true;
private bool _renderItalic = true;
private bool _renderFontSize = true;
private bool _renderFontName = true;
private bool _renderFontColor = true;
private bool _renderBodyColor = true;
private bool _renderDivAlign = true;
private bool _renderDivNoWrap = false;
private bool _requiresNoBreakInFormatting = false;
}
/*
* the WriterStyle class is used to store and
* control state for rendering format and layout
*/
[Obsolete("The System.Web.Mobile.dll assembly has been deprecated and should no longer be used. For information about how to develop ASP.NET mobile applications, see http://go.microsoft.com/fwlink/?LinkId=157231.")]
internal class WriterStyle
{
private Wrapping _wrapping;
private Alignment _alignment;
private String _fontName;
private Color _fontColor;
private FontSize _fontSize;
private bool _bold;
private bool _italic;
private bool _format;
private bool _layout;
internal WriterStyle()
{
_wrapping = Wrapping.Wrap;
_alignment = Alignment.Left;
_fontName = String.Empty;
_fontColor = Color.Empty;
_fontSize = FontSize.Normal;
_bold = false;
_italic = false;
_format = true;
_layout = true;
}
internal WriterStyle(Style style)
{
Debug.Assert(style != null, "writer style is null");
_alignment = (Alignment) style[Style.AlignmentKey, true];
if(_alignment == Alignment.NotSet)
{
_alignment = Alignment.Left;
}
_wrapping = (Wrapping) style[Style.WrappingKey, true];
if(_wrapping == Wrapping.NotSet)
{
_wrapping = Wrapping.Wrap;
}
_fontSize = (FontSize) style[Style.FontSizeKey , true];
if(_fontSize == FontSize.NotSet)
{
_fontSize = FontSize.Normal;
}
_fontName = (String) style[Style.FontNameKey , true];
_fontColor = (Color) style[Style.ForeColorKey, true];
_bold = ((BooleanOption) style[Style.BoldKey, true] == BooleanOption.True);
_italic = ((BooleanOption) style[Style.ItalicKey, true] == BooleanOption.True);
_format = true;
_layout = true;
}
internal bool Format
{
get { return _format; }
set { _format = value; }
}
internal bool Layout
{
get { return _layout; }
set { _layout = value; }
}
internal Wrapping Wrapping
{
get { return _wrapping; }
set { _wrapping = value; }
}
internal Alignment Alignment
{
get { return _alignment; }
set { _alignment = value; }
}
internal String FontName
{
get { return _fontName; }
set { _fontName = value; }
}
internal Color FontColor
{
get { return _fontColor; }
set { _fontColor = value; }
}
internal FontSize FontSize
{
get { return _fontSize; }
set { _fontSize = value; }
}
internal bool Bold
{
get { return _bold; }
set { _bold = value; }
}
internal bool Italic
{
get { return _italic; }
set { _italic = value; }
}
}
/*
* The StyleTag class is extended for specific tags
*/
[Obsolete("The System.Web.Mobile.dll assembly has been deprecated and should no longer be used. For information about how to develop ASP.NET mobile applications, see http://go.microsoft.com/fwlink/?LinkId=157231.")]
internal abstract class StyleTag
{
private int _level = -1;
#if UNUSED_CODE
internal StyleTag()
{
}
#endif
internal StyleTag(int level)
{
_level = level;
}
internal virtual int Level
{
get
{
return _level;
}
set
{
_level = value;
}
}
internal abstract void CloseTag(WriterState state);
}
[Obsolete("The System.Web.Mobile.dll assembly has been deprecated and should no longer be used. For information about how to develop ASP.NET mobile applications, see http://go.microsoft.com/fwlink/?LinkId=157231.")]
internal class BoldStyleTag : StyleTag
{
internal BoldStyleTag(int level) : base(level)
{
}
internal override void CloseTag(WriterState state)
{
state.Writer.WriteEndTag("b");
state.Current.Bold = false;
}
}
[Obsolete("The System.Web.Mobile.dll assembly has been deprecated and should no longer be used. For information about how to develop ASP.NET mobile applications, see http://go.microsoft.com/fwlink/?LinkId=157231.")]
internal class ItalicStyleTag : StyleTag
{
internal ItalicStyleTag(int level) : base(level)
{
}
internal override void CloseTag(WriterState state)
{
state.Writer.WriteEndTag("i");
state.Current.Italic = false;
}
}
[Obsolete("The System.Web.Mobile.dll assembly has been deprecated and should no longer be used. For information about how to develop ASP.NET mobile applications, see http://go.microsoft.com/fwlink/?LinkId=157231.")]
internal class FontStyleTag : StyleTag
{
private String _name;
private Color _color;
private FontSize _size;
internal FontStyleTag(int level) : base(level)
{
_name = String.Empty;
_color = Color.Empty;
_size = FontSize.Normal;
}
#if UNUSED_CODE
internal FontStyleTag(int level, String name, Color color, FontSize size) : base(level)
{
Name = _name;
Color = color;
FontSize = size;
}
#endif
internal String Name
{
get { return _name; }
set { _name = value; }
}
internal Color Color
{
get { return _color; }
set { _color = value; }
}
internal FontSize FontSize
{
get { return _size; }
set { _size = value; }
}
internal override void CloseTag(WriterState state)
{
state.Writer.WriteEndTag("font");
//reset FontLevel and rebuild state info
state.FontLevel = -1;
state.Current.FontColor = Color.Empty;
state.Current.FontName = String.Empty;
state.Current.FontSize = FontSize.Normal;
//reset the FontLevel
Stack tmpStack = new Stack();
while(state.TagsWritten.Count > 0)
{
Object o = state.TagsWritten.Pop();
tmpStack.Push(o);
if(o is FontStyleTag)
{
state.FontLevel = ((FontStyleTag)o).Level;
break;
}
}
while(tmpStack.Count > 0)
{
state.TagsWritten.Push(tmpStack.Pop());
}
//there is a font tag in the stack
if(state.FontLevel > -1)
{
if(Color != Color.Empty)
{
//reset font color to something further down the stack
Stack tempStack = new Stack();
while(state.TagsWritten.Count > 0)
{
Object o = state.TagsWritten.Pop();
tempStack.Push(o);
if(o is FontStyleTag)
{
if(((FontStyleTag)o).Color != Color.Empty)
{
state.Current.FontColor = ((FontStyleTag)o).Color;
break;
}
}
}
while(tempStack.Count > 0)
{
state.TagsWritten.Push(tempStack.Pop());
}
}
if(Name == null || Name.Length > 0)
{
//reset font name to something futher down the stack
Stack tempStack = new Stack();
while(state.TagsWritten.Count > 0)
{
Object o = state.TagsWritten.Pop();
tempStack.Push(o);
if(o is FontStyleTag)
{
String name = ((FontStyleTag)o).Name;
if(name == null || name.Length > 0)
{
state.Current.FontName = name;
break;
}
}
}
while(tempStack.Count > 0)
{
state.TagsWritten.Push(tempStack.Pop());
}
}
//reset font size to something further down the stack
while(state.TagsWritten.Count > 0)
{
Object o = state.TagsWritten.Pop();
tmpStack.Push(o);
if (o is FontStyleTag)
{
if(((FontStyleTag)o).FontSize != FontSize.Normal)
{
state.Current.FontSize = ((FontStyleTag)o).FontSize;
break;
}
}
}
while(tmpStack.Count > 0)
{
state.TagsWritten.Push(tmpStack.Pop());
}
}
}
}
[Obsolete("The System.Web.Mobile.dll assembly has been deprecated and should no longer be used. For information about how to develop ASP.NET mobile applications, see http://go.microsoft.com/fwlink/?LinkId=157231.")]
internal class DivStyleTag : StyleTag
{
private Wrapping _wrapping;
private Alignment _alignment;
private bool _alignWritten;
internal DivStyleTag(int level) : base(level)
{
_wrapping = Wrapping.Wrap;
_alignment = Alignment.Left;
_alignWritten = false;
}
internal Wrapping Wrapping
{
get { return _wrapping; }
set { _wrapping = value; }
}
internal Alignment Alignment
{
get { return _alignment; }
set { _alignment = value; }
}
internal bool AlignmentWritten
{
get { return _alignWritten; }
set { _alignWritten = value; }
}
internal override void CloseTag(WriterState state)
{
state.Writer.WriteEndTag("div");
state.BreakPending = false;
//reset current div info and rebuild
state.DivLevel = -1;
state.Current.Alignment = Alignment.Left;
state.Current.Wrapping = Wrapping.Wrap;
Stack tempStack = new Stack();
//reset alignment : ideally these resets could be combined
//in practice, the number of items on the stack is small
//so it may be comparable
//reset wrapping
while(state.TagsWritten.Count > 0)
{
Object o = state.TagsWritten.Pop();
tempStack.Push(o);
if(o is DivStyleTag)
{
if(((DivStyleTag)o).Wrapping == Wrapping.NoWrap)
{
state.Current.Wrapping = Wrapping.NoWrap;
break;
}
}
}
while(tempStack.Count > 0)
{
state.TagsWritten.Push(tempStack.Pop());
}
//reset alignment
while(state.TagsWritten.Count > 0)
{
Object o = state.TagsWritten.Pop();
tempStack.Push(o);
if(o is DivStyleTag)
{
if(((DivStyleTag)o).Alignment != Alignment.NotSet)
{
state.Current.Alignment = ((DivStyleTag)o).Alignment;
break;
}
}
}
while(tempStack.Count > 0)
{
state.TagsWritten.Push(tempStack.Pop());
}
//reset divLevel
while(state.TagsWritten.Count > 0)
{
Object o = state.TagsWritten.Pop();
tempStack.Push(o);
if(o is DivStyleTag)
{
state.DivLevel = ((DivStyleTag)o).Level;
break;
}
}
while(tempStack.Count > 0)
{
state.TagsWritten.Push(tempStack.Pop());
}
}
}
/*
* the StyleStack class maintains WriterStyle objects
* pushed on the stack from Enter[Style/Format/Layout]
* and removed using Exit[Style/Format/Layout]
*/
[Obsolete("The System.Web.Mobile.dll assembly has been deprecated and should no longer be used. For information about how to develop ASP.NET mobile applications, see http://go.microsoft.com/fwlink/?LinkId=157231.")]
internal class StyleStack
{
private HtmlMobileTextWriter _writer;
private Stack _stack;
protected StyleStack(HtmlMobileTextWriter writer)
{
_writer = writer;
_stack = new Stack();
}
internal void Push(WriterStyle style)
{
_stack.Push(style);
_writer.ShouldEnsureStyle = true;
}
internal WriterStyle Pop()
{
_writer.ShouldEnsureStyle = true;
return (WriterStyle)_stack.Pop();
}
internal WriterStyle Peek()
{
if(_stack.Count == 0)
{
return new WriterStyle(); //retrieves default values
}
return (WriterStyle)_stack.Peek();
}
internal int Count
{
get
{
return _stack.Count;
}
}
}
/* the WriterState tracks what styles have been entered, what tags have been written
and controls transitions from the current state to a desired state
*/
[Obsolete("The System.Web.Mobile.dll assembly has been deprecated and should no longer be used. For information about how to develop ASP.NET mobile applications, see http://go.microsoft.com/fwlink/?LinkId=157231.")]
internal class WriterState : StyleStack
{
private bool _inTransition = false; //prevent recursion
private Stack _stack; //stack of WriterStyle objects
private Stack _tagsWritten; //stack of StyleTag objects for written tags
private bool _breakPending = false; //track if we owe a <br>
private WriterStyle _current; //the current style
private HtmlMobileTextWriter _writer; //the output stream
private int _fontLevel = -1;
private int _divLevel = -1;
private int _mark = 0;
internal WriterState(HtmlMobileTextWriter writer) : base(writer)
{
_writer = writer;
_stack = new Stack();
_current = new WriterStyle();
_tagsWritten = new Stack();
}
internal WriterStyle Current
{
get
{
return _current;
}
}
/*
Pushes the current WriterStyle and tagsWritten stack for later use,
starts using a new default WriterStyle
*/
internal void PushState()
{
_writer.ShouldEnsureStyle = true;
_stack.Push(_current);
_current = new WriterStyle();
_stack.Push(_tagsWritten);
_tagsWritten = new Stack();
_stack.Push(BreakPending);
BreakPending = false;
}
internal int FontLevel
{
get { return _fontLevel; }
set { _fontLevel = value; }
}
internal int DivLevel
{
get { return _divLevel; }
set { _divLevel = value; }
}
/*
Pops the last WriterStyle pushed and makes it current
and restores the tagsWritten stack
*/
internal WriterStyle PopState()
{
_writer.ShouldEnsureStyle = true;
BreakPending = (bool)_stack.Pop();
//close all open tags
while(_tagsWritten.Count > 0)
{
CloseTag();
}
_tagsWritten = (Stack)_stack.Pop();
_current = (WriterStyle)_stack.Pop();
return _current;
}
/*
BreakPending property accessor
*/
internal bool BreakPending
{
get { return _breakPending; }
set { _breakPending = value; }
}
internal HtmlTextWriter Writer
{
get
{
return _writer;
}
}
internal Stack TagsWritten
{
get
{
return _tagsWritten;
}
}
/*
pop a tag from the stack of StyleTags,
adjust state accordingly
*/
internal void CloseTag()
{
StyleTag tag = (StyleTag)_tagsWritten.Pop();
tag.CloseTag(this);
}
internal void MarkStyleContext()
{
_mark = _tagsWritten.Count;
}
internal void UnMarkStyleContext()
{
while(_tagsWritten.Count > _mark)
{
CloseTag();
}
}
private bool FontChange(WriterStyle newStyle)
{
return (
(( _current.FontColor != newStyle.FontColor ) && (_writer.RenderFontColor)) ||
(( _current.FontSize != newStyle.FontSize ) && (_writer.RenderFontSize)) ||
(( _current.FontName != newStyle.FontName ) && (_writer.RenderFontName))
);
}
private bool DivChange(WriterStyle newStyle)
{
return (
(newStyle.Layout) &&
(((newStyle.Wrapping != _current.Wrapping) && (_writer.RenderDivNoWrap)) ||
((newStyle.Alignment != _current.Alignment) && (_writer.RenderDivAlign)) )
);
}
internal void Transition(WriterStyle newStyle)
{
Transition(newStyle, true);
}
private const String _pocketPC = "Pocket IE";
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;
}
}
}
}
|