ListView.cs 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299
  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 Novell, Inc. (http://www.novell.com)
  21. //
  22. // Author:
  23. // Ravindra ([email protected])
  24. //
  25. // TODO:
  26. // - Keys to be handled ENTER/PAGE UP/PAGE DOWN/HOME/END/ARROWS/CTRL/SHIFT
  27. // - Item text editing
  28. // - Column resizing/reodering
  29. // - Feedback for item activation, change in cursor types as mouse moves.
  30. // - HideSelection
  31. // NOT COMPLETE
  32. using System.Collections;
  33. using System.ComponentModel;
  34. using System.ComponentModel.Design;
  35. using System.Drawing;
  36. using System.Runtime.InteropServices;
  37. namespace System.Windows.Forms
  38. {
  39. [DefaultEvent ("SelectedIndexChanged")]
  40. [DefaultProperty ("Items")]
  41. [Designer ("System.Windows.Forms.Design.ListViewDesigner, " + Consts.AssemblySystem_Design,
  42. typeof (IDesigner))]
  43. public class ListView : Control
  44. {
  45. private ItemActivation activation = ItemActivation.Standard;
  46. private ListViewAlignment alignment = ListViewAlignment.Top;
  47. private bool allow_column_reorder = false;
  48. private bool auto_arrange = true;
  49. private BorderStyle border_style = BorderStyle.Fixed3D;
  50. private bool check_boxes = false;
  51. private CheckedIndexCollection checked_indices;
  52. private CheckedListViewItemCollection checked_items;
  53. private ColumnHeader clicked_column;
  54. private ListViewItem clicked_item;
  55. private ListViewItem last_clicked_item;
  56. private ColumnHeaderCollection columns;
  57. private bool ctrl_pressed;
  58. private bool shift_pressed;
  59. private bool draw_headers = true; // Used for painting. Do we need to draw column headers ?
  60. private ListViewItem focused_item;
  61. private bool full_row_select = false;
  62. private bool grid_lines = false;
  63. private ColumnHeaderStyle header_style = ColumnHeaderStyle.Clickable;
  64. private bool hide_selection = true;
  65. private bool hover_selection = false;
  66. private IComparer item_sorter;
  67. private ListViewItemCollection items;
  68. private bool label_edit = false;
  69. private bool label_wrap = true;
  70. private bool multiselect = true;
  71. private bool redraw = true;
  72. private bool scrollable = true;
  73. private SelectedIndexCollection selected_indices;
  74. private SelectedListViewItemCollection selected_items;
  75. private SortOrder sort_order = SortOrder.None;
  76. private ImageList state_image_list;
  77. private bool updating = false;
  78. private View view = View.LargeIcon;
  79. private int layout_wd; // We might draw more than our client area
  80. private int layout_ht; // therefore we need to have these two.
  81. //private TextBox editor; // Used for editing an item text
  82. private ScrollBar h_scroll; // used for scrolling horizontally
  83. private ScrollBar v_scroll; // used for scrolling vertically
  84. private int h_marker; // Position markers for scrolling
  85. private int v_marker;
  86. // internal variables
  87. internal ImageList large_image_list;
  88. internal ImageList small_image_list;
  89. internal Size text_size = Size.Empty;
  90. #region Events
  91. public event LabelEditEventHandler AfterLabelEdit;
  92. [Browsable (false)]
  93. [EditorBrowsable (EditorBrowsableState.Never)]
  94. public new event EventHandler BackgroundImageChanged;
  95. public event LabelEditEventHandler BeforeLabelEdit;
  96. public event ColumnClickEventHandler ColumnClick;
  97. public event EventHandler ItemActivate;
  98. public event ItemCheckEventHandler ItemCheck;
  99. public event ItemDragEventHandler ItemDrag;
  100. [Browsable (false)]
  101. [EditorBrowsable (EditorBrowsableState.Never)]
  102. public new event PaintEventHandler Paint;
  103. public event EventHandler SelectedIndexChanged;
  104. [Browsable (false)]
  105. [EditorBrowsable (EditorBrowsableState.Never)]
  106. public new event EventHandler TextChanged;
  107. #endregion // Events
  108. #region Public Constructors
  109. public ListView ()
  110. {
  111. background_color = ThemeEngine.Current.ColorWindow;
  112. checked_indices = new CheckedIndexCollection (this);
  113. checked_items = new CheckedListViewItemCollection (this);
  114. columns = new ColumnHeaderCollection (this);
  115. foreground_color = SystemColors.WindowText;
  116. items = new ListViewItemCollection (this);
  117. selected_indices = new SelectedIndexCollection (this);
  118. selected_items = new SelectedListViewItemCollection (this);
  119. // we are mostly scrollable
  120. h_scroll = new HScrollBar ();
  121. v_scroll = new VScrollBar ();
  122. h_marker = v_marker = 0;
  123. // scroll bars are disabled initially
  124. h_scroll.Visible = false;
  125. h_scroll.ValueChanged += new EventHandler(HorizontalScroller);
  126. v_scroll.Visible = false;
  127. v_scroll.ValueChanged += new EventHandler(VerticalScroller);
  128. // event handlers
  129. base.DoubleClick += new EventHandler(ListView_DoubleClick);
  130. base.KeyDown += new KeyEventHandler(ListView_KeyDown);
  131. base.KeyUp += new KeyEventHandler(ListView_KeyUp);
  132. base.MouseDown += new MouseEventHandler(ListView_MouseDown);
  133. base.MouseHover += new EventHandler(ListView_MouseHover);
  134. base.MouseUp += new MouseEventHandler(ListView_MouseUp);
  135. base.MouseMove += new MouseEventHandler(ListView_MouseMove);
  136. base.Paint += new PaintEventHandler (ListView_Paint);
  137. }
  138. #endregion // Public Constructors
  139. #region Private Internal Properties
  140. internal Size CheckBoxSize {
  141. get {
  142. if (this.check_boxes) {
  143. if (this.state_image_list != null)
  144. return this.state_image_list.ImageSize;
  145. else
  146. return ThemeEngine.Current.ListViewCheckBoxSize;
  147. }
  148. return Size.Empty;
  149. }
  150. }
  151. internal bool CanMultiselect {
  152. get {
  153. if (this.multiselect &&
  154. (this.ctrl_pressed || this.shift_pressed))
  155. return true;
  156. else
  157. return false;
  158. }
  159. }
  160. #endregion // Private Internal Properties
  161. #region Protected Properties
  162. protected override CreateParams CreateParams {
  163. get { return base.CreateParams; }
  164. }
  165. protected override Size DefaultSize {
  166. get { return ThemeEngine.Current.ListViewDefaultSize; }
  167. }
  168. #endregion // Protected Properties
  169. #region Public Instance Properties
  170. [DefaultValue (ItemActivation.Standard)]
  171. public ItemActivation Activation {
  172. get { return activation; }
  173. set { activation = value; }
  174. }
  175. [DefaultValue (ListViewAlignment.Top)]
  176. [Localizable (true)]
  177. public ListViewAlignment Alignment {
  178. get { return alignment; }
  179. set {
  180. if (this.alignment != value) {
  181. alignment = value;
  182. // alignment does not matter in Details/List views
  183. if (this.view == View.LargeIcon ||
  184. this.View == View.SmallIcon)
  185. this.Redraw (true);
  186. }
  187. }
  188. }
  189. [DefaultValue (false)]
  190. public bool AllowColumnReorder {
  191. get { return allow_column_reorder; }
  192. set {
  193. if (this.allow_column_reorder != value) {
  194. allow_column_reorder = value;
  195. // column reorder does not matter in Details view
  196. if (this.view != View.Details)
  197. this.Redraw (true);
  198. }
  199. }
  200. }
  201. [DefaultValue (true)]
  202. public bool AutoArrange {
  203. get { return auto_arrange; }
  204. set {
  205. if (auto_arrange != value) {
  206. auto_arrange = value;
  207. // autoarrange does not matter in Details/List views
  208. if (this.view == View.LargeIcon || this.View == View.SmallIcon)
  209. this.Redraw (true);
  210. }
  211. }
  212. }
  213. public override Color BackColor {
  214. get {
  215. if (background_color.IsEmpty)
  216. return ThemeEngine.Current.ColorWindow;
  217. else
  218. return background_color;
  219. }
  220. set { background_color = value; }
  221. }
  222. [Browsable (false)]
  223. [EditorBrowsable (EditorBrowsableState.Never)]
  224. public override Image BackgroundImage {
  225. get { return background_image; }
  226. set {
  227. if (value == background_image)
  228. return;
  229. background_image = value;
  230. if (BackgroundImageChanged != null)
  231. BackgroundImageChanged (this, new EventArgs ());
  232. }
  233. }
  234. [DefaultValue (BorderStyle.Fixed3D)]
  235. [DispId (-504)]
  236. public BorderStyle BorderStyle {
  237. get { return border_style; }
  238. set {
  239. if (border_style != value) {
  240. border_style = value;
  241. this.Redraw (false);
  242. }
  243. }
  244. }
  245. [DefaultValue (false)]
  246. public bool CheckBoxes {
  247. get { return check_boxes; }
  248. set {
  249. if (check_boxes != value) {
  250. check_boxes = value;
  251. this.Redraw (true);
  252. }
  253. }
  254. }
  255. [Browsable (false)]
  256. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  257. public CheckedIndexCollection CheckedIndices {
  258. get { return checked_indices; }
  259. }
  260. [Browsable (false)]
  261. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  262. public CheckedListViewItemCollection CheckedItems {
  263. get { return checked_items; }
  264. }
  265. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
  266. [Localizable (true)]
  267. [MergableProperty (false)]
  268. public ColumnHeaderCollection Columns {
  269. get { return columns; }
  270. }
  271. [Browsable (false)]
  272. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  273. public ListViewItem FocusedItem {
  274. get { return focused_item; }
  275. }
  276. public override Color ForeColor {
  277. get {
  278. if (foreground_color.IsEmpty)
  279. return ThemeEngine.Current.ColorWindowText;
  280. else
  281. return foreground_color;
  282. }
  283. set { foreground_color = value; }
  284. }
  285. [DefaultValue (false)]
  286. public bool FullRowSelect {
  287. get { return full_row_select; }
  288. set { full_row_select = value; }
  289. }
  290. [DefaultValue (false)]
  291. public bool GridLines {
  292. get { return grid_lines; }
  293. set {
  294. if (grid_lines != value) {
  295. grid_lines = value;
  296. this.Redraw (false);
  297. }
  298. }
  299. }
  300. [DefaultValue (ColumnHeaderStyle.Clickable)]
  301. public ColumnHeaderStyle HeaderStyle {
  302. get { return header_style; }
  303. set {
  304. if (header_style != value) {
  305. header_style = value;
  306. // header style matters only in Details view
  307. if (this.view == View.Details)
  308. this.Redraw (false);
  309. }
  310. }
  311. }
  312. [DefaultValue (true)]
  313. public bool HideSelection {
  314. get { return hide_selection; }
  315. set {
  316. if (hide_selection != value) {
  317. hide_selection = value;
  318. this.Redraw (false);
  319. }
  320. }
  321. }
  322. [DefaultValue (false)]
  323. public bool HoverSelection {
  324. get { return hover_selection; }
  325. set { hover_selection = value; }
  326. }
  327. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
  328. [Localizable (true)]
  329. [MergableProperty (false)]
  330. public ListViewItemCollection Items {
  331. get { return items; }
  332. }
  333. [DefaultValue (false)]
  334. public bool LabelEdit {
  335. get { return label_edit; }
  336. set { label_edit = value; }
  337. }
  338. [DefaultValue (false)]
  339. [Localizable (true)]
  340. public bool LabelWrap {
  341. get { return label_wrap; }
  342. set {
  343. if (label_wrap != value) {
  344. label_wrap = value;
  345. this.Redraw (true);
  346. }
  347. }
  348. }
  349. [DefaultValue (null)]
  350. public ImageList LargeImageList {
  351. get { return large_image_list; }
  352. set {
  353. large_image_list = value;
  354. this.Redraw (true);
  355. }
  356. }
  357. [Browsable (false)]
  358. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  359. public IComparer ListViewItemSorter {
  360. get { return item_sorter; }
  361. set { item_sorter = value; }
  362. }
  363. [DefaultValue (true)]
  364. public bool MultiSelect {
  365. get { return multiselect; }
  366. set { multiselect = value; }
  367. }
  368. [DefaultValue (true)]
  369. public bool Scrollable {
  370. get { return scrollable; }
  371. set {
  372. if (scrollable != value) {
  373. scrollable = value;
  374. this.Redraw (true);
  375. }
  376. }
  377. }
  378. [Browsable (false)]
  379. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  380. public SelectedIndexCollection SelectedIndices {
  381. get { return selected_indices; }
  382. }
  383. [Browsable (false)]
  384. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  385. public SelectedListViewItemCollection SelectedItems {
  386. get { return selected_items; }
  387. }
  388. [DefaultValue (null)]
  389. public ImageList SmallImageList {
  390. get { return small_image_list; }
  391. set {
  392. small_image_list = value;
  393. this.Redraw (true);
  394. }
  395. }
  396. [DefaultValue (SortOrder.None)]
  397. public SortOrder Sorting {
  398. get { return sort_order; }
  399. set { sort_order = value; }
  400. }
  401. [DefaultValue (null)]
  402. public ImageList StateImageList {
  403. get { return state_image_list; }
  404. set {
  405. state_image_list = value;
  406. this.Redraw (true);
  407. }
  408. }
  409. [Bindable (false)]
  410. [Browsable (false)]
  411. [EditorBrowsable (EditorBrowsableState.Never)]
  412. public override string Text {
  413. get { return text; }
  414. set {
  415. if (value == text)
  416. return;
  417. text = value;
  418. this.Redraw (true);
  419. if (TextChanged != null)
  420. TextChanged (this, new EventArgs ());
  421. }
  422. }
  423. [Browsable (false)]
  424. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  425. public ListViewItem TopItem {
  426. get {
  427. // there is no item
  428. if (this.items.Count == 0)
  429. return null;
  430. // if contents are not scrolled
  431. // it is the first item
  432. else if (h_marker == 0 && v_marker == 0)
  433. return this.items [0];
  434. // do a hit test for the scrolled position
  435. else {
  436. foreach (ListViewItem item in this.items) {
  437. if (item.EntireRect.Contains (h_marker, v_marker))
  438. return item;
  439. }
  440. return null;
  441. }
  442. }
  443. }
  444. [DefaultValue (View.LargeIcon)]
  445. public View View {
  446. get { return view; }
  447. set { view = value; }
  448. }
  449. #endregion // Public Instance Properties
  450. #region Internal Methods Properties
  451. internal int TotalWidth {
  452. get { return Math.Max (this.Width, this.layout_wd); }
  453. }
  454. internal int TotalHeight {
  455. get { return Math.Max (this.Height, this.layout_ht); }
  456. }
  457. internal void Redraw (bool recalculate)
  458. {
  459. // Avoid calculations when control is being updated
  460. if (this.updating)
  461. return;
  462. if (recalculate)
  463. CalculateListView (this.alignment);
  464. redraw = true;
  465. Refresh ();
  466. }
  467. internal Size GetChildColumnSize (int index)
  468. {
  469. Size ret_size = Size.Empty;
  470. ColumnHeader col = this.columns [index];
  471. if (col.Width == -2) { // autosize = max(items, columnheader)
  472. Size size = Size.Ceiling (this.DeviceContext.MeasureString
  473. (col.Text, this.Font));
  474. ret_size = BiggestItem (index);
  475. if (size.Width > ret_size.Width)
  476. ret_size = size;
  477. }
  478. else { // -1 and all the values < -2 are put under one category
  479. ret_size = BiggestItem (index);
  480. // fall back to empty columns' width if no subitem is available for a column
  481. if (ret_size.IsEmpty) {
  482. ret_size.Width = ThemeEngine.Current.ListViewEmptyColumnWidth;
  483. if (col.Text.Length > 0)
  484. ret_size.Height = Size.Ceiling (this.DeviceContext.MeasureString
  485. (col.Text, this.Font)).Height;
  486. else
  487. ret_size.Height = this.Font.Height;
  488. }
  489. }
  490. // adjust the size for icon and checkbox for 0th column
  491. if (index == 0) {
  492. ret_size.Width += (this.CheckBoxSize.Width + 4);
  493. if (this.small_image_list != null)
  494. ret_size.Width += this.small_image_list.ImageSize.Width;
  495. }
  496. return ret_size;
  497. }
  498. // Returns the size of biggest item text in a column.
  499. private Size BiggestItem (int col)
  500. {
  501. Size temp = Size.Empty;
  502. Size ret_size = Size.Empty;
  503. // 0th column holds the item text, we check the size of
  504. // the various subitems falling in that column and get
  505. // the biggest one's size.
  506. foreach (ListViewItem item in items) {
  507. if (col >= item.SubItems.Count)
  508. continue;
  509. temp = Size.Ceiling (this.DeviceContext.MeasureString
  510. (item.SubItems [col].Text, this.Font));
  511. if (temp.Width > ret_size.Width)
  512. ret_size = temp;
  513. }
  514. // adjustment for space
  515. if (!ret_size.IsEmpty)
  516. ret_size.Width += 4;
  517. return ret_size;
  518. }
  519. // Sets the size of the biggest item text as per the view
  520. private void CalcTextSize ()
  521. {
  522. // clear the old value
  523. text_size = Size.Empty;
  524. if (items.Count == 0)
  525. return;
  526. text_size = BiggestItem (0);
  527. if (view == View.LargeIcon && this.label_wrap) {
  528. Size temp = Size.Empty;
  529. if (this.check_boxes)
  530. temp.Width += 2 * this.CheckBoxSize.Width;
  531. if (large_image_list != null)
  532. temp.Width += large_image_list.ImageSize.Width;
  533. if (temp.Width == 0)
  534. temp.Width = 43;
  535. // wrapping is done for two lines only
  536. if (text_size.Width > temp.Width) {
  537. text_size.Width = temp.Width;
  538. text_size.Height *= 2;
  539. }
  540. }
  541. else if (view == View.List) {
  542. // in list view max text shown in determined by the
  543. // control width, even if scolling is enabled.
  544. int max_wd = this.Width - (this.CheckBoxSize.Width - 2);
  545. if (this.small_image_list != null)
  546. max_wd -= this.small_image_list.ImageSize.Width;
  547. if (text_size.Width > max_wd)
  548. text_size.Width = max_wd;
  549. }
  550. // we do the default settings, if we have got 0's
  551. if (text_size.Height <= 0)
  552. text_size.Height = this.Font.Height;
  553. if (text_size.Width <= 0)
  554. text_size.Width = this.Width;
  555. // little adjustment
  556. text_size.Width += 4;
  557. text_size.Height += 2;
  558. }
  559. // Sets the location of every item on
  560. // the ListView as per the view
  561. private void CalculateListView (ListViewAlignment align)
  562. {
  563. int current_pos_x = 0; // our x-position marker
  564. int current_pos_y = 0; // our y-position marker
  565. int item_ht;
  566. int item_wd;
  567. int max; // max x_pos or y_pos depending on the alignment
  568. int current = 0; // current row or column
  569. int vertical_spacing = ThemeEngine.Current.ListViewVerticalSpacing;
  570. int horizontal_spacing = ThemeEngine.Current.ListViewHorizontalSpacing;
  571. CalcTextSize ();
  572. switch (view) {
  573. case View.Details:
  574. // ColumnHeaders are not drawn if headerstyle is none
  575. int ht = (this.header_style == ColumnHeaderStyle.None) ?
  576. 2 : this.Font.Height + 2;
  577. if (columns.Count > 0) {
  578. foreach (ColumnHeader col in columns) {
  579. col.X = current_pos_x;
  580. col.Y = 0;
  581. col.CalcColumnHeader ();
  582. current_pos_x += col.Wd;
  583. }
  584. this.layout_wd = current_pos_x;
  585. }
  586. // set the position marker for placing items
  587. // vertically down
  588. current_pos_y = ht;
  589. if (items.Count > 0) {
  590. foreach (ListViewItem item in items) {
  591. item.location.X = 0;
  592. item.location.Y = current_pos_y;
  593. item.CalcListViewItem ();
  594. current_pos_y += item.EntireRect.Height;
  595. }
  596. this.layout_ht = current_pos_y;
  597. // some space for bottom gridline
  598. if (this.grid_lines)
  599. this.layout_ht += 2;
  600. }
  601. break;
  602. case View.SmallIcon:
  603. vertical_spacing = 0;
  604. horizontal_spacing = 0;
  605. goto case View.LargeIcon;
  606. case View.LargeIcon:
  607. if (items.Count > 0) {
  608. items [0].CalcListViewItem ();
  609. item_ht = items [0].EntireRect.Height;
  610. item_wd = items [0].EntireRect.Width;
  611. // top (default) and snaptogrid alignments are handled same way
  612. if (align == ListViewAlignment.Left) {
  613. max = this.Height;
  614. foreach (ListViewItem item in items) {
  615. item.location.X = current_pos_x +
  616. horizontal_spacing;
  617. item.location.Y = current_pos_y;
  618. item.CalcListViewItem ();
  619. current_pos_y += item_ht;
  620. current ++; // just to know about the last element
  621. // we just did the last item
  622. if (current == items.Count) {
  623. if (max < current_pos_y)
  624. max = current_pos_y;
  625. current_pos_x = item.EntireRect.Right;
  626. break;
  627. }
  628. else {
  629. // is there enough space for another row ?
  630. if ((current_pos_y + vertical_spacing
  631. + item_ht) <= this.Height)
  632. current_pos_y += vertical_spacing;
  633. else {
  634. // start another column
  635. // make current_pos_y as the
  636. // max value and reset
  637. // current_pos_y value.
  638. max = current_pos_y;
  639. current_pos_x += item_wd;
  640. current_pos_y = 0;
  641. }
  642. }
  643. }
  644. // adjust the layout dimensions
  645. this.layout_ht = max;
  646. this.layout_wd = current_pos_x;
  647. }
  648. else { // other default/top alignment
  649. max = this.Width;
  650. foreach (ListViewItem item in items) {
  651. item.location.X = current_pos_x +
  652. horizontal_spacing;
  653. item.location.Y = current_pos_y;
  654. item.CalcListViewItem ();
  655. current_pos_x += item_wd;
  656. current ++; // just to know about the last element
  657. // we just did the last item
  658. if (current == items.Count) {
  659. if (max < current_pos_x)
  660. max = current_pos_x;
  661. current_pos_y = item.EntireRect.Bottom;
  662. break;
  663. }
  664. else {
  665. // is there enough space for another column?
  666. if ((current_pos_x + horizontal_spacing
  667. + item_wd) <= this.Width)
  668. continue;
  669. else {
  670. // start another row
  671. // make current_pos_x as the
  672. // max value and reset
  673. // current_pos_x value.
  674. max = current_pos_x;
  675. current_pos_y += (item_ht +
  676. vertical_spacing);
  677. current_pos_x = 0;
  678. }
  679. }
  680. }
  681. // adjust the layout dimensions
  682. this.layout_wd = max;
  683. this.layout_ht = current_pos_y;
  684. }
  685. }
  686. break;
  687. case View.List:
  688. if (items.Count > 0) {
  689. items [0].CalcListViewItem ();
  690. item_ht = items [0].EntireRect.Height;
  691. item_wd = items [0].EntireRect.Width;
  692. max = this.Height / item_ht;
  693. if (max == 0)
  694. max = 1; // we draw at least one row
  695. foreach (ListViewItem item in items) {
  696. item.location.X = current_pos_x;
  697. item.location.Y = current_pos_y;
  698. item.CalcListViewItem ();
  699. current ++;
  700. if (current == max) {
  701. current_pos_x += item_wd;
  702. current_pos_y = 0;
  703. current = 0;
  704. }
  705. else
  706. current_pos_y += item_ht;
  707. }
  708. // adjust the layout dimensions
  709. this.layout_ht = max * item_ht;
  710. if (current == 0) // we have fully filled layout
  711. this.layout_wd = current_pos_x;
  712. else
  713. this.layout_wd = current_pos_x + item_wd;
  714. }
  715. break;
  716. }
  717. if (this.scrollable && this.items.Count > 0) {
  718. // making a scroll bar visible might make
  719. // other scroll bar visible
  720. if (this.layout_wd > this.Width) {
  721. this.h_scroll.Visible = true;
  722. if ((this.layout_ht + this.h_scroll.Height) > this.Height)
  723. this.v_scroll.Visible = true;
  724. }
  725. else if (this.layout_ht > this.Height) {
  726. this.v_scroll.Visible = true;
  727. if ((this.layout_wd + this.v_scroll.Width) > this.Width)
  728. this.h_scroll.Visible = true;
  729. }
  730. // create big enough buffers
  731. if (this.layout_wd > this.Width ||
  732. this.layout_ht > this.Height)
  733. this.CreateBuffers (this.TotalWidth, this.TotalHeight);
  734. if (this.h_scroll.Visible) {
  735. this.h_scroll.Location = new Point (0, this.Height
  736. - this.h_scroll.Height);
  737. this.h_scroll.Minimum = 0;
  738. // if v_scroll is visible, adjust the maximum of the
  739. // h_scroll to account for the width of v_scroll
  740. if (this.v_scroll.Visible) {
  741. this.h_scroll.Maximum = this.layout_wd + this.v_scroll.Width;
  742. this.h_scroll.Width = this.Width - this.v_scroll.Width;
  743. }
  744. else {
  745. this.h_scroll.Maximum = this.layout_wd;
  746. this.h_scroll.Width = this.Width;
  747. }
  748. this.h_scroll.LargeChange = this.Width;
  749. this.h_scroll.SmallChange = this.Font.Height;
  750. }
  751. // vertical scrollbar
  752. if (this.v_scroll.Visible) {
  753. this.v_scroll.Location = new Point (this.Width
  754. - this.v_scroll.Width, 0);
  755. this.v_scroll.Minimum = 0;
  756. // if h_scroll is visible, adjust the maximum of the
  757. // v_scroll to account for the height of h_scroll
  758. if (this.h_scroll.Visible) {
  759. this.v_scroll.Maximum = this.layout_ht + this.h_scroll.Height;
  760. this.v_scroll.Height = this.Height - this.h_scroll.Height;
  761. }
  762. else {
  763. this.v_scroll.Maximum = this.layout_ht;
  764. this.v_scroll.Height = this.Height;
  765. }
  766. this.v_scroll.LargeChange = this.Height;
  767. this.v_scroll.SmallChange = this.Font.Height;
  768. }
  769. }
  770. else {
  771. this.h_scroll.Visible = false;
  772. this.v_scroll.Visible = false;
  773. }
  774. }
  775. // Event Handlers
  776. private void ListView_DoubleClick (object sender, EventArgs e)
  777. {
  778. if (this.activation == ItemActivation.Standard
  779. && this.ItemActivate != null)
  780. this.ItemActivate (this, e);
  781. }
  782. private void ListView_KeyDown (object sender, KeyEventArgs ke)
  783. {
  784. int index = -1;
  785. if (ke.Handled)
  786. return;
  787. ke.Handled = true;
  788. switch (ke.KeyCode) {
  789. case Keys.ControlKey:
  790. this.ctrl_pressed = true;
  791. break;
  792. case Keys.Down:
  793. // FIXME:TODO
  794. break;
  795. case Keys.End:
  796. this.v_scroll.Value = this.v_scroll.Maximum;
  797. break;
  798. case Keys.Home:
  799. this.v_scroll.Value = this.v_scroll.Minimum;
  800. break;
  801. case Keys.Left:
  802. index = -1;
  803. if (this.last_clicked_item != null)
  804. index = this.last_clicked_item.Index;
  805. else
  806. break;
  807. if (index > 0)
  808. index -= 1;
  809. this.last_clicked_item = this.items [index];
  810. this.last_clicked_item.Selected = true;
  811. this.EnsureVisible (index);
  812. break;
  813. case Keys.Right:
  814. if (this.last_clicked_item != null)
  815. index = this.last_clicked_item.Index + 1;
  816. else
  817. index = 1;
  818. if (index == this.items.Count)
  819. break;
  820. this.last_clicked_item = this.items [index];
  821. this.last_clicked_item.Selected = true;
  822. this.EnsureVisible (index);
  823. break;
  824. case Keys.ShiftKey:
  825. this.shift_pressed = true;
  826. break;
  827. case Keys.Up:
  828. // FIXME:TODO
  829. break;
  830. default:
  831. ke.Handled = false;
  832. break;
  833. }
  834. }
  835. private void ListView_KeyUp (object sender, KeyEventArgs ke)
  836. {
  837. if (!ke.Handled) {
  838. if (ke.KeyCode == Keys.ControlKey)
  839. this.ctrl_pressed = false;
  840. if (ke.KeyCode == Keys.ShiftKey)
  841. this.shift_pressed = false;
  842. ke.Handled = true;
  843. }
  844. }
  845. private void ListView_MouseDown (object sender, MouseEventArgs me)
  846. {
  847. if (items.Count == 0)
  848. return;
  849. Point hit = Point.Empty;
  850. if (this.HeaderStyle != ColumnHeaderStyle.None) {
  851. // take horizontal scrolling into account
  852. hit = new Point (me.X + h_marker, me.Y);
  853. // hit test on columns
  854. if (this.view == View.Details && this.columns.Count > 0) {
  855. foreach (ColumnHeader col in this.columns) {
  856. if (col.Rect.Contains (hit)) {
  857. this.clicked_column = col;
  858. this.Capture = true;
  859. break;
  860. }
  861. }
  862. if (this.clicked_column != null) {
  863. this.clicked_column.pressed = true;
  864. this.draw_headers = true;
  865. this.Redraw (false);
  866. return;
  867. }
  868. }
  869. }
  870. // hit test on items
  871. // we need to take scrolling into account
  872. hit = new Point (me.X + h_marker, me.Y + v_marker);
  873. foreach (ListViewItem item in this.items) {
  874. if (item.CheckRect.Contains (hit)) {
  875. CheckState curr_state = item.Checked ?
  876. CheckState.Checked : CheckState.Unchecked;
  877. if (item.Checked)
  878. item.Checked = false;
  879. else
  880. item.Checked = true;
  881. CheckState new_state = item.Checked ?
  882. CheckState.Checked : CheckState.Unchecked;
  883. this.Redraw (false);
  884. // Raise the ItemCheck event
  885. ItemCheckEventArgs ice = new ItemCheckEventArgs (item.Index,
  886. curr_state,
  887. new_state);
  888. this.OnItemCheck (ice);
  889. break;
  890. }
  891. if (this.view == View.Details &&
  892. this.FullRowSelect == false) {
  893. if (item.LabelRect.Contains (hit)) {
  894. this.clicked_item = item;
  895. break;
  896. }
  897. }
  898. else {
  899. if (item.EntireRect.Contains (hit)) {
  900. this.clicked_item = item;
  901. break;
  902. }
  903. }
  904. }
  905. if (this.clicked_item != null) {
  906. this.clicked_item.Selected = true;
  907. // Raise the event
  908. this.OnSelectedIndexChanged (new EventArgs ());
  909. this.Redraw (false);
  910. }
  911. // set the FocusedItem to be the current clicked_item
  912. this.focused_item = this.clicked_item;
  913. }
  914. private void ListView_MouseHover (object sender, EventArgs e)
  915. {
  916. // handle the hover events only when the mouse
  917. // is not captured.
  918. if (this.hover_selection == false || this.Capture)
  919. return;
  920. // hit test for the items
  921. Point hit = this.PointToClient (Control.MousePosition);
  922. ListViewItem item = this.GetItemAt (hit.X, hit.Y);
  923. if (item != null) {
  924. item.Selected = true;
  925. // Raise the event
  926. this.OnSelectedIndexChanged (new EventArgs ());
  927. this.Redraw (false);
  928. }
  929. }
  930. private void ListView_MouseMove (object sender, MouseEventArgs me)
  931. {
  932. // Column header is always at the top. It can
  933. // scroll only horizontally. So, we have to take
  934. // only horizontal scrolling into account
  935. Point hit = new Point (me.X + h_marker, me.Y);
  936. // non-null clicked_col means mouse down has happened
  937. // on a column
  938. if (this.clicked_column != null) {
  939. if (this.clicked_column.pressed == false &&
  940. this.clicked_column.Rect.Contains (hit)) {
  941. this.clicked_column.pressed = true;
  942. this.draw_headers = true;
  943. this.Redraw (false);
  944. }
  945. else if (this.clicked_column.pressed &&
  946. ! this.clicked_column.Rect.Contains (hit)) {
  947. this.clicked_column.pressed = false;
  948. this.draw_headers = true;
  949. this.Redraw (false);
  950. }
  951. }
  952. }
  953. private void ListView_MouseUp (object sender, MouseEventArgs me)
  954. {
  955. this.Capture = false;
  956. if (items.Count == 0)
  957. return;
  958. Point hit = new Point (me.X, me.Y);
  959. if (this.clicked_column != null) {
  960. if (this.clicked_column.pressed) {
  961. this.clicked_column.pressed = false;
  962. this.draw_headers = true;
  963. this.Redraw (false);
  964. // Raise the ColumnClick event
  965. this.OnColumnClick (new ColumnClickEventArgs
  966. (this.clicked_column.Index));
  967. }
  968. }
  969. // Raise the ItemActivate event
  970. Rectangle rect = Rectangle.Empty;
  971. if (this.clicked_item != null) {
  972. if (this.view == View.Details && !this.full_row_select)
  973. rect = this.clicked_item.LabelRect;
  974. else
  975. rect = this.clicked_item.EntireRect;
  976. // We handle double click in a separate handler
  977. if (this.activation != ItemActivation.Standard &&
  978. rect.Contains (hit)) {
  979. if (this.activation == ItemActivation.OneClick)
  980. this.ItemActivate (this, EventArgs.Empty);
  981. // ItemActivate is raised on the second click on the same item
  982. else if (this.activation == ItemActivation.TwoClick) {
  983. if (this.last_clicked_item == this.clicked_item) {
  984. this.ItemActivate (this, EventArgs.Empty);
  985. this.last_clicked_item = null;
  986. }
  987. else
  988. this.last_clicked_item = this.clicked_item;
  989. }
  990. }
  991. }
  992. this.clicked_column = null;
  993. this.clicked_item = null;
  994. }
  995. private void ListView_Paint (object sender, PaintEventArgs pe)
  996. {
  997. if (this.Width <= 0 || this.Height <= 0 ||
  998. this.Visible == false || this.updating == true)
  999. return;
  1000. if (redraw) {
  1001. ThemeEngine.Current.DrawListView (this.DeviceContext,
  1002. pe.ClipRectangle, this);
  1003. redraw = false;
  1004. }
  1005. // We paint on the screen as per the location set
  1006. // by the two scrollbars. In case of details view
  1007. // since column headers can scroll only horizontally
  1008. // and items can scroll in both directions, paiting is
  1009. // done separtely for the column header and the items.
  1010. Rectangle srcRect = this.ClientRectangle;
  1011. Rectangle dstRect = this.ClientRectangle;
  1012. // set the visible starting point
  1013. if (scrollable) {
  1014. srcRect.X += h_marker;
  1015. srcRect.Y += v_marker;
  1016. if (h_scroll.Visible) {
  1017. srcRect.Height -= h_scroll.Height;
  1018. dstRect.Height -= h_scroll.Height;
  1019. }
  1020. if (v_scroll.Visible) {
  1021. srcRect.Width -= v_scroll.Width;
  1022. dstRect.Width -= v_scroll.Width;
  1023. }
  1024. }
  1025. // We paint the column headers always at the top, in case
  1026. // of vertical scrolling. Therefore, we advance the painting
  1027. // by the amount equal to the column height.
  1028. if (this.view == View.Details &&
  1029. this.Columns.Count > 0 &&
  1030. this.header_style != ColumnHeaderStyle.None &&
  1031. v_marker > 0) {
  1032. int col_ht = this.Columns [0].Ht;
  1033. if (this.draw_headers) {
  1034. this.draw_headers = false;
  1035. // Move the source rect by the amount of horizontal
  1036. // scrolling done so far.
  1037. Rectangle headerSrc = new Rectangle (h_marker, 0,
  1038. srcRect.Width, col_ht);
  1039. // dest rect is always stable at 0,0
  1040. Rectangle headerDst = new Rectangle (0, 0, srcRect.Width, col_ht);
  1041. pe.Graphics.DrawImage (this.ImageBuffer, headerDst,
  1042. headerSrc, GraphicsUnit.Pixel);
  1043. }
  1044. dstRect.Y += col_ht;
  1045. srcRect.Y += col_ht;
  1046. }
  1047. // Paint the items
  1048. pe.Graphics.DrawImage (this.ImageBuffer, dstRect,
  1049. srcRect, GraphicsUnit.Pixel);
  1050. // Draw the border of the list view
  1051. // The border is painted here separately, because
  1052. // our imagebuffer might be scrollable
  1053. ThemeEngine.Current.CPDrawBorderStyle (pe.Graphics,
  1054. this.ClientRectangle,
  1055. this.BorderStyle);
  1056. // Raise the Paint event
  1057. if (Paint != null)
  1058. Paint (this, pe);
  1059. }
  1060. private void HorizontalScroller (object sender, EventArgs e)
  1061. {
  1062. // Avoid unnecessary flickering, when button is
  1063. // kept pressed at the end
  1064. if (h_marker != h_scroll.Value) {
  1065. h_marker = h_scroll.Value;
  1066. // draw the headers again
  1067. this.draw_headers = true;
  1068. this.Refresh ();
  1069. }
  1070. }
  1071. private void VerticalScroller (object sender, EventArgs e)
  1072. {
  1073. // Avoid unnecessary flickering, when button is
  1074. // kept pressed at the end
  1075. if (v_marker != v_scroll.Value) {
  1076. v_marker = v_scroll.Value;
  1077. this.Refresh ();
  1078. }
  1079. }
  1080. #endregion // Internal Methods Properties
  1081. #region Protected Methods
  1082. protected override void CreateHandle ()
  1083. {
  1084. base.CreateHandle ();
  1085. }
  1086. protected override void Dispose (bool disposing)
  1087. {
  1088. // FIXME: TODO
  1089. }
  1090. protected override bool IsInputKey (Keys keyData)
  1091. {
  1092. return base.IsInputKey (keyData);
  1093. }
  1094. protected virtual void OnAfterLabelEdit (LabelEditEventArgs e)
  1095. {
  1096. if (AfterLabelEdit != null)
  1097. AfterLabelEdit (this, e);
  1098. }
  1099. protected virtual void OnBeforeLabelEdit (LabelEditEventArgs e)
  1100. {
  1101. if (BeforeLabelEdit != null)
  1102. BeforeLabelEdit (this, e);
  1103. }
  1104. protected virtual void OnColumnClick (ColumnClickEventArgs e)
  1105. {
  1106. if (ColumnClick != null)
  1107. ColumnClick (this, e);
  1108. }
  1109. protected override void OnEnabledChanged (EventArgs e)
  1110. {
  1111. base.OnEnabledChanged (e);
  1112. }
  1113. protected override void OnFontChanged (EventArgs e)
  1114. {
  1115. base.OnFontChanged (e);
  1116. }
  1117. protected override void OnHandleCreated (EventArgs e)
  1118. {
  1119. base.OnHandleCreated (e);
  1120. this.Controls.Add (this.v_scroll);
  1121. this.Controls.Add (this.h_scroll);
  1122. this.SetStyle (ControlStyles.UserPaint |
  1123. ControlStyles.AllPaintingInWmPaint, true);
  1124. }
  1125. protected override void OnHandleDestroyed (EventArgs e)
  1126. {
  1127. base.OnHandleDestroyed (e);
  1128. }
  1129. protected virtual void OnItemActivate (EventArgs e)
  1130. {
  1131. if (ItemActivate != null)
  1132. ItemActivate (this, e);
  1133. }
  1134. protected virtual void OnItemCheck (ItemCheckEventArgs ice)
  1135. {
  1136. if (ItemCheck != null)
  1137. ItemCheck (this, ice);
  1138. }
  1139. protected virtual void OnItemDrag (ItemDragEventArgs e)
  1140. {
  1141. if (ItemDrag != null)
  1142. ItemDrag (this, e);
  1143. }
  1144. protected virtual void OnSelectedIndexChanged (EventArgs e)
  1145. {
  1146. if (SelectedIndexChanged != null)
  1147. SelectedIndexChanged (this, e);
  1148. }
  1149. protected override void OnSystemColorsChanged (EventArgs e)
  1150. {
  1151. base.OnSystemColorsChanged (e);
  1152. }
  1153. protected void RealizeProperties ()
  1154. {
  1155. // FIXME: TODO
  1156. }
  1157. protected void UpdateExtendedStyles ()
  1158. {
  1159. // FIXME: TODO
  1160. }
  1161. protected override void WndProc (ref Message m)
  1162. {
  1163. base.WndProc (ref m);
  1164. }
  1165. #endregion // Protected Methods
  1166. #region Public Instance Methods
  1167. public void ArrangeIcons ()
  1168. {
  1169. ArrangeIcons (this.alignment);
  1170. }
  1171. public void ArrangeIcons (ListViewAlignment alignment)
  1172. {
  1173. // Icons are arranged only if view is set to LargeIcon or SmallIcon
  1174. if (view == View.LargeIcon || view == View.SmallIcon) {
  1175. this.CalculateListView (alignment);
  1176. // we have done the calculations already
  1177. this.Redraw (false);
  1178. }
  1179. }
  1180. public void BeginUpdate ()
  1181. {
  1182. // flag to avoid painting
  1183. updating = true;
  1184. }
  1185. public void Clear ()
  1186. {
  1187. columns.Clear ();
  1188. items.Clear ();
  1189. this.Redraw (true);
  1190. }
  1191. public void EndUpdate ()
  1192. {
  1193. // flag to avoid painting
  1194. updating = false;
  1195. // probably, now we need a redraw with recalculations
  1196. this.Redraw (true);
  1197. }
  1198. public void EnsureVisible (int index)
  1199. {
  1200. if (index < 0 || index >= this.items.Count || this.scrollable == false)
  1201. return;
  1202. // dimensions of visible area
  1203. int view_wd = this.Width - (this.v_scroll.Visible ? this.v_scroll.Width : 0);
  1204. int view_ht = this.Height - (this.h_scroll.Visible ? this.h_scroll.Height : 0);
  1205. // visible area is decided by the h_marker and v_marker
  1206. Rectangle view_rect = new Rectangle (h_marker, v_marker, view_wd, view_ht);
  1207. // an item's bounding rect
  1208. Rectangle rect = this.items [index].EntireRect;
  1209. // we don't need to do anything if item is visible.
  1210. // visible area is represented by (0,0,view_wd,view_ht)
  1211. if (view_rect.Contains (rect))
  1212. return;
  1213. // Scroll Left or Up
  1214. if ((rect.Left < view_rect.Left) || (rect.Top < view_rect.Top)) {
  1215. if (rect.Left < view_rect.Left)
  1216. this.h_scroll.Value -= (view_rect.Left - rect.Left);
  1217. if (rect.Top < view_rect.Top)
  1218. this.v_scroll.Value -= (view_rect.Top - rect.Top);
  1219. }
  1220. // Scroll Right or Down
  1221. else {
  1222. if (rect.Right > view_rect.Right)
  1223. this.h_scroll.Value += (rect.Right - view_rect.Right);
  1224. if (rect.Bottom > view_rect.Bottom)
  1225. this.v_scroll.Value += (rect.Bottom - view_rect.Bottom);
  1226. }
  1227. }
  1228. public ListViewItem GetItemAt (int x, int y)
  1229. {
  1230. foreach (ListViewItem item in items) {
  1231. if (item.Bounds.Contains (x, y))
  1232. return item;
  1233. }
  1234. return null;
  1235. }
  1236. public Rectangle GetItemRect (int index)
  1237. {
  1238. return GetItemRect (index, ItemBoundsPortion.Entire);
  1239. }
  1240. public Rectangle GetItemRect (int index, ItemBoundsPortion portion)
  1241. {
  1242. if (index < 0 || index >= items.Count)
  1243. throw new IndexOutOfRangeException ("Invalid Index");
  1244. return items [index].GetBounds (portion);
  1245. }
  1246. public void Sort ()
  1247. {
  1248. if (sort_order != SortOrder.None)
  1249. items.list.Sort (item_sorter);
  1250. if (sort_order == SortOrder.Descending)
  1251. items.list.Reverse ();
  1252. this.Redraw (true);
  1253. }
  1254. public override string ToString ()
  1255. {
  1256. int count = this.Items.Count;
  1257. if (count == 0)
  1258. return string.Format ("System.Windows.Forms.ListView, Items.Count: 0");
  1259. else
  1260. return string.Format ("System.Windows.Forms.ListView, Items.Count: {0}, Items[0]: {1}", count, this.Items [0].ToString ());
  1261. }
  1262. #endregion // Public Instance Methods
  1263. #region Subclasses
  1264. public class CheckedIndexCollection : IList, ICollection, IEnumerable
  1265. {
  1266. internal ArrayList list;
  1267. private ListView owner;
  1268. #region Public Constructor
  1269. public CheckedIndexCollection (ListView owner)
  1270. {
  1271. list = new ArrayList ();
  1272. this.owner = owner;
  1273. }
  1274. #endregion // Public Constructor
  1275. #region Public Properties
  1276. [Browsable (false)]
  1277. public virtual int Count {
  1278. get { return list.Count; }
  1279. }
  1280. public virtual bool IsReadOnly {
  1281. get { return true; }
  1282. }
  1283. public int this [int index] {
  1284. get {
  1285. if (index < 0 || index >= list.Count)
  1286. throw new ArgumentOutOfRangeException ("Index out of range.");
  1287. return (int) list [index];
  1288. }
  1289. }
  1290. bool ICollection.IsSynchronized {
  1291. get { return list.IsSynchronized; }
  1292. }
  1293. object ICollection.SyncRoot {
  1294. get { return list.SyncRoot; }
  1295. }
  1296. bool IList.IsFixedSize {
  1297. get { return list.IsFixedSize; }
  1298. }
  1299. object IList.this [int index] {
  1300. get { return this [index]; }
  1301. set { throw new NotSupportedException ("SetItem operation is not supported."); }
  1302. }
  1303. #endregion // Public Properties
  1304. #region Public Methods
  1305. public bool Contains (int checkedIndex)
  1306. {
  1307. return list.Contains (checkedIndex);
  1308. }
  1309. public virtual IEnumerator GetEnumerator ()
  1310. {
  1311. return list.GetEnumerator ();
  1312. }
  1313. void ICollection.CopyTo (Array dest, int index)
  1314. {
  1315. list.CopyTo (dest, index);
  1316. }
  1317. int IList.Add (object value)
  1318. {
  1319. throw new NotSupportedException ("Add operation is not supported.");
  1320. }
  1321. void IList.Clear ()
  1322. {
  1323. throw new NotSupportedException ("Clear operation is not supported.");
  1324. }
  1325. bool IList.Contains (object checkedIndex)
  1326. {
  1327. return list.Contains (checkedIndex);
  1328. }
  1329. int IList.IndexOf (object checkedIndex)
  1330. {
  1331. return list.IndexOf (checkedIndex);
  1332. }
  1333. void IList.Insert (int index, object value)
  1334. {
  1335. throw new NotSupportedException ("Insert operation is not supported.");
  1336. }
  1337. void IList.Remove (object value)
  1338. {
  1339. throw new NotSupportedException ("Remove operation is not supported.");
  1340. }
  1341. void IList.RemoveAt (int index)
  1342. {
  1343. throw new NotSupportedException ("RemoveAt operation is not supported.");
  1344. }
  1345. public int IndexOf (int checkedIndex)
  1346. {
  1347. return list.IndexOf (checkedIndex);
  1348. }
  1349. #endregion // Public Methods
  1350. } // CheckedIndexCollection
  1351. public class CheckedListViewItemCollection : IList, ICollection, IEnumerable
  1352. {
  1353. internal ArrayList list;
  1354. private ListView owner;
  1355. #region Public Constructor
  1356. public CheckedListViewItemCollection (ListView owner)
  1357. {
  1358. list = new ArrayList ();
  1359. this.owner = owner;
  1360. }
  1361. #endregion // Public Constructor
  1362. #region Public Properties
  1363. [Browsable (false)]
  1364. public virtual int Count {
  1365. get { return list.Count; }
  1366. }
  1367. public virtual bool IsReadOnly {
  1368. get { return true; }
  1369. }
  1370. public ListViewItem this [int index] {
  1371. get {
  1372. if (index < 0 || index >= list.Count)
  1373. throw new ArgumentOutOfRangeException ("Index out of range.");
  1374. return (ListViewItem) list [index];
  1375. }
  1376. }
  1377. bool ICollection.IsSynchronized {
  1378. get { return list.IsSynchronized; }
  1379. }
  1380. object ICollection.SyncRoot {
  1381. get { return list.SyncRoot; }
  1382. }
  1383. bool IList.IsFixedSize {
  1384. get { return list.IsFixedSize; }
  1385. }
  1386. object IList.this [int index] {
  1387. get { return this [index]; }
  1388. set { throw new NotSupportedException ("SetItem operation is not supported."); }
  1389. }
  1390. #endregion // Public Properties
  1391. #region Public Methods
  1392. public bool Contains (ListViewItem item)
  1393. {
  1394. return list.Contains (item);
  1395. }
  1396. public virtual void CopyTo (Array dest, int index)
  1397. {
  1398. list.CopyTo (dest, index);
  1399. }
  1400. public virtual IEnumerator GetEnumerator ()
  1401. {
  1402. return list.GetEnumerator ();
  1403. }
  1404. int IList.Add (object value)
  1405. {
  1406. throw new NotSupportedException ("Add operation is not supported.");
  1407. }
  1408. void IList.Clear ()
  1409. {
  1410. throw new NotSupportedException ("Clear operation is not supported.");
  1411. }
  1412. bool IList.Contains (object item)
  1413. {
  1414. return list.Contains (item);
  1415. }
  1416. int IList.IndexOf (object item)
  1417. {
  1418. return list.IndexOf (item);
  1419. }
  1420. void IList.Insert (int index, object value)
  1421. {
  1422. throw new NotSupportedException ("Insert operation is not supported.");
  1423. }
  1424. void IList.Remove (object value)
  1425. {
  1426. throw new NotSupportedException ("Remove operation is not supported.");
  1427. }
  1428. void IList.RemoveAt (int index)
  1429. {
  1430. throw new NotSupportedException ("RemoveAt operation is not supported.");
  1431. }
  1432. public int IndexOf (ListViewItem item)
  1433. {
  1434. return list.IndexOf (item);
  1435. }
  1436. #endregion // Public Methods
  1437. } // CheckedListViewItemCollection
  1438. public class ColumnHeaderCollection : IList, ICollection, IEnumerable
  1439. {
  1440. internal ArrayList list;
  1441. private ListView owner;
  1442. #region Public Constructor
  1443. public ColumnHeaderCollection (ListView owner)
  1444. {
  1445. list = new ArrayList ();
  1446. this.owner = owner;
  1447. }
  1448. #endregion // Public Constructor
  1449. #region Public Properties
  1450. [Browsable (false)]
  1451. public virtual int Count {
  1452. get { return list.Count; }
  1453. }
  1454. public virtual bool IsReadOnly {
  1455. get { return false; }
  1456. }
  1457. public virtual ColumnHeader this [int index] {
  1458. get {
  1459. if (index < 0 || index >= list.Count)
  1460. throw new ArgumentOutOfRangeException ("Index out of range.");
  1461. return (ColumnHeader) list [index];
  1462. }
  1463. }
  1464. bool ICollection.IsSynchronized {
  1465. get { return list.IsSynchronized; }
  1466. }
  1467. object ICollection.SyncRoot {
  1468. get { return list.SyncRoot; }
  1469. }
  1470. bool IList.IsFixedSize {
  1471. get { return list.IsFixedSize; }
  1472. }
  1473. object IList.this [int index] {
  1474. get { return this [index]; }
  1475. set { throw new NotSupportedException ("SetItem operation is not supported."); }
  1476. }
  1477. #endregion // Public Properties
  1478. #region Public Methods
  1479. public virtual int Add (ColumnHeader value)
  1480. {
  1481. return list.Add (value);
  1482. }
  1483. public virtual ColumnHeader Add (string str, int width, HorizontalAlignment textAlign)
  1484. {
  1485. ColumnHeader colHeader = new ColumnHeader (this.owner, str, textAlign, width);
  1486. this.Add (colHeader);
  1487. return colHeader;
  1488. }
  1489. public virtual void AddRange (ColumnHeader [] values)
  1490. {
  1491. foreach (ColumnHeader colHeader in values)
  1492. this.Add (colHeader);
  1493. }
  1494. public virtual void Clear ()
  1495. {
  1496. list.Clear ();
  1497. }
  1498. public bool Contains (ColumnHeader value)
  1499. {
  1500. return list.Contains (value);
  1501. }
  1502. public virtual IEnumerator GetEnumerator ()
  1503. {
  1504. return list.GetEnumerator ();
  1505. }
  1506. void ICollection.CopyTo (Array dest, int index)
  1507. {
  1508. list.CopyTo (dest, index);
  1509. }
  1510. int IList.Add (object value)
  1511. {
  1512. if (! (value is ColumnHeader)) {
  1513. throw new ArgumentException ("Not of type ColumnHeader", "value");
  1514. }
  1515. return this.Add ((ColumnHeader) value);
  1516. }
  1517. bool IList.Contains (object value)
  1518. {
  1519. if (! (value is ColumnHeader)) {
  1520. throw new ArgumentException ("Not of type ColumnHeader", "value");
  1521. }
  1522. return this.Contains ((ColumnHeader) value);
  1523. }
  1524. int IList.IndexOf (object value)
  1525. {
  1526. if (! (value is ColumnHeader)) {
  1527. throw new ArgumentException ("Not of type ColumnHeader", "value");
  1528. }
  1529. return this.IndexOf ((ColumnHeader) value);
  1530. }
  1531. void IList.Insert (int index, object value)
  1532. {
  1533. if (! (value is ColumnHeader)) {
  1534. throw new ArgumentException ("Not of type ColumnHeader", "value");
  1535. }
  1536. this.Insert (index, (ColumnHeader) value);
  1537. }
  1538. void IList.Remove (object value)
  1539. {
  1540. if (! (value is ColumnHeader)) {
  1541. throw new ArgumentException ("Not of type ColumnHeader", "value");
  1542. }
  1543. this.Remove ((ColumnHeader) value);
  1544. }
  1545. public int IndexOf (ColumnHeader value)
  1546. {
  1547. return list.IndexOf (value);
  1548. }
  1549. public void Insert (int index, ColumnHeader value)
  1550. {
  1551. if (index < 0 || index >= list.Count)
  1552. throw new ArgumentOutOfRangeException ("Index out of range.");
  1553. list.Insert (index, value);
  1554. }
  1555. public void Insert (int index, string str, int width, HorizontalAlignment textAlign)
  1556. {
  1557. ColumnHeader colHeader = new ColumnHeader (this.owner, str, textAlign, width);
  1558. this.Insert (index, colHeader);
  1559. }
  1560. public virtual void Remove (ColumnHeader column)
  1561. {
  1562. list.Remove (column);
  1563. }
  1564. public virtual void RemoveAt (int index)
  1565. {
  1566. if (index < 0 || index >= list.Count)
  1567. throw new ArgumentOutOfRangeException ("Index out of range.");
  1568. list.RemoveAt (index);
  1569. }
  1570. #endregion // Public Methods
  1571. } // ColumnHeaderCollection
  1572. public class ListViewItemCollection : IList, ICollection, IEnumerable
  1573. {
  1574. internal ArrayList list;
  1575. private ListView owner;
  1576. #region Public Constructor
  1577. public ListViewItemCollection (ListView owner)
  1578. {
  1579. list = new ArrayList ();
  1580. this.owner = owner;
  1581. }
  1582. #endregion // Public Constructor
  1583. #region Public Properties
  1584. [Browsable (false)]
  1585. public virtual int Count {
  1586. get { return list.Count; }
  1587. }
  1588. public virtual bool IsReadOnly {
  1589. get { return false; }
  1590. }
  1591. public virtual ListViewItem this [int displayIndex] {
  1592. get {
  1593. if (displayIndex < 0 || displayIndex >= list.Count)
  1594. throw new ArgumentOutOfRangeException ("Index out of range.");
  1595. return (ListViewItem) list [displayIndex];
  1596. }
  1597. set {
  1598. if (displayIndex < 0 || displayIndex >= list.Count)
  1599. throw new ArgumentOutOfRangeException ("Index out of range.");
  1600. if (list.Contains (value))
  1601. throw new ArgumentException ("An item cannot be added more than once. To add an item again, you need to clone it.", "value");
  1602. value.owner = this.owner;
  1603. list [displayIndex] = value;
  1604. owner.Redraw (true);
  1605. }
  1606. }
  1607. bool ICollection.IsSynchronized {
  1608. get { return list.IsSynchronized; }
  1609. }
  1610. object ICollection.SyncRoot {
  1611. get { return list.SyncRoot; }
  1612. }
  1613. bool IList.IsFixedSize {
  1614. get { return list.IsFixedSize; }
  1615. }
  1616. object IList.this [int index] {
  1617. get { return this [index]; }
  1618. set {
  1619. if (value is ListViewItem)
  1620. this [index] = (ListViewItem) value;
  1621. else
  1622. this [index] = new ListViewItem (value.ToString ());
  1623. }
  1624. }
  1625. #endregion // Public Properties
  1626. #region Public Methods
  1627. public virtual ListViewItem Add (ListViewItem value)
  1628. {
  1629. if (list.Contains (value))
  1630. throw new ArgumentException ("An item cannot be added more than once. To add an item again, you need to clone it.", "value");
  1631. value.owner = this.owner;
  1632. list.Add (value);
  1633. if (owner.Sorting != SortOrder.None)
  1634. owner.Sort ();
  1635. owner.Redraw (true);
  1636. return value;
  1637. }
  1638. public virtual ListViewItem Add (string text)
  1639. {
  1640. ListViewItem item = new ListViewItem (text);
  1641. return this.Add (item);
  1642. }
  1643. public virtual ListViewItem Add (string text, int imageIndex)
  1644. {
  1645. ListViewItem item = new ListViewItem (text, imageIndex);
  1646. return this.Add (item);
  1647. }
  1648. public void AddRange (ListViewItem [] values)
  1649. {
  1650. list.Clear ();
  1651. foreach (ListViewItem item in values) {
  1652. item.owner = this.owner;
  1653. list.Add (item);
  1654. }
  1655. if (owner.Sorting != SortOrder.None)
  1656. owner.Sort ();
  1657. owner.Redraw (true);
  1658. }
  1659. public virtual void Clear ()
  1660. {
  1661. list.Clear ();
  1662. }
  1663. public bool Contains (ListViewItem item)
  1664. {
  1665. return list.Contains (item);
  1666. }
  1667. public virtual void CopyTo (Array dest, int index)
  1668. {
  1669. list.CopyTo (dest, index);
  1670. }
  1671. public virtual IEnumerator GetEnumerator ()
  1672. {
  1673. return list.GetEnumerator ();
  1674. }
  1675. int IList.Add (object item)
  1676. {
  1677. int result;
  1678. ListViewItem li;
  1679. if (item is ListViewItem) {
  1680. li = (ListViewItem) item;
  1681. if (list.Contains (li))
  1682. throw new ArgumentException ("An item cannot be added more than once. To add an item again, you need to clone it.", "item");
  1683. }
  1684. else
  1685. li = new ListViewItem (item.ToString ());
  1686. li.owner = this.owner;
  1687. result = list.Add (li);
  1688. owner.Redraw (true);
  1689. return result;
  1690. }
  1691. bool IList.Contains (object item)
  1692. {
  1693. return list.Contains (item);
  1694. }
  1695. int IList.IndexOf (object item)
  1696. {
  1697. return list.IndexOf (item);
  1698. }
  1699. void IList.Insert (int index, object item)
  1700. {
  1701. if (item is ListViewItem)
  1702. this.Insert (index, (ListViewItem) item);
  1703. else
  1704. this.Insert (index, item.ToString ());
  1705. }
  1706. void IList.Remove (object item)
  1707. {
  1708. if (list.Contains (item)) {
  1709. list.Remove (item);
  1710. owner.Redraw (true);
  1711. }
  1712. }
  1713. public int IndexOf (ListViewItem item)
  1714. {
  1715. return list.IndexOf (item);
  1716. }
  1717. public ListViewItem Insert (int index, ListViewItem item)
  1718. {
  1719. if (index < 0 || index >= list.Count)
  1720. throw new ArgumentOutOfRangeException ("Index out of range.");
  1721. if (list.Contains (item))
  1722. throw new ArgumentException ("An item cannot be added more than once. To add an item again, you need to clone it.", "item");
  1723. item.owner = this.owner;
  1724. list.Insert (index, item);
  1725. owner.Redraw (true);
  1726. return item;
  1727. }
  1728. public ListViewItem Insert (int index, string text)
  1729. {
  1730. return this.Insert (index, new ListViewItem (text));
  1731. }
  1732. public ListViewItem Insert (int index, string text, int imageIndex)
  1733. {
  1734. return this.Insert (index, new ListViewItem (text, imageIndex));
  1735. }
  1736. public virtual void Remove (ListViewItem item)
  1737. {
  1738. if (list.Contains (item)) {
  1739. list.Remove (item);
  1740. owner.Redraw (true);
  1741. }
  1742. }
  1743. public virtual void RemoveAt (int index)
  1744. {
  1745. if (index < 0 || index >= list.Count)
  1746. throw new ArgumentOutOfRangeException ("Index out of range.");
  1747. list.RemoveAt (index);
  1748. owner.Redraw (false);
  1749. }
  1750. #endregion // Public Methods
  1751. } // ListViewItemCollection
  1752. public class SelectedIndexCollection : IList, ICollection, IEnumerable
  1753. {
  1754. internal ArrayList list;
  1755. private ListView owner;
  1756. #region Public Constructor
  1757. public SelectedIndexCollection (ListView owner)
  1758. {
  1759. list = new ArrayList ();
  1760. this.owner = owner;
  1761. }
  1762. #endregion // Public Constructor
  1763. #region Public Properties
  1764. [Browsable (false)]
  1765. public virtual int Count {
  1766. get { return list.Count; }
  1767. }
  1768. public virtual bool IsReadOnly {
  1769. get { return true; }
  1770. }
  1771. public int this [int index] {
  1772. get {
  1773. if (index < 0 || index >= list.Count)
  1774. throw new ArgumentOutOfRangeException ("Index out of range.");
  1775. return (int) list [index];
  1776. }
  1777. }
  1778. bool ICollection.IsSynchronized {
  1779. get { return list.IsSynchronized; }
  1780. }
  1781. object ICollection.SyncRoot {
  1782. get { return list.SyncRoot; }
  1783. }
  1784. bool IList.IsFixedSize {
  1785. get { return list.IsFixedSize; }
  1786. }
  1787. object IList.this [int index] {
  1788. get { return this [index]; }
  1789. set { throw new NotSupportedException ("SetItem operation is not supported."); }
  1790. }
  1791. #endregion // Public Properties
  1792. #region Public Methods
  1793. public bool Contains (int selectedIndex)
  1794. {
  1795. return list.Contains (selectedIndex);
  1796. }
  1797. public virtual void CopyTo (Array dest, int index)
  1798. {
  1799. list.CopyTo (dest, index);
  1800. }
  1801. public virtual IEnumerator GetEnumerator ()
  1802. {
  1803. return list.GetEnumerator ();
  1804. }
  1805. int IList.Add (object value)
  1806. {
  1807. throw new NotSupportedException ("Add operation is not supported.");
  1808. }
  1809. void IList.Clear ()
  1810. {
  1811. throw new NotSupportedException ("Clear operation is not supported.");
  1812. }
  1813. bool IList.Contains (object selectedIndex)
  1814. {
  1815. return list.Contains (selectedIndex);
  1816. }
  1817. int IList.IndexOf (object selectedIndex)
  1818. {
  1819. return list.IndexOf (selectedIndex);
  1820. }
  1821. void IList.Insert (int index, object value)
  1822. {
  1823. throw new NotSupportedException ("Insert operation is not supported.");
  1824. }
  1825. void IList.Remove (object value)
  1826. {
  1827. throw new NotSupportedException ("Remove operation is not supported.");
  1828. }
  1829. void IList.RemoveAt (int index)
  1830. {
  1831. throw new NotSupportedException ("RemoveAt operation is not supported.");
  1832. }
  1833. public int IndexOf (int selectedIndex)
  1834. {
  1835. return list.IndexOf (selectedIndex);
  1836. }
  1837. #endregion // Public Methods
  1838. } // SelectedIndexCollection
  1839. public class SelectedListViewItemCollection : IList, ICollection, IEnumerable
  1840. {
  1841. internal ArrayList list;
  1842. private ListView owner;
  1843. #region Public Constructor
  1844. public SelectedListViewItemCollection (ListView owner)
  1845. {
  1846. list = new ArrayList ();
  1847. this.owner = owner;
  1848. }
  1849. #endregion // Public Constructor
  1850. #region Public Properties
  1851. [Browsable (false)]
  1852. public virtual int Count {
  1853. get { return list.Count; }
  1854. }
  1855. public virtual bool IsReadOnly {
  1856. get { return true; }
  1857. }
  1858. public ListViewItem this [int index] {
  1859. get {
  1860. if (index < 0 || index >= list.Count)
  1861. throw new ArgumentOutOfRangeException ("Index out of range.");
  1862. return (ListViewItem) list [index];
  1863. }
  1864. }
  1865. bool ICollection.IsSynchronized {
  1866. get { return list.IsSynchronized; }
  1867. }
  1868. object ICollection.SyncRoot {
  1869. get { return list.SyncRoot; }
  1870. }
  1871. bool IList.IsFixedSize {
  1872. get { return list.IsFixedSize; }
  1873. }
  1874. object IList.this [int index] {
  1875. get { return this [index]; }
  1876. set { throw new NotSupportedException ("SetItem operation is not supported."); }
  1877. }
  1878. #endregion // Public Properties
  1879. #region Public Methods
  1880. public virtual void Clear ()
  1881. {
  1882. // mark the items as unselected before clearing the list
  1883. for (int i = 0; i < list.Count; i++)
  1884. ((ListViewItem) list [i]).selected = false;
  1885. list.Clear ();
  1886. }
  1887. public bool Contains (ListViewItem item)
  1888. {
  1889. return list.Contains (item);
  1890. }
  1891. public virtual void CopyTo (Array dest, int index)
  1892. {
  1893. list.CopyTo (dest, index);
  1894. }
  1895. public virtual IEnumerator GetEnumerator ()
  1896. {
  1897. return list.GetEnumerator ();
  1898. }
  1899. int IList.Add (object value)
  1900. {
  1901. throw new NotSupportedException ("Add operation is not supported.");
  1902. }
  1903. bool IList.Contains (object item)
  1904. {
  1905. return list.Contains (item);
  1906. }
  1907. int IList.IndexOf (object item)
  1908. {
  1909. return list.IndexOf (item);
  1910. }
  1911. void IList.Insert (int index, object value)
  1912. {
  1913. throw new NotSupportedException ("Insert operation is not supported.");
  1914. }
  1915. void IList.Remove (object value)
  1916. {
  1917. throw new NotSupportedException ("Remove operation is not supported.");
  1918. }
  1919. void IList.RemoveAt (int index)
  1920. {
  1921. throw new NotSupportedException ("RemoveAt operation is not supported.");
  1922. }
  1923. public int IndexOf (ListViewItem item)
  1924. {
  1925. return list.IndexOf (item);
  1926. }
  1927. #endregion // Public Methods
  1928. } // SelectedListViewItemCollection
  1929. #endregion // Subclasses
  1930. }
  1931. }