ControlPager.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. //
  2. // Permission is hereby granted, free of charge, to any person obtaining
  3. // a copy of this software and associated documentation files (the
  4. // "Software"), to deal in the Software without restriction, including
  5. // without limitation the rights to use, copy, modify, merge, publish,
  6. // distribute, sublicense, and/or sell copies of the Software, and to
  7. // permit persons to whom the Software is furnished to do so, subject to
  8. // the following conditions:
  9. //
  10. // The above copyright notice and this permission notice shall be
  11. // included in all copies or substantial portions of the Software.
  12. //
  13. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  14. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  15. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  16. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  17. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  18. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  19. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  20. //
  21. /**
  22. * Project : Mono
  23. * Namespace : System.Web.UI.MobileControls
  24. * Class : ControlPager
  25. * Author : Gaurav Vaish
  26. *
  27. * Copyright : 2003 with Gaurav Vaish, and with
  28. * Ximian Inc
  29. */
  30. using System.Web.Mobile;
  31. namespace System.Web.UI.MobileControls
  32. {
  33. public class ControlPager
  34. {
  35. private int pageCount = 0;
  36. private int maxPage = -1;
  37. private int pageWt;
  38. private int remainingWt = 0;
  39. private Form form;
  40. // To ponder: will const be better?
  41. public static readonly int DefaultWeight = 100;
  42. public static readonly int UseDefaultWeight = -1;
  43. public ControlPager(Form form, int pageWeight)
  44. {
  45. this.form = form;
  46. this.pageWt = pageWeight;
  47. }
  48. public int PageCount
  49. {
  50. get
  51. {
  52. return pageCount;
  53. }
  54. set
  55. {
  56. pageCount = value;
  57. }
  58. }
  59. public int MaximumPage
  60. {
  61. get
  62. {
  63. return maxPage;
  64. }
  65. set
  66. {
  67. maxPage = value;
  68. }
  69. }
  70. public int PageWeight
  71. {
  72. get
  73. {
  74. return pageWt;
  75. }
  76. set
  77. {
  78. pageWt = value;
  79. }
  80. }
  81. public int RemainingWeight
  82. {
  83. get
  84. {
  85. return remainingWt;
  86. }
  87. set
  88. {
  89. remainingWt = value;
  90. }
  91. }
  92. public ItemPager GetItemPager(MobileControl control, int itemCount,
  93. int itemsPerPage, int itemWeight)
  94. {
  95. return new ItemPager(this, control, itemCount,
  96. itemsPerPage, itemWeight);
  97. }
  98. public int GetPage(int weight)
  99. {
  100. if(weight > remainingWt)
  101. {
  102. PageCount += 1;
  103. RemainingWeight = PageWeight;
  104. }
  105. if(remainingWt > weight)
  106. {
  107. remainingWt -= weight;
  108. } else
  109. {
  110. remainingWt = 0;
  111. }
  112. return PageCount;
  113. }
  114. }
  115. }