ToolBar.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890
  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 ([email protected])
  24. // Mike Kestner <[email protected]>
  25. //
  26. // TODO:
  27. // - Tooltip
  28. //
  29. // Copyright (C) 2004-2006 Novell, Inc. (http://www.novell.com)
  30. //
  31. // NOT COMPLETE
  32. using System.Collections;
  33. using System.ComponentModel;
  34. using System.ComponentModel.Design;
  35. using System.Drawing;
  36. using System.Drawing.Imaging;
  37. using System.Runtime.InteropServices;
  38. namespace System.Windows.Forms
  39. {
  40. [DefaultEvent ("ButtonClick")]
  41. [DefaultProperty ("Buttons")]
  42. [Designer ("System.Windows.Forms.Design.ToolBarDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
  43. public class ToolBar : Control
  44. {
  45. #region Instance Variables
  46. bool size_specified = false;
  47. ToolBarButton current_button;
  48. #endregion Instance Variables
  49. #region Events
  50. [Browsable (false)]
  51. [EditorBrowsable (EditorBrowsableState.Never)]
  52. public new event EventHandler BackColorChanged {
  53. add { base.BackColorChanged += value; }
  54. remove { base.BackColorChanged -= value; }
  55. }
  56. [Browsable (false)]
  57. [EditorBrowsable (EditorBrowsableState.Never)]
  58. public new event EventHandler BackgroundImageChanged {
  59. add { base.BackgroundImageChanged += value; }
  60. remove { base.BackgroundImageChanged -= value; }
  61. }
  62. public event ToolBarButtonClickEventHandler ButtonClick;
  63. public event ToolBarButtonClickEventHandler ButtonDropDown;
  64. [Browsable (false)]
  65. [EditorBrowsable (EditorBrowsableState.Never)]
  66. public new event EventHandler ForeColorChanged {
  67. add { base.ForeColorChanged += value; }
  68. remove { base.ForeColorChanged -= value; }
  69. }
  70. [Browsable (false)]
  71. [EditorBrowsable (EditorBrowsableState.Never)]
  72. public new event EventHandler ImeModeChanged {
  73. add { base.ImeModeChanged += value; }
  74. remove { base.ImeModeChanged -= value; }
  75. }
  76. [Browsable (false)]
  77. [EditorBrowsable (EditorBrowsableState.Never)]
  78. public new event PaintEventHandler Paint {
  79. add { base.Paint += value; }
  80. remove { base.Paint -= value; }
  81. }
  82. [Browsable (false)]
  83. [EditorBrowsable (EditorBrowsableState.Never)]
  84. public new event EventHandler RightToLeftChanged {
  85. add { base.RightToLeftChanged += value; }
  86. remove { base.RightToLeftChanged -= value; }
  87. }
  88. [Browsable (false)]
  89. [EditorBrowsable (EditorBrowsableState.Never)]
  90. public new event EventHandler TextChanged {
  91. add { base.TextChanged += value; }
  92. remove { base.TextChanged -= value; }
  93. }
  94. #endregion Events
  95. #region Constructor
  96. public ToolBar ()
  97. {
  98. background_color = ThemeEngine.Current.DefaultControlBackColor;
  99. foreground_color = ThemeEngine.Current.DefaultControlForeColor;
  100. buttons = new ToolBarButtonCollection (this);
  101. dock_style = DockStyle.Top;
  102. MouseDown += new MouseEventHandler (ToolBar_MouseDown);
  103. MouseLeave += new EventHandler (ToolBar_MouseLeave);
  104. MouseMove += new MouseEventHandler (ToolBar_MouseMove);
  105. MouseUp += new MouseEventHandler (ToolBar_MouseUp);
  106. Paint += new PaintEventHandler (ToolBar_Paint);
  107. SetStyle (ControlStyles.UserPaint, false);
  108. SetStyle (ControlStyles.FixedHeight, true);
  109. }
  110. #endregion Constructor
  111. #region protected Properties
  112. protected override CreateParams CreateParams
  113. {
  114. get { return base.CreateParams; }
  115. }
  116. protected override ImeMode DefaultImeMode {
  117. get { return ImeMode.Disable; }
  118. }
  119. protected override Size DefaultSize {
  120. get { return ThemeEngine.Current.ToolBarDefaultSize; }
  121. }
  122. #endregion
  123. ToolBarAppearance appearance = ToolBarAppearance.Normal;
  124. #region Public Properties
  125. [DefaultValue (ToolBarAppearance.Normal)]
  126. [Localizable (true)]
  127. public ToolBarAppearance Appearance {
  128. get { return appearance; }
  129. set {
  130. if (value == appearance)
  131. return;
  132. appearance = value;
  133. Redraw (false);
  134. }
  135. }
  136. bool autosize = true;
  137. [DefaultValue (true)]
  138. [Localizable (true)]
  139. public bool AutoSize {
  140. get { return autosize; }
  141. set {
  142. if (value == autosize)
  143. return;
  144. autosize = value;
  145. Redraw (true);
  146. }
  147. }
  148. [Browsable (false)]
  149. [EditorBrowsable (EditorBrowsableState.Never)]
  150. public override Color BackColor {
  151. get { return background_color; }
  152. set {
  153. if (value == background_color)
  154. return;
  155. background_color = value;
  156. OnBackColorChanged (EventArgs.Empty);
  157. Redraw (false);
  158. }
  159. }
  160. [Browsable (false)]
  161. [EditorBrowsable (EditorBrowsableState.Never)]
  162. public override Image BackgroundImage {
  163. get { return background_image; }
  164. set {
  165. if (value == background_image)
  166. return;
  167. background_image = value;
  168. OnBackgroundImageChanged (EventArgs.Empty);
  169. Redraw (false);
  170. }
  171. }
  172. [DefaultValue (BorderStyle.None)]
  173. [DispIdAttribute (-504)]
  174. public BorderStyle BorderStyle {
  175. get { return InternalBorderStyle; }
  176. set { InternalBorderStyle = value; }
  177. }
  178. ToolBarButtonCollection buttons;
  179. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
  180. [Localizable (true)]
  181. [MergableProperty (false)]
  182. public ToolBarButtonCollection Buttons {
  183. get { return buttons; }
  184. }
  185. Size button_size;
  186. [Localizable (true)]
  187. [RefreshProperties (RefreshProperties.All)]
  188. public Size ButtonSize {
  189. get {
  190. if (button_size.IsEmpty) {
  191. if (buttons.Count == 0)
  192. return new Size (39, 36);
  193. else
  194. return CalcButtonSize ();
  195. }
  196. return button_size;
  197. }
  198. set {
  199. size_specified = true;
  200. if (button_size == value)
  201. return;
  202. button_size = value;
  203. Redraw (true);
  204. }
  205. }
  206. bool divider = true;
  207. [DefaultValue (true)]
  208. public bool Divider {
  209. get { return divider; }
  210. set {
  211. if (value == divider)
  212. return;
  213. divider = value;
  214. Redraw (false);
  215. }
  216. }
  217. [DefaultValue (DockStyle.Top)]
  218. [Localizable (true)]
  219. public override DockStyle Dock {
  220. get { return base.Dock; }
  221. set { base.Dock = value; }
  222. }
  223. bool drop_down_arrows = false;
  224. [DefaultValue (false)]
  225. [Localizable (true)]
  226. public bool DropDownArrows {
  227. get { return drop_down_arrows; }
  228. set {
  229. if (value == drop_down_arrows)
  230. return;
  231. drop_down_arrows = value;
  232. Redraw (true);
  233. }
  234. }
  235. [Browsable (false)]
  236. [EditorBrowsable (EditorBrowsableState.Never)]
  237. public override Color ForeColor {
  238. get { return foreground_color; }
  239. set {
  240. if (value == foreground_color)
  241. return;
  242. foreground_color = value;
  243. OnForeColorChanged (EventArgs.Empty);
  244. Redraw (false);
  245. }
  246. }
  247. ImageList image_list;
  248. [DefaultValue (null)]
  249. public ImageList ImageList {
  250. get { return image_list; }
  251. set { image_list = value; }
  252. }
  253. [Browsable (false)]
  254. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  255. [EditorBrowsable (EditorBrowsableState.Advanced)]
  256. public Size ImageSize {
  257. get {
  258. if (ImageList == null)
  259. return Size.Empty;
  260. return ImageList.ImageSize;
  261. }
  262. }
  263. ImeMode ime_mode;
  264. [Browsable (false)]
  265. [EditorBrowsable (EditorBrowsableState.Never)]
  266. public new ImeMode ImeMode {
  267. get { return ime_mode; }
  268. set {
  269. if (value == ime_mode)
  270. return;
  271. ime_mode = value;
  272. OnImeModeChanged (EventArgs.Empty);
  273. }
  274. }
  275. [Browsable (false)]
  276. [EditorBrowsable (EditorBrowsableState.Never)]
  277. public override RightToLeft RightToLeft {
  278. get { return base.RightToLeft; }
  279. set {
  280. if (value == base.RightToLeft)
  281. return;
  282. base.RightToLeft = value;
  283. OnRightToLeftChanged (EventArgs.Empty);
  284. }
  285. }
  286. bool show_tooltips = false;
  287. [DefaultValue (false)]
  288. [Localizable (true)]
  289. public bool ShowToolTips {
  290. get { return show_tooltips; }
  291. set { show_tooltips = value; }
  292. }
  293. [DefaultValue (false)]
  294. public new bool TabStop {
  295. get { return base.TabStop; }
  296. set { base.TabStop = value; }
  297. }
  298. [Bindable (false)]
  299. [Browsable (false)]
  300. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  301. [EditorBrowsable (EditorBrowsableState.Never)]
  302. public override string Text {
  303. get { return text; }
  304. set {
  305. if (value == text)
  306. return;
  307. text = value;
  308. Redraw (true);
  309. OnTextChanged (EventArgs.Empty);
  310. }
  311. }
  312. ToolBarTextAlign text_alignment = ToolBarTextAlign.Underneath;
  313. [DefaultValue (ToolBarTextAlign.Underneath)]
  314. [Localizable (true)]
  315. public ToolBarTextAlign TextAlign {
  316. get { return text_alignment; }
  317. set {
  318. if (value == text_alignment)
  319. return;
  320. text_alignment = value;
  321. Redraw (true);
  322. }
  323. }
  324. bool wrappable = true;
  325. [DefaultValue (true)]
  326. [Localizable (true)]
  327. public bool Wrappable {
  328. get { return wrappable; }
  329. set {
  330. if (value == wrappable)
  331. return;
  332. wrappable = value;
  333. Redraw (true);
  334. }
  335. }
  336. #endregion Public Properties
  337. #region Public Methods
  338. public override string ToString ()
  339. {
  340. int count = this.Buttons.Count;
  341. if (count == 0)
  342. return string.Format ("System.Windows.Forms.ToolBar, Button.Count: 0");
  343. else
  344. return string.Format ("System.Windows.Forms.ToolBar, Button.Count: {0}, Buttons[0]: {1}",
  345. count, this.Buttons [0].ToString ());
  346. }
  347. #endregion Public Methods
  348. #region Protected Methods
  349. protected override void CreateHandle ()
  350. {
  351. base.CreateHandle ();
  352. }
  353. protected override void Dispose (bool disposing)
  354. {
  355. if (disposing)
  356. ImageList = null;
  357. base.Dispose (disposing);
  358. }
  359. protected virtual void OnButtonClick (ToolBarButtonClickEventArgs e)
  360. {
  361. if (e.Button.Style == ToolBarButtonStyle.ToggleButton) {
  362. if (! e.Button.Pushed)
  363. e.Button.Pushed = true;
  364. else
  365. e.Button.Pushed = false;
  366. }
  367. e.Button.pressed = false;
  368. Invalidate (e.Button.Rectangle);
  369. Redraw (false);
  370. if (ButtonClick != null)
  371. ButtonClick (this, e);
  372. }
  373. protected virtual void OnButtonDropDown (ToolBarButtonClickEventArgs e)
  374. {
  375. if (ButtonDropDown != null)
  376. ButtonDropDown (this, e);
  377. if (e.Button.DropDownMenu == null)
  378. return;
  379. Point loc = new Point (e.Button.Rectangle.X + 1, e.Button.Rectangle.Bottom + 1);
  380. ((ContextMenu) e.Button.DropDownMenu).Show (this, loc);
  381. e.Button.dd_pressed = false;
  382. Invalidate (e.Button.Rectangle);
  383. }
  384. protected override void OnFontChanged (EventArgs e)
  385. {
  386. base.OnFontChanged (e);
  387. Redraw (true);
  388. }
  389. protected override void OnHandleCreated (EventArgs e)
  390. {
  391. base.OnHandleCreated (e);
  392. }
  393. protected override void OnResize (EventArgs e)
  394. {
  395. base.OnResize (e);
  396. if (Width <= 0 || Height <= 0 || !Visible)
  397. return;
  398. Redraw (true);
  399. }
  400. protected override void SetBoundsCore (int x, int y, int width, int height, BoundsSpecified specified)
  401. {
  402. base.SetBoundsCore (x, y, width, height, specified);
  403. }
  404. protected override void WndProc (ref Message m)
  405. {
  406. base.WndProc (ref m);
  407. }
  408. #endregion Protected Methods
  409. #region Private Methods
  410. private void ToolBar_MouseDown (object sender, MouseEventArgs me)
  411. {
  412. if (!Enabled)
  413. return;
  414. Point loc = new Point (me.X, me.Y);
  415. // draw the pushed button
  416. foreach (ToolBarButton button in buttons) {
  417. if (button.Enabled && button.Rectangle.Contains (loc)) {
  418. // Mark the DropDown rect as pressed.
  419. // We don't redraw the dropdown rect.
  420. if (button.Style == ToolBarButtonStyle.DropDownButton) {
  421. Rectangle rect = button.Rectangle;
  422. rect.Width = ThemeEngine.Current.ToolBarDropDownWidth;
  423. rect.X = button.Rectangle.Right - rect.Width;
  424. if (rect.Contains (loc)) {
  425. if (button.DropDownMenu != null) {
  426. button.dd_pressed = true;
  427. Invalidate (rect);
  428. }
  429. break;
  430. }
  431. }
  432. button.pressed = true;
  433. button.inside = true;
  434. Invalidate (button.Rectangle);
  435. break;
  436. }
  437. }
  438. }
  439. private void ToolBar_MouseUp (object sender, MouseEventArgs me)
  440. {
  441. if (!Enabled)
  442. return;
  443. Point loc = new Point (me.X, me.Y);
  444. // draw the normal button
  445. foreach (ToolBarButton button in buttons) {
  446. if (button.Enabled && button.Rectangle.Contains (loc)) {
  447. if (button.Style == ToolBarButtonStyle.DropDownButton) {
  448. Rectangle ddRect = button.Rectangle;
  449. ddRect.Width = ThemeEngine.Current.ToolBarDropDownWidth;
  450. ddRect.X = button.Rectangle.Right - ddRect.Width;
  451. if (ddRect.Contains (loc)) {
  452. if (button.dd_pressed)
  453. OnButtonDropDown (new ToolBarButtonClickEventArgs (button));
  454. continue;
  455. }
  456. }
  457. // Fire a ButtonClick
  458. if (button.pressed)
  459. OnButtonClick (new ToolBarButtonClickEventArgs (button));
  460. } else if (button.pressed) {
  461. button.pressed = false;
  462. Invalidate (button.Rectangle);
  463. }
  464. }
  465. }
  466. private void ToolBar_MouseLeave (object sender, EventArgs e)
  467. {
  468. if (!Enabled || appearance != ToolBarAppearance.Flat || current_button == null)
  469. return;
  470. if (current_button.Hilight) {
  471. current_button.Hilight = false;
  472. Invalidate (current_button.Rectangle);
  473. Redraw (false);
  474. }
  475. current_button = null;
  476. }
  477. private void ToolBar_MouseMove (object sender, MouseEventArgs me)
  478. {
  479. if (!Enabled)
  480. return;
  481. Point loc = new Point (me.X, me.Y);
  482. if (this.Capture) {
  483. // If the button was pressed and we leave, release the
  484. // button press and vice versa
  485. foreach (ToolBarButton button in buttons) {
  486. if (button.pressed &&
  487. (button.inside != button.Rectangle.Contains (loc))) {
  488. button.inside = button.Rectangle.Contains (loc);
  489. button.Hilight = false;
  490. Invalidate (button.Rectangle);
  491. Redraw (false);
  492. break;
  493. }
  494. }
  495. }
  496. // following is only for flat style toolbar
  497. else if (appearance == ToolBarAppearance.Flat) {
  498. if (current_button != null && current_button.Rectangle.Contains (loc)) {
  499. if (current_button.Hilight || current_button.Pushed)
  500. return;
  501. current_button.Hilight = true;
  502. Invalidate (current_button.Rectangle);
  503. Redraw (false);
  504. }
  505. else {
  506. foreach (ToolBarButton button in buttons) {
  507. if (button.Rectangle.Contains (loc) && button.Enabled) {
  508. current_button = button;
  509. if (current_button.Hilight || current_button.Pushed)
  510. continue;
  511. current_button.Hilight = true;
  512. Invalidate (current_button.Rectangle);
  513. Redraw (false);
  514. }
  515. else if (button.Hilight) {
  516. button.Hilight = false;
  517. Invalidate (button.Rectangle);
  518. Redraw (false);
  519. }
  520. }
  521. }
  522. }
  523. }
  524. private void ToolBar_Paint (object sender, PaintEventArgs pevent)
  525. {
  526. ThemeEngine.Current.DrawToolBar (pevent.Graphics, pevent.ClipRectangle, this);
  527. }
  528. internal void Redraw (bool recalculate)
  529. {
  530. if (recalculate)
  531. Layout ();
  532. Refresh ();
  533. }
  534. private Size CalcButtonSize ()
  535. {
  536. String longestText = buttons [0].Text;
  537. for (int i = 1; i < buttons.Count; i++) {
  538. if (buttons[i].Text.Length > longestText.Length)
  539. longestText = buttons[i].Text;
  540. }
  541. SizeF sz = this.DeviceContext.MeasureString (longestText, this.Font);
  542. Size size = new Size ((int) Math.Ceiling (sz.Width), (int) Math.Ceiling (sz.Height));
  543. if (ImageList != null) {
  544. // adjustment for the image grip
  545. int imgWidth = this.ImageSize.Width + 2 * ThemeEngine.Current.ToolBarImageGripWidth;
  546. int imgHeight = this.ImageSize.Height + 2 * ThemeEngine.Current.ToolBarImageGripWidth;
  547. if (text_alignment == ToolBarTextAlign.Right) {
  548. size.Width = imgWidth + size.Width;
  549. size.Height = (size.Height > imgHeight) ? size.Height : imgHeight;
  550. }
  551. else {
  552. size.Height = imgHeight + size.Height;
  553. size.Width = (size.Width > imgWidth) ? size.Width : imgWidth;
  554. }
  555. }
  556. return size;
  557. }
  558. void Layout ()
  559. {
  560. Theme theme = ThemeEngine.Current;
  561. int ht = ButtonSize.Height + theme.ToolBarGripWidth;
  562. int x = theme.ToolBarGripWidth;
  563. int y = theme.ToolBarGripWidth;
  564. if (Wrappable) {
  565. int separator_index = -1;
  566. for (int i = 0; i < buttons.Count; i++) {
  567. ToolBarButton button = buttons [i];
  568. if (!button.Visible)
  569. continue;
  570. if (size_specified)
  571. button.Layout (ButtonSize);
  572. else
  573. button.Layout ();
  574. bool is_separator = button.Style == ToolBarButtonStyle.Separator;
  575. if (x + button.Rectangle.Width < Width || is_separator) {
  576. button.Location = new Point (x, y);
  577. x += button.Rectangle.Width;
  578. if (is_separator)
  579. separator_index = i;
  580. } else if (separator_index > 0) {
  581. i = separator_index;
  582. separator_index = -1;
  583. x = theme.ToolBarGripWidth;
  584. y += ht;
  585. } else {
  586. x = theme.ToolBarGripWidth;
  587. y += ht;
  588. button.Location = new Point (x, y);
  589. x += button.Rectangle.Width;
  590. }
  591. }
  592. if (AutoSize)
  593. Height = y + ht;
  594. } else {
  595. if (AutoSize)
  596. Height = ht;
  597. else
  598. Height = DefaultSize.Height;
  599. foreach (ToolBarButton button in buttons) {
  600. if (size_specified)
  601. button.Layout (ButtonSize);
  602. else
  603. button.Layout ();
  604. button.Location = new Point (x, y);
  605. x += button.Rectangle.Width;
  606. }
  607. }
  608. }
  609. #endregion Private Methods
  610. #region subclass
  611. public class ToolBarButtonCollection : IList, ICollection, IEnumerable
  612. {
  613. #region instance variables
  614. private ArrayList list;
  615. private ToolBar owner;
  616. #endregion
  617. #region constructors
  618. public ToolBarButtonCollection (ToolBar owner)
  619. {
  620. this.owner = owner;
  621. list = new ArrayList ();
  622. }
  623. #endregion
  624. #region properties
  625. [Browsable (false)]
  626. public int Count {
  627. get { return list.Count; }
  628. }
  629. public bool IsReadOnly {
  630. get { return list.IsReadOnly; }
  631. }
  632. public virtual ToolBarButton this [int index] {
  633. get { return (ToolBarButton) list [index]; }
  634. set {
  635. value.SetParent (owner);
  636. list [index] = value;
  637. owner.Redraw (true);
  638. }
  639. }
  640. bool ICollection.IsSynchronized {
  641. get { return list.IsSynchronized; }
  642. }
  643. object ICollection.SyncRoot {
  644. get { return list.SyncRoot; }
  645. }
  646. bool IList.IsFixedSize {
  647. get { return list.IsFixedSize; }
  648. }
  649. object IList.this [int index] {
  650. get { return this [index]; }
  651. set {
  652. if (! (value is ToolBarButton))
  653. throw new ArgumentException("Not of type ToolBarButton", "value");
  654. this [index] = (ToolBarButton) value;
  655. }
  656. }
  657. #endregion
  658. #region methods
  659. public int Add (string text)
  660. {
  661. ToolBarButton button = new ToolBarButton (text);
  662. return this.Add (button);
  663. }
  664. public int Add (ToolBarButton button)
  665. {
  666. int result;
  667. button.SetParent (owner);
  668. result = list.Add (button);
  669. owner.Redraw (true);
  670. return result;
  671. }
  672. public void AddRange (ToolBarButton [] buttons)
  673. {
  674. foreach (ToolBarButton button in buttons)
  675. Add (button);
  676. }
  677. public void Clear ()
  678. {
  679. list.Clear ();
  680. owner.Redraw (false);
  681. }
  682. public bool Contains (ToolBarButton button)
  683. {
  684. return list.Contains (button);
  685. }
  686. public IEnumerator GetEnumerator ()
  687. {
  688. return list.GetEnumerator ();
  689. }
  690. void ICollection.CopyTo (Array dest, int index)
  691. {
  692. list.CopyTo (dest, index);
  693. }
  694. int IList.Add (object button)
  695. {
  696. if (! (button is ToolBarButton)) {
  697. throw new ArgumentException("Not of type ToolBarButton", "button");
  698. }
  699. return this.Add ((ToolBarButton) button);
  700. }
  701. bool IList.Contains (object button)
  702. {
  703. if (! (button is ToolBarButton)) {
  704. throw new ArgumentException("Not of type ToolBarButton", "button");
  705. }
  706. return this.Contains ((ToolBarButton) button);
  707. }
  708. int IList.IndexOf (object button)
  709. {
  710. if (! (button is ToolBarButton)) {
  711. throw new ArgumentException("Not of type ToolBarButton", "button");
  712. }
  713. return this.IndexOf ((ToolBarButton) button);
  714. }
  715. void IList.Insert (int index, object button)
  716. {
  717. if (! (button is ToolBarButton)) {
  718. throw new ArgumentException("Not of type ToolBarButton", "button");
  719. }
  720. this.Insert (index, (ToolBarButton) button);
  721. }
  722. void IList.Remove (object button)
  723. {
  724. if (! (button is ToolBarButton)) {
  725. throw new ArgumentException("Not of type ToolBarButton", "button");
  726. }
  727. this.Remove ((ToolBarButton) button);
  728. }
  729. public int IndexOf (ToolBarButton button)
  730. {
  731. return list.IndexOf (button);
  732. }
  733. public void Insert (int index, ToolBarButton button)
  734. {
  735. list.Insert (index, button);
  736. owner.Redraw (true);
  737. }
  738. public void Remove (ToolBarButton button)
  739. {
  740. list.Remove (button);
  741. owner.Redraw (true);
  742. }
  743. public void RemoveAt (int index)
  744. {
  745. list.RemoveAt (index);
  746. owner.Redraw (true);
  747. }
  748. #endregion methods
  749. }
  750. #endregion subclass
  751. }
  752. }