PagerSettings.cs 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. //
  2. // System.Web.UI.WebControls.PagerSettings.cs
  3. //
  4. // Authors:
  5. // Lluis Sanchez Gual ([email protected])
  6. //
  7. // (C) 2005 Novell, Inc (http://www.novell.com)
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining
  10. // a copy of this software and associated documentation files (the
  11. // "Software"), to deal in the Software without restriction, including
  12. // without limitation the rights to use, copy, modify, merge, publish,
  13. // distribute, sublicense, and/or sell copies of the Software, and to
  14. // permit persons to whom the Software is furnished to do so, subject to
  15. // the following conditions:
  16. //
  17. // The above copyright notice and this permission notice shall be
  18. // included in all copies or substantial portions of the Software.
  19. //
  20. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  21. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  23. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  24. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  25. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  26. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27. //
  28. // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
  29. //
  30. #if NET_2_0
  31. using System.ComponentModel;
  32. using System.Security.Permissions;
  33. namespace System.Web.UI.WebControls
  34. {
  35. [TypeConverterAttribute (typeof(ExpandableObjectConverter))]
  36. [AspNetHostingPermissionAttribute (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
  37. public sealed class PagerSettings: IStateManager
  38. {
  39. StateBag ViewState = new StateBag ();
  40. Control ctrl;
  41. public PagerSettings ()
  42. {
  43. }
  44. internal PagerSettings (Control ctrl)
  45. {
  46. this.ctrl = ctrl;
  47. }
  48. [WebCategoryAttribute ("Appearance")]
  49. [NotifyParentPropertyAttribute (true)]
  50. [UrlPropertyAttribute]
  51. [DefaultValueAttribute ("")]
  52. [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
  53. public string FirstPageImageUrl {
  54. get {
  55. object ob = ViewState ["FirstPageImageUrl"];
  56. if (ob != null) return (string) ob;
  57. return string.Empty;
  58. }
  59. set {
  60. ViewState ["FirstPageImageUrl"] = value;
  61. }
  62. }
  63. [WebCategoryAttribute ("Appearance")]
  64. [DefaultValueAttribute ("<<")]
  65. [NotifyParentPropertyAttribute (true)]
  66. public string FirstPageText {
  67. get {
  68. object ob = ViewState ["FirstPageText"];
  69. if (ob != null) return (string) ob;
  70. return "<<";
  71. }
  72. set {
  73. ViewState ["FirstPageText"] = value;
  74. }
  75. }
  76. [WebCategoryAttribute ("Appearance")]
  77. [NotifyParentPropertyAttribute (true)]
  78. [UrlPropertyAttribute]
  79. [DefaultValueAttribute ("")]
  80. [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
  81. public string LastPageImageUrl {
  82. get {
  83. object ob = ViewState ["LastPageImageUrl"];
  84. if (ob != null) return (string) ob;
  85. return string.Empty;
  86. }
  87. set {
  88. ViewState ["LastPageImageUrl"] = value;
  89. }
  90. }
  91. [NotifyParentPropertyAttribute (true)]
  92. [WebCategoryAttribute ("Appearance")]
  93. [DefaultValueAttribute (">>")]
  94. public string LastPageText {
  95. get {
  96. object ob = ViewState ["LastPageText"];
  97. if (ob != null) return (string) ob;
  98. return ">>";
  99. }
  100. set {
  101. ViewState ["LastPageText"] = value;
  102. }
  103. }
  104. [NotifyParentPropertyAttribute (true)]
  105. [WebCategoryAttribute ("Appearance")]
  106. [DefaultValueAttribute (PagerButtons.Numeric)]
  107. public PagerButtons Mode {
  108. get {
  109. object ob = ViewState ["Mode"];
  110. if (ob != null) return (PagerButtons) ob;
  111. return PagerButtons.Numeric;
  112. }
  113. set {
  114. ViewState ["Mode"] = value;
  115. }
  116. }
  117. [WebCategoryAttribute ("Appearance")]
  118. [NotifyParentPropertyAttribute (true)]
  119. [UrlPropertyAttribute]
  120. [DefaultValueAttribute ("")]
  121. [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
  122. public string NextPageImageUrl {
  123. get {
  124. object ob = ViewState ["NextPageImageUrl"];
  125. if (ob != null) return (string) ob;
  126. return string.Empty;
  127. }
  128. set {
  129. ViewState ["NextPageImageUrl"] = value;
  130. }
  131. }
  132. [WebCategoryAttribute ("Appearance")]
  133. [NotifyParentPropertyAttribute (true)]
  134. [DefaultValueAttribute (">")]
  135. public string NextPageText {
  136. get {
  137. object ob = ViewState ["NextPageText"];
  138. if (ob != null) return (string) ob;
  139. return ">";
  140. }
  141. set {
  142. ViewState ["NextPageText"] = value;
  143. }
  144. }
  145. [WebCategoryAttribute ("Behavior")]
  146. [NotifyParentPropertyAttribute (true)]
  147. [DefaultValueAttribute (10)]
  148. public int PageButtonCount {
  149. get {
  150. object ob = ViewState ["PageButtonCount"];
  151. if (ob != null) return (int) ob;
  152. return 10;
  153. }
  154. set {
  155. ViewState ["PageButtonCount"] = value;
  156. }
  157. }
  158. [WebCategoryAttribute ("Layout")]
  159. [DefaultValueAttribute (PagerPosition.Bottom)]
  160. [NotifyParentPropertyAttribute (true)]
  161. public PagerPosition Position {
  162. get {
  163. object ob = ViewState ["Position"];
  164. if (ob != null) return (PagerPosition) ob;
  165. return PagerPosition.Bottom;
  166. }
  167. set {
  168. ViewState ["Position"] = value;
  169. }
  170. }
  171. [WebCategoryAttribute ("Appearance")]
  172. [NotifyParentPropertyAttribute (true)]
  173. [UrlPropertyAttribute]
  174. [DefaultValueAttribute ("")]
  175. [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
  176. public string PreviousPageImageUrl {
  177. get {
  178. object ob = ViewState ["PreviousPageImageUrl"];
  179. if (ob != null) return (string) ob;
  180. return string.Empty;
  181. }
  182. set {
  183. ViewState ["PreviousPageImageUrl"] = value;
  184. }
  185. }
  186. [WebCategoryAttribute ("Appearance")]
  187. [DefaultValueAttribute ("<")]
  188. [NotifyParentPropertyAttribute (true)]
  189. public string PreviousPageText {
  190. get {
  191. object ob = ViewState ["PreviousPageText"];
  192. if (ob != null) return (string) ob;
  193. return "<";
  194. }
  195. set {
  196. ViewState ["PreviousPageText"] = value;
  197. }
  198. }
  199. [WebCategoryAttribute ("Appearance")]
  200. [DefaultValueAttribute (true)]
  201. [NotifyParentPropertyAttribute (true)]
  202. public bool Visible {
  203. get {
  204. object ob = ViewState ["Visible"];
  205. if (ob != null) return (bool) ob;
  206. return true;
  207. }
  208. set {
  209. ViewState ["Visible"] = value;
  210. }
  211. }
  212. public override string ToString ()
  213. {
  214. return string.Empty;
  215. }
  216. void IStateManager.LoadViewState (object savedState)
  217. {
  218. ViewState.LoadViewState (savedState);
  219. }
  220. object IStateManager.SaveViewState ()
  221. {
  222. return ViewState.SaveViewState();
  223. }
  224. void IStateManager.TrackViewState ()
  225. {
  226. ViewState.TrackViewState();
  227. }
  228. bool IStateManager.IsTrackingViewState
  229. {
  230. get { return ViewState.IsTrackingViewState; }
  231. }
  232. internal Table CreatePagerControl (int currentPage, int pageCount)
  233. {
  234. Table table = new Table ();
  235. TableRow row = new TableRow ();
  236. table.Rows.Add (row);
  237. if (Mode == PagerButtons.NextPrevious || Mode == PagerButtons.NextPreviousFirstLast)
  238. {
  239. if (currentPage > 0) {
  240. if (Mode == PagerButtons.NextPreviousFirstLast)
  241. row.Cells.Add (CreateCell (FirstPageText, FirstPageImageUrl, "Page", "First"));
  242. row.Cells.Add (CreateCell (PreviousPageText, PreviousPageImageUrl, "Page", "Prev"));
  243. }
  244. if (currentPage < pageCount - 1) {
  245. row.Cells.Add (CreateCell (NextPageText, NextPageImageUrl, "Page", "Next"));
  246. if (Mode == PagerButtons.NextPreviousFirstLast)
  247. row.Cells.Add (CreateCell (LastPageText, LastPageImageUrl, "Page", "Last"));
  248. }
  249. }
  250. else if (Mode == PagerButtons.Numeric || Mode == PagerButtons.NumericFirstLast)
  251. {
  252. int first = currentPage / PageButtonCount;
  253. int last = first + PageButtonCount;
  254. if (last >= pageCount) last = pageCount;
  255. if (first > 0) {
  256. if (Mode == PagerButtons.NumericFirstLast)
  257. row.Cells.Add (CreateCell (FirstPageText, FirstPageImageUrl, "Page", "First"));
  258. row.Cells.Add (CreateCell (PreviousPageText, PreviousPageImageUrl, "Page", "Prev"));
  259. }
  260. for (int n = first; n < last; n++)
  261. row.Cells.Add (CreateCell ((n+1).ToString(), string.Empty, (n != currentPage) ? "Page" : "", (n+1).ToString()));
  262. if (last < pageCount - 1) {
  263. row.Cells.Add (CreateCell (NextPageText, NextPageImageUrl, "Page", "Next"));
  264. if (Mode == PagerButtons.NumericFirstLast)
  265. row.Cells.Add (CreateCell (LastPageText, LastPageImageUrl, "Page", "Last"));
  266. }
  267. }
  268. return table;
  269. }
  270. TableCell CreateCell (string text, string image, string command, string argument)
  271. {
  272. TableCell cell = new TableCell ();
  273. cell.Controls.Add (new DataControlButton (ctrl, text, image, command, argument, true));
  274. return cell;
  275. }
  276. }
  277. }
  278. #endif