* X11Dnd.cs: Drop to a control with another control on top of
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / ToolBar.cs
1 // System.Windows.Forms.ToolBar.cs
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining
4 // a copy of this software and associated documentation files (the
5 // "Software"), to deal in the Software without restriction, including
6 // without limitation the rights to use, copy, modify, merge, publish,
7 // distribute, sublicense, and/or sell copies of the Software, and to
8 // permit persons to whom the Software is furnished to do so, subject to
9 // the following conditions:
10 //
11 // The above copyright notice and this permission notice shall be
12 // included in all copies or substantial portions of the Software.
13 //
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 //
22 // Author:
23 //      Ravindra (rkumar@novell.com)
24 //      Mike Kestner <mkestner@novell.com>
25 //
26 // TODO:
27 //   - Tooltip
28 //
29 // Copyright (C) 2004-2006  Novell, Inc. (http://www.novell.com)
30 //
31
32
33 // NOT COMPLETE
34
35 using System.Collections;
36 using System.ComponentModel;
37 using System.ComponentModel.Design;
38 using System.Drawing;
39 using System.Drawing.Imaging;
40 using System.Runtime.InteropServices;
41
42 namespace System.Windows.Forms
43 {       
44         [DefaultEvent ("ButtonClick")]
45         [DefaultProperty ("Buttons")]
46         [Designer ("System.Windows.Forms.Design.ToolBarDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
47         public class ToolBar : Control
48         {
49                 #region Instance Variables
50                 bool size_specified = false;
51                 ToolBarButton current_button;
52                 #endregion Instance Variables
53
54                 #region Events
55                 [Browsable (false)]
56                 [EditorBrowsable (EditorBrowsableState.Never)]
57                 public new event EventHandler BackColorChanged {
58                         add { base.BackColorChanged += value; }
59                         remove { base.BackColorChanged -= value; }
60                 }
61
62                 [Browsable (false)]
63                 [EditorBrowsable (EditorBrowsableState.Never)]
64                 public new event EventHandler BackgroundImageChanged {
65                         add { base.BackgroundImageChanged += value; }
66                         remove { base.BackgroundImageChanged -= value; }
67                 }
68
69                 public event ToolBarButtonClickEventHandler ButtonClick;
70                 public event ToolBarButtonClickEventHandler ButtonDropDown;
71
72                 [Browsable (false)]
73                 [EditorBrowsable (EditorBrowsableState.Never)]
74                 public new event EventHandler ForeColorChanged {
75                         add { base.ForeColorChanged += value; }
76                         remove { base.ForeColorChanged -= value; }
77                 }
78
79                 [Browsable (false)]
80                 [EditorBrowsable (EditorBrowsableState.Never)]
81                 public new event EventHandler ImeModeChanged {
82                         add { base.ImeModeChanged += value; }
83                         remove { base.ImeModeChanged -= value; }
84                 }
85
86                 [Browsable (false)]
87                 [EditorBrowsable (EditorBrowsableState.Never)]
88                 public new event PaintEventHandler Paint {
89                         add { base.Paint += value; }
90                         remove { base.Paint -= value; }
91                 }
92
93                 [Browsable (false)]
94                 [EditorBrowsable (EditorBrowsableState.Never)]
95                 public new event EventHandler RightToLeftChanged {
96                         add { base.RightToLeftChanged += value; }
97                         remove { base.RightToLeftChanged -= value; }
98                 }
99
100                 [Browsable (false)]
101                 [EditorBrowsable (EditorBrowsableState.Never)]
102                 public new event EventHandler TextChanged {
103                         add { base.TextChanged += value; }
104                         remove { base.TextChanged -= value; }
105                 }
106                 #endregion Events
107
108                 #region Constructor
109                 public ToolBar ()
110                 {
111                         background_color = ThemeEngine.Current.DefaultControlBackColor;
112                         foreground_color = ThemeEngine.Current.DefaultControlForeColor;
113                         buttons = new ToolBarButtonCollection (this);
114                         dock_style = DockStyle.Top;
115                         
116                         MouseDown += new MouseEventHandler (ToolBar_MouseDown);
117                         MouseLeave += new EventHandler (ToolBar_MouseLeave);
118                         MouseMove += new MouseEventHandler (ToolBar_MouseMove);
119                         MouseUp += new MouseEventHandler (ToolBar_MouseUp);
120
121                         SetStyle (ControlStyles.UserPaint, false);
122                         SetStyle (ControlStyles.FixedHeight, true);
123                 }
124                 #endregion Constructor
125
126                 #region protected Properties
127                 protected override CreateParams CreateParams 
128                 {
129                         get { return base.CreateParams; }
130                 }
131
132                 protected override ImeMode DefaultImeMode {
133                         get { return ImeMode.Disable; }
134                 }
135
136                 protected override Size DefaultSize {
137                         get { return ThemeEngine.Current.ToolBarDefaultSize; }
138                 }
139                 #endregion
140
141                 ToolBarAppearance appearance = ToolBarAppearance.Normal;
142
143                 #region Public Properties
144                 [DefaultValue (ToolBarAppearance.Normal)]
145                 [Localizable (true)]
146                 public ToolBarAppearance Appearance {
147                         get { return appearance; }
148                         set {
149                                 if (value == appearance)
150                                         return;
151
152                                 appearance = value;
153                                 Redraw (false);
154                         }
155                 }
156
157                 bool autosize = true;
158
159                 [DefaultValue (true)]
160                 [Localizable (true)]
161                 public bool AutoSize {
162                         get { return autosize; }
163                         set {
164                                 if (value == autosize)
165                                         return;
166
167                                 autosize = value;
168                                 Redraw (true);
169                         }
170                 }
171
172                 [Browsable (false)]
173                 [EditorBrowsable (EditorBrowsableState.Never)]
174                 public override Color BackColor {
175                         get { return background_color; }
176                         set {
177                                 if (value == background_color)
178                                         return;
179
180                                 background_color = value;
181                                 OnBackColorChanged (EventArgs.Empty);
182                                 Redraw (false);
183                         }
184                 }
185
186                 [Browsable (false)]
187                 [EditorBrowsable (EditorBrowsableState.Never)]
188                 public override Image BackgroundImage {
189                         get { return background_image; }
190                         set {
191                                 if (value == background_image)
192                                         return;
193
194                                 background_image = value;
195                                 OnBackgroundImageChanged (EventArgs.Empty);
196                                 Redraw (false);
197                         }
198                 }
199
200                 [DefaultValue (BorderStyle.None)]
201                 [DispIdAttribute (-504)]
202                 public BorderStyle BorderStyle {
203                         get { return InternalBorderStyle; }
204                         set { InternalBorderStyle = value; }
205                 }
206
207                 ToolBarButtonCollection buttons;
208
209                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
210                 [Localizable (true)]
211                 [MergableProperty (false)]
212                 public ToolBarButtonCollection Buttons {
213                         get { return buttons; }
214                 }
215
216                 Size button_size;
217
218                 [Localizable (true)]
219                 [RefreshProperties (RefreshProperties.All)]
220                 public Size ButtonSize {
221                         get {
222                                 if (button_size.IsEmpty) {
223                                         if (buttons.Count == 0)
224                                                 return new Size (39, 36);
225                                         else
226                                                 return CalcButtonSize ();
227                                 }
228                                 return button_size;
229                         }
230                         set {
231                                 size_specified = true;
232                                 if (button_size == value)
233                                         return;
234
235                                 button_size = value;
236                                 Redraw (true);
237                         }
238                 }
239
240                 bool divider = true;
241
242                 [DefaultValue (true)]
243                 public bool Divider {
244                         get { return divider; }
245                         set {
246                                 if (value == divider)
247                                         return;
248
249                                 divider = value;
250                                 Redraw (false);
251                         }
252                 }
253
254                 [DefaultValue (DockStyle.Top)]
255                 [Localizable (true)]
256                 public override DockStyle Dock {
257                         get { return base.Dock; }
258                         set { base.Dock = value; } 
259                 }
260
261                 bool drop_down_arrows = false;
262
263                 [DefaultValue (false)]
264                 [Localizable (true)]
265                 public bool DropDownArrows {
266                         get { return drop_down_arrows; }
267                         set {
268                                 if (value == drop_down_arrows)
269                                         return;
270
271                                 drop_down_arrows = value;
272                                 Redraw (true);
273                         }
274                 }
275
276                 [Browsable (false)]
277                 [EditorBrowsable (EditorBrowsableState.Never)]
278                 public override Color ForeColor {
279                         get { return foreground_color; }
280                         set {
281                                 if (value == foreground_color)
282                                         return;
283
284                                 foreground_color = value;
285                                 OnForeColorChanged (EventArgs.Empty);
286                                 Redraw (false);
287                         }
288                 }
289
290                 ImageList image_list;
291
292                 [DefaultValue (null)]
293                 public ImageList ImageList {
294                         get { return image_list; }
295                         set { image_list = value; }
296                 }
297
298                 [Browsable (false)]
299                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
300                 [EditorBrowsable (EditorBrowsableState.Advanced)]
301                 public Size ImageSize {
302                         get {
303                                 if (ImageList == null)
304                                         return Size.Empty;
305
306                                 return ImageList.ImageSize;
307                         }
308                 }
309
310                 ImeMode ime_mode;
311
312                 [Browsable (false)]
313                 [EditorBrowsable (EditorBrowsableState.Never)]
314                 public new ImeMode ImeMode {
315                         get { return ime_mode; }
316                         set {
317                                 if (value == ime_mode)
318                                         return;
319
320                                 ime_mode = value;
321                                 OnImeModeChanged (EventArgs.Empty);
322                         }
323                 }
324
325                 [Browsable (false)]
326                 [EditorBrowsable (EditorBrowsableState.Never)]
327                 public override RightToLeft RightToLeft {
328                         get { return base.RightToLeft; }
329                         set {
330                                 if (value == base.RightToLeft)
331                                         return;
332
333                                 base.RightToLeft = value;
334                                 OnRightToLeftChanged (EventArgs.Empty);
335                         }
336                 }
337
338                 bool show_tooltips = false;
339
340                 [DefaultValue (false)]
341                 [Localizable (true)]
342                 public bool ShowToolTips {
343                         get { return show_tooltips; }
344                         set { show_tooltips = value; }
345                 }
346
347                 [DefaultValue (false)]
348                 public new bool TabStop {
349                         get { return base.TabStop; }
350                         set { base.TabStop = value; }
351                 }
352
353                 [Bindable (false)]
354                 [Browsable (false)]
355                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
356                 [EditorBrowsable (EditorBrowsableState.Never)]
357                 public override string Text {
358                         get { return text; } 
359                         set {
360                                 if (value == text)
361                                         return;
362
363                                 text = value;
364                                 Redraw (true);
365                                 OnTextChanged (EventArgs.Empty);
366                         }
367                 }
368
369                 ToolBarTextAlign text_alignment = ToolBarTextAlign.Underneath;
370
371                 [DefaultValue (ToolBarTextAlign.Underneath)]
372                 [Localizable (true)]
373                 public ToolBarTextAlign TextAlign {
374                         get { return text_alignment; }
375                         set {
376                                 if (value == text_alignment)
377                                         return;
378
379                                 text_alignment = value;
380                                 Redraw (true);
381                         }
382                 }
383
384                 bool wrappable = true;
385
386                 [DefaultValue (true)]
387                 [Localizable (true)]
388                 public bool Wrappable {
389                         get { return wrappable; }
390                         set {
391                                 if (value == wrappable)
392                                         return;
393
394                                 wrappable = value;
395                                 Redraw (true);
396                         }
397                 }
398                 #endregion Public Properties
399
400                 #region Public Methods
401                 public override string ToString ()
402                 {
403                         int count = this.Buttons.Count;
404
405                         if (count == 0)
406                                 return string.Format ("System.Windows.Forms.ToolBar, Button.Count: 0");
407                         else
408                                 return string.Format ("System.Windows.Forms.ToolBar, Button.Count: {0}, Buttons[0]: {1}",
409                                                       count, this.Buttons [0].ToString ());
410                 }
411                 #endregion Public Methods
412
413                 #region Protected Methods
414                 protected override void CreateHandle ()
415                 {
416                         base.CreateHandle ();
417                 }
418
419                 protected override void Dispose (bool disposing)
420                 {
421                         if (disposing)
422                                 ImageList = null;
423
424                         base.Dispose (disposing);
425                 }
426
427                 protected virtual void OnButtonClick (ToolBarButtonClickEventArgs e)
428                 {
429                         if (e.Button.Style == ToolBarButtonStyle.ToggleButton) {
430                                 if (! e.Button.Pushed)
431                                         e.Button.Pushed = true;
432                                 else
433                                         e.Button.Pushed = false;
434                         }
435                         e.Button.pressed = false;
436
437                         Invalidate (e.Button.Rectangle);
438                         Redraw (false);
439
440                         if (ButtonClick != null)
441                                 ButtonClick (this, e);
442                 }
443
444                 protected virtual void OnButtonDropDown (ToolBarButtonClickEventArgs e) 
445                 {
446                         if (ButtonDropDown != null)
447                                 ButtonDropDown (this, e);
448
449                         if (e.Button.DropDownMenu == null)
450                                 return;
451
452                         Point loc = new Point (e.Button.Rectangle.X + 1, e.Button.Rectangle.Bottom + 1);
453                         ((ContextMenu) e.Button.DropDownMenu).Show (this, loc);
454
455                         e.Button.dd_pressed = false;
456                         Invalidate (e.Button.Rectangle);
457                 }
458
459                 protected override void OnFontChanged (EventArgs e)
460                 {
461                         base.OnFontChanged (e);
462                         Redraw (true);
463                 }
464
465                 protected override void OnHandleCreated (EventArgs e)
466                 {
467                         base.OnHandleCreated (e);
468                 }
469
470                 protected override void OnResize (EventArgs e)
471                 {
472                         base.OnResize (e);
473
474                         if (Width <= 0 || Height <= 0 || !Visible)
475                                 return;
476
477                         Redraw (true);
478                 }
479
480                 protected override void SetBoundsCore (int x, int y, int width, int height, BoundsSpecified specified)
481                 {
482                         base.SetBoundsCore (x, y, width, height, specified);
483                 }
484
485                 protected override void WndProc (ref Message m)
486                 {
487                         base.WndProc (ref m);
488                 }
489
490                 #endregion Protected Methods
491
492                 #region Private Methods
493                 private void ToolBar_MouseDown (object sender, MouseEventArgs me)
494                 {
495                         if (!Enabled) 
496                                 return;
497
498                         Point loc = new Point (me.X, me.Y);
499
500                         // draw the pushed button
501                         foreach (ToolBarButton button in buttons) {
502                                 if (button.Enabled && button.Rectangle.Contains (loc)) {
503                                         // Mark the DropDown rect as pressed.
504                                         // We don't redraw the dropdown rect.
505                                         if (button.Style == ToolBarButtonStyle.DropDownButton) {
506                                                 Rectangle rect = button.Rectangle;
507                                                 rect.Width = ThemeEngine.Current.ToolBarDropDownWidth;
508                                                 rect.X = button.Rectangle.Right - rect.Width;
509                                                 if (rect.Contains (loc)) {
510                                                         if (button.DropDownMenu != null) {
511                                                                 button.dd_pressed = true;
512                                                                 Invalidate (rect);
513                                                         }
514                                                         break;
515                                                 }
516                                         }
517                                         button.pressed = true;
518                                         button.inside = true;
519                                         Invalidate (button.Rectangle);
520                                         break;
521                                 }
522                         }
523                 }
524
525                 private void ToolBar_MouseUp (object sender, MouseEventArgs me)
526                 {
527                         if (!Enabled) 
528                                 return;
529
530                         Point loc = new Point (me.X, me.Y);
531
532                         // draw the normal button
533                         // Make a copy in case the list is modified during enumeration
534                         ArrayList buttons = new ArrayList (this.buttons);
535                         foreach (ToolBarButton button in buttons) {
536                                 if (button.Enabled && button.Rectangle.Contains (loc)) {
537                                         if (button.Style == ToolBarButtonStyle.DropDownButton) {
538                                                 Rectangle ddRect = button.Rectangle;
539                                                 ddRect.Width = ThemeEngine.Current.ToolBarDropDownWidth;
540                                                 ddRect.X = button.Rectangle.Right - ddRect.Width;
541                                                 if (ddRect.Contains (loc)) {
542                                                         if (button.dd_pressed)
543                                                                 OnButtonDropDown (new ToolBarButtonClickEventArgs (button));
544                                                         continue;
545                                                 }
546                                         }
547                                         // Fire a ButtonClick
548                                         if (button.pressed)
549                                                 OnButtonClick (new ToolBarButtonClickEventArgs (button));
550                                 } else if (button.pressed) {
551                                         button.pressed = false;
552                                         Invalidate (button.Rectangle);
553                                 }
554                         }
555                 }
556
557                 private void ToolBar_MouseLeave (object sender, EventArgs e)
558                 {
559                         if (!Enabled || appearance != ToolBarAppearance.Flat || current_button == null) 
560                                 return;
561
562                         if (current_button.Hilight) {
563                                 current_button.Hilight = false;
564                                 Invalidate (current_button.Rectangle);
565                                 Redraw (false);
566                         }
567                         current_button = null;
568                 }
569
570                 private void ToolBar_MouseMove (object sender, MouseEventArgs me)
571                 {
572                         if (!Enabled) 
573                                 return;
574
575                         Point loc = new Point (me.X, me.Y);
576
577                         if (this.Capture) {
578                                 // If the button was pressed and we leave, release the 
579                                 // button press and vice versa
580                                 foreach (ToolBarButton button in buttons) {
581                                         if (button.pressed &&
582                                             (button.inside != button.Rectangle.Contains (loc))) {
583                                                 button.inside = button.Rectangle.Contains (loc);
584                                                 button.Hilight = false;
585                                                 Invalidate (button.Rectangle);
586                                                 Redraw (false);
587                                                 break;
588                                         }
589                                 }
590                         }
591                         // following is only for flat style toolbar
592                         else if (appearance == ToolBarAppearance.Flat) {
593                                 if (current_button != null && current_button.Rectangle.Contains (loc)) {
594                                         if (current_button.Hilight || current_button.Pushed)
595                                                 return;
596                                         current_button.Hilight = true;
597                                         Invalidate (current_button.Rectangle);
598                                         Redraw (false);
599                                 }
600                                 else {
601                                         foreach (ToolBarButton button in buttons) {
602                                                 if (button.Rectangle.Contains (loc) && button.Enabled) {
603                                                         current_button = button;
604                                                         if (current_button.Hilight || current_button.Pushed)
605                                                                 continue;
606                                                         current_button.Hilight = true;
607                                                         Invalidate (current_button.Rectangle);
608                                                         Redraw (false);
609                                                 }
610                                                 else if (button.Hilight) {
611                                                         button.Hilight = false;
612                                                         Invalidate (button.Rectangle);
613                                                         Redraw (false);
614                                                 }
615                                         }
616                                 }
617                         }
618                 }
619
620                 internal override void OnPaintInternal (PaintEventArgs pevent)
621                 {
622                         ThemeEngine.Current.DrawToolBar (pevent.Graphics, pevent.ClipRectangle, this);
623                 }
624
625                 internal void Redraw (bool recalculate)
626                 {
627                         if (recalculate)
628                                 Layout ();
629
630                         Refresh ();
631                 }
632
633                 private Size CalcButtonSize ()
634                 {
635                         String longestText = buttons [0].Text;
636                         for (int i = 1; i < buttons.Count; i++) {
637                                 if (buttons[i].Text.Length > longestText.Length)
638                                         longestText = buttons[i].Text;
639                         }
640
641                         SizeF sz = this.DeviceContext.MeasureString (longestText, this.Font);
642                         Size size = new Size ((int) Math.Ceiling (sz.Width), (int) Math.Ceiling (sz.Height));
643
644                         if (ImageList != null) {
645                                 // adjustment for the image grip 
646                                 int imgWidth = this.ImageSize.Width + 2 * ThemeEngine.Current.ToolBarImageGripWidth; 
647                                 int imgHeight = this.ImageSize.Height + 2 * ThemeEngine.Current.ToolBarImageGripWidth;
648
649                                 if (text_alignment == ToolBarTextAlign.Right) {
650                                         size.Width = imgWidth + size.Width;
651                                         size.Height = (size.Height > imgHeight) ? size.Height : imgHeight;
652                                 }
653                                 else {
654                                         size.Height = imgHeight + size.Height;
655                                         size.Width = (size.Width > imgWidth) ? size.Width : imgWidth;
656                                 }
657                         }
658                         return size;
659                 }
660
661                 void Layout ()
662                 {
663                         Theme theme = ThemeEngine.Current;
664                         int ht = ButtonSize.Height + theme.ToolBarGripWidth;
665                         int x = theme.ToolBarGripWidth;
666                         int y = theme.ToolBarGripWidth;
667
668                         if (Wrappable) {
669                                 int separator_index = -1;
670
671                                 for (int i = 0; i < buttons.Count; i++) {
672                                         ToolBarButton button = buttons [i];
673
674                                         if (!button.Visible)
675                                                 continue;
676
677                                         if (size_specified)
678                                                 button.Layout (ButtonSize);
679                                         else
680                                                 button.Layout ();
681
682                                         bool is_separator = button.Style == ToolBarButtonStyle.Separator;
683
684                                         if (x + button.Rectangle.Width < Width || is_separator) {
685                                                 button.Location = new Point (x, y);
686                                                 x += button.Rectangle.Width;
687                                                 if (is_separator)
688                                                         separator_index = i;
689                                         } else if (separator_index > 0) { 
690                                                 i = separator_index;
691                                                 separator_index = -1;
692                                                 x = theme.ToolBarGripWidth;
693                                                 y += ht; 
694                                         } else {
695                                                 x = theme.ToolBarGripWidth;
696                                                 y += ht; 
697                                                 button.Location = new Point (x, y);
698                                                 x += button.Rectangle.Width;
699                                         }
700                                 }
701                                 if (AutoSize)
702                                         Height = y + ht;
703                         } else {
704                                 if (AutoSize)
705                                         Height = ht;
706                                 else
707                                         Height = DefaultSize.Height;
708                                 foreach (ToolBarButton button in buttons) {
709                                         if (size_specified)
710                                                 button.Layout (ButtonSize);
711                                         else
712                                                 button.Layout ();
713                                         button.Location = new Point (x, y);
714                                         x += button.Rectangle.Width;
715                                 }
716                         }
717                 }
718                 #endregion Private Methods
719
720                 #region subclass
721                 public class ToolBarButtonCollection : IList, ICollection, IEnumerable
722                 {
723                         #region instance variables
724                         private ArrayList list;
725                         private ToolBar owner;
726                         #endregion
727
728                         #region constructors
729                         public ToolBarButtonCollection (ToolBar owner)
730                         {
731                                 this.owner = owner;
732                                 list = new ArrayList ();
733                         }
734                         #endregion
735
736                         #region properties
737                         [Browsable (false)]
738                         public int Count {
739                                 get { return list.Count; }
740                         }
741
742                         public bool IsReadOnly {
743                                 get { return list.IsReadOnly; }
744                         }
745
746                         public virtual ToolBarButton this [int index] {
747                                 get { return (ToolBarButton) list [index]; }
748                                 set {
749                                         value.SetParent (owner);
750                                         list [index] = value;
751                                         owner.Redraw (true);
752                                 }
753                         }
754
755                         bool ICollection.IsSynchronized {
756                                 get { return list.IsSynchronized; }
757                         }
758
759                         object ICollection.SyncRoot {
760                                 get { return list.SyncRoot; }
761                         }
762
763                         bool IList.IsFixedSize {
764                                 get { return list.IsFixedSize; }
765                         }
766
767                         object IList.this [int index] {
768                                 get { return this [index]; }
769                                 set {
770                                         if (! (value is ToolBarButton))
771                                                 throw new ArgumentException("Not of type ToolBarButton", "value");
772                                         this [index] = (ToolBarButton) value;
773                                 }
774                         }
775                         #endregion
776
777                         #region methods
778                         public int Add (string text)
779                         {
780                                 ToolBarButton button = new ToolBarButton (text);
781                                 return this.Add (button);
782                         }
783
784                         public int Add (ToolBarButton button)
785                         {
786                                 int result;
787                                 button.SetParent (owner);
788                                 result = list.Add (button);
789                                 owner.Redraw (true);
790                                 return result;
791                         }
792
793                         public void AddRange (ToolBarButton [] buttons)
794                         {
795                                 foreach (ToolBarButton button in buttons)
796                                         Add (button);
797                         }
798
799                         public void Clear ()
800                         {
801                                 list.Clear ();
802                                 owner.Redraw (false);
803                         }
804
805                         public bool Contains (ToolBarButton button)
806                         {
807                                 return list.Contains (button);
808                         }
809
810                         public IEnumerator GetEnumerator ()
811                         {
812                                 return list.GetEnumerator ();
813                         }
814
815                         void ICollection.CopyTo (Array dest, int index)
816                         {
817                                 list.CopyTo (dest, index);
818                         }
819
820                         int IList.Add (object button)
821                         {
822                                 if (! (button is ToolBarButton)) {
823                                         throw new ArgumentException("Not of type ToolBarButton", "button");
824                                 }
825
826                                 return this.Add ((ToolBarButton) button);
827                         }
828
829                         bool IList.Contains (object button)
830                         {
831                                 if (! (button is ToolBarButton)) {
832                                         throw new ArgumentException("Not of type ToolBarButton", "button");
833                                 }
834
835                                 return this.Contains ((ToolBarButton) button);
836                         }
837
838                         int IList.IndexOf (object button)
839                         {
840                                 if (! (button is ToolBarButton)) {
841                                         throw new ArgumentException("Not of type ToolBarButton", "button");
842                                 }
843
844                                 return this.IndexOf ((ToolBarButton) button);
845                         }
846
847                         void IList.Insert (int index, object button)
848                         {
849                                 if (! (button is ToolBarButton)) {
850                                         throw new ArgumentException("Not of type ToolBarButton", "button");
851                                 }
852
853                                 this.Insert (index, (ToolBarButton) button);
854                         }
855
856                         void IList.Remove (object button)
857                         {
858                                 if (! (button is ToolBarButton)) {
859                                         throw new ArgumentException("Not of type ToolBarButton", "button");
860                                 }
861
862                                 this.Remove ((ToolBarButton) button);
863                         }
864
865                         public int IndexOf (ToolBarButton button)
866                         {
867                                 return list.IndexOf (button);
868                         }
869
870                         public void Insert (int index, ToolBarButton button)
871                         {
872                                 list.Insert (index, button);
873                                 owner.Redraw (true);
874                         }
875
876                         public void Remove (ToolBarButton button)
877                         {
878                                 list.Remove (button);
879                                 owner.Redraw (true);
880                         }
881
882                         public void RemoveAt (int index)
883                         {
884                                 list.RemoveAt (index);
885                                 owner.Redraw (true);
886                         }
887                         #endregion methods
888                 }
889                 #endregion subclass
890         }
891 }