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