D:/Projects/Anthem/Anthem/Calendar.cs

00001 using System;
00002 using System.ComponentModel;
00003 using System.Drawing;
00004 using System.IO;
00005 using System.Text.RegularExpressions;
00006 using System.Web;
00007 using System.Web.UI;
00008 using ASP = System.Web.UI.WebControls;
00009 
00010 // It looks like very little effort was put into making the Calendar control
00011 // customizable which is why this control is such a hack job. Is it too much
00012 // to ask to make your methods protected and virtual, Microsoft?
00013 
00014 namespace Anthem
00015 {
00019     [ToolboxBitmap(typeof(ASP.Calendar))]
00020     public class Calendar : ASP.Calendar, IUpdatableControl, ICallBackControl
00021     {
00022         #region Unique Anthem control code
00023 
00028         protected override void OnSelectionChanged()
00029         {
00030             base.OnSelectionChanged();
00031             UpdateAfterCallBack = true;
00032         }
00033 
00038         protected override void OnVisibleMonthChanged(DateTime newDate, DateTime previousDate)
00039         {
00040             base.OnVisibleMonthChanged(newDate, previousDate);
00041             UpdateAfterCallBack = true;
00042         }
00043 
00044         private const string parentTagName = "div";
00045         private Regex regex = new Regex("href=\"javascript:__doPostBack\\('(.*?)','(.*?)'\\)\"", RegexOptions.Compiled | RegexOptions.IgnoreCase);
00046 
00051         protected override void Render(HtmlTextWriter writer)
00052         {
00053 #if !V2
00054             bool DesignMode = this.Context == null;
00055 #endif
00056             if (!DesignMode)
00057             {
00058                 // parentTagName must be defined as a private const string field in this class.
00059                 Anthem.Manager.WriteBeginControlMarker(writer, parentTagName, this);
00060             }
00061             if (Visible)
00062             {
00063                 StringWriter sw = new StringWriter();
00064                 HtmlTextWriter tw = new HtmlTextWriter(sw);
00065                 base.Render(tw);
00066                 string text = sw.ToString();
00067                 if (this.EnableCallBack)
00068                 {
00069                     foreach (Match match in regex.Matches(text))
00070                     {
00071                         string newtext = string.Format(
00072                             "onclick=\"Anthem_FireCallBackEvent(this,event,'{0}','{1}',false,'','','{2}',{3},{4},{5},{6},true,true);return false;\" ",
00073                             match.Groups[1].Value.Replace('$', ':'),
00074                             match.Groups[2].Value,
00075                             HttpUtility.HtmlEncode(TextDuringCallBack),
00076                             EnabledDuringCallBack ? "true" : "false",
00077                             (PreCallBackFunction == null || PreCallBackFunction.Length == 0) ? "null" : PreCallBackFunction,
00078                             (PostCallBackFunction == null || PostCallBackFunction.Length == 0) ? "null" : PostCallBackFunction,
00079                             (CallBackCancelledFunction == null || CallBackCancelledFunction.Length == 0) ? "null" : CallBackCancelledFunction
00080                             );
00081                         text = text.Replace(match.Value, newtext + match.Value);
00082                     }
00083                 }
00084                 writer.Write(text);
00085             }
00086             if (!DesignMode)
00087             {
00088                 Anthem.Manager.WriteEndControlMarker(writer, parentTagName, this);
00089             }
00090         }
00091 
00092         #endregion
00093 
00094         #region ICallBackControl implementation
00095 
00100         [Category("Anthem")]
00101         [DefaultValue("")]
00102         [Description("The javascript function to call on the client if the callback is cancelled.")]
00103         public virtual string CallBackCancelledFunction
00104         {
00105             get
00106             {
00107                 string text = (string)ViewState["CallBackCancelledFunction"];
00108                 if (text == null)
00109                     return string.Empty;
00110                 else
00111                     return text;
00112             }
00113             set
00114             {
00115                 ViewState["CallBackCancelledFunction"] = value;
00116             }
00117         }
00118 
00126         [Category("Anthem")]
00127         [DefaultValue(true)]
00128         [Description("True if this control uses callbacks instead of postbacks to post data to the server.")]
00129         public virtual bool EnableCallBack
00130         {
00131             get
00132             {
00133                 object obj = this.ViewState["EnableCallBack"];
00134                 if (obj == null)
00135                     return true;
00136                 else
00137                     return (bool)obj;
00138             }
00139             set
00140             {
00141                 ViewState["EnableCallBack"] = value;
00142             }
00143         }
00144 
00153         [Category("Anthem")]
00154         [DefaultValue(true)]
00155         [Description("True if this control is enabled on the client during callbacks.")]
00156         public virtual bool EnabledDuringCallBack
00157         {
00158             get
00159             {
00160                 object obj = this.ViewState["EnabledDuringCallBack"];
00161                 if (obj == null)
00162                     return true;
00163                 else
00164                     return (bool)obj;
00165             }
00166             set
00167             {
00168                 ViewState["EnabledDuringCallBack"] = value;
00169             }
00170         }
00171 
00172 
00190         [Category("Anthem")]
00191         [DefaultValue("")]
00192         [Description("The javascript function to call on the client after the callback response is received.")]
00193         public virtual string PostCallBackFunction
00194         {
00195             get
00196             {
00197                 string text = (string)this.ViewState["PostCallBackFunction"];
00198                 if (text == null)
00199                 {
00200                     return string.Empty;
00201                 }
00202                 return text;
00203             }
00204             set
00205             {
00206                 ViewState["PostCallBackFunction"] = value;
00207             }
00208         }
00209 
00215         [Category("Anthem")]
00216         [DefaultValue("")]
00217         [Description("The javascript function to call on the client before the callback is made.")]
00218         public virtual string PreCallBackFunction
00219         {
00220             get
00221             {
00222                 string text = (string)this.ViewState["PreCallBackFunction"];
00223                 if (text == null)
00224                 {
00225                     return string.Empty;
00226                 }
00227                 return text;
00228             }
00229             set
00230             {
00231                 ViewState["PreCallBackFunction"] = value;
00232             }
00233         }
00234 
00243         [Category("Anthem")]
00244         [DefaultValue("")]
00245         [Description("The text to display during the callback.")]
00246         public virtual string TextDuringCallBack
00247         {
00248             get
00249             {
00250                 string text = (string)this.ViewState["TextDuringCallBack"];
00251                 if (text == null)
00252                 {
00253                     return string.Empty;
00254                 }
00255                 return text;
00256             }
00257             set
00258             {
00259                 ViewState["TextDuringCallBack"] = value;
00260             }
00261         }
00262 
00263         #endregion
00264 
00265         #region IUpdatableControl implementation
00266 
00280         [Category("Anthem")]
00281         [DefaultValue(false)]
00282         [Description("True if this control should be updated after each callback.")]
00283         public virtual bool AutoUpdateAfterCallBack
00284         {
00285             get
00286             {
00287                 object obj = this.ViewState["AutoUpdateAfterCallBack"];
00288                 if (obj == null)
00289                     return false;
00290                 else
00291                     return (bool)obj;
00292             }
00293             set
00294             {
00295                 if (value) UpdateAfterCallBack = true;
00296                 ViewState["AutoUpdateAfterCallBack"] = value;
00297             }
00298         }
00299 
00300         private bool _updateAfterCallBack = false;
00301 
00316         [Browsable(false)]
00317         [DefaultValue(false)]
00318         public virtual bool UpdateAfterCallBack
00319         {
00320             get { return _updateAfterCallBack; }
00321             set { _updateAfterCallBack = value; }
00322         }
00323 
00324         #endregion
00325 
00326         #region Common Anthem control code
00327 
00333         protected override void OnLoad(EventArgs e)
00334         {
00335             base.OnLoad(e);
00336             Anthem.Manager.Register(this);
00337         }
00338 
00339 #if V2
00343         public override void RenderControl(HtmlTextWriter writer)
00344         {
00345             base.Visible = true;
00346             base.RenderControl(writer);
00347         }
00348 #endif
00349 
00357         public override bool Visible
00358         {
00359             get
00360             {
00361 #if !V2
00362                 bool DesignMode = this.Context == null;
00363 #endif
00364                 return Anthem.Manager.GetControlVisible(this, ViewState, DesignMode);
00365             }
00366             set { Anthem.Manager.SetControlVisible(ViewState, value); }
00367         }
00368 
00369         #endregion
00370     }
00371 }

Generated on Wed Mar 14 23:50:39 2007 for Anthem by  doxygen 1.5.1-p1