Fix bug #395
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / ToolStripOverflowButton.cs
1 //
2 // ToolStripOverflowButton.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) 2007 Novell
24 //
25 // Authors:
26 //      Jonathan Pobst (monkey@jpobst.com)
27 //
28
29 using System;
30 using System.Runtime.InteropServices;
31 using System.ComponentModel;
32 using System.Drawing;
33 using System.Windows.Forms.Design;
34
35 namespace System.Windows.Forms
36 {
37         [ToolStripItemDesignerAvailability (ToolStripItemDesignerAvailability.None)]
38         public class ToolStripOverflowButton : ToolStripDropDownButton
39         {
40                 #region Internal Constructor
41                 internal ToolStripOverflowButton (ToolStrip ts)
42                 {
43                         this.InternalOwner = ts;
44                         this.Parent = ts;
45                         this.Visible = false;
46                 }
47                 #endregion
48                 
49                 #region Public Properties
50                 public override bool HasDropDownItems {
51                         get { 
52                                 if (this.drop_down == null)
53                                         return false;
54                                         
55                                 return this.DropDown.DisplayedItems.Count > 0; 
56                         }
57                 }
58
59                 [Browsable (false)]
60                 [EditorBrowsable (EditorBrowsableState.Never)]
61                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
62                 public new bool RightToLeftAutoMirrorImage {
63                         get { return base.RightToLeftAutoMirrorImage; }
64                         set { base.RightToLeftAutoMirrorImage = value; }
65                 }
66                 #endregion
67
68                 #region Protected Properties
69                 protected internal override Padding DefaultMargin {
70                         get { return new Padding (0, 1, 0, 2); }
71                 }
72                 #endregion
73
74                 #region Public Methods
75                 public override Size GetPreferredSize (Size constrainingSize)
76                 {
77                         return new Size (16, this.Parent.Height);
78                 }
79                 #endregion
80
81                 #region Protected Methods
82                 protected override AccessibleObject CreateAccessibilityInstance ()
83                 {
84                         return new ToolStripOverflowButtonAccessibleObject ();
85                 }
86                 
87                 protected override ToolStripDropDown CreateDefaultDropDown ()
88                 {
89                         ToolStripDropDown tsdd = new ToolStripOverflow (this);
90                         tsdd.DefaultDropDownDirection = ToolStripDropDownDirection.BelowLeft;
91                         tsdd.OwnerItem = this;
92                         return tsdd;
93                 }
94
95                 protected override void OnPaint (PaintEventArgs e)
96                 {
97                         if (this.Owner != null)
98                                 this.Owner.Renderer.DrawOverflowButtonBackground (new ToolStripItemRenderEventArgs (e.Graphics, this));
99                 }
100
101                 protected internal override void SetBounds (Rectangle bounds)
102                 {
103                         base.SetBounds (bounds);
104                 }
105                 #endregion
106
107                 #region ToolStripOverflowButtonAccessibleObject Class
108                 private class ToolStripOverflowButtonAccessibleObject : AccessibleObject
109                 {
110                 }
111                 #endregion
112         }
113 }