New test.
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / ToolStripSeparator.cs
1 //
2 // ToolStripSeparator.cs
3 //
4 // Permission is hereby granted, free of charge, to any person obtaining
5 // a copy of this software and associated documentation files (the
6 // "Software"), to deal in the Software without restriction, including
7 // without limitation the rights to use, copy, modify, merge, publish,
8 // distribute, sublicense, and/or sell copies of the Software, and to
9 // permit persons to whom the Software is furnished to do so, subject to
10 // the following conditions:
11 // 
12 // The above copyright notice and this permission notice shall be
13 // included in all copies or substantial portions of the Software.
14 // 
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 //
23 // Copyright (c) 2006 Jonathan Pobst
24 //
25 // Authors:
26 //      Jonathan Pobst (monkey@jpobst.com)
27 //
28 #if NET_2_0
29
30 using System.Drawing;
31 using System.ComponentModel;
32
33 namespace System.Windows.Forms
34 {
35         public class ToolStripSeparator : ToolStripItem
36         {
37                 private bool auto_tool_tip;
38                 private ToolStripItemDisplayStyle display_style;
39                 private bool double_click_enabled;
40                 private ContentAlignment image_align;
41                 private int image_index;
42                 private ToolStripItemImageScaling image_scaling;
43                 private ContentAlignment text_align;
44                 private TextImageRelation text_image_relation;
45                 private string tool_tip_text;
46
47                 public ToolStripSeparator ()
48                 {
49                         this.ForeColor = SystemColors.ControlDark;
50                 }
51
52                 #region Public Properties
53                 [Browsable (false)]
54                 [EditorBrowsable (EditorBrowsableState.Never)]
55                 public bool AutoToolTip {
56                         get { return this.auto_tool_tip; }
57                         set { this.auto_tool_tip = value; }
58                 }
59
60                 public override bool CanSelect { get { return false; } }
61
62                 [Browsable (false)]
63                 [EditorBrowsable (EditorBrowsableState.Never)]
64                 public ToolStripItemDisplayStyle DisplayStyle {
65                         get { return this.display_style; }
66                         set { this.display_style = value; }
67                 }
68
69                 [Browsable (false)]
70                 [EditorBrowsable (EditorBrowsableState.Never)]
71                 public bool DoubleClickEnabled {
72                         get { return this.double_click_enabled; }
73                         set { this.double_click_enabled = value; }
74                 }
75
76                 [Browsable (false)]
77                 [EditorBrowsable (EditorBrowsableState.Never)]
78                 public override bool Enabled {
79                         get { return base.Enabled; }
80                         set { base.Enabled = value; }
81                 }
82
83                 [Browsable (false)]
84                 [EditorBrowsable (EditorBrowsableState.Never)]
85                 public override Font Font {
86                         get { return base.Font; }
87                         set { base.Font = value; }
88                 }
89
90                 [Browsable (false)]
91                 [EditorBrowsable (EditorBrowsableState.Never)]
92                 public override Image Image {
93                         get { return base.Image; }
94                         set { base.Image = value; }
95                 }
96
97                 [Browsable (false)]
98                 [EditorBrowsable (EditorBrowsableState.Never)]
99                 public ContentAlignment ImageAlign {
100                         get { return this.image_align; }
101                         set {
102                                 if (!Enum.IsDefined (typeof (ContentAlignment), value))
103                                         throw new InvalidEnumArgumentException (string.Format ("Enum argument value '{0}' is not valid for ContentAlignment", value));
104
105                                 this.image_align = value;
106                         }
107                 }
108
109                 [Browsable (false)]
110                 [EditorBrowsable (EditorBrowsableState.Never)]
111                 public int ImageIndex {
112                         get { return this.image_index; }
113                         set {
114                                 if (value < -1)
115                                         throw new ArgumentException ("ImageIndex cannot be less than -1");
116
117                                 this.image_index = value;
118                         }
119                 }
120
121                 [Browsable (false)]
122                 [EditorBrowsable (EditorBrowsableState.Never)]
123                 public ToolStripItemImageScaling ImageScaling {
124                         get { return this.image_scaling; }
125                         set { this.image_scaling = value; }
126                 }
127
128                 [Browsable (false)]
129                 [EditorBrowsable (EditorBrowsableState.Never)]
130                 public override string Text {
131                         get { return base.Text; }
132                         set { base.Text = value; }
133                 }
134
135                 [Browsable (false)]
136                 [EditorBrowsable (EditorBrowsableState.Never)]
137                 public ContentAlignment TextAlign {
138                         get { return this.text_align; }
139                         set {
140                                 if (!Enum.IsDefined (typeof (ContentAlignment), value))
141                                         throw new InvalidEnumArgumentException (string.Format ("Enum argument value '{0}' is not valid for ContentAlignment", value));
142
143                                 this.text_align = value;
144                         }
145                 }
146
147                 [Browsable (false)]
148                 [EditorBrowsable (EditorBrowsableState.Never)]
149                 public TextImageRelation TextImageRelation {
150                         get { return this.text_image_relation; }
151                         set { this.text_image_relation = value; }
152                 }
153
154                 [Browsable (false)]
155                 [EditorBrowsable (EditorBrowsableState.Never)]
156                 public string ToolTipText {
157                         get { return this.tool_tip_text; }
158                         set { this.tool_tip_text = value; }
159                 }
160                 #endregion
161
162                 #region Protected Properties
163                 protected internal override Padding DefaultMargin { get { return new Padding(); } }
164                 protected override Size DefaultSize { get { return new Size(6, 6); } }
165                 #endregion
166
167                 #region Public Methods
168                 public override Size GetPreferredSize (Size constrainingSize)
169                 {
170                         return new Size(6, 6);
171                 }
172                 #endregion
173
174                 #region Protected Methods
175                 protected override AccessibleObject CreateAccessibilityInstance ()
176                 {
177                         ToolStripItemAccessibleObject ao = new ToolStripItemAccessibleObject (this);
178
179                         ao.default_action = "Press";
180                         ao.role = AccessibleRole.Separator;
181                         ao.state = AccessibleStates.None;
182
183                         return ao;
184                 }
185                 
186                 [EditorBrowsable (EditorBrowsableState.Never)]
187                 protected override void OnFontChanged (EventArgs e)
188                 {
189                         base.OnFontChanged (e);
190                 }
191                 
192                 protected override void OnPaint (PaintEventArgs e)
193                 {
194                         base.OnPaint (e);
195                         
196                         if (this.Owner != null)
197                         {
198                                 if (this.IsOnDropDown)
199                                         this.Owner.Renderer.DrawSeparator (new ToolStripSeparatorRenderEventArgs (e.Graphics, this, this.Owner.Orientation == Orientation.Horizontal ? false : true));
200                                 else
201                                         this.Owner.Renderer.DrawSeparator (new ToolStripSeparatorRenderEventArgs (e.Graphics, this, this.Owner.Orientation == Orientation.Horizontal ? true : false));
202                         }
203                 }
204
205                 protected internal override void SetBounds (Rectangle bounds)
206                 {
207                         base.SetBounds (bounds);
208                 }
209                 #endregion
210
211                 #region Public Events
212                 [Browsable (false)]
213                 [EditorBrowsable (EditorBrowsableState.Never)]
214                 public event EventHandler DisplayStyleChanged;
215
216                 [Browsable (false)]
217                 [EditorBrowsable (EditorBrowsableState.Never)]
218                 public event EventHandler EnabledChanged;
219
220                 [Browsable (false)]
221                 [EditorBrowsable (EditorBrowsableState.Never)]
222                 public event EventHandler TextChanged;
223                 #endregion
224         }
225 }
226 #endif