PropertyGridView.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758
  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) 2005 Novell, Inc. (http://www.novell.com)
  21. //
  22. // Authors:
  23. // Jonathan Chambers ([email protected])
  24. //
  25. //
  26. // NOT COMPLETE
  27. using System;
  28. using System.Collections;
  29. using System.Drawing;
  30. using System.Drawing.Design;
  31. using System.ComponentModel;
  32. using System.Windows.Forms.Design;
  33. namespace System.Windows.Forms.PropertyGridInternal
  34. {
  35. internal class PropertyGridView : System.Windows.Forms.ScrollableControl, IWindowsFormsEditorService
  36. {
  37. #region Private Members
  38. private const int V_INDENT = 16;
  39. private const int ROW_HEIGHT = 16;
  40. private const int RESIZE_WIDTH = 3;
  41. private const int BUTTON_WIDTH = 25;
  42. private PropertyGridTextBox grid_textbox;
  43. private PropertyGrid property_grid;
  44. private bool resizing_grid;
  45. private int splitter_location;
  46. private int open_grid_item_count = -1;
  47. private int skipped_grid_items;
  48. private PropertyGridDropDown dropdown_form;
  49. private bool dropdown_form_showing;
  50. private Form dialog_form;
  51. private VScrollBar vbar;
  52. private StringFormat stringFormat;
  53. #endregion
  54. #region Contructors
  55. public PropertyGridView (PropertyGrid propertyGrid)
  56. {
  57. property_grid = propertyGrid;
  58. property_grid.SelectedGridItemChanged+=new SelectedGridItemChangedEventHandler(HandleSelectedGridItemChanged);
  59. property_grid.PropertyValueChanged+=new PropertyValueChangedEventHandler(HandlePropertyValueChanged);
  60. stringFormat = new StringFormat();
  61. stringFormat.FormatFlags = StringFormatFlags.NoWrap;
  62. stringFormat.Trimming = StringTrimming.None;
  63. this.BackColor = Color.Beige;
  64. grid_textbox = new PropertyGridTextBox();
  65. grid_textbox.DropDownButtonClicked +=new EventHandler(DropDownButtonClicked);
  66. grid_textbox.DialogButtonClicked +=new EventHandler(DialogButtonClicked);
  67. dropdown_form = new PropertyGridDropDown();
  68. dropdown_form.FormBorderStyle = FormBorderStyle.None;
  69. dropdown_form.ShowInTaskbar = false;
  70. dialog_form = new Form();
  71. //dialog_form.FormBorderStyle = FormBorderStyle.None;
  72. grid_textbox.Visible = false;
  73. grid_textbox.Font = this.Font;//new Font(this.Font,FontStyle.Bold);
  74. grid_textbox.BackColor = this.BackColor;
  75. // Not working at all, used to??
  76. grid_textbox.Validating += new CancelEventHandler(TextBoxValidating);
  77. this.Controls.Add(grid_textbox);
  78. vbar = new VScrollBar();
  79. vbar.Visible = false;
  80. vbar.Scroll+=new ScrollEventHandler(HandleScroll);
  81. vbar.Dock = DockStyle.Right;
  82. this.Controls.Add(vbar);
  83. splitter_location = 65;
  84. resizing_grid = false;
  85. ForeColorChanged+=new EventHandler(RedrawEvent);
  86. BackColorChanged+=new System.EventHandler(RedrawEvent);
  87. FontChanged+=new EventHandler(RedrawEvent);
  88. SizeChanged+=new EventHandler(RedrawEvent);
  89. SetStyle(ControlStyles.DoubleBuffer, true);
  90. SetStyle(ControlStyles.UserPaint, true);
  91. SetStyle(ControlStyles.AllPaintingInWmPaint, true);
  92. SetStyle(ControlStyles.ResizeRedraw, false);
  93. SetStyle(ControlStyles.StandardClick | ControlStyles.StandardDoubleClick, false);
  94. }
  95. #endregion
  96. #region Protected Instance Methods
  97. protected override void OnPaint(PaintEventArgs e)
  98. {
  99. if (property_grid.SelectedGridItem != null && property_grid.SelectedGridItem.GridItemType == GridItemType.Property)
  100. {
  101. grid_textbox.Visible = true;
  102. if (!grid_textbox.Focused)
  103. grid_textbox.Focus();
  104. }
  105. else
  106. {
  107. grid_textbox.Visible = false;
  108. }
  109. // Decide if we need a scrollbar
  110. open_grid_item_count = 0;
  111. // draw grid outline
  112. //DrawBackground(e);
  113. e.Graphics.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (BackColor), ClientRectangle);
  114. // draw grid items
  115. // can we use the transform
  116. //pevent.Graphics.TranslateTransform(0, -vbar.Value*ROW_HEIGHT);
  117. int yLoc = -vbar.Value*ROW_HEIGHT;
  118. DrawGridItems(property_grid.grid_items, e, 1, ref yLoc);
  119. DrawGrid(e, yLoc);
  120. e.Graphics.DrawRectangle(SystemPens.ControlDark, 0,0,Width-1,Height-1 );
  121. UpdateScrollBar();
  122. base.OnPaint(e);
  123. }
  124. protected override void OnMouseMove (MouseEventArgs e)
  125. {
  126. if (resizing_grid)
  127. {
  128. splitter_location = Math.Max(e.X,2*V_INDENT);
  129. Refresh();
  130. }
  131. if (e.X > splitter_location - RESIZE_WIDTH && e.X < splitter_location + RESIZE_WIDTH)
  132. this.Cursor = Cursors.SizeWE;
  133. else
  134. this.Cursor = Cursors.Default;
  135. base.OnMouseMove (e);
  136. }
  137. private GridItem GetSelectedGridItem (GridItemCollection grid_items, int y, ref int current)
  138. {
  139. foreach (GridItem child_grid_item in grid_items)
  140. {
  141. if (y > current && y < current + ROW_HEIGHT)
  142. {
  143. return child_grid_item;
  144. }
  145. current += ROW_HEIGHT;
  146. if (child_grid_item.Expanded)
  147. {
  148. GridItem foundItem = GetSelectedGridItem(child_grid_item.GridItems, y, ref current);
  149. if (foundItem != null)
  150. return foundItem;
  151. }
  152. }
  153. return null;
  154. }
  155. protected override void OnMouseDown (MouseEventArgs e)
  156. {
  157. if (e.X > splitter_location - RESIZE_WIDTH && e.X < splitter_location + RESIZE_WIDTH)
  158. {
  159. resizing_grid = true;
  160. }
  161. else
  162. {
  163. int offset = -vbar.Value*ROW_HEIGHT;
  164. GridItem foundItem = GetSelectedGridItem(property_grid.grid_items, e.Y, ref offset);
  165. if (foundItem != null)
  166. {
  167. if (foundItem.Expandable)
  168. {
  169. if (e.X >=3 && e.X <= 11 && (e.Y % ROW_HEIGHT >= 3 && e.Y % ROW_HEIGHT <= 11))
  170. {
  171. foundItem.Expanded = !foundItem.Expanded;
  172. Invalidate();
  173. }
  174. }
  175. this.property_grid.SelectedGridItem = foundItem;
  176. }
  177. base.OnMouseDown (e);
  178. }
  179. }
  180. protected override void OnMouseUp (MouseEventArgs e)
  181. {
  182. resizing_grid = false;
  183. base.OnMouseUp (e);
  184. }
  185. protected override void OnKeyDown (KeyEventArgs e)
  186. {
  187. base.OnKeyDown (e);
  188. }
  189. #endregion
  190. #region Private Helper Methods
  191. private void UpdateScrollBar()
  192. {
  193. int visible_rows = this.ClientRectangle.Height/ROW_HEIGHT;
  194. if (open_grid_item_count > visible_rows)
  195. {
  196. vbar.Visible = true;
  197. vbar.SmallChange = 1;
  198. vbar.Minimum = 0;
  199. vbar.Maximum = open_grid_item_count-1;
  200. vbar.LargeChange = visible_rows;
  201. }
  202. else
  203. {
  204. vbar.Visible = false;
  205. }
  206. }
  207. private GridItem GetGridItemAt (int y)
  208. {
  209. return null;
  210. }
  211. #region Drawing Code
  212. private void DrawGrid(PaintEventArgs pevent, int yLoc)
  213. {
  214. Pen pen = ThemeEngine.Current.ResPool.GetPen(property_grid.LineColor);
  215. // vertical divider line
  216. pevent.Graphics.DrawLine(pen, splitter_location, 0, splitter_location, yLoc);
  217. while (yLoc >= 0)
  218. {
  219. // horizontal lines
  220. pevent.Graphics.DrawLine(pen, 0, yLoc, ClientRectangle.Width, yLoc);
  221. yLoc -= ROW_HEIGHT;
  222. }
  223. }
  224. private void DrawGridItems(GridItemCollection grid_items, PaintEventArgs pevent, int depth, ref int yLoc)
  225. {
  226. foreach (GridItem grid_item in grid_items)
  227. {
  228. DrawGridItem (grid_item, pevent, depth, ref yLoc);
  229. if (grid_item.Expanded)
  230. DrawGridItems(grid_item.GridItems, pevent, (grid_item.GridItemType == GridItemType.Category) ? depth : depth+1, ref yLoc);
  231. }
  232. }
  233. private void DrawGridItemLabel(GridItem grid_item, PaintEventArgs pevent, Rectangle rect)
  234. {
  235. int x = rect.X+1;
  236. if (grid_item.Parent != null && grid_item.Parent.GridItemType != GridItemType.Category)
  237. x += V_INDENT;
  238. Font font = this.Font;
  239. Brush brush = SystemBrushes.WindowText;
  240. if (grid_item.GridItemType == GridItemType.Category)
  241. {
  242. font = new Font(font, FontStyle.Bold);
  243. brush = SystemBrushes.ControlDark;
  244. }
  245. if (grid_item == property_grid.SelectedGridItem && grid_item.GridItemType != GridItemType.Category)
  246. {
  247. pevent.Graphics.FillRectangle (SystemBrushes.Highlight, rect);
  248. // Label
  249. brush = SystemBrushes.HighlightText;
  250. }
  251. pevent.Graphics.DrawString(grid_item.Label,font,brush,new Rectangle(x, rect.Y + 2,x-rect.X+rect.Width-2,rect.Height-2),stringFormat);
  252. }
  253. private void DrawGridItemValue(GridItem grid_item, PaintEventArgs pevent, Rectangle rect)
  254. {
  255. // Value
  256. if (grid_item.PropertyDescriptor != null)
  257. {
  258. bool paintsValue = false;
  259. UITypeEditor editor = null;
  260. object temp = grid_item.PropertyDescriptor.GetEditor(typeof(UITypeEditor));
  261. editor = (UITypeEditor)temp;//grid_item.PropertyDescriptor.GetEditor(typeof(UITypeEditor));
  262. if (editor != null)
  263. {
  264. paintsValue = editor.GetPaintValueSupported();
  265. }
  266. if (grid_item == property_grid.SelectedGridItem)
  267. {
  268. grid_textbox.ReadOnly = false;
  269. grid_textbox.DropDownButtonVisible = false;
  270. grid_textbox.DialogButtonVisible = false;
  271. if (editor != null)
  272. {
  273. UITypeEditorEditStyle style = editor.GetEditStyle();
  274. switch (style)
  275. {
  276. case UITypeEditorEditStyle.DropDown:
  277. grid_textbox.DropDownButtonVisible = true;
  278. break;
  279. case UITypeEditorEditStyle.Modal:
  280. grid_textbox.DialogButtonVisible = true;
  281. break;
  282. }
  283. }
  284. else
  285. {
  286. try
  287. {
  288. if (grid_item.PropertyDescriptor.Converter != null)
  289. {
  290. if (grid_item.PropertyDescriptor.Converter.GetStandardValuesSupported())
  291. {
  292. grid_textbox.DropDownButtonVisible = true;
  293. grid_textbox.ReadOnly = true;
  294. }
  295. }
  296. else
  297. {
  298. System.Console.WriteLine("Converter not available for type {0}",grid_item.PropertyDescriptor.PropertyType);
  299. }
  300. }
  301. catch (Exception ex)
  302. {
  303. }
  304. }
  305. }
  306. int xLoc = splitter_location+1;
  307. if (paintsValue)
  308. {
  309. pevent.Graphics.DrawRectangle(ThemeEngine.Current.ResPool.GetPen(Color.Black), splitter_location+2,rect.Y+2, 20, ROW_HEIGHT-4);
  310. try
  311. {
  312. editor.PaintValue(grid_item.Value, pevent.Graphics, new Rectangle(splitter_location+3,rect.Y+3, 19, ROW_HEIGHT-5));
  313. }
  314. catch (Exception ex)
  315. {
  316. System.Console.WriteLine(ex.Message);
  317. System.Console.WriteLine("Paint Value failed for type {0}",grid_item.PropertyDescriptor.PropertyType);
  318. // design time stuff is not playing nice
  319. }
  320. xLoc += 27;
  321. }
  322. Font font = this.Font;
  323. try
  324. {
  325. if (grid_item.PropertyDescriptor.Converter != null)
  326. {
  327. string value = grid_item.PropertyDescriptor.Converter.ConvertToString(grid_item.Value);
  328. if (grid_item.PropertyDescriptor.CanResetValue(property_grid.SelectedObject))
  329. font = new Font(font, FontStyle.Bold);
  330. pevent.Graphics.DrawString(value,font,SystemBrushes.WindowText,new RectangleF(xLoc,rect.Y+2, ClientRectangle.Width-(xLoc), ROW_HEIGHT),stringFormat);
  331. }
  332. else
  333. {
  334. System.Console.WriteLine("No converter for type {0}",grid_item.PropertyDescriptor.PropertyType);
  335. }
  336. }
  337. catch (Exception e)
  338. {
  339. }
  340. if (grid_item == property_grid.SelectedGridItem && grid_item.GridItemType != GridItemType.Category)
  341. {
  342. grid_textbox.SetBounds(xLoc, rect.Top, ClientRectangle.Width-xLoc - (vbar.Visible ? vbar.Width: 0),ROW_HEIGHT);
  343. }
  344. }
  345. }
  346. private void DrawGridItem (GridItem grid_item, PaintEventArgs pevent, int depth, ref int yLoc)
  347. {
  348. if (yLoc > -ROW_HEIGHT && yLoc < ClientRectangle.Height)
  349. {
  350. // left column
  351. pevent.Graphics.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (property_grid.LineColor), 0,yLoc,V_INDENT, ROW_HEIGHT);
  352. if (grid_item.Expandable)
  353. {
  354. grid_item.PlusMinusBounds = DrawPlusMinus(pevent, 3, yLoc+3, grid_item.Expanded, grid_item.GridItemType == GridItemType.Category);
  355. }
  356. if (grid_item.GridItemType == GridItemType.Category)
  357. {
  358. pevent.Graphics.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (property_grid.LineColor), depth*V_INDENT,yLoc,ClientRectangle.Width-(depth*V_INDENT), ROW_HEIGHT);
  359. }
  360. DrawGridItemLabel(grid_item, pevent, new Rectangle(depth*V_INDENT,yLoc, splitter_location-depth*V_INDENT, ROW_HEIGHT));
  361. DrawGridItemValue(grid_item, pevent, new Rectangle(splitter_location+2,yLoc, ClientRectangle.Width-splitter_location-2, ROW_HEIGHT));
  362. }
  363. grid_item.Top = yLoc;
  364. yLoc += ROW_HEIGHT;
  365. open_grid_item_count++;
  366. }
  367. private Rectangle DrawPlusMinus (PaintEventArgs pevent, int x, int y, bool expanded, bool category)
  368. {
  369. Rectangle bounds = new Rectangle(x, y, 8, 8);
  370. if (!category) pevent.Graphics.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush(Color.White), bounds);
  371. pevent.Graphics.DrawRectangle (SystemPens.ControlDark, bounds);
  372. pevent.Graphics.DrawLine (SystemPens.ControlDark, x+2, y+4, x + 6, y+4);
  373. if (!expanded)
  374. pevent.Graphics.DrawLine (SystemPens.ControlDark, x+4, y+2, x+4, y+6);
  375. return bounds;
  376. }
  377. #endregion
  378. #region Event Handling
  379. private void RedrawEvent (object sender, System.EventArgs e)
  380. {
  381. Refresh();
  382. }
  383. private void TextBoxValidating (object sender, CancelEventArgs e)
  384. {
  385. if (this.property_grid.SelectedGridItem != null)
  386. {
  387. PropertyDescriptor desc = property_grid.SelectedGridItem.PropertyDescriptor;
  388. if (desc != null)
  389. {
  390. try
  391. {
  392. if (desc.Converter != null)
  393. {
  394. SetPropertyValue(desc.Converter.ConvertFromString(grid_textbox.Text));
  395. }
  396. else
  397. {
  398. System.Console.WriteLine("No converter for type {0}",desc.PropertyType);
  399. }
  400. }
  401. catch (Exception ex)
  402. {
  403. Console.WriteLine("Error converting string");
  404. }
  405. }
  406. }
  407. }
  408. #endregion
  409. #endregion
  410. private void dropdown_form_Deactivate (object sender, EventArgs e)
  411. {
  412. dropdown_form_showing = false;
  413. dropdown_form.Hide();
  414. //dropdown_form = new Form();
  415. }
  416. private void listBox_SelectedIndexChanged (object sender, EventArgs e)
  417. {
  418. if (this.property_grid.SelectedGridItem != null)
  419. {
  420. PropertyDescriptor desc = property_grid.SelectedGridItem.PropertyDescriptor;
  421. if (desc != null)
  422. {
  423. SetPropertyValue(((ListBox)sender).SelectedItem);
  424. }
  425. }
  426. dropdown_form.Hide();
  427. //dropdown_form = new Form();
  428. Refresh();
  429. }
  430. private void SetPropertyValue(object newVal)
  431. {
  432. if (this.property_grid.SelectedGridItem != null)
  433. {
  434. PropertyDescriptor desc = property_grid.SelectedGridItem.PropertyDescriptor;
  435. if (desc != null)
  436. {
  437. desc.SetValue(property_grid.SelectedObject, newVal);
  438. }
  439. }
  440. }
  441. private void DropDownButtonClicked (object sender, EventArgs e)
  442. {
  443. if (property_grid.SelectedGridItem.PropertyDescriptor.GetEditor(typeof(UITypeEditor)) == null)
  444. {
  445. //dropdown_form.FormBorderStyle = FormBorderStyle.None;
  446. dropdown_form.Deactivate +=new EventHandler(dropdown_form_Deactivate);
  447. ListBox listBox = new ListBox();
  448. listBox.Dock = DockStyle.Fill;
  449. listBox.SelectedIndexChanged +=new EventHandler(listBox_SelectedIndexChanged);
  450. foreach (object obj in property_grid.SelectedGridItem.PropertyDescriptor.Converter.GetStandardValues())
  451. listBox.Items.Add(obj);
  452. dropdown_form.Controls.Clear();
  453. dropdown_form.Controls.Add(listBox);
  454. dropdown_form.Location = PointToScreen(new Point(grid_textbox.Location.X,grid_textbox.Location.Y+ROW_HEIGHT));
  455. dropdown_form.Width = grid_textbox.Width;
  456. dropdown_form.Show();
  457. }
  458. else // use editor
  459. {
  460. UITypeEditor editor = (UITypeEditor)property_grid.SelectedGridItem.PropertyDescriptor.GetEditor(typeof(UITypeEditor));
  461. System.ComponentModel.Design.ServiceContainer service_container = new System.ComponentModel.Design.ServiceContainer();
  462. service_container.AddService(typeof(System.Windows.Forms.Design.IWindowsFormsEditorService), this);
  463. SetPropertyValue(editor.EditValue(new ITypeDescriptorContextImpl(this.property_grid), service_container,property_grid.SelectedGridItem.Value));
  464. }
  465. }
  466. private void DialogButtonClicked(object sender, EventArgs e)
  467. {
  468. //dialog_form.Location = PointToScreen(new Point(grid_textbox.Location.X,grid_textbox.Location.Y+ROW_HEIGHT));
  469. //dropdown_form.Width = grid_textbox.Width;
  470. dialog_form.Show();
  471. }
  472. private void HandleScroll(object sender, ScrollEventArgs e)
  473. {
  474. if (e.NewValue <= 0)
  475. {
  476. e.NewValue = 0;
  477. if (e.NewValue == vbar.Value)return;
  478. }
  479. if (e.NewValue > vbar.Maximum-ClientRectangle.Height/ROW_HEIGHT)
  480. {
  481. e.NewValue = vbar.Maximum-ClientRectangle.Height/ROW_HEIGHT+1;
  482. if (e.NewValue == vbar.Value)return;
  483. }
  484. switch (e.Type)
  485. {
  486. case ScrollEventType.SmallDecrement:
  487. XplatUI.ScrollWindow(Handle, 0, ROW_HEIGHT, false);
  488. grid_textbox.Top += ROW_HEIGHT;
  489. Invalidate(ClientRectangle);
  490. //Invalidate(new Rectangle(0,0,ClientRectangle.Width,ROW_HEIGHT));
  491. break;
  492. case ScrollEventType.SmallIncrement:
  493. XplatUI.ScrollWindow(Handle, 0, -ROW_HEIGHT, false);
  494. grid_textbox.Top -= ROW_HEIGHT;
  495. Invalidate(ClientRectangle);
  496. //Invalidate(new Rectangle(0,ClientRectangle.Bottom-ROW_HEIGHT,ClientRectangle.Width,ROW_HEIGHT));
  497. break;
  498. case ScrollEventType.LargeDecrement:
  499. XplatUI.ScrollWindow(Handle, 0, ROW_HEIGHT, false);
  500. Invalidate(ClientRectangle);
  501. break;
  502. case ScrollEventType.LargeIncrement:
  503. XplatUI.ScrollWindow(Handle, 0, -ROW_HEIGHT, false);
  504. Invalidate(ClientRectangle);
  505. break;
  506. case ScrollEventType.ThumbTrack:
  507. XplatUI.ScrollWindow(Handle, 0, -(vbar.Value-e.NewValue), false);
  508. Invalidate(ClientRectangle);
  509. break;
  510. case ScrollEventType.ThumbPosition:
  511. Invalidate(ClientRectangle);
  512. break;
  513. }
  514. }
  515. private void HandleSelectedGridItemChanged(object sender, SelectedGridItemChangedEventArgs e)
  516. {
  517. // Region not working correctly
  518. //Region clip = new Region();
  519. //if (property_grid.SelectedGridItem != null)
  520. // clip.Union(new Rectangle(0,property_grid.SelectedGridItem.Top, ClientRectangle.Width, ROW_HEIGHT));
  521. // clip.Union(new Rectangle(0,property_grid.SelectedGridItem.Top, ClientRectangle.Width, ROW_HEIGHT));
  522. if (e.NewSelection.PropertyDescriptor != null)
  523. {
  524. grid_textbox.Text = e.NewSelection.PropertyDescriptor.Converter.ConvertToString(e.NewSelection.Value);
  525. if (e.NewSelection.PropertyDescriptor.CanResetValue(property_grid.SelectedObject))
  526. grid_textbox.Font = new Font(this.Font, FontStyle.Bold);
  527. else
  528. grid_textbox.Font = this.Font;
  529. }
  530. Invalidate(/*clip*/this.ClientRectangle);
  531. Update();
  532. }
  533. private void HandlePropertyValueChanged(object s, PropertyValueChangedEventArgs e)
  534. {
  535. if (e.ChangedItem.PropertyDescriptor != null)
  536. {
  537. grid_textbox.Text = e.ChangedItem.PropertyDescriptor.Converter.ConvertToString(e.ChangedItem.Value);
  538. if (e.ChangedItem.PropertyDescriptor.CanResetValue(property_grid.SelectedObject))
  539. grid_textbox.Font = new Font(this.Font, FontStyle.Bold);
  540. else
  541. grid_textbox.Font = this.Font;
  542. }
  543. }
  544. #region IWindowsFormsEditorService Members
  545. public void CloseDropDown()
  546. {
  547. dropdown_form_showing = false;
  548. dropdown_form.Hide();
  549. }
  550. public void DropDownControl(Control control)
  551. {
  552. //dropdown_form.FormBorderStyle = FormBorderStyle.None;
  553. dropdown_form.Deactivate +=new EventHandler(dropdown_form_Deactivate);
  554. dropdown_form.Size = control.Size;
  555. control.Dock = DockStyle.Fill;
  556. dropdown_form.Controls.Clear();
  557. dropdown_form.Controls.Add(control);
  558. dropdown_form.Location = PointToScreen(new Point(grid_textbox.Location.X,grid_textbox.Location.Y+ROW_HEIGHT));
  559. dropdown_form.Width = grid_textbox.Width;
  560. dropdown_form_showing = true;
  561. dropdown_form.Show();
  562. System.Windows.Forms.MSG msg = new MSG();
  563. while (XplatUI.GetMessage(ref msg, IntPtr.Zero, 0, 0) && dropdown_form_showing)
  564. {
  565. XplatUI.TranslateMessage(ref msg);
  566. XplatUI.DispatchMessage(ref msg);
  567. }
  568. }
  569. public System.Windows.Forms.DialogResult ShowDialog(Form dialog)
  570. {
  571. return dialog.ShowDialog(this);
  572. }
  573. #endregion
  574. #region DropDownForm Class
  575. #endregion DropDownForm Class
  576. #region Internal Classes
  577. internal class ITypeDescriptorContextImpl : System.ComponentModel.ITypeDescriptorContext
  578. {
  579. private PropertyGrid property_grid;
  580. public ITypeDescriptorContextImpl(PropertyGrid propertyGrid)
  581. {
  582. property_grid = propertyGrid;
  583. }
  584. #region ITypeDescriptorContext Members
  585. public void OnComponentChanged()
  586. {
  587. // TODO: Add SystemComp.OnComponentChanged implementation
  588. }
  589. public IContainer Container
  590. {
  591. get
  592. {
  593. return property_grid as IContainer;
  594. }
  595. }
  596. public bool OnComponentChanging()
  597. {
  598. // TODO: Add SystemComp.OnComponentChanging implementation
  599. return false;
  600. }
  601. public object Instance
  602. {
  603. get
  604. {
  605. return property_grid.SelectedGridItem.Value;
  606. }
  607. }
  608. public PropertyDescriptor PropertyDescriptor
  609. {
  610. get
  611. {
  612. return property_grid.SelectedGridItem.PropertyDescriptor;
  613. }
  614. }
  615. #endregion
  616. #region IServiceProvider Members
  617. public object GetService(Type serviceType)
  618. {
  619. // TODO: Add SystemComp.GetService implementation
  620. return null;
  621. }
  622. #endregion
  623. }
  624. /*
  625. class ComboListBox
  626. */
  627. internal class PropertyGridDropDown : Form
  628. {
  629. protected override CreateParams CreateParams
  630. {
  631. get
  632. {
  633. CreateParams cp = base.CreateParams;
  634. cp.Style = unchecked ((int)(WindowStyles.WS_POPUP | WindowStyles.WS_VISIBLE | WindowStyles.WS_CLIPSIBLINGS | WindowStyles.WS_CLIPCHILDREN));
  635. cp.ExStyle |= (int)(WindowExStyles.WS_EX_TOOLWINDOW | WindowExStyles.WS_EX_TOPMOST);
  636. return cp;
  637. }
  638. }
  639. }
  640. #endregion
  641. }
  642. }