merge -r 60439:60440
[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                         foreach (ToolBarButton button in buttons) {
534                                 if (button.Enabled && button.Rectangle.Contains (loc)) {
535                                         if (button.Style == ToolBarButtonStyle.DropDownButton) {
536                                                 Rectangle ddRect = button.Rectangle;
537                                                 ddRect.Width = ThemeEngine.Current.ToolBarDropDownWidth;
538                                                 ddRect.X = button.Rectangle.Right - ddRect.Width;
539                                                 if (ddRect.Contains (loc)) {
540                                                         if (button.dd_pressed)
541                                                                 OnButtonDropDown (new ToolBarButtonClickEventArgs (button));
542                                                         continue;
543                                                 }
544                                         }
545                                         // Fire a ButtonClick
546                                         if (button.pressed)
547                                                 OnButtonClick (new ToolBarButtonClickEventArgs (button));
548                                 } else if (button.pressed) {
549                                         button.pressed = false;
550                                         Invalidate (button.Rectangle);
551                                 }
552                         }
553                 }
554
555                 private void ToolBar_MouseLeave (object sender, EventArgs e)
556                 {
557                         if (!Enabled || appearance != ToolBarAppearance.Flat || current_button == null) 
558                                 return;
559
560                         if (current_button.Hilight) {
561                                 current_button.Hilight = false;
562                                 Invalidate (current_button.Rectangle);
563                                 Redraw (false);
564                         }
565                         current_button = null;
566                 }
567
568                 private void ToolBar_MouseMove (object sender, MouseEventArgs me)
569                 {
570                         if (!Enabled) 
571                                 return;
572
573                         Point loc = new Point (me.X, me.Y);
574
575                         if (this.Capture) {
576                                 // If the button was pressed and we leave, release the 
577                                 // button press and vice versa
578                                 foreach (ToolBarButton button in buttons) {
579                                         if (button.pressed &&
580                                             (button.inside != button.Rectangle.Contains (loc))) {
581                                                 button.inside = button.Rectangle.Contains (loc);
582                                                 button.Hilight = false;
583                                                 Invalidate (button.Rectangle);
584                                                 Redraw (false);
585                                                 break;
586                                         }
587                                 }
588                         }
589                         // following is only for flat style toolbar
590                         else if (appearance == ToolBarAppearance.Flat) {
591                                 if (current_button != null && current_button.Rectangle.Contains (loc)) {
592                                         if (current_button.Hilight || current_button.Pushed)
593                                                 return;
594                                         current_button.Hilight = true;
595                                         Invalidate (current_button.Rectangle);
596                                         Redraw (false);
597                                 }
598                                 else {
599                                         foreach (ToolBarButton button in buttons) {
600                                                 if (button.Rectangle.Contains (loc) && button.Enabled) {
601                                                         current_button = button;
602                                                         if (current_button.Hilight || current_button.Pushed)
603                                                                 continue;
604                                                         current_button.Hilight = true;
605                                                         Invalidate (current_button.Rectangle);
606                                                         Redraw (false);
607                                                 }
608                                                 else if (button.Hilight) {
609                                                         button.Hilight = false;
610                                                         Invalidate (button.Rectangle);
611                                                         Redraw (false);
612                                                 }
613                                         }
614                                 }
615                         }
616                 }
617
618                 internal override void OnPaintInternal (PaintEventArgs pevent)
619                 {
620                         ThemeEngine.Current.DrawToolBar (pevent.Graphics, pevent.ClipRectangle, this);
621                 }
622
623                 internal void Redraw (bool recalculate)
624                 {
625                         if (recalculate)
626                                 Layout ();
627
628                         Refresh ();
629                 }
630
631                 private Size CalcButtonSize ()
632                 {
633                         String longestText = buttons [0].Text;
634                         for (int i = 1; i < buttons.Count; i++) {
635                                 if (buttons[i].Text.Length > longestText.Length)
636                                         longestText = buttons[i].Text;
637                         }
638
639                         SizeF sz = this.DeviceContext.MeasureString (longestText, this.Font);
640                         Size size = new Size ((int) Math.Ceiling (sz.Width), (int) Math.Ceiling (sz.Height));
641
642                         if (ImageList != null) {
643                                 // adjustment for the image grip 
644                                 int imgWidth = this.ImageSize.Width + 2 * ThemeEngine.Current.ToolBarImageGripWidth; 
645                                 int imgHeight = this.ImageSize.Height + 2 * ThemeEngine.Current.ToolBarImageGripWidth;
646
647                                 if (text_alignment == ToolBarTextAlign.Right) {
648                                         size.Width = imgWidth + size.Width;
649                                         size.Height = (size.Height > imgHeight) ? size.Height : imgHeight;
650                                 }
651                                 else {
652                                         size.Height = imgHeight + size.Height;
653                                         size.Width = (size.Width > imgWidth) ? size.Width : imgWidth;
654                                 }
655                         }
656                         return size;
657                 }
658
659                 void Layout ()
660                 {
661                         Theme theme = ThemeEngine.Current;
662                         int ht = ButtonSize.Height + theme.ToolBarGripWidth;
663                         int x = theme.ToolBarGripWidth;
664                         int y = theme.ToolBarGripWidth;
665
666                         if (Wrappable) {
667                                 int separator_index = -1;
668
669                                 for (int i = 0; i < buttons.Count; i++) {
670                                         ToolBarButton button = buttons [i];
671
672                                         if (!button.Visible)
673                                                 continue;
674
675                                         if (size_specified)
676                                                 button.Layout (ButtonSize);
677                                         else
678                                                 button.Layout ();
679
680                                         bool is_separator = button.Style == ToolBarButtonStyle.Separator;
681
682                                         if (x + button.Rectangle.Width < Width || is_separator) {
683                                                 button.Location = new Point (x, y);
684                                                 x += button.Rectangle.Width;
685                                                 if (is_separator)
686                                                         separator_index = i;
687                                         } else if (separator_index > 0) { 
688                                                 i = separator_index;
689                                                 separator_index = -1;
690                                                 x = theme.ToolBarGripWidth;
691                                                 y += ht; 
692                                         } else {
693                                                 x = theme.ToolBarGripWidth;
694                                                 y += ht; 
695                                                 button.Location = new Point (x, y);
696                                                 x += button.Rectangle.Width;
697                                         }
698                                 }
699                                 if (AutoSize)
700                                         Height = y + ht;
701                         } else {
702                                 if (AutoSize)
703                                         Height = ht;
704                                 else
705                                         Height = DefaultSize.Height;
706                                 foreach (ToolBarButton button in buttons) {
707                                         if (size_specified)
708                                                 button.Layout (ButtonSize);
709                                         else
710                                                 button.Layout ();
711                                         button.Location = new Point (x, y);
712                                         x += button.Rectangle.Width;
713                                 }
714                         }
715                 }
716                 #endregion Private Methods
717
718                 #region subclass
719                 public class ToolBarButtonCollection : IList, ICollection, IEnumerable
720                 {
721                         #region instance variables
722                         private ArrayList list;
723                         private ToolBar owner;
724                         #endregion
725
726                         #region constructors
727                         public ToolBarButtonCollection (ToolBar owner)
728                         {
729                                 this.owner = owner;
730                                 list = new ArrayList ();
731                         }
732                         #endregion
733
734                         #region properties
735                         [Browsable (false)]
736                         public int Count {
737                                 get { return list.Count; }
738                         }
739
740                         public bool IsReadOnly {
741                                 get { return list.IsReadOnly; }
742                         }
743
744                         public virtual ToolBarButton this [int index] {
745                                 get { return (ToolBarButton) list [index]; }
746                                 set {
747                                         value.SetParent (owner);
748                                         list [index] = value;
749                                         owner.Redraw (true);
750                                 }
751                         }
752
753                         bool ICollection.IsSynchronized {
754                                 get { return list.IsSynchronized; }
755                         }
756
757                         object ICollection.SyncRoot {
758                                 get { return list.SyncRoot; }
759                         }
760
761                         bool IList.IsFixedSize {
762                                 get { return list.IsFixedSize; }
763                         }
764
765                         object IList.this [int index] {
766                                 get { return this [index]; }
767                                 set {
768                                         if (! (value is ToolBarButton))
769                                                 throw new ArgumentException("Not of type ToolBarButton", "value");
770                                         this [index] = (ToolBarButton) value;
771                                 }
772                         }
773                         #endregion
774
775                         #region methods
776                         public int Add (string text)
777                         {
778                                 ToolBarButton button = new ToolBarButton (text);
779                                 return this.Add (button);
780                         }
781
782                         public int Add (ToolBarButton button)
783                         {
784                                 int result;
785                                 button.SetParent (owner);
786                                 result = list.Add (button);
787                                 owner.Redraw (true);
788                                 return result;
789                         }
790
791                         public void AddRange (ToolBarButton [] buttons)
792                         {
793                                 foreach (ToolBarButton button in buttons)
794                                         Add (button);
795                         }
796
797                         public void Clear ()
798                         {
799                                 list.Clear ();
800                                 owner.Redraw (false);
801                         }
802
803                         public bool Contains (ToolBarButton button)
804                         {
805                                 return list.Contains (button);
806                         }
807
808                         public IEnumerator GetEnumerator ()
809                         {
810                                 return list.GetEnumerator ();
811                         }
812
813                         void ICollection.CopyTo (Array dest, int index)
814                         {
815                                 list.CopyTo (dest, index);
816                         }
817
818                         int IList.Add (object button)
819                         {
820                                 if (! (button is ToolBarButton)) {
821                                         throw new ArgumentException("Not of type ToolBarButton", "button");
822                                 }
823
824                                 return this.Add ((ToolBarButton) button);
825                         }
826
827                         bool IList.Contains (object button)
828                         {
829                                 if (! (button is ToolBarButton)) {
830                                         throw new ArgumentException("Not of type ToolBarButton", "button");
831                                 }
832
833                                 return this.Contains ((ToolBarButton) button);
834                         }
835
836                         int IList.IndexOf (object button)
837                         {
838                                 if (! (button is ToolBarButton)) {
839                                         throw new ArgumentException("Not of type ToolBarButton", "button");
840                                 }
841
842                                 return this.IndexOf ((ToolBarButton) button);
843                         }
844
845                         void IList.Insert (int index, object button)
846                         {
847                                 if (! (button is ToolBarButton)) {
848                                         throw new ArgumentException("Not of type ToolBarButton", "button");
849                                 }
850
851                                 this.Insert (index, (ToolBarButton) button);
852                         }
853
854                         void IList.Remove (object button)
855                         {
856                                 if (! (button is ToolBarButton)) {
857                                         throw new ArgumentException("Not of type ToolBarButton", "button");
858                                 }
859
860                                 this.Remove ((ToolBarButton) button);
861                         }
862
863                         public int IndexOf (ToolBarButton button)
864                         {
865                                 return list.IndexOf (button);
866                         }
867
868                         public void Insert (int index, ToolBarButton button)
869                         {
870                                 list.Insert (index, button);
871                                 owner.Redraw (true);
872                         }
873
874                         public void Remove (ToolBarButton button)
875                         {
876                                 list.Remove (button);
877                                 owner.Redraw (true);
878                         }
879
880                         public void RemoveAt (int index)
881                         {
882                                 list.RemoveAt (index);
883                                 owner.Redraw (true);
884                         }
885                         #endregion methods
886                 }
887                 #endregion subclass
888         }
889 }