merge -r 61110:61111
[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 (24, 22);
225                                         Size result = CalcButtonSize ();
226                                         if (result.IsEmpty)
227                                                 return new Size (24, 22);
228                                         else
229                                                 return result;
230                                 }
231                                 return button_size;
232                         }
233                         set {
234                                 size_specified = true;
235                                 if (button_size == value)
236                                         return;
237
238                                 button_size = value;
239                                 Redraw (true);
240                         }
241                 }
242
243                 bool divider = true;
244
245                 [DefaultValue (true)]
246                 public bool Divider {
247                         get { return divider; }
248                         set {
249                                 if (value == divider)
250                                         return;
251
252                                 divider = value;
253                                 Redraw (false);
254                         }
255                 }
256
257                 [DefaultValue (DockStyle.Top)]
258                 [Localizable (true)]
259                 public override DockStyle Dock {
260                         get { return base.Dock; }
261                         set { base.Dock = value; } 
262                 }
263
264                 bool drop_down_arrows = false;
265
266                 [DefaultValue (false)]
267                 [Localizable (true)]
268                 public bool DropDownArrows {
269                         get { return drop_down_arrows; }
270                         set {
271                                 if (value == drop_down_arrows)
272                                         return;
273
274                                 drop_down_arrows = value;
275                                 Redraw (true);
276                         }
277                 }
278
279                 [Browsable (false)]
280                 [EditorBrowsable (EditorBrowsableState.Never)]
281                 public override Color ForeColor {
282                         get { return foreground_color; }
283                         set {
284                                 if (value == foreground_color)
285                                         return;
286
287                                 foreground_color = value;
288                                 OnForeColorChanged (EventArgs.Empty);
289                                 Redraw (false);
290                         }
291                 }
292
293                 ImageList image_list;
294
295                 [DefaultValue (null)]
296                 public ImageList ImageList {
297                         get { return image_list; }
298                         set { image_list = value; }
299                 }
300
301                 [Browsable (false)]
302                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
303                 [EditorBrowsable (EditorBrowsableState.Advanced)]
304                 public Size ImageSize {
305                         get {
306                                 if (ImageList == null)
307                                         return Size.Empty;
308
309                                 return ImageList.ImageSize;
310                         }
311                 }
312
313                 ImeMode ime_mode;
314
315                 [Browsable (false)]
316                 [EditorBrowsable (EditorBrowsableState.Never)]
317                 public new ImeMode ImeMode {
318                         get { return ime_mode; }
319                         set {
320                                 if (value == ime_mode)
321                                         return;
322
323                                 ime_mode = value;
324                                 OnImeModeChanged (EventArgs.Empty);
325                         }
326                 }
327
328                 [Browsable (false)]
329                 [EditorBrowsable (EditorBrowsableState.Never)]
330                 public override RightToLeft RightToLeft {
331                         get { return base.RightToLeft; }
332                         set {
333                                 if (value == base.RightToLeft)
334                                         return;
335
336                                 base.RightToLeft = value;
337                                 OnRightToLeftChanged (EventArgs.Empty);
338                         }
339                 }
340
341                 bool show_tooltips = false;
342
343                 [DefaultValue (false)]
344                 [Localizable (true)]
345                 public bool ShowToolTips {
346                         get { return show_tooltips; }
347                         set { show_tooltips = value; }
348                 }
349
350                 [DefaultValue (false)]
351                 public new bool TabStop {
352                         get { return base.TabStop; }
353                         set { base.TabStop = value; }
354                 }
355
356                 [Bindable (false)]
357                 [Browsable (false)]
358                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
359                 [EditorBrowsable (EditorBrowsableState.Never)]
360                 public override string Text {
361                         get { return text; } 
362                         set {
363                                 if (value == text)
364                                         return;
365
366                                 text = value;
367                                 Redraw (true);
368                                 OnTextChanged (EventArgs.Empty);
369                         }
370                 }
371
372                 ToolBarTextAlign text_alignment = ToolBarTextAlign.Underneath;
373
374                 [DefaultValue (ToolBarTextAlign.Underneath)]
375                 [Localizable (true)]
376                 public ToolBarTextAlign TextAlign {
377                         get { return text_alignment; }
378                         set {
379                                 if (value == text_alignment)
380                                         return;
381
382                                 text_alignment = value;
383                                 Redraw (true);
384                         }
385                 }
386
387                 bool wrappable = true;
388
389                 [DefaultValue (true)]
390                 [Localizable (true)]
391                 public bool Wrappable {
392                         get { return wrappable; }
393                         set {
394                                 if (value == wrappable)
395                                         return;
396
397                                 wrappable = value;
398                                 Redraw (true);
399                         }
400                 }
401                 #endregion Public Properties
402
403                 #region Public Methods
404                 public override string ToString ()
405                 {
406                         int count = this.Buttons.Count;
407
408                         if (count == 0)
409                                 return string.Format ("System.Windows.Forms.ToolBar, Button.Count: 0");
410                         else
411                                 return string.Format ("System.Windows.Forms.ToolBar, Button.Count: {0}, Buttons[0]: {1}",
412                                                       count, this.Buttons [0].ToString ());
413                 }
414                 #endregion Public Methods
415
416                 #region Protected Methods
417                 protected override void CreateHandle ()
418                 {
419                         base.CreateHandle ();
420                 }
421
422                 protected override void Dispose (bool disposing)
423                 {
424                         if (disposing)
425                                 ImageList = null;
426
427                         base.Dispose (disposing);
428                 }
429
430                 protected virtual void OnButtonClick (ToolBarButtonClickEventArgs e)
431                 {
432                         if (e.Button.Style == ToolBarButtonStyle.ToggleButton) {
433                                 if (! e.Button.Pushed)
434                                         e.Button.Pushed = true;
435                                 else
436                                         e.Button.Pushed = false;
437                         }
438                         e.Button.pressed = false;
439
440                         Invalidate (e.Button.Rectangle);
441                         Redraw (false);
442
443                         if (ButtonClick != null)
444                                 ButtonClick (this, e);
445                 }
446
447                 protected virtual void OnButtonDropDown (ToolBarButtonClickEventArgs e) 
448                 {
449                         if (ButtonDropDown != null)
450                                 ButtonDropDown (this, e);
451
452                         if (e.Button.DropDownMenu == null)
453                                 return;
454
455                         Point loc = new Point (e.Button.Rectangle.X + 1, e.Button.Rectangle.Bottom + 1);
456                         ((ContextMenu) e.Button.DropDownMenu).Show (this, loc);
457
458                         e.Button.dd_pressed = false;
459                         Invalidate (e.Button.Rectangle);
460                 }
461
462                 protected override void OnFontChanged (EventArgs e)
463                 {
464                         base.OnFontChanged (e);
465                         Redraw (true);
466                 }
467
468                 protected override void OnHandleCreated (EventArgs e)
469                 {
470                         base.OnHandleCreated (e);
471                 }
472
473                 protected override void OnResize (EventArgs e)
474                 {
475                         base.OnResize (e);
476
477                         if (Width <= 0 || Height <= 0 || !Visible)
478                                 return;
479
480                         Redraw (true);
481                 }
482
483                 protected override void SetBoundsCore (int x, int y, int width, int height, BoundsSpecified specified)
484                 {
485                         base.SetBoundsCore (x, y, width, height, specified);
486                 }
487
488                 protected override void WndProc (ref Message m)
489                 {
490                         base.WndProc (ref m);
491                 }
492
493                 #endregion Protected Methods
494
495                 #region Private Methods
496                 private void ToolBar_MouseDown (object sender, MouseEventArgs me)
497                 {
498                         if (!Enabled) 
499                                 return;
500
501                         Point loc = new Point (me.X, me.Y);
502
503                         // draw the pushed button
504                         foreach (ToolBarButton button in buttons) {
505                                 if (button.Enabled && button.Rectangle.Contains (loc)) {
506                                         // Mark the DropDown rect as pressed.
507                                         // We don't redraw the dropdown rect.
508                                         if (button.Style == ToolBarButtonStyle.DropDownButton) {
509                                                 Rectangle rect = button.Rectangle;
510                                                 rect.Width = ThemeEngine.Current.ToolBarDropDownWidth;
511                                                 rect.X = button.Rectangle.Right - rect.Width;
512                                                 if (rect.Contains (loc)) {
513                                                         if (button.DropDownMenu != null) {
514                                                                 button.dd_pressed = true;
515                                                                 Invalidate (rect);
516                                                         }
517                                                         break;
518                                                 }
519                                         }
520                                         button.pressed = true;
521                                         button.inside = true;
522                                         Invalidate (button.Rectangle);
523                                         break;
524                                 }
525                         }
526                 }
527
528                 private void ToolBar_MouseUp (object sender, MouseEventArgs me)
529                 {
530                         if (!Enabled) 
531                                 return;
532
533                         Point loc = new Point (me.X, me.Y);
534
535                         // draw the normal button
536                         // Make a copy in case the list is modified during enumeration
537                         ArrayList buttons = new ArrayList (this.buttons);
538                         foreach (ToolBarButton button in buttons) {
539                                 if (button.Enabled && button.Rectangle.Contains (loc)) {
540                                         if (button.Style == ToolBarButtonStyle.DropDownButton) {
541                                                 Rectangle ddRect = button.Rectangle;
542                                                 ddRect.Width = ThemeEngine.Current.ToolBarDropDownWidth;
543                                                 ddRect.X = button.Rectangle.Right - ddRect.Width;
544                                                 if (ddRect.Contains (loc)) {
545                                                         if (button.dd_pressed)
546                                                                 OnButtonDropDown (new ToolBarButtonClickEventArgs (button));
547                                                         continue;
548                                                 }
549                                         }
550                                         // Fire a ButtonClick
551                                         if (button.pressed)
552                                                 OnButtonClick (new ToolBarButtonClickEventArgs (button));
553                                 } else if (button.pressed) {
554                                         button.pressed = false;
555                                         Invalidate (button.Rectangle);
556                                 }
557                         }
558                 }
559
560                 private void ToolBar_MouseLeave (object sender, EventArgs e)
561                 {
562                         if (!Enabled || appearance != ToolBarAppearance.Flat || current_button == null) 
563                                 return;
564
565                         if (current_button.Hilight) {
566                                 current_button.Hilight = false;
567                                 Invalidate (current_button.Rectangle);
568                                 Redraw (false);
569                         }
570                         current_button = null;
571                 }
572
573                 private void ToolBar_MouseMove (object sender, MouseEventArgs me)
574                 {
575                         if (!Enabled) 
576                                 return;
577
578                         Point loc = new Point (me.X, me.Y);
579
580                         if (this.Capture) {
581                                 // If the button was pressed and we leave, release the 
582                                 // button press and vice versa
583                                 foreach (ToolBarButton button in buttons) {
584                                         if (button.pressed &&
585                                             (button.inside != button.Rectangle.Contains (loc))) {
586                                                 button.inside = button.Rectangle.Contains (loc);
587                                                 button.Hilight = false;
588                                                 Invalidate (button.Rectangle);
589                                                 Redraw (false);
590                                                 break;
591                                         }
592                                 }
593                         }
594                         // following is only for flat style toolbar
595                         else if (appearance == ToolBarAppearance.Flat) {
596                                 if (current_button != null && current_button.Rectangle.Contains (loc)) {
597                                         if (current_button.Hilight || current_button.Pushed)
598                                                 return;
599                                         current_button.Hilight = true;
600                                         Invalidate (current_button.Rectangle);
601                                         Redraw (false);
602                                 }
603                                 else {
604                                         foreach (ToolBarButton button in buttons) {
605                                                 if (button.Rectangle.Contains (loc) && button.Enabled) {
606                                                         current_button = button;
607                                                         if (current_button.Hilight || current_button.Pushed)
608                                                                 continue;
609                                                         current_button.Hilight = true;
610                                                         Invalidate (current_button.Rectangle);
611                                                         Redraw (false);
612                                                 }
613                                                 else if (button.Hilight) {
614                                                         button.Hilight = false;
615                                                         Invalidate (button.Rectangle);
616                                                         Redraw (false);
617                                                 }
618                                         }
619                                 }
620                         }
621                 }
622
623                 internal override void OnPaintInternal (PaintEventArgs pevent)
624                 {
625                         ThemeEngine.Current.DrawToolBar (pevent.Graphics, pevent.ClipRectangle, this);
626                 }
627
628                 internal void Redraw (bool recalculate)
629                 {
630                         if (recalculate)
631                                 Layout ();
632
633                         Refresh ();
634                 }
635
636                 const int text_padding = 3;
637
638                 private Size CalcButtonSize ()
639                 {
640                         string longest_text = buttons [0].Text;
641                         for (int i = 1; i < buttons.Count; i++) {
642                                 if (buttons[i].Text.Length > longest_text.Length)
643                                         longest_text = buttons[i].Text;
644                         }
645
646                         Size size = Size.Empty;
647                         if (longest_text != null && longest_text.Length > 0) {
648                                 SizeF sz = this.DeviceContext.MeasureString (longest_text, this.Font);
649                                 size = new Size ((int) Math.Ceiling (sz.Width) + 2 * text_padding, (int) Math.Ceiling (sz.Height));
650                         }
651
652                         if (ImageList != null) {
653                                 // adjustment for the image grip 
654                                 int imgWidth = this.ImageSize.Width + 2 * ThemeEngine.Current.ToolBarImageGripWidth; 
655                                 int imgHeight = this.ImageSize.Height + 2 * ThemeEngine.Current.ToolBarImageGripWidth;
656
657                                 if (text_alignment == ToolBarTextAlign.Right) {
658                                         size.Width = imgWidth + size.Width;
659                                         size.Height = (size.Height > imgHeight) ? size.Height : imgHeight;
660                                 }
661                                 else {
662                                         size.Height = imgHeight + size.Height;
663                                         size.Width = (size.Width > imgWidth) ? size.Width : imgWidth;
664                                 }
665                         }
666                         return size;
667                 }
668
669                 void Layout ()
670                 {
671                         Theme theme = ThemeEngine.Current;
672                         int ht = ButtonSize.Height + theme.ToolBarGripWidth;
673                         int x = theme.ToolBarGripWidth;
674                         int y = theme.ToolBarGripWidth;
675
676                         if (Wrappable) {
677                                 int separator_index = -1;
678
679                                 for (int i = 0; i < buttons.Count; i++) {
680                                         ToolBarButton button = buttons [i];
681
682                                         if (!button.Visible)
683                                                 continue;
684
685                                         if (size_specified)
686                                                 button.Layout (ButtonSize);
687                                         else
688                                                 button.Layout ();
689
690                                         bool is_separator = button.Style == ToolBarButtonStyle.Separator;
691
692                                         if (x + button.Rectangle.Width < Width || is_separator) {
693                                                 button.Location = new Point (x, y);
694                                                 x += button.Rectangle.Width;
695                                                 if (is_separator)
696                                                         separator_index = i;
697                                         } else if (separator_index > 0) { 
698                                                 i = separator_index;
699                                                 separator_index = -1;
700                                                 x = theme.ToolBarGripWidth;
701                                                 y += ht; 
702                                         } else {
703                                                 x = theme.ToolBarGripWidth;
704                                                 y += ht; 
705                                                 button.Location = new Point (x, y);
706                                                 x += button.Rectangle.Width;
707                                         }
708                                 }
709                                 if (AutoSize)
710                                         Height = y + ht;
711                         } else {
712                                 if (AutoSize)
713                                         Height = ht;
714                                 else
715                                         Height = DefaultSize.Height;
716                                 foreach (ToolBarButton button in buttons) {
717                                         if (size_specified)
718                                                 button.Layout (ButtonSize);
719                                         else
720                                                 button.Layout ();
721                                         button.Location = new Point (x, y);
722                                         x += button.Rectangle.Width;
723                                 }
724                         }
725                 }
726                 #endregion Private Methods
727
728                 #region subclass
729                 public class ToolBarButtonCollection : IList, ICollection, IEnumerable
730                 {
731                         #region instance variables
732                         private ArrayList list;
733                         private ToolBar owner;
734                         #endregion
735
736                         #region constructors
737                         public ToolBarButtonCollection (ToolBar owner)
738                         {
739                                 this.owner = owner;
740                                 list = new ArrayList ();
741                         }
742                         #endregion
743
744                         #region properties
745                         [Browsable (false)]
746                         public int Count {
747                                 get { return list.Count; }
748                         }
749
750                         public bool IsReadOnly {
751                                 get { return list.IsReadOnly; }
752                         }
753
754                         public virtual ToolBarButton this [int index] {
755                                 get { return (ToolBarButton) list [index]; }
756                                 set {
757                                         value.SetParent (owner);
758                                         list [index] = value;
759                                         owner.Redraw (true);
760                                 }
761                         }
762
763                         bool ICollection.IsSynchronized {
764                                 get { return list.IsSynchronized; }
765                         }
766
767                         object ICollection.SyncRoot {
768                                 get { return list.SyncRoot; }
769                         }
770
771                         bool IList.IsFixedSize {
772                                 get { return list.IsFixedSize; }
773                         }
774
775                         object IList.this [int index] {
776                                 get { return this [index]; }
777                                 set {
778                                         if (! (value is ToolBarButton))
779                                                 throw new ArgumentException("Not of type ToolBarButton", "value");
780                                         this [index] = (ToolBarButton) value;
781                                 }
782                         }
783                         #endregion
784
785                         #region methods
786                         public int Add (string text)
787                         {
788                                 ToolBarButton button = new ToolBarButton (text);
789                                 return this.Add (button);
790                         }
791
792                         public int Add (ToolBarButton button)
793                         {
794                                 int result;
795                                 button.SetParent (owner);
796                                 result = list.Add (button);
797                                 owner.Redraw (true);
798                                 return result;
799                         }
800
801                         public void AddRange (ToolBarButton [] buttons)
802                         {
803                                 foreach (ToolBarButton button in buttons)
804                                         Add (button);
805                         }
806
807                         public void Clear ()
808                         {
809                                 list.Clear ();
810                                 owner.Redraw (false);
811                         }
812
813                         public bool Contains (ToolBarButton button)
814                         {
815                                 return list.Contains (button);
816                         }
817
818                         public IEnumerator GetEnumerator ()
819                         {
820                                 return list.GetEnumerator ();
821                         }
822
823                         void ICollection.CopyTo (Array dest, int index)
824                         {
825                                 list.CopyTo (dest, index);
826                         }
827
828                         int IList.Add (object button)
829                         {
830                                 if (! (button is ToolBarButton)) {
831                                         throw new ArgumentException("Not of type ToolBarButton", "button");
832                                 }
833
834                                 return this.Add ((ToolBarButton) button);
835                         }
836
837                         bool IList.Contains (object button)
838                         {
839                                 if (! (button is ToolBarButton)) {
840                                         throw new ArgumentException("Not of type ToolBarButton", "button");
841                                 }
842
843                                 return this.Contains ((ToolBarButton) button);
844                         }
845
846                         int IList.IndexOf (object button)
847                         {
848                                 if (! (button is ToolBarButton)) {
849                                         throw new ArgumentException("Not of type ToolBarButton", "button");
850                                 }
851
852                                 return this.IndexOf ((ToolBarButton) button);
853                         }
854
855                         void IList.Insert (int index, object button)
856                         {
857                                 if (! (button is ToolBarButton)) {
858                                         throw new ArgumentException("Not of type ToolBarButton", "button");
859                                 }
860
861                                 this.Insert (index, (ToolBarButton) button);
862                         }
863
864                         void IList.Remove (object button)
865                         {
866                                 if (! (button is ToolBarButton)) {
867                                         throw new ArgumentException("Not of type ToolBarButton", "button");
868                                 }
869
870                                 this.Remove ((ToolBarButton) button);
871                         }
872
873                         public int IndexOf (ToolBarButton button)
874                         {
875                                 return list.IndexOf (button);
876                         }
877
878                         public void Insert (int index, ToolBarButton button)
879                         {
880                                 list.Insert (index, button);
881                                 owner.Redraw (true);
882                         }
883
884                         public void Remove (ToolBarButton button)
885                         {
886                                 list.Remove (button);
887                                 owner.Redraw (true);
888                         }
889
890                         public void RemoveAt (int index)
891                         {
892                                 list.RemoveAt (index);
893                                 owner.Redraw (true);
894                         }
895                         #endregion methods
896                 }
897                 #endregion subclass
898         }
899 }