PropertyGrid.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886
  1. // Permission is hereby granted, free of charge, to any person obtaining
  2. // a copy of this software and associated documentation files (the
  3. // "Software"), to deal in the Software without restriction, including
  4. // without limitation the rights to use, copy, modify, merge, publish,
  5. // distribute, sublicense, and/or sell copies of the Software, and to
  6. // permit persons to whom the Software is furnished to do so, subject to
  7. // the following conditions:
  8. //
  9. // The above copyright notice and this permission notice shall be
  10. // included in all copies or substantial portions of the Software.
  11. //
  12. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  13. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  14. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  15. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  16. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  17. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  18. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  19. //
  20. // Copyright (c) 2004-2005 Novell, Inc.
  21. //
  22. // Authors:
  23. // Jonathan Chambers ([email protected])
  24. //
  25. // NOT COMPLETE
  26. using System;
  27. using System.Drawing;
  28. using System.Drawing.Design;
  29. using System.ComponentModel;
  30. using System.Collections;
  31. using System.ComponentModel.Design;
  32. using System.Reflection;
  33. using System.Windows.Forms.Design;
  34. using System.Windows.Forms.PropertyGridInternal;
  35. namespace System.Windows.Forms
  36. {
  37. [Designer("System.Windows.Forms.Design.PropertyGridDesigner, " + Consts.AssemblySystem_Design)]
  38. public class PropertyGrid : System.Windows.Forms.ContainerControl, ComponentModel.Com2Interop.IComPropertyBrowser
  39. {
  40. #region Private Members
  41. private const int GRID_ITEM_HEIGHT = 16;
  42. private const int GRID_LEFT_COLUMN_WIDTH = 16;
  43. private const int DIVIDER_PADDING = 2;
  44. private AttributeCollection browsable_attributes = null;
  45. private bool can_show_commands = false;
  46. private Color commands_back_color;
  47. private Color commands_fore_color;
  48. private bool commands_visible;
  49. private bool commands_visible_if_available;
  50. private Point context_menu_default_location;
  51. private bool large_buttons;
  52. private Color line_color;
  53. private PropertySort property_sort;
  54. private PropertyTabCollection property_tabs;
  55. private GridItem selected_grid_item;
  56. internal GridItemCollection grid_items;
  57. private object[] selected_objects;
  58. private PropertyTab selected_tab;
  59. private ImageList toolbar_imagelist;
  60. private ToolBarButton categorized_toolbarbutton;
  61. private ToolBarButton alphabetic_toolbarbutton;
  62. private ToolBarButton separator_toolbarbutton;
  63. private ToolBarButton propertypages_toolbarbutton;
  64. internal ToolBar toolbar;
  65. internal PropertyGridView property_grid_view;
  66. internal Splitter splitter;
  67. internal Panel help_panel;
  68. internal Label help_title_label;
  69. internal Label help_description_label;
  70. private ContextMenu context_menu;
  71. private MenuItem reset_menuitem;
  72. private MenuItem description_menuitem;
  73. #endregion // Private Members
  74. #region Contructors
  75. public PropertyGrid() {
  76. selected_objects = new object[1];
  77. grid_items = new GridItemCollection();
  78. line_color = SystemColors.ScrollBar;
  79. line_color = SystemColors.ScrollBar;
  80. browsable_attributes = new AttributeCollection(new Attribute[] {});
  81. commands_visible_if_available = false;
  82. property_sort = PropertySort.Categorized;
  83. property_grid_view = new PropertyGridView(this);
  84. property_grid_view.Dock = DockStyle.Fill;
  85. splitter = new Splitter();
  86. splitter.Dock = DockStyle.Bottom;
  87. help_panel = new Panel();
  88. help_panel.Dock = DockStyle.Bottom;
  89. help_panel.Height = 50;
  90. help_description_label = new Label();
  91. help_description_label.Dock = DockStyle.Fill;
  92. help_description_label.Name = "help_description_label";
  93. help_description_label.Font = this.Font;
  94. help_title_label = new Label();
  95. help_title_label.Dock = DockStyle.Top;
  96. help_title_label.Name = "help_title_label";
  97. help_description_label.Font = new Font(this.Font,FontStyle.Bold);
  98. help_panel.Controls.Add(help_description_label);
  99. help_panel.Controls.Add(help_title_label);
  100. toolbar = new ToolBar();
  101. toolbar.Dock = DockStyle.Top;
  102. categorized_toolbarbutton = new ToolBarButton();
  103. alphabetic_toolbarbutton = new ToolBarButton();
  104. separator_toolbarbutton = new ToolBarButton();
  105. propertypages_toolbarbutton = new ToolBarButton();
  106. context_menu = new ContextMenu();
  107. //help_title_label.Dock = DockStyle.Top;
  108. help_title_label.Name = "help_title_label";
  109. help_title_label.Location = new Point(2,20);
  110. help_title_label.Size = new Size(20,20);
  111. toolbar_imagelist = new ImageList();
  112. toolbar_imagelist.ColorDepth = ColorDepth.Depth32Bit;
  113. toolbar_imagelist.ImageSize = new System.Drawing.Size(16, 16);
  114. toolbar_imagelist.TransparentColor = System.Drawing.Color.Transparent;
  115. toolbar.Appearance = ToolBarAppearance.Flat;
  116. toolbar.AutoSize = false;
  117. toolbar.Buttons.AddRange(new ToolBarButton[] {
  118. categorized_toolbarbutton,
  119. alphabetic_toolbarbutton,
  120. separator_toolbarbutton,
  121. propertypages_toolbarbutton});
  122. toolbar.ButtonSize = new System.Drawing.Size(20, 20);
  123. toolbar.ImageList = toolbar_imagelist;
  124. toolbar.Location = new System.Drawing.Point(0, 0);
  125. toolbar.Name = "toolbar";
  126. toolbar.ShowToolTips = true;
  127. toolbar.Size = new System.Drawing.Size(256, 27);
  128. toolbar.TabIndex = 0;
  129. toolbar.ButtonClick += new ToolBarButtonClickEventHandler(toolbar_ButtonClick);
  130. categorized_toolbarbutton.Style = ToolBarButtonStyle.ToggleButton;
  131. categorized_toolbarbutton.ToolTipText = "Categorized";
  132. categorized_toolbarbutton.Text = "C";
  133. alphabetic_toolbarbutton.Style = ToolBarButtonStyle.ToggleButton;
  134. alphabetic_toolbarbutton.ToolTipText = "Alphabetic";
  135. alphabetic_toolbarbutton.Text = "A";
  136. alphabetic_toolbarbutton.ImageIndex = 0;
  137. separator_toolbarbutton.Style = ToolBarButtonStyle.Separator;
  138. propertypages_toolbarbutton.Enabled = false;
  139. propertypages_toolbarbutton.Style = ToolBarButtonStyle.ToggleButton;
  140. propertypages_toolbarbutton.ToolTipText = "Property Pages";
  141. propertypages_toolbarbutton.Text = "P";
  142. reset_menuitem = context_menu.MenuItems.Add("Reset");
  143. reset_menuitem.Click +=new EventHandler(OnResetPropertyClick);
  144. context_menu.MenuItems.Add("-");
  145. description_menuitem = context_menu.MenuItems.Add("Description");
  146. description_menuitem.Click += new EventHandler(OnDescriptionClick);
  147. description_menuitem.Checked = this.HelpVisible;
  148. this.ContextMenu = context_menu;
  149. toolbar.ContextMenu = context_menu;
  150. this.Controls.Add(property_grid_view);
  151. this.Controls.Add(toolbar);
  152. this.Controls.Add(splitter);
  153. this.Controls.Add(help_panel);
  154. this.Name = "PropertyGrid";
  155. this.Size = new System.Drawing.Size(256, 400);
  156. has_focus = false;
  157. //TextChanged+=new System.EventHandler(RedrawEvent);
  158. //ForeColorChanged+=new EventHandler(RedrawEvent);
  159. //BackColorChanged+=new System.EventHandler(RedrawEvent);
  160. //FontChanged+=new EventHandler(RedrawEvent);
  161. //SizeChanged+=new EventHandler(RedrawEvent);
  162. SetStyle(ControlStyles.UserPaint, true);
  163. SetStyle(ControlStyles.AllPaintingInWmPaint, true);
  164. SetStyle(ControlStyles.ResizeRedraw, true);
  165. SetStyle(ControlStyles.StandardClick | ControlStyles.StandardDoubleClick, false);
  166. UpdateToolBarButtons();
  167. }
  168. #endregion // Constructors
  169. #region Public Instance Properties
  170. [BrowsableAttribute(false)]
  171. [EditorBrowsableAttribute(EditorBrowsableState.Advanced)]
  172. [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden)]
  173. public AttributeCollection BrowsableAttributes {
  174. get {
  175. return browsable_attributes;
  176. }
  177. set {
  178. if (browsable_attributes == value) {
  179. return;
  180. }
  181. browsable_attributes = value;
  182. }
  183. }
  184. public override Color BackColor {
  185. get {
  186. return base.BackColor;
  187. }
  188. set {
  189. if (base.BackColor == value) {
  190. return;
  191. }
  192. base.BackColor = value;
  193. }
  194. }
  195. [BrowsableAttribute(false)]
  196. [EditorBrowsableAttribute(EditorBrowsableState.Advanced)]
  197. public virtual bool CanShowCommands {
  198. get {
  199. return can_show_commands;
  200. }
  201. }
  202. public Color CommandsBackColor {
  203. get {
  204. return commands_back_color;
  205. }
  206. set {
  207. if (commands_back_color == value) {
  208. return;
  209. }
  210. commands_back_color = value;
  211. }
  212. }
  213. public Color CommandsForeColor {
  214. get {
  215. return commands_fore_color;
  216. }
  217. set {
  218. if (commands_fore_color == value) {
  219. return;
  220. }
  221. commands_fore_color = value;
  222. }
  223. }
  224. [BrowsableAttribute(false)]
  225. [EditorBrowsableAttribute(EditorBrowsableState.Advanced)]
  226. public virtual bool CommandsVisible {
  227. get {
  228. return commands_visible;
  229. }
  230. }
  231. [DefaultValue(false)]
  232. public virtual bool CommandsVisibleIfAvailable {
  233. get {
  234. return commands_visible_if_available;
  235. }
  236. set {
  237. if (commands_visible_if_available == value) {
  238. return;
  239. }
  240. commands_visible_if_available = value;
  241. }
  242. }
  243. [BrowsableAttribute(false)]
  244. [EditorBrowsableAttribute(EditorBrowsableState.Advanced)]
  245. [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden)]
  246. public Point ContextMenuDefaultLocation {
  247. get {
  248. return context_menu_default_location;
  249. }
  250. }
  251. public Color HelpBackColor {
  252. get
  253. {
  254. return help_panel.BackColor;
  255. }
  256. set
  257. {
  258. if (help_panel.BackColor == value) {
  259. return;
  260. }
  261. help_panel.BackColor = value;
  262. }
  263. }
  264. public Color HelpForeColor {
  265. get {
  266. return help_panel.ForeColor;
  267. }
  268. set {
  269. if (help_panel.ForeColor == value) {
  270. return;
  271. }
  272. help_panel.ForeColor = value;
  273. }
  274. }
  275. [DefaultValue(true)]
  276. [Localizable(true)]
  277. public virtual bool HelpVisible {
  278. get {
  279. return help_panel.Visible;
  280. }
  281. set {
  282. if (help_panel.Visible == value) {
  283. return;
  284. }
  285. help_panel.Visible = value;
  286. }
  287. }
  288. public bool LargeButtons {
  289. get {
  290. return large_buttons;
  291. }
  292. set {
  293. if (large_buttons == value) {
  294. return;
  295. }
  296. large_buttons = value;
  297. }
  298. }
  299. public Color LineColor {
  300. get {
  301. return line_color;
  302. }
  303. set {
  304. if (line_color == value) {
  305. return;
  306. }
  307. line_color = value;
  308. }
  309. }
  310. [DefaultValue(PropertySort.Categorized)]
  311. public PropertySort PropertySort {
  312. get {
  313. return property_sort;
  314. }
  315. set {
  316. if (!Enum.IsDefined (typeof (PropertySort), value)) {
  317. throw new InvalidEnumArgumentException (string.Format("Enum argument value '{0}' is not valid for PropertySort", value));
  318. }
  319. if (property_sort == value) {
  320. return;
  321. }
  322. property_sort = value;
  323. ReflectObjects();
  324. property_grid_view.Redraw();
  325. if (PropertySortChanged != null) {
  326. PropertySortChanged(this, EventArgs.Empty);
  327. }
  328. }
  329. }
  330. [BrowsableAttribute(false)]
  331. [EditorBrowsableAttribute(EditorBrowsableState.Advanced)]
  332. [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden)]
  333. public PropertyTabCollection PropertyTabs {
  334. get {
  335. return property_tabs;
  336. }
  337. }
  338. [BrowsableAttribute(false)]
  339. [EditorBrowsableAttribute(EditorBrowsableState.Advanced)]
  340. [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden)]
  341. public GridItem SelectedGridItem {
  342. get {
  343. return selected_grid_item;
  344. }
  345. set {
  346. if (selected_grid_item == value) {
  347. return;
  348. }
  349. GridItem oldItem = selected_grid_item;
  350. selected_grid_item = value;
  351. this.help_title_label.Text = selected_grid_item.Label;
  352. if (selected_grid_item.PropertyDescriptor != null)
  353. this.help_description_label.Text = selected_grid_item.PropertyDescriptor.Description;
  354. property_grid_view.Redraw();
  355. if (SelectedGridItemChanged != null) {
  356. SelectedGridItemChanged(this, new SelectedGridItemChangedEventArgs( oldItem, selected_grid_item));
  357. }
  358. }
  359. }
  360. [DefaultValue(null)]
  361. [TypeConverter("System.Windows.Forms.PropertyGrid+SelectedObjectConverter, System.Windows.Forms, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
  362. public object SelectedObject {
  363. get {
  364. return selected_objects[0];
  365. }
  366. set {
  367. selected_objects = new object[] {value};
  368. ReflectObjects();
  369. property_grid_view.Redraw();
  370. }
  371. }
  372. [BrowsableAttribute(false)]
  373. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  374. public object[] SelectedObjects {
  375. get {
  376. return selected_objects;
  377. }
  378. set {
  379. selected_objects = value;
  380. ReflectObjects();
  381. }
  382. }
  383. [BrowsableAttribute(false)]
  384. [EditorBrowsable(EditorBrowsableState.Advanced)]
  385. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  386. public PropertyTab SelectedTab {
  387. get {
  388. return selected_tab;
  389. }
  390. }
  391. public override ISite Site {
  392. get {
  393. return base.Site;
  394. }
  395. set {
  396. base.Site = value;
  397. }
  398. }
  399. [DefaultValue(true)]
  400. public virtual bool ToolbarVisible {
  401. get {
  402. return toolbar.Visible;
  403. }
  404. set {
  405. if (toolbar.Visible == value) {
  406. return;
  407. }
  408. toolbar.Visible = value;
  409. }
  410. }
  411. public Color ViewBackColor {
  412. get {
  413. return property_grid_view.BackColor;
  414. }
  415. set {
  416. if (property_grid_view.BackColor == value) {
  417. return;
  418. }
  419. property_grid_view.BackColor = value;
  420. }
  421. }
  422. public Color ViewForeColor {
  423. get {
  424. return property_grid_view.ForeColor;
  425. }
  426. set {
  427. if (property_grid_view.ForeColor == value) {
  428. return;
  429. }
  430. property_grid_view.ForeColor = value;
  431. }
  432. }
  433. #endregion // Public Instance Properties
  434. #region Protected Instance Properties
  435. protected override Size DefaultSize {
  436. get {
  437. return base.DefaultSize;
  438. }
  439. }
  440. [MonoTODO]
  441. [Browsable(false)]
  442. [EditorBrowsable(EditorBrowsableState.Advanced)]
  443. protected virtual Type DefaultTabType {
  444. get {
  445. throw new NotImplementedException();
  446. }
  447. }
  448. protected override bool ShowFocusCues {
  449. get {
  450. return base.ShowFocusCues;
  451. }
  452. }
  453. #endregion // Protected Instance Properties
  454. #region Public Instance Methods
  455. [MonoTODO]
  456. public void CollapseAllGridItems ()
  457. {
  458. throw new NotImplementedException();
  459. }
  460. [MonoTODO]
  461. public void ExpandAllGridItems ()
  462. {
  463. throw new NotImplementedException();
  464. }
  465. public override void Refresh ()
  466. {
  467. base.Refresh ();
  468. }
  469. [MonoTODO]
  470. public void RefreshTabs (PropertyTabScope tabScope)
  471. {
  472. throw new NotImplementedException();
  473. }
  474. [MonoTODO]
  475. public void ResetSelectedProperty()
  476. {
  477. throw new NotImplementedException();
  478. }
  479. #endregion // Public Instance Methods
  480. #region Protected Instance Methods
  481. [MonoTODO]
  482. protected virtual PropertyTab CreatePropertyTab(Type tabType)
  483. {
  484. throw new NotImplementedException();
  485. }
  486. protected override void OnFontChanged(EventArgs e)
  487. {
  488. base.OnFontChanged (e);
  489. }
  490. protected override void OnGotFocus(EventArgs e)
  491. {
  492. has_focus=true;
  493. base.OnGotFocus(e);
  494. }
  495. protected override void OnHandleCreated (EventArgs e)
  496. {
  497. base.OnHandleCreated (e);
  498. }
  499. protected override void OnHandleDestroyed (EventArgs e)
  500. {
  501. base.OnHandleDestroyed (e);
  502. }
  503. protected override void OnMouseDown (MouseEventArgs e)
  504. {
  505. base.OnMouseDown (e);
  506. }
  507. protected override void OnMouseMove (MouseEventArgs e)
  508. {
  509. base.OnMouseMove (e);
  510. }
  511. protected override void OnMouseUp (MouseEventArgs e)
  512. {
  513. base.OnMouseUp (e);
  514. }
  515. protected override void OnPaint (PaintEventArgs pevent)
  516. {
  517. base.OnPaint (pevent);
  518. }
  519. [MonoTODO]
  520. protected virtual void OnPropertyTabChanged (PropertyTabChangedEventArgs e)
  521. {
  522. throw new NotImplementedException();
  523. }
  524. [MonoTODO]
  525. protected virtual void OnPropertyValueChanged (PropertyValueChangedEventArgs e)
  526. {
  527. throw new NotImplementedException();
  528. }
  529. protected override void OnResize (EventArgs e)
  530. {
  531. base.OnResize (e);
  532. }
  533. [MonoTODO]
  534. protected virtual void OnSelectedGridItemChanged (SelectedGridItemChangedEventArgs e)
  535. {
  536. throw new NotImplementedException();
  537. }
  538. [MonoTODO]
  539. protected virtual void OnSelectedObjectsChanged (EventArgs e)
  540. {
  541. throw new NotImplementedException();
  542. }
  543. protected override void OnSystemColorsChanged (EventArgs e)
  544. {
  545. base.OnSystemColorsChanged (e);
  546. }
  547. protected override void OnVisibleChanged (EventArgs e)
  548. {
  549. base.OnVisibleChanged (e);
  550. }
  551. protected override bool ProcessDialogKey (Keys keyData)
  552. {
  553. return base.ProcessDialogKey (keyData);
  554. }
  555. protected override void ScaleCore (float dx, float dy)
  556. {
  557. base.ScaleCore (dx, dy);
  558. }
  559. protected override void WndProc (ref Message m)
  560. {
  561. base.WndProc (ref m);
  562. }
  563. #endregion
  564. #region Events
  565. public event EventHandler PropertySortChanged;
  566. public event PropertyTabChangedEventHandler PropertyTabChanged;
  567. public event PropertyValueChangedEventHandler PropertyValueChanged;
  568. public event SelectedGridItemChangedEventHandler SelectedGridItemChanged;
  569. public event EventHandler SelectedObjectsChanged;
  570. #endregion
  571. #region Com2Interop.IComPropertyBrowser Interface
  572. [MonoTODO]
  573. bool ComponentModel.Com2Interop.IComPropertyBrowser.InPropertySet {
  574. get {
  575. throw new NotImplementedException();
  576. }
  577. }
  578. [MonoTODO]
  579. void ComponentModel.Com2Interop.IComPropertyBrowser.DropDownDone() {
  580. throw new NotImplementedException();
  581. }
  582. [MonoTODO]
  583. bool ComponentModel.Com2Interop.IComPropertyBrowser.EnsurePendingChangesCommitted() {
  584. throw new NotImplementedException();
  585. }
  586. [MonoTODO]
  587. void ComponentModel.Com2Interop.IComPropertyBrowser.HandleF4() {
  588. throw new NotImplementedException();
  589. }
  590. [MonoTODO]
  591. void ComponentModel.Com2Interop.IComPropertyBrowser.LoadState(Microsoft.Win32.RegistryKey key) {
  592. throw new NotImplementedException();
  593. }
  594. [MonoTODO]
  595. void ComponentModel.Com2Interop.IComPropertyBrowser.SaveState(Microsoft.Win32.RegistryKey key) {
  596. throw new NotImplementedException();
  597. }
  598. [MonoTODO]
  599. private event ComponentRenameEventHandler com_component_name_changed;
  600. event ComponentRenameEventHandler ComponentModel.Com2Interop.IComPropertyBrowser.ComComponentNameChanged {
  601. add { com_component_name_changed += value; }
  602. remove { com_component_name_changed -= value; }
  603. }
  604. #endregion // Com2Interop.IComPropertyBrowser Interface
  605. #region PropertyTabCollection Class
  606. public class PropertyTabCollection : ICollection, IEnumerable
  607. {
  608. #region Private Constructors
  609. private PropertyTabCollection() {
  610. }
  611. #endregion // Private Constructors
  612. [MonoTODO]
  613. public PropertyTab this[int index] {
  614. get {
  615. throw new NotImplementedException();
  616. }
  617. }
  618. #region ICollection Members
  619. [MonoTODO]
  620. bool ICollection.IsSynchronized
  621. {
  622. get {
  623. // TODO: Add PropertyTabCollection.IsSynchronized getter implementation
  624. return false;
  625. }
  626. }
  627. [MonoTODO]
  628. void ICollection.CopyTo(Array array, int index)
  629. {
  630. // TODO: Add PropertyTabCollection.CopyTo implementation
  631. }
  632. [MonoTODO]
  633. object ICollection.SyncRoot
  634. {
  635. get {
  636. // TODO: Add PropertyTabCollection.SyncRoot getter implementation
  637. return null;
  638. }
  639. }
  640. #endregion
  641. #region IEnumerable Members
  642. [MonoTODO]
  643. public IEnumerator GetEnumerator() {
  644. // TODO: Add PropertyTabCollection.GetEnumerator implementation
  645. return null;
  646. }
  647. #endregion
  648. #region ICollection Members
  649. [MonoTODO]
  650. public int Count {
  651. get {
  652. // TODO: Add PropertyTabCollection.Count getter implementation
  653. return 0;
  654. }
  655. }
  656. #endregion
  657. }
  658. #endregion // PropertyTabCollection Class
  659. #region Private Helper Methods
  660. private void toolbar_ButtonClick (object sender, ToolBarButtonClickEventArgs e)
  661. {
  662. if (e.Button == alphabetic_toolbarbutton) {
  663. this.PropertySort = PropertySort.Alphabetical;
  664. }
  665. else if (e.Button == categorized_toolbarbutton) {
  666. this.PropertySort = PropertySort.Categorized;
  667. }
  668. UpdateToolBarButtons();
  669. ReflectObjects();
  670. property_grid_view.Redraw();
  671. }
  672. internal void UpdateToolBarButtons ()
  673. {
  674. if (PropertySort == PropertySort.Alphabetical) {
  675. categorized_toolbarbutton.Pushed = false;
  676. alphabetic_toolbarbutton.Pushed = true;
  677. }
  678. else if (PropertySort == PropertySort.Categorized) {
  679. categorized_toolbarbutton.Pushed = true;
  680. alphabetic_toolbarbutton.Pushed = false;
  681. }
  682. else {
  683. categorized_toolbarbutton.Pushed = false;
  684. alphabetic_toolbarbutton.Pushed = false;
  685. }
  686. }
  687. private void OnResetPropertyClick (object sender, EventArgs e)
  688. {
  689. ResetSelectedProperty();
  690. }
  691. private void OnDescriptionClick (object sender, EventArgs e)
  692. {
  693. this.HelpVisible = !this.HelpVisible;
  694. description_menuitem.Checked = this.HelpVisible;
  695. }
  696. private void ReflectObjects ()
  697. {
  698. GridItemCollection alphabetical_grid_items = new GridItemCollection();
  699. GridItemCollection category_grid_items = new GridItemCollection();
  700. foreach (object obj in selected_objects) {
  701. if (obj != null) {
  702. PopulateGridItemCollection(obj,alphabetical_grid_items, category_grid_items);
  703. }
  704. }
  705. if (PropertySort == PropertySort.Alphabetical) {
  706. grid_items = alphabetical_grid_items;
  707. }
  708. // need to use categories
  709. else {
  710. grid_items = category_grid_items;
  711. }
  712. }
  713. private void PopulateGridItemCollection (object obj, GridItemCollection grid_item_coll, GridItemCollection category_grid_item_coll)
  714. {
  715. PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(obj);
  716. for (int i = 0; i < properties.Count;i++) {
  717. bool not_browseable = properties[i].Attributes.Contains(new BrowsableAttribute(false));
  718. if (!not_browseable) {
  719. GridEntry grid_entry = new GridEntry(obj, properties[i]);
  720. grid_item_coll.Add(properties[i].Name,grid_entry);
  721. string category = properties[i].Category;
  722. GridItem cat_item = category_grid_item_coll[category];
  723. if (cat_item == null) {
  724. cat_item = new CategoryGridEntry(category);
  725. category_grid_item_coll.Add(category,cat_item);
  726. }
  727. cat_item.GridItems.Add(properties[i].Name,grid_entry);
  728. }
  729. }
  730. }
  731. #endregion // Private Helper Methods
  732. }
  733. }