source: default/framework/trunk/WebLibrary/Sources/UI/WebControls/LocalizedMessage.cs @ 864

このファイルの 864 以降における最終更新内容864 で hizuya@… が 12年前 に更新しました
  • プリミティブ型がある場合はそれを使用するように変更。
  • XML コメント中の null, true, false を <see langword=""/> を使うように変更。
  • using ディレクティブを SA1200 に合わせて最適化。
ファイルサイズ: 8.8 KB
 
1// ----------------------------------------------------------------------------
2// <copyright company="F.C. Soft., Inc.">
3//   Copyright(c) F.C. Soft., Inc.  All rights reserved.
4// </copyright>
5// <license>
6//   Licensed to F.C. Soft., Inc. (FCSoft) under one or more contributor
7//   license agreements.  See the NOTICE file distributed with this work for
8//   additional information regarding copyright ownership.  FCSoft licenses
9//   this file to You under the Apache License, Version 2.0 (the "License");
10//   you may not use this file except in compliance with the License.  You
11//   may obtain a copy of the License at
12//
13//     http://www.apache.org/licenses/LICENSE-2.0
14//
15//   Unless required by applicable law or agreed to in writing, software
16//   distributed under the License is distributed on an "AS IS" BASIS,
17//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18//   See the License for the specific language governing permissions and
19//   limitations under the License.
20// </license>
21// ----------------------------------------------------------------------------
22
23namespace FCSoft.SilverFrost.Framework.Web.UI.WebControls
24{
25    using System.Collections.Specialized;
26    using System.ComponentModel;
27    using System.Drawing.Design;
28    using System.Web;
29    using System.Web.UI;
30    using System.Web.UI.WebControls;
31
32
33    /// <summary>
34    /// ローカライズされたメッセージを表すコントロールです。
35    /// </summary>
36    [ParseChildren(true)]
37    [PersistChildren(false)]
38    [ControlBuilder(typeof(ControlBuilder))]
39    [ToolboxData("<{0}:LocalizedMessage runat=\"server\" Text=\"message\"/>")]
40    [WebDescription("Description_LocalizedMessage")]
41    [ControlInitializerTarget]
42    public class LocalizedMessage :
43        Localize
44    {
45        /// <summary>
46        /// テキストのパラメータ。
47        /// </summary>
48        private ParameterCollection textParameters;
49
50        /// <summary>
51        /// 表示するかどうか。
52        /// </summary>
53        private bool visible;
54
55 
56        /// <summary>
57        /// インスタンスを作成します。
58        /// </summary>
59        public LocalizedMessage()
60        {
61            ControlInitializer.ApplyProperties(this);
62        }
63
64
65        /// <summary>
66        /// サーバー コントロールを UI としてページに表示するかどうかを示す値を取得または設定します。
67        /// </summary>
68        /// <value>
69        /// コントロールがページに表示される場合は <see langword="true"/>。
70        /// それ以外の場合は <see langword="false"/>。
71        /// 既定値は <see langword="false"/>。
72        /// </value>
73        /// <remarks>
74        /// このプロパティの値はポストバックされる度に <see langword="false"/> になります。
75        /// </remarks>
76        [DefaultValue(false)]
77        public override bool Visible
78        {
79            get
80            {
81                return visible;
82            }
83
84            set
85            {
86                visible = value;
87            }
88        }
89
90        /// <summary>
91        /// <see cref="Text"/> プロパティに埋め込むためのパラメータコレクションです。
92        /// パラメータの名前は無視され、並び順だけが意識されます。
93        /// </summary>
94        /// <value>
95        /// <see cref="Text"/> プロパティに埋め込むためのパラメータコレクション。
96        /// </value>
97        [Editor("System.Web.UI.Design.WebControls.ParameterCollectionEditor, " + AssemblyRef.SystemDesign, typeof(UITypeEditor))]
98        [MergableProperty(false)]
99        [PersistenceMode(PersistenceMode.InnerProperty)]
100        [Themeable(false)]
101        [DefaultValue(null)]
102        [WebCategory("Appearance")]
103        [WebDescription("Description_LocalizedMessage_TextParameters")]
104        public ParameterCollection TextParameters
105        {
106            get
107            {
108                if (textParameters == null)
109                {
110                    textParameters = new ParameterCollection();
111
112                    if (IsTrackingViewState)
113                    {
114                        ((IStateManager)textParameters).TrackViewState();
115                    }
116                }
117
118                return textParameters;
119            }
120        }
121
122
123        /// <summary>
124        /// <see cref="LocalizedMessage"/> コントロールに XML 要素または HTML 要素が解析されたことを通知し、
125        /// その要素をコントロールの <see cref="ControlCollection"/> に追加します。
126        /// </summary>
127        /// <param name="obj">
128        /// 解析された要素を表す <see cref="object"/>。
129        /// </param>
130        protected override void AddParsedSubObject(object obj)
131        {
132            Control control = obj as Control;
133            if (control != null)
134            {
135                Controls.Add(control);
136            }
137        }
138
139        /// <summary>
140        /// コントロールへの変更の追跡および保存の開始点を、
141        /// コントロールのビューステートの一部としてマークします。
142        /// </summary>
143        protected override void TrackViewState()
144        {
145            // 親を呼び出す
146            base.TrackViewState();
147
148            if (textParameters != null)
149            {
150                ((IStateManager)textParameters).TrackViewState();
151            }
152        }
153
154        /// <summary>
155        /// <see cref="LocalizedMessage"/> コントロールの保存された状態を読み込みます。
156        /// </summary>
157        /// <param name="savedState">
158        /// <see cref="LocalizedMessage"/> の保存された状態を格納している
159        /// <see cref="object"/>。
160        /// </param>
161        protected override void LoadViewState(object savedState)
162        {
163            if (savedState == null)
164            {
165                return;
166            }
167
168            Pair state = (Pair)savedState;
169
170            // 親を呼び出す
171            base.LoadViewState(state.First);
172
173            if (state.Second != null)
174            {
175                ((IStateManager)TextParameters).LoadViewState(state.Second);
176            }
177        }
178
179        /// <summary>
180        /// <see cref="LocalizedMessage"/> コントロールの状態を格納します。
181        /// </summary>
182        /// <returns>
183        /// <see cref="LocalizedMessage"/> の保存された状態を格納しているオブジェクト。
184        /// </returns>
185        protected override object SaveViewState()
186        {
187            Pair state = new Pair();
188
189            // 親を呼び出す
190            state.First = base.SaveViewState();
191
192            if (textParameters != null)
193            {
194                state.Second = ((IStateManager)textParameters).SaveViewState();
195            }
196
197            if (state.First == null && state.Second == null)
198            {
199                return null;
200            }
201
202            return state;
203        }
204
205        /// <summary>
206        /// 提供されたクライアントに表示される内容を書き込む
207        /// <see cref="HtmlTextWriter"/> オブジェクトに、サーバー コントロールの内容を送信します。
208        /// </summary>
209        /// <param name="writer">
210        /// ライタ。
211        /// </param>
212        protected override void Render(HtmlTextWriter writer)
213        {
214            string text = Text;
215            if (string.IsNullOrEmpty(text))
216            {
217                return;
218            }
219
220            text = FormatText(text);
221
222            if (Mode != LiteralMode.Encode)
223            {
224                writer.Write(text);
225                return;
226            }
227
228            HttpUtility.HtmlEncode(text, writer);
229        }
230
231
232        /// <summary>
233        /// 指定した文字列をフォーマットして返します。
234        /// </summary>
235        /// <param name="value">
236        /// 文字列。
237        /// </param>
238        /// <returns>
239        /// フォーマットした文字列。
240        /// </returns>
241        protected virtual string FormatText(string value)
242        {
243            object[] formatArgs;
244
245            // パラメータを埋め込む
246            if (textParameters != null)
247            {
248                IOrderedDictionary values = textParameters.GetValues(Context, this);
249                formatArgs = new object[textParameters.Count];
250                values.Values.CopyTo(formatArgs, 0);
251            }
252            else
253            {
254                formatArgs = new object[0];
255            }
256
257            return Utility.Format(value, formatArgs);
258        }
259    }
260}
詳しい使い方は TracBrowser を参照してください。