ToolBar.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852
  1. //
  2. // System.Windows.Forms.ToolBar.cs
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining
  5. // a copy of this software and associated documentation files (the
  6. // "Software"), to deal in the Software without restriction, including
  7. // without limitation the rights to use, copy, modify, merge, publish,
  8. // distribute, sublicense, and/or sell copies of the Software, and to
  9. // permit persons to whom the Software is furnished to do so, subject to
  10. // the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be
  13. // included in all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  18. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  19. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  20. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  21. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. //
  23. // Authors:
  24. // Ravindra ([email protected])
  25. //
  26. // TODO:
  27. // - Drawing dotted text when text is too big to draw on a button
  28. // - Hilighting a button in flat appearance, when mouse moves over
  29. // - RightToLeft
  30. // - DropDown ContextMenu
  31. //
  32. // Copyright (C) Novell Inc., 2004
  33. //
  34. //
  35. // $Revision: 1.1 $
  36. // $Modtime: $
  37. // $Log: ToolBar.cs,v $
  38. // Revision 1.1 2004/08/15 23:13:15 ravindra
  39. // First Implementation of ToolBar control.
  40. //
  41. //
  42. //
  43. // NOT COMPLETE
  44. using System.Collections;
  45. using System.Drawing;
  46. using System.Drawing.Imaging;
  47. using System.Drawing.Drawing2D;
  48. namespace System.Windows.Forms
  49. {
  50. public class ToolBar : Control
  51. {
  52. #region Instance Variables
  53. private ToolBarAppearance appearance;
  54. private bool autosize;
  55. private BorderStyle borderStyle;
  56. private ToolBarButtonCollection buttons;
  57. private Size buttonSize;
  58. private bool divider;
  59. private bool dropDownArrows;
  60. private ImageList imageList;
  61. private ImeMode imeMode;
  62. private bool showToolTips;
  63. private ToolBarTextAlign textAlignment;
  64. private bool wrappable; // flag to make the toolbar wrappable
  65. private bool recalculate; // flag to make sure that we calculate the toolbar before drawing
  66. private bool redraw; // flag to force redrawing the control
  67. #endregion Instance Variables
  68. #region Events
  69. public new event EventHandler BackColorChanged;
  70. public new event EventHandler BackgroundImageChanged;
  71. public event ToolBarButtonClickEventHandler ButtonClick;
  72. public event ToolBarButtonClickEventHandler ButtonDropDown;
  73. public new event EventHandler ForeColorChanged;
  74. public new event EventHandler ImeModeChanged;
  75. public new event PaintEventHandler Paint;
  76. public new event EventHandler RightToLeftChanged;
  77. public new event EventHandler TextChanged;
  78. #endregion Events
  79. #region Constructor
  80. public ToolBar ()
  81. {
  82. appearance = ToolBarAppearance.Normal;
  83. autosize = true;
  84. background_color = ThemeEngine.Current.DefaultControlBackColor;
  85. borderStyle = BorderStyle.None;
  86. buttons = new ToolBarButtonCollection (this);
  87. buttonSize = Size.Empty;
  88. divider = true;
  89. dropDownArrows = false;
  90. foreground_color = ThemeEngine.Current.DefaultControlForeColor;
  91. showToolTips = false;
  92. textAlignment = ToolBarTextAlign.Underneath;
  93. wrappable = true;
  94. redraw = true;
  95. recalculate = true;
  96. }
  97. #endregion Constructor
  98. #region protected Properties
  99. protected override CreateParams CreateParams
  100. {
  101. get {
  102. CreateParams createParams = base.CreateParams;
  103. createParams.ClassName = XplatUI.DefaultClassName;
  104. createParams.Style = (int) WindowStyles.WS_CHILD | (int) WindowStyles.WS_VISIBLE;
  105. return createParams;
  106. }
  107. }
  108. protected override ImeMode DefaultImeMode {
  109. get { return ImeMode.Disable; }
  110. }
  111. protected override Size DefaultSize {
  112. get { return new Size (100, 42); }
  113. }
  114. #endregion
  115. #region Public Properties
  116. public ToolBarAppearance Appearance {
  117. get { return appearance; }
  118. set {
  119. if (value == appearance)
  120. return;
  121. appearance = value;
  122. Redraw (false);
  123. }
  124. }
  125. public bool AutoSize {
  126. get { return autosize; }
  127. set {
  128. if (value == autosize)
  129. return;
  130. autosize = value;
  131. Redraw (true);
  132. }
  133. }
  134. public override Color BackColor {
  135. get { return background_color; }
  136. set {
  137. if (value == background_color)
  138. return;
  139. background_color = value;
  140. if (BackColorChanged != null)
  141. BackColorChanged (this, new EventArgs ());
  142. Redraw (false);
  143. }
  144. }
  145. public override Image BackgroundImage {
  146. get { return background_image; }
  147. set {
  148. if (value == background_image)
  149. return;
  150. background_image = value;
  151. if (BackgroundImageChanged != null)
  152. BackgroundImageChanged (this, new EventArgs ());
  153. Redraw (false);
  154. }
  155. }
  156. public BorderStyle BorderStyle {
  157. get { return borderStyle; }
  158. set {
  159. if (value == borderStyle)
  160. return;
  161. borderStyle = value;
  162. Redraw (false);
  163. }
  164. }
  165. public ToolBarButtonCollection Buttons {
  166. get { return buttons; }
  167. }
  168. public Size ButtonSize {
  169. get {
  170. if (buttonSize.IsEmpty) {
  171. if (buttons.Count == 0)
  172. return new Size (39, 36);
  173. else
  174. return CalcButtonSize ();
  175. }
  176. return buttonSize;
  177. }
  178. set {
  179. if (buttonSize.Width == value.Width && buttonSize.Height == value.Height)
  180. return;
  181. if (value.Width > 0 && value.Height > 0) {
  182. buttonSize = value;
  183. Redraw (true);
  184. }
  185. }
  186. }
  187. public bool Divider {
  188. get { return divider; }
  189. set { divider = value; }
  190. }
  191. public override DockStyle Dock {
  192. get { return base.Dock; }
  193. set { base.Dock = value; }
  194. }
  195. public bool DropDownArrows {
  196. get { return dropDownArrows; }
  197. set {
  198. if (value == dropDownArrows)
  199. return;
  200. dropDownArrows = value;
  201. Redraw (true);
  202. }
  203. }
  204. public override Color ForeColor {
  205. get { return foreground_color; }
  206. set {
  207. if (value == foreground_color)
  208. return;
  209. foreground_color = value;
  210. Redraw (false);
  211. }
  212. }
  213. public ImageList ImageList {
  214. get { return imageList; }
  215. set { imageList = value; }
  216. }
  217. public Size ImageSize {
  218. get {
  219. if (imageList == null)
  220. return Size.Empty;
  221. return imageList.ImageSize;
  222. }
  223. }
  224. public new ImeMode ImeMode {
  225. get { return imeMode; }
  226. set {
  227. if (value == imeMode)
  228. return;
  229. imeMode = value;
  230. if (ImeModeChanged != null)
  231. ImeModeChanged (this, new EventArgs ());
  232. }
  233. }
  234. /* NYI in Control.cs.
  235. public override RightToLeft RightToLeft {
  236. get { return base.RightToLeft; }
  237. set {
  238. if (value == base.RightToLeft)
  239. return;
  240. base.RightToLeft = value;
  241. if (RightToLeftChanged != null)
  242. RightToLeftChanged (this, new EventArgs ());
  243. }
  244. }
  245. */
  246. public bool ShowToolTips {
  247. get { return showToolTips; }
  248. set { showToolTips = value; }
  249. }
  250. public new bool TabStop {
  251. get { return base.TabStop; }
  252. set { base.TabStop = value; }
  253. }
  254. public override string Text {
  255. get { return text; }
  256. set {
  257. if (value == text)
  258. return;
  259. text = value;
  260. Redraw (true);
  261. if (TextChanged != null)
  262. TextChanged (this, new EventArgs ());
  263. }
  264. }
  265. public ToolBarTextAlign TextAlign {
  266. get { return textAlignment; }
  267. set {
  268. if (value == textAlignment)
  269. return;
  270. textAlignment = value;
  271. Redraw (true);
  272. }
  273. }
  274. public bool Wrappable {
  275. get { return wrappable; }
  276. set {
  277. if (value == wrappable)
  278. return;
  279. wrappable = value;
  280. Redraw (true);
  281. }
  282. }
  283. #endregion Public Properties
  284. #region Public Methods
  285. public override string ToString ()
  286. {
  287. int count = this.Buttons.Count;
  288. if (count == 0)
  289. return string.Format ("System.Windows.Forms.ToolBar, Button.Count: 0");
  290. else
  291. return string.Format ("System.Windows.Forms.ToolBar, Button.Count: {0}, Buttons[0]: {1}",
  292. count, this.Buttons [0].ToString ());
  293. }
  294. #endregion Public Methods
  295. #region Internal Methods
  296. internal Rectangle GetChildBounds (ToolBarButton button)
  297. {
  298. if (button.Style == ToolBarButtonStyle.Separator)
  299. return new Rectangle (button.Location.X, button.Location.Y,
  300. ThemeEngine.Current.ToolBarSeparatorWidth, this.ButtonSize.Height);
  301. SizeF sz = this.DeviceContext.MeasureString (button.Text, this.Font);
  302. Size size = new Size ((int) Math.Ceiling (sz.Width), (int) Math.Ceiling (sz.Height));
  303. if (imageList != null) {
  304. int imgWidth = this.ImageSize.Width + 2 * ThemeEngine.Current.ToolBarImageGripWidth;
  305. // adjustment for the image grip
  306. int imgHeight = this.ImageSize.Height + 2 * ThemeEngine.Current.ToolBarImageGripWidth;
  307. if (textAlignment == ToolBarTextAlign.Right) {
  308. size.Width = imgWidth + size.Width;
  309. size.Height = (size.Height > imgHeight) ? size.Height : imgHeight;
  310. }
  311. else {
  312. size.Height = imgHeight + size.Height;
  313. size.Width = (size.Width > imgWidth) ? size.Width : imgWidth;
  314. }
  315. }
  316. if (button.Style == ToolBarButtonStyle.DropDownButton && this.dropDownArrows)
  317. size.Width += ThemeEngine.Current.ToolBarDropDownWidth;
  318. return new Rectangle (button.Location, size);
  319. }
  320. internal void Redraw (bool recalculate)
  321. {
  322. redraw = true;
  323. this.recalculate = recalculate;
  324. }
  325. #endregion Internal Methods
  326. #region Protected Methods
  327. protected override void CreateHandle ()
  328. {
  329. base.CreateHandle ();
  330. }
  331. protected override void Dispose (bool disposing)
  332. {
  333. if (disposing) {
  334. if (imageList != null)
  335. imageList.Dispose ();
  336. }
  337. base.Dispose (disposing);
  338. }
  339. protected virtual void OnButtonClick (ToolBarButtonClickEventArgs e)
  340. {
  341. if (e.Button.Style == ToolBarButtonStyle.ToggleButton) {
  342. if (! e.Button.Pushed)
  343. e.Button.Pushed = true;
  344. else
  345. e.Button.Pushed = false;
  346. Invalidate (e.Button.Rectangle);
  347. }
  348. if (ButtonClick != null)
  349. ButtonClick (this, e);
  350. else
  351. return;
  352. }
  353. protected virtual void OnButtonDropDown (ToolBarButtonClickEventArgs e)
  354. {
  355. //if (e.Button.Style == ToolBarButtonStyle.DropDown)
  356. if (ButtonDropDown != null)
  357. ButtonDropDown (this, e);
  358. else
  359. return;
  360. }
  361. protected override void OnFontChanged (EventArgs e)
  362. {
  363. base.OnFontChanged (e);
  364. Redraw (true);
  365. }
  366. protected override void OnHandleCreated (EventArgs e)
  367. {
  368. base.OnHandleCreated (e);
  369. Refresh ();
  370. }
  371. protected override void OnMouseDown (MouseEventArgs me)
  372. {
  373. base.OnMouseDown (me);
  374. if (! Enabled) return;
  375. Point hit = new Point (me.X - Location.X, me.Y - Location.Y);
  376. // draw the pushed button
  377. foreach (ToolBarButton button in buttons) {
  378. if (button.Rectangle.Contains (hit) && button.Enabled) {
  379. button.Pushed = true;
  380. Redraw (false);
  381. Invalidate (button.Rectangle);
  382. break;
  383. }
  384. }
  385. }
  386. protected override void OnMouseUp (MouseEventArgs me)
  387. {
  388. base.OnMouseUp (me);
  389. if (! Enabled) return;
  390. Point hit = new Point (me.X - Location.X, me.Y - Location.Y);
  391. // draw the normal button
  392. foreach (ToolBarButton button in buttons) {
  393. if (button.Rectangle.Contains (hit) && button.Enabled) {
  394. button.Pushed = false;
  395. Redraw (false);
  396. Invalidate (button.Rectangle);
  397. return;
  398. }
  399. }
  400. }
  401. protected override void OnMouseEnter (EventArgs e)
  402. {
  403. base.OnMouseEnter (e);
  404. if (!Enabled || appearance != ToolBarAppearance.Flat) return;
  405. // TODO:
  406. // draw the transparent rectangle with single line border around the flat button
  407. }
  408. protected override void OnMouseLeave (EventArgs e)
  409. {
  410. base.OnMouseLeave (e);
  411. if (!Enabled || appearance != ToolBarAppearance.Flat) return;
  412. // TODO:
  413. // draw the normal flat button
  414. }
  415. protected override void OnPaint (PaintEventArgs pe)
  416. {
  417. if (Width <= 0 || Height <= 0 || Visible == false)
  418. return;
  419. Draw ();
  420. pe.Graphics.DrawImage (ImageBuffer, pe.ClipRectangle, pe.ClipRectangle, GraphicsUnit.Pixel);
  421. }
  422. protected override void OnResize (EventArgs e)
  423. {
  424. base.OnResize (e);
  425. if (Width <= 0 || Height <= 0 || Visible == false)
  426. return;
  427. Redraw (true);
  428. }
  429. protected override void SetBoundsCore (int x, int y, int width, int height, BoundsSpecified specified)
  430. {
  431. base.SetBoundsCore (x, y, width, height, specified);
  432. }
  433. protected override void WndProc (ref Message m)
  434. {
  435. base.WndProc (ref m);
  436. }
  437. #endregion Protected Methods
  438. #region Private Methods
  439. private void Draw ()
  440. {
  441. if (redraw) {
  442. StringFormat strFormat = new StringFormat ();
  443. if (textAlignment == ToolBarTextAlign.Underneath) {
  444. strFormat.LineAlignment = StringAlignment.Center;
  445. strFormat.Alignment = StringAlignment.Center;
  446. }
  447. else {
  448. strFormat.LineAlignment = StringAlignment.Center;
  449. strFormat.Alignment = StringAlignment.Near;
  450. }
  451. if (recalculate) {
  452. CalcToolBar ();
  453. CreateBuffers (Width, Height);
  454. }
  455. ThemeEngine.Current.DrawToolBar (DeviceContext, this, strFormat);
  456. }
  457. redraw = false;
  458. recalculate = false;
  459. }
  460. private Size CalcButtonSize ()
  461. {
  462. ToolBarButton button;
  463. String longestText = buttons [0].Text;
  464. for (int i = 1; i < buttons.Count; i++) {
  465. if (buttons[i].Text.Length > longestText.Length)
  466. longestText = buttons[i].Text;
  467. }
  468. SizeF sz = this.DeviceContext.MeasureString (longestText, this.Font);
  469. Size size = new Size ((int) Math.Ceiling (sz.Width), (int) Math.Ceiling (sz.Height));
  470. if (imageList != null) {
  471. int imgWidth = this.ImageSize.Width + 2 * ThemeEngine.Current.ToolBarImageGripWidth;
  472. // adjustment for the image grip
  473. int imgHeight = this.ImageSize.Height + 2 * ThemeEngine.Current.ToolBarImageGripWidth;
  474. if (textAlignment == ToolBarTextAlign.Right) {
  475. size.Width = imgWidth + size.Width;
  476. size.Height = (size.Height > imgHeight) ? size.Height : imgHeight;
  477. }
  478. else {
  479. size.Height = imgHeight + size.Height;
  480. size.Width = (size.Width > imgWidth) ? size.Width : imgWidth;
  481. }
  482. }
  483. return size;
  484. }
  485. private void DumpToolBar (string msg) {
  486. Console.WriteLine (msg);
  487. Console.WriteLine ("ToolBar: name: " + this.Text);
  488. Console.WriteLine ("ToolBar: wd, ht: " + this.Size);
  489. Console.WriteLine ("ToolBar: img size: " + this.ImageSize);
  490. Console.WriteLine ("ToolBar: button sz: " + this.buttonSize);
  491. Console.WriteLine ("ToolBar: textalignment: "+ this.TextAlign);
  492. Console.WriteLine ("ToolBar: appearance: "+ this.Appearance);
  493. Console.WriteLine ("ToolBar: wrappable: "+ this.Wrappable);
  494. Console.WriteLine ("ToolBar: buttons count: " + this.Buttons.Count);
  495. int i= 0;
  496. foreach (ToolBarButton b in buttons) {
  497. Console.WriteLine ("ToolBar: button [{0}]:",i++);
  498. b.Dump ();
  499. }
  500. }
  501. /* Checks for the separators and sets the location of a button and its wrapper flag */
  502. private void CalcToolBar ()
  503. {
  504. int wd = this.Width; // the amount of space we have for rest of the buttons
  505. int ht = this.ButtonSize.Height; // all buttons are displayed with the same height
  506. Point loc = new Point (0, 0); // the location to place the next button
  507. // clear all the wrappers if toolbar is not wrappable
  508. if (! wrappable && ! autosize) {
  509. if (this.Height != this.DefaultSize.Height)
  510. this.Height = this.DefaultSize.Height;
  511. foreach (ToolBarButton button in buttons) {
  512. button.Location = loc;
  513. button.Wrapper = false;
  514. loc.X = loc.X + button.Rectangle.Width;
  515. }
  516. }
  517. else if (! wrappable) { // autosizeable
  518. if (ht != this.Height)
  519. this.Height = ht;
  520. foreach (ToolBarButton button in buttons) {
  521. button.Location = loc;
  522. button.Wrapper = false;
  523. loc.X = loc.X + button.Rectangle.Width;
  524. }
  525. }
  526. else { // wrappable
  527. bool seenSeparator = false;
  528. int separatorIndex = -1;
  529. ToolBarButton button;
  530. for (int i = 0; i < buttons.Count; i++) {
  531. button = buttons [i];
  532. if (button.Visible) {
  533. if (button.Style == ToolBarButtonStyle.Separator) {
  534. wd -= ThemeEngine.Current.ToolBarSeparatorWidth;
  535. if (wd > 0) {
  536. button.Wrapper = false; // clear the old flag in case it was set
  537. button.Location = loc;
  538. loc.X = loc.X + ThemeEngine.Current.ToolBarSeparatorWidth;
  539. }
  540. else {
  541. button.Wrapper = true;
  542. button.Location = loc;
  543. loc.X = 0;
  544. wd = this.Width;
  545. // we need space to draw horizontal separator
  546. loc.Y = loc.Y + ThemeEngine.Current.ToolBarSeparatorWidth + ht;
  547. }
  548. seenSeparator = true;
  549. separatorIndex = i;
  550. }
  551. else {
  552. Rectangle rect = button.Rectangle;
  553. wd -= rect.Width;
  554. if (wd > 0) {
  555. button.Wrapper = false;
  556. button.Location = loc;
  557. loc.X = loc.X + rect.Width;
  558. }
  559. else if (seenSeparator) {
  560. // wrap at the separator and reassign the locations
  561. i = separatorIndex; // for loop is going to increment it
  562. buttons [separatorIndex].Wrapper = true;
  563. seenSeparator = false;
  564. separatorIndex = -1;
  565. loc.X = 0;
  566. // we need space to draw horizontal separator
  567. loc.Y = loc.Y + ht + ThemeEngine.Current.ToolBarSeparatorWidth;
  568. wd = this.Width;
  569. continue;
  570. }
  571. else {
  572. button.Wrapper = true;
  573. wd = this.Width;
  574. loc.X = 0;
  575. loc.Y += ht;
  576. button.Location = loc;
  577. loc.X = loc.X + rect.Width;
  578. }
  579. }
  580. }
  581. else // don't consider invisible buttons
  582. continue;
  583. }
  584. /* adjust the control height, if we are autosizeable */
  585. if (autosize) // wrappable
  586. if (this.Height != (loc.Y + ht))
  587. this.Height = loc.Y + ht;
  588. }
  589. }
  590. #endregion Private Methods
  591. #region subclass
  592. public class ToolBarButtonCollection : IList, ICollection, IEnumerable
  593. {
  594. #region instance variables
  595. private ArrayList buttonsList;
  596. private ToolBar owner;
  597. #endregion
  598. #region constructors
  599. public ToolBarButtonCollection (ToolBar owner)
  600. {
  601. this.owner = owner;
  602. this.buttonsList = new ArrayList ();
  603. }
  604. #endregion
  605. #region properties
  606. public virtual int Count {
  607. get { return buttonsList.Count; }
  608. }
  609. public virtual bool IsReadOnly {
  610. get { return buttonsList.IsReadOnly; }
  611. }
  612. public virtual ToolBarButton this [int index] {
  613. get { return (ToolBarButton) buttonsList [index]; }
  614. set {
  615. value.SetParent (owner);
  616. buttonsList [index] = value;
  617. owner.Redraw (true);
  618. }
  619. }
  620. bool ICollection.IsSynchronized {
  621. get { return buttonsList.IsSynchronized; }
  622. }
  623. object ICollection.SyncRoot {
  624. get { return buttonsList.SyncRoot; }
  625. }
  626. bool IList.IsFixedSize {
  627. get { return buttonsList.IsFixedSize; }
  628. }
  629. object IList.this [int index] {
  630. get { return this [index]; }
  631. set {
  632. if (! (value is ToolBarButton))
  633. throw new ArgumentException("Not of type ToolBarButton", "value");
  634. this [index] = (ToolBarButton) value;
  635. }
  636. }
  637. #endregion
  638. #region methods
  639. public int Add (string text)
  640. {
  641. ToolBarButton button = new ToolBarButton (text);
  642. return this.Add (button);
  643. }
  644. public int Add (ToolBarButton button)
  645. {
  646. int result;
  647. button.SetParent (owner);
  648. result = buttonsList.Add (button);
  649. owner.Redraw (true);
  650. return result;
  651. }
  652. public void AddRange (ToolBarButton [] buttons)
  653. {
  654. foreach (ToolBarButton button in buttons)
  655. Add (button);
  656. }
  657. public virtual void Clear ()
  658. {
  659. buttonsList.Clear ();
  660. owner.Redraw (false);
  661. }
  662. public bool Contains (ToolBarButton button)
  663. {
  664. return buttonsList.Contains (button);
  665. }
  666. public virtual IEnumerator GetEnumerator ()
  667. {
  668. return buttonsList.GetEnumerator ();
  669. }
  670. void ICollection.CopyTo (Array dest, int index)
  671. {
  672. buttonsList.CopyTo (dest, index);
  673. }
  674. int IList.Add (object button)
  675. {
  676. if (! (button is ToolBarButton)) {
  677. throw new ArgumentException("Not of type ToolBarButton", "button");
  678. }
  679. return this.Add ((ToolBarButton) button);
  680. }
  681. bool IList.Contains (object button)
  682. {
  683. if (! (button is ToolBarButton)) {
  684. throw new ArgumentException("Not of type ToolBarButton", "button");
  685. }
  686. return this.Contains ((ToolBarButton) button);
  687. }
  688. int IList.IndexOf (object button)
  689. {
  690. if (! (button is ToolBarButton)) {
  691. throw new ArgumentException("Not of type ToolBarButton", "button");
  692. }
  693. return this.IndexOf ((ToolBarButton) button);
  694. }
  695. void IList.Insert (int index, object button)
  696. {
  697. if (! (button is ToolBarButton)) {
  698. throw new ArgumentException("Not of type ToolBarButton", "button");
  699. }
  700. this.Insert (index, (ToolBarButton) button);
  701. }
  702. void IList.Remove (object button)
  703. {
  704. if (! (button is ToolBarButton)) {
  705. throw new ArgumentException("Not of type ToolBarButton", "button");
  706. }
  707. this.Remove ((ToolBarButton) button);
  708. }
  709. public int IndexOf (ToolBarButton button)
  710. {
  711. return buttonsList.IndexOf (button);
  712. }
  713. public void Insert (int index, ToolBarButton button)
  714. {
  715. buttonsList.Insert (index, button);
  716. owner.Redraw (true);
  717. }
  718. public void Remove (ToolBarButton button)
  719. {
  720. buttonsList.Remove (button);
  721. owner.Redraw (true);
  722. }
  723. public virtual void RemoveAt (int index)
  724. {
  725. buttonsList.RemoveAt (index);
  726. owner.Redraw (true);
  727. }
  728. #endregion methods
  729. }
  730. #endregion subclass
  731. }
  732. }